func DebugRequestLobbyStart(so socketio.Socket) func(string) string { return chelpers.FilterRequest(so, debugRequestLobbyStartFilter, func(params map[string]interface{}) string { lobby, _ := models.GetLobbyById(params["id"].(uint)) bytes, _ := models.DecorateLobbyConnectJSON(lobby).Encode() room := fmt.Sprintf("%s_private", chelpers.GetLobbyRoom(lobby.ID)) broadcaster.SendMessageToRoom(room, "lobbyStart", string(bytes)) bytes, _ = chelpers.BuildSuccessJSON(simplejson.New()).Encode() return string(bytes) }) }
func PlayerReady(so socketio.Socket) func(string) string { return chelpers.FilterRequest(so, playerReadyFilter, func(_ map[string]interface{}) string { steamid := chelpers.GetSteamId(so.Id()) player, tperr := models.GetPlayerBySteamId(steamid) if tperr != nil { bytes, _ := tperr.ErrorJSON().Encode() return string(bytes) } lobbyid, tperr := player.GetLobbyId() if tperr != nil { bytes, _ := tperr.ErrorJSON().Encode() return string(bytes) } lobby, tperr := models.GetLobbyById(lobbyid) if tperr != nil { bytes, _ := tperr.ErrorJSON().Encode() return string(bytes) } if lobby.State != models.LobbyStateReadyingUp { bytes, _ := helpers.NewTPError("Lobby hasn't been filled up yet.", 4).ErrorJSON().Encode() return string(bytes) } helpers.LockRecord(lobby.ID, lobby) tperr = lobby.ReadyPlayer(player) defer helpers.UnlockRecord(lobby.ID, lobby) if tperr != nil { bytes, _ := tperr.ErrorJSON().Encode() return string(bytes) } if lobby.IsEveryoneReady() { lobby.State = models.LobbyStateInProgress lobby.Save() bytes, _ := models.DecorateLobbyConnectJSON(lobby).Encode() room := fmt.Sprintf("%s_private", chelpers.GetLobbyRoom(lobby.ID)) broadcaster.SendMessageToRoom(room, "lobbyStart", string(bytes)) models.BroadcastLobbyList() } bytes, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode() return 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)) } }