forked from SoDOff-Project/sodoff-mmo
implement setting zone (room name)
This commit is contained in:
parent
13e9723626
commit
fd9c7b817c
@ -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<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 LogError(string message) => Console.WriteLine($"An Error Has Occured When Sending An API Request - {message}");
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user