extended server pong message; serverbrowser enhanced

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@3990 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
ac_stef
2008-12-11 15:33:23 +00:00
parent b23d935cbc
commit 65d53e48e3
5 changed files with 51 additions and 11 deletions
+2
View File
@@ -92,6 +92,8 @@ enum { DISC_NONE = 0, DISC_EOP, DISC_CN, DISC_MKICK, DISC_MBAN, DISC_TAGT, DISC_
#define EXT_TEAMSCORE 2
#define EXT_PLAYERSTATS_RESP_STATS -11
enum { PONGFLAG_PASSWORD = 0, PONGFLAG_BANNED, PONGFLAG_BLACKLIST, PONGFLAG_MASTERMODE = 6, PONGFLAG_NUM };
enum
{
GMODE_DEMO = -3,
+4 -3
View File
@@ -193,14 +193,15 @@ struct serverinfo
string full;
string map;
string sdesc;
string description;
string cmd;
int mode, numplayers, maxclients, ping, protocol, minremain, resolved, port, lastpingmillis;
int mode, numplayers, maxclients, ping, protocol, minremain, resolved, port, lastpingmillis, pongflags;
ENetAddress address;
serverinfo()
: mode(0), numplayers(0), maxclients(0), ping(9999), protocol(0), minremain(0), resolved(UNRESOLVED), port(-1), lastpingmillis(0)
: mode(0), numplayers(0), maxclients(0), ping(9999), protocol(0), minremain(0), resolved(UNRESOLVED), port(-1), lastpingmillis(0), pongflags(0)
{
name[0] = full[0] = map[0] = sdesc[0] = '\0';
name[0] = full[0] = map[0] = sdesc[0] = description[0] = '\0';
}
};
+11 -3
View File
@@ -1669,10 +1669,10 @@ void readblacklist(const char *name)
logger->writeline(log::info,"read %d blacklist entries from %s", blacklist.length(), blfilename);
}
bool checkblacklist(enet_uint32 ip)
bool checkblacklist(enet_uint32 ip) // ip: network byte order
{
iprange t;
t.lr = ip;
t.lr = ntohl(ip); // blacklist uses host byte order
t.ur = 0;
return blacklist.search(&t, cmpipmatch) != NULL;
}
@@ -2044,7 +2044,7 @@ bool isbanned(int cn)
if(b.millis < servmillis) { bans.remove(i--); }
if(b.address.host == c.peer->address.host) { return true; }
}
return checkblacklist(atoip(c.hostname));
return checkblacklist(c.peer->address.host);
}
int serveroperator()
@@ -3381,6 +3381,14 @@ void cleanupserver()
if(logger) DELETEP(logger);
}
int getpongflags(enet_uint32 ip)
{
int flags = mastermode << PONGFLAG_MASTERMODE;
flags |= serverpassword[0] ? 1 << PONGFLAG_PASSWORD : 0;
loopv(bans) if(bans[i].address.host == ip) { flags |= 1 << PONGFLAG_BANNED; break; }
flags |= checkblacklist(ip) ? 1 << PONGFLAG_BLACKLIST : 0;
return flags;
}
void extinfo_cnbuf(ucharbuf &p, int cn)
{
if(cn == -1) // add all available player ids
+32 -5
View File
@@ -447,8 +447,30 @@ void checkpings()
getstring(text, p);
s_strcpy(si->map, text);
getstring(text, p);
s_strcpy(si->sdesc, text);
filterservdesc(si->sdesc, text);
s_strcpy(si->description, text);
si->maxclients = getint(p);
if(p.remaining())
{
si->pongflags = getint(p);
}
else
{
si->pongflags = 0;
}
if(si->pongflags > 0)
{
const char *sp = "";
int mm = si->pongflags >> PONGFLAG_MASTERMODE;
if(si->pongflags & (1 << PONGFLAG_BANNED))
sp = "you are banned from this server";
if(si->pongflags & (1 << PONGFLAG_BLACKLIST))
sp = "you are blacklisted on this server";
else if(si->pongflags & 1 << PONGFLAG_PASSWORD)
sp = "this server is password-protected";
else if(mm) sp = mmfullname(mm);
s_sprintf(si->description)("%s \f1(%s)", si->sdesc, sp);
}
}
}
@@ -558,6 +580,8 @@ void refreshservers(void *menu, bool init)
serverinfo &si = *servers[i];
if(!showallservers && si.lastpingmillis < servermenumillis) continue;
bool showthisone = true;
char basecolor = (si.pongflags & ((1 << PONGFLAG_BANNED) | (1 << PONGFLAG_BLACKLIST))) ? '4' : '5';
char plnumcolor = si.numplayers >= si.maxclients ? '2' : (si.pongflags & 1 << PONGFLAG_PASSWORD) ? '3' : (si.pongflags >> PONGFLAG_MASTERMODE ? '1' : basecolor);
if(si.address.host != ENET_HOST_ANY && si.ping != 9999)
{
if(si.protocol!=PROTOCOL_VERSION)
@@ -565,8 +589,11 @@ void refreshservers(void *menu, bool init)
if(!showonlygoodservers) s_sprintf(si.full)("%s:%d [%s protocol]", si.name, si.port, si.protocol<PROTOCOL_VERSION ? "older" : "newer");
else showthisone = false;
}
else if(si.map[0]) s_sprintf(si.full)("%d\t%d/%d\t%s, %s: %s:%d %s", si.ping, si.numplayers, si.maxclients, si.map, modestr(si.mode, modeacronyms > 0), si.name, si.port, si.sdesc);
else s_sprintf(si.full)("%d\t%d/%d\tempty: %s:%d %s", si.ping, si.numplayers, si.maxclients, si.name, si.port, si.sdesc);
else if(si.map[0]) s_sprintf(si.full)("\f%c%d\t\fs\f%c%d/%d\fr\t%s, %s: %s:%d %s", basecolor, si.ping,
plnumcolor, si.numplayers, si.maxclients,
si.map, modestr(si.mode, modeacronyms > 0), si.name, si.port, si.sdesc);
else s_sprintf(si.full)("\f%c%d\t\fs\f%c%d/%d\fr\tempty: %s:%d %s", basecolor, si.ping,
plnumcolor, si.numplayers, si.maxclients, si.name, si.port, si.sdesc);
}
else
{
@@ -574,9 +601,9 @@ void refreshservers(void *menu, bool init)
else showthisone = false;
}
si.full[75] = 0; // cut off too long server descriptions
si.sdesc[75] = 0;
si.description[75] = 0;
s_sprintf(si.cmd)("connect %s %d", si.name, si.port);
if(showthisone) menumanual(menu, si.full, si.cmd, NULL, si.sdesc);
if(showthisone) menumanual(menu, si.full, si.cmd, NULL, si.description);
}
}
}
+2
View File
@@ -156,6 +156,7 @@ uchar *retrieveservers(uchar *buf, int buflen)
ENetSocket pongsock = ENET_SOCKET_NULL, lansock = ENET_SOCKET_NULL;
string serverdesc;
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)
{
@@ -204,6 +205,7 @@ void serverms(int mode, int numplayers, int minremain, char *smapname, int milli
sendstring(smapname, po);
sendstring(serverdesc, po);
putint(po, maxclients);
putint(po, getpongflags(addr.host));
}
else // ext pong - additional server infos
{