Skip to content

Commit e25a535

Browse files
committed
init
1 parent e489909 commit e25a535

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

simple-game-server-go/internal/game/allocated.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func (g *Game) acceptClient(server *net.TCPListener) (*net.TCPConn, error) {
9696

9797
g.clients.Store(client.RemoteAddr(), client)
9898
currentPlayers := g.Server.PlayerJoined()
99+
99100
g.logger.WithFields(logrus.Fields{
100101
"client_ip": client.RemoteAddr().String(),
101102
"current_players": currentPlayers,
@@ -128,6 +129,41 @@ func (g *Game) handleClient(client *net.TCPConn) {
128129
}
129130
}
130131

132+
133+
func (g *Game) FakeCCU() {
134+
tick := time.NewTicker(15 * time.Second)
135+
defer tick.Stop()
136+
137+
increasing := true
138+
minFakeCCU := int32(1)
139+
maxFakeCCU := int32(10)
140+
fakeCCU := minFakeCCU
141+
142+
for {
143+
select {
144+
case <-tick.C:
145+
146+
// make a fake sine graph
147+
148+
if fakeCCU >= maxFakeCCU {
149+
increasing = false
150+
} else if fakeCCU <= minFakeCCU {
151+
increasing = true
152+
}
153+
154+
if increasing {
155+
fakeCCU++
156+
} else {
157+
fakeCCU--
158+
}
159+
160+
g.logger.Info(fmt.Sprintf("Bens Fake CCU: %d", fakeCCU))
161+
g.Server.SetCurrentPlayers(fakeCCU)
162+
163+
}
164+
}
165+
}
166+
131167
// readyForPlayers waits 20s then reports that the game is ready for players.
132168
//
133169
// This is to simulate a game server waiting for any initialization to complete
@@ -137,7 +173,10 @@ func (g *Game) handleClient(client *net.TCPConn) {
137173
// configuration variable in the build configuration to a duration string
138174
// recognised by `time.ParseDuration`, e.g. "30s".
139175
func (g *Game) readyForPlayers() {
140-
g.logger.Info("ready for players")
176+
g.logger.Info("ben ready for playerzzz")
177+
178+
// g.Server.SetCurrentPlayers(0)
179+
go g.FakeCCU() // call function as go routine
141180

142181
timeout := defaultReadyTimeout
143182

0 commit comments

Comments
 (0)