init.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. network_whois = network_whois or {}
  2. network_whois.modpath = minetest.get_modpath("network_whois")
  3. function network_whois.display(name, target)
  4. local player = minetest.get_player_by_name(target)
  5. if not player then
  6. minetest.chat_send_player(name, "# Server: Player <" .. rename.gpn(target) .. "> not found.")
  7. return
  8. end
  9. local info = minetest.get_player_information(target)
  10. if not info then
  11. minetest.chat_send_player(name, "# Server: Information for player <" .. rename.gpn(target) .. "> not found!")
  12. return
  13. end
  14. minetest.chat_send_player(name, "# Server: Account <" .. rename.gpn(target) ..
  15. ">: ADR " .. info.address ..
  16. ", IPV " .. info.ip_version ..
  17. ", CU " .. info.connection_uptime ..
  18. ", AVG RTT " .. info.avg_rtt ..
  19. ", PV " .. info.protocol_version ..
  20. ", RN <" .. rename.grn(target) .. ">" ..
  21. ".")
  22. end
  23. function network_whois.whois(name, param)
  24. if param == nil or param == "" then
  25. local players = minetest.get_connected_players()
  26. for k, v in pairs(players) do
  27. local pname = v:get_player_name()
  28. network_whois.display(name, pname)
  29. end
  30. return true
  31. end
  32. network_whois.display(name, param)
  33. return true
  34. end
  35. if not network_whois.registered then
  36. minetest.register_privilege("whois", {
  37. description = "Enables an authorized user to obtain information about a player's connection to the server.",
  38. give_to_singleplayer = false,
  39. })
  40. minetest.register_chatcommand("whois", {
  41. params = "[<player>]",
  42. description = "Get information about a player's connection to the server.",
  43. privs = {whois=true},
  44. func = function(...)
  45. return network_whois.whois(...)
  46. end
  47. })
  48. local c = "whois:core"
  49. local f = network_whois.modpath .. "/init.lua"
  50. reload.register_file(c, f, false)
  51. network_whois.registered = true
  52. end