Skip to content

Commit 5fb71ef

Browse files
committed
- Per player chat color in lobby
- Better dev support for multi accounts
1 parent 7bee1d1 commit 5fb71ef

7 files changed

Lines changed: 75 additions & 29 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ class NGMP_OnlineServices_LobbyInterface
334334
m_OnCannotConnectToLobbyCallback = nullptr;
335335
}
336336

337-
std::function<void(UnicodeString strMessage, GameSpyColors color)> m_OnChatCallback = nullptr;
338-
void RegisterForChatCallback(std::function<void(UnicodeString strMessage, GameSpyColors color)> cb)
337+
std::function<void(UnicodeString strMessage, Color color)> m_OnChatCallback = nullptr;
338+
void RegisterForChatCallback(std::function<void(UnicodeString strMessage, Color color)> cb)
339339
{
340340
m_OnChatCallback = cb;
341341
}

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,50 @@
55
#include "../GameSpy/PeerDefs.h"
66
#include "OnlineServices_Init.h"
77

8+
extern Color PlayerSlotColors[MAX_SLOTS];
9+
810
enum class EChatMessageType
911
{
1012
CHAT_MESSAGE_TYPE_NETWORK_ROOM,
1113
CHAT_MESSAGE_TYPE_LOBBY
1214
};
13-
static GameSpyColors DetermineColorForChatMessage(EChatMessageType chatMessageType, Bool isPublic, Bool isAction)
15+
static Color DetermineColorForChatMessage(EChatMessageType chatMessageType, Bool isPublic, Bool isAction, int lobbySlot = -1)
1416
{
15-
GameSpyColors style;
17+
Color style;
1618

1719
// TODO_NGMP: Support owner chat again
1820
Bool isOwner = false;
1921

2022
if (isPublic && isAction)
2123
{
22-
style = (isOwner) ? GSCOLOR_CHAT_OWNER_EMOTE : GSCOLOR_CHAT_EMOTE;
24+
style = (isOwner) ? GameSpyColor[GSCOLOR_CHAT_OWNER_EMOTE] : GameSpyColor[GSCOLOR_CHAT_EMOTE];
2325
}
2426
else if (isPublic)
2527
{
26-
style = (isOwner) ? GSCOLOR_CHAT_OWNER : GSCOLOR_CHAT_NORMAL;
28+
// use lobby colors
29+
if (chatMessageType == EChatMessageType::CHAT_MESSAGE_TYPE_LOBBY)
30+
{
31+
if (lobbySlot == -1)
32+
{
33+
return GameMakeColor(255, 255, 255, 255);
34+
}
35+
else
36+
{
37+
style = PlayerSlotColors[lobbySlot];
38+
}
39+
}
40+
else
41+
{
42+
style = (isOwner) ? GameSpyColor[GSCOLOR_CHAT_OWNER] : GameSpyColor[GSCOLOR_CHAT_NORMAL];
43+
}
2744
}
2845
else if (isAction)
2946
{
30-
style = (isOwner) ? GSCOLOR_CHAT_PRIVATE_OWNER_EMOTE : GSCOLOR_CHAT_PRIVATE_EMOTE;
47+
style = (isOwner) ? GameSpyColor[GSCOLOR_CHAT_PRIVATE_OWNER_EMOTE] : GameSpyColor[GSCOLOR_CHAT_PRIVATE_EMOTE];
3148
}
3249
else
3350
{
34-
style = (isOwner) ? GSCOLOR_CHAT_PRIVATE_OWNER : GSCOLOR_CHAT_PRIVATE;
51+
style = (isOwner) ? GameSpyColor[GSCOLOR_CHAT_PRIVATE_OWNER] : GameSpyColor[GSCOLOR_CHAT_PRIVATE];
3552
}
3653

3754
// filters language
@@ -69,8 +86,8 @@ class NGMP_OnlineServices_RoomsInterface
6986
NGMP_OnlineServicesManager::GetInstance()->GetWebSocket()->SendData_LeaveNetworkRoom();
7087
}
7188

