Skip to content

Commit d6d4178

Browse files
committed
hooked up motd and tooltips
1 parent 27507d8 commit d6d4178

10 files changed

Lines changed: 150 additions & 29 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ enum ENetworkMeshType : uint8_t
1717
class NetworkMemberBase
1818
{
1919
public:
20-
AsciiString m_strName = "NO_NAME";
20+
int64_t user_id = -1;
21+
std::string display_name;
22+
2123
ENetworkConnectionState m_connectionState = ENetworkConnectionState::NOT_CONNECTED;
2224
bool m_bIsHost = false;
2325

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ class NetworkMesh
9292
return m_mapConnections;
9393
}
9494

95+
PlayerConnection* GetConnectionForUser(int64_t user_id)
96+
{
97+
if (m_mapConnections.contains(user_id))
98+
{
99+
return &m_mapConnections[user_id];
100+
}
101+
102+
return nullptr;
103+
}
104+
95105
private:
96106
PlayerConnection* GetConnectionForPeer(ENetPeer* peer)
97107
{

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ class NGMP_OnlineServicesManager
165165
return m_vecRooms;
166166
}
167167

168+
void ProcessMOTD(const char* szMOTD)
169+
{
170+
m_strMOTD = std::string(szMOTD);
171+
}
172+
168173
std::function<void(NGMP_ENATType previousNATType, NGMP_ENATType newNATType)> m_cbNATTypeChanged = nullptr;
169174
void RegisterForNATTypeChanges(std::function<void(NGMP_ENATType previousNATType, NGMP_ENATType newNATType)> cbNATTypeChanged) { m_cbNATTypeChanged = cbNATTypeChanged; }
170175

@@ -201,6 +206,8 @@ class NGMP_OnlineServicesManager
201206
return AsciiString("Undetermined");
202207
}
203208

209+
std::string& GetMOTD() { return m_strMOTD; }
210+
204211
private:
205212
//EOS_HPlatform m_EOSPlatformHandle = nullptr;
206213

@@ -225,4 +232,6 @@ class NGMP_OnlineServicesManager
225232
int64_t m_timeBetweenUserPuts = 60000;
226233

227234
WebSocket* m_pWebSocket = nullptr;
235+
236+
std::string m_strMOTD;
228237
};

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

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

88
struct LobbyMemberEntry : public NetworkMemberBase
99
{
10-
int64_t user_id = -1;
11-
std::string display_name;
1210

1311
std::string strIPAddress;
1412
uint16_t preferredPort;

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,19 @@ class NGMP_OnlineServices_RoomsInterface
4141
m_RosterNeedsRefreshCallback = cb;
4242
}
4343

44-
NetworkRoomMember* GetRoomMemberFromID(uint64_t puid)
44+
NetworkRoomMember* GetRoomMemberFromIndex(int index)
45+
{
46+
if (m_mapMembers.size() > index)
47+
{
48+
auto it = m_mapMembers.begin();
49+
std::advance(it, index);
50+
return &it->second;
51+
}
52+
53+
return nullptr;
54+
}
55+
56+
NetworkRoomMember* GetRoomMemberFromID(int64_t puid)
4557
{
4658
if (m_mapMembers.contains(puid))
4759
{
@@ -78,7 +90,7 @@ class NGMP_OnlineServices_RoomsInterface
7890
}
7991
}
8092

81-
void OnRosterUpdated(std::vector<std::string> vecUsers);
93+
void OnRosterUpdated(std::vector<std::string> vecUsers, std::vector<int64_t> vecIDs);
8294

8395
int GetCurrentRoomID() const { return m_CurrentRoomID; }
8496

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
#include "GameNetwork/GeneralsOnline/NGMP_interfaces.h"
6969
#include <ws2ipdef.h>
70+
#include <format>
7071
NGMPGame* TheNGMPGame = NULL;
7172

