當前位置: 首頁>>代碼示例>>Golang>>正文


Golang models.NewLobby函數代碼示例

本文整理匯總了Golang中github.com/TF2Stadium/Helen/models.NewLobby函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewLobby函數的具體用法?Golang NewLobby怎麽用?Golang NewLobby使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewLobby函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestGetSpectatingIds

func TestGetSpectatingIds(t *testing.T) {
	testhelpers.CleanupDB()

	player, _ := models.NewPlayer("asdf")
	database.DB.Save(player)

	specIds, specErr := player.GetSpectatingIds()
	assert.Nil(t, specErr)
	assert.Equal(t, len(specIds), 0)
	//assert.Equal(t, []uint{lobby.ID, lobby2.ID}, specIds)

	lobby1 := models.NewLobby("cp_badlands", models.LobbyTypeSixes, "ugc", models.ServerRecord{}, 1, false)
	database.DB.Save(lobby1)
	lobby1.AddSpectator(player)

	specIds, specErr = player.GetSpectatingIds()
	assert.Nil(t, specErr)
	assert.Equal(t, specIds[0], lobby1.ID)

	lobby2 := models.NewLobby("cp_badlands", models.LobbyTypeSixes, "ugc", models.ServerRecord{}, 1, false)
	database.DB.Save(lobby2)
	lobby2.AddSpectator(player)

	specIds, specErr = player.GetSpectatingIds()
	assert.Nil(t, specErr)
	assert.Equal(t, []uint{lobby1.ID, lobby2.ID}, specIds)
}
開發者ID:demipixel,項目名稱:Helen,代碼行數:27,代碼來源:player_test.go

示例2: TestIsSpectating

func TestIsSpectating(t *testing.T) {
	testhelpers.CleanupDB()

	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, "ugc", models.ServerRecord{}, 1, false)
	database.DB.Save(lobby)

	lobby2 := models.NewLobby("cp_badlands", models.LobbyTypeSixes, "ugc", models.ServerRecord{}, 1, false)
	database.DB.Save(lobby2)

	player, _ := models.NewPlayer("asdf")
	database.DB.Save(player)

	isSpectating := player.IsSpectatingId(lobby.ID)
	assert.False(t, isSpectating)

	lobby.AddSpectator(player)

	isSpectating = player.IsSpectatingId(lobby.ID)
	assert.True(t, isSpectating)

	lobby2.AddSpectator(player)
	isSpectating2 := player.IsSpectatingId(lobby2.ID)
	assert.True(t, isSpectating2)

	specIds, specErr := player.GetSpectatingIds()
	assert.Nil(t, specErr)
	assert.Equal(t, []uint{lobby.ID, lobby2.ID}, specIds)

	lobby.RemoveSpectator(player, false)
	isSpectating = player.IsSpectatingId(lobby.ID)
	assert.False(t, isSpectating)
}
開發者ID:N1xx1,項目名稱:Helen,代碼行數:32,代碼來源:player_test.go

示例3: TestLobbyAdd

func TestLobbyAdd(t *testing.T) {
	migrations.TestCleanup()
	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, models.ServerRecord{0, "", ""}, 0)
	lobby.Save()

	var players []*models.Player

	for i := 0; i < 12; i++ {
		player, playErr := models.NewPlayer("p" + fmt.Sprint(i))
		assert.Nil(t, playErr)

		player.Save()
		players = append(players, player)
	}

	// add player
	err := lobby.AddPlayer(players[0], 0)
	assert.Nil(t, err)

	slot, err2 := lobby.GetPlayerSlot(players[0])
	assert.Equal(t, slot, 0)
	assert.Nil(t, err2)

	id, err3 := lobby.GetPlayerIdBySlot(0)
	assert.Equal(t, id, players[0].ID)
	assert.Nil(t, err3)

	// try to switch slots
	err = lobby.AddPlayer(players[0], 1)
	assert.Nil(t, err)

	slot, err2 = lobby.GetPlayerSlot(players[0])
	assert.Equal(t, slot, 1)
	assert.Nil(t, err2)

	// this should be empty now
	id, err3 = lobby.GetPlayerIdBySlot(0)
	assert.NotNil(t, err3)

	// try to add a second player to the same slot
	err = lobby.AddPlayer(players[1], 1)
	assert.NotNil(t, err)

	// try to add a player to a wrong slot slot
	err = lobby.AddPlayer(players[2], 55)
	assert.NotNil(t, err)

	lobby2 := models.NewLobby("cp_granary", models.LobbyTypeSixes, models.ServerRecord{0, "", ""}, 0)
	lobby2.Save()

	// try to add a player while they're in another lobby
	err = lobby.AddPlayer(players[0], 1)
	assert.NotNil(t, err)
}
開發者ID:UnnoTed,項目名稱:Helen,代碼行數:54,代碼來源:lobby_test.go

