Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove get5 and rcon stuff #2

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w
# Runtime image
FROM redhat/ubi9-minimal:9.3

RUN rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
RUN rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
RUN microdnf -y update && microdnf -y install ca-certificates inotify-tools && microdnf reinstall -y tzdata

COPY --from=build-env /app/app /
Expand Down
2 changes: 0 additions & 2 deletions cmd/unwindia_pterodactyl/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ type environment struct {
PteroClientApiURL url.URL `env:"PTERODACTYL_CLIENT_API_URL,notEmpty"`
PteroClientApiToken string `env:"PTERODACTYL_CLIENT_API_TOKEN,notEmpty"`
PteroFetchInterval time.Duration `env:"PTERODACTYL_FETCH_INTERVAL" envDefault:"15s"`

RconRetries int `env:"RCON_RETRIES" envDefault:"10" envDescription:"How often to retry"`
}

// Environment holds all environment configuration with more advanced typing and validation
Expand Down
9 changes: 0 additions & 9 deletions cmd/unwindia_pterodactyl/errors/httpErrors.go

This file was deleted.

33 changes: 1 addition & 32 deletions cmd/unwindia_pterodactyl/jobs/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
"github.com/GSH-LAN/Unwindia_common/src/go/workitemLock"
"github.com/GSH-LAN/Unwindia_pterodactyl/cmd/unwindia_pterodactyl/database"
"github.com/GSH-LAN/Unwindia_pterodactyl/cmd/unwindia_pterodactyl/pterodactyl"
"github.com/GSH-LAN/Unwindia_pterodactyl/cmd/unwindia_pterodactyl/template"
"github.com/ThreeDotsLabs/watermill/message"
rcon "github.com/forewing/csgo-rcon"
"github.com/gammazero/workerpool"
jsoniter "github.com/json-iterator/go"
"github.com/modern-go/reflect2"
Expand All @@ -33,11 +31,10 @@ type Worker struct {
semaphore *semaphore.Weighted
jobLock workitemLock.WorkItemLock
config config.ConfigClient
rconRetries int
baseTopic string
}

