Example #1
0
        /// <summary>
        /// Checks if this character name is valid for a new character
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        internal static bool CheckCharacterName(string name)
        {
            bool valid = true;

            // Check for invalid characters
            if (name.IndexOfAny(Settings.ForbiddenCharacters) >= 0)
                return false;

            using (DBManager dbManager = new DBManager(Databases.User))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(1))
                {
                    dbManager.CreateInParameter(dbCmd, "name", System.Data.DbType.String, name);
                    dbManager.CreateInParameter(dbCmd, "now", System.Data.DbType.DateTime, DateTime.UtcNow);
                    try
                    {
                        dbCmd.Connection.Open();
                        using (DbDataReader reader = dbCmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                valid = false;
                            }
                        }
                    }
                    // When an error occurs, say that name exists to block creation
                    catch (Exception ex) { ConsoleUtils.ShowError(ex.Message); valid = false; }
                    finally { dbCmd.Connection.Close(); }
                }
            }

            return valid;
        }
Example #2
0
        /// <summary>
        /// Creates a new Character to this account
        /// </summary>
        /// <param name="player"></param>
        /// <param name="charInfo"></param>
        /// <returns></returns>
        internal static bool Create(Player player, Network.Packets.LobbyCharacterInfo charInfo)
        {
            // Ensures the name is available
            if (!CheckCharacterName(charInfo.Name))
                return false;

            lock (CreateLock)
            {
                bool result = true;
                using (DBManager dbManager = new DBManager(Databases.User))
                {
                    using (DbCommand dbCmd = dbManager.CreateCommand(2))
                    {
                        int charId;
                        short job = 0;
                        int startWeapon = 0;
                        int startClothes = 0;
                        int startBag = 490001;
                        Position startPos = new Position();

                        switch (charInfo.ModelInfo.Race)
                        {
                            case 3: // Gaia
                                job = 100;
                                startPos.X = 164474;
                                startPos.Y = 52932;

                                startWeapon = 112100; //Trainee's Small Axe
                                if (charInfo.ModelInfo.WearInfo[2] == 601)
                                    startClothes = 220100;
                                else
                                    startClothes = 220109;
                                break;

                            case 4: // Deva
                                job = 200;
                                startPos.X = 164335;
                                startPos.Y = 49510;

                                startWeapon = 106100; // Beginner's Mace
                                if (charInfo.ModelInfo.WearInfo[2] == 601)
                                    startClothes = 240100;
                                else
                                    startClothes = 240109;
                                break;

                            case 5: // Asura
                                job = 300;
                                startPos.X = 168356;
                                startPos.Y = 55399;

                                startWeapon = 103100; // Beginner's Dirk
                                if (charInfo.ModelInfo.WearInfo[2] == 601)
                                    startClothes = 230100;
                                else
                                    startClothes = 230109;
                                break;
                        }

                        dbManager.CreateInParameter(dbCmd, "accId", System.Data.DbType.Int32, player.AccountId);
                        dbManager.CreateInParameter(dbCmd, "name", System.Data.DbType.String, charInfo.Name);
                        dbManager.CreateInParameter(dbCmd, "race", System.Data.DbType.Byte, (byte)charInfo.ModelInfo.Race);
                        dbManager.CreateInParameter(dbCmd, "sex", System.Data.DbType.Int32, charInfo.ModelInfo.Sex);
                        dbManager.CreateInParameter(dbCmd, "job", System.Data.DbType.Int16, job);
                        dbManager.CreateInParameter(dbCmd, "level", System.Data.DbType.Int32, 1);
                        dbManager.CreateInParameter(dbCmd, "x", System.Data.DbType.Single, startPos.X);
                        dbManager.CreateInParameter(dbCmd, "y", System.Data.DbType.Single, startPos.Y);
                        dbManager.CreateInParameter(dbCmd, "textureId", System.Data.DbType.Int32, charInfo.ModelInfo.TextureId);
                        dbManager.CreateInParameter(dbCmd, "hairId", System.Data.DbType.Int32, charInfo.ModelInfo.ModelId[0]);
                        dbManager.CreateInParameter(dbCmd, "faceId", System.Data.DbType.Int32, charInfo.ModelInfo.ModelId[1]);
                        dbManager.CreateInParameter(dbCmd, "bodyId", System.Data.DbType.Int32, charInfo.ModelInfo.ModelId[2]);
                        dbManager.CreateInParameter(dbCmd, "handsId", System.Data.DbType.Int32, charInfo.ModelInfo.ModelId[3]);
                        dbManager.CreateInParameter(dbCmd, "feetId", System.Data.DbType.Int32, charInfo.ModelInfo.ModelId[4]);
                        dbManager.CreateInParameter(dbCmd, "skinColor", System.Data.DbType.UInt32, charInfo.SkinColor);

                        try
                        {
                            dbCmd.Connection.Open();
                            charId = Convert.ToInt32(dbCmd.ExecuteScalar());

                            Inventory.InsertItem(charId, startWeapon, true);
                            Inventory.InsertItem(charId, startClothes, true);
                            Inventory.InsertItem(charId, startBag, true);
                        }
                        catch (Exception ex) { ConsoleUtils.ShowError(ex.Message); result = false; }
                        finally { dbCmd.Connection.Close(); }
                    }
                }
                return result;
            }
        }
Example #3
0
        /// <summary>
        /// Loads character data into player
        /// and sends to client
        /// </summary>
        /// <param name="player"></param>
        /// <param name="name"></param>
        /// <param name="race"></param>
        internal static void Login(Player player, string name, byte race)
        {
            using (DBManager dbManager = new DBManager(Databases.User))
            {
                #region Character Info load
                using (DbCommand dbCmd = dbManager.CreateCommand(5))
                {
                    dbManager.CreateInParameter(dbCmd, "accId", System.Data.DbType.String, player.AccountId);
                    dbManager.CreateInParameter(dbCmd, "now", System.Data.DbType.DateTime, DateTime.UtcNow);
                    dbManager.CreateInParameter(dbCmd, "name", System.Data.DbType.String, name);

                    int off = 0;

                    try
                    {
                        dbCmd.Connection.Open();

                        using (DbDataReader reader = dbCmd.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                player.CharacterId = (int)reader[off++]; // 0
                                off++; // AccountId // 1
                                player.Name = (string)reader[off++]; // 3
                                player.PartyId = (int)reader[off++]; // 4
                                player.GuildId = (int)reader[off++]; // 5
                                off++; // PrevGuildId // 6
                                // 7~10
                                player.Position = new Position((int)reader[off++], (int)reader[off++], (int)reader[off++], (byte)reader[off++]);
                                player.Race = (byte)reader[off++]; // 11
                                player.Sex = (int)reader[off++]; // 12
                                player.Level = (int)reader[off++]; // 13
                                player.MaxReachedLevel = (int)reader[off++]; // 14
                                player.Exp = (long)reader[off++]; // 15
                                player.LastDecreasedExp = (long)reader[off++]; // 16
                                player.Hp = (int)reader[off++]; // 17
                                player.Mp = (short)(int)reader[off++]; // 18 // TODO :FIX
                                player.Stamina = (int)reader[off++]; // 19
                                player.Havoc = (int)reader[off++]; // 20
                                player.Job = (short)reader[off++]; // 21
                                player.JobDepth = (byte)reader[off++]; // 22
                                player.JobLevel = (int)reader[off++]; // 23
                                player.Jp = (int)reader[off++]; // 24
                                player.TotalJp = (int)reader[off++]; // 25
                                for (int i = 0; i < 3; i++)
                                { // Previous Jobs
                                    player.PrevJobs[i].Id = (int)reader[off++]; // 26, 28, 30
                                    player.PrevJobs[i].Level = (int)reader[off++]; // 27, 29, 31
                                }
                                player.ImmoralPoints = (decimal)reader[off++]; // 32
                                player.Cha = (int)reader[off++]; // 33
                                player.Pkc = (int)reader[off++]; // 34
                                player.Dkc = (int)reader[off++]; // 35
                                player.Huntaholic.Points = (int)reader[off++]; // 36
                                player.Huntaholic.EnterCount = (int)reader[off++]; // 37
                                player.Gold = (long)reader[off++]; // 38
                                player.Chaos = (int)reader[off++]; // 39
                                player.SkinColor = (uint)reader[off++]; // 40
                                player.HairId = (int)reader[off++]; // 41
                                player.FaceId = (int)reader[off++]; // 42
                                player.BodyId = (int)reader[off++]; // 43
                                player.HandsId = (int)reader[off++]; // 44
                                player.FeetId = (int)reader[off++]; // 45
                                player.TextureId = (int)reader[off++]; // 46
                                for (int i = 0; i < 6; i++)
                                    player.Belt[i].Id = (long)reader[off++]; // 47, 48, 49, 50, 51, 52
                                for (int i = 0; i < 6; i++)
                                    player.Summon[i].Id = (int)reader[off++]; // 53, 54, 55, 56, 57, 58
                                player.MainSummon = (int)reader[off++]; // 59
                                player.SubSummon = (int)reader[off++]; // 60
                                player.RemainSummonTime = (int)reader[off++]; // 61
                                player.Pet = (int)reader[off++]; // 62
                                off++; // Create Date // 63
                                off++; // Delete Date // 64
                                off++; // Login Time // 65
                                off++; // Login count // 66
                                off++; // Logout Time // 67
                                off++; // Play Time // 68
                                player.ChatBlockTime = (int)reader[off++]; // 69
                                player.AdvChatCount = (int)reader[off++]; // 70
                                off++; // NameChanged // 71
                                off++; // Auto User // 72
                                player.GuildBlockTime = (int)reader[off++]; // 73
                                player.PkMode = (byte)reader[off++]; // 74
                                off++; // Otp Value // 75
                                off++; // Otp Date // 76
                                player.ClientInfo = (string)reader[off++]; // 77
                            }
                        }
                    }
                    catch (Exception ex) { ConsoleUtils.ShowError(ex.Message + " (Offset: " + off + ")"); }
                    finally { dbCmd.Connection.Close(); }
                }

                #endregion

                #region Update login_time
                using (DbCommand dbCmd = dbManager.CreateCommand(7))
                {
                    dbManager.CreateInParameter(dbCmd, "cid", System.Data.DbType.Int32, player.CharacterId);
                    try
                    {
                        dbCmd.Connection.Open();
                        dbCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex) { ConsoleUtils.ShowError("Failed to Update LoginTime. Error {0}", ex.Message); }
                    finally { dbCmd.Connection.Close(); }
                }
                #endregion

                player.Stats.Load(player);
                ClientPackets.Instance.StatInfo(player, player.Stats, player.Attributes, false);
                ClientPackets.Instance.StatInfo(player, player.BonusStats, player.BonusAttributes, true);

                //ClientPackets.send_Login_pre1(player);

                // Load Inventory
                Inventory.Load(player);

                //ClientPackets.send_Login_pre1(player);

                ClientPackets.send_Login_pre2(player);

                ClientPackets.Instance.LoginResult(player);

                ClientPackets.Instance.StatInfo(player, player.Stats, player.Attributes, false);
                ClientPackets.Instance.StatInfo(player, player.BonusStats, player.BonusAttributes, true);

                ClientPackets.Instance.InventoryList(player, player.InventoryHandles);
                ClientPackets.Instance.EquipSummon(player, player.Summon, false);

                ClientPackets.Instance.WearInfo(player, player.WearInfo);
                ClientPackets.Instance.GoldUpdate(player, player.Gold, player.Chaos);
                ClientPackets.Instance.Property(player, "chaos", player.Chaos, true);
                ClientPackets.Instance.LevelUpdate(player, player.Level, player.JobLevel);
                ClientPackets.Instance.ExpUpdate(player, player.Exp, player.Jp);

                ClientPackets.Instance.Property(player, "job", player.Job, true);
                ClientPackets.Instance.Property(player, "job_level", player.JobLevel, true);
                ClientPackets.Instance.Property(player, "job_0", player.PrevJobs[0].Id, true);
                ClientPackets.Instance.Property(player, "jlv_0", player.PrevJobs[0].Level, true);
                ClientPackets.Instance.Property(player, "job_1", player.PrevJobs[1].Id, true);
                ClientPackets.Instance.Property(player, "jlv_1", player.PrevJobs[1].Level, true);
                ClientPackets.Instance.Property(player, "job_2", player.PrevJobs[2].Id, true);
                ClientPackets.Instance.Property(player, "jlv_2", player.PrevJobs[2].Level, true);

                ClientPackets.Instance.BeltSlotInfo(player, player.Belt);

                ClientPackets.send_Login_pre3(player);

                ClientPackets.Instance.Property(player, "huntaholic_ent", player.Huntaholic.EnterCount, true);
                ClientPackets.Instance.Property(player, "dk_count", player.Dkc, true);
                ClientPackets.Instance.Property(player, "pk_count", player.Pkc, true);
                ClientPackets.Instance.Property(player, "immoral", player.ImmoralPoints, true);
                ClientPackets.Instance.Property(player, "stamina", player.Stamina, true);
                ClientPackets.Instance.Property(player, "max_stamina", player.MaxStamina, true);
                ClientPackets.Instance.Property(player, "channel", player.Cha, true);

                ClientPackets.Instance.StatusChange(player, player.Handle, 0);

                ClientPackets.Instance.QuestList(player); // TODO : Incomplete packet

                ClientPackets.Instance.Chat(player, "@FRIEND", 0x8C, "FLIST|");
                ClientPackets.Instance.Chat(player, "@FRIEND", 0x8C, "DLIST|");

                // TODO : what is this used for?
                ClientPackets.Instance.Property(player, "playtime", 0, true);
                ClientPackets.Instance.Property(player, "playtime_limit1", 0, true);
                ClientPackets.Instance.Property(player, "playtime_limit2", 0, true);

                // TODO : Get new location by position
                ClientPackets.Instance.ChangeLocation(player, 0, 100302);
                // TODO : Get proper weather info and region
                ClientPackets.Instance.WeatherInfo(player, 100302, 1);

                ClientPackets.send_Login_pre4(player);

                ClientPackets.Instance.Property(player, "client_info", player.ClientInfo, false);
                ClientPackets.Instance.Property(player, "stamina_regen", player.StaminaRegen, true);
            }

            // TODO : PlaceHolder Data, must be replaced with real one
            //ClientPackets.send_Login(player);
        }
