Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GeneralsMD/Code/GameEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ set(GAMEENGINE_SRC
# Source/GameNetwork/GameSpy/Thread/ThreadUtils.cpp
# Source/GameNetwork/GameSpyOverlay.cpp
Source/GameNetwork/GUIUtil.cpp
Source/GameNetwork/RandomAssign.cpp
# Source/GameNetwork/IPEnumeration.cpp
# Source/GameNetwork/LANAPI.cpp
# Source/GameNetwork/LANAPICallbacks.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class NGMP_OnlineServices_LobbyInterface
void UpdateCurrentLobby_AITeam(int slot, int team);
void UpdateCurrentLobby_AIStartPos(int slot, int startpos);

void UpdateCurrentLobby_BulkSlotUpdate(NGMPGame* game);

void UpdateCurrentLobbyMaxCameraHeight(uint16_t maxCameraHeight);

void SetJoinability(ELobbyJoinability joinabilityFlag);
Expand Down
8 changes: 8 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/GameNetwork/RandomAssign.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

class GameInfo;

#include <vector>

void performRandomAssign(GameInfo *game, const std::vector<Int> &lockedTemplates);
std::vector<Int> buildLockedTemplates();
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "Common/MultiplayerSettings.h"
#include "GameClient/GameText.h"
#include "GameNetwork/GUIUtil.h"
#include "GameNetwork/RandomAssign.h"


extern char *LANnextScreen;
Expand Down Expand Up @@ -110,6 +111,7 @@ static NameKeyType textEntryChatID = NAMEKEY_INVALID;
static NameKeyType textEntryMapDisplayID = NAMEKEY_INVALID;
static NameKeyType buttonBackID = NAMEKEY_INVALID;
static NameKeyType buttonStartID = NAMEKEY_INVALID;
static NameKeyType buttonRandomizeID = NAMEKEY_INVALID;
static NameKeyType buttonEmoteID = NAMEKEY_INVALID;
static NameKeyType buttonSelectMapID = NAMEKEY_INVALID;
static NameKeyType checkboxLimitSuperweaponsID = NAMEKEY_INVALID;
Expand All @@ -119,6 +121,7 @@ static NameKeyType windowMapID = NAMEKEY_INVALID;
static GameWindow *parentLanGameOptions = nullptr;
static GameWindow *buttonBack = nullptr;
static GameWindow *buttonStart = nullptr;
static GameWindow *buttonRandomize = nullptr;
static GameWindow *buttonSelectMap = nullptr;
static GameWindow *buttonEmote = nullptr;
static GameWindow *textEntryChat = nullptr;
Expand Down Expand Up @@ -674,6 +677,7 @@ void InitLanGameGadgets()
parentLanGameOptionsID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:LanGameOptionsMenuParent" );
buttonBackID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonBack" );
buttonStartID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonStart" );
buttonRandomizeID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ButtonRandomize" );
textEntryChatID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:TextEntryChat" );
textEntryMapDisplayID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:TextEntryMapDisplay" );
listboxChatWindowLanGameID = TheNameKeyGenerator->nameToKey( "LanGameOptionsMenu.wnd:ListboxChatWindowLanGame" );
Expand All @@ -692,6 +696,8 @@ void InitLanGameGadgets()
DEBUG_ASSERTCRASH(buttonSelectMap, ("Could not find the buttonSelectMap"));
buttonStart = TheWindowManager->winGetWindowFromId( parentLanGameOptions,buttonStartID );
DEBUG_ASSERTCRASH(buttonStart, ("Could not find the buttonStart"));
buttonRandomize = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonRandomizeID );
DEBUG_ASSERTCRASH(buttonRandomize, ("Could not find the buttonRandomize"));
buttonBack = TheWindowManager->winGetWindowFromId( parentLanGameOptions, buttonBackID);
DEBUG_ASSERTCRASH(buttonBack, ("Could not find the buttonBack"));
listboxChatWindowLanGame = TheWindowManager->winGetWindowFromId( parentLanGameOptions, listboxChatWindowLanGameID );
Expand Down Expand Up @@ -795,6 +801,7 @@ void DeinitLanGameGadgets()
buttonSelectMap = nullptr;
buttonStart = nullptr;
buttonBack = nullptr;
buttonRandomize = nullptr;
listboxChatWindowLanGame = nullptr;
textEntryChat = nullptr;
textEntryMapDisplay = nullptr;
Expand Down Expand Up @@ -885,6 +892,7 @@ void LanGameOptionsMenuInit( WindowLayout *layout, void *userData )
//DEBUG_LOG(("LanGameOptionsMenuInit(): map is %s", TheLAN->GetMyGame()->getMap().str()));
buttonStart->winSetText(TheGameText->fetch("GUI:Accept"));
buttonSelectMap->winEnable( FALSE );
buttonRandomize->winEnable( FALSE );
checkboxLimitSuperweapons->winEnable( FALSE ); // Can look but only host can touch
comboBoxStartingCash->winEnable( FALSE ); // Ditto
TheLAN->GetMyGame()->setMapCRC( TheLAN->GetMyGame()->getMapCRC() ); // force a recheck
Expand Down Expand Up @@ -1275,6 +1283,16 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m

}
}
else if ( controlID == buttonRandomizeID )
{
if (TheLAN->AmIHost())
{
std::vector<Int> lockedTemplates = buildLockedTemplates();
performRandomAssign(TheLAN->GetMyGame(), lockedTemplates);
TheLAN->RequestGameOptions(GenerateGameOptionsString(), true);
lanUpdateSlotList();
}
}
else if ( controlID == checkboxLimitSuperweaponsID )
{
handleLimitSuperweaponsClick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
#include "GameNetwork/GameSpy/GSConfig.h"

#include "GameNetwork/GeneralsOnline/NGMP_interfaces.h"
#include "GameNetwork/RandomAssign.h"
#include "GameClient/ChallengeGenerals.h"
#include <ws2ipdef.h>
#include <format>
#include "../OnlineServices_Init.h"
Expand Down Expand Up @@ -201,6 +203,7 @@ static NameKeyType buttonBackID = NAMEKEY_INVALID;
static NameKeyType buttonStartID = NAMEKEY_INVALID;
static NameKeyType buttonEmoteID = NAMEKEY_INVALID;
static NameKeyType buttonSelectMapID = NAMEKEY_INVALID;
static NameKeyType buttonRandomizeID = NAMEKEY_INVALID;
static NameKeyType windowMapID = NAMEKEY_INVALID;

#if defined(GENERALS_ONLINE_ENABLE_MATCH_START_COUNTDOWN)
Expand All @@ -218,6 +221,7 @@ static GameWindow *parentWOLGameSetup = NULL;
static GameWindow *buttonBack = NULL;
static GameWindow *buttonStart = NULL;
static GameWindow *buttonSelectMap = NULL;
static GameWindow *buttonRandomize = NULL;
static GameWindow *buttonEmote = NULL;
static GameWindow *textEntryChat = NULL;
static GameWindow *textEntryMapDisplay = NULL;
Expand Down Expand Up @@ -1470,6 +1474,7 @@ void InitWOLGameGadgets()
listboxGameSetupChatID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:ListboxChatWindowGameSpyGameSetup" );
buttonEmoteID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:ButtonEmote" );
buttonSelectMapID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:ButtonSelectMap" );
buttonRandomizeID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:ButtonRandomize" );
checkBoxUseStatsID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:CheckBoxUseStats" );
windowMapID = TheNameKeyGenerator->nameToKey( "GameSpyGameOptionsMenu.wnd:MapWindow" );
checkBoxLimitSuperweaponsID = TheNameKeyGenerator->nameToKey("GameSpyGameOptionsMenu.wnd:CheckboxLimitSuperweapons");
Expand All @@ -1483,6 +1488,8 @@ void InitWOLGameGadgets()
parentWOLGameSetup = TheWindowManager->winGetWindowFromId( NULL, parentWOLGameSetupID );
buttonEmote = TheWindowManager->winGetWindowFromId( parentWOLGameSetup,buttonEmoteID );
buttonSelectMap = TheWindowManager->winGetWindowFromId( parentWOLGameSetup,buttonSelectMapID );
buttonRandomize = TheWindowManager->winGetWindowFromId( parentWOLGameSetup, buttonRandomizeID );
DEBUG_ASSERTCRASH(buttonRandomize, ("Could not find the buttonRandomize"));
checkBoxUseStats = TheWindowManager->winGetWindowFromId( parentWOLGameSetup, checkBoxUseStatsID );
buttonStart = TheWindowManager->winGetWindowFromId( parentWOLGameSetup,buttonStartID );
buttonBack = TheWindowManager->winGetWindowFromId( parentWOLGameSetup, buttonBackID);
Expand Down Expand Up @@ -1528,6 +1535,7 @@ void InitWOLGameGadgets()
{
checkBoxLimitSuperweapons->winEnable( false );
comboBoxStartingCash->winEnable( false );
buttonRandomize->winEnable( false );
NameKeyType labelID = TheNameKeyGenerator->nameToKey("GameSpyGameOptionsMenu.wnd:StartingCashLabel");
TheWindowManager->winGetWindowFromId(parentWOLGameSetup, labelID)->winEnable( FALSE );
}
Expand All @@ -1536,6 +1544,7 @@ void InitWOLGameGadgets()
{
checkBoxLimitSuperweapons->winEnable(true);
comboBoxStartingCash->winEnable(true);
buttonRandomize->winEnable(true);
}
#endif

Expand All @@ -1548,6 +1557,7 @@ void InitWOLGameGadgets()
checkBoxLimitSuperweapons->winEnable( FALSE );
comboBoxStartingCash->winEnable( FALSE );
checkBoxLimitArmies->winEnable( FALSE );
buttonRandomize->winEnable( FALSE );
NameKeyType labelID = TheNameKeyGenerator->nameToKey("GameSpyGameOptionsMenu.wnd:StartingCashLabel");
TheWindowManager->winGetWindowFromId(parentWOLGameSetup, labelID)->winEnable( FALSE );
}
Expand Down Expand Up @@ -1688,6 +1698,7 @@ void DeinitWOLGameGadgets()
parentWOLGameSetup = NULL;
buttonEmote = NULL;
buttonSelectMap = NULL;
buttonRandomize = NULL;
buttonStart = NULL;
buttonBack = NULL;
listboxGameSetupChat = NULL;
Expand Down Expand Up @@ -2085,6 +2096,7 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData )
buttonStart->winSetText(TheGameText->fetch("GUI:Accept"));
buttonStart->winEnable( FALSE );
buttonSelectMap->winEnable( FALSE );
buttonRandomize->winEnable( FALSE );
initialAcceptEnable = FALSE;

