func (Player) PlayerSettingsGet(server *wsevent.Server, so *wsevent.Client, data []byte) []byte { reqerr := chelpers.FilterRequest(so, 0, true) if reqerr != nil { return reqerr.Encode() } var args struct { Key string `json:"key"` } err := chelpers.GetParams(data, &args) if err != nil { return helpers.NewTPErrorFromError(err).Encode() } player, _ := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id())) var settings []models.PlayerSetting var setting models.PlayerSetting if args.Key == "*" { settings, err = player.GetSettings() } else { setting, err = player.GetSetting(args.Key) settings = append(settings, setting) } if err != nil { return helpers.NewTPErrorFromError(err).Encode() } result := models.DecoratePlayerSettingsJson(settings) resp, _ := chelpers.BuildSuccessJSON(result).Encode() return resp }
func PlayerSettingsGet(so socketio.Socket) func(string) string { return chelpers.FilterRequest(so, playerSettingsGetFilter, func(params map[string]interface{}) string { player, _ := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id())) key := params["key"].(string) var err error var settings []models.PlayerSetting var setting models.PlayerSetting if key == "" { settings, err = player.GetSettings() } else { setting, err = player.GetSetting(key) settings = append(settings, setting) } if err != nil { bytes, _ := chelpers.BuildFailureJSON(err.Error(), 0).Encode() return string(bytes) } result := models.DecoratePlayerSettingsJson(settings) resp, _ := chelpers.BuildSuccessJSON(result).Encode() return string(resp) }) }
func AfterConnectLoggedIn(so *wsevent.Client, player *models.Player) { if time.Since(player.UpdatedAt) >= time.Hour*1 { player.UpdatePlayerInfo() player.Save() } lobbyID, err := player.GetLobbyID(false) if err == nil { lobby, _ := models.GetLobbyByIDServer(lobbyID) AfterLobbyJoin(so, lobby, player) AfterLobbySpec(socket.AuthServer, so, lobby) models.BroadcastLobbyToUser(lobby, chelpers.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 { broadcaster.SendMessage(player.SteamID, "lobbyStart", models.DecorateLobbyConnect(lobby, player.Name, slot.Slot)) } else if lobby.State == models.LobbyStateReadyingUp && !slot.Ready { data := struct { Timeout int64 `json:"timeout"` }{lobby.ReadyUpTimeLeft()} broadcaster.SendMessage(player.SteamID, "lobbyReadyUp", data) } } } settings, err2 := player.GetSettings() if err2 == nil { broadcaster.SendMessage(player.SteamID, "playerSettings", models.DecoratePlayerSettingsJson(settings)) } profilePlayer, err3 := models.GetPlayerWithStats(player.SteamID) if err3 == nil { broadcaster.SendMessage(player.SteamID, "playerProfile", models.DecoratePlayerProfileJson(profilePlayer)) } }
func (Player) PlayerSettingsGet(so *wsevent.Client, args struct { Key *string `json:"key"` }) interface{} { var err error player, _ := models.GetPlayerBySteamID(chelpers.GetSteamId(so.ID)) var settings []models.PlayerSetting var setting models.PlayerSetting if *args.Key == "*" { settings, err = player.GetSettings() } else { setting, err = player.GetSetting(*args.Key) settings = append(settings, setting) } if err != nil { return helpers.NewTPErrorFromError(err) } result := models.DecoratePlayerSettingsJson(settings) return chelpers.NewResponse(result) }
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)) } }