예제 #1
0
        private static void OnAllianceChallengeReportMessageReceived(AllianceChallengeReportMessage message)
        {
            if (AllianceManager.TryGet(message.AccountId, out Alliance alliance))
            {
                ChallengeStreamEntry streamEntry = (ChallengeStreamEntry)StreamManager.GetAllianceStream(message.StreamId);

                if (streamEntry != null)
                {
                    ChallengeReplayStreamEntry challengeReplayStreamEntry = new ChallengeReplayStreamEntry();

                    challengeReplayStreamEntry.SetSenderAvatarId(challengeReplayStreamEntry.GetSenderAvatarId());
                    challengeReplayStreamEntry.SetSenderHomeId(challengeReplayStreamEntry.GetSenderHomeId());
                    challengeReplayStreamEntry.SetSenderName(challengeReplayStreamEntry.GetSenderName());
                    challengeReplayStreamEntry.SetSenderLevel(challengeReplayStreamEntry.GetSenderLevel());
                    challengeReplayStreamEntry.SetSenderLeagueType(challengeReplayStreamEntry.GetSenderLeagueType());
                    challengeReplayStreamEntry.SetSenderRole(challengeReplayStreamEntry.GetSenderRole());

                    challengeReplayStreamEntry.SetBattleLogJSON(message.BattleLog);
                    challengeReplayStreamEntry.SetReplayMajorVersion(LogicVersion.MAJOR_VERSION);
                    challengeReplayStreamEntry.SetReplayBuildVersion(LogicVersion.BUILD_VERSION);
                    challengeReplayStreamEntry.SetReplayContentVersion(ResourceManager.GetContentVersion());
                    challengeReplayStreamEntry.SetReplayId(message.ReplayId);

                    StreamManager.Create(alliance.Id, challengeReplayStreamEntry);

                    alliance.RemoveStreamEntry(streamEntry.GetId());
                    alliance.AddStreamEntry(challengeReplayStreamEntry);
                }
                else
                {
                    Logging.Warning("StreamMessageManager.onAllianceChallengeReportMessageReceived: pStreamEntry has been deleted. Replay ignored.");
                }
            }
        }
        private void OnAcceptFriendlyBattleMessageReceived(AcceptFriendlyBattleMessage message)
        {
            if (this.m_session.Alliance != null)
            {
                Alliance  alliance = this.m_session.Alliance;
                LogicLong streamId = message.GetStreamId();

                if (alliance.StreamEntryList.IndexOf(streamId) != -1)
                {
                    StreamEntry streamEntry = StreamManager.GetAllianceStream(message.GetStreamId());

                    if (streamEntry.GetStreamEntryType() == StreamEntryType.CHALLENGE)
                    {
                        ChallengeStreamEntry challengeStreamEntry = (ChallengeStreamEntry)streamEntry;

                        if (challengeStreamEntry.IsStarted())
                        {
                            ChallengeFailedMessage challengeFailedMessage = new ChallengeFailedMessage();
                            challengeFailedMessage.SetReason(ChallengeFailedMessage.Reason.ALREADY_CLOSED);
                            this.m_session.SendPiranhaMessage(challengeFailedMessage, 1);
                            return;
                        }

                        this.m_session.SendMessage(new ChangeGameStateMessage
                        {
                            StateType           = GameStateType.CHALLENGE_ATTACK,
                            ChallengeAllianceId = alliance.Id,
                            ChallengeHomeId     = challengeStreamEntry.GetSenderAvatarId(),
                            ChallengeStreamId   = challengeStreamEntry.GetId(),
                            ChallengeHomeJSON   = challengeStreamEntry.GetSnapshotHomeJSON(),
                            ChallengeMapId      = challengeStreamEntry.IsWarLayout() ? 1 : 0
                        }, 9);

                        challengeStreamEntry.SetStarted(true);
                        alliance.UpdateStreamEntry(challengeStreamEntry);

                        return;
                    }
                }
            }

            ChallengeFailedMessage challengeFailedMessageGeneric = new ChallengeFailedMessage();

            challengeFailedMessageGeneric.SetReason(ChallengeFailedMessage.Reason.GENERIC);
            this.m_session.SendPiranhaMessage(challengeFailedMessageGeneric, 1);
        }