Exemplo n.º 1
0
        private static void OnLoadAvatarStreamOfTypeRequestMessageReceived(LoadAvatarStreamOfTypeRequestMessage message)
        {
            LoadAvatarStreamOfTypeResponseMessage loadAvatarStreamOfTypeResponseMessage = new LoadAvatarStreamOfTypeResponseMessage();
            LogicArrayList <AvatarStreamEntry>    streamEntryList = new LogicArrayList <AvatarStreamEntry>(message.StreamIds.Size());

            for (int i = 0; i < message.StreamIds.Size(); i++)
            {
                AvatarStreamEntry entry = StreamManager.GetAvatarStream(message.StreamIds[i]);

                if (entry != null && entry.GetAvatarStreamEntryType() == message.Type)
                {
                    if (message.SenderAvatarId != null && !entry.GetSenderAvatarId().Equals(message.SenderAvatarId))
                    {
                        continue;
                    }

                    streamEntryList.Add(entry);
                }
            }

            loadAvatarStreamOfTypeResponseMessage.Success    = true;
            loadAvatarStreamOfTypeResponseMessage.StreamList = streamEntryList;

            ServerRequestManager.SendResponse(loadAvatarStreamOfTypeResponseMessage, message);
        }
        private static void OnGameCreateAllianceInvitationRequestMessageReceived(GameCreateAllianceInvitationRequestMessage message)
        {
            if (GameAvatarManager.TryGet(message.AccountId, out GameAvatar avatar))
            {
                if (avatar.LogicClientAvatar.IsInAlliance() || avatar.HasServerCommandOfType(LogicCommandType.JOIN_ALLIANCE) || avatar.PendingAllianceJoinResponse)
                {
                    ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage
                    {
                        ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.ALREADY_IN_ALLIANCE
                    }, message);
                    return;
                }

                if (!avatar.LogicClientAvatar.HasAllianceCastle())
                {
                    ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage
                    {
                        ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.NO_CASTLE
                    }, message);
                    return;
                }

                ServerRequestManager.Create(new LoadAvatarStreamOfTypeRequestMessage
                {
                    StreamIds      = avatar.AvatarStreamList,
                    SenderAvatarId = message.Entry.GetSenderAvatarId(),
                    Type           = AvatarStreamEntryType.ALLIANCE_INVITATION
                }, ServerManager.GetDocumentSocket(11, avatar.Id), 5).OnComplete = args =>
                {
                    if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success)
                    {
                        LoadAvatarStreamOfTypeResponseMessage loadAvatarStreamOfTypeResponseMessage = (LoadAvatarStreamOfTypeResponseMessage)args.ResponseMessage;

                        for (int i = 0; i < loadAvatarStreamOfTypeResponseMessage.StreamList.Size(); i++)
                        {
                            AllianceInvitationAvatarStreamEntry allianceInvitationAvatarStreamEntry = (AllianceInvitationAvatarStreamEntry)loadAvatarStreamOfTypeResponseMessage.StreamList[i];

                            if (allianceInvitationAvatarStreamEntry.GetAllianceId().Equals(message.Entry.GetAllianceId()))
                            {
                                ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage
                                {
                                    ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.ALREADY_HAS_AN_INVITE
                                }, message);
                                return;
                            }
                        }

                        if (loadAvatarStreamOfTypeResponseMessage.StreamList.Size() >= 10)
                        {
                            ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage
                            {
                                ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.HAS_TOO_MANY_INVITES
                            }, message);
                        }

                        ServerMessageManager.SendMessage(new CreateAvatarStreamMessage
                        {
                            AccountId = message.AccountId,
                            Entry     = message.Entry
                        }, 9);

                        ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage
                        {
                            Success = true
                        }, message);
                    }
                    else
                    {
                        ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage
                        {
                            ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.GENERIC
                        }, message);
                    }
                };
            }
            else
            {
                ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage
                {
                    ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.GENERIC
                }, message);
            }
        }