Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.cpp
- /* Converter */
- #include "Precomp.h"
- CLog Log;
- #define TABLE_NUM 5
- static string table[TABLE_NUM] = {
- "Exit",
- "creature_proto",
- "creature_names",
- "creature_spawns",
- "Mindeeet",
- };
- bool SendMenu()
- {
- uint32 num;
- printf("AscNHalf Sql db converter \n");
- printf("Melyiket szeretned konvertalni?? \n\n");
- for(uint32 i = 0; i < TABLE_NUM; i++)
- {
- printf("%u. %s \n", i, table[i]);
- }
- printf("\nValaszott tabla: ");
- cin >> num;
- if(num >= TABLE_NUM)
- {
- printf("Hibas szam. \n ");
- return false;
- }
- Converter* conv = new Converter();
- switch(num)
- {
- case 0:
- {
- // semmit se kell tennünk
- }break;
- case 1:
- {
- conv->creature_proto();
- }break;
- case 2:
- {
- conv->creature_names();
- }break;
- case 3:
- {
- conv->creature_spawns();
- }break;
- case 4:
- {
- conv->creature_proto();
- conv->creature_names();
- conv->creature_spawns();
- }break;
- }
- if(num != 0)
- {
- printf("\nMit szretnel tenni?\n");
- printf("1. exit. \n2. ujrainditom a konvertert.");
- num = 0;
- cin >> num;
- switch(num)
- {
- case 2:
- {
- delete conv;
- return false;
- }break;
- }
- }
- delete conv;
- return true;
- }
- void main()
- {
- bool end = false;
- while(!end)
- {
- end = SendMenu();
- }
- return;
- }
- // converter.cpp
- /* Converter */
- #include "Precomp.h"
- Converter::Converter()
- {
- MySQLConnection * mSQLConnTdb = new MySQLConnection("localhost", "root", "");
- mSQLConnTdb->UseDatabase("tdb");
- MySQLConnection * mSQLConnYtdb = new MySQLConnection("localhost", "root", "");
- mSQLConnYtdb->UseDatabase("ytdb");
- MySQLConnection * mSQLConnAsc = new MySQLConnection("localhost", "root", "");
- mSQLConnAsc->UseDatabase("test");
- }
- Converter::~Converter()
- {
- delete mSQLConnTdb;
- delete mSQLConnYtdb;
- delete mSQLConnAsc;
- }
- void Converter::creature_proto()
- {
- printf("Converting creature_proto... \n");
- CreatureProto * cp = new CreatureProto;
- QueryResult* db = mSQLConnTdb->Query("SELECT * FROM creature_template");
- QueryResult* t1;
- stringstream ss;
- if(db)
- {
- do
- {
- cp->AttackTime = 0;
- cp->AttackType = 0;
- cp->aura_string = "''";
- cp->auraimmune_flag = 0;
- cp->boss = 0;
- cp->BoundingRadius = 0.0f;
- cp->CanMove = 7;
- cp->CombatReach = 0.0f;
- cp->death_state = 0;
- cp->extra_a9_flags = 0;
- cp->Faction = 0;
- cp->fly_speed = 14.0f;
- cp->Id = 0;
- cp->invisibility_type = 0;
- cp->Item1 = 0;
- cp->Item2 = 0;
- cp->Item3 = 0;
- cp->MaxDamage = 0.0f;
- cp->MaxHealth = 1;
- cp->MaxLevel = 0;
- cp->maxmoney = 0;
- cp->MinDamage = 0.0f;
- cp->MinHealth = 1;
- cp->MinLevel = 0;
- cp->minmoney = 0;
- //cp->no_xp = false;
- cp->NPCFLags = 0;
- cp->Power = 0;
- cp->Powertype = 0;
- cp->RangedAttackTime = 0;
- cp->RangedMaxDamage = 0.0f;
- cp->RangedMinDamage = 0.0f;
- for(uint32 i = 0; i < 7; i++)
- cp->Resistances[i] = 0;
- cp->RespawnTime = 360000;
- cp->run_speed = 8.0f;
- cp->Scale = 0.0f;
- cp->SpellClickid = 0;
- cp->vehicle_entry = -1;
- cp->walk_speed = 2.5f;
- t1 = mSQLConnTdb->Query("SELECT `equipentry1`,`equipentry2`,`equipentry3` FROM `creature_equip_template` WHERE `entry`=%u", db->Fetch()[79].GetUInt32());
- if(t1)
- {
- cp->Item1 = t1->Fetch()[0].GetUInt32();
- cp->Item2 = t1->Fetch()[1].GetUInt32();
- cp->Item3 = t1->Fetch()[2].GetUInt32();
- delete t1;
- }
- t1 = mSQLConnTdb->Query("SELECT `DeathState` FROM `creature` WHERE `id`=%u", db->Fetch()[0].GetUInt32());
- if(t1)
- {
- cp->death_state = t1->Fetch()[0].GetUInt32();
- delete t1;
- }
- t1 = mSQLConnYtdb->("SELECT `minhealth`,`maxhealth`,`minmana`,`maxmana` FROM `creature_template WHERE `entry`=%u", db->Fetch()[0].GetUInt32());
- if(t1)
- {
- cp->MinHealth = t1->Fetch()[0].GetUInt32();
- cp->MaxHealth = t1->Fetch()[1].GetUInt32();
- cp->Power = ((t1->Fetch()[2].GetUInt32() + t1->Fetch()[3].GetUInt32()) * 0.5);
- delete t1;
- }
- /*subq = "";
- ss.clear();
- ss.str ("");
- ss << "SELECT `bounding_radius`, `combat_reach` FROM `creature_model_info` WHERE `modelid`=" ;*/
- cp->Id = db->Fetch()[0].GetUInt32();
- cp->MinLevel = db->Fetch()[14].GetUInt32();
- cp->MaxLevel = db->Fetch()[15].GetUInt32();
- cp->Faction = db->Fetch()[17].GetUInt32();
- cp->NPCFLags = db->Fetch()[19].GetUInt32();
- cp->walk_speed = db->Fetch()[20].GetFloat();
- cp->run_speed = db->Fetch()[21].GetFloat();
- cp->Scale = db->Fetch()[22].GetFloat();
- cp->MinDamage = db->Fetch()[24].GetFloat();
- cp->MaxDamage = db->Fetch()[25].GetFloat();
- cp->AttackTime = db->Fetch()[29].GetUInt32();
- cp->RangedAttackTime = db->Fetch()[30].GetUInt32();
- cp->RangedMaxDamage = db->Fetch()[40].GetFloat();
- cp->RangedMinDamage = db->Fetch()[39].GetFloat();
- uint32 y = 0;
- for(uint32 i = 47; i < 53; i++)
- {
- cp->Resistances[y] = db->Fetch()[i].GetUInt32();
- ++y;
- }
- if(db->Fetch()[61].GetUInt32() != 0)
- cp->vehicle_entry = db->Fetch()[61].GetUInt32();
- cp->minmoney = db->Fetch()[62].GetUInt32();
- cp->maxmoney = db->Fetch()[63].GetUInt32();
- cp->extra_a9_flags = db->Fetch()[81].GetUInt32();
- ss.clear();
- ss.str ("");
- ss << "INSERT INTO `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `powertype`, `power`,";
- ss << "`scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`,";
- ss << "`Item1`, `Item2`, `Item3`, `RespawnTime`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`,";
- ss << "`resistance7`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `minmoney`, `maxmoney`, `invisibility_type`, `death_state`,";
- ss << "`walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `auraimmune_flag`, `vehicle_entry`, `SpellClickId`, `CanMove`) VALUES (";
- ss << cp->Id << "," << cp->MinLevel << "," << cp->MaxLevel << "," << cp->Faction << "," << cp->MinHealth << "," << cp->MaxHealth << ",";
- ss << cp->Powertype << "," << cp->Power << "," << cp->Scale << "," << cp->NPCFLags << "," << cp->AttackTime << "," << cp->AttackType << ",";
- ss << cp->MinDamage << "," << cp->MaxDamage << "," << cp->RangedAttackTime << "," << cp->RangedMinDamage << "," << cp->RangedMaxDamage << ",";
- ss << cp->Item1 << "," << cp->Item2 << "," << cp->Item3 << "," << cp->RespawnTime << ",";
- for(uint32 i = 0; i < 7; i++)
- ss << cp->Resistances[i] << ",";
- ss << cp->CombatReach << "," << cp->BoundingRadius << "," << cp->aura_string << "," << cp->boss << "," << cp->minmoney << "," << cp->maxmoney << ",";
- ss << cp->invisibility_type << "," << cp->death_state << "," << cp->walk_speed << "," << cp->run_speed << "," << cp->fly_speed << "," << cp->extra_a9_flags << ",";
- ss << cp->auraimmune_flag << "," << cp->vehicle_entry << "," << cp->SpellClickid << "," << cp->CanMove << ")";
- mSQLConnAsc->Execute(ss.str());
- printf("%u ", db->Fetch()[0].GetUInt32());
- } while(db->NextRow());
- delete db;
- }
- delete cp;
- }
- void Converter::creature_names()
- {
- printf("Converting creature_names... \n");
- CreatureNames * cn = new CreatureNames;
- QueryResult* db = mSQLConnTdb->Query("SELECT * FROM creature_template");
- stringstream ss;
- if(db)
- {
- do
- {
- cn->Civilian = 0;
- cn->Family = 0;
- cn->Female_DisplayID = 0;
- cn->Female_DisplayID2 = 0;
- cn->Flags1 = 0;
- cn->Id = 0;
- cn->info_str = "";
- cn->Leader = 0;
- cn->Male_DisplayID = 0;
- cn->Male_DisplayID2 = 0;
- cn->Name = "";
- cn->Rank = 0;
- cn->SpellDataID = 0;
- cn->SubName = "";
- cn->Type = 0;
- cn->TypeFlags = 0;
- cn->unkfloat1 = 0.0f;
- cn->unkfloat2 = 0.0f;
- cn->Unknown1 = 0;
- cn->Id = db->Fetch()[0].GetUInt32();
- cn->Male_DisplayID = db->Fetch()[6].GetUInt32();
- cn->Male_DisplayID2 = db->Fetch()[7].GetUInt32();
- cn->Female_DisplayID = db->Fetch()[8].GetUInt32();
- cn->Female_DisplayID2 = db->Fetch()[9].GetUInt32();
- if(db->Fetch()[10].GetString() != NULL)
- cn->Name = db->Fetch()[10].GetString();
- if(db->Fetch()[11].GetString() != NULL)
- cn->SubName = db->Fetch()[11].GetString();
- if(db->Fetch()[12].GetString() != NULL)
- cn->info_str = db->Fetch()[12].GetString();
- cn->Rank = db->Fetch()[23].GetUInt32();
- cn->Family = db->Fetch()[34].GetUInt32();
- cn->Type = db->Fetch()[42].GetUInt32();
- cn->TypeFlags = db->Fetch()[43].GetUInt32();
- cn->SpellDataID = db->Fetch()[61].GetUInt32();
- cn->Leader = db->Fetch()[71].GetUInt32();
- ss.clear();
- ss.str ("");
- ss << "INSERT INTO `creature_names` (`entry`,`name`,`subname`,`info_str`,`Flags1`,`type`,`loot_skill_type`,`family`,`rank`,`unk4`,";
- ss << "`spelldataid`,`male_displayid`,`female_displayid`,`male_displayid2`,`female_displayid2`,`unknown_float1`,`unknown_float2`,";
- ss << "`civilian`,`leader`) VALUES (";
- ss << cn->Id << ",'" << mSQLConnAsc->EscapeString(string(cn->Name)) << "','" << mSQLConnAsc->EscapeString(string(cn->SubName)) << "','";
- ss << mSQLConnAsc->EscapeString(string(cn->info_str)) << "'," << cn->Flags1 << "," << cn->Type << "," << cn->TypeFlags << ",";
- ss << cn->Family << "," << cn->Rank << "," << cn->Unknown1 << "," << cn->SpellDataID << "," << cn->Male_DisplayID << "," << cn->Female_DisplayID << ",";
- ss << cn->Male_DisplayID2 << "," << cn->Female_DisplayID2 << "," << cn->unkfloat1 << "," << cn->unkfloat2 << "," << cn->Civilian << "," << cn->Leader << ")";
- mSQLConnAsc->Execute(ss.str());
- printf("%u ", db->Fetch()[0].GetUInt32());
- } while(db->NextRow());
- delete db;
- }
- delete cn;
- }
- void Converter::creature_spawns()
- {
- printf("Converting creature_spawns... \n");
- CreatureSpawn * cs = new CreatureSpawn;
- QueryResult* db = mSQLConnYtdb->Query("SELECT * FROM creature");
- QueryResult* t1;
- stringstream ss;
- if(db)
- {
- do
- {
- cs->bytes = 0;
- cs->bytes1 = 0;
- cs->bytes2 = 0;
- cs->channel_spell = 0;
- cs->channel_target_creature = 0;
- cs->channel_target_go = 0;
- cs->displayid = 0;
- cs->emote_state = 0;
- cs->entry = 0;
- cs->eventid = 0;
- cs->factionid = 0;
- cs->flags = 0;
- cs->id = 0;
- cs->MountedDisplayID = 0;
- cs->movetype = 0;
- cs->map = 0;
- cs->x = 0.0f;
- cs->y = 0.0f;
- cs->z = 0.0f;
- cs->o = 0.0f;
- cs->phase = 0;
- cs->stand_state = 0;
- cs->vehicle = 0;
- t1 = mSQLConnTdb->Query("SELECT `unit_flags`,`VehicleId`,`faction_A` FROM `creature_template` WHERE `entry`=%u", db->Fetch()[1].GetUInt32());
- if(t1)
- {
- cs->flags = t1->Fetch()[0].GetUInt32();
- cs->vehicle = t1->Fetch()[1].GetUInt32();
- cs->factionid = t1->Fetch()[2].GetUInt32();
- delete t1;
- }
- t1 = mSQLConnYtdb->Query("SELECT `bytes1`,`bytes2`,`mount`,`emote` FROM `creature_template_addon` WHERE `entry`=%u", db->Fetch()[1].GetUInt32());
- if(t1)
- {
- cs->bytes1 = t1->Fetch()[0].GetUInt32();
- cs->bytes2 = t1->Fetch()[1].GetUInt32();
- cs->MountedDisplayID = t1->Fetch()[2].GetUInt32();
- cs->emote_state = t1->Fetch()[3].GetUInt32();
- delete t1;
- }
- cs->id = db->Fetch()[0].GetUInt32();
- cs->entry = db->Fetch()[1].GetUInt32();
- cs->map = db->Fetch()[2].GetUInt32();
- cs->displayid = db->Fetch()[5].GetUInt32();
- cs->x = db->Fetch()[7].GetFloat();
- cs->y = db->Fetch()[8].GetFloat();
- cs->z = db->Fetch()[9].GetFloat();
- cs->o = db->Fetch()[10].GetFloat();
- cs->movetype = db->Fetch()[17].GetUInt32();
- cs->phase = db->Fetch()[4].GetInt32();
- ss.clear();
- ss.str ("");
- ss << "INSERT INTO `creature_spawns` (`id`,`entry`,`map`,`position_x`,`position_y`,`position_z`,`orientation`,`movetype`,`displayid`,`faction`,`flags`,";
- ss << "`bytes`,`bytes1`,`bytes2`,`emote_state`,`channel_spell`,`channel_target_sqlid_go`,`channel_target_sqlid_creature`,`standstate`,";
- ss << "`MountedDisplayID`,`phase`,`vehicle`,`eventid`) VALUES(";
- ss << cs->id << "," << cs->entry << "," << cs->map << "," << cs->x << "," << cs->y << "," << cs->z << "," << cs->o << "," << cs->movetype << ",";
- ss << cs->displayid << "," << cs->factionid << "," << cs->flags << "," << cs->bytes << "," << cs->bytes1 << "," << cs->bytes2 << "," << cs->emote_state;
- ss << "," << cs->channel_spell << "," << cs->channel_target_go << "," << cs->channel_target_creature << "," << cs->stand_state << ",";
- ss << cs->MountedDisplayID << "," << cs->phase << "," << cs->vehicle << "," << cs->eventid << ")";
- mSQLConnAsc->Execute(ss.str());
- printf("%u ", db->Fetch()[0].GetUInt32());
- } while(db->NextRow());
- delete db;
- }
- delete cs;
- }
- void Converter::creature_waypoints()
- {
- CreatureWaypoints * cw = new CreatureWaypoints;
- QueryResult* db = mSQLConnYtdb->Query("SELECT * FROM creature_movement");
- stringstream ss;
- if(db)
- {
- do
- {
- cw->spawnid = 0;
- cw->waypointid = 0;
- cw->x = 0.0f;
- cw->y = 0.0f;
- cw->z = 0.0f;
- cw->o = 0.0f;
- cw->waittimes = 0;
- } while(db->NextRow());
- delete db;
- }
- delete cw;
- }
- // mysqlconnectio.cpp
- /* Converter */
- #include "Precomp.h"
- MySQLConnection::MySQLConnection(string host, string user, string password)
- {
- handle = mysql_init(NULL);
- mysql_real_connect(handle, host.c_str(), user.c_str(), password.c_str(), "", 3306, "", 0);
- if(!handle)
- {
- Log.Notice("mySQL", "Error connecting to database on %s", host.c_str());
- return;
- }
- mHost = host;
- mUser = user;
- mPassword = password;
- }
- MySQLConnection::~MySQLConnection()
- {
- if(handle)
- mysql_close(handle);
- }
- void MySQLConnection::Execute(string query)
- {
- //dunno what it does ...leaving untouched
- int result = mysql_query(handle, query.c_str());
- if(result > NULL)
- {
- uint32 errnom = mysql_errno(handle);
- const char * reason = mysql_error(handle);
- Log.Notice("MySQL", "Query Failed: %s\nReason: %s", query.c_str(), reason);
- // Errors which require us to reconnect.
- if(errnom == 2006 || errnom == 2008 || errnom == 2013 || errnom == 2055)
- {
- handle = mysql_init(NULL);
- mysql_real_connect(handle, mHost.c_str(), mUser.c_str(), mPassword.c_str(), "", 3306, "", 0);
- if(!handle)
- return;
- UseDatabase(mDatabase);
- Execute(query);
- }
- }
- }
- void MySQLConnection::QueryASync(mySQLCallback callback, const char * query, ...)
- {
- char* sql = new char[16384];
- va_list vlist;
- va_start(vlist, query);
- vsnprintf(sql, 16384, query, vlist);
- va_end(vlist);
- string querystring = string(sql);
- delete[] sql;
- ASyncQuery* pQuery = new ASyncQuery;
- pQuery->callback = callback;
- pQuery->query = querystring;
- AsynchronousQueries.push_back(pQuery);
- }
- QueryResult* MySQLConnection::Query(const char * query, ...)
- {
- char* sql = new char[16384];
- va_list vlist;
- va_start(vlist, query);
- vsnprintf(sql, 16384, query, vlist);
- va_end(vlist);
- string querystring = string(sql);
- delete[] sql;
- Execute(querystring);
- QueryResult* res;
- MYSQL_RES* pRes = mysql_store_result(handle);
- uint32 uRows = (uint32)mysql_affected_rows(handle);
- uint32 uFields = (uint32)mysql_field_count(handle);
- if(uRows == 0 || uFields == 0 || pRes == 0)
- {
- if(pRes != NULL)
- mysql_free_result(pRes);
- return NULL;
- }
- res = new QueryResult(pRes, uFields, uRows);
- res->NextRow();
- return res;
- }
- string MySQLConnection::EscapeString(string Escape)
- {
- char a2[16384] = {0};
- const char * ret;
- if(mysql_real_escape_string(handle, a2, Escape.c_str(), (unsigned long)Escape.length()) == 0)
- ret = Escape.c_str();
- else
- ret = a2;
- return string(ret);
- }
- void MySQLConnection::UseDatabase(string database)
- {
- mysql_select_db(handle, database.c_str());
- mDatabase = database;
- }
- void MySQLConnection::Update()
- {
- while(true)
- {
- if(AsynchronousQueries.size() > NULL)
- {
- ASyncQuery* pQuery = AsynchronousQueries.front();
- AsynchronousQueries.pop_front();
- QueryResult* pResult = Query(pQuery->query.c_str());
- if(pResult)
- pQuery->callback(pResult);
- }
- Sleep(100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement