From: Tupone A. <at...@us...> - 2004-04-17 15:22:02
|
Update of /cvsroot/bzflag/bzflag/src/bzfs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18600 Modified Files: PlayerInfo.cxx PlayerInfo.h bzfs.cxx Log Message: Some little code re-arrangement Index: PlayerInfo.cxx =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzfs/PlayerInfo.cxx,v retrieving revision 1.21 retrieving revision 1.22 diff -w -u -r1.21 -r1.22 --- PlayerInfo.cxx 15 Apr 2004 21:24:14 -0000 1.21 +++ PlayerInfo.cxx 17 Apr 2004 15:21:48 -0000 1.22 @@ -52,7 +52,7 @@ #endif }; -void PlayerInfo::resetPlayer() { +void PlayerInfo::resetPlayer(bool ctf) { wasRabbit = false; toBeKicked = false; Admin = false; @@ -102,13 +102,26 @@ #ifdef TIMELIMIT playedEarly = false; #endif + + restartOnBase = ctf; } bool PlayerInfo::isAccessVerified() const { return accessInfo.verified; } -void PlayerInfo::resetAccess() { +bool PlayerInfo::removePlayer(const char *reason) { + + // check if we are called again for a dropped player! + if (fd == -1) + return false; + + bool wasPlaying = state > PlayerInLimbo; + + // status message + DEBUG1("Player %s [%d] on %d removed: %s\n", callSign, playerIndex, fd, + reason); + // shutdown TCP socket shutdown(fd, 2); close(fd); @@ -149,6 +162,16 @@ hostname = NULL; } #endif + + state = PlayerNoExist; + +#ifdef NETWORK_STATS + if (wasPlaying) { + dumpMessageStats(); + } +#endif + + return wasPlaying; } bool PlayerInfo::gotAccessFailure() { @@ -536,12 +559,6 @@ ntohs(_uaddr.sin_port), udpSocket); }; -void PlayerInfo::debugRemove(const char *reason) { - // status message - DEBUG1("Player %s [%d] on %d removed: %s\n", callSign, playerIndex, fd, - reason); -}; - void PlayerInfo::debugAdd() { DEBUG1("Player %s [%d] has joined from %s:%d on %i\n", callSign, playerIndex, inet_ntoa(taddr.sin_addr), @@ -628,14 +645,6 @@ return state == PlayerAlive; }; -bool PlayerInfo::isInLimbo() { - return state == PlayerInLimbo; -}; - -void PlayerInfo::remove() { - state = PlayerNoExist; -}; - bool PlayerInfo::isDead() { return state == PlayerDead; }; @@ -668,7 +677,7 @@ return buf; }; -void *PlayerInfo::unpackEnter(void *buf) { +void PlayerInfo::unpackEnter(void *buf) { // data: type, team, name, email uint16_t _type; int16_t _team; @@ -678,7 +687,8 @@ team = TeamColor(_team); buf = nboUnpackString(buf, callSign, CallSignLen); buf = nboUnpackString(buf, email, EmailLen); - return buf; + cleanCallSign(); + cleanEMail(); }; void PlayerInfo::getLagStats(char* msg) { Index: PlayerInfo.h =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzfs/PlayerInfo.h,v retrieving revision 1.41 retrieving revision 1.42 diff -w -u -r1.41 -r1.42 --- PlayerInfo.h 15 Apr 2004 18:45:06 -0000 1.41 +++ PlayerInfo.h 17 Apr 2004 15:21:48 -0000 1.42 @@ -87,9 +87,10 @@ public: void initPlayer(const struct sockaddr_in& clientAddr, int _fd, int _playerIndex); - void resetPlayer(); + void resetPlayer(bool ctf); bool isAccessVerified() const; - void resetAccess(); + // return false if player was not really in + bool removePlayer(const char *reason); bool gotAccessFailure(); void setLoginFail(); void reloadInfo(); @@ -111,9 +112,6 @@ void storeInfo(const char* pwd); void setPassword(const std::string& pwd); void initStatistics(); -#ifdef NETWORK_STATS - void dumpMessageStats(); -#endif bool isConnected(); int pflush(fd_set *set); RxStatus receive(size_t length); @@ -127,7 +125,6 @@ void dropUnconnected(); void debugUdpInfo(); void debugUdpRead(int n, struct sockaddr_in &_uaddr, int udpSocket); - void debugRemove(const char *reason); void debugAdd(); void fdSet(fd_set *read_set, fd_set *write_set, int &maxFile); int fdIsSet(fd_set *set); @@ -142,21 +139,17 @@ bool exist(); void signingOn(); bool isAlive(); - bool isInLimbo(); - void remove(); bool isDead(); void setAlive(); void setDead(); bool isBot(); bool isHuman(); void *packUpdate(void *buf); - void *unpackEnter(void *buf); + void unpackEnter(void *buf); void getLagStats(char* msg); const char *getCallSign() const; - void cleanCallSign(); bool isCallSignReadable(); const char *getEMail() const; - void cleanEMail(); bool isEMailReadable(); void *packVirtualFlagCapture(void *buf); bool isTeam(TeamColor team) const; @@ -211,9 +204,14 @@ void countMessage(uint16_t code, int len, int direction); #endif private: + void cleanCallSign(); + void cleanEMail(); void udpSend(int udpSocket, const void *b, size_t l); int send(const void *buffer, size_t length); int bufferedSend(int playerIndex, const void *buffer, size_t length); +#ifdef NETWORK_STATS + void dumpMessageStats(); +#endif int playerIndex; Index: bzfs.cxx =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzfs/bzfs.cxx,v retrieving revision 1.644 retrieving revision 1.645 diff -w -u -r1.644 -r1.645 --- bzfs.cxx 15 Apr 2004 18:45:06 -0000 1.644 +++ bzfs.cxx 17 Apr 2004 15:21:48 -0000 1.645 @@ -1533,8 +1533,6 @@ static void addPlayer(int playerIndex) { - player[playerIndex].cleanCallSign(); - // don't allow empty callsign if (player[playerIndex].getCallSign()[0] == '\0') rejectPlayer(playerIndex, RejectBadCallsign); @@ -1570,8 +1568,6 @@ rejectPlayer(playerIndex, RejectBadCallsign); } - player[playerIndex].cleanEMail(); - // make sure the email is not obscene/filtered if (clOptions->filterCallsigns) { DEBUG2("checking email: %s\n",player[playerIndex].getEMail()); @@ -1671,8 +1667,7 @@ rejectPlayer(playerIndex, RejectTeamFull); return ; } - player[playerIndex].resetPlayer(); - player[playerIndex].setRestartOnBase + player[playerIndex].resetPlayer ((clOptions->gameStyle & TeamFlagGameStyle) != 0); // accept player @@ -2104,40 +2099,16 @@ // not to undo operations that haven't been done. // first shutdown connection - // check if we are called again for a dropped player! - if (!player[playerIndex].isConnected()) - return; - - if (reason == NULL) - reason = ""; - - // status message - player[playerIndex].debugRemove(reason); - // send a super kill to be polite if (notify) directMessage(playerIndex, MsgSuperKill, 0, getDirectMessageBuffer()); - player[playerIndex].resetAccess(); + bool wasPlaying = player[playerIndex].removePlayer(reason); // player is outta here. if player never joined a team then // don't count as a player. - if (player[playerIndex].isInLimbo()) { - player[playerIndex].remove(); - - while ((playerIndex >= 0) - && (playerIndex+1 == curMaxPlayers) - && !player[playerIndex].exist() - && !player[playerIndex].isConnected()) - { - playerIndex--; - curMaxPlayers--; - } - return; - } - - player[playerIndex].remove(); + if (wasPlaying) { // if there is an active poll, cancel any vote this player may have made static VotingArbiter *arbiter = (VotingArbiter *)BZDB.getPointer("poll"); if ((arbiter != NULL) && (arbiter->knowsPoll())) { @@ -2189,14 +2160,11 @@ sendTeamUpdate(-1, teamNum); } -#ifdef NETWORK_STATS - player[playerIndex].dumpMessageStats(); -#endif - fixTeamCount(); // tell the list server the new number of players listServerLink->queueMessage(ListServerLink::ADD); + } while ((playerIndex >= 0) && (playerIndex+1 == curMaxPlayers) @@ -2207,6 +2175,7 @@ curMaxPlayers--; } + if (wasPlaying) { // anybody left? int i; for (i = 0; i < curMaxPlayers; i++) @@ -2235,6 +2204,7 @@ } } } +} // are the two teams foes withthe current game style? static bool areFoes(TeamColor team1, TeamColor team2) @@ -3218,7 +3188,7 @@ switch (code) { // player joining case MsgEnter: { - buf = player[t].unpackEnter(buf); + player[t].unpackEnter(buf); addPlayer(t); player[t].debugAdd(); break; |