/// <summary> /// Attemps to read from the socket or blocks until /// a message is ready to be read and if successful, it /// processes that message. /// </summary> /// <param name="player">Player doing the action.</param> /// <param name="world">A reference to the game world.</param> /// <returns>Returns true if to continue processing messages, /// false otherwise.</returns> private bool ProcessNextMessage(Player player, GameWorld world) { //TODO: Handle logging out disposed error... ;/ if (!netmsg.Connected()) { return false; } netmsg.Reset(); ushort header = netmsg.GetU16(); if (header > HEADER_MAX_VAL) { throw new Exception("Invalid header sent. Header: " + header); } //Only process loged in player's messages, unless player //wants to log out if (!world.IsCreatureLogedIn(player)) { if (header == 0xFF) { //Logout header player.Logout(); return false; } } else if (messageDecoder[header] == null) { PrintHeader(netmsg, header); } else { messageDecoder[header].Invoke(player, world); } return true; }