本文整理匯總了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
}