Example #4
0
        /// <summary>
        /// Deletes a character from this account
        /// </summary>
        /// <param name="player"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        internal static bool Delete(Player player, string name)
        {
            bool result = true;

            using (DBManager dbManager = new DBManager(Databases.User))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand((Settings.KeepDeletedCharacters ? 3 : 4)))
                {
                    if (Settings.KeepDeletedCharacters)
                        dbManager.CreateInParameter(dbCmd, "now", System.Data.DbType.DateTime, DateTime.UtcNow);
                    dbManager.CreateInParameter(dbCmd, "accId", System.Data.DbType.Int32, player.AccountId);
                    dbManager.CreateInParameter(dbCmd, "name", System.Data.DbType.String, name);

                    try
                    {
                        dbCmd.Connection.Open();
                        dbCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex) { ConsoleUtils.ShowError(ex.Message); result = false; }
                    finally { dbCmd.Connection.Close(); }
                }
            }

            return result;
        }
Example #5
0
        /// <summary>
        /// Retrieves the character list
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        internal static void GetCharacterList(Player player)
        {
            List<Network.Packets.LobbyCharacterInfo> charList = new List<Network.Packets.LobbyCharacterInfo>();

            ushort lastLoginIndex = 0;

            using (DBManager dbManager = new DBManager(Databases.User))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(0))
                {
                    dbManager.CreateInParameter(dbCmd, "accId", System.Data.DbType.String, player.AccountId);
                    dbManager.CreateInParameter(dbCmd, "now", System.Data.DbType.DateTime, DateTime.UtcNow);
                    try
                    {
                        dbCmd.Connection.Open();

                        using (DbDataReader reader = dbCmd.ExecuteReader())
                        {
                            ushort count = 0;
                            DateTime lastLoginTime = new DateTime(0);

                            while (reader.Read())
                            {
                                // Reads the character data
                                Network.Packets.LobbyCharacterInfo chara = new Network.Packets.LobbyCharacterInfo();
                                int charId = (int)reader[0];
                                chara.Name = (string)reader[2];
                                chara.ModelInfo.Race = (byte)reader[10];
                                chara.ModelInfo.Sex = (int)reader[11];
                                chara.ModelInfo.TextureId = (int)reader[45];
                                for (int i = 0; i < 5; i++)
                                    chara.ModelInfo.ModelId[i] = (int)reader[40 + i];

                                using (DBManager dbManager2 = new DBManager(Databases.User))
                                {
                                    using (DbCommand dbCmd2 = dbManager2.CreateCommand(6))
                                    {
                                        dbManager2.CreateInParameter(dbCmd2, "charId", System.Data.DbType.Int32, charId);

                                        try
                                        {
                                            dbCmd2.Connection.Open();

                                            using (DbDataReader reader2 = dbCmd2.ExecuteReader())
                                            {
                                                while (reader2.Read())
                                                {
                                                    chara.ModelInfo.WearInfo[(short)reader2[0]] = (int)reader2[1];
                                                    chara.WearItemEnhanceInfo[(short)reader2[0]] = (int)reader2[2];
                                                    chara.WearItemLevelInfo[(short)reader2[0]] = (int)reader2[3];
                                                    chara.WearItemElementalType[(short)reader2[0]] = (byte)(sbyte)reader2[4];
                                                }
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            ConsoleUtils.ShowError("Failed to load character inventory. (Error: {0})", e.Message);
                                        }
                                        finally
                                        {
                                            dbCmd2.Connection.Close();
                                        }
                                    }
                                }
                                chara.Level = (int)reader[12];
                                chara.Job = (short)reader[20];
                                chara.JobLevel = (int)reader[22];
                                // TODO : chara.ExpPercentage = (int)
                                chara.Hp = (int)reader[16];
                                chara.Mp = (int)reader[17];
                                chara.Permission = player.Permission;
                                chara.IsBanned = false;
                                chara.SkinColor = (uint)reader[39];
                                chara.CreateTime = ((DateTime)reader[62]).ToString("yyyy/MM/dd");
                                chara.DeleteTime = "9999/12/31";
                                DateTime loginTime = (DateTime)reader[64];
                                if (loginTime > lastLoginTime)
                                {
                                    lastLoginTime = loginTime;
                                    lastLoginIndex = count;
                                }

                                // Adds data to char List
                                charList.Add(chara);

                                count++;
                            }
                        }
                    }
                    catch (Exception ex) { ConsoleUtils.ShowError(ex.Message); }
                    finally { dbCmd.Connection.Close(); }
                }
            }

            ClientPackets.Instance.CharacterList(player, charList.ToArray(), lastLoginIndex);
        }
Example #6
0
        internal static void InsertItem(int charId, int itemCode, bool equip)
        {
            DB_Item item = Arcadia.ItemResource[itemCode];
            using (DBManager dbManager = new DBManager(Databases.User))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(21))
                {
                    dbManager.CreateInParameter(dbCmd, "owner_id", System.Data.DbType.Int64, charId);
                    dbManager.CreateInParameter(dbCmd, "idx", System.Data.DbType.Int32, 0);
                    dbManager.CreateInParameter(dbCmd, "code", System.Data.DbType.Int32, itemCode);
                    dbManager.CreateInParameter(dbCmd, "cnt", System.Data.DbType.Int64, 1);
                    dbManager.CreateInParameter(dbCmd, "level", System.Data.DbType.Int32, item.level);
                    dbManager.CreateInParameter(dbCmd, "enhance", System.Data.DbType.Int32, item.enhance);
                    dbManager.CreateInParameter(dbCmd, "durability", System.Data.DbType.Int32, item.ethereal_durability);
                    dbManager.CreateInParameter(dbCmd, "endurance", System.Data.DbType.Int32, item.endurance);
                    dbManager.CreateInParameter(dbCmd, "flag", System.Data.DbType.Int32, 0);
                    dbManager.CreateInParameter(dbCmd, "gcode", System.Data.DbType.Int32, 0);
                    dbManager.CreateInParameter(dbCmd, "wear_info", System.Data.DbType.Int32, (equip ? item.wear_type : -1));
                    dbManager.CreateInParameter(dbCmd, "socket_0", System.Data.DbType.Int32, 0);
                    dbManager.CreateInParameter(dbCmd, "socket_1", System.Data.DbType.Int32, 0);
                    dbManager.CreateInParameter(dbCmd, "socket_2", System.Data.DbType.Int32, 0);
                    dbManager.CreateInParameter(dbCmd, "socket_3", System.Data.DbType.Int32, 0);
                    dbManager.CreateInParameter(dbCmd, "remain_time", System.Data.DbType.Int32, item.available_period);
                    dbManager.CreateInParameter(dbCmd, "elemental_effect_type", System.Data.DbType.Int32, 0);
                    dbManager.CreateInParameter(dbCmd, "elemental_effect_expire_time", System.Data.DbType.DateTime, new DateTime(0));
                    dbManager.CreateInParameter(dbCmd, "elemental_effect_attack_point", System.Data.DbType.Int32, 0);
                    dbManager.CreateInParameter(dbCmd, "elemental_effect_magic_point", System.Data.DbType.Int32, 0);
                    dbManager.CreateInParameter(dbCmd, "create_time", System.Data.DbType.DateTime, DateTime.UtcNow);

                    try
                    {
                        dbCmd.Connection.Open();
                        dbCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex) { ConsoleUtils.ShowError(ex.Message); }
                    finally { dbCmd.Connection.Close(); }
                }
            }
        }
