From 4673fd3ca06010e74f8223486b0f34e58c7b0a7e Mon Sep 17 00:00:00 2001 From: Dennis Friis Date: Tue, 7 Jul 2009 00:52:08 +0200 Subject: Fixes to socket system to make it cope better with fd depletion. Also added timeout for fullconnect, secured map server from stateless connections. --- src/char/char.c | 27 ++++++++++++++------------- src/char/int_guild.c | 12 ++++++------ src/char/int_party.c | 4 ++-- src/char/int_storage.c | 8 ++++---- src/char/inter.c | 12 ++++++------ 5 files changed, 32 insertions(+), 31 deletions(-) (limited to 'src/char') diff --git a/src/char/char.c b/src/char/char.c index 3035ce1..37580b6 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -122,7 +122,7 @@ int char_log(char *fmt, ...) { va_start(ap, fmt); - logfp = fopen(char_log_filename, "a"); + logfp = fopen_(char_log_filename, "a"); if (logfp) { if (fmt[0] == '\0') // jump a line if no message fprintf(logfp, RETCODE); @@ -132,7 +132,7 @@ int char_log(char *fmt, ...) { sprintf(tmpstr + 19, ".%03d: %s", (int)tv.tv_usec / 1000, fmt); vfprintf(logfp, tmpstr, ap); } - fclose(logfp); + fclose_(logfp); } va_end(ap); @@ -558,7 +558,7 @@ int mmo_char_init(void) { char_num = 0; - fp = fopen(char_txt, "r"); + fp = fopen_(char_txt, "r"); if (fp == NULL) { printf("Characters file not found: %s.\n", char_txt); char_log("Characters file not found: %s." RETCODE, char_txt); @@ -637,7 +637,7 @@ int mmo_char_init(void) { char_log("%s", line); } } - fclose(fp); + fclose_(fp); if (char_num == 0) { printf("mmo_char_init: No character found in %s.\n", char_txt); @@ -1091,9 +1091,9 @@ void create_online_files(void) { } // write files - fp = fopen(online_txt_filename, "w"); + fp = fopen_(online_txt_filename, "w"); if (fp != NULL) { - fp2 = fopen(online_html_filename, "w"); + fp2 = fopen_(online_html_filename, "w"); if (fp2 != NULL) { // get time time(&time_server); // get time in seconds since 1/1/1970 @@ -1256,9 +1256,9 @@ void create_online_files(void) { } fprintf(fp2, " \n"); fprintf(fp2, "\n"); - fclose(fp2); + fclose_(fp2); } - fclose(fp); + fclose_(fp); } return; @@ -2975,7 +2975,8 @@ int send_users_tologin(int tid, unsigned int tick, int id, int data) { int check_connect_login_server(int tid, unsigned int tick, int id, int data) { if (login_fd <= 0 || session[login_fd] == NULL) { printf("Attempt to connect to login-server...\n"); - login_fd = make_connection(login_ip, login_port); + if ((login_fd = make_connection(login_ip, login_port)) < 0) + return 0; session[login_fd]->func_parse = parse_tologin; realloc_fifo(login_fd, FIFOSIZE_SERVERLINK, FIFOSIZE_SERVERLINK); WFIFOW(login_fd,0) = 0x2710; @@ -3027,7 +3028,7 @@ int lan_config_read(const char *lancfgName) { for(j = 0; j < 4; j++) subnetmaski[j] = 255; - fp = fopen(lancfgName, "r"); + fp = fopen_(lancfgName, "r"); if (fp == NULL) { printf("LAN support configuration file not found: %s\n", lancfgName); @@ -3079,7 +3080,7 @@ int lan_config_read(const char *lancfgName) { printf("Sub-network mask of the map-server: %d.%d.%d.%d.\n", subnetmaski[0], subnetmaski[1], subnetmaski[2], subnetmaski[3]); } } - fclose(fp); + fclose_(fp); // sub-network check of the map-server { @@ -3101,7 +3102,7 @@ int lan_config_read(const char *lancfgName) { int char_config_read(const char *cfgName) { struct hostent *h = NULL; char line[1024], w1[1024], w2[1024]; - FILE *fp = fopen(cfgName, "r"); + FILE *fp = fopen_(cfgName, "r"); if (fp == NULL) { printf("Configuration file not found: %s.\n", cfgName); @@ -3231,7 +3232,7 @@ int char_config_read(const char *cfgName) { char_config_read(w2); } } - fclose(fp); + fclose_(fp); return 0; } diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 665e017..f84964c 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -357,7 +357,7 @@ int inter_guild_readdb() { FILE *fp; char line[1024]; - fp = fopen("db/exp_guild.txt", "r"); + fp = fopen_("db/exp_guild.txt", "r"); if (fp == NULL) { printf("can't read db/exp_guild.txt\n"); return 1; @@ -369,7 +369,7 @@ int inter_guild_readdb() { guild_exp[i] = atoi(line); i++; } - fclose(fp); + fclose_(fp); return 0; } @@ -387,7 +387,7 @@ int inter_guild_init() { guild_db = numdb_init(); castle_db = numdb_init(); - if ((fp = fopen(guild_txt,"r")) == NULL) + if ((fp = fopen_(guild_txt,"r")) == NULL) return 1; while(fgets(line, sizeof(line)-1, fp)) { j = 0; @@ -414,12 +414,12 @@ int inter_guild_init() { } c++; } - fclose(fp); + fclose_(fp); // printf("int_guild: %s read done (%d guilds)\n", guild_txt, c); c = 0;//カウンタ初期化 - if ((fp = fopen(castle_txt, "r")) == NULL) { + if ((fp = fopen_(castle_txt, "r")) == NULL) { return 1; } @@ -481,7 +481,7 @@ int inter_guild_init() { return 0; } - fclose(fp); + fclose_(fp); return 0; } diff --git a/src/char/int_party.c b/src/char/int_party.c index 0fd58fa..f0b06b6 100644 --- a/src/char/int_party.c +++ b/src/char/int_party.c @@ -84,7 +84,7 @@ int inter_party_init() { party_db = numdb_init(); - if ((fp = fopen(party_txt, "r")) == NULL) + if ((fp = fopen_(party_txt, "r")) == NULL) return 1; while(fgets(line, sizeof(line) - 1, fp)) { @@ -111,7 +111,7 @@ int inter_party_init() { } c++; } - fclose(fp); + fclose_(fp); // printf("int_party: %s read done (%d parties)\n", party_txt, c); return 0; diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 8f7f9d7..2612e17 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -240,7 +240,7 @@ int inter_storage_init() storage_db = numdb_init(); - fp=fopen(storage_txt,"r"); + fp=fopen_(storage_txt,"r"); if(fp==NULL){ printf("cant't read : %s\n",storage_txt); return 1; @@ -263,12 +263,12 @@ int inter_storage_init() } c++; } - fclose(fp); + fclose_(fp); c = 0; guild_storage_db = numdb_init(); - fp=fopen(guild_storage_txt,"r"); + fp=fopen_(guild_storage_txt,"r"); if(fp==NULL){ printf("cant't read : %s\n",guild_storage_txt); return 1; @@ -291,7 +291,7 @@ int inter_storage_init() } c++; } - fclose(fp); + fclose_(fp); return 0; } diff --git a/src/char/inter.c b/src/char/inter.c index 98e7ad0..6e50432 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -108,7 +108,7 @@ int inter_accreg_init() { accreg_db = numdb_init(); - if( (fp = fopen(accreg_txt, "r")) == NULL) + if( (fp = fopen_(accreg_txt, "r")) == NULL) return 1; while(fgets(line, sizeof(line)-1, fp)){ line[sizeof(line)-1] = '\0'; @@ -126,7 +126,7 @@ int inter_accreg_init() { } c++; } - fclose(fp); + fclose_(fp); // printf("inter: %s read done (%d)\n", accreg_txt, c); return 0; @@ -173,7 +173,7 @@ int inter_config_read(const char *cfgName) { char line[1024], w1[1024], w2[1024]; FILE *fp; - fp = fopen(cfgName, "r"); + fp = fopen_(cfgName, "r"); if (fp == NULL) { printf("file not found: %s\n", cfgName); return 1; @@ -208,7 +208,7 @@ int inter_config_read(const char *cfgName) { inter_config_read(w2); } } - fclose(fp); + fclose_(fp); return 0; } @@ -219,10 +219,10 @@ int inter_log(char *fmt,...) { va_list ap; va_start(ap,fmt); - logfp = fopen(inter_log_filename, "a"); + logfp = fopen_(inter_log_filename, "a"); if (logfp) { vfprintf(logfp, fmt, ap); - fclose(logfp); + fclose_(logfp); } va_end(ap); -- cgit v1.2.3-60-g2f50