C# Simplest Proxy

07/30/2011 00:06 pushedx#16
Quote:
Originally Posted by sarkoplata View Post
About sending packets : How i send packets with this simplest proxy example ? I mean ;
remote_context.relaysecurity.send or
remote_context.socket.send or with whatever?
Even though i tried both , packet isn't being sent to server.
First, you never, ever send directly through the Socket object. Only through a Security object. Be sure you don't do this or you will have disastrous bugs!

It's kind of hard to explain clearly because it all depends on "perspective". Let's start out with the GatewayServer to make things simple.

local_context - The context for your sro_client and proxy connection.
remote_context - The context for your proxy and SRO server connection.

The "perspective" you are at is that of the proxy. So for example: sro_client <-> [proxy / you] <-> Silkroad server. When you send to the local_context, that means you are sending data from the proxy to sro_client. When you send to the remote_context, you are sending data from the proxy to the Silkroad server.

To inject data to the server, you would need to send data to the remote_context's security object directly. So, remote_context.Security.Send(...);

To inject data to the client, you would need to send data to the local_context's security object directly. So, local_context.Security.Send(...);

The "RelaySecurity" object is to make "forwarding" packets easier from one direction to the other, but it's not for the injecting data logic that you need.

It takes some thinking through, but try to imagine a proxy as just being an emulator (sro_client <-> proxy) + a clientless (proxy <-> SRO server). If you want to send data to the server, you have to use the remote_context object since that is your clientless object. If you want to send data to the client, you use the local_context since that is your emulator.

I hope that clears it up!
07/30/2011 00:06 benco#17
Quote:
Originally Posted by sarkoplata View Post
Well ! I added context.relaysecurity.send(packet) for each packet-handle-sub.
Now working perfectly !
Thank you for all :)

Edit :

With some chars when i hit start , it doesnt do anything , some part of chardata is being parsed , and loading bar value is 0 . Why is that happens?

Edit 2 :

I dc randomly. I mean , i cant even find out why i am dcing :/ How i will know where i am doing something wrong ?
is your game crash during loading player data ? when you are entering in map ? if it that, maybe I know what is the problem.
07/30/2011 00:15 sarkoplata#18
Quote:
Originally Posted by pushedx View Post
First, you never, ever send directly through the Socket object. Only through a Security object. Be sure you don't do this or you will have disastrous bugs!

It's kind of hard to explain clearly because it all depends on "perspective". Let's start out with the GatewayServer to make things simple.

local_context - The context for your sro_client and proxy connection.
remote_context - The context for your proxy and SRO server connection.

The "perspective" you are at is that of the proxy. So for example: sro_client <-> [proxy / you] <-> Silkroad server. When you send to the local_context, that means you are sending data from the proxy to sro_client. When you send to the remote_context, you are sending data from the proxy to the Silkroad server.

To inject data to the server, you would need to send data to the remote_context's security object directly. So, remote_context.Security.Send(...);

To inject data to the client, you would need to send data to the local_context's security object directly. So, local_context.Security.Send(...);

The "RelaySecurity" object is to make "forwarding" packets easier from one direction to the other, but it's not for the injecting data logic that you need.

It takes some thinking through, but try to imagine a proxy as just being an emulator (sro_client <-> proxy) + a clientless (proxy <-> SRO server). If you want to send data to the server, you have to use the remote_context object since that is your clientless object. If you want to send data to the client, you use the local_context since that is your emulator.

I hope that clears it up!
Well , thank you for nice explanation ! I just got it clearly now :)

@benco

Yes, it - was crashing - when trying to load char data and was being stuck at loading part. I still ignore errors so it doesnt stuck but a real solution would be nice. :)

edit : I dont know why i still cannot send packets , strangely
Is it related to my code ?
Code:
  Dim packetx As New Packet(&H704F, False, False)
        packetx.WriteUInt8(4)
        Proxy.remote_context.Security.Send(packetx)
07/30/2011 00:39 benco#19
silkroad packets are chunked when there's huge data. You should parse server packet correctly before to send it to sro_client.exe

simple exemple :

050030130000ABCDEF|packet 1
0102|packet 2
concat packet 1 with packet to get all data. this exemple can be reapted.
Is that help you ?
07/30/2011 00:53 sarkoplata#20
Quote:
Originally Posted by benco View Post
silkroad packets are chunked when there's huge data. You should parse server packet correctly before to send it to sro_client.exe

simple exemple :

