Advertisement
kaeza

Read TOS plz!!!1!!

Dec 30th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. local FORMNAME = "tos:tos_fs"
  2.  
  3. local TOS = [[
  4. Lorem ipsum dolor sit amet, consectetur adipiscing
  5. elit. Fusce sit amet nunc egestas, euismod neque at,
  6. placerat quam. Proin nec massa malesuada,  egestas
  7. elit tincidunt, cursus nunc. Morbi libero justo,
  8. sodales sed lacus nec, convallis rhoncus est. Cras
  9. pharetra elit sit amet enim vulputate semper. Sed
  10. in laoreet est. Curabitur euismod lacus mauris, id
  11. vulputate ante mattis ac. In semper accumsan mollis.
  12.  
  13. Duis in tincidunt ligula. Vivamus pellentesque lacus
  14. eros, id eleifend elit rutrum eget. Cras facilisis
  15. nulla nisl, nec mollis ligula scelerisque nec. Etiam
  16. ultrices egestas erat, non iaculis risus ornare in.
  17. Vivamus sed nisl vitae dolor condimentum sodales.
  18. Vestibulum eget pretium metus, ut fermentum ipsum.
  19. Phasellus arcu tortor, egestas malesuada sagittis a,
  20. vestibulum ut tellus. Nulla tincidunt mauris vitae
  21. dolor consectetur malesuada. Mauris placerat est
  22. turpis, vel fringilla tellus venenatis nec. Cras
  23. interdum porttitor ipsum, id sodales sapien pharetra
  24. eu. Pellentesque mattis quis sapien ut sagittis.
  25.  
  26. Vestibulum ante ipsum primis in faucibus orci luctus
  27. et ultrices posuere cubilia Curae. Nunc nec massa
  28. tincidunt mauris commodo imperdiet vel ac purus.
  29. Aliquam in ultrices nibh. Nam aliquam laoreet arcu,
  30. eget pharetra lorem viverra vitae. In et fringilla
  31. nulla. Fusce ac aliquet nulla. Nulla ultricies vitae
  32. tortor sit amet mattis. Integer nibh magna, laoreet
  33. in mattis sit amet, vulputate sed neque. Proin
  34. accumsan interdum risus, eget tristique lacus
  35. scelerisque cursus.
  36. ]]
  37.  
  38. local TOS_list = { } -- list[paragraph][word]
  39. local par_wordlist
  40. par_wordlist = { }
  41. for line in TOS:gmatch("(.-)\n") do
  42.     if line == "" then
  43.         table.insert(TOS_list, par_wordlist)
  44.         par_wordlist = { }
  45.     end
  46.     for word in line:gmatch("[%w][%w'_-]*") do
  47.         table.insert(par_wordlist, word)
  48.     end
  49. end
  50.  
  51. local ord_suffix = { "st", "nd", "rd", [11] = "th", [12] = "th", [13] = "th" }
  52. local function ordinal(n)
  53.     return n..(ord_suffix[n % 100] or ord_suffix[n % 10] or "th")
  54. end
  55.  
  56. local function rnditem(list)
  57.     local i = math.floor(math.random(1, #list))
  58.     return list[i], i
  59. end
  60.  
  61. local function make_formspec()
  62.     local par, pindex = rnditem(TOS_list)
  63.     local word, windex = rnditem(par)
  64.     local fs = { "size[8,6]" }
  65.     table.insert(fs, "textarea[0.5,0.5;7,5;TOS;Terms of Service;"..TOS.."]")
  66.     table.insert(fs, "field[0.5,5;5,1;entry;Please enter the "
  67.         ..ordinal(windex).." word of the "..ordinal(pindex).." paragraph.;]")
  68.     table.insert(fs, "button[6,5;1.5,0.5;ok;Accept]")
  69.     table.insert(fs, "field[10,10;0.1,0.1;hidden_word;;"..word.."]")
  70.     return table.concat(fs)
  71. end
  72.  
  73. minetest.register_on_player_receive_fields(function(player, formname, fields)
  74.     if formname ~= FORMNAME then return end
  75.     local name = player:get_player_name()
  76.     -- Prevent older clients from escaping the TOS.
  77.     -- MWAHAHAHAHA!
  78.     if not fields.ok then
  79.         minetest.show_formspec(name, FORMNAME, make_formspec())
  80.     end
  81.     if fields.quit then
  82.         local privs = minetest.get_player_privs(name)
  83.         if not privs.tos_accepted then
  84.             minetest.chat_send_player(name, "Please read the message.")
  85.             minetest.show_formspec(name, FORMNAME, make_formspec())
  86.             return
  87.         end
  88.     elseif fields.ok then
  89.         if fields.hidden_word == fields.entry then
  90.             minetest.chat_send_player(name, "You're on!")
  91.             local privs = minetest.get_player_privs(name)
  92.             privs.tos_accepted = true
  93.             minetest.set_player_privs(name, privs)
  94.         else
  95.             minetest.chat_send_player(name, "Wrong word.")
  96.             minetest.show_formspec(name, FORMNAME, make_formspec())
  97.             return
  98.         end
  99.     end
  100. end)
  101.  
  102. minetest.register_on_joinplayer(function(player)
  103.     local name = player:get_player_name()
  104.     local privs = minetest.get_player_privs(name)
  105.     if not privs.tos_accepted then
  106.         minetest.after(1, function()
  107.             minetest.show_formspec(name, FORMNAME, make_formspec())
  108.         end)
  109.     end
  110. end)
  111.  
  112. minetest.register_privilege("tos_accepted", "TOS Accepted")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement