diff --git a/simple-game-server-go/go.mod b/simple-game-server-go/go.mod index c5e8fa0..0ef582e 100644 --- a/simple-game-server-go/go.mod +++ b/simple-game-server-go/go.mod @@ -3,7 +3,7 @@ module github.com/Unity-Technologies/multiplay-examples/simple-game-server-go go 1.20 require ( - github.com/Unity-Technologies/unity-gaming-services-go-sdk v0.3.1 + github.com/Unity-Technologies/unity-gaming-services-go-sdk v0.4.1 github.com/sirupsen/logrus v1.9.0 github.com/stretchr/testify v1.8.2 ) diff --git a/simple-game-server-go/go.sum b/simple-game-server-go/go.sum index 5a33355..3657449 100644 --- a/simple-game-server-go/go.sum +++ b/simple-game-server-go/go.sum @@ -2,6 +2,8 @@ github.com/FZambia/eagle v0.0.2 h1:35qHDuXSQevZ4w9A51k4wU7OE/tPHTEWXoywA93hvkY= github.com/FZambia/sentinel v1.1.0 h1:qrCBfxc8SvJihYNjBWgwUI93ZCvFe/PJIPTHKmlp8a8= github.com/Unity-Technologies/unity-gaming-services-go-sdk v0.3.1 h1:piV2hAtoc5ke3ywkIvUs82J+CphjWXoN3219isDmY00= github.com/Unity-Technologies/unity-gaming-services-go-sdk v0.3.1/go.mod h1:WgDwSafd4alCs+HdK0z+7htBVZIe+LUrLQgM738WDd0= +github.com/Unity-Technologies/unity-gaming-services-go-sdk v0.4.1 h1:oM4+Pi8ZA9qVoqclK/S1dDUQd9QZoKWrDLY7gJzIHAw= +github.com/Unity-Technologies/unity-gaming-services-go-sdk v0.4.1/go.mod h1:WgDwSafd4alCs+HdK0z+7htBVZIe+LUrLQgM738WDd0= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/centrifugal/centrifuge v0.21.1 h1:7saDm953rxzke4YfzoNekxKnpckmdTnz8EzbSribwos= github.com/centrifugal/centrifuge-go v0.8.4 h1:X23NuXmXTqdlp6PNrZLj1bWcPpehVq5u8LxuM2+NrIA= diff --git a/simple-game-server-go/internal/game/allocated.go b/simple-game-server-go/internal/game/allocated.go index 3180276..f26be83 100644 --- a/simple-game-server-go/internal/game/allocated.go +++ b/simple-game-server-go/internal/game/allocated.go @@ -14,7 +14,7 @@ import ( "github.com/sirupsen/logrus" ) -const defaultMaxPlayers = 4 +const defaultMaxPlayers = 64 // allocated starts a game after the server has been allocated. func (g *Game) allocated(allocationID string) { @@ -58,6 +58,8 @@ func (g *Game) launchGame(port int64) { return } + go g.simulatePlayers() + g.gameBind = gs for { @@ -71,11 +73,34 @@ func (g *Game) launchGame(port int64) { continue } - go g.handleClient(client) } } +const startPlayers = 30 + +func (g *Game) simulatePlayers() { + // Setup baseline of players + for i := 0; i < startPlayers; i++ { + g.Server.PlayerJoined() + } + for { + j, err := rand.Int(rand.Reader, big.NewInt(4)) + if err != nil { + g.logger.Debug(err) + fmt.Println("j: ", j) + return + } + + if j.Int64() == 0 || j.Int64() == 1 { + g.Server.PlayerLeft() + } else { + g.Server.PlayerJoined() + } + time.Sleep(20 * time.Second) + } +} + // acceptClient accepts a new TCP connection and updates internal state. func (g *Game) acceptClient(server *net.TCPListener) (*net.TCPConn, error) { client, err := server.AcceptTCP()