MServer.h
00001 #ifndef MSERVER_H 00002 #define MSERVER_H 00003 00004 #include "MCommandCommunicator.h" 00005 #include "RealCPNet.h" 00006 00007 #include <list> 00008 using namespace std; 00009 00010 class MCommand; 00011 00013 class MServer : public MCommandCommunicator { 00014 protected: 00015 MRealCPNet m_RealCPNet; 00016 00017 list<MCommObject*> m_AcceptWaitQueue; 00018 CRITICAL_SECTION m_csAcceptWaitQueue; 00019 00020 void LockAcceptWaitQueue() { EnterCriticalSection(&m_csAcceptWaitQueue); } 00021 void UnlockAcceptWaitQueue() { LeaveCriticalSection(&m_csAcceptWaitQueue); } 00022 00023 MUIDRefCache m_CommRefCache; 00024 CRITICAL_SECTION m_csCommList; 00025 00026 void LockCommList() { EnterCriticalSection(&m_csCommList); } 00027 void UnlockCommList() { LeaveCriticalSection(&m_csCommList); } 00028 00029 MCommandList m_SafeCmdQueue; 00030 CRITICAL_SECTION m_csSafeCmdQueue; 00031 void LockSafeCmdQueue() { EnterCriticalSection(&m_csSafeCmdQueue); } 00032 void UnlockSafeCmdQueue() { LeaveCriticalSection(&m_csSafeCmdQueue); } 00033 00035 virtual MUID UseUID(void) = 0; 00036 00037 void AddCommObject(const MUID& uid, MCommObject* pCommObj); 00038 void RemoveCommObject(const MUID& uid); 00039 00040 void PostSafeQueue(MCommand* pNew); 00041 00043 void SendCommand(MCommand* pCommand); 00044 void ParsePacket(MCommObject* pCommObj, MPacketHeader* pPacket); 00045 00047 virtual void OnPrepareRun(void); 00049 virtual void OnRun(void); 00051 virtual bool OnCommand(MCommand* pCommand); 00052 00053 virtual void OnNetClear(const MUID& CommUID); 00054 00055 bool SendMsgReplyConnect(MUID* pHostUID, MUID* pAllocUID, MCommObject* pCommObj); 00056 bool SendMsgCommand(DWORD nClientKey, char* pBuf, int nSize); 00057 00058 static void RCPCallback(void* pCallbackContext, RCP_IO_OPERATION nIO, DWORD nKey, MPacketHeader* pPacket, DWORD dwPacketLen); // Thread not safe 00059 00060 public: // For Debugging 00061 char m_szName[128]; 00062 void SetName(char* pszName) { strcpy(m_szName, pszName); } 00063 void DebugLog(char* pszLog) { 00064 char szLog[128]; 00065 wsprintf(szLog, "[%s] %s \n", m_szName, pszLog); 00066 OutputDebugString(szLog); 00067 } 00068 00069 public: 00070 MServer(void); 00071 ~MServer(void); 00072 00074 bool Create(int nPort); 00076 void Destroy(void); 00077 00078 00082 virtual int Connect(MCommObject* pCommObj); // 연결실패시 반드시 Disconnect() 호출해야함 00083 int ReplyConnect(MUID* pTargetUID, MUID* pAllocUID, MCommObject* pCommObj); 00084 virtual int OnAccept(MCommObject* pCommObj); 00086 virtual void OnLocalLogin(MUID CommUID, MUID PlayerUID); 00088 virtual void Disconnect(MUID uid); 00089 virtual int OnDisconnect(MCommObject* pCommObj); // Thread not safe 00090 00091 virtual void Log(unsigned int nLogLevel, const char* szLog){} 00092 }; 00093 00094 #endif
MAIET entertainment