- Fixed the sleep timers not being removed when the an npc was being unloaded and when reloading scripts.

Ref: http://www.eathena.ws/board/index.php?showtopic=131464

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@9629 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
FlavioJS 2007-01-07 17:59:25 +00:00
parent 3433d36c12
commit da5d22b67f
5 changed files with 37 additions and 14 deletions

View File

@ -4,6 +4,8 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2007/01/07 2007/01/07
* Fixed the sleep timers not being removed when the an npc was being
unloaded and when reloading scripts. [FlavioJS]
* Updated the documentation to match the agitcheck() behavior * Updated the documentation to match the agitcheck() behavior
* Undid the memset->malloc_set replacement * Undid the memset->malloc_set replacement
(let's be compatible and leave such optimizations to system devs, ok?) (let's be compatible and leave such optimizations to system devs, ok?)

View File

@ -18,6 +18,8 @@
#define DIFF_TICK(a,b) ((int)((a)-(b))) #define DIFF_TICK(a,b) ((int)((a)-(b)))
#define INVALID_TIMER -1
// Struct declaration // Struct declaration
typedef int (*TimerFunc)(int,unsigned int,int,int); typedef int (*TimerFunc)(int,unsigned int,int,int);
@ -38,7 +40,7 @@ unsigned int gettick_nocache(void);
unsigned int gettick(void); unsigned int gettick(void);
int add_timer(unsigned int,TimerFunc f,int,int); int add_timer(unsigned int,TimerFunc f,int,int);
int add_timer_interval(unsigned int,TimerFunc f,int,int,int); int add_timer_interval(unsigned int tick, TimerFunc func, int id, int data, int interval);
int delete_timer(int,TimerFunc f); int delete_timer(int,TimerFunc f);
int addtick_timer(int tid,unsigned int tick); int addtick_timer(int tid,unsigned int tick);

View File

@ -1471,6 +1471,7 @@ int npc_unload(struct npc_data *nd)
} }
} }
} }
script_stop_sleeptimers(nd->bl.id);
aFree(nd); aFree(nd);
return 0; return 0;

View File

@ -6,18 +6,6 @@
//#define DEBUG_DISASM //#define DEBUG_DISASM
//#define DEBUG_RUN //#define DEBUG_RUN
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#ifndef _WIN32
#include <sys/time.h>
#endif
#include <time.h>
#include <setjmp.h>
#include "../common/cbasetypes.h" #include "../common/cbasetypes.h"
#include "../common/socket.h" #include "../common/socket.h"
#include "../common/timer.h" #include "../common/timer.h"
@ -53,6 +41,18 @@
#include "irc.h" #include "irc.h"
#include "pet.h" #include "pet.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#ifndef WIN32
#include <sys/time.h>
#endif
#include <time.h>
#include <setjmp.h>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/// Returns the stack_data at the target index /// Returns the stack_data at the target index
@ -2683,6 +2683,21 @@ void run_script(struct script_code *rootscript,int pos,int rid,int oid)
run_script_main(st); run_script_main(st);
} }
void script_stop_sleeptimers(int id)
{
struct script_state* st;
for(;;)
{
st = (struct script_state*)linkdb_erase(&sleep_db,(void*)id);
if( st == NULL )
break; // no more sleep timers
if( st->sleep.timer != INVALID_TIMER )
delete_timer(st->sleep.timer, run_script_timer);
script_free_stack(st->stack);
aFree(st);
}
}
/*========================================== /*==========================================
* Žwèƒm<EFBFBD>[ƒhðsleep_db©ç<EFBFBD>í<EFBFBD>œ * Žwèƒm<EFBFBD>[ƒhðsleep_db©ç<EFBFBD>í<EFBFBD>œ
*------------------------------------------ *------------------------------------------
@ -3439,6 +3454,8 @@ int script_reload()
struct linkdb_node *n = (struct linkdb_node *)sleep_db; struct linkdb_node *n = (struct linkdb_node *)sleep_db;
while(n) { while(n) {
struct script_state *st = (struct script_state *)n->data; struct script_state *st = (struct script_state *)n->data;
if( st->sleep.timer != INVALID_TIMER )
delete_timer(st->sleep.timer, run_script_timer);
script_free_stack(st->stack); script_free_stack(st->stack);
aFree(st); aFree(st);
n = n->next; n = n->next;

View File

@ -73,6 +73,7 @@ void setd_sub(struct script_state *st, struct map_session_data *sd, char *varnam
int run_script_timer(int tid, unsigned int tick, int id, int data); int run_script_timer(int tid, unsigned int tick, int id, int data);
void run_script_main(struct script_state *st); void run_script_main(struct script_state *st);
void script_stop_sleeptimers(int id);
struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n); struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n);
void script_free_stack(struct script_stack*); void script_free_stack(struct script_stack*);
void script_free_code(struct script_code* code); void script_free_code(struct script_code* code);