public void Create()
        {
            var skinTone = Server.Protocol.Voltron.Model.SkinTone.LIGHT;

            switch (View.AppearanceType)
            {
            case Vitaboy.AppearanceType.Medium:
                skinTone = Server.Protocol.Voltron.Model.SkinTone.MEDIUM;
                break;

            case Vitaboy.AppearanceType.Dark:
                skinTone = Server.Protocol.Voltron.Model.SkinTone.DARK;
                break;
            }

            var packet = new RSGZWrapperPDU
            {
                BodyOutfitId = (uint)(View.BodyOutfitId >> 32),
                HeadOutfitId = (uint)(View.HeadOutfitId >> 32),
                Name         = View.Name,
                Description  = View.Description,
                Gender       = View.Gender == Gender.Male ? Server.Protocol.Voltron.Model.Gender.MALE : Server.Protocol.Voltron.Model.Gender.FEMALE,
                SkinTone     = skinTone
            };

            CASRegulator.CreateSim(packet);
        }
예제 #2
0
        /// <summary>
        /// Register a new avatar
        /// </summary>
        /// <param name="session"></param>
        /// <param name="packet"></param>
        public void Handle(IVoltronSession session, RSGZWrapperPDU packet)
        {
            PurchasableOutfit head = null;
            PurchasableOutfit body = null;

            switch (packet.Gender)
            {
            case Protocol.Voltron.Model.Gender.FEMALE:
                head = ValidFemaleOutfits[packet.HeadOutfitId];
                body = ValidFemaleOutfits[packet.BodyOutfitId];
                break;

            case Protocol.Voltron.Model.Gender.MALE:
                head = ValidMaleOutfits[packet.HeadOutfitId];
                body = ValidMaleOutfits[packet.BodyOutfitId];
                break;
            }

            if (head == null)
            {
                session.Write(new CreateASimResponse {
                    Status = CreateASimStatus.FAILED,
                    Reason = CreateASimFailureReason.HEAD_VALIDATION_ERROR
                });
                return;
            }

            if (body == null)
            {
                session.Write(new CreateASimResponse
                {
                    Status = CreateASimStatus.FAILED,
                    Reason = CreateASimFailureReason.BODY_VALIDATION_ERROR
                });
                return;
            }

            if (!NAME_VALIDATION.IsMatch(packet.Name))
            {
                session.Write(new CreateASimResponse
                {
                    Status = CreateASimStatus.FAILED,
                    Reason = CreateASimFailureReason.NAME_VALIDATION_ERROR
                });
                return;
            }

            if (!DESC_VALIDATION.IsMatch(packet.Description))
            {
                session.Write(new CreateASimResponse
                {
                    Status = CreateASimStatus.FAILED,
                    Reason = CreateASimFailureReason.DESC_VALIDATION_ERROR
                });
                return;
            }

            uint newId = 0;

            using (var db = DAFactory.Get)
            {
                var newAvatar = new DbAvatar
                {
                    shard_id    = Context.ShardId,
                    name        = packet.Name,
                    description = packet.Description,
                    date        = Epoch.Now,
                    head        = head.OutfitID,
                    body        = body.OutfitID,
                    skin_tone   = (byte)packet.SkinTone,
                    gender      = packet.Gender == Protocol.Voltron.Model.Gender.FEMALE ? DbAvatarGender.female : DbAvatarGender.male,
                    user_id     = session.UserId,
                    budget      = 0
                };

                if (packet.Gender == Protocol.Voltron.Model.Gender.MALE)
                {
                    newAvatar.body_swimwear  = 0x5470000000D;
                    newAvatar.body_sleepwear = 0x5440000000D;
                }
                else
                {
                    newAvatar.body_swimwear  = 0x620000000D;
                    newAvatar.body_sleepwear = 0x5150000000D;
                }

                var user = db.Users.GetById(session.UserId);
                if ((user?.is_moderator) ?? false)
                {
                    newAvatar.moderation_level = 1;
                }

                try
                {
                    newId = db.Avatars.Create(newAvatar);
                } catch (Exception e)
                {
                    //unique name error or avatar limit exceeded.
                    //todo: special error for avatar limit? exception is thrown from BEFORE INSERT trigger.
                    session.Write(new CreateASimResponse
                    {
                        Status = CreateASimStatus.FAILED,
                        Reason = CreateASimFailureReason.NAME_TAKEN
                    });
                    return;
                }

                //create clothes
                try
                {
                    db.Outfits.Create(new Database.DA.Outfits.DbOutfit {
                        avatar_owner   = newId,
                        asset_id       = newAvatar.body,
                        purchase_price = 0,
                        sale_price     = 0,
                        outfit_type    = (byte)VMPersonSuits.DefaultDaywear,
                        outfit_source  = Database.DA.Outfits.DbOutfitSource.cas
                    });

                    db.Outfits.Create(new Database.DA.Outfits.DbOutfit
                    {
                        avatar_owner   = newId,
                        asset_id       = newAvatar.body_sleepwear,
                        purchase_price = 0,
                        sale_price     = 0,
                        outfit_type    = (byte)VMPersonSuits.DefaultSleepwear,
                        outfit_source  = Database.DA.Outfits.DbOutfitSource.cas
                    });

                    db.Outfits.Create(new Database.DA.Outfits.DbOutfit
                    {
                        avatar_owner   = newId,
                        asset_id       = newAvatar.body_swimwear,
                        purchase_price = 0,
                        sale_price     = 0,
                        outfit_type    = (byte)VMPersonSuits.DefaultSwimwear,
                        outfit_source  = Database.DA.Outfits.DbOutfitSource.cas
                    });
                }
                catch (Exception e) {
                    session.Write(new CreateASimResponse
                    {
                        Status = CreateASimStatus.FAILED,
                        Reason = CreateASimFailureReason.NONE
                    });
                    return;
                }
            }

            ((VoltronSession)session).AvatarId = newId;

            session.Write(new CreateASimResponse {
                Status      = CreateASimStatus.SUCCESS,
                NewAvatarId = newId
            });
            session.Write(new TransmitCreateAvatarNotificationPDU {
            });
        }
예제 #3
0
 public void CreateSim(RSGZWrapperPDU packet)
 {
     this.AsyncProcessMessage(packet);
 }