Skip to content

Commit c955abc

Browse files
committed
Sync team, side, color and starting position to/from lobby service
1 parent 2783c09 commit c955abc

4 files changed

Lines changed: 145 additions & 90 deletions

File tree

GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ struct LobbyMemberEntry : public NetworkMemberBase
1212
uint16_t preferredPort;
1313
// NOTE: NetworkMemberBase is not deserialized
1414

15+
int side = -1;
16+
int color = -1;
17+
int team = -1;
18+
int startpos = -1;
19+
1520
bool IsValid() const { return user_id != -1; }
1621
};
1722

@@ -59,6 +64,11 @@ class NGMP_OnlineServices_LobbyInterface
5964
// updates
6065
void UpdateCurrentLobby_Map(AsciiString strMap, AsciiString strMapPath, int newMaxPlayers);
6166

67+
void UpdateCurrentLobby_MySide(int side, int updatedStartPos);
68+
void UpdateCurrentLobby_MyColor(int side);
69+
void UpdateCurrentLobby_MyStartPos(int side);
70+
void UpdateCurrentLobby_MyTeam(int side);
71+
6272
void SetLobbyListDirty()
6373
{
6474
m_bLobbyListDirty = true;

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

Lines changed: 31 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,6 @@ NameKeyType listboxGameSetupChatID = NAMEKEY_INVALID;
552552

553553
static void handleColorSelection(int index)
554554
{
555-
// TODO_NGMP
556-
return;
557555
GameWindow *combo = comboBoxColor[index];
558556
Int color, selIndex;
559557
GadgetComboBoxGetSelectedPos(combo, &selIndex);
@@ -582,35 +580,19 @@ static void handleColorSelection(int index)
582580
}
583581
}
584582
}
583+
584+
// TODO_NGMP: Enforce this on the service too
585585
if(!colorAvailable)
586586
return;
587587
}
588588

589-
slot->setColor(color);
589+
// NGMP: Dont set it locally / directly anymore, rely on the lobby service instead
590+
//slot->setColor(color);
590591

591-
if (TheGameSpyInfo->amIHost())
592-
{
593-
// send around a new slotlist
594-
TheGameSpyInfo->setGameOptions();
595-
WOLDisplaySlotList();
596-
}
597-
else
592+
// NGMP: Update lobby (if local, for remote players we'll get it from the service)
593+
if (index == myGame->getLocalSlotNum())
598594
{
599-
// request the color from the host
600-
if (!slot->isPlayer(TheGameSpyInfo->getLocalName()))
601-
return;
602-
603-
AsciiString options;
604-
options.format("Color=%d", color);
605-
AsciiString hostName;
606-
hostName.translate(myGame->getSlot(0)->getName());
607-
PeerRequest req;
608-
req.peerRequestType = PeerRequest::PEERREQUEST_UTMPLAYER;
609-
req.UTM.isStagingRoom = TRUE;
610-
req.id = "REQ/";
611-
req.nick = hostName.str();
612-
req.options = options.str();
613-
TheGameSpyPeerMessageQueue->addRequest(req);
595+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->UpdateCurrentLobby_MyColor(color);
614596
}
615597
}
616598
}
@@ -632,22 +614,33 @@ static void handlePlayerTemplateSelection(int index)
632614
Int oldTemplate = slot->getPlayerTemplate();
633615
slot->setPlayerTemplate(playerTemplate);
634616

617+
int updatedStartPos = slot->getStartPos();
618+
635619
if (oldTemplate == PLAYERTEMPLATE_OBSERVER)
636620
{
637621
// was observer, so populate color & team with all, and enable
638622
GadgetComboBoxSetSelectedPos(comboBoxColor[index], 0);
639623
GadgetComboBoxSetSelectedPos(comboBoxTeam[index], 0);
640624
slot->setStartPos(-1);
625+
updatedStartPos = -1;
641626
}
642627
else if (playerTemplate == PLAYERTEMPLATE_OBSERVER)
643628
{
644629
// is becoming observer, so populate color & team with random only, and disable
645630
GadgetComboBoxSetSelectedPos(comboBoxColor[index], 0);
646631
GadgetComboBoxSetSelectedPos(comboBoxTeam[index], 0);
647632
slot->setStartPos(-1);
633+
updatedStartPos = -1;
648634
}
649635

636+
// NGMP: Update lobby (if local, for remote players we'll get it from the service)
637+
if (index == myGame->getLocalSlotNum())
638+
{
639+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->UpdateCurrentLobby_MySide(playerTemplate, updatedStartPos);
640+
}
650641

642+
// NGMP: Dont set it locally / directly anymore, rely on the lobby service instead
643+
/*
651644
if (NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->IsHost())
652645
{
653646
// send around a new slotlist
@@ -675,16 +668,15 @@ static void handlePlayerTemplateSelection(int index)
675668
req.options = options.str();
676669
TheGameSpyPeerMessageQueue->addRequest(req);
677670
*/
671+
/*
678672
}
673+
*/
679674
}
680675
}
681676

682677

683678
static void handleStartPositionSelection(Int player, int startPos)
684679
{
685-
// TODO_NGMP
686-
return;
687-
688680
NGMPGame* myGame = NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->GetCurrentGame();
689681

690682
if (myGame)
@@ -715,34 +707,14 @@ static void handleStartPositionSelection(Int player, int startPos)
715707
if( !isAvailable )
716708
return;
717709
}
718-
slot->setStartPos(startPos);
719710

