joinspec.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. joinspec = joinspec or {}
  2. joinspec.modpath = minetest.get_modpath("welcome_msg")
  3. joinspec.data = {
  4. warning = "Welcome to the frontier, Stranger! You have arrived on Enyekala (Must Test), a complex, detailed survival-mode game built on top of the Minetest Engine (https://www.minetest.net/).\n\n" ..
  5. "Please read this text, as it contains important information about this server. You will need to scroll this text to read all of it. Once you have closed this formspec, you can reshow it by typing “/info” in the chat, without quotes.\n\n" ..
  6. "This is a heavily modded, hard-core PvP & PvE survival server. " ..
  7. "The only way to find greatness is to survive, mine, build, and fight your way up! " ..
  8. "There is no creative mode.\n\n" ..
  9. "As a new adventurer, you start in a dry and dreary place the old-timers call “The Outback”. This is the dimension of the Unreal, because nothing here lasts, and in time, all is forgotten …. Leaving this realm, and finding your way to the true world, is akin to a test of skill. If you can escape this place then it may be that you have a chance to overcome the much harder challenge of survival in the natural realm. Many will not make the attempt. For them, the place of the Unreal is reality enough, and there is no need to seek anything else. You, O Adventuring Stranger, must make your choice.\n\n" ..
  10. "Upon appearing in the Outback, your first order of business is to obtain a stone pick. Most stone here is unsuitable, but if you go rock prospecting you’ll find the right kind. You can pluck the dry shrubs to find sticks. Once you have a stone pick, you should locate some iron and build an iron pick. Craft yourself some armor while you’re at it, and the best sword you can lay hands on. Eventually, you will need to discover how to locate flint so that you can construct a flint and steel. This is what you’ll need in order to activate the dimensional gateway, which is your way out. The portal chamber is well-guarded, so you will need to fight your way through. In order to activate the portal, you must stand physically inside of it, and strike the obsidian with your flint and steel. The dimensional transfer takes a little time, and more guards may appear in the meanwhile, so you must be quick. Finally, if you get stuck in the Outback without suitable tools, you can use /spawn to return yourself to the spawnpoint.\n\n" ..
  11. "The above is a coarse outline of your path through the Outback. The patient adventurer may wish to make some detours. Survival in the overworld is much harder than making a living in the Outback. The better your supplies that you bring with you through the dimensional gate, the better your chances in the overworld will be. Consider stockpiling food, weaponry, rare items, farming materials, and most importantly, a BED. Keep in mind that the dimensional gateway is UNSTABLE. The portal’s exit coordinates change once every " .. randspawn.min_days .. " to " .. randspawn.max_days .. " realtime days, and you cannot rely on there being much (or even any) infrastructure to support you once you arrive at the other side! Until you meet others, this is hard-core PvE survival.\n\n" ..
  12. "Here is a warning: wait until sunrise to use the Outback’s dimensional gate. Do not use it at night!\n\n" ..
  13. "You may read the server’s webpage at http://arklegacy.duckdns.org/. " ..
  14. "On this site you will find the server rules, as well as an additional introduction to the world, a FAQ, " ..
  15. "some gameplay tips, and of course some maps of various locations. The website does not cover everything about Must Test—indeed it cannot—and part of the experience is about exploring, experimenting, and discovering undocumented stuff. Feel free to ask questions of the old-timers—but be careful! If you annoy them too much, you’d better beware lest they feed you to a Dungeon Master …. >:)\n\n" ..
  16. "Due to the way the mapgen generates ores (among other things), trade with other players comes highly recommended; " ..
  17. "sell what you don’t need and buy what you do. It is rare for one person to have convenient access to all available resources on this server, though with enough effort it can be done.\n\n" ..
  18. "Minegeld is currency here. " ..
  19. "You can trade gold, silver and copper ingots for minegeld at the Wild North Precious Metal Exchange, " ..
  20. "which is located in the northeast quarter of the city at 1238, -8748. Some long-time inhabitants have commissioned banks out of their own resources, which you can use as well.\n\n" ..
  21. "In order to register and preserve your account and player data, " ..
  22. "you must obtain a Proof of Citizenship. The recipe is in the craft guide. Once you have crafted your Proof of Citizenship (PoC) you must keep it in your MAIN inventory at all times. Without it, the server will erase your account. This happens every Sunday when the system is purged of excess player data. Note that later you can upgrade your PoC to a Key, which provides a number of useful features for experienced adventurers, as well as a way to communicate with offline players (via in-game mail).\n\n" ..
  23. "This server makes use of the latest Minetest APIs, therefore a recent client is recommended.",
  24. version = minetest.get_version(),
  25. }
  26. local COLOR_ORANGE = core.get_color_escape_sequence("#ff3621")
  27. function joinspec.on_joinplayer(player)
  28. -- Do not show joinspec to players who are dead on join.
  29. -- It causes the 'respawn' formspec (shown automatically by the client)
  30. -- to disappear, and the player can never respawn.
  31. local pname = player:get_player_name()
  32. local pos = player:get_pos()
  33. if player:get_hp() > 0 then
  34. local result = passport.player_registered(pname)
  35. local haskey = passport.player_has_key(pname)
  36. joinspec.show_formspec(pname, result, haskey)
  37. else
  38. minetest.log("error", "Player " .. pname .. " joined while dead! Not showing welcome formspec.")
  39. -- Force respawn player in Outback (bypass bed code for simplicity's sake)
  40. -- if player joins while dead. This nixes a 'disconnect on death' hack.
  41. -- An uncracked client will still display the respawn formspec, and the
  42. -- player will respawn again in their bed after pressing the button.
  43. randspawn.reposition_player(pname, pos)
  44. end
  45. if rc.current_realm_at_pos(pos) == "abyss" then
  46. -- If player logs in (or spawns) in the Outback, then show them the reset
  47. -- timeout after 30 seconds.
  48. minetest.after(30, function()
  49. local days1 = math.floor(serveressentials.get_outback_timeout() / (60*60*24))
  50. local days2 = math.floor(randspawn.get_spawn_reset_timeout() / (60*60*24))
  51. local s1 = "s"
  52. local s2 = "s"
  53. if days1 == 1 then s1 = "" end
  54. if days2 == 1 then s2 = "" end
  55. minetest.chat_send_player(pname,
  56. core.get_color_escape_sequence("#ffff00") ..
  57. "# Server: In " .. days1 .. " day" .. s1 ..", the dry winds of the Outback will cease. Then all begins again.")
  58. minetest.chat_send_player(pname,
  59. core.get_color_escape_sequence("#ffff00") ..
  60. "# Server: The unstable Dimensional Gate will shift its exit location in " .. days2 .. " day" .. s2 .. ".")
  61. end)
  62. end
  63. end
  64. function joinspec.generate_formspec(pname, returningplayer, haskey)
  65. local formspec = ""
  66. if returningplayer then
  67. -- Returning player.
  68. formspec = formspec ..
  69. "size[7,4.9]" ..
  70. default.gui_bg ..
  71. default.gui_bg_img ..
  72. default.gui_slots
  73. formspec = formspec ..
  74. "box[0,0;6.8,2;#101010FF]" ..
  75. "image[0.4,0.1;7.3,2.1;musttest_game_logo.png]"
  76. formspec = formspec ..
  77. "label[0,2.1;Server: ‘Must Test’ @ minetest:arklegacy.duckdns.org:30000]"
  78. formspec = formspec ..
  79. "label[0,2.6;Greetings <" .. pname .. ">. Welcome back to the frontier!]"
  80. local logintime = "Your last login time is unknown!"
  81. local pauth = core.get_auth_handler().get_auth(pname)
  82. if pauth and pauth.last_login then
  83. local days = math.floor((os.time() - pauth.last_login) / (60 * 60 * 24))
  84. logintime = "Your last login was on " .. os.date("!%Y/%m/%d, %H:%M UTC", pauth.last_login) .. " "
  85. if days <= 0 then
  86. logintime = logintime .. "(Today)"
  87. elseif days == 1 then
  88. logintime = logintime .. "(Yesterday)"
  89. else
  90. logintime = logintime .. "(" .. days .. " Days Ago)"
  91. end
  92. end
  93. logintime = minetest.formspec_escape(logintime)
  94. formspec = formspec ..
  95. "label[0,3.1;" .. logintime .. "]"
  96. -- Exit buttons.
  97. formspec = formspec ..
  98. "button[0,3.8;2,1;wrongserver;Not Now]" ..
  99. "button[2,3.8;2,1;trading;Trading]" ..
  100. "button[5,3.8;2,1;playgame;Proceed!]"
  101. if haskey then
  102. formspec = formspec ..
  103. "button[4,3.8;1,1;passport;Key]"
  104. end
  105. formspec = formspec ..
  106. "label[2.6,4.7;" .. minetest.formspec_escape(COLOR_ORANGE .. "Priority: Survive!") .. "]"
  107. else
  108. -- New player.
  109. formspec = formspec ..
  110. "size[7,8.3]" ..
  111. default.gui_bg ..
  112. default.gui_bg_img ..
  113. default.gui_slots
  114. formspec = formspec ..
  115. "box[0,0;6.8,2;#101010FF]" ..
  116. "image[0.4,0.1;7.3,2.1;musttest_game_logo.png]"
  117. local warning = minetest.formspec_escape(joinspec.data.warning)
  118. formspec = formspec ..
  119. "textarea[0.3,2.3;7,5.6;warning;;" .. warning .. "]"
  120. -- Exit buttons.
  121. formspec = formspec ..
  122. "button[0,7.3;2,1;wrongserver;" .. minetest.formspec_escape("I’m Scared ...") .. "]" ..
  123. "button[2,7.3;2,1;trading;Tradernet]" ..
  124. "button[4,7.3;3,1;playgame;Accept Challenge!]"
  125. formspec = formspec ..
  126. "label[2.6,8.1;" .. minetest.formspec_escape(COLOR_ORANGE .. "Priority: Survive!") .. "]"
  127. end
  128. return formspec
  129. end
  130. function joinspec.show_formspec(pname, returningplayer, haskey)
  131. local formspec = joinspec.generate_formspec(pname, returningplayer, haskey)
  132. minetest.show_formspec(pname, "joinspec:main", formspec)
  133. end
  134. function joinspec.on_receive_fields(player, formname, fields)
  135. if formname ~= "joinspec:main" then
  136. return
  137. end
  138. local pname = player:get_player_name()
  139. if fields.playgame then
  140. minetest.close_formspec(pname, "joinspec:main")
  141. end
  142. if fields.wrongserver then
  143. minetest.kick_player(pname, "You pressed the 'Leave Server' button. ;-)")
  144. minetest.chat_send_all("# Server: <" .. rename.gpn(pname) .. "> was kicked off the server.")
  145. end
  146. if fields.passport then
  147. passport.open_keys[pname] = true
  148. ambiance.sound_play("fancy_chime1", player:get_pos(), 1.0, 20, "", false)
  149. passport.show_formspec(pname)
  150. end
  151. if fields.trading then
  152. local pos = vector.round(player:get_pos())
  153. ads.show_formspec(pos, pname, false)
  154. end
  155. return true
  156. end
  157. function joinspec.show_info(pname, param)
  158. joinspec.show_formspec(pname, false)
  159. end
  160. if not joinspec.run_once then
  161. minetest.register_on_joinplayer(function(...)
  162. return joinspec.on_joinplayer(...)
  163. end)
  164. minetest.register_on_player_receive_fields(function(...)
  165. return joinspec.on_receive_fields(...)
  166. end)
  167. minetest.register_chatcommand("info", {
  168. params = "",
  169. description = "(Re)show the server's welcome formspec, with basic server information.",
  170. privs = {},
  171. func = function(...)
  172. joinspec.show_info(...)
  173. return true
  174. end,
  175. })
  176. local c = "joinspec:core"
  177. local f = joinspec.modpath .. "/joinspec.lua"
  178. reload.register_file(c, f, false)
  179. joinspec.run_once = true
  180. end