Exemple #1
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();
            }
        }
Exemple #2
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var nick     = request.Data.GetOrDefault <string>(k.nick).Trim();
                var avatar   = request.Data.GetOrDefault <Dictionary <string, object> >(k.avatar);
                var raceID   = request.Data.GetOrDefault <int>(k.raceID);
                var majorID  = request.Data.GetOrDefault <int>(k.majorID);
                var schoolID = request.Data.GetOrDefault <int>(k.schoolID);
                var sparkID  = request.Data.GetOrDefault <int>(k.sparkID);

                var account = _accountManager.Repository.Get(request.Session.AccountId);
                if (account == null)
                {
                    throw new PerpetuumException(ErrorCodes.AccountNotFound);
                }

                Character.CheckNickAndThrowIfFailed(nick, request.Session.AccessLevel, account);

                //only 3 characters per account is allowed
                var activeCharactersCount = _accountManager.GetActiveCharactersCount(account);
                if (activeCharactersCount >= 3)
                {
                    throw new PerpetuumException(ErrorCodes.MaximumAmountOfCharactersReached);
                }

                if (account.FirstCharacterDate == null)
                {
                    account.FirstCharacterDate = DateTime.Now;
                    _accountManager.Repository.Update(account);
                }

                var character = CreateNewCharacter();
                character.AccountId = account.Id;
                character.Nick      = nick;
                character.Avatar    = GenxyString.FromDictionary(avatar);
                character.IsDocked  = true;

                DockingBase        dockingBase;
                DefaultCorporation corporation;

                if (schoolID > 0)
                {
                    if (majorID == 0 || raceID == 0 || sparkID == 0)
                    {
                        throw new PerpetuumException(ErrorCodes.WTFErrorMedicalAttentionSuggested);
                    }

                    corporation = DefaultCorporation.GetBySchool(raceID, schoolID) ?? throw new PerpetuumException(ErrorCodes.CorporationNotExists);
                    dockingBase = corporation.GetDockingBase();
                    dockingBase.CreateStarterRobotForCharacter(character, true);

                    character.MajorId  = majorID;
                    character.RaceId   = raceID;
                    character.SchoolId = schoolID;
                    character.SparkId  = sparkID;
                    character.AddToWallet(TransactionType.CharacterCreate, 20000);

                    var extensions = character.GetDefaultExtensions();
                    character.SetExtensions(extensions);

                    var sparkToActivate = _sparkHelper.ConvertCharacterWizardSparkIdToSpark(sparkID);
                    _sparkHelper.ActivateSpark(character, sparkToActivate);
                }
                else
                {
                    // training
                    dockingBase = _dockingBaseHelper.GetTrainingDockingBase();
                    corporation = ((TrainingDockingBase)dockingBase).GetTrainingCorporation();
                    character.SetAllExtensionLevel(5);
                    dockingBase.CreateStarterRobotForCharacter(character);
                    character.AddToWallet(TransactionType.CharacterCreate, 10000000);
                }

                character.CurrentDockingBaseEid = dockingBase.Eid;
                character.DefaultCorporationEid = corporation.Eid;

                //add to default corp, only in sql
                corporation.AddNewCharacter(character);

                _accountManager.PackageGenerateAll(account);

                Transaction.Current.OnCommited(() =>
                {
                    _channelManager.JoinChannel(corporation.ChannelName, character);
                    Message.Builder.FromRequest(request).SetData(k.characterID, character.Id).Send();
                });

                scope.Complete();
            }
        }