Pol  Revision:cb584c9
polcfg.cpp
Go to the documentation of this file.
1 
14 #include "polcfg.h"
15 
16 #include <cstdio>
17 #include <exception>
18 #include <string.h>
19 #include <string>
20 #include <sys/stat.h>
21 #include <time.h>
22 
23 #include "../bscript/config.h"
24 #include "../clib/Debugging/ExceptionParser.h"
25 #include "../clib/cfgelem.h"
26 #include "../clib/cfgfile.h"
27 #include "../clib/fileutil.h"
28 #include "../clib/logfacility.h"
29 #include "../clib/mdump.h"
30 #include "../clib/passert.h"
31 #include "../clib/strutil.h"
32 #include "../plib/systemstate.h"
33 #include "core.h"
34 #include "globals/state.h"
35 #include "globals/uvars.h"
36 #include "objtype.h"
37 #include "polsig.h"
38 #include "proplist.h"
39 
40 namespace Pol
41 {
42 namespace Core
43 {
44 struct stat PolConfig::pol_cfg_stat;
45 
46 void PolConfig::read_pol_config( bool initial_load )
47 {
48  Clib::ConfigFile cf( "pol.cfg" );
49  Clib::ConfigElem elem;
50 
51  cf.readraw( elem );
52 
53  if ( initial_load )
54  {
55  stat( "pol.cfg", &pol_cfg_stat );
56 
57  // these config options can't change after startup.
58  Plib::systemstate.config.uo_datafile_root = elem.remove_string( "UoDataFileRoot" );
60  Clib::normalized_dir_form( Plib::systemstate.config.uo_datafile_root );
61 
62  Plib::systemstate.config.world_data_path = elem.remove_string( "WorldDataPath", "data/" );
64  Clib::normalized_dir_form( Plib::systemstate.config.world_data_path );
65 
66  Plib::systemstate.config.realm_data_path = elem.remove_string( "RealmDataPath", "realm/" );
68  Clib::normalized_dir_form( Plib::systemstate.config.realm_data_path );
69 
70  Plib::systemstate.config.pidfile_path = elem.remove_string( "PidFilePath", "./" );
72  Clib::normalized_dir_form( Plib::systemstate.config.pidfile_path );
73 
74  Plib::systemstate.config.listen_port = elem.remove_ushort( "ListenPort", 0 );
75  Plib::systemstate.config.check_integrity = true; // elem.remove_bool( "CheckIntegrity", true );
76  Plib::systemstate.config.count_resource_tiles = elem.remove_bool( "CountResourceTiles", false );
77  Plib::systemstate.config.multithread = elem.remove_ushort( "Multithread", 1 );
78  Plib::systemstate.config.web_server = elem.remove_bool( "WebServer", false );
79  Plib::systemstate.config.web_server_port = elem.remove_ushort( "WebServerPort", 8080 );
80 
81  unsigned short max_tile = elem.remove_ushort( "MaxTileID", UOBJ_DEFAULT_MAX );
82 
83  if ( max_tile != UOBJ_DEFAULT_MAX && max_tile != UOBJ_SA_MAX && max_tile != UOBJ_HSA_MAX )
85  else
87 
88  unsigned int max_obj = elem.remove_unsigned( "MaxObjtype", EXTOBJ_HIGHEST_DEFAULT );
89  if ( max_obj < EXTOBJ_HIGHEST_DEFAULT || max_obj > 0xFFFFFFFF )
91  else
93 
94  Plib::systemstate.config.ignore_load_errors = elem.remove_bool( "IgnoreLoadErrors", false );
95 
96  Plib::systemstate.config.debug_port = elem.remove_ushort( "DebugPort", 0 );
97 
98  Plib::systemstate.config.account_save = elem.remove_int( "AccountDataSave", -1 );
99  if ( Plib::systemstate.config.account_save > 0 )
100  {
101  gamestate.write_account_task->set_secs( Plib::systemstate.config.account_save );
102  gamestate.write_account_task->start();
103  }
104  }
105  Plib::systemstate.config.verbose = elem.remove_bool( "Verbose", false );
106  Plib::systemstate.config.watch_mapcache = elem.remove_bool( "WatchMapCache", false );
107  Plib::systemstate.config.loglevel = elem.remove_ushort( "LogLevel", 0 );
108  Plib::systemstate.config.select_timeout_usecs = elem.remove_ushort( "SelectTimeout", 10 );
109  Plib::systemstate.config.watch_rpm = elem.remove_bool( "WatchRpm", false );
110  Plib::systemstate.config.watch_sysload = elem.remove_bool( "WatchSysLoad", false );
111  Plib::systemstate.config.log_sysload = elem.remove_bool( "LogSysLoad", false );
112  Plib::systemstate.config.inhibit_saves = elem.remove_bool( "InhibitSaves", false );
113  Plib::systemstate.config.log_script_cycles = elem.remove_bool( "LogScriptCycles", false );
114  Plib::systemstate.config.web_server_local_only = elem.remove_bool( "WebServerLocalOnly", true );
115  Plib::systemstate.config.web_server_debug = elem.remove_ushort( "WebServerDebug", 0 );
116  Plib::systemstate.config.web_server_password = elem.remove_string( "WebServerPassword", "" );
117 
118  Plib::systemstate.config.profile_cprops = elem.remove_bool( "ProfileCProps", false );
119 
121  elem.remove_bool( "CacheInteractiveScripts", true );
122  Plib::systemstate.config.show_speech_colors = elem.remove_bool( "ShowSpeechColors", false );
123  Plib::systemstate.config.require_spellbooks = elem.remove_bool( "RequireSpellbooks", true );
124 
125  Plib::systemstate.config.enable_secure_trading = elem.remove_bool( "EnableSecureTrading", false );
127  elem.remove_ulong( "RunawayScriptThreshold", 5000 );
128 
130  elem.remove_ushort( "MinCmdLvlToIgnoreInactivity", 1 );
132  elem.remove_ushort( "InactivityWarningTimeout", 4 );
134  elem.remove_ushort( "InactivityDisconnectTimeout", 5 );
135 
136  Plib::systemstate.config.min_cmdlevel_to_login = elem.remove_ushort( "MinCmdlevelToLogin", 0 );
137 
138  Bscript::escript_config.max_call_depth = elem.remove_ulong( "MaxCallDepth", 100 );
139  Clib::passert_dump_stack = elem.remove_bool( "DumpStackOnAssertionFailure", false );
140 
141  std::string tmp = elem.remove_string( "AssertionFailureAction", "abort" );
142  if ( Clib::strlower( tmp ) == "abort" )
143  {
144  Clib::passert_shutdown = false;
145  Clib::passert_nosave = false;
146  Clib::passert_abort = true;
148  SAVE_FULL; // should never come into play
149  }
150  else if ( Clib::strlower( tmp ) == "continue" )
151  {
152  Clib::passert_shutdown = false;
153  Clib::passert_nosave = false;
154  Clib::passert_abort = false;
156  SAVE_FULL; // should never come into play
157  }
158  else if ( Clib::strlower( tmp ) == "shutdown" )
159  {
160  Clib::passert_shutdown = true;
161  Clib::passert_nosave = false;
162  Clib::passert_abort = false;
164  }
165  else if ( Clib::strlower( tmp ) == "shutdown-nosave" )
166  {
167  Clib::passert_shutdown = true;
168  Clib::passert_nosave = true;
169  Clib::passert_abort = false;
171  SAVE_FULL; // should never come into play
172  }
173  else if ( Clib::strlower( tmp ) == "shutdown-save-full" )
174  {
175  Clib::passert_shutdown = true;
176  Clib::passert_nosave = false;
177  Clib::passert_abort = false;
179  }
180  else if ( Clib::strlower( tmp ) == "shutdown-save-incremental" )
181  {
182  Clib::passert_shutdown = true;
183  Clib::passert_nosave = false;
184  Clib::passert_abort = false;
186  }
187  else
188  {
189  Clib::passert_shutdown = false;
190  Clib::passert_abort = true;
192  SAVE_FULL; // should never come into play
193  POLLOG_ERROR.Format(
194  "Unknown pol.cfg AssertionFailureAction value: {} (expected abort, continue, shutdown, or "
195  "shutdown-nosave)\n" )
196  << tmp;
197  }
198 
199  tmp = elem.remove_string( "ShutdownSaveType", "full" );
200  if ( Clib::strlower( tmp ) == "full" )
201  {
203  }
204  else if ( Clib::strlower( tmp ) == "incremental" )
205  {
207  }
208  else
209  {
211  POLLOG_ERROR.Format(
212  "Unknown pol.cfg ShutdownSaveType value: {} (expected full or incremental)\n" )
213  << tmp;
214  }
215 
216  CalculateCryptKeys( elem.remove_string( "ClientEncryptionVersion", "none" ),
218 
220  elem.remove_bool( "DisplayUnknownPackets", false );
221  Plib::systemstate.config.exp_los_checks_map = elem.remove_bool( "ExpLosChecksMap", true );
222  Plib::systemstate.config.enable_debug_log = elem.remove_bool( "EnableDebugLog", false );
223  Plib::systemstate.config.debug_password = elem.remove_string( "DebugPassword", "" );
224  Plib::systemstate.config.debug_local_only = elem.remove_bool( "DebugLocalOnly", true );
225 
227  elem.remove_bool( "ThreadStacktracesWhenStuck", false );
228 
230  elem.remove_bool( "ReportRunToCompletionScripts", true );
232  elem.remove_bool( "ReportCriticalScripts", true );
234  elem.remove_bool( "ReportMissingConfigs", true );
235  Plib::systemstate.config.max_clients = elem.remove_ushort( "MaximumClients", 300 );
236  Plib::systemstate.config.character_slots = elem.remove_ushort( "CharacterSlots", 5 );
238  elem.remove_ushort( "MaximumClientsBypassCmdLevel", 1 );
240  elem.remove_bool( "AllowMultiClientsPerAccount", false );
241  Plib::systemstate.config.minidump_type = elem.remove_string( "MiniDumpType", "variable" );
243  elem.remove_bool( "RetainCleartextPasswords", false );
244  Plib::systemstate.config.discard_old_events = elem.remove_bool( "DiscardOldEvents", false );
246  elem.remove_bool( "TimestampEveryLine", false ); // clib/logfacility.h bool
248  elem.remove_bool( "UseSingleThreadLogin", false );
249  Plib::systemstate.config.disable_nagle = elem.remove_bool( "DisableNagle", false );
250  Plib::systemstate.config.show_realm_info = elem.remove_bool( "ShowRealmInfo", false );
251 
252  Plib::systemstate.config.enforce_mount_objtype = elem.remove_bool( "EnforceMountObjtype", false );
253  Plib::systemstate.config.single_thread_decay = elem.remove_bool( "SingleThreadDecay", false );
255  elem.remove_bool( "ThreadDecayStatistics", false );
256 
257  // store the configuration for the reporting system in the ExceptionParser
258  bool reportingActive = elem.remove_bool( "ReportCrashsAutomatically", false );
259  std::string reportingAdminEmail = elem.remove_string( "ReportAdminEmail", "" );
260  std::string reportingServer = elem.remove_string( "ReportServer", "polserver.com" );
261  std::string reportingUrl = elem.remove_string( "ReportURL", "/pol/report_program_abort.php" );
263  reportingActive, reportingServer, reportingUrl, reportingAdminEmail );
264 
265 #ifdef _WIN32
267 #endif
268 
269  if ( !Plib::systemstate.config.enable_debug_log )
271 
272  Plib::systemstate.config.debug_level = elem.remove_ushort( "DebugLevel", 0 );
273 
277  if ( !Plib::systemstate.config.profile_cprops )
279 }
280 
282 {
283  THREAD_CHECKPOINT( tasks, 600 );
284  try
285  {
286  struct stat newst;
287  stat( "pol.cfg", &newst );
288 
289  if ( ( newst.st_mtime != PolConfig::pol_cfg_stat.st_mtime ) &&
290  ( newst.st_mtime < time( nullptr ) - 10 ) )
291  {
292  POLLOG_INFO << "Reloading pol.cfg...";
293  memcpy( &PolConfig::pol_cfg_stat, &newst, sizeof PolConfig::pol_cfg_stat );
294 
296  POLLOG_INFO << "Done!\n";
297  }
298  }
299  catch ( std::exception& ex )
300  {
301  POLLOG_ERROR << "Error rereading pol.cfg: " << ex.what() << "\n";
302  }
303  THREAD_CHECKPOINT( tasks, 699 );
304 }
305 
307 {
309 }
310 }
311 }
bool require_spellbooks
Definition: polcfg.h:53
int assertion_shutdown_save_type
Definition: polcfg.h:86
unsigned short web_server_debug
Definition: polcfg.h:48
bool check_integrity
Definition: polcfg.h:39
bool enable_debug_log
Definition: polcfg.h:70
unsigned short debug_level
Definition: polcfg.h:78
std::string remove_string(const char *propname)
Definition: cfgfile.cpp:381
unsigned short max_clients
Definition: polcfg.h:64
std::string debug_password
Definition: polcfg.h:73
SystemState systemstate
Definition: systemstate.cpp:12
Core::PolConfig config
Definition: systemstate.h:43
const int SAVE_FULL
Definition: core.h:77
std::string world_data_path
Definition: polcfg.h:28
static CPropProfiler & instance()
Definition: proplist.cpp:71
static void read_pol_config(bool initial_load)
Definition: polcfg.cpp:46
bool report_rtc_scripts
Definition: polcfg.h:79
unsigned int runaway_script_threshold
Definition: polcfg.h:55
#define POLLOG_INFO
Definition: logfacility.h:213
unsigned short listen_port
Definition: polcfg.h:31
unsigned int remove_ulong(const char *propname)
Definition: cfgfile.cpp:461
bool enforce_mount_objtype
Definition: polcfg.h:95
int remove_int(const char *propname)
Definition: cfgfile.cpp:340
bool passert_shutdown
Definition: passert.cpp:31
EScriptConfig escript_config
bool enable_secure_trading
Definition: polcfg.h:54
#define THREAD_CHECKPOINT(thread, check)
Definition: polsig.h:48
bool LogfileTimestampEveryLine
Definition: logfacility.cpp:32
bool retain_cleartext_passwords
Definition: polcfg.h:82
bool debug_local_only
Definition: polcfg.h:74
static void reload_pol_cfg()
Definition: polcfg.cpp:281
static void configureProgramAbortReportingSystem(bool active, std::string server, std::string url, std::string reporter)
Configures the bug reporting system.
std::string web_server_password
Definition: polcfg.h:49
unsigned short max_clients_bypass_cmdlevel
Definition: polcfg.h:66
#define POLLOG_ERROR
Definition: logfacility.h:207
#define UOBJ_SA_MAX
Definition: objtype.h:16
unsigned int max_tile_id
Definition: polcfg.h:61
bool passert_dump_stack
Definition: passert.cpp:30
void readraw(ConfigElem &elem)
Definition: cfgfile.cpp:1028
#define UOBJ_HSA_MAX
Definition: objtype.h:15
#define UOBJ_DEFAULT_MAX
Definition: objtype.h:17
bool show_realm_info
Definition: polcfg.h:94
bool exp_los_checks_map
Definition: polcfg.h:69
unsigned short debug_port
Definition: polcfg.h:72
int shutdown_save_type
Definition: polcfg.h:85
#define EXTOBJ_HIGHEST_DEFAULT
Definition: objtype.h:226
Crypt::TCryptInfo client_encryption_version
Definition: polcfg.h:43
unsigned short loglevel
Definition: polcfg.h:33
bool passert_nosave
Definition: passert.cpp:33
bool log_traces_when_stuck
Definition: polcfg.h:76
unsigned short select_timeout_usecs
Definition: polcfg.h:34
static void SetMiniDumpType(const std::string &dumptype)
Definition: mdump.cpp:64
bool ignore_load_errors
Definition: polcfg.h:56
const int SAVE_INCREMENTAL
Definition: core.h:78
bool display_unknown_packets
Definition: polcfg.h:68
static struct stat pol_cfg_stat
Definition: polcfg.h:111
unsigned short multithread
Definition: polcfg.h:44
bool web_server_local_only
Definition: polcfg.h:47
std::string pidfile_path
Definition: polcfg.h:30
unsigned short web_server_port
Definition: polcfg.h:46
std::string minidump_type
Definition: polcfg.h:88
GameState gamestate
Definition: uvars.cpp:74
bool report_missing_configs
Definition: polcfg.h:81
unsigned short min_cmdlevel_to_login
Definition: polcfg.h:60
bool show_speech_colors
Definition: polcfg.h:52
unsigned int max_call_depth
Definition: config.h:15
bool cache_interactive_scripts
Definition: polcfg.h:51
bool single_thread_decay
Definition: polcfg.h:96
bool use_single_thread_login
Definition: polcfg.h:91
void CalculateCryptKeys(const std::string &name, TCryptInfo &infoCrypt)
Definition: cryptkey.cpp:31
std::string strlower(const std::string &str)
Definition: strutil.cpp:276
static bool programAbortReporting()
Returns true if the bug reporting is active.
bool count_resource_tiles
Definition: polcfg.h:42
bool allow_multi_clients_per_account
Definition: polcfg.h:67
unsigned short inactivity_disconnect_timeout
Definition: polcfg.h:59
unsigned short remove_ushort(const char *propname)
Definition: cfgfile.cpp:318
unsigned short inactivity_warning_timeout
Definition: polcfg.h:58
bool report_program_aborts()
Returns true if program aborts are reported.
Definition: polcfg.cpp:306
std::string realm_data_path
Definition: polcfg.h:29
std::string normalized_dir_form(const std::string &istr)
Definition: fileutil.cpp:25
std::string uo_datafile_root
Definition: polcfg.h:27
bool report_critical_scripts
Definition: polcfg.h:80
bool discard_old_events
Definition: polcfg.h:83
unsigned short character_slots
Definition: polcfg.h:65
Definition: berror.cpp:12
bool log_script_cycles
Definition: polcfg.h:41
unsigned remove_unsigned(const char *propname)
Definition: cfgfile.cpp:360
bool remove_bool(const char *propname)
Definition: cfgfile.cpp:426
bool thread_decay_statistics
Definition: polcfg.h:97
std::unique_ptr< PeriodicTask > write_account_task
Definition: uvars.h:172
unsigned int max_objtype
Definition: polcfg.h:62
#define DISABLE_DEBUGLOG
Definition: logfacility.h:257
bool passert_abort
Definition: passert.cpp:32
unsigned short min_cmdlvl_ignore_inactivity
Definition: polcfg.h:57