Skip to content

Commit 1e37075

Browse files
committed
refactor(lan): Simplify LAN player tooltip related code (#1693)
1 parent affa598 commit 1e37075

File tree

8 files changed

+66
-50
lines changed

8 files changed

+66
-50
lines changed

Generals/Code/GameEngine/Include/GameNetwork/LANAPICallbacks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extern const Color acceptFalseColor;
7474

7575
void lanUpdateSlotList( void );
7676
void updateGameOptions( void );
77-
77+
void setLANPlayerTooltip(LANPlayer* player);
7878

7979
//Enum is used for the utility function so other windows do not need
8080
//to know about controls on LanGameOptions window.

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,8 @@ static void playerTooltip(GameWindow *window,
214214
TheMouse->setCursorTooltip( UnicodeString::TheEmptyString );
215215
return;
216216
}
217-
UnicodeString tooltip;
218-
tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getLogin().str(), player->getHost().str());
219-
#if defined(RTS_DEBUG)
220-
UnicodeString ip;
221-
ip.format(L" - %d.%d.%d.%d", PRINTF_IP_AS_4_INTS(player->getIP()));
222-
tooltip.concat(ip);
223-
#endif
224217

225-
TheMouse->setCursorTooltip( tooltip );
218+
setLANPlayerTooltip(player);
226219
}
227220

228221
void StartPressed(void)
@@ -903,6 +896,21 @@ void updateGameOptions( void )
903896
}
904897

905898

899+
//-------------------------------------------------------------------------------------------------
900+
//-------------------------------------------------------------------------------------------------
901+
void setLANPlayerTooltip(LANPlayer* player)
902+
{
903+
UnicodeString tooltip;
904+
tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getLogin().str(), player->getHost().str());
905+
#if defined(RTS_DEBUG)
906+
UnicodeString ip;
907+
ip.format(L" - %d.%d.%d.%d", PRINTF_IP_AS_4_INTS(player->getIP()));
908+
tooltip.concat(ip);
909+
#endif
910+
TheMouse->setCursorTooltip( tooltip );
911+
912+
}
913+
906914

907915
//-------------------------------------------------------------------------------------------------
908916
/** This is called when a shutdown is complete for this menu */

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanLobbyMenu.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,8 @@ static void playerTooltip(GameWindow *window,
310310
//TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:LobbyPlayers") );
311311
return;
312312
}
313-
UnicodeString tooltip;
314-
tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getLogin().str(), player->getHost().str());
315-
#if defined(RTS_DEBUG)
316-
UnicodeString ip;
317-
ip.format(L" - %d.%d.%d.%d", PRINTF_IP_AS_4_INTS(player->getIP()));
318-
tooltip.concat(ip);
319-
#endif
320-
TheMouse->setCursorTooltip( tooltip );
313+
314+
setLANPlayerTooltip(player);
321315
}
322316

323317

Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,27 @@ void LANAPI::init( void )
112112

113113
m_lastGameopt = "";
114114

115-
unsigned long bufSize = UNLEN + 1;
116115
char userName[UNLEN + 1];
117-
if (!GetUserName(userName, &bufSize))
116+
DWORD bufSize = ARRAY_SIZE(userName);
117+
if (GetUserNameA(userName, &bufSize))
118118
{
119-
strcpy(userName, "unknown");
119+
m_userName.set(userName, bufSize);
120+
}
121+
else
122+
{
123+
m_userName = "unknown";
120124
}
121-
m_userName = userName;
122125

123-
bufSize = MAX_COMPUTERNAME_LENGTH + 1;
124126
char computerName[MAX_COMPUTERNAME_LENGTH + 1];
125-
if (!GetComputerName(computerName, &bufSize))
127+
bufSize = ARRAY_SIZE(computerName);
128+
if (GetComputerNameA(computerName, &bufSize))
129+
{
130+
m_hostName.set(computerName, bufSize);
131+
}
132+
else
126133
{
127-
strcpy(computerName, "unknown");
134+
m_hostName = "unknown";
128135
}
129-
m_hostName = computerName;
130136
}
131137

