mc_read.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "strconv"
  6. )
  7. func ReadLog(w http.ResponseWriter, r *http.Request) {
  8. log := MCServer.ReadAllLog()
  9. jsonData, _ := json.Marshal(log)
  10. sendJSONResponse(w, string(jsonData))
  11. }
  12. func ReadLogFrom(w http.ResponseWriter, r *http.Request) {
  13. start, _ := mv(r, "start", false)
  14. startInt, _ := strconv.Atoi(start)
  15. end := MCServer.LenLog()
  16. if startInt > MCServer.LenLog()-1 {
  17. sendJSONResponse(w, "[]")
  18. } else {
  19. log := MCServer.ReadRangeLog(startInt, end)
  20. jsonData, _ := json.Marshal(log)
  21. sendJSONResponse(w, string(jsonData))
  22. }
  23. }
  24. func ReadBanIP(w http.ResponseWriter, r *http.Request) {
  25. config := Config.ReadAllBannedIPs()
  26. jsonData, _ := json.Marshal(config)
  27. sendJSONResponse(w, string(jsonData))
  28. }
  29. func ReadBanPlayer(w http.ResponseWriter, r *http.Request) {
  30. config := Config.ReadAllBannedPlayers()
  31. jsonData, _ := json.Marshal(config)
  32. sendJSONResponse(w, string(jsonData))
  33. }
  34. func ReadEULA(w http.ResponseWriter, r *http.Request) {
  35. config := Config.ReadEULA()
  36. jsonData, _ := json.Marshal(config)
  37. sendJSONResponse(w, string(jsonData))
  38. }
  39. func ReadOps(w http.ResponseWriter, r *http.Request) {
  40. config := Config.ReadAllOps()
  41. jsonData, _ := json.Marshal(config)
  42. sendJSONResponse(w, string(jsonData))
  43. }
  44. func ReadProperties(w http.ResponseWriter, r *http.Request) {
  45. config := Config.ReadAllProperties()
  46. jsonData, _ := json.Marshal(config)
  47. sendJSONResponse(w, string(jsonData))
  48. }
  49. func ReadWhitelist(w http.ResponseWriter, r *http.Request) {
  50. config := Config.ReadAllWhitelists()
  51. jsonData, _ := json.Marshal(config)
  52. sendJSONResponse(w, string(jsonData))
  53. }