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
Thomas van Weert 9edcb83fc4 CHG: refactor
CHG: use concurrent map instead of regular map with lock
DEL: global session control, moved to per server only
DEL: unused command system
2023-02-16 20:04:17 +01:00

41 lines
772 B
Go
Executable file

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)
}
}
})
namespace.OnDisconnect(func(so socketio.Socket) {
clientType := so.GetQuery().Get("type")
if clientType == "server" {
serverQuit(so)
} else if clientType == "client" {
clientQuit(so)
}
})
namespace.OnError(func(so socketio.Socket, err ...interface{}) {
fmt.Println(err)
})
}