Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Silv3rPRO committed Jun 11, 2016
1 parent 48bd5ef commit e2816ed
Show file tree
Hide file tree
Showing 89 changed files with 16,719 additions and 0 deletions.
Binary file added Assets/message.wav
Binary file not shown.
161 changes: 161 additions & 0 deletions BrightNetwork/BrightClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
using System;
using System.Net;
using System.Net.Sockets;

namespace BrightNetwork
{
public class BrightClient
{
public event Action Connected;
public event Action<Exception> Disconnected;
public event Action<byte[]> DataReceived;

public bool IsConnected { get; private set; }

public IPAddress RemoteIPAddress
{
get { return _endPoint.Address; }
}

private Socket _socket;
private IPEndPoint _endPoint;
private bool _isClosed;
private byte[] _receiveBuffer;

public BrightClient()
{
_receiveBuffer = new byte[4096];
}

public BrightClient(Socket socket)
{
_receiveBuffer = new byte[4096];
Initialize(socket);
}

public void Initialize(Socket socket)
{
_endPoint = (IPEndPoint)socket.RemoteEndPoint;
_socket = socket;
IsConnected = true;
Connected?.Invoke();
BeginReceive();
}

public void BeginConnect(IPAddress address, int port)
{
if (!IsConnected && !_isClosed)
{
IsConnected = true;
try
{
_endPoint = new IPEndPoint(address, port);
_socket = new Socket(_endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
_socket.BeginConnect(_endPoint, new AsyncCallback(ConnectCallback), null);
}
catch (Exception ex)
{
Close(ex);
}
}
}

public void BeginSend(byte[] data)
{
try
{
_socket.BeginSend(data, 0, data.Length, SocketFlags.None, SendCallback, data.Length);
}
catch (Exception ex)
{
Close(ex);
}
}

public void Close(Exception error = null)
{
if (!_isClosed)
{
_isClosed = true;
try
{
if (_socket != null)
{
_socket.Close();
}
}
catch (Exception ex)
{
ex = new AggregateException(error, ex);
}
Disconnected?.Invoke(error);
}
}

private void BeginReceive()
{
try
{
_socket.BeginReceive(_receiveBuffer, 0, _receiveBuffer.Length, SocketFlags.None, ReceiveCallback, null);
}
catch (Exception ex)
{
Close(ex);
}
}

private void ConnectCallback(IAsyncResult result)
{
try
{
_socket.EndConnect(result);
}
catch (Exception ex)
{
Close(ex);
return;
}
Connected?.Invoke();
BeginReceive();
}

private void SendCallback(IAsyncResult result)
{
try
{
int bytesSent = _socket.EndSend(result);
if (bytesSent != (int)result.AsyncState)
{
Close();
}
}
catch (Exception ex)
{
Close(ex);
}
}

private void ReceiveCallback(IAsyncResult result)
{
int bytesRead;
try
{
bytesRead = _socket.EndReceive(result);
}
catch (Exception ex)
{
Close(ex);
return;
}
if (bytesRead == 0)
{
Close();
return;
}
byte[] data = new byte[bytesRead];
Array.Copy(_receiveBuffer, data, bytesRead);
DataReceived?.Invoke(data);
BeginReceive();
}
}
}
56 changes: 56 additions & 0 deletions BrightNetwork/BrightNetwork.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F6F45690-9361-4DA4-8A8A-18D782E29752}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BrightNetwork</RootNamespace>
<AssemblyName>BrightNetwork</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BrightClient.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SimpleTextClient.cs" />
<Compile Include="SocksConnection.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
36 changes: 36 additions & 0 deletions BrightNetwork/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("BrightNetwork")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BrightNetwork")]
[assembly: AssemblyCopyright("Copyright © Silv3r, 2016-2032")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f6f45690-9361-4da4-8a8a-18d782e29752")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit e2816ed

Please sign in to comment.