Skip to content

Commit 08b06e3

Browse files
authored
[GEN][ZH] Improve Network logging (#406)
Add DEBUG_LOG message when sending packet is incomplete, when an unknown packet is received and when a packet cannot be sent. Add PRINTF_IP_AS_4_INTS macro to simplify printing of IP addresses. Also change logs in LANAPI::update to print proper IP addresses.
1 parent df099f6 commit 08b06e3

File tree

26 files changed

+132
-128
lines changed

26 files changed

+132
-128
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,6 @@ static const Int NETWORK_BASE_PORT_NUMBER = 8088;
212212
class NetworkInterface;
213213
extern NetworkInterface *TheNetwork;
214214

215+
#define PRINTF_IP_AS_4_INTS(ip) ((ip) >> 24) & 0xff, ((ip) >> 16) & 0xff, ((ip) >> 8 ) & 0xff, (ip) & 0xff
215216

216217
#endif

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ static void playerTooltip(GameWindow *window,
221221
}
222222
UnicodeString tooltip;
223223
tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getName().str(), player->getLogin().str(), player->getHost().str());
224+
#if defined(_DEBUG) || defined(_INTERNAL)
225+
UnicodeString ip;
226+
ip.format(L" - %d.%d.%d.%d", PRINTF_IP_AS_4_INTS(player->getIP()));
227+
tooltip.concat(ip);
228+
#endif
229+
224230
TheMouse->setCursorTooltip( tooltip );
225231
}
226232

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ static void playerTooltip(GameWindow *window,
312312
}
313313
UnicodeString tooltip;
314314
tooltip.format(TheGameText->fetch("TOOLTIP:LANPlayer"), player->getName().str(), player->getLogin().str(), player->getHost().str());
315+
#if defined(_DEBUG) || defined(_INTERNAL)
316+
UnicodeString ip;
317+
ip.format(L" - %d.%d.%d.%d", PRINTF_IP_AS_4_INTS(player->getIP()));
318+
tooltip.concat(ip);
319+
#endif
315320
TheMouse->setCursorTooltip( tooltip );
316321
}
317322

@@ -377,7 +382,7 @@ void LanLobbyMenuInit( WindowLayout *layout, void *userData )
377382
// Choose an IP address, then initialize the LAN singleton
378383
UnsignedInt IP = TheGlobalData->m_defaultIP;
379384
IPEnumeration IPs;
380-
385+
const WideChar* IPSource;
381386
if (!IP)
382387
{
383388
EnumeratedIP *IPlist = IPs.getAddresses();
@@ -393,23 +398,18 @@ void LanLobbyMenuInit( WindowLayout *layout, void *userData )
393398
/// @todo: display error and exit lan lobby if no IPs are found
394399
}
395400

396-
//UnicodeString str;
397-
//str.format(L"Local IP chosen: %hs", IPlist->getIPstring().str());
398-
//GadgetListBoxAddEntryText(listboxChatWindow, str, chatSystemColor, -1, 0);
401+
IPSource = L"Local IP chosen";
399402
IP = IPlist->getIP();
400403
}
401404
else
402405
{
403-
/*
404-
UnicodeString str;
405-
str.format(L"Default local IP: %d.%d.%d.%d",
406-
(IP >> 24),
407-
(IP >> 16) & 0xFF,
408-
(IP >> 8) & 0xFF,
409-
IP & 0xFF);
410-
GadgetListBoxAddEntryText(listboxChatWindow, str, chatSystemColor, -1, 0);
411-
*/
406+
IPSource = L"Default local IP";
412407
}
408+
#if defined(_DEBUG) || defined(_INTERNAL)
409+
UnicodeString str;
410+
str.format(L"%s: %d.%d.%d.%d", IPSource, PRINTF_IP_AS_4_INTS(IP));
411+
GadgetListBoxAddEntryText(listboxChatWindow, str, chatSystemColor, -1, 0);
412+
#endif
413413

414414
// TheLAN->init() sets us to be in a LAN menu screen automatically.
415415
TheLAN->init();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void HostDirectConnectGame()
193193

194194
UnsignedInt localIP = TheLAN->GetLocalIP();
195195
UnicodeString localIPString;
196-
localIPString.format(L"%d.%d.%d.%d", localIP >> 24, (localIP & 0xff0000) >> 16, (localIP & 0xff00) >> 8, localIP & 0xff);
196+
localIPString.format(L"%d.%d.%d.%d", PRINTF_IP_AS_4_INTS(localIP));
197197

198198
UnicodeString name;
199199
name = GadgetTextEntryGetText(editPlayerName);
@@ -347,7 +347,7 @@ void NetworkDirectConnectInit( WindowLayout *layout, void *userData )
347347
}
348348

