Disconnect() public method

Handles a player disconnection. Cleans up the player from other players on the server as well as handles cleaning up the player from the system.
public Disconnect ( ) : void
return void
コード例 #1
0
        /// <summary>
        /// Handles network callbacks and adding to the players buffer
        /// </summary>
        /// <param name="result"></param>
        static void Receive(IAsyncResult result)
        {
            Player p = (Player)result.AsyncState;

            if (p.disconnected)
            {
                return;
            }
            try
            {
                int length = p.socket.EndReceive(result);
                if (length == 0)
                {
                    p.Disconnect(); return;
                }

                byte[] b = new byte[p.buffer.Length + length];
                Buffer.BlockCopy(p.buffer, 0, b, 0, p.buffer.Length);
                Buffer.BlockCopy(p.tempbuffer, 0, b, p.buffer.Length, length);

                p.buffer = p.HandleMessage(b);
                p.socket.BeginReceive(p.tempbuffer, 0, p.tempbuffer.Length, SocketFlags.None,
                                      new AsyncCallback(Receive), p);
            }
            catch (SocketException)
            {
                p.Disconnect();
            }
            catch (Exception e)
            {
                Logger.Log(e.Message);
                p.Kick("Error!");
            }
        }