Update of /cvsroot/gcblue/gcb_wx/include/network
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4666/include/network
Modified Files:
tcMultiplayerInterface.h
Added Files:
tcChatMessageHandler.h tcMessageHandler.h
Log Message:
--- NEW FILE: tcMessageHandler.h ---
/** @file tcMessageHandler.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 _MESSAGEHANDLER_H_
#define _MESSAGEHANDLER_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define BEGIN_NAMESPACE(x) namespace x {
#define END_NAMESPACE }
BEGIN_NAMESPACE(network)
/**
* 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() {}
};
END_NAMESPACE
#endif
--- NEW FILE: tcChatMessageHandler.h ---
/** @file tcChatMessageHandler.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 _CHATMESSAGEHANDLER_H_
#define _CHATMESSAGEHANDLER_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
*/
class tcChatMessageHandler : public tcMessageHandler
{
public:
virtual void Handle(int connectionId, unsigned messageSize, const unsigned char *data);
tcChatMessageHandler(std::queue<std::string>& _chatText);
virtual ~tcChatMessageHandler();
private:
std::queue<std::string>& chatText;
};
END_NAMESPACE
#endif
Index: tcMultiplayerInterface.h
===================================================================
RCS file: /cvsroot/gcblue/gcb_wx/include/network/tcMultiplayerInterface.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** tcMultiplayerInterface.h 4 Apr 2004 20:54:12 -0000 1.4
--- tcMultiplayerInterface.h 5 Apr 2004 02:24:28 -0000 1.5
***************
*** 28,36 ****
#include <queue>
! /*
#include <vector>
- #include <map>
- */
--- 28,35 ----
#include <queue>
! #include <map>
! #include <string>
#include <vector>
***************
*** 42,45 ****
--- 41,45 ----
class tcNetworkInterface;
+ class tcMessageHandler;
***************
*** 67,72 ****
MSG_USERNAME = 2
};
! static tcMultiplayerInterface& Get();
std::string GetChatText();
int GetConnectionId(unsigned connectionIdx);
--- 67,73 ----
MSG_USERNAME = 2
};
! static tcMultiplayerInterface* Get();
+ void AddMessageHandler(int messageId, tcMessageHandler* handler);
std::string GetChatText();
int GetConnectionId(unsigned connectionIdx);
***************
*** 90,98 ****
std::string myName;
std::map<int, tcPlayerStatus> playerInfo; ///< map of (connection id, tcPlayerStatus) pairs
bool tcpChat; ///< true to use TCP for chat protocol, otherwise UDP
bool IsNewPlayer(int id);
! void ProcessMessage(int connectionId, int messageId,
unsigned messageSize, const unsigned char *data);
void ProcessReceiveMessages();
void UpdatePlayerInfo();
--- 91,103 ----
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();
bool IsNewPlayer(int id);
! void ProcessChatMessage(int connectionId, unsigned messageSize, const unsigned char *data);
! void ProcessMessage(int messageId, int connectionId,
unsigned messageSize, const unsigned char *data);
+
void ProcessReceiveMessages();
void UpdatePlayerInfo();
|