From 054594bec658b0e522686e703fcf28802ef7d8f7 Mon Sep 17 00:00:00 2001 From: Rafael Barreto Date: Fri, 16 Jul 2010 21:57:13 +0000 Subject: [PATCH] removing 3 ints from SV_SHOOT... and some other stuff git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5385 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/client.cpp | 4 +++- source/src/clientgame.cpp | 45 ++++++++++++++++++++++++++++++++++++-- source/src/clients2c.cpp | 5 ++++- source/src/entity.h | 4 ++-- source/src/protocol.cpp | 2 +- source/src/protocol.h | 2 +- source/src/server.cpp | 23 ++++++++++++++----- source/src/serveractions.h | 5 +++-- source/src/weapon.cpp | 1 + 9 files changed, 76 insertions(+), 15 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index 3dca5152..e83f79f5 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -357,7 +357,7 @@ void c2sinfo(playerent *d) // send update to the server dz = dzt - d->vel_t.i[2], // pack rest in 1 int: strafe:2, move:2, onfloor:1, onladder: 1 f = (d->strafe&3) | ((d->move&3)<<2) | (((int)d->onfloor)<<4) | (((int)d->onladder)<<5) | ((d->lifesequence&1)<<6) | (((int)d->crouching)<<7), - g = (dx?1:0) | ((dy?1:0)<<1) | ((dz?1:0)<<2) | ((r?1:0)<<3) | (((int)d->scoping)<<4); + g = (dx?1:0) | ((dy?1:0)<<1) | ((dz?1:0)<<2) | ((r?1:0)<<3) | (((int)d->scoping)<<4) | (((int)d->shoot)<<5); d->vel_t.i[0] = dxt; d->vel_t.i[1] = dyt; d->vel_t.i[2] = dzt; @@ -401,6 +401,7 @@ void c2sinfo(playerent *d) // send update to the server b.putbits(1, s == 11 ? 1 : 0); b.putbits(s, z); b.putbits(1, d->scoping ? 1 : 0); + b.putbits(1, d->shoot ? 1 : 0); } else { // classic POS packet @@ -419,6 +420,7 @@ void c2sinfo(playerent *d) // send update to the server putuint(q, f); } sendpackettoserv(0, q.finalize()); + d->shoot = false; } if(sendmapidenttoserver || messages.length() || totalmillis-lastping>250) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 513940cb..e152eb85 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -994,7 +994,7 @@ COMMAND(dropflag, ARG_NONE); char *votestring(int type, char *arg1, char *arg2) { - 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 *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", "%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'; @@ -1020,8 +1020,18 @@ char *votestring(int type, char *arg1, char *arg2) formatstring(out)(msg, atoi(arg1) == 0 ? "disable" : "enable"); break; case SA_MAP: - formatstring(out)(msg, arg1, modestr(atoi(arg2), modeacronyms > 0)); + { + int n = atoi(arg2); + if ( n >= GMODE_NUM ) + { + formatstring(out)(msg, arg1, modestr(n-GMODE_NUM, modeacronyms > 0)," (in the next game)"); + } + else + { + formatstring(out)(msg, arg1, modestr(n, modeacronyms > 0),""); + } break; + } case SA_SERVERDESC: formatstring(out)(msg, arg1); break; @@ -1167,6 +1177,37 @@ void voteresult(int v) void clearvote() { DELETEP(curvote); DELETEP(calledvote); } +const char *modestrings[] = +{ + "tdm", "coop", "dm", "lms", "ts", "ctf", "pf", "btdm", "bdm", "lss", + "osok", "tosok", "bosok", "htf", "tktf", "ktf" +}; + +void setnext(char *arg1, char *arg2) +{ + for (int i = 0; i < GMODE_NUM; i++) + { + switch(i) + { + case GMODE_COOPEDIT: + case GMODE_BOTTEAMDEATHMATCH: + case GMODE_BOTDEATHMATCH: + case GMODE_BOTONESHOTONEKILL: + continue; + } + if ( !strcmp(arg1,modestrings[i]) ) + { + string n; + itoa(n, i+GMODE_NUM); + nextmode=i+GMODE_NUM; + callvote(SA_MAP, arg2, n); + return; + } + } + +} +COMMAND(setnext, ARG_2STR); + COMMANDN(callvote, scallvote, ARG_3STR); //fixme,ah COMMAND(vote, ARG_1EXP); diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 3bf455c1..8f219a62 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -118,7 +118,7 @@ void parsepositions(ucharbuf &p) int cn, f, g; vec o, vel; float yaw, pitch, roll = 0; - bool scoping = false; + bool scoping, shoot; if(type == SV_POSC) { bitbuf q(p); @@ -146,6 +146,7 @@ void parsepositions(ucharbuf &p) if(negz) z = -z; o.z = z / DMF; scoping = ( q.getbits(1) ? true : false ); + shoot = ( q.getbits(1) ? true : false ); } else { @@ -161,6 +162,7 @@ void parsepositions(ucharbuf &p) if ((g>>1) & 1) vel.y = getint(p)/DVELF; else vel.y = 0; if ((g>>2) & 1) vel.z = getint(p)/DVELF; else vel.z = 0; scoping = ( (g>>4) & 1 ? true : false ); + shoot = ( (g>>5) & 1 ? true : false ); // we are not using this yet f = getuint(p); } int seqcolor = (f>>6)&1; @@ -838,6 +840,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) case SV_GAMEMODE: nextmode = getint(p); + if (nextmode >= GMODE_NUM) nextmode -= GMODE_NUM; break; case SV_TIMEUP: diff --git a/source/src/entity.h b/source/src/entity.h index 15dc3b82..862002f2 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -104,7 +104,7 @@ public: int timeinair; // used for fake gravity float radius, eyeheight, maxeyeheight, aboveeye; // bounding box size bool inwater; - bool onfloor, onladder, jumpnext, crouching, crouchedinair, trycrouch, cancollide, stuck, scoping; + bool onfloor, onladder, jumpnext, crouching, crouchedinair, trycrouch, cancollide, stuck, scoping, shoot; int lastjump; int lastsplash; char move, strafe; @@ -113,7 +113,7 @@ public: int last_pos; physent() : o(0, 0, 0), deltapos(0, 0, 0), newpos(0, 0, 0), yaw(270), pitch(0), roll(0), pitchvel(0), - crouching(false), crouchedinair(false), trycrouch(false), cancollide(true), stuck(false), scoping(false), lastjump(0), lastsplash(0), state(CS_ALIVE), last_pos(0) + crouching(false), crouchedinair(false), trycrouch(false), cancollide(true), stuck(false), scoping(false), shoot(false), lastjump(0), lastsplash(0), state(CS_ALIVE), last_pos(0) { reset(); } diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index 388b6dc3..47167bc8 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -307,7 +307,7 @@ const char *modeacronymnames[] = "OSOK", "TOSOK", "BOSOK", "HTF", "TKTF", "KTF" }; -const char *voteerrors[] = { "voting is currently disabled", "there is already a vote pending", "already voted", "can't vote that often", "this vote is not allowed in the current environment (singleplayer/multiplayer)", "no permission", "invalid vote", "server denied your call" }; +const char *voteerrors[] = { "voting is currently disabled", "there is already a vote pending", "already voted", "can't vote that often", "this vote is not allowed in the current environment (singleplayer/multiplayer)", "no permission", "invalid vote", "server denied your call", "the next map/mode is already set" }; const char *mmfullnames[] = { "open", "private", "match" }; const char *fullmodestr(int n) { return (n>=-1 && size_t(n+1) < sizeof(modefullnames)/sizeof(modefullnames[0])) ? modefullnames[n+1] : "unknown"; } diff --git a/source/src/protocol.h b/source/src/protocol.h index 4d9938fa..969d5358 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -53,7 +53,7 @@ extern const char *messagenames[SV_NUM]; 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_SERVERDESC, SA_SHUFFLETEAMS, SA_NUM}; enum { VOTE_NEUTRAL = 0, VOTE_YES, VOTE_NO, VOTE_NUM }; -enum { VOTEE_DISABLED = 0, VOTEE_CUR, VOTEE_MUL, VOTEE_MAX, VOTEE_AREA, VOTEE_PERMISSION, VOTEE_INVALID, VOTEE_WEAK, VOTEE_NUM }; +enum { VOTEE_DISABLED = 0, VOTEE_CUR, VOTEE_MUL, VOTEE_MAX, VOTEE_AREA, VOTEE_PERMISSION, VOTEE_INVALID, VOTEE_WEAK, VOTEE_NEXT, VOTEE_NUM }; enum { MM_OPEN = 0, MM_PRIVATE, MM_MATCH, MM_NUM }; enum { MM_MASK = 0x03 }; enum { AT_DISABLED = 0, AT_ENABLED = 1, AT_SHUFFLE = 2, AT_NUM }; enum { FA_PICKUP = 0, FA_STEAL, FA_DROP, FA_LOST, FA_RETURN, FA_SCORE, FA_NUM, FA_RESET }; diff --git a/source/src/server.cpp b/source/src/server.cpp index 4e45a104..fa04e61b 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -2051,6 +2051,8 @@ void scallvoteerr(voteinfo *v, int error) logline(ACLOG_INFO, "[%s] client %s failed to call a vote: %s (%s)", clients[v->owner]->hostname, clients[v->owner]->name, v->action->desc ? v->action->desc : "[unknown]", voteerrorstr(error)); } +bool map_queued = false; + bool scallvote(voteinfo *v, ENetPacket *msg) // true if a regular vote was called { int area = isdedicated ? EE_DED_SERV : EE_LOCAL_SERV; @@ -2066,6 +2068,7 @@ bool scallvote(voteinfo *v, ENetPacket *msg) // true if a regular vote was calle else if( v->action->role > c->role ) error = VOTEE_PERMISSION; else if( !(area & v->action->area) ) error = VOTEE_AREA; else if( curvote && curvote->result==VOTE_NEUTRAL ) error = VOTEE_CUR; + else if( v->type == SA_MAP && v->num >= GMODE_NUM && map_queued ) error = VOTEE_NEXT; else if( c->role == CR_DEFAULT && v->action->isdisabled() ) error = VOTEE_DISABLED; else if( (c->lastvotecall && servmillis - c->lastvotecall < 60*1000 && c->role != CR_ADMIN && numclients()>1) || c->nvotes > 3 ) error = VOTEE_MAX; else if( v->boot && c->role < roleconf('W') && !is_lagging(b) && !b->mute && b->spamcount < 2 ) { @@ -2082,6 +2085,12 @@ bool scallvote(voteinfo *v, ENetPacket *msg) // true if a regular vote was calle } else { + if ( v->type == SA_MAP && v->num >= GMODE_NUM ) + { + map_queued = true; + nextgamemode = v->num-GMODE_NUM; + copystring(nextmapname, v->text); + } sendpacket(-1, 1, msg, v->owner); scallvotesuc(v); return true; @@ -2844,7 +2853,8 @@ void process(ENetPacket *packet, int sender, int chan) } seteventmillis(shot.shot); shot.shot.gun = getint(p); - loopk(3) shot.shot.from[k] = getint(p)/DMF; +// loopk(3) shot.shot.from[k] = getint(p)/DMF; + loopk(3) { shot.shot.from[k] = cl->state.o.v[k] + ( k == 2 ? (((cl->f>>7)&1)?2.2f:4.2f) : 0); getint(p);} loopk(3) shot.shot.to[k] = getint(p)/DMF; checkshoot(sender, &shot); int hits = getint(p); @@ -2935,7 +2945,7 @@ void process(ENetPacket *packet, int sender, int chan) val[1] = getint(p); int g = getuint(p); // g loopi(4) if ( (g >> i) & 1 ) getint(p); - val[2] = getuint(p); + val[2] = clients[cn]->f = getuint(p); if(!cl->isonrightmap) break; if(cl->type==ST_TCPIP && (cl->state.state==CS_ALIVE || cl->state.state==CS_EDITING)) { @@ -2968,7 +2978,7 @@ void process(ENetPacket *packet, int sender, int chan) if(!q.getbits(1)) q.getbits(6); if(!q.getbits(1)) q.getbits(4 + 4 + 4); int f = q.getbits(8); - val[2] = f; + val[2] = clients[cn]->f = f; int negz = q.getbits(1); int zfull = q.getbits(1); int s = q.rembits(); @@ -2977,6 +2987,7 @@ void process(ENetPacket *packet, int sender, int chan) int zt = q.getbits(s); if(negz) zt = -zt; q.getbits(1); // scoping + q.getbits(1); // shooting if(!cl->isonrightmap || p.remaining() || p.overread()) { p.flags = 0; break; } if(((f >> 6) & 1) != (cl->state.lifesequence & 1) || usefactor != (smapstats.hdr.sfactor < 7 ? 7 : smapstats.hdr.sfactor)) break; @@ -3132,12 +3143,13 @@ void process(ENetPacket *packet, int sender, int chan) case SA_MAP: { getstring(text, p); - strncpy(vi->text,text,MAXTRANS-1); filtertext(text, text); + strncpy(vi->text,text,MAXTRANS-1); int mode = getint(p); vi->num = mode; + int qmode = (mode >= GMODE_NUM ? mode - GMODE_NUM : mode); if(mode==GMODE_DEMO) vi->action = new demoplayaction(newstring(text)); - else vi->action = new mapaction(newstring(text), mode, sender); + else vi->action = new mapaction(newstring(text), qmode, sender, qmode!=mode); break; } case SA_KICK: @@ -3541,6 +3553,7 @@ void serverslice(uint timeout) // main server update, called from cube main lo //start next game if(nextmapname[0]) startgame(nextmapname, nextgamemode); else maprot.next(); + map_queued = false; } resetserverifempty(); diff --git a/source/src/serveractions.h b/source/src/serveractions.h index fee14ea3..39b4c9a3 100644 --- a/source/src/serveractions.h +++ b/source/src/serveractions.h @@ -57,9 +57,10 @@ struct mapaction : serveraction { char *map; int mode; - bool mapok; + bool mapok, queue; void perform() { + if (queue) return; if(isdedicated && numclients() > 2 && smode >= 0 && smode != 1 && gamemillis > gamelimit/4) { forceintermission = true; @@ -73,7 +74,7 @@ struct mapaction : serveraction } bool isvalid() { return serveraction::isvalid() && mode != GMODE_DEMO && map[0] && mapok && !(isdedicated && !m_mp(mode)); } bool isdisabled() { return maprot.current() && !maprot.current()->vote; } - mapaction(char *map, int mode, int caller) : map(map), mode(mode) + mapaction(char *map, int mode, int caller, bool q) : map(map), mode(mode), queue(q) { if(isdedicated) { diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 7e009fe7..0885479a 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -1017,6 +1017,7 @@ bool gun::attack(vec &targ) mag--; sendshoot(from, to); + owner->shoot = true; return true; }