Esempio n. 1
0
        static void AcceptCallback(IAsyncResult result)
        {
            if (Server.shuttingDown)
            {
                return;
            }
            TcpListen listen = (TcpListen)result.AsyncState;
            TcpSocket s      = null;

            try {
                Socket raw    = listen.socket.EndAccept(result);
                bool   cancel = false;

                OnConnectionReceivedEvent.Call(raw, ref cancel);
                if (cancel)
                {
                    // intentionally non-clean connection close
                    try { raw.Close(); } catch { }
                }
                else
                {
                    s = new TcpSocket(raw);
                    Logger.Log(LogType.UserActivity, s.IP + " connected to the server.");
                    s.Init();
                }
            } catch (Exception ex) {
                if (!(ex is SocketException))
                {
                    Logger.LogError(ex);
                }
                if (s != null)
                {
                    s.Close();
                }
            }
            listen.AcceptNextAsync();
        }
Esempio n. 2
0
 public override void Unload(bool shutdown)
 {
     OnPlayerStartConnectingEvent.Unregister(HandleConnecting);
     OnConnectionReceivedEvent.Unregister(HandleConnectionReceived);
     Server.Background.Cancel(clearTask);
 }
Esempio n. 3
0
 public override void Load(bool startup)
 {
     OnPlayerStartConnectingEvent.Register(HandleConnecting, Priority.System_Level);
     OnConnectionReceivedEvent.Register(HandleConnectionReceived, Priority.System_Level);
     clearTask = Server.Background.QueueRepeat(CleanupTask, null, TimeSpan.FromMinutes(10));
 }