[Releaase] Packet Tutorial (general and SRO-specific)

08/21/2012 22:20 intercsaki#16
I just wanted to mention, that your website is unreachable. :D

We are patient.


EDIT: While you're about rewriting the tuts, can you tell us some about using packets in C#? That would give some of us a real boost - me, for example. :)
08/21/2012 23:25 lesderid#17
Quote:
Originally Posted by intercsaki View Post
I just wanted to mention, that your website is unreachable. :D

We are patient.
I know that it's still offline. I've been trying to turn it on for hours. I blame Host1Free.
08/21/2012 23:40 intercsaki#18
I keep trying tomorrow. ^^
08/22/2012 07:30 evolution007#19
attached rar with pictures for offline view. have fun

//removed by lesderid request
08/22/2012 10:03 lesderid#20
Quote:
Originally Posted by evolution007 View Post
attached rar with pictures for offline view. have fun
Could you please remove them? "Though no rights were ever claimed, please do not distribute these pictures separately."

You can download them from my site, but I don't want people sharing them on forums.

The site is now online again, sorry for the inconvenience.
08/22/2012 13:11 kevin_owner#21
Quote:
Originally Posted by intercsaki View Post
I just wanted to mention, that your website is unreachable. :D

We are patient.


EDIT: While you're about rewriting the tuts, can you tell us some about using packets in C#? That would give some of us a real boost - me, for example. :)
Well I could give you a few tips. The easiest way to write a packet in .net is with the BinaryWriter and BinaryReader class.

Code:
			byte[] packet;
			using (MemoryStream memoryStream = new MemoryStream())
			{
				using (BinaryWriter writer = new BinaryWriter(memoryStream))
				{
					writer.Write((short)1);
					writer.Write((short)0x5000);
					writer.Write((short)0);
					writer.Write((byte)1);

				}
				packet = memoryStream.ToArray();
			}

			using (MemoryStream memoryStream = new MemoryStream(packet))
			{
				using (BinaryReader reader = new BinaryReader(memoryStream))
				{
					short dataSize = reader.ReadInt16();
					short opcode = reader.ReadInt16();
					short securityBytes = reader.ReadInt16();
					byte flag = reader.ReadByte();
					Console.WriteLine("Data in packet is: {0}", dataSize);
					Console.WriteLine("Opcode is: {0:X4}", opcode);
					Console.WriteLine("Security bytes are: {0}", securityBytes);
					Console.WriteLine("Encryption flag: {0}", flag);
				}
			}
This is a very small and basic example of how to write and read packets in C#. The first piece of code with the BinaryWriter created a packet and the 2nd part reads the packet we just created.

Once you have written a packet you can send it to the client or server using a Socket. You use a byte array to send and receive packets.
08/23/2012 11:22 intercsaki#22
Quote:
Originally Posted by kevin_owner View Post
Well I could give you a few tips. The easiest way to write a packet in .net is with the BinaryWriter and BinaryReader class.

Code:
			byte[] packet;
			using (MemoryStream memoryStream = new MemoryStream())
			{
				using (BinaryWriter writer = new BinaryWriter(memoryStream))
				{
					writer.Write((short)1);
					writer.Write((short)0x5000);
					writer.Write((short)0);
					writer.Write((byte)1);

				}
				packet = memoryStream.ToArray();
			}

			using (MemoryStream memoryStream = new MemoryStream(packet))
			{
				using (BinaryReader reader = new BinaryReader(memoryStream))
				{
					short dataSize = reader.ReadInt16();
					short opcode = reader.ReadInt16();
					short securityBytes = reader.ReadInt16();
					byte flag = reader.ReadByte();
					Console.WriteLine("Data in packet is: {0}", dataSize);
					Console.WriteLine("Opcode is: {0:X4}", opcode);
					Console.WriteLine("Security bytes are: {0}", securityBytes);
					Console.WriteLine("Encryption flag: {0}", flag);
				}
			}
This is a very small and basic example of how to write and read packets in C#. The first piece of code with the BinaryWriter created a packet and the 2nd part reads the packet we just created.

Once you have written a packet you can send it to the client or server using a Socket. You use a byte array to send and receive packets.
Wow. :D Thanks. I save that for further examination. ;P Honestly, I'm not there (yet) to use these, I recently started to learn C# more comprhensively. :) But I'm sure this will be handy. :D
08/23/2012 17:45 lesderid#23
Quote:
Originally Posted by intercsaki View Post
Wow. :D Thanks. I save that for further examination. ;P Honestly, I'm not there (yet) to use these, I recently started to learn C# more comprhensively. :) But I'm sure this will be handy. :D
You should honestly just use Drew's SilkroadSecurityAPI instead of reinventing the wheel.
08/23/2012 18:01 evolution007#24
Quote:
Originally Posted by lesderid View Post
You should honestly just use Drew's SilkroadSecurityAPI instead of reinventing the wheel.
its quite hard to understand every part of program when you're newbie
08/23/2012 20:03 intercsaki#25
Quote:
Originally Posted by lesderid View Post
You should honestly just use Drew's SilkroadSecurityAPI instead of reinventing the wheel.
Why though, I would know every single particle well. Which would help me in my future work. :)

After I gained enough experience (that sounds sro-ish), I'll concentrate on performance.
03/07/2013 15:06 mohgabr#26
Great tutorials
But please can you fix :
-Tutorial 03: Using Packets in C#
-Tutorial 04: Using a Database
03/07/2013 17:47 lesderid#27
Quote:
Originally Posted by mohgabr View Post
Great tutorials
But please can you fix :
-Tutorial 03: Using Packets in C#
-Tutorial 04: Using a Database
Read the first post.
03/08/2013 00:01 intercsaki#28
Hey, I didn't even know I was looking for this!

Thanks Fate! :D