720-
if (myGame->amIHost())
721-
{
722-
// send around a new slotlist
723-
myGame->resetAccepted();
724-
TheGameSpyInfo->setGameOptions();
725-
WOLDisplaySlotList();
726-
}
727-
else
728-
{
729-
// request the color from the host
730-
if (AreSlotListUpdatesEnabled())
731-
{
732-
// request the playerTemplate from the host
733-
AsciiString options;
734-
options.format("StartPos=%d", slot->getStartPos());
735-
AsciiString hostName;
736-
hostName.translate(myGame->getSlot(0)->getName());
737-
PeerRequest req;
738-
req.peerRequestType = PeerRequest::PEERREQUEST_UTMPLAYER;
739-
req.UTM.isStagingRoom = TRUE;
740-
req.id = "REQ/";
741-
req.nick = hostName.str();
742-
req.options = options.str();
743-
TheGameSpyPeerMessageQueue->addRequest(req);
711+
// NGMP: Dont set it locally / directly anymore, rely on the lobby service instead
712+
//slot->setStartPos(startPos);
744713

745-
}
714+
// NGMP: Update lobby (if local, for remote players we'll get it from the service)
715+
if (player == myGame->getLocalSlotNum())
716+
{
717+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->UpdateCurrentLobby_MyStartPos(startPos);
746718
}
747719
}
748720
}
@@ -751,9 +723,6 @@ static void handleStartPositionSelection(Int player, int startPos)
751723

752724
static void handleTeamSelection(int index)
753725
{
754-
// TODO_NGMP
755-
return;
756-
757726
GameWindow *combo = comboBoxTeam[index];
758727
Int team, selIndex;
759728
GadgetComboBoxGetSelectedPos(combo, &selIndex);
@@ -767,29 +736,13 @@ static void handleTeamSelection(int index)
767736
if (team == slot->getTeamNumber())
768737
return;
769738

770-
slot->setTeamNumber(team);
739+
// NGMP: Dont set it locally / directly anymore, rely on the lobby service instead
740+
//slot->setTeamNumber(team);
771741

772-
if (TheGameSpyInfo->amIHost())
742+
// NGMP: Update lobby (if local, for remote players we'll get it from the service)
743+
if (index == myGame->getLocalSlotNum())
773744
{
774-
// send around a new slotlist
775-
myGame->resetAccepted();
776-
TheGameSpyInfo->setGameOptions();
777-
WOLDisplaySlotList();
778-
}
779-
else
780-
{
781-
// request the team from the host
782-
AsciiString options;
783-
options.format("Team=%d", team);
784-
AsciiString hostName;
785-
hostName.translate(myGame->getSlot(0)->getName());
786-
PeerRequest req;
787-
req.peerRequestType = PeerRequest::PEERREQUEST_UTMPLAYER;
788-
req.UTM.isStagingRoom = TRUE;
789-
req.id = "REQ/";
790-
req.nick = hostName.str();
791-
req.options = options.str();
792-
TheGameSpyPeerMessageQueue->addRequest(req);
745+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->UpdateCurrentLobby_MyTeam(team);
793746
}
794747
}
795748
}

GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void NGMPGame::SyncWithLobby(LobbyEntry& lobby)
6161
void NGMPGame::UpdateSlotsFromCurrentLobby()
6262
{
6363
// NOTE: Generals expects slot 0 to be host, this is hardcoded in places, EOS always returns the local player in index 0, so we need to correct this...
64-
bool bAddedFirstAI = false;
64+
//bool bAddedFirstAI = false;
6565
int realInsertPos = 1;
6666

6767
for (Int i = 0; i < MAX_SLOTS; ++i)
@@ -82,10 +82,10 @@ void NGMPGame::UpdateSlotsFromCurrentLobby()
8282
slot->setState(SLOT_PLAYER, str, 0);
8383

8484
// TODO_NGMP_URGENT: not yet impl, but being out of sync causes mismatch
85-
slot->setColor(5);
86-
slot->setTeamNumber(0);
87-
slot->setStartPos(0);
88-
slot->setPlayerTemplate(PLAYERTEMPLATE_RANDOM);
85+
slot->setColor(pLobbyMember.color);
86+
slot->setTeamNumber(pLobbyMember.team);
87+
slot->setStartPos(pLobbyMember.startpos);
88+
slot->setPlayerTemplate(pLobbyMember.side);
8989
}
9090
else
9191
{
@@ -96,10 +96,10 @@ void NGMPGame::UpdateSlotsFromCurrentLobby()
9696

9797

9898
// TODO_NGMP_URGENT: not yet impl, but being out of sync causes mismatch
99-
slot->setColor(5);
100-
slot->setTeamNumber(realInsertPos);
101-
slot->setStartPos(realInsertPos);
102-
slot->setPlayerTemplate(PLAYERTEMPLATE_RANDOM);
99+
slot->setColor(pLobbyMember.color);
100+
slot->setTeamNumber(pLobbyMember.team);
101+
slot->setStartPos(pLobbyMember.startpos);
102+
slot->setPlayerTemplate(pLobbyMember.side);
103103
++realInsertPos;
104104
// TODO_NGMP: Check player lists are synced across game with > 2 clients
105105
}
@@ -124,6 +124,7 @@ void NGMPGame::UpdateSlotsFromCurrentLobby()
124124
{
125125
// TODO_NGMP: Support AI slots
126126

127+
/*
127128
// set empty
128129
NGMPGameSlot* slot = (NGMPGameSlot*)getSlot(i);
129130
@@ -146,6 +147,7 @@ void NGMPGame::UpdateSlotsFromCurrentLobby()
146147
slot->setState(SLOT_OPEN);
147148
}
148149
}
150+
*/
149151
}
150152

151153
// dont need to handle else here, we set it up upon lobby creation

0 commit comments

Comments
 (0)