CSCommon: MMatchChannel.h 소스 파일

MAIET

MMatchChannel.h

00001 #ifndef MMATCHCHANNEL_H
00002 #define MMATCHCHANNEL_H
00003 
00004 #include <map>
00005 #include <list>
00006 using namespace std;
00007 
00008 #include "MMatchGlobal.h"
00009 #include "MUID.h"
00010 #include "MMatchChannel.h"
00011 #include "MPageArray.h"
00012 #include "MSmartRefresh.h"
00013 
00014 #define CHANNELNAME_LEN     64
00015 #define CHANNELRULE_LEN     64
00016 #define DEFAULT_CHANNEL_MAXPLAYERS          200
00017 #define DEFAULT_CHANNEL_MAXSTAGES           100
00018 #define MAX_CHANNEL_MAXSTAGES               500
00019 #define NUM_PLAYERLIST_NODE                 6
00020 #define CHANNEL_NO_LEVEL                    (-1)
00021 
00022 class MMatchObject;
00023 class MMatchStage;
00024 class MCommand;
00025 
00026 
00027 enum MCHANNEL_TYPE {
00028     MCHANNEL_TYPE_PRESET    = 0,        // 일반채널
00029     MCHANNEL_TYPE_USER      = 1,        // 사설채널
00030     MCHANNEL_TYPE_PRIVATE   = 2,        // 비밀채널 - 현재 안쓰임
00031     MCHANNEL_TYPE_CLAN      = 3,        // 클랜채널
00032     MCHANNEL_TYPE_MAX
00033 };
00034 
00035 enum MCHANNEL_RULE {
00036     MCHANNEL_RULE_NOVICE=0,
00037     MCHANNEL_RULE_NEWBIE,
00038     MCHANNEL_RULE_ROOKIE,
00039     MCHANNEL_RULE_MASTERY,
00040 
00041     MCHANNEL_RULE_MAX
00042 };
00043 
00044 #define MCHANNEL_RULE_NOVICE_STR        "novice"
00045 #define MCHANNEL_RULE_NEWBIE_STR        "newbie"
00046 #define MCHANNEL_RULE_ROOKIE_STR        "rookie"
00047 #define MCHANNEL_RULE_MASTERY_STR       "mastery"
00048 
00049 
00050 // 채널 리스트 달라고 요청할때 보내는 구조체
00051 struct MCHANNELLISTNODE {
00052     MUID            uidChannel;                     // 채널 UID
00053     short           nNo;                            // 채널번호
00054     unsigned char   nPlayers;                       // 현재인원
00055     short           nMaxPlayers;                    // 최대인원
00056     short           nLevelMin;                      // 최소레벨
00057     short           nLevelMax;                      // 최대레벨
00058     char            nChannelType;                   // 채널타입
00059     char            szChannelName[CHANNELNAME_LEN]; // 채널이름
00060 };
00061 
00062 typedef map<string, MMatchObject*>          MObjectStrMap;
00063 typedef map<int, MMatchStage*>              MChannelStageMap;
00064 typedef MPageArray<MMatchObject*>           MChannelUserArray;
00065 
00066 
00067 class MMatchChannel {
00068 private:
00069     MUID            m_uidChannel;
00070     char            m_szChannelName[CHANNELNAME_LEN];
00071     MCHANNEL_TYPE   m_nChannelType;
00072     int             m_nMaxPlayers;
00073     int             m_nLevelMin;
00074     int             m_nLevelMax;
00075     int             m_nMaxStages;
00076     char            m_szRuleName[CHANNELRULE_LEN];
00077     MCHANNEL_RULE   m_nRuleType;
00078     //bool          m_bNewbieChannel;       // 뉴비채널은 정말 초보만 들어갈 수 있다.
00079 
00080     MUIDRefCache    m_ObjUIDCaches;         // 채널전체 플레이어들
00081     MUIDRefCache    m_ObjUIDLobbyCaches;    // 로비에 있는 플레이어들
00082 //  MObjectStrMap   m_ObjStrCaches;
00083 
00084     MMatchStage*    m_pStages[MAX_CHANNEL_MAXSTAGES];
00085     list<int>       m_UnusedStageIndexList;
00086 
00087     MChannelUserArray           m_UserArray;
00088     MSmartRefresh               m_SmartRefresh;
00089 
00090     unsigned long   m_nChecksum;    // 목록및 정보 갱신용
00091     unsigned long   m_nLastChecksumTick;
00092 
00093     unsigned long   m_nLastTick;
00094     unsigned long   m_nEmptyPeriod;
00095 
00096     void JoinLobby(const MUID& uid, const MMatchObject* pObj);
00097     void LeaveLobby(const MUID& uid);
00098 protected:
00099     inline bool IsChecksumUpdateTime(unsigned long nTick);
00100     void UpdateChecksum(unsigned long nTick);
00101     unsigned long GetEmptyPeriod()  { return m_nEmptyPeriod; }
00102 
00103 public:
00104     bool CheckTick(unsigned long nClock);
00105     void Tick(unsigned long nClock);
00106 
00107     unsigned long GetChecksum()     { return m_nChecksum; }
00108     bool CheckLifePeriod();
00109 
00110 public:
00111     bool Create(const MUID& uid, const char* pszName, const char* pszRuleName, 
00112                 MCHANNEL_TYPE nType=MCHANNEL_TYPE_PRESET, int nMaxPlayers=DEFAULT_CHANNEL_MAXPLAYERS, 
00113                 int nLevelMin=CHANNEL_NO_LEVEL, int nLevelMax=CHANNEL_NO_LEVEL);
00114     void Destroy();
00115 
00116     const char* GetName()           { return m_szChannelName; }
00117     const char* GetRuleName()       { return m_szRuleName; }
00118     MUID GetUID()                   { return m_uidChannel; }
00119     MCHANNEL_TYPE GetChannelType()  { return m_nChannelType; }
00120     MCHANNEL_RULE GetRuleType()     { return m_nRuleType; }
00121 
00122     int GetMaxPlayers()             { return m_nMaxPlayers; }
00123     int GetLevelMin()               { return m_nLevelMin; }
00124     int GetLevelMax()               { return m_nLevelMax; }
00125     int GetMaxStages()              { return m_nMaxStages; }
00126     size_t GetObjCount()            { return m_ObjUIDCaches.size(); }
00127     MUIDRefCache::iterator GetObjBegin()        { return m_ObjUIDCaches.begin(); }
00128     MUIDRefCache::iterator GetObjEnd()          { return m_ObjUIDCaches.end(); }
00129     MUIDRefCache::iterator GetLobbyObjBegin()   { return m_ObjUIDLobbyCaches.begin(); }
00130     MUIDRefCache::iterator GetLobbyObjEnd()     { return m_ObjUIDLobbyCaches.end(); }
00131 
00132 
00133     void AddObject(const MUID& uid, MMatchObject* pObj);
00134     void RemoveObject(const MUID& uid);
00135 public:
00136     bool AddStage(MMatchStage* pStage);
00137     void RemoveStage(MMatchStage* pStage);
00138     bool IsEmptyStage(int nIndex);
00139     MMatchStage* GetStage(int nIndex);
00140     int GetPrevStageCount(int nStageIndex); // nStageIndex를 포함하지 않는 nStageIndex이전의 만들어진 방 개수 
00141     int GetNextStageCount(int nStageIndex); // nStageIndex를 포함하지 않는 nStageIndex이후의 만들어진 방 개수 
00142     
00143     //bool IsNewbieChannel()            { return m_bNewbieChannel; }
00144 
00145 public:
00146     MChannelUserArray* GetUserArray()   { return &m_UserArray; }
00147 
00148 public:
00149     void SyncPlayerList(MMatchObject* pObj, int nPage);
00150 };
00151 
00152 
00153 class MMatchChannelMap : public map<MUID, MMatchChannel*> {
00154 private:
00155     MUID                        m_uidGenerate;
00156     unsigned long               m_nChecksum;
00157     map<MUID, MMatchChannel*>   m_TypesChannelMap[MCHANNEL_TYPE_MAX];
00158     void Insert(const MUID& uid, MMatchChannel* pChannel)   {   insert(value_type(uid, pChannel));  }
00159     MUID UseUID()               {   m_uidGenerate.Increase();   return m_uidGenerate;   }
00160 //  void UpdateChecksum(unsigned long nClock);
00161 public:
00162     MMatchChannelMap()          {   m_uidGenerate = MUID(0,0);  m_nChecksum=0; }
00163     virtual ~MMatchChannelMap() {   }
00164     void Destroy();
00165     
00166     MMatchChannel* Find(const MUID& uidChannel);
00167     MMatchChannel* Find(const MCHANNEL_TYPE nChannelType, const char* pszChannelName);
00168 
00169     bool Add(const char* pszChannelName, const char* pszRuleName, MUID* pAllocUID, MCHANNEL_TYPE nType=MCHANNEL_TYPE_PRESET, int nMaxPlayers=DEFAULT_CHANNEL_MAXPLAYERS, int nLevelMin=-1, int nLevelMax=-1);
00170     bool Remove(const MUID& uidChannel, MMatchChannelMap::iterator* pNextItor);
00171     void Update(unsigned long nClock);
00172 
00173     unsigned long GetChannelListChecksum() { return m_nChecksum; }
00174     int GetChannelCount(MCHANNEL_TYPE nChannelType);
00175 
00176     map<MUID, MMatchChannel*>::iterator GetTypesChannelMapBegin(MCHANNEL_TYPE nType);
00177     map<MUID, MMatchChannel*>::iterator GetTypesChannelMapEnd(MCHANNEL_TYPE nType);
00178 
00179 };
00180 
00181 
00182 #endif


MAIET entertainment