func AfterConnectLoggedIn(server *wsevent.Server, so *wsevent.Client, player *models.Player) { lobbyIdPlaying, err := player.GetLobbyId() if err == nil { lobby, _ := models.GetLobbyByIdServer(lobbyIdPlaying) AfterLobbyJoin(server, so, lobby, player) AfterLobbySpec(server, so, lobby) models.BroadcastLobbyToUser(lobby, GetSteamId(so.Id())) slot := &models.LobbySlot{} err := db.DB.Where("lobby_id = ? AND player_id = ?", lobby.ID, player.ID).First(slot).Error if err == nil { if lobby.State == models.LobbyStateInProgress && !models.IsPlayerInServer(player.SteamId) { bytes, _ := json.Marshal(models.DecorateLobbyConnect(lobby, player.Name, slot.Class)) broadcaster.SendMessage(player.SteamId, "lobbyStart", string(bytes)) } else if lobby.State == models.LobbyStateReadyingUp && !slot.Ready { data := struct { Timeout int64 `json:"timeout"` }{lobby.ReadyUpTimeLeft()} bytes, _ := json.Marshal(data) broadcaster.SendMessage(player.SteamId, "lobbyReadyUp", string(bytes)) } } } settings, err2 := player.GetSettings() if err2 == nil { bytes, _ := json.Marshal(models.DecoratePlayerSettingsJson(settings)) broadcaster.SendMessage(player.SteamId, "playerSettings", string(bytes)) } profilePlayer, err3 := models.GetPlayerWithStats(player.SteamId) if err3 == nil { bytes, _ := json.Marshal(models.DecoratePlayerProfileJson(profilePlayer)) broadcaster.SendMessage(player.SteamId, "playerProfile", string(bytes)) } }
func AfterConnectLoggedIn(so socketio.Socket, player *models.Player) { lobbyIdPlaying, err := player.GetLobbyId() if err == nil { lobby, _ := models.GetLobbyById(lobbyIdPlaying) AfterLobbyJoin(so, lobby, player) AfterLobbySpec(so, lobby) models.BroadcastLobbyToUser(lobby, GetSteamId(so.Id())) slot := &models.LobbySlot{} err := db.DB.Where("lobby_id = ? AND player_id = ?", lobby.ID, player.ID).First(slot).Error if err == nil { if lobby.State == models.LobbyStateInProgress && !slot.InGame { bytes, _ := models.DecorateLobbyConnectJSON(lobby).Encode() broadcaster.SendMessage(player.SteamId, "lobbyStart", string(bytes)) } else if lobby.State == models.LobbyStateReadyingUp && !slot.Ready { left := simplejson.New() left.Set("timeout", lobby.ReadyUpTimeLeft()) bytes, _ := left.Encode() broadcaster.SendMessage(player.SteamId, "lobbyReadyUp", string(bytes)) } } } settings, err2 := player.GetSettings() if err2 == nil { json := models.DecoratePlayerSettingsJson(settings) bytes, _ := json.Encode() broadcaster.SendMessage(player.SteamId, "playerSettings", string(bytes)) } profilePlayer, err3 := models.GetPlayerWithStats(player.SteamId) if err3 == nil { json := models.DecoratePlayerProfileJson(profilePlayer) bytes, _ := json.Encode() broadcaster.SendMessage(player.SteamId, "playerProfile", string(bytes)) } }