From f66f445506ceac6701c0c062401129c4ffc9dded Mon Sep 17 00:00:00 2001 From: Rafael Barreto Date: Sun, 6 Jun 2010 19:05:42 +0000 Subject: [PATCH] vote reason implemented for kick/ban git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5151 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- config/admin.cfg | 4 ++-- config/docs.cfg | 4 ++++ source/src/clientgame.cpp | 34 ++++++++++++++++++++++++++-------- source/src/clients2c.cpp | 9 +++++++++ source/src/server.cpp | 15 +++++++++++++-- source/src/serveractions.h | 12 ++++++------ 6 files changed, 60 insertions(+), 18 deletions(-) diff --git a/config/admin.cfg b/config/admin.cfg index ccb9d15c..6d07e588 100644 --- a/config/admin.cfg +++ b/config/admin.cfg @@ -1,5 +1,5 @@ -alias kick [ callvote 0 $arg1 ] -alias ban [ callvote 1 $arg1 ] +alias kick [ callvote 0 $arg1 $arg2 ] +alias ban [ callvote 1 $arg1 $arg2 ] alias removebans [ callvote 2 $arg1 ] alias mastermode [ callvote 3 $arg1 ] alias autoteam [ callvote 4 $arg1 ] diff --git a/config/docs.cfg b/config/docs.cfg index 5a56c448..668f42eb 100644 --- a/config/docs.cfg +++ b/config/docs.cfg @@ -3276,6 +3276,8 @@ docident [ban] [Temporary ban of the specified player from the server.]; docargument [CN] [The player to ban] [Client number] [0]; +docargument [R] [The reason for this vote] [] [0]; + docremark [Temporary ban duration is fixed at 20 minutes.]; @@ -3322,6 +3324,8 @@ docident [kick] [Kicks the specified player from the server.]; docargument [CN] [The player to kick] [Client number] [0]; +docargument [R] [The reason for this vote] [] [0]; + docident [listfavcats] [List all registered serverbrowser favourites categories]; diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 16f4f402..28e39e1f 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -980,7 +980,7 @@ COMMAND(dropflag, ARG_NONE); char *votestring(int type, char *arg1, char *arg2) { - const char *msgs[] = { "kick player %s", "ban player %s", "remove all bans", "set mastermode to %s", "%s autoteam", "force player %s to the enemy team", "give admin to player %s", "load map %s in mode %s", "%s demo recording for the next match", "stop demo recording", "clear all demos", "set server description to '%s'", "shuffle teams"}; + const char *msgs[] = { "kick player %s, reason: %s", "ban player %s, reason: %s", "remove all bans", "set mastermode to %s", "%s autoteam", "force player %s to the enemy team", "give admin to player %s", "load map %s in mode %s", "%s demo recording for the next match", "stop demo recording", "clear all demos", "set server description to '%s'", "shuffle teams"}; const char *msg = msgs[type]; char *out = newstring(MAXSTRLEN); out[MAXSTRLEN] = '\0'; @@ -994,7 +994,8 @@ char *votestring(int type, char *arg1, char *arg2) int cn = atoi(arg1); playerent *p = (cn == getclientnum() ? player1 : getclient(cn)); if(!p) break; - formatstring(out)(msg, colorname(p)); + if ( SA_KICK || SA_BAN ) formatstring(out)(msg, colorname(p), arg2); + else formatstring(out)(msg, colorname(p)); break; } case SA_MASTERMODE: @@ -1044,6 +1045,11 @@ void callvote(int type, char *arg1, char *arg2) putint(p, v->type); switch(v->type) { + case SA_KICK: + case SA_BAN: + putint(p, atoi(arg1)); + sendstring(arg2, p); + break; case SA_MAP: sendstring(arg1, p); putint(p, nextmode); @@ -1069,13 +1075,25 @@ void scallvote(char *type, char *arg1, char *arg2) if(type && inmainloop) { int t = atoi(type); - if(t==SA_MAP) // FIXME - { - string n; - itoa(n, nextmode); - callvote(t, arg1, n); + switch (t) { + case SA_MAP: // FIXME + { + string n; + itoa(n, nextmode); + callvote(t, arg1, n); + break; + } + case SA_KICK: + case SA_BAN: + { + if ( !arg2 || strlen(arg2) <= 3 ) { + conoutf(_("\f3invalid reason")); + break; + } + } + default: + callvote(t, arg1, arg2); } - else callvote(t, arg1, arg2); } } diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index b5980afb..25cb6f9d 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -1025,6 +1025,15 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) itoa(a, getint(p)); v = newvotedisplayinfo(d, type, text, a); break; + case SA_KICK: + case SA_BAN: + { + itoa(a, getint(p)); + getstring(text, p); + filtertext(text, text); + v = newvotedisplayinfo(d, type, a, text); + break; + } case SA_SERVERDESC: getstring(text, p); filtertext(text, text); diff --git a/source/src/server.cpp b/source/src/server.cpp index c9260808..293a9cb8 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -53,6 +53,7 @@ servermapbuffer mapbuffer; // cmod char *global_name; int clientnumber = 0; +int cn2boot; bool valid_client(int cn) { @@ -2943,11 +2944,21 @@ void process(ENetPacket *packet, int sender, int chan) break; } case SA_KICK: - vi->action = new kickaction(getint(p)); + { + cn2boot = getint(p); + getstring(text, p); + filtertext(text, text); + vi->action = new kickaction(cn2boot, newstring(text)); break; + } case SA_BAN: - vi->action = new banaction(getint(p)); + { + cn2boot = getint(p); + getstring(text, p); + filtertext(text, text); + vi->action = new banaction(cn2boot, newstring(text)); break; + } case SA_REMBANS: vi->action = new removebansaction(); break; diff --git a/source/src/serveractions.h b/source/src/serveractions.h index d58e691b..07a37cd6 100644 --- a/source/src/serveractions.h +++ b/source/src/serveractions.h @@ -183,14 +183,14 @@ struct kickaction : playeraction bool wasvalid; void perform() { disconnect(DISC_MKICK); } virtual bool isvalid() { return wasvalid || playeraction::isvalid(); } - kickaction(int cn) : playeraction(cn) + kickaction(int cn, char *reason) : playeraction(cn) { wasvalid = false; role = roleconf('K'); - if(isvalid()) + if(isvalid() && strlen(reason) > 3) { wasvalid = true; - formatstring(desc)("kick player %s", clients[cn]->name); + formatstring(desc)("kick player %s, reason: %s", clients[cn]->name, reason); } } }; @@ -205,14 +205,14 @@ struct banaction : playeraction disconnect(DISC_MBAN); } virtual bool isvalid() { return wasvalid || playeraction::isvalid(); } - banaction(int cn) : playeraction(cn) + banaction(int cn, char *reason) : playeraction(cn) { wasvalid = false; role = roleconf('B'); - if(isvalid()) + if(isvalid() && strlen(reason) > 3) { wasvalid = true; - formatstring(desc)("ban player %s", clients[cn]->name); + formatstring(desc)("ban player %s, reason: %s", clients[cn]->name, reason); } } };