#ifndef _FRIEND_LIST_H_ #define _FRIEND_LIST_H_ #include #include #include #include #include #include class CXRefFriends { public: static CXRefFriends& GetInstance(); typedef std::multimap XRefTable; CXRefFriends() { } ~CXRefFriends() { } // FnProcess´Â bool operator() (CXRefFriends::XRefTable::value_type&) ÇÔ¼ö¸¦ °®´Â ±¸Á¶Ã¼(Ŭ·¡½º)ÀÌ´Ù. template void Process(unsigned long dwFriendID, FnProcess fnProcess) { // dwFriendID¸¦ Ä£±¸·Î °¡Áø ¸ðµç CID¿¡ ´ëÇØ¼­ ÀÛ¾÷ÇÑ´Ù. std::pair result = m_XRefTable.equal_range(dwFriendID); std::for_each(result.first, result.second, fnProcess); } private: XRefTable::iterator Add(unsigned long dwOwnerID, unsigned long dwFriendID) { return m_XRefTable.insert(std::make_pair(dwFriendID, dwOwnerID)); } void Remove(XRefTable::iterator erasePos) { m_XRefTable.erase(erasePos); } XRefTable m_XRefTable; // Add, Remove Method¸¦ °¨Ãß±â À§Çؼ­ friend·Î ÁöÁ¤. friend class CFriendList; }; class CFriendList { public: enum { MAX_FRIENDS_NUM = 100 }; class Rebind { private: CXRefFriends::XRefTable::iterator m_XRefItr; FriendInfo m_friendInfo; Rebind() : m_XRefItr() { } Rebind(const CXRefFriends::XRefTable::iterator& XRefItr, const FriendInfo& friendInfo) : m_XRefItr(XRefItr), m_friendInfo(friendInfo) { } public: inline unsigned long GetCID() { return m_friendInfo.m_dwCID; } inline unsigned long GetGroup() { return m_friendInfo.GetGroup(); } inline bool IsLogined() { return m_friendInfo.IsLogined(); } inline const char* GetCharacterName() { return m_friendInfo.m_szName; } inline bool IsFriend(const char* szName) { return 0 == strncmp(szName, m_friendInfo.m_szName, FriendInfo::MAX_NAME); } inline bool SetGroup(unsigned long dwGroup) { return m_friendInfo.SetGroup(dwGroup); } inline void SetLoginStatus(bool bLogin) { m_friendInfo.SetLoginStatus(bLogin); } inline void UpdateLevel(char cLevel) { m_friendInfo.m_cLevel = cLevel; } inline void UpdateGID(unsigned long dwGID) { m_friendInfo.m_dwGID = dwGID; } inline void UpdateServerID(unsigned long dwServerID) { m_friendInfo.m_dwServerID = dwServerID; } inline void UpdateClass(unsigned short wClass) { m_friendInfo.m_wClass = wClass; } inline char GetLevel() { return m_friendInfo.m_cLevel; } inline unsigned long GetGID() { return m_friendInfo.m_dwGID; } inline unsigned short GetClass() { return m_friendInfo.m_wClass; } inline unsigned long GetServerID() { return m_friendInfo.m_dwServerID; } inline void InitializeFriendInfo(unsigned long dwServerID, unsigned long dwGID, unsigned short wClass, char cLevel) { m_friendInfo.m_dwServerID = dwServerID; m_friendInfo.m_dwGID = (m_friendInfo.m_dwGID!=dwGID) ? dwGID : m_friendInfo.m_dwGID; m_friendInfo.m_cLevel = (m_friendInfo.m_cLevel!=cLevel) ? cLevel : m_friendInfo.m_cLevel; m_friendInfo.m_wClass = (m_friendInfo.m_wClass!=wClass) ? wClass : m_friendInfo.m_wClass; } friend class CFriendList; friend class CFindFriendCID; friend inline static bool operator < (unsigned long dwCID, const Rebind& rhs) { return dwCID < rhs.m_friendInfo.m_dwCID; } friend inline static bool operator < (const Rebind& lhs, unsigned long dwCID) { return lhs.m_friendInfo.m_dwCID < dwCID; } friend inline static bool operator < (const Rebind& lhs, const Rebind& rhs) { return lhs.m_friendInfo.m_dwCID < rhs.m_friendInfo.m_dwCID; } }; typedef std::vector FriendList; CFriendList(unsigned long dwOwnerCID, CXRefFriends* lpXRefTable = NULL); ~CFriendList(); void Clear(); bool Add(unsigned long dwFriendCID, const char* szCharacterName, unsigned long dwGID, unsigned short wClass, char cLevel, unsigned long dwServerID); bool Remove(unsigned long dwFriendCID); // CID°¡ °°´Ù°í, À̸§±îÁö °°ÀºÁö´Â º¸ÀåÇÒ ¼ö ¾ø´Ù. ¹Ýµå½Ã È®ÀÎÇÒ °Í. Rebind* GetFriend(unsigned long dwFriendCID); Rebind* GetFriend(const char* szFriendName); bool SerializeIn(const char* szBuffer_In, unsigned long dwBufferSize_In); bool SerializeOut(char* szBuffer_Out, unsigned long& dwBufferSize_InOut) const; void GetCIDList(unsigned long* dwCID_In); // µðºñ¿ë // bool SerializeOut(char* szBuffer_Out, char* szInfoBuffer_Out, unsigned long& dwBufferSize_InOut, unsigned long& dwInfoBufferSize_InOut) const; bool SerializeIn(const char* szBuffer_In, const char* szInfo_In, unsigned long dwBufferSize_In, unsigned long dwInfoBufferSize_In); unsigned long GetFriendNum() const { return static_cast(m_friendList.size()); } // FnProcess´Â bool operator() (CFriendList::Rebind&) ÇÔ¼ö¸¦ °®´Â ±¸Á¶Ã¼(Ŭ·¡½º)ÀÌ´Ù. template void Process(FnProcess fnProcess) { std::for_each(m_friendList.begin(), m_friendList.end(), fnProcess); } private: struct Flags; unsigned long m_dwOwnerCID; // XRef»ðÀÔ¿ë. CXRefFriends* m_lpXRefTable; // XRefTableÆ÷ÀÎÅÍ (NULLÀÌ¸é »ðÀÔ ¾È ÇÔ) FriendList m_friendList; }; #endif