initial implementation of BB teams (WIP)

This commit is contained in:
Martin Michelsen
2023-11-18 20:49:18 -08:00
parent 99d1a3272a
commit c1e225847e
21 changed files with 1249 additions and 123 deletions
+40
View File
@@ -263,6 +263,46 @@ shared_ptr<Lobby> Client::require_lobby() const {
return l;
}
shared_ptr<TeamIndex::Team> Client::team() {
if (!this->license) {
throw logic_error("Client::team called on client with no license");
}
if (this->license->bb_team_id == 0) {
return nullptr;
}
auto p = this->game_data.character(false);
auto s = this->require_server_state();
auto team = s->team_index->get_by_id(this->license->bb_team_id);
if (!team) {
this->license->bb_team_id = 0;
this->license->save();
return nullptr;
}
auto member_it = team->members.find(this->license->serial_number);
if (member_it == team->members.end()) {
this->license->bb_team_id = 0;
this->license->save();
return nullptr;
}
// The team membership is valid, but the player name may be different; update
// the team membership if needed
if (p) {
auto& m = member_it->second;
string name = p->disp.name.decode(this->language());
if (m.name != name) {
this->log.info("Updating player name in team config");
m.name = name;
team->save_config();
}
}
return team;
}
void Client::dispatch_save_game_data(evutil_socket_t, short, void* ctx) {
reinterpret_cast<Client*>(ctx)->save_game_data();
}