Example #7
0
        internal static void Load(Player player)
        {
            using (DBManager dbManager = new DBManager(Databases.User))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(20))
                {
                    dbManager.CreateInParameter(dbCmd, "charId", System.Data.DbType.Int64, player.CharacterId);

                    #region Character Inventory load

                    try
                    {
                        dbCmd.Connection.Open();

                        using (DbDataReader reader = dbCmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                int off = 0;

                                Item item = new Item((long)reader[off++]);
                                off += 6;
                                item.Code = (int)reader[off++];
                                item.Count = (long)reader[off++];
                                item.Level = (int)reader[off++];
                                item.Enhance = (int)reader[off++];
                                item.Durability = (int)reader[off++];
                                item.Endurance = (uint)(int)reader[off++];
                                item.Flag = (int)reader[off++];
                                item.GCode = (int)reader[off++];
                                item.WearInfo = (Wear)reader[off++];
                                item.Socket[0] = (int)reader[off++];
                                item.Socket[1] = (int)reader[off++];
                                item.Socket[2] = (int)reader[off++];
                                item.Socket[3] = (int)reader[off++];
                                item.RemainTime = (int)reader[off++];
                                // TODO : Elemental data

                                if (item.WearInfo >= 0)
                                    Equip(player, item, false);

                                player.Inventory.Add(item.Handle, item);
                                player.InventoryHandles.Add(item.Handle);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ConsoleUtils.ShowError("Failed to load inventory. Error: {0}", e.Message);
                    }

                    #endregion
                }
            }
        }
