public void RemoveUser(TcpSocket connectionInfo) => Task.Run(() => { if (!Exists(connectionInfo)) { return; } Remove(this[connectionInfo]); }).Wait();
private void BeginAccepting() { Start(); BeginAcceptTcpClient(ar => { try { TcpSocket socket = new TcpSocket((( TcpListener )ar.AsyncState).EndAcceptTcpClient(ar)); ClientConnectionRequested?.Invoke(socket); } catch (ObjectDisposedException) { /* Is caused when exitting the server while still listening for new clients */ } BeginAccepting(); }, this); }
public User(int id, string username, TcpSocket tcpConnectionInfo) { ID = id; Username = username; TcpConnectionInfo = tcpConnectionInfo; }
public User(string username, TcpSocket tcpConnectionInfo) { ID = -1; Username = username; TcpConnectionInfo = tcpConnectionInfo; }
public User(TcpSocket tcpConnectionInfo) { ID = -1; Username = "******"; TcpConnectionInfo = tcpConnectionInfo; }
public bool Exists(TcpSocket connectionInfo) => this[connectionInfo] != null;
public void CreateTempUser(TcpSocket connectionInfo) => AddUser(new User(connectionInfo));
public void CreateUser(string username, TcpSocket connectionInfo) => AddUser(new User(username, connectionInfo));
public User this[TcpSocket connectionInfo] { get { try { return(_userList.First(u => u.TcpConnectionInfo == connectionInfo)); } catch (Exception) { return(null); } } }