Resolved a client hang in the scenario where the client sent loadendack before the server finished loading all data (bugreport:3700).

Improved the performance of pc_autosave() to stop scanning players after it has already found the player it wanted to save (bugreport:3717).
The 'overweight' status changes (SC_WEIGHT50/SC_WEIGHT90) will now be cleared on logout, to avoid saving them into the database (they get derived from player weight during login anyway).
Improved lock.c on windows to use C's access(0) function instead of doing fopen/fclose when testing for existence of files.
Re-added the 'static' attribute to mapindex_getmapname_ext's buffer; returning the address of a non-static local variable is undefined behavior (see r13901).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14144 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
ultramage 2009-11-13 21:06:21 +00:00
parent f3ca552ec5
commit c517fd305a
5 changed files with 24 additions and 23 deletions

View File

@ -11,21 +11,12 @@
#ifndef WIN32
#include <unistd.h>
#else
#include <windows.h>
#include <io.h>
#define F_OK 0x0
#define R_OK 0x4
#endif
#ifndef WIN32
#define exists(filename) (!access(filename, F_OK))
#else
// could be speed up maybe?
int exists(char *file) {
FILE *fp;
if ((fp = fopen(file,"r")) && fclose(fp) == 0) return 1;
return 0;
}
#endif
#define exists(filename) (!access(filename, F_OK))
// 書き込みファイルの保護処理
// (書き込みが終わるまで、旧ファイルを保管しておく)
@ -33,13 +24,12 @@ int exists(char *file) {
// 新しいファイルの書き込み開始
FILE* lock_fopen (const char* filename, int *info) {
char newfile[512];
FILE *fp;
int no = 0;
// 安全なファイル名を得る(手抜き)
do {
sprintf(newfile, "%s_%04d.tmp", filename, ++no);
} while((fp = fopen(newfile,"r")) && (fclose(fp), no < 9999));
} while(exists(newfile) && no < 9999);
*info = no;
return fopen(newfile,"w");
}

View File

@ -47,7 +47,7 @@ const char* mapindex_getmapname(const char* string, char* output)
/// Result gets placed either into 'buf' or in a static local buffer.
const char* mapindex_getmapname_ext(const char* string, char* output)
{
char buf[MAP_NAME_LENGTH_EXT];
static char buf[MAP_NAME_LENGTH_EXT];
char* dest = (output != NULL) ? output : buf;
size_t len;

View File

@ -13416,15 +13416,21 @@ int clif_parse(int fd)
if ((int)RFIFOREST(fd) < packet_len)
return 0; // not enough data received to form the packet
if (packet_db[packet_ver][cmd].func) {
if (sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
; //Only valid packet when player is not on a map is the finish-loading packet.
if( packet_db[packet_ver][cmd].func == clif_parse_debug )
packet_db[packet_ver][cmd].func(fd, sd);
else
if( packet_db[packet_ver][cmd].func != NULL )
{
if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
; //Only valid packet when there is no session
else
if ((sd && sd->state.active)
|| packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
|| packet_db[packet_ver][cmd].func == clif_parse_debug
) //Only execute the function when there's an active sd (except for debug/wanttoconnect packets)
packet_db[packet_ver][cmd].func(fd, sd);
if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
; //Only valid packet when player is not on a map
else
if( sd && session[sd->fd]->flag.eof )
; //No more packets accepted
else
packet_db[packet_ver][cmd].func(fd, sd);
}
#if DUMP_UNKNOWN_PACKET
else if (battle_config.error_log)

View File

@ -1600,6 +1600,10 @@ int map_quit(struct map_session_data *sd)
status_change_end(&sd->bl,SC_GUILDAURA,-1);
if(sd->sc.data[SC_ENDURE] && sd->sc.data[SC_ENDURE]->val4)
status_change_end(&sd->bl,SC_ENDURE,-1); //No need to save infinite endure.
if(sd->sc.data[SC_WEIGHT50])
status_change_end(&sd->bl,SC_WEIGHT50,-1);
if(sd->sc.data[SC_WEIGHT90])
status_change_end(&sd->bl,SC_WEIGHT90,-1);
if (battle_config.debuff_on_logout&1) {
if(sd->sc.data[SC_ORCISH])
status_change_end(&sd->bl,SC_ORCISH,-1);

View File

@ -1086,7 +1086,7 @@ int pc_reg_received(struct map_session_data *sd)
intif_request_questlog(sd);
#endif
if (!sd->state.connect_new && sd->fd)
if (sd->state.connect_new == 0 && sd->fd)
{ //Character already loaded map! Gotta trigger LoadEndAck manually.
sd->state.connect_new = 1;
clif_parse_LoadEndAck(sd->fd, sd);
@ -7467,6 +7467,7 @@ int pc_autosave(int tid, unsigned int tick, int id, intptr data)
save_flag = 2;
chrif_save(sd,0);
break;
}
mapit_free(iter);