本文整理匯總了Golang中github.com/TF2Stadium/wsevent.Client.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Close方法的具體用法?Golang Client.Close怎麽用?Golang Client.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/TF2Stadium/wsevent.Client
的用法示例。
在下文中一共展示了Client.Close方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: SocketHandler
func SocketHandler(w http.ResponseWriter, r *http.Request) {
//check if player is in the whitelist
if config.Constants.SteamIDWhitelist != "" {
allowed := false
session, err := chelpers.GetSessionHTTP(r)
if err == nil {
steamid, ok := session.Values["steam_id"]
allowed = ok && chelpers.IsSteamIDWhitelisted(steamid.(string))
}
if !allowed {
http.Error(w, "Sorry, but you're not in the closed alpha", 403)
return
}
}
session, err := chelpers.GetSessionHTTP(r)
var so *wsevent.Client
if err == nil {
_, ok := session.Values["steam_id"]
if ok {
so, err = socket.AuthServer.NewClient(upgrader, w, r)
} else {
so, err = socket.UnauthServer.NewClient(upgrader, w, r)
}
pprof.Clients.Add(1)
} else {
var estr = "Couldn't create WebSocket connection."
//estr = err.Error()
logrus.Error(err.Error())
http.Error(w, estr, 500)
return
}
if err != nil || so == nil {
login.LogoutSession(w, r)
return
}
//logrus.Debug("Connected to Socket")
err = SocketInit(so)
if err != nil {
login.LogoutSession(w, r)
so.Close()
}
}
示例3: SocketHandler
func SocketHandler(w http.ResponseWriter, r *http.Request) {
token, err := chelpers.GetToken(r)
if err != nil && err != http.ErrNoCookie { //invalid jwt token
logrus.Errorf("Error reading JWT: %v", err)
token = nil
}
//check if player is in the whitelist
if config.Constants.SteamIDWhitelist != "" {
if token == nil {
// player isn't logged in,
// and access is restricted to logged in people
http.Error(w, "Not logged in", http.StatusForbidden)
return
}
if !chelpers.IsSteamIDWhitelisted(token.Claims.(*chelpers.TF2StadiumClaims).SteamID) {
http.Error(w, "you're not in the beta", http.StatusForbidden)
return
}
}
var so *wsevent.Client
if token != nil { //received valid jwt
so, err = socket.AuthServer.NewClient(upgrader, w, r)
} else {
so, err = socket.UnauthServer.NewClient(upgrader, w, r)
}
if err != nil {
return
}
so.Token = token
//logrus.Debug("Connected to Socket")
err = SocketInit(so)
if err != nil {
logrus.Error(err)
so.Close()
return
}
}