Example #8
0
        internal static void LoadMonster()
        {
            MonsterResource = new Dictionary<int, DB_Monster>();

            using (DBManager dbManager = new DBManager(Databases.Game))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(11))
                {
                    try
                    {
                        dbManager.CreateInParameter(dbCmd, "localflag", System.Data.DbType.Int32, Settings.LocalFlag);
                        dbCmd.Connection.Open();

                        using (DbDataReader dbReader = dbCmd.ExecuteReader())
                        {
                            while (dbReader.Read())
                            {
                                int off = 0;
                                int id = (int)dbReader[off++];
                                DB_Monster monster = new DB_Monster
                                {
                                    monster_group = (int)dbReader[off++],
                                    name_id = (int)dbReader[off++],
                                    location_id = (int)dbReader[off++],
                                    model = (string)dbReader[off++],
                                    motion_file_id = (int)dbReader[off++],
                                    transform_level = (int)dbReader[off++],
                                    walk_type = (byte)dbReader[off++],
                                    slant_type = (byte)dbReader[off++],
                                    size = (decimal)dbReader[off++],
                                    scale = (decimal)dbReader[off++],
                                    target_fx_size = (decimal)dbReader[off++],
                                    camera_x = (int)dbReader[off++],
                                    camera_y = (int)dbReader[off++],
                                    camera_z = (int)dbReader[off++],
                                    target_x = (decimal)dbReader[off++],
                                    target_y = (decimal)dbReader[off++],
                                    target_z = (decimal)dbReader[off++],
                                    level = (int)dbReader[off++],
                                    grp = (int)dbReader[off++],
                                    magic_type = (int)dbReader[off++],
                                    race = (int)dbReader[off++],
                                    visible_range = (int)dbReader[off++],
                                    chase_range = (int)dbReader[off++],
                                    f_first_attack = (byte)dbReader[off++],
                                    f_group_first_attack = (byte)dbReader[off++],
                                    f_response_casting = (byte)dbReader[off++],
                                    f_response_race = (byte)dbReader[off++],
                                    f_response_battle = (byte)dbReader[off++],
                                    monster_type = (byte)dbReader[off++],
                                    stat_id = (int)dbReader[off++],
                                    fight_type = (int)dbReader[off++],
                                    monster_skill_link_id = (int)dbReader[off++],
                                    material = (int)dbReader[off++],
                                    weapon_type = (int)dbReader[off++],
                                    attack_motion_speed = (int)dbReader[off++],
                                    ability = (int)dbReader[off++],
                                    standard_walk_speed = (int)dbReader[off++],
                                    standard_run_speed = (int)dbReader[off++],
                                    walk_speed = (int)dbReader[off++],
                                    run_speed = (int)dbReader[off++],
                                    attack_range = (decimal)dbReader[off++],
                                    hidesense_range = (decimal)dbReader[off++],
                                    hp = (int)dbReader[off++],
                                    mp = (int)dbReader[off++],
                                    attack_point = (int)dbReader[off++],
                                    magic_point = (int)dbReader[off++],
                                    defence = (int)dbReader[off++],
                                    magic_defence = (int)dbReader[off++],
                                    attack_speed = (int)dbReader[off++],
                                    magic_speed = (int)dbReader[off++],
                                    accuracy = (int)dbReader[off++],
                                    avoid = (int)dbReader[off++],
                                    magic_accuracy = (int)dbReader[off++],
                                    magic_avoid = (int)dbReader[off++],
                                    taming_id = (int)dbReader[off++],
                                    taming_percentage = (decimal)dbReader[off++],
                                    taming_exp_mod = (decimal)dbReader[off++],
                                    exp = (int)dbReader[off++],
                                    jp = (int)dbReader[off++],
                                    gold_drop_percentage = (int)dbReader[off++],
                                    gold_min = (int)dbReader[off++],
                                    gold_max = (int)dbReader[off++],
                                    chaos_drop_percentage = (int)dbReader[off++],
                                    chaos_min = (int)dbReader[off++],
                                    chaos_max = (int)dbReader[off++],
                                    exp_2 = (int)dbReader[off++],
                                    jp_2 = (int)dbReader[off++],
                                    gold_min_2 = (int)dbReader[off++],
                                    gold_max_2 = (int)dbReader[off++],
                                    chaos_min_2 = (int)dbReader[off++],
                                    chaos_max_2 = (int)dbReader[off++],
                                    drop_table_link_id = (int)dbReader[off++],
                                    texture_group = (int)dbReader[off++],
                                    local_flag = (int)dbReader[off++],
                                    script_on_dead = (string)dbReader[off++]
                                };

                                if (MonsterResource.ContainsKey(id))
                                    ConsoleUtils.ShowError("Duplicated Monster with ID {0}; Current Local Flag: {1}, Ignored Local Flag: {2}", id, MonsterResource[id].local_flag, monster.local_flag);
                                else
                                    MonsterResource.Add(id, monster);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ConsoleUtils.ShowSQL(ex.Message);
                        return;
                    }
                    finally { dbCmd.Connection.Close(); }
                }
            }

            ConsoleUtils.ShowNotice("{0} entries loaded from MonsterResource", MonsterResource.Count);
        }
Example #9
0
        internal static void LoadAuctionCategory()
        {
            AuctionCategoryResource = new Dictionary<int, DB_AuctionCategory[]>();

            using (DBManager dbManager = new DBManager(Databases.Game))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(0))
                {
                    try
                    {
                        dbManager.CreateInParameter(dbCmd, "localflag", System.Data.DbType.Int32, Settings.LocalFlag);
                        dbCmd.Connection.Open();

                        using (DbDataReader dbReader = dbCmd.ExecuteReader())
                        {
                            int category_id = -1;
                            List<DB_AuctionCategory> subItems = new List<DB_AuctionCategory>();

                            while (dbReader.Read())
                            {
                                if ((int)dbReader[0] != category_id && category_id != -1)
                                {
                                    if (!AuctionCategoryResource.ContainsKey(category_id))
                                        AuctionCategoryResource.Add(category_id, subItems.ToArray());
                                    else
                                        ConsoleUtils.ShowError("Duplicated Auction Category Resource with ID {0}. Skipping duplicated entry.", category_id);

                                    subItems.Clear();
                                }
                                category_id = (int)dbReader[0];
                                DB_AuctionCategory subCat = new DB_AuctionCategory
                                {
                                    sub_category_id = (int)dbReader[1],
                                    name_id = (int)dbReader[2],
                                    local_flag = (int)dbReader[3],
                                    item_group = (int)dbReader[4],
                                    item_class = (int)dbReader[5]
                                };
                                subItems.Add(subCat);
                            }

                            if (category_id != -1)
                            {
                                AuctionCategoryResource.Add(category_id, subItems.ToArray());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ConsoleUtils.ShowSQL(ex.Message);
                        return;
                    }
                    finally { dbCmd.Connection.Close(); }
                }
            }

            ConsoleUtils.ShowNotice("{0} entries loaded from AuctionCategoryResource", AuctionCategoryResource.Count);
        }
