/// establishes database connection static bool account_db_sql_init(AccountDB* self) { AccountDB_SQL* db = (AccountDB_SQL*)self; Sql* sql_handle; const char* username; const char* password; const char* hostname; uint16 port; const char* database; const char* codepage; db->accounts = Sql_Malloc(); sql_handle = db->accounts; if( db->db_hostname[0] != '\0' ) {// local settings username = db->db_username; password = db->db_password; hostname = db->db_hostname; port = db->db_port; database = db->db_database; codepage = db->codepage; } else {// global settings username = db->global_db_username; password = db->global_db_password; hostname = db->global_db_hostname; port = db->global_db_port; database = db->global_db_database; codepage = db->global_codepage; } if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) { Sql_ShowDebug(sql_handle); Sql_Free(db->accounts); db->accounts = NULL; return false; } if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); return true; }
/** * Initialize the module. * Launched at login-serv start, create db or other long scope variable here. */ void ipban_init(void) { const char* username = ipban_db_username; const char* password = ipban_db_password; const char* hostname = ipban_db_hostname; uint16 port = ipban_db_port; const char* database = ipban_db_database; const char* codepage = ipban_codepage; ipban_inited = true; if( !login_config.ipban ) return;// ipban disabled if( ipban_db_hostname[0] != '\0' ) {// local settings username = ipban_db_username; password = ipban_db_password; hostname = ipban_db_hostname; port = ipban_db_port; database = ipban_db_database; codepage = ipban_codepage; } // establish connections sql_handle = Sql_Malloc(); if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) { ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n", username, password, hostname, port, database); Sql_ShowDebug(sql_handle); Sql_Free(sql_handle); exit(EXIT_FAILURE); } ShowInfo("Ipban connection made.\n"); if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); if( login_config.ipban_cleanup_interval > 0 ) { // set up periodic cleanup of connection history and active bans add_timer_func_list(ipban_cleanup, "ipban_cleanup"); cleanup_timer_id = add_timer_interval(gettick()+10, ipban_cleanup, 0, 0, login_config.ipban_cleanup_interval*1000); } else // make sure it gets cleaned up on login-server start regardless of interval-based cleanups ipban_cleanup(0,0,0,0); }
/** * Initialize the module. * Launched at login-serv start, create db or other long scope variable here. * @return true if success else exit execution */ bool loginlog_init(void) { const char* username; const char* password; const char* hostname; uint16 port; const char* database; const char* codepage; if( log_db_hostname[0] != '\0' ) {// local settings username = log_db_username; password = log_db_password; hostname = log_db_hostname; port = log_db_port; database = log_db_database; codepage = log_codepage; } else {// global settings username = global_db_username; password = global_db_password; hostname = global_db_hostname; port = global_db_port; database = global_db_database; codepage = global_codepage; } sql_handle = Sql_Malloc(); if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) { ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n", username, password, hostname, port, database); Sql_ShowDebug(sql_handle); Sql_Free(sql_handle); exit(EXIT_FAILURE); } if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); enabled = true; return true; }
// initialize int inter_init_sql(const char *file) { //int i; ShowInfo ("inter-server inicializando...\n"); inter_config_read(file); //DB connection initialized sql_handle = Sql_Malloc(); ShowInfo("Conectando à DB de chars.... (Character Server)\n"); if( SQL_ERROR == Sql_Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) ) { Sql_ShowDebug(sql_handle); Sql_Free(sql_handle); exit(EXIT_FAILURE); } if( *default_codepage ) { if( SQL_ERROR == Sql_SetEncoding(sql_handle, default_codepage) ) Sql_ShowDebug(sql_handle); } ShowStatus("Conectado ao banco de dados principal '"CL_WHITE"%s"CL_RESET"'.\n", char_server_db); Sql_PrintExtendedInfo(sql_handle); wis_db = idb_alloc(DB_OPT_RELEASE_DATA); inter_guild_sql_init(); inter_storage_sql_init(); inter_party_sql_init(); inter_pet_sql_init(); inter_homunculus_sql_init(); inter_mercenary_sql_init(); inter_elemental_sql_init(); inter_accreg_sql_init(); inter_mail_sql_init(); inter_auction_sql_init(); geoip_readdb(); msg_config_read("conf/msg_athena.conf"); return 0; }
void CDataLoader::ExpireAHItems() { Sql_t* sqlH2 = Sql_Malloc(); Sql_Connect(sqlH2, search_config.mysql_login.c_str(), search_config.mysql_password.c_str(), search_config.mysql_host.c_str(), search_config.mysql_port, search_config.mysql_database.c_str()); std::string qStr = "SELECT T0.id,T0.itemid,T1.stacksize, T0.stack, T0.seller FROM auction_house T0 INNER JOIN item_basic T1 ON \ T0.itemid = T1.itemid WHERE datediff(now(),from_unixtime(date)) >=%u AND buyer_name IS NULL;"; int32 ret = Sql_Query(SqlHandle, qStr.c_str(), search_config.expire_days); int64 expiredAuctions = Sql_NumRows(SqlHandle); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { while (Sql_NextRow(SqlHandle) == SQL_SUCCESS) { std::string qStr2; // iterate through the expired auctions and return them to the seller uint32 saleID = (uint32)Sql_GetUIntData(SqlHandle, 0); uint32 itemID = (uint32)Sql_GetUIntData(SqlHandle, 1); uint8 itemStack = (uint8)Sql_GetUIntData(SqlHandle, 2); uint8 ahStack = (uint8)Sql_GetUIntData(SqlHandle, 3); uint32 seller = (uint32)Sql_GetUIntData(SqlHandle, 4); ret = Sql_Query(sqlH2, "INSERT INTO delivery_box (charid, charname, box, itemid, itemsubid, quantity, senderid, sender) VALUES " "(%u, (select charname from chars where charid=%u), 1, %u, 0, %u, 0, 'AH-Jeuno');", seller, seller, itemID, ahStack == 1 ? itemStack : 1 ); // ShowMessage(cC2, seller, seller, itemID); if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) { // delete the item from the auction house Sql_Query(sqlH2, "DELETE FROM auction_house WHERE id= %u", saleID); } } } else if (ret == SQL_ERROR) { // ShowMessage(CL_RED"SQL ERROR: %s\n\n" CL_RESET, SQL_ERROR); } ShowMessage("Sent %u expired auction house items back to sellers\n", expiredAuctions); Sql_Free(sqlH2); }
void do_final(int code) { aFree((void*)login_config.mysql_host); aFree((void*)login_config.mysql_login); aFree((void*)login_config.mysql_password); aFree((void*)login_config.mysql_database); message_server_close(); if (messageThread.joinable()) { messageThread.join(); } Sql_Free(SqlHandle); timer_final(); socket_final(); malloc_final(); exit(code); }
void do_final(void) { aFree(g_PBuff); aFree(PTempBuff); aFree((void*)map_config.mysql_host); aFree((void*)map_config.mysql_database); itemutils::FreeItemList(); battleutils::FreeWeaponSkillsList(); battleutils::FreeSkillChainDamageModifiers(); petutils::FreePetList(); zoneutils::FreeZoneList(); luautils::free(); delete CTaskMgr::getInstance(); delete CVanaTime::getInstance(); Sql_Free(SqlHandle); }
// initialize int inter_init_sql(const char *file) { //int i; ShowInfo ("interserver initialize...\n"); inter_config_read(file); //DB connection initialized sql_handle = Sql_Malloc(); ShowInfo("Connect Character DB server.... (Character Server)\n"); if( SQL_ERROR == Sql_Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) ) { Sql_ShowDebug(sql_handle); Sql_Free(sql_handle); exit(EXIT_FAILURE); } if( *default_codepage ) { if( SQL_ERROR == Sql_SetEncoding(sql_handle, default_codepage) ) Sql_ShowDebug(sql_handle); } ShowStatus("Connected to main database '%s'.\n", char_server_db); Sql_PrintExtendedInfo(sql_handle); #ifndef TXT_SQL_CONVERT wis_db = idb_alloc(DB_OPT_RELEASE_DATA); inter_guild_sql_init(); inter_storage_sql_init(); inter_party_sql_init(); inter_pet_sql_init(); inter_homunculus_sql_init(); inter_mercenary_sql_init(); inter_accreg_sql_init(); inter_mail_sql_init(); inter_auction_sql_init(); #endif //TXT_SQL_CONVERT return 0; }
/** * Establish the database connection. * @param self: pointer to db */ static bool account_db_sql_init(AccountDB* self) { AccountDB_SQL* db = (AccountDB_SQL*)self; Sql* sql_handle; const char* username = "******"; const char* password = ""; const char* hostname = "127.0.0.1"; uint16 port = 3306; const char* database = "ragnarok"; const char* codepage = ""; db->accounts = Sql_Malloc(); sql_handle = db->accounts; if( db->db_hostname[0] != '\0' ) {// local settings username = db->db_username; password = db->db_password; hostname = db->db_hostname; port = db->db_port; database = db->db_database; codepage = db->codepage; } if( SQL_ERROR == Sql_Connect(sql_handle, username, password, hostname, port, database) ) { ShowError("Couldn't connect with uname='%s',passwd='%s',host='%s',port='%d',database='%s'\n", username, password, hostname, port, database); Sql_ShowDebug(sql_handle); Sql_Free(db->accounts); db->accounts = NULL; return false; } if( codepage[0] != '\0' && SQL_ERROR == Sql_SetEncoding(sql_handle, codepage) ) Sql_ShowDebug(sql_handle); return true; }
// initialize int inter_init_sql(const char *file) { inter_config_defaults(); inter_config_read(file); //DB connection initialized sql_handle = Sql_Malloc(); ShowInfo("Connect Character DB server.... (Character Server)\n"); if( SQL_ERROR == Sql_Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) ) { ShowError("Couldn't connect with username = '******', password = '******', host = '%s', port = '%d', database = '%s'\n", char_server_id, char_server_pw, char_server_ip, char_server_port, char_server_db); Sql_ShowDebug(sql_handle); Sql_Free(sql_handle); exit(EXIT_FAILURE); } if( *default_codepage ) { if( SQL_ERROR == Sql_SetEncoding(sql_handle, default_codepage) ) Sql_ShowDebug(sql_handle); } wis_db = idb_alloc(DB_OPT_RELEASE_DATA); inter_config_readConf(); inter_guild_sql_init(); inter_storage_sql_init(); inter_party_sql_init(); inter_pet_sql_init(); inter_homunculus_sql_init(); inter_mercenary_sql_init(); inter_elemental_sql_init(); inter_mail_sql_init(); inter_auction_sql_init(); inter_clan_init(); geoip_readdb(); return 0; }
// initialize int inter_init_sql(const char *file) { //int i; ShowInfo ("interserver initialize...\n"); inter_config_read(file); //DB connection initialized sql_handle = Sql_Malloc(); ShowInfo("Connect Character DB server.... (Character Server)\n"); if( SQL_ERROR == Sql_Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db) ) { Sql_ShowDebug(sql_handle); Sql_Free(sql_handle); exit(EXIT_FAILURE); } if( *default_codepage ) { if( SQL_ERROR == Sql_SetEncoding(sql_handle, default_codepage) ) Sql_ShowDebug(sql_handle); } wis_db = idb_alloc(DB_OPT_RELEASE_DATA); inter_guild_sql_init(); inter_storage_sql_init(); inter_party_sql_init(); inter_pet_sql_init(); inter_homunculus_sql_init(); inter_mercenary_sql_init(); inter_elemental_sql_init(); inter_accreg_sql_init(); inter_mail_sql_init(); inter_auction_sql_init(); geoip_readdb(); msg_config_read("conf/msg_athena.conf"); return 0; }
bool loginlog_final(void) { Sql_Free(sql_handle); sql_handle = NULL; return true; }
void log_sql_final(void) { ShowStatus("Conex%co com database Log fechada....\n", 198); Sql_Free(logs->mysql_handle); logs->mysql_handle = NULL; }
CInstanceLoader::~CInstanceLoader() { Sql_Free(SqlInstanceHandle); }
int convert_login(void) { Sql* mysql_handle; SqlStmt* stmt; int line_counter = 0; FILE *fp; int account_id, logincount, user_level, state, n, i; char line[2048], userid[2048], pass[2048], lastlogin[2048], sex, email[2048], error_message[2048], last_ip[2048], memo[2048]; int ban_until_time, connect_until_time; char dummy[2048]; mysql_handle = Sql_Malloc(); if ( SQL_ERROR == Sql_Connect(mysql_handle, db_server_id, db_server_pw, db_server_ip, db_server_port, db_server_logindb) ) { Sql_ShowDebug(mysql_handle); Sql_Free(mysql_handle); exit(EXIT_FAILURE); } ShowStatus("Connect: Success!\n"); ShowStatus("Convert start...\n"); fp = fopen(ACCOUNT_TXT_NAME,"r"); if(fp == NULL) return 0; while(fgets(line,sizeof(line),fp) != NULL) { line_counter++; if(line[0]=='/' && line[1]=='/') continue; i = sscanf(line, "%d\t%[^\t]\t%[^\t]\t%[^\t]\t%c\t%d\t%d\t%[^\t]\t%[^\t]\t%d\t%[^\t]\t%[^\t]\t%d\t%[^\r\n]%n", &account_id, userid, pass, lastlogin, &sex, &logincount, &state, email, error_message, &connect_until_time, last_ip, memo, &ban_until_time, dummy, &n); if (i < 13) { ShowWarning("Skipping incompatible data on line %d\n", line_counter); continue; } if (i > 13) ShowWarning("Reading login account variables is not implemented, data will be lost! (line %d)\n", line_counter); user_level = isGM(account_id); ShowInfo("Converting user (id: %d, name: %s, gm level: %d)\n", account_id, userid, user_level); stmt = SqlStmt_Malloc(mysql_handle); if( SQL_ERROR == SqlStmt_Prepare(stmt, "REPLACE INTO `login` " "(`account_id`, `userid`, `user_pass`, `lastlogin`, `sex`, `logincount`, `email`, `level`, `error_message`, `connect_until`, `last_ip`, `memo`, `ban_until`, `state`) " "VALUES " "(%d, ?, ?, '%s', '%c', %d, '%s', %d, '%s', %d, '%s', '%s', %d, %d)", account_id, lastlogin, sex, logincount, email, user_level, error_message, connect_until_time, last_ip, memo, ban_until_time, state) || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_STRING, userid, strnlen(userid, 255)) || SQL_ERROR == SqlStmt_BindParam(stmt, 1, SQLDT_STRING, pass, strnlen(pass, 32)) || SQL_ERROR == SqlStmt_Execute(stmt) ) { SqlStmt_ShowDebug(stmt); } SqlStmt_Free(stmt); //TODO: parse the rest of the line to read the login-stored account variables, and import them to `global_reg_value` // then remove the 'dummy' buffer } fclose(fp); Sql_Free(mysql_handle); ShowStatus("Convert end...\n"); return 0; }
CDataLoader::~CDataLoader() { Sql_Free(SqlHandle); }