| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- /*
- ** Command & Conquer Generals Zero Hour(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/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////
- // FILE: GSConfig.cpp
- // Author: Matthew D. Campbell, Sept 2002
- // Description: GameSpy online config
- ///////////////////////////////////////////////////////////////////////////////////////
- // INCLUDES ///////////////////////////////////////////////////////////////////////////
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- #include "Common/GameState.h"
- #include "GameClient/MapUtil.h"
- #include "GameNetwork/GameSpy/GSConfig.h"
- #include "GameNetwork/RankPointValue.h"
- #ifdef _INTERNAL
- // for occasional debugging...
- //#pragma optimize("", off)
- //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
- #endif
- ///////////////////////////////////////////////////////////////////////////////////////
- GameSpyConfigInterface *TheGameSpyConfig = NULL;
- class GameSpyConfig : public GameSpyConfigInterface
- {
- public:
- GameSpyConfig( AsciiString config );
- ~GameSpyConfig() {}
- // Pings
- std::list<AsciiString> getPingServers(void) { return m_pingServers; }
- Int getNumPingRepetitions(void) { return m_pingReps; }
- Int getPingTimeoutInMs(void) { return m_pingTimeout; }
- virtual Int getPingCutoffGood( void ) { return m_pingCutoffGood; }
- virtual Int getPingCutoffBad( void ) { return m_pingCutoffBad; }
- // QM
- std::list<AsciiString> getQMMaps(void) { return m_qmMaps; }
- Int getQMBotID(void) { return m_qmBotID; }
- Int getQMChannel(void) { return m_qmChannel; }
- void setQMChannel(Int channel) { m_qmChannel = channel; }
- // Player Info
- Int getPointsForRank(Int rank);
- virtual Bool isPlayerVIP(Int id);
-
- virtual Bool getManglerLocation(Int index, AsciiString& host, UnsignedShort& port);
- // Ladder / Any other external parsing
- AsciiString getLeftoverConfig(void) { return m_leftoverConfig; }
-
- // NAT Timeouts
- virtual Int getTimeBetweenRetries() { return m_natRetryInterval; }
- virtual Int getMaxManglerRetries() { return m_natMaxManglerRetries; }
- virtual time_t getRetryInterval() { return m_natManglerRetryInterval; }
- virtual time_t getKeepaliveInterval() { return m_natKeepaliveInterval; }
- virtual time_t getPortTimeout() { return m_natPortTimeout; }
- virtual time_t getRoundTimeout() { return m_natRoundTimeout; }
- // Custom match
- virtual Bool restrictGamesToLobby() { return m_restrictGamesToLobby; }
- protected:
- std::list<AsciiString> m_pingServers;
- Int m_pingReps;
- Int m_pingTimeout;
- Int m_pingCutoffGood;
- Int m_pingCutoffBad;
- Int m_natRetryInterval;
- Int m_natMaxManglerRetries;
- time_t m_natManglerRetryInterval;
- time_t m_natKeepaliveInterval;
- time_t m_natPortTimeout;
- time_t m_natRoundTimeout;
- std::vector<AsciiString> m_manglerHosts;
- std::vector<UnsignedShort> m_manglerPorts;
- std::list<AsciiString> m_qmMaps;
- Int m_qmBotID;
- Int m_qmChannel;
- Bool m_restrictGamesToLobby;
- std::set<Int> m_vip; // VIP people
- Int m_rankPoints[MAX_RANKS];
- AsciiString m_leftoverConfig;
- };
- ///////////////////////////////////////////////////////////////////////////////////////
- GameSpyConfigInterface* GameSpyConfigInterface::create(AsciiString config)
- {
- return NEW GameSpyConfig(config);
- }
- ///////////////////////////////////////////////////////////////////////////////////////
- class SectionChecker
- {
- public:
- typedef std::list<const Bool *> SectionList;
- void addVar(const Bool *var) { m_bools.push_back(var); }
- Bool isInSection();
- protected:
- SectionList m_bools;
- };
- Bool SectionChecker::isInSection() {
- Bool ret = FALSE;
- for (SectionList::const_iterator it = m_bools.begin(); it != m_bools.end(); ++it)
- {
- ret = ret || **it;
- }
- return ret;
- }
- ///////////////////////////////////////////////////////////////////////////////////////
- GameSpyConfig::GameSpyConfig( AsciiString config ) :
- m_natRetryInterval(1000),
- m_natMaxManglerRetries(25),
- m_natManglerRetryInterval(300),
- m_natKeepaliveInterval(15000),
- m_natPortTimeout(10000),
- m_natRoundTimeout(10000),
- m_pingReps(1),
- m_pingTimeout(1000),
- m_pingCutoffGood(300),
- m_pingCutoffBad(600),
- m_restrictGamesToLobby(FALSE),
- m_qmBotID(0),
- m_qmChannel(0)
- {
- m_rankPoints[0] = 0;
- m_rankPoints[1] = 5;
- m_rankPoints[2] = 10;
- m_rankPoints[3] = 20;
- m_rankPoints[4] = 50;
- m_rankPoints[5] = 100;
- m_rankPoints[6] = 200;
- m_rankPoints[7] = 500;
- m_rankPoints[8] = 1000;
- m_rankPoints[9] = 2000;
- AsciiString line;
- Bool inPingServers = FALSE;
- Bool inPingDuration = FALSE;
- Bool inQMMaps = FALSE;
- Bool inQMBot = FALSE;
- Bool inManglers = FALSE;
- Bool inVIP = FALSE;
- Bool inNAT = FALSE;
- Bool inCustom = FALSE;
- SectionChecker sections;
- sections.addVar(&inPingServers);
- sections.addVar(&inPingDuration);
- sections.addVar(&inQMMaps);
- sections.addVar(&inQMBot);
- sections.addVar(&inManglers);
- sections.addVar(&inVIP);
- sections.addVar(&inNAT);
- sections.addVar(&inCustom);
- while (config.nextToken(&line, "\n"))
- {
- if (line.getCharAt(line.getLength()-1) == '\r')
- line.removeLastChar(); // there is a trailing '\r'
- line.trim();
- if (line.isEmpty())
- continue;
- if (!sections.isInSection() && line.compare("<PingServers>") == 0)
- {
- inPingServers = TRUE;
- }
- else if (inPingServers && line.compare("</PingServers>") == 0)
- {
- inPingServers = FALSE;
- }
- else if (!sections.isInSection() && line.compare("<PingDuration>") == 0)
- {
- inPingDuration = TRUE;
- }
- else if (inPingDuration && line.compare("</PingDuration>") == 0)
- {
- inPingDuration = FALSE;
- }
- else if (!sections.isInSection() && line.compare("<QMMaps>") == 0)
- {
- inQMMaps = TRUE;
- }
- else if (inQMMaps && line.compare("</QMMaps>") == 0)
- {
- inQMMaps = FALSE;
- }
- else if (!sections.isInSection() && line.compare("<Manglers>") == 0)
- {
- inManglers = TRUE;
- }
- else if (inManglers && line.compare("</Manglers>") == 0)
- {
- inManglers = FALSE;
- }
- else if (!sections.isInSection() && line.compare("<QMBot>") == 0)
- {
- inQMBot = TRUE;
- }
- else if (inQMBot && line.compare("</QMBot>") == 0)
- {
- inQMBot = FALSE;
- }
- else if (!sections.isInSection() && line.compare("<VIP>") == 0)
- {
- inVIP = TRUE;
- }
- else if (inVIP && line.compare("</VIP>") == 0)
- {
- inVIP = FALSE;
- }
- else if (!sections.isInSection() && line.compare("<NAT>") == 0)
- {
- inNAT = TRUE;
- }
- else if (inNAT && line.compare("</NAT>") == 0)
- {
- inNAT = FALSE;
- }
- else if (!sections.isInSection() && line.compare("<Custom>") == 0)
- {
- inCustom = TRUE;
- }
- else if (inCustom && line.compare("</Custom>") == 0)
- {
- inCustom = FALSE;
- }
- else if (inVIP)
- {
- line.toLower();
- if (line.getLength())
- {
- Int val = atoi(line.str());
- if (val > 0)
- m_vip.insert(val);
- }
- }
- else if (inPingServers)
- {
- line.toLower();
- m_pingServers.push_back(line);
- }
- else if (inPingDuration)
- {
- line.toLower();
- AsciiString key, val;
- if (line.nextToken(&key, " ="))
- {
- if (key == "reps")
- {
- if (line.nextToken(&val, " ="))
- {
- m_pingReps = atoi(val.str());
- }
- }
- else if (key == "timeout")
- {
- if (line.nextToken(&val, " ="))
- {
- m_pingTimeout = atoi(val.str());
- }
- }
- else if (key == "low")
- {
- if (line.nextToken(&val, " ="))
- {
- m_pingCutoffGood = atoi(val.str());
- }
- }
- else if (key == "med")
- {
- if (line.nextToken(&val, " ="))
- {
- m_pingCutoffBad = atoi(val.str());
- }
- }
- }
- }
- else if (inManglers)
- {
- line.trim();
- line.toLower();
- AsciiString hostStr;
- AsciiString portStr;
- line.nextToken(&hostStr, ":");
- line.nextToken(&portStr, ":\n\r");
- if (hostStr.isNotEmpty() && portStr.isNotEmpty())
- {
- m_manglerHosts.push_back(hostStr);
- m_manglerPorts.push_back(atoi(portStr.str()));
- }
- }
- else if (inQMMaps)
- {
- line.toLower();
- AsciiString mapName;
- mapName.format("%s\\%s\\%s.map", TheMapCache->getMapDir().str(), line.str(), line.str());
- mapName = TheGameState->portableMapPathToRealMapPath(TheGameState->realMapPathToPortableMapPath(mapName));
- mapName.toLower();
- const MapMetaData *md = TheMapCache->findMap(mapName);
- if (md)
- {
- m_qmMaps.push_back(mapName);
- }
- }
- else if (inQMBot)
- {
- line.toLower();
- AsciiString key, val;
- if (line.nextToken(&key, " ="))
- {
- if (key == "id")
- {
- if (line.nextToken(&val, " ="))
- {
- m_qmBotID = atoi(val.str());
- }
- }
- }
- }
- else if (inNAT)
- {
- line.toLower();
- AsciiString key, val;
- if (line.nextToken(&key, " ="))
- {
- if (key == "retryinterval")
- {
- if (line.nextToken(&val, " ="))
- {
- m_natRetryInterval = atoi(val.str());
- }
- }
- else if (key == "manglerretries")
- {
- if (line.nextToken(&val, " ="))
- {
- m_natMaxManglerRetries = atoi(val.str());
- }
- }
- else if (key == "manglerinterval")
- {
- if (line.nextToken(&val, " ="))
- {
- m_natManglerRetryInterval = atoi(val.str());
- }
- }
- else if (key == "keepaliveinterval")
- {
- if (line.nextToken(&val, " ="))
- {
- m_natKeepaliveInterval = atoi(val.str());
- }
- }
- else if (key == "porttimeout")
- {
- if (line.nextToken(&val, " ="))
- {
- m_natPortTimeout = atoi(val.str());
- }
- }
- else if (key == "roundtimeout")
- {
- if (line.nextToken(&val, " ="))
- {
- m_natRoundTimeout = atoi(val.str());
- }
- }
- else
- {
- DEBUG_LOG(("Unknown key '%s' = '%s' in NAT block of GameSpy Config\n", key.str(), val.str()));
- }
- }
- else
- {
- DEBUG_LOG(("Key '%s' missing val in NAT block of GameSpy Config\n", key.str()));
- }
- }
- else if (inCustom)
- {
- line.toLower();
- AsciiString key, val;
- if (line.nextToken(&key, " =") && line.nextToken(&val, " ="))
- {
- if (key == "restricted")
- {
- m_restrictGamesToLobby = atoi(val.str());
- }
- else
- {
- DEBUG_LOG(("Unknown key '%s' = '%s' in Custom block of GameSpy Config\n", key.str(), val.str()));
- }
- }
- else
- {
- DEBUG_LOG(("Key '%s' missing val in Custom block of GameSpy Config\n", key.str()));
- }
- }
- else
- {
- m_leftoverConfig.concat(line);
- m_leftoverConfig.concat('\n');
- }
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////
- Int GameSpyConfig::getPointsForRank(Int rank)
- {
- if (rank >= MAX_RANKS) rank = MAX_RANKS-1;
- if (rank < 0) rank = 0;
- return m_rankPoints[rank];
- }
- ///////////////////////////////////////////////////////////////////////////////////////
- Bool GameSpyConfig::getManglerLocation(Int index, AsciiString& host, UnsignedShort& port)
- {
- if (index < 0 || index >= m_manglerHosts.size())
- {
- return FALSE;
- }
- host = m_manglerHosts[index];
- port = m_manglerPorts[index];
- return TRUE;
- }
- ///////////////////////////////////////////////////////////////////////////////////////
- Bool GameSpyConfig::isPlayerVIP(Int id)
- {
- std::set<Int>::const_iterator it = std::find(m_vip.begin(), m_vip.end(), id);
- return it != m_vip.end();
- }
- ///////////////////////////////////////////////////////////////////////////////////////
|