From 1356590f9dba2dc7cef1bc2222c0f2261a35f610 Mon Sep 17 00:00:00 2001 From: sireus Date: Fri, 24 Aug 2012 20:19:08 +0000 Subject: [PATCH] fix IP-related endianness confusion (please double-check, I don't have HW to test this :) ) git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6866 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/clientgame.cpp | 17 ++++++++++++----- source/src/server.cpp | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 318de8ba..fb9c27bb 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -883,7 +883,7 @@ void writekillmsgcfg() void burstshots(char *gun_str, char *shots_str) { - // args are passed as strings to differentiate 2 cases : shots_str == "0" or shots_str is empty (not specified from cubescript). + // args are passed as strings to differentiate 2 cases : shots_str == "0" or shots_str is empty (not specified from cubescript). int gun = gun_str ? atoi(gun_str) : -1; int shots = shots_str && *shots_str != '\0' ? atoi(shots_str) : -1; @@ -1633,11 +1633,18 @@ void whois(int cn) return; } - int ip = p->address; + uchar ip[4]; + if(isbigendian()) + { + enet_uint32 big = endianswap(p->address); + memmove(&ip, &big, 4); + } + else memmove(&ip, &p->address, 4); + if(m_teammode) conoutf(_("%c0INFO: %c5%s has %d teamkills."), CC, CC, p->name, p->tks); - if((ip>>24&0xFF) > 0 || player1->clientrole==CR_ADMIN) - conoutf("WHOIS client %d:\n\f5name\t%s\n\f5IP\t%d.%d.%d.%d", cn, colorname(p), ip&0xFF, ip>>8&0xFF, ip>>16&0xFF, ip>>24&0xFF); // full IP - else conoutf("WHOIS client %d:\n\f5name\t%s\n\f5IP\t%d.%d.%d.x", cn, colorname(p), ip&0xFF, ip>>8&0xFF, ip>>16&0xFF); // censored IP + if(ip[3] != 0 || player1->clientrole==CR_ADMIN) + conoutf("WHOIS client %d:\n\f5name\t%s\n\f5IP\t%d.%d.%d.%d", cn, colorname(p), ip[0], ip[1], ip[2], ip[3]); // full IP + else conoutf("WHOIS client %d:\n\f5name\t%s\n\f5IP\t%d.%d.%d.x", cn, colorname(p), ip[0], ip[1], ip[2]); // censored IP } COMMAND(whois, ARG_1INT); diff --git a/source/src/server.cpp b/source/src/server.cpp index f02ce1d1..52de708e 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -2409,7 +2409,7 @@ void sendiplist(int receiver, int cn) && (clients[i]->clientnum == cn || cn == -1)) { putint(p, i); - putint(p, clients[i]->peer->address.host); + putint(p, isbigendian() ? endianswap(clients[i]->peer->address.host) : clients[i]->peer->address.host); } putint(p, -1); sendpacket(receiver, 1, p.finalize()); @@ -2465,7 +2465,7 @@ void putinitclient(client &c, packetbuf &p) putint(p, c.team); enet_uint32 ip = 0; if(c.type == ST_TCPIP) ip = c.peer->address.host & 0xFFFFFF; - putint(p, ip); + putint(p, isbigendian() ? endianswap(ip) : ip); } void sendinitclient(client &c)