diff options
author | Haru <haru@dotalux.com> | 2015-08-11 01:47:15 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2015-08-15 00:51:44 +0200 |
commit | 22bd368e5d4d8d61a7189d03f52c3afd90c0729e (patch) | |
tree | b8617bdfe901c41ff006d160b5bbceadb52f7bfb /src | |
parent | bbf42063d78e393c2fc7a74b105aca6fb6357414 (diff) | |
download | hercules-22bd368e5d4d8d61a7189d03f52c3afd90c0729e.tar.gz hercules-22bd368e5d4d8d61a7189d03f52c3afd90c0729e.tar.bz2 hercules-22bd368e5d4d8d61a7189d03f52c3afd90c0729e.tar.xz hercules-22bd368e5d4d8d61a7189d03f52c3afd90c0729e.zip |
Added core HPM interface
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.c | 24 | ||||
-rw-r--r-- | src/char/loginif.c | 4 | ||||
-rw-r--r-- | src/common/HPM.c | 6 | ||||
-rw-r--r-- | src/common/console.c | 2 | ||||
-rw-r--r-- | src/common/core.c | 18 | ||||
-rw-r--r-- | src/common/core.h | 29 | ||||
-rw-r--r-- | src/login/login.c | 18 | ||||
-rw-r--r-- | src/map/atcommand.c | 4 | ||||
-rw-r--r-- | src/map/chrif.c | 6 | ||||
-rw-r--r-- | src/map/clif.c | 2 | ||||
-rw-r--r-- | src/map/elemental.c | 2 | ||||
-rw-r--r-- | src/map/map.c | 18 | ||||
-rw-r--r-- | src/map/skill.c | 4 | ||||
-rw-r--r-- | src/map/status.c | 2 | ||||
-rw-r--r-- | src/plugins/sample.c | 17 |
15 files changed, 73 insertions, 83 deletions
diff --git a/src/char/char.c b/src/char/char.c index 4741c3115..811507602 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -3242,7 +3242,7 @@ void char_parse_frommap_char_select_req(int fd) int32 group_id = RFIFOL(fd, 18); RFIFOSKIP(fd,22); - if( runflag != CHARSERVER_ST_RUNNING ) + if( core->runflag != CHARSERVER_ST_RUNNING ) { chr->select_ack(fd, account_id, 0); } @@ -3297,7 +3297,7 @@ void char_parse_frommap_change_map_server(int fd) char_data = (struct mmo_charstatus*)uidb_get(chr->char_db_,RFIFOL(fd,14)); } - if (runflag == CHARSERVER_ST_RUNNING && sockt->session_is_active(map_fd) && char_data) { + if (core->runflag == CHARSERVER_ST_RUNNING && sockt->session_is_active(map_fd) && char_data) { //Send the map server the auth of this player. struct online_char_data* data; struct char_auth_node* node; @@ -3778,7 +3778,7 @@ void char_parse_frommap_auth_request(int fd, int id) cd = (struct mmo_charstatus*)uidb_get(chr->char_db_,char_id); } - if( runflag == CHARSERVER_ST_RUNNING && cd && standalone ) { + if( core->runflag == CHARSERVER_ST_RUNNING && cd && standalone ) { cd->sex = sex; chr->map_auth_ok(fd, account_id, NULL, cd); @@ -3786,7 +3786,7 @@ void char_parse_frommap_auth_request(int fd, int id) return; } - if( runflag == CHARSERVER_ST_RUNNING && + if( core->runflag == CHARSERVER_ST_RUNNING && cd != NULL && node != NULL && node->account_id == account_id && @@ -4454,7 +4454,7 @@ void char_parse_char_connect(int fd, struct char_session_data* sd, uint32 ipl) // send back account_id chr->send_account_id(fd, account_id); - if( runflag != CHARSERVER_ST_RUNNING ) { + if( core->runflag != CHARSERVER_ST_RUNNING ) { chr->auth_error(fd, 0); return; } @@ -4962,7 +4962,7 @@ void char_parse_char_login_map_server(int fd, uint32 ipl) l_pass[23] = '\0'; ARR_FIND( 0, ARRAYLENGTH(chr->server), i, chr->server[i].fd <= 0 ); - if (runflag != CHARSERVER_ST_RUNNING || + if (core->runflag != CHARSERVER_ST_RUNNING || i == ARRAYLENGTH(chr->server) || strcmp(l_user, chr->userid) != 0 || strcmp(l_pass, chr->passwd) != 0 || @@ -5792,17 +5792,17 @@ void set_server_type(void) { /// Called when a terminate signal is received. void do_shutdown(void) { - if( runflag != CHARSERVER_ST_SHUTDOWN ) + if( core->runflag != CHARSERVER_ST_SHUTDOWN ) { int id; - runflag = CHARSERVER_ST_SHUTDOWN; + core->runflag = CHARSERVER_ST_SHUTDOWN; ShowStatus("Shutting down...\n"); // TODO proper shutdown procedure; wait for acks?, kick all characters, ... [FlavoJS] for( id = 0; id < ARRAYLENGTH(chr->server); ++id ) mapif->server_reset(id); loginif->check_shutdown(); sockt->flush_fifos(); - runflag = CORE_ST_STOP; + core->runflag = CORE_ST_STOP; } } @@ -5976,10 +5976,10 @@ int do_init(int argc, char **argv) { #endif ShowStatus("The char-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %d).\n\n", chr->port); - if( runflag != CORE_ST_STOP ) + if( core->runflag != CORE_ST_STOP ) { - shutdown_callback = do_shutdown; - runflag = CHARSERVER_ST_RUNNING; + core->shutdown_callback = do_shutdown; + core->runflag = CHARSERVER_ST_RUNNING; } HPM->event(HPET_READY); diff --git a/src/char/loginif.c b/src/char/loginif.c index d55701aaa..422c7c589 100644 --- a/src/char/loginif.c +++ b/src/char/loginif.c @@ -39,9 +39,9 @@ void loginif_reset(void) /// If all the conditions are met, it stops the core loop. void loginif_check_shutdown(void) { - if( runflag != CHARSERVER_ST_SHUTDOWN ) + if( core->runflag != CHARSERVER_ST_SHUTDOWN ) return; - runflag = CORE_ST_STOP; + core->runflag = CORE_ST_STOP; } diff --git a/src/common/HPM.c b/src/common/HPM.c index d9abdfab7..b4594d1ca 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -752,11 +752,7 @@ void hplugins_share_defaults(void) { HPM->share(hpm_add_arg,"addArg"); HPM->share(hplugins_addconf,"addConf"); /* core */ - HPM->share(&runflag,"runflag"); - HPM->share(arg_v,"arg_v"); - HPM->share(&arg_c,"arg_c"); - HPM->share(SERVER_NAME,"SERVER_NAME"); - HPM->share(&SERVER_TYPE,"SERVER_TYPE"); + HPM->share(core,"core"); HPM->share(HPMiMalloc, "iMalloc"); HPM->share(cmdline,"cmdline"); /* console */ diff --git a/src/common/console.c b/src/common/console.c index 5091d1a6c..0dd225d4d 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -102,7 +102,7 @@ int console_parse_key_pressed(void) * Stops server **/ CPCMD_C(exit,server) { - runflag = 0; + core->runflag = 0; } /** diff --git a/src/common/core.c b/src/common/core.c index 2f89d004e..7f5a1da53 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -41,11 +41,8 @@ /// Called when a terminate signal is received. void (*shutdown_callback)(void) = NULL; -int runflag = CORE_ST_RUN; -int arg_c = 0; -char **arg_v = NULL; - -char *SERVER_NAME = NULL; +struct core_interface core_s; +struct core_interface *core = &core_s; #ifndef MINICORE // minimalist Core // Added by Gabuzomeu @@ -90,7 +87,7 @@ static BOOL WINAPI console_handler(DWORD c_event) { if( shutdown_callback != NULL ) shutdown_callback(); else - runflag = CORE_ST_STOP;// auto-shutdown + core->runflag = CORE_ST_STOP;// auto-shutdown break; default: return FALSE; @@ -118,7 +115,7 @@ static void sig_proc(int sn) { if( shutdown_callback != NULL ) shutdown_callback(); else - runflag = CORE_ST_STOP;// auto-shutdown + core->runflag = CORE_ST_STOP;// auto-shutdown break; case SIGSEGV: case SIGFPE: @@ -389,8 +386,9 @@ int main (int argc, char **argv) { SERVER_NAME = ++p1; p2 = p1; } - arg_c = argc; - arg_v = argv; + core->arg_c = argc; + core->arg_v = argv; + core->runflag = CORE_ST_RUN; } core_defaults(); @@ -442,7 +440,7 @@ int main (int argc, char **argv) { do_init(argc,argv); // Main runtime cycle - while (runflag != CORE_ST_STOP) { + while (core->runflag != CORE_ST_STOP) { int next = timer->perform(timer->gettick_nocache()); sockt->perform(next); } diff --git a/src/common/core.h b/src/common/core.h index b0f0449a3..c92bf4fa6 100644 --- a/src/common/core.h +++ b/src/common/core.h @@ -57,28 +57,30 @@ struct cmdline_interface { const char *(*arg_source) (struct CmdlineArgData *arg); }; +struct core_interface { + int arg_c; + char **arg_v; + /// @see E_CORE_ST + int runflag; + char *server_name; + enum server_types server_type; + + /// Called when a terminate signal is received. (Ctrl+C pressed) + /// If NULL, runflag is set to CORE_ST_STOP instead. + void (*shutdown_callback)(void); +}; + #define CMDLINEARG(x) bool cmdline_arg_ ## x (const char *name, const char *params) +#define SERVER_NAME (core->server_name) +#define SERVER_TYPE (core->server_type) #ifdef HERCULES_CORE -extern int arg_c; -extern char **arg_v; - -/// @see E_CORE_ST -extern int runflag; -extern char *SERVER_NAME; - -enum server_types SERVER_TYPE; - extern void cmdline_args_init_local(void); extern int do_init(int,char**); extern void set_server_type(void); extern void do_abort(void); extern int do_final(void); -/// Called when a terminate signal is received. (Ctrl+C pressed) -/// If NULL, runflag is set to CORE_ST_STOP instead. -extern void (*shutdown_callback)(void); - /// Special plugin ID assigned to the Hercules core #define HPM_PID_CORE ((unsigned int)-1) @@ -88,6 +90,7 @@ extern void (*shutdown_callback)(void); void cmdline_defaults(void); #endif // HERCULES_CORE +HPShared struct core_interface *core; HPShared struct cmdline_interface *cmdline; #endif /* COMMON_CORE_H */ diff --git a/src/login/login.c b/src/login/login.c index 420c8687b..cf27fe71a 100644 --- a/src/login/login.c +++ b/src/login/login.c @@ -294,7 +294,7 @@ void login_fromchar_parse_auth(int fd, int id, const char *const ip) RFIFOSKIP(fd,23); node = (struct login_auth_node*)idb_get(login->auth_db, account_id); - if( runflag == LOGINSERVER_ST_RUNNING && + if( core->runflag == LOGINSERVER_ST_RUNNING && node != NULL && node->account_id == account_id && node->login_id1 == login_id1 && @@ -1192,7 +1192,7 @@ void login_auth_ok(struct login_session_data* sd) nullpo_retv(sd); fd = sd->fd; ip = sockt->session[fd]->client_addr; - if( runflag != LOGINSERVER_ST_RUNNING ) + if( core->runflag != LOGINSERVER_ST_RUNNING ) { // players can only login while running login->connection_problem(fd, 1); // 01 = server closed @@ -1537,7 +1537,7 @@ void login_parse_request_connection(int fd, struct login_session_data* sd, const login_log(sockt->session[fd]->client_addr, sd->userid, 100, message); result = login->mmo_auth(sd, true); - if (runflag == LOGINSERVER_ST_RUNNING && + if (core->runflag == LOGINSERVER_ST_RUNNING && result == -1 && sd->sex == 'S' && sd->account_id >= 0 && @@ -1905,16 +1905,16 @@ void set_server_type(void) { /// Called when a terminate signal is received. void do_shutdown_login(void) { - if( runflag != LOGINSERVER_ST_SHUTDOWN ) + if( core->runflag != LOGINSERVER_ST_SHUTDOWN ) { int id; - runflag = LOGINSERVER_ST_SHUTDOWN; + core->runflag = LOGINSERVER_ST_SHUTDOWN; ShowStatus("Shutting down...\n"); // TODO proper shutdown procedure; kick all characters, wait for acks, ... [FlavioJS] for( id = 0; id < ARRAYLENGTH(server); ++id ) chrif_server_reset(id); sockt->flush_fifos(); - runflag = CORE_ST_STOP; + core->runflag = CORE_ST_STOP; } } @@ -2033,9 +2033,9 @@ int do_init(int argc, char** argv) exit(EXIT_FAILURE); } - if( runflag != CORE_ST_STOP ) { - shutdown_callback = do_shutdown_login; - runflag = LOGINSERVER_ST_RUNNING; + if( core->runflag != CORE_ST_STOP ) { + core->shutdown_callback = do_shutdown_login; + core->runflag = LOGINSERVER_ST_RUNNING; } ShowStatus("The login-server is "CL_GREEN"ready"CL_RESET" (Server is listening on the port %u).\n\n", login_config.login_port); diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 1fec0af5b..95db0c2e6 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -10200,7 +10200,7 @@ bool atcommand_can_use2(struct map_session_data *sd, const char *command, AtComm bool atcommand_hp_add(char *name, AtCommandFunc func) { /* if commands are added after group permissions are thrown in, they end up with no permissions */ /* so we restrict commands to be linked in during boot */ - if( runflag == MAPSERVER_ST_RUNNING ) { + if( core->runflag == MAPSERVER_ST_RUNNING ) { ShowDebug("atcommand_hp_add: Commands can't be added after server is ready, skipping '%s'...\n",name); return false; } @@ -10232,7 +10232,7 @@ void atcommand_db_clear(void) { } void atcommand_doload(void) { - if( runflag >= MAPSERVER_ST_RUNNING ) + if( core->runflag >= MAPSERVER_ST_RUNNING ) atcommand->cmd_db_clear(); if( atcommand->db == NULL ) atcommand->db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, ATCOMMAND_LENGTH); diff --git a/src/map/chrif.c b/src/map/chrif.c index ac96e1d84..65c042533 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -103,11 +103,11 @@ void chrif_reset(void) { /// Releases the cookie when all characters are saved. /// If all the conditions are met, it stops the core loop. void chrif_check_shutdown(void) { - if( runflag != MAPSERVER_ST_SHUTDOWN ) + if( core->runflag != MAPSERVER_ST_SHUTDOWN ) return; if( db_size(chrif->auth_db) > 0 ) return; - runflag = CORE_ST_STOP; + core->runflag = CORE_ST_STOP; } struct auth_node* chrif_search(int account_id) { @@ -608,7 +608,7 @@ void chrif_authok(int fd) { sd = node->sd; - if( runflag == MAPSERVER_ST_RUNNING && + if( core->runflag == MAPSERVER_ST_RUNNING && node->account_id == account_id && node->char_id == char_id && node->login_id1 == login_id1 ) diff --git a/src/map/clif.c b/src/map/clif.c index 296fd5cb3..ded028974 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -8945,7 +8945,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data* sd) { client_tick = RFIFOL(fd, packet_db[cmd].pos[3]); sex = RFIFOB(fd, packet_db[cmd].pos[4]); - if( runflag != MAPSERVER_ST_RUNNING ) { // not allowed + if( core->runflag != MAPSERVER_ST_RUNNING ) { // not allowed clif->authfail_fd(fd,1);// server closed return; } diff --git a/src/map/elemental.c b/src/map/elemental.c index d74e7a199..435dffaf4 100644 --- a/src/map/elemental.c +++ b/src/map/elemental.c @@ -786,7 +786,7 @@ int read_elementaldb(void) { sprintf(line, "%s/%s", map->db_path, "elemental_db.txt"); - if( runflag == MAPSERVER_ST_RUNNING ) //only necessary after we're up + if( core->runflag == MAPSERVER_ST_RUNNING ) //only necessary after we're up memset(elemental->db,0,sizeof(elemental->db)); fp = fopen(line, "r"); diff --git a/src/map/map.c b/src/map/map.c index 5766563c7..115ad510d 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -1802,7 +1802,7 @@ int map_quit(struct map_session_data *sd) { if( sd->bg_id && !sd->bg_queue.arena ) /* TODO: dump this chunk after bg_queue is fully enabled */ bg->team_leave(sd,BGTL_QUIT); - if (sd->state.autotrade && runflag != MAPSERVER_ST_SHUTDOWN && !channel->config->closing) + if (sd->state.autotrade && core->runflag != MAPSERVER_ST_SHUTDOWN && !channel->config->closing) pc->autotrade_update(sd,PAUC_REMOVE); skill->cooldown_save(sd); @@ -5545,9 +5545,9 @@ void set_server_type(void) { /// Called when a terminate signal is received. void do_shutdown(void) { - if( runflag != MAPSERVER_ST_SHUTDOWN ) + if( core->runflag != MAPSERVER_ST_SHUTDOWN ) { - runflag = MAPSERVER_ST_SHUTDOWN; + core->runflag = MAPSERVER_ST_SHUTDOWN; ShowStatus("Shutting down...\n"); { struct map_session_data* sd; @@ -5723,7 +5723,7 @@ void map_load_defaults(void) { */ static CMDLINEARG(runonce) { - runflag = CORE_ST_STOP; + core->runflag = CORE_ST_STOP; return true; } /** @@ -5831,7 +5831,7 @@ static CMDLINEARG(logconfig) static CMDLINEARG(scriptcheck) { map->minimal = true; - runflag = CORE_ST_STOP; + core->runflag = CORE_ST_STOP; map->scriptcheck = true; return true; } @@ -5861,7 +5861,7 @@ static CMDLINEARG(generatetranslations) { ShowError("export-dialog: failed to open '%s' for writing\n",script->lang_export_file); } - runflag = CORE_ST_STOP; + core->runflag = CORE_ST_STOP; return true; } @@ -6060,9 +6060,9 @@ int do_init(int argc, char *argv[]) ShowStatus("Server is '"CL_GREEN"ready"CL_RESET"' and listening on port '"CL_WHITE"%d"CL_RESET"'.\n\n", map->port); - if( runflag != CORE_ST_STOP ) { - shutdown_callback = map->do_shutdown; - runflag = MAPSERVER_ST_RUNNING; + if( core->runflag != CORE_ST_STOP ) { + core->shutdown_callback = map->do_shutdown; + core->runflag = MAPSERVER_ST_RUNNING; } map_cp_defaults(); diff --git a/src/map/skill.c b/src/map/skill.c index 00babb4f6..c647cc325 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -18091,7 +18091,7 @@ void skill_init_unit_layout (void) int i,j,pos = 0; //when != it was already cleared during skill_defaults() no need to repeat - if( runflag == MAPSERVER_ST_RUNNING ) + if( core->runflag == MAPSERVER_ST_RUNNING ) memset(skill->dbs->unit_layout, 0, sizeof(skill->dbs->unit_layout)); // standard square layouts go first @@ -18976,7 +18976,7 @@ void skill_readdb(bool minimal) { db_clear(skill->name2id_db); /* when != it was called during init and this procedure was already performed by skill_defaults() */ - if( runflag == MAPSERVER_ST_RUNNING ) { + if( core->runflag == MAPSERVER_ST_RUNNING ) { memset(ZEROED_BLOCK_POS(skill->dbs), 0, ZEROED_BLOCK_SIZE(skill->dbs)); } diff --git a/src/map/status.c b/src/map/status.c index dc99c1f95..4fc975268 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -12302,7 +12302,7 @@ int status_readdb(void) // initialize databases to default // - if( runflag == MAPSERVER_ST_RUNNING ) {//not necessary during boot + if( core->runflag == MAPSERVER_ST_RUNNING ) {//not necessary during boot // reset job_db.conf data memset(status->dbs->max_weight_base, 0, sizeof(status->dbs->max_weight_base)); memset(status->dbs->HP_table, 0, sizeof(status->dbs->HP_table)); diff --git a/src/plugins/sample.c b/src/plugins/sample.c index 58be9c05f..275edb129 100644 --- a/src/plugins/sample.c +++ b/src/plugins/sample.c @@ -117,22 +117,15 @@ void parse_my_setting(const char *val) { } /* run when server starts */ HPExport void plugin_init (void) { - char *server_type; - char *server_name; + ShowInfo("Server type is "); - /* core vars */ - server_type = GET_SYMBOL("SERVER_TYPE"); // FIXME - server_name = GET_SYMBOL("SERVER_NAME"); // FIXME - - ShowInfo ("Server type is "); - - switch (*server_type) { - case SERVER_TYPE_LOGIN: printf ("Login Server\n"); break; - case SERVER_TYPE_CHAR: printf ("Char Server\n"); break; + switch (SERVER_TYPE) { + case SERVER_TYPE_LOGIN: printf("Login Server\n"); break; + case SERVER_TYPE_CHAR: printf("Char Server\n"); break; case SERVER_TYPE_MAP: printf ("Map Server\n"); break; } - ShowInfo ("I'm being run from the '%s' filename\n", server_name); + ShowInfo("I'm being run from the '%s' filename\n", SERVER_NAME); /* addAtcommand("command-key",command-function) tells map server to call ACMD(sample) when "sample" command is used */ /* - it will print a warning when used on a non-map-server plugin */ |