Esempio n. 1
0
        public AccountOBJ GetAccountFromDB(string username)
        {
            CHeck();
            AccountOBJ account = null;
            Users      usr     = session.QueryOver <Users>().Where(x => x.UserName == username).List().FirstOrDefault();

            if (usr != null)
            {
                account = new AccountOBJ(usr);

                IList <Characters> chars = session.QueryOver <Characters>().Where(x => x.UserId == account.Id).List();

                account.Skins = new SortedList <uint, CharacterOBJ>();

                for (int c = 0; c < chars.Count; c++)
                {
                    Characters   character = chars[c];
                    CharacterOBJ objchar   = new CharacterOBJ(character);
                    account.Skins.Add(objchar.PlayerId, objchar);
                }

                if (chars.Count == 0)
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        short      skinId = Settings.randomSkins[new Random().Next(Settings.randomSkins.Length)];
                        ConfiModel model  = ConfigManager.GetModel(skinId);
                        if (model != null)
                        {
                            Characters ccc = new Characters(account.Id, skinId)
                            {
                                SkinColorId   = model.SkinColorId,
                                EyeColorId    = model.EyeColorId,
                                HairColorId   = model.HairColorId,
                                ShirtColorId  = model.ShirtColorId,
                                PantsColorId  = model.PantsColorId,
                                BootsColorId  = model.BootsColorId,
                                GlovesColorId = model.GlovesColorId
                            };
                            session.Save(ccc);
                            transaction.Commit();
                        }
                    }
                    chars = session.QueryOver <Characters>().Where(x => x.UserId == account.Id).List();
                    for (int c = 0; c < chars.Count; c++)
                    {
                        Characters   character = chars[c];
                        CharacterOBJ objchar   = new CharacterOBJ(character);

                        account.Skins.Add(objchar.PlayerId, objchar);
                    }
                }

                IList <Actives> actives    = session.QueryOver <Actives>().Where(x => x.UserId == account.Id).List();
                ActivesConfig[] allActives = ConfigManager.GetActives();

                if (allActives.Length != actives.Count)
                {
                    for (int c = 0; c < actives.Count; c++)
                    {
                        Actives    active    = actives[c];
                        ActivesOBJ objactive = new ActivesOBJ(active);
                        account.Actives.Add(objactive.ActiveId, objactive);
                    }

                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        for (int a = 0; a < allActives.Length; a++)
                        {
                            ActivesConfig ac = allActives[a];
                            if (!account.Actives.ContainsKey(ac.ActiveId))
                            {
                                Actives active = new Actives
                                {
                                    UserId    = account.Id,
                                    value     = 0,
                                    ActiveId  = ac.ActiveId,
                                    collected = false
                                };

                                session.Save(active); // <-- this

                                ActivesOBJ objactive = new ActivesOBJ(active);
                                account.Actives.Add(objactive.ActiveId, objactive);
                            }
                        }
                        transaction.Commit();
                    }

                    account.Actives.Clear();
                    actives = session.QueryOver <Actives>().Where(x => x.UserId == account.Id).List();

                    for (int c = 0; c < actives.Count; c++)
                    {
                        Actives    active    = actives[c];
                        ActivesOBJ objactive = new ActivesOBJ(active);
                        account.Actives.Add(objactive.ActiveId, objactive);
                    }
                }
                else
                {
                    for (int c = 0; c < actives.Count; c++)
                    {
                        Actives    active    = actives[c];
                        ActivesOBJ objactive = new ActivesOBJ(active);
                        account.Actives.Add(objactive.ActiveId, objactive);
                    }
                }
            }
            return(account);
        }
        public bool Execute(JHSNetworkMessage netMsg)
        {
            if (DbManager == null)
            {
                DbManager = AccountManager.Instance;
            }

            DeleteCharacter packet = netMsg.ReadMessage <DeleteCharacter>();

            if (packet != null)
            {
                uint       connectionId = netMsg.conn.connectionId;
                AccountOBJ user         = DbManager.GetOnlineByConnectionId(connectionId);
                if (user != null)
                {
                    lock (user)
                    {
                        if (user.Skins.Count <= 1)
                        {
                            netMsg.conn.Send(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterResponse()
                            {
                                STATUS = NOT_DELETE_LAST_CHARACTER
                            });
                            return(true);
                        }
                        CharacterOBJ character = user.GetPlayer(packet.PlayerId);
                        if (character != null)
                        {
                            ConfiModel model = ConfigManager.GetModel(character.SkinId);
                            if (model == null)
                            {
                                netMsg.conn.Send(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterResponse()
                                {
                                    STATUS = ITEM_CONFIG_WRONG
                                });
                                return(true);
                            }
                            uint playerId = character.PlayerId;
                            if (DbService.RemoveEntity(character.GetEntity()) && user.Skins.Remove(playerId))
                            {
                                user.Silver += model.SilverPrice;
                                user.ResetNotification();
                                DbService.SubmitUpdate2Queue(user);
                                netMsg.conn.Send(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterResponse()
                                {
                                    STATUS = SUCCESS, PlayerId = playerId, Gold = (uint)user.Gold, Silver = (uint)user.Silver
                                });
                            }
                            else
                            {
                                netMsg.conn.Send(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterResponse()
                                {
                                    STATUS = PLAYER_NOT_FOUND
                                });
                            }
                        }
                        else
                        {
                            netMsg.conn.Send(NetworkConstants.DELETE_CHARACTER, new DeleteCharacterResponse()
                            {
                                STATUS = PLAYER_NOT_FOUND
                            });
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 3
0
        public bool Execute(JHSNetworkMessage netMsg)
        {
            if (DbManager == null)
            {
                DbManager = AccountManager.Instance;
            }

            BuySkin packet = netMsg.ReadMessage <BuySkin>();

            if (packet != null)
            {
                uint       connectionId = netMsg.conn.connectionId;
                AccountOBJ user         = DbManager.GetOnlineByConnectionId(connectionId);
                if (user != null)
                {
                    ConfiModel model = ConfigManager.GetModel((int)packet.ModelId);
                    if (model == null)
                    {
                        netMsg.conn.Send(NetworkConstants.BUYCHARACTER, new BuySkinResponse()
                        {
                            STATUS = ITEM_CONFIG_WRONG
                        });
                        return(true);
                    }
                    //Silver Buy
                    if (packet.BuyType == 0)
                    {
                        //TO DO CHECK IF CHARACTER ALREADY HAS THE MODEL
                        lock (user)
                        {
                            if (user.Silver < model.SilverPrice)
                            {
                                netMsg.conn.Send(NetworkConstants.BUYCHARACTER, new BuySkinResponse()
                                {
                                    STATUS = NOT_ENOUGH_SILVER
                                });
                                return(true);
                            }
                            Characters ccc = new Characters(user.Id, model.ModelId)
                            {
                                SkinColorId   = model.SkinColorId,
                                EyeColorId    = model.EyeColorId,
                                HairColorId   = model.HairColorId,
                                ShirtColorId  = model.ShirtColorId,
                                PantsColorId  = model.PantsColorId,
                                BootsColorId  = model.BootsColorId,
                                GlovesColorId = model.GlovesColorId
                            };
                            ccc.PlayerId = DbService.SaveEntity(ccc);
                            CharacterOBJ obj = new CharacterOBJ(ccc);
                            user.Skins.Add(obj.PlayerId, obj);
                            user.ResetNotification();
                            user.Silver -= model.SilverPrice;
                            DbService.SubmitUpdate2Queue(user);
                            netMsg.conn.Send(NetworkConstants.BUYCHARACTER, new BuySkinResponse()
                            {
                                STATUS = SUCCESS, Gold = (uint)user.Gold, Silver = (uint)user.Silver, character = obj.GetServerChar()
                            });
                            return(true);
                        }
                    }
                    else // GOLD BUY
                    {
                        //TO DO CHECK IF CHARACTER ALREADY HAS THE MODEL
                        lock (user)
                        {
                            if (user.Gold < model.GoldPrice)
                            {
                                netMsg.conn.Send(NetworkConstants.BUYCHARACTER, new BuySkinResponse()
                                {
                                    STATUS = NOT_ENOUGH_GOLD
                                });
                                return(true);
                            }
                            Characters ccc = new Characters(user.Id, model.ModelId)
                            {
                                SkinColorId   = model.SkinColorId,
                                EyeColorId    = model.EyeColorId,
                                HairColorId   = model.HairColorId,
                                ShirtColorId  = model.ShirtColorId,
                                PantsColorId  = model.PantsColorId,
                                BootsColorId  = model.BootsColorId,
                                GlovesColorId = model.GlovesColorId
                            };
                            ccc.PlayerId = DbService.SaveEntity(ccc);
                            CharacterOBJ obj = new CharacterOBJ(ccc);
                            user.Skins.Add(obj.PlayerId, obj);
                            user.Gold -= model.GoldPrice;
                            DbService.SubmitUpdate2Queue(user);
                            netMsg.conn.Send(NetworkConstants.BUYCHARACTER, new BuySkinResponse()
                            {
                                STATUS = SUCCESS, Gold = (uint)user.Gold, Silver = (uint)user.Silver, character = obj.GetServerChar()
                            });
                            return(true);
                        }
                    }
                }
            }

            return(true);
        }