示例#1
0
 public void InvokeClientConnect(XeonClient client)
 {
     if (OnClientConnect != null)
     {
         OnClientConnect.Invoke(client);
     }
 }
示例#2
0
 public void Start()
 {
     Listener = new TcpListener(BindAddress, Port);
     Listener.Start();
     Log.WriteLine($"Listening on {BindAddress}:{Port}...");
     NetworkThread = new Thread(async() =>
     {
         while (true)
         {
             if (Listener.Pending())
             {
                 TcpClient tclient = await Listener.AcceptTcpClientAsync();
                 tclient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                 tclient.Client.NoDelay = true;
                 XeonClient xclient     = new XeonClient(tclient);
                 Log.WriteLine($"Client <{xclient.GUID}> connected: {xclient.RemoteEndPoint}");
                 xclient.OnMessage += (data) =>
                 {
                     Log.WriteLine($"Client <{xclient.GUID}> data received: {data}");
                 };
                 xclient.OnDisconnect += () =>
                 {
                     using (MutLock <List <XeonClient> > list = Clients.Lock())
                     {
                         list.Value.Remove(xclient);
                     }
                     Log.WriteLine($"Client <{xclient.GUID}> disconnected.");
                     xclient = null;
                     tclient = null;
                 };
                 using (MutLock <List <XeonClient> > list = Clients.Lock())
                 {
                     list.Value.Add(xclient);
                 }
                 await xclient.WriteLine("Welcome to the Xeon Project.");
                 await xclient.Write("lua> ");
                 await xclient.Will(Telnet.Option.LineMode);
                 await xclient.Will(Telnet.Option.GMCP);
                 InvokeClientConnect(xclient);
             }
         }
     });
     NetworkThread.Start();
 }