132138
void LANAPI::reset( void )

GeneralsMD/Code/GameEngine/Include/GameNetwork/LANAPICallbacks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extern const Color acceptFalseColor;
7474

7575
void lanUpdateSlotList( void );
7676
void updateGameOptions( void );
77-
77+
void setLANPlayerTooltip(LANPlayer* player);
7878

7979
//Enum is used for the utility function so other windows do not need
8080
//to know about controls on LanGameOptions window.

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,8 @@ static void playerTooltip(GameWindow *window,
221221
TheMouse->setCursorTooltip( UnicodeString::TheEmptyString );
222222
return;
223223
}
224-
UnicodeString tooltip;
225-
tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getLogin().str(), player->getHost().str());
226-
#if defined(RTS_DEBUG)
227-
UnicodeString ip;
228-
ip.format(L" - %d.%d.%d.%d", PRINTF_IP_AS_4_INTS(player->getIP()));
229-
tooltip.concat(ip);
230-
#endif
231224

232-
TheMouse->setCursorTooltip( tooltip );
225+
setLANPlayerTooltip(player);
233226
}
234227

235228
void StartPressed(void)
@@ -998,6 +991,21 @@ void updateGameOptions( void )
998991
}
999992

1000993

994+
//-------------------------------------------------------------------------------------------------
995+
//-------------------------------------------------------------------------------------------------
996+
void setLANPlayerTooltip(LANPlayer* player)
997+
{
998+
UnicodeString tooltip;
999+
tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getLogin().str(), player->getHost().str());
1000+
#if defined(RTS_DEBUG)
1001+
UnicodeString ip;
1002+
ip.format(L" - %d.%d.%d.%d", PRINTF_IP_AS_4_INTS(player->getIP()));
1003+
tooltip.concat(ip);
1004+
#endif
1005+
TheMouse->setCursorTooltip( tooltip );
1006+
1007+
}
1008+
10011009

10021010
//-------------------------------------------------------------------------------------------------
10031011
/** This is called when a shutdown is complete for this menu */

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,8 @@ static void playerTooltip(GameWindow *window,
352352
//TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:LobbyPlayers") );
353353
return;
354354
}
355-
UnicodeString tooltip;
356-
tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getLogin().str(), player->getHost().str());
357-
#if defined(RTS_DEBUG)
358-
UnicodeString ip;
359-
ip.format(L" - %d.%d.%d.%d", PRINTF_IP_AS_4_INTS(player->getIP()));
360-
tooltip.concat(ip);
361-
#endif
362-
TheMouse->setCursorTooltip( tooltip );
355+
356+
setLANPlayerTooltip(player);
363357
}
364358

365359

GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,27 @@ void LANAPI::init( void )
112112

113113
m_lastGameopt = "";
114114

115-
unsigned long bufSize = UNLEN + 1;
116115
char userName[UNLEN + 1];
117-
if (!GetUserName(userName, &bufSize))
116+
DWORD bufSize = ARRAY_SIZE(userName);
117+
if (GetUserNameA(userName, &bufSize))
118118
{
119-
strcpy(userName, "unknown");
119+
m_userName.set(userName, bufSize);
120+
}
121+
else
122+
{
123+
m_userName = "unknown";
120124
}
121-
m_userName = userName;
122125

123-
bufSize = MAX_COMPUTERNAME_LENGTH + 1;
124126
char computerName[MAX_COMPUTERNAME_LENGTH + 1];
125-
if (!GetComputerName(computerName, &bufSize))
127+
bufSize = ARRAY_SIZE(computerName);
128+
if (GetComputerNameA(computerName, &bufSize))
129+
{
130+
m_hostName.set(computerName, bufSize);
131+
}
132+
else
126133
{
127-
strcpy(computerName, "unknown");
134+
m_hostName = "unknown";
128135
}
129-
m_hostName = computerName;
130136
}
131137

132138
void LANAPI::reset( void )

0 commit comments

Comments
 (0)