72-
std::function<void(UnicodeString strMessage, GameSpyColors color)> m_OnChatCallback = nullptr;
73-
void RegisterForChatCallback(std::function<void(UnicodeString strMessage, GameSpyColors color)> cb)
89+
std::function<void(UnicodeString strMessage, Color color)> m_OnChatCallback = nullptr;
90+
void RegisterForChatCallback(std::function<void(UnicodeString strMessage, Color color)> cb)
7491
{
7592
m_OnChatCallback = cb;
7693
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,11 +1387,11 @@ void InitWOLGameGadgets( void )
13871387

13881388
if (theGameInfo->getLocalSlotNum() != i)
13891389
{
1390-
GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch("GUI:Open"), GameSpyColor[GSCOLOR_PLAYER_NORMAL]);
1391-
GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch("GUI:Closed"), GameSpyColor[GSCOLOR_PLAYER_NORMAL]);
1392-
GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch("GUI:EasyAI"), GameSpyColor[GSCOLOR_PLAYER_NORMAL]);
1393-
GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch("GUI:MediumAI"), GameSpyColor[GSCOLOR_PLAYER_NORMAL]);
1394-
GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch("GUI:HardAI"), GameSpyColor[GSCOLOR_PLAYER_NORMAL]);
1390+
GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch("GUI:Open"), PlayerSlotColors[i]);
1391+
GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch("GUI:Closed"), PlayerSlotColors[i]);
1392+
GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch("GUI:EasyAI"), PlayerSlotColors[i]);
1393+
GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch("GUI:MediumAI"), PlayerSlotColors[i]);
1394+
GadgetComboBoxAddEntry(comboBoxPlayer[i], TheGameText->fetch("GUI:HardAI"), PlayerSlotColors[i]);
13951395
GadgetComboBoxSetSelectedPos(comboBoxPlayer[i], 0);
13961396
}
13971397
else
@@ -1400,7 +1400,7 @@ void InitWOLGameGadgets( void )
14001400
NGMPGameSlot* slot = theGameInfo->getGameSpySlot(i);
14011401
if (slot)
14021402
{
1403-
GadgetComboBoxAddEntry(comboBoxPlayer[i], slot->getName(), GameMakeColor(0, 162, 232, 255));
1403+
GadgetComboBoxAddEntry(comboBoxPlayer[i], slot->getName(), PlayerSlotColors[i]);
14041404
GadgetComboBoxSetSelectedPos(comboBoxPlayer[i], 0);
14051405
}
14061406
}
@@ -1528,9 +1528,9 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData )
15281528
buttonBuddy->winEnable(FALSE);
15291529

