Skip to content
Closed
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
59 changes: 49 additions & 10 deletions simple-game-server-go/internal/game/allocated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import (
"context"
"crypto/rand"
// "crypto/rand"

Check failure on line 5 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

Comment should end in a period (godot)

Check failure on line 5 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

Comment should end in a period (godot)
"errors"
"fmt"

Check failure on line 7 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

File is not `goimports`-ed (goimports)

Check failure on line 7 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

File is not `goimports`-ed (goimports)
"math/big"
// "math/big"

Check failure on line 8 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

Comment should end in a period (godot)

Check failure on line 8 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

Comment should end in a period (godot)
"net"
"strconv"
"syscall"
"time"

"github.com/Unity-Technologies/unity-gaming-services-go-sdk/game-server-hosting/server"
// "github.com/Unity-Technologies/unity-gaming-services-go-sdk/game-server-hosting/server"

Check failure on line 14 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

Comment should end in a period (godot)

Check failure on line 14 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

Comment should end in a period (godot)
"github.com/sirupsen/logrus"
)

Expand All @@ -37,12 +37,12 @@
g.Server.SetGameType(c.Extra["gameType"])
g.Server.SetGameMap(c.Extra["map"])

// Set a random metric, if using SQP.
if c.QueryType == server.QueryProtocolSQP {
if i, err := rand.Int(rand.Reader, big.NewInt(100)); err == nil {
_ = g.SetMetric(0, float32(i.Int64()))
}
}
// // Set a random metric, if using SQP.
// if c.QueryType == server.QueryProtocolSQP {
// if i, err := rand.Int(rand.Reader, big.NewInt(100)); err == nil {
// _ = g.SetMetric(0, float32(i.Int64()))
// }
// }

go g.launchGame(port)
}
Expand Down Expand Up @@ -96,6 +96,7 @@

g.clients.Store(client.RemoteAddr(), client)
currentPlayers := g.Server.PlayerJoined()

Check failure on line 99 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

File is not `gci`-ed with --skip-generated -s standard,default (gci)

Check failure on line 99 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

File is not `gci`-ed with --skip-generated -s standard,default (gci)
g.logger.WithFields(logrus.Fields{
"client_ip": client.RemoteAddr().String(),
"current_players": currentPlayers,
Expand Down Expand Up @@ -128,6 +129,41 @@
}
}


Check failure on line 132 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

File is not `gci`-ed with --skip-generated -s standard,default (gci)

Check failure on line 132 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

File is not `gci`-ed with --skip-generated -s standard,default (gci)
func (g *Game) FakeCCU() {
tick := time.NewTicker(15 * time.Second)
defer tick.Stop()

increasing := true
minFakeCCU := int32(1)
maxFakeCCU := int32(10)
fakeCCU := minFakeCCU

for {

Check failure on line 142 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

S1000: should use for range instead of for { select {} } (gosimple)

Check failure on line 142 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

S1000: should use for range instead of for { select {} } (gosimple)
select {
case <-tick.C:

Check failure on line 145 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

File is not `gci`-ed with --skip-generated -s standard,default (gci)

Check failure on line 145 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

File is not `gci`-ed with --skip-generated -s standard,default (gci)
// make a fake sine graph

if fakeCCU >= maxFakeCCU {
increasing = false
} else if fakeCCU <= minFakeCCU {
increasing = true
}

if increasing {
fakeCCU++
} else {
fakeCCU--
}

g.logger.Info(fmt.Sprintf("Bens Fake CCU: %d", fakeCCU))
g.Server.SetCurrentPlayers(fakeCCU)

Check failure on line 162 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

File is not `gofumpt`-ed (gofumpt)

Check failure on line 162 in simple-game-server-go/internal/game/allocated.go

View workflow job for this annotation

GitHub Actions / goreleaser

File is not `gofumpt`-ed (gofumpt)
}
}
}

// readyForPlayers waits 20s then reports that the game is ready for players.
//
// This is to simulate a game server waiting for any initialization to complete
Expand All @@ -137,7 +173,10 @@
// configuration variable in the build configuration to a duration string
// recognised by `time.ParseDuration`, e.g. "30s".
func (g *Game) readyForPlayers() {
g.logger.Info("ready for players")
g.logger.Info("ben ready for playerzzz")

// g.Server.SetCurrentPlayers(0)
go g.FakeCCU() // call function as go routine

timeout := defaultReadyTimeout

Expand Down
Loading