Barbosik / MultiOgar

An open source Ogar server implementation, written with Node.js.
Other
61 stars 44 forks source link

Support for the uws module #158

Open henopied opened 8 years ago

henopied commented 8 years ago

I would like to see uws support as it could allow many more clients to connect to multiogar while using less system resources.

makandz commented 8 years ago

"µWS is one of the most lightweight, efficient & scalable WebSocket server implementations available." - I'm interested :+1:

BaumanDev commented 8 years ago

I've tried. Had problems with a compiler or something. Gave up.

henopied commented 8 years ago

The issue is with the sendpacket function.

BaumanDev commented 8 years ago

I don't see what can be causing it. :/

Influxx commented 8 years ago

I also tried implementing uws but couldn't get past the sendPacket issue. Maybe @Barbosik can help out or give us a clue?

David1ali12 commented 8 years ago

uws so much faster

henopied commented 8 years ago

I have found the issue and that is the uws client is not exposed so we cannot add things to its prototype. https://github.com/uWebSockets/uWebSockets/issues/184 edit: I will make a pr once this is resolved

xinyuweb commented 8 years ago

del "WebSocket.prototype.sendPacket"

add ws.sendPacket to function "close"

function close(error) {
        this.server.ips[this.socket.remoteAddress] -= 1;
        // Log disconnections
        this.server.log.onDisconnect(this.socket.remoteAddress);

        var client = this.socket.playerTracker;
        var len = this.socket.playerTracker.cells.length;
        for (var i = 0; i < len; i++) {
            var cell = this.socket.playerTracker.cells[i];

            if (!cell) {
                continue;
            }

            cell.calcMove = function () {
                return;
            }; // Clear function so that the cell cant move
            this.server.removeNode(cell);
        }
        client.disconnect = this.server.config.playerDisconnectTime * 20;
        this.socket.sendPacket = function () {
            return;
        }; // Clear function so no packets are sent

        if (client.disconnect == -20) {
            var index = this.server.clients.indexOf(this.socket)
                if (index > -1) {
                    this.server.clients.splice(index, 1);
                }
        }
    }

    ws.sendPacket = function (packet) {
        function getBuf(data) {
            var array = new Uint8Array(data.buffer || data);
            var l = data.byteLength || data.length;
            var o = data.byteOffset || 0;
            var buffer = new Buffer(l);

            for (var i = 0; i < l; i++) {
                buffer[i] = array[o + i];
            }

            return buffer;
        }

        //if (this.readyState == WebSocket.OPEN && (this._socket.bufferSize == 0) && packet.build) {
        if (this.readyState == 1 && packet.build) {
            var buf = packet.build();
            this.send(getBuf(buf), {
                binary : true
            });
        } else if (!packet.build) {
            // Do nothing
        } else {
            this.readyState = WebSocket.CLOSED;
            this.emit('close');
            this.removeAllListeners();
        }
    }

    ws.remoteAddress = ws._socket.remoteAddress;
    ws.remotePort = ws._socket.remotePort;
    this.log.onConnect(ws.remoteAddress); // Log connections

    ws.playerTracker = new PlayerTracker(this, ws);
    ws.packetHandler = new PacketHandler(this, ws);
    ws.on('message', ws.packetHandler.handleMessage.bind(ws.packetHandler));
    var bindObject = {
        server : this,
        socket : ws
    };

    ws.on('error', close.bind(bindObject));
    ws.on('close', close.bind(bindObject));
    this.clients.push(ws);
}
BaumanDev commented 8 years ago

^^ That can get us uws?

henopied commented 8 years ago

The above code wouldn't really be ideal.

ghost commented 8 years ago

Could you please try out 0.7.2? I think it should be fixed.

Influxx commented 8 years ago

Thanks @henopied and @alexhultman !

BaumanDev commented 8 years ago

Is there a tutorial for windows 10?

ghost commented 8 years ago

@NatsuTheGreat of uws? Nope it doesn't work on Windows currently. There are patches pending to be merged to nodejs which will allow it to work though.

BaumanDev commented 8 years ago

@alexhultman RIP. Going to have to stick with ws.

ghost commented 8 years ago

@NatsuTheGreat That's up to you. Next Node.js 6.x version will have the patches though.

BaumanDev commented 8 years ago

I am using v6.2.1

ghost commented 8 years ago

@NatsuTheGreat Right, I forgot. It actually already works on 6.3.0 but not with SSL. SSL will come with the next version after 6.3.0.

BaumanDev commented 8 years ago

I am not using SSL, I have an older modified version of MultiOgar. Should I just get 6.3.0?

henopied commented 8 years ago

Should I make a pull request that allows one to choose between uws and ws in the config?

David1ali12 commented 8 years ago

omg yes @henopied please I need uws

henopied commented 8 years ago

@ItzLevvie Oh whoops, silly me!

Barbosik commented 8 years ago

does it has any advantage against ws?

ghost commented 8 years ago

@Barbosik https://github.com/uWebSockets/uWebSockets#benchmarks-table---validate

BaumanDev commented 8 years ago
        throw new Error('Compilation of µWebSockets has failed and there is no pre-compiled binary ' +
        ^

Error: Compilation of µWebSockets has failed and there is no pre-compiled binary available for your system. Please install a supported C++11 compiler and reinstall the module 'uws'.
ghost commented 8 years ago

@NatsuTheGreat I assume you did not read the installation instructions?

BaumanDev commented 8 years ago

Setting it up on windows is confusing me..

chuushi commented 8 years ago

I thought Windows support was broken. You need knowledge of C++ or something to use on windows.

BaumanDev commented 8 years ago

It doesn't say that support for windows is broken anymore.

ghost commented 8 years ago

Yes it is very confusing to run:

npm install windows-build-tools npm install uws

especially when this is clearly written in English instructions on the front page under Installation.

BaumanDev commented 8 years ago

Lmao Alex, and what about those compilers you were talking about?

On Windows you need to search the web for pre-compiled binaries or simply compile the dependencies yourself.

Very explanatory. npm install windows-build-tools Doesn't make a difference as of now.

ghost commented 8 years ago

Installation -> Node.js is your section, not the "native developers" section...

Never mind, clearly I will have to bundle it with pre-built binaries for Windows...

BaumanDev commented 8 years ago

Well lets see, Alex:

npm install --save uws

First of what I see there, and then:

npm install windows-build-tools

I have installed

npm install uws

And

npm install windows-build-tools

Yet the error keeps talking about a C++ Compiler. :/

Barbosik commented 8 years ago

@alexhultman: does it provide any functionality to minimize impact of DDoS attacks? For example, does it support cloudflare proxy? (there is some issues with headers, so I cannot use ws with cloudflare)

ghost commented 8 years ago

@NatsuTheGreat You did reinstall uws after installing windows-build-tools?

BaumanDev commented 8 years ago

I went in order,

npm install uws npm install windows-build-tools

ghost commented 8 years ago

@NatsuTheGreat That statement does not answer my question, besides - it is the opposite of what the installation instructions tells you to. You need to reinstall uws after installing windows-build-tools.

BaumanDev commented 8 years ago

Okay, sorry. I'll try it now.

BaumanDev commented 8 years ago

Same error. There are also problems with npm install windows-build-tools

ghost commented 8 years ago

You can write in my Gitter.

BaumanDev commented 8 years ago

Oh, I had to run that through Admin CMD Prompt. Python was installed. Waiting for more replies from console.

ghost commented 8 years ago

Write in Gitter, I guess you write npm install --global --production windows-build-tools

m-byte918 commented 8 years ago

@alexhultman vape naysh :+1: