From 8fd7ea9e4f38bd02b99e4fa42fc2003390a25adc Mon Sep 17 00:00:00 2001 From: FlavioJS Date: Sun, 7 Jan 2007 17:59:25 +0000 Subject: - 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://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9629 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/timer.h | 4 +++- src/map/npc.c | 3 ++- src/map/script.c | 41 +++++++++++++++++++++++++++++------------ src/map/script.h | 1 + 4 files changed, 35 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/common/timer.h b/src/common/timer.h index 7184beec5..243b12e7d 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -18,6 +18,8 @@ #define DIFF_TICK(a,b) ((int)((a)-(b))) +#define INVALID_TIMER -1 + // Struct declaration typedef int (*TimerFunc)(int,unsigned int,int,int); @@ -38,7 +40,7 @@ unsigned int gettick_nocache(void); unsigned int gettick(void); 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 addtick_timer(int tid,unsigned int tick); diff --git a/src/map/npc.c b/src/map/npc.c index b90886da6..802bc3b4a 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1471,6 +1471,7 @@ int npc_unload(struct npc_data *nd) } } } + script_stop_sleeptimers(nd->bl.id); aFree(nd); return 0; @@ -2922,7 +2923,7 @@ int npc_reload (void) //Re-read the NPC Script Events cache. npc_read_event_script(); - + //Execute the OnInit event for freshly loaded npcs. [Skotlex] ShowStatus("Event '"CL_WHITE"OnInit"CL_RESET"' executed with '" CL_WHITE"%d"CL_RESET"' NPCs.\n",npc_event_doall("OnInit")); diff --git a/src/map/script.c b/src/map/script.c index 4b84f6c72..3efa8dbc0 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -6,18 +6,6 @@ //#define DEBUG_DISASM //#define DEBUG_RUN -#include -#include -#include -#include -#include - -#ifndef _WIN32 - #include -#endif -#include -#include - #include "../common/cbasetypes.h" #include "../common/socket.h" #include "../common/timer.h" @@ -53,6 +41,18 @@ #include "irc.h" #include "pet.h" +#include +#include +#include +#include +#include +#ifndef WIN32 + #include +#endif +#include +#include + + /////////////////////////////////////////////////////////////////////////////// /// 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); } +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); + } +} + /*========================================== * 指定ノードをsleep_dbから削除 *------------------------------------------ @@ -3439,6 +3454,8 @@ int script_reload() struct linkdb_node *n = (struct linkdb_node *)sleep_db; while(n) { 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); aFree(st); n = n->next; diff --git a/src/map/script.h b/src/map/script.h index dc75edf56..13b1ef41a 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -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); void run_script_main(struct script_state *st); +void script_stop_sleeptimers(int id); struct linkdb_node* script_erase_sleepdb(struct linkdb_node *n); void script_free_stack(struct script_stack*); void script_free_code(struct script_code* code); -- cgit v1.2.3-70-g09d2