From 758aec9aea2dd65cfca2bb19ba71e1577ea400c9 Mon Sep 17 00:00:00 2001 From: driAn Date: Wed, 20 Sep 2006 19:33:23 +0000 Subject: [PATCH] no message git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@414 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/client.cpp | 10 +++- source/src/clientgame.cpp | 17 +++++++ source/src/clients2c.cpp | 7 --- source/src/cube.h | 1 + source/src/main.cpp | 7 +-- source/src/protos.h | 2 +- source/src/server.cpp | 98 ++++++++++++++++++++++++++++----------- source/src/serverutil.cpp | 8 ++-- 8 files changed, 106 insertions(+), 44 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index cf722687..1ffa7d6a 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -202,6 +202,8 @@ void sendpackettoserv(void *packet) else localclienttoserver((ENetPacket *)packet); } +extern string masterpwd; + void c2sinfo(dynent *d) // send update to the server { if(clientnum<0) return; // we haven't had a welcome message from the server yet @@ -239,7 +241,13 @@ void c2sinfo(dynent *d) // send update to the server putint(p, SV_WEAPCHANGE); putint(p, player1->gunselect); gun_changed = false; - } + }; + if(masterpwd[0]) + { + putint(p, SV_GETMASTER); + sendstring(masterpwd, p); + masterpwd[0] = 0; + }; if(senditemstoserver) { packet->flags = ENET_PACKET_FLAG_RELIABLE; diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 4f38c990..fa7916b5 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -686,3 +686,20 @@ void flagaction(int flag, int action) default: break; }; }; + +string masterpwd; + +void getmaster(char *pwd) +{ + if(!pwd[0]) return; + if(strlen(pwd)>15) { conoutf("the master password has a maximum length of 15 characters"); return; }; + strcpy_s(masterpwd, pwd); +}; + +void mastercommand(int cmd, int arg1) +{ + addmsg(1, 3, SV_MASTERCMD, cmd, arg1); +}; + +COMMAND(getmaster, ARG_1STR); +COMMAND(mastercommand, ARG_2INT); \ No newline at end of file diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 315b8802..10c77336 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -481,13 +481,6 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th break; }; -/* - case SV_EXT: // so we can messages without breaking previous clients/servers, if necessary - { - for(int n = getint(p); n; n--) getint(p); - break; - }; -*/ // Added by Rick: Bot specific messages case SV_BOTSOUND: { diff --git a/source/src/cube.h b/source/src/cube.h index fd83fbf6..83b27f95 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -313,6 +313,7 @@ enum SV_BOTFRAGS, SV_ADDBOT, SV_BOTUPDATE, SV_BOTCOMMAND, // End add SV_BOTITEMPICKUP, SV_BOT2CLIENTDMG, SV_DIEDBYBOT, + SV_GETMASTER, SV_MASTERCMD, SV_EXT, }; diff --git a/source/src/main.cpp b/source/src/main.cpp index bcc7a9bb..3b26c446 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -95,7 +95,6 @@ int framesinmap = 0; int main(int argc, char **argv) { - bool dedicated = false; int fs = SDL_FULLSCREEN, par = 0, uprate = 0, maxcl = 4; char *sdesc = "", *ip = "", *master = NULL, *passwd = "", *maprot = NULL; islittleendian = *((char *)&islittleendian); @@ -108,7 +107,6 @@ int main(int argc, char **argv) char *a = &argv[i][2]; if(argv[i][0]=='-') switch(argv[i][1]) { - case 'd': dedicated = true; break; case 't': fs = 0; break; case 'w': scr_w = atoi(a); break; case 'h': scr_h = atoi(a); break; @@ -117,8 +115,7 @@ int main(int argc, char **argv) case 'i': ip = a; break; case 'm': master = a; break; case 'p': passwd = a; break; - case 'c': maxcl = atoi(a); break; - case 'r': maprot = a; break; // EDIT: AH + case 'c': maxcl = atoi(a); break; //EDIT: AH default: conoutf("unknown commandline option"); } else conoutf("unknown commandline argument"); @@ -135,7 +132,7 @@ int main(int argc, char **argv) if(enet_initialize()<0) fatal("Unable to initialise network module"); initclient(); - initserver(dedicated, uprate, sdesc, ip, master, passwd, maxcl, maprot); // never returns if dedicated + initserver(false, uprate, sdesc, ip, master, passwd, maxcl, NULL, NULL); // never returns if dedicated log("world"); empty_world(7, true); diff --git a/source/src/protos.h b/source/src/protos.h index 66920a24..093daee0 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -223,7 +223,7 @@ extern void rendermd3gun(); extern void loadweapons(); // server -extern void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, char *passwd, int maxcl, char *maprot); // EDIT: AH +extern void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, char *passwd, int maxcl, char *maprot, char *masterpwd); // EDIT: AH extern void cleanupserver(); extern void localconnect(); extern void localdisconnect(); diff --git a/source/src/server.cpp b/source/src/server.cpp index c84dd326..68338985 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -4,8 +4,7 @@ #include "cube.h" #define m_ctf_s (mode==5) -#define m_teammode_s (gamemode==0 || gamemode==4 || gamemode==5) -#define m_notimelimit_s (mode==1) +#define m_teammode_s (mode==0 || mode==4 || mode==5) enum { ST_EMPTY, ST_LOCAL, ST_TCPIP }; @@ -18,12 +17,15 @@ struct client // server side version of "dynent" type string name; int modevote; // Added by Rick: For bot voting +#ifndef STANDALONE bool addbot, kickbot, changebotskill; short botcount; string botteam, botname; short botskill; bool kickallbots; +#endif // End add + bool ismaster; }; vector clients; @@ -31,6 +33,9 @@ vector clients; int maxclients = 8; string smapname; +char *masterpasswd = NULL; +enum { MCMD_KICK = 0, MCMD_BAN }; + int numclients() { int num = 0; @@ -148,7 +153,7 @@ void ctfreset(bool send=true) }; } -void sendservmsg(char *msg) +void sendservmsg(char *msg, int client=-1) { ENetPacket *packet = enet_packet_create(NULL, _MAXDEFSTR+10, ENET_PACKET_FLAG_RELIABLE); uchar *start = packet->data; @@ -157,16 +162,19 @@ void sendservmsg(char *msg) sendstring(msg, p); *(ushort *)start = ENET_HOST_TO_NET_16(p-start); enet_packet_resize(packet, p-start); - multicast(packet, -1); + if(client==-1) multicast(packet, -1); else send(client, packet); if(packet->referenceCount==0) enet_packet_destroy(packet); }; void disconnect_client(int n, char *reason) { if(n<0 || n>=clients.length()) return; - printf("disconnecting client (%s) [%s]\n", clients[n].hostname, reason); + sprintf_sd(clientreason)("server closed the connection: %s", reason); + sendservmsg(clientreason, n); enet_peer_disconnect(clients[n].peer); + printf("disconnecting client (%s) [%s]\n", clients[n].hostname, reason); clients[n].type = ST_EMPTY; + clients[n].ismaster = false; send2(true, -1, SV_CDIS, n); }; @@ -294,8 +302,10 @@ bool vote(char *map, int reqmode, int sender) return true; }; +//fixmebot // Added by Rick: Vote for bot commands +#ifndef STANDALONE void resetbotvotes() { loopv(clients) @@ -313,7 +323,6 @@ void resetbotvotes() bool addbotvote(int count, char *team, int skill, char *name, int sender) { -#ifndef STANDALONE clients[sender].addbot = true; clients[sender].kickbot = false; clients[sender].changebotskill = false; @@ -361,10 +370,11 @@ bool addbotvote(int count, char *team, int skill, char *name, int sender) if(yes/(float)(yes+no) <= 0.5f) return false; sendservmsg("vote passed"); resetbotvotes(); -#endif + return true; }; + bool kickbotvote(int specific, char *name, int sender) { clients[sender].addbot = false; @@ -411,7 +421,6 @@ bool kickbotvote(int specific, char *name, int sender) bool botskillvote(int skill, int sender) { -#ifndef STANDALONE clients[sender].addbot = false; clients[sender].kickbot = false; clients[sender].changebotskill = true; @@ -434,7 +443,6 @@ bool botskillvote(int skill, int sender) if(yes/(float)(yes+no) <= 0.5f) return false; sendservmsg("vote passed"); resetbotvotes(); -#endif return true; }; @@ -452,7 +460,6 @@ void botcommand(uchar *&p, char *text, int sender) strcpy(team, text); sgetstr(); strcpy(name, text); -#ifndef STANDALONE if (addbotvote(count, team, skill, name, sender)) { while(count>0) @@ -461,7 +468,6 @@ void botcommand(uchar *&p, char *text, int sender) count--; } } -#endif break; } case COMMAND_KICKBOT: @@ -470,7 +476,7 @@ void botcommand(uchar *&p, char *text, int sender) if (specific) sgetstr(); -#ifndef STANDALONE + if (kickbotvote(specific, text, sender)) { if (specific) @@ -478,23 +484,21 @@ void botcommand(uchar *&p, char *text, int sender) else kickallbots(); } -#endif } case COMMAND_BOTSKILL: { int skill = getint(p); -#ifndef STANDALONE if (botskillvote(skill, sender)) { BotManager.ChangeBotSkill(skill, NULL); } -#endif } } } - +#endif // End add + // force map change, EDIT: AH void changemap() { @@ -510,6 +514,34 @@ void changemap() if(packet->referenceCount==0) enet_packet_destroy(packet); }; +void getmaster(int sender, char *pwd) +{ + if(!pwd[0] || !isdedicated) return; + if(masterpasswd && !strcmp(masterpasswd, pwd)) clients[sender].ismaster = true; + else disconnect_client(sender, "failed master login"); +}; + +void mastercmd(int sender, int cmd, int arg1) +{ + if(!isdedicated) return; + if(clients[sender].ismaster==false) disconnect_client(sender, "access to master commands denied"); + switch(cmd) + { + case MCMD_KICK: + { + if(arg1 < 0 && arg1 >= clients.length()) return; + disconnect_client(sender, "you were kicked from the server"); + break; + }; + case MCMD_BAN: + { + if(arg1 < 0 && arg1 >= clients.length()) return; + disconnect_client(sender, "you were kicked from the server and banned for 20 minutes"); + break; + }; + }; +}; + // server side processing of updates: does very little and most state is tracked client only // could be extended to move more gameplay to server (at expense of lag) @@ -625,8 +657,10 @@ void process(ENetPacket * packet, int sender) // sender may be -1 case SV_RECVMAP: send(sender, recvmap(sender)); return; - + + // Added by Rick: Bot specifc messages +#ifndef STANDALONE case SV_ADDBOT: getint(p); sgetstr(); @@ -639,7 +673,9 @@ void process(ENetPacket * packet, int sender) // sender may be -1 botcommand(p, text, sender); break; } +#endif // End add by Rick + // EDIT: AH case SV_FLAGPICKUP: @@ -699,13 +735,18 @@ void process(ENetPacket * packet, int sender) // sender may be -1 break; }; -/* - case SV_EXT: // allows for new features that require no server updates - { - for(int n = getint(p); n; n--) getint(p); - break; - }; -*/ + case SV_GETMASTER: + { + sgetstr(); + getmaster(sender, text); + break; + }; + + case SV_MASTERCMD: + { + mastercmd(sender, getint(p), getint(p)); + break; + }; default: { @@ -785,7 +826,9 @@ void resetserverifempty() clients.setsize(0); smapname[0] = 0; resetvotes(); - resetbotvotes(); // Added by Rick +#ifndef STANDALONE + resetbotvotes(); // Added by Rick +#endif resetitems(); mode = 0; mapreload = false; @@ -933,7 +976,7 @@ void localconnect() send_welcome(&c-&clients[0]); }; -void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, char *passwd, int maxcl, char *maprot) // EDIT: AH +void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, char *passwd, int maxcl, char *maprot, char *masterpwd) // EDIT: AH { serverpassword = passwd; maxclients = maxcl; @@ -946,8 +989,9 @@ void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, serverhost = enet_host_create(&address, MAXCLIENTS, 0, uprate); if(!serverhost) fatal("could not create server host\n"); loopi(MAXCLIENTS) serverhost->peers[i].data = (void *)-1; - if(!maprot) maprot = newstring("config/maprot.cfg"); + if(!maprot || !maprot[0]) maprot = newstring("config/maprot.cfg"); readscfg(path(maprot)); // EDIT: AH + if(!masterpwd || !masterpwd[0]) masterpasswd = masterpwd; }; resetserverifempty(); diff --git a/source/src/serverutil.cpp b/source/src/serverutil.cpp index c55b7f9c..9be64594 100644 --- a/source/src/serverutil.cpp +++ b/source/src/serverutil.cpp @@ -66,6 +66,7 @@ char msgsizesl[] = // size inclusive message token, 0 for variable SV_BOTFRAGS, 3, SV_ADDBOT, 5, SV_BOTUPDATE, 12, SV_BOTCOMMAND, 0, // End add SV_BOTITEMPICKUP, 3, SV_BOT2CLIENTDMG, 5, SV_DIEDBYBOT, 2, + SV_GETMASTER, 0, SV_MASTERCMD, 3, SV_EXT, 0, -1 }; @@ -117,7 +118,7 @@ void *alloc(int s) { void *b = calloc(1,s); if(!b) fatal("no memory!"); return b int main(int argc, char* argv[]) // EDIT: AH { int uprate = 0, maxcl = 4; - char *sdesc = "", *ip = "", *master = NULL, *passwd = "", *maprot = ""; + char *sdesc = "", *ip = "", *master = NULL, *passwd = "", *maprot = "", *masterpwd = NULL; for(int i = 1; i