core, web_service: Changes to announce service
Separated registering and updating to correspond to the new announce API endpoint. Also added a verify_UID for JWT audience verification.
This commit is contained in:
parent
1a8841f96e
commit
ab335ccf1b
5 changed files with 135 additions and 49 deletions
|
@ -29,6 +29,21 @@ AnnounceMultiplayerSession::AnnounceMultiplayerSession() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void AnnounceMultiplayerSession::Register() {
|
||||
std::shared_ptr<Network::Room> room = Network::GetRoom().lock();
|
||||
if (!room) {
|
||||
return;
|
||||
}
|
||||
if (room->GetState() != Network::Room::State::Open) {
|
||||
return;
|
||||
}
|
||||
UpdateBackendData(room);
|
||||
std::string result = backend->Register();
|
||||
LOG_INFO(WebService, "Room has been registered");
|
||||
room->SetVerifyUID(result);
|
||||
registered = true;
|
||||
}
|
||||
|
||||
void AnnounceMultiplayerSession::Start() {
|
||||
if (announce_multiplayer_thread) {
|
||||
Stop();
|
||||
|
@ -44,6 +59,7 @@ void AnnounceMultiplayerSession::Stop() {
|
|||
announce_multiplayer_thread->join();
|
||||
announce_multiplayer_thread.reset();
|
||||
backend->Delete();
|
||||
registered = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +80,24 @@ AnnounceMultiplayerSession::~AnnounceMultiplayerSession() {
|
|||
Stop();
|
||||
}
|
||||
|
||||
void AnnounceMultiplayerSession::UpdateBackendData(std::shared_ptr<Network::Room> room) {
|
||||
Network::RoomInformation room_information = room->GetRoomInformation();
|
||||
std::vector<Network::Room::Member> memberlist = room->GetRoomMemberList();
|
||||
backend->SetRoomInformation(
|
||||
room_information.name, room_information.description, room_information.port,
|
||||
room_information.member_slots, Network::network_version, room->HasPassword(),
|
||||
room_information.preferred_game, room_information.preferred_game_id);
|
||||
backend->ClearPlayers();
|
||||
for (const auto& member : memberlist) {
|
||||
backend->AddPlayer(member.username, member.nickname, member.avatar_url, member.mac_address,
|
||||
member.game_info.id, member.game_info.name);
|
||||
}
|
||||
}
|
||||
|
||||
void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() {
|
||||
if (!registered) {
|
||||
Register();
|
||||
}
|
||||
auto update_time = std::chrono::steady_clock::now();
|
||||
std::future<Common::WebResult> future;
|
||||
while (!shutdown_event.WaitUntil(update_time)) {
|
||||
|
@ -76,25 +109,19 @@ void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() {
|
|||
if (room->GetState() != Network::Room::State::Open) {
|
||||
break;
|
||||
}
|
||||
Network::RoomInformation room_information = room->GetRoomInformation();
|
||||
std::vector<Network::Room::Member> memberlist = room->GetRoomMemberList();
|
||||
backend->SetRoomInformation(room_information.uid, room_information.name,
|
||||
room_information.description, room_information.port,
|
||||
room_information.member_slots, Network::network_version,
|
||||
room->HasPassword(), room_information.preferred_game,
|
||||
room_information.preferred_game_id);
|
||||
backend->ClearPlayers();
|
||||
for (const auto& member : memberlist) {
|
||||
backend->AddPlayer(member.nickname, member.mac_address, member.game_info.id,
|
||||
member.game_info.name);
|
||||
}
|
||||
Common::WebResult result = backend->Announce();
|
||||
UpdateBackendData(room);
|
||||
Common::WebResult result = backend->Update();
|
||||
if (result.result_code != Common::WebResult::Code::Success) {
|
||||
std::lock_guard<std::mutex> lock(callback_mutex);
|
||||
for (auto callback : error_callbacks) {
|
||||
(*callback)(result);
|
||||
}
|
||||
}
|
||||
if (result.result_string == "404") {
|
||||
registered = false;
|
||||
// Needs to register the room again
|
||||
Register();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue