本文整理汇总了Golang中github.com/TF2Stadium/wsevent.Client.Request方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Request方法的具体用法?Golang Client.Request怎么用?Golang Client.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/TF2Stadium/wsevent.Client
的用法示例。
在下文中一共展示了Client.Request方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}