diff options
Diffstat (limited to 'src/char')
-rw-r--r-- | src/char/Makefile | 4 | ||||
-rw-r--r-- | src/char/char.c | 13 | ||||
-rw-r--r-- | src/char/int_storage.c | 9 |
3 files changed, 23 insertions, 3 deletions
diff --git a/src/char/Makefile b/src/char/Makefile index d4344a0..841edfd 100644 --- a/src/char/Makefile +++ b/src/char/Makefile @@ -1,8 +1,8 @@ all: char-server txt: char-server -COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o -COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/db.h ../common/lock.h ../common/timer.h ../common/malloc.h +COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/db.o ../common/lock.o ../common/malloc.o ../common/mt_rand.o +COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/db.h ../common/lock.h ../common/timer.h ../common/malloc.h ../common/mt_rand.h char-server: char.o inter.o int_party.o int_guild.o int_storage.o $(COMMON_OBJ) $(CC) -o ../../$@ $> diff --git a/src/char/char.c b/src/char/char.c index 38c1f4a..fbf512e 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -720,8 +720,20 @@ void mmo_char_sync(void) { // Function to save (in a periodic way) datas in files //---------------------------------------------------- int mmo_char_sync_timer(int tid, unsigned int tick, int id, int data) { + pid_t pid; + + // This can take a lot of time. Fork a child to handle the work and return at once + // If we're unable to fork just continue running the function normally + if ((pid = fork()) > 0) + return 0; + mmo_char_sync(); inter_save(); + + // If we're a child we should suicide now. + if (pid == 0) + exit(0); + return 0; } @@ -905,7 +917,6 @@ int make_new_char(int fd, unsigned char *dat) { memcpy(&char_dat[i].save_point, &start_point, sizeof(start_point)); char_num++; - mmo_char_sync(); return i; } diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 2612e17..0829384 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -328,6 +328,10 @@ int inter_storage_save() { FILE *fp; int lock; + + if (!storage_db) + return 1; + if( (fp=lock_fopen(storage_txt,&lock))==NULL ){ printf("int_storage: cant write [%s] !!! data is lost !!!\n",storage_txt); return 1; @@ -342,6 +346,7 @@ int inter_guild_storage_save_sub(void *key,void *data,va_list ap) { char line[65536]; FILE *fp; + if(inter_guild_search(((struct guild_storage *)data)->guild_id) != NULL) { guild_storage_tostr(line,(struct guild_storage *)data); fp=va_arg(ap,FILE *); @@ -356,6 +361,10 @@ int inter_guild_storage_save() { FILE *fp; int lock; + + if (!guild_storage_db) + return 1; + if( (fp=lock_fopen(guild_storage_txt,&lock))==NULL ){ printf("int_storage: cant write [%s] !!! data is lost !!!\n",guild_storage_txt); return 1; |