summaryrefslogtreecommitdiff
path: root/src/common/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/core.c')
-rw-r--r--src/common/core.c86
1 files changed, 32 insertions, 54 deletions
diff --git a/src/common/core.c b/src/common/core.c
index 9a131d042..dbd1d2596 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2016 Hercules Dev Team
+ * Copyright (C) 2012-2018 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -23,32 +23,30 @@
#include "config/core.h"
#include "core.h"
+#include "common/HPM.h"
#include "common/cbasetypes.h"
+#include "common/conf.h"
#include "common/console.h"
#include "common/db.h"
#include "common/des.h"
+#include "common/ers.h"
#include "common/grfio.h"
+#include "common/md5calc.h"
#include "common/memmgr.h"
#include "common/mmo.h"
+#include "common/mutex.h"
#include "common/nullpo.h"
+#include "common/packets.h"
+#include "common/random.h"
#include "common/showmsg.h"
+#include "common/socket.h"
+#include "common/sql.h"
#include "common/strlib.h"
#include "common/sysinfo.h"
+#include "common/thread.h"
#include "common/timer.h"
#include "common/utils.h"
-#ifndef MINICORE
-# include "common/HPM.h"
-# include "common/conf.h"
-# include "common/ers.h"
-# include "common/md5calc.h"
-# include "common/mutex.h"
-# include "common/random.h"
-# include "common/socket.h"
-# include "common/sql.h"
-# include "common/thread.h"
-#endif
-
#ifndef _WIN32
# include <unistd.h>
#else
@@ -80,13 +78,9 @@
// And don't complain to us if the XYZ plugin you installed wiped your hard disk, or worse.
// Note: This feature is deprecated, and should not be used.
-/// Called when a terminate signal is received.
-void (*shutdown_callback)(void) = NULL;
-
-struct core_interface core_s;
+static struct core_interface core_s;
struct core_interface *core = &core_s;
-#ifndef MINICORE // minimalist Core
// Added by Gabuzomeu
//
// This is an implementation of signal() using sigaction() for portability.
@@ -100,7 +94,7 @@ struct core_interface *core = &core_s;
#ifndef POSIX
#define compat_signal(signo, func) signal((signo), (func))
#else
-sigfunc *compat_signal(int signo, sigfunc *func)
+static sigfunc *compat_signal(int signo, sigfunc *func)
{
struct sigaction sact, oact;
@@ -128,8 +122,8 @@ static BOOL WINAPI console_handler(DWORD c_event)
case CTRL_CLOSE_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
- if( shutdown_callback != NULL )
- shutdown_callback();
+ if (core->shutdown_callback != NULL)
+ core->shutdown_callback();
else
core->runflag = CORE_ST_STOP;// auto-shutdown
break;
@@ -158,8 +152,8 @@ static void sig_proc(int sn)
case SIGTERM:
if (++is_called > 3)
exit(EXIT_SUCCESS);
- if( shutdown_callback != NULL )
- shutdown_callback();
+ if (core->shutdown_callback != NULL)
+ core->shutdown_callback();
else
core->runflag = CORE_ST_STOP;// auto-shutdown
break;
@@ -183,7 +177,7 @@ static void sig_proc(int sn)
}
}
-void signals_init (void)
+static void signals_init(void)
{
compat_signal(SIGTERM, sig_proc);
compat_signal(SIGINT, sig_proc);
@@ -199,14 +193,13 @@ void signals_init (void)
compat_signal(SIGTRAP, SIG_DFL);
#endif
}
-#endif
/**
* Warns the user if executed as superuser (root)
*
* @retval false if the check didn't pass and the program should be terminated.
*/
-bool usercheck(void)
+static bool usercheck(void)
{
#ifndef _WIN32
if (sysinfo->is_superuser()) {
@@ -250,13 +243,11 @@ bool usercheck(void)
return true;
}
-void core_defaults(void)
+static void core_defaults(void)
{
nullpo_defaults();
-#ifndef MINICORE
hpm_defaults();
HCache_defaults();
-#endif
sysinfo_defaults();
console_defaults();
strlib_defaults();
@@ -265,30 +256,25 @@ void core_defaults(void)
cmdline_defaults();
des_defaults();
grfio_defaults(); // Note: grfio is lazily loaded. grfio->init() and grfio->final() are not automatically called.
-#ifndef MINICORE
mutex_defaults();
libconfig_defaults();
sql_defaults();
timer_defaults();
db_defaults();
socket_defaults();
+ packets_defaults();
rnd_defaults();
md5_defaults();
thread_defaults();
-#endif
}
/**
* Returns the source (core or plugin name) for the given command-line argument
*/
-const char *cmdline_arg_source(struct CmdlineArgData *arg)
+static const char *cmdline_arg_source(struct CmdlineArgData *arg)
{
-#ifdef MINICORE
- return "core";
-#else // !MINICORE
nullpo_retr(NULL, arg);
return HPM->pid2name(arg->pluginID);
-#endif // MINICORE
}
/**
@@ -302,7 +288,7 @@ const char *cmdline_arg_source(struct CmdlineArgData *arg)
* @param options options associated to the command-line argument. @see enum cmdline_options.
* @return the success status.
*/
-bool cmdline_arg_add(unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options)
+static bool cmdline_arg_add(unsigned int pluginID, const char *name, char shortname, CmdlineExecFunc func, const char *help, unsigned int options)
{
struct CmdlineArgData *data = NULL;
@@ -366,7 +352,7 @@ static CMDLINEARG(version)
* @param argc the program's argc.
* @return true if a value for the current argument is available on the command line.
*/
-bool cmdline_arg_next_value(const char *name, int current_arg, int argc)
+static bool cmdline_arg_next_value(const char *name, int current_arg, int argc)
{
if (current_arg >= argc-1) {
ShowError("Missing value for option '%s'.\n", name);
@@ -394,7 +380,7 @@ bool cmdline_arg_next_value(const char *name, int current_arg, int argc)
* line arguments or handler's failure cause the program to abort.
* @return the amount of command line handlers successfully executed.
*/
-int cmdline_exec(int argc, char **argv, unsigned int options)
+static int cmdline_exec(int argc, char **argv, unsigned int options)
{
int count = 0, i;
@@ -447,21 +433,15 @@ int cmdline_exec(int argc, char **argv, unsigned int options)
/**
* Defines the global command-line arguments.
*/
-void cmdline_init(void)
+static void cmdline_init(void)
{
-#ifdef MINICORE
- // Minicore has no HPM. This value isn't used, but the arg_add function requires it, so we're (re)defining it here
-#define HPM_PID_CORE ((unsigned int)-1)
-#endif
CMDLINEARG_DEF(help, 'h', "Displays this help screen", CMDLINE_OPT_NORMAL);
CMDLINEARG_DEF(version, 'v', "Displays the server's version.", CMDLINE_OPT_NORMAL);
-#ifndef MINICORE
CMDLINEARG_DEF2(load-plugin, loadplugin, "Loads an additional plugin (can be repeated).", CMDLINE_OPT_PARAM|CMDLINE_OPT_PREINIT);
-#endif // !MINICORE
cmdline_args_init_local();
}
-void cmdline_final(void)
+static void cmdline_final(void)
{
while (VECTOR_LENGTH(cmdline->args_data) > 0) {
struct CmdlineArgData *data = &VECTOR_POP(cmdline->args_data);
@@ -471,7 +451,7 @@ void cmdline_final(void)
VECTOR_CLEAR(cmdline->args_data);
}
-struct cmdline_interface cmdline_s;
+static struct cmdline_interface cmdline_s;
struct cmdline_interface *cmdline;
void cmdline_defaults(void)
@@ -491,7 +471,7 @@ void cmdline_defaults(void)
/*======================================
* CORE : MAINROUTINE
*--------------------------------------*/
-int main (int argc, char **argv)
+int main(int argc, char **argv)
{
int retval = EXIT_SUCCESS;
{// initialize program arguments
@@ -524,10 +504,6 @@ int main (int argc, char **argv)
if (!usercheck())
return EXIT_FAILURE;
-#ifdef MINICORE // minimalist Core
- do_init(argc,argv);
- do_final();
-#else// not MINICORE
set_server_type();
Sql_Init();
@@ -552,6 +528,8 @@ int main (int argc, char **argv)
sockt->init();
+ packets->init();
+
do_init(argc,argv);
// Main runtime cycle
@@ -565,12 +543,12 @@ int main (int argc, char **argv)
retval = do_final();
HPM->final();
timer->final();
+ packets->final();
sockt->final();
DB->final();
thread->final();
ers_final();
rnd->final();
-#endif
cmdline->final();
//sysinfo->final(); Called by iMalloc->final()