package user import ( "github.com/Mindgamesnl/socketio" "github.com/ParadoxPixel/ThemePark-Websocket/data" "github.com/ParadoxPixel/ThemePark-Websocket/objects" "log" "sync" ) func serverLogin(so socketio.Socket) { id := so.GetQuery().Get("id") if !data.CanServer(id) { if debug { log.Println( "Server with id:", so.GetQuery().Get("id"), "already connected", ) } _ = so.Close() return } data.AddServer(&objects.Server{ ID: id, Sessions: make(map[string]socketio.Socket), Attraction: make(map[string]string), Socket: so, Mux: new(sync.RWMutex), }) if debug { log.Println( "Server with id:", so.GetQuery().Get("id"), "connected", ) } } func serverQuit(so socketio.Socket) { session := so.GetQuery().Get("id") obj := data.RemoveServer(session) if obj == nil { return } if debug { log.Println( "Server with id:", so.GetQuery().Get("id"), "disconnected", ) } // Disconnect users for _, user := range obj.Sessions { _ = user.Emit("close", "SERVER_ERROR") _ = user.Close() } }