Post Pacific  

Go Back   Post Pacific > Lineage 2 > Lineage 2 Help

Notices

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 15.02.2007, 00:20   #2
astrid
Архивный участник
 
Join Date: May 2006
Posts: 55
Default

At last one who write code not on PHP
Use this for datatypes(C#):
Code:
using System;
using System.IO;
using System.Text;
namespace l2.cached
{
	/// <summary>
	/// Упаковка нешифрованных пакетов Клиент->Сервер (CacheD).
	/// Формирование заголовка пакета.
	/// </summary>
	public abstract class sPacketModel
	{
		MemoryStream _ms;
		

		protected sPacketModel()
		{
			_ms = new MemoryStream();
		}

		protected void WriteD(int value)
		{
			_ms.WriteByte((byte)(value &0xff));	
			_ms.WriteByte((byte)(value >> 8 &0xff));
			_ms.WriteByte((byte)(value >> 16 &0xff));
			_ms.WriteByte((byte)(value >> 24 &0xff));
		}

		protected void WriteH(int value)
		{
			_ms.WriteByte((byte)(value &0xff));	
			_ms.WriteByte((byte)(value >> 8 &0xff));
		}

		protected void WriteC(int value)
		{
			_ms.WriteByte((byte)(value &0xff));
		}

		protected void WriteF(double fvalue)
		{
			byte[] b = System.BitConverter.GetBytes(fvalue);
			_ms.Write(b,0,b.Length);
		}

		protected void WriteS(string text)
		{
			try
			{
				if (text != null)
				{	
					byte[] byteText = Encoding.Unicode.GetBytes(text);
					_ms.Write(byteText,0,byteText.Length);
				}
			}
			catch
			{
			}

			_ms.WriteByte((byte)0);
			_ms.WriteByte((byte)0);
		}

		public byte[] GetBytes()
		{
			MemoryStream _ms2=new MemoryStream();
			int length = (int)_ms.Length+2;
			_ms2.WriteByte((byte)(length &0xff));	
			_ms2.WriteByte((byte)(length >> 8 &0xff));
			_ms.WriteTo(_ms2);
			return _ms2.ToArray();
		}
		public abstract byte[] GetContent();
	}
}
and this is example of BanCharPacket packet:
Code:
using System;
using l2.cached;

namespace l2.cachedpackets
{
	/// <summary>
	/// Пакет BanCharPacket бан персонажа на n часов.
	/// ID: 39
	/// формат: ddS
	/// </summary>
	public class sBanChar:sPacketModel
	{
		private int _charid;
		private int _hours;
		public sBanChar(int charid, int hours) 
		{
			_charid=charid;
			_hours=hours;
		}
		public override byte[] GetContent()
		{
			WriteC(39);
			WriteD(_charid);
			WriteD(_hours);
			WriteS("1");
			return GetBytes();
		}
	}
}
i think you can make rest by yourself.
astrid is offline  
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:09.