示例#1
0
        public void Disconnect()
        {
            if (!_socket.Connected)
            {
                return;
            }

            Console.WriteLine($"Disconnecting {_socket.RemoteEndPoint}");

            ServerWrapper.Log(Encoding.ASCII.GetBytes($"{_socket.RemoteEndPoint} disconnected."));

            _socket.Shutdown(SocketShutdown.Both);
            _socket.Close();
        }
示例#2
0
 public void Parse(string str)
 {
     if (str.StartsWith($"{Name}:/nick "))
     {
         str = ServerWrapper.RemoveWhiteSpace(Encoding.ASCII.GetBytes(str));
         ServerWrapper.Log($"{Name} has changed their name to {str.Substring($"{Name}:/nick ".Length)}");
         Console.WriteLine($"{Name} has changed their name to {str.Substring($"{Name}:/nick ".Length)}");
         Name = str.Substring($"{Name}:/nick ".Length);
     }
     else if (str.Trim() == "/disconnect")
     {
         ServerWrapper.Log($"{Name} has disconnected.");
         Console.WriteLine($"{Name} has disconnected.");
         Disconnect();
         ServerWrapper.ConnectedUsers.Remove(this);
     }
     else
     {
         Console.WriteLine(ServerWrapper.RemoveWhiteSpace(Encoding.ASCII.GetBytes(str)));
         ServerWrapper.Log(ServerWrapper.RemoveWhiteSpace(Encoding.ASCII.GetBytes(str)));
     }
 }