示例#1
0
        static void AcceptCallback(IAsyncResult result)
        {
            if (Server.shuttingDown)
            {
                return;
            }
            TcpListen listen   = (TcpListen)result.AsyncState;
            Player    p        = null;
            bool      accepted = false;

            try {
                p = new Player();
                p.Connect(listen.socket.EndAccept(result));
                listen.AcceptNextAsync();
                accepted = true;
            } catch (Exception ex) {
                if (!(ex is SocketException))
                {
                    Logger.LogError(ex);
                }

                if (p != null)
                {
                    p.Disconnect();
                }
                if (!accepted)
                {
                    listen.AcceptNextAsync();
                }
            }
        }
示例#2
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();
        }