From fd9c7b817c6efe9ebb2e4630847ac3508e4ad6c6 Mon Sep 17 00:00:00 2001 From: AlanMoonbase Date: Tue, 18 Mar 2025 15:43:26 -0700 Subject: [PATCH] implement setting zone (room name) --- src/Core/ApiWebService.cs | 24 ++++++++++++++++++++++++ src/Core/Client.cs | 8 +++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Core/ApiWebService.cs b/src/Core/ApiWebService.cs index 0b21553..f4af081 100644 --- a/src/Core/ApiWebService.cs +++ b/src/Core/ApiWebService.cs @@ -96,6 +96,30 @@ public class ApiWebService } catch (Exception e) { LogError(e.Message); return false; } } + public bool SetRoom(Client client, int roomId, string zoneName) + { + HttpClient httpClient = new(); + var content = new FormUrlEncodedContent + ( + new Dictionary + { + { "token", client.PlayerData.UNToken }, + { "roomId", roomId.ToString() }, + { "zoneName", zoneName } + } + ); + + try + { + var response = httpClient.PostAsync($"{Configuration.ServerConfiguration.ApiUrl}/Precense/SetVikingRoom", content).Result; + Log("Precense/SetVikingRoom"); + + if (response.StatusCode == System.Net.HttpStatusCode.OK && response.Content != null) return response.Content.ReadFromJsonAsync().Result; + else return false; + } + catch (Exception e) { LogError(e.Message); return false; } + } + private void Log(string endpoint) => Console.WriteLine($"Sent API Request To {Configuration.ServerConfiguration.ApiUrl}/{endpoint}"); private void LogError(string message) => Console.WriteLine($"An Error Has Occured When Sending An API Request - {message}"); diff --git a/src/Core/Client.cs b/src/Core/Client.cs index ddb9617..84df129 100644 --- a/src/Core/Client.cs +++ b/src/Core/Client.cs @@ -64,6 +64,7 @@ public class Client { Room.Send(NetworkObject.WrapObject(0, 1004, data).Serialize()); apiWebService.SetOnline(this, false); + apiWebService.SetRoom(this, 0, string.Empty); } // set new room (null when SetRoom is used as LeaveRoom) @@ -74,9 +75,14 @@ public class Client { Room.AddClient(this); Send(Room.SubscribeRoom()); - if (Room.Name != "LIMBO") UpdatePlayerUserVariables(); // do not update user vars if room is limbo apiWebService.SetOnline(this, true); + + if (Room.Name != "LIMBO") + { + UpdatePlayerUserVariables(); + apiWebService.SetRoom(this, Room.Id, Room.Name); + } // do not update user vars or set room if limbo } } }