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 #include <playerdata.h>
32
33 using namespace std;
34
PlayerData(unsigned uniqueId,int number,PlayerType type,PlayerRights rights,bool isGameAdmin)35 PlayerData::PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights, bool isGameAdmin)
36 : m_uniqueId(uniqueId), m_dbId(DB_ID_INVALID), m_number(number), m_startCash(-1), m_type(type), m_rights(rights), m_isGameAdmin(isGameAdmin)
37 {
38 }
39
PlayerData(const PlayerData & other)40 PlayerData::PlayerData(const PlayerData &other)
41 : m_uniqueId(other.GetUniqueId()), m_dbId(other.GetDBId()), m_number(other.GetNumber()), m_startCash(other.GetStartCash()),
42 m_guid(other.GetGuid()), m_oldGuid(other.GetOldGuid()), m_name(other.GetName()), m_password(), m_country(other.GetCountry()),
43 m_avatarFile(other.GetAvatarFile()), m_avatarMD5(other.GetAvatarMD5()), m_type(other.GetType()), m_rights(other.GetRights()),
44 m_isGameAdmin(other.IsGameAdmin()), m_netAvatarFile(), m_dataMutex()
45 {
46 }
47
~PlayerData()48 PlayerData::~PlayerData()
49 {
50 }
51
52 string
GetName() const53 PlayerData::GetName() const
54 {
55 boost::mutex::scoped_lock lock(m_dataMutex);
56 return m_name;
57 }
58
59 void
SetName(const string & name)60 PlayerData::SetName(const string &name)
61 {
62 boost::mutex::scoped_lock lock(m_dataMutex);
63 m_name = name;
64 }
65
66 std::string
GetCountry() const67 PlayerData::GetCountry() const
68 {
69 boost::mutex::scoped_lock lock(m_dataMutex);
70 return m_country;
71 }
72
73 void
SetCountry(const std::string & country)74 PlayerData::SetCountry(const std::string &country)
75 {
76 boost::mutex::scoped_lock lock(m_dataMutex);
77 m_country = country;
78 }
79
80 string
GetAvatarFile() const81 PlayerData::GetAvatarFile() const
82 {
83 boost::mutex::scoped_lock lock(m_dataMutex);
84 return m_avatarFile;
85 }
86
87 void
SetAvatarFile(const std::string & avatarFile)88 PlayerData::SetAvatarFile(const std::string &avatarFile)
89 {
90 boost::mutex::scoped_lock lock(m_dataMutex);
91 m_avatarFile = avatarFile;
92 }
93
94 MD5Buf
GetAvatarMD5() const95 PlayerData::GetAvatarMD5() const
96 {
97 boost::mutex::scoped_lock lock(m_dataMutex);
98 return m_avatarMD5;
99 }
100 void
SetAvatarMD5(const MD5Buf & avatarMD5)101 PlayerData::SetAvatarMD5(const MD5Buf &avatarMD5)
102 {
103 boost::mutex::scoped_lock lock(m_dataMutex);
104 m_avatarMD5 = avatarMD5;
105 }
106
107 boost::shared_ptr<AvatarFile>
GetNetAvatarFile() const108 PlayerData::GetNetAvatarFile() const
109 {
110 return m_netAvatarFile;
111 }
112
113 void
SetNetAvatarFile(boost::shared_ptr<AvatarFile> AvatarFile)114 PlayerData::SetNetAvatarFile(boost::shared_ptr<AvatarFile> AvatarFile)
115 {
116 m_netAvatarFile = AvatarFile;
117 }
118
119 PlayerType
GetType() const120 PlayerData::GetType() const
121 {
122 boost::mutex::scoped_lock lock(m_dataMutex);
123 return m_type;
124 }
125
126 void
SetType(PlayerType type)127 PlayerData::SetType(PlayerType type)
128 {
129 boost::mutex::scoped_lock lock(m_dataMutex);
130 m_type = type;
131 }
132
133 PlayerRights
GetRights() const134 PlayerData::GetRights() const
135 {
136 boost::mutex::scoped_lock lock(m_dataMutex);
137 return m_rights;
138 }
139
140 void
SetRights(PlayerRights rights)141 PlayerData::SetRights(PlayerRights rights)
142 {
143 boost::mutex::scoped_lock lock(m_dataMutex);
144 m_rights = rights;
145 }
146
147 bool
IsGameAdmin() const148 PlayerData::IsGameAdmin() const
149 {
150 boost::mutex::scoped_lock lock(m_dataMutex);
151 return m_isGameAdmin;
152 }
153
154 void
SetGameAdmin(bool isAdmin)155 PlayerData::SetGameAdmin(bool isAdmin)
156 {
157 boost::mutex::scoped_lock lock(m_dataMutex);
158 m_isGameAdmin = isAdmin;
159 }
160
161 unsigned
GetUniqueId() const162 PlayerData::GetUniqueId() const
163 {
164 // const value - no mutex needed.
165 return m_uniqueId;
166 }
167
168 int
GetNumber() const169 PlayerData::GetNumber() const
170 {
171 boost::mutex::scoped_lock lock(m_dataMutex);
172 return m_number;
173 }
174
175 void
SetNumber(int number)176 PlayerData::SetNumber(int number)
177 {
178 boost::mutex::scoped_lock lock(m_dataMutex);
179 m_number = number;
180 }
181
182 std::string
GetGuid() const183 PlayerData::GetGuid() const
184 {
185 boost::mutex::scoped_lock lock(m_dataMutex);
186 return m_guid;
187 }
188
189 void
SetGuid(const std::string & guid)190 PlayerData::SetGuid(const std::string &guid)
191 {
192 boost::mutex::scoped_lock lock(m_dataMutex);
193 m_guid = guid;
194 }
195
196 std::string
GetOldGuid() const197 PlayerData::GetOldGuid() const
198 {
199 boost::mutex::scoped_lock lock(m_dataMutex);
200 return m_oldGuid;
201 }
202
203 void
SetOldGuid(const std::string & guid)204 PlayerData::SetOldGuid(const std::string &guid)
205 {
206 boost::mutex::scoped_lock lock(m_dataMutex);
207 m_oldGuid = guid;
208 }
209
210 DB_id
GetDBId() const211 PlayerData::GetDBId() const
212 {
213 boost::mutex::scoped_lock lock(m_dataMutex);
214 return m_dbId;
215 }
216
217 void
SetDBId(DB_id id)218 PlayerData::SetDBId(DB_id id)
219 {
220 boost::mutex::scoped_lock lock(m_dataMutex);
221 m_dbId = id;
222 }
223
224 int
GetStartCash() const225 PlayerData::GetStartCash() const
226 {
227 boost::mutex::scoped_lock lock(m_dataMutex);
228 return m_startCash;
229 }
230
231 void
SetStartCash(int cash)232 PlayerData::SetStartCash(int cash)
233 {
234 boost::mutex::scoped_lock lock(m_dataMutex);
235 m_startCash = cash;
236 }
237
238 bool
operator <(const PlayerData & other) const239 PlayerData::operator<(const PlayerData &other) const
240 {
241 boost::mutex::scoped_lock lock(m_dataMutex);
242 return m_number < other.GetNumber();
243 }
244
245