From 4c21d09122fbcf31e9d52f09cbd3591df3c556e4 Mon Sep 17 00:00:00 2001 From: driAn Date: Sat, 25 Nov 2006 21:18:31 +0000 Subject: [PATCH] mastermode wip! coloured messages \fx git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@729 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/client.cpp | 4 +-- source/src/clientextras.cpp | 2 +- source/src/clientgame.cpp | 20 +++++++++----- source/src/clients2c.cpp | 2 +- source/src/console.cpp | 2 +- source/src/protocol.h | 6 ++-- source/src/protos.h | 2 +- source/src/renderextras.cpp | 14 ---------- source/src/rendertext.cpp | 9 +++++- source/src/server.cpp | 55 +++++++++++++++++++++++++++++++++---- source/src/serverutil.cpp | 2 +- 11 files changed, 81 insertions(+), 37 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index 3099a3b3..002b28fb 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -179,7 +179,7 @@ void trydisconnect() disconnect(0, !disconnecting); }; -void toserver(char *text) { conoutf("%s:\f %s", player1->name, text); addmsg(SV_TEXT, "rs", text); }; +void toserver(char *text) { conoutf("%s:\f0 %s", player1->name, text); addmsg(SV_TEXT, "rs", text); }; void echo(char *text) { conoutf("%s", text); }; void lanconnect() @@ -383,7 +383,7 @@ void gets2c() // get updates from the server case ENET_EVENT_TYPE_DISCONNECT: extern char *disc_reasons[]; if(event.data>DISC_MAXCLIENTS) event.data = DISC_NONE; - if(!disconnecting || event.data) conoutf("\fserver network error, disconnecting (%s) ...", disc_reasons[event.data]); + if(!disconnecting || event.data) conoutf("\f3server network error, disconnecting (%s) ...", disc_reasons[event.data]); disconnect(); return; diff --git a/source/src/clientextras.cpp b/source/src/clientextras.cpp index a6571bcb..020c04fe 100644 --- a/source/src/clientextras.cpp +++ b/source/src/clientextras.cpp @@ -89,7 +89,7 @@ int menu = 0; void renderscore(playerent *d) { s_sprintfd(lag)("%d", d->plag); - s_sprintfd(name) ("(%s)", d->name); + s_sprintfd(name) ("(%s)", d->name); if(m_ctf) s_sprintf(scorelines.add().s)("%d\t%d\t%s\t%d\t%s\t%s", d->flagscore, d->frags, d->state==CS_LAGGED ? "LAG" : lag, d->ping, d->team, d->state==CS_DEAD ? name : d->name); else s_sprintf(scorelines.add().s)("%d\t%s\t%d\t%s\t%s", d->frags, d->state==CS_LAGGED ? "LAG" : lag, d->ping, m_teammode ? d->team : "", d->state==CS_DEAD ? name : d->name); menumanual(menu, scorelines.length()-1, scorelines.last().s); diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 539b1528..21c31976 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -34,7 +34,7 @@ char *getclientmap() { return clientmap; }; extern bool c2sinit; extern int dblend; -int setskin(playerent *pl, int skin) +void setskin(playerent *pl, int skin) { if(!pl) return; int maxskin = rb_team_int(pl->team) == TEAM_CLA ? 3 : 5; @@ -659,14 +659,20 @@ void flagaction(int flag, int action) }; }; -void getmaster(char *pwd) +void setmaster(char *claim, char *password) { - if(!pwd[0]) return; - if(strlen(pwd)>15) { conoutf("the master password has a maximum length of 15 characters"); return; }; - addmsg(SV_GETMASTER, "rs", pwd); + int c = atoi(claim); + if(c < 0 || c > 1) return; + + if(password[0]) + { + if(strlen(password) > 15) { conoutf("the master password has a maximum length of 15 characters"); return; } + else addmsg(SV_SETMASTERLOGIN, "ris", c, password); + } + else addmsg(SV_SETMASTER, "ri", c); }; -void mastercommand(int cmd, int a) +void mastercommand(int cmd, int a) // one of MCMD_* { addmsg(SV_MASTERCMD, "rii", cmd, a); }; @@ -683,6 +689,6 @@ void showmastermenu(int m) // 0=kick, 1=ban menuset(menu); }; -COMMANDN(masterlogin, getmaster, ARG_1STR); +COMMAND(setmaster, ARG_2STR); COMMAND(mastercommand, ARG_2INT); COMMAND(showmastermenu, ARG_1INT); diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 6de713d4..2fa97102 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -138,7 +138,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) case SV_TEXT: if(!d) return; getstring(text, p); - conoutf("%s:\f %s", d->name, &text); + conoutf("%s:\f0 %s", d->name, &text); break; case SV_MAPCHANGE: diff --git a/source/src/console.cpp b/source/src/console.cpp index 631ba5d1..65d8b5ec 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -29,7 +29,7 @@ void conline(const char *sf, bool highlight) // add a line to the console conlines.insert(0,cl); if(highlight) // show line in a different colour, for chat etc. { - cl.cref[0] = '\f'; + cl.cref[0] = '\f0'; cl.cref[1] = 0; s_strcat(cl.cref, sf); } diff --git a/source/src/protocol.h b/source/src/protocol.h index b1688d87..aeca54c3 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -18,16 +18,16 @@ enum SV_SENDMAP, SV_RECVMAP, SV_SERVMSG, SV_ITEMLIST, SV_WEAPCHANGE, SV_MODELSKIN, SV_FLAGPICKUP, SV_FLAGDROP, SV_FLAGRETURN, SV_FLAGSCORE, SV_FLAGINFO, SV_FLAGS, //EDIT: AH - SV_GETMASTER, SV_MASTERCMD, + SV_SETMASTER, SV_SETMASTERLOGIN, SV_MASTERCMD, SV_PWD, SV_CLIENT, }; -enum { MCMD_KICK = 0, MCMD_BAN, MCMD_REMBANS }; +enum { MCMD_KICK = 0, MCMD_BAN, MCMD_REMBANS, MCMD_MASTERMODE }; #define DMF 16.0f #define DAF 1.0f #define DVF 100.0f -enum { DISC_NONE = 0, DISC_EOP, DISC_CN, DISC_MKICK, DISC_MBAN, DISC_TAGT, DISC_BANREFUSE, DISC_WRONGPW, DISC_MLOGINFAIL, DISC_MAXCLIENTS }; +enum { DISC_NONE = 0, DISC_EOP, DISC_CN, DISC_MKICK, DISC_MBAN, DISC_TAGT, DISC_BANREFUSE, DISC_WRONGPW, DISC_MLOGINFAIL, DISC_MAXCLIENTS, DISC_MASTERMODE }; diff --git a/source/src/protos.h b/source/src/protos.h index 339601e0..045b3861 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -110,7 +110,7 @@ extern void timeupdate(int timeremain); extern void fixcamerarange(physent *cam = camera1); extern void respawnself(); // EDIT: AH extern void ctf_death(); -extern int setskin(playerent *pl, int skin); +extern void setskin(playerent *pl, int skin); //game mode extras extern void arenarespawn(); extern void respawn(); diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index aad66ec0..5d835b74 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -301,20 +301,6 @@ void damageblend(int n) { dblend += n; }; VARP(hidestats, 0, 1, 1); VARP(crosshairfx, 0, 1, 1); -/*VAR(scopefov, 5, 50, 50); -bool scoped = false; -int oldfov = 100; - -void togglescope(bool deactivate) -{ - if(player1->gunselect==GUN_SNIPER) - { - if(!scoped) oldfov = getvar("fov"); - scoped = !scoped; - setvar("fov", scoped ? scopefov : oldfov); - } -}*/ - void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater) { readmatrices(); diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index 1c703c6d..72e5c50d 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -158,7 +158,14 @@ void draw_text(const char *str, int left, int top) { int c = str[i]; if(c=='\t') { x = (x-left+PIXELTAB)/PIXELTAB*PIXELTAB+left; continue; }; - if(c=='\f') { glColor3ub(64,255,128); continue; }; + if(c=='\f') switch(str[i+1]) + { + case '0': glColor3ub(64,255,128); i++; continue; // green: player talk + case '1': glColor3ub(96,160,255); i++; continue; // blue: "echo" command + case '2': glColor3ub(255,192,64); i++; continue; // yellow: gameplay messages + case '3': glColor3ub(255,64,64); i++; continue; // red: important errors + default: continue; // white: everything else + }; if(c==' ') { x += FONTH/2; continue; }; c -= 33; if(c<0 || c>=95) continue; diff --git a/source/src/server.cpp b/source/src/server.cpp index 399cbbc2..e3fa04ff 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -7,6 +7,9 @@ #define valid_flag(f) (f >= 0 && f < 2) enum { ST_EMPTY, ST_LOCAL, ST_TCPIP }; +enum { MM_OPEN, MM_PRIVATE, MM_NUM }; + +int mastermode = MM_OPEN; struct clientscore { @@ -311,7 +314,7 @@ void sendservmsg(char *msg, int client=-1) sendf(client, 1, "ris", SV_SERVMSG, msg); }; -char *disc_reasons[] = { "normal", "end of packet", "client num", "kicked by master", "banned by master", "tag type", "connection refused due to ban", "wrong password", "failed master login", "server FULL (maxclients)"}; +char *disc_reasons[] = { "normal", "end of packet", "client num", "kicked by master", "banned by master", "tag type", "connection refused due to ban", "wrong password", "failed master login", "server FULL (maxclients)", "server mastermode is \"private\"" }; void disconnect_client(int n, int reason = -1) { @@ -487,7 +490,7 @@ bool isbanned(int cn) return false; }; -void getmaster(int sender, char *pwd) +/*void getmaster(int sender, char *pwd) { if(!pwd[0] || !isdedicated) return; if(masterpasswd && !strcmp(masterpasswd, pwd)) @@ -496,6 +499,29 @@ void getmaster(int sender, char *pwd) sendservmsg("master login successful", sender); } else disconnect_client(sender, DISC_MLOGINFAIL); +};*/ + +int master() +{ + loopv(clients) if(clients[i]->type!=ST_EMPTY && clients[i]->ismaster) return i; + return -1; +}; + +void setmaster(int client, bool claim, char *pwd = NULL) +{ + if(!isdedicated || !valid_client(client)) return; + + int curmaster = master(); + if((curmaster == -1 || curmaster == client) || (pwd && pwd[0] && masterpasswd && !strcmp(masterpasswd, pwd))) + { + if(claim) sendservmsg("you claimed the master status", client); + else if(clients[client]->ismaster) sendservmsg("you gave up the master status", client); + loopv(clients) if(clients[i]->type!=ST_EMPTY) clients[i]->ismaster = (i == client); + } + else if(pwd && pwd[0]) + { + disconnect_client(client, DISC_MLOGINFAIL); // avoid brute-force + }; }; void mastercmd(int sender, int cmd, int a) @@ -526,6 +552,14 @@ void mastercmd(int sender, int cmd, int a) sendservmsg("bans removed"); break; }; + case MCMD_MASTERMODE: + { + if(a < 0 || a >= MM_NUM) return; + mastermode = a; + s_sprintfd(msg)("mastermode set to %i", mastermode); + sendservmsg(msg); + break; + }; }; }; @@ -751,10 +785,19 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 break; }; - case SV_GETMASTER: - getstring(text, p); - getmaster(sender, text); + case SV_SETMASTER: + { + setmaster(sender, getint(p) != 0); break; + }; + + case SV_SETMASTERLOGIN: + { + bool claim = getint(p) != 0; + getstring(text, p); + setmaster(sender, claim, text); + break; + }; case SV_MASTERCMD: { @@ -871,10 +914,12 @@ void resetserverifempty() loopv(clients) if(clients[i]->type!=ST_EMPTY) return; //clients.setsize(0); resetmap("", 0, 10, false); + mastermode == MM_OPEN; }; int refuseconnect(int i) { + if(mastermode == MM_PRIVATE) return DISC_MASTERMODE; if(valid_client(i) && isbanned(i)) return DISC_BANREFUSE; return DISC_NONE; }; diff --git a/source/src/serverutil.cpp b/source/src/serverutil.cpp index f67c93f3..a578f24e 100644 --- a/source/src/serverutil.cpp +++ b/source/src/serverutil.cpp @@ -94,7 +94,7 @@ char msgsizesl[] = // size inclusive message token, 0 for variable SV_SENDMAP, 0, SV_RECVMAP, 1, SV_SERVMSG, 0, SV_ITEMLIST, 0, SV_WEAPCHANGE, 2, SV_MODELSKIN, 2, SV_FLAGPICKUP, 2, SV_FLAGDROP, 2, SV_FLAGRETURN, 2, SV_FLAGSCORE, 2, SV_FLAGINFO, 0, SV_FLAGS, 2, // EDIT: AH - SV_GETMASTER, 0, SV_MASTERCMD, 3, + SV_SETMASTER, 2, SV_SETMASTERLOGIN, 0, SV_MASTERCMD, 3, SV_PWD, 0, SV_CLIENT, 0, -1