diff --git a/Changelog.txt b/Changelog.txt index 48bef41935..fdc84ae6fa 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,6 +1,7 @@ Date Added 12/18 + * Fixed import command in inter_athena.conf file [Ajarn] * Changed few God-items to fit kRO 12/7/04 Patch [Aria] * Readded my own npc [Aria] * Fixed SQL char creation, it now follows MySQL standards and uses mysql_last_insert_id [Ajarn] diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 053b335101..91bc604a38 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -2842,6 +2842,9 @@ void sql_config_read(const char *cfgName){ /* Kalaspuff, to get login_db */ }else if(strcmpi(w1,"lowest_gm_level")==0){ lowest_gm_level = atoi(w2); printf("set lowest_gm_level : %s\n",w2); + //support the import command, just like any other config + }else if(strcmpi(w1,"import")==0){ + sql_config_read(w2); } } fclose(fp); diff --git a/src/login_sql/login.c b/src/login_sql/login.c index c7e0a79c75..3785d33d86 100644 --- a/src/login_sql/login.c +++ b/src/login_sql/login.c @@ -42,7 +42,7 @@ MYSQL_RES* sql_res ; MYSQL_ROW sql_row ; // It's to check IP of a player between login-server and char-server (part of anti-hacking system) -int check_ip_flag; +int check_ip_flag; // Login's FD int login_fd; @@ -80,10 +80,10 @@ int flush_time=100; char date_format[32] = "%Y-%m-%d %H:%M:%S"; // minimum level of player/GM (0: player, 1-99: gm) to connect on the server -int min_level_to_connect = 0; +int min_level_to_connect = 0; // It's to check IP of a player between login-server and char-server (part of anti-hacking system) -int check_ip_flag = 1; +int check_ip_flag = 1; // Dynamic IP Ban config int ipban = 1; @@ -102,7 +102,7 @@ char login_server_pw[16] = "ragnarok"; char login_server_db[16] = "ragnarok"; int use_md5_passwds = 0; -// MySQL custom table and column names +// MySQL custom table and column names char login_db[32] = "login"; char loginlog_db[32] = "loginlog"; char login_db_account_id[32] = "account_id"; @@ -141,7 +141,7 @@ int is_user_online(int account_id) { p = numdb_search(online_db, account_id); if (p == NULL) return 0; - + #ifdef DEBUG printf("Acccount [%d] Online\n",*p); #endif @@ -170,7 +170,7 @@ void sql_query(char* query,char function[32]) { // printf("Uncontrolled param: %s",&mysql_handle); // if (strcmp(mysql_error(&mysql_handle),"CR_COMMANDS_OUT_OF_SYNC") !=0) exit(1); } - + strcpy(prev_query,query); } @@ -181,7 +181,7 @@ void sql_query(char* query,char function[32]) { unsigned char isGM(int account_id) { unsigned char *level; - + level = numdb_search(gm_db, account_id); if (level == NULL) return 0; @@ -209,38 +209,38 @@ void do_final_gmdb(void) { void read_GMs(int fd) { unsigned char *level; int i=0; - + if(gm_db) do_final_gmdb(); - + gm_db = numdb_init(); - + sprintf(tmpsql,"SELECT `%s`,`%s` FROM `%s` WHERE `%s` > '%d'", login_db_account_id, login_db_level, login_db,login_db_level,lowest_gm_level); sql_query(tmpsql,"read_GMs"); - + WFIFOW(fd, 0) = 0x2732; - + if ((sql_res = mysql_store_result(&mysql_handle))) { for(i=0;(sql_row = mysql_fetch_row(sql_res));i++) { level = malloc(sizeof(unsigned char)); - + if( (*level = atoi(sql_row[1])) > 99 ) *level = 99; numdb_insert(gm_db, atoi(sql_row[0]), level); - + WFIFOL(fd,6+5*i) = atoi(sql_row[0]); WFIFOB(fd,10+5*i) = *level; } - + WFIFOW(fd,2) = i; } - + WFIFOSET(fd,6+5*i); - + mysql_free_result(sql_res); -} - +} + //--------------------------------------------------- // E-mail check: return 0 (not correct) or 1 (valid). @@ -305,7 +305,7 @@ int mmo_auth_sqldb_init(void) { } else { printf("Connected to MySQL Server\n"); } - + //delete all server status sprintf(tmpsql,"TRUNCATE TABLE `sstatus`"); sql_query(tmpsql,"mmo_db_close"); @@ -348,12 +348,12 @@ int mmo_auth( struct mmo_account* account , int fd){ char tmpstr[256]; char t_uid[32], t_pass[32]; char user_password[32]; - + char ip[16]; - + int encpasswdok = 0; int state; - + #ifdef PASSWORDENC char logbuf[1024], *p = logbuf; char md5str[64],md5bin[32]; @@ -362,7 +362,7 @@ int mmo_auth( struct mmo_account* account , int fd){ unsigned char *sin_addr = (unsigned char *)&session[fd]->client_addr.sin_addr; sprintf(ip, "%d.%d.%d.%d", sin_addr[0], sin_addr[1], sin_addr[2], sin_addr[3]); - + #ifdef DEBUG printf ("Starting auth for [%s]...\n",ip); #endif @@ -421,7 +421,7 @@ int mmo_auth( struct mmo_account* account , int fd){ strftime(tmpstr, 20, date_format, localtime(&account->ban_until_time)); tmpstr[19] = '\0'; if (account->ban_until_time > time(NULL)) { // always banned - mysql_free_result(sql_res); + mysql_free_result(sql_res); return 7; } else { // ban is finished // reset the ban time @@ -434,7 +434,7 @@ int mmo_auth( struct mmo_account* account , int fd){ break; } } - + if (atol(sql_row[6]) != 0 && atol(sql_row[6]) < time(NULL)) { return 2; // 2 = This ID is expired } @@ -462,10 +462,10 @@ int mmo_auth( struct mmo_account* account , int fd){ #ifdef DEBUG printf ("Starting md5calc..\n"); #endif - + if (j > 2) j = 1; - + do { if (j == 1) { sprintf(md5str, "%s%s", md5key,sql_row[2]); @@ -473,14 +473,14 @@ int mmo_auth( struct mmo_account* account , int fd){ sprintf(md5str, "%s%s", sql_row[2], md5key); } else md5str[0] = 0; - #ifdef DEBUG + #ifdef DEBUG printf("j: [%d] mdstr: [%s]\n", j, md5str); #endif - + MD5_String2binary(md5str, md5bin); encpasswdok = (memcmp(user_password, md5bin, 16) == 0); } while (j < 2 && !encpasswdok && (j++) != account->passwdenc); - + #ifdef DEBUG printf("key [%s] md5 [%s] ", md5key, md5str); printf("client [%s] accountpass [%s]\n", user_password, sql_row[2]); @@ -494,24 +494,24 @@ int mmo_auth( struct mmo_account* account , int fd){ printf ("auth failed pass error %s %s %s" RETCODE, tmpstr, account->userid, user_password); #endif #ifdef PASSWORDENC - } else { + } else { p += sprintf(p, "auth failed pass error %s %s recv-md5[", tmpstr, account->userid); - + for(j = 0; j < 16; j++) p += sprintf(p, "%02x", ((unsigned char *)user_password)[j]); - + p += sprintf(p, "] calc-md5["); - + for(j = 0; j < 16; j++) p += sprintf(p, "%02x", ((unsigned char *)md5bin)[j]); - + p += sprintf(p, "] md5key["); - + for(j = 0; j < md5keylen; j++) p += sprintf(p, "%02x", ((unsigned char *)md5key)[j]); - + p += sprintf(p, "]" RETCODE); - + #ifdef DEBUG printf("%s\n", p); #endif @@ -534,7 +534,7 @@ int mmo_auth( struct mmo_account* account , int fd){ sprintf(tmpsql, "UPDATE `%s` SET `lastlogin` = NOW(), `logincount`=`logincount` +1, `last_ip`='%s' WHERE BINARY `%s` = '%s'", login_db, ip, login_db_userid, sql_row[1]); sql_query(tmpsql,"mmo_auth"); - + mysql_free_result(sql_res) ; //resource free return -1; @@ -549,7 +549,7 @@ int lan_ip_check(unsigned char *p) { int lancharip[4]; unsigned int k0, k1, k2, k3; - + sscanf(lan_char_ip, "%d.%d.%d.%d", &k0, &k1, &k2, &k3); lancharip[0] = k0; lancharip[1] = k1; lancharip[2] = k2; lancharip[3] = k3; @@ -561,7 +561,7 @@ int lan_ip_check(unsigned char *p) { #ifdef DEBUG printf("LAN check: %s.\n", (lancheck) ? "\033[1;32mLAN\033[0m" : "\033[1;31mWAN\033[0m"); #endif - + return lancheck; } @@ -584,24 +584,24 @@ int ip_ban_check(int tid, unsigned int tick, int id, int data){ //------------------------------------ int parse_console(char *buf) { char *type,*command; - + type = (char *)malloc(64); command = (char *)malloc(64); - + memset(type,0,64); memset(command,0,64); - + printf("Console: %s\n",buf); - + if ( sscanf(buf, "%[^:]:%[^\n]", type , command ) < 2 ) sscanf(buf,"%[^\n]",type); - + printf("Type of command: %s || Command: %s \n",type,command); - + if(buf) free(buf); if(type) free(type); if(command) free(command); - + return 0; } @@ -731,15 +731,15 @@ int login_config_read(const char *cfgName){ else if(strcmpi(w1,"dynamic_pass_failure_ban_how_long")==0){ dynamic_pass_failure_ban_how_long=atoi(w2); printf ("set dynamic_pass_failure_ban_how_long : %d\n",dynamic_pass_failure_ban_how_long); - } + } else if(strcmpi(w1,"anti_freeze_enable")==0){ anti_freeze_enable = config_switch(w2); - } + } else if (strcmpi(w1, "anti_freeze_interval") == 0) { ANTI_FREEZE_INTERVAL = atoi(w2); if (ANTI_FREEZE_INTERVAL < 5) ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds - } + } else if (strcmpi(w1, "import") == 0) { login_config_read(w2); } else if(strcmpi(w1,"imalive_on")==0) { //Added by Mugendai for I'm Alive mod @@ -853,6 +853,10 @@ void sql_config_read(const char *cfgName){ /* Kalaspuff, to get login_db */ else if(strcmpi(w1,"lowest_gm_level")==0){ lowest_gm_level = atoi(w2); } + //support the import command, just like any other config + else if(strcmpi(w1,"import")==0){ + sql_config_read(w2); + } } fclose(fp); printf("reading SQL configuration done.....\n"); @@ -883,20 +887,20 @@ int do_init(int argc,char **argv){ //read login configuration login_config_read( (argc>1)?argv[1]:LOGIN_CONF_NAME ); - + //read SQL configuration sql_config_read(SQL_CONF_NAME); - + //read LAN support configuation login_lan_config_read((argc > 1) ? argv[1] : LAN_CONF_NAME); - + //Generate Passworded Key. #ifdef DEBUG printf ("memset value: [0] var: [md5key] \n"); #endif - + memset(md5key, 0, sizeof(md5key)); - + #ifdef DEBUG printf ("memset var: [md5key] complete\n"); printf ("Set MD5 key length\n"); @@ -905,23 +909,23 @@ int do_init(int argc,char **argv){ md5keylen=rand()%4+12; for(i=0;i=BL_LIST_MAX) { if(battle_config.error_log) printf("map_foreachinarea: *WARNING* block count too many!\n"); } map_freeblock_lock(); // メモリからの解放を禁止する - + for(i=blockcount;iprev) // 有効かどうかチェック func(bl_list[i],ap); @@ -544,7 +544,7 @@ void map_foreachinmovearea(int (*func)(struct block_list*,va_list),int m,int x0, } map_freeblock_lock(); // メモリからの解放を禁止する - + for(i=blockcount;iprev) // 有効かどうかチェック func(bl_list[i],ap); @@ -592,7 +592,7 @@ void map_foreachincell(int (*func)(struct block_list*,va_list),int m,int x,int y if(bl && bl->x==x && bl->y==y && bl_list_count=BL_LIST_MAX) { if(battle_config.error_log) @@ -600,7 +600,7 @@ void map_foreachincell(int (*func)(struct block_list*,va_list),int m,int x,int y } map_freeblock_lock(); // メモリからの解放を禁止する - + for(i=blockcount;iprev) // 有効かどうかチェック func(bl_list[i],ap); @@ -679,7 +679,7 @@ int map_delobject(int id) { if(obj==NULL) return 0; - map_delobjectnofree(id); + map_delobjectnofree(id); map_freeblock(obj); return 0; @@ -955,7 +955,7 @@ int map_quit(struct map_session_data *sd) { if(sd->chatID) // チャットから出る chat_leavechat(sd); - + if(sd->trade_partner) // 取引を中断する trade_tradecancel(sd); @@ -1180,7 +1180,7 @@ int map_addnpc(int m,struct npc_data *nd) { void map_removenpc(void) { int i,m,n=0; - + for(m=0;mfd = 0; strcpy( sd->status.name , "console"); - + type = (char *)malloc(64); command = (char *)malloc(64); map = (char *)malloc(64); buf2 = (char *)malloc(72); - + memset(type,0,64); memset(command,0,64); memset(map,0,64); - memset(buf2,0,72); - + memset(buf2,0,72); + if ( ( n = sscanf(buf, "%[^:]:%[^:]:%99s %d %d[^\n]", type , command , map , &x , &y )) < 5 ) if ( ( n = sscanf(buf, "%[^:]:%[^\n]", type , command )) < 2 ) n = sscanf(buf,"%[^\n]",type); - + if ( n == 5 ) { if (x <= 0) { x = rand() % 399 + 1; sd->bl.x = x; } else { sd->bl.x = x; - } - + } + if (y <= 0) { y = rand() % 399 + 1; sd->bl.y = y; } else { sd->bl.y = y; - } - + } + m = map_mapname2mapid(map); if ( m >= 0 ) sd->bl.m = m; else { printf("Console: Unknown map\n"); goto end; - } - } + } + } printf("Type of command: %s || Command: %s || Map: %s Coords: %d %d\n",type,command,map,x,y); - + if ( strcmpi("admin",type) == 0 && n == 5 ) { sprintf(buf2,"console: %s",command); if( is_atcommand(sd->fd,sd,buf2,99) == AtCommand_None ) @@ -1778,8 +1778,8 @@ int parse_console(char *buf) { printf("IE: @spawn\n"); printf("To shutdown the server:\n"); printf("server:shutdown\n"); - } - + } + end: free(buf); free(type); @@ -1787,7 +1787,7 @@ int parse_console(char *buf) { free(map); free(buf2); free(sd); - + return 0; } @@ -1816,7 +1816,7 @@ int map_config_read(char *cfgName) { } else if (strcmpi(w1, "char_ip") == 0) { char_ip_set_ = 1; h = gethostbyname (w2); - if(h != NULL) { + if(h != NULL) { snprintf(tmp_output,sizeof(tmp_output),"Character server IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]); ShowInfo(tmp_output); sprintf(w2,"%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]); @@ -1827,7 +1827,7 @@ int map_config_read(char *cfgName) { } else if (strcmpi(w1, "map_ip") == 0) { map_ip_set_ = 1; h = gethostbyname (w2); - if (h != NULL) { + if (h != NULL) { printf("Map server IP address : %s -> %d.%d.%d.%d\n", w2, (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]); sprintf(w2, "%d.%d.%d.%d", (unsigned char)h->h_addr[0], (unsigned char)h->h_addr[1], (unsigned char)h->h_addr[2], (unsigned char)h->h_addr[3]); } @@ -1904,9 +1904,9 @@ int map_sql_init(void){ else { printf ("connect success! (Map Server Connection)\n"); } - + mysql_init(&lmysql_handle); - + //DB connection start printf("Connect Login DB Server....\n"); if(!mysql_real_connect(&lmysql_handle, login_server_ip, login_server_id, login_server_pw, @@ -1918,7 +1918,7 @@ int map_sql_init(void){ else { printf ("connect success! (Login Server Connection)\n"); } - + if(battle_config.mail_system) { // mail system [Valaris] mysql_init(&mail_handle); if(!mysql_real_connect(&mail_handle, map_server_ip, map_server_id, map_server_pw, @@ -1941,9 +1941,9 @@ int map_sql_close(void){ } int log_sql_init(void){ - + mysql_init(&mmysql_handle); - + //DB connection start printf("\033[1;29m[SQL]\033[0;0m: Connecting to Log Database \033[1;29m%s\033[0;0m At \033[1;29m%s\033[0;0m...\n",log_db,log_db_ip); if(!mysql_real_connect(&mmysql_handle, log_db_ip, log_db_id, log_db_pw, @@ -1986,7 +1986,7 @@ int sql_config_read(char *cfgName) } else if(strcmpi(w1,"login_db")==0){ strcpy(login_db,w2); } else if (strcmpi(w1, "char_db") == 0) { - strcpy(char_db, w2); + strcpy(char_db, w2); } else if(strcmpi(w1,"gm_db_level")==0){ strcpy(gm_db_level,w2); } else if(strcmpi(w1,"gm_db_account_id")==0){ @@ -2047,7 +2047,10 @@ int sql_config_read(char *cfgName) strcpy(log_db_pw, w2); } else if(strcmpi(w1,"log_db_port")==0) { log_db_port = atoi(w2); - } + //support the import command, just like any other config + } else if(strcmpi(w1,"import")==0){ + sql_config_read(w2); + } } fclose(fp); @@ -2080,7 +2083,7 @@ int online_timer(int tid,unsigned int tick,int id,int data) char_online_check(); - check_online_timer=add_timer(gettick()+CHECK_INTERVAL,online_timer,0,0); + check_online_timer=add_timer(gettick()+CHECK_INTERVAL,online_timer,0,0); return 0; } @@ -2093,7 +2096,7 @@ void char_online_check(void) do_reset_online(); for(i=0;isession_data) && sd && sd->state.auth && + if (session[i] && (sd = session[i]->session_data) && sd && sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd))) if(sd->status.char_id) { sprintf(tmp_sql,"UPDATE `%s` SET `online`='1' WHERE `char_id`='%d'", char_db, sd->status.char_id); @@ -2103,7 +2106,7 @@ void char_online_check(void) } } - + if(check_online_timer && check_online_timer != -1) { delete_timer(check_online_timer,online_timer); add_timer(gettick()+CHECK_INTERVAL,online_timer,0,0); @@ -2176,7 +2179,7 @@ void do_final(void) { map_foreachinarea(cleanup_sub, map_id, 0, 0, map[map_id].xs, map[map_id].ys, 0, 0); } - for (i = 0; i < fd_max; i++) + for (i = 0; i < fd_max; i++) delete_session(i); map_removenpc(); @@ -2257,20 +2260,20 @@ int do_init(int argc, char *argv[]) { map_config_read(MAP_CONF_NAME); - if ((naddr_ == 0) && (map_ip_set_ == 0 || char_ip_set_ == 0)) { + if ((naddr_ == 0) && (map_ip_set_ == 0 || char_ip_set_ == 0)) { printf("\nUnable to determine your IP address... please edit\n"); printf("the map_athena.conf file and set it.\n"); printf("(127.0.0.1 is valid if you have no network interface)\n"); } - if (map_ip_set_ == 0 || char_ip_set_ == 0) { + if (map_ip_set_ == 0 || char_ip_set_ == 0) { // The map server should know what IP address it is running on // - MouseJstr int localaddr = ntohl(addr_[0]); unsigned char *ptr = (unsigned char *) &localaddr; char buf[16]; sprintf(buf, "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]);; - if (naddr_ != 1) + if (naddr_ != 1) printf("Multiple interfaces detected.. using %s as our IP address\n", buf); else printf("Defaulting to %s as our IP address\n", buf); @@ -2279,10 +2282,10 @@ int do_init(int argc, char *argv[]) { if (char_ip_set_ == 0) chrif_setip(buf); - if (ptr[0] == 192 && ptr[1] == 168) + if (ptr[0] == 192 && ptr[1] == 168) printf("\nFirewall detected.. \n edit lan_support.conf and map_athena.conf\n\n"); - } - + } + battle_config_read(BATTLE_CONF_FILENAME); msg_config_read(MSG_CONF_NAME); atcommand_config_read(ATCOMMAND_CONF_FILENAME); @@ -2316,7 +2319,7 @@ int do_init(int argc, char *argv[]) { } fclose(data_conf); } // end of reading grf-files.txt for AFMs - + map_readallmap(); @@ -2330,7 +2333,7 @@ int do_init(int argc, char *argv[]) { #ifndef TXT_ONLY // online status timer, checks every hour [Valaris] add_timer_func_list(online_timer, "online_timer"); - check_online_timer=add_timer(gettick()+CHECK_INTERVAL,online_timer,0,0); + check_online_timer=add_timer(gettick()+CHECK_INTERVAL,online_timer,0,0); #endif /* not TXT_ONLY */ do_init_chrif(); @@ -2347,11 +2350,11 @@ int do_init(int argc, char *argv[]) { do_init_pet(); #ifndef TXT_ONLY /* mail system [Valaris] */ - if(battle_config.mail_system) + if(battle_config.mail_system) do_init_mail(); - if (log_config.branch || log_config.drop || log_config.mvpdrop || - log_config.present || log_config.produce || log_config.refine || + if (log_config.branch || log_config.drop || log_config.mvpdrop || + log_config.present || log_config.produce || log_config.refine || log_config.trade) { log_sql_init(); @@ -2359,22 +2362,22 @@ int do_init(int argc, char *argv[]) { #endif /* not TXT_ONLY */ npc_event_do_oninit(); // npcのOnInitイベント実行 - + if ( console ) { set_defaultconsoleparse(parse_console); start_console(); } - + if (battle_config.pk_mode == 1) printf("The server is running in \033[1;31mPK Mode\033[0m.\n"); - + //Added for Mugendais I'm Alive mod if (imalive_on) add_timer_interval(gettick()+10, imalive_timer,0,0,imalive_time*1000); printf("The map-server is \033[1;32mready\033[0m (Server is listening on the port %d).\n\n", map_port); ticks = gettick(); - + return 0; }