示例4: TestLobbyRemove

func TestLobbyRemove(t *testing.T) {
	migrations.TestCleanup()
	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, models.ServerRecord{0, "", ""}, 0)
	lobby.Save()

	player, playErr := models.NewPlayer("1235")
	assert.Nil(t, playErr)
	player.Save()

	// add player
	err := lobby.AddPlayer(player, 0)
	assert.Nil(t, err)

	// remove player
	err = lobby.RemovePlayer(player)
	assert.Nil(t, err)

	// this should be empty now
	_, err2 := lobby.GetPlayerIdBySlot(0)
	assert.NotNil(t, err2)

	// can add player again
	err = lobby.AddPlayer(player, 0)
	assert.Nil(t, err)
}
開發者ID:UnnoTed,項目名稱:Helen,代碼行數:25,代碼來源:lobby_test.go

示例5: TestSpectators

func TestSpectators(t *testing.T) {
	migrations.TestCleanup()

	player, playErr := models.NewPlayer("apple")
	assert.Nil(t, playErr)

	player.Save()

	player2, playErr2 := models.NewPlayer("testing1")
	assert.Nil(t, playErr2)
	player2.Save()

	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, models.ServerRecord{0, "", ""}, 0)
	lobby.Save()

	err := lobby.AddSpectator(player)
	assert.Nil(t, err)

	var specs []models.Player
	db.DB.Model(lobby).Association("Spectators").Find(&specs)
	assert.Equal(t, 1, len(specs))

	err = lobby.AddSpectator(player2)
	assert.Nil(t, err)

	specs = nil
	db.DB.Model(lobby).Association("Spectators").Find(&specs)
	assert.Equal(t, 2, len(specs))
	assert.Equal(t, true, specs[0].IsSpectatingId(lobby.ID))

	err = lobby.RemoveSpectator(player)
	assert.Nil(t, err)

	specs = nil
	db.DB.Model(lobby).Association("Spectators").Find(&specs)
	assert.Equal(t, 1, len(specs))

	// adding the same player again should not increase the count
	err = lobby.AddSpectator(player2)
	specs = nil
	db.DB.Model(lobby).Association("Spectators").Find(&specs)
	assert.Equal(t, 1, len(specs))

	// players in lobby should be removed from it if added as spectator
	lobby.AddPlayer(player, 10)
	err = lobby.AddSpectator(player)
	assert.Nil(t, err)
	_, terr := lobby.GetPlayerSlot(player)
	assert.NotNil(t, terr)

	// adding a player should remove them from spectators
	lobby.AddPlayer(player2, 11)
	specs = nil
	db.DB.Model(lobby).Association("Spectators").Find(&specs)
	assert.Equal(t, 0, len(specs))
}
開發者ID:UnnoTed,項目名稱:Helen,代碼行數:56,代碼來源:lobby_test.go

示例6: LobbyCreate

