Example #1
0
 public void SendMessage(int ClientID, Packet packet)
 {
     if (this.RCClientInfo.ContainsKey(ClientID))
     {
         ClientServer.Client client = this.RCClientInfo[ClientID];
         if (client.RCClient.Initialized)
         {
             client.Connection.Transmit(packet);
         }
     }
 }
Example #2
0
 private void ClientDisconnected(object sender, EventArgs arg)
 {
     lock (Base.SyncRoot)
     {
         ClientServer.Client client = sender as ClientServer.Client;
         if (client != null)
         {
             this.RemoveClient(client.ID);
             Log <RCServerService> .Logger.DebugFormat("RC Client {0} disconnected", client.ID);
         }
     }
 }
Example #3
0
        private void ClientConnected(object sender, EventArgs arg)
        {
            TcpClient tcpClient = sender as TcpClient;

            if (tcpClient != null)
            {
                lock (Base.SyncRoot)
                {
                    string clientIP            = tcpClient.RemoteEndPoint.Address.ToString();
                    ClientServer.Client client = new ClientServer.Client(this.NewClientID(), clientIP, tcpClient);
                    client.Disconnected        += this.ClientDisconnected;
                    client.PacketReceived      += this.PacketReceived;
                    client.RCClient.ClientInit += this.ClientInitialized;
                    this.RCClientInfo.Add(client.ID, client);
                    Log <RCServerService> .Logger.DebugFormat("RC Client {0} connected", client.ID);
                }
            }
        }
Example #4
0
        private void PacketReceived(object sender, EventArgs <ArraySegment <byte> > e)
        {
            try
            {
                lock (Base.SyncRoot)
                {
                    ClientServer.Client client = sender as ClientServer.Client;
                    if (client != null)
                    {
                        Packet packet = new Packet(e.Value);
                        try
                        {
                            if (!this.PreProcess(client.RCClient, packet))
                            {
                                this.MF.Handle(packet, client.RCClient);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log <RCServerService> .Logger.Error("Packet error", ex);

                            Base.ControlServer.NotifyMessage(MessageType.Message, "[{0}/{1}({2})] - {3}", new object[]
                            {
                                client.ID,
                                client.RCClient.Name,
                                client.RCClient.ClientIP,
                                ex.ToString()
                            });
                            client.Connection.Disconnect();
                        }
                    }
                }
            }
            catch (Exception ex2)
            {
                Log <RCClient> .Logger.Error(ex2);
            }
        }