15301530
// register for chat events
1531-
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->RegisterForChatCallback([](UnicodeString strMessage, GameSpyColors color)
1531+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->RegisterForChatCallback([](UnicodeString strMessage, Color color)
15321532
{
1533-
GadgetListBoxAddEntryText(listboxGameSetupChat, strMessage, GameSpyColor[color], -1, -1);
1533+
GadgetListBoxAddEntryText(listboxGameSetupChat, strMessage, color, -1, -1);
15341534
});
15351535

15361536
// cannot connect to the lobby we joined

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,9 @@ void WOLLobbyMenuInit( WindowLayout *layout, void *userData )
10081008
// TODO_NGMP: player list change callbacks
10091009

10101010
// register for chat events
1011-
NGMP_OnlineServicesManager::GetInstance()->GetRoomsInterface()->RegisterForChatCallback([](UnicodeString strMessage, GameSpyColors color)
1011+
NGMP_OnlineServicesManager::GetInstance()->GetRoomsInterface()->RegisterForChatCallback([](UnicodeString strMessage, Color color)
10121012
{
1013-
GadgetListBoxAddEntryText(listboxLobbyChat, strMessage, GameSpyColor[color], -1, -1);
1013+
GadgetListBoxAddEntryText(listboxLobbyChat, strMessage, color, -1, -1);
10141014
});
10151015

10161016
// register for roster events

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
std::string m_strNetworkLogFileName;
1010
std::mutex m_logMutex;
1111

12+
Color PlayerSlotColors[MAX_SLOTS] =
13+
{
14+
GameMakeColor(0, 162, 232, 255),
15+
GameMakeColor(255, 0, 0, 255),
16+
GameMakeColor(0, 255, 0, 255),
17+
GameMakeColor(0, 0, 255, 255),
18+
GameMakeColor(255, 194, 15, 255),
19+
GameMakeColor(163, 73, 164, 255),
20+
GameMakeColor(230, 157, 181, 255),
21+
GameMakeColor(16, 82, 35, 255),
22+
};
23+
1224
std::string to_utf8(const std::wstring& wstr)
1325
{
1426
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414

1515
#pragma comment(lib, "Crypt32.lib")
1616

17-
#if _DEBUG
18-
#define CREDENTIALS_FILENAME "credentials_env_dev.json"
19-
#elif defined(USE_TEST_ENV)
17+
#if defined(USE_TEST_ENV)
2018
#define CREDENTIALS_FILENAME "credentials_env_test.json"
21-
#else
19+
#elseif !DEBUG
2220
#define CREDENTIALS_FILENAME "credentials.json"
2321
#endif
2422

2523
#include "GameNetwork/GeneralsOnline/vendor/libcurl/curl.h"
24+
#include "GameClient/ClientInstance.h"
2625

2726
enum class EAuthResponseResult : int
2827
{
@@ -455,6 +454,11 @@ bool NGMP_OnlineServices_AuthInterface::GetCredentials(std::string& strRefreshTo
455454

456455
std::string NGMP_OnlineServices_AuthInterface::GetCredentialsFilePath()
457456
{
458-
std::string strPatcherDirPath = std::format("{}/GeneralsOnlineData/{}", TheGlobalData->getPath_UserData().str(), CREDENTIALS_FILENAME);
459-
return strPatcherDirPath;
457+
// debug supports multi inst, so needs seperate tokens
458+
#if _DEBUG
459+
std::string strCredsPath = std::format("{}/GeneralsOnlineData/credentials_dev_env_{}.json", TheGlobalData->getPath_UserData().str(), rts::ClientInstance::getInstanceIndex());
460+
#else
461+
std::string strCredsPath = std::format("{}/GeneralsOnlineData/{}", TheGlobalData->getPath_UserData().str(), CREDENTIALS_FILENAME);
462+
#endif
463+
return strCredsPath;
460464
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ class WebSocketMessage_LobbyChatIncoming : public WebSocketMessageBase
191191
bool action;
192192
bool announcement;
193193
bool show_announcement_to_host;
194+
int64_t user_id;
194195

195-
NLOHMANN_DEFINE_TYPE_INTRUSIVE(WebSocketMessage_LobbyChatIncoming, msg_id, message, action, announcement, show_announcement_to_host)
196+
NLOHMANN_DEFINE_TYPE_INTRUSIVE(WebSocketMessage_LobbyChatIncoming, msg_id, message, action, announcement, show_announcement_to_host, user_id)
196197
};
197198

198199
class WebSocketMessage_RelayUpgrade : public WebSocketMessageBase
@@ -309,7 +310,7 @@ void WebSocket::Tick()
309310

310311
UnicodeString unicodeStr(from_utf8(chatData.message).c_str());
311312

312-
GameSpyColors color = DetermineColorForChatMessage(EChatMessageType::CHAT_MESSAGE_TYPE_NETWORK_ROOM, true, chatData.action);
313+
Color color = DetermineColorForChatMessage(EChatMessageType::CHAT_MESSAGE_TYPE_NETWORK_ROOM, true, chatData.action);
313314

314315
if (NGMP_OnlineServicesManager::GetInstance()->GetRoomsInterface()->m_OnChatCallback != nullptr)
315316
{
@@ -341,7 +342,19 @@ void WebSocket::Tick()
341342
WebSocketMessage_LobbyChatIncoming chatData = jsonObject.get<WebSocketMessage_LobbyChatIncoming>();
342343

343344
UnicodeString unicodeStr(from_utf8(chatData.message).c_str());
344-
GameSpyColors color = DetermineColorForChatMessage(EChatMessageType::CHAT_MESSAGE_TYPE_LOBBY, true, chatData.action);
345+
346+
int lobbySlot = -1;
347+
auto lobbyMembers = NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->GetMembersListForCurrentRoom();
348+
for (const auto& lobbyMember : lobbyMembers)
349+
{
350+
if (lobbyMember.user_id == chatData.user_id)
351+
{
352+
lobbySlot = lobbyMember.m_SlotIndex;
353+
break;
354+
}
355+
}
356+
357+
Color color = DetermineColorForChatMessage(EChatMessageType::CHAT_MESSAGE_TYPE_LOBBY, true, chatData.action, lobbySlot);
345358

346359
if (NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->m_OnChatCallback != nullptr)
347360
{

0 commit comments

Comments
 (0)