[NodeJS] Silkroad Security API + clientless example

03/29/2020 17:33 gigola123#1
Hello everyone,

Just releasing my Silkroad Security API wrapper for node.js, it's not something big but you can do whatever you want with it, first of all I was rewritting all SilkroadSecurityAPI with javascript but it wasn't stable so I prefered to use the current API written in C++, biggest credits goes to Drew and WeeMan.

With this lib you can do whatever you want, I did a proxy but have to test all the performance, also a real clientless, moving share ect.. from a website. It can make your creation more extensible.

The main purpose of this system is to run the lib from an other operating system than Windows, then you can make your own proxy on a linux server which will handle all the network traffic.

You can read the readme.md or follow those step:
  • Install node.js with npm (node >= 12)
  • run: npm install silkroad-security --ignore-scripts

Then you can do whatever you want, "--ignore-scripts" in installation will skip the build stuff, if you want to use the compiled file directly.

Here an example of clientless which work:

Code:
const { SilkroadSecurityJS, stream } = require('silkroad-security'),
    net = require('net');

let silkroad = {
        ip: '127.0.0.1',
        port: 15779,
        version: 201,
        local: 22
    },
    security = new SilkroadSecurityJS(),
    client = new net.Socket()
    

client.connect({
    host: silkroad.ip,
    port: silkroad.port,
    onread: {
        buffer: Buffer.alloc(8 * 1024)
    }
});

client.on('data', (data) => {
    security.Recv(data)
});

setInterval(() => {

    let packToSend = security.GetPacketToSend()

    for (let y = 0; y < packToSend.length; y++) {
        let data = Buffer.from(packToSend[y])
        client.write(data)
    }

    let packetToRecv = security.GetPacketToRecv()

    for (let i = 0; i < packetToRecv.length; i++) {
        HandlePacketGateway(security, packetToRecv[i])
    }


}, 1)

client.on('close', () => {
	console.log('Connection closed');
});

function HandlePacketGateway(security, packet) {

    let reader = new stream.reader(packet['data'])

    console.log((packet['opcode']).toString(16))

    if (packet['opcode'] == 0x2001) {

        let server = reader.string()

		if (server == 'GatewayServer') {

            let rep = new stream.writer();
            rep.uint8(silkroad.local);
            rep.string("SR_Client");
            rep.uint32(silkroad.version);
            
            security.Send(0x6100, rep, true, false)

        } 
            
    } else if (packet['opcode'] == 0xA100) {

        security.Send(0x6101, [], true, false)

    } else if (packet['opcode'] == 0xA101) {

        while (reader.uint8() == 1) {
            reader.uint8();
            reader.string('ascii');
        }

        var servers = []

        while (reader.uint8() == 1) {
            
            var server = {
                serverID: reader.uint16(),
                Name: reader.string('ascii'),
                ratio : reader.float(),
                status: reader.uint8()
            };

            server.players = Math.round(server.ratio * 3500.0);
            servers.push(server);
        }

        console.log('--- Servers ---')
        console.log(servers);

    }

}
With a bit more code, you can make it login into game world, move ect..

I also tested it for make proxy between modules, it worked well, if you want to change the identity, there is 2 way:

Code:
let ssjs = new SilkroadSecurityJS("SR_Client", 0)
Or
Code:
let ssjs = new SilkroadSecurityJS()
ssjs.ChangeIdentity("SR_Client", 0)
By default it'll use the SR_Client identity

Here the npm link -> [Only registered and activated users can see links. Click Here To Register...]
03/30/2020 01:34 JellyBitz#2
Quote:
Originally Posted by gigola123 View Post
... I did a proxy but have to test all the performance ...
What about connection stability?
It is like connecting a socket and keep it alive as much as I want?
Probabilities to be constantly disconnected?
What do you think about the most servers using HWID which means client it's required?
03/30/2020 03:04 gigola123#3
Quote:
Originally Posted by JellyBitz View Post
What about connection stability?
Well, actually for our customers (out of Silkroad), we built a node.js socket.io app with 2000 concurrent user with "cluster mode" in 8 process ([Only registered and activated users can see links. Click Here To Register...]) and it works without any problem, sometimes we've some disconnect because of the user's connection but it's not really a big impact.

Quote:
Originally Posted by JellyBitz View Post
It is like connecting a socket and keep it alive as much as I want?
Probabilities to be constantly disconnected?
But yes, you can keep it alive as much as you want but I never really worked with TCP and node.js together to be honest, only on some little scale project, this is why I want to test it in a larger scale. I ran 10 clients a whole day with a little proxy, tried much exploit like the "A003 ddos", everything worked well, never crash and no process overload, everything run fine and I was on a single thread.

Quote:
Originally Posted by JellyBitz View Post
What do you think about the most servers using HWID which means client it's required?
I guess you speak about the clientless, if you can parse the packet which the HWID send then send the good one it's good I think, probably some HWID will add the current time, at this point you'll have to "uncrypt" their logic and recreat it on the clientless.

By the way, I've seen what you did with your xSroMap, it's really nice good idea to use Leaflet.
Your project xSroMap is the best think to allie with this library.
Have a clientless server which send socket.io data to your xSroMap then everything is in real time, it's an interesting project !
04/01/2020 04:24 qoaway#4
well its good effort and good work mate but imo I'd prefer running .net or c++ app in background with json rpc instead of running nodejs for silkroad connection. I don't see the any pros of using nodejs here

btw xSroMap is really good project, we have already implemetend such feature on our server check [Only registered and activated users can see links. Click Here To Register...]
04/25/2020 20:06 Otakanikaru#5
Looks like saved me some time, thanks a lot.
05/01/2020 13:10 ArmOReTotTL#6
Thank you mate :)