public void Stop() { Running = false; Logging.Info("AresServer", "Chatroom server shutting down."); timer.Change(-1, -1); timer.Dispose(); Config.PropertyChanged -= Config_PropertyChanged; listener?.Dispose(); listener = null; tlslistener?.Dispose(); tlslistener = null; idpool.Clear(); Stats.Reset(); Channels.PropertyChanged -= OnChannelsPropertyChanged; Channels.Stop(); Channels.Channels.SaveModel(Path.Combine(Config.Directories.AppData, "channels.json")); lock (pending) { foreach (var sock in pending) { sock.Dispose();//suppress disconnect event } pending.Clear(); } foreach (var user in Users) { History.Add(user); user.Dispose();//suppress disconnect event } Users.Clear(); History.Admin.Save();//admin are saved separate from history History.SaveModel(Path.Combine(Config.Directories.AppData, "history.json")); Logging.Info("AresServer", "Chatroom server stopped."); }
public void Start() { Stats.Start(); Channels.PropertyChanged += OnChannelsPropertyChanged; Channels.Server = this; Channels.Start(Config.Port); for (ushort i = 0; i < Config.MaxClients; i++) { idpool.Push(i); } Config.PropertyChanged += Config_PropertyChanged; if (Config.UseTcpSockets || Config.UseWebSockets) { LocalAddresses = Utils.GetLocalAddresses(); listener = new AresTcpSocket(new ClientFormatter()); listener.Accepted += ClientAccepted; listener.Bind(new IPEndPoint(Config.LocalIp, Config.Port)); listener.Listen(25); if (Config.UseTlsSockets) { tlslistener = new AresTcpSocket(new ClientFormatter()); tlslistener.Accepted += TLSClientAccepted; tlslistener.Bind(new IPEndPoint(Config.LocalIp, Config.Port + 1)); tlslistener.Listen(25); } } Running = true; Stats.StartTime = DateTime.Now; timer = new Timer(new TimerCallback(OnTimer), null, ticklength, ticklength); Logging.Info("AresServer", "Chatroom server started."); }
public void Start() { stats.Start(); channels.Start(); for (ushort i = 0; i < config.MaxClients; i++) { idpool.Push(i); } config.PropertyChanged += Config_PropertyChanged; listener = new AresTcpSocket(new ClientFormatter()); listener.Accepted += ClientAccepted; Logging.WriteLines(new[] { "Server started", "----------", String.Format("Listening on port: {0}", config.Port), "----------" }); IPHostEntry entry = Dns.GetHostEntry(Environment.MachineName); foreach (var ip in entry.AddressList) { if (ip.AddressFamily == listener.Socket.AddressFamily) { LocalIp = ip; break; } } listener.Bind(new IPEndPoint(IPAddress.Any, config.Port)); listener.Listen(25); RaisePropertyChanged(() => Running); timer = new Timer(new TimerCallback(OnTimer), null, ticklength, ticklength); }
public void Stop() { timer.Change(-1, -1); timer.Dispose(); config.PropertyChanged -= Config_PropertyChanged; listener.Dispose(); listener = null; idpool.Clear(); stats.Reset(); channels.Stop(); RaisePropertyChanged(() => Running); lock (pending) { foreach (var sock in pending) { sock.Dispose();//suppress disconnect event } pending.Clear(); } lock (users.SyncRoot) { foreach (var user in users) { history.Add(user); user.Dispose();//suppress disconnect event } users.Clear(); } history.Save(); }
public PendingConnection(AresTcpSocket socket, DateTime time) { this.Socket = socket; this.Time = time; }