[Gcblue-commits] gcb_wx/src/network tcMultiplayerInterface.cpp,1.26,1.27 tcTextMessageHandler.cpp,1.
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-05-08 23:29:07
|
Update of /cvsroot/gcblue/gcb_wx/src/network In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17986/src/network Modified Files: tcMultiplayerInterface.cpp tcTextMessageHandler.cpp tcUpdateMessageHandler.cpp Log Message: Landing bug fix, changed /gm create to require starting coords, added fuel to air update Index: tcUpdateMessageHandler.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcUpdateMessageHandler.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** tcUpdateMessageHandler.cpp 5 May 2005 02:14:52 -0000 1.15 --- tcUpdateMessageHandler.cpp 8 May 2005 23:28:58 -0000 1.16 *************** *** 35,38 **** --- 35,40 ---- #include "common/tcObjStream.h" #include "tcSimPythonInterface.h" + #include "tcScenarioInterface.h" + #include "tcMapOverlay.h" #ifdef _DEBUG *************** *** 124,127 **** --- 126,152 ---- } + void tcUpdateMessageHandler::AddScenarioInfo(tcUpdateStream& stream) + { + tcSimState* simState = tcSimState::Get(); + tcSimPythonInterface* pythonInterface = tcSimPythonInterface::Get(); + tcScenarioInterface* scenarioInterface = pythonInterface->GetScenarioInterface(); + tcMapOverlay* overlay = scenarioInterface->GetMapOverlay(); + + std::string scenarioName = simState->GetScenarioName(); + stream << scenarioName; + + std::string scenarioDescription = simState->GetScenarioDescription(); + stream << scenarioDescription; + + double theater_lon; + double theater_lat; + scenarioInterface->GetStartTheater(theater_lon, theater_lat); + stream << theater_lon; + stream << theater_lat; + + overlay->operator>>(stream); + + } + /** * Adds header information to sensor update stream *************** *** 202,205 **** --- 227,232 ---- case SCRIPT_COMMANDS: break; + case SCENARIO_INFO: + break; default: fprintf(stderr, "tcUpdateMessageHandler::InitializeMessage - bad message type\n"); *************** *** 318,321 **** --- 345,355 ---- } break; + case SCENARIO_INFO: + { + tcUpdateStream stream((const char*)data, messageSize); + stream >> messageType; + HandleScenarioInfo(stream); + } + break; default: fprintf(stderr, "tcUpdateMessageHandler::Handle - " *************** *** 606,609 **** --- 640,674 ---- } + void tcUpdateMessageHandler::HandleScenarioInfo(tcUpdateStream& stream) + { + tcSimState* simState = tcSimState::Get(); + tcSimPythonInterface* pythonInterface = tcSimPythonInterface::Get(); + tcScenarioInterface* scenarioInterface = pythonInterface->GetScenarioInterface(); + tcMapOverlay* overlay = scenarioInterface->GetMapOverlay(); + + wxASSERT(simState->IsMultiplayerClient()); + + std::string scenarioName; + stream >> scenarioName; + simState->SetScenarioName(scenarioName); + + std::string scenarioDescription; + stream >> scenarioDescription; + simState->SetScenarioDescription(scenarioDescription); + + simState->SetScenarioLoaded(true); + + double theater_lon; + double theater_lat; + stream >> theater_lon; + stream >> theater_lat; + if ((theater_lon != 0) && (theater_lat != 0)) + { + scenarioInterface->ChangeMapTheater(theater_lon, theater_lat); + } + + overlay->operator<<(stream); + } + /** * Handle SCRIPT_COMMANDS message (server only) Index: tcTextMessageHandler.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcTextMessageHandler.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tcTextMessageHandler.cpp 6 May 2005 23:57:50 -0000 1.6 --- tcTextMessageHandler.cpp 8 May 2005 23:28:58 -0000 1.7 *************** *** 67,73 **** // send to tcMessageInterface in client mode (mode based popups of chat text) tcMessageInterface::Get()->PostChatText(text); } - chatText.push(text); } --- 67,73 ---- // send to tcMessageInterface in client mode (mode based popups of chat text) tcMessageInterface::Get()->PostChatText(text); + chatText.push(text); } } Index: tcMultiplayerInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcMultiplayerInterface.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** tcMultiplayerInterface.cpp 6 May 2005 23:57:50 -0000 1.26 --- tcMultiplayerInterface.cpp 8 May 2005 23:28:58 -0000 1.27 *************** *** 257,260 **** --- 257,267 ---- 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", playerStatus.GetNameWithRank().c_str()); + BroadcastChatText(s.c_str()); } else if (loginStatus == tcAccountDatabase::DUPLICATE_LOGIN) *************** *** 398,401 **** --- 405,410 ---- messageLength, (unsigned char*)buff, protocol); } + + chatText.push(message); } *************** *** 426,429 **** --- 435,450 ---- /** + * Broadcasts scenario info to all clients + * Should be used when scenario is changed + */ + void tcMultiplayerInterface::BroadcastScenarioInfo() + { + const std::vector<int>& destinations = GetConnectionVector(); + + SendScenarioInfo(destinations); + } + + + /** * Clears messageMap, deleting all message handlers */ *************** *** 464,467 **** --- 485,489 ---- } + const std::string& tcMultiplayerInterface::GetConnectionStatus(int connectionId) { *************** *** 475,478 **** --- 497,518 ---- } + /** + * Version that returns list of connection ids as vector (more expensive) + */ + const std::vector<int>& tcMultiplayerInterface::GetConnectionVector() const + { + static std::vector<int> connectionVector; + + connectionVector.clear(); + const std::list<int>& connectionList = GetConnectionList(); + for (std::list<int>::const_iterator k=connectionList.begin(); + k != connectionList.end(); ++k) + { + connectionVector.push_back(*k); + } + + return connectionVector; + } + wxEvtHandler* tcMultiplayerInterface::GetEvtHandler() const { *************** *** 728,734 **** // SendChatText(connectionId, " /gm getaccountdata '<username>' '<param>'"); // SendChatText(connectionId, " /gm setaccountdata '<username>' '<param>' <value>"); ! SendChatText(connectionId, " /gm create '<class>' '<unitname>' <alliance>"); SendChatText(connectionId, " /gm destroy <id>"); ! SendChatText(connectionId, " /gm move <id> <lat_deg> <lon_deg> (<alt>)"); // SendChatText(connectionId, " /gm reload <id>"); SendChatText(connectionId, " /gm repair <id>"); --- 768,774 ---- // SendChatText(connectionId, " /gm getaccountdata '<username>' '<param>'"); // SendChatText(connectionId, " /gm setaccountdata '<username>' '<param>' <value>"); ! SendChatText(connectionId, " /gm create '<class>' '<unitname>' <alliance> <lat_deg> <lon_deg> (<alt_m>)"); SendChatText(connectionId, " /gm destroy <id>"); ! SendChatText(connectionId, " /gm move <id> <lat_deg> <lon_deg> (<alt_m>)"); // SendChatText(connectionId, " /gm reload <id>"); SendChatText(connectionId, " /gm repair <id>"); *************** *** 841,851 **** { const char delim = '\''; ! wxString s1 = args.AfterFirst(delim); ! wxString unitClass = s1.BeforeFirst(delim); ! s1 = s1.AfterFirst(delim); ! s1 = s1.AfterFirst(delim); ! wxString unitName = s1.BeforeFirst(delim); ! s1 = s1.AfterFirst(delim); ! s1 = s1.AfterFirst(' '); long alliance = 0; if ((!s1.ToLong(&alliance)) || (alliance < 0)) --- 881,895 ---- { const char delim = '\''; ! wxString params = args.AfterFirst(delim); ! wxString unitClass = params.BeforeFirst(delim); ! params = params.AfterFirst(delim); ! params = params.AfterFirst(delim); ! wxString unitName = params.BeforeFirst(delim); ! params = params.AfterFirst(delim); ! ! ! params = params.AfterFirst(' '); ! wxString s1 = params.BeforeFirst(' '); ! long alliance = 0; if ((!s1.ToLong(&alliance)) || (alliance < 0)) *************** *** 856,859 **** --- 900,932 ---- } + double lat_deg = 0; + params = params.AfterFirst(' '); + s1 = params.BeforeFirst(' '); + if (!s1.ToDouble(&lat_deg)) + { + msg = wxString::Format("*** Bad latitude for /gm create"); + return; + } + + double lon_deg = 0; + params = params.AfterFirst(' '); + s1 = params.BeforeFirst(' '); + if (!s1.ToDouble(&lon_deg)) + { + msg = wxString::Format("*** Bad longitude for /gm create"); + return; + } + + double alt_m = 0; + params = params.AfterFirst(' '); + s1 = params.BeforeFirst(' '); + if (!s1.ToDouble(&alt_m)) + { + alt_m = 0; + } + + + + tcScenarioInterface* scenarioInterface = tcSimPythonInterface::Get()->GetScenarioInterface(); wxASSERT(scenarioInterface); *************** *** 863,869 **** unit.className = unitClass.c_str(); unit.unitName = unitName.c_str(); ! unit.lat = 0; ! unit.lon = 0; ! unit.alt = 0; unit.heading = 0; unit.speed = 0; --- 936,942 ---- unit.className = unitClass.c_str(); unit.unitName = unitName.c_str(); ! unit.lat = lat_deg; ! unit.lon = lon_deg; ! unit.alt = alt_m; unit.heading = 0; unit.speed = 0; *************** *** 1252,1255 **** --- 1325,1341 ---- } + void tcMultiplayerInterface::SendScenarioInfo(const std::vector<int>& destinations) + { + tcUpdateStream stream; + tcUpdateMessageHandler::InitializeMessage(tcUpdateMessageHandler::SCENARIO_INFO, stream); + tcUpdateMessageHandler::AddScenarioInfo(stream); + + for (unsigned n=0; n<destinations.size(); n++) + { + SendUpdateMessageTCP(destinations[n], stream); + } + + } + void tcMultiplayerInterface::SendSoundEffect(const std::string& player, const std::string& effect, long id) { *************** *** 1307,1310 **** --- 1393,1408 ---- } + void tcMultiplayerInterface::SendUpdateMessageTCP(int destination, tcStream& stream) + { + size_t streamSize = stream.size(); + char* buffer = new char[streamSize]; + stream.read(buffer, streamSize); + + networkInterface->SendMessage(destination, MSG_UPDATE, streamSize, (unsigned char*)buffer, + tcNetworkInterface::TCP); + + delete buffer; + } + /** * 0 - UDP, otherwise - TCP *************** *** 1471,1488 **** unsigned updateCount = 0; for (iter.First();iter.NotDone();iter.Next()) ! { ! tcGameObject* obj = iter.Get(); ! if ((pstatus.alliance == obj->GetAlliance()) || !IsServer()) ! { ! if (obj->HasNewCommand()) ! { ! tcUpdateMessageHandler::AddCommandUpdate(obj, commandStream); ! if (clearNewCmdFlag) obj->ClearNewCommand(); ! updateCount++; #ifdef _DEBUG ! fprintf(stdout, "%d ", obj->mnID); #endif ! } ! } // create new message if updateCount gets too large --- 1569,1589 ---- unsigned updateCount = 0; for (iter.First();iter.NotDone();iter.Next()) ! { ! tcGameObject* obj = iter.Get(); ! if (obj->HasNewCommand()) ! { ! if ((pstatus.alliance == obj->GetAlliance()) || !IsServer()) ! { ! tcUpdateMessageHandler::AddCommandUpdate(obj, commandStream); ! ! updateCount++; #ifdef _DEBUG ! fprintf(stdout, "%d ", obj->mnID); #endif ! } ! ! // extremely important! not clearing command will flood network ! if (clearNewCmdFlag) obj->ClearNewCommand(); ! } // create new message if updateCount gets too large *************** *** 1778,1783 **** eraseKeys.push(iter->first); tcSound::Get()->PlayEffect("fslide"); - LogOutPlayer(iter->second.name); } --- 1879,1895 ---- eraseKeys.push(iter->first); tcSound::Get()->PlayEffect("fslide"); LogOutPlayer(iter->second.name); + + if (IsServer()) + { + wxString msg = wxString::Format("*** %s has left the game", + iter->second.GetNameWithRank().c_str()); + BroadcastChatText(msg.c_str()); + } + else + { + chatText.push(std::string("Lost connection to server")); + wxMessageBox("Lost connection to server", "Network", wxICON_WARNING); + } } |