Skip to content

Commit 9fb6a01

Browse files
committed
Major implementation refactor.
1 parent 4019d2b commit 9fb6a01

File tree

10 files changed

+96
-36
lines changed

10 files changed

+96
-36
lines changed

GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPI.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ class LANAPI : public LANAPIInterface
282282
void handleGameStartTimer( LANMessage *msg, UnsignedInt senderIP );
283283
void handleGameOptions( LANMessage *msg, UnsignedInt senderIP );
284284
void handleInActive( LANMessage *msg, UnsignedInt senderIP );
285+
void handlePatchVersion( LANMessage *msg, UnsignedInt senderIP );
285286

286287
};
287288

@@ -319,6 +320,7 @@ struct LANMessage
319320
MSG_INACTIVE, ///< I've alt-tabbed out. Unaccept me cause I'm a poo-flinging monkey.
320321

321322
MSG_REQUEST_GAME_INFO, ///< For direct connect, get the game info from a specific IP Address
323+
MSG_PATCH_VERSION, ///< TheSuperHackers patch version
322324

323325
MSG_MAX
324326
} LANMessageType;
@@ -366,7 +368,6 @@ struct LANMessage
366368
UnsignedInt exeCRC;
367369
UnsignedInt iniCRC;
368370
char serial[g_maxSerialLength];
369-
UnsignedInt patchVersion;
370371
} GameToJoin;
371372

372373
// GameJoined is sent with JOIN_ACCEPT
@@ -416,6 +417,11 @@ struct LANMessage
416417
char options[m_lanMaxOptionsLength+1];
417418
} GameOptions;
418419

420+
struct
421+
{
422+
UnsignedInt patchVersion;
423+
} PatchInfo;
424+
419425
};
420426
};
421427
#pragma pack(pop)

GeneralsMD/Code/GameEngine/Include/GameNetwork/LANPlayer.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
class LANPlayer
4040
{
4141
public:
42-
LANPlayer() { m_name = m_login = m_host = L""; m_lastHeard = 0; m_next = NULL; m_IP = 0; }
42+
LANPlayer() { m_name = m_login = m_host = L""; m_lastHeard = 0; m_next = NULL; m_IP = 0; m_patchVersion = 0; }
4343

4444
// Access functions
4545
inline UnicodeString getName( void ) { return m_name; }
@@ -56,14 +56,17 @@ class LANPlayer
5656
inline void setNext( LANPlayer *next ) { m_next = next; }
5757
inline UnsignedInt getIP( void ) { return m_IP; }
5858
inline void setIP( UnsignedInt IP ) { m_IP = IP; }
59+
inline void setPatchVersion(UnsignedInt patchVersion) { m_patchVersion = patchVersion; }
60+
inline UnsignedInt getPatchVersion() const { return m_patchVersion; }
5961

6062
protected:
61-
UnicodeString m_name; ///< Player name
62-
UnicodeString m_login; ///< login name
63-
UnicodeString m_host; ///< machine name
64-
UnsignedInt m_lastHeard; ///< The last time we heard from this player (for timeout purposes)
65-
LANPlayer *m_next; ///< Linked list pointer
66-
UnsignedInt m_IP; ///< Player's IP
63+
UnicodeString m_name; ///< Player name
64+
UnicodeString m_login; ///< login name
65+
UnicodeString m_host; ///< machine name
66+
UnsignedInt m_lastHeard; ///< The last time we heard from this player (for timeout purposes)
67+
LANPlayer *m_next; ///< Linked list pointer
68+
UnsignedInt m_IP; ///< Player's IP
69+
UnsignedInt m_patchVersion; ///< TheSuperHackers patch version
6770
};
6871

6972
#endif //_LANPLAYER_H_

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Diplomacy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ void PopulateInGameDiplomacyPopup( void )
572572
}
573573
}
574574

575-
if (slot->isHuman() && (TheGameInfo->getLocalSlotNum() == slotNum || slot->getPatchVersion() >= 1337))
575+
if (slot->isHuman() && (TheGameInfo->getLocalSlotNum() == slotNum || slot->getPatchVersion() > 0))
576576
text.concat(L"[SH]");
577577

578578
staticTextStatus[rowNum]->winSetEnabledTextColors(frontColor, backColor);

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/GameInfoWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void RefreshGameInfoWindow(GameInfo *gameInfo, UnicodeString gameName)
177177
}
178178
else if(slot->isHuman())
179179
{
180-
addedRow = GadgetListBoxAddEntryText(listBoxPlayers, slot->getName(), (slot->getPatchVersion() >= 1337) ? 0xFFFFFF00 : playerColor, -1, 1);
180+
addedRow = GadgetListBoxAddEntryText(listBoxPlayers, slot->getName(),playerColor,-1,1);
181181
}
182182
Int playerTemplate = slot->getPlayerTemplate();
183183
if(playerTemplate == PLAYERTEMPLATE_OBSERVER)

GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ void UpdateSlotList( GameInfo *myGame, GameWindow *comboPlayer[],
423423
}
424424
if(slot->isHuman())
425425
{
426-
if (i == myGame->getLocalSlotNum() || myGame->getSlot(i)->getPatchVersion() >= 1337)
426+
if (i == myGame->getLocalSlotNum() || myGame->getSlot(i)->getPatchVersion() > 0)
427427
{
428428
GadgetComboBoxSetEnabledTextColors(comboPlayer[i], 0xFFFFFF00, 0xFF000000);
429429
GadgetComboBoxSetDisabledTextColors(comboPlayer[i], 0xFFC0C000, 0xFF000000);

GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -922,21 +922,8 @@ AsciiString GameInfoToAsciiString( const GameInfo *game )
922922
DEBUG_LOG(("Map name is %s", mapName.str()));
923923
}
924924

925-
UnsignedByte patchedClients = 0;
926-
{
927-
for (Int i = 0; i < MAX_SLOTS; ++i)
928-
{
929-
const GameSlot* slot = game->getConstSlot(i);
930-
if (slot && slot->isHuman() && (i == game->getLocalSlotNum() || slot->getPatchVersion() >= 1337))
931-
patchedClients |= (1 << i);
932-
}
933-
}
934-
935-
AsciiString statsString;
936-
statsString.format("%d P%cP", game->getUseStats() & 1, patchedClients);
937-
938925
AsciiString optionsString;
939-
optionsString.format("US=%s;M=%2.2x%s;MC=%X;MS=%d;SD=%d;C=%d;SR=%u;SC=%u;O=%c;", statsString.str(), game->getMapContentsMask(), newMapName.str(),
926+
optionsString.format("US=%d;M=%2.2x%s;MC=%X;MS=%d;SD=%d;C=%d;SR=%u;SC=%u;O=%c;", game->getUseStats(), game->getMapContentsMask(), newMapName.str(),
940927
game->getMapCRC(), game->getMapSize(), game->getSeed(), game->getCRCInterval(), game->getSuperweaponRestriction(),
941928
game->getStartingCash().countMoney(), game->oldFactionsOnly() ? 'Y' : 'N' );
942929

@@ -1031,7 +1018,6 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)
10311018
Int useStats = TRUE;
10321019
Money startingCash = TheGlobalData->m_defaultStartingCash;
10331020
UnsignedShort restriction = 0; // Always the default
1034-
UnsignedByte patchedClients = 0;
10351021

10361022
Bool sawMap, sawMapCRC, sawMapSize, sawSeed, sawSlotlist, sawUseStats, sawSuperweaponRestriction, sawStartingCash, sawOldFactions;
10371023
sawMap = sawMapCRC = sawMapSize = sawSeed = sawSlotlist = sawUseStats = sawSuperweaponRestriction = sawStartingCash = sawOldFactions = FALSE;
@@ -1065,9 +1051,6 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)
10651051
{
10661052
useStats = atoi(val.str());
10671053
sawUseStats = true;
1068-
1069-
if (val.getLength() >= 5 && val.getCharAt(2) == 'P' && val.getCharAt(4) == 'P')
1070-
patchedClients = val.getCharAt(3);
10711054
}
10721055
else
10731056
if (key.compare("M") == 0)
@@ -1498,8 +1481,8 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)
14981481

14991482
for(Int i = 0; i<MAX_SLOTS; i++)
15001483
{
1501-
if (patchedClients & (1 << i))
1502-
newSlot[i].setPatchVersion(1337);
1484+
if (game->getConstSlot(i)->getState() == SLOT_PLAYER && newSlot[i].getState() == SLOT_PLAYER)
1485+
newSlot[i].setPatchVersion(game->getConstSlot(i)->getPatchVersion());
15031486

15041487
game->setSlot(i,newSlot[i]);
15051488
}

GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "Common/crc.h"
3030
#include "Common/GameState.h"
3131
#include "Common/Registry.h"
32+
#include "Common/version.h"
3233
#include "GameNetwork/LANAPI.h"
3334
#include "GameNetwork/networkutil.h"
3435
#include "Common/GlobalData.h"
@@ -417,6 +418,9 @@ void LANAPI::update( void )
417418
case LANMessage::MSG_INACTIVE: // someone is telling us that we're inactive.
418419
handleInActive( msg, senderIP );
419420
break;
421+
case LANMessage::MSG_PATCH_VERSION: // someone is sharing their patch version with us
422+
handlePatchVersion( msg, senderIP );
423+
break;
420424

421425
default:
422426
DEBUG_LOG(("Unknown LAN message type %d", msg->LANMessageType));
@@ -461,6 +465,14 @@ void LANAPI::update( void )
461465
}
462466
}
463467

468+
if (m_inLobby || (m_currentGame && !m_currentGame->isGameInProgress())) {
469+
LANMessage msg;
470+
fillInLANMessage(&msg);
471+
msg.LANMessageType = LANMessage::MSG_PATCH_VERSION;
472+
msg.PatchInfo.patchVersion = TheVersion->getVersionNumber();
473+
sendMessage(&msg);
474+
}
475+
464476
Bool playerListChanged = false;
465477
Bool gameListChanged = false;
466478

