Send out player data
This commit is contained in:
parent
d700b27487
commit
7aeafc7b42
@ -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))
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user