public static void Init()
        {
            GameAvatarManager.m_documents = new Dictionary <long, GameAvatar>();

            int[] higherIDs = ServerGame.GameDatabase.GetCounterHigherIDs();

            for (int i = 0; i < higherIDs.Length; i++)
            {
                int highId = i;

                Parallel.For(1, higherIDs[i] + 1, lowId =>
                {
                    LogicLong id = new LogicLong(highId, lowId);

                    if (ServerManager.GetDocumentSocket(ServerCore.Type, id) == ServerCore.Socket)
                    {
                        IOperationResult <string> document = ServerGame.GameDatabase.Get(id).Result;

                        if (document.Success)
                        {
                            lock (GameAvatarManager.m_documents)
                            {
                                GameAvatar gameDocument = CouchbaseDocument.Load <GameAvatar>(document.Value);

                                GameAvatarManager.m_documents.Add(id, gameDocument);
                                GameMatchmakingManager.Enqueue(gameDocument);
                            }
                        }
                    }
                });
            }
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
0
        private static GameAvatar FindEnemy(MatchmakingEntry entry, Dictionary <long, GameAvatar> documents)
        {
            GameAvatar        document      = entry.Session.GameAvatar;
            LogicClientAvatar playerAvatar1 = document.LogicClientAvatar;

            int totalSecs       = TimeUtil.GetTimestamp() - entry.Timestamp;
            int strength1       = GameMatchmakingManager.CalculateStrength(playerAvatar1);
            int maxStrengthDiff = 50 + LogicMath.Clamp(totalSecs * 150 / 60, 0, 150);

            foreach (GameAvatar enemy in documents.Values)
            {
                LogicClientAvatar playerAvatar2 = enemy.LogicClientAvatar;

#if DEBUG
                if (ServerCore.Random.Rand(100) <= 95)
                {
                    continue;
                }
#else
                if (playerAvatar1.IsInAlliance() && playerAvatar2.IsInAlliance() && playerAvatar1.GetAllianceId().Equals(playerAvatar2.GetAllianceId()))
                {
                    continue;
                }

                int strength2 = GameMatchmakingManager.CalculateStrength(playerAvatar2);

                if (LogicMath.Abs(strength1 - strength2) >= maxStrengthDiff)
                {
                    continue;
                }
                if (document.HasRecentlyMatchedWithEnemy(enemy.Id))
                {
                    continue;
                }
#endif
                return(enemy);
            }

            return(null);
        }
Esempio n. 4
0
        private static void Update()
        {
            while (true)
            {
                Dictionary <long, MatchmakingEntry> sessions     = new Dictionary <long, MatchmakingEntry>(GameMatchmakingManager.m_queue);
                Dictionary <long, GameAvatar>       offlineUsers = new Dictionary <long, GameAvatar>(GameMatchmakingManager.m_offlinePlayers);

                foreach (MatchmakingEntry entry in sessions.Values)
                {
                    if (entry.MatchConfirmation)
                    {
                        continue;
                    }
                    if (ServerStatus.Status == ServerStatusType.SHUTDOWN_STARTED ||
                        ServerStatus.Status == ServerStatusType.MAINTENANCE ||
                        ServerStatus.Status == ServerStatusType.COOLDOWN_AFTER_MAINTENANCE)
                    {
                        entry.Session.SendMessage(new GameMatchmakingResultMessage(), 9);
                        entry.MatchConfirmation = true;
                        continue;
                    }

                    GameAvatar enemy = GameMatchmakingManager.FindEnemy(entry, offlineUsers);

                    if (enemy != null)
                    {
                        entry.Session.SendMessage(new GameMatchmakingResultMessage
                        {
                            EnemyId = enemy.Id
                        }, 9);
                        entry.MatchConfirmation = true;
                    }
                }

                Thread.Sleep(250);
            }
        }