7273
void WOLDisplaySlotList( void );
@@ -1109,9 +1110,26 @@ void WOLDisplaySlotList( void )
11091110
{
11101111
if (i == game->getLocalSlotNum())
11111112
{
1112-
// set up my own ping...
1113-
slot->setPingString("TODO_NGMP");
1114-
//slot->setPingString(TheGameSpyInfo->getPingString());
1113+
LobbyMemberEntry member = NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->GetRoomMemberFromID(slot->m_userID);
1114+
PlayerConnection* pConnection = NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->GetNetworkMesh()->GetConnectionForUser(slot->m_userID);
1115+
1116+
std::string strPingString = "";
1117+
std::string strConnectionState = "Not Connected";
1118+
int latency = -1;
1119+
if (pConnection != nullptr)
1120+
{
1121+
strConnectionState = "Connected";
1122+
latency = pConnection->latency;
1123+
1124+
}
1125+
1126+
strPingString = std::format("Display Name: {}\nUser ID: {}\nConnection Type: {}\nLatency: {}",
1127+
member.display_name.c_str(),
1128+
member.user_id,
1129+
strConnectionState.c_str(),
1130+
latency);
1131+
1132+
slot->setPingString(strPingString.c_str());
11151133
}
11161134

11171135
if (genericPingWindow[i])

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ static void playerTooltip(GameWindow *window,
234234
UnsignedInt mouse)
235235
{
236236
// TODO_NGMP: Support all of this again
237-
TheMouse->setCursorTooltip(UnicodeString(L"TODO_NGMP"), -1, NULL, 1.5f); // the text and width are the only params used. the others are the default values.
238-
return;
239237

240238
Int x, y, row, col;
241239
x = LOLONGTOSHORT(mouse);
@@ -245,14 +243,40 @@ static void playerTooltip(GameWindow *window,
245243

246244
if (row == -1 || col == -1)
247245
{
248-
TheMouse->setCursorTooltip( UnicodeString::TheEmptyString);//TheGameText->fetch("TOOLTIP:PlayersInLobby") );
246+
TheMouse->setCursorTooltip(UnicodeString::TheEmptyString);//TheGameText->fetch("TOOLTIP:PlayersInLobby") );
249247
return;
250248
}
251249

252250
UnicodeString uName = GadgetListBoxGetText(window, row, COLUMN_PLAYERNAME);
253251
AsciiString aName;
254252
aName.translate(uName);
255253

254+
NetworkRoomMember* pRoomMember = NGMP_OnlineServicesManager::GetInstance()->GetRoomsInterface()->GetRoomMemberFromIndex(row);
255+
256+
if (col > 0)
257+
{
258+
if (pRoomMember != nullptr)
259+
{
260+
std::string strTooltip = std::format("Display Name: {}\nUser ID: {}", pRoomMember->display_name.c_str(), pRoomMember->user_id);
261+
262+
UnicodeString ucTooltip;
263+
ucTooltip.translate(strTooltip.c_str());
264+
265+
TheMouse->setCursorTooltip(ucTooltip, -1, NULL, 1.5f); // the text and width are the only params used. the others are the default values.
266+
}
267+
else
268+
{
269+
TheMouse->setCursorTooltip(UnicodeString(L"Error: 1"), -1, NULL, 1.5f); // the text and width are the only params used. the others are the default values.
270+
}
271+
272+
273+
274+
}
275+
276+
277+
return;
278+
279+
256280
PlayerInfoMap::iterator it = TheGameSpyInfo->getPlayerInfoMap()->find(aName);
257281
PlayerInfo *info = &(it->second);
258282
Bool isLocalPlayer = (TheGameSpyInfo->getLocalName().compareNoCase(info->m_name) == 0);
@@ -524,7 +548,7 @@ void PopulateLobbyPlayerListbox(void)
524548

525549
// TODO_NGMP: fill out more
526550
PlayerInfo pi;
527-
pi.m_name = netRoomMember.m_strName;
551+
pi.m_name = AsciiString(netRoomMember.display_name.c_str());
528552

529553
// NGMP: Color by connection state
530554

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static void updateNumPlayersOnline(void)
252252
UnicodeString line;
253253

254254
#if defined(GENERALS_ONLINE)
255-
AsciiString aMotd = "TODO MOTD GOES HERE";
255+
AsciiString aMotd = AsciiString(NGMP_OnlineServicesManager::GetInstance()->GetMOTD().c_str());
256256
#else
257257
AsciiString aMotd = TheGameSpyInfo->getMOTD();
258258
#endif

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

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <windows.h>
1111
#include <wincred.h>
1212
#include "GameNetwork/GameSpyOverlay.h"
13+
#include "../json.hpp"
1314

1415

1516
#include "GameNetwork/GeneralsOnline/vendor/libcurl/curl.h"
@@ -294,6 +295,13 @@ void NGMP_OnlineServices_AuthInterface::Tick()
294295
}
295296
}
296297

298+
struct MOTDResponse
299+
{
300+
std::string MOTD;
301+
302+
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MOTDResponse, MOTD)
303+
};
304+
297305
void NGMP_OnlineServices_AuthInterface::OnLoginComplete(bool bSuccess, const char* szWSAddr, const char* szWSToken)
298306
{
299307
if (bSuccess)
@@ -307,14 +315,49 @@ void NGMP_OnlineServices_AuthInterface::OnLoginComplete(bool bSuccess, const cha
307315
// NOTE: This is partially blocking and partially async...
308316
NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().DetermineLocalNetworkCapabilities([this]()
309317
{
310-
ClearGSMessageBoxes();
318+
// GET MOTD
311319

312-
for (auto cb : m_vecLogin_PendingCallbacks)
313-
{
314-
// TODO_NGMP: Support failure
315-
cb(true);
316-
}
317-
m_vecLogin_PendingCallbacks.clear();
320+
std::string strURI = NGMP_OnlineServicesManager::GetAPIEndpoint("MOTD", true);
321+
std::map<std::string, std::string> mapHeaders;
322+
NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendGETRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, [=](bool bSuccess, int statusCode, std::string strBody)
323+
{
324+
try
325+
{
326+
nlohmann::json jsonObject = nlohmann::json::parse(strBody);
327+
MOTDResponse motdResp = jsonObject.get<MOTDResponse>();
328+
329+
330+
NGMP_OnlineServicesManager::GetInstance()->ProcessMOTD(motdResp.MOTD.c_str());
331+
332+
// go to next screen
333+
ClearGSMessageBoxes();
334+
335+
for (auto cb : m_vecLogin_PendingCallbacks)
336+
{
337+
// TODO_NGMP: Support failure
338+
cb(true);
339+
}
340+
m_vecLogin_PendingCallbacks.clear();
341+
342+
}
343+
catch (...)
344+
{
345+
NetworkLog("VERSION CHECK: Failed to parse response");
346+
347+
// if MOTD was bad, still proceed, its a soft error
348+
NGMP_OnlineServicesManager::GetInstance()->ProcessMOTD("Error retrieving MOTD");
349+
350+
// go to next screen
351+
ClearGSMessageBoxes();
352+
353+
for (auto cb : m_vecLogin_PendingCallbacks)
354+
{
355+
// TODO_NGMP: Support failure
356+
cb(true);
357+
}
358+
m_vecLogin_PendingCallbacks.clear();
359+
}
360+
});
318361
});
319362
}
320363
else

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,10 @@ class WebSocketMessage_RoomChatIncoming : public WebSocketMessageBase
151151
class WebSocketMessage_NetworkRoomMemberListUpdate : public WebSocketMessageBase
152152
{
153153
public:
154-
std::vector<std::string> users;
154+
std::vector<std::string> names;
155+
std::vector<int64_t> ids;
155156

156-
NLOHMANN_DEFINE_TYPE_INTRUSIVE(WebSocketMessage_NetworkRoomMemberListUpdate, users)
157+
NLOHMANN_DEFINE_TYPE_INTRUSIVE(WebSocketMessage_NetworkRoomMemberListUpdate, names, ids)
157158
};
158159

