public void AddClient(BaseClient baseClient) { if (!Clients.ContainsKey(baseClient.Id)) { baseClient.OnPacketSended += (Id, basepacket) => { OnPacketSended?.Invoke(Id, basepacket); }; Clients.Add(baseClient.Id, baseClient); if (baseClient.IsBot == true) { List <ClientInfo> clientInfos = new List <ClientInfo>(); foreach (var item in Clients) { if (item.Value.IsBot == true) { clientInfos.Add(new ClientInfo(item.Value.Id, ((HardwareClient)(item.Value)).gPSPosition)); } } foreach (var item in Clients) { if (item.Value.IsBot == false) { item.Value.SendPacket(new ClientinfoPacket(clientInfos.ToArray())); } } } } }
public void SendPacket(BasePacket basePacket) { if (clientSender.SendPacket(basePacket)) { OnPacketSended?.Invoke(Id, basePacket); } }
private void Start() { receiverObj = gameObject.GetComponent <PacketReceiverObj>(); receiverObj.Init(); receiverObj.OnDataInvoke += (Id, basepacket) => { OnDataInvoke?.Invoke(Id, basepacket); }; clientsManagerObj = gameObject.GetComponent <ClientsManagerObj>(); clientsManagerObj.Init(receiverObj); clientsManagerObj.clientsManager.OnPacketSended += (Id, basepacket) => { OnPacketSended?.Invoke(Id, basepacket); }; ConnectedClients = clientsManagerObj.clientsManager.Clients; TaskQueue = new Queue <Action>(); socketServer = new SocketServer(TaskQueue, this, lockObject); UnmanagedConnectedClients = socketServer.clientsManager.SocketClients; UnmanagedPreClients = socketServer.clientsManager.PreClients; socketServer.Start(); }