Skip to content

Commit a2ee974

Browse files
committed
Added lobby commands /setpassword and /removepassword
1 parent 110f425 commit a2ee974

5 files changed

Lines changed: 102 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
//#define USE_PORT_MAPPER 1
88

9+
#define GENERALS_ONLINE_LOBBY_MAX_PASSWORD_LENGTH 16
10+
911
#if !defined(_DEBUG)
1012
//#define USE_TEST_ENV 1
1113
#endif

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ enum EWebSocketMessageID
5151
MATCHMAKING_ACTION_JOIN_PREARRANGED_LOBBY = 20,
5252
MATCHMAKING_ACTION_START_GAME = 21,
5353
MATCHMAKING_MESSAGE = 22,
54-
START_GAME_COUNTDOWN_STARTED = 23
54+
START_GAME_COUNTDOWN_STARTED = 23,
55+
LOBBY_REMOVE_PASSWORD = 24,
56+
LOBBY_CHANGE_PASSWORD = 25
5557
};
5658

5759
enum class EQoSRegions
@@ -168,6 +170,10 @@ class WebSocket
168170
void SendData_Signalling(int64_t targetUserID, std::vector<uint8_t> vecPayload);
169171
void SendData_StartGame();
170172

173+
void SendData_ChangeLobbyPassword(UnicodeString& strNewPassword);
174+
void SendData_RemoveLobbyPassword();
175+
176+
171177
void SendData_CountdownStarted();
172178

173179
void Tick();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void PopupHostGameInit( WindowLayout *layout, void *userData )
402402
// hide password for streams
403403
EntryData* e = (EntryData*)textEntryGamePassword->winGetUserData();
404404
e->secretText = true;
405-
e->maxTextLen = 16;
405+
e->maxTextLen = GENERALS_ONLINE_LOBBY_MAX_PASSWORD_LENGTH;
406406
#endif
407407

408408
}

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,78 @@ Bool handleGameSetupSlashCommands(UnicodeString uText)
33533353

33543354
return TRUE;
33553355
}
3356+
else if (token == "setpassword" && uText.getLength() > 13)
3357+
{
3358+
UnicodeString newPassword(uText.str() + 13); // skip the /setpassword and space
3359+
3360+
NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_LobbyInterface>();
3361+
NGMP_OnlineServices_AuthInterface* pAuthInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_AuthInterface>();
3362+
if (pLobbyInterface != nullptr && pAuthInterface != nullptr)
3363+
{
3364+
LobbyEntry& theLobby = pLobbyInterface->GetCurrentLobby();
3365+
3366+
// This is just done clientside to show an error message, server validates it also
3367+
if (theLobby.owner == pAuthInterface->GetUserID())
3368+
{
3369+
if (newPassword.getLength() == 0 || newPassword.getLength() > GENERALS_ONLINE_LOBBY_MAX_PASSWORD_LENGTH)
3370+
{
3371+
UnicodeString errorMsg;
3372+
errorMsg.format(L"The new password must be between 1 and %d characters.", GENERALS_ONLINE_LOBBY_MAX_PASSWORD_LENGTH);
3373+
GadgetListBoxAddEntryText(listboxGameSetupChat, errorMsg, GameMakeColor(255, 0, 0, 255), -1, -1);
3374+
}
3375+
else
3376+
{
3377+
WebSocket* pWS = NGMP_OnlineServicesManager::GetWebSocket();
3378+
if (pWS != nullptr)
3379+
{
3380+
pWS->SendData_ChangeLobbyPassword(newPassword);
3381+
3382+
GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"The lobby password has been updated. You can remove the password by using /removepassword"), GameMakeColor(0, 255, 0, 255), -1, -1);
3383+
}
3384+
}
3385+
}
3386+
else
3387+
{
3388+
GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"You are not the lobby owner."), GameMakeColor(255, 0, 0, 255), -1, -1);
3389+
}
3390+
}
3391+
3392+
return TRUE; // was a slash command
3393+
}
3394+
else if (token == "removepassword" || token == "clearpassword" || token == "resetpassword")
3395+
{
3396+
NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_LobbyInterface>();
3397+
NGMP_OnlineServices_AuthInterface* pAuthInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_AuthInterface>();
3398+
if (pLobbyInterface != nullptr && pAuthInterface != nullptr)
3399+
{
3400+
LobbyEntry& theLobby = pLobbyInterface->GetCurrentLobby();
3401+
3402+
// This is just done clientside to show an error message, server validates it also
3403+
if (theLobby.owner == pAuthInterface->GetUserID())
3404+
{
3405+
if (theLobby.passworded)
3406+
{
3407+
WebSocket* pWS = NGMP_OnlineServicesManager::GetWebSocket();
3408+
if (pWS != nullptr)
3409+
{
3410+
pWS->SendData_RemoveLobbyPassword();
3411+
3412+
GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"The lobby password has been removed. You can set a password using /setpassword <password>"), GameMakeColor(0, 255, 0, 255), -1, -1);
3413+
}
3414+
}
3415+
else
3416+
{
3417+
GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"The lobby is not passworded. You can set a password using /setpassword <password>"), GameMakeColor(255, 0, 0, 255), -1, -1);
3418+
}
3419+
}
3420+
else
3421+
{
3422+
GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"You are not the lobby owner."), GameMakeColor(255, 0, 0, 255), -1, -1);
3423+
}
3424+
}
3425+
3426+
return TRUE; // was a slash command
3427+
}
33563428
else if (token == "connections" || token == "conns" || token == "c")
33573429
{
33583430
// TODO_NGMP: Disable this on retail builds

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,26 @@ void WebSocket::Shutdown()
605605
Disconnect();
606606
}
607607

608+
void WebSocket::SendData_ChangeLobbyPassword(UnicodeString& strNewPassword)
609+
{
610+
nlohmann::json j;
611+
j["msg_id"] = EWebSocketMessageID::LOBBY_CHANGE_PASSWORD;
612+
j["new_password"] = to_utf8(strNewPassword.str());
613+
std::string strBody = j.dump();
614+
615+
Send(strBody.c_str());
616+
}
617+
618+
619+
void WebSocket::SendData_RemoveLobbyPassword()
620+
{
621+
nlohmann::json j;
622+
j["msg_id"] = EWebSocketMessageID::LOBBY_REMOVE_PASSWORD;
623+
std::string strBody = j.dump();
624+
625+
Send(strBody.c_str());
626+
}
627+
608628
void WebSocket::SendData_ChangeName(UnicodeString& strNewName)
609629
{
610630
nlohmann::json j;
@@ -663,7 +683,6 @@ void WebSocket::SendData_StartGame()
663683
Send(strBody.c_str());
664684
}
665685

666-
667686
void WebSocket::SendData_CountdownStarted()
668687
{
669688
nlohmann::json j;

0 commit comments

Comments
 (0)