Пример #1
0
        public void HandleRequest(IRequest request)
        {
            var pattern = request.Data.GetOrDefault <string>(k.name);

            if (pattern.Equals(string.Empty) || pattern.Length < 2)
            {
                throw new PerpetuumException(ErrorCodes.SearchStringTooShort);
            }

            pattern = $"%{pattern}%";

            var corporationEids = Db.Query().CommandText("select top (32) eid from corporations where ([name] like @pattern or nick like @pattern) and defaultcorp=0")
                                  .SetParameter("@pattern", pattern)
                                  .Execute()
                                  .Select(r => DataRecordExtensions.GetValue <long>(r, 0))
                                  .ToArray();

            if (corporationEids.Any())
            {
                var result = CorporationData.GetAnyInfoDictionary(corporationEids);
                Message.Builder.FromRequest(request).WithData(result).WrapToResult().Send();
            }
            else
            {
                Message.Builder.FromRequest(request).WithEmpty().Send();
            }
        }
Пример #2
0
        public void HandleRequest(IZoneRequest request)
        {
            var definition = request.Data.GetOrDefault <int>(k.definition);

            const string q = @"SELECT id FROM dbo.decor WHERE zoneid=@zoneId AND definition=@definition";

            var decorIds =
                Db.Query().CommandText(q)
                .SetParameter("@definition", definition)
                .SetParameter("@zoneId", request.Zone.Id)
                .Execute()
                .Select(r => DataRecordExtensions.GetValue <int>(r, 0)).ToArray();

            foreach (var decorId in decorIds)
            {
                try
                {
                    var ec = request.Zone.DecorHandler.DrawDecorEnvironment(decorId);
                    Logger.Info("decorId:" + decorId + " " + ec);
                }
                catch (Exception ex)
                {
                    Logger.Error(decorId + "was the bad decor.");
                    Logger.Exception(ex);
                }
            }

            Message.Builder.FromRequest(request).WithOk().Send();
        }
Пример #3
0
        public void HandleRequest(IZoneRequest request)
        {
            const string q = "select id from dbo.decor where zoneid=@zoneId and locked=0";

            var ids =
                Db.Query().CommandText(q)
                .SetParameter("@zoneId", request.Zone.Id)
                .Execute()
                .Select(r => DataRecordExtensions.GetValue <int>(r, 0)).ToArray();


            foreach (var decorId in ids)
            {
                try
                {
                    var ec = request.Zone.DecorHandler.DrawDecorEnvironment(decorId);
                    Logger.Info("decorId:" + decorId + " " + ec);
                }
                catch (Exception ex)
                {
                    Logger.Error(decorId + "was the bad decor.");
                    Logger.Exception(ex);
                }
            }

            Message.Builder.FromRequest(request).WithOk().Send();
        }
Пример #4
0
 public NewsCategory()
 {
     _newsCategoryInfos = Db.Query().CommandText("select id,category from newscategories").Execute()
                          .ToDictionary("n", r => new Dictionary <string, object>
     {
         { k.ID, DataRecordExtensions.GetValue <int>(r, 0) },
         { k.category, DataRecordExtensions.GetValue <string>(r, 1) }
     });
 }
        private static Dictionary <string, object> LoadExtensionCategories()
        {
            var result = Db.Query().CommandText("select extensioncategoryid,categoryname,hidden from extensioncategories").Execute()
                         .ToDictionary("c", r => new Dictionary <string, object>
            {
                { k.ID, DataRecordExtensions.GetValue <int>(r, 0) },
                { k.name, DataRecordExtensions.GetValue <string>(r, 1) },
                { k.hidden, DataRecordExtensions.GetValue <bool>(r, 2) },
            });

            return(result);
        }
