[Gcblue-commits] gcb_wx/src/network tcConnectionData.cpp,1.11,1.12 tcMultiplayerInterface.cpp,1.22,1
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-04-17 22:35:40
|
Update of /cvsroot/gcblue/gcb_wx/src/network In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14954/src/network Modified Files: tcConnectionData.cpp tcMultiplayerInterface.cpp tcNetworkInterface.cpp tcUpdateMessageHandler.cpp Log Message: fixed problem writing to account database, added command state update as part of create update for new objects at client, removed application-level command ack Index: tcUpdateMessageHandler.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcUpdateMessageHandler.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** tcUpdateMessageHandler.cpp 2 Nov 2004 04:23:56 -0000 1.12 --- tcUpdateMessageHandler.cpp 17 Apr 2005 22:35:31 -0000 1.13 *************** *** 46,53 **** void tcUpdateMessageHandler::AddCommandAck(tcGameObject* obj, tcCommandStream& stream) { ! wxASSERT(stream.GetAck()); ! ! stream << obj->mnID; // write id ! *obj >> stream; } --- 46,50 ---- void tcUpdateMessageHandler::AddCommandAck(tcGameObject* obj, tcCommandStream& stream) { ! wxASSERT(false); } *************** *** 58,63 **** void tcUpdateMessageHandler::AddCommandUpdate(tcGameObject* obj, tcCommandStream& stream) { - wxASSERT(!stream.GetAck()); - stream << obj->mnID; // write id --- 55,58 ---- *************** *** 89,92 **** --- 84,92 ---- stream << obj->mnDBKey; *obj >> stream; + + tcCommandStream& commandStream = stream.AsCommandStream(); + commandStream.SetDetailLevel(tcStream::WRITE_ALL); + *obj >> commandStream; + } *************** *** 279,283 **** void tcUpdateMessageHandler::HandleCommandAck(tcCommandStream& stream) { ! stream.SetAck(true); tcSimState* simState = tcSimState::Get(); --- 279,283 ---- void tcUpdateMessageHandler::HandleCommandAck(tcCommandStream& stream) { ! wxASSERT(false); tcSimState* simState = tcSimState::Get(); *************** *** 319,328 **** - // Init ack message - tcCommandStream commandStream; - tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::COMMAND_ACK, commandStream); - commandStream.SetAck(true); - - unsigned nAcks = 0; unsigned nUnknowns = 0; --- 319,322 ---- *************** *** 339,350 **** tcGameObject* obj = simState->GetObject(id); ! // update obj and add ack if it exists, otherwise skip if (obj) { *obj << stream; - tcUpdateMessageHandler::AddCommandAck(obj, commandStream); - nAcks++; - fprintf(stdout, "%d ", id); } --- 333,341 ---- tcGameObject* obj = simState->GetObject(id); ! // update obj if it exists, otherwise skip if (obj) { *obj << stream; fprintf(stdout, "%d ", id); } *************** *** 357,368 **** } fprintf(stdout, "\n"); - - if (nAcks) - { - tcMultiplayerInterface::Get()->SendUpdateMessage(connectionId, commandStream); - #ifdef _DEBUG - fprintf(stdout, ">> Sent obj command update ack, time: %.1f\n", simState->GetTime()); - #endif - } } --- 348,351 ---- *************** *** 376,379 **** --- 359,365 ---- tcDatabase* database = simState->mpDatabase; // convert database to singleton eventually + // command stream update is located after each create update to initialize command params + tcCommandStream& commandStream = stream.AsCommandStream(); + fprintf(stdout, "<< Received obj create msg, time %.1f: ", simState->GetTime()); *************** *** 403,406 **** --- 389,394 ---- simState->AddPlatformWithKey(obj, id); fprintf(stdout, "%d (%d)", id, obj->mnAlliance); + + *obj << commandStream; } else Index: tcConnectionData.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcConnectionData.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** tcConnectionData.cpp 16 Apr 2005 20:44:43 -0000 1.11 --- tcConnectionData.cpp 17 Apr 2005 22:35:31 -0000 1.12 *************** *** 154,157 **** --- 154,162 ---- } + const char* tcConnectionData::GetIdString() const + { + return idString.c_str(); + } + const wxIPV4address& tcConnectionData::GetPeerAddress() const { *************** *** 412,416 **** UDPaddress.Service(tcNetworkInterface::UDP_PORT); ! peerName = UDPaddress.Hostname(); } --- 417,421 ---- UDPaddress.Service(tcNetworkInterface::UDP_PORT); ! peerName = UDPaddress.IPAddress().c_str(); } Index: tcMultiplayerInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcMultiplayerInterface.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** tcMultiplayerInterface.cpp 16 Apr 2005 20:44:43 -0000 1.22 --- tcMultiplayerInterface.cpp 17 Apr 2005 22:35:31 -0000 1.23 *************** *** 191,196 **** { playerStatus.name = username; ! playerStatus.isAuthenticated = true; ! msg = wxString::Format("Welcome %s\n", username.c_str()); } else if (status == tcAccountDatabase::USER_NOT_FOUND) --- 191,209 ---- { playerStatus.name = username; ! ! const tcConnectionData* const connection = networkInterface->GetConnection(connectionId); ! std::string ipAddress = connection->GetIdString(); ! ! int loginStatus = LogInPlayer(username, connectionId, msg); ! ! if (loginStatus == tcAccountDatabase::SUCCESS) ! { ! playerStatus.isAuthenticated = true; ! } ! else if (loginStatus == tcAccountDatabase::DUPLICATE_LOGIN) ! { ! playerStatus.name += "_DUP"; ! } ! } else if (status == tcAccountDatabase::USER_NOT_FOUND) *************** *** 212,215 **** --- 225,275 ---- /** + * Logs player in after username/password has been authenticated. Checks for duplicate + * logins, etc. + * @return tcAccountDatabase::SUCCESS if successful + */ + int tcMultiplayerInterface::LogInPlayer(const std::string& username, int connectionId, wxString& msg) + { + tcConnectionData* connection = networkInterface->GetConnection(connectionId); + std::string ipAddress = connection->GetIdString(); + + int loginStatus = tcAccountDatabase::Get()->LogIn(username, ipAddress); + + if (loginStatus == tcAccountDatabase::SUCCESS) + { + msg = wxString::Format("Welcome %s\n", username.c_str()); + } + else if (loginStatus == tcAccountDatabase::DUPLICATE_LOGIN) + { + msg = wxString::Format("Username, %s, is already logged in\n", username.c_str()); + } + else + { + msg = wxString::Format("Unknown login error for username, %s\n", username.c_str()); + } + + return loginStatus; + } + + /** + * Log out all players that are logged in. Call before shutting down server. + */ + void tcMultiplayerInterface::LogOutAllPlayers() + { + if (!IsServer()) return; + + for (std::map<int,tcPlayerStatus>::iterator iter = playerInfo.begin(); + iter != playerInfo.end(); ++iter) + { + if (iter->second.isAuthenticated) + { + tcAccountDatabase::Get()->LogOut(iter->second.name); + iter->second.isAuthenticated = false; + } + } + + } + + /** * Broadcast chat text to all connected clients */ *************** *** 416,419 **** --- 476,481 ---- void tcMultiplayerInterface::MakeClient() { + if (IsServer()) LogOutAllPlayers(); + networkInterface->MakeClient(); tcMessageHandler::SetAsClient(); *************** *** 436,442 **** void tcMultiplayerInterface::Reset() { ! networkInterface->MakeClient(); ! tcMessageHandler::SetAsClient(); ! InitMessageHandlers(); } --- 498,502 ---- void tcMultiplayerInterface::Reset() { ! MakeClient(); } *************** *** 878,882 **** } ! void tcMultiplayerInterface::UpdateEntityCommands(int connectionId, bool updateUnack, bool clearNewCmdFlag) { int connId = connectionId; --- 938,942 ---- } ! void tcMultiplayerInterface::UpdateEntityCommands(int connectionId, bool clearNewCmdFlag) { int connId = connectionId; *************** *** 899,903 **** if ((pstatus.alliance == obj->mnAlliance) || !IsServer()) { ! if (obj->HasNewCommand() || (updateUnack && obj->HasUnacknowledgedCommand())) { tcUpdateMessageHandler::AddCommandUpdate(obj, commandStream); --- 959,963 ---- if ((pstatus.alliance == obj->mnAlliance) || !IsServer()) { ! if (obj->HasNewCommand()) { tcUpdateMessageHandler::AddCommandUpdate(obj, commandStream); *************** *** 995,998 **** --- 1055,1071 ---- fprintf(stdout, "C%d ", obj->mnID); #endif + + if (createCount >= 8) + { + SendUpdateMessage(connId, createStream); + #ifdef _DEBUG + fprintf(stdout, "Sent obj create msg, time: %d\n", t); + #endif + createStream.clear(); + tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::CREATE, + createStream); + createCount = 0; + } + } *************** *** 1020,1024 **** /** ! * Server only for now, send state updates on objects to clients */ void tcMultiplayerInterface::UpdateEntities() --- 1093,1097 ---- /** ! * Send state updates on objects to clients (command info in both directions) */ void tcMultiplayerInterface::UpdateEntities() *************** *** 1034,1058 **** { int id = *iter; ! /* always do new cmd update, clear flag on last only (likely need ! ** to track acks for each connection, or move ack to network level */ bool clearNewCmdFlag = (n++ == nConnections - 1); ! UpdateEntityCommands(id, false, clearNewCmdFlag); tcPlayerStatus& player = GetPlayerStatus(id); unsigned int dt = t - player.entityUpdateTime; ! if ((dt > entityUpdateInterval) && (player.isAuthenticated)) ! { ! player.entityUpdateTime = t; ! if (IsServer()) ! { ! UpdateDestroyedEntities(id); ! UpdateNewAndExistingEntities(id); ! } ! UpdateEntityCommands(id, true, true); // clear new cmd flag (broken) fprintf(stdout, "Performed entity state update, conn %d, t: %d\n", id, t); ! ! } --- 1107,1130 ---- { int id = *iter; ! ! /* always do new cmd update, clear flag on last only. ! ** New commands need to be send to all clients at once with ! ** this system */ bool clearNewCmdFlag = (n++ == nConnections - 1); ! UpdateEntityCommands(id, clearNewCmdFlag); tcPlayerStatus& player = GetPlayerStatus(id); unsigned int dt = t - player.entityUpdateTime; ! ! if ((dt > entityUpdateInterval) && (player.isAuthenticated) && IsServer()) ! { ! player.entityUpdateTime = t; ! ! UpdateDestroyedEntities(id); ! UpdateNewAndExistingEntities(id); fprintf(stdout, "Performed entity state update, conn %d, t: %d\n", id, t); ! } *************** *** 1145,1148 **** --- 1217,1222 ---- eraseKeys.push(iter->first); tcSound::Get()->PlayEffect("fslide"); + + tcAccountDatabase::Get()->LogOut(iter->second.name); } *************** *** 1163,1200 **** void tcMultiplayerInterface::UpdateSensorMap(int connectionId) { - tcUpdateStream stream; - tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::SENSOR_UPDATE, stream); - int connId = connectionId; tcPlayerStatus& pstatus = GetPlayerStatus(connId); int alliance = pstatus.alliance; - tcUpdateMessageHandler::AddSensorUpdateHeader(alliance, stream); - size_t initialStreamSize = stream.size(); - tcSimState* simState = tcSimState::Get(); wxASSERT(simState); tcSensorMap* sensorMap = simState->GetSensorMap(); - wxASSERT(sensorMap); - tcAllianceSensorMap* allianceSensorMap = sensorMap->GetMap(alliance); ! if (allianceSensorMap) ! { ! *allianceSensorMap >> stream; ! if (stream.size() > initialStreamSize) ! { ! SendUpdateMessage(connId, stream); ! fprintf(stdout, ">> sensormap update msg sent, connId (%d) size (%d)\n", ! connId, stream.size()); ! } ! } ! else ! { ! fprintf(stderr, "Error - tcMultiplayerInterface::UpdateSensorMap - " ! "NULL allianceSensorMap\n"); ! } ! } --- 1237,1265 ---- void tcMultiplayerInterface::UpdateSensorMap(int connectionId) { int connId = connectionId; tcPlayerStatus& pstatus = GetPlayerStatus(connId); int alliance = pstatus.alliance; tcSimState* simState = tcSimState::Get(); wxASSERT(simState); tcSensorMap* sensorMap = simState->GetSensorMap(); tcAllianceSensorMap* allianceSensorMap = sensorMap->GetMap(alliance); + if (allianceSensorMap == 0) return; + ! tcUpdateStream stream; ! tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::SENSOR_UPDATE, stream); ! ! tcUpdateMessageHandler::AddSensorUpdateHeader(alliance, stream); ! size_t initialStreamSize = stream.size(); ! ! *allianceSensorMap >> stream; ! if (stream.size() > initialStreamSize) ! { ! SendUpdateMessage(connId, stream); ! fprintf(stdout, ">> sensormap update msg sent, connId (%d) size (%d)\n", ! connId, stream.size()); ! } } *************** *** 1269,1272 **** --- 1334,1338 ---- tcMultiplayerInterface::~tcMultiplayerInterface() { + if (IsServer()) LogOutAllPlayers(); ClearMessageMap(); if (networkInterface) delete networkInterface; Index: tcNetworkInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcNetworkInterface.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** tcNetworkInterface.cpp 16 Apr 2005 20:44:43 -0000 1.16 --- tcNetworkInterface.cpp 17 Apr 2005 22:35:31 -0000 1.17 *************** *** 66,70 **** cdata->id = connectionIndex++; - socket->SetEventHandler(*this, cdata->id); socket->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_CONNECTION_FLAG); --- 66,69 ---- *************** *** 288,291 **** --- 287,291 ---- + /** * Lookup connection by peerName and return pointer to connection data |