From 629d7346c34b0d60958048dd31ad69106c664f40 Mon Sep 17 00:00:00 2001 From: Lucas GAUTHERON Date: Thu, 23 Aug 2012 10:43:25 +0000 Subject: [PATCH] retrieve IP addresses when players join and allow cubescript to fetch these IPs git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6859 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/clientgame.cpp | 19 ++++++++++++++++++- source/src/clients2c.cpp | 11 +++++------ source/src/entity.h | 1 + source/src/server.cpp | 31 ++++++++++++++++++++++++++----- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 697dcbac..8f2bb894 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -336,6 +336,13 @@ void playerinfo(const char *cn, const char *attr) ATTR_INT(alive, p->state == CS_ALIVE ? 1 : 0); ATTR_INT(spect, p->team == TEAM_SPECT || p->spectatemode == SM_FLY ? 1 : 0); ATTR_INT(cn, p->clientnum); // only useful to get player1's client number. + + string addr = ""; + if((p->address>>24&0xFF) > 0 || player1->clientrole==CR_ADMIN) + formatstring(addr)("%d.%d.%d.%d", p->address&0xFF, p->address>>8&0xFF, p->address>>16&0xFF, p->address>>24&0xFF); // full IP + else formatstring(addr)("%d.%d.%d.x", p->address&0xFF, p->address>>8&0xFF, p->address>>16&0xFF); // censored IP + ATTR_STR(ip, addr); + conoutf("invalid attribute: %s", attr); } @@ -1603,7 +1610,17 @@ void cleanplayervotes(playerent *p) void whois(int cn) { - addmsg(SV_WHOIS, "ri", cn); + playerent *pl = getclient(cn); + if(!pl) + { + conoutf(_("invalid player name")); + return; + } + + if(m_teammode) conoutf(_("%c0INFO: %c5%s has %d teamkills."), CC, CC, pl->name, pl->tks); + if((pl->address>>24&0xFF) > 0 || player1->clientrole==CR_ADMIN) + conoutf("WHOIS %2d: %-16s\t%d.%d.%d.%d", cn, pl ? colorname(pl) : "", pl->address&0xFF, pl->address>>8&0xFF, pl->address>>16&0xFF, pl->address>>24&0xFF); // full IP + else conoutf("WHOIS client %d:\n\f5name\t%s\n\f5IP\t%d.%d.%d.x", cn, pl ? colorname(pl) : "", pl->address&0xFF, pl->address>>8&0xFF, pl->address>>16&0xFF); // censored IP } COMMAND(whois, ARG_1INT); diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 65fbb4c9..6c083f64 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -618,6 +618,9 @@ void parsemessages(int cn, playerent *d, ucharbuf &p, bool demo = false) } loopi(2) d->setskin(i, getint(p)); d->team = getint(p); + + d->address = getint(p); // partial or complete IP address + if(m_flags) loopi(2) { flaginfo &f = flaginfos[i]; @@ -1288,13 +1291,9 @@ void parsemessages(int cn, playerent *d, ucharbuf &p, bool demo = false) case SV_WHOISINFO: { - int cn = getint(p); + int cn = getint(p), ip = getint(p); playerent *pl = getclient(cn); - int ip = getint(p); - if(m_teammode) conoutf(_("%c0INFO: %c5%s has %d teamkills."), CC, CC, pl->name, pl->tks); - if((ip>>24&0xFF) > 0 || player1->clientrole==CR_ADMIN) - conoutf("WHOIS %2d: %-16s\t%d.%d.%d.%d", cn, pl ? colorname(pl) : "", 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, pl ? colorname(pl) : "", ip&0xFF, ip>>8&0xFF, ip>>16&0xFF); // censored IP + if(pl) pl->address = ip; break; } diff --git a/source/src/entity.h b/source/src/entity.h index 0d44429f..ccf57ed1 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -385,6 +385,7 @@ private: int curskin, nextskin[2]; public: int clientnum, lastupdate, plag, ping; + enet_uint32 address; int lifesequence; // sequence id for each respawn, used in damage test int frags, flagscore, deaths, points, tks; int lastaction, lastmove, lastpain, lastvoicecom; diff --git a/source/src/server.cpp b/source/src/server.cpp index 02f35c0e..9a78a5f5 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -2271,6 +2271,18 @@ void changeclientrole(int client, int role, char *pwd, bool force) if(pd.line > -1) logline(ACLOG_INFO,"[%s] player %s used admin password in line %d", clients[client]->hostname, clients[client]->name[0] ? clients[client]->name : "[unnamed]", pd.line); logline(ACLOG_INFO,"[%s] set role of player %s to %s", clients[client]->hostname, clients[client]->name[0] ? clients[client]->name : "[unnamed]", role == CR_ADMIN ? "admin" : "normal player"); // flowtron : connecting players haven't got a name yet (connectadmin) + if(role > CR_DEFAULT) + { + // send complete IP addresses + packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE); + loopv(clients) if(clients[i]->clientnum != client) + { + putint(p, SV_WHOISINFO); + putint(p, clients[i]->clientnum); + putint(p, clients[i]->peer->address.host); + } + sendpacket(client, 1, p.finalize()); + } } else if(pwd && pwd[0]) disconnect_client(client, DISC_SOPLOGINFAIL); // avoid brute-force if(curvote) curvote->evaluate(); @@ -2456,7 +2468,7 @@ void sendservinfo(client &c) sendf(c.clientnum, 1, "ri5", SV_SERVINFO, c.clientnum, isdedicated ? SERVER_PROTOCOL_VERSION : PROTOCOL_VERSION, c.salt, scl.serverpassword[0] ? 1 : 0); } -void putinitclient(client &c, packetbuf &p) +void putinitclient(client &c, packetbuf &p, int n) { putint(p, SV_INITCLIENT); putint(p, c.clientnum); @@ -2464,13 +2476,22 @@ void putinitclient(client &c, packetbuf &p) putint(p, c.skin[TEAM_CLA]); putint(p, c.skin[TEAM_RVSF]); putint(p, c.team); + enet_uint32 ip = isdedicated ? ( (n != -1 && clients[n]->role == CR_ADMIN) ? + c.peer->address.host : + c.peer->address.host & 0xFFFFFF + ) : 0; + putint(p, ip); // FIXME ? Maybe the IPs addresses should only be sent with SV_WHOISINFO } void sendinitclient(client &c) { - packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE); - putinitclient(c, p); - sendpacket(-1, 1, p.finalize(), c.clientnum); + loopv(clients) if(clients[i]->clientnum != c.clientnum) + { + packetbuf p(MAXTRANS, ENET_PACKET_FLAG_RELIABLE); + putinitclient(c, p, clients[i]->clientnum); + sendpacket(clients[i]->clientnum, 1, p.finalize()); + } + } void welcomeinitclient(packetbuf &p, int exclude = -1) @@ -2479,7 +2500,7 @@ void welcomeinitclient(packetbuf &p, int exclude = -1) { client &c = *clients[i]; if(c.type!=ST_TCPIP || !c.isauthed || c.clientnum == exclude) continue; - putinitclient(c, p); + putinitclient(c, p, exclude); } }