Removed old code

This commit is contained in:
Norbi Peti 2016-06-16 12:43:44 +02:00
parent 8b439e1d81
commit c82419f1b3
10 changed files with 62 additions and 964 deletions

View file

@ -1,20 +1,32 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2013 for Windows Desktop # Visual Studio 14
VisualStudioVersion = 12.0.21005.1 VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Connection forwarder", "Connection forwarder\Connection forwarder.csproj", "{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Connection forwarder", "Connection forwarder\Connection forwarder.csproj", "{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Debug|Any CPU.Build.0 = Debug|Any CPU {8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Debug|x64.ActiveCfg = Debug|x64
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Debug|x64.Build.0 = Debug|x64
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Debug|x86.ActiveCfg = Debug|x86
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Debug|x86.Build.0 = Debug|x86
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Release|Any CPU.ActiveCfg = Release|Any CPU {8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Release|Any CPU.Build.0 = Release|Any CPU {8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Release|Any CPU.Build.0 = Release|Any CPU
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Release|x64.ActiveCfg = Release|x64
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Release|x64.Build.0 = Release|x64
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Release|x86.ActiveCfg = Release|x86
{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}.Release|x86.Build.0 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View file

@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}</ProjectGuid> <ProjectGuid>{8FA8C951-B4EE-4176-83E2-54F7EA4115A2}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Connection_forwarder</RootNamespace> <RootNamespace>Connection_forwarder</RootNamespace>
<AssemblyName>Connection forwarder</AssemblyName> <AssemblyName>Connection forwarder</AssemblyName>
@ -31,12 +31,53 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Cyotek.Data.Nbt"> <Reference Include="RakNet, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
<HintPath>..\..\..\..\..\Downloads\Cyotek.Data.Nbt-master\Cyotek.Data.Nbt-master\Cyotek.Data.Nbt\bin\Debug\Cyotek.Data.Nbt.dll</HintPath> <SpecificVersion>False</SpecificVersion>
</Reference> <HintPath>.\RakNet.dll</HintPath>
<Reference Include="Nito.Async">
<HintPath>..\..\..\..\..\Downloads\Nito.Async.1.4\Nito.Async.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@ -50,21 +91,8 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ConnectionThread.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="ListenThread.cs" />
<Compile Include="PCPackets.cs" />
<Compile Include="PEPackets.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>

View file

@ -1,77 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using Cyotek.Data.Nbt;
using System.Threading;
using System.Net;
namespace Connection_forwarder
{
class ClientConnectionThread
{
public Int64 ClientID;
public bool DataChanged = false;
public byte[] DataBuffer;
public void Run(object obj)
{
Thread.CurrentThread.Name = "ClientConnectionThread";
//Form1.Threads.Add(Thread.CurrentThread);
//IPEndPoint RemoteIP = (IPEndPoint)remip;
IPEndPoint RemoteIP = (IPEndPoint)((object[])obj)[0];
UdpClient connection = (UdpClient)((object[])obj)[1];
ClientID = (Int64)((object[])obj)[2];
//Program.ConnThreads.Add(ClientID, new object[] { Thread.CurrentThread, this }); //Remove it over time
Program.ConnThreads.Add(RemoteIP, new object[] { Thread.CurrentThread, this }); //Remove it over time
//UdpClient listenclient;
//byte[] buffer;
//bool brvar = false;
//UdpClient sendsocket;
var lasttick = Environment.TickCount;
while (Environment.TickCount - lasttick < 60 * 1000)
{
if (DataChanged)
{ //Now DataBuffer contains the received packet
Console.WriteLine("Data changed...");
Console.WriteLine("PacketID: 0x{0:X}", DataBuffer[0]);
lasttick = Environment.TickCount;
DataChanged = false; //Finished working
}
/*do
{
//new PEPackets(PEPackets.TOCLIENT_LoginStatusPacket, new object[] { 0 }, sendsocket, RemoteIP);
//connsocket[1] = new Socket(SocketType.Stream, ProtocolType.Tcp); //We still need to connect to the server
//((Socket)connsocket[1]).Connect("localhost", Form1.PortNumber);
//After login loop to receive all messages
} while (false);*/
}
Program.ConnThreads.Remove(RemoteIP);
}
/*private bool done = false;
void saea_Completed(object sender, SocketAsyncEventArgs e)
{
done = true;
}*/
public void SendData(object data)
{
}
}
class ServerConnectionThread
{
public void Run(object sckt)
{
Thread.CurrentThread.Name = "ServerConnectionThread";
//Form1.Threads.Add(Thread.CurrentThread);
/*object connsocket;
connsocket = ((UdpClient)((object[])sckt)[0]);
var serversock = ((Socket)((object[])sckt)[1]);
(connsocket as Socket).Close();
serversock.Close();*/
}
}
}

View file

@ -1,151 +0,0 @@
namespace Connection_forwarder
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.portBox = new System.Windows.Forms.TextBox();
this.startbtn = new System.Windows.Forms.Button();
this.startforwardbtn = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.portBox2 = new System.Windows.Forms.TextBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.SuspendLayout();
//
// portBox
//
this.portBox.Location = new System.Drawing.Point(105, 71);
this.portBox.Name = "portBox";
this.portBox.Size = new System.Drawing.Size(57, 20);
this.portBox.TabIndex = 0;
this.portBox.Text = "25565";
//
// startbtn
//
this.startbtn.Location = new System.Drawing.Point(169, 71);
this.startbtn.Name = "startbtn";
this.startbtn.Size = new System.Drawing.Size(75, 23);
this.startbtn.TabIndex = 1;
this.startbtn.Text = "Start test";
this.startbtn.UseVisualStyleBackColor = true;
this.startbtn.Click += new System.EventHandler(this.startbtn_Click);
//
// startforwardbtn
//
this.startforwardbtn.Location = new System.Drawing.Point(90, 202);
this.startforwardbtn.Name = "startforwardbtn";
this.startforwardbtn.Size = new System.Drawing.Size(89, 23);
this.startforwardbtn.TabIndex = 2;
this.startforwardbtn.Text = "Start forwarding";
this.startforwardbtn.UseVisualStyleBackColor = true;
this.startforwardbtn.Click += new System.EventHandler(this.startforwardbtn_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(45, 76);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(54, 13);
this.label1.TabIndex = 3;
this.label1.Text = "Server IP:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(37, 106);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(62, 13);
this.label2.TabIndex = 4;
this.label2.Text = "Program IP:";
//
// portBox2
//
this.portBox2.Location = new System.Drawing.Point(105, 103);
this.portBox2.Name = "portBox2";
this.portBox2.Size = new System.Drawing.Size(57, 20);
this.portBox2.TabIndex = 5;
this.portBox2.Text = "8888";
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(40, 129);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(132, 17);
this.radioButton1.TabIndex = 6;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "PC Version (for testing)";
this.radioButton1.UseVisualStyleBackColor = true;
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Checked = true;
this.radioButton2.Location = new System.Drawing.Point(40, 153);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(77, 17);
this.radioButton2.TabIndex = 7;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "PE Version";
this.radioButton2.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.portBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.startforwardbtn);
this.Controls.Add(this.startbtn);
this.Controls.Add(this.portBox);
this.Name = "Form1";
this.Text = "Form1";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox portBox;
private System.Windows.Forms.Button startbtn;
private System.Windows.Forms.Button startforwardbtn;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox portBox2;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
}
}

View file

@ -1,57 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Connection_forwarder
{
public partial class Form1 : Form
{
public static int PortNumber;
public static int PortNumber2;
//public static bool PEVersion;
//public static List<Thread> Threads = new List<Thread>();
public Form1()
{
InitializeComponent();
//Threads.Add(Thread.CurrentThread);
}
private void startbtn_Click(object sender, EventArgs e)
{
var s = new Socket(SocketType.Stream, ProtocolType.Tcp);
s.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), Int32.Parse(portBox.Text)));
s.Listen(2);
s = s.Accept();
var a = new NetworkStream(s);
byte[] buffer = new byte[512];
a.Read(buffer, 0, 512);
MessageBox.Show("Contents:\n" + buffer.ToString());
s.Close();
MessageBox.Show(Encoding.ASCII.GetString(buffer));
}
private void startforwardbtn_Click(object sender, EventArgs e)
{
PortNumber = Int32.Parse(portBox.Text);
PortNumber2 = Int32.Parse(portBox2.Text);
//PEVersion = radioButton2.Checked;
new Thread(new ThreadStart(ListenThread.Run)).Start();
startforwardbtn.Enabled = false;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Environment.Exit(0);
}
}
}