050030130000ABCDEF|packet 1
0102|packet 2
concat packet 1 with packet to get all data. this exemple can be reapted.
Is that help you ?
Not really. I just didnt understand what you said.

^ Addition to my upper post :

I tried to send packet at agentServer thread and it work. Some equivalent processes are being i think thats why i can't send from somewhere else.Like :
Code:
remote_context.RelaySecurity = local_context.Security
            local_context.RelaySecurity = remote_context.Security
So my local_context and remote_contexts are public shared at Proxy.vb.
I acess them from somewhere else and writing :
remote_context.security.send(packet)
So i think I should do something before i try to send from another class.
07/30/2011 01:12 benco#21
I thought the problem come from sro server to sro game.
I did't see proxy code and security handshake. Give local_context and remote_contexte throw constructor of classes that need security.send.
07/30/2011 01:29 sarkoplata#22
Quote:
Originally Posted by benco View Post
I thought the problem come from sro server to sro game.
I did't see proxy code and security handshake. Give local_context and remote_contexte throw constructor of classes that need security.send.
Thanks i created 2different contexts for agentserver and gatewayserver so i can send now from anywhere :)
10/10/2011 02:23 Kyra#23
Thanks man really help :)
11/30/2011 14:15 slamangkero#24
hello, i'm trying to make a new connection to a hackshield server running on my pc using this example. i was able to connect but i can't seem to forward 0x2114 packet to localhost:15777. i'm planning on analyzing packets without being disconnected.

here's what i added:

Context hs_context = new Context();// new context for hs server connection

List<Context> contexts = new List<Context>();
contexts.Add(local_context);
contexts.Add(remote_context);
contexts.Add(hs_context);// add hs context to list of contexts

//create a client socket
Socket hs = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
{
hs_context.Socket = hs;
hs_context.Socket.Connect("localhost", 15777);
}

//added hs packet processing block
else if (packet.Opcode == 0x2114)
{
//forward packet to hs server here
Console.WriteLine("Hackshield Packet is received");
}

Thanks in advance
02/07/2012 10:55 Devsome#25
First of all , thanks !
Got it , thanks
10/15/2012 20:43 bdeniz#26
Quote:
Originally Posted by bdeniz View Post
i think its easier

using System.Net.Sockets;


private void Form1_Load(object sender, EventArgs e)
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//usage : socket.Connect(" IP" , port); ( u can write this into a button or write on forms load event
}
example, open phconector.ini,

write it to IP : 127.0.0.1
and write it to Listenport : 10001

open ph connector,

open a new C# form and write .

using System.Net.Sockets;

//create a button ( name = Button1)
private void Button1_Click(object sender, EventArgs e)
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect("127.0.0.1", 10001);
}

Run application and click button1. and look phconnector.exe

u will see

Connection to silkroad established
conecting to the login server

then you can login with edx loader.

note : if u want to try, enter a real server ip instead 127.0.0.1
and run edx loader with redirect login ip: server ip you writed, and port = 10001
10/31/2012 20:43 tarek1500#27
i wanna understand how the proxy works , i wanna make it my self
i need simple way plz
01/25/2013 07:12 Alireza.imani#28
what is it ' s usage code?
03/08/2013 12:41 spartai333#29
Hi guys, i read all the tutorials, examples etc. I decided to write a "tool" for vsro based servers. Im just a hobby coder but now i think ive understand the main things about silkroad security, how bots etc works, and i already know a lot about silkroad packets.
My problem is, i want to use pushedx's simplest proxy on my project, but i cant make it work. I always got c9 error. I read all off the posts from its thread, but i didnt find any solution. I use the second posted code from pushedx.
There are my connection configs from the code:

Code:
  
            String gateway_host = "127.0.0.1";
            Int32 gateway_port = 16000;

            String agent_host = "192.168.1.101";
            Int32 agent_port = 16001;

            String remote_host = "5.153.13.184";
            Int32 remote_port = 9779;

            String type = "gateway";
Also i use the code which was posted second by pushedx. Im trying to redirect my client with edxLoader, and the proxy works fine until i hit the chapta code. Than i got C9 error.

I set edxLoader like this:

[Only registered and activated users can see links. Click Here To Register...]

Uploaded with [Only registered and activated users can see links. Click Here To Register...]

Thank you for your answers, and also thanks for your great tutorials pushedx.
04/04/2015 12:08 alexhun#30
I'm getting error on this line :/ int count = context.Socket.Receive(context.Buffer.Buffer);
"an existing connection was forcibly closed by the remote host "