public static SessionState GetNewSession(SessionTypes sessionType)
        {
            var maxOccupany = ConfigManager.GetValue <UInt32>("MaxOccupany", 100).Value;
            var maxUserID   = ConfigManager.GetValue <UInt32>("MaxUserID", 9999).Value;
            var userID      = (UInt32)0;
            var loops       = 0;

            if (sessionStates.Count >= maxOccupany)
            {
                return(null); // Server Full!
            }

            do
            {
                userID = ServerState.lastIssuedUserID = ((ServerState.lastIssuedUserID + 1) % maxUserID);

                if (userID == 0)
                {
                    loops++;
                }
                if (loops > 1)
                {
                    return(null);           // Server Full!
                }
            } while (userID == 0 || sessionStates.ContainsKey(userID));

            INetworkDriver driver = null;

            switch (sessionType)
            {
            case SessionTypes.TcpSocket:
                driver = new PalaceSocketDriver();

                break;
            //case SessionTypes.ProxySocket:
            //    driver = new ProxySocketDriver();

            //    break;
            case SessionTypes.WebSocket:
                driver = new WebSocketDriver();

                break;
            }

            lock (sessionStates)
            {
                sessionStates.TryAdd(userID, new SessionState
                {
                    UserID = userID,
                    driver = driver,
                });
            }

            return(sessionStates[userID]);
        }
        private void Cleanup()
        {
            Log.Debug(nameof(this.Cleanup));
            var ws = this.Ws;

            ws?.RemoveAllListeners();

            /* NO RUNNING IN BROWSER
             * utils.unloadDel(this.unloadRef);
             * this.unloadRef = this.ws = null;
             */
            this.Ws = null;
            this.RemoveAllListeners();
        }