// 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); }
/** * Destroy the module. * Launched at login-serv end, cleanup db connection or other thing here. */ void ipban_final(void) { if( !login_config.ipban ) return;// ipban disabled if( login_config.ipban_cleanup_interval > 0 ) // release data delete_timer(cleanup_timer_id, ipban_cleanup); ipban_cleanup(0,0,0,0); // always clean up on login-server stop // close connections Sql_Free(sql_handle); sql_handle = NULL; }