public void AddClient(Client c) { Clients.Add(c, c.GetPlayer()); }
public void RemoveClient(Client c) { Clients.Remove(c); }
public void Run() { IPAddress BindAddress; int BindPort = Config.BindPort; if (!IPAddress.TryParse(Config.BindAddress, out BindAddress)) { Logger.Error("Specified IP address is invalid; using default."); BindAddress = IPAddress.Any; } if (BindPort < 1 || BindPort > 65535) { Logger.Error("Specified port is invalid; using default."); BindPort = 31337; } LocalEP = new IPEndPoint(BindAddress, BindPort); try { BindSocket.Bind(LocalEP); BindSocket.Listen(0); Logger.Info("Server bound to {0}.", BindSocket.LocalEndPoint); } catch (SocketException e) { Logger.Fatal("Unable to bind to {0}. {1}", LocalEP, e); return; } Running = true; Client Client; while (BindSocket.IsBound) { try { Client = new Client(this, BindSocket.Accept()); GameState.AddClient(Client); Logger.Info("New Connection [{0}].", Client.RemoteEndPoint); } catch (SocketException e) { Logger.Warn("{0}", e); } } Logger.Fatal("Server no longer bound."); }