[Tutorial] Netty Based Server

08/08/2016 00:52 ItsTequila#1


Basics and a little introduction to Netty
Quote:
You ever felt like coding something harder than 4.1? Or maybe well less complicated (For me ;p). Well I'm here to help you out about learning to read netty classes and coding an emulator to handle all the requests and responses =).


Starting from the bottom - How to read
Quote:
Well the real base is to get a swf and a decompiler. In this tutorial I will use the 7.5.3 SWF & FFDec.

*This tutorial isn't limited just to 7.5.3, it's valid for all the swfs except the newest ones with netty folder changed*

You probably have just opened the swf and asked yourself, what am I doing with my life? Well it's not that hard as it may seem, it's even easier than you thought. As of this part you gotta choose if to read the classes from the decompiler or from n++. I personally prefer to decompile all the files to flash and just read everything using notepad++.
So now we're going into the real part, reading the classes.
Head to the folder called net -> bigpoint -> darkorbit -> net -> netty -> commands.
As for today's tutorial I won't jump into handlers or encryptions so just use meanwhile a premade swf (from private server).

Well here is the beginning of reading the commands and parsing them. I already made a tool to do the job for me but I didn't have enough time to fully complete it. (You may find the download under the Downloads section.)

First thing you would like to do is take your emulator and get the first command you've received from the connection. As for me and everyone else on this world it is 666.

So what you do is simply press CTRL+F and jump into Find in files menu.
It should look something like this.

[Only registered and activated users can see links. Click Here To Register...]
(Instead of 666 put the command ID.)

And the result you get should be the following:
[Only registered and activated users can see links. Click Here To Register...]

The next thing you should look is the command's ID.
Code:
public static const ID:int = 666;
That is always sent first in case you want to send the command.
Code:
writeShort(ID);
-- everything else --
But as of today we're only reading it.
Take a look at the last few lines,
Code:
      protected function writeInternal(param1:IDataOutput) : void
      {
         param1.writeInt(this.major);
         param1.writeUTF(this.minor);
         param1.writeInt(this.build);
      }
It should look something like this.

Now when you read the command you should get int,string,int.
So for example you are using a basic parser.
Code:
Debug.WriteLine(p.Id + " " + p.ReadInt() + " " p.ReadUTF() " " + p.ReadInt());
Use that to output all the params received.

And that is the base of how to read the netty commands.

Converting classes to C#
Quote:
For this example I will use the NettyBase source as example, link is down below.

So you've got to the point of converting / creating your own commands?
Well now we gotta identify if the commands we're converting is a subcommand or not.
How do we do that?

In this example we will use VisualModifierCommand.
First thing we do is on Notepad++ [CTRL + F] -> Find in Files
*Make sure you've located the search into the netty/commands folder*
[Only registered and activated users can see links. Click Here To Register...]
and click 'Find All'.

If you see to it's called in class with name other than "VisualModifierCommand" you can know to this command is a sub.

So how do I convert a normal command?
So how do I convert a sub?


Normal Command
Quote:
You can use the following template for creating a normal command:
Code:
namespace NettyBase.Net.netty.commands
{
    class TestCommand
    {
        public const short ID = 0; // Command ID, Replace it.

        public static byte[] write()
        {
            var cmd = new ByteArray(ID);
            // Command params goes here //
            return cmd.ToByteArray();
        }
    }
}
So how can I get the command params?
At the bottom of the class there is
Code:
      protected function writeInternal(param1:IDataOutput) : void
      {
         param1.writeInt(this.uid);
         param1.writeInt(this.newLevel);
      }
In this command for example we have 2 params, uid & newLevel and both of them are int.
That is how they should look in C#:
Code:
cmd.Integer(uid);
cmd.Integer(newLevel);
And the final command should look like that:
Code:
namespace NettyBase.Net.netty.commands
{
    class LevelUpCommand
    {
        public const short ID = 32247;

        public static byte[] write(int uid, int newLevel)
        {
            var cmd = new ByteArray(ID);
            cmd.Integer(uid);
            cmd.Integer(newLevel);
            return cmd.ToByteArray();
        }
    }
}
Sub Commands

Quote:
* To be continued *

Downloads & Others
Quote:
NettyBase Emulator
Quote:
So as you saw from above there is the NettyBase emulator. It is emulator that I created for helping everyone who wants to build his own 7.5.3 client emu.
I've also setup place to test your emulator instead of downloading xampp and htdocs and messing with all that stuff.

You can test your emulator here: [Only registered and activated users can see links. Click Here To Register...]

So to the main part of what this emulator does,
* It dumps all the packets that are not defined into a file called
Quote:
UndefinedCommands.dump
* I've cleaned up some codes here and there and also added Parser & ByteArray so you won't have to deal with this when you code your server.

