Beispiel #1
0
        public ClientDataDB(string string_column, string table)
        {
            string id_column = null;

            try
            {
                MySql.Data.MySqlClient.MySqlCommand    cmd    = DBConnect.GetInstance().Query(String.Format("SHOW columns FROM {0}", table));
                MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                id_column = (string)reader["field"];
                reader.Close();
            }
            catch (System.Exception e)
            {
                // TODO: show config option to configure sql connection
            }
            Load(id_column, string_column, table, null);
        }
Beispiel #2
0
        public void LoadAll()
        {
            CurrentAction(this, new LoadingEventArgs("quests"));
            dbString.Add(StorageType.Quest, new ClientDataDB <string>("title", "quest_template"));

            CurrentAction(this, new LoadingEventArgs("creatures"));
            dbString.Add(StorageType.Creature, new ClientDataDB <string>("entry", "name", "creature_template"));
            dbString.Add(StorageType.CreatureEntryWithAI, new ClientDataDB <string>("entry", "ScriptName", "creature_template", "AIName = \"SmartAI\""));

            //dbInt.Add(StorageType.CreatureGuid, new ClientDataDB<int>("guid", "entry", "creature"));



            MySql.Data.MySqlClient.MySqlCommand cmd = DBConnect.GetInstance().Query(String.Format("SELECT guid, concat(name, ' ', creature.id) as _name, count(source_type) as smartAI FROM creature left join smart_scripts on source_type=0 and entryorguid=(-guid) join creature_template on creature_template.entry=creature.id group by guid "));
            dbString.Add(StorageType.CreatureGuid, new ClientData <String>());
            dbString.Add(StorageType.CreatureGuidWithSAI, new ClientData <String>());
            if (cmd != null)
            {
                using (MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        dbString[StorageType.CreatureGuid].Set(Convert.ToInt32(reader["guid"]), Convert.ToString(reader["_name"]));
                        if (Convert.ToInt32(reader["smartAI"]) > 0)
                        {
                            dbString[StorageType.CreatureGuidWithSAI].Set(Convert.ToInt32(reader["guid"]), Convert.ToString(reader["_name"]));
                        }
                    }
                }
            }


            CurrentAction(this, new LoadingEventArgs("gameobjects"));
            dbString.Add(StorageType.GameObject, new ClientDataDB <string>("entry", "name", "gameobject_template"));
            dbString.Add(StorageType.GameObjectEntryWithAI, new ClientDataDB <string>("entry", "ScriptName", "gameobject_template", "AIName = \"SmartGameObjectAI\""));


            cmd = DBConnect.GetInstance().Query(String.Format("SELECT guid, concat(name, ' ', gameobject.id) as _name, count(source_type) as smartAI FROM gameobject left join smart_scripts on source_type=1 and entryorguid=(-guid) join gameobject_template on gameobject_template.entry=gameobject.id group by guid "));
            dbString.Add(StorageType.GameObjectGuid, new ClientData <String>());
            dbString.Add(StorageType.GameObjectGuidWithAI, new ClientData <String>());
            if (cmd != null)
            {
                using (MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        dbString[StorageType.GameObjectGuid].Set(Convert.ToInt32(reader["guid"]), Convert.ToString(reader["_name"]));
                        if (Convert.ToInt32(reader["smartAI"]) > 0)
                        {
                            dbString[StorageType.GameObjectGuidWithAI].Set(Convert.ToInt32(reader["guid"]), Convert.ToString(reader["_name"]));
                        }
                    }
                }
            }


            cmd = DBConnect.GetInstance().Query(String.Format("SELECT entryorguid FROM smart_scripts where source_type=9 group by entryorguid"));
            dbString.Add(StorageType.TimedActionList, new ClientData <String>());
            if (cmd != null)
            {
                using (MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        dbString[StorageType.TimedActionList].Set(Convert.ToInt32(reader["entryorguid"]), null);
                    }
                }
            }

            CurrentAction(this, new LoadingEventArgs("area triggers"));
            dbString.Add(StorageType.AreaTrigger, new ClientDataDBC("AreaTrigger.dbc",
                                                                    delegate(BinaryReader br, Dictionary <int, string> strings)
            {
                StringBuilder sb = new StringBuilder();
                br.ReadInt32();
                sb.Append("(");
                sb.Append(br.ReadSingle());
                sb.Append(", ");
                sb.Append(br.ReadSingle());
                sb.Append(", ");
                sb.Append(br.ReadSingle());
                sb.Append(")");
                return(sb.ToString());
            }
                                                                    ));
            dbString.Add(StorageType.AreaTriggerWithSAI, new ClientDataDB <string>("entry", "ScriptName", "areatrigger_scripts", "ScriptName = \"SmartTrigger\""));

            CurrentAction(this, new LoadingEventArgs("game events"));
            dbString.Add(StorageType.GameEvent, new ClientDataDB <string>("EventEntry", "description", "game_event"));



            Dictionary <String, DBCConfig> dbc_config = JsonConvert.DeserializeObject <Dictionary <String, DBCConfig> >(File.ReadAllText(@"data\dbc.json"));

            if (string.IsNullOrEmpty(Properties.Settings.Default.DBCVersion))
            {
                Properties.Settings.Default.DBCVersion = GuessDBCVersion(dbc_config);
                Properties.Settings.Default.Save();
            }

            if (!string.IsNullOrEmpty(Properties.Settings.Default.DBCVersion))
            {
                foreach (StorageType type in dbc_config[Properties.Settings.Default.DBCVersion].offsets.Keys)
                {
                    if (dbc_config[Properties.Settings.Default.DBCVersion].offsets[type].unsupported)
                    {
                        continue;
                    }
                    CurrentAction(this, new LoadingEventArgs(type.ToString()));
                    dbString.Add(type, new ClientDataDBC(dbc_config[Properties.Settings.Default.DBCVersion].offsets[type].file, dbc_config[Properties.Settings.Default.DBCVersion].offsets[type].offset));
                }
            }



            FinishedLoading(this, new EventArgs());
        }