Example #10
0
        internal static void LoadSummon()
        {
            SummonResource = new Dictionary<int, DB_Summon>();

            using (DBManager dbManager = new DBManager(Databases.Game))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(26))
                {
                    try
                    {
                        dbManager.CreateInParameter(dbCmd, "localflag", System.Data.DbType.Int32, Settings.LocalFlag);
                        dbCmd.Connection.Open();

                        using (DbDataReader dbReader = dbCmd.ExecuteReader())
                        {
                            while (dbReader.Read())
                            {
                                int off = 0;
                                int id = (int)dbReader[off++];

                                if (!SummonResource.ContainsKey(id))
                                    SummonResource.Add(
                                        id,
                                        new DB_Summon
                                        {
                                            model_id = (int)dbReader[off++],
                                            name_id = (int)dbReader[off++],
                                            type = (int)dbReader[off++],
                                            magic_type = (int)dbReader[off++],
                                            rate = (byte)dbReader[off++],
                                            stat_id = (int)dbReader[off++],
                                            size = (decimal)dbReader[off++],
                                            scale = (decimal)dbReader[off++],
                                            target_fx_size = (decimal)dbReader[off++],
                                            standard_walk_speed = (int)dbReader[off++],
                                            standard_run_speed = (int)dbReader[off++],
                                            riding_speed = (int)dbReader[off++],
                                            run_speed = (int)dbReader[off++],
                                            is_riding_only = (byte)dbReader[off++],
                                            riding_motion_type = (int)dbReader[off++],
                                            attack_range = (decimal)dbReader[off++],
                                            walk_type = (int)dbReader[off++],
                                            slant_type = (int)dbReader[off++],
                                            material = (int)dbReader[off++],
                                            weapon_type = (int)dbReader[off++],
                                            attack_motion_speed = (int)dbReader[off++],
                                            form = (int)dbReader[off++],
                                            evolve_target = (int)dbReader[off++],
                                            camera_x = (int)dbReader[off++],
                                            camera_y = (int)dbReader[off++],
                                            camera_z = (int)dbReader[off++],
                                            target_x = (decimal)dbReader[off++],
                                            target_y = (decimal)dbReader[off++],
                                            target_z = (decimal)dbReader[off++],
                                            model = (string)dbReader[off++],
                                            motion_file_id = (int)dbReader[off++],
                                            face_id = (int)dbReader[off++],
                                            face_file_name = (string)dbReader[off++],
                                            card_id = (int)dbReader[off++],
                                            script_text = (string)dbReader[off++],
                                            illust_file_name = (string)dbReader[off++],
                                            text_feature_id = (int)dbReader[off++],
                                            text_name_id = (int)dbReader[off++],
                                            skill1_id = (int)dbReader[off++],
                                            skill1_text_id = (int)dbReader[off++],
                                            skill2_id = (int)dbReader[off++],
                                            skill2_text_id = (int)dbReader[off++],
                                            skill3_id = (int)dbReader[off++],
                                            skill3_text_id = (int)dbReader[off++],
                                            skill4_id = (int)dbReader[off++],
                                            skill4_text_id = (int)dbReader[off++],
                                            skill5_id = (int)dbReader[off++],
                                            skill5_text_id = (int)dbReader[off++],
                                            texture_group = (int)dbReader[off++],
                                            local_flag = (int)dbReader[off++]
                                        });
                                else
                                    ConsoleUtils.ShowError("Duplicated Summon with ID {0}. Skipping duplicated entry.", id);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ConsoleUtils.ShowSQL(ex.Message);
                        return;
                    }
                    finally { dbCmd.Connection.Close(); }
                }
            }

            ConsoleUtils.ShowNotice("{0} entries loaded from SummonResource", SummonResource.Count);
        }
Example #11
0
        internal static void LoadAutoAuctionResource()
        {
            AutoAuctionResource = new Dictionary<int, DB_AutoAuction>();

            using (DBManager dbManager = new DBManager(Databases.Game))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(1))
                {
                    try
                    {
                        dbManager.CreateInParameter(dbCmd, "localflag", System.Data.DbType.Int32, Settings.LocalFlag);
                        dbCmd.Connection.Open();

                        using (DbDataReader dbReader = dbCmd.ExecuteReader())
                        {
                            while (dbReader.Read())
                            {
                                int off = 0;
                                int id = (int)dbReader[off++];

                                DB_AutoAuction autoAuction = new DB_AutoAuction
                                {
                                    item_id = (int)dbReader[off++],
                                    auctionseller_id = (int)dbReader[off++],
                                    price = (long)dbReader[off++],
                                    secroute_apply = Convert.ToChar(dbReader[off++]),
                                    local_flag = (int)dbReader[off++],
                                    auction_enrollment_time = (DateTime)dbReader[off++],
                                    repeat_apply = Convert.ToChar(dbReader[off++]),
                                    repeat_term = (int)dbReader[off++],
                                    auctiontime_type = (short)dbReader[off++],
                                };

                                if (!AutoAuctionResource.ContainsKey(id))
                                    AutoAuctionResource.Add(id, autoAuction);
                                else
                                    ConsoleUtils.ShowError("Duplicated Auction Resource with ID {0}. Skipping duplicated entry.", id);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ConsoleUtils.ShowSQL(ex.Message);
                        return;
                    }
                    finally { dbCmd.Connection.Close(); }
                }
            }

            ConsoleUtils.ShowNotice("{0} entries loaded from AutoAuctionResource", AutoAuctionResource.Count);
        }
