From 0650dd3a64552e208c098dc0794eae82641a588c Mon Sep 17 00:00:00 2001 From: ac_stef Date: Sat, 16 May 2009 17:18:17 +0000 Subject: [PATCH] new commands: modconnect, modconnectadmin & modlanconnect git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4391 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/client.cpp | 26 ++++++++++++++++++++++++++ source/src/clients2c.cpp | 8 ++++---- source/src/menus.cpp | 8 +++++++- source/src/protocol.cpp | 2 +- source/src/protocol.h | 5 ++++- source/src/protos.h | 2 +- source/src/server.cpp | 15 ++++++++++----- source/src/serverms.cpp | 6 +++--- 8 files changed, 56 insertions(+), 16 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index 687c5a46..2d76dca3 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -43,6 +43,7 @@ void throttle() string clientpassword = ""; int connectrole = CR_DEFAULT; +bool modprotocol = false; void abortconnect() { @@ -116,17 +117,39 @@ void connectserv_(const char *servername, const char *serverport = NULL, const c void connectserv(char *servername, char *serverport, char *password) { + modprotocol = false; connectserv_(servername, serverport, password); } void connectadmin(char *servername, char *serverport, char *password) { + modprotocol = false; if(!password[0]) return; connectserv_(servername, serverport, password, CR_ADMIN); } void lanconnect() { + modprotocol = false; + connectserv_(NULL); +} + +void modconnectserv(char *servername, char *serverport, char *password) +{ + modprotocol = true; + connectserv_(servername, serverport, password); +} + +void modconnectadmin(char *servername, char *serverport, char *password) +{ + modprotocol = true; + if(!password[0]) return; + connectserv_(servername, serverport, password, CR_ADMIN); +} + +void modlanconnect() +{ + modprotocol = true; connectserv_(NULL); } @@ -217,6 +240,9 @@ COMMANDN(say, toserver, ARG_CONC); COMMANDN(connect, connectserv, ARG_3STR); COMMAND(connectadmin, ARG_3STR); COMMAND(lanconnect, ARG_NONE); +COMMANDN(modconnect, modconnectserv, ARG_3STR); +COMMAND(modconnectadmin, ARG_3STR); +COMMAND(modlanconnect, ARG_NONE); COMMANDN(disconnect, trydisconnect, ARG_NONE); void cleanupclient() diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 8e137e94..f985e73e 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -202,17 +202,17 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) case SV_INITS2C: // welcome messsage from the server { int mycn = getint(p), prot = getint(p); - if(prot!=PROTOCOL_VERSION) + if(prot!=CUR_PROTOCOL_VERSION && !(watchingdemo && prot == -PROTOCOL_VERSION)) { - conoutf("\f3you are using a different game protocol (you: %d, server: %d)", PROTOCOL_VERSION, prot); - + conoutf("\f3you are using a different game protocol (you: %d, server: %d)", CUR_PROTOCOL_VERSION, prot); +#if 0 if(prot<1000) // bug, possibly { // might indicate a client/server communication bug, create error report pktlogger.flushtolog("packetlog_protocol.txt"); conoutf("\f3wrote a network error report to packetlog_protocol.txt, please post this file to the bugtracker now!"); } - +#endif disconnect(); return; } diff --git a/source/src/menus.cpp b/source/src/menus.cpp index 7e93a69e..e0580465 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -890,7 +890,13 @@ char *getfiledesc(const char *dir, const char *name, const char *ext) gzclose(f); endianswap(&hdr.version, sizeof(int), 1); endianswap(&hdr.protocol, sizeof(int), 1); - s_sprintf(text)("%s%s", (hdr.version!=DEMO_VERSION || hdr.protocol!=PROTOCOL_VERSION) ? "(incompatible file) " : "", hdr.desc); + const char *tag = "(incompatible file) "; + if(hdr.version == DEMO_VERSION) + { + if(hdr.protocol == PROTOCOL_VERSION) tag = ""; + else if(hdr.protocol == -PROTOCOL_VERSION) tag = "(recorded on modded server) "; + } + s_sprintf(text)("%s%s", tag, hdr.desc); text[DHDR_DESCCHARS - 1] = '\0'; return newstring(text); } diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index b710319f..cc7013ff 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -219,7 +219,7 @@ char msgsizelookup(int msg) const char *genpwdhash(const char *name, const char *pwd, int salt) { static string temp; - s_sprintf(temp)("%s %d %s %s %d", pwd, salt, name, pwd, PROTOCOL_VERSION); + s_sprintf(temp)("%s %d %s %s %d", pwd, salt, name, pwd, abs(PROTOCOL_VERSION)); tiger::hashval hash; tiger::hash((uchar *)temp, (int)strlen(temp), hash); s_sprintf(temp)("%llx %llx %llx", hash.chunks[0], hash.chunks[1], hash.chunks[2]); diff --git a/source/src/protocol.h b/source/src/protocol.h index 23dc0436..eac19e8b 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -5,12 +5,15 @@ #define CUBE_SERVINFO_PORT_LAN 28762 #define CUBE_SERVINFO_PORT(serverport) (serverport+1) #define CUBE_SERVINFO_TO_SERV_PORT(servinfoport) (servinfoport-1) -#define PROTOCOL_VERSION 1129 // bump when protocol changes +#define PROTOCOL_VERSION 1129 // bump when protocol changes (use negative numbers for mods!) #define DEMO_VERSION 1 // bump when demo format changes #define DEMO_MAGIC "ASSAULTCUBE_DEMO" #define MAXMAPSENDSIZE 65536 #define MAXCFGFILESIZE 65536 +extern bool modprotocol; +#define CUR_PROTOCOL_VERSION (modprotocol ? -PROTOCOL_VERSION : PROTOCOL_VERSION) + // network messages codes, c2s, c2c, s2c enum { diff --git a/source/src/protos.h b/source/src/protos.h index edd5b61f..e9796e50 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -688,7 +688,7 @@ extern void filterservdesc(char *dst, const char *src, int len = sizeof(string)- extern void startintermission(); extern void restoreserverstate(vector &ents); extern uchar *retrieveservers(uchar *buf, int buflen); -extern 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); +extern 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); extern char msgsizelookup(int msg); extern const char *genpwdhash(const char *name, const char *pwd, int salt); extern void servermsinit(const char *master, const char *ip, int serverport, bool listen); diff --git a/source/src/server.cpp b/source/src/server.cpp index 7269c397..b5ac9628 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -16,6 +16,10 @@ #define DEBUGCOND (true) +#define SERVER_PROTOCOL_VERSION (PROTOCOL_VERSION) // server without any gameplay modification +//#define SERVER_PROTOCOL_VERSION (-PROTOCOL_VERSION) // server with gameplay modification but compatible to vanilla client (using /modconnect) +//#define SERVER_PROTOCOL_VERSION (PROTOCOL_VERSION) // server with incompatible protocol (change PROTOCOL_VERSION in file protocol.h to a negative number!) + void resetmap(const char *newname, int newmode, int newtime = -1, bool notify = true); void disconnect_client(int n, int reason = -1); int clienthasflag(int cn); @@ -773,7 +777,7 @@ void setupdemorecord() demoheader hdr; memcpy(hdr.magic, DEMO_MAGIC, sizeof(hdr.magic)); hdr.version = DEMO_VERSION; - hdr.protocol = PROTOCOL_VERSION; + hdr.protocol = SERVER_PROTOCOL_VERSION; endianswap(&hdr.version, sizeof(int), 1); endianswap(&hdr.protocol, sizeof(int), 1); memset(hdr.desc, 0, DHDR_DESCCHARS); @@ -898,7 +902,7 @@ void setupdemoplayback() endianswap(&hdr.version, sizeof(int), 1); endianswap(&hdr.protocol, sizeof(int), 1); if(hdr.version!=DEMO_VERSION) s_sprintf(msg)("demo \"%s\" requires an %s version of AssaultCube", file, hdr.versionaddress, &mnum, &msend, &mrec, &cnum, &csend, &crec); + serverms(smode, numclients(), minremain, smapname, servmillis, serverhost->address, &mnum, &msend, &mrec, &cnum, &csend, &crec, SERVER_PROTOCOL_VERSION); if(autoteam && m_teammode && !m_arena && !interm && servmillis - lastfillup > 5000 && refillteams()) lastfillup = servmillis; @@ -3937,6 +3941,7 @@ void localdisconnect() void localconnect() { + modprotocol = false; client &c = addclient(); c.type = ST_LOCAL; c.role = CR_ADMIN; @@ -3957,7 +3962,7 @@ void initserver(bool dedicated) else s_sprintf(identity)("[%s|%d]", scl.ip[0] ? scl.ip : "local", scl.serverport); logger = newlogger(identity, scl.syslogfacility); if(dedicated) logger->open(); // log on ded servers only - logger->writeline(log::info, "logging local AssaultCube server (version %d, protocol %d/%d, logident %s(%d)) now..", AC_VERSION, PROTOCOL_VERSION, EXT_VERSION, identity, scl.syslogfacility); + logger->writeline(log::info, "logging local AssaultCube server (version %d, protocol %d/%d, logident %s(%d)) now..", AC_VERSION, SERVER_PROTOCOL_VERSION, EXT_VERSION, identity, scl.syslogfacility); if((isdedicated = dedicated)) { diff --git a/source/src/serverms.cpp b/source/src/serverms.cpp index af648b61..69e7020a 100644 --- a/source/src/serverms.cpp +++ b/source/src/serverms.cpp @@ -156,7 +156,7 @@ uchar *retrieveservers(uchar *buf, int buflen) ENetSocket pongsock = ENET_SOCKET_NULL, lansock = ENET_SOCKET_NULL; 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) +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); @@ -165,7 +165,7 @@ void serverms(int mode, int numplayers, int minremain, char *smapname, int milli ENET_SOCKETSET_EMPTY(sockset); ENetSocket maxsock = pongsock; ENET_SOCKETSET_ADD(sockset, pongsock); - if(lansock != ENET_SOCKET_NULL) + if(lansock != ENET_SOCKET_NULL) { maxsock = max(maxsock, lansock); ENET_SOCKETSET_ADD(sockset, lansock); @@ -197,7 +197,7 @@ void serverms(int mode, int numplayers, int minremain, char *smapname, int milli extern struct servercommandline scl; extern string servdesc_current; (*mnum)++; *mrec += len; std = true; - putint(po, PROTOCOL_VERSION); + putint(po, protocol_version); putint(po, mode); putint(po, numplayers); putint(po, minremain);