View file

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -1,193 +0,0 @@
using Nito.Async;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Connection_forwarder
{
class ListenThread
{
public static void Run()
{
Thread.CurrentThread.Name = "ListenThread";
//Form1.Threads.Add(Thread.CurrentThread);
UdpClient connection;
var RemoteIP = new IPEndPoint(IPAddress.Any, Form1.PortNumber2);
connection = new UdpClient(Form1.PortNumber2);
while (true)
{
/*
* PE connection:
* When player joins start a thread and open connection to server
* When player leaves or times out disconnect from the server with matching data sent
*
* So basically handle the PE join here to know when to start a new thread
*/
do
{
//connection.Connect(new IPEndPoint(IPAddress.Any, Form1.PortNumber2));
byte[] buffer;
buffer = connection.Receive(ref RemoteIP); //Receive the packet ID to determine IP
/*
* Or receive all data and send it to the matching ConnectionThread determined by Client ID
*
* Actually the Client ID is not used later on...
* So determine IP every time and send the packet to matching thread
*/
//connection.Connect(RemoteIP);
//connection.Send(buffer, buffer.Length);
//connection.Close();
//if (Program.ConnThreads.ContainsKey(RemoteIP))
//if (Program.ConnThreads.ContainsKey(PEPackets.GetClientID(buffer)))
//break; //Let the ConnectionThread handle the request - By detecting packet type...
bool brvar = false;
//Int64 cid;
Console.WriteLine("Received packet: 0x{0:X}", buffer[0]);
//if (buffer[0] != PEPackets.TOSERVER_ID_OPEN_CONNECTION_REQUEST_1 && Program.ConnThreads.ContainsKey(cid = PEPackets.GetClientID(buffer)))
if (buffer[0] != PEPackets.TOSERVER_ID_OPEN_CONNECTION_REQUEST_1 && Program.ConnThreads.ContainsKey(RemoteIP))
{
//Handle packets and send data to matching thread
//(new Task(((ClientConnectionThread)Program.ConnThreads[cid][1]).SendData, buffer)).Start(new LimitedConcurrencyLevelTaskScheduler(1));
//new ListenThread().MemberwiseClone();
while (((ClientConnectionThread)Program.ConnThreads[RemoteIP][1]).DataChanged)
; //Wait until thread finishes
((ClientConnectionThread)Program.ConnThreads[RemoteIP][1]).DataBuffer = buffer;
((ClientConnectionThread)Program.ConnThreads[RemoteIP][1]).DataChanged = true;
break;
}
else if (buffer[0] != PEPackets.TOSERVER_ID_OPEN_CONNECTION_REQUEST_1)
break;
for (int i = 0; i < PEPackets.MAGIC.Length; i++)
{
if (buffer[i + 1] != PEPackets.MAGIC[i])
{
Console.WriteLine("There is no magic for this client...");
brvar = true;
break;
}
}
if (brvar)
break;
Console.WriteLine("Magic accepted.");
//var sendsocket = new UdpClient(Form1.PortNumber2);
//sendsocket.EnableBroadcast = true;
connection.Connect(RemoteIP); //Make it only communicate with the currently joining player
if (buffer[PEPackets.MAGIC.Length + 1] != PEPackets.ProtocolVer)
{
new PEPackets(PEPackets.TOCLIENT_ID_INCOMPATIBLE_PROTOCOL_VERSION, new object[] { PEPackets.ProtocolVer, PEPackets.MAGIC, 0x00000000372cdc9e }, connection, RemoteIP); //ID_INCOMPATIBLE_PROTOCOL_VERSION (0x1A)
break;
}
new PEPackets(PEPackets.TOCLIENT_ID_OPEN_CONNECTION_REPLY_1, new object[] { PEPackets.MAGIC, 0x00000000372cdc9e, 0, 1447 }, connection, RemoteIP);
//sendsocket.Close();
Console.WriteLine("Open connection 1 succeed.");
/*
* We must handle the open connection 2 here in order to obtain ClientID
*/
buffer = connection.Receive(ref RemoteIP);
Console.WriteLine("Received packet: " + buffer[0]);
if (buffer[0] != PEPackets.TOSERVER_ID_OPEN_CONNECTION_REQUEST_2)
break;
for (int i = 0; i < PEPackets.MAGIC.Length; i++)
{
if (buffer[i + 1] != PEPackets.MAGIC[i])
{
Console.WriteLine("There is no magic for this client...");
brvar = true;
break;
}
}
if (brvar)
break;
byte[] bufferPart = new byte[5];
Console.WriteLine("Extracting data...");
Array.Copy(buffer, PEPackets.MAGIC.Length + 1, bufferPart, 0, 5);
for (int i = 0; i < bufferPart.Length; i++)
{
if (bufferPart[i] != 0x00)
{
brvar = true;
break;
}
}
if (brvar)
break;
Array.Copy(buffer, PEPackets.MAGIC.Length + 6, bufferPart = new byte[2], 0, 2);
short ServerPortFromClient = BitConverter.ToInt16(bufferPart, 0);
Console.WriteLine("ServerPortFromClient: " + ServerPortFromClient);
Array.Copy(buffer, PEPackets.MAGIC.Length + 8, bufferPart, 0, 2);
short MTUSize = BitConverter.ToInt16(bufferPart, 0);
Console.WriteLine("MTUSize: " + MTUSize);
Array.Copy(buffer, PEPackets.MAGIC.Length + 10, bufferPart = new byte[8], 0, 8);
long ClientID = BitConverter.ToInt64(bufferPart, 0);
Console.WriteLine("ClientID: " + ClientID);
//sendsocket = new UdpClient(Form1.PortNumber2);
//sendsocket.Connect(RemoteIP);
new PEPackets(PEPackets.TOCLIENT_ID_OPEN_CONNECTION_REPLY_2, new object[] { PEPackets.MAGIC, 0x00000000372cdc9e, Form1.PortNumber2, 1464, 0 }, connection, RemoteIP);
//sendsocket.Close();
//listenclient = new UdpClient(Form1.PortNumber2);
//buffer = listenclient.Receive(ref RemoteIP);
buffer = connection.Receive(ref RemoteIP);
//Console.WriteLine("Received: 0x{0:X}", buffer[0]);
//Console.WriteLine("Second byte: 0x{0:X}", buffer[1]);
//listenclient.Close();
while (buffer[0] != 0x84)
{ //Send NACK back
Console.WriteLine("Received packet: 0x{0:X}", buffer[0]);
Console.WriteLine("Incorrect packet. Resending...");
var tmpreta = PEPackets.DecodeDataPacket(buffer);
if (tmpreta == null)
break;
byte[] Counta = PEPackets.IntTo3Byte((int)tmpreta[1]);
//new PEPackets(0xA0, new object[] { (short)1, true, 0x84 }, connection, RemoteIP);
new PEPackets(0xA0, new object[] { (short)1, true, Counta }, connection, RemoteIP);
buffer = connection.Receive(ref RemoteIP);
}
/*
* Custom packet 0x84:
* Count field (3 bytes) and then data payload:
* Encapsulation ID (1 byte) (=0x00) and then length then data packet:
* Status (1 byte/8 bits)
*/
//var tmp = BitConverter.GetBytes(0x84).ToList<byte>();
//Console.WriteLine("Remove 1st byte from: " + tmp[0] + ", " + tmp[1] + ", " + tmp[2] + ", " + tmp[3]);
//tmp.RemoveAt(3); //We only need 3 bytes
//new PEPackets(0xC0, new object[] { (short)1, true, tmp.ToArray() }, connection, RemoteIP); //Send ACK
var lasttick = Environment.TickCount;
do
{
var tmpret = PEPackets.DecodeDataPacket(buffer);
if (tmpret == null)
break;
Console.WriteLine("Count: " + (int)tmpret[1]);
Console.WriteLine("EncapsulationID: " + tmpret[0]);
Console.WriteLine("Count2: " + tmpret[3]);
byte[] Count = PEPackets.IntTo3Byte((int)tmpret[1]);
Console.WriteLine("Count 1st byte: " + Count[0]);
new PEPackets(0xC0, new object[] { (short)1, true, Count }, connection, RemoteIP);
} while ((buffer = connection.Receive(ref RemoteIP))[0] == 0x84 && Environment.TickCount - lasttick < 6000 * 1000);
//-----------------------------
var threadvar = new Object[3];
connection.Close();
connection = new UdpClient(Form1.PortNumber2);
threadvar[0] = RemoteIP;
threadvar[1] = connection;
threadvar[2] = ClientID;
new Thread(new ParameterizedThreadStart(new ClientConnectionThread().Run)).Start(threadvar);
//new Thread(new ParameterizedThreadStart(new ServerConnectionThread().Run)).Start(threadvar);
//new ActionThread().Do(new ClientConnectionThread().Run(threadvar));
} while (false);
}
}
}
}

