本文整理汇总了Golang中github.com/TF2Stadium/Helen/controllers/controllerhelpers.GetSteamId函数的典型用法代码示例。如果您正苦于以下问题:Golang GetSteamId函数的具体用法?Golang GetSteamId怎么用?Golang GetSteamId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetSteamId函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SocketInit
//SocketInit initializes the websocket connection for the provided socket
func SocketInit(so *wsevent.Client) error {
chelpers.AuthenticateSocket(so.ID, so.Request)
loggedIn := chelpers.IsLoggedInSocket(so.ID)
if loggedIn {
steamid := chelpers.GetSteamId(so.ID)
sessions.AddSocket(steamid, so)
}
if loggedIn {
hooks.AfterConnect(socket.AuthServer, so)
player, err := models.GetPlayerBySteamID(chelpers.GetSteamId(so.ID))
if err != nil {
logrus.Warning(
"User has a cookie with but a matching player record doesn't exist: %s",
chelpers.GetSteamId(so.ID))
chelpers.DeauthenticateSocket(so.ID)
hooks.AfterConnect(socket.UnauthServer, so)
return ErrRecordNotFound
}
hooks.AfterConnectLoggedIn(so, player)
} else {
hooks.AfterConnect(socket.UnauthServer, so)
so.EmitJSON(helpers.NewRequest("playerSettings", "{}"))
so.EmitJSON(helpers.NewRequest("playerProfile", "{}"))
}
so.EmitJSON(helpers.NewRequest("socketInitialized", "{}"))
return nil
}
示例2: 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
}
示例3: 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)
})
}
示例4: PlayerSettingsSet
func (Player) PlayerSettingsSet(so *wsevent.Client, args struct {
Key *string `json:"key"`
Value *string `json:"value"`
}) interface{} {
player, _ := models.GetPlayerBySteamID(chelpers.GetSteamId(so.ID))
err := player.SetSetting(*args.Key, *args.Value)
if err != nil {
return helpers.NewTPErrorFromError(err)
}
switch *args.Key {
case "siteAlias":
profile := models.DecoratePlayerProfileJson(player)
so.EmitJSON(helpers.NewRequest("playerProfile", profile))
if lobbyID, _ := player.GetLobbyID(true); lobbyID != 0 {
lobby, _ := models.GetLobbyByID(lobbyID)
lobbyData := lobby.LobbyData(true)
lobbyData.Send()
}
case "mumbleNick":
if !reMumbleNick.MatchString(*args.Value) {
return helpers.NewTPError("Invalid Mumble nick.", -1)
}
}
return chelpers.EmptySuccessJS
}
示例5: 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
}
示例6: PlayerProfile
func (Player) PlayerProfile(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, 0, true)
if reqerr != nil {
return reqerr.Encode()
}
var args struct {
Steamid string `json:"steamid"`
}
err := chelpers.GetParams(data, &args)
if err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
steamid := args.Steamid
if steamid == "" {
steamid = chelpers.GetSteamId(so.Id())
}
player, playErr := models.GetPlayerWithStats(steamid)
if playErr != nil {
return playErr.Encode()
}
result := models.DecoratePlayerProfileJson(player)
resp, _ := chelpers.BuildSuccessJSON(result).Encode()
return resp
}
示例7: PlayerNotReady
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
}
示例8: 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
}
示例9: LobbyLeave
func (Lobby) LobbyLeave(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()
}
steamId := chelpers.GetSteamId(so.Id())
lob, player, tperr := removePlayerFromLobby(*args.Id, steamId)
if tperr != nil {
return tperr.Encode()
}
chelpers.AfterLobbyLeave(server, so, lob, player)
return chelpers.EmptySuccessJS
}
示例10: 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)
})
}
示例11: 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)
}
}
}
示例12: LobbyBan
func (Lobby) LobbyBan(so *wsevent.Client, args struct {
Id *uint `json:"id"`
Steamid *string `json:"steamid"`
}) interface{} {
steamId := *args.Steamid
selfSteamId := chelpers.GetSteamId(so.ID)
if steamId == selfSteamId {
return helpers.NewTPError("Player can't kick himself.", -1)
}
if ok, tperr := playerCanKick(*args.Id, selfSteamId); !ok {
return tperr
}
lob, player, tperr := removePlayerFromLobby(*args.Id, steamId)
if tperr != nil {
return tperr
}
lob.BanPlayer(player)
hooks.AfterLobbyLeave(lob, player)
// broadcaster.SendMessage(steamId, "sendNotification",
// fmt.Sprintf(`{"notification": "You have been removed from Lobby #%d"}`, *args.Id))
return chelpers.EmptySuccessJS
}
示例13: 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
}
示例14: 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
}
示例15: OnDisconnect
//OnDisconnect is connected when a player with a given socketID disconnects
func OnDisconnect(socketID string) {
pprof.Clients.Add(-1)
defer chelpers.DeauthenticateSocket(socketID)
if chelpers.IsLoggedInSocket(socketID) {
steamid := chelpers.GetSteamId(socketID)
sessions.RemoveSocket(socketID, steamid)
player, tperr := models.GetPlayerBySteamID(steamid)
if tperr != nil || player == nil {
logrus.Error(tperr.Error())
return
}
ids, tperr := player.GetSpectatingIds()
if tperr != nil {
logrus.Error(tperr.Error())
return
}
for _, id := range ids {
//if this _specific_ socket is spectating this lobby, remove them from it
//player might be spectating other lobbies in another tab, but we don't care
if sessions.IsSpectating(socketID, id) {
lobby, _ := models.GetLobbyByID(id)
err := lobby.RemoveSpectator(player, true)
if err != nil {
logrus.Error(err.Error())
continue
}
sessions.RemoveSpectator(socketID)
//logrus.Debug("removing %s from %d", player.SteamId, id)
}
}
id, _ := player.GetLobbyID(true)
//if player is in a waiting lobby, and hasn't connected for > 30 seconds,
//remove him from it. Here, connected = player isn't connected from any tab/window
if id != 0 && sessions.ConnectedSockets(player.SteamID) == 0 {
time.AfterFunc(time.Second*30, func() {
if !sessions.IsConnected(player.SteamID) {
//player may have changed lobbies during this time
//fetch lobby ID again
id, err := player.GetLobbyID(true)
if err != nil {
return
}
lobby := &models.Lobby{}
db.DB.First(lobby, id)
lobby.RemovePlayer(player)
}
})
}
}
}