1 /***************************************************************************** 2 * PokerTH - The open source texas holdem engine * 3 * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May * 4 * * 5 * This program is free software: you can redistribute it and/or modify * 6 * it under the terms of the GNU Affero General Public License as * 7 * published by the Free Software Foundation, either version 3 of the * 8 * License, or (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU Affero General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU Affero General Public License * 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 17 * * 18 * * 19 * Additional permission under GNU AGPL version 3 section 7 * 20 * * 21 * If you modify this program, or any covered work, by linking or * 22 * combining it with the OpenSSL project's OpenSSL library (or a * 23 * modified version of that library), containing parts covered by the * 24 * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * 25 * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * 26 * permission to convey the resulting work. * 27 * Corresponding Source for a non-source form of such a combination * 28 * shall include the source code for the parts of OpenSSL used as well * 29 * as that of the covered work. * 30 *****************************************************************************/ 31 /* Player data. */ 32 33 #ifndef _PLAYERDATA_H_ 34 #define _PLAYERDATA_H_ 35 36 #include <boost/shared_ptr.hpp> 37 #include <boost/thread.hpp> 38 #include <string> 39 #include <list> 40 #include <vector> 41 #include <map> 42 #include <core/crypthelper.h> 43 #include <db/serverdbcallback.h> 44 45 class SessionData; 46 47 enum PlayerType { 48 PLAYER_TYPE_COMPUTER, 49 PLAYER_TYPE_HUMAN 50 }; 51 52 enum PlayerRights { 53 PLAYER_RIGHTS_GUEST = 1, 54 PLAYER_RIGHTS_NORMAL, 55 PLAYER_RIGHTS_ADMIN 56 }; 57 58 enum AvatarFileType { 59 AVATAR_FILE_TYPE_UNKNOWN = 0, 60 AVATAR_FILE_TYPE_PNG, 61 AVATAR_FILE_TYPE_JPG, 62 AVATAR_FILE_TYPE_GIF 63 }; 64 65 struct AvatarFile { AvatarFileAvatarFile66 AvatarFile() : fileType(AVATAR_FILE_TYPE_UNKNOWN), reportedSize(0) {} 67 std::vector<unsigned char> fileData; 68 AvatarFileType fileType; 69 size_t reportedSize; 70 }; 71 72 struct PlayerInfo { PlayerInfoPlayerInfo73 PlayerInfo() : ptype(PLAYER_TYPE_HUMAN), isGuest(false), isAdmin(false), hasAvatar(false), avatarType(AVATAR_FILE_TYPE_UNKNOWN) {} 74 std::string playerName; 75 PlayerType ptype; 76 bool isGuest; 77 bool isAdmin; 78 std::string countryCode; 79 bool hasAvatar; 80 MD5Buf avatar; 81 AvatarFileType avatarType; 82 }; 83 84 class PlayerData 85 { 86 public: 87 PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights, bool isGameAdmin); 88 PlayerData(const PlayerData &other); 89 ~PlayerData(); 90 91 std::string GetName() const; 92 void SetName(const std::string &name); 93 std::string GetCountry() const; 94 void SetCountry(const std::string &country); 95 std::string GetAvatarFile() const; 96 void SetAvatarFile(const std::string &avatarFile); 97 MD5Buf GetAvatarMD5() const; 98 void SetAvatarMD5(const MD5Buf &avatarMD5); 99 boost::shared_ptr<AvatarFile> GetNetAvatarFile() const; 100 void SetNetAvatarFile(boost::shared_ptr<AvatarFile> AvatarFile); 101 PlayerType GetType() const; 102 void SetType(PlayerType type); 103 PlayerRights GetRights() const; 104 void SetRights(PlayerRights rights); 105 bool IsGameAdmin() const; 106 void SetGameAdmin(bool isAdmin); 107 unsigned GetUniqueId() const; 108 int GetNumber() const; 109 void SetNumber(int number); 110 std::string GetGuid() const; 111 void SetGuid(const std::string &guid); 112 std::string GetOldGuid() const; 113 void SetOldGuid(const std::string &guid); 114 DB_id GetDBId() const; 115 void SetDBId(DB_id id); 116 int GetStartCash() const; 117 void SetStartCash(int cash); 118 119 bool operator<(const PlayerData &other) const; 120 121 private: 122 const unsigned m_uniqueId; 123 DB_id m_dbId; 124 int m_number; 125 int m_startCash; // only used if > 0 126 std::string m_guid; 127 std::string m_oldGuid; 128 std::string m_name; 129 std::string m_password; 130 std::string m_country; 131 std::string m_avatarFile; 132 MD5Buf m_avatarMD5; 133 PlayerType m_type; 134 PlayerRights m_rights; 135 bool m_isGameAdmin; 136 boost::shared_ptr<AvatarFile> m_netAvatarFile; 137 138 mutable boost::mutex m_dataMutex; 139 }; 140 141 typedef std::list<std::pair<unsigned, unsigned> > RemovePlayerList; 142 typedef std::list<boost::shared_ptr<PlayerData> > PlayerDataList; 143 typedef std::map<unsigned, boost::shared_ptr<PlayerData> > PlayerDataMap; 144 145 #endif 146 147