3
0
Fork 0
This repository has been archived on 2024-11-14. You can view files and clone it, but cannot push or open issues or pull requests.
ThemeParkPlus-Socket/handlers/user/handler.go

42 lines
772 B
Go
Raw Permalink Normal View History

2022-08-12 19:08:47 +00:00
package user
import (
"fmt"
"github.com/Mindgamesnl/socketio"
"log"
)
var debug bool
func Load(namespace socketio.Namespace, b bool) {
debug = b
namespace.OnConnect(func(so socketio.Socket) {
clientType := so.GetQuery().Get("type")
if clientType == "server" {
serverLogin(so)
return
} else if clientType == "client" {
clientLogin(so)
return
} else {
_ = so.Close()
if debug {
log.Println("invalid client type:", clientType)
}
2022-08-12 19:08:47 +00:00
}
})
namespace.OnDisconnect(func(so socketio.Socket) {
clientType := so.GetQuery().Get("type")
if clientType == "server" {
serverQuit(so)
2022-08-12 19:08:47 +00:00
} else if clientType == "client" {
clientQuit(so)
2022-08-12 19:08:47 +00:00
}
})
namespace.OnError(func(so socketio.Socket, err ...interface{}) {
fmt.Println(err)
})
}