FICTURE7 / CoCSharp

Clash of Clans library, proxy and server written in .NET [Unmaintained]
MIT License
109 stars 57 forks source link

Plugging in a new packet source in CoCSharp.Network #88

Closed dls314 closed 7 years ago

dls314 commented 7 years ago

Anyone have any thoughts about this?

My thought is to create an upward facing plugin interface from parts of NetworkManagerAsync, but I'd like to hear any thoughts about any approaches.

My goal is to feed in captured packets as from https://github.com/PcapDotNet/Pcap.Net

FICTURE7 commented 7 years ago

Just to let you know that I have very little knowledge regarding those 'low-level' protocols and Pcap.Net in general. And never worked with raw sockets.

But here is what I would do, first I'd probably rip off all of the Clash of Clans related code in the NetworkManagerAsync class. Methods such as SendMessage and ProcessReceive contains a lot of that crappy stuff. Then create an interface or an abstract ProtocolProcessor class and PacketProcessor class to replace those Clash of Clans stuff. You might not need the ProtocolProcessor since your goal is to feed captured packets into it right?

Those 2 classes will provide extra flexibility to the NetworkManagerAsync as you can replace and modify the packet and protocol handling easily. For example you might want to create an IPv4ProtocolProcessor and an IPv4PacketProcessor to handle IPv4.

To keep track of how much data has been written or read, it sets the SocketAsyncEventArgs.UserToken's value to a MessageReceiveToken or MessageSendToken instance which gets reset after each read or write. So you might need a custom token for each different protocols.

It would probably require a lot of work to fix all of my shit, but hey what do I know.

FICTURE7 commented 7 years ago

Also Pcap.Net is a great library, you could easily feed the byte[] Packet.Buffer property into the MessageBufferManager's buffer which is a single huge buffer, each instance of the SocketAsyncEventArgs takes a segment of it to send and receive.

And sorry for the crappy explanation.

dls314 commented 7 years ago

That explanation rocked. Now to find time to work on it.

FICTURE7 commented 7 years ago

Great, glad I could help. =]