package minecraft

import (
	"github.com/gofiber/fiber/v2"
	"krakatoa.net/backend/modules/configs/serverConfig"
	"krakatoa.net/backend/modules/kraProtocol"
	"krakatoa.net/backend/modules/logger"
	"krakatoa.net/backend/serverCommunication"
)

func RestartServer(c *fiber.Ctx) error {
	if c.Params("accessKey") == serverConfig.Cfg.Servers.MinecraftServer.AccessKey {
		logger.Minecraft.Infoln("RestartServer msg", c.Params("serverName"), c.Hostname(), c.IP())

		serverCommunication.SendMessageToMinecraftServer(kraProtocol.StatusSend, kraProtocol.DestProxy, "", 33329, c.Params("serverName"))

		return c.SendStatus(fiber.StatusOK)
	}

	return c.SendStatus(fiber.StatusUnauthorized)
}
