From ac267c7549bbe1f37975dd4ef9b959b7f1dc036a Mon Sep 17 00:00:00 2001 From: driAn Date: Sun, 4 May 2008 20:27:35 +0000 Subject: [PATCH] demo playback only locally, execution environments git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1876 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/clientgame.cpp | 2 +- source/src/protocol.h | 3 ++- source/src/server.cpp | 14 ++++++++------ source/src/serveractions.h | 20 ++++++++++++++------ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 8e1e3b88..344adc17 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -754,7 +754,7 @@ void callvotesuc() void callvoteerr(int e) { if(e < 0 || e >= VOTEE_NUM) return; - const char *verr[VOTEE_NUM] = { "voting is currently disabled", "there is already a vote pending", "you have already voted", "you can't vote that often", "this vote is only available in multiplayer" }; + const char *verr[VOTEE_NUM] = { "voting is currently disabled", "there is already a vote pending", "you have already voted", "you can't vote that often", "this vote is not allowed in the current environment (singleplayer/multiplayer)" }; conoutf("\f3could not vote: %s", verr[e]); DELETEP(calledvote); } diff --git a/source/src/protocol.h b/source/src/protocol.h index be710e0e..055f9764 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -35,7 +35,7 @@ enum enum { SA_KICK = 0, SA_BAN, SA_REMBANS, SA_MASTERMODE, SA_AUTOTEAM, SA_FORCETEAM, SA_GIVEADMIN, SA_MAP, SA_RECORDDEMO, SA_STOPDEMO, SA_CLEARDEMOS, SA_NUM}; enum { VOTE_NEUTRAL = 0, VOTE_YES, VOTE_NO, VOTE_NUM }; -enum { VOTEE_DISABLED = 0, VOTEE_CUR, VOTEE_MUL, VOTEE_MAX, VOTEE_DED, VOTEE_NUM }; +enum { VOTEE_DISABLED = 0, VOTEE_CUR, VOTEE_MUL, VOTEE_MAX, VOTEE_AREA, VOTEE_NUM }; enum { MM_OPEN, MM_PRIVATE, MM_NUM }; #define DMF 16.0f @@ -56,6 +56,7 @@ enum { DISC_NONE = 0, DISC_EOP, DISC_CN, DISC_MKICK, DISC_MBAN, DISC_TAGT, DISC_ enum { + GMODE_DEMO = -3, GMODE_TEAMDEATHMATCH = 0, GMODE_COOPEDIT, GMODE_DEATHMATCH, diff --git a/source/src/server.cpp b/source/src/server.cpp index 71b08e30..09b6384d 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -1484,13 +1484,11 @@ bool vote(int sender, int vote) // true if the vote was placed successfully bool callvote(voteinfo *v) // true if a regular vote was called { if(!v || !v->isvalid() || v->action->role > clients[v->owner]->role) return false; + int area = isdedicated ? EE_DED_SERV : EE_LOCAL_SERV; + if(!(area & v->action->area)) sendf(v->owner, 1, "ri2", SV_CALLVOTEERR, VOTEE_AREA); // action now allowed in current area if(!isdedicated) { - if(v->action->dedicated) // available on ded servers only - { - sendf(v->owner, 1, "ri2", SV_CALLVOTEERR, VOTEE_DED); - } - else if(clients[v->owner]->type == ST_LOCAL) // allow op commands locally + if(clients[v->owner]->type == ST_LOCAL) // allow op commands locally { v->action->perform(); } @@ -2008,10 +2006,14 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 switch(getint(p)) { case SA_MAP: + { getstring(text, p); filtertext(text, text); - vi->action = new mapaction(newstring(text), getint(p)); + int mode = getint(p); + if(mode==GMODE_DEMO) vi->action = new demoplayaction(text); + else vi->action = new mapaction(newstring(text), mode); break; + } case SA_KICK: vi->action = new kickaction(getint(p)); break; diff --git a/source/src/serveractions.h b/source/src/serveractions.h index 3f566ed8..9bb3a1e9 100644 --- a/source/src/serveractions.h +++ b/source/src/serveractions.h @@ -1,13 +1,15 @@ // available server actions +enum { EE_LOCAL_SERV = 1, EE_DED_SERV = 1<<1 }; // execution environment + struct serveraction { int role; // required client role - bool dedicated; // only on ded servers + int area; // only on ded servers virtual ~serveraction() {} virtual void perform() = 0; virtual bool isvalid() { return true; } - serveraction() : role(CR_DEFAULT), dedicated(true) {} + serveraction() : role(CR_DEFAULT), area(EE_DED_SERV) {} }; struct mapaction : serveraction @@ -15,13 +17,19 @@ struct mapaction : serveraction char *map; int mode; void perform() { resetmap(map, mode); } - mapaction(char *map, int mode) : map(map), mode(mode) - { - dedicated = false; - } + bool isvalid() { return serveraction::isvalid() && mode != GMODE_DEMO; } + mapaction(char *map, int mode) : map(map), mode(mode) { area |= EE_LOCAL_SERV; } // local too ~mapaction() { DELETEA(map); } }; +struct demoplayaction : serveraction +{ + char *map; + void perform() { resetmap(map, GMODE_DEMO); } + demoplayaction(char *map) : map(map) { area = EE_LOCAL_SERV; } // only local + ~demoplayaction() { DELETEA(map); } +}; + struct playeraction : serveraction { int cn;