public override void OnReceiveAccountMessage(ServerAccountMessage message)
        {
            switch (message.GetMessageType())
            {
            case ServerMessageType.GAME_STATE_CALLBACK:
                GameMessageManager.OnHomeStateCallbackMessageReceived((GameStateCallbackMessage)message);
                break;

            case ServerMessageType.GAME_ALLOW_SERVER_COMMAND:
                GameMessageManager.OnGameAllowServerCommandMessageReceived((GameAllowServerCommandMessage)message);
                break;

            case ServerMessageType.ALLIANCE_LEAVED:
                GameMessageManager.OnAllianceLeavedMessageReceived((AllianceLeavedMessage)message);
                break;

            case ServerMessageType.CREATE_AVATAR_STREAM:
                GameMessageManager.OnNewAvatarStreamMessageReceived((CreateAvatarStreamMessage)message);
                break;

            case ServerMessageType.INITIALIZE_LIVE_REPLAY:
            case ServerMessageType.END_LIVE_REPLAY:
            case ServerMessageType.CLIENT_UPDATE_LIVE_REPLAY:
            case ServerMessageType.SERVER_UPDATE_LIVE_REPLAY:
            case ServerMessageType.LIVE_REPLAY_REMOVE_SPECTATOR:
                LiveReplayManager.ReceiveMessage(message);
                break;
            }
        }
        public override void OnReceiveRequestMessage(ServerRequestMessage message)
        {
            switch (message.GetMessageType())
            {
            case ServerMessageType.AVATAR_REQUEST:
                GameMessageManager.OnAvatarRequestMessageReceived((AvatarRequestMessage)message);
                break;

            case ServerMessageType.GAME_AVATAR_REQUEST:
                GameMessageManager.OnGameAvatarRequestMessageReceived((GameAvatarRequestMessage)message);
                break;

            case ServerMessageType.GAME_JOIN_ALLIANCE_REQUEST:
                GameMessageManager.OnGameJoinAllianceRequestMessageReceived((GameJoinAllianceRequestMessage)message);
                break;

            case ServerMessageType.GAME_CREATE_ALLIANCE_INVITATION_REQUEST:
                GameMessageManager.OnGameCreateAllianceInvitationRequestMessageReceived((GameCreateAllianceInvitationRequestMessage)message);
                break;

            case ServerMessageType.LIVE_REPLAY_ADD_SPECTATOR_REQUEST:
                LiveReplayManager.ReceiveMessage(message);
                break;
            }
        }
        public override void OnReceiveSessionMessage(ServerSessionMessage message)
        {
            switch (message.GetMessageType())
            {
            case ServerMessageType.START_SERVER_SESSION:
                GameSessionManager.OnStartServerSessionMessageReceived((StartServerSessionMessage)message);
                break;

            case ServerMessageType.STOP_SERVER_SESSION:
                GameSessionManager.OnStopServerSessionMessageReceived((StopServerSessionMessage)message);
                break;

            case ServerMessageType.UPDATE_SOCKET_SERVER_SESSION:
                GameMessageManager.OnUpdateSocketServerSessionMessageReceived((UpdateSocketServerSessionMessage)message);
                break;

            case ServerMessageType.FORWARD_LOGIC_MESSAGE:
                GameMessageManager.OnForwardLogicMessageReceived((ForwardLogicMessage)message);
                break;

            case ServerMessageType.FORWARD_LOGIC_REQUEST_MESSAGE:
                GameMessageManager.OnForwardLogicMessageRequestMessageReceived((ForwardLogicRequestMessage)message);
                break;

            case ServerMessageType.CHANGE_GAME_STATE:
                GameMessageManager.OnChangeGameStateMessageReceived((ChangeGameStateMessage)message);
                break;

            case ServerMessageType.GAME_MATCHMAKING:
                GameMessageManager.OnGameMatchmakingMessageReceived((GameMatchmakingMessage)message);
                break;

            case ServerMessageType.GAME_MATCHMAKING_RESULT:
                GameMatchmakingManager.OnGameMatchmakingResultMessageReceived((GameMatchmakingResultMessage)message);
                break;

            case ServerMessageType.GAME_START_FAKE_ATTACK:
                GameMessageManager.OnGameStartFakeAttackMessageReceived((GameStartFakeAttackMessage)message);
                break;

            case ServerMessageType.GAME_FRIENDLY_SCOUT:
                GameMessageManager.OnGameFriendlyScoutMessageReceived((GameFriendlyScoutMessage)message);
                break;

            case ServerMessageType.GAME_SPECTATE_LIVE_REPLAY:
                GameMessageManager.OnGameSpectateLiveReplayMessageReceived((GameSpectateLiveReplayMessage)message);
                break;
            }
        }
        private static void OnForwardLogicMessageRequestMessageReceived(ForwardLogicRequestMessage message)
        {
            PiranhaMessage logicMessage = LogicMagicMessageFactory.Instance.CreateMessageByType(message.MessageType);

            if (logicMessage == null)
            {
                throw new Exception("logicMessage should not be NULL!");
            }

            logicMessage.GetByteStream().SetByteArray(message.MessageBytes, message.MessageLength);
            logicMessage.SetMessageVersion(message.MessageVersion);
            logicMessage.Decode();

            if (!logicMessage.IsServerToClientMessage())
            {
                switch (logicMessage.GetMessageType())
                {
                case AskForAvatarProfileMessage.MESSAGE_TYPE:
                {
                    AskForAvatarProfileMessage askForAvatarProfileMessage = (AskForAvatarProfileMessage)logicMessage;
                    LogicLong avatarId = askForAvatarProfileMessage.RemoveAvatarId();

                    if (GameAvatarManager.TryGet(avatarId, out GameAvatar document))
                    {
                        AvatarProfileMessage   avatarProfileMessage   = new AvatarProfileMessage();
                        AvatarProfileFullEntry avatarProfileFullEntry = new AvatarProfileFullEntry();

                        avatarProfileFullEntry.SetLogicClientAvatar(document.LogicClientAvatar);
                        avatarProfileFullEntry.SetCompressedHomeJSON(document.LogicClientHome.GetCompressibleHomeJSON().GetCompressed());

                        avatarProfileMessage.SetAvatarProfileFullEntry(avatarProfileFullEntry);

                        ServerMessageManager.SendMessage(GameMessageManager.CreateForwardLogicMessage(avatarProfileMessage, message.SessionId), ServerManager.GetProxySocket(message.SessionId));
                    }
                    else
                    {
                        AvatarProfileFailedMessage avatarProfileFailedMessage = new AvatarProfileFailedMessage();
                        avatarProfileFailedMessage.SetErrorType(AvatarProfileFailedMessage.ErrorType.NOT_FOUND);
                        ServerMessageManager.SendMessage(GameMessageManager.CreateForwardLogicMessage(avatarProfileFailedMessage, message.SessionId),
                                                         ServerManager.GetProxySocket(message.SessionId));
                    }

                    break;
                }
                }
            }
        }