From eb23c4546eef93773e819a73c4e30f00189f1eb2 Mon Sep 17 00:00:00 2001 From: driAn Date: Sun, 8 Oct 2006 11:57:33 +0000 Subject: [PATCH] no message git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@426 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/doc/classes | 112 ----------- source/enet/protocol.c | 2 +- source/src/client.cpp | 15 +- source/src/clientextras.cpp | 2 +- source/src/clientgame.cpp | 22 ++- source/src/clients2c.cpp | 33 +++- source/src/console.cpp | 2 +- source/src/cube.h | 7 +- source/src/entities.cpp | 2 +- source/src/main.cpp | 11 ++ source/src/menus.cpp | 18 +- source/src/protos.h | 4 +- source/src/renderextras.cpp | 6 +- source/src/server.cpp | 151 ++++++++++----- source/src/tools.h | 6 +- source/src/weapon.cpp | 5 +- source/vcpp/cube.sln | 3 + source/vcpp/cube.suo | Bin 19456 -> 26112 bytes source/vcpp/cube.vcproj | 371 +++++++++++++++++++++++++++++++++++- 19 files changed, 572 insertions(+), 200 deletions(-) delete mode 100755 source/doc/classes diff --git a/source/doc/classes b/source/doc/classes deleted file mode 100755 index d27ab1e5..00000000 --- a/source/doc/classes +++ /dev/null @@ -1,112 +0,0 @@ ----- - -11.11.2004 - -Andrew 'arghvark' Davis -Adrian 'driAn' Henke - ----- - -ActionCube coding - - -The class system - - - -0. Inheriting - - -ac_game That's the basis/parent class. This class includes all data -| for the gameplay such as fraglimit, timeleft. It has all the other objects such -| ac_players, ac_vehicle, ac_light, etc. as instance! -| -+-->ac_ctf Inherits from ac_game. This class can be used. The only difference between -| ac_game and ac_ctf are the methods. The methods of ac_ctf declare the gameplay, -| how the flag stuff works, etc. The whole gameplay can be changed in those methods. -| -+-->ac_tf Same as above. -| -| -### all the other game modes - - - - -ac_actor This is the basic class of anything that can be controled by a player.Contains all -| the junk that is universal to any object in the world that is player (or ai) controled. -| -+-->ac_player This class inherits from ac_actor and contains data specific to players, such as ammo - | health ect. - | - +-->ac_bot This class inherits from player class and replaces monster.cpp It will contain AI code -| so we can add bots and single player later. -| -+-->ac_vehicale Inherits from actor, this could be used for user controled vehicles. Could have vehicales - | like airplane, automobile, and boat inherit from it. - | - +-->ac_boat ... - | - | - ### all the other vehicales - - - - -ac_entity A parent class of all enties in the map. An entity is anything that can not be controled -| by the player -| -+-->ac_light ... -| -| -### all the other entities - - - - - - -1. Data flow and storage tree - - It shows only how the data will be stored and where the specific functions/methods are. - - -+ means a instance -@ means a method - -Example: a game running in the ctf mode - - -ac_ctf -| -+->timeleft -+->fraglimit -+->friendlyfire (bool for on/off) -+->players array/vector of ac_player. All players are stored here. See below what ac_player includes! -+->bots ... -+->entities ... -| -@->Shoot(ac_player,ac_player) Get called when a player shoots another player. If those are in the same team, the shooted -| player lose his health only when friendlyfire is TRUE. If health<=0 set the shooted players -| state to AC_FRAGGED. If the fragged guy took a flag, the fragger gets few bonus points (?) -| Sets players[fragger]->frags+=1 if the shooted guy has no HP left. -| -@->GotFlag(ac_player) Sets players[x]->gotflag=TRUE. Alerts the enemy team that their flag was stealed. -| -@->FlagReturn(ac_player) Give this player few extra points. -| -@->Kick(ac_player) -| -@->Spawn(ac_player) Controls the time based spawning. Sets players[x]->state=AC_DEFAULT. -| -@->Suicide(ac_player) Take few frags/points. -| -@->ChangeTeam(ac_player,team) Set players[x]->frags=0 and players[x]->team=team. -| -@->Vote(ac_player,anydata) Some voting stuff. If they vote a new game mode, ac_ctf gets killed and another class, as -| example ac_tf gets started. -# - - - - diff --git a/source/enet/protocol.c b/source/enet/protocol.c index ef8935b6..0a1ee56a 100755 --- a/source/enet/protocol.c +++ b/source/enet/protocol.c @@ -1134,7 +1134,7 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch #else fprintf (stderr, #endif - "peer %u: %f%%+-%f%% packet loss, %u+-%u ms round trip time, %f%% throttle, %u/%u outgoing, %u/%u incoming\n", currentPeer -> incomingPeerID, currentPeer -> packetLoss / (float) ENET_PEER_PACKET_LOSS_SCALE, currentPeer -> packetLossVariance / (float) ENET_PEER_PACKET_LOSS_SCALE, currentPeer -> roundTripTime, currentPeer -> roundTripTimeVariance, currentPeer -> packetThrottle / (float) ENET_PEER_PACKET_THROTTLE_SCALE, enet_list_size (& currentPeer -> outgoingReliableCommands), enet_list_size (& currentPeer -> outgoingUnreliableCommands), currentPeer -> channels != NULL ? enet_list_size (& currentPeer -> channels -> incomingReliableCommands) : 0, enet_list_size (& currentPeer -> channels -> incomingUnreliableCommands)); + "peer %u: %f%%+-%f%% packet loss, %u+-%u ms round trip time, %f%% throttle, %u/%u outgoing, %u/%u incoming\n", currentPeer -> incomingPeerID, currentPeer -> packetLoss / (float) ENET_PEER_PACKET_LOSS_SCALE, currentPeer -> packetLossVariance / (float) ENET_PEER_PACKET_LOSS_SCALE, currentPeer -> roundTripTime, currentPeer -> roundTripTimeVariance, currentPeer -> packetThrottle / (float) ENET_PEER_PACKET_THROTTLE_SCALE, enet_list_size (& currentPeer -> outgoingReliableCommands), enet_list_size (& currentPeer -> outgoingUnreliableCommands), currentPeer -> channels != NULL ? enet_list_size (& currentPeer -> channels -> incomingReliableCommands) : 0, currentPeer -> channels != NULL ? enet_list_size (& currentPeer -> channels -> incomingUnreliableCommands) : 0); #endif currentPeer -> packetLossVariance -= currentPeer -> packetLossVariance / 4; diff --git a/source/src/client.cpp b/source/src/client.cpp index 1ffa7d6a..47b9a8ef 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -173,7 +173,7 @@ void addmsg(int rel, int num, int type, ...) void server_err() { - conoutf("server network error, disconnecting..."); + conoutf("server network error or player kick, disconnecting..."); disconnect(); }; @@ -220,6 +220,13 @@ void c2sinfo(dynent *d) // send update to the server toservermap[0] = 0; putint(p, nextmode); } + else if(masterpwd[0]) + { + packet->flags = ENET_PACKET_FLAG_RELIABLE; + putint(p, SV_GETMASTER); + sendstring(masterpwd, p); + masterpwd[0] = 0; + } else { putint(p, SV_POS); @@ -242,12 +249,6 @@ void c2sinfo(dynent *d) // send update to the server 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/clientextras.cpp b/source/src/clientextras.cpp index 3649401d..365c9996 100644 --- a/source/src/clientextras.cpp +++ b/source/src/clientextras.cpp @@ -158,7 +158,7 @@ void renderscores() loopj(teamsused) { string sc; - if(m_ctf) sprintf_s(sc)("[ %s: %d %d ]", teamname[j], teamflagscore[j], teamscore[j]); + if(m_ctf) sprintf_s(sc)("[ %s: %d flags %d frags ]", teamname[j], teamflagscore[j], teamscore[j]); else sprintf_s(sc)("[ %s: %d ]", teamname[j], teamscore[j]); strcat_s(teamscores, sc); }; diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index fa7916b5..18ed32f8 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -445,6 +445,7 @@ void mousemove(int dx, int dy) void selfdamage(int damage, int actor, dynent *act, bool gib) { + if(!act) return; if(player1->state!=CS_ALIVE || editmode || intermission) return; damageblend(damage); demoblend(damage); @@ -696,10 +697,23 @@ void getmaster(char *pwd) strcpy_s(masterpwd, pwd); }; -void mastercommand(int cmd, int arg1) +void mastercommand(int cmd, int a) { - addmsg(1, 3, SV_MASTERCMD, cmd, arg1); + addmsg(1, 3, SV_MASTERCMD, cmd, a); }; -COMMAND(getmaster, ARG_1STR); -COMMAND(mastercommand, ARG_2INT); \ No newline at end of file +void showmastermenu(int m) // 0=kick, 1=ban +{ + int menu = (m == MCMD_KICK ? 3 : 4); + purgemenu(menu); + + loopv(players) + { + if(players[i]) menumanual(menu, i, players[i]->name, (char *) i); + }; + menuset(menu); +}; + +COMMANDN(masterlogin, getmaster, ARG_1STR); +COMMAND(mastercommand, ARG_2INT); +COMMAND(showmastermenu, ARG_1INT); \ No newline at end of file diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 10c77336..1d30b561 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -72,6 +72,11 @@ void updatepos(dynent *d) }; }; +extern void trydisconnect(); + +#define CN_CHECK if(cn<0 || cn>=players.length()) { conoutf("invalid client (msg %i)", type); return; }; +//#define SENDER_CHECK if(sender<0) { conoutf("invalid sender (msg %i)", type); return; }; + void localservertoclient(uchar *buf, int len) // processes any updates from the server { if(ENET_NET_TO_HOST_16(*(ushort *)buf)!=len) neterr("packet length"); @@ -99,8 +104,8 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th return; }; toservermap[0] = 0; - clientnum = cn; // we are now fully connected - if(!getint(p)) strcpy_s(toservermap, getclientmap()); // we are the first client on this server, set map + clientnum = cn; // we are now fully connectedss + bool firstplayer = !getint(p); sgetstr(); if(text[0] && strcmp(text, clientpassword)) { @@ -108,10 +113,16 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th disconnect(); return; }; - if(getint(p)==1) + int m = getint(p); + if(m==1) { conoutf("server is FULL, disconnecting.."); - }; + } + else if(m==2) + { + conoutf("you are BANNED from this server"); + } + else if(firstplayer) strcpy_s(toservermap, getclientmap()); // we are the first client on this server, set map break; }; @@ -258,7 +269,7 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th case SV_DIEDBYBOT: killedbybot = true; case SV_GIBDIED: - if(type!=SV_DIEDBYBOT) gib = true; // fixme + if(type!=SV_DIEDBYBOT) gib = true; // uargl.. fixme case SV_DIED: { int actor = getint(p); @@ -308,6 +319,7 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th case SV_FRAGS: + CN_CHECK; players[cn]->frags = getint(p); break; @@ -380,6 +392,7 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th break; case SV_CLIENTPING: + CN_CHECK; players[cn]->ping = getint(p); break; @@ -404,6 +417,7 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th case SV_WEAPCHANGE: { + CN_CHECK; players[cn]->gunselect = getint(p); break; }; @@ -461,6 +475,7 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th case SV_FLAGS: { + CN_CHECK; players[cn]->flagscore = getint(p); break; }; @@ -660,6 +675,14 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th case SV_BOTCOMMAND: botcommand(p, text); break; + + case SV_MASTERCMD: + { + int cmd = getint(p), arg1 = getint(p); + dynent *a = getclient(arg1); + if(a && d) conoutf("player %s has been %s by %s", a->name, cmd == MCMD_KICK ? "kicked" : "banned", d->name); + break; + }; // End add diff --git a/source/src/console.cpp b/source/src/console.cpp index 7c78beef..8e522b3d 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -6,7 +6,7 @@ struct cline { char *cref; int outtime; }; vector conlines; -const int ndraw = 5; +const int ndraw = 6; const int WORDWRAP = 80; int conskip = 0; diff --git a/source/src/cube.h b/source/src/cube.h index 83b27f95..6a59bc3e 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -95,6 +95,9 @@ enum { GUN_KNIFE = 0, GUN_PISTOL, GUN_SHOTGUN, GUN_SUBGUN, GUN_SNIPER, GUN_ASSAU enum { G_PRIMARY=0, G_SECONDARY, G_MELEE, G_GRENADE, G_NUM }; +//enum { MCMD_KICK = 0, MCMD_BAN }; +enum { MCMD_KICK = 0, MCMD_BAN }; + // Added by Rick class CBot; @@ -290,7 +293,7 @@ enum { M_NONE = 0, M_SEARCH, M_HOME, M_ATTACKING, M_PAIN, M_SLEEP, M_AIMING, M_N #define MAXCLIENTS 256 // in a multiplayer game, can be arbitrarily changed #define MAXTRANS 5000 // max amount of data to swallow in 1 go -#define CUBE_SERVER_PORT 28765 +#define CUBE_SERVER_PORT 28764 #define CUBE_SERVINFO_PORT 28766 #define PROTOCOL_VERSION 123 // bump when protocol changes @@ -328,7 +331,7 @@ enum S_SHOTGUN, S_RSHOTGUN, S_SUBGUN, S_RSUBGUN, S_SNIPER, S_RSNIPER, - S_ASSULT, S_RASSULT, + S_ASSAULT, S_RASSAULT, S_ITEMAMMO, S_ITEMHEALTH, S_ITEMARMOUR, S_ITEMPUP, S_NOAMMO, S_PUPOUT, diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 3569c8d6..8a649a01 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -259,7 +259,7 @@ void resetspawns() loopv(ents) { entity &e = ents[i]; - if(m_noitemsnade && (e.type == I_CLIPS || e.type == I_AMMO)) e.type = I_GRENADE; + if(m_noitemsnade && e.type == I_CLIPS) e.type = I_GRENADE; else if(m_pistol && e.type==I_AMMO) e.type = I_CLIPS; } }; diff --git a/source/src/main.cpp b/source/src/main.cpp index 3b26c446..238cde51 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -176,6 +176,8 @@ int main(int argc, char **argv) newmenu("frags\tpj\tping\tteam\tname"); newmenu("ping\tplr\tserver"); newmenu("flags\tfrags\tpj\tping\tteam\tname"); + newmenu("kick player"); + newmenu("ban player"); exec("config/keymap.cfg"); exec("config/menus.cfg"); exec("config/prefabs.cfg"); @@ -255,4 +257,13 @@ int main(int argc, char **argv) }; +void loadcrosshair(char *c) +{ + sprintf_sd(p)("packages/misc/crosshairs/%s", c); + path(p); + int xs, ys; + installtex(1, p, xs, ys); +}; + +COMMAND(loadcrosshair, ARG_1STR); diff --git a/source/src/menus.cpp b/source/src/menus.cpp index d6110875..5ab151af 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -150,15 +150,20 @@ void newmenu(char *name) menu.mdl = NULL; }; -void menumanual(int m, int n, char *text) +void menumanual(int m, int n, char *text, char *action) { if(!n) menus[m].items.setsize(0); mitem &mitem = menus[m].items.add(); mitem.text = text; - mitem.action = ""; + mitem.action = action; mitem.hoveraction = NULL; } +void purgemenu(int m) +{ + menus[m].items.setsize(0); +} + void menuitem(char *text, char *action, char *hoveraction) { gmenu &menu = menus.last(); @@ -233,11 +238,18 @@ bool menukey(int code, bool isdown) { if(code==SDLK_RETURN || code==-2) { + if(menusel<0 || menusel >= menus[vmenu].items.length()) { menuset(-1); return true; }; char *action = menus[vmenu].items[menusel].action; if(vmenu==1) connects(getservername(menusel)); + else if(vmenu==3 || vmenu==4) + { + mastercommand(vmenu==3 ? MCMD_KICK : MCMD_BAN, (int)action); + purgemenu(vmenu); + return true; + } menustack.add(vmenu); menuset(-1); - execute(action, true); + if(action) execute(action, true); }; }; return true; diff --git a/source/src/protos.h b/source/src/protos.h index 093daee0..ae92b681 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -24,11 +24,12 @@ extern char *getcurcommand(); // menus extern bool rendermenu(); extern void menuset(int menu); -extern void menumanual(int m, int n, char *text); +extern void menumanual(int m, int n, char *text, char *action=NULL); extern void sortmenu(int m, int start, int num); extern bool menukey(int code, bool isdown); extern void newmenu(char *name); extern void rendermenumdl(); +extern void purgemenu(int m); // serverbrowser extern void addserver(char *servername); @@ -98,6 +99,7 @@ extern void ctf_death(); //game mode extras extern void arenarespawn(); extern void respawn(); +extern void mastercommand(int cmd, int arg1); // clientextras extern void renderclients(); diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index b1e44ba6..58a6308c 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -619,8 +619,8 @@ void renderphysents() }; VAR(gibnum, 0, 6, 1000); -VAR(gibttl, 0, 0, 15000); -VAR(gibspeed, 1, 7, 20); +VAR(gibttl, 0, 5000, 15000); +VAR(gibspeed, 1, 5, 20); void addgib(dynent *d) { @@ -632,7 +632,7 @@ void addgib(dynent *d) physent *p = new_physent(); p->owner = d; p->millis = lastmillis; - p->timetolife = gibttl ? gibttl : 5000+rnd(10)*100; + p->timetolife = gibttl+rnd(10)*100; p->state = GIB; diff --git a/source/src/server.cpp b/source/src/server.cpp index 68338985..ec13717f 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -6,6 +6,9 @@ #define m_ctf_s (mode==5) #define m_teammode_s (mode==0 || mode==4 || mode==5) +#define valid_client(c) (c >= 0 && c < clients.length() && clients[c].type!=ST_EMPTY) +#define valid_flag(f) (f >= 0 && f < 2) + enum { ST_EMPTY, ST_LOCAL, ST_TCPIP }; struct client // server side version of "dynent" type @@ -34,7 +37,6 @@ int maxclients = 8; string smapname; char *masterpasswd = NULL; -enum { MCMD_KICK = 0, MCMD_BAN }; int numclients() { @@ -55,6 +57,7 @@ extern void kickallbots(void); #endif // End add + void restoreserverstate(vector &ents) // hack: called from savegame code, only works in SP { loopv(sents) @@ -169,10 +172,8 @@ void sendservmsg(char *msg, int client=-1) void disconnect_client(int n, char *reason) { if(n<0 || n>=clients.length()) return; - 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); + enet_peer_disconnect(clients[n].peer); clients[n].type = ST_EMPTY; clients[n].ismaster = false; send2(true, -1, SV_CDIS, n); @@ -514,29 +515,52 @@ void changemap() if(packet->referenceCount==0) enet_packet_destroy(packet); }; -void getmaster(int sender, char *pwd) +struct ban { + ENetAddress address; + int secs; +}; + +vector bans; + +bool isbanned(int cn) +{ + if(!valid_client(cn)) return false; + client &c = clients[cn]; + loopv(bans) + { + ban &b = bans[i]; + if(b.secs < lastsec) { bans.remove(i--); }; + if(b.address.host == c.peer->address.host) { return true; }; + }; + return false; +}; + +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) +void mastercmd(int sender, int cmd, int a) { if(!isdedicated) return; - if(clients[sender].ismaster==false) disconnect_client(sender, "access to master commands denied"); + if(clients[sender].ismaster==false) return; switch(cmd) { case MCMD_KICK: { - if(arg1 < 0 && arg1 >= clients.length()) return; - disconnect_client(sender, "you were kicked from the server"); + if(!valid_client(a)) return; + disconnect_client(a, "kicked by master"); 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"); + if(!valid_client(a)) return; + ban b = { clients[a].peer->address, lastsec+20*60 }; + bans.add(b); + disconnect_client(a, "banned by master"); break; }; }; @@ -545,6 +569,26 @@ void mastercmd(int sender, int cmd, int arg1) // 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) +#ifdef STANDALONE +#define CN_CHECK if(!valid_client(cn)) { if(sender>=0) disconnect_client(sender, "client num"); return; }; +#define SENDER_CHECK if(sender<0) return; +#else +#define CN_CHECK if(!valid_client(cn)) { if(sender>=0) disconnect_client(sender, "client num"); conoutf("invalid client (msg %i)", type); return; }; +#define SENDER_CHECK if(sender<0) { conoutf("invalid sender (msg %i)", type); return; }; +#endif + + +/*void bp(bool p) +{ + if(!p) + { + printf("breakpoint reached"); + } +} +#define CN_CHECK bp(valid_client(cn)); +#define SENDER_CHECK bp(sender>=0); +*/ + int tmp_pos[3]; void process(ENetPacket * packet, int sender) // sender may be -1 @@ -562,7 +606,7 @@ void process(ENetPacket * packet, int sender) // sender may be -1 while(p=clients.length() || clients[cn].type==ST_EMPTY) - { - disconnect_client(sender, "client num"); - return; - }; + CN_CHECK; + if(cn!=sender) { if(sender>=0) disconnect_client(sender, "client num"); return; }; int size = msgsizelookup(type); - assert(size!=-1); + if(size==-1) { disconnect_client(sender, "msg size"); return; }; loopi(3) tmp_pos[i] = getint(p); loopi(size-5) getint(p); break; @@ -648,6 +694,7 @@ void process(ENetPacket * packet, int sender) // sender may be -1 case SV_SENDMAP: { + SENDER_CHECK; sgetstr(); int mapsize = getint(p); sendmaps(sender, text, mapsize, p); @@ -655,6 +702,7 @@ void process(ENetPacket * packet, int sender) // sender may be -1 } case SV_RECVMAP: + SENDER_CHECK; send(sender, recvmap(sender)); return; @@ -664,7 +712,7 @@ void process(ENetPacket * packet, int sender) // sender may be -1 case SV_ADDBOT: getint(p); sgetstr(); - //strcpy_s(clients[cn].name, text); + strcpy_s(clients[cn].name, text); sgetstr(); getint(p); break; @@ -681,12 +729,13 @@ void process(ENetPacket * packet, int sender) // sender may be -1 case SV_FLAGPICKUP: { int flag = getint(p); - if(flag<0 || flag>1) return; + if(!valid_flag(flag)) return; ctfflag &f = ctfflags[flag]; if(f.state!=CTFF_STOLEN) { f.state = CTFF_STOLEN; f.thief_cn = sender; + f.lastupdate = lastsec; sendflaginfo(flag, SV_FLAGPICKUP); }; break; @@ -695,7 +744,7 @@ void process(ENetPacket * packet, int sender) // sender may be -1 case SV_FLAGDROP: { int flag = getint(p); - if(flag<0|| flag>1) return; + if(!valid_flag(flag)) return; ctfflag &f = ctfflags[flag]; if(f.state==CTFF_STOLEN && (sender==-1 || f.thief_cn==sender)) { @@ -710,12 +759,13 @@ void process(ENetPacket * packet, int sender) // sender may be -1 case SV_FLAGRETURN: { int flag = getint(p); - if(flag<0|| flag>1) return; + if(!valid_flag(flag)) return; ctfflag &f = ctfflags[flag]; if(f.state==CTFF_DROPPED) { f.state = CTFF_INBASE; f.thief_cn = sender; + f.lastupdate = lastsec; sendflaginfo(flag, SV_FLAGRETURN); }; break; @@ -724,12 +774,13 @@ void process(ENetPacket * packet, int sender) // sender may be -1 case SV_FLAGSCORE: { int flag = getint(p); - if(flag<0|| flag>1) return; + if(!valid_flag(flag)) return; ctfflag &f = ctfflags[flag]; if(f.state==CTFF_STOLEN) { f.state = CTFF_INBASE; f.thief_cn = sender; + f.lastupdate = lastsec; sendflaginfo(flag, SV_FLAGSCORE); }; break; @@ -737,26 +788,29 @@ void process(ENetPacket * packet, int sender) // sender may be -1 case SV_GETMASTER: { + SENDER_CHECK; sgetstr(); getmaster(sender, text); - break; + return; }; case SV_MASTERCMD: { - mastercmd(sender, getint(p), getint(p)); + SENDER_CHECK; + int cmd = getint(p), a = getint(p); + mastercmd(sender, cmd, a); break; }; default: { int size = msgsizelookup(type); - if(size==-1) { disconnect_client(sender, "tag type"); return; }; + if(size==-1) { if(sender>=0) disconnect_client(sender, "tag type"); return; }; loopi(size-1) getint(p); }; }; - if(p>end) { disconnect_client(sender, "end of packet"); return; }; + if(p>end) { if(sender>=0) disconnect_client(sender, "end of packet"); return; }; multicast(packet, sender); }; @@ -771,8 +825,9 @@ void send_welcome(int n) if(!smapname[0] && configsets.length()) nextcfgset(); // EDIT:AH putint(p, smapname[0]); sendstring(serverpassword, p); - putint(p, numclients()>maxclients); - if(smapname[0]) + int discn = numclients()>maxclients ? 1 : (isbanned(n) ? 2 : 0); + putint(p, discn); + if(smapname[0] && !discn) { putint(p, SV_MAPCHANGE); sendstring(smapname, p); @@ -791,7 +846,7 @@ void multicast(ENetPacket *packet, int sender) { loopv(clients) { - if(i==sender) continue; + if(i==sender) continue; send(i, packet); }; }; @@ -823,7 +878,7 @@ void checkintermission() void resetserverifempty() { loopv(clients) if(clients[i].type!=ST_EMPTY) return; - clients.setsize(0); + //clients.setsize(0); smapname[0] = 0; resetvotes(); #ifndef STANDALONE @@ -858,13 +913,13 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal loopi(2) { ctfflag &f = ctfflags[i]; - if(f.state==CTFF_DROPPED && seconds-f.lastupdate>30) + if(f.state==CTFF_DROPPED && seconds-f.lastupdate>30) { f.state=CTFF_INBASE; sendflaginfo(i, -1); sprintf_sd(msg)("the server reset the %s flag", rb_team_string(i)); sendservmsg(msg); - send2(true, -1, SV_SOUND, S_FLAGDROP); + send2(true, -1, SV_SOUND, S_FLAGRETURN); }; }; }; @@ -922,6 +977,14 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal ENetEvent event; if(enet_host_service(serverhost, &event, timeout) > 0) { + + if(numplayers>maxclients) + { + disconnect_client(lastconnect, "maxclients reached"); + } + + loopv(clients) if(valid_client(i) && isbanned(i)) disconnect_client(i, "connection refused due to ban"); + switch(event.type) { case ENET_EVENT_TYPE_CONNECT: @@ -930,31 +993,29 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal c.type = ST_TCPIP; c.peer = event.peer; c.peer->data = (void *)(&c-&clients[0]); - char hn[1024]; - strcpy_s(c.hostname, (enet_address_get_host(&c.peer->address, hn, sizeof(hn))==0) ? hn : "localhost"); - printf("client connected (%s)\n", c.hostname); - send_welcome(lastconnect = &c-&clients[0]); - break; + c.ismaster = false; + char hn[1024]; + strcpy_s(c.hostname, (enet_address_get_host(&c.peer->address, hn, sizeof(hn))==0) ? hn : "localhost"); + printf("client connected (%s)\n", c.hostname); + send_welcome(lastconnect = &c-&clients[0]); + break; } case ENET_EVENT_TYPE_RECEIVE: brec += event.packet->dataLength; + if(!valid_client((int)event.peer->data)) break; process(event.packet, (int)event.peer->data); if(event.packet->referenceCount==0) enet_packet_destroy(event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: - if((int)event.peer->data<0) break; + if(!valid_client((int)event.peer->data)) break; printf("disconnected client (%s)\n", clients[(int)event.peer->data].hostname); clients[(int)event.peer->data].type = ST_EMPTY; + clients[(int)event.peer->data].ismaster = false; send2(true, -1, SV_CDIS, (int)event.peer->data); event.peer->data = (void *)-1; break; }; - - if(numplayers>maxclients) - { - disconnect_client(lastconnect, "maxclients reached"); - }; }; }; @@ -991,7 +1052,7 @@ void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, loopi(MAXCLIENTS) serverhost->peers[i].data = (void *)-1; if(!maprot || !maprot[0]) maprot = newstring("config/maprot.cfg"); readscfg(path(maprot)); // EDIT: AH - if(!masterpwd || !masterpwd[0]) masterpasswd = masterpwd; + if(masterpwd && masterpwd[0]) masterpasswd = masterpwd; }; resetserverifempty(); diff --git a/source/src/tools.h b/source/src/tools.h index f9a57b54..ed47d6e7 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -182,7 +182,11 @@ template struct vector bool empty() { return ulen==0; }; int length() { return ulen; }; - T &operator[](int i) { assert(i>=0 && i=0 && ii; ulen--) buf[ulen-1].~T(); }; T *getbuf() { return buf; }; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 93d95083..fdb87656 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -16,7 +16,7 @@ guninfo guns[NUMGUNS] = { S_SHOTGUN, S_RSHOTGUN, 2400, 1000, 6, 0, 0, 1, 35, 7, 9, 9, false, "shotgun" }, //reload time is for 1 shell from 7 too powerful to 6 { S_SUBGUN, S_RSUBGUN, 1650, 80, 17, 0, 0, 70, 15, 30, 1, 2, true, "subgun" }, { S_SNIPER, S_RSNIPER, 1950, 1500, 72, 0, 0, 60, 50, 5, 4, 4, false, "sniper" }, - { S_ASSULT, S_RASSULT, 2000, 130, 20, 0, 0, 20, 40, 20, 0, 2, true, "assult" }, //recoil was 44 + { S_ASSAULT, S_RASSAULT, 2000, 130, 20, 0, 0, 20, 40, 20, 0, 2, true, "assault" }, //recoil was 44 { S_NULL, S_NULL, 1000, 1200, 150, 20, 6, 1, 1, 1, 3, 1, "grenade" }, }; @@ -92,7 +92,7 @@ COMMAND(altattack, ARG_NONE); void reload(dynent *d) { if(!d || d->reloading) return; - if(d == player1 && scoped) { togglescope(); }; + if(d == player1 && scoped) { togglescope(); }; bool akimbo = d->gunselect==GUN_PISTOL && d->akimbo!=0; if(d->gunselect==GUN_KNIFE || d->gunselect==GUN_GRENADE) return; @@ -466,7 +466,6 @@ physent *new_nade(dynent *d, int millis = 0) void explode_nade(physent *i) { if(!i) return; - printf("explode\n"); if(i->state != NADE_THROWED) { diff --git a/source/vcpp/cube.sln b/source/vcpp/cube.sln index a1dc2daa..c71047d6 100644 --- a/source/vcpp/cube.sln +++ b/source/vcpp/cube.sln @@ -9,6 +9,7 @@ Global Profile = Profile Release = Release Standalone = Standalone + Standalone Debug = Standalone Debug EndGlobalSection GlobalSection(ProjectConfiguration) = postSolution {1FAF5BB4-C49A-4124-9F23-188528BAE7C8}.Debug.ActiveCfg = Debug|Win32 @@ -19,6 +20,8 @@ Global {1FAF5BB4-C49A-4124-9F23-188528BAE7C8}.Release.Build.0 = Release|Win32 {1FAF5BB4-C49A-4124-9F23-188528BAE7C8}.Standalone.ActiveCfg = Standalone|Win32 {1FAF5BB4-C49A-4124-9F23-188528BAE7C8}.Standalone.Build.0 = Standalone|Win32 + {1FAF5BB4-C49A-4124-9F23-188528BAE7C8}.Standalone Debug.ActiveCfg = Standalone Debug|Win32 + {1FAF5BB4-C49A-4124-9F23-188528BAE7C8}.Standalone Debug.Build.0 = Standalone Debug|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution DPBuild = 5 diff --git a/source/vcpp/cube.suo b/source/vcpp/cube.suo index 2e6d09b8573562313e7755be55565bc449e6caa4..4b74eabe1de1cac3fa4a69e3c7a97bf37735a1f1 100644 GIT binary patch delta 3548 zcmeHJU2M};6u-CY=V)>Nb+qf&wg0jY)-lG0FxdyBgKdm4U}Hpy3}I|+ObctaAq(4>Uog=aje_X|4@R;?0!)qO&A)T)RZ31e5T3yCEjIH{-UZ?$_4L~EXNtbN~Z3eagExK$Q z=ysiN1Kk0%;|^OadBNSfd=KbTz+PY<&r4x zZ&XaeA*6&Mpcqi8O>vq-2Hf31+Y}c?l}ajgHODglG`ucoI&;Jvgqh13G~#^D5Ro(u za^6TIS>M>R^vm$^+J%OejLGA4Z^;UJ%QY;Us77s|u**(8?kuU&39p-SR5hOEu9pQc2py+^vcMicK54$)DTLXe7tIPAPQ0c(| zGsBAG`sWmN86^rE?0J~v0P_Ja+G*uG&I#^9kee(RT6T^MTU_*$&qq12`p40jGg8z)Qf(z**oN@Cv{w@EUL)7zbhiCmgk`DlU8n z%)7t^;36;qya!wY-Um2$?vJ;fj;oK}G19gCh{8AJ!L$-s`1r~E!%6|ln+MZXp#RkP zN_QYrZW{|V*u|f+0Su%}@GZdgk_A=r5gKI%!j zUeG|kpfxarTgDLx;&vC{lYoi9*7u==CGpuCjPh#rP)i~nCvS-#b z$2@Nk5AK5L*~ovW?_(OIy27)gLVWk}>dfD+eR7-o;!)V*Fb6<+%&yfITKVo4qb3!L z!w;G7s4%WrTuI`Q%WQhgZ56=K2y_Sy-?ecwBInlUr?i3jh2>9vaXwg zp=SclR6B)mNm{RN&~}V(?4i<<0VVNB=s*3) zn_*xkeCSU!T-8p_jY`0i+IEtQ*r`YZ`e9RVASd-MAK$1rE}KJ=cDM>?#=GejzDl16 z6iZrdR(`HyIR-b1_V9RY9Z{Yw|@$K_83@>1{cKDfhf(y|^m-h)<} zl$5^Ih8D!6dr<_R2mTK9UBAg01Rb7vWqfJuJTeLGdMbwTE^0pV!^&XNGH|s$pQh_6t*& Z>|9~aeACc=Exo9JbV9Cv{9Qyx`Wp(;`6d7W delta 2912 zcmb_eZ%kWN6hHU%4;z%N1y%}nv_gR*gB1qb8rW>1bPO0c=LdD29YR5n!BRG-Y)I8@ zPMzE6`QitoOI%De#EiT}zs+qXW>FK-7!#dYH1V5>n#c!-#`?RD@^71sS$bc7J?EZt z-#vfcx#u?ag^0Z&E?!Wk_lHDWKV&q2I`w$uh8oqsFZA_9#7?7K?B#97eEmO(M1mhR z9-24}xtvJ&!0!XRz$-ul&p`VLzqkY1ZWJ{4|D@h0zE)4@S-}Iu|=u0gLTsZiqJ3}rctV(YAicU zeN;&`&}9M#XauiB_>a{y*#g@p@*tFyztX#SHuKADS`Ud~nbeShNfY17I%?bu?pdQc zW(w+g)f(HxGjL^?251ORH{3Z4dl3pPa$$He0%;VI2!*MZJb3ECd1$LP_hR*^rVk+< z-Sjlp^=Ugskm3OBerY zwQ{xF#2@5;&5kZN$81-GUiBAzB$S(ab*}JR!84xU*<;I8Z#LQlTir!*hffe+ZF`V? z4xeE=Wm6`9Y;MqvQ#Fs<^RZQ5Egp&s1{=FjlB4)e!DMNU z(snw=u+@CKt$R2E9By#%W4)oQq+4zjyXvbtE=>2q5eu-G-P!6HQ&Cc|AXH~Jnw3`B zBVK~$IB)_u3A_wQ`D>uBCV4r39sC*KEO0Ii?13eQC(;f43Jlx9(xTy`FugHXbf@W|-&*8cvkUT|4+^mtBVv;oq$5 zjOg|)RL4`L9y z-Kj6aH4s_RJMUbh?c~Lo<#$?2)GLiKW#YCvck4%F5Q&6+sm?F%70UIHP^6a&b-qR% zMZ4IHzU-wsY6cg;w({2xNfl&X@Xg@7nxqEYR>V|CTX1-5akm6Cy)H-r?hFp_FHHmd zLuXd_ZpLhBGA33T)MnEgaeqd# z0QgEUtVLa%+PpQ5QQvI+ey}99x#F~%8|6snkqK97lWB}_zM_fbKg$3*lKeN>udZ#w Q&G=K#e%$eS> + + + + + + + + + + + + + + + @@ -422,6 +482,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -438,6 +504,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -454,6 +526,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -470,6 +548,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -479,6 +563,12 @@ + + + @@ -495,6 +585,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -511,6 +607,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + + + + @@ -547,6 +655,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -563,6 +677,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -572,6 +692,12 @@ + + + @@ -596,6 +722,12 @@ + + + @@ -629,6 +761,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> + + + @@ -650,6 +788,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> + + + @@ -671,6 +815,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> + + + @@ -692,6 +842,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> + + + @@ -713,6 +869,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> + + + @@ -734,6 +896,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> + + + @@ -755,6 +923,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> + + + @@ -776,6 +950,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> + + + @@ -797,6 +977,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -813,6 +999,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -829,6 +1021,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -845,6 +1043,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -861,6 +1065,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -877,6 +1087,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -893,6 +1109,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + + + + @@ -929,6 +1157,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -938,6 +1172,12 @@ + + + @@ -954,6 +1194,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + + + + @@ -990,6 +1242,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -1006,6 +1264,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -1022,6 +1286,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -1045,6 +1315,14 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="1"/> + + + @@ -1061,6 +1339,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="3"/> + + + @@ -1082,6 +1366,12 @@ Name="VCCLCompilerTool" UsePrecompiledHeader="0"/> + + + + Name="Standalone|Win32" + ExcludedFromBuild="TRUE"> @@ -1134,6 +1425,12 @@ + + + @@ -1143,6 +1440,12 @@ + + + @@ -1152,6 +1455,12 @@ + + + @@ -1161,6 +1470,12 @@ + + + @@ -1170,6 +1485,12 @@ + + + @@ -1179,6 +1500,12 @@ + + + @@ -1188,6 +1515,12 @@ + + + @@ -1197,6 +1530,12 @@ + + + @@ -1206,6 +1545,12 @@ + + + @@ -1215,6 +1560,12 @@ + + +