Пример #6
0
        public void HandleRequest(IRequest request)
        {
            var queryStr = "select distinct itemdefinition from marketitems where marketeid=@marketEID and (( formembersof is not null and @fmo=formembersof) or ( formembersof is null ))";

            var corporders = request.Data.GetOrDefault <int>(k.corporationOnly) == 1;

            if (corporders)
            {
                queryStr = "select distinct itemdefinition from marketitems where marketeid=@marketEID and formembersof is not null and @fmo=formembersof";
            }

            var marketEid = request.Data.GetOrDefault <long>(k.eid);

            var character      = request.Session.Character;
            var definitionList = Db.Query().CommandText(queryStr)
                                 .SetParameter("@marketEID", marketEid)
                                 .SetParameter("@fmo", character.CorporationEid)
                                 .Execute()
                                 .Select(e => DataRecordExtensions.GetValue <int>(e, 0)).ToArray();

            //just in case
            if (definitionList.Length == 0)
            {
                Message.Builder.FromRequest(request).WithEmpty().Send();
                return;
            }

            var categoryFlags = new List <long>();

            foreach (var definition in definitionList)
            {
                if (!_entityServices.Defaults.TryGet(definition, out EntityDefault ed))
                {
                    Logger.Error("disabled definition on market: " + definition);
                    continue;
                }

                categoryFlags.Add((long)ed.CategoryFlags);
            }

            //var categoryFlags = (from d in definitionList select (long) EntityDefaultHelper.entityDefaults[d].categoryFlags).Distinct().ToArray();

            var result = new Dictionary <string, object>
            {
                { k.definition, definitionList },
                { k.categoryFlags, categoryFlags.Distinct().ToArray() },
                { k.corporationOnly, corporders },
            };

            Message.Builder.FromRequest(request).WithData(result).Send();
        }
 private static Dictionary <string, object> LoadAggregateInfos()
 {
     return(Db.Query().CommandText("select * from aggregatefields").Execute()
            .ToDictionary("a", record => new Dictionary <string, object>
     {
         { k.ID, DataRecordExtensions.GetValue <int>(record, "id") },
         { k.name, DataRecordExtensions.GetValue <string>(record, "name") },
         { k.formula, DataRecordExtensions.GetValue <int>(record, "formula") },
         { k.measurementUnit, DataRecordExtensions.GetValue <string>(record, "measurementunit") },
         { k.measurementMultiplier, DataRecordExtensions.GetValue <double>(record, "measurementmultiplier") },
         { k.measurementOffset, DataRecordExtensions.GetValue <double>(record, "measurementoffset") },
         { k.category, DataRecordExtensions.GetValue <int>(record, "category") },
         { k.digits, DataRecordExtensions.GetValue <int>(record, "digits") }
     }));
 }
        public void HandleRequest(IRequest request)
        {
            var decorCategoryList = Db.Query().CommandText("select id,categoryname from decorcategories").Execute()
                                    .ToDictionary("d", r => new Dictionary <string, object>
            {
                { k.ID, DataRecordExtensions.GetValue <int>(r, 0) },
                { k.name, DataRecordExtensions.GetValue <string>(r, 1) }
            });

            var result = new Dictionary <string, object> {
                { k.data, decorCategoryList }
            };

            Message.Builder.FromRequest(request).WithData(result).Send();
        }
Пример #9
0
        private Dictionary <string, object> GetExtensionHistory(Character character)
        {
            var records = Db.Query().CommandText("select extensionid,extensionlevel,eventtime,points from accountextensionspent where characterid=@characterID")
                          .SetParameter("@characterID", character.Id)
                          .Execute();

            var counter = 0;

            return(records.Where(e => _extensionReader.GetExtensions().ContainsKey(DataRecordExtensions.GetValue <int>(e, 0)))
                   .Select(e => (object)new Dictionary <string, object>
            {
                { k.extensionID, DataRecordExtensions.GetValue <int>(e, 0) },
                { k.extensionLevel, DataRecordExtensions.GetValue <int>(e, 1) },
                { k.learnedTime, DataRecordExtensions.GetValue <DateTime>(e, 2) },
                { k.points, DataRecordExtensions.GetValue <int>(e, 3) }
            }).ToDictionary(d => "e" + counter++));
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var character = request.Session.Character; //target character or current character

                if (request.Data.TryGetValue(k.characterID, out int characterID))
                {
                    character = Character.Get(characterID);
                }
                var level = request.Data.GetOrDefault(k.level, 9);//target level or default value

                var giveAll = false;
                if (request.Data.TryGetValue(k.extensionID, out int extensionID))
                {
                    _extensionReader.GetExtensions().ContainsKey(extensionID).ThrowIfFalse(ErrorCodes.ItemNotFound);
                }
                else
                {
                    giveAll = true;
                }

                if (giveAll)
                {
                    var extensionz = from e in Db.Query().CommandText("select extensionid from extensions where active=1 and hidden=0").Execute()
                                     select new Extension(DataRecordExtensions.GetValue <int>(e, 0), level);

                    character.SetExtensions(extensionz);
                }
                else
                {
                    character.SetExtension(new Extension(extensionID, level));
                }

                Db.Query().CommandText("delete accountextensionspent where accountid=@accountID")
                .SetParameter("@accountID", request.Session.AccountId)
                .ExecuteNonQuery();

                Message.Builder.FromRequest(request).WithOk().Send();

                scope.Complete();
            }
        }
