small fixes
This commit is contained in:
@@ -8,10 +8,22 @@ import (
|
||||
|
||||
"gitea.mrixs.me/minecraft-platform/backend/internal/database"
|
||||
"gitea.mrixs.me/minecraft-platform/backend/internal/models"
|
||||
"github.com/Tnze/go-mc/bot/basic"
|
||||
"github.com/Tnze/go-mc/net"
|
||||
"github.com/Tnze/go-mc/bot"
|
||||
"github.com/Tnze/go-mc/chat"
|
||||
)
|
||||
|
||||
type pingResponse struct {
|
||||
Description chat.Message `json:"description"`
|
||||
Players struct {
|
||||
Max int `json:"max"`
|
||||
Online int `json:"online"`
|
||||
} `json:"players"`
|
||||
Version struct {
|
||||
Name string `json:"name"`
|
||||
Protocol int `json:"protocol"`
|
||||
} `json:"version"`
|
||||
}
|
||||
|
||||
type ServerPoller struct {
|
||||
Repo *database.ServerRepository
|
||||
}
|
||||
@@ -47,29 +59,19 @@ func (p *ServerPoller) pollAllServers(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (p *ServerPoller) pollServer(ctx context.Context, server *models.GameServer) {
|
||||
resp, delay, err := net.PingAndListTimeout(server.Address, 5*time.Second)
|
||||
resp, delay, err := bot.PingAndList(server.Address)
|
||||
if err != nil {
|
||||
log.Printf("Poller: failed to ping %s (%s): %v", server.Name, server.Address, err)
|
||||
return
|
||||
}
|
||||
|
||||
var status basic.ServerList
|
||||
var status pingResponse
|
||||
if err := json.Unmarshal(resp, &status); err != nil {
|
||||
log.Printf("Poller: failed to unmarshal status for %s: %v", server.Name, err)
|
||||
return
|
||||
}
|
||||
|
||||
// MOTD может быть сложным объектом, извлекаем текст
|
||||
var motdText string
|
||||
if s, ok := status.Description.(string); ok {
|
||||
motdText = s
|
||||
} else {
|
||||
if m, ok := status.Description.(map[string]interface{}); ok {
|
||||
if t, ok := m["text"].(string); ok {
|
||||
motdText = t
|
||||
}
|
||||
}
|
||||
}
|
||||
motdText := status.Description.String()
|
||||
|
||||
updateData := &models.ServerStatus{
|
||||
StatusJSON: string(resp),
|
||||
|
||||
Reference in New Issue
Block a user