func LobbyCreate(so socketio.Socket) func(string) string {
	return chelpers.FilterRequest(so, lobbyCreateFilters,
		func(params map[string]interface{}) string {

			player, _ := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))

			mapName := params["mapName"].(string)
			lobbytypestring := params["type"].(string)
			league := params["league"].(string)
			server := params["server"].(string)
			rconPwd := params["rconpwd"].(string)
			whitelist := int(params["whitelist"].(uint))
			mumble := params["mumbleRequired"].(bool)

			var playermap = map[string]models.LobbyType{
				"debug":      models.LobbyTypeDebug,
				"sixes":      models.LobbyTypeSixes,
				"highlander": models.LobbyTypeHighlander,
			}

			lobbytype, _ := playermap[lobbytypestring]

			randBytes := make([]byte, 6)
			rand.Read(randBytes)
			serverPwd := base64.URLEncoding.EncodeToString(randBytes)

			//TODO what if playermap[lobbytype] is nil?
			info := models.ServerRecord{
				Host:           server,
				RconPassword:   rconPwd,
				ServerPassword: serverPwd}
			err := models.VerifyInfo(info)
			if err != nil {
				return err.Error()
			}

			lob := models.NewLobby(mapName, lobbytype, league, info, whitelist, mumble)
			lob.CreatedBySteamID = player.SteamId
			lob.Save()
			err = lob.SetupServer()

			if err != nil {
				bytes, _ := err.(*helpers.TPError).ErrorJSON().Encode()
				return string(bytes)
			}

			lob.State = models.LobbyStateWaiting
			lob.Save()
			lobby_id := simplejson.New()
			lobby_id.Set("id", lob.ID)
			bytes, _ := chelpers.BuildSuccessJSON(lobby_id).Encode()
			return string(bytes)
		})
}
開發者ID:mcapu,項目名稱:Helen,代碼行數:54,代碼來源:lobbyHandlers.go

示例7: TestLobbyCreation

func TestLobbyCreation(t *testing.T) {
	migrations.TestCleanup()
	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, models.ServerRecord{0, "testip", ""}, 0)
	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)
	//testing password creation
	assert.Equal(t, len(lobby.Server.ServerPassword), 8)
	lobby3 := models.NewLobby("cp_process_final", models.LobbyTypeSixes, models.ServerRecord{0, "testip", ""}, 0)
	lobby3.Save()
	assert.NotEqual(t, lobby.Server.ServerPassword, lobby3.Server.ServerPassword)

	lobby.MapName = "cp_granary"
	lobby.Save()

	db.DB.First(lobby2)
	assert.Equal(t, "cp_granary", lobby2.MapName)
}
開發者ID:UnnoTed,項目名稱:Helen,代碼行數:22,代碼來源:lobby_test.go

示例8: TestUnreadyPlayer

func TestUnreadyPlayer(t *testing.T) {
	migrations.TestCleanup()
	player, playErr := models.NewPlayer("testing")
	assert.Nil(t, playErr)

	player.Save()
	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, models.ServerRecord{0, "", ""}, 0)
	lobby.Save()
	lobby.AddPlayer(player, 0)

	lobby.ReadyPlayer(player)
	lobby.UnreadyPlayer(player)
	ready, err := lobby.IsPlayerReady(player)
	assert.Equal(t, ready, false)
	assert.Nil(t, err)
}
開發者ID:UnnoTed,項目名稱:Helen,代碼行數:16,代碼來源:lobby_test.go

示例9: 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)
}
開發者ID:N1xx1,項目名稱:Helen,代碼行數:17,代碼來源:lobby_test.go

示例10: TestUnreadyAllPlayers

func TestUnreadyAllPlayers(t *testing.T) {
	testhelpers.CleanupDB()

	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, "", models.ServerRecord{0, "", "", ""}, 0, false)
	lobby.Save()

	for i := 0; i < 12; i++ {
		player, playErr := models.NewPlayer(strconv.Itoa(i))
		assert.Nil(t, playErr)
		player.Save()
		lobby.AddPlayer(player, i)
		lobby.ReadyPlayer(player)
	}

	err := lobby.UnreadyAllPlayers()
	assert.Nil(t, err)
	ready := lobby.IsEveryoneReady()
	assert.Equal(t, ready, false)
}
開發者ID:N1xx1,項目名稱:Helen,代碼行數:19,代碼來源:lobby_test.go

示例11: TestIsSpectating

