This is a Theaded Packet Queue'er for the coemu source. You will need to modify it a little bit if you have another source.
First create a new file and name it PacketThreading.cs
Copy and paste this code
Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using WorldServer.Networking; //EDIT change this to the folder your ClientSocket.cs is in
namespace WorldServer.Packets //EDIT change this to namespace of your project
{
public class PacketThreading
{
protected static int Counter = 0;
private static Hashtable Data = new Hashtable();
private static Hashtable Data1 = new Hashtable();
private static byte t1 = 0, t2 = 0, t = 0;
public static void TurnOn()
{
ThreadPool.QueueUserWorkItem(new WaitCallback(Thread1_Execute));
ThreadPool.QueueUserWorkItem(new WaitCallback(Thread2_Execute));
}
public static void Thread1_Execute(object state)
{
while (true)
{
foreach (PacketData packet in Data.Values)
{
TryExecute(packet.data, packet.CSocket);
}
Data.Clear();
t1 = 0;
Thread.Sleep(10);
}
}
public static void Thread2_Execute(object state)
{
while (true)
{
foreach (PacketData packet in Data1.Values)
{
TryExecute(packet.data, packet.CSocket);
}
Data1.Clear();
t2 = 0;
Thread.Sleep(10);
}
}
private static void TryExecute(byte[] data, ClientSocket CSocket)
{
try
{
PacketProcessor.ProcessPacket(data, CSocket);
}
catch (Exception e) { Program.WriteLine(e.ToString()); }
}
public static void Add(PacketData Packet)
{
int Count = Counter + 1;
switch (t)
{
case 0:
{
Data.Add(Count, Packet);
Counter = Count;
t = 0;
}
break;
case 1:
{
Data1.Add(Count, Packet);
Counter = Count;
t = 1;
}
break;
}
}
}
public class PacketData
{
protected byte[] _data;
public byte[] data
{
get { return _data; }
set { _data = value; }
}
protected ClientSocket _CSocket;
public ClientSocket CSocket
{
get { return _CSocket; }
set { _CSocket = value; }
}
public void Execute()
{
PacketThreading.Add(this);
}
}
}
Then in ClientSocket.cs preplace this:
Code:
PacketProcessor.ProcessPacket(Data, this);
with:
Code:
PacketData P = new PacketData();
P.data = Data;
P.CSocket = this;
P.Execute();
And somewhere where your server is initializing add this:
Code:
PacketThreading.TurnOn();