using System.Collections.Generic; using System.Collections.Concurrent; using System.Net.Sockets; namespace Passer.Control { public class Client { //public ConnectionMethod connection; public UdpClient udpClient; public string ipAddress; public int port; public byte networkId; public readonly ConcurrentQueue messageQueue = new(); public static Client GetClient(string ipAddress, int port) { foreach (Client c in clients) { if (c.ipAddress == ipAddress && c.port == port) return c; } return null; } static public List clients = new List(); public static Client NewClient() { Client client = new(); clients.Add(client); client.networkId = 0; return client; } public static Client NewUDPClient(UdpClient udpClient, string ipAddress, int port) { Client client = NewClient(); client.ipAddress = null; client.port = port; client.udpClient = udpClient; return client; } public void ProcessMessage(IMessage msg) { switch (msg) { case ClientMsg clientMsg: ProcessClient(clientMsg); break; case NetworkIdMsg networkId: ProcessNetworkId(networkId); break; case InvestigateMsg investigate: ProcessInvestigate(investigate); break; case ThingMsg thing: ProcessThing(thing); break; case NameMsg name: ProcessName(name); break; case ModelUrlMsg modelUrl: ProcessModelUrl(modelUrl); break; case PoseMsg pose: ProcessPose(pose); break; case CustomMsg custom: ProcessCustom(custom); break; case TextMsg text: ProcessText(text); break; case DestroyMsg destroy: ProcessDestroy(destroy); break; } } protected virtual void ProcessClient(ClientMsg client) { } protected virtual void ProcessNetworkId(NetworkIdMsg networkId) { } protected virtual void ProcessInvestigate(InvestigateMsg investigate) { } protected virtual void ProcessThing(ThingMsg thing) { } protected virtual void ProcessName(NameMsg name) { } protected virtual void ProcessModelUrl(ModelUrlMsg modelUrl) { } protected virtual void ProcessPose(PoseMsg pose) { } protected virtual void ProcessCustom(CustomMsg custom) { } protected virtual void ProcessText(TextMsg text) { } protected virtual void ProcessDestroy(DestroyMsg destroy) { } } }