Add debug messages
This commit is contained in:
@ -111,13 +111,14 @@ func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB
|
|||||||
player.Y = 16
|
player.Y = 16
|
||||||
} else {
|
} else {
|
||||||
logger.Error(loadPlayerErr.Error())
|
logger.Error(loadPlayerErr.Error())
|
||||||
player = entities.PlayerEntity{
|
player = &entities.PlayerEntity{
|
||||||
X: 16,
|
X: 16,
|
||||||
Y: 16,
|
Y: 16,
|
||||||
Name: "ERROR",
|
Name: "ERROR",
|
||||||
Presence: precense,
|
Presence: precense,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.Info("Successfully loaded player object from storage!")
|
||||||
|
|
||||||
if jsonObj, err := player.GetPosJSON(); err != nil {
|
if jsonObj, err := player.GetPosJSON(); err != nil {
|
||||||
logger.Error(err.Error())
|
logger.Error(err.Error())
|
||||||
@ -126,12 +127,15 @@ func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB
|
|||||||
logger.Error(sendErr.Error())
|
logger.Error(sendErr.Error())
|
||||||
}
|
}
|
||||||
stateJSON, _ := player.GetStateJSON()
|
stateJSON, _ := player.GetStateJSON()
|
||||||
|
|
||||||
|
// Send player state to clients
|
||||||
if sendErr := dispatcher.BroadcastMessage(OpCodePlayerState, stateJSON, mState.GetPrecenseList(), player.Presence, true); sendErr != nil {
|
if sendErr := dispatcher.BroadcastMessage(OpCodePlayerState, stateJSON, mState.GetPrecenseList(), player.Presence, true); sendErr != nil {
|
||||||
logger.Error(sendErr.Error())
|
logger.Error(sendErr.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.Info("Successfully sent player state and location!")
|
||||||
|
|
||||||
mState.players[precense.GetUserId()] = player
|
mState.players[precense.GetUserId()] = *player
|
||||||
|
|
||||||
// Get intial tile data around player
|
// Get intial tile data around player
|
||||||
if regionData, err := mState.worldMap.GetJSONRegionAround(player.X, player.Y, maxRenderDistance); err != nil {
|
if regionData, err := mState.worldMap.GetJSONRegionAround(player.X, player.Y, maxRenderDistance); err != nil {
|
||||||
@ -143,6 +147,9 @@ func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB
|
|||||||
logger.Error(sendErr.Error())
|
logger.Error(sendErr.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.Info("Successfully send intial tile data to connected players")
|
||||||
|
|
||||||
for _, otherPlayer := range mState.players {
|
for _, otherPlayer := range mState.players {
|
||||||
// Broadcast player data to client
|
// Broadcast player data to client
|
||||||
if jsonObj, err := otherPlayer.GetPosJSON(); err != nil {
|
if jsonObj, err := otherPlayer.GetPosJSON(); err != nil {
|
||||||
|
@ -53,7 +53,7 @@ func PlayerDataExists(ctx context.Context, nk runtime.NakamaModule, userID strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadPlayer creates player object
|
// LoadPlayer creates player object
|
||||||
func LoadPlayer(ctx context.Context, nk runtime.NakamaModule, presence runtime.Presence) (PlayerEntity, error) {
|
func LoadPlayer(ctx context.Context, nk runtime.NakamaModule, presence runtime.Presence) (*PlayerEntity, error) {
|
||||||
player := PlayerEntity{Presence: presence}
|
player := PlayerEntity{Presence: presence}
|
||||||
|
|
||||||
// Read storage
|
// Read storage
|
||||||
@ -66,7 +66,7 @@ func LoadPlayer(ctx context.Context, nk runtime.NakamaModule, presence runtime.P
|
|||||||
}
|
}
|
||||||
records, err := nk.StorageRead(ctx, PlayerReads)
|
records, err := nk.StorageRead(ctx, PlayerReads)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return player, err
|
return &player, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load storage records into object
|
// Load storage records into object
|
||||||
@ -76,7 +76,7 @@ func LoadPlayer(ctx context.Context, nk runtime.NakamaModule, presence runtime.P
|
|||||||
responseData := PlayerSaveData{}
|
responseData := PlayerSaveData{}
|
||||||
err := json.Unmarshal([]byte(record.Value), &responseData)
|
err := json.Unmarshal([]byte(record.Value), &responseData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return player, err
|
return &player, err
|
||||||
}
|
}
|
||||||
player.Name = responseData.Name
|
player.Name = responseData.Name
|
||||||
player.Faction = gameworld.Faction(responseData.Faction)
|
player.Faction = gameworld.Faction(responseData.Faction)
|
||||||
@ -84,7 +84,7 @@ func LoadPlayer(ctx context.Context, nk runtime.NakamaModule, presence runtime.P
|
|||||||
player.Y = 16.0
|
player.Y = 16.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return player, nil
|
return &player, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPosJSON returns the player's position as a JSON object
|
// GetPosJSON returns the player's position as a JSON object
|
||||||
|
@ -14,6 +14,7 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
|
|||||||
github.com/heroiclabs/nakama-common v1.5.1 h1:ViCm9AvYYdQOCSKEa34SuSQ80JyZOHl6ODawESWf2wk=
|
github.com/heroiclabs/nakama-common v1.5.1 h1:ViCm9AvYYdQOCSKEa34SuSQ80JyZOHl6ODawESWf2wk=
|
||||||
github.com/heroiclabs/nakama-common v1.5.1/go.mod h1:nZAXHdeo4SyPlCyf7pU9rCVizxEhBF74gt7teDe/EaQ=
|
github.com/heroiclabs/nakama-common v1.5.1/go.mod h1:nZAXHdeo4SyPlCyf7pU9rCVizxEhBF74gt7teDe/EaQ=
|
||||||
github.com/heroiclabs/nakama-common v1.7.2 h1:FQedePGCorBl3tXW4Ro8+XLGbEDQfGrT5Tb07j1UaLc=
|
github.com/heroiclabs/nakama-common v1.7.2 h1:FQedePGCorBl3tXW4Ro8+XLGbEDQfGrT5Tb07j1UaLc=
|
||||||
|
github.com/heroiclabs/nakama-common v1.7.3 h1:HksdpzLdSzfbOGRlrHgZIz+dPXrM9oaWrIEZXnWW3eE=
|
||||||
github.com/josephbmanley/family v0.0.0-20200815220504-0d9d05943cef h1:6oijVkew6eKI1fGE+YMaxmiNlp/hkN9wDpStoid9/ZI=
|
github.com/josephbmanley/family v0.0.0-20200815220504-0d9d05943cef h1:6oijVkew6eKI1fGE+YMaxmiNlp/hkN9wDpStoid9/ZI=
|
||||||
github.com/josephbmanley/family v0.0.0-20200816202226-abfb0f428423 h1:ynsJFMYkfs3JspzvLCfmPGJwdKY/4QeX457U0+y4J1I=
|
github.com/josephbmanley/family v0.0.0-20200816202226-abfb0f428423 h1:ynsJFMYkfs3JspzvLCfmPGJwdKY/4QeX457U0+y4J1I=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
Reference in New Issue
Block a user