Update of /cvsroot/bzflag/bzflag/src/bzflag In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22482/src/bzflag Modified Files: CommandsImplementation.cxx ComposeDefaultKey.cxx ServerCommandKey.cxx ServerLink.cxx ServerLink.h clientCommands.cxx playing.cxx playing.h Log Message: All packets related to players have the player-id inside the message Index: CommandsImplementation.cxx =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/CommandsImplementation.cxx,v retrieving revision 2.27 retrieving revision 2.28 diff -w -u -r2.27 -r2.28 --- CommandsImplementation.cxx 23 Nov 2005 01:34:58 -0000 2.27 +++ CommandsImplementation.cxx 9 Dec 2005 15:15:38 -0000 2.28 @@ -208,11 +208,8 @@ "Server-side Commands"); const char* msg = "/?"; - const int msgLen = strlen(msg) + 1; - cptr = (char*) nboPackUByte(buffer, ServerPlayer); - nboPackString(cptr, msg, msgLen); - serverLink->send(MsgMessage, PlayerIdPLen + msgLen, buffer); - + strncpy(buffer, msg, MessageLen); + serverLink->sendMessage(ServerPlayer, buffer); return true; } @@ -269,9 +266,7 @@ char messageBuffer[MessageLen]; memset(messageBuffer, 0, MessageLen); strncpy(messageBuffer, "/clientquery", MessageLen); - nboPackString(messageMessage + PlayerIdPLen, messageBuffer, MessageLen); - serverLink->send(MsgMessage, sizeof(messageMessage), messageMessage); - + serverLink->sendMessage(msgDestination, messageBuffer); return true; } @@ -504,8 +499,7 @@ char messageBuffer[MessageLen]; // send message memset(messageBuffer, 0, MessageLen); strncpy(messageBuffer, commandLine, MessageLen); - nboPackString(messageMessage + PlayerIdPLen, messageBuffer, MessageLen); - serverLink->send(MsgMessage, sizeof(messageMessage), messageMessage); + serverLink->sendMessage(msgDestination, messageBuffer); CommandsStandard::quit(); // kill client return true; } Index: ComposeDefaultKey.cxx =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/ComposeDefaultKey.cxx,v retrieving revision 2.18 retrieving revision 2.19 diff -w -u -r2.18 -r2.19 --- ComposeDefaultKey.cxx 23 Nov 2005 01:34:58 -0000 2.18 +++ ComposeDefaultKey.cxx 9 Dec 2005 15:15:38 -0000 2.19 @@ -94,9 +94,7 @@ char messageBuffer[MessageLen]; memset(messageBuffer, 0, MessageLen); strncpy(messageBuffer, message.c_str(), MessageLen); - nboPackString(messageMessage + PlayerIdPLen, messageBuffer, - MessageLen); - serverLink->send(MsgMessage, sizeof(messageMessage), messageMessage); + serverLink->sendMessage(msgDestination, messageBuffer); } // record message in history @@ -155,8 +153,7 @@ selectNextRecipient(key.button != BzfKeyEvent::Left, false); const Player *recipient = myTank->getRecipient(); if (recipient) { - void* buf = messageMessage; - buf = nboPackUByte(buf, recipient->getId()); + msgDestination = recipient->getId(); std::string composePrompt = "Send to "; composePrompt += recipient->getCallSign(); composePrompt += ": "; Index: ServerCommandKey.cxx =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/ServerCommandKey.cxx,v retrieving revision 2.5 retrieving revision 2.6 diff -w -u -r2.5 -r2.6 --- ServerCommandKey.cxx 23 Oct 2005 09:45:37 -0000 2.5 +++ ServerCommandKey.cxx 9 Dec 2005 15:15:38 -0000 2.6 @@ -352,19 +352,14 @@ if (sendMsg.find("/password", 0) == std::string::npos) addMessage(NULL, displayMsg, 2); - void* buf = messageMessage; - buf = nboPackUByte(buf, ServerPlayer); - char messageBuffer[MessageLen]; memset(messageBuffer, 0, MessageLen); strncpy(messageBuffer, sendMsg.c_str(), MessageLen); - buf = nboPackString(buf, messageBuffer, MessageLen); - serverLink->send(MsgMessage, sizeof(messageMessage), messageMessage); + serverLink->sendMessage(ServerPlayer, messageBuffer); } } hud->setComposing(std::string()); - //myTank->setRecipient(NULL); HUDui::setDefaultKey(NULL); return true; } Index: ServerLink.cxx =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/ServerLink.cxx,v retrieving revision 2.13 retrieving revision 2.14 diff -w -u -r2.13 -r2.14 --- ServerLink.cxx 27 Nov 2005 18:02:21 -0000 2.13 +++ ServerLink.cxx 9 Dec 2005 15:15:38 -0000 2.14 @@ -559,9 +559,11 @@ const char* token) { if (state != Okay) return; - char msg[PlayerIdPLen + 4 + CallSignLen + EmailLen + TokenLen + VersionLen] = {0}; + char msg[MaxPacketLen] = {0}; void* buf = msg; + buf = nboPackUByte(buf, uint8_t(getId())); + buf = nboPackUShort(buf, uint16_t(type)); buf = nboPackUShort(buf, uint16_t(team)); ::strncpy((char*)buf, name, CallSignLen - 1); @@ -572,7 +574,7 @@ buf = (void*)((char*)buf + TokenLen); ::strncpy((char*)buf, getAppVersion(), VersionLen - 1); buf = (void*)((char*)buf + VersionLen); - send(MsgEnter, sizeof(msg), msg); + send(MsgEnter, (char*)buf - msg, msg); } bool ServerLink::readEnter (std::string& reason, @@ -615,22 +617,27 @@ #ifndef BUILDING_BZADMIN void ServerLink::sendCaptureFlag(TeamColor team) { - char msg[2]; - nboPackUShort(msg, uint16_t(team)); + char msg[3]; + void* buf = msg; + buf = nboPackUByte(buf, uint8_t(getId())); + nboPackUShort(buf, uint16_t(team)); send(MsgCaptureFlag, sizeof(msg), msg); } void ServerLink::sendGrabFlag(int flagIndex) { - char msg[2]; - nboPackUShort(msg, uint16_t(flagIndex)); + char msg[3]; + void* buf = msg; + buf = nboPackUByte(buf, uint8_t(getId())); + nboPackUShort(buf, uint16_t(flagIndex)); send(MsgGrabFlag, sizeof(msg), msg); } void ServerLink::sendDropFlag(const float* position) { - char msg[12]; + char msg[13]; void* buf = msg; + buf = nboPackUByte(buf, uint8_t(getId())); buf = nboPackVector(buf, position); send(MsgDropFlag, sizeof(msg), msg); } @@ -640,9 +647,10 @@ const FlagType* flagType, int phydrv) { - char msg[PlayerIdPLen + 2 + 2 + FlagPackSize + 4]; + char msg[6 + FlagPackSize + 4]; void* buf = msg; + buf = nboPackUByte(buf, getId()); buf = nboPackUByte(buf, killer); buf = nboPackUShort(buf, int16_t(reason)); buf = nboPackShort(buf, int16_t(shotId)); @@ -710,13 +718,18 @@ void ServerLink::sendAlive() { - send(MsgAlive, 0, NULL); + char msg[1]; + + msg[0] = getId(); + + send(MsgAlive, sizeof(msg), msg); } void ServerLink::sendTeleport(int from, int to) { - char msg[4]; + char msg[5]; void* buf = msg; + buf = nboPackUByte(buf, uint8_t(getId())); buf = nboPackUShort(buf, uint16_t(from)); buf = nboPackUShort(buf, uint16_t(to)); send(MsgTeleport, sizeof(msg), msg); @@ -738,14 +751,52 @@ void ServerLink::sendPaused(bool paused) { - uint8_t p = paused; - send(MsgPause, 1, &p); + char msg[2]; + void* buf = msg; + buf = nboPackUByte(buf, uint8_t(getId())); + buf = nboPackUByte(buf, uint8_t(paused)); + send(MsgPause, sizeof(msg), msg); +} + +void ServerLink::sendExit() +{ + char msg[1]; + + msg[0] = getId(); + + send(MsgExit, sizeof(msg), msg); } void ServerLink::sendAutoPilot(bool autopilot) { - uint8_t p = autopilot; - send(MsgAutoPilot, 1, &p); + char msg[2]; + void* buf = msg; + buf = nboPackUByte(buf, uint8_t(getId())); + buf = nboPackUByte(buf, uint8_t(autopilot)); + send(MsgAutoPilot, sizeof(msg), msg); +} + +void ServerLink::sendMessage(const PlayerId& to, char message[MessageLen]) +{ + char msg[MaxPacketLen]; + void* buf = msg; + + buf = nboPackUByte(buf, uint8_t(getId())); + buf = nboPackUByte(buf, uint8_t(to)); + buf = nboPackString(buf, message, MessageLen); + + send(MsgMessage, (char *)buf - msg, msg); +} + +void ServerLink::sendLagPing(char pingRequest[2]) +{ + char msg[3]; + void* buf = msg; + + buf = nboPackUByte(buf, uint8_t(getId())); + buf = nboPackString(buf, pingRequest, sizeof(pingRequest)); + + send(MsgLagPing, sizeof(msg), msg); } void ServerLink::sendUDPlinkRequest() @@ -829,9 +880,19 @@ void ServerLink::sendKerberosTicket(const char *principal, const krb5_data *ticket) { + char msg[MaxPacketLen]; + void* buf = msg; + DEBUG3("Sent authentication ticket to server : \n"); - send(MsgKrbPrincipal, strlen(principal), principal); - send(MsgKrbTicket, ticket->length, ticket->data); + + buf = nboPackUByte(buf, uint8_t(getId())); + buf = nboPackString(buf, principal, strlen(principal)); + send(MsgKrbPrincipal, (char *)buf - msg, msg); + + buf = msg; + buf = nboPackUByte(buf, uint8_t(getId())); + buf = nboPackString(buf, ticket->data, ticket->length); + send(MsgKrbTicket, (char *)buf - msg, msg); } #endif Index: ServerLink.h =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/ServerLink.h,v retrieving revision 2.6 retrieving revision 2.7 diff -w -u -r2.6 -r2.7 --- ServerLink.h 13 Nov 2005 03:25:44 -0000 2.6 +++ ServerLink.h 9 Dec 2005 15:15:38 -0000 2.7 @@ -97,7 +97,11 @@ void sendTransferFlag(const PlayerId&, const PlayerId&); void sendNewRabbit(); void sendPaused(bool paused); + void sendExit(); void sendAutoPilot(bool autopilot); + void sendMessage(const PlayerId& to, + char message[MessageLen]); + void sendLagPing(char pingRequest[]); void sendUDPlinkRequest(); static ServerLink* getServer(); // const Index: clientCommands.cxx =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/clientCommands.cxx,v retrieving revision 2.21 retrieving revision 2.22 diff -w -u -r2.21 -r2.22 --- clientCommands.cxx 25 Oct 2005 02:40:45 -0000 2.21 +++ clientCommands.cxx 9 Dec 2005 15:15:38 -0000 2.22 @@ -576,19 +576,16 @@ return "use send only when connected"; std::string composePrompt; if (args[0] == "all") { - void* buf = messageMessage; - buf = nboPackUByte(buf, AllPlayers); + msgDestination = AllPlayers; composePrompt = "Send to all: "; } else if (args[0] == "team") { - void* buf = messageMessage; - buf = nboPackUByte(buf, TeamToPlayerId(myTank->getTeam())); + msgDestination = myTank->getTeam(); composePrompt = "Send to teammates: "; } else if (args[0] == "nemesis") { const Player* nemesis = myTank->getNemesis(); - if (!nemesis) return std::string(); - - void* buf = messageMessage; - buf = nboPackUByte(buf, nemesis->getId()); + if (!nemesis) + return std::string(); + msgDestination = nemesis->getId(); composePrompt = "Send to "; composePrompt += nemesis->getCallSign(); composePrompt += ": "; @@ -604,17 +601,14 @@ } recipient = myTank->getRecipient(); if (recipient) { - void* buf = messageMessage; - buf = nboPackUByte(buf, recipient->getId()); + msgDestination = recipient->getId(); composePrompt = "Send to "; composePrompt += recipient->getCallSign(); composePrompt += ": "; } } else if (args[0] == "admin") { - void* buf = messageMessage; - buf = nboPackUByte(buf, AdminPlayers); + msgDestination = AdminPlayers; composePrompt = "Send to Admin : "; - } else { return "usage: send {all|team|nemesis|recipient|admin}"; } Index: playing.cxx =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/playing.cxx,v retrieving revision 2.165 retrieving revision 2.166 diff -w -u -r2.165 -r2.166 --- playing.cxx 23 Nov 2005 21:43:20 -0000 2.165 +++ playing.cxx 9 Dec 2005 15:15:38 -0000 2.166 @@ -143,7 +143,7 @@ static MessageOfTheDay *motd = NULL; DefaultCompleter completer; -char messageMessage[PlayerIdPLen + MessageLen]; +PlayerId msgDestination; static void setHuntTarget(); static void setTankFlags(); @@ -718,13 +718,13 @@ if (pressed) { char name[32]; int msgno = (key.button - BzfKeyEvent::F1) + 1; - void* buf = messageMessage; + PlayerId to; if (key.shift == BzfKeyEvent::ControlKey) { sprintf(name, "quickTeamMessage%d", msgno); - buf = nboPackUByte(buf, TeamToPlayerId(myTank->getTeam())); + to = myTank->getTeam(); } else { sprintf(name, "quickMessage%d", msgno); - buf = nboPackUByte(buf, AllPlayers); + to = AllPlayers; } if (BZDB.isSet(name)) { char messageBuffer[MessageLen]; @@ -732,8 +732,7 @@ strncpy(messageBuffer, BZDB.get(name).c_str(), MessageLen); - nboPackString(buf, messageBuffer, MessageLen); - serverLink->send(MsgMessage, sizeof(messageMessage), messageMessage); + serverLink->sendMessage(to, messageBuffer); } } } else if (myTank->isAlive()) { @@ -2058,10 +2057,7 @@ strncpy(meaculpa, "sorry, i'm just a silly machine", MessageLen); - char *buf = messageMessage; - buf = (char*)nboPackUByte(buf, victimPlayer->getId()); - nboPackString(buf, meaculpa, MessageLen-1); - serverLink->send(MsgMessage, sizeof(messageMessage), messageMessage); + serverLink->sendMessage(victimPlayer->getId(), meaculpa); } } } else { @@ -2278,10 +2274,7 @@ char meaculpa[MessageLen]; memset(meaculpa, 0, MessageLen); strncpy(meaculpa, "sorry, i'm just a silly machine", MessageLen); - char *buf = messageMessage; - buf = (char*)nboPackUShort(buf, myTank->getTeam()); - nboPackString(buf, meaculpa, MessageLen-1); - serverLink->send(MsgMessage, sizeof(messageMessage), messageMessage); + serverLink->sendMessage(myTank->getTeam(), meaculpa); } } } else { @@ -2618,14 +2611,16 @@ for (size_t j = 0; j < countof(passwdKeys); j++) { if (BZDB.isSet(passwdKeys[j])) { + char messageBuffer[MessageLen]; + memset(messageBuffer, 0, MessageLen); std::string passwdResponse = "/identify " + BZDB.get(passwdKeys[j]); addMessage(0, ("Autoidentifying with password stored for " + passwdKeys[j]).c_str(), 2, false); - void *buf = messageMessage; - buf = nboPackUByte(buf, ServerPlayer); - nboPackString(buf, (void*) passwdResponse.c_str(), MessageLen); - serverLink->send(MsgMessage, sizeof(messageMessage), messageMessage); + strncpy(messageBuffer, + passwdResponse.c_str(), + MessageLen); + serverLink->sendMessage(ServerPlayer, messageBuffer); break; } } @@ -2965,7 +2960,7 @@ // just echo lag ping message case MsgLagPing: - serverLink->send(MsgLagPing,2,msg); + serverLink->sendLagPing((char *)msg); break; } } @@ -4414,7 +4409,7 @@ int i; for (i = 0; i < numRobots; i++) { if (robots[i] && robotServer[i]) - robotServer[i]->send(MsgExit, 0, NULL); + robotServer[i]->sendExit(); delete robots[i]; delete robotServer[i]; robots[i] = NULL; @@ -4476,7 +4471,7 @@ hud->setAltitudeTape(false); // shut down server connection - if (sayGoodbye) serverLink->send(MsgExit, 0, NULL); + if (sayGoodbye) serverLink->sendExit(); ServerLink::setServer(NULL); delete serverLink; serverLink = NULL; Index: playing.h =================================================================== RCS file: /cvsroot/bzflag/bzflag/src/bzflag/playing.h,v retrieving revision 2.14 retrieving revision 2.15 diff -w -u -r2.14 -r2.15 --- playing.h 28 Oct 2005 18:52:52 -0000 2.14 +++ playing.h 9 Dec 2005 15:15:38 -0000 2.15 @@ -97,7 +97,7 @@ extern void joinGame(); extern HUDRenderer *hud; -extern char messageMessage[PlayerIdPLen + MessageLen]; +extern PlayerId msgDestination; extern ServerLink* serverLink; extern int numFlags; extern StartupInfo startupInfo; |