forked from SoDOff-Project/sodoff-mmo
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
b57bd2679f | |||
fd9c7b817c |
32
src/CommandHandlers/JoinUserHandler.cs
Normal file
32
src/CommandHandlers/JoinUserHandler.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using sodoffmmo.Attributes;
|
||||||
|
using sodoffmmo.Core;
|
||||||
|
using sodoffmmo.Data;
|
||||||
|
|
||||||
|
namespace sodoffmmo.CommandHandlers
|
||||||
|
{
|
||||||
|
[ExtensionCommandHandler("JU")]
|
||||||
|
public class JoinUserHandler : CommandHandler
|
||||||
|
{
|
||||||
|
public override Task Handle(Client client, NetworkObject receivedObject)
|
||||||
|
{
|
||||||
|
string mpId = receivedObject.Get<NetworkObject>("p").Get<string>("0");
|
||||||
|
|
||||||
|
if (mpId != null)
|
||||||
|
{
|
||||||
|
Room? room = Room.AllRooms().FirstOrDefault(e => e.Id == Int32.Parse(mpId));
|
||||||
|
|
||||||
|
if (room != null)
|
||||||
|
{
|
||||||
|
client.SetRoom(room);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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}");
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user