[Gcblue-commits] gcb_wx/src/network tcMultiplayerInterface.cpp,1.31,1.32 tcNetworkInterface.cpp,1.20
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-09-10 21:47:46
|
Update of /cvsroot/gcblue/gcb_wx/src/network In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1255/src/network Modified Files: tcMultiplayerInterface.cpp tcNetworkInterface.cpp tcUpdateMessageHandler.cpp Log Message: GCB 0.8.0 release Index: tcUpdateMessageHandler.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcUpdateMessageHandler.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** tcUpdateMessageHandler.cpp 26 Jul 2005 00:37:04 -0000 1.17 --- tcUpdateMessageHandler.cpp 10 Sep 2005 21:47:38 -0000 1.18 *************** *** 38,41 **** --- 38,42 ---- #include "tcScenarioInterface.h" #include "tcMapOverlay.h" + #include "tcMessageInterface.h" #ifdef _DEBUG *************** *** 45,48 **** --- 46,63 ---- BEGIN_NAMESPACE(network) + + + void tcUpdateMessageHandler::AddBriefingText(long alliance, tcStream& stream) + { + + tcScenarioInterface* scenarioInterface = tcSimPythonInterface::Get()->GetScenarioInterface(); + wxASSERT(scenarioInterface); + + const std::string& briefingText = scenarioInterface->GetSimpleBriefing(alliance); + + stream << alliance; + stream << briefingText; + } + /** * stream must have SetAck(true) called first *************** *** 371,374 **** --- 386,396 ---- } break; + case BRIEFING_TEXT: + { + tcStream stream((const char*)data, messageSize); + stream >> messageType; + HandleBriefingText(stream); + } + break; default: fprintf(stderr, "tcUpdateMessageHandler::Handle - " *************** *** 380,383 **** --- 402,422 ---- } + void tcUpdateMessageHandler::HandleBriefingText(tcStream& stream) + { + long alliance; + std::string briefingText; + + stream >> alliance; + stream >> briefingText; + + tcScenarioInterface* scenarioInterface = tcSimPythonInterface::Get()->GetScenarioInterface(); + + scenarioInterface->SetSimpleBriefing(alliance, briefingText); + + tcMessageInterface::Get()->ClearChannel("Briefing"); + tcMessageInterface::Get()->ChannelMessage("Briefing", briefingText); + } + + /** * Handle COMMAND_ACK *************** *** 681,684 **** --- 720,728 ---- wxASSERT(simState->IsMultiplayerClient()); + // clear previous scenario info + pythonInterface->SetMenuPlatform(-1); + simState->Clear(); + + std::string scenarioName; stream >> scenarioName; Index: tcMultiplayerInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcMultiplayerInterface.cpp,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** tcMultiplayerInterface.cpp 29 Jul 2005 02:35:53 -0000 1.31 --- tcMultiplayerInterface.cpp 10 Sep 2005 21:47:38 -0000 1.32 *************** *** 273,277 **** else if (status == tcAccountDatabase::USER_NOT_FOUND) { ! msg = wxString::Format("Username, %s, does not exist\n", username.c_str()); } else if (status == tcAccountDatabase::PASSWORD_INVALID) --- 273,317 ---- else if (status == tcAccountDatabase::USER_NOT_FOUND) { ! // if acceptAllClients then add this user to the database and login ! if (acceptAllClients) ! { ! int status = tcAccountDatabase::Get()->AddUser(username, passwordHash, "unk"); ! if (status == tcAccountDatabase::SUCCESS) ! { ! msg.Printf("*** Added account for %s", username.c_str()); ! playerStatus.name = username; ! ! int loginStatus = LogInPlayer(username, connectionId, playerStatus, msg); ! ! if (loginStatus == tcAccountDatabase::SUCCESS) ! { ! playerStatus.isAuthenticated = true; ! SendSoundEffect(connectionId, "Welcome"); ! ! std::vector<int> connectionList; ! connectionList.push_back(connectionId); ! SendScenarioInfo(connectionList); ! ! wxString s = wxString::Format("*** %s has entered the game (new player)", playerStatus.GetNameWithRank().c_str()); ! BroadcastChatText(s.c_str()); ! SendChatText(connectionId, "A new account has been created for you.\n"); ! SendChatText(connectionId, "Please choose your alliance with the '/alliance <#>' command"); ! } ! else if (loginStatus == tcAccountDatabase::DUPLICATE_LOGIN) ! { ! playerStatus.name += "_DUP"; ! } ! ! ! } ! else ! { ! msg.Printf("*** Error adding account %s (%d)", username.c_str(), status); ! } ! } ! else ! { ! msg = wxString::Format("Username, %s, is not registered\n", username.c_str()); ! } } else if (status == tcAccountDatabase::PASSWORD_INVALID) *************** *** 312,315 **** --- 352,360 ---- SendControlMessage(connectionId, tcControlMessageHandler::CM_ALLIANCE, userData.alliance); + if (playerStatus.alliance != 0) + { + SendBriefingText(connectionId, playerStatus.alliance); + } + unsigned char rank = tcUserInfo::Get()->ScoreToRank(userData.score); playerStatus.SetRank(rank); *************** *** 480,483 **** --- 525,533 ---- */ + bool tcMultiplayerInterface::GetAcceptAllClients() const + { + return acceptAllClients; + } + const std::list<int>& tcMultiplayerInterface::GetConnectionList() const { *************** *** 726,732 **** tcAccountDatabase::Get()->SetUserAlliance(player.GetName(), player.alliance); ! SendControlMessage(connectionId, tcControlMessageHandler::CM_ALLIANCE, alliance); ! msg = wxString::Format("*** Success - alliance set to %d", alliance); ! } else { --- 776,788 ---- tcAccountDatabase::Get()->SetUserAlliance(player.GetName(), player.alliance); ! SendControlMessage(connectionId, tcControlMessageHandler::CM_ALLIANCE, alliance); ! msg = wxString::Format("*** Success - alliance set to %d", alliance); ! ! // update briefing text for new alliance ! if (alliance != 0) ! { ! SendBriefingText(connectionId, alliance); ! } ! } else { *************** *** 1077,1080 **** --- 1133,1140 ---- ProcessGameMasterCommand(pstatus, args); } + else if (command == "who") + { + ProcessWho(pstatus, args); + } else { *************** *** 1176,1179 **** --- 1236,1261 ---- } + /** + * Send list of players currently in game back to client + */ + void tcMultiplayerInterface::ProcessWho(tcPlayerStatus& player, const wxString& args) + { + const std::list<int>& connectionList = networkInterface->GetConnectionList(); + std::list<int>::const_iterator iter = connectionList.begin(); + + SendChatText(player.connectionId, ""); + SendChatText(player.connectionId, "Players currently in game:"); + for( ; iter != connectionList.end(); ++iter) + { + tcPlayerStatus& playerInfo = GetPlayerStatus(*iter); + const std::string& connectionStatus = networkInterface->GetConnectionStatus(*iter, 0); + + wxString s = wxString::Format("%s [%d] %s", playerInfo.GetNameWithRank().c_str(), + playerInfo.GetAlliance(), connectionStatus.c_str()); + + SendChatText(player.connectionId, s.c_str()); + } + } + void tcMultiplayerInterface::SendAuthRequest(int destination) *************** *** 1202,1205 **** --- 1284,1300 ---- /** + * Sends simple briefing text to client for indicated alliance + * This is the only way of getting briefing info in multiplayer + */ + void tcMultiplayerInterface::SendBriefingText(int destination, int alliance) + { + tcUpdateStream stream; + tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::BRIEFING_TEXT, stream); + tcUpdateMessageHandler::AddBriefingText(alliance, stream); + + SendUpdateMessageTCP(destination, stream); + } + + /** * Sends a test message of text to destination */ *************** *** 1338,1342 **** --- 1433,1442 ---- for (unsigned n=0; n<destinations.size(); n++) { + int connectionId = destinations[n]; + + tcPlayerStatus& player = GetPlayerStatus(connectionId); + SendUpdateMessageTCP(destinations[n], stream); + SendBriefingText(destinations[n], player.alliance); } *************** *** 1410,1427 **** } ! /** ! * 0 - UDP, otherwise - TCP ! */ ! void tcMultiplayerInterface::SetChatProtocol(int code) ! { ! if (code) ! { ! tcpChat = true; ! } ! else ! { ! tcpChat = false; // use UDP ! } ! } /** --- 1510,1532 ---- } ! void tcMultiplayerInterface::SetAcceptAllClients(bool state) ! { ! acceptAllClients = state; ! } ! ! /** ! * 0 - UDP, otherwise - TCP ! */ ! void tcMultiplayerInterface::SetChatProtocol(int code) ! { ! if (code) ! { ! tcpChat = true; ! } ! else ! { ! tcpChat = false; // use UDP ! } ! } /** *************** *** 1639,1643 **** tcPlayerStatus& player = GetPlayerStatus(connectionId); ! if (player.isAuthenticated) { tcUpdateStream updateStream; --- 1744,1748 ---- tcPlayerStatus& player = GetPlayerStatus(connectionId); ! if ((player.isAuthenticated) && (player.GetAlliance() != 0)) { tcUpdateStream updateStream; *************** *** 2034,2038 **** entityUpdateInterval(50), sensorUpdateInterval(50), ! goalUpdateInterval(600) { networkInterface = new tcNetworkInterface(); --- 2139,2144 ---- entityUpdateInterval(50), sensorUpdateInterval(50), ! goalUpdateInterval(600), ! acceptAllClients(true) { networkInterface = new tcNetworkInterface(); *************** *** 2058,2062 **** */ tcMultiplayerInterface::tcMultiplayerInterface(const tcMultiplayerInterface& source) ! : entityUpdateInterval(50), sensorUpdateInterval(50), goalUpdateInterval(600) --- 2164,2168 ---- */ tcMultiplayerInterface::tcMultiplayerInterface(const tcMultiplayerInterface& source) ! : entityUpdateInterval(10), sensorUpdateInterval(50), goalUpdateInterval(600) Index: tcNetworkInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcNetworkInterface.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** tcNetworkInterface.cpp 11 Jun 2005 21:01:44 -0000 1.20 --- tcNetworkInterface.cpp 10 Sep 2005 21:47:38 -0000 1.21 *************** *** 220,224 **** ! const std::string& tcNetworkInterface::GetConnectionStatus(int id) { static std::string s; --- 220,224 ---- ! const std::string& tcNetworkInterface::GetConnectionStatus(int id, int detailLevel) { static std::string s; *************** *** 258,264 **** float ping_ms = 1000.0f * connData->GetPingTime(); ! wxString status = wxString::Format("(%.0f) %04d %04d %03d %.0f", ! dt_sec, bytesIn, bytesOut, resentCount, ping_ms); ! s = status.c_str(); return s; } --- 258,282 ---- float ping_ms = 1000.0f * connData->GetPingTime(); ! if (detailLevel <= 0) ! { ! if (dt_sec < 300.0f) ! { ! wxString status = wxString::Format("(%.0f s) ping %.0f ms", ! dt_sec, ping_ms); ! s = status.c_str(); ! } ! else // show connection time in minutes ! { ! wxString status = wxString::Format("(%.0f m) ping %.0f ms", ! 0.0166667f * dt_sec, ping_ms); ! s = status.c_str(); ! } ! } ! else ! { ! wxString status = wxString::Format("(%.0f) %04d %04d %03d %.0f", ! dt_sec, bytesIn, bytesOut, resentCount, ping_ms); ! s = status.c_str(); ! } return s; } |