@@ -635,7 +647,6 @@ void LANAPI::RequestGameJoin( LANGameInfo *game, UnsignedInt ip /* = 0 */ )
635647
GetStringFromRegistry("\\ergc", "", s);
636648
strncpy(msg.GameToJoin.serial, s.str(), g_maxSerialLength);
637649
msg.GameToJoin.serial[g_maxSerialLength-1] = '\0';
638-
msg.GameToJoin.patchVersion = 1337;
639650

640651
sendMessage(&msg, ip);
641652

GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,8 @@ void LANAPI::OnPlayerList( LANPlayer *playerList )
642642
LANPlayer *player = m_lobbyPlayers;
643643
while (player)
644644
{
645-
Int addedIndex = GadgetListBoxAddEntryText(listboxPlayers, player->getName(), playerColor, -1, -1);
645+
const Color color = (player->getPatchVersion() > 0 || m_localIP == player->getIP()) ? 0xFFFFFF00 : playerColor;
646+
Int addedIndex = GadgetListBoxAddEntryText(listboxPlayers, player->getName(), color, -1, -1);
646647
GadgetListBoxSetItemData(listboxPlayers, (void *)player->getIP(),addedIndex, 0 );
647648

648649
if (selectedIP == player->getIP())

GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,6 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
348348
newSlot.setPort(NETWORK_BASE_PORT_NUMBER);
349349
newSlot.setLastHeard(timeGetTime());
350350
newSlot.setSerial(msg->GameToJoin.serial);
351-
if (msg->GameToJoin.patchVersion == 1337)
352-
newSlot.setPatchVersion(msg->GameToJoin.patchVersion);
353351
m_currentGame->setSlot(player,newSlot);
354352
DEBUG_LOG(("LANAPI::handleRequestJoin - added player %ls at ip 0x%08x to the game", msg->name, senderIP));
355353

@@ -684,3 +682,58 @@ void LANAPI::handleInActive(LANMessage *msg, UnsignedInt senderIP) {
684682
RequestGameOptions(options, FALSE);
685683
lanUpdateSlotList();
686684
}
685+
686+
void LANAPI::handlePatchVersion(LANMessage* msg, UnsignedInt senderIP)
687+
{
688+
if (m_inLobby)
689+
{
690+
LANPlayer *player = m_lobbyPlayers;
691+
while (player)
692+
{
693+
if (player->getIP() == senderIP)
694+
{
695+
if (!player->getPatchVersion() && msg->PatchInfo.patchVersion > 0)
696+
{
697+
player->setPatchVersion(msg->PatchInfo.patchVersion);
698+
OnPlayerList(m_lobbyPlayers);
699+
}
700+
break;
701+
}
702+
703+
player = player->getNext();
704+
}
705+
706+
LANGameInfo* game = m_games;
707+
while (game)
708+
{
709+
GameSlot *slot = game->getSlot(0);
710+
if (slot->getIP() == senderIP)
711+
{
712+
DEBUG_ASSERTCRASH(game->getHostIP() == slot->getIP(), ("First game slot is not used by the host"));
713+
714+
if (!slot->getPatchVersion() && msg->PatchInfo.patchVersion > 0)
715+
{
716+
slot->setPatchVersion(msg->PatchInfo.patchVersion);
717+
OnGameList(m_games);
718+
}
719+
break;
720+
}
721+
722+
game = game->getNext();
723+
}
724+
}
725+
else if (m_currentGame && !m_currentGame->isGameInProgress())
726+
{
727+
for (int player = 0; player < MAX_SLOTS; ++player)
728+
{
729+
if (m_currentGame->getIP(player) == senderIP)
730+
{
731+
if (!m_currentGame->getSlot(player)->getPatchVersion() && msg->PatchInfo.patchVersion > 0)
732+
{
733+
m_currentGame->getSlot(player)->setPatchVersion(msg->PatchInfo.patchVersion);
734+
}
735+
break;
736+
}
737+
}
738+
}
739+
}

GeneralsMD/Code/GameEngine/Source/GameNetwork/LANGameInfo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ void LANDisplayGameList( GameWindow *gameListbox, LANGameInfo *gameList )
226226
{
227227
txtGName.concat(L"]");
228228
}
229-
Int addedIndex = GadgetListBoxAddEntryText(gameListbox, txtGName, (gameList->isGameInProgress())?gameInProgressColor:gameColor, -1, -1);
229+
const Color color = (gameList->getSlot(0)->getPatchVersion() > 0)
230+
? ((gameList->isGameInProgress()) ? 0xFF808000 : 0xFFFFFF00)
231+
: ((gameList->isGameInProgress()) ? gameInProgressColor : gameColor);
232+
Int addedIndex = GadgetListBoxAddEntryText(gameListbox, txtGName, color, -1, -1);
230233
GadgetListBoxSetItemData(gameListbox, (void *)gameList, addedIndex, 0 );
231234

232235
if (selectedPtr == gameList)

0 commit comments

Comments
 (0)