* I've made also login so you won't mess with the settings because they usually take tons of time to setup and much headache.

* I've coded also the LegacyModule (Old packets)
All you need to do in order to send an old packet ("0|asdasd") is
Code:
client.Send(LegacyModule.write("0|asdasd"));
Atm I also started doing another tool that will help you order all the commands that you didn't define (NettyHelper) but as of now it's just a form so don't expect it to function.
* I will add all the info needed to create a server, just give me some time.

* If anyone would like to add something feel free to PM me and I will provide you with credit and add it into the post =).
08/08/2016 01:16 MrCriticalRx#2
jumm ...
08/08/2016 11:59 manulaiko3.0#3
Searching for integers that way will only lead to a lot of unnecessary results
08/08/2016 13:28 ItsTequila#4
Quote:
Originally Posted by manulaiko3.0 View Post
Searching for integers that way will only lead to a lot of unnecessary results
I will get into that later. I didn't have enough time finishing it up. And also as I mentioned at the bottom of the post if you would like to contribute you are free to do so.
08/08/2016 16:29 -Real-#5
Well Done Shock! Nice to See you Getting Better :)
08/09/2016 21:24 ItsTequila#6
Today's update:
Quote:
Originally Posted by Main post
NettyBase Emulator
Quote:
So as you saw from above there is the NettyBase emulator. It is emulator that I created for helping everyone who wants to build his own 7.5.3 client emu.
I've also setup place to test your emulator instead of downloading xampp and htdocs and messing with all that stuff.

You can test your emulator here: [Only registered and activated users can see links. Click Here To Register...]

So to the main part of what this emulator does,
* It dumps all the packets that are not defined into a file called
Quote:
UndefinedCommands.dump
* I've cleaned up some codes here and there and also added Parser & ByteArray so you won't have to deal with this when you code your server.

* I've made also login so you won't mess with the settings because they usually take tons of time to setup and much headache.

* I've coded also the LegacyModule (Old packets)
All you need to do in order to send an old packet ("0|asdasd") is
Code:
client.Send(LegacyModule.write("0|asdasd"));
Atm I also started doing another tool that will help you order all the commands that you didn't define (NettyHelper) but as of now it's just a form so don't expect it to function.
Soon I will add more updates to the emulator & also finish up the NettyHelper =).
08/09/2016 23:13 SYSTEMEWAR#7
Hi,

Glad to see someone who want to do his best in opensource !

then i'm going to contribute with this :)

[Only registered and activated users can see links. Click Here To Register...]

Best Regards
08/09/2016 23:30 ItsTequila#8
Quote:
Originally Posted by SYSTEMEWAR View Post
Hi,

Glad to see someone who want to do his best in opensource !

then i'm going to contribute with this :)

[Only registered and activated users can see links. Click Here To Register...]

Best Regards
Thank you for your contribution, parts of your code will be added in the next release.

Sneak peak of what I've been playing with :3
[Only registered and activated users can see links. Click Here To Register...]

PS: I fixed the buggy translations now [Only registered and activated users can see links. Click Here To Register...] should look all in normal language :p
08/09/2016 23:58 Azza12#9
[Only registered and activated users can see links. Click Here To Register...]
Hopefully you will release the CMS So i can get server running
08/10/2016 00:01 ItsTequila#10
Quote:
Originally Posted by Azza12 View Post
[Only registered and activated users can see links. Click Here To Register...]
Hopefully you will release the CMS So i can get server running
I'm currently considering the option of doing public server so everyone can enjoy and meanwhile be free to take the source =)
And don't forget, you're always welcome to contribute!
08/10/2016 00:05 Azza12#11
Quote:
Originally Posted by NUMANDERBUHMAN View Post
I'm currently considering the option of doing public server so everyone can enjoy and meanwhile be free to take the source =)
And don't forget, you're always welcome to contribute!
Mate i've test the ingame i downloaded the Emulator but which source you are on about
08/10/2016 00:42 ItsTequila#12
So as of now I'm confirming to there will be online version for everyone to enjoy very very soon :)!

Quote:
Originally Posted by Azza12 View Post
Mate i've test the ingame i downloaded the Emulator but which source you are on about
The new version ;)
08/10/2016 00:47 Azza12#13
Quote:
Originally Posted by NUMANDERBUHMAN View Post
So as of now I'm confirming to there will be online version for everyone to enjoy very very soon :)!



The new version ;)
Nice nice ;) mate, can't wait
Wanted to make my own server with your CMS But if your bringing one out i will play :D
08/10/2016 20:34 4K@60fps#14
Hey guys the link where you can test your emulator has been changed, new link is here: [Only registered and activated users can see links. Click Here To Register...]
08/10/2016 20:40 wall57#15
now that's rare on 2016...

usually between the catfights and grammar wars something nice pops up.