core.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef CORE_HPP
  4. #define CORE_HPP
  5. #include <string>
  6. #include <vector>
  7. #include "timer.hpp"
  8. #ifdef _WIN32
  9. #include "winapi.hpp" // Console close event handling
  10. #endif
  11. /* so that developers with --enable-debug can raise signals from any section of the code they'd like */
  12. #ifdef DEBUG
  13. #include <signal.h>
  14. #endif
  15. #if defined(BUILDBOT)
  16. extern int buildbotflag;
  17. #endif
  18. #define UNKNOWN_VERSION '\x02'
  19. extern char *SERVER_NAME;
  20. extern char db_path[12]; /// relative path for db from servers
  21. extern char conf_path[12]; /// relative path for conf from servers
  22. extern int parse_console(const char* buf);
  23. const char *get_svn_revision(void);
  24. const char *get_git_hash(void);
  25. namespace rathena{
  26. namespace server_core{
  27. enum class e_core_status{
  28. NOT_STARTED,
  29. CORE_INITIALIZING,
  30. CORE_INITIALIZED,
  31. SERVER_INITIALIZING,
  32. SERVER_INITIALIZED,
  33. RUNNING,
  34. STOPPING,
  35. SERVER_FINALIZING,
  36. SERVER_FINALIZED,
  37. CORE_FINALIZING,
  38. CORE_FINALIZED,
  39. STOPPED,
  40. };
  41. enum class e_core_type{
  42. LOGIN,
  43. CHARACTER,
  44. MAP,
  45. TOOL,
  46. WEB
  47. };
  48. class Core{
  49. private:
  50. e_core_status status;
  51. e_core_type type;
  52. bool run_once;
  53. bool crashed;
  54. protected:
  55. virtual bool initialize( int argc, char* argv[] );
  56. virtual void handle_main( t_tick next );
  57. virtual void finalize();
  58. virtual void handle_crash();
  59. virtual void handle_shutdown();
  60. void set_status( e_core_status status );
  61. public:
  62. Core( e_core_type type ){
  63. this->status = e_core_status::NOT_STARTED;
  64. this->run_once = false;
  65. this->crashed = false;
  66. this->type = type;
  67. }
  68. e_core_status get_status();
  69. e_core_type get_type();
  70. bool is_running();
  71. // TODO: refactor to protected
  72. void set_run_once( bool run_once );
  73. void signal_crash();
  74. void signal_shutdown();
  75. int start( int argc, char* argv[] );
  76. };
  77. }
  78. }
  79. extern rathena::server_core::Core* global_core;
  80. template <typename T> int main_core( int argc, char *argv[] ){
  81. T server = {};
  82. global_core = &server;
  83. return server.start( argc, argv );
  84. }
  85. #endif /* CORE_HPP */