View file

@ -1,168 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace Connection_forwarder
{
class PCPackets
{
/* http://wiki.vg/Pre-release_protocol */
/// <summary>
/// <para>Gamemode Unsigned Byte 0: survival, 1: creative, 2: adventure. Bit 3 (0x8) is the hardcore flag</para>
/// <para>Dimension Byte -1: nether, 0: overworld, 1: end</para>
/// <para>Difficulty Unsigned Byte 0 thru 3 for Peaceful, Easy, Normal, Hard</para>
/// <para>Max Players Unsigned Byte Used by the client to draw the player list</para>
/// <para>Level Type String default, flat, largeBiomes, amplified, default_1_1</para>
/// <para>Reduced Debug Info Boolean</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_JOIN_GAME = 0x01;
/// <summary>
/// <para>Json data: string; Chat, Limited to 32767 bytes</para>
/// <para>Position: byte; 0 - Chat (chat box) ,1 - System Message (chat box), 2 - Above action bar</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_CHAT_MESSAGE = 0x02;
/// <summary>
/// <para>EntityID VarInt Entity's ID</para>
/// <para>Slot Short Equipment slot: 0=held, 1-4=armor slot (1 - boots, 2 - leggings, 3 - chestplate, 4 - helmet</para>
/// <para>Item Slot Item in slot format</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_ENTITY_EQUIPMENT = 0x04;
/// <summary>
/// <para>Sent by the server after login to specify the coordinates of the spawn point (the point at which players spawn at, and which the compass points to). It can be sent at any time to update the point compasses point at.</para>
/// <para>0x05 Location Position Spawn location</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_SPAWN_POSITION = 0x05;
/// <summary>
/// <para>Sent by the server to update/set the health of the player it is sent to.</para>
/// <para>Food saturation acts as a food "overcharge". Food values will not decrease while the saturation is over zero. Players logging in automatically get a saturation of 5.0. Eating food increases the saturation as well as the food bar.</para>
/// <para>Health Float 0 or less = dead, 20 = full HP</para>
/// <para>Food VarInt 0 - 20</para>
/// <para>Food Saturation Float Seems to vary from 0.0 to 5.0 in integer increments</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_UPDATE_HEALTH = 0x06;
/// <summary>
/// <para>Updates the players position on the server. If the distance between the last known position of the player on the server and the new position set by this packet is greater than 100 units will result in the client being kicked for "You moved too quickly :( (Hacking?)" Also if the fixed-point number of X or Z is set greater than 3.2E7D the client will be kicked for "Illegal position"</para>
/// <para>Yaw is measured in degrees, and does not follow classical trigonometry rules. The unit circle of yaw on the XZ-plane starts at (0, 1) and turns counterclockwise, with 90 at (-1, 0), 180 at (0,-1) and 270 at (1, 0). Additionally, yaw is not clamped to between 0 and 360 degrees; any number is valid, including negative numbers and numbers greater than 360.</para>
/// <para>Pitch is measured in degrees, where 0 is looking straight ahead, -90 is looking straight up, and 90 is looking straight down.</para>
/// <para>The yaw of player (in degrees), standing at point (x0,z0) and looking towards point (x,z) one can be calculated with:</para>
/// <para> l = x-x0</para>
/// <para> w = z-z0</para>
/// <para> c = sqrt( l*l + w*w )</para>
/// <para> alpha1 = -arcsin(l/c)/PI*180</para>
/// <para> alpha2 = arccos(w/c)/PI*180</para>
/// <para> if alpha2 > 90 then</para>
/// <para> yaw = 180 - alpha1</para>
/// <para> else</para>
/// <para> yaw = alpha1</para>
/// <para>You can get a unit vector from a given yaw/pitch via:</para>
/// <para> x = -cos(pitch) * sin(yaw)</para>
/// <para> y = -sin(pitch)</para>
/// <para> z = cos(pitch) * cos(yaw)</para>
/// <para>About the flags field:</para>
/// <para> (Dinnerbone) It's a bitfield, X/Y/Z/Y_ROT/X_ROT. If X is set, the x value is relative and not absolute.</para>
/// <para>X Double Absolute/Relative position</para>
/// <para>Y Double Absolute/Relative position</para>
/// <para>Z Double Absolute/Relative position</para>
/// <para>Yaw Float Absolute/Relative rotation on the X Axis, in degrees</para>
/// <para>Pitch Float Absolute/Relative rotation on the Y Axis, in degrees</para>
/// <para>Flags Byte </para>
/// <para>X 0x01</para>
/// <para>Y 0x02</para>
/// <para>Z 0x04</para>
/// <para>Y_ROT 0x08</para>
/// <para>X_ROT 0x10;</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_PLAYER_POSITION_AND_LOOK = 0x08;
/// <summary>
/// <para>This packet tells that a player goes to bed.</para>
/// <para>The client with the matching Entity ID will go into bed mode.</para>
/// <para>This Packet is sent to all nearby players including the one sent to bed.</para>
/// <para>Entity ID VarInt Player ID</para>
/// <para>Location Position Block location of the head part of the bed</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_USE_BED = 0x0A;
/// <summary>
/// <para>This packet tells that a player goes to bed.</para>
/// <para>This packet is sent by the server when a player comes into visible range, not when a player joins.</para>
/// <para>Servers can, however, safely spawn player entities for players not in visible range. The client appears to handle it correctly.</para>
/// <para>When in online-mode the uuids must be valid and have valid skin blobs, in offline-mode uuid v3 is used.</para>
/// <para>For NPCs UUID v2 should be used. Note:</para>
/// <para>(+Grum) i will never confirm this as a feature you know that :)</para>
/// <para>Entity ID VarInt Player's Entity ID</para>
/// <para>Player UUID UUID Player's UUID</para>
/// <para>X Int Player X as a Fixed-Point number</para>
/// <para>Y Int Player X as a Fixed-Point number</para>
/// <para>Z Int Player X as a Fixed-Point number</para>
/// <para>Yaw Byte Player rotation as a packed byte</para>
/// <para>Pitch Byte Player rotation as a packet byte</para>
/// <para>Current Item Short The item the player is currently holding. Note that this should be 0 for "no item", unlike -1 used in other packets. A negative value crashes clients.</para>
/// <para>Metadata Metadata The client will crash if no metadata is sent</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_SPAWN_PLAYER = 0x0C;
/// <summary>
/// <para>This packet tells that a player goes to bed.</para>
/// <para>Sent by the server when someone picks up an item lying on the ground - its sole purpose appears to be the animation of the item flying towards you. It doesn't destroy the entity in the client memory, and it doesn't add it to your inventory. The server only checks for items to be picked up after each Player Position and [Player Position & Look packet sent by the client.</para>
/// <para>Collected Entity ID VarInt</para>
/// <para>Collector Entity ID VarInt</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_COLLECT_ITEM = 0x0A;
/// <summary>
/// <para>This packet shows location, name, and type of painting.</para>
/// <para>Calculating the center of an image: given a (width x height) grid of cells, with (0, 0) being the top left corner, the center is (max(0, width / 2 - 1), height / 2). E.g.</para>
/// <para>2x1 (1, 0) 4x4 (1, 2)</para>
/// <para>Entity ID VarInt Entity's ID</para>
/// <para>Title String Name of the painting. Max length 13</para>
/// <para>Location Position Center coordinates</para>
/// <para>Direction Unsigned Byte Direction the painting faces (0 -z, 1 -x, 2 +z, 3 +x)</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_SPAWN_PAINTING = 0x10;
/// <summary>
/// <para>Velocity is believed to be in units of 1/8000 of a block per server tick (50ms); for example, -1343 would move (-1343 / 8000) = 0.167875 blocks per tick (or 3,3575 blocks per second).</para>
/// <para>Entity ID VarInt Entity's ID</para>
/// <para>Velocity X Short Velocity on the X axis</para>
/// <para>Velocity Y Short Velocity on the Y axis</para>
/// <para>Velocity Z Short Velocity on the Z axis</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_ENTITY_VELOCITY = 0x12;
/// <summary>
/// <para>Sent by the server when an list of Entities is to be destroyed on the client.</para>
/// <para>Entity ID VarInt Entity's ID</para>
/// <para>Count VarInt Length of following array</para>
/// <para>Entity IDs Array of VarInt The list of entities of destroy</para>
/// </summary>
public static readonly byte PLAY_TOCLIENT_DESTROY_ENTITIES = 0x13;
public PCPackets(byte packetid, object[] data, Socket sock)
{
var tmp=new List<byte>();
tmp.Add(packetid);
for(int i=0; i<data.Length; i++)
{
if (data.GetType() == typeof(bool))
tmp.AddRange(BitConverter.GetBytes((bool)data[i]));
else if (data.GetType() == typeof(char))
tmp.AddRange(BitConverter.GetBytes((char)data[i]));
else if (data.GetType() == typeof(double))
tmp.AddRange(BitConverter.GetBytes((double)data[i]));
else if (data.GetType() == typeof(float))
tmp.AddRange(BitConverter.GetBytes((float)data[i]));
else if (data.GetType() == typeof(int))
tmp.AddRange(BitConverter.GetBytes((int)data[i]));
else if (data.GetType() == typeof(long))
tmp.AddRange(BitConverter.GetBytes((long)data[i]));
else if (data.GetType() == typeof(short))
tmp.AddRange(BitConverter.GetBytes((short)data[i]));
else if (data.GetType() == typeof(uint))
tmp.AddRange(BitConverter.GetBytes((uint)data[i]));
else if (data.GetType() == typeof(ulong))
tmp.AddRange(BitConverter.GetBytes((ushort)data[i]));
else if (data.GetType() == typeof(ushort))
tmp.AddRange(BitConverter.GetBytes((ushort)data[i]));
}
sock.Send(tmp.ToArray());
}
}
}

