log client version; log tk stats; logging fixes

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4395 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
ac_stef
2009-05-17 18:39:18 +00:00
parent f5e7039432
commit 5cc05dbb8a
4 changed files with 54 additions and 20 deletions
+15
View File
@@ -403,6 +403,21 @@ void sendintro()
ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE);
ucharbuf p(packet->data, packet->dataLength);
putint(p, SV_CONNECT);
putint(p, AC_VERSION);
putint(p, (isbigendian() ? 0x80 : 0 )|(adler((unsigned char *)guns, sizeof(guns)) % 31 << 8)|
#ifdef WIN32
0x40 |
#endif
#ifdef __APPLE__
0x20 |
#endif
#ifdef _DEBUG
0x08 |
#endif
#ifdef __GNUC__
0x04 |
#endif
0);
sendstring(player1->name, p);
sendstring(genpwdhash(player1->name, clientpassword, sessionid), p);
putint(p, connectrole);
+27 -20
View File
@@ -250,6 +250,7 @@ struct client // server side version of "dynent" type
int vote;
int role;
int connectmillis;
int acversion, acbuildtype;
bool isauthed; // for passworded servers
bool haswelcome;
bool isonrightmap;
@@ -2481,11 +2482,12 @@ void disconnect_client(int n, int reason)
if(sc)
{
sc->save(c.state);
scoresaved = " (score saved)";
scoresaved = ", score saved";
}
}
if(reason>=0) logger->writeline(log::info, "[%s] disconnecting client %s (%s) (cn %d)%s", c.hostname, c.name, disc_reason(reason), n, scoresaved);
else logger->writeline(log::info, "[%s] disconnected client %s (cn %d)%s", c.hostname, c.name, n, scoresaved);
int sp = (servmillis - c.connectmillis) / 1000;
if(reason>=0) logger->writeline(log::info, "[%s] disconnecting client %s (%s) cn %d, %d seconds played%s", c.hostname, c.name, disc_reason(reason), n, sp, scoresaved);
else logger->writeline(log::info, "[%s] disconnected client %s cn %d, %d seconds played%s", c.hostname, c.name, n, sp, scoresaved);
c.peer->data = (void *)-1;
if(reason>=0) enet_peer_disconnect(c.peer, reason);
clients[n]->zap();
@@ -2870,6 +2872,9 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1
else if(chan!=1 || getint(p)!=SV_CONNECT) disconnect_client(sender, DISC_TAGT);
else
{
cl->acversion = getint(p);
cl->acbuildtype = getint(p);
s_sprintfd(tags)(", AC: %d|%x", cl->acversion, cl->acbuildtype);
getstring(text, p);
filtertext(text, text, 0, MAXNAMELEN);
if(!text[0]) s_strcpy(text, "unarmed");
@@ -2883,26 +2888,25 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1
bool srvfull = numnonlocalclients() > scl.maxclients;
bool srvprivate = mastermode == MM_PRIVATE;
int bl = 0, wl = nbl.checknickwhitelist(*cl);
const char *wlp = wl == NWL_PASS ? ", nickname whitelist match" : "";
if(wl == NWL_PASS) s_strcat(tags, ", nickname whitelist match");
if(wl == NWL_UNLISTED) bl = nbl.checknickblacklist(cl->name);
if(wl == NWL_IPFAIL || wl == NWL_PWDFAIL)
{ // nickname matches whitelist, but IP is not in the required range or PWD doesn't match
logger->writeline(log::info, "[%s] '%s' matches nickname whitelist: wrong %s", cl->hostname, cl->name, wl == NWL_IPFAIL ? "IP" : "PWD");
logger->writeline(log::info, "[%s] '%s' matches nickname whitelist: wrong %s%s", cl->hostname, cl->name, wl == NWL_IPFAIL ? "IP" : "PWD", tags);
disconnect_client(sender, DISC_BADNICK);
}
else if(bl > 0)
{ // nickname matches blacklist
logger->writeline(log::info, "[%s] '%s' matches nickname blacklist line %d", cl->hostname, cl->name, bl);
logger->writeline(log::info, "[%s] '%s' matches nickname blacklist line %d%s", cl->hostname, cl->name, bl, tags);
disconnect_client(sender, DISC_BADNICK);
}
else if(checkadmin(cl->name, text, cl->salt, &pd) && (!pd.denyadmin || (banned && !srvfull && !srvprivate))) // pass admins always through
{ // admin (or deban) password match
bool banremoved = false;
cl->isauthed = true;
if(!pd.denyadmin && wantrole == CR_ADMIN) clientrole = CR_ADMIN;
if(banned)
{
loopv(bans) if(bans[i].address.host == cl->peer->address.host) { banremoved = true; bans.remove(i); break; } // remove admin bans
loopv(bans) if(bans[i].address.host == cl->peer->address.host) { bans.remove(i); s_strcat(tags, ", ban removed"); break; } // remove admin bans
}
if(srvfull)
{
@@ -2912,14 +2916,14 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1
break;
}
}
logger->writeline(log::info, "[%s] %s logged in using the admin password in line %d%s%s", cl->hostname, cl->name, pd.line, wlp, banremoved ? ", (ban removed)" : "");
logger->writeline(log::info, "[%s] %s logged in using the admin password in line %d%s", cl->hostname, cl->name, pd.line, tags);
}
else if(scl.serverpassword[0] && !(srvprivate || srvfull || banned))
{ // server password required
if(!strcmp(genpwdhash(cl->name, scl.serverpassword, cl->salt), text))
{
cl->isauthed = true;
logger->writeline(log::info, "[%s] %s client logged in (using serverpassword)%s", cl->hostname, cl->name, wlp);
logger->writeline(log::info, "[%s] %s client logged in (using serverpassword)%s", cl->hostname, cl->name, tags);
}
else disconnect_client(sender, DISC_WRONGPW);
}
@@ -2929,7 +2933,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1
else
{
cl->isauthed = true;
logger->writeline(log::info, "[%s] %s logged in (default)%s", cl->hostname, cl->name, wlp);
logger->writeline(log::info, "[%s] %s logged in (default)%s", cl->hostname, cl->name, tags);
}
}
if(!cl->isauthed) return;
@@ -3277,8 +3281,8 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1
int ls = (1 << maplayout_factor) - 1;
if(po.x < 0 || po.y < 0 || po.x > ls || po.y > ls || maplayout[((int) po.x) + (((int) po.y) << maplayout_factor)] > po.z + 3)
{
clients[cn]->mapcollisions++;
if(gamemillis > 10 && (clients[cn]->mapcollisions % 25) == 1) // assume map to be loaded after 10 seconds: fixme
if(gamemillis > 10000 && (servmillis - clients[cn]->connectmillis) > 10000) clients[cn]->mapcollisions++; // assume map to be loaded after 10 seconds: fixme
if((clients[cn]->mapcollisions % 25) == 1)
{
logger->writeline(log::info, "[%s] %s collides with the map (%d)", clients[cn]->hostname, clients[cn]->name, clients[cn]->mapcollisions);
}
@@ -3637,19 +3641,22 @@ void rereadcfgs(void)
void loggamestatus(const char *reason)
{
int fragscore[2] = {0, 0}, flagscore[2] = {0, 0}, pnum[2] = {0, 0}, n;
string text1, text2;
s_sprintf(text1)("%d minutes remaining", minremain);
string text;
s_sprintf(text)("%d minutes remaining", minremain);
logger->writeline(log::info, "");
logger->writeline(log::info, "Game status: %s on %s, %s, %s%c %s",
modestr(gamemode), smapname, reason ? reason : text1, mmfullname(mastermode), custom_servdesc ? ',' : '\0', servdesc_current);
logger->writeline(log::info, "cn name %sfrag death %sping role host", m_teammode ? "team " : "", m_flags ? "flags " : "");
modestr(gamemode), smapname, reason ? reason : text, mmfullname(mastermode), custom_servdesc ? ',' : '\0', servdesc_current);
logger->writeline(log::info, "cn name %s%sfrag death %sping role host", m_teammode ? "team " : "", m_flags ? "flag " : "", m_teammode ? "tk " : "");
loopv(clients)
{
client &c = *clients[i];
if(c.type == ST_EMPTY || !c.name[0]) continue;
s_sprintf(text1)("%2d %-16s%c%-4s", c.clientnum, c.name, m_teammode ? ' ' : '\0', c.team);
s_sprintf(text2)(" %4d %5d%c%5d", c.state.frags, c.state.deaths, m_flags ? ' ' : '\0', c.state.flagscore);
logger->writeline(log::info, "%s%s%5d %-6s %s", text1, text2, c.ping, c.role == CR_ADMIN ? "admin" : "normal", c.hostname);
s_sprintf(text)("%2d %-16s ", c.clientnum, c.name); // cn name
if(m_teammode) s_strcatf(text, "%-4s ", c.team); // team
if(m_flags) s_strcatf(text, "%4d ", c.state.flagscore); // flag
s_strcatf(text, "%4d %5d", c.state.frags, c.state.deaths); // frag death
if(m_teammode) s_strcatf(text, " %2d", c.state.teamkills); // tk
logger->writeline(log::info, "%s%5d %s %s", text, c.ping, c.role == CR_ADMIN ? "admin " : "normal", c.hostname);
n = team_int(c.team);
flagscore[n] += c.state.flagscore;
fragscore[n] += c.state.frags;
+11
View File
@@ -509,6 +509,17 @@ bool cmpf(char *fn, enet_uint32 c)
return r;
}
enet_uint32 adler(unsigned char *data, size_t len)
{
enet_uint32 a = 1, b = 0;
while (len--)
{
a += *data++;
b += a;
}
return b;
}
void endianswap(void *memory, int stride, int length) // little endian as storage format
{
static const int littleendian = 1;
+1
View File
@@ -598,6 +598,7 @@ extern bool delfile(const char *path);
extern struct mapstats *loadmapstats(const char *filename, bool getlayout);
extern bool cmpb(void *b, int n, enet_uint32 c);
extern bool cmpf(char *fn, enet_uint32 c);
extern enet_uint32 adler(unsigned char *data, size_t len);
extern void endianswap(void *, int, int);
extern bool isbigendian();
extern void strtoupper(char *s);