From e25a535694e118707b71c8fe0ced19522044bdc4 Mon Sep 17 00:00:00 2001 From: shellywell123 Date: Thu, 17 Apr 2025 11:54:57 +0000 Subject: [PATCH 1/2] init --- .../internal/game/allocated.go | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/simple-game-server-go/internal/game/allocated.go b/simple-game-server-go/internal/game/allocated.go index 055ce29..fd04284 100644 --- a/simple-game-server-go/internal/game/allocated.go +++ b/simple-game-server-go/internal/game/allocated.go @@ -96,6 +96,7 @@ func (g *Game) acceptClient(server *net.TCPListener) (*net.TCPConn, error) { g.clients.Store(client.RemoteAddr(), client) currentPlayers := g.Server.PlayerJoined() + g.logger.WithFields(logrus.Fields{ "client_ip": client.RemoteAddr().String(), "current_players": currentPlayers, @@ -128,6 +129,41 @@ func (g *Game) handleClient(client *net.TCPConn) { } } + +func (g *Game) FakeCCU() { + tick := time.NewTicker(15 * time.Second) + defer tick.Stop() + + increasing := true + minFakeCCU := int32(1) + maxFakeCCU := int32(10) + fakeCCU := minFakeCCU + + for { + select { + case <-tick.C: + + // 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) + + } + } +} + // 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 @@ -137,7 +173,10 @@ func (g *Game) handleClient(client *net.TCPConn) { // 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 From b2a0ad47ce45c3d1d0002d430bfcebf42c130f55 Mon Sep 17 00:00:00 2001 From: shellywell123 Date: Sat, 3 May 2025 11:52:01 +0100 Subject: [PATCH 2/2] block rand metric --- .../internal/game/allocated.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/simple-game-server-go/internal/game/allocated.go b/simple-game-server-go/internal/game/allocated.go index fd04284..f0b71f2 100644 --- a/simple-game-server-go/internal/game/allocated.go +++ b/simple-game-server-go/internal/game/allocated.go @@ -2,16 +2,16 @@ package game import ( "context" - "crypto/rand" + // "crypto/rand" "errors" "fmt" - "math/big" + // "math/big" "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" "github.com/sirupsen/logrus" ) @@ -37,12 +37,12 @@ func (g *Game) allocated(allocationID string) { 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) }