Implemented disconnects

This commit is contained in:
2024-01-28 16:47:41 +01:00
parent 5c6df98909
commit 70ebe4f05a
5 changed files with 40 additions and 23 deletions

View File

@ -40,7 +40,7 @@ func (game *Game) Login(data []byte, address *net.UDPAddr, server *Server) error
return errors.New("login failure")
}
player := game.players.Add(address, account)
player := NewPlayer(address, account, game)
player.authToken = createAuthToken()
player.KeepAlive()
@ -49,24 +49,10 @@ func (game *Game) Login(data []byte, address *net.UDPAddr, server *Server) error
response = AppendString(response, player.authToken)
server.Send(packet.Login, response, address)
game.onLogin(player)
game.players.Add(player)
return nil
}
// Inform the newly logged in player about existing players.
// Also inform existing players about the newly logged in player.
func (game *Game) onLogin(player *Player) {
game.players.Each(func(other *Player) bool {
game.server.Send(packet.PlayerAdd, other.State(), player.address)
if other != player {
game.server.Send(packet.PlayerAdd, player.State(), other.address)
}
return true
})
}
func getLoginData(data []byte) (string, string, error) {
loginRequest := [2]string{}
err := json.Unmarshal(data, &loginRequest)