349349
UnsignedInt ip = TheLAN->GetLocalIP();
350-
ipstr.format(L"%d.%d.%d.%d", ip >> 24, (ip & 0xff0000) >> 16, (ip & 0xff00) >> 8, ip & 0xff);
350+
ipstr.format(L"%d.%d.%d.%d", PRINTF_IP_AS_4_INTS(ip));
351351
GadgetStaticTextSetText(staticLocalIP, ipstr);
352352

353353
TheLAN->RequestLobbyLeave(true);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ void OptionPreferences::setLANIPAddress( AsciiString IP )
289289
void OptionPreferences::setLANIPAddress( UnsignedInt IP )
290290
{
291291
AsciiString tmp;
292-
tmp.format("%d.%d.%d.%d", ((IP & 0xff000000) >> 24), ((IP & 0xff0000) >> 16), ((IP & 0xff00) >> 8), (IP & 0xff));
292+
tmp.format("%d.%d.%d.%d", PRINTF_IP_AS_4_INTS(IP));
293293
(*this)["IPAddress"] = tmp;
294294
}
295295

@@ -317,7 +317,7 @@ void OptionPreferences::setOnlineIPAddress( AsciiString IP )
317317
void OptionPreferences::setOnlineIPAddress( UnsignedInt IP )
318318
{
319319
AsciiString tmp;
320-
tmp.format("%d.%d.%d.%d", ((IP & 0xff000000) >> 24), ((IP & 0xff0000) >> 16), ((IP & 0xff00) >> 8), (IP & 0xff));
320+
tmp.format("%d.%d.%d.%d", PRINTF_IP_AS_4_INTS(IP));
321321
(*this)["GameSpyIPAddress"] = tmp;
322322
}
323323

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,10 +1946,7 @@ void ConnectionManager::parseUserList(const GameInfo *game)
19461946
char *listPos;
19471947
19481948
DEBUG_LOG(("ConnectionManager::parseUserList - looking for local user at %d.%d.%d.%d:%d\n",
1949-
(m_localAddr >> 24) & 0xff,
1950-
(m_localAddr >> 16) & 0xff,
1951-
(m_localAddr >> 8) & 0xff,
1952-
m_localAddr & 0xff,
1949+
PRINTF_IP_AS_4_INTS(m_localAddr),
19531950
m_localPort));
19541951
19551952
int numUsers = 0;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,7 @@ Bool FirewallHelperClass::sendToManglerFromPort(UnsignedInt address, UnsignedSho
364364
packet.length = sizeof(ManglerData);
365365

366366
DEBUG_LOG(("FirewallHelperClass::sendToManglerFromPort - Sending from port %d to %d.%d.%d.%d:%d\n", (UnsignedInt)port,
367-
(address & 0xFF000000) >> 24,
368-
(address & 0xFF0000) >> 16,
369-
(address & 0xFF00) >> 8,
370-
(address & 0xFF), MANGLER_PORT));
367+
PRINTF_IP_AS_4_INTS(address), MANGLER_PORT));
371368
/*
372369
DEBUG_LOG(("Buffer = "));
373370
for (i = 0; i < sizeof(ManglerData); ++i) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ void GameInfo::setSlot( Int slotNum, GameSlot slotInfo )
440440
#endif
441441

442442
DEBUG_LOG(("GameInfo::setSlot - setting slot %d to be player %ls with IP %d.%d.%d.%d\n", slotNum, slotInfo.getName().str(),
443-
ip >> 24, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff));
443+
PRINTF_IP_AS_4_INTS(ip)));
444444
}
445445

446446
GameSlot* GameInfo::getSlot( Int slotNum )

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,7 @@ void GameSpyLaunchGame( void )
537537
*/
538538
{
539539
user.format(",%s@%d.%d.%d.%d:%d", tmpUserName.str(),
540-
((ip & 0xff000000) >> 24),
541-
((ip & 0xff0000) >> 16),
542-
((ip & 0xff00) >> 8),
543-
((ip & 0xff)),
540+
PRINTF_IP_AS_4_INTS(ip),
544541
TheNAT->getSlotPort(i)
545542
);
546543
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,43 +359,43 @@ void LANAPI::update( void )
359359
{
360360
// Location specification
361361
case LANMessage::MSG_REQUEST_LOCATIONS: // Hey, where is everybody?
362-
// DEBUG_LOG(("LANAPI::update - got a MSG_REQUEST_LOCATIONS from 0x%08x\n", senderIP));
362+
DEBUG_LOG(("LANAPI::update - got a MSG_REQUEST_LOCATIONS from %d.%d.%d.%d\n", PRINTF_IP_AS_4_INTS(senderIP)));
363363
handleRequestLocations( msg, senderIP );
364364
break;
365365
case LANMessage::MSG_GAME_ANNOUNCE: // Here someone is, and here's his game info!
366-
// DEBUG_LOG(("LANAPI::update - got a MSG_GAME_ANNOUNCE from 0x%08x\n", senderIP));
366+
DEBUG_LOG(("LANAPI::update - got a MSG_GAME_ANNOUNCE from %d.%d.%d.%d\n", PRINTF_IP_AS_4_INTS(senderIP)));
367367
handleGameAnnounce( msg, senderIP );
368368
break;
369369
case LANMessage::MSG_LOBBY_ANNOUNCE: // Hey, I'm in the lobby!
370-
// DEBUG_LOG(("LANAPI::update - got a MSG_LOBBY_ANNOUNCE from 0x%08x\n", senderIP));
370+
DEBUG_LOG(("LANAPI::update - got a MSG_LOBBY_ANNOUNCE from %d.%d.%d.%d\n", PRINTF_IP_AS_4_INTS(senderIP)));
371371
handleLobbyAnnounce( msg, senderIP );
372372
break;
373373
case LANMessage::MSG_REQUEST_GAME_INFO:
374-
// DEBUG_LOG(("LANAPI::update - got a MSG_REQUEST_GAME_INFO from 0x%08x\n", senderIP));
374+
DEBUG_LOG(("LANAPI::update - got a MSG_REQUEST_GAME_INFO from %d.%d.%d.%d\n", PRINTF_IP_AS_4_INTS(senderIP)));
375375
handleRequestGameInfo( msg, senderIP );
376376
break;
377377

378378
// Joining games
379379
case LANMessage::MSG_REQUEST_JOIN: // Let me in! Let me in!
380-
// DEBUG_LOG(("LANAPI::update - got a MSG_REQUEST_JOIN from 0x%08x\n", senderIP));
380+
DEBUG_LOG(("LANAPI::update - got a MSG_REQUEST_JOIN from %d.%d.%d.%d\n", PRINTF_IP_AS_4_INTS(senderIP)));
381381
handleRequestJoin( msg, senderIP );
382382
break;
383383
case LANMessage::MSG_JOIN_ACCEPT: // Okay, you can join.
384-
// DEBUG_LOG(("LANAPI::update - got a MSG_JOIN_ACCEPT from 0x%08x\n", senderIP));
384+
DEBUG_LOG(("LANAPI::update - got a MSG_JOIN_ACCEPT from %d.%d.%d.%d\n", PRINTF_IP_AS_4_INTS(senderIP)));
385385
handleJoinAccept( msg, senderIP );
386386
break;
387387
case LANMessage::MSG_JOIN_DENY: // Go away! We don't want any!
388-
// DEBUG_LOG(("LANAPI::update - got a MSG_JOIN_DENY from 0x%08x\n", senderIP));
388+
DEBUG_LOG(("LANAPI::update - got a MSG_JOIN_DENY from %d.%d.%d.%d\n", PRINTF_IP_AS_4_INTS(senderIP)));
389389
handleJoinDeny( msg, senderIP );
390390
break;
391391

392392
// Leaving games, lobby
393393
case LANMessage::MSG_REQUEST_GAME_LEAVE: // I'm outa here!
394-
// DEBUG_LOG(("LANAPI::update - got a MSG_REQUEST_GAME_LEAVE from 0x%08x\n", senderIP));
394+
DEBUG_LOG(("LANAPI::update - got a MSG_REQUEST_GAME_LEAVE from %d.%d.%d.%d\n", PRINTF_IP_AS_4_INTS(senderIP)));
395395
handleRequestGameLeave( msg, senderIP );
396396
break;
397397
case LANMessage::MSG_REQUEST_LOBBY_LEAVE: // I'm outa here!
398-
// DEBUG_LOG(("LANAPI::update - got a MSG_REQUEST_LOBBY_LEAVE from 0x%08x\n", senderIP));
398+
DEBUG_LOG(("LANAPI::update - got a MSG_REQUEST_LOBBY_LEAVE from %d.%d.%d.%d\n", PRINTF_IP_AS_4_INTS(senderIP)));
399399
handleRequestLobbyLeave( msg, senderIP );
400400
break;
401401

@@ -416,7 +416,7 @@ void LANAPI::update( void )
416416
handleGameStartTimer( msg, senderIP );
417417
break;
418418
case LANMessage::MSG_GAME_OPTIONS: // Here's some info about the game.
419-
// DEBUG_LOG(("LANAPI::update - got a MSG_GAME_OPTIONS from 0x%08x\n", senderIP));
419+
DEBUG_LOG(("LANAPI::update - got a MSG_GAME_OPTIONS from %d.%d.%d.%d\n", PRINTF_IP_AS_4_INTS(senderIP)));
420420
handleGameOptions( msg, senderIP );
421421
break;
422422
case LANMessage::MSG_INACTIVE: // someone is telling us that we're inactive.

0 commit comments

Comments
 (0)