Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.44 KB | None | 0 0
  1. var
  2. dontdoshit=0
  3. fuckupcount=0
  4. PASSWORD="root"
  5. list/Serverlist=new
  6. save_system/mysql/saves
  7. sql_host
  8. sql_database
  9. sql_user
  10. sql_password
  11.  
  12. check_ref
  13. var
  14. success = 0
  15. count = 0
  16.  
  17. proc
  18. // Mirror a topic message to every connected server, except the source server.
  19. mirror(href, addr, file)
  20. spawn() for(var/X in (Serverlist - addr))
  21. world.Export("[X]?[href]", file)
  22. mirror_check(href, addr, file)
  23. var/check_ref/ret = new
  24. var/launched = 0
  25. for(var/X in (Serverlist - addr))
  26. ++launched
  27. spawn()
  28. var/val = world.Export("[X]?[href]", file)
  29. ++ret.count
  30. ret.success = ret.success || val
  31. while(launched > ret.count && !ret.success)
  32. sleep(1)
  33. return ret.success
  34.  
  35. update_helpers(addr)
  36. var/list/helpers = saves.GetHelpers()
  37.  
  38. for(var/village in helpers)
  39. var/topic = list("action" = "update_helpers", "village" = village, "names" = dd_list2text(helpers[village],";"), "Password"=PASSWORD)
  40. if(!addr)
  41. mirror(list2params(topic))
  42. else
  43. world.Export("[addr]?[list2params(topic)]")
  44.  
  45. world/proc
  46. Reeb()
  47. dontdoshit=1
  48.  
  49. shutdown()
  50.  
  51. // Make sure servers are still connected.
  52. Server_Loop()
  53. set background = 1
  54. while(world)
  55. for(var/X in Serverlist)
  56. spawn()
  57. if(!world.Export("[X]?ping"))
  58. world.log << "Removed server [X]: Ping failed"
  59. Serverlist -= X
  60.  
  61. sleep(600) // Repeat every minute.
  62.  
  63. world/New()
  64. ..()
  65. var/ini_reader/IRead = new("config.ini", INIREADER_INI)
  66. var/list/Dict = IRead.ReadSetting("settings")
  67.  
  68. sql_host=Dict["SQL_Host"]
  69. sql_database=Dict["SQL_Database"]
  70. sql_user=Dict["SQL_User"]
  71. sql_password=Dict["SQL_Password"]
  72.  
  73. // Connect to MySQL database.
  74. saves = new /save_system/mysql(sql_host, sql_database, sql_user, sql_password)
  75. if(!saves.ready)
  76. del world
  77.  
  78. // Start up ping loop.
  79. spawn() Server_Loop()
  80.  
  81. world/Topic(href, addr)
  82. if(!saves.IsAllowedServer(copytext(addr, 1, findtext(addr, ":"))))
  83. return 0
  84.  
  85. // Let pings go through without a password
  86. if(href == "ping") return ..()
  87. if(dontdoshit)
  88. return
  89.  
  90. var/T[] = params2list(href)
  91. var/P=T["Password"]
  92.  
  93. if(P!=PASSWORD)
  94. return
  95.  
  96. #if DM_VERSION >= 462
  97. if(findtextEx(addr, ":"))
  98. #else
  99. if(findText(addr, ":"))
  100. #endif
  101. // It's a server we don't already know about -- assume it's new.
  102. if(!(addr in Serverlist))
  103. world.log << "Added server [addr]"
  104. Serverlist += addr
  105. else
  106. // Server without a port!
  107. // The announce scripts trigger this, so let them through
  108. // Anything else should be ignored because it's a copy of the game running in DS
  109. if(T["action"] != "announce")
  110. return
  111.  
  112. switch(T["action"])
  113. if("newserver")
  114. spawn()
  115. update_helpers(addr)
  116. if("announce")
  117. mirror(href, addr)
  118.  
  119. if("chat_mirror")
  120. T["source"] = addr
  121. mirror(list2params(T), addr)
  122.  
  123. if("mute")
  124. world.Export("[T["server"]]?[href]")
  125.  
  126.  
  127. if("is-logged-in")
  128. return mirror_check(href, addr)
  129.  
  130. if("get_chars")
  131. . = saves.GetCharacterNames(T["key"])
  132.  
  133. if(istype(., /list))
  134. . = list2params(.)
  135.  
  136. return .
  137.  
  138. if("check_name")
  139. return saves.IsNameUsed(T["name"])
  140.  
  141. if("new_squad")
  142. return saves.CreateSquad(T["name"], T["leader"])
  143.  
  144. if("squad_delete")
  145. . = saves.DeleteSquad(T["squad"])
  146.  
  147. if(. && !T["nomirror"])
  148. mirror(href, addr)
  149.  
  150. return .
  151.  
  152. if("squad_leader_change")
  153. . = saves.ChangeSquadLeader(T["squad"], T["new_leader"])
  154.  
  155. if(.)
  156. mirror(href, addr)
  157.  
  158. return .
  159.  
  160. if("squad_member_count")
  161. return saves.GetSquadMemberCount(T["squad"])
  162.  
  163. if("squad_info")
  164. . = saves.GetSquadInfo(T["squad"])
  165.  
  166. if(istype(., /list))
  167. . = list2params(.)
  168.  
  169. return .
  170.  
  171. if("new_faction")
  172. return saves.CreateFaction(T["name"], T["leader"], T["village"], T["mouse_icon"], T["chat_icon"], T["chuunin_item"], T["member_limit"])
  173.  
  174. if("faction_delete")
  175. . = saves.DeleteFaction(T["faction"])
  176.  
  177. if(. && !T["nomirror"])
  178. mirror(href, addr)
  179.  
  180. return .
  181.  
  182. if("faction_leader_change")
  183. . = saves.ChangeFactionLeader(T["faction"], T["new_leader"])
  184.  
  185. if(.)
  186. mirror(href, addr)
  187.  
  188. return .
  189.  
  190. if("faction_member_count")
  191. return saves.GetFactionMemberCount(T["squad"])
  192.  
  193. if("faction_info")
  194. . = saves.GetFactionInfo(T["faction"])
  195.  
  196. if(istype(., /list))
  197. . = list2params(.)
  198.  
  199. return .
  200.  
  201. if("add_helper")
  202. . = saves.AddHelper(T["name"], T["village"])
  203.  
  204. if(.)
  205. update_helpers()
  206.  
  207. return .
  208.  
  209. if("remove_helper")
  210. . = saves.RemoveHelper(T["name"], T["village"])
  211.  
  212. if(.)
  213. update_helpers()
  214.  
  215. return .
  216.  
  217. if("is_banned")
  218. return saves.IsBanned(T["key"], T["computer_id"])
  219.  
  220. if("add_ban")
  221. return saves.AddBan(T["key"], T["computer_id"])
  222.  
  223. if("remove_ban")
  224. return saves.RemoveBan(T["key"], T["computer_id"])
  225.  
  226. if("char_info_set_comment")
  227. return saves.SetInfoCardComment(T["char"], T["village"], T["comment"])
  228.  
  229. if("char_info_card")
  230. . = saves.GetInfoCard(T["char"], T["village"])
  231.  
  232. if(istype(., /list))
  233. . = list2params(.)
  234.  
  235. return .
  236.  
  237. if("rename_save")
  238. return saves.RenameCharacter(T["name_old"], T["name_new"])
  239.  
  240. if("delete_save")
  241. return saves.DeleteCharacter(T["char"])
  242.  
  243. if("get_save")
  244. . = saves.GetCharacter(T["char"], T["key"])
  245.  
  246. if(istype(., /list))
  247. var/encoded[0]
  248.  
  249. for(var/list/L in .)
  250. encoded += dd_list2text(L,";")
  251.  
  252. . = dd_list2text(encoded,"$")
  253.  
  254. return .
  255.  
  256. if("update_save")
  257. return saves.SaveCharacter(T["key"], T["inv"], T["bar"], T["strg"], T["nums"], T["lst"])
  258.  
  259. if("removeserver")
  260. world.log << "Removed server [addr]: Requested removal"
  261. Serverlist -= addr
  262. return ..()
  263.  
  264. proc
  265. /*
  266. Replace proc
  267. This replaces word in text with replace
  268. All three arguments are expected to be text
  269. */
  270. Replace(text,word,replace)
  271. var/pos = findtext(text,word)
  272. while(pos)
  273. text = copytext(text,1,pos) + replace + copytext(text,pos+length(word))
  274. pos = findtext(text,word)
  275. return text
  276.  
  277. /*
  278. Replace All proc
  279. replace_list: list in the format word = replace
  280. replaces each word with it's replace entry
  281. */
  282. Replace_All(text,replace_list)
  283. for(var/word in replace_list)
  284. var/pos = findtext(text,word)
  285. while(pos)
  286. text = copytext(text,1,pos) + replace_list[word] + copytext(text,pos+length(word))
  287. pos = findtext(text,word)
  288. return text
  289.  
  290. Escape_String(str)
  291. return Replace_All(str, list(";" = " ", "$" = " ", "&" = " "))
  292.  
  293. proc/Sanitize(X)
  294. var/Y="NULL"
  295. if(isnull(X))
  296. Y="NULL"
  297. else
  298. Y="[X]"
  299. return Y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement