| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /******************************************************************************
- *
- * FILE
- * $Archive: /Commando/Code/WWOnline/WOLServer.cpp $
- *
- * DESCRIPTION
- * These classes encapsulate a Westwood Online Server.
- *
- * This is a base class. Derived classes include (but not necessarily limited to)
- * ChatServer, GameResultsServer, LadderServer, and WDTServer.
- *
- * Server primarily repackages the WOL Server struct
- *
- * PROGRAMMER
- * $Author: Denzil_l $
- *
- * VERSION INFO
- * $Revision: 14 $
- * $Modtime: 1/12/02 9:42p $
- *
- ******************************************************************************/
- #include <stdlib.h>
- #include "WOLServer.h"
- #include "WOLProduct.h"
- #include <commando\_globals.h>
- #include <string.h>
- #include <WWDebug\WWDebug.h>
- #include <WWLib\Registry.h>
- namespace WWOnline {
- /******************************************************************************
- *
- * NAME
- * ServerData::ServerData
- *
- * DESCRIPTION
- * Constructor
- *
- * INPUTS
- * Server - WOLAPI Server structure representing server.
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- ServerData::ServerData(const WOL::Server& server)
- {
- memcpy(&mData, &server, sizeof(mData));
- mData.next = NULL;
- }
- /******************************************************************************
- *
- * NAME
- * ServerData::~ServerData
- *
- * DESCRIPTION
- * Destructor
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- ServerData::~ServerData()
- {
- WWDEBUG_SAY(("WOL: Destructing ServerData %s:%s\n", mData.connlabel, mData.name));
- }
- /******************************************************************************
- *
- * NAME
- * IRCServerData::Create
- *
- * DESCRIPTION
- * Create a IRC server instance.
- *
- * INPUTS
- * Server - WOLAPI server structure
- *
- * RESULT
- * Instance of IRC server class.
- *
- ******************************************************************************/
- RefPtr<IRCServerData> IRCServerData::Create(const WOL::Server& server)
- {
- WWASSERT((strcmp((char*)server.connlabel, "IRC") == 0) || (strcmp((char*)server.connlabel, "IGS") == 0));
- return new IRCServerData(server);
- }
- /******************************************************************************
- *
- * NAME
- * IRCServerData::IRCServerData
- *
- * DESCRIPTION
- * Constructor
- *
- * INPUTS
- * Server - WOLAPI server structure
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- IRCServerData::IRCServerData(const WOL::Server& server) :
- ServerData(server),
- mMatchesLanguageCode(false),
- mHasLanguageCode(false)
- {
- mIsGameServer = (strcmp((char*)server.connlabel, "IGS") == 0);
- RefPtr<Product> product = Product::Current();
- WWASSERT(product.IsValid() && "WWOnline product not initialized.");
- char* namePart = strchr((char*)server.name, ':');
- if (namePart)
- {
- namePart++;
- }
- char name[sizeof(server.name) + 1];
- strcpy(name, (char*)server.name);
- char* langPart = strtok(name, ":");
- if (namePart && langPart)
- {
- char* token = strtok(langPart, ",");
- if (token)
- {
- long productLangCode = product->GetLanguageCode();
- do
- {
- long langCode = atol(token);
- if (langCode == productLangCode)
- {
- mMatchesLanguageCode = true;
- }
- token = strtok(NULL, ",");
- } while (token);
- }
- }
- if (namePart)
- {
- mServerName = namePart;
- mHasLanguageCode = true;
- }
- else
- {
- mServerName = (char*)server.name;
- }
- }
- /******************************************************************************
- *
- * NAME
- * HostPortServerData::HostPortServerData
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- HostPortServerData::HostPortServerData(const WOL::Server& server) :
- ServerData(server)
- {
- char data[sizeof(server.conndata) + 1];
- strcpy(data, (char*)server.conndata);
- char* token = strtok(data, ";");
- WWASSERT(token);
- if (token)
- {
- token = strtok(NULL, ";");
- }
- WWASSERT(token);
- if (token)
- {
- mHostAddress = token;
- token = strtok(NULL, ";");
- }
- WWASSERT(token);
- if (token)
- {
- mHostPort = atol(token);
- }
- }
- /******************************************************************************
- *
- * NAME
- * LadderServerData::Create
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- *
- ******************************************************************************/
- RefPtr<LadderServerData> LadderServerData::Create(const WOL::Server& server)
- {
- WWASSERT(strcmp((char*)server.connlabel, "LAD") == 0);
- return new LadderServerData(server);
- }
- /******************************************************************************
- *
- * NAME
- * LadderServerData::LadderServerData
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- LadderServerData::LadderServerData(const WOL::Server& server) :
- HostPortServerData(server)
- {
- }
- /******************************************************************************
- *
- * NAME
- * GameResultsServerData::Create
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- *
- ******************************************************************************/
- RefPtr<GameResultsServerData> GameResultsServerData::Create(const WOL::Server& server)
- {
- WWASSERT(strcmp((char*)server.connlabel, "GAM") == 0);
- return new GameResultsServerData(server);
- }
- /******************************************************************************
- *
- * NAME
- * GameResultsServerData::GameResultsServerData
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- GameResultsServerData::GameResultsServerData(const WOL::Server& server) :
- HostPortServerData(server)
- {
- }
- /******************************************************************************
- *
- * NAME
- * WDTServerData::Create
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- *
- ******************************************************************************/
- RefPtr<WDTServerData> WDTServerData::Create(const WOL::Server& server)
- {
- WWASSERT(strcmp((char*)server.connlabel, "WDT") == 0);
- return new WDTServerData(server);
- }
- /******************************************************************************
- *
- * NAME
- * WDTServerData::WDTServerData
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- WDTServerData::WDTServerData(const WOL::Server& server) :
- HostPortServerData(server)
- {
- }
- /******************************************************************************
- *
- * NAME
- * MGLServerData::Create
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- *
- ******************************************************************************/
- RefPtr<MGLServerData> MGLServerData::Create(const WOL::Server& server)
- {
- WWASSERT(strcmp((char*)server.connlabel, "MGL") == 0);
- return new MGLServerData(server);
- }
- /******************************************************************************
- *
- * NAME
- * MGLServerData::MGLServerData
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- MGLServerData::MGLServerData(const WOL::Server& server) :
- HostPortServerData(server)
- {
- WWDEBUG_SAY(("WOL: ManglerServer %s:%d\n", GetHostAddress(), GetPort()));
- }
- RefPtr<PingServerData> PingServerData::Create(const WOL::Server& server)
- {
- WWASSERT(strcmp((char*)server.connlabel, "PNG") == 0);
- return new PingServerData(server);
- }
- PingServerData::PingServerData(const WOL::Server& server) :
- HostPortServerData(server),
- mPingTime(-1)
- {
- WWDEBUG_SAY(("WOL: PingServer %s:%d\n", GetHostAddress(), GetPort()));
- }
- void PingServerData::SetPingTime(int time)
- {
- mPingTime = time;
- // Save the ping time in the registry.
- RegistryClass reg(APPLICATION_SUB_KEY_NAME_SERVER_LIST);
- reg.Set_Int(GetHostAddress(), time);
- }
- }
|