Implemented disconnects
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user