Compare commits

...

2 Commits

2 changed files with 31 additions and 0 deletions

View File

@ -74,6 +74,28 @@ public class ApiWebService
} catch (Exception e) { LogError(e.Message); return false; }
}
public bool SetOnline(Client client, bool online)
{
HttpClient httpClient = new();
var content = new FormUrlEncodedContent
(
new Dictionary<string, string>
{
{ "token", client.PlayerData.UNToken },
{ "online", online.ToString() }
}
);
try
{
var response = httpClient.PostAsync($"{Configuration.ServerConfiguration.ApiUrl}/Precense/SetVikingOnline", content).Result;
Log("Precense/SetVikingOnline");
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 LogError(string message) => Console.WriteLine($"An Error Has Occured When Sending An API Request - {message}");

View File

@ -47,6 +47,9 @@ public class Client {
}
public void SetRoom(Room? room) {
// api web service for setting precense
ApiWebService apiWebService = new();
lock(clientLock) {
// set variable player data as not valid, but do not reset all player data
PlayerData.IsValid = false;
@ -59,6 +62,8 @@ public class Client {
data.Add("r", Room.Id);
data.Add("u", ClientID);
Room.Send(NetworkObject.WrapObject(0, 1004, data).Serialize());
apiWebService.SetOnline(this, false);
}
// set new room (null when SetRoom is used as LeaveRoom)
@ -70,6 +75,8 @@ public class Client {
Send(Room.SubscribeRoom());
if (Room.Name != "LIMBO") UpdatePlayerUserVariables(); // do not update user vars if room is limbo
apiWebService.SetOnline(this, true);
}
}
}
@ -98,11 +105,13 @@ public class Client {
}
public void ScheduleDisconnect() {
ApiWebService apiWebService = new();
if (Room != null) {
// quiet remove from room (to avoid issues in Room.Send)
// - do not change Room value here
// - full remove will be will take place Server.HandleClient (before real disconnected)
Room.RemoveClient(this);
apiWebService.SetOnline(this, false);
}
scheduledDisconnect = true;
}