159160
void WebSocket::Tick()
@@ -211,7 +212,7 @@ void WebSocket::Tick()
211212
case EWebSocketMessageID::NETWORK_ROOM_MEMBER_LIST_UPDATE:
212213
{
213214
WebSocketMessage_NetworkRoomMemberListUpdate memberList = jsonObject.get<WebSocketMessage_NetworkRoomMemberListUpdate>();
214-
NGMP_OnlineServicesManager::GetInstance()->GetRoomsInterface()->OnRosterUpdated(memberList.users);
215+
NGMP_OnlineServicesManager::GetInstance()->GetRoomsInterface()->OnRosterUpdated(memberList.names, memberList.ids);
215216
}
216217
break;
217218

@@ -576,17 +577,21 @@ void NGMP_OnlineServices_RoomsInterface::SendChatMessageToCurrentRoom(UnicodeStr
576577
NGMP_OnlineServicesManager::GetInstance()->GetWebSocket()->SendData_RoomChatMessage(strChatMsg.str());
577578
}
578579

579-
void NGMP_OnlineServices_RoomsInterface::OnRosterUpdated(std::vector<std::string> vecUsers)
580+
void NGMP_OnlineServices_RoomsInterface::OnRosterUpdated(std::vector<std::string> vecNames, std::vector<int64_t> vecIDs)
580581
{
581582
m_mapMembers.clear();
582583

583-
Int64 i = 0;
584-
for (std::string strDisplayName : vecUsers)
584+
int index = 0;
585+
for (std::string strDisplayName : vecNames)
585586
{
587+
int64_t id = vecIDs.at(index);
588+
586589
NetworkRoomMember newMember;
587-
newMember.m_strName = AsciiString(strDisplayName.c_str());
588-
m_mapMembers.emplace(i, newMember);
589-
++i;
590+
newMember.display_name = strDisplayName;
591+
newMember.user_id = id;
592+
m_mapMembers.emplace(id, newMember);
593+
594+
++index;
590595
}
591596

592597
if (m_RosterNeedsRefreshCallback != nullptr)

0 commit comments

Comments
 (0)