本文整理匯總了Golang中github.com/TF2Stadium/Helen/models.GetLobbyById函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetLobbyById函數的具體用法?Golang GetLobbyById怎麽用?Golang GetLobbyById使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetLobbyById函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LobbySpectatorJoin
func (Lobby) LobbySpectatorJoin(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, authority.AuthAction(0), true)
if reqerr != nil {
bytes, _ := json.Marshal(reqerr)
return bytes
}
var args struct {
Id *uint `json:"id"`
}
if err := chelpers.GetParams(data, &args); err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
var lob *models.Lobby
lob, tperr := models.GetLobbyById(*args.Id)
if tperr != nil {
return tperr.Encode()
}
player, tperr := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
if tperr != nil {
return tperr.Encode()
}
var specSameLobby bool
arr, tperr := player.GetSpectatingIds()
if len(arr) != 0 {
for _, id := range arr {
if id == *args.Id {
specSameLobby = true
continue
}
lobby, _ := models.GetLobbyById(id)
lobby.RemoveSpectator(player, true)
server.RemoveClient(so.Id(), 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(); id != *args.Id && !specSameLobby {
tperr = lob.AddSpectator(player)
if tperr != nil {
return tperr.Encode()
}
chelpers.AfterLobbySpec(server, so, lob)
}
models.BroadcastLobbyToUser(lob, player.SteamId)
return chelpers.EmptySuccessJS
}
示例2: DebugLobbyFill
func DebugLobbyFill(so socketio.Socket) func(string) string {
return chelpers.FilterRequest(so, debugLobbyFillFilter,
func(param map[string]interface{}) string {
id := param["id"].(uint)
lobby, _ := models.GetLobbyById(id)
var players []*models.Player
for i := 1; i < int(lobby.Type)*2; i++ {
steamid := "DEBUG" + strconv.FormatUint(uint64(time.Now().Unix()), 10) + strconv.Itoa(i)
player, _ := models.NewPlayer(steamid)
player.Debug = true
player.Save()
players = append(players, player)
lobby.AddPlayer(player, i)
}
lobby.State = models.LobbyStateReadyingUp
lobby.Save()
room := fmt.Sprintf("%s_public", chelpers.GetLobbyRoom(lobby.ID))
broadcaster.SendMessageToRoom(room, "lobbyReadyUp", "")
lobby.ReadyUpTimeoutCheck()
bytes, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode()
return string(bytes)
})
}
示例3: removePlayerFromLobby
func removePlayerFromLobby(lobbyId uint, steamId string) (*models.Lobby, *models.Player, *helpers.TPError) {
player, tperr := models.GetPlayerBySteamId(steamId)
if tperr != nil {
return nil, nil, tperr
}
lob, tperr := models.GetLobbyById(lobbyId)
if tperr != nil {
return nil, nil, tperr
}
switch lob.State {
case models.LobbyStateInProgress:
return lob, player, helpers.NewTPError("Lobby is in progress.", 1)
case models.LobbyStateEnded:
return lob, player, helpers.NewTPError("Lobby has closed.", 1)
}
_, err := lob.GetPlayerSlot(player)
if err != nil {
return lob, player, helpers.NewTPError("Player not playing", 2)
}
if err := lob.RemovePlayer(player); err != nil {
return lob, player, err
}
return lob, player, lob.AddSpectator(player)
}
示例4: LobbyClose
func LobbyClose(so socketio.Socket) func(string) string {
return chelpers.FilterRequest(so, lobbyCloseFilters,
func(params map[string]interface{}) string {
player, _ := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
lobbyid := params["id"].(uint)
lob, tperr := models.GetLobbyById(uint(lobbyid))
if tperr != nil {
bytes, _ := tperr.ErrorJSON().Encode()
return string(bytes)
}
if player.SteamId != lob.CreatedBySteamID && player.Role != helpers.RoleAdmin {
bytes, _ := chelpers.BuildFailureJSON("Player not authorized to close lobby.", 1).Encode()
return string(bytes)
}
if lob.State == models.LobbyStateEnded {
bytes, _ := chelpers.BuildFailureJSON("Lobby already closed.", -1).Encode()
return string(bytes)
}
helpers.LockRecord(lob.ID, lob)
lob.Close(true)
helpers.UnlockRecord(lob.ID, lob)
chelpers.StopLogger(lobbyid)
models.BroadcastLobbyList() // has to be done manually for now
bytes, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode()
return string(bytes)
})
}
示例5: onDisconnect
func onDisconnect(id string) {
//defer helpers.Logger.Debug("Disconnected from Socket")
defer chelpers.DeauthenticateSocket(id)
if chelpers.IsLoggedInSocket(id) {
steamid := chelpers.GetSteamId(id)
broadcaster.RemoveSocket(steamid)
player, tperr := models.GetPlayerBySteamId(steamid)
if tperr != nil || player == nil {
helpers.Logger.Error(tperr.Error())
return
}
ids, tperr := player.GetSpectatingIds()
if tperr != nil {
helpers.Logger.Error(tperr.Error())
return
}
for _, id := range ids {
lobby, _ := models.GetLobbyById(id)
err := lobby.RemoveSpectator(player, true)
if err != nil {
helpers.Logger.Error(err.Error())
continue
}
//helpers.Logger.Debug("removing %s from %d", player.SteamId, id)
}
}
}
示例6: DebugLobbyReady
func DebugLobbyReady(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, 0, true)
if reqerr != nil {
return reqerr.Encode()
}
var args struct {
Id *uint `json:"id"`
}
err := chelpers.GetParams(data, &args)
if err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
lobby, _ := models.GetLobbyById(*args.Id)
var slots []models.LobbySlot
db.DB.Where("lobby_id = ?", lobby.ID).Find(&slots)
for _, slot := range slots {
slot.Ready = true
db.DB.Save(slot)
}
lobby.OnChange(true)
return chelpers.EmptySuccessJS
}
示例7: DebugRequestLobbyStart
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)
})
}
示例8: PlayerReady
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)
})
}
示例9: DebugPlayerSub
func DebugPlayerSub(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, 0, true)
if reqerr != nil {
return reqerr.Encode()
}
var args struct {
Id *uint `json:"id"`
Team *string `json:"team"`
Class *string `json:"class"`
}
err := chelpers.GetParams(data, &args)
if err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
lob, tperr := models.GetLobbyById(*args.Id)
if tperr != nil {
return tperr.Encode()
}
s, tperr := models.LobbyGetPlayerSlot(lob.Type, *args.Team, *args.Class)
if tperr != nil {
return tperr.Encode()
}
slot := models.LobbySlot{}
err = db.DB.Where("slot = ?", s).First(&slot).Error
if err != nil {
helpers.Logger.Debug("", slot, s)
return helpers.NewTPErrorFromError(err).Encode()
}
player := models.Player{}
err = db.DB.First(&player, slot.PlayerId).Error
if err != nil {
helpers.Logger.Debug("", player)
return helpers.NewTPErrorFromError(err).Encode()
}
sub, _ := models.NewSub(*args.Id, player.SteamId)
db.DB.Save(sub)
models.BroadcastSubList()
return chelpers.EmptySuccessJS
}
示例10: playerCanKick
func playerCanKick(lobbyId uint, steamId string) (bool, *helpers.TPError) {
lob, tperr := models.GetLobbyById(lobbyId)
if tperr != nil {
return false, tperr
}
player, tperr2 := models.GetPlayerBySteamId(steamId)
if tperr2 != nil {
return false, tperr2
}
if steamId != lob.CreatedBySteamID && player.Role != helpers.RoleAdmin {
return false, helpers.NewTPError("Not authorized to kick players", 1)
}
return true, nil
}
示例11: PlayerNotReady
func PlayerNotReady(so socketio.Socket) func(string) string {
return chelpers.FilterRequest(so, playerUnreadyFilter,
func(_ map[string]interface{}) string {
player, tperr := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
if tperr != nil {
bytes, _ := tperr.ErrorJSON().Encode()
return string(bytes)
}
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.UnreadyPlayer(player)
lobby.RemovePlayer(player)
helpers.UnlockRecord(lobby.ID, lobby)
if tperr != nil {
bytes, _ := tperr.ErrorJSON().Encode()
return string(bytes)
}
lobby.UnreadyAllPlayers()
bytes, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode()
return string(bytes)
})
}
示例12: TestLobbyCreation
func TestLobbyCreation(t *testing.T) {
testhelpers.CleanupDB()
lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, "ugc", models.ServerRecord{0, "testip", "", ""}, 0, false)
lobby.Save()
lobby2, _ := models.GetLobbyById(lobby.ID)
assert.Equal(t, lobby.ID, lobby2.ID)
assert.Equal(t, lobby.ServerInfo.Host, lobby2.ServerInfo.Host)
assert.Equal(t, lobby.ServerInfo.ID, lobby2.ServerInfo.ID)
lobby.MapName = "cp_granary"
lobby.Save()
db.DB.First(lobby2)
assert.Equal(t, "cp_granary", lobby2.MapName)
}
示例13: LobbyNoLoginSpectatorJoin
func LobbyNoLoginSpectatorJoin(so socketio.Socket) func(string) string {
return chelpers.FilterRequest(so, lobbyNoLoginSpectatorJoinFilters,
func(params map[string]interface{}) string {
id := params["id"].(uint)
lobby, err := models.GetLobbyById(id)
if err != nil {
bytes, _ := err.ErrorJSON().Encode()
return string(bytes)
}
chelpers.AfterLobbySpec(so, lobby)
bytes, _ := models.DecorateLobbyDataJSON(lobby, true).Encode()
so.Emit("lobbyData", string(bytes))
bytes, _ = chelpers.BuildSuccessJSON(simplejson.New()).Encode()
return string(bytes)
})
}
示例14: DebugLobbyReady
func DebugLobbyReady(so socketio.Socket) func(string) string {
return chelpers.FilterRequest(so, debugLobbyReadyFilter,
func(param map[string]interface{}) string {
id := param["id"].(uint)
lobby, _ := models.GetLobbyById(id)
var slots []models.LobbySlot
db.DB.Where("lobby_id = ?", lobby.ID).Find(&slots)
for _, slot := range slots {
slot.Ready = true
db.DB.Save(slot)
}
lobby.OnChange(true)
bytes, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode()
return string(bytes)
})
}
示例15: LobbyServerReset
func (Lobby) LobbyServerReset(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, authority.AuthAction(0), true)
if reqerr != nil {
return reqerr.Encode()
}
var args struct {
ID *uint `json:"id"`
}
if err := chelpers.GetParams(data, &args); err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
player, err := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
if err != nil {
return err.Encode()
}
lobby, tperr := models.GetLobbyById(*args.ID)
if player.SteamId != lobby.CreatedBySteamID {
return helpers.NewTPError("Player not authorized to close lobby.", -1).Encode()
}
if tperr != nil {
return tperr.Encode()
}
if lobby.State == models.LobbyStateEnded {
return helpers.NewTPError("Lobby has ended", 1).Encode()
}
if err := models.ReExecConfig(lobby.ID); err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
return chelpers.EmptySuccessJS
}