本文整理汇总了Golang中github.com/TF2Stadium/wsevent.Client.Id方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Id方法的具体用法?Golang Client.Id怎么用?Golang Client.Id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/TF2Stadium/wsevent.Client
的用法示例。
在下文中一共展示了Client.Id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: 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
}
示例5: 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
}
示例6: GetSocketInfo
func (Global) GetSocketInfo(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
socketinfo := struct {
ID string `json:"id"`
Rooms []string `json:"rooms"`
}{so.Id(), server.RoomsJoined(so.Id())}
bytes, _ := json.Marshal(socketinfo)
return bytes
}
示例7: 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
}
示例8: FilterRequest
func FilterRequest(so *wsevent.Client, action authority.AuthAction, login bool) (err *helpers.TPError) {
if int(action) != 0 {
var role, _ = GetPlayerRole(so.Id())
can := role.Can(action)
if !can {
err = helpers.NewTPError("You are not authorized to perform this action.", 0)
}
}
return
}
示例9: AfterLobbyLeave
func AfterLobbyLeave(server *wsevent.Server, so *wsevent.Client, lobby *models.Lobby, player *models.Player) {
//pub := fmt.Sprintf("%s_public", GetLobbyRoom(lobby.ID))
// bytes, _ := json.Marshal(models.DecorateLobbyData(lobby, true))
// broadcaster.SendMessageToRoom(pub, "lobbyData", string(bytes))
bytes, _ := json.Marshal(models.DecorateLobbyLeave(lobby))
broadcaster.SendMessage(player.SteamId, "lobbyLeft", string(bytes))
server.RemoveClient(so.Id(), fmt.Sprintf("%s_private", GetLobbyRoom(lobby.ID)))
}
示例10: AdminChangeRole
func (Admin) AdminChangeRole(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"`
Role *string `json:"role"`
}
err := chelpers.GetParams(data, &args)
if err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
role, ok := helpers.RoleMap[*args.Role]
if !ok || role == helpers.RoleAdmin {
return helpers.NewTPError("Invalid role parameter", 0).Encode()
}
otherPlayer, err := models.GetPlayerBySteamId(*args.Steamid)
if err != nil {
return helpers.NewTPError("Player not found.", 0).Encode()
}
currPlayer, _ := chelpers.GetPlayerSocket(so.Id())
models.LogAdminAction(currPlayer.ID, helpers.ActionChangeRole, otherPlayer.ID)
// actual change happens
otherPlayer.Role = role
db.DB.Save(&otherPlayer)
// rewrite session data. THIS WON'T WRITE A COOKIE SO IT ONLY WORKS WITH
// STORES THAT STORE DATA IN COOKIES (AND NOT ONLY SESSION ID).
session, sesserr := chelpers.GetSessionHTTP(so.Request())
if sesserr == nil {
session.Values["role"] = role
session.Save(so.Request(), FakeResponseWriter{})
}
return chelpers.EmptySuccessJS
}
示例11: PlayerReady
func (Player) PlayerReady(_ *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, authority.AuthAction(0), true)
if reqerr != nil {
return reqerr.Encode()
}
steamid := chelpers.GetSteamId(so.Id())
player, tperr := models.GetPlayerBySteamId(steamid)
if tperr != nil {
return tperr.Encode()
}
lobbyid, tperr := player.GetLobbyId()
if tperr != nil {
return tperr.Encode()
}
lobby, tperr := models.GetLobbyByIdServer(lobbyid)
if tperr != nil {
return tperr.Encode()
}
if lobby.State != models.LobbyStateReadyingUp {
return helpers.NewTPError("Lobby hasn't been filled up yet.", 4).Encode()
}
tperr = lobby.ReadyPlayer(player)
if tperr != nil {
return tperr.Encode()
}
if lobby.IsEveryoneReady() {
db.DB.Table("lobbies").Where("id = ?", lobby.ID).Update("state", models.LobbyStateInProgress)
chelpers.BroadcastLobbyStart(lobby)
models.BroadcastLobbyList()
models.FumbleLobbyStarted(lobby)
}
return chelpers.EmptySuccessJS
}
示例12: 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
}
示例13: LobbyBan
func (Lobby) LobbyBan(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"`
Steamid *string `json:"steamid"`
}
if err := chelpers.GetParams(data, &args); err != nil {
return helpers.NewTPErrorFromError(err).Encode()
}
steamId := *args.Steamid
selfSteamId := chelpers.GetSteamId(so.Id())
if steamId == selfSteamId {
return helpers.NewTPError("Player can't kick himself.", -1).Encode()
}
if ok, tperr := playerCanKick(*args.Id, selfSteamId); !ok {
return tperr.Encode()
}
lob, player, tperr := removePlayerFromLobby(*args.Id, steamId)
if tperr != nil {
return tperr.Encode()
}
lob.BanPlayer(player)
so, _ = broadcaster.GetSocket(player.SteamId)
chelpers.AfterLobbyLeave(server, so, lob, player)
broadcaster.SendMessage(steamId, "sendNotification",
fmt.Sprintf(`{"notification": "You have been removed from Lobby #%d"}`, *args.Id))
return chelpers.EmptySuccessJS
}
示例14: LobbySpectatorLeave
func (Lobby) LobbySpectatorLeave(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())
player, tperr := models.GetPlayerBySteamId(steamId)
if tperr != nil {
return tperr.Encode()
}
lob, tperr := models.GetLobbyById(*args.Id)
if tperr != nil {
return tperr.Encode()
}
if !player.IsSpectatingId(lob.ID) {
if id, _ := player.GetLobbyId(); id == *args.Id {
chelpers.AfterLobbySpecLeave(server, so, lob)
return chelpers.EmptySuccessJS
}
return helpers.NewTPError("Player is not spectating", -1).Encode()
}
lob.RemoveSpectator(player, true)
chelpers.AfterLobbySpecLeave(server, so, lob)
return chelpers.EmptySuccessJS
}
示例15: LobbyClose
func (Lobby) LobbyClose(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, _ := models.GetPlayerBySteamId(chelpers.GetSteamId(so.Id()))
lob, tperr := models.GetLobbyByIdServer(uint(*args.Id))
if tperr != nil {
return tperr.Encode()
}
if player.SteamId != lob.CreatedBySteamID && player.Role != helpers.RoleAdmin {
return helpers.NewTPError("Player not authorized to close lobby.", -1).Encode()
}
if lob.State == models.LobbyStateEnded {
return helpers.NewTPError("Lobby already closed.", -1).Encode()
}
models.FumbleLobbyEnded(lob)
lob.Close(true)
models.BroadcastLobbyList() // has to be done manually for now
return chelpers.EmptySuccessJS
}