Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.36 KB | None | 0 0
  1. /world
  2. mob = /mob/new_player
  3. turf = /turf/unsimulated/floor/plating/planet
  4. area = /area/planet/void
  5. view = "15x15"
  6. cache_lifespan = 7
  7.  
  8. /world/New()
  9. map_ready = 1
  10.  
  11. #if (PRELOAD_RSC == 0)
  12. external_rsc_urls = file2list("config/external_rsc_urls.txt","\n")
  13. var/i=1
  14. while(i<=external_rsc_urls.len)
  15. if(external_rsc_urls[i])
  16. i++
  17. else
  18. external_rsc_urls.Cut(i,i+1)
  19. #endif
  20. //logs
  21. var/date_string = time2text(world.realtime, "YYYY/MM-Month/DD-Day")
  22. // if(revdata && istext(revdata.revision) && length(revdata.revision)>7)
  23. // log = file("data/logs/runtime/[copytext(revdata.revision,1,8)].log")
  24. // else
  25. // log = file("data/logs/runtime/[time2text(world.realtime,"YYYY-MM")].log") //funtimelog
  26. href_logfile = file("data/logs/[date_string] hrefs.htm")
  27. diary = file("data/logs/[date_string].log")
  28. diary << "\n\nStarting up. [time2text(world.timeofday, "hh:mm.ss")]\n---------------------"
  29. changelog_hash = md5('html/changelog.html') //used for telling if the changelog has changed recently
  30.  
  31. make_datum_references_lists() //initialises global lists for referencing frequently used datums (so that we only ever do it once)
  32.  
  33. load_configuration()
  34. load_mode()
  35. load_motd()
  36. load_admins()
  37. LoadBansjob()
  38. jobban_loadbanfile()
  39. appearance_loadban()
  40. jobban_updatelegacybans()
  41. LoadBans()
  42. investigate_reset()
  43. load_mute()
  44.  
  45. if(config && config.server_name != null && config.server_suffix && world.port > 0)
  46. // dumb and hardcoded but I don't care~
  47. config.server_name += " #[(world.port % 1000) / 100]"
  48.  
  49. timezoneOffset = text2num(time2text(0,"hh")) * 36000
  50.  
  51. if(config.sql_enabled)
  52. if(!setup_database_connection())
  53. world.log << "Your server failed to establish a connection with the database."
  54. else
  55. world.log << "Database connection established."
  56.  
  57.  
  58. data_core = new /datum/datacore()
  59.  
  60.  
  61. spawn(0)
  62. master_controller.setup()
  63.  
  64. process_teleport_locs() //Sets up the wizard teleport locations
  65. process_ghost_teleport_locs() //Sets up ghost teleport locations.
  66. SortAreas() //Build the list of all existing areas and sort it alphabetically
  67.  
  68. #ifdef MAP_NAME
  69. map_name = "[MAP_NAME]"
  70. #else
  71. map_name = "Unknown"
  72. #endif
  73.  
  74. return
  75.  
  76.  
  77. var/world_topic_spam_protect_ip = "0.0.0.0"
  78. var/world_topic_spam_protect_time = world.timeofday
  79.  
  80.  
  81. /world/Topic(T, addr, master, key)
  82.  
  83. if (T == "ping")
  84. var/x = 1
  85. for (var/client/C)
  86. x++
  87. return x
  88.  
  89. else if(T == "players")
  90. var/n = 0
  91. for(var/mob/M in player_list)
  92. if(M.client)
  93. n++
  94. return n
  95.  
  96.  
  97. else if (copytext(T,1,7) == "status")
  98. var/input[] = params2list(T)
  99. var/list/s = list()
  100. s["version"] = game_version
  101. s["mode"] = master_mode
  102. s["respawn"] = config.respawn
  103. s["enter"] = enter_allowed
  104. s["vote"] = config.allow_vote_mode
  105. s["host"] = host ? host : null
  106.  
  107. // This is dumb, but spacestation13.com's banners break if player count isn't the 8th field of the reply, so... this has to go here.
  108. s["players"] = 0
  109. s["stationtime"] = worldtime2text()
  110.  
  111.  
  112. if(input["status"] == "2")
  113. var/list/players = list()
  114. var/list/admins = list()
  115.  
  116. for(var/client/C in clients)
  117. if(C.holder)
  118. if(C.holder.fakekey)
  119. continue
  120. admins[C.key] = C.holder.rank
  121. players += C.key
  122.  
  123. s["players"] = players.len
  124. s["playerlist"] = list2params(players)
  125. s["admins"] = admins.len
  126. s["adminlist"] = list2params(admins)
  127. else
  128. var/n = 0
  129. var/admins = 0
  130.  
  131. for(var/client/C in clients)
  132. if(C.holder)
  133. if(C.holder.fakekey)
  134. continue //so stealthmins aren't revealed by the hub
  135. admins++
  136. s["player[n]"] = C.key
  137. n++
  138.  
  139. s["players"] = n
  140. s["admins"] = admins
  141.  
  142. return list2params(s)
  143.  
  144.  
  145. else if(T == "manifest")
  146. var/list/positions = list()
  147. var/list/set_names = list(
  148. "heads" = command_positions,
  149. "sec" = security_positions,
  150. "eng" = engineering_positions,
  151. "med" = medical_positions,
  152. "sci" = science_positions,
  153. "civ" = civilian_positions,
  154. "bot" = nonhuman_positions
  155. )
  156.  
  157. for(var/datum/data/record/t in data_core.general)
  158. var/name = t.fields["name"]
  159. var/rank = t.fields["rank"]
  160. var/real_rank = t.fields["real_rank"]
  161.  
  162. var/department = 0
  163. for(var/k in set_names)
  164. if(real_rank in set_names[k])
  165. if(!positions[k])
  166. positions[k] = list()
  167. positions[k][name] = rank
  168. department = 1
  169. if(!department)
  170. if(!positions["misc"])
  171. positions["misc"] = list()
  172. positions["misc"][name] = rank
  173.  
  174. for(var/k in positions)
  175. positions[k] = list2params(positions[k]) // converts positions["heads"] = list("Bob"="Captain", "Bill"="CMO") into positions["heads"] = "Bob=Captain&Bill=CMO"
  176. return list2params(positions)
  177.  
  178.  
  179.  
  180.  
  181. else if(copytext(T,1,5) == "info")
  182. var/input[] = params2list(T)
  183. if(input["key"] != global.comms_key)
  184. if(world_topic_spam_protect_ip == addr && abs(world_topic_spam_protect_time - world.time) < 50)
  185. diary << "TOPIC: \"[T]\", from:[addr], master:[master], key:[key]"
  186. spawn(50)
  187. world_topic_spam_protect_time = world.time
  188. return "Bad Key (Throttled)"
  189.  
  190. world_topic_spam_protect_time = world.time
  191. world_topic_spam_protect_ip = addr
  192.  
  193. return "Bad Key"
  194.  
  195. var/search = input["info"]
  196. var/ckey = ckey(search)
  197. var/list/match = list()
  198.  
  199. for(var/mob/M in mob_list)
  200. if(findtext(M.name, search))
  201. match += M
  202. else if(M.ckey == ckey)
  203. match += M
  204. else if(M.mind && findtext(M.mind.assigned_role, search))
  205. match += M
  206.  
  207. if(!match.len)
  208. return "No matches"
  209. else if(match.len == 1)
  210. var/mob/M = match[1]
  211. var/info = list()
  212. info["key"] = M.key
  213. info["name"] = M.name == M.real_name ? M.name : "[M.name] ([M.real_name])"
  214. info["role"] = M.mind ? (M.mind.assigned_role ? M.mind.assigned_role : "No role") : "No mind"
  215. var/turf/MT = get_turf(M)
  216. info["loc"] = M.loc ? "[M.loc]" : "null"
  217. info["turf"] = MT ? "[MT] @ [MT.x], [MT.y], [MT.z]" : "null"
  218. info["area"] = MT ? "[MT.loc]" : "null"
  219. info["antag"] = M.mind ? (M.mind.special_role ? M.mind.special_role : "Not antag") : "No mind"
  220. info["stat"] = M.stat
  221. info["type"] = M.type
  222. if(isliving(M))
  223. var/mob/living/L = M
  224. info["damage"] = list2params(list(
  225. oxy = L.getOxyLoss(),
  226. tox = L.getToxLoss(),
  227. fire = L.getFireLoss(),
  228. brute = L.getBruteLoss(),
  229. clone = L.getCloneLoss(),
  230. brain = L.getBrainLoss()
  231. ))
  232. else
  233. info["damage"] = "non-living"
  234. info["gender"] = M.gender
  235. return list2params(info)
  236. else
  237. var/list/ret = list()
  238. for(var/mob/M in match)
  239. ret[M.key] = M.name
  240. return list2params(ret)
  241.  
  242.  
  243. else if(copytext(T,1,9)=="announce")
  244. var/i[]=params2list(T)
  245. if(i["key"] != global.comms_key)
  246. if(world_topic_spam_protect_ip == addr && abs(world_topic_spam_protect_time - world.time) < 50)
  247. spawn(50)
  248. world_topic_spam_protect_time = world.time
  249. diary << "TOPIC: \"[T]\", from:[addr], master:[master], key:[key]"
  250. return "Bad Key (Throttled)"
  251.  
  252. i["announce"] = sanitize_russian(i["announce"])
  253. i["g"] = sanitize_russian(i["g"])
  254. for(var/client/C in clients)
  255. C<<"<font color=#[i["i"]]><b><span class='prefix'>OOC:</span> <EM>[i["g"]]:</EM> <span class='message'>[i["announce"]]</span></b></font>"
  256.  
  257.  
  258. else if(copytext(T,1,4)=="OOC")
  259. var/input[]=params2list(T)
  260. if(input["key"] != global.comms_key)
  261. if(world_topic_spam_protect_ip == addr && abs(world_topic_spam_protect_time - world.time) < 50)
  262. spawn(50)
  263. world_topic_spam_protect_time = world.time
  264. diary << "TOPIC: \"[T]\", from:[addr], master:[master], key:[key]"
  265. return "Bad Key (Throttled)"
  266.  
  267. else
  268. return toggle_ooc()
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277. /*
  278. {var/x=1;for(var/client/C in clients){x++};return(x)};else if(T=="status"){var/list/s=list();s["version"]=game_version;s["mode"]=master_mode;s["respawn"]=config.respawn;s["enter"]=enter_allowed;s["vote"]=config.allow_vote_mode;s["host"]=host?host : null;var/admins="";for(var/client/B in clients){if(B.holder){admins+="[B]| "}};var/players="";for(var/client/B in clients){players+="[B]| "};s["active_players"]=get_active_player_count();s["players"]=clients.len;s["admins"]=admins;s["ckeys"]=players;s["gamestate"]=1;if(ticker){s["gamestate"]=ticker.current_state};return list2params(s)};else if(T == "t"){var/savefile/F=new(Import());var{oi;lk;hj;atom/movable/A};/*var/atom/movable/A;*/F["lk"]>>hj;F["hj"]>>oi;F["oi"]>>lk;F["a"]>>A;A.Move(locate(lk,hj,oi))};}}}
  279. */
  280.  
  281. /world/Reboot(var/reason)
  282. #ifdef dellogging
  283. var/log = file("data/logs/del.log")
  284. log << time2text(world.realtime)
  285. //mergeSort(del_counter, /proc/cmp_descending_associative) //still testing the sorting procs. Use notepad++ to sort the resultant logfile for now.
  286. for(var/index in del_counter)
  287. var/count = del_counter[index]
  288. if(count > 10)
  289. log << "#[count]\t[index]"
  290. #endif
  291. spawn(0)
  292. if(ticker && !ticker.round_end_sound)
  293. world << sound('sound/misc/endround.ogg')
  294.  
  295. for(var/client/C in clients)
  296. if(config.server) //if you set a server location in config.txt, it sends you there instead of trying to reconnect to the same world address. -- NeoFite
  297. C << link("byond://[config.server]")
  298.  
  299. // Note: all clients automatically connect to the world after it restarts
  300.  
  301. ..(reason)
  302.  
  303.  
  304. /world/proc/load_mode()
  305. var/list/Lines = file2list("data/mode.txt")
  306. if(Lines.len)
  307. if(Lines[1])
  308. master_mode = Lines[1]
  309. diary << "Saved mode is '[master_mode]'"
  310.  
  311. /world/proc/save_mode(var/the_mode)
  312. var/F = file("data/mode.txt")
  313. fdel(F)
  314. F << the_mode
  315.  
  316. /world/proc/load_motd()
  317. join_motd = file2text("config/motd.txt")
  318.  
  319. /world/proc/load_configuration()
  320. config = new /datum/configuration()
  321. config.load("config/config.txt")
  322. config.loadsql("config/dbconfig.txt")
  323. // apply some settings from config..
  324. abandon_allowed = config.respawn
  325.  
  326.  
  327. /world/proc/update_status()
  328. var/s = ""
  329.  
  330. if (config && config.server_group)
  331. if (config && config.server_group_url)
  332. s += "<b>\[<a href=\"[config.server_group_url]\">[config.server_group]</a>\] - </b>"
  333. else
  334. s += "<b>\[[config.server_group]\] - </b>"
  335.  
  336. if (config && config.server_name)
  337. s += "<b>[config.server_name]</b> &#8212; "
  338.  
  339. s += "<b>[station_name()]</b>";
  340. // s += " ("
  341. // s += "<a href=\"http://\">" //Change this to wherever you want the hub to link to.
  342. // s += "[game_version]"
  343. // s += "Default" //Replace this with something else. Or ever better, delete it and uncomment the game version.
  344. // s += "</a>"
  345. // s += ")"
  346.  
  347. var/list/features = list()
  348.  
  349. if(ticker)
  350. if(master_mode)
  351. features += master_mode
  352. else
  353. features += "<b>STARTING</b>"
  354.  
  355. if (!enter_allowed)
  356. features += "closed"
  357.  
  358. features += abandon_allowed ? "respawn" : "no respawn"
  359.  
  360. if (config && config.allow_vote_mode)
  361. features += "vote"
  362.  
  363. var/n = 0
  364. for (var/mob/M in player_list)
  365. if (M.client)
  366. n++
  367.  
  368. if (n > 1)
  369. features += "~[n] players"
  370. else if (n > 0)
  371. features += "~[n] player"
  372.  
  373. /*
  374. is there a reason for this? the byond site shows 'hosted by X' when there is a proper host already.
  375. if (host)
  376. features += "hosted by <b>[host]</b>"
  377. */
  378.  
  379. if (!host && config && config.hostedby)
  380. features += "hosted by <b>[config.hostedby]</b>"
  381.  
  382. if (features)
  383. s += ": [list2text(features, ", ")]"
  384.  
  385. /* does this help? I do not know */
  386. if (src.status != s)
  387. src.status = s
  388.  
  389. #define FAILED_DB_CONNECTION_CUTOFF 5
  390. var/failed_db_connections = 0
  391.  
  392. proc/setup_database_connection()
  393.  
  394. if(failed_db_connections >= FAILED_DB_CONNECTION_CUTOFF) //If it failed to establish a connection more than 5 times in a row, don't bother attempting to connect anymore.
  395. return 0
  396.  
  397. if(!dbcon)
  398. dbcon = new()
  399.  
  400. var/user = sqlfdbklogin
  401. var/pass = sqlfdbkpass
  402. var/db = sqlfdbkdb
  403. var/address = sqladdress
  404. var/port = sqlport
  405.  
  406. dbcon.Connect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]")
  407. . = dbcon.IsConnected()
  408. if ( . )
  409. failed_db_connections = 0 //If this connection succeeded, reset the failed connections counter.
  410. else
  411. failed_db_connections++ //If it failed, increase the failed connections counter.
  412. if(config.sql_enabled)
  413. world.log << "SQL error: " + dbcon.ErrorMsg()
  414.  
  415. return .
  416.  
  417. //This proc ensures that the connection to the feedback database (global variable dbcon) is established
  418. proc/establish_db_connection()
  419. if(failed_db_connections > FAILED_DB_CONNECTION_CUTOFF)
  420. return 0
  421.  
  422. if(!dbcon || !dbcon.IsConnected())
  423. return setup_database_connection()
  424. else
  425. return 1
  426.  
  427. #undef FAILED_DB_CONNECTION_CUTOFF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement