예제 #1
0
        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()));
                        }
                    }
                }
            }
        }
예제 #2
0
 public void SendPacket(BasePacket basePacket)
 {
     if (clientSender.SendPacket(basePacket))
     {
         OnPacketSended?.Invoke(Id, basePacket);
     }
 }
예제 #3
0
    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();
    }