public override PartyData ReadParty(int id)
        {
            PartyData       result = null;
            MySQLRowsReader reader = ExecuteReader("SELECT * FROM party WHERE id=@id LIMIT 1",
                                                   new MySqlParameter("@id", id));

            if (reader.Read())
            {
                result = new PartyData(id, reader.GetBoolean("shareExp"), reader.GetBoolean("shareItem"), reader.GetString("leaderId"));
                reader = ExecuteReader("SELECT id, dataId, characterName, level FROM characters WHERE partyId=@id",
                                       new MySqlParameter("@id", id));
                SocialCharacterData partyMemberData;
                while (reader.Read())
                {
                    // Get some required data, other data will be set at server side
                    partyMemberData               = new SocialCharacterData();
                    partyMemberData.id            = reader.GetString("id");
                    partyMemberData.characterName = reader.GetString("characterName");
                    partyMemberData.dataId        = reader.GetInt32("dataId");
                    partyMemberData.level         = reader.GetInt16("level");
                    result.AddMember(partyMemberData);
                }
            }
            return(result);
        }
        public override List <SocialCharacterData> ReadFriends(string id1)
        {
            List <SocialCharacterData> result = new List <SocialCharacterData>();

            MySQLRowsReader reader = ExecuteReader("SELECT characterId2 FROM friend WHERE characterId1=@id1",
                                                   new MySqlParameter("@id1", id1));
            string characterId;
            SocialCharacterData socialCharacterData;
            MySQLRowsReader     reader2;

            while (reader.Read())
            {
                characterId = reader.GetString("characterId2");
                reader2     = ExecuteReader("SELECT id, dataId, characterName, level FROM characters WHERE BINARY id = @id",
                                            new MySqlParameter("@id", characterId));
                while (reader2.Read())
                {
                    // Get some required data, other data will be set at server side
                    socialCharacterData               = new SocialCharacterData();
                    socialCharacterData.id            = reader2.GetString("id");
                    socialCharacterData.characterName = reader2.GetString("characterName");
                    socialCharacterData.dataId        = reader2.GetInt32("dataId");
                    socialCharacterData.level         = reader2.GetInt16("level");
                    result.Add(socialCharacterData);
                }
            }
            return(result);
        }
        private bool ReadBuilding(MySQLRowsReader reader, out BuildingSaveData result, bool resetReader = true)
        {
            if (resetReader)
            {
                reader.ResetReader();
            }

            if (reader.Read())
            {
                result              = new BuildingSaveData();
                result.Id           = reader.GetString("id");
                result.ParentId     = reader.GetString("parentId");
                result.DataId       = reader.GetInt32("dataId");
                result.CurrentHp    = reader.GetInt32("currentHp");
                result.Position     = new Vector3(reader.GetFloat("positionX"), reader.GetFloat("positionY"), reader.GetFloat("positionZ"));
                result.Rotation     = Quaternion.Euler(reader.GetFloat("rotationX"), reader.GetFloat("rotationY"), reader.GetFloat("rotationZ"));
                result.IsLocked     = reader.GetBoolean("isLocked");
                result.LockPassword = reader.GetString("lockPassword");
                result.CreatorId    = reader.GetString("creatorId");
                result.CreatorName  = reader.GetString("creatorName");
                return(true);
            }
            result = new BuildingSaveData();
            return(false);
        }
        public MySQLRowsReader ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, string sql, params MySqlParameter[] args)
        {
            var createLocalConnection = false;

            if (connection == null)
            {
                connection  = NewConnection();
                transaction = null;
                connection.Open();
                createLocalConnection = true;
            }
            var result = new MySQLRowsReader();

            using (var cmd = new MySqlCommand(sql, connection))
            {
                if (transaction != null)
                {
                    cmd.Transaction = transaction;
                }
                foreach (var arg in args)
                {
                    cmd.Parameters.Add(arg);
                }
                var dataReader = cmd.ExecuteReader();
                result.Init(dataReader);
                dataReader.Close();
            }
            if (createLocalConnection)
            {
                connection.Close();
            }
            return(result);
        }
