[Gcblue-commits] gcb_wx/src/network tcMultiplayerInterface.cpp,1.14,1.15 tcUpdateMessageHandler.cpp,
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-05-09 20:40:34
|
Update of /cvsroot/gcblue/gcb_wx/src/network In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1643/src/network Modified Files: tcMultiplayerInterface.cpp tcUpdateMessageHandler.cpp Log Message: Index: tcUpdateMessageHandler.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcUpdateMessageHandler.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** tcUpdateMessageHandler.cpp 8 May 2004 22:20:29 -0000 1.8 --- tcUpdateMessageHandler.cpp 9 May 2004 20:40:23 -0000 1.9 *************** *** 346,350 **** else { ! stream.skip(updateSize); fprintf(stdout, "%d(X) ", id); --- 346,350 ---- else { ! stream.skip_read(updateSize); fprintf(stdout, "%d(X) ", id); *************** *** 538,542 **** missingIds.push(id); fprintf(stdout, "%d(X) ", id); ! stream.skip(updateSize); } } --- 538,542 ---- missingIds.push(id); fprintf(stdout, "%d(X) ", id); ! stream.skip_read(updateSize); } } Index: tcMultiplayerInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/network/tcMultiplayerInterface.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** tcMultiplayerInterface.cpp 8 May 2004 21:25:26 -0000 1.14 --- tcMultiplayerInterface.cpp 9 May 2004 20:40:22 -0000 1.15 *************** *** 39,42 **** --- 39,43 ---- #include "tcSimState.h" #include "tcGameObjIterator.h" + #include "tcConsoleBox.h" BEGIN_NAMESPACE(network) *************** *** 105,108 **** --- 106,136 ---- /** + * Adds tcConsoleBox to chat subscriber vector. Chat text will be printed + * to the tcConsoleBox when new text arrives. + */ + void tcMultiplayerInterface::AddChatSubscriber(tcConsoleBox* subscriber) + { + chatSubscribers.push_back(subscriber); + } + + /** + * Removes tcConsoleBox from chat subscriber list + */ + void tcMultiplayerInterface::RemoveChatSubscriber(tcConsoleBox* subscriber) + { + + for(std::vector<tcConsoleBox*>::iterator iter = chatSubscribers.begin() + ; iter != chatSubscribers.end(); ++iter) + { + if ((*iter) == subscriber) + { + chatSubscribers.erase(iter); + return; + } + } + fprintf(stderr, "Error - RemoveChatSubscriber - Not found\n"); + } + + /** * Adds message handler for message with messageId. * tcMessageHandler::Handle method will be called for any matching messages received *************** *** 175,179 **** } ! std::string tcMultiplayerInterface::GetChatText() { --- 203,207 ---- } ! /* std::string tcMultiplayerInterface::GetChatText() { *************** *** 183,186 **** --- 211,215 ---- return text; } + */ int tcMultiplayerInterface::GetConnectionId(unsigned connectionIdx) *************** *** 314,331 **** } ! void tcMultiplayerInterface::ProcessChatMessage(int connectionId, ! unsigned messageSize, const unsigned char *data) { ! chatText.push(std::string((char*)data)); ! if (networkInterface->IsServer()) { ! // broadcast chat text to all clients ! unsigned nConn = networkInterface->GetNumConnections(); ! for (unsigned n=0;n<nConn;n++) { ! int connId = networkInterface->GetConnectionId(n); ! SendChatText(connId, (char*)data); } } } --- 343,365 ---- } ! ! /** ! * Send queued chat text to subscribers. This should be periodically called ! * as part of the update method ! */ ! void tcMultiplayerInterface::DistributeChatText() { ! while (!chatText.empty()) { ! std::string text = chatText.front(); ! chatText.pop(); ! ! for(std::vector<tcConsoleBox*>::iterator iter = chatSubscribers.begin() ! ; iter != chatSubscribers.end(); ++iter) { ! (*iter)->Print(text.c_str()); } } + } *************** *** 454,471 **** mm[n]->Handle(connectionId, messageSize, data); } - - /* - switch (messageId) - { - case MSG_CHATTEXT: - ProcessChatMessage(connectionId, messageSize, data); - - break; - default: - std::cerr << "Error - tcMultiplayerInterface::ProcessMessage unrecognized message" - << std::endl; - break; - } - */ } --- 488,491 ---- *************** *** 596,599 **** --- 616,622 ---- ProcessReceiveMessages(); + // distribute chat text + DistributeChatText(); + // update player information UpdatePlayerInfo(); |