WOLDisplaySlotList();
Expand Down Expand Up @@ -2356,6 +2368,7 @@ void WOLGameSetupMenuUpdate( WindowLayout * layout, void *userData)
buttonStart->winSetText(TheGameText->fetch("GUI:Start"));
buttonStart->winEnable(TRUE);
buttonSelectMap->winEnable(TRUE);
buttonRandomize->winEnable(TRUE);
initialAcceptEnable = TRUE;

comboBoxStartingCash->winEnable(TRUE);
Expand Down Expand Up @@ -3942,6 +3955,21 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msg
WOLMapSelectLayout->hide( FALSE );
WOLMapSelectLayout->bringForward();
}
else if ( controlID == buttonRandomizeID )
{
NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_LobbyInterface>();
if (pLobbyInterface != nullptr && pLobbyInterface->IsHost())
{
NGMPGame* game = pLobbyInterface->GetCurrentGame();
if (game)
{
std::vector<Int> lockedTemplates = buildLockedTemplates();
performRandomAssign(game, lockedTemplates);
pLobbyInterface->UpdateCurrentLobby_BulkSlotUpdate(game);
WOLDisplaySlotList();
}
}
}
else if ( controlID == buttonStartID )
{
savePlayerInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ enum class ELobbyUpdateField
AI_TEAM = 15,
AI_START_POS = 16,
MAX_CAMERA_HEIGHT = 17,
JOINABILITY = 18
JOINABILITY = 18,
HOST_ACTION_BULK_SLOT_UPDATE = 19
};

