func KillServer(c *gin.Context) {
	item, _ := c.Get("server")
	server := item.(*programs.Program)
	err := server.Kill()
	if response.HandleError(c, err, http.StatusInternalServerError) {
	} else {
		c.Status(http.StatusNoContent)
	}
}
@Summary Kill server
@Description Stops the given server forcefully
@Accept json
@Produce json
@Success 204 {object} response.Empty "Server killed"
@Failure 400 {object} response.Error
@Failure 403 {object} response.Empty
@Failure 404 {object} response.Empty
@Failure 500 {object} response.Error
@Param id path string true "Server Identifier"
@Router /server/{id}/stop [post]
package server
import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/gorilla/websocket"
	"github.com/itsjamie/gin-cors"
	"github.com/pufferpanel/apufferi/v4"
	"github.com/pufferpanel/apufferi/v4/logging"
	"github.com/pufferpanel/apufferi/v4/response"
	"github.com/pufferpanel/apufferi/v4/scope"
	"github.com/pufferpanel/pufferd/v2"
	"github.com/pufferpanel/pufferd/v2/httphandlers"
	"github.com/pufferpanel/pufferd/v2/messages"
	"github.com/pufferpanel/pufferd/v2/programs"
	"github.com/satori/go.uuid"
	"github.com/spf13/cast"
	"io"
	"io/ioutil"
	"mime"
	"net/http"
	"os"
	"path/filepath"
)
var wsupgrader = websocket.Upgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
	CheckOrigin: func(r *http.Request) bool {
		return true
	},
}
func RegisterRoutes(e *gin.RouterGroup) {
	l := e.Group("/server")
	{
		l.PUT("/:id", httphandlers.OAuth2Handler(scope.ServersCreate, false), CreateServer)
		l.DELETE("/:id", httphandlers.OAuth2Handler(scope.ServersDelete, true), DeleteServer)
		l.GET("/:id", httphandlers.OAuth2Handler(scope.ServersEditAdmin, true), GetServerAdmin)
		l.POST("/:id", httphandlers.OAuth2Handler(scope.ServersEditAdmin, true), EditServerAdmin)
		l.OPTIONS("/:id", response.CreateOptions("PUT", "DELETE", "GET", "POST"))
		l.GET("/:id/data", httphandlers.OAuth2Handler(scope.ServersEdit, true), GetServer)
		l.POST("/:id/data", httphandlers.OAuth2Handler(scope.ServersEdit, true), EditServer)
		l.OPTIONS("/:id/data", response.CreateOptions("GET", "POST"))
		l.POST("/:id/reload", httphandlers.OAuth2Handler(scope.ServersEditAdmin, true), ReloadServer)
		l.OPTIONS("/:id/reload", response.CreateOptions("POST"))
		l.POST("/:id/start", httphandlers.OAuth2Handler(scope.ServersStart, true), StartServer)
		l.OPTIONS("/:id/start", response.CreateOptions("POST"))
		l.POST("/:id/stop", httphandlers.OAuth2Handler(scope.ServersStop, true), StopServer)
		l.OPTIONS("/:id/stop", response.CreateOptions("POST"))
		l.POST("/:id/kill", httphandlers.OAuth2Handler(scope.ServersStop, true), KillServer)
		l.OPTIONS("/:id/kill", response.CreateOptions("POST"))
		l.POST("/:id/install", httphandlers.OAuth2Handler(scope.ServersInstall, true), InstallServer)
		l.OPTIONS("/:id/install", response.CreateOptions("POST"))
		l.GET("/:id/file/*filename", httphandlers.OAuth2Handler(scope.ServersFilesGet, true), GetFile)
		l.PUT("/:id/file/*filename", httphandlers.OAuth2Handler(scope.ServersFilesPut, true), PutFile)
		l.DELETE("/:id/file/*filename", httphandlers.OAuth2Handler(scope.ServersFilesPut, true), DeleteFile)
		l.POST("/:id/file/*filename", httphandlers.OAuth2Handler(scope.ServersFilesPut, true), response.NotImplemented)
		l.OPTIONS("/:id/file/*filename", response.CreateOptions("GET", "PUT", "DELETE", "POST"))
		l.GET("/:id/console", httphandlers.OAuth2Handler(scope.ServersConsole, true), GetLogs)
		l.POST("/:id/console", httphandlers.OAuth2Handler(scope.ServersConsoleSend, true), PostConsole)
		l.OPTIONS("/:id/console", response.CreateOptions("GET", "POST"))
		l.GET("/:id/stats", httphandlers.OAuth2Handler(scope.ServersStat, true), GetStats)
		l.OPTIONS("/:id/stats", response.CreateOptions("GET"))
		l.GET("/:id/status", httphandlers.OAuth2Handler(scope.ServersStat, true), GetStatus)
		l.OPTIONS("/:id/status", response.CreateOptions("GET"))
	}
	p := e.Group("/socket")
	{
		p.GET("/:id", httphandlers.OAuth2Handler(scope.ServersConsole, true), cors.Middleware(cors.Config{
			Origins:     "*",
			Credentials: true,
		}), OpenSocket)
		p.Handle("CONNECT", "/:id", func(c *gin.Context) {
			c.Header("Access-Control-Allow-Origin", "*")
			c.Header("Access-Control-Allow-Credentials", "false")
		})
		p.OPTIONS("/:id", response.CreateOptions("GET"))
	}
	l.POST("", httphandlers.OAuth2Handler(scope.ServersCreate, false), CreateServer)
	l.OPTIONS("", response.CreateOptions("POST"))
}
func StartServer(c *gin.Context) {
	item, _ := c.Get("server")
	server := item.(*programs.Program)
	_, wait := c.GetQuery("wait")
	if wait {
		err := server.Start()
		if response.HandleError(c, err, http.StatusInternalServerError) {
		} else {
			c.Status(http.StatusNoContent)
		}
	} else {
		go func() {
			err := server.Start()
			if err != nil {
				logging.Exception(fmt.Sprintf("Error starting server %s", server.Id()), err)
			}
		}()
		c.Status(http.StatusAccepted)
	}
}
func StopServer(c *gin.Context) {
	item, _ := c.Get("server")
	server := item.(*programs.Program)
	_, wait := c.GetQuery("wait")
	err := server.Stop()
	if response.HandleError(c, err, http.StatusInternalServerError) {
		return
	}
	if wait {
		err = server.GetEnvironment().WaitForMainProcess()
		if response.HandleError(c, err, http.StatusInternalServerError) {
		} else {
			c.Status(http.StatusNoContent)
		}
	} else {
		c.Status(204)
	}
}