From 7aeafc7b426e6f90cfa1a7d1c6f379139e226f41 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Fri, 21 Aug 2020 01:33:08 -0400 Subject: [PATCH] Send out player data --- server/plugin/control/control.go | 8 ++++++-- server/plugin/entities/entities.go | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server/plugin/control/control.go b/server/plugin/control/control.go index e395611..babd87b 100644 --- a/server/plugin/control/control.go +++ b/server/plugin/control/control.go @@ -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)) } diff --git a/server/plugin/entities/entities.go b/server/plugin/entities/entities.go index 7f68e71..f27aacc 100644 --- a/server/plugin/entities/entities.go +++ b/server/plugin/entities/entities.go @@ -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 }