当前位置: 首页>>代码示例>>Golang>>正文


Golang models.GetPlayerBySteamId函数代码示例

本文整理汇总了Golang中github.com/TF2Stadium/Helen/models.GetPlayerBySteamId函数的典型用法代码示例。如果您正苦于以下问题:Golang GetPlayerBySteamId函数的具体用法?Golang GetPlayerBySteamId怎么用?Golang GetPlayerBySteamId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetPlayerBySteamId函数的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
}
开发者ID:demipixel,项目名称:Helen,代码行数:60,代码来源:lobby.go

示例2: 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)
		}

	}
}
开发者ID:demipixel,项目名称:Helen,代码行数:30,代码来源:socket.go

示例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)
}
开发者ID:demipixel,项目名称:Helen,代码行数:29,代码来源:lobby.go

示例4: PlayerSettingsSet

func (Player) PlayerSettingsSet(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"`
		Value string `json:"value"`
	}

	err := chelpers.GetParams(data, &args)
	if err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

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

	err = player.SetSetting(args.Key, args.Value)
	if err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	return chelpers.EmptySuccessJS
}
开发者ID:demipixel,项目名称:Helen,代码行数:25,代码来源:player.go

示例5: SocketInit

func SocketInit(server *wsevent.Server, noauth *wsevent.Server, so *wsevent.Client) error {
	chelpers.AuthenticateSocket(so.Id(), so.Request())
	loggedIn := chelpers.IsLoggedInSocket(so.Id())
	if loggedIn {
		steamid := chelpers.GetSteamId(so.Id())
		broadcaster.SetSocket(steamid, so)
	}

	if loggedIn {
		chelpers.AfterConnect(server, so)

		player, err := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
		if err != nil {
			helpers.Logger.Warning(
				"User has a cookie with but a matching player record doesn't exist: %s",
				chelpers.GetSteamId(so.Id()))
			chelpers.DeauthenticateSocket(so.Id())
			so.Close()
			return ErrRecordNotFound
		}

		chelpers.AfterConnectLoggedIn(server, so, player)
	} else {
		chelpers.AfterConnect(noauth, so)
		so.EmitJSON(helpers.NewRequest("playerSettings", "{}"))
		so.EmitJSON(helpers.NewRequest("playerProfile", "{}"))
	}

	so.EmitJSON(helpers.NewRequest("socketInitialized", "{}"))

	return nil
}
开发者ID:demipixel,项目名称:Helen,代码行数:32,代码来源:socket.go

示例6: 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)
		})

}
开发者ID:mcapu,项目名称:Helen,代码行数:34,代码来源:lobbyHandlers.go

示例7: PlayerSettingsGet

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
}
开发者ID:demipixel,项目名称:Helen,代码行数:34,代码来源:player.go

示例8: PlayerSettingsGet

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)
		})
}
开发者ID:N1xx1,项目名称:Helen,代码行数:27,代码来源:player.go

示例9: ChatSend

func (Chat) ChatSend(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
	reqerr := chelpers.FilterRequest(so, 0, true)

	if reqerr != nil {
		return reqerr.Encode()
	}
	var args struct {
		Message *string `json:"message"`
		Room    *int    `json:"room"`
	}

	err := chelpers.GetParams(data, &args)
	if err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	player, tperr := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
	if tperr != nil {
		return tperr.Encode()
	}

	//helpers.Logger.Debug("received chat message: %s %s", *args.Message, player.Name)

	if *args.Room > 0 {
		spec := player.IsSpectatingId(uint(*args.Room))
		//Check if player has either joined, or is spectating lobby
		lobbyId, tperr := player.GetLobbyId()

		if tperr != nil && !spec && lobbyId != uint(*args.Room) {
			return helpers.NewTPError("Player is not in the lobby.", 5).Encode()
		}
	} else {
		// else room is the lobby list room
		*args.Room, _ = strconv.Atoi(config.Constants.GlobalChatRoom)
	}
	if (*args.Message)[0] == '\n' {
		return helpers.NewTPError("Cannot send messages prefixed with newline", 4).Encode()
	}

	if len(*args.Message) > 120 {
		return helpers.NewTPError("Message too long", 4).Encode()
	}

	message := models.NewChatMessage(*args.Message, *args.Room, player)
	db.DB.Save(message)
	bytes, _ := json.Marshal(message)
	broadcaster.SendMessageToRoom(fmt.Sprintf("%s_public",
		chelpers.GetLobbyRoom(uint(*args.Room))),
		"chatReceive", string(bytes))

	if strings.HasPrefix(*args.Message, "!admin") {
		chelpers.SendToSlack(*args.Message, player.Name, player.SteamId)
	}

	return chelpers.EmptySuccessJS
}
开发者ID:demipixel,项目名称:Helen,代码行数:56,代码来源:chat.go

示例10: 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

示例11: 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

示例12: 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)
		})
}
开发者ID:mcapu,项目名称:Helen,代码行数:51,代码来源:lobbyHandlers.go

示例13: 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
}
开发者ID:demipixel,项目名称:Helen,代码行数:15,代码来源:lobby.go

示例14: ChatSend

func ChatSend(so socketio.Socket) func(string) string {
	return chelpers.FilterRequest(so, chatSendFilter,
		func(params map[string]interface{}) string {
			message := params["message"].(string)
			room := params["room"].(int)

			player, tperr := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
			if tperr != nil {
				bytes, _ := tperr.ErrorJSON().Encode()
				return string(bytes)
			}

			helpers.Logger.Debug("received chat message: %s %s", message, player.Name)

			spec := player.IsSpectatingId(uint(room))
			//Check if player has either joined, or is spectating lobby
			lobbyId, tperr := player.GetLobbyId()
			if room > 0 {
				if tperr != nil && !spec && lobbyId != uint(room) {
					bytes, _ := chelpers.BuildFailureJSON("Player is not in the lobby.", 5).Encode()
					return string(bytes)
				}
			} else {
				// else room is the lobby list room
				room, _ = strconv.Atoi(config.Constants.GlobalChatRoom)
			}

			chatMessage := simplejson.New()
			// TODO send proper timestamps
			chatMessage.Set("timestamp", time.Now().Unix())
			chatMessage.Set("message", message)
			chatMessage.Set("room", room)

			chatMessage.Set("player", models.DecoratePlayerSummaryJson(player))
			bytes, _ := chatMessage.Encode()
			broadcaster.SendMessageToRoom(fmt.Sprintf("%s_public",
				chelpers.GetLobbyRoom(uint(room))),
				"chatReceive", string(bytes))

			resp, _ := chelpers.BuildSuccessJSON(simplejson.New()).Encode()

			chelpers.LogChat(uint(room), player.Name, player.SteamId, message)

			chelpers.AddScrollbackMessage(uint(room), string(bytes))
			return string(resp)
		})
}
开发者ID:N1xx1,项目名称:Helen,代码行数:47,代码来源:chat.go

示例15: 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)
		})
}
开发者ID:N1xx1,项目名称:Helen,代码行数:47,代码来源:lobby.go


注:本文中的github.com/TF2Stadium/Helen/models.GetPlayerBySteamId函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。