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!

[C#] best way to code packets?

YEy i has custom title^_^
Joined
Sep 29, 2006
Messages
452
Reaction score
67
so im about to start building my emulator so far made function to encrypt/decrypt the packets and simple server that listen socket and send packets to client anyway..

i was wondering what would be best way to code packets like i got this packet here
47 20 1A 00 AD 01 00 00 01 0F 00 32 31 38 2E 31 34 35 2E 35 35 2E 31 37 30 00 98 21 00 00

the structure is something like this:
packet id
packet length
random crap
ip length

ip

so how could i make something smart out from this, i tried make public byte with string ip to declare the ip but it looks stupid heres the code of it
Code:
        public byte[] SendIp(string ip)
        {
            byte[] test;
            test = Encoding.ASCII.GetBytes(ip);
            byte[] packet;
            packet = new byte[30];
            packet[0] = 0x47;
            packet[1] = 0x20;
            packet[2] = (byte)(packet.Length); // packet length
            packet[3] = 0x00;
            packet[4] = 0xAD;
            packet[5] = 0x01;
            packet[6] = 0x00;
            packet[7] = 0x00;
            packet[8] = 0x01;
            packet[9] = (byte)(test.Length); // ip length
            packet[10] = 0x00;
            for (int i = 0; i > test.Length; i++)
            {
                packet[10 + i] = test[i];
            }
            packet[25] = 0x00;
            packet[26] = 0x98;
            packet[27] = 0x21;
            packet[28] = 0x00;
            packet[29] = 0x00;
            return packet;
        }
it can be used like packets.SendIp("218.145.55.170") just wondering if there is any smarter ways to do this and when i build emulator i need make it answer packets by reading the packet id, if im right?
like hundred of cases then make packet builder build the answer for those packets or something like this if anyone could clear me out abit do so :rolleyes:
 
You've got my respect!
Joined
Apr 8, 2008
Messages
508
Reaction score
147
Use a packet class, they make it much easier.
 
YEy i has custom title^_^
Joined
Sep 29, 2006
Messages
452
Reaction score
67
its already on its own class but i mean ways how to code those packets later like packets that need data from database etc.
cause atm i only made packets look like this
Code:
public byte[] AcceptLauncher = { 0x47, 0x20, 0x19, 0x00, 0xAD, 0x01, 0x00, 0x00, 0x01, 0x0E, 0x00, 0x31, 0x39, 0x32, 0x2E, 0x31, 0x36, 0x38, 0x2E, 0x30, 0x2E, 0x31, 0x30, 0x30, 0x00, 0x98, 0x21, 0x00, 0x00 };
which is same packet as the launcher one but the upper one is newer/better since you can change ip faster
 
Watching from above
Legend
Joined
Apr 9, 2004
Messages
3,828
Reaction score
752
It sounds like you're doing it upside down. If you first build the core which actually has all the functionality that a server should, figuring out how to send the data will hardly be a problem.
 
YEy i has custom title^_^
Joined
Sep 29, 2006
Messages
452
Reaction score
67
so basicly i would build database first then functions that takes data from there like player max health or something like this?
 
Watching from above
Legend
Joined
Apr 9, 2004
Messages
3,828
Reaction score
752
Well, yeah. Of course at first it may look like you'll get far by just replying to client's messages with the kind of constant packets you're working with right now, but as soon as you get to log onto your emulated server most of your work will go into methods to keep your world going and the client-server communication will turn out to be a rather minimal job. Take this from someone who hasn't coded a server, though.
 
Back
Top