2015-05-10 11:11:27 +00:00
|
|
|
|
using System;
|
2015-05-10 17:02:10 +00:00
|
|
|
|
using System.CodeDom;
|
2015-05-10 11:11:27 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2015-06-05 21:07:37 +00:00
|
|
|
|
using xServer.Core.Networking;
|
2015-05-10 11:11:27 +00:00
|
|
|
|
using xServer.Core.Packets;
|
|
|
|
|
using xServer.Core.ReverseProxy.Packets;
|
|
|
|
|
|
|
|
|
|
namespace xServer.Core.ReverseProxy
|
|
|
|
|
{
|
|
|
|
|
public class ReverseProxyCommandHandler
|
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
public static void HandleCommand(Client client, IPacket packet)
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
var type = packet.GetType();
|
|
|
|
|
if (type == typeof (ReverseProxyConnectResponse))
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
ReverseProxyConnectResponse response = (ReverseProxyConnectResponse) packet;
|
2015-05-10 11:11:27 +00:00
|
|
|
|
if (client.Value.ProxyServer != null)
|
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
ReverseProxyClient socksClient =
|
|
|
|
|
client.Value.ProxyServer.GetClientByConnectionId(response.ConnectionId);
|
|
|
|
|
if (socksClient != null)
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
socksClient.CommandResponse(response);
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-10 17:02:10 +00:00
|
|
|
|
else if (type == typeof (ReverseProxyData))
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
ReverseProxyData dataCommand = (ReverseProxyData) packet;
|
|
|
|
|
ReverseProxyClient socksClient =
|
|
|
|
|
client.Value.ProxyServer.GetClientByConnectionId(dataCommand.ConnectionId);
|
2015-05-10 11:11:27 +00:00
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
if (socksClient != null)
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
socksClient.SendToClient(dataCommand.Data);
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-10 17:02:10 +00:00
|
|
|
|
else if (type == typeof (ReverseProxyDisconnect))
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
ReverseProxyDisconnect disconnectCommand = (ReverseProxyDisconnect) packet;
|
|
|
|
|
ReverseProxyClient socksClient =
|
|
|
|
|
client.Value.ProxyServer.GetClientByConnectionId(disconnectCommand.ConnectionId);
|
2015-05-10 11:11:27 +00:00
|
|
|
|
|
2015-05-10 17:02:10 +00:00
|
|
|
|
if (socksClient != null)
|
2015-05-10 11:11:27 +00:00
|
|
|
|
{
|
2015-05-10 17:02:10 +00:00
|
|
|
|
socksClient.Disconnect();
|
2015-05-10 11:11:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|