mc_read.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package main
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "strconv"
  6. "aytechnology.us/gominecraft/mod/mc"
  7. )
  8. func ReadLog(w http.ResponseWriter, r *http.Request) {
  9. log := MCServer.ReadAllLog()
  10. jsonData, _ := json.Marshal(log)
  11. sendJSONResponse(w, string(jsonData))
  12. }
  13. func ReadLogFrom(w http.ResponseWriter, r *http.Request) {
  14. start, _ := mv(r, "start", false)
  15. startInt, _ := strconv.Atoi(start)
  16. end := MCServer.LenLog()
  17. //show only first 3000 record if start ~ end is >= 3000
  18. if end-startInt > 3000 {
  19. startInt = end - 3000
  20. }
  21. if startInt > MCServer.LenLog()-1 {
  22. sendJSONResponse(w, "[]")
  23. } else {
  24. log := MCServer.ReadRangeLog(startInt, end)
  25. jsonData, _ := json.Marshal(log)
  26. sendJSONResponse(w, string(jsonData))
  27. }
  28. }
  29. func ReadBanIP(w http.ResponseWriter, r *http.Request) {
  30. config := Config.ReadAllBannedIPs()
  31. jsonData, _ := json.Marshal(config)
  32. sendJSONResponse(w, string(jsonData))
  33. }
  34. func ReadBanPlayer(w http.ResponseWriter, r *http.Request) {
  35. config := Config.ReadAllBannedPlayers()
  36. for _, item := range config {
  37. skin := mc.NewHandler(item.UUID, serverConfig.Folder+"/skin/")
  38. skin.DownloadSkin()
  39. }
  40. jsonData, _ := json.Marshal(config)
  41. sendJSONResponse(w, string(jsonData))
  42. }
  43. func ReadEULA(w http.ResponseWriter, r *http.Request) {
  44. config := Config.ReadEULA()
  45. jsonData, _ := json.Marshal(config)
  46. sendJSONResponse(w, string(jsonData))
  47. }
  48. func ReadOps(w http.ResponseWriter, r *http.Request) {
  49. config := Config.ReadAllOps()
  50. for _, item := range config {
  51. skin := mc.NewHandler(item.UUID, serverConfig.Folder+"/skin/")
  52. skin.DownloadSkin()
  53. }
  54. jsonData, _ := json.Marshal(config)
  55. sendJSONResponse(w, string(jsonData))
  56. }
  57. func ReadProperties(w http.ResponseWriter, r *http.Request) {
  58. config := Config.ReadAllProperties()
  59. jsonData, _ := json.Marshal(config)
  60. sendJSONResponse(w, string(jsonData))
  61. }
  62. func ReadWhitelist(w http.ResponseWriter, r *http.Request) {
  63. config := Config.ReadAllWhitelists()
  64. for _, item := range config {
  65. skin := mc.NewHandler(item.UUID, serverConfig.Folder+"/skin/")
  66. skin.DownloadSkin()
  67. }
  68. jsonData, _ := json.Marshal(config)
  69. sendJSONResponse(w, string(jsonData))
  70. }