[Gcblue-commits] gcb_wx/include/network tcControlMessageHandler.h,NONE,1.1 tcTextMessageHandler.h,NO
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-04-07 00:54:01
|
Update of /cvsroot/gcblue/gcb_wx/include/network In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25434/include/network Modified Files: tcMessageHandler.h tcMultiplayerInterface.h Added Files: tcControlMessageHandler.h tcTextMessageHandler.h Removed Files: tcChatMessageHandler.h Log Message: Index: tcMessageHandler.h =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/include/network/tcMessageHandler.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** tcMessageHandler.h 5 Apr 2004 02:24:28 -0000 1.1 --- tcMessageHandler.h 7 Apr 2004 00:41:07 -0000 1.2 *************** *** 33,45 **** /** ! * Abstract base class for message handler */ class tcMessageHandler { public: virtual void Handle(int connectionId, unsigned messageSize, const unsigned char *data) = 0; virtual ~tcMessageHandler() {} protected: tcMessageHandler() {} }; --- 33,50 ---- /** ! * Base class for message handler */ class tcMessageHandler { public: + static void SetAsServer(); + static void SetAsClient(); + virtual void Handle(int connectionId, unsigned messageSize, const unsigned char *data) = 0; + virtual ~tcMessageHandler() {} protected: tcMessageHandler() {} + static bool isServer; }; Index: tcMultiplayerInterface.h =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/include/network/tcMultiplayerInterface.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tcMultiplayerInterface.h 5 Apr 2004 02:24:28 -0000 1.5 --- tcMultiplayerInterface.h 7 Apr 2004 00:41:07 -0000 1.6 *************** *** 33,38 **** - - #define BEGIN_NAMESPACE(x) namespace x { #define END_NAMESPACE } --- 33,36 ---- *************** *** 58,61 **** --- 56,60 ---- * also try this as an abstract base class, but application level * methods exist in this class as well. + * */ class tcMultiplayerInterface *************** *** 65,87 **** { MSG_CHATTEXT = 1, ! MSG_USERNAME = 2 }; static tcMultiplayerInterface* Get(); void AddMessageHandler(int messageId, tcMessageHandler* handler); std::string GetChatText(); int GetConnectionId(unsigned connectionIdx); std::string GetConnectionStatus(unsigned connectionIdx); ! unsigned GetNumConnections(); ! ! bool IsChatTextAvail(); bool IsServer(); void MakeClient(); void MakeServer(); void OpenConnection(std::string hostName); void SendChatText(int destination, std::string message); void SendTestUDP(int destination, std::string message); void SetChatProtocol(int code); void Update(); --- 64,94 ---- { MSG_CHATTEXT = 1, ! MSG_CONTROL = 2, ! MSG_USERNAME = 3 }; static tcMultiplayerInterface* Get(); void AddMessageHandler(int messageId, tcMessageHandler* handler); + void BroadcastControlMessage(int messageCode); std::string GetChatText(); int GetConnectionId(unsigned connectionIdx); std::string GetConnectionStatus(unsigned connectionIdx); ! std::string GetName() const; unsigned GetNumConnections(); ! tcPlayerStatus& GetPlayerStatus(int connectionId); ///< redundant with GetConnectionStatus? ! void InitMessageHandlers(); ! bool IsChatTextAvail(); ! bool IsCommand(std::string text); bool IsServer(); void MakeClient(); void MakeServer(); void OpenConnection(std::string hostName); + void ProcessCommandClient(int connectionId, std::string text); + void ProcessCommandServer(std::string text); void SendChatText(int destination, std::string message); + void SendControlMessage(int destination, int messageCode); void SendTestUDP(int destination, std::string message); void SetChatProtocol(int code); + void SetName(const std::string& name); void Update(); *************** *** 89,96 **** tcNetworkInterface *networkInterface; std::queue<std::string> chatText; ///< chat text to display ! std::string myName; std::map<int, tcPlayerStatus> playerInfo; ///< map of (connection id, tcPlayerStatus) pairs std::map<int, std::vector<tcMessageHandler*> > messageMap; ///< map of (message id, message handler vector) pairs bool tcpChat; ///< true to use TCP for chat protocol, otherwise UDP void ClearMessageMap(); --- 96,104 ---- tcNetworkInterface *networkInterface; std::queue<std::string> chatText; ///< chat text to display ! std::string myName; ///< name to identify player std::map<int, tcPlayerStatus> playerInfo; ///< map of (connection id, tcPlayerStatus) pairs std::map<int, std::vector<tcMessageHandler*> > messageMap; ///< map of (message id, message handler vector) pairs bool tcpChat; ///< true to use TCP for chat protocol, otherwise UDP + tcPlayerStatus errorPlayerStatus; ///< status to return if player not found void ClearMessageMap(); --- NEW FILE: tcControlMessageHandler.h --- /** @file tcControlMessageHandler.h * * Copyright (C) 2004 Dewitt "Cole" Colclough (de...@tw...) * All rights reserved. * * This file is part of the Global Conflict Blue (GCB) program. * GCB is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * GCB is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GCB; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _CONTROLMESSAGEHANDLER_H_ #define _CONTROLMESSAGEHANDLER_H_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include <queue> #include <string> #include "network/tcMessageHandler.h" #define BEGIN_NAMESPACE(x) namespace x { #define END_NAMESPACE } BEGIN_NAMESPACE(network) /** * Control message received handler. * Control messages are used to do things like start and pause the game */ class tcControlMessageHandler : public tcMessageHandler { public: enum { CM_BEEP = 1, CM_STARTGAME = 2 }; static void CreateControlMessage(int messageCode, unsigned& messageSize, unsigned char *data); virtual void Handle(int connectionId, unsigned messageSize, const unsigned char *data); tcControlMessageHandler(); virtual ~tcControlMessageHandler(); }; END_NAMESPACE #endif --- NEW FILE: tcTextMessageHandler.h --- /** @file tcTextMessageHandler.h * * Copyright (C) 2004 Dewitt "Cole" Colclough (de...@tw...) * All rights reserved. * * This file is part of the Global Conflict Blue (GCB) program. * GCB is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * GCB is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GCB; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _TEXTMESSAGEHANDLER_H_ #define _TEXTMESSAGEHANDLER_H_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include <queue> #include <string> #include "network/tcMessageHandler.h" #define BEGIN_NAMESPACE(x) namespace x { #define END_NAMESPACE } BEGIN_NAMESPACE(network) /** * Chat message received handler, also handles text slash '/' commands * Also added code to create messages so that it's in one place. */ class tcTextMessageHandler : public tcMessageHandler { public: static void CreateMessage(unsigned& messageSize, unsigned char *data, std::string text, unsigned maxSize); virtual void Handle(int connectionId, unsigned messageSize, const unsigned char *data); tcTextMessageHandler(std::queue<std::string>& _chatText); virtual ~tcTextMessageHandler(); private: std::queue<std::string>& chatText; // reference to queue for storing chat text }; END_NAMESPACE #endif --- tcChatMessageHandler.h DELETED --- |