Пример #11
0
        public void HandleRequest(IRequest request)
        {
            var pollID = Db.Query().CommandText("select min(pollid) from polls where active=1 and pollid not in (select pollid from pollanswers where accountid=@accountID)")
                         .SetParameter("@accountID", request.Session.AccountId)
                         .ExecuteScalar <int>();

            if (pollID == 0)
            {
                Message.Builder.FromRequest(request).WithEmpty().Send();
                return;
            }

            var onePoll = Db.Query().CommandText("select pollid,topic,started from polls where pollid=@pollID")
                          .SetParameter("@pollID", pollID)
                          .ExecuteSingleRow();

            var poll = new Dictionary <string, object>
            {
                { k.ID, onePoll.GetValue <int>(0) },
                { k.topic, onePoll.GetValue <string>(1) },
                { k.started, onePoll.GetValue <DateTime>(2) }
            };

            var choices = Db.Query().CommandText("select choiceid,choicetext from pollchoices where pollid=@pollID")
                          .SetParameter("@pollID", pollID)
                          .Execute()
                          .ToDictionary("c", r => new Dictionary <string, object>
            {
                { k.choiceID, DataRecordExtensions.GetValue <int>(r, 0) },
                { k.choiceText, DataRecordExtensions.GetValue <string>(r, 1) }
            });

            if (choices.Count > 0)
            {
                poll.Add(k.choices, choices);
                Message.Builder.FromRequest(request).WithData(poll).WrapToResult().Send();
            }
            else
            {
                Message.Builder.FromRequest(request).WithEmpty().Send();
            }
        }
Пример #12
0
        public void HandleRequest(IRequest request)
        {
            var character = request.Session.Character;

            var publicContainer = _entityServices.Defaults.GetByName(DefinitionNames.PUBLIC_CONTAINER);
            var lista           = Db.Query().CommandText("itemCount")
                                  .SetParameter("@owner", character.Eid)
                                  .SetParameter("@publicContainerDefinition", publicContainer.Definition)
                                  .Execute()
                                  .ToDictionary("c", r => new Dictionary <string, object>
            {
                { k.eid, DataRecordExtensions.GetValue <long>(r, 0) },
                { k.amount, DataRecordExtensions.GetValue <int>(r, 1) }
            });

            var result = new Dictionary <string, object> {
                { k.data, lista }
            };

            Message.Builder.FromRequest(request).WithData(result).Send();
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var extensionId = request.Data.GetOrDefault <int>(k.ID);
                var fee         = request.Data.GetOrDefault <int>(k.fee);

                Logger.Info("reverting extension:" + extensionId + " fee: " + fee);
                var characterIDs = Db.Query().CommandText("SELECT distinct characterid FROM accountextensionspent WHERE extensionid=@extensionID")
                                   .SetParameter("@extensionID", extensionId)
                                   .Execute()
                                   .Select(r => DataRecordExtensions.GetValue <int>(r, 0)).ToList();

                foreach (var characterId in characterIDs)
                {
                    var res = Db.Query().CommandText("update characters set credit=credit+@fee where characterid=@characterId").SetParameter("@characterId", characterId).SetParameter("@fee", fee)
                              .ExecuteNonQuery();

                    if (res != 1)
                    {
                        Logger.Error("character was not found: " + characterId);
                        continue;
                    }

                    Logger.Info("characterID:" + characterId + " extensionID:" + extensionId + " returned:" + fee);
                }

                //delete skill and EP cost (return ep)
                Db.Query().CommandText("DELETE characterextensions WHERE extensionid=@extensionID; DELETE accountextensionspent WHERE extensionid=@extensionID")
                .SetParameter("@extensionID", extensionId)
                .ExecuteNonQuery();

                Logger.Info("extension reverted. " + extensionId);
                Message.Builder.FromRequest(request).WithOk().Send();

                scope.Complete();
            }
        }