Example #12
0
        /// <summary>
        /// IMBC Login
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="otp"></param>
        internal void IMBCLogin(string userId, string otp)
        {
            int accId = 0;
            byte perm = 0;
            ushort svId = 0;

            using (DBManager dbManager = new DBManager(Databases.Auth))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(1))
                {
                    dbManager.CreateInParameter(dbCmd, "id", System.Data.DbType.String, userId);
                    try
                    {
                        dbCmd.Connection.Open();

                        using (DbDataReader reader = dbCmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                accId = (int)reader[0];
                                perm = (byte)reader[3];
                                svId = Convert.ToUInt16((int)reader[4]);
                            }
                        }
                    }
                    catch (Exception ex) { ConsoleUtils.ShowError(ex.Message); }
                    finally { dbCmd.Connection.Close(); }
                }
            }

            if (accId > 0)
            { // Account exists, lets check otp
                string dbOtp = "";

                using (DBManager dbManager = new DBManager(Databases.Auth))
                {
                    using (DbCommand dbCmd = dbManager.CreateCommand(2))
                    {
                        dbManager.CreateInParameter(dbCmd, "acc", System.Data.DbType.String, accId);
                        try
                        {
                            dbCmd.Connection.Open();

                            using (DbDataReader reader = dbCmd.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    dbOtp = (string)reader[1];
                                }
                            }
                        }
                        catch (Exception ex) { ConsoleUtils.ShowError(ex.Message); }
                        finally { dbCmd.Connection.Close(); }
                    }
                }

                if (dbOtp.Length > 0 && dbOtp.Equals(otp))
                { // Valid otp, remove entry
                    using (DBManager dbManager = new DBManager(Databases.Auth))
                    {
                        using (DbCommand dbCmd = dbManager.CreateCommand(3))
                        {
                            dbManager.CreateInParameter(dbCmd, "acc", System.Data.DbType.String, accId);
                            try
                            {
                                dbCmd.Connection.Open();
                                dbCmd.ExecuteNonQuery();
                            }
                            catch (Exception ex) { ConsoleUtils.ShowError(ex.Message); }
                            finally { dbCmd.Connection.Close(); }
                        }
                    }

                    this.AccountId = accId;
                    this.UserId = userId;
                    this.Permission = perm;
                    this.LastServerId = svId;

                    ClientPackets.Instance.Result(this, 0); // Success
                    return;
                }
            }

            ClientPackets.Instance.Result(this, 1);  // Fail
            return;
        }
Example #13
0
        /// <summary>
        /// Normal Login
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="cryptedPass"></param>
        internal void Login(string userId, byte[] cryptedPass)
        {
            string userPass = Des.Decrypt(cryptedPass).Trim('\0');

            this.AccountId = -1;

            if (Settings.UseMD5)
            {
                using (MD5 md5Hash = MD5.Create())
                {
                    byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(userPass));

                    StringBuilder sBuilder = new StringBuilder();

                    for (int i = 0; i < data.Length; i++)
                    {
                        sBuilder.Append(data[i].ToString("x2"));
                    }

                    userPass = sBuilder.ToString();
                }
            }

            using (DBManager dbManager = new DBManager(Databases.Auth))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(0))
                {
                    dbManager.CreateInParameter(dbCmd, "id", System.Data.DbType.String, userId);
                    dbManager.CreateInParameter(dbCmd, "pass", System.Data.DbType.String, userPass);
                    try
                    {
                        dbCmd.Connection.Open();

                        using (DbDataReader reader = dbCmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                this.AccountId = (int)reader[0];
                                this.UserId = (string)reader[1];
                                this.Permission = (byte)reader[3];
                                this.LastServerId = Convert.ToUInt16((int)reader[4]);
                            }
                        }
                    }
                    catch (Exception ex) { ConsoleUtils.ShowError(ex.Message); }
                    finally { dbCmd.Connection.Close(); }
                }
            }

            if (this.AccountId >= 0)
            {
                ClientPackets.Instance.Result(this, 0); // Success
            }
            else
            {
                ClientPackets.Instance.Result(this, 1);  // Fail
            }
        }
Example #14
0
        internal void JoinServer(ushort index)
        {
            if (!Server.Instance.GameServers.ContainsKey(index))
            {
                ConsoleUtils.ShowWarning("User '{0}' trying to join invalid server {1}", this.UserId, index);
                return;
            }

            // Updates last_serverid
            using (DBManager dbManager = new DBManager(Databases.Auth))
            {
                using (DbCommand dbCmd = dbManager.CreateCommand(4))
                {
                    dbManager.CreateInParameter(dbCmd, "sid", System.Data.DbType.Int32, (int)index);
                    dbManager.CreateInParameter(dbCmd, "acc", System.Data.DbType.Int32, this.AccountId);
                    try
                    {
                        dbCmd.Connection.Open();
                        dbCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex) { ConsoleUtils.ShowError(ex.Message); }
                    finally { dbCmd.Connection.Close(); }
                }
            }

            Server.Instance.GameServers[index].UserJoin(this);
        }