Send own player object

This commit is contained in:
Layla 2020-08-21 02:39:10 -04:00
parent c0c82f3677
commit 5b022e17fa
No known key found for this signature in database
GPG Key ID: A494D9357BA1BE31

View File

@ -96,6 +96,14 @@ func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB
Presence: precense,
}
if jsonObj, err := player.GetPosJSON(); err != nil {
logger.Error(err.Error())
} else {
if sendErr := dispatcher.BroadcastMessage(OpCodeUpdatePosition, jsonObj, []runtime.Presence{precense}, player.Presence, true); sendErr != nil {
logger.Error(sendErr.Error())
}
}
mState.players[precense.GetUserId()] = player
// Get intial tile data around player
@ -108,12 +116,12 @@ func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB
logger.Error(sendErr.Error())
}
}
for _, player := range mState.players {
for _, otherPlayer := range mState.players {
// Broadcast player data to client
if jsonObj, err := player.GetPosJSON(); err != nil {
if jsonObj, err := otherPlayer.GetPosJSON(); err != nil {
logger.Error(err.Error())
} else {
if sendErr := dispatcher.BroadcastMessage(OpCodeUpdatePosition, jsonObj, []runtime.Presence{precense}, player.Presence, true); sendErr != nil {
if sendErr := dispatcher.BroadcastMessage(OpCodeUpdatePosition, jsonObj, []runtime.Presence{precense}, otherPlayer.Presence, true); sendErr != nil {
logger.Error(sendErr.Error())
}
}