public void AddServerCommand(LogicServerCommand serverCommand)
        {
            int id = -1;

            for (int i = 0; i < this.ServerCommands.Size(); i++)
            {
                if (this.ServerCommands[i].GetId() > id)
                {
                    id = this.ServerCommands[i].GetId();
                }
            }

            serverCommand.SetId(id + 1);
            this.ServerCommands.Add(serverCommand);

            if (this.CurrentSession != null && this.CurrentSession.GameState != null)
            {
                this.CurrentSession.SendMessage(new HomeServerCommandAllowedMessage
                {
                    ServerCommand = serverCommand
                }, 10);
            }
            else
            {
                GameAvatarManager.ExecuteServerCommandsInOfflineMode(this);
                GameAvatarManager.Save(this);
            }
        }
        public static void ExecuteServerCommandsInOfflineMode(GameAvatar document)
        {
            if (document.ServerCommands.Size() != 0)
            {
                LogicGameMode logicGameMode = new LogicGameMode();
                LogicLevel    logicLevel    = logicGameMode.GetLevel();

                logicLevel.SetVisitorAvatar(document.LogicClientAvatar);

                try
                {
                    for (int i = 0; i < document.ServerCommands.Size(); i++)
                    {
                        int result = document.ServerCommands[i].Execute(logicLevel);

                        if (result == 0)
                        {
                            document.ServerCommands.Remove(i--);
                        }
                    }

                    GameAvatarManager.Save(document);
                }
                catch (Exception exception)
                {
                    Logging.Error("GameAvatarManager.executeServerCommandsInOfflineMode: server command execution in offline mode failed: " + exception);
                }
            }
        }
예제 #3
0
        public static void OnGameMatchmakingResultMessageReceived(GameMatchmakingResultMessage message)
        {
            if (GameMatchmakingManager.m_queue.TryGetValue(message.SessionId, out MatchmakingEntry entry))
            {
                GameSession session = entry.Session;

                if (message.EnemyId != null)
                {
                    GameAvatar enemy = GameAvatarManager.Get(message.EnemyId);
                    GameMatchmakingManager.Dequeue(session);

                    entry.Session.GameAvatar.AddRecentlyMatchedEnemy(message.EnemyId);
                    session.LoadGameState(new GameMatchedAttackState
                    {
                        Home            = enemy.LogicClientHome,
                        HomeOwnerAvatar = enemy.LogicClientAvatar,
                        PlayerAvatar    = session.GameAvatar.LogicClientAvatar,
                        MaintenanceTime = enemy.MaintenanceTime,
                        SaveTime        = enemy.SaveTime,

                        LiveReplayId = LiveReplayManager.Create(session, null, null)
                    });
                }
                else
                {
                    AttackHomeFailedMessage attackHomeFailedMessage = new AttackHomeFailedMessage();

                    switch (ServerStatus.Status)
                    {
                    case ServerStatusType.SHUTDOWN_STARTED:
                    case ServerStatusType.MAINTENANCE:
                        attackHomeFailedMessage.SetReason(AttackHomeFailedMessage.Reason.SHUTDOWN_ATTACK_DISABLED);
                        break;

                    case ServerStatusType.COOLDOWN_AFTER_MAINTENANCE:
                        attackHomeFailedMessage.SetReason(AttackHomeFailedMessage.Reason.COOLDOWN_AFTER_MAINTENANCE);
                        break;

                    default:
                        entry.MatchConfirmation = false;
                        return;
                    }

                    session.SendPiranhaMessage(attackHomeFailedMessage, 1);
                    GameMatchmakingManager.Dequeue(session);
                }
            }
        }