func (Player) PlayerNotReady(so *wsevent.Client, _ struct{}) interface{} { player, tperr := models.GetPlayerBySteamID(chelpers.GetSteamId(so.ID)) if tperr != nil { return tperr } lobbyid, tperr := player.GetLobbyID(false) if tperr != nil { return tperr } lobby, tperr := models.GetLobbyByID(lobbyid) if tperr != nil { return tperr } if lobby.State != models.LobbyStateReadyingUp { return helpers.NewTPError("Lobby hasn't been filled up yet.", 4) } tperr = lobby.UnreadyPlayer(player) lobby.RemovePlayer(player) hooks.AfterLobbyLeave(lobby, player) lobby.AddSpectator(player) hooks.AfterLobbySpec(socket.AuthServer, so, lobby) if tperr != nil { return tperr } lobby.UnreadyAllPlayers() return chelpers.EmptySuccessJS }
func (Unauth) LobbySpectatorJoin(so *wsevent.Client, args struct { ID *uint `json:"id"` }) interface{} { lob, err := lobby.GetLobbyByID(*args.ID) if err != nil { return err } hooks.AfterLobbySpec(socket.UnauthServer, so, nil, lob) so.EmitJSON(helpers.NewRequest("lobbyData", lobby.DecorateLobbyData(lob, true))) return emptySuccess }
func (Lobby) UnAuthSpecJoin(so *wsevent.Client, args struct { ID *uint `json:"id"` }) interface{} { var lob *models.Lobby lob, tperr := models.GetLobbyByID(*args.ID) if tperr != nil { return tperr } hooks.AfterLobbySpec(socket.UnauthServer, so, lob) so.EmitJSON(helpers.NewRequest("lobbyData", models.DecorateLobbyData(lob, true))) return chelpers.EmptySuccessJS }
func (Lobby) LobbySpectatorJoin(so *wsevent.Client, args struct { Id *uint `json:"id"` }) interface{} { var lob *models.Lobby lob, tperr := models.GetLobbyByID(*args.Id) if tperr != nil { return tperr } player := chelpers.GetPlayerFromSocket(so.ID) var specSameLobby bool arr, tperr := player.GetSpectatingIds() if len(arr) != 0 { for _, id := range arr { if id == *args.Id { specSameLobby = true continue } //a socket should only spectate one lobby, remove socket from //any other lobby room //multiple sockets from one player can spectatte multiple lobbies socket.AuthServer.RemoveClient(so, fmt.Sprintf("%d_public", id)) } } // If the player is already in the lobby (either joined a slot or is spectating), don't add them. // Just Broadcast the lobby to them, so the frontend displays it. if id, _ := player.GetLobbyID(false); id != *args.Id && !specSameLobby { tperr = lob.AddSpectator(player) if tperr != nil { return tperr } } hooks.AfterLobbySpec(socket.AuthServer, so, lob) models.BroadcastLobbyToUser(lob, player.SteamID) return chelpers.EmptySuccessJS }