Send out player data

This commit is contained in:
Layla 2020-08-21 01:33:08 -04:00
parent d700b27487
commit 7aeafc7b42
No known key found for this signature in database
GPG Key ID: A494D9357BA1BE31
2 changed files with 18 additions and 6 deletions

View File

@ -139,8 +139,12 @@ func (m *Match) MatchLoop(ctx context.Context, logger runtime.Logger, db *sql.DB
if response, err := player.ParsePositionRequest(message.GetData()); err == nil {
player.UpdateBasedOnResponse(response)
dispatcher.BroadcastMessage(OpCodeUpdatePosition, []byte{}, mState.GetPrecenseList(), player.Presence, false)
logger.Info("Yes")
if jsonObject, err := player.GetPosJSON(); err == nil {
dispatcher.BroadcastMessage(OpCodeUpdatePosition, jsonObject, mState.GetPrecenseList(), player.Presence, false)
logger.Info("Yes")
} else {
logger.Error(fmt.Sprintf("Failed to get player json: %s", err.Error))
}
} else {
logger.Error(fmt.Sprintf("Failed to parse update pos request: %s", err.Error))
}

View File

@ -16,8 +16,8 @@ type PlayerEntity struct {
// PlayerPosResponse struct that represents client data
type PlayerPosResponse struct {
X float64
Y float64
X string
Y string
}
// ParsePositionRequest parses data from client
@ -29,8 +29,16 @@ func (p *PlayerEntity) ParsePositionRequest(data []byte) (PlayerPosResponse, err
//UpdateBasedOnResponse updates the player object based on a response object
func (p *PlayerEntity) UpdateBasedOnResponse(response PlayerPosResponse) error {
p.Y = response.Y
p.X = response.X
if fx, err := strconv.ParseFloat(response.X, 64); err != nil {
return err
} else {
p.X = fx
if fy, err := strconv.ParseFloat(response.Y, 64); err != nil {
return err
} else {
p.Y = fy
}
}
return nil
}