View file

@ -1,168 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace Connection_forwarder
{
class PEPackets
{
public static readonly byte[] MAGIC = new byte[16] { 0, 255, 255, 0, 254, 254, 254, 254, 253, 253, 253, 253, 18, 52, 86, 120 };
public const byte ProtocolVer = 5;
/// <summary>
/// <para>Sent when the server doesn't support the RakNet protocol specified in 0x05.</para>
/// <para>Protocol Version byte 5 </para>
/// <para>MAGIC MAGIC </para>
/// <para>Server ID int64 0x00000000372cdc9e </para>
/// </summary>
public static readonly byte TOCLIENT_ID_INCOMPATIBLE_PROTOCOL_VERSION = 0x1A;
/// <summary>
/// <para>If the version is different than yours, reply with a ID_INCOMPATIBLE_PROTOCOL_VERSION (0x1A)</para>
/// <para>Sent from the client after the player taps on the server in the world list The client will repeatedly send this with reducing sizes until it successfully receives a reply. Observed behaviour is that the client will send packets ~0.5s apart in the following way, until it gets a 0x06 response packet, or reaches the end of these:</para>
/// <para>4 packets of Null Payload length of 1447</para>
/// <para>4 packets of Null Payload length of 1155</para>
/// <para>5 packets of Null Payload length of 531</para>
/// <para>If the server doesnt't reply the client, the client will display a "Connect Error" window</para>
/// <para>MAGIC MAGIC </para>
/// <para>RakNet Protocol Version byte 5 Check the Data Packet section for the current version</para>
/// <para>Null Payload many 0x00 bytes 0x00 * 1447 MTU (Maximum Transport Unit)</para>
/// <para>Total Size: 18 Bytes + length of Null Payload</para>
/// </summary>
public static readonly byte TOSERVER_ID_OPEN_CONNECTION_REQUEST_1 = 0x05;
public static readonly byte TOCLIENT_ID_OPEN_CONNECTION_REPLY_1 = 0x06;
public static readonly byte TOSERVER_ID_OPEN_CONNECTION_REQUEST_2 = 0x07;
public static readonly byte TOCLIENT_ID_OPEN_CONNECTION_REPLY_2 = 0x08;
public static readonly byte TOSERVER_ReadyPacket = 0x84;
public static readonly byte TOCLIENT_LoginStatusPacket = 0x83;
public PEPackets(byte packetid, object[] data, UdpClient sock, IPEndPoint ep)
{
var tmp = new List<byte>();
tmp.Add(packetid);
for (int i = 0; i < data.Length; i++)
{
if (!data[i].GetType().IsSubclassOf(typeof(Array)))
{
if (data[i].GetType() == typeof(byte))
tmp.Add((byte)data[i]);
else if (data[i].GetType() == typeof(bool))
tmp.AddRange(BitConverter.GetBytes((bool)data[i]));
else if (data[i].GetType() == typeof(char))
tmp.AddRange(BitConverter.GetBytes((char)data[i]));
else if (data[i].GetType() == typeof(short))
tmp.AddRange(BitConverter.GetBytes((short)data[i]));
else if (data[i].GetType() == typeof(int))
tmp.AddRange(BitConverter.GetBytes((int)data[i]));
else if (data[i].GetType() == typeof(long))
tmp.AddRange(BitConverter.GetBytes((long)data[i]));
else if (data[i].GetType() == typeof(double))
tmp.AddRange(BitConverter.GetBytes((double)data[i]));
else if (data[i].GetType() == typeof(float))
tmp.AddRange(BitConverter.GetBytes((float)data[i]));
else if (data[i].GetType() == typeof(uint))
tmp.AddRange(BitConverter.GetBytes((uint)data[i]));
else if (data[i].GetType() == typeof(ulong))
tmp.AddRange(BitConverter.GetBytes((ushort)data[i]));
else if (data[i].GetType() == typeof(ushort))
tmp.AddRange(BitConverter.GetBytes((ushort)data[i]));
}
else
{
for (int j = 0; j < ((Array)data[i]).Length; j++)
{
if (((Array)data[i]).GetValue(j).GetType() == typeof(byte))
tmp.Add((byte)((Array)data[i]).GetValue(j));
else if (((Array)data[i]).GetValue(j).GetType() == typeof(bool))
tmp.AddRange(BitConverter.GetBytes((bool)((Array)data[i]).GetValue(j)));
else if (((Array)data[i]).GetValue(j).GetType() == typeof(char))
tmp.AddRange(BitConverter.GetBytes((char)((Array)data[i]).GetValue(j)));
else if (((Array)data[i]).GetValue(j).GetType() == typeof(double))
tmp.AddRange(BitConverter.GetBytes((double)((Array)data[i]).GetValue(j)));
else if (((Array)data[i]).GetValue(j).GetType() == typeof(float))
tmp.AddRange(BitConverter.GetBytes((float)((Array)data[i]).GetValue(j)));
else if (((Array)data[i]).GetValue(j).GetType() == typeof(int))
tmp.AddRange(BitConverter.GetBytes((int)((Array)data[i]).GetValue(j)));
else if (((Array)data[i]).GetValue(j).GetType() == typeof(long))
tmp.AddRange(BitConverter.GetBytes((long)((Array)data[i]).GetValue(j)));
else if (((Array)data[i]).GetValue(j).GetType() == typeof(short))
tmp.AddRange(BitConverter.GetBytes((short)((Array)data[i]).GetValue(j)));
else if (((Array)data[i]).GetValue(j).GetType() == typeof(uint))
tmp.AddRange(BitConverter.GetBytes((uint)((Array)data[i]).GetValue(j)));
else if (((Array)data[i]).GetValue(j).GetType() == typeof(ulong))
tmp.AddRange(BitConverter.GetBytes((ushort)((Array)data[i]).GetValue(j)));
else if (((Array)data[i]).GetValue(j).GetType() == typeof(ushort))
tmp.AddRange(BitConverter.GetBytes((ushort)((Array)data[i]).GetValue(j)));
else Console.WriteLine("Unknown type in array: " + ((Array)data[i]).GetValue(j).GetType());
}
}
}
try
{
sock.Send(tmp.ToArray(), tmp.Count, ep);
}
catch
{
sock.Send(tmp.ToArray(), tmp.Count);
}
}
internal static Int64 GetClientID(byte[] buffer)
{ //ClientID is in open connection request 2 and in data packets
switch(buffer[0])
{
case 0x84:
byte[] tmp = new byte[8];
Array.Copy(buffer, 17, tmp, 0, 8);
return BitConverter.ToInt64(tmp, 0);
default:
Console.WriteLine("Unable to get ClientID: " + buffer);
return 0;
}
}
public static object[] DecodeDataPacket(byte[] data)
{
byte[] tmp;
//Array.Copy(data, 1, tmp = new byte[4], 1, 3); //Leave the first byte 0 so it will (hopefully) give the correct 4-bit representation
Array.Copy(data, 1, tmp = new byte[4], 0, 3); //Nope, it starts at the first byte
int Count = BitConverter.ToInt32(tmp, 0);
byte EncapsulationID = data[4];
short length;
int Count2;
int Unknown;
switch(EncapsulationID)
{
case 0x00:
length = BitConverter.ToInt16(data, 5);
Array.Copy(data, 7, tmp=new byte[data.Length-8], 0, data.Length-8); //7. byte: data +1
return new object[] { EncapsulationID, Count, length, tmp };
case 0x40:
length = BitConverter.ToInt16(data, 5);
Array.Copy(data, 7, tmp = new byte[4], 0, 3); //7. byte: Count(?)
Count2 = BitConverter.ToInt32(tmp, 0);
Array.Copy(data, 10, tmp=new byte[data.Length-11], 0, data.Length - 11); //10. byte: data + Count +1
return new object[] { EncapsulationID, Count, length, Count2, tmp };
case 0x60:
length = BitConverter.ToInt16(data, 5);
Array.Copy(data, 7, tmp = new byte[4], 0, 3); //7. byte: Count(?)
Count2 = BitConverter.ToInt32(tmp, 0);
Unknown = BitConverter.ToInt32(data, 10); //10. byte: Unknown
Array.Copy(data, 14, tmp=new byte[data.Length-15], 0, data.Length - 15); //14. byte: data +1
return new object[] { EncapsulationID, Count, length, Count2, tmp };
default:
return null;
}
}
public static byte[] IntTo3Byte(int i)
{
byte[] tmp = BitConverter.GetBytes(i);
byte[] ret = new byte[3];
//Array.Copy(tmp, 1, ret, 0, 3);
Array.Copy(tmp, 0, ret, 0, 3);
return ret;
}
}
}

View file

@ -14,12 +14,9 @@ namespace Connection_forwarder
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
[STAThread]
static void Main() static void Main()
{ {
Application.EnableVisualStyles(); Console.WriteLine(":P");
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
} }
public static IPAddress GetLocalIP() public static IPAddress GetLocalIP()
{ {
@ -35,10 +32,5 @@ namespace Connection_forwarder
} }
return localIP; return localIP;
} }
/// <summary>
//// Int64: ClientID
/// IP
/// </summary>
public static Dictionary<IPEndPoint, Object[]> ConnThreads = new Dictionary<IPEndPoint, Object[]>();
} }
} }