forked from SoDOff-Project/sodoff-mmo
add Client.JoinRoom()
This commit is contained in:
parent
e7e2c21be6
commit
9b896f6326
@ -7,32 +7,11 @@ namespace sodoffmmo.CommandHandlers;
|
|||||||
[ExtensionCommandHandler("JA")]
|
[ExtensionCommandHandler("JA")]
|
||||||
class JoinRoomHandler : ICommandHandler
|
class JoinRoomHandler : ICommandHandler
|
||||||
{
|
{
|
||||||
Room room;
|
|
||||||
Client client;
|
|
||||||
public void Handle(Client client, NetworkObject receivedObject)
|
public void Handle(Client client, NetworkObject receivedObject)
|
||||||
{
|
{
|
||||||
string roomName = receivedObject.Get<NetworkObject>("p").Get<string>("rn");
|
string roomName = receivedObject.Get<NetworkObject>("p").Get<string>("rn");
|
||||||
client.LeaveRoom();
|
Room room = Room.GetOrAdd(roomName);
|
||||||
client.InvalidatePlayerData();
|
|
||||||
room = Room.GetOrAdd(roomName);
|
|
||||||
Console.WriteLine($"Join Room: {roomName} RoomID: {room.Id} IID: {client.ClientID}");
|
Console.WriteLine($"Join Room: {roomName} RoomID: {room.Id} IID: {client.ClientID}");
|
||||||
this.client = client;
|
client.JoinRoom(room);
|
||||||
|
|
||||||
client.Send(room.RespondJoinRoom());
|
|
||||||
client.Send(room.SubscribeRoom());
|
|
||||||
UpdatePlayerUserVariables();
|
|
||||||
client.Room = room;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdatePlayerUserVariables() {
|
|
||||||
foreach (Client c in room.Clients) {
|
|
||||||
NetworkObject cmd = new();
|
|
||||||
NetworkObject obj = new();
|
|
||||||
cmd.Add("c", "SUV");
|
|
||||||
obj.Add("MID", c.ClientID);
|
|
||||||
cmd.Add("p", obj);
|
|
||||||
client.Send(NetworkObject.WrapObject(1, 13, cmd).Serialize());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,26 @@ public class Client {
|
|||||||
Room = null;
|
Room = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void JoinRoom(Room room) {
|
||||||
|
LeaveRoom();
|
||||||
|
InvalidatePlayerData();
|
||||||
|
Room = room;
|
||||||
|
Send(Room.RespondJoinRoom());
|
||||||
|
Send(Room.SubscribeRoom());
|
||||||
|
UpdatePlayerUserVariables();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdatePlayerUserVariables() {
|
||||||
|
foreach (Client c in Room.Clients) {
|
||||||
|
NetworkObject cmd = new();
|
||||||
|
NetworkObject obj = new();
|
||||||
|
cmd.Add("c", "SUV");
|
||||||
|
obj.Add("MID", c.ClientID);
|
||||||
|
cmd.Add("p", obj);
|
||||||
|
Send(NetworkObject.WrapObject(1, 13, cmd).Serialize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void InvalidatePlayerData() {
|
public void InvalidatePlayerData() {
|
||||||
PlayerData = new();
|
PlayerData = new();
|
||||||
|
@ -124,15 +124,8 @@ public class GauntletRoom : Room {
|
|||||||
if (room is null)
|
if (room is null)
|
||||||
room = GauntletRoom.Get();
|
room = GauntletRoom.Get();
|
||||||
|
|
||||||
room.AddPlayer(client); // must be call before InvalidatePlayerData - we need uid
|
room.AddPlayer(client); // must be call before JoinRoom (before InvalidatePlayerData) - we need uid
|
||||||
|
client.JoinRoom(room);
|
||||||
client.LeaveRoom();
|
|
||||||
client.InvalidatePlayerData();
|
|
||||||
|
|
||||||
client.Send(room.RespondJoinRoom());
|
|
||||||
client.Send(room.SubscribeRoom());
|
|
||||||
room.SendUJR();
|
room.SendUJR();
|
||||||
|
|
||||||
client.Room = room;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ using sodoffmmo.Data;
|
|||||||
|
|
||||||
namespace sodoffmmo.Core;
|
namespace sodoffmmo.Core;
|
||||||
public class Room {
|
public class Room {
|
||||||
static int id = 2;
|
|
||||||
static Dictionary<string, Room> rooms = new();
|
static Dictionary<string, Room> rooms = new();
|
||||||
|
|
||||||
List<Client> clients = new();
|
List<Client> clients = new();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user