123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
- // For more information, see LICENCE in the main folder
- #ifndef CORE_HPP
- #define CORE_HPP
- #include <string>
- #include <vector>
- #include "timer.hpp"
- #ifdef _WIN32
- #include "winapi.hpp" // Console close event handling
- #endif
- /* so that developers with --enable-debug can raise signals from any section of the code they'd like */
- #ifdef DEBUG
- #include <signal.h>
- #endif
- #if defined(BUILDBOT)
- extern int buildbotflag;
- #endif
- #define UNKNOWN_VERSION '\x02'
- extern char *SERVER_NAME;
- extern char db_path[12]; /// relative path for db from servers
- extern char conf_path[12]; /// relative path for conf from servers
- extern int parse_console(const char* buf);
- const char *get_svn_revision(void);
- const char *get_git_hash(void);
- namespace rathena{
- namespace server_core{
- enum class e_core_status{
- NOT_STARTED,
- CORE_INITIALIZING,
- CORE_INITIALIZED,
- SERVER_INITIALIZING,
- SERVER_INITIALIZED,
- RUNNING,
- STOPPING,
- SERVER_FINALIZING,
- SERVER_FINALIZED,
- CORE_FINALIZING,
- CORE_FINALIZED,
- STOPPED,
- };
- enum class e_core_type{
- LOGIN,
- CHARACTER,
- MAP,
- TOOL,
- WEB
- };
- class Core{
- private:
- e_core_status status;
- e_core_type type;
- bool run_once;
- bool crashed;
- protected:
- virtual bool initialize( int argc, char* argv[] );
- virtual void handle_main( t_tick next );
- virtual void finalize();
- virtual void handle_crash();
- virtual void handle_shutdown();
- void set_status( e_core_status status );
- public:
- Core( e_core_type type ){
- this->status = e_core_status::NOT_STARTED;
- this->run_once = false;
- this->crashed = false;
- this->type = type;
- }
- e_core_status get_status();
- e_core_type get_type();
- bool is_running();
- // TODO: refactor to protected
- void set_run_once( bool run_once );
- void signal_crash();
- void signal_shutdown();
- int start( int argc, char* argv[] );
- };
- }
- }
- extern rathena::server_core::Core* global_core;
- template <typename T> int main_core( int argc, char *argv[] ){
- T server = {};
- global_core = &server;
- return server.start( argc, argv );
- }
- #endif /* CORE_HPP */
|