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 {
|
if response, err := player.ParsePositionRequest(message.GetData()); err == nil {
|
||||||
player.UpdateBasedOnResponse(response)
|
player.UpdateBasedOnResponse(response)
|
||||||
dispatcher.BroadcastMessage(OpCodeUpdatePosition, []byte{}, mState.GetPrecenseList(), player.Presence, false)
|
if jsonObject, err := player.GetPosJSON(); err == nil {
|
||||||
logger.Info("Yes")
|
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 {
|
} else {
|
||||||
logger.Error(fmt.Sprintf("Failed to parse update pos request: %s", err.Error))
|
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
|
// PlayerPosResponse struct that represents client data
|
||||||
type PlayerPosResponse struct {
|
type PlayerPosResponse struct {
|
||||||
X float64
|
X string
|
||||||
Y float64
|
Y string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParsePositionRequest parses data from client
|
// 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
|
//UpdateBasedOnResponse updates the player object based on a response object
|
||||||
func (p *PlayerEntity) UpdateBasedOnResponse(response PlayerPosResponse) error {
|
func (p *PlayerEntity) UpdateBasedOnResponse(response PlayerPosResponse) error {
|
||||||
p.Y = response.Y
|
if fx, err := strconv.ParseFloat(response.X, 64); err != nil {
|
||||||
p.X = response.X
|
return err
|
||||||
|
} else {
|
||||||
|
p.X = fx
|
||||||
|
if fy, err := strconv.ParseFloat(response.Y, 64); err != nil {
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
p.Y = fy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user