From 7ec8634727887edf382534127c4016208245eed3 Mon Sep 17 00:00:00 2001 From: ac_stef Date: Tue, 2 Jun 2009 22:22:24 +0000 Subject: [PATCH] cleanup git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4460 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/command.cpp | 4 ++-- source/src/log.cpp | 45 +++++++++++++++++------------------------ source/src/protocol.cpp | 1 - source/src/protocol.h | 2 -- source/src/server.cpp | 17 ++++++++++------ source/src/serverms.cpp | 2 +- 6 files changed, 32 insertions(+), 39 deletions(-) diff --git a/source/src/command.cpp b/source/src/command.cpp index af8d7c42..41dae22f 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -1001,7 +1001,7 @@ void systime() result(numtime()); } -void timestamp() +void timestamp_() { result(timestring(true, "%Y %m %d %H %M %S")); } @@ -1021,7 +1021,7 @@ int millis_() { extern int totalmillis; return totalmillis; } COMMANDN(millis, millis_, ARG_IVAL); COMMAND(systime, ARG_NONE); -COMMAND(timestamp, ARG_NONE); +COMMANDN(timestamp, timestamp_, ARG_NONE); COMMAND(datestring, ARG_NONE); COMMANDN(timestring, timestring_, ARG_NONE); diff --git a/source/src/log.cpp b/source/src/log.cpp index 1f15e86e..adae4c85 100644 --- a/source/src/log.cpp +++ b/source/src/log.cpp @@ -4,7 +4,7 @@ #include "cube.h" #if !defined(WIN32) && !defined(__APPLE__) - + #include #include @@ -13,7 +13,7 @@ static const int facilities[] = { LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7 }; static const int levels[] = { LOG_DEBUG, LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERR }; #endif - + static const char *leveldesc[] = { "", "", "", "WARNING: ", "ERROR: " }; static FILE *fp = NULL; static string filepath, ident; @@ -37,7 +37,7 @@ bool initlogging(const char *identity, int facility_, int consolethres, int file #ifdef AC_USE_SYSLOG if(syslogthres >= 0) syslogthreshold = min(syslogthres, (int)ACLOG_NUM); if(syslogthreshold < ACLOG_NUM) - { + { facility &= 7; s_sprintf(ident)("AssaultCube%s", identity); openlog(ident, LOG_NDELAY, facilities[facility]); @@ -68,31 +68,22 @@ bool logline(int level, const char *msg, ...) { if(!enabled) return false; if(level < 0 || level >= ACLOG_NUM) return false; - s_sprintfdv(sf, msg); - filtertext(sf, sf, 2); - const char *ts = timestamp ? timestring(true, "%b %d %H:%M:%S ") : ""; - if(consolethreshold <= level) - { - printf("%s%s%s\n", ts, leveldesc[level], sf); - fflush(stdout); - } - if(fp && filethreshold <= level) - { - fprintf(fp, "%s%s%s\n", ts, leveldesc[level], sf); - fflush(fp); - } -#ifdef AC_USE_SYSLOG - if(syslogthreshold <= level) + s_sprintfdv(sf, msg); + filtertext(sf, sf, 2); + const char *ts = timestamp ? timestring(true, "%b %d %H:%M:%S ") : "", *ld = leveldesc[level]; + char *p, *l = sf; + do { // break into single lines first - char *p, *l = sf; - do - { - if((p = strchr(l, '\n'))) *p = '\0'; - syslog(levels[level], "%s", l); - l = p + 1; - } - while(p); - } + if((p = strchr(l, '\n'))) *p = '\0'; + if(consolethreshold <= level) printf("%s%s%s\n", ts, ld, l); + if(fp && filethreshold <= level) fprintf(fp, "%s%s%s\n", ts, ld, l); +#ifdef AC_USE_SYSLOG + if(syslogthreshold <= level) syslog(levels[level], "%s", l); #endif + l = p + 1; + } + while(p); + if(consolethreshold <= level) fflush(stdout); + if(fp && filethreshold <= level) fflush(fp); return consolethreshold <= level; } diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index cc7013ff..41cb6257 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -195,7 +195,6 @@ char msgsizesl[] = // size inclusive message token, 0 for variable SV_EDITMODE, 2, SV_EDITH, 7, SV_EDITT, 7, SV_EDITS, 6, SV_EDITD, 6, SV_EDITE, 6, SV_NEWMAP, 2, SV_SENDMAP, 0, SV_RECVMAP, 1, SV_REMOVEMAP, 0, SV_SERVMSG, 0, SV_ITEMLIST, 0, SV_WEAPCHANGE, 2, SV_PRIMARYWEAP, 2, - SV_MODELSKIN, 2, SV_FLAGACTION, 3, SV_FLAGINFO, 0, SV_FLAGMSG, 0, SV_FLAGCNT, 3, SV_ARENAWIN, 2, SV_SETADMIN, 0, SV_SERVOPINFO, 3, diff --git a/source/src/protocol.h b/source/src/protocol.h index eac19e8b..2a5a6c0c 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -27,7 +27,6 @@ enum SV_EDITMODE, SV_EDITH, SV_EDITT, SV_EDITS, SV_EDITD, SV_EDITE, SV_NEWMAP, SV_SENDMAP, SV_RECVMAP, SV_REMOVEMAP, SV_SERVMSG, SV_ITEMLIST, SV_WEAPCHANGE, SV_PRIMARYWEAP, - SV_MODELSKIN, SV_FLAGACTION, SV_FLAGINFO, SV_FLAGMSG, SV_FLAGCNT, SV_ARENAWIN, SV_SETADMIN, SV_SERVOPINFO, @@ -58,7 +57,6 @@ const static char *messagenames[] = "SV_EDITMODE", "SV_EDITH", "SV_EDITT", "SV_EDITS", "SV_EDITD", "SV_EDITE", "SV_NEWMAP", "SV_SENDMAP", "SV_RECVMAP", "SV_REMOVEMAP", "SV_SERVMSG", "SV_ITEMLIST", "SV_WEAPCHANGE", "SV_PRIMARYWEAP", - "SV_MODELSKIN", "SV_FLAGACTION", "SV_FLAGINFO", "SV_FLAGMSG", "SV_FLAGCNT", "SV_ARENAWIN", "SV_SETADMIN", "SV_SERVOPINFO", diff --git a/source/src/server.cpp b/source/src/server.cpp index 49a92f2d..a485a302 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -2810,13 +2810,18 @@ int checktype(int type, client *cl) static int edittypes[] = { SV_EDITENT, SV_EDITH, SV_EDITT, SV_EDITS, SV_EDITD, SV_EDITE, SV_NEWMAP }; if(cl && smode!=GMODE_COOPEDIT) loopi(sizeof(edittypes)/sizeof(int)) if(type == edittypes[i]) return -1; // server only messages - static int servtypes[] = { SV_INITS2C, SV_MAPRELOAD, SV_SERVMSG, SV_GIBDAMAGE, SV_DAMAGE, - SV_HITPUSH, SV_SHOTFX, SV_DIED, SV_SPAWNSTATE, SV_FORCEDEATH, SV_ITEMACC, - SV_ITEMSPAWN, SV_TIMEUP, SV_CDIS, SV_PONG, SV_RESUME, - SV_FLAGINFO, SV_FLAGMSG, SV_FLAGCNT, - SV_ARENAWIN, SV_SENDDEMOLIST, SV_SENDDEMO, SV_DEMOPLAYBACK, SV_CLIENT, - SV_CALLVOTESUC, SV_CALLVOTEERR, SV_VOTERESULT, SV_WHOISINFO, SV_ITEMLIST }; + static int servtypes[] = { SV_INITS2C, SV_WELCOME, SV_CDIS, SV_GIBDIED, SV_DIED, + SV_GIBDAMAGE, SV_DAMAGE, SV_HITPUSH, SV_SHOTFX, + SV_SPAWNSTATE, SV_FORCEDEATH, SV_RESUME, SV_TIMEUP, + SV_MAPRELOAD, SV_ITEMACC, SV_MAPCHANGE, SV_ITEMSPAWN, SV_PONG, + SV_SERVMSG, SV_ITEMLIST, SV_FLAGINFO, SV_FLAGMSG, SV_FLAGCNT, + SV_ARENAWIN, SV_SERVOPINFO, + SV_CALLVOTESUC, SV_CALLVOTEERR, SV_VOTERESULT, + SV_FORCETEAM, SV_AUTOTEAM, SV_WHOISINFO, + SV_SENDDEMOLIST, SV_SENDDEMO, SV_DEMOPLAYBACK, + SV_CLIENT, SV_FORCENOTIFY }; if(cl) loopi(sizeof(servtypes)/sizeof(int)) if(type == servtypes[i]) return -1; + if (type < 0 || type >= SV_NUM) return -1; return type; } diff --git a/source/src/serverms.cpp b/source/src/serverms.cpp index 4c86162f..4cd1ddbe 100644 --- a/source/src/serverms.cpp +++ b/source/src/serverms.cpp @@ -156,7 +156,7 @@ extern int getpongflags(enet_uint32 ip); void serverms(int mode, int numplayers, int minremain, char *smapname, int millis, const ENetAddress &localaddr, int *mnum, int *msend, int *mrec, int *cnum, int *csend, int *crec, int protocol_version) { checkmasterreply(); - updatemasterserver(millis, localaddr); + if(protocol_version > 0 || strncmp(masterpath, AC_MASTER_URI, 23)) updatemasterserver(millis, localaddr); static ENetSocketSet sockset; ENET_SOCKETSET_EMPTY(sockset);