void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_Map(AsciiString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers)
Expand Down Expand Up @@ -468,6 +469,45 @@ void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_ForceReady()
});
}

void NGMP_OnlineServices_LobbyInterface::UpdateCurrentLobby_BulkSlotUpdate(NGMPGame* game)
{
ClearAutoReadyCountdown();
if (TheNGMPGame && TheNGMPGame->IsCountdownStarted())
TheNGMPGame->StopCountdown();

std::string strURI = std::format("{}/{}", NGMP_OnlineServicesManager::GetAPIEndpoint("Lobby"), m_CurrentLobby.lobbyID);
std::map<std::string, std::string> mapHeaders;

nlohmann::json j;
j["field"] = ELobbyUpdateField::HOST_ACTION_BULK_SLOT_UPDATE;

nlohmann::json slotsArray = nlohmann::json::array();
for (int i = 0; i < MAX_SLOTS; ++i)
{
const GameSlot *slot = game->getConstSlot(i);
if (slot && slot->isOccupied())
{
nlohmann::json slotEntry;
slotEntry["slot_index"] = i;
slotEntry["side"] = slot->getPlayerTemplate();
slotEntry["color"] = slot->getColor();
slotEntry["start_pos"] = slot->getStartPos();
slotEntry["team"] = slot->getTeamNumber();
slotsArray.push_back(slotEntry);
}
}
j["slots"] = slotsArray;
std::string strPostData = j.dump();

NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPOSTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq)
{
if (!bSuccess || statusCode < 200 || statusCode >= 300)
{
DEBUG_LOG(("UpdateCurrentLobby_BulkSlotUpdate failed: success=%d, status=%d", bSuccess, statusCode));
}
});
}

void NGMP_OnlineServices_LobbyInterface::SendChatMessageToCurrentLobby(UnicodeString& strChatMsgUnicode, bool bIsAction)
{
std::shared_ptr<WebSocket> pWS = NGMP_OnlineServicesManager::GetWebSocket();;
Expand Down
Loading
Loading