implement setting zone (room name)

This commit is contained in:
Alan Moon 2025-03-18 15:43:26 -07:00
parent 13e9723626
commit fd9c7b817c
2 changed files with 31 additions and 1 deletions

View File

@ -96,6 +96,30 @@ public class ApiWebService
} catch (Exception e) { LogError(e.Message); return false; } } 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<string, string>
{
{ "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<bool>().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 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}"); private void LogError(string message) => Console.WriteLine($"An Error Has Occured When Sending An API Request - {message}");

View File

@ -64,6 +64,7 @@ public class Client {
Room.Send(NetworkObject.WrapObject(0, 1004, data).Serialize()); Room.Send(NetworkObject.WrapObject(0, 1004, data).Serialize());
apiWebService.SetOnline(this, false); apiWebService.SetOnline(this, false);
apiWebService.SetRoom(this, 0, string.Empty);
} }
// set new room (null when SetRoom is used as LeaveRoom) // set new room (null when SetRoom is used as LeaveRoom)
@ -74,9 +75,14 @@ public class Client {
Room.AddClient(this); Room.AddClient(this);
Send(Room.SubscribeRoom()); Send(Room.SubscribeRoom());
if (Room.Name != "LIMBO") UpdatePlayerUserVariables(); // do not update user vars if room is limbo
apiWebService.SetOnline(this, true); 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
} }
} }
} }