1 #include <mysql/mysql_time.h>
5 #include <battlefield/clan.h>
7 std::unordered_map<std::string, Battlefield::Clan::SetterFunc> Battlefield::Clan::SetterMap = {
8 {
"name", &Battlefield::Clan::SetName },
9 {
"tag", &Battlefield::Clan::SetTag },
10 {
"homepage", &Battlefield::Clan::SetHomepage },
11 {
"info", &Battlefield::Clan::SetInfo },
12 {
"region", &Battlefield::Clan::SetRegion },
17 this->SetClanId(543151);
18 this->SetName(
"AT-STARS");
20 this->SetHomepage(
"UMBRELLA");
21 this->SetInfo(
"G%2dVIRUS");
25 bool Battlefield::Clan::SetClanId(
int clanid)
29 this->_clanid = clanid;
37 bool Battlefield::Clan::SetClanId(
const std::string& str_clanid)
41 int clanid = std::stoi(str_clanid);
43 return this->SetClanId(clanid);
50 bool Battlefield::Clan::SetName(
const std::string& name)
54 this->_name = name.substr(0, 31);
64 bool Battlefield::Clan::SetTag(
const std::string& tag)
66 if(tag.size() < 2 || tag.size() > 3)
75 bool Battlefield::Clan::SetHomepage(
const std::string& homepage)
77 if(homepage.size() > 256)
79 this->_homepage = homepage.substr(0, 255);
83 this->_homepage = homepage;
89 bool Battlefield::Clan::SetInfo(
const std::string& info)
91 if(info.size() > 1024)
93 this->_info = info.substr(0, 1023);
105 this->_region = region;
109 bool Battlefield::Clan::SetRegion(uint8_t int_region)
111 if(int_region >=
static_cast<uint8_t
>(Regions::America) && int_region <=
static_cast<uint8_t
>(Regions::Asia))
115 return this->SetRegion(region);
121 bool Battlefield::Clan::SetRegion(
const std::string& str_region)
125 uint8_t int_region =
static_cast<uint8_t
>(std::stoul(str_region));
127 return this->SetRegion(int_region);
134 bool Battlefield::Clan::SetScore(uint32_t score)
136 this->_score = score;
140 bool Battlefield::Clan::SetWins(uint32_t wins)
146 bool Battlefield::Clan::SetLosses(uint32_t losses)
148 this->_losses = losses;
152 bool Battlefield::Clan::SetDraws(uint32_t draws)
154 this->_draws = draws;
158 bool Battlefield::Clan::SetCreatedAt(MYSQL_TIME created_at)
160 this->_created_at = Util::Time::GetDateTime(created_at);
165 bool Battlefield::Clan::SetDisable(
bool disable)
167 this->_disable = disable;
171 bool Battlefield::Clan::SetDisable(uint8_t disable)
173 return this->SetDisable(disable == 1);
176 void Battlefield::Clan::AddRank(
int profileid, Ranks rank)
178 this->_ranks.insert(std::make_pair(profileid, rank));
181 void Battlefield::Clan::AddRank(
int profileid, uint8_t int_rank)
183 this->AddRank(profileid, convertRank(int_rank));
188 auto it = this->_ranks.find(profileid);
189 if (it != this->_ranks.end())
194 return Ranks::Unknown;
203 int int_rank = std::stoi(str_rank);
205 return convertRank(int_rank);
209 return Ranks::Unknown;
214 if(int_rank >=
static_cast<uint8_t
>(Ranks::Leader) && int_rank <=
static_cast<uint8_t
>(Ranks::Member))
216 return static_cast<Ranks>(int_rank);
219 return Ranks::Unknown;
226 uint8_t int_region =
static_cast<uint8_t
>(std::stoul(str_region));
228 return convertRegion(int_region);
232 return Regions::Unknown;
237 if(int_region >=
static_cast<uint8_t
>(Regions::America) && int_region <=
static_cast<uint8_t
>(Regions::Asia))
239 return static_cast<Regions>(int_region);
242 return Regions::Unknown;
static Regions convertRegion(const std::string &str_region)
Converts a string representation of a region to its corresponding enum value.
static Ranks convertRank(const std::string &rank)
Converts a string representation of a rank to its corresponding enum value.
Regions
Represents the regions associated with clans.
void useExample()
Performs an example operation using the Clan class.
Ranks
Represents the ranks within a clan.