Exemplo n.º 5
0
        public override bool IncreaseGuildExp(int id, int increaseExp, int[] expTree, out short resultLevel, out int resultExp, out short resultSkillPoint)
        {
            resultLevel      = 1;
            resultExp        = 0;
            resultSkillPoint = 0;

            MySQLRowsReader reader = ExecuteReader("UPDATE guild SET exp=exp+@increaseExp WHERE id=@id;" +
                                                   "SELECT level, exp, skillPoint FROM guild WHERE id=@id LIMIT 1;",
                                                   new MySqlParameter("@increaseExp", increaseExp),
                                                   new MySqlParameter("@id", id));

            if (reader.Read())
            {
                resultLevel      = (short)reader.GetInt32("level");
                resultExp        = reader.GetInt32("exp");
                resultSkillPoint = (short)reader.GetInt32("skillPoint");
                // Update when guild level is increase
                if (SocialSystemSetting.CalculateIncreasedGuildExp(expTree, resultLevel, resultExp, resultSkillPoint, out resultLevel, out resultExp, out resultSkillPoint))
                {
                    ExecuteNonQuery("UPDATE guild SET level=@level, exp=@exp, skillPoint=@skillPoint WHERE id=@id",
                                    new MySqlParameter("@level", resultLevel),
                                    new MySqlParameter("@exp", resultExp),
                                    new MySqlParameter("@skillPoint", resultSkillPoint),
                                    new MySqlParameter("@id", id));
                }
                // Return true if success
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        public List <EquipWeapons> ReadCharacterEquipWeapons(string characterId)
        {
            List <EquipWeapons> result = new List <EquipWeapons>();

            MySQLRowsReader reader = ExecuteReader("SELECT * FROM characteritem WHERE characterId=@characterId AND (inventoryType=@inventoryType1 OR inventoryType=@inventoryType2) ORDER BY idx ASC",
                                                   new MySqlParameter("@characterId", characterId),
                                                   new MySqlParameter("@inventoryType1", (byte)InventoryType.EquipWeaponRight),
                                                   new MySqlParameter("@inventoryType2", (byte)InventoryType.EquipWeaponLeft));

            CharacterItem tempInventory;
            byte          equipWeaponSet;
            InventoryType inventoryType;

            while (ReadCharacterItem(reader, out tempInventory, false))
            {
                equipWeaponSet = reader.GetByte("idx");
                inventoryType  = (InventoryType)reader.GetSByte("inventoryType");
                // Fill weapon sets if needed
                while (result.Count <= equipWeaponSet)
                {
                    result.Add(new EquipWeapons());
                }
                // Get equip weapon set
                if (inventoryType == InventoryType.EquipWeaponRight)
                {
                    result[equipWeaponSet].rightHand = tempInventory;
                }
                if (inventoryType == InventoryType.EquipWeaponLeft)
                {
                    result[equipWeaponSet].leftHand = tempInventory;
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        private bool ReadCharacterItem(MySQLRowsReader reader, out CharacterItem result, bool resetReader = true)
        {
            if (resetReader)
            {
                reader.ResetReader();
            }

            if (reader.Read())
            {
                result                     = new CharacterItem();
                result.id                  = reader.GetString("id");
                result.dataId              = reader.GetInt32("dataId");
                result.level               = reader.GetInt16("level");
                result.amount              = reader.GetInt16("amount");
                result.equipSlotIndex      = reader.GetByte("equipSlotIndex");
                result.durability          = reader.GetFloat("durability");
                result.exp                 = reader.GetInt32("exp");
                result.lockRemainsDuration = reader.GetFloat("lockRemainsDuration");
                result.ammo                = reader.GetInt16("ammo");
                result.sockets             = ReadSockets(reader.GetString("sockets"));
                return(true);
            }
            result = CharacterItem.Empty;
            return(false);
        }
        public override string GooglePlayLogin(string gId, string email)
        {
            string          id     = string.Empty;
            MySQLRowsReader reader = ExecuteReader("SELECT id FROM userlogin WHERE username=@username AND password=@password AND authType=@authType LIMIT 1",
                                                   new MySqlParameter("@username", "g_" + gId),
                                                   new MySqlParameter("@password", GenericUtils.GetMD5(gId)),
                                                   new MySqlParameter("@authType", AUTH_TYPE_GOOGLE_PLAY));

            if (reader.Read())
            {
                id = reader.GetString("id");
            }
            else
            {
                ExecuteNonQuery("INSERT INTO userlogin (id, username, password, email, authType) VALUES (@id, @username, @password, @email, @authType)",
                                new MySqlParameter("@id", GenericUtils.GetUniqueId()),
                                new MySqlParameter("@username", "g_" + gId),
                                new MySqlParameter("@password", GenericUtils.GetMD5(gId)),
                                new MySqlParameter("@email", email),
                                new MySqlParameter("@authType", AUTH_TYPE_GOOGLE_PLAY));

                // Read last entry
                reader = ExecuteReader("SELECT id FROM userlogin WHERE username=@username AND password=@password AND authType=@authType LIMIT 1",
                                       new MySqlParameter("@username", "g_" + gId),
                                       new MySqlParameter("@password", GenericUtils.GetMD5(gId)),
                                       new MySqlParameter("@authType", AUTH_TYPE_GOOGLE_PLAY));

                if (reader.Read())
                {
                    id = reader.GetString("id");
                }
            }
            return(id);
        }
        public EquipWeapons ReadCharacterEquipWeapons(string characterId)
        {
            EquipWeapons result = new EquipWeapons();
            // Right hand weapon
            MySQLRowsReader reader = ExecuteReader("SELECT * FROM characteritem WHERE characterId=@characterId AND inventoryType=@inventoryType LIMIT 1",
                                                   new MySqlParameter("@characterId", characterId),
                                                   new MySqlParameter("@inventoryType", (byte)InventoryType.EquipWeaponRight));
            CharacterItem rightWeapon;

            if (ReadCharacterItem(reader, out rightWeapon))
            {
                result.rightHand = rightWeapon;
            }
            // Left hand weapon
            reader = ExecuteReader("SELECT * FROM characteritem WHERE characterId=@characterId AND inventoryType=@inventoryType LIMIT 1",
                                   new MySqlParameter("@characterId", characterId),
                                   new MySqlParameter("@inventoryType", (byte)InventoryType.EquipWeaponLeft));
            CharacterItem leftWeapon;

            if (ReadCharacterItem(reader, out leftWeapon))
            {
                result.leftHand = leftWeapon;
            }
            return(result);
        }
        public void ReadCharacter_UMA(
            PlayerCharacterData characterData,
            bool withEquipWeapons,
            bool withAttributes,
            bool withSkills,
            bool withSkillUsages,
            bool withBuffs,
            bool withEquipItems,
            bool withNonEquipItems,
            bool withSummons,
            bool withHotkeys,
            bool withQuests)
        {
            // Read uma data
            MySQLRowsReader reader = ExecuteReader("SELECT data FROM characterumasaves WHERE id=@id",
                                                   new MySqlParameter("@id", characterData.Id));

            if (reader.Read())
            {
                string      data        = reader.GetString("data");
                string[]    splitedData = data.Split(',');
                List <byte> bytes       = new List <byte>();
                foreach (string entry in splitedData)
                {
                    bytes.Add(byte.Parse(entry));
                }
                UmaAvatarData umaAvatarData = new UmaAvatarData();
                umaAvatarData.SetBytes(bytes);
                characterData.UmaAvatarData = umaAvatarData;
            }
        }
Exemplo n.º 11
0
        public MySQLRowsReader ExecuteReader(string sql, params MySqlParameter[] args)
        {
            MySqlConnection connection = NewConnection();

            connection.Open();
            MySQLRowsReader result = ExecuteReader(connection, null, sql, args);

            connection.Close();
            return(result);
        }
        public override List <BuildingSaveData> ReadBuildings(string mapName)
        {
            List <BuildingSaveData> result = new List <BuildingSaveData>();
            MySQLRowsReader         reader = ExecuteReader("SELECT * FROM buildings WHERE mapName=@mapName", new MySqlParameter("@mapName", mapName));
            BuildingSaveData        tempBuilding;

            while (ReadBuilding(reader, out tempBuilding, false))
            {
                result.Add(tempBuilding);
            }
            return(result);
        }
Exemplo n.º 13
0
        public override int GetGold(string userId)
        {
            int             gold   = 0;
            MySQLRowsReader reader = ExecuteReader("SELECT gold FROM userlogin WHERE id=@id LIMIT 1",
                                                   new MySqlParameter("@id", userId));

            if (reader.Read())
            {
                gold = reader.GetInt32("gold");
            }
            return(gold);
        }
Exemplo n.º 14
0
        public override int GetCash(string userId)
        {
            int             cash   = 0;
            MySQLRowsReader reader = ExecuteReader("SELECT cash FROM userlogin WHERE id=@id LIMIT 1",
                                                   new MySqlParameter("@id", userId));

            if (reader.Read())
            {
                cash = reader.GetInt32("cash");
            }
            return(cash);
        }
        public override int GetGuildGold(int guildId)
        {
            int             gold   = 0;
            MySQLRowsReader reader = ExecuteReader("SELECT gold FROM guild WHERE id=@id LIMIT 1",
                                                   new MySqlParameter("@id", guildId));

            if (reader.Read())
            {
                gold = reader.GetInt32("gold");
            }
            return(gold);
        }
Exemplo n.º 16
0
        public override byte GetUserLevel(string userId)
        {
            byte            userLevel = 0;
            MySQLRowsReader reader    = ExecuteReader("SELECT userLevel FROM userlogin WHERE id=@id LIMIT 1",
                                                      new MySqlParameter("@id", userId));

            if (reader.Read())
            {
                userLevel = (byte)reader.GetSByte("userLevel");
            }
            return(userLevel);
        }
        public override List <PlayerCharacterData> ReadCharacters(string userId)
        {
            List <PlayerCharacterData> result = new List <PlayerCharacterData>();
            MySQLRowsReader            reader = ExecuteReader("SELECT id FROM characters WHERE userId=@userId ORDER BY updateAt DESC", new MySqlParameter("@userId", userId));

            while (reader.Read())
            {
                string characterId = reader.GetString("id");
                result.Add(ReadCharacter(userId, characterId, true, true, true, false, false, true, false, false, false, false));
            }
            return(result);
        }
        public override GuildData ReadGuild(int id, GuildRoleData[] defaultGuildRoles)
        {
            GuildData       result = null;
            MySQLRowsReader reader = ExecuteReader("SELECT * FROM guild WHERE id=@id LIMIT 1",
                                                   new MySqlParameter("@id", id));

            if (reader.Read())
            {
                result              = new GuildData(id, reader.GetString("guildName"), reader.GetString("leaderId"), defaultGuildRoles);
                result.level        = reader.GetInt16("level");
                result.exp          = reader.GetInt32("exp");
                result.skillPoint   = reader.GetInt16("skillPoint");
                result.guildMessage = reader.GetString("guildMessage");
                result.gold         = reader.GetInt32("gold");

                reader = ExecuteReader("SELECT * FROM guildrole WHERE guildId=@id",
                                       new MySqlParameter("@id", id));
                byte          guildRole;
                GuildRoleData guildRoleData;
                while (reader.Read())
                {
                    guildRole                        = reader.GetByte("guildRole");
                    guildRoleData                    = new GuildRoleData();
                    guildRoleData.roleName           = reader.GetString("name");
                    guildRoleData.canInvite          = reader.GetBoolean("canInvite");
                    guildRoleData.canKick            = reader.GetBoolean("canKick");
                    guildRoleData.shareExpPercentage = reader.GetByte("shareExpPercentage");
                    result.SetRole(guildRole, guildRoleData);
                }

                reader = ExecuteReader("SELECT id, dataId, characterName, level, guildRole FROM characters WHERE guildId=@id",
                                       new MySqlParameter("@id", id));
                SocialCharacterData guildMemberData;
                while (reader.Read())
                {
                    // Get some required data, other data will be set at server side
                    guildMemberData               = new SocialCharacterData();
                    guildMemberData.id            = reader.GetString("id");
                    guildMemberData.characterName = reader.GetString("characterName");
                    guildMemberData.dataId        = reader.GetInt32("dataId");
                    guildMemberData.level         = reader.GetInt16("level");
                    result.AddMember(guildMemberData, reader.GetByte("guildRole"));
                }

                reader = ExecuteReader("SELECT dataId, level FROM guildskill WHERE guildId=@id",
                                       new MySqlParameter("@id", id));
                while (reader.Read())
                {
                    result.SetSkillLevel(reader.GetInt32("dataId"), reader.GetInt16("level"));
                }
            }
            return(result);
        }
        public List <CharacterQuest> ReadCharacterQuests(string characterId)
        {
            List <CharacterQuest> result = new List <CharacterQuest>();
            MySQLRowsReader       reader = ExecuteReader("SELECT * FROM characterquest WHERE characterId=@characterId ORDER BY idx ASC",
                                                         new MySqlParameter("@characterId", characterId));
            CharacterQuest tempQuest;

            while (ReadCharacterQuest(reader, out tempQuest, false))
            {
                result.Add(tempQuest);
            }
            return(result);
        }
        public List <CharacterAttribute> ReadCharacterAttributes(string characterId)
        {
            List <CharacterAttribute> result = new List <CharacterAttribute>();
            MySQLRowsReader           reader = ExecuteReader("SELECT * FROM characterattribute WHERE characterId=@characterId ORDER BY idx ASC",
                                                             new MySqlParameter("@characterId", characterId));
            CharacterAttribute tempAttribute;

            while (ReadCharacterAttribute(reader, out tempAttribute, false))
            {
                result.Add(tempAttribute);
            }
            return(result);
        }
Exemplo n.º 21
0
        public List <CharacterBuff> ReadCharacterBuffs(string characterId)
        {
            List <CharacterBuff> result = new List <CharacterBuff>();
            MySQLRowsReader      reader = ExecuteReader("SELECT * FROM characterbuff WHERE characterId=@characterId ORDER BY buffRemainsDuration ASC",
                                                        new MySqlParameter("@characterId", characterId));
            CharacterBuff tempBuff;

            while (ReadCharacterBuff(reader, out tempBuff, false))
            {
                result.Add(tempBuff);
            }
            return(result);
        }
        public List <CharacterHotkey> ReadCharacterHotkeys(string characterId)
        {
            List <CharacterHotkey> result = new List <CharacterHotkey>();
            MySQLRowsReader        reader = ExecuteReader("SELECT * FROM characterhotkey WHERE characterId=@characterId",
                                                          new MySqlParameter("@characterId", characterId));
            CharacterHotkey tempHotkey;

            while (ReadCharacterHotkey(reader, out tempHotkey, false))
            {
                result.Add(tempHotkey);
            }
            return(result);
        }
        public List <CharacterSkillUsage> ReadCharacterSkillUsages(string characterId)
        {
            List <CharacterSkillUsage> result = new List <CharacterSkillUsage>();
            MySQLRowsReader            reader = ExecuteReader("SELECT * FROM characterskillusage WHERE characterId=@characterId ORDER BY coolDownRemainsDuration ASC",
                                                              new MySqlParameter("@characterId", characterId));
            CharacterSkillUsage tempSkillUsage;

            while (ReadCharacterSkillUsage(reader, out tempSkillUsage, false))
            {
                result.Add(tempSkillUsage);
            }
            return(result);
        }
Exemplo n.º 24
0
        public List <CharacterSummon> ReadCharacterSummons(string characterId)
        {
            List <CharacterSummon> result = new List <CharacterSummon>();
            MySQLRowsReader        reader = ExecuteReader("SELECT * FROM charactersummon WHERE characterId=@characterId ORDER BY type DESC",
                                                          new MySqlParameter("@characterId", characterId));
            CharacterSummon tempSummon;

            while (ReadCharacterSummon(reader, out tempSummon, false))
            {
                result.Add(tempSummon);
            }
            return(result);
        }
Exemplo n.º 25
0
        public List <CharacterSkill> ReadCharacterSkills(string characterId)
        {
            List <CharacterSkill> result = new List <CharacterSkill>();
            MySQLRowsReader       reader = ExecuteReader("SELECT * FROM characterskill WHERE characterId=@characterId ORDER BY idx ASC",
                                                         new MySqlParameter("@characterId", characterId));
            CharacterSkill tempSkill;

            while (ReadCharacterSkill(reader, out tempSkill, false))
            {
                result.Add(tempSkill);
            }
            return(result);
        }
        private List <CharacterItem> ReadCharacterItems(string characterId, InventoryType inventoryType)
        {
            List <CharacterItem> result = new List <CharacterItem>();
            MySQLRowsReader      reader = ExecuteReader("SELECT * FROM characteritem WHERE characterId=@characterId AND inventoryType=@inventoryType ORDER BY idx ASC",
                                                        new MySqlParameter("@characterId", characterId),
                                                        new MySqlParameter("@inventoryType", (byte)inventoryType));
            CharacterItem tempInventory;

            while (ReadCharacterItem(reader, out tempInventory, false))
            {
                result.Add(tempInventory);
            }
            return(result);
        }
        public override List <CharacterItem> ReadStorageItems(StorageType storageType, string storageOwnerId)
        {
            List <CharacterItem> result = new List <CharacterItem>();
            MySQLRowsReader      reader = ExecuteReader("SELECT * FROM storageitem WHERE storageType=@storageType AND storageOwnerId=@storageOwnerId ORDER BY idx ASC",
                                                        new MySqlParameter("@storageType", (byte)storageType),
                                                        new MySqlParameter("@storageOwnerId", storageOwnerId));
            CharacterItem tempInventory;

            while (ReadStorageItem(reader, out tempInventory, false))
            {
                result.Add(tempInventory);
            }
            return(result);
        }
Exemplo n.º 28
0
        public override string ValidateUserLogin(string username, string password)
        {
            string          id     = string.Empty;
            MySQLRowsReader reader = ExecuteReader("SELECT id FROM userlogin WHERE username=@username AND password=@password AND authType=@authType LIMIT 1",
                                                   new MySqlParameter("@username", username),
                                                   new MySqlParameter("@password", GenericUtils.GetMD5(password)),
                                                   new MySqlParameter("@authType", AUTH_TYPE_NORMAL));

            if (reader.Read())
            {
                id = reader.GetString("id");
            }

            return(id);
        }
Exemplo n.º 29
0
        private bool ReadCharacterSkill(MySQLRowsReader reader, out CharacterSkill result, bool resetReader = true)
        {
            if (resetReader)
            {
                reader.ResetReader();
            }

            if (reader.Read())
            {
                result        = new CharacterSkill();
                result.dataId = reader.GetInt32("dataId");
                result.level  = (short)reader.GetInt32("level");
                return(true);
            }
            result = CharacterSkill.Empty;
            return(false);
        }
        private bool ReadCharacterAttribute(MySQLRowsReader reader, out CharacterAttribute result, bool resetReader = true)
        {
            if (resetReader)
            {
                reader.ResetReader();
            }

            if (reader.Read())
            {
                result        = new CharacterAttribute();
                result.dataId = reader.GetInt32("dataId");
                result.amount = (short)reader.GetInt32("amount");
                return(true);
            }
            result = CharacterAttribute.Empty;
            return(false);
        }