You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

using System;
using GameServer.Arch;
using GameServer.Game;
namespace GameServer.Management {
public class Client {
public readonly int Id;
public readonly TcpManager Tcp;
public readonly UdpManager Udp;
public string Name { get; set; }
public Player Player;
public Room Room { get; set; }
public Client(int clientId) {
Id = clientId;
Tcp = new TcpManager(Id);
Udp = new UdpManager(Id);
}
public void OnConnect() {
ServerSend.Welcome(Id, "Welcome to the server!");
if (Tcp.Socket.Client.RemoteEndPoint != null)
_endpoint = Tcp.Socket.Client.RemoteEndPoint.ToString();
}
public void Disconnect() {
Tcp.Disconnect();
Udp.Disconnect();
if (Room != null)
Server.LeaveRoom(this);
Player = null;
Console.WriteLine($"{this} has disconnected.");
}
private string _endpoint = "Client";
public override string ToString() {
return $"{{\"{Name}\" | {_endpoint}}}";
}
}
}