Пример #14
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                const string queryStr = "SELECT characterid,sparkID FROM characters WHERE active=1";

                var dataPairs = Db.Query().CommandText(queryStr).Execute().Select(r => new KeyValuePair <int, int>(r.GetValue <int>(0), DataRecordExtensions.GetValue <int>(r, 1))).ToArray();

                var counter = 0;

                foreach (var keyValuePair in dataPairs)
                {
                    if (counter++ % 5 == 0)
                    {
                        Logger.Info(counter / (double)dataPairs.Length * 100.0 + " progress.");
                    }

                    var character = Character.Get(keyValuePair.Key);
                    var cwSparkId = keyValuePair.Value;

                    var activeSparkId = _sparkHelper.ConvertCharacterWizardSparkIdToSpark(cwSparkId);
                    _sparkHelper.ActivateSpark(character, activeSparkId);
                }

                Message.Builder.FromRequest(request).WithOk().Send();

                scope.Complete();
            }
        }
        public void HandleRequest(IRequest request)
        {
            var primaryActivity   = request.Data.GetOrDefault(k.primaryActivity, -1);
            var primaryzone       = request.Data.GetOrDefault(k.zoneID, -1);
            var primaryBase       = request.Data.GetOrDefault(k.baseEID, (long)-1);
            var orientation       = request.Data.GetOrDefault(k.orientation, -1);
            var lookingFor        = request.Data.GetOrDefault(k.lookingFor, -1);
            var preferredFaction  = request.Data.GetOrDefault(k.preferredFaction, -1);
            var providesInsurance = request.Data.GetOrDefault(k.providesInsurance, -1);
            var timeZone          = request.Data.GetOrDefault(k.timeZone, -1);
            var requiredActivity  = request.Data.GetOrDefault(k.requiredActivity, -1);
            var communication     = request.Data.GetOrDefault(k.communication, -1);
            var services          = request.Data.GetOrDefault(k.services, -1);


            var clauseList = new List <string>();
            var query      = Db.Query();

            var searchString = "SELECT corporationeid FROM yellowpages WHERE ";

            if (primaryActivity > 0)
            {
                clauseList.Add("(primaryactivity & @primaryactivity) > 0 ");
                query.SetParameter("@primaryactivity", primaryActivity);
            }

            if (primaryzone >= 0)
            {
                clauseList.Add("zoneid = @primaryzone ");
                query.SetParameter("@primaryzone", primaryzone);
            }

            if (primaryBase > 0)
            {
                clauseList.Add("baseeid = @primarybase ");
                query.SetParameter("@primarybase", primaryBase);
            }

            if (orientation > 0)
            {
                clauseList.Add("(orientation & @orientation) > 0 ");
                query.SetParameter("@orientation", orientation);
            }

            if (lookingFor > 0)
            {
                clauseList.Add("(lookingfor & @lookingfor) > 0 ");
                query.SetParameter("@lookingfor", lookingFor);
            }

            if (preferredFaction > 0)
            {
                clauseList.Add("preferredfaction = @preferredfaction ");
                query.SetParameter("@preferredfaction", preferredFaction);
            }

            if (providesInsurance > 0)
            {
                clauseList.Add("(providesinsurance & @providesinsurance) > 0 ");
                query.SetParameter("@providesinsurance", providesInsurance);
            }

            if (timeZone > 0)
            {
                clauseList.Add("(timezone & @timezone) > 0 ");
                query.SetParameter("@timezone", timeZone);
            }

            if (requiredActivity > 0)
            {
                clauseList.Add("requiredactivity <= @requiredactivity ");
                query.SetParameter("@requiredactivity", requiredActivity);
            }

            if (communication > 0)
            {
                clauseList.Add("(communication & @communication) > 0 ");
                query.SetParameter("@communication", communication);
            }

            if (services > 0)
            {
                clauseList.Add("(services & @services) > 0");
                query.SetParameter("@services", services);
            }


            long[] corpEids;

            if (clauseList.Count == 0)
            {
                //all corps
                corpEids = query.CommandText("select corporationeid from yellowpages").Execute()
                           .Select(r => DataRecordExtensions.GetValue <long>(r, 0))
                           .ToArray();
            }
            else
            {
                searchString += clauseList.ArrayToString("AND ");

                query.CommandText(searchString);

                corpEids = query.Execute()
                           .Select(r => DataRecordExtensions.GetValue <long>(r, 0))
                           .ToArray();
            }

            if (corpEids.IsNullOrEmpty())
            {
                Message.Builder.FromRequest(request).WithEmpty().Send();
                return;
            }

            var result = new Dictionary <string, object>
            {
                { k.eid, corpEids }
            };

            Message.Builder.FromRequest(request).WithData(result).Send();
        }