From 7406992171ac0503ec74a3f160493ee2a86b64f8 Mon Sep 17 00:00:00 2001 From: ac_stef Date: Thu, 2 Jul 2009 11:50:49 +0000 Subject: [PATCH] fix ctf race condition git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4561 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/entities.cpp | 3 ++- source/src/protocol.h | 2 +- source/src/server.cpp | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 07892ed8..16b380bc 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -338,12 +338,13 @@ void flagpickup(int fln) { if(flagdropmillis && flagdropmillis>lastmillis) return; flaginfo &f = flaginfos[fln]; + int action = f.state == CTFF_INBASE ? FA_STEAL : FA_PICKUP; f.flagent->spawned = false; f.state = CTFF_STOLEN; f.actor = player1; // do this although we don't know if we picked the flag to avoid getting it after a possible respawn f.actor_cn = getclientnum(); f.ack = false; - addmsg(SV_FLAGACTION, "rii", FA_PICKUP, f.team); + addmsg(SV_FLAGACTION, "rii", action, f.team); } void tryflagdrop(bool manual) diff --git a/source/src/protocol.h b/source/src/protocol.h index 8555c7be..dab2d9d0 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -76,7 +76,7 @@ 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_NUM }; enum { MM_OPEN = 0, MM_PRIVATE, MM_MATCH, MM_NUM }; enum { AT_DISABLED = 0, AT_ENABLED, AT_SHUFFLE, AT_NUM }; -enum { FA_PICKUP = 0, FA_DROP, FA_LOST, FA_RETURN, FA_SCORE, FA_NUM, FA_RESET }; +enum { FA_PICKUP = 0, FA_STEAL, FA_DROP, FA_LOST, FA_RETURN, FA_SCORE, FA_NUM, FA_RESET }; enum { FM_PICKUP = 0, FM_DROP, FM_LOST, FM_RETURN, FM_SCORE, FM_KTFSCORE, FM_SCOREFAIL, FM_RESET, FM_NUM }; #define DMF 16.0f diff --git a/source/src/server.cpp b/source/src/server.cpp index e74864c8..e5d75b69 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -717,8 +717,9 @@ void flagaction(int flag, int action, int actor) switch(action) { case FA_PICKUP: // ctf: f = enemy team htf: f = own team + case FA_STEAL: { - if(deadactor || f.state == CTFF_STOLEN) return; + if(deadactor || f.state != (action == FA_STEAL ? CTFF_INBASE : CTFF_DROPPED)) return; flagdistance(f, actor); int team = team_base(clients[actor]->team); if(m_ctf) team = team_opposite(team); @@ -770,7 +771,7 @@ void flagaction(int flag, int action, int actor) { switch(action) { - case FA_PICKUP: + case FA_STEAL: if(deadactor || f.state != CTFF_INBASE) return; flagdistance(f, actor); f.state = CTFF_STOLEN; @@ -814,7 +815,7 @@ void flagaction(int flag, int action, int actor) switch(message) { case FM_PICKUP: - logline(ACLOG_INFO,"[%s] %s stole the flag", c.hostname, c.name); + logline(ACLOG_INFO,"[%s] %s %s the flag", c.hostname, c.name, action == FA_STEAL ? "stole" : "picked up"); break; case FM_DROP: case FM_LOST: