Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Another GunZ Emulator

Status
Not open for further replies.
Joined
Sep 10, 2007
Messages
970
Reaction score
815
This time in a fun language!

I've worked on this for..30 minutes?

output for lulz
Code:
C:\Users\Jacob\Documents\My Web Sites\Empty Site>node server.js
Connection from: 127.0.0.1
Got packet from client: 3e9

server.js
Code:
var net = require('net');
var client = require('./client');


clients = [];
index = 0;
net.createServer(function(socket) {
    socket.addListener("connect", function() {
        console.log("Connection from: " + socket.remoteAddress);
        clients.push(new client(socket, index++));
    });
}).listen(6000);

client.js
Code:
var sys = require('sys');
var net = require('net');
var packetreader = require('./packetreader');


module.exports = Client;


function Client(socket, index) {
    this.socket = socket;
    this.uid = index;
    this.onConnection();
    var instance = this;
    this.socket.addListener('data', function(data) {
          packetreader.decrypt(data, 2, 2, instance.key);
          var size = data.readUInt16LE(2);
          if (size <= data.length){
              var packet = new packetreader(data, instance.key);
              console.log("Got packet from client: " + packet.getCommandId().toString(16));
          }
    });
}


Client.prototype.onConnection = function() {
    this.key = new Buffer(32);
    var buffer = new Buffer(26);
    var iv = new Buffer([0x37, 0x04, 0x5D, 0x2E, 0x43, 0x3A,
                0x49, 0x53, 0x50, 0x05, 0x13, 0xC9,
                0x28, 0xA4, 0x4D, 0x05]);
    var xor = new Buffer([0x57, 0x02, 0x5B, 0x04, 0x34, 0x06, 0x01,
                0x08, 0x37, 0x0A, 0x12, 0x69, 0x41, 0x38,
                0x0F, 0x78]);


    // bulid the key
    var ipLong = this.intToNetworkLong(this.socket.remoteAddress);
    this.key.writeUInt32LE(ipLong, 0);
    this.key.writeUInt32LE(2, 4);
    this.key.writeUInt32LE(0, 8);
    this.key.writeUInt32LE(this.uid, 12);
    iv.copy(this.key, 16, 0, 16);


    // build the packet
    buffer.writeUInt16LE(10, 0);
    buffer.writeUInt32LE(26, 2);
    buffer.writeUInt32LE(0, 6);
    for(var i = 4; i < 12; i += 4)
        buffer.writeUInt32LE(this.key.readUInt32LE(i), 6 + i);
    buffer.writeUInt32LE(this.key.readUInt32LE(0), 22);


    for(i = 0; i < 4; ++i) {
        var a = xor.readUInt32LE(i * 4);
        var b = this.key.readUInt32LE(i * 4);
        this.key.writeUInt32LE(a ^ b, i * 4);
    }


    this.sendRawPacket(buffer);
}


Client.prototype.sendRawPacket = function(buffer) {
    this.socket.write(buffer);
}


Client.prototype.intToNetworkLong = function(value) {
    ip = String(value);
    var parts = ip.split(".");
    var res = 0;


    res += parseInt(parts[0], 10) << 24;
    res += parseInt(parts[1], 10) << 16;
    res += parseInt(parts[2], 10) << 8;
    res += parseInt(parts[3], 10);


    return res;
}

packetreader.js
Code:
var sys = require('sys');
module.exports = PacketReader;


function PacketReader(buffer, key)
{
    this.data = buffer;
    this.key = key;
    PacketReader.decrypt(this.data, 6, this.data.length - 6, this.key);
}


PacketReader.prototype.getCommandId = function() {
    return this.data.readUInt16LE(8);
}


PacketReader.decrypt = function(data, index, size, key) {
    for(var i = 0; i < size; ++i) {
        var a = data[index + i];
        a ^= 0xf0;
        var b = (7 & a);
        a = (a >> 3);
        b = (b << 5);
        b = (a | b);
        data[index + i] = (b ^ key[i % 32]);
    }
}


wutdo?
 
Daemonsring Developer
Joined
Jul 10, 2007
Messages
679
Reaction score
262
Nice idea, Whats next? Emulator in PHP?
Anyway goodluck with it!
 
Joined
Sep 10, 2007
Messages
970
Reaction score
815
I used to think that with browserquest. then I realized I was sorely mistaken.
You can sleep on the couch tonight.
Code:
var sys = require('sys');
module.exports = PacketReader;


function PacketReader(buffer, key)
{
    this.data = buffer;
    this.key = key;
    PacketReader.decrypt(this.data, 6, this.data.length - 6, this.key);
    this.position = 11;
}


PacketReader.prototype.getCommandId = function() {
    return this.data.readUInt16LE(8);
}


PacketReader.prototype.readUInt = function() {
    if(this.data.length >= this.position + 4) {
        this.position += 4;
        return this.data.readUInt32LE(this.position - 4);
    }
    return NaN;
}


PacketReader.prototype.readUShort = function() {
    if(this.data.length >= (this.position + 2)) {
        this.position += 2;
        return this.data.readUInt16LE(this.position - 2);
    }
    return NaN;
}


PacketReader.prototype.readByte = function() {
    if(this.data.length >= (this.position + 1)) {
        return this.data[this.position++];
    }
    return NaN;
}


PacketReader.prototype.readUID = function() {
    var high = this.readUInt();
    var low = this.readUInt();


    return low;
}


PacketReader.prototype.readString = function() {
    var len = this.readUShort();
    if(len > 0 && len < 65536 && this.data.length >= (this.position + len)) {
        var out = "";
        for(var i = 0; i < len - 2; ++i)
            out += String.fromCharCode(this.data[this.position + i]);
        this.position += len;
        return out;
    }
    return "NaS";
}


PacketReader.prototype.readBlob = function() {
    var total = this.readUInt();
    var count = this.readUInt();
    var size = this.readUInt();


    if(this.data.length >= (this.position + (count * size))) {
        var out = new Buffer(count * size);
        this.data.copy(out, 0, this.data, this.positon, this.postion + (count * size));
        this.position += (count * size);
        return [count, size, out];
    }
    return null;
}


PacketReader.decrypt = function(data, index, size, key) {
    for(var i = 0; i < size; ++i) {
        var a = data[index + i];
        a = (a ^ 0x0f0);
        var b = (7 & a);
        a = (a >>> 3);
        b = (b << 5);
        b = (a | b);
        data[index + i] = (b ^ key[i % 32]);
    }
}
 
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
Easier Linux compatibility, fast as duck and easy to make.

Yeah, because JavaScript is the fastest language out there, especially when it comes down to networking and routines. It also really, really blinks out in OOP. It's not like it was designed to make web-pages interactive.
 
Junior Spellweaver
Joined
Apr 8, 2009
Messages
171
Reaction score
22
Yeah, because JavaScript is the fastest language out there, especially when it comes down to networking and routines.

oops, I accidentally your logic.
It also really, really blinks out in OOP.
you owe me $1 for the coke I just snorted.
It's not like it was designed to make web-pages interactive.
No. It was created to make netscape interactive. Huge difference. But then again, surely you must know why a language was created doesn't really affect it's performance. It's not like we should be using computers to play GunZ instead of say, solving P = NP?!
Code:
var sys = require('sys');
module.exports = PacketReader;


function PacketReader(buffer, key)
{
    this.data = buffer;
    this.key = key;
    PacketReader.decrypt(this.data, 6, this.data.length - 6, this.key);
    this.position = 11;
}


PacketReader.prototype.getCommandId = function() {
    return this.data.readUInt16LE(8);
}


PacketReader.prototype.readUInt = function() {
    if(this.data.length >= this.position + 4) {
        this.position += 4;
        return this.data.readUInt32LE(this.position - 4);
    }
    return NaN;
}


PacketReader.prototype.readUShort = function() {
    if(this.data.length >= (this.position + 2)) {
        this.position += 2;
        return this.data.readUInt16LE(this.position - 2);
    }
    return NaN;
}


PacketReader.prototype.readByte = function() {
    if(this.data.length >= (this.position + 1)) {
        return this.data[this.position++];
    }
    return NaN;
}


PacketReader.prototype.readUID = function() {
    var high = this.readUInt();
    var low = this.readUInt();


    return low;
}


PacketReader.prototype.readString = function() {
    var len = this.readUShort();
    if(len > 0 && len < 65536 && this.data.length >= (this.position + len)) {
        var out = "";
        for(var i = 0; i < len - 2; ++i)
            out += String.fromCharCode(this.data[this.position + i]);
        this.position += len;
        return out;
    }
    return "NaS";
}


PacketReader.prototype.readBlob = function() {
    var total = this.readUInt();
    var count = this.readUInt();
    var size = this.readUInt();


    if(this.data.length >= (this.position + (count * size))) {
        var out = new Buffer(count * size);
        this.data.copy(out, 0, this.data, this.positon, this.postion + (count * size));
        this.position += (count * size);
        return [count, size, out];
    }
    return null;
}


PacketReader.decrypt = function(data, index, size, key) {
    for(var i = 0; i < size; ++i) {
        var a = data[index + i];
        a = (a ^ 0x0f0);
        var b = (7 & a);
        a = (a >>> 3);
        b = (b << 5);
        b = (a | b);
        data[index + i] = (b ^ key[i % 32]);
    }
}

You're still sleeping on the couch tonight. Bow before my python godliness.
also
ThePhailure772 - Another GunZ Emulator - RaGEZONE Forums

hi phoenix. op doesn't object. bye phoenix.
 
Joined
Sep 10, 2007
Messages
970
Reaction score
815

