本文整理汇总了Golang中github.com/TF2Stadium/Helen/models.NewPlayer函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPlayer函数的具体用法?Golang NewPlayer怎么用?Golang NewPlayer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPlayer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: TestPlayerSettings
func TestPlayerSettings(t *testing.T) {
testhelpers.CleanupDB()
player, _ := models.NewPlayer("76561197999073985")
settings, err := player.GetSettings()
assert.Nil(t, err)
assert.Equal(t, 0, len(settings))
err = player.SetSetting("foo", "bar")
assert.Nil(t, err)
settings, err = player.GetSettings()
assert.Nil(t, err)
assert.Equal(t, "foo", settings[0].Key)
assert.Equal(t, "bar", settings[0].Value)
setting, err := player.GetSetting("foo")
assert.Nil(t, err)
assert.Equal(t, "bar", setting.Value)
err = player.SetSetting("hello", "world")
assert.Nil(t, err)
settings, err = player.GetSettings()
assert.Nil(t, err)
assert.Equal(t, 2, len(settings))
}
开发者ID:N1xx1,项目名称:Helen,代码行数:29,代码来源:player_test.go
示例3: 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)
})
}
开发者ID:N1xx1,项目名称:Helen,代码行数:27,代码来源:debug.go
示例4: setSession
func setSession(w http.ResponseWriter, r *http.Request, steamid string) {
session, _ := controllerhelpers.GetSessionHTTP(r)
session.Values["steam_id"] = steamid
player := &models.Player{}
err := database.DB.Where("steam_id = ?", steamid).First(player).Error
var playErr error
if err == gorm.RecordNotFound {
player, playErr = models.NewPlayer(steamid)
if playErr != nil {
helpers.Logger.Debug(playErr.Error())
}
database.DB.Create(player)
} else if err != nil {
helpers.Logger.Debug("steamLogin.go:60 ", err)
}
session.Values["id"] = fmt.Sprint(player.ID)
session.Values["role"] = player.Role
session.Options.Domain = config.Constants.CookieDomain
err = session.Save(r, w)
}
开发者ID:mcapu,项目名称:Helen,代码行数:26,代码来源:steamLogin.go
示例5: 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
示例6: 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
示例7: TestPlayerInfoFetching
func TestPlayerInfoFetching(t *testing.T) {
testhelpers.CleanupDB()
if config.Constants.SteamDevApiKey == "your steam dev api key" {
return
}
// disable mock mode because we're actually testing it
config.Constants.SteamApiMockUp = false
player, playErr := models.NewPlayer("76561197999073985")
assert.Nil(t, playErr)
assert.Equal(t, "http://steamcommunity.com/id/nonagono/", player.Profileurl)
assert.Regexp(t, "(.*)steamcommunity/public/images/avatars/(.*).jpg", player.Avatar)
assert.True(t, player.GameHours >= 3000)
player.Stats.PlayedCountSet(models.LobbyTypeSixes, 3)
player.Stats.PlayedCountSet(models.LobbyTypeHighlander, 7)
player.Stats.PlayedCountIncrease(models.LobbyTypeSixes) // sixes: 3 -> 4
assert.Equal(t, 4, player.Stats.PlayedCountGet(models.LobbyTypeSixes))
assert.Equal(t, 7, player.Stats.PlayedCountGet(models.LobbyTypeHighlander))
database.DB.Save(player)
player2, err := models.GetPlayerWithStats(player.SteamId)
assert.Nil(t, err)
assert.Equal(t, 4, player2.Stats.PlayedCountGet(models.LobbyTypeSixes))
assert.Equal(t, 7, player2.Stats.PlayedCountGet(models.LobbyTypeHighlander))
assert.Equal(t, "http://steamcommunity.com/id/nonagono/", player2.Profileurl)
}
开发者ID:N1xx1,项目名称:Helen,代码行数:34,代码来源:player_test.go
示例8: 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
示例9: CreatePlayer
func CreatePlayer() *models.Player {
bytes := make([]byte, 10)
rand.Read(bytes)
steamID := base64.URLEncoding.EncodeToString(bytes)
player, _ := models.NewPlayer(steamID)
player.Save()
return player
}
开发者ID:gpittarelli,项目名称:Helen,代码行数:9,代码来源:modelhelpers.go
示例10: 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
示例11: 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
示例12: TestPlayerBanning
func TestPlayerBanning(t *testing.T) {
testhelpers.CleanupDB()
player, _ := models.NewPlayer("76561197999073985")
player.Save()
assert.False(t, player.IsBanned(models.PlayerBanJoin))
assert.False(t, player.IsBanned(models.PlayerBanCreate))
assert.False(t, player.IsBanned(models.PlayerBanChat))
assert.False(t, player.IsBanned(models.PlayerBanFull))
past := time.Now().Add(time.Second * -10)
player.BanUntil(past, models.PlayerBanJoin, "they suck")
assert.False(t, player.IsBanned(models.PlayerBanJoin))
future := time.Now().Add(time.Second * 10)
player.BanUntil(future, models.PlayerBanJoin, "they suck")
player.BanUntil(future, models.PlayerBanFull, "they suck")
player2, _ := models.GetPlayerBySteamId(player.SteamId)
assert.False(t, player2.IsBanned(models.PlayerBanCreate))
assert.False(t, player2.IsBanned(models.PlayerBanChat))
isBannedFull, untilFull := player2.IsBannedWithTime(models.PlayerBanFull)
assert.True(t, isBannedFull)
assert.True(t, future.Sub(untilFull) < time.Second)
assert.True(t, untilFull.Sub(future) < time.Second)
log.Println(future.Sub(untilFull))
isBannedJoin, untilJoin := player2.IsBannedWithTime(models.PlayerBanJoin)
assert.True(t, isBannedJoin)
assert.True(t, future.Sub(untilJoin) < time.Second)
assert.True(t, untilJoin.Sub(future) < time.Second)
future2 := time.Now().Add(time.Second * 20)
player2.BanUntil(future2, models.PlayerBanJoin, "they suck")
isBannedJoin2, untilJoin2 := player2.IsBannedWithTime(models.PlayerBanJoin)
assert.True(t, isBannedJoin2)
assert.True(t, future2.Sub(untilJoin2) < time.Second)
assert.True(t, untilJoin.Sub(future2) < time.Second)
bans, err := player2.GetActiveBans()
assert.Nil(t, err)
assert.Equal(t, 3, len(bans))
player2.Unban(models.PlayerBanJoin)
player2.Unban(models.PlayerBanFull)
assert.False(t, player2.IsBanned(models.PlayerBanJoin))
assert.False(t, player2.IsBanned(models.PlayerBanCreate))
assert.False(t, player2.IsBanned(models.PlayerBanChat))
assert.False(t, player2.IsBanned(models.PlayerBanFull))
}
开发者ID:N1xx1,项目名称:Helen,代码行数:51,代码来源:player_test.go
示例13: 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
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: 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
示例19: setSession
func setSession(w http.ResponseWriter, r *http.Request, steamid string) error {
session, _ := controllerhelpers.GetSessionHTTP(r)
session.Values["steam_id"] = steamid
player := &models.Player{}
err := database.DB.Where("steam_id = ?", steamid).First(player).Error
var playErr error
if err == gorm.RecordNotFound {
// Successful first-time login
player, playErr = models.NewPlayer(steamid)
if playErr != nil {
return playErr
}
database.DB.Create(player)
} else if err == nil {
// Successful repeat login
err = player.UpdatePlayerInfo()
if err == nil {
player.Save()
} else {
return err
}
} else if err != nil {
// Failed login
return err
}
session.Values["id"] = fmt.Sprint(player.ID)
session.Values["role"] = player.Role
session.Options.Domain = config.Constants.CookieDomain
err = session.Save(r, w)
return err
}
开发者ID:demipixel,项目名称:Helen,代码行数:37,代码来源:steamLogin.go
示例20: LoginCallbackHandler
func LoginCallbackHandler(w http.ResponseWriter, r *http.Request) {
fullURL := config.Constants.Domain + r.URL.String()
id, err := openid.Verify(fullURL, discoveryCache, nonceStore)
if err != nil {
helpers.Logger.Debug(err.Error())
return
}
parts := strings.Split(id, "/")
steamid := parts[len(parts)-1]
session, _ := controllerhelpers.GetSessionHTTP(r)
session.Values["steam_id"] = steamid
player := &models.Player{}
var playErr error
err = database.DB.Where("steam_id = ?", steamid).First(player).Error
if err == gorm.RecordNotFound {
player, playErr = models.NewPlayer(steamid)
if playErr != nil {
helpers.Logger.Debug(playErr.Error())
}
database.DB.Create(player)
} else if err != nil {
helpers.Logger.Debug("steamLogin.go:60 ", err)
}
session.Values["id"] = fmt.Sprint(player.ID)
err = session.Save(r, w)
http.Redirect(w, r, config.Constants.LoginRedirectPath, 303)
}
开发者ID:UnnoTed,项目名称:Helen,代码行数:36,代码来源:steamLogin.go
注:本文中的github.com/TF2Stadium/Helen/models.NewPlayer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论