You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

361 lines
12 KiB

  1. #define RESTART_COUNTER_PATH "data/round_counter.txt"
  2. GLOBAL_VAR(restart_counter)
  3. /**
  4. * World creation
  5. *
  6. * Here is where a round itself is actually begun and setup, lots of important config changes happen here
  7. * * db connection setup
  8. * * config loaded from files
  9. * * loads admins
  10. * * Sets up the dynamic menu system
  11. * * and most importantly, calls initialize on the master subsystem, starting the game loop that causes the rest of the game to begin processing and setting up
  12. *
  13. * Note this happens after the Master subsystem is created (as that is a global datum), this means all the subsystems exist,
  14. * but they have not been Initialized at this point, only their New proc has run
  15. *
  16. * Nothing happens until something moves. ~Albert Einstein
  17. *
  18. */
  19. /world/New()
  20. enable_debugger()
  21. //Early profile for auto-profiler - will be stopped on profiler init if necessary.
  22. #if DM_BUILD >= 1506
  23. world.Profile(PROFILE_START)
  24. #endif
  25. log_world("World loaded at [time_stamp()]!")
  26. SetupExternalRSC()
  27. GLOB.config_error_log = GLOB.world_manifest_log = GLOB.world_pda_log = GLOB.world_job_debug_log = GLOB.sql_error_log = GLOB.world_href_log = GLOB.world_runtime_log = GLOB.world_attack_log = GLOB.world_game_log = GLOB.world_shuttle_log = "data/logs/config_error.[GUID()].log" //temporary file used to record errors with loading config, moved to log directory once logging is set bl
  28. make_datum_references_lists() //initialises global lists for referencing frequently used datums (so that we only ever do it once)
  29. TgsNew(minimum_required_security_level = TGS_SECURITY_TRUSTED)
  30. GLOB.revdata = new
  31. config.Load(params[OVERRIDE_CONFIG_DIRECTORY_PARAMETER])
  32. load_admins()
  33. //SetupLogs depends on the RoundID, so lets check
  34. //DB schema and set RoundID if we can
  35. SSdbcore.CheckSchemaVersion()
  36. SSdbcore.SetRoundID()
  37. SetupLogs()
  38. #ifndef USE_CUSTOM_ERROR_HANDLER
  39. world.log = file("[GLOB.log_directory]/dd.log")
  40. #else
  41. if (TgsAvailable())
  42. world.log = file("[GLOB.log_directory]/dd.log") //not all runtimes trigger world/Error, so this is the only way to ensure we can see all of them.
  43. #endif
  44. LoadVerbs(/datum/verbs/menu)
  45. if(CONFIG_GET(flag/usewhitelist))
  46. load_whitelist()
  47. GLOB.timezoneOffset = text2num(time2text(0,"hh")) * 36000
  48. if(fexists(RESTART_COUNTER_PATH))
  49. GLOB.restart_counter = text2num(trim(file2text(RESTART_COUNTER_PATH)))
  50. fdel(RESTART_COUNTER_PATH)
  51. if(NO_INIT_PARAMETER in params)
  52. return
  53. Master.Initialize(10, FALSE, TRUE)
  54. if(TEST_RUN_PARAMETER in params)
  55. HandleTestRun()
  56. /world/proc/HandleTestRun()
  57. //trigger things to run the whole process
  58. Master.sleep_offline_after_initializations = FALSE
  59. SSticker.start_immediately = TRUE
  60. CONFIG_SET(number/round_end_countdown, 0)
  61. var/datum/callback/cb
  62. #ifdef UNIT_TESTS
  63. cb = CALLBACK(GLOBAL_PROC, /proc/RunUnitTests)
  64. #else
  65. cb = VARSET_CALLBACK(SSticker, force_ending, TRUE)
  66. #endif
  67. SSticker.OnRoundstart(CALLBACK(GLOBAL_PROC, /proc/addtimer, cb, 10 SECONDS))
  68. /world/proc/SetupExternalRSC()
  69. #if (PRELOAD_RSC == 0)
  70. GLOB.external_rsc_urls = world.file2list("[global.config.directory]/external_rsc_urls.txt","\n")
  71. var/i=1
  72. while(i<=GLOB.external_rsc_urls.len)
  73. if(GLOB.external_rsc_urls[i])
  74. i++
  75. else
  76. GLOB.external_rsc_urls.Cut(i,i+1)
  77. #endif
  78. /world/proc/SetupLogs()
  79. var/override_dir = params[OVERRIDE_LOG_DIRECTORY_PARAMETER]
  80. if(!override_dir)
  81. var/realtime = world.realtime
  82. var/texttime = time2text(realtime, "YYYY/MM/DD")
  83. GLOB.log_directory = "data/logs/[texttime]/round-"
  84. GLOB.picture_logging_prefix = "L_[time2text(realtime, "YYYYMMDD")]_"
  85. GLOB.picture_log_directory = "data/picture_logs/[texttime]/round-"
  86. if(GLOB.round_id)
  87. GLOB.log_directory += "[GLOB.round_id]"
  88. GLOB.picture_logging_prefix += "R_[GLOB.round_id]_"
  89. GLOB.picture_log_directory += "[GLOB.round_id]"
  90. else
  91. var/timestamp = replacetext(time_stamp(), ":", ".")
  92. GLOB.log_directory += "[timestamp]"
  93. GLOB.picture_log_directory += "[timestamp]"
  94. GLOB.picture_logging_prefix += "T_[timestamp]_"
  95. else
  96. GLOB.log_directory = "data/logs/[override_dir]"
  97. GLOB.picture_logging_prefix = "O_[override_dir]_"
  98. GLOB.picture_log_directory = "data/picture_logs/[override_dir]"
  99. GLOB.world_game_log = "[GLOB.log_directory]/game.log"
  100. GLOB.world_mecha_log = "[GLOB.log_directory]/mecha.log"
  101. GLOB.world_virus_log = "[GLOB.log_directory]/virus.log"
  102. GLOB.world_cloning_log = "[GLOB.log_directory]/cloning.log"
  103. GLOB.world_asset_log = "[GLOB.log_directory]/asset.log"
  104. GLOB.world_attack_log = "[GLOB.log_directory]/attack.log"
  105. GLOB.world_pda_log = "[GLOB.log_directory]/pda.log"
  106. GLOB.world_telecomms_log = "[GLOB.log_directory]/telecomms.log"
  107. GLOB.world_manifest_log = "[GLOB.log_directory]/manifest.log"
  108. GLOB.world_href_log = "[GLOB.log_directory]/hrefs.log"
  109. GLOB.sql_error_log = "[GLOB.log_directory]/sql.log"
  110. GLOB.world_qdel_log = "[GLOB.log_directory]/qdel.log"
  111. GLOB.world_map_error_log = "[GLOB.log_directory]/map_errors.log"
  112. GLOB.world_runtime_log = "[GLOB.log_directory]/runtime.log"
  113. GLOB.query_debug_log = "[GLOB.log_directory]/query_debug.log"
  114. GLOB.world_job_debug_log = "[GLOB.log_directory]/job_debug.log"
  115. GLOB.world_paper_log = "[GLOB.log_directory]/paper.log"
  116. GLOB.tgui_log = "[GLOB.log_directory]/tgui.log"
  117. GLOB.world_shuttle_log = "[GLOB.log_directory]/shuttle.log"
  118. GLOB.discord_api_log = "[GLOB.log_directory]/discord_api_log.log"
  119. GLOB.demo_log = "[GLOB.log_directory]/demo.log"
  120. #ifdef UNIT_TESTS
  121. GLOB.test_log = file("[GLOB.log_directory]/tests.log")
  122. start_log(GLOB.test_log)
  123. #endif
  124. start_log(GLOB.world_game_log)
  125. start_log(GLOB.world_attack_log)
  126. start_log(GLOB.world_pda_log)
  127. start_log(GLOB.world_telecomms_log)
  128. start_log(GLOB.world_manifest_log)
  129. start_log(GLOB.world_href_log)
  130. start_log(GLOB.world_qdel_log)
  131. start_log(GLOB.world_runtime_log)
  132. start_log(GLOB.world_job_debug_log)
  133. start_log(GLOB.tgui_log)
  134. start_log(GLOB.world_shuttle_log)
  135. start_log(GLOB.discord_api_log)
  136. GLOB.changelog_hash = md5('html/changelog.html') //for telling if the changelog has changed recently
  137. if(fexists(GLOB.config_error_log))
  138. fcopy(GLOB.config_error_log, "[GLOB.log_directory]/config_error.log")
  139. fdel(GLOB.config_error_log)
  140. if(GLOB.round_id)
  141. log_game("Round ID: [GLOB.round_id]")
  142. // This was printed early in startup to the world log and config_error.log,
  143. // but those are both private, so let's put the commit info in the runtime
  144. // log which is ultimately public.
  145. log_runtime(GLOB.revdata.get_log_message())
  146. /world/Topic(T, addr, master, key)
  147. TGS_TOPIC //redirect to server tools if necessary
  148. var/static/list/topic_handlers = TopicHandlers()
  149. var/list/input = params2list(T)
  150. var/datum/world_topic/handler
  151. for(var/I in topic_handlers)
  152. if(I in input)
  153. handler = topic_handlers[I]
  154. break
  155. if((!handler || initial(handler.log)) && config && CONFIG_GET(flag/log_world_topic))
  156. log_topic("\"[T]\", from:[addr], master:[master], key:[key]")
  157. if(!handler)
  158. return
  159. handler = new handler()
  160. return handler.TryRun(input)
  161. /world/proc/AnnouncePR(announcement, list/payload)
  162. var/static/list/PRcounts = list() //PR id -> number of times announced this round
  163. var/id = "[payload["pull_request"]["id"]]"
  164. if(!PRcounts[id])
  165. PRcounts[id] = 1
  166. else
  167. ++PRcounts[id]
  168. if(PRcounts[id] > PR_ANNOUNCEMENTS_PER_ROUND)
  169. return
  170. var/final_composed = "<span class='announce'>PR: [announcement]</span>"
  171. for(var/client/C in GLOB.clients)
  172. C.AnnouncePR(final_composed)
  173. /world/proc/FinishTestRun()
  174. set waitfor = FALSE
  175. var/list/fail_reasons
  176. if(GLOB)
  177. if(GLOB.total_runtimes != 0)
  178. fail_reasons = list("Total runtimes: [GLOB.total_runtimes]")
  179. #ifdef UNIT_TESTS
  180. if(GLOB.failed_any_test)
  181. LAZYADD(fail_reasons, "Unit Tests failed!")
  182. #endif
  183. if(!GLOB.log_directory)
  184. LAZYADD(fail_reasons, "Missing GLOB.log_directory!")
  185. else
  186. fail_reasons = list("Missing GLOB!")
  187. if(!fail_reasons)
  188. text2file("Success!", "[GLOB.log_directory]/clean_run.lk")
  189. else
  190. log_world("Test run failed!\n[fail_reasons.Join("\n")]")
  191. sleep(0) //yes, 0, this'll let Reboot finish and prevent byond memes
  192. qdel(src) //shut it down
  193. /world/Reboot(reason = 0, fast_track = FALSE)
  194. if (reason || fast_track) //special reboot, do none of the normal stuff
  195. if (usr)
  196. log_admin("[key_name(usr)] Has requested an immediate world restart via client side debugging tools")
  197. message_admins("[key_name_admin(usr)] Has requested an immediate world restart via client side debugging tools")
  198. to_chat(world, "<span class='boldannounce'>Rebooting World immediately due to host request.</span>")
  199. else
  200. to_chat(world, "<span class='boldannounce'>Rebooting world...</span>")
  201. Master.Shutdown() //run SS shutdowns
  202. TgsReboot()
  203. if(TEST_RUN_PARAMETER in params)
  204. FinishTestRun()
  205. return
  206. if(TgsAvailable())
  207. var/do_hard_reboot
  208. // check the hard reboot counter
  209. var/ruhr = CONFIG_GET(number/rounds_until_hard_restart)
  210. switch(ruhr)
  211. if(-1)
  212. do_hard_reboot = FALSE
  213. if(0)
  214. do_hard_reboot = TRUE
  215. else
  216. if(GLOB.restart_counter >= ruhr)
  217. do_hard_reboot = TRUE
  218. else
  219. text2file("[++GLOB.restart_counter]", RESTART_COUNTER_PATH)
  220. do_hard_reboot = FALSE
  221. if(do_hard_reboot)
  222. log_world("World hard rebooted at [time_stamp()]")
  223. shutdown_logging() // See comment below.
  224. TgsEndProcess()
  225. log_world("World rebooted at [time_stamp()]")
  226. shutdown_logging() // Past this point, no logging procs can be used, at risk of data loss.
  227. ..()
  228. /world/proc/update_status()
  229. var/list/features = list()
  230. if(GLOB.master_mode)
  231. features += GLOB.master_mode
  232. if (!GLOB.enter_allowed)
  233. features += "closed"
  234. var/s = ""
  235. var/hostedby
  236. if(config)
  237. var/server_name = CONFIG_GET(string/servername)
  238. if (server_name)
  239. s += "<b>[server_name]</b> &#8212; "
  240. features += "[CONFIG_GET(flag/norespawn) ? "no " : ""]respawn"
  241. if(CONFIG_GET(flag/allow_vote_mode))
  242. features += "vote"
  243. if(CONFIG_GET(flag/allow_ai))
  244. features += "AI allowed"
  245. hostedby = CONFIG_GET(string/hostedby)
  246. s += "<b>[station_name()]</b>";
  247. s += " ("
  248. s += "<a href=\"http://\">" //Change this to wherever you want the hub to link to.
  249. s += "Default" //Replace this with something else. Or ever better, delete it and uncomment the game version.
  250. s += "</a>"
  251. s += ")"
  252. var/players = GLOB.clients.len
  253. var/popcaptext = ""
  254. var/popcap = max(CONFIG_GET(number/extreme_popcap), CONFIG_GET(number/hard_popcap), CONFIG_GET(number/soft_popcap))
  255. if (popcap)
  256. popcaptext = "/[popcap]"
  257. if (players > 1)
  258. features += "[players][popcaptext] players"
  259. else if (players > 0)
  260. features += "[players][popcaptext] player"
  261. game_state = (CONFIG_GET(number/extreme_popcap) && players >= CONFIG_GET(number/extreme_popcap)) //tells the hub if we are full
  262. if (!host && hostedby)
  263. features += "hosted by <b>[hostedby]</b>"
  264. if (features)
  265. s += ": [jointext(features, ", ")]"
  266. status = s
  267. /world/proc/update_hub_visibility(new_visibility)
  268. if(new_visibility == GLOB.hub_visibility)
  269. return
  270. GLOB.hub_visibility = new_visibility
  271. if(GLOB.hub_visibility)
  272. hub_password = "kMZy3U5jJHSiBQjr"
  273. else
  274. hub_password = "SORRYNOPASSWORD"
  275. /world/proc/incrementMaxZ()
  276. maxz++
  277. SSmobs.MaxZChanged()
  278. SSidlenpcpool.MaxZChanged()
  279. /world/proc/change_fps(new_value = 20)
  280. if(new_value <= 0)
  281. CRASH("change_fps() called with [new_value] new_value.")
  282. if(fps == new_value)
  283. return //No change required.
  284. fps = new_value
  285. on_tickrate_change()
  286. /world/proc/change_tick_lag(new_value = 0.5)
  287. if(new_value <= 0)
  288. CRASH("change_tick_lag() called with [new_value] new_value.")
  289. if(tick_lag == new_value)
  290. return //No change required.
  291. tick_lag = new_value
  292. on_tickrate_change()
  293. /world/proc/on_tickrate_change()
  294. SStimer?.reset_buckets()