// initialize int inter_init_sql (const char *file) { 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; }
// initialize void ipban_init(void) { const char* username; const char* password; const char* hostname; uint16 port; const char* database; const char* 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; } 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; } // establish connections sql_handle = Sql_Malloc(); if( SQL_ERROR == Sql_Connect(sql_handle, 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); ShowStatus("Conectado ao banco de dados ipban '%s'.\n", database); Sql_PrintExtendedInfo(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); }
/// 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); ShowStatus("Connected to main database '%s'.\n", database); Sql_PrintExtendedInfo(sql_handle); return true; }
// 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; }