diff --git a/source/src/client.cpp b/source/src/client.cpp index 47b9a8ef..283e801b 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -182,6 +182,7 @@ string toservermap; bool senditemstoserver = false; // after a map change, since server doesn't have map data string clientpassword; +char *toserverpwd = NULL; void password(char *p) { strcpy_s(clientpassword, p); }; COMMAND(password, ARG_1STR); @@ -192,6 +193,7 @@ void initclientnet() ctext[0] = 0; toservermap[0] = 0; clientpassword[0] = 0; + toserverpwd = NULL; newname("unnamed"); ctf_team("red"); }; @@ -212,7 +214,15 @@ void c2sinfo(dynent *d) // send update to the server uchar *start = packet->data; uchar *p = start+2; bool serveriteminitdone = false; - if(toservermap[0]) // suggest server to change map + if(toserverpwd) + { + packet->flags = ENET_PACKET_FLAG_RELIABLE; + putint(p, SV_PWD); + sendstring(toserverpwd, p); + toserverpwd[0] = 0; + toserverpwd = NULL; + } + else if(toservermap[0]) // suggest server to change map { // do this exclusively as map change may invalidate rest of update packet->flags = ENET_PACKET_FLAG_RELIABLE; putint(p, SV_MAPCHANGE); diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 18ed32f8..fa7adaf4 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -149,7 +149,7 @@ void respawn() if(m_arena) { conoutf("waiting for new round to start..."); return; }; respawnself(); weaponswitch(player1->primary); - player1->lastaction -= WEAPONCHANGE_TIME/2.0f; + player1->lastaction -= WEAPONCHANGE_TIME/2; }; }; @@ -358,7 +358,7 @@ int nearestenemy(vec *v, string team) else if(distsquared < nearestPlayerDistSquared) nearestPlayerDistSquared = distsquared; // if a player is closer }; if(nearestPlayerDistSquared >= securespawndist * securespawndist || nearestPlayerDistSquared == -1) return -1; // a distance more than securespawndist means the place is free - else return sqrt(nearestPlayerDistSquared); + else return (int) sqrt(nearestPlayerDistSquared); }; int spawncycle = -1; @@ -709,7 +709,7 @@ void showmastermenu(int m) // 0=kick, 1=ban loopv(players) { - if(players[i]) menumanual(menu, i, players[i]->name, (char *) i); + if(players[i]) menumanual(menu, i, players[i]->name, (char *) i); // ugly hack }; menuset(menu); }; diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 1d30b561..925c18da 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -6,6 +6,7 @@ extern int clientnum; extern bool c2sinit, senditemstoserver; extern string toservermap; extern string clientpassword; +extern char *toserverpwd; void neterr(char *s) { @@ -47,6 +48,7 @@ void botcommand(uchar *&p, char *text) } // End add + // update the position of other clients in the game in our world // don't care if he's in the scenery or other players, // just don't overlap with our client @@ -106,13 +108,11 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th toservermap[0] = 0; clientnum = cn; // we are now fully connectedss bool firstplayer = !getint(p); - sgetstr(); - if(text[0] && strcmp(text, clientpassword)) - { - conoutf("you need to set the correct password to join this server!"); - disconnect(); - return; - }; + if(getint(p) > 0) + { + conoutf("INFO: this server is password protected"); + toserverpwd = clientpassword; + }; int m = getint(p); if(m==1) { @@ -333,8 +333,6 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th { uint i = getint(p); setspawn(i, true); - if(i>=ents.length() || i<0) break; - vec v = { ents[i].x, ents[i].y, ents[i].z }; break; }; @@ -446,14 +444,14 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th f.flag->x = (ushort) (getint(p)/DMF); f.flag->y = (ushort) (getint(p)/DMF); f.flag->z = (ushort) (getint(p)/DMF); - f.flag->z -= 4.1; + f.flag->z -= 4; float floor = (float)S(f.flag->x, f.flag->y)->floor; if(f.flag->z > hdr.waterlevel) // above water { if(floor < hdr.waterlevel) f.flag->z = hdr.waterlevel; // avoid dropping into water else - f.flag->z = floor; + f.flag->z = (short)floor; }; f.flag->spawned = true; } @@ -483,7 +481,7 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th case SV_FLAGPICKUP: { int flag = getint(p); - if(flag<0|flag>1) return; + if(flag<0||flag>1) return; flaginfos[flag].state=CTFF_STOLEN; break; }; @@ -583,7 +581,7 @@ void localservertoclient(uchar *buf, int len) // processes any updates from th { int b = getint(p); int killer = getint(p); - bool KilledByABot = getint(p); + bool KilledByABot = getint(p) > 0; //fixmebot dynent *bot = getbot(b); if((b==killer) && KilledByABot) diff --git a/source/src/cube.h b/source/src/cube.h index 6a59bc3e..3bc16da9 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -95,8 +95,7 @@ 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 }; +enum { MCMD_KICK = 0, MCMD_BAN, MCMD_REMBANS }; // Added by Rick @@ -317,6 +316,7 @@ enum // End add SV_BOTITEMPICKUP, SV_BOT2CLIENTDMG, SV_DIEDBYBOT, SV_GETMASTER, SV_MASTERCMD, + SV_PWD, SV_EXT, }; diff --git a/source/src/protos.h b/source/src/protos.h index ae92b681..79865ace 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -142,7 +142,7 @@ extern void keyrepeat(bool on); // rendertext extern void draw_text(char *str, int left, int top, int gl_num); -extern void draw_textf(char *fstr, int left, int top, int gl_num, int arg); +extern void draw_textf(char *fstr, int left, int top, int gl_num, ...); extern int text_width(char *str); extern void draw_envbox(int t, int fogdist); diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index 58a6308c..12b386a3 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -53,20 +53,20 @@ void blendbox(int x1, int y1, int x2, int y2, bool border, int tex) glDisable(GL_BLEND); glColor3d(1.0, 1.0, 1.0); - float texw = 512.0f; - float texh = texw; - int cols = (x2-x1)/texw+1; - int rows = (y2-y1)/texh+1; + int texw = 512; + int texh = texw; + int cols = (int)((x2-x1)/texw+1); + int rows = (int)((y2-y1)/texh+1); xtraverts += cols*rows*4; loopj(rows) { float ytexcut = 0.0f; float yboxcut = 0.0f; - if((j+1)*texh>y2-y1) // cut last row to match the box height*/ + if((j+1)*texh>y2-y1) // cut last row to match the box height { - yboxcut = (((j+1)*texh)-(y2-y1)); - ytexcut = (((j+1)*texh)-(y2-y1))/texh; + yboxcut = (float)(((j+1)*texh)-(y2-y1)); + ytexcut = (float)(((j+1)*texh)-(y2-y1))/texh; } loopi(cols) @@ -75,15 +75,15 @@ void blendbox(int x1, int y1, int x2, int y2, bool border, int tex) float xboxcut = 0.0f; if((i+1)*texw>x2-x1) { - xboxcut = (((i+1)*texw)-(x2-x1)); - xtexcut = (((i+1)*texw)-(x2-x1))/texw; + xboxcut = (float)(((i+1)*texw)-(x2-x1)); + xtexcut = (float)(((i+1)*texw)-(x2-x1))/texw; } glBegin(GL_QUADS); - glTexCoord2f(0, 0); glVertex2i(x1+texw*i, y1+texh*j); - glTexCoord2f(1-xtexcut, 0); glVertex2i(x1+texw*(i+1)-xboxcut, y1+texh*j); - glTexCoord2f(1-xtexcut, 1-ytexcut); glVertex2i(x1+texw*(i+1)-xboxcut, y1+texh*(j+1)-yboxcut); - glTexCoord2f(0, 1-ytexcut); glVertex2i(x1+texw*i, y1+texh*(j+1)-yboxcut); + glTexCoord2f(0.0f, 0.0f); glVertex2f((float)x1+texw*i, (float)y1+texh*j); + glTexCoord2f(1-xtexcut, 0); glVertex2f(x1+texw*(i+1)-xboxcut, (float)y1+texh*j); + glTexCoord2f(1-xtexcut, 1-ytexcut); glVertex2f(x1+texw*(i+1)-xboxcut, (float)y1+texh*(j+1)-yboxcut); + glTexCoord2f(0, 1-ytexcut); glVertex2f((float)x1+texw*i, y1+texh*(j+1)-yboxcut); glEnd(); } } @@ -361,7 +361,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat char *command = getcurcommand(); dynent *player = playerincrosshair(); dynent *bot = botincrosshair(); - if(command) draw_textf("> %s_", 20, 1570, 2, (int)command); + if(command) draw_textf("> %s_", 20, 1570, 2, command); else if(closeent[0]) draw_text(closeent, 20, 1570, 2); else if(player || (bot && (player=bot))) draw_text(player->name, 20, 1570, 2); @@ -461,7 +461,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat if(flaginfos[TEAM_RVSF].state == CTFF_INBASE) glDisable(GL_BLEND); else glEnable(GL_BLEND); drawicon(0, 0, 1820, 1650, 11, 1.0f/4.0f); glDisable(GL_BLEND); - drawicon(rb_team_int(player1->team)*64*ctf_scl, 64*ctf_scl, VIRTW-128-10, 10, 11, 1.0f/4.0f); // shows which team you are + drawicon((float)(rb_team_int(player1->team)*64*ctf_scl), (float)(64*ctf_scl), VIRTW-128-10, 10, 11, 1.0/4.0); // shows which team you are glPopMatrix(); // big flag icon @@ -473,7 +473,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat glBlendFunc(GL_SRC_ALPHA, GL_ONE); glColor4f(1.0f, 1.0f, 1.0f, (float)(sin(lastmillis / 100.0) + 1) / 2); glEnable(GL_BLEND); - drawicon(rb_opposite(rb_team_int(player1->team))*128*ctf_scl, 128*ctf_scl, 1065, VIRTH/2/3*2, 11, 1.0f/2.0f); + drawicon((float)(rb_opposite(rb_team_int(player1->team))*128*ctf_scl),(float)(128*ctf_scl), 1065, VIRTH/2/3*2, 11, 1.0/2.0); glPopMatrix(); }; }; @@ -644,8 +644,8 @@ void addgib(dynent *d) p->o = d->o; p->o.z -= d->aboveeye; - float gibvelangle = rnd(360); - float speed = gibspeed; + float gibvelangle = (float) rnd(360); + float speed = (float) gibspeed; p->vel.x = sin(gibvelangle)*speed*rnd(1000)/1000.0f; p->vel.y = cos(gibvelangle)*speed*rnd(1000)/1000.0f; p->vel.z = speed*rnd(1000)/1000.0f; diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 465bdc98..9863c169 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -243,7 +243,7 @@ VARF(gamma, 30, 100, 300, }; }); -void trypitch(int i) { player1->pitch=i; } +void trypitch(int i) { player1->pitch = (float)i; } COMMAND(trypitch, ARG_1INT); void transplayer() diff --git a/source/src/rendermd3.cpp b/source/src/rendermd3.cpp index b8f308d4..9efbf7ef 100644 --- a/source/src/rendermd3.cpp +++ b/source/src/rendermd3.cpp @@ -400,9 +400,8 @@ struct weaponmove weaponmove() : k_rot(0), kick(0), anim(0) { pos.x = pos.y = pos.z = 0.0f; }; - calcmove(vec base, int basetime) + void calcmove(vec base, int basetime) { - bool akimbo = player1->akimbo && player1->gunselect==GUN_PISTOL; int timediff = NADE_THROWING ? (lastmillis-player1->thrownademillis) : lastmillis-basetime; int animtime = attackdelay(player1->gunselect); int rtime = reloadtime(player1->gunselect); @@ -452,7 +451,6 @@ struct weaponmove k_back = kick_back(player1->gunselect)*kick/10; }; - int swayt = (lastmillis+1)/10 % 100; float swayspeed = (float) (sin((float)lastmillis/swayspeeddiv))/(swaymovediv/10.0f); float swayupspeed = (float) (sin((float)lastmillis/swayupspeeddiv-90))/(swayupmovediv/10.0f); diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index 3f07b003..c93f28d0 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -118,9 +118,9 @@ int text_width(char *str) } -void draw_textf(char *fstr, int left, int top, int gl_num, int arg) +void draw_textf(char *fstr, int left, int top, int gl_num, ...) { - sprintf_sd(str)(fstr,arg); + sprintf_sdlv(str, gl_num, fstr); draw_text(str, left, top, gl_num); }; diff --git a/source/src/server.cpp b/source/src/server.cpp index ec13717f..2b9f820e 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -29,6 +29,7 @@ struct client // server side version of "dynent" type #endif // End add bool ismaster; + bool isauthed; // for passworded servers }; vector clients; @@ -45,6 +46,13 @@ int numclients() return num; }; +void zapclient(int c) +{ + if(c<0 || c>=clients.length()) return; + clients[c].type = ST_EMPTY; + clients[c].ismaster = clients[c].isauthed = false; +}; + vector sents; bool notgotitems = true; // true when map has changed and waiting for clients to send item @@ -174,8 +182,7 @@ void disconnect_client(int n, char *reason) if(n<0 || n>=clients.length()) return; 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; + zapclient(n); send2(true, -1, SV_CDIS, n); }; @@ -222,7 +229,7 @@ void readscfg(char *cfg) bool lastline = false; while((p = strstr(l, "\n")) != NULL || (l && (lastline=true))) // remove empty/invalid lines { - int len = lastline ? strlen(l) : p-l; + size_t len = lastline ? strlen(l) : p-l; string line; strn0cpy(line, l, len+1); char *d = line; @@ -248,7 +255,7 @@ void readscfg(char *cfg) strcpy(c.mapname, argv[0]+numspaces); c.mode = atoi(argv[1]); c.time = atoi(argv[2]); - c.vote = (bool) atoi(argv[3]); + c.vote = atoi(argv[3]) > 0; configsets.add(c); argc = 0; }; @@ -563,9 +570,35 @@ void mastercmd(int sender, int cmd, int a) disconnect_client(a, "banned by master"); break; }; + case MCMD_REMBANS: + { + if(bans.length()) bans.setsize(0); + break; + }; }; }; +void sendmapinfo(int c) +{ + if(!valid_client(c)) return; + if(smapname[0]) + { + ENetPacket * packet = enet_packet_create (NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE); + uchar *start = packet->data; + uchar *p = start+2; + putint(p, SV_MAPCHANGE); + sendstring(smapname, p); + putint(p, mode); + putint(p, SV_ITEMLIST); + loopv(sents) if(sents[i].spawned) putint(p, i); + putint(p, -1); + *(ushort *)start = ENET_HOST_TO_NET_16(p-start); + enet_packet_resize(packet, p-start); + send(c, packet); + }; +}; + + // 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) @@ -582,7 +615,7 @@ void mastercmd(int sender, int cmd, int a) { if(!p) { - printf("breakpoint reached"); + printf("validation failed"); } } #define CN_CHECK bp(valid_client(cn)); @@ -604,6 +637,19 @@ void process(ENetPacket * packet, int sender) // sender may be -1 char text[MAXTRANS]; int cn = -1, type; + if(serverpassword[0] && sender>=0 && sender<=clients.length() && !clients[sender].isauthed) + { + int msg = getint(p); + sgetstr(); + if(msg != SV_PWD || !text[0] || strcmp(text, serverpassword)) disconnect_client(sender, "wrong password"); + else + { + clients[sender].isauthed = true; + sendmapinfo(sender); + }; + return; + }; + while(pmaxclients ? 1 : (isbanned(n) ? 2 : 0); putint(p, discn); - if(smapname[0] && !discn) + if(smapname[0] && !discn && !serverpassword[0]) { putint(p, SV_MAPCHANGE); sendstring(smapname, p); @@ -977,7 +1015,6 @@ 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"); @@ -993,7 +1030,7 @@ 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]); - c.ismaster = false; + c.ismaster = c.isauthed = 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); @@ -1001,17 +1038,19 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal 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); + int cn = (int)event.peer->data; + if(!valid_client(cn)) break; + process(event.packet, cn); if(event.packet->referenceCount==0) enet_packet_destroy(event.packet); break; + } case ENET_EVENT_TYPE_DISCONNECT: 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; + zapclient((int)event.peer->data); send2(true, -1, SV_CDIS, (int)event.peer->data); event.peer->data = (void *)-1; break; @@ -1026,7 +1065,7 @@ void cleanupserver() void localdisconnect() { - loopv(clients) if(clients[i].type==ST_LOCAL) clients[i].type = ST_EMPTY; + loopv(clients) if(clients[i].type==ST_LOCAL) zapclient(i); }; void localconnect() diff --git a/source/src/serverutil.cpp b/source/src/serverutil.cpp index 9be64594..d1e7b077 100644 --- a/source/src/serverutil.cpp +++ b/source/src/serverutil.cpp @@ -67,6 +67,7 @@ char msgsizesl[] = // size inclusive message token, 0 for variable // End add SV_BOTITEMPICKUP, 3, SV_BOT2CLIENTDMG, 5, SV_DIEDBYBOT, 2, SV_GETMASTER, 0, SV_MASTERCMD, 3, + SV_PWD, 0, SV_EXT, 0, -1 }; diff --git a/source/vcpp/cube.suo b/source/vcpp/cube.suo index 4b74eabe..4146f07e 100644 Binary files a/source/vcpp/cube.suo and b/source/vcpp/cube.suo differ diff --git a/source/vcpp/cube.vcproj b/source/vcpp/cube.vcproj index 4da86710..99341e2c 100644 --- a/source/vcpp/cube.vcproj +++ b/source/vcpp/cube.vcproj @@ -181,7 +181,7 @@ FavorSizeOrSpeed="2" OmitFramePointers="TRUE" OptimizeForProcessor="2" - AdditionalIncludeDirectories="C:\W\cube\enet\include;C:\w\cube\include" + AdditionalIncludeDirectories="..\enet\include;..\include" PreprocessorDefinitions="WIN32,NDEBUG,_CONSOLE,USE_ENET" StringPooling="TRUE" MinimalRebuild="TRUE" @@ -205,11 +205,11 @@