示例#1
0
        private static void OnAllianceShareReplayMessageReceivedReceived(AllianceShareReplayMessage message)
        {
            if (AllianceManager.TryGet(message.AccountId, out Alliance alliance) && alliance.Members.TryGetValue(message.MemberId, out AllianceMemberEntry memberEntry))
            {
                ServerRequestManager.Create(new LoadAvatarStreamRequestMessage
                {
                    Id = message.ReplayId
                }, ServerManager.GetDocumentSocket(11, message.ReplayId)).OnComplete = args =>
                {
                    if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success)
                    {
                        LoadAvatarStreamResponseMessage responseMessage = (LoadAvatarStreamResponseMessage)args.ResponseMessage;

                        if (responseMessage.Entry.GetAvatarStreamEntryType() == AvatarStreamEntryType.ATTACKER_BATTLE_REPORT ||
                            responseMessage.Entry.GetAvatarStreamEntryType() == AvatarStreamEntryType.DEFENDER_BATTLE_REPORT)
                        {
                            BattleReportStreamEntry battleReportStreamEntry = (BattleReportStreamEntry)responseMessage.Entry;
                            ReplayStreamEntry       replayStreamEntry       = new ReplayStreamEntry();
                            AllianceStreamEntryUtil.SetSenderInfo(replayStreamEntry, memberEntry);

                            replayStreamEntry.SetAttack(responseMessage.Entry.GetAvatarStreamEntryType() == AvatarStreamEntryType.ATTACKER_BATTLE_REPORT);
                            replayStreamEntry.SetBattleLogJSON(battleReportStreamEntry.GetBattleLogJSON());
                            replayStreamEntry.SetMajorVersion(battleReportStreamEntry.GetMajorVersion());
                            replayStreamEntry.SetBuildVersion(battleReportStreamEntry.GetBuildVersion());
                            replayStreamEntry.SetContentVersion(battleReportStreamEntry.GetContentVersion());
                            replayStreamEntry.SetReplayId(battleReportStreamEntry.GetReplayId());
                            replayStreamEntry.SetReplayShardId(battleReportStreamEntry.GetReplayShardId());
                            replayStreamEntry.SetOpponentName(battleReportStreamEntry.GetSenderName());

                            string replayMessage = message.Message;

                            if (replayMessage != null && replayMessage.Length > 128)
                            {
                                replayMessage = replayMessage.Substring(0, 128);
                            }

                            replayStreamEntry.SetMessage(replayMessage);

                            StreamManager.Create(alliance.Id, replayStreamEntry);

                            alliance.AddStreamEntry(replayStreamEntry);

                            AllianceManager.Save(alliance);
                        }
                    }
                };
            }
        }
示例#2
0
        private void OnJoinAllianceUsingInvitationMessageReceived(JoinAllianceUsingInvitationMessage message)
        {
            if (this.CanJoinAlliance())
            {
                ServerRequestManager.Create(new LoadAvatarStreamRequestMessage
                {
                    Id = message.GetAvatarStreamEntryId()
                }, ServerManager.GetDocumentSocket(11, this.m_session.AccountId), 5).OnComplete = args =>
                {
                    if (this.m_session.IsDestructed())
                    {
                        return;
                    }

                    if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success)
                    {
                        LoadAvatarStreamResponseMessage     responseMessage = (LoadAvatarStreamResponseMessage)args.ResponseMessage;
                        AllianceInvitationAvatarStreamEntry allianceInvitationAvatarStreamEntry = (AllianceInvitationAvatarStreamEntry)responseMessage.Entry;
                        LogicLong allianceId = allianceInvitationAvatarStreamEntry.GetAllianceId();
                        ServerRequestManager.Create(new GameJoinAllianceRequestMessage
                        {
                            AccountId      = this.m_session.AccountId,
                            AllianceId     = allianceId,
                            AvatarStreamId = allianceInvitationAvatarStreamEntry.GetId(),
                            Invited        = true
                        }, ServerManager.GetDocumentSocket(9, this.m_session.AccountId)).OnComplete = this.OnGameAllianceJoin;
                    }
                    else
                    {
                        AllianceJoinFailedMessage allianceJoinFailedMessage = new AllianceJoinFailedMessage();
                        allianceJoinFailedMessage.SetReason(AllianceJoinFailedMessage.Reason.ALREADY_IN_ALLIANCE);
                        this.m_session.SendPiranhaMessage(allianceJoinFailedMessage, 1);
                    }
                };
            }
            else
            {
                AllianceJoinFailedMessage allianceJoinFailedMessage = new AllianceJoinFailedMessage();
                allianceJoinFailedMessage.SetReason(AllianceJoinFailedMessage.Reason.ALREADY_IN_ALLIANCE);
                this.m_session.SendPiranhaMessage(allianceJoinFailedMessage, 1);
            }
        }