本文整理匯總了Golang中github.com/TF2Stadium/wsevent.Server.On方法的典型用法代碼示例。如果您正苦於以下問題:Golang Server.On方法的具體用法?Golang Server.On怎麽用?Golang Server.On使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/TF2Stadium/wsevent.Server
的用法示例。
在下文中一共展示了Server.On方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ServerInit
func ServerInit(server *wsevent.Server, noAuthServer *wsevent.Server) {
server.OnDisconnect = onDisconnect
server.Extractor = getEvent
noAuthServer.OnDisconnect = onDisconnect
noAuthServer.Extractor = getEvent
server.On("authenticationTest", func(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
reqerr := chelpers.FilterRequest(so, 0, true)
if reqerr != nil {
bytes, _ := json.Marshal(reqerr)
return bytes
}
bytes, _ := json.Marshal(struct {
Message string `json:"message"`
}{"authenticated"})
return bytes
})
//Global Handlers
server.Register(handler.Global{})
//Lobby Handlers
server.Register(handler.Lobby{})
//server.On("lobbyCreate", handler.LobbyCreate)
//Player Handlers
server.Register(handler.Player{})
//Chat Handlers
server.Register(handler.Chat{})
//Admin Handlers
server.Register(handler.Admin{})
//Debugging handlers
// if config.Constants.ServerMockUp {
// server.On("debugLobbyFill", handler.DebugLobbyFill)
// server.On("debugLobbyReady", handler.DebugLobbyReady)
// server.On("debugUpdateStatsFilter", handler.DebugUpdateStatsFilter)
// server.On("debugPlayerSub", handler.DebugPlayerSub)
// }
noAuthServer.On("lobbySpectatorJoin", func(s *wsevent.Server, so *wsevent.Client, data []byte) []byte {
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()
}
chelpers.AfterLobbySpec(s, so, lob)
bytes, _ := json.Marshal(models.DecorateLobbyData(lob, true))
so.EmitJSON(helpers.NewRequest("lobbyData", string(bytes)))
return chelpers.EmptySuccessJS
})
noAuthServer.On("getSocketInfo", (handler.Global{}).GetSocketInfo)
noAuthServer.DefaultHandler = func(_ *wsevent.Server, so *wsevent.Client, data []byte) []byte {
return helpers.NewTPError("Player isn't logged in.", -4).Encode()
}
}