Esempio n. 1
0
        private static async void OnSearchAlliancesMessageReceived(SearchAlliancesMessage message, ForwardLogicRequestMessage requestMessage)
        {
            if (message.IsJoinableOnly())
            {
                ServerRequestManager.Create(new AvatarRequestMessage
                {
                    AccountId = requestMessage.AccountId
                }, ServerManager.GetDocumentSocket(9, requestMessage.AccountId), 5).OnComplete = async args =>
                {
                    LogicClientAvatar playerAvatar = null;

                    if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success)
                    {
                        playerAvatar = ((AvatarResponseMessage)args.ResponseMessage).LogicClientAvatar;
                    }

                    AllianceListMessage allianceListMessage = new AllianceListMessage();

                    allianceListMessage.SetAlliances(await SearchManager.SearchAlliances(message, playerAvatar));
                    allianceListMessage.SetBookmarkList(new LogicArrayList <LogicLong>());
                    allianceListMessage.SetSearchString(message.GetSearchString());

                    ServerMessageManager.SendMessage(SearchMessageManager.CreateForwardLogicMessage(allianceListMessage, requestMessage.SessionId),
                                                     ServerManager.GetProxySocket(requestMessage.SessionId));
                };
            }
            else
            {
                AllianceListMessage allianceListMessage = new AllianceListMessage();

                allianceListMessage.SetAlliances(await SearchManager.SearchAlliances(message, null));
                allianceListMessage.SetBookmarkList(new LogicArrayList <LogicLong>());
                allianceListMessage.SetSearchString(message.GetSearchString());

                ServerMessageManager.SendMessage(SearchMessageManager.CreateForwardLogicMessage(allianceListMessage, requestMessage.SessionId),
                                                 ServerManager.GetProxySocket(requestMessage.SessionId));
            }
        }
Esempio n. 2
0
        public static async Task <LogicArrayList <AllianceHeaderEntry> > SearchAlliances(SearchAlliancesMessage searchAlliancesMessage, LogicClientAvatar playerAvatar)
        {
            LogicArrayList <AllianceHeaderEntry> allianceList = new LogicArrayList <AllianceHeaderEntry>();
            StringBuilder builder = new StringBuilder();

            builder.Append("SELECT ");
            builder.Append(SearchManager.QUERY_ALLIANCES_LIST_SELECT);
            builder.Append(" FROM `%BUCKET%` WHERE meta().id LIKE '%KEY_PREFIX%%' AND (");

            string searchString = searchAlliancesMessage.GetSearchString();

            if (!string.IsNullOrEmpty(searchString))
            {
                if (searchString.Length >= 16)
                {
                    searchString = searchString.Substring(0, 15);
                }

                if (searchString.StartsWith(HashTagCodeGenerator.CONVERSION_TAG))
                {
                    LogicLong allianceId = HashTagCodeGenerator.m_instance.ToId(searchString.Trim().ToUpperInvariant());

                    if (allianceId != null)
                    {
                        builder.Append(CouchbaseDocument.JSON_ATTRIBUTE_ID_HIGH);
                        builder.Append(" == ");
                        builder.Append(allianceId.GetHigherInt().ToString());
                        builder.Append(" AND ");
                        builder.Append(CouchbaseDocument.JSON_ATTRIBUTE_ID_LOW);
                        builder.Append(" == ");
                        builder.Append(allianceId.GetLowerInt().ToString());
                        builder.Append(" OR ");
                    }
                }

                builder.Append("LOWER(alliance_name) LIKE '%");
                builder.Append(searchString.ToLowerInvariant());
                builder.Append("%' AND ");
            }

            builder.Append("member_count BETWEEN ");
            builder.Append(searchAlliancesMessage.GetMinimumMembers().ToString());
            builder.Append(" AND ");
            builder.Append(searchAlliancesMessage.GetMaximumMembers().ToString());

            if (searchAlliancesMessage.GetWarFrequency() != 0)
            {
                builder.Append(" AND war_freq == ");
                builder.Append(searchAlliancesMessage.GetWarFrequency().ToString());
            }

            if (searchAlliancesMessage.GetOrigin() != null)
            {
                builder.Append(" AND origin == ");
                builder.Append(searchAlliancesMessage.GetOrigin().GetGlobalID().ToString());
            }

            if (searchAlliancesMessage.GetRequiredScore() != 0)
            {
                builder.Append(" AND score >= ");
                builder.Append(searchAlliancesMessage.GetRequiredScore().ToString());
            }

            if (searchAlliancesMessage.GetRequiredDuelScore() != 0)
            {
                builder.Append(" AND duel_score >= ");
                builder.Append(searchAlliancesMessage.GetRequiredDuelScore().ToString());
            }

            if (searchAlliancesMessage.GetMinimumExpLevel() != 0)
            {
                builder.Append(" AND xp_level >= ");
                builder.Append(searchAlliancesMessage.GetMinimumExpLevel().ToString());
            }

            if (searchAlliancesMessage.IsJoinableOnly())
            {
                builder.Append(" AND required_score <= ");
                builder.Append(playerAvatar.GetScore().ToString());
                builder.Append(" AND required_duel_score <= ");
                builder.Append(playerAvatar.GetDuelScore().ToString());
            }

            builder.AppendLine(") ORDER BY score DESC LIMIT 200");

            IQueryResult <JObject> result = await ServerSearch.AllianceDatabase.ExecuteCommand <JObject>(builder.ToString());

            if (result.Success)
            {
                allianceList.EnsureCapacity(result.Rows.Count);
                result.Rows.ForEach(jsonObject => { allianceList.Add(SearchManager.LoadAllianceHeaderEntry(jsonObject)); });
            }

            return(allianceList);
        }