forked from SoDOff-Project/sodoff-mmo
Merge pull request 'Buddy Precense Reporting' (#3) from buddy-precense into main
Reviewed-on: https://gitea.milenia.local.alanmoon.net/Moonbase/sodoff-mmo/pulls/3
This commit is contained in:
commit
b378ff2689
@ -74,6 +74,28 @@ public class ApiWebService
|
|||||||
} catch (Exception e) { LogError(e.Message); return false; }
|
} 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 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}");
|
||||||
|
@ -47,6 +47,9 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SetRoom(Room? room) {
|
public void SetRoom(Room? room) {
|
||||||
|
// api web service for setting precense
|
||||||
|
ApiWebService apiWebService = new();
|
||||||
|
|
||||||
lock(clientLock) {
|
lock(clientLock) {
|
||||||
// set variable player data as not valid, but do not reset all player data
|
// set variable player data as not valid, but do not reset all player data
|
||||||
PlayerData.IsValid = false;
|
PlayerData.IsValid = false;
|
||||||
@ -59,6 +62,8 @@ public class Client {
|
|||||||
data.Add("r", Room.Id);
|
data.Add("r", Room.Id);
|
||||||
data.Add("u", ClientID);
|
data.Add("u", ClientID);
|
||||||
Room.Send(NetworkObject.WrapObject(0, 1004, data).Serialize());
|
Room.Send(NetworkObject.WrapObject(0, 1004, data).Serialize());
|
||||||
|
|
||||||
|
apiWebService.SetOnline(this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set new room (null when SetRoom is used as LeaveRoom)
|
// set new room (null when SetRoom is used as LeaveRoom)
|
||||||
@ -70,6 +75,8 @@ public class Client {
|
|||||||
|
|
||||||
Send(Room.SubscribeRoom());
|
Send(Room.SubscribeRoom());
|
||||||
if (Room.Name != "LIMBO") UpdatePlayerUserVariables(); // do not update user vars if room is limbo
|
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() {
|
public void ScheduleDisconnect() {
|
||||||
|
ApiWebService apiWebService = new();
|
||||||
if (Room != null) {
|
if (Room != null) {
|
||||||
// quiet remove from room (to avoid issues in Room.Send)
|
// quiet remove from room (to avoid issues in Room.Send)
|
||||||
// - do not change Room value here
|
// - do not change Room value here
|
||||||
// - full remove will be will take place Server.HandleClient (before real disconnected)
|
// - full remove will be will take place Server.HandleClient (before real disconnected)
|
||||||
Room.RemoveClient(this);
|
Room.RemoveClient(this);
|
||||||
|
apiWebService.SetOnline(this, false);
|
||||||
}
|
}
|
||||||
scheduledDisconnect = true;
|
scheduledDisconnect = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user