oops, I accidentally your logic.
do wat m8
As the above tests show, node is fast. Really fast. Much faster than Apache - many more requests per second, higher transfer rate with much smaller number of failed requests at the same time. Really shining.Obviously it is more hungry for system's CPU and memory, but this should not be surprising considering its performance.
 
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986

oops, I accidentally your logic.

You're comparing it to a webserver and a web programming language, that's cool but makes no sense considering Apache is not a programming language and PHP is a web programming language.

you owe me $1 for the coke I just snorted.

You owe me 5$ for not sensing the appropriate amount of sarcasm.

No. It was created to make netscape interactive. Huge difference. But then again, surely you must know why a language was created doesn't really affect it's performance. It's not like we should be using computers to play GunZ instead of say, solving P = NP?!

Yeah, and how exactly does netscape not display webpages?
 
Junior Spellweaver
Joined
Apr 8, 2009
Messages
171
Reaction score
22
You're comparing it to a webserver and a web programming language, that's cool but makes no sense considering Apache is not a programming language and PHP is a web programming language.
Oh, so I guess Apache is in no way related to networking, which proves that js is a bad idea for a server emulator. Hm.
Also, check your facts on PHP.
You owe me 5$ for not sensing the appropriate amount of sarcasm.
Lawdy, I sho does apologizes for not detecting your sarcasm, boss!
Yeah, and how exactly does netscape not display webpages?
Don't know if you knew, but JS was developed in the 90s- back when such languages were used as an api to provide "plugins", per se. Oops.
 
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
Oh, so I guess Apache is in no way related to networking, which proves that js is a bad idea for a server emulator. Hm.
Also, check your facts on PHP.

Apache is related to networking but not to JS where this whole argument is about. As for PHP, I know it's used for other purposes but the language was still designed for websites.

Don't know if you knew, but JS was developed in the 90s- back when such languages were used as an api to provide "plugins", per se. Oops.

Then no, I didn't. It's still not designed for this purpose, which was my point after all.
 
Junior Spellweaver
Joined
Apr 8, 2009
Messages
171
Reaction score
22
Apache is related to networking but not to JS where this whole argument is about. As for PHP, I know it's used for other purposes but the language was still designed for websites.

Then no, I didn't. It's still not designed for this purpose, which was my point after all.

So you established that JS wasn't designed for this. Great. What makes this a bad choice then? Clearly node.js inplements JS for a purpose other than websites, and it's obviously damn good, too.
 
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
So you established that JS wasn't designed for this. Great. What makes this a bad choice then? Clearly node.js inplements JS for a purpose other than websites, and it's obviously damn good, too.

How about the simple fact that JavaScript does not support multi threading.
 
Junior Spellweaver
Joined
Apr 8, 2009
Messages
171
Reaction score
22
How about the simple fact that JavaScript does not support multi threading.

http://bjouhier.wordpress.com/2012/03/11/fibers-and-threads-in-node-js-what-for/
Let me just point out that you're an idiot. The javascript SPECIFICATION, and the Node.js IMPLEMENTATION are two different things.
If you've never used node.js, then why are you bitching?
 
Praise the Sun!
Loyal Member
Joined
Dec 4, 2007
Messages
2,502
Reaction score
986
Let me just point out that you're an idiot.

That's just sweet.

The javascript SPECIFICATION, and the Node.js IMPLEMENTATION are two different things.
If you've never used node.js, then why are you bitching?

So, I was referring to JavaScript just like you were in http://forum.ragezone.com/f496/another-gunz-emulator-877520/#post7239980.

Anyway, I've looked up the specification of Node.js and considering your code is not pre-compiled, it makes it a bad choice for CPU intensive tasks such as a gameserver. Hence why Node.js was, just like PHP, created for web-based applications.
 
Junior Spellweaver
Joined
Apr 8, 2009
Messages
171
Reaction score
22
Anyway, I've looked up the specification of Node.js and considering your code is not pre-compiled, it makes it a bad choice for CPU intensive tasks such as a gameserver. Hence why Node.js was, just like PHP, created for web-based applications.

So basically your argument is that JS is not as fast as, say, java(? lolwut java is a compiled language), and as such it's a crappy idea that should never be implemented? Sorry to burst your bubble, but this wasn't really designed for speed, rather cross-platform support.
Not to mention that it [strike]PROBABLY[/strike] definitely would run much faster and with lower resource usage than MAIET's server, but then again anything that wasn't developed by you or MAIET is pretty good.

obtw, I don't usually quote wikipedia, but oh bbq.
Node.js is a software system designed for writing highly scalable Internet applications, notably web servers. Programs are written in JavaScript, using event-driven, asynchronous I/O to minimize overhead and maximize scalability.
Look up overhead, big boi, or write your own ultrafastuberawesumtasticomgsecksy emulator.
 
Status
Not open for further replies.
Back
Top