func TestIsSpectating(t *testing.T) {
	migrations.TestCleanup()

	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, models.ServerRecord{}, 1)
	database.DB.Save(lobby)
	player, _ := models.NewPlayer("asdf")
	database.DB.Save(player)

	isSpectating := player.IsSpectatingId(lobby.ID)
	assert.False(t, isSpectating)

	lobby.AddSpectator(player)

	isSpectating = player.IsSpectatingId(lobby.ID)
	assert.True(t, isSpectating)

	lobby.RemoveSpectator(player)
	isSpectating = player.IsSpectatingId(lobby.ID)
	assert.False(t, isSpectating)
}
開發者ID:UnnoTed,項目名稱:Helen,代碼行數:20,代碼來源:player_test.go

示例12: TestRemoveUnreadyPlayers

func TestRemoveUnreadyPlayers(t *testing.T) {
	testhelpers.CleanupDB()
	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, "", models.ServerRecord{0, "", "", ""}, 0, false)
	lobby.Save()

	for i := 0; i < 12; i++ {
		player, playErr := models.NewPlayer(strconv.Itoa(i))
		assert.Nil(t, playErr)
		player.Save()
		lobby.AddPlayer(player, i)
	}

	err := lobby.RemoveUnreadyPlayers()
	assert.Nil(t, err)

	for i := 0; i < 12; i++ {
		_, err := lobby.GetPlayerIdBySlot(i)
		assert.NotNil(t, err)
	}
}
開發者ID:N1xx1,項目名稱:Helen,代碼行數:20,代碼來源:lobby_test.go

示例13: TestReadyPlayer

func TestReadyPlayer(t *testing.T) {
	testhelpers.CleanupDB()
	player, playErr := models.NewPlayer("testing")
	assert.Nil(t, playErr)

	player.Save()
	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, "", models.ServerRecord{0, "", "", ""}, 0, false)
	lobby.Save()
	lobby.AddPlayer(player, 0)

	lobby.ReadyPlayer(player)
	ready, err := lobby.IsPlayerReady(player)
	assert.Equal(t, ready, true)
	assert.Nil(t, err)

	lobby.UnreadyPlayer(player)
	lobby.ReadyPlayer(player)
	ready, err = lobby.IsPlayerReady(player)
	assert.Equal(t, ready, true)
	assert.Nil(t, err)
}
開發者ID:N1xx1,項目名稱:Helen,代碼行數:21,代碼來源:lobby_test.go

示例14: TestIsEveryoneReady

func TestIsEveryoneReady(t *testing.T) {
	migrations.TestCleanup()
	player, playErr := models.NewPlayer("0")
	assert.Nil(t, playErr)

	player.Save()
	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, models.ServerRecord{0, "", ""}, 0)
	lobby.Save()
	lobby.AddPlayer(player, 0)
	lobby.ReadyPlayer(player)
	assert.Equal(t, lobby.IsEveryoneReady(), false)

	for i := 1; i < 12; i++ {
		player, playErr = models.NewPlayer(strconv.Itoa(i))
		assert.Nil(t, playErr)
		player.Save()
		lobby.AddPlayer(player, i)
		lobby.ReadyPlayer(player)
	}
	assert.Equal(t, lobby.IsEveryoneReady(), true)
}
開發者ID:UnnoTed,項目名稱:Helen,代碼行數:21,代碼來源:lobby_test.go

示例15: TestLobbyBan

func TestLobbyBan(t *testing.T) {
	migrations.TestCleanup()
	lobby := models.NewLobby("cp_badlands", models.LobbyTypeSixes, models.ServerRecord{0, "", ""}, 0)
	lobby.Save()

	player, playErr := models.NewPlayer("1235")
	assert.Nil(t, playErr)
	player.Save()

	// add player
	err := lobby.AddPlayer(player, 0)
	assert.Nil(t, err)

	// ban player
	err = lobby.RemovePlayer(player)
	lobby.BanPlayer(player)
	assert.Nil(t, err)

	// should not be able to add again
	err = lobby.AddPlayer(player, 5)
	assert.NotNil(t, err)
}
開發者ID:UnnoTed,項目名稱:Helen,代碼行數:22,代碼來源:lobby_test.go


注:本文中的github.com/TF2Stadium/Helen/models.NewLobby函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。