func NewWorker(ctx context.Context, db database.DatabaseClient, pool *workerpool.WorkerPool, pteroClient pterodactyl.Client, matchPublisher message.Publisher, config config.ConfigClient, rconRetries int, baseTopic string) *Worker {
func NewWorker(ctx context.Context, db database.DatabaseClient, pool *workerpool.WorkerPool, pteroClient pterodactyl.Client, matchPublisher message.Publisher, config config.ConfigClient, baseTopic string) *Worker {
w := Worker{
ctx: ctx,
db: db,
Expand All @@ -47,7 +44,6 @@ func NewWorker(ctx context.Context, db database.DatabaseClient, pool *workerpool
semaphore: semaphore.NewWeighted(int64(1)),
jobLock: workitemLock.NewMemoryWorkItemLock(),
config: config,
rconRetries: rconRetries,
baseTopic: baseTopic,
}
return &w
Expand Down Expand Up @@ -177,33 +173,6 @@ func (w *Worker) processJob(ctx context.Context, job *database.Job) error {
return err
}

rconClient := rcon.New(job.MatchInfo.ServerAddress, servermgmtpass, time.Second*10)
go func() {
time.Sleep(gsTemplate.ServerReadyRconWaitTime.Duration)

for _, command := range gsTemplate.ServerReadyRconCommands {
for i := 0; i < w.rconRetries; i++ {
parsedCommand, err := template.ParseTemplateForMatch(command, &job.MatchInfo)
if err != nil {
log.Error().Err(err).Str("jobid", job.ID.String()).Str("command", command).Msg("Error parsing rcon command template")
continue
}

_, err = rconClient.Execute(parsedCommand)
if err != nil {
log.Error().Err(err).Str("jobid", job.ID.String()).Str("command", parsedCommand).Str("address", job.MatchInfo.ServerAddress).Msg("Error executing rcon command")
continue
}

log.Debug().Str("command", parsedCommand).Msg("Successfully executed command")
time.Sleep(time.Second)
break
}
}
}()

// We now need to publish to message queue

msg := messagebroker.Message{
Type: messagebroker.MessageTypeUpdated,
SubType: messagebroker.UNWINDIA_MATCH_SERVER_READY.String(),
Expand Down

This file was deleted.

15 changes: 0 additions & 15 deletions cmd/unwindia_pterodactyl/server/errors.go

This file was deleted.

49 changes: 1 addition & 48 deletions cmd/unwindia_pterodactyl/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/GSH-LAN/Unwindia_pterodactyl/cmd/unwindia_pterodactyl/messagequeue"
"github.com/GSH-LAN/Unwindia_pterodactyl/cmd/unwindia_pterodactyl/pterodactyl"
"github.com/GSH-LAN/Unwindia_pterodactyl/cmd/unwindia_pterodactyl/router"
"github.com/GSH-LAN/Unwindia_pterodactyl/cmd/unwindia_pterodactyl/template"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/gammazero/workerpool"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -63,7 +62,7 @@ func NewServer(ctx context.Context, env *environment.Environment, cfgClient conf
return nil, err
}

jobHandler := jobs.NewWorker(ctx, dbClient, wp, pteroClient, matchPublisher, cfgClient, env.RconRetries, env.PulsarBaseTopic)
jobHandler := jobs.NewWorker(ctx, dbClient, wp, pteroClient, matchPublisher, cfgClient, env.PulsarBaseTopic)

srv := Server{
ctx: ctx,
Expand Down Expand Up @@ -223,11 +222,7 @@ func (s *Server) setupRouter() {
// GinErrorHandler middleware for handle problem details error on gin
s.router.Use(func(c *gin.Context) {
c.Next()

for _, err := range c.Errors {

// add custom map problem details here...

if _, err := problem.ResolveProblemDetails(c.Writer, c.Request, err); err != nil {
log.Error().Err(err).Msg("gin error")
}
Expand All @@ -240,14 +235,9 @@ func (s *Server) setupRouter() {
//internal.GET("/health", gin.WrapF(handlers.NewJSONHandlerFunc(health.Health, nil)))
internal.GET("/metrics", gin.WrapH(promhttp.Handler()))

//serverApi := s.router.Group("/api/v1/server")
//serverApi.POST("/")

v1Api := s.router.Group("/api/v1")
v1Api.POST("/jobs", s.handleCreateJob)
v1Api.POST("/preinstall/:game/:amount", s.handlePreinstall)

v1Api.GET("/match/:matchid/:template", s.handleMatchTemplate)
}

func (s *Server) handleCreateJob(ctx *gin.Context) {
Expand Down Expand Up @@ -321,40 +311,3 @@ func (s *Server) handlePreinstall(ctx *gin.Context) {
ctx.JSON(http.StatusCreated, gin.H{"servers": createdJobs})
}
}

func (s *Server) handleMatchTemplate(ctx *gin.Context) {
matchid := ctx.Param("matchid")
templateName := ctx.Param("template")

matchInfo, err := s.dbClient.GetMatchInfoForMatchId(s.ctx, matchid)
if err != nil {
log.Error().Err(err).Msg("error getting info for match")
ctx.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
return
}

templateText, ok := s.config.GetConfig().Templates[fmt.Sprintf("PTERODACTYL_%s.gohtml", templateName)]
if !ok {
log.Error().Str("template", templateName).Msg("template not found")
ctx.JSON(http.StatusBadRequest, gin.H{
"error": fmt.Errorf("template %s not found", templateName),
})
return
}

parsedMatchTemplate, err := template.ParseTemplateForMatch(templateText, &matchInfo.MatchInfo)
if err != nil {
log.Error().Err(err).Msg("Error parsing template")
ctx.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
return
}
log.Debug().Str("commentText", parsedMatchTemplate).Msg("parsed Template")

log.Info().Str("matchid", matchid).Str("template", templateName).Msg("creating template for match")

ctx.String(http.StatusOK, parsedMatchTemplate)
}
36 changes: 0 additions & 36 deletions cmd/unwindia_pterodactyl/template/template.go

This file was deleted.

Loading