HandleMessage() private method

Handles messages in the buffer
private HandleMessage ( byte buffer ) : byte[]
buffer byte the buffer to process
return byte[]
コード例 #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!");
            }
        }