wow i hope my database password doesn't show up
woomy
This commit is contained in:
parent
8867c3051a
commit
22f4a8f702
17 changed files with 273 additions and 73 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -304,3 +304,4 @@ $RECYCLE.BIN/
|
||||||
|
|
||||||
# Windows shortcuts
|
# Windows shortcuts
|
||||||
*.lnk
|
*.lnk
|
||||||
|
server/config.ini
|
||||||
|
|
99
protocol.md
99
protocol.md
|
@ -36,6 +36,8 @@ All numbers, unless otherwise specified, are the string representation of a base
|
||||||
|
|
||||||
A packet ID may have a specific "direction" of communication, in that an endpoint may either act as a _requester_ or a _responder_. A _requester_ is an endpoint that drives all of the communication on that specific packet ID, while the _responder_ is responsible for providing a timely response to the requests it receives. A _responder_ for a specific packet ID should never send that packet ID unsolicited; either the packet will be ignored or the other endpoint will close the connection. Any packet ID marked as bidirectional may be initiated by either endpoint at any time.
|
A packet ID may have a specific "direction" of communication, in that an endpoint may either act as a _requester_ or a _responder_. A _requester_ is an endpoint that drives all of the communication on that specific packet ID, while the _responder_ is responsible for providing a timely response to the requests it receives. A _responder_ for a specific packet ID should never send that packet ID unsolicited; either the packet will be ignored or the other endpoint will close the connection. Any packet ID marked as bidirectional may be initiated by either endpoint at any time.
|
||||||
|
|
||||||
|
A _blind requester_ is an endpoint that sends out a packet of a certain ID and either does not expect a response or expects a response on a different packet ID.
|
||||||
|
|
||||||
#### Server to Client
|
#### Server to Client
|
||||||
|
|
||||||
TODO: populate
|
TODO: populate
|
||||||
|
@ -59,7 +61,80 @@ Communication between the master server and clients will be done over a WebSocke
|
||||||
<table style="margin-right: 8px; margin-bottom: 8px;">
|
<table style="margin-right: 8px; margin-bottom: 8px;">
|
||||||
<thead>
|
<thead>
|
||||||
<th colspan="100" class="center">
|
<th colspan="100" class="center">
|
||||||
ID 0: Key Exchange<br />
|
ID 1: Key Exchange<br />
|
||||||
|
Requester (resp. StM ID 0)
|
||||||
|
</th>
|
||||||
|
</thead>
|
||||||
|
<thead>
|
||||||
|
<th>#</th>
|
||||||
|
<th>Region</th>
|
||||||
|
<th>Type</th>
|
||||||
|
</thead>
|
||||||
|
<tr>
|
||||||
|
<td>1</td>
|
||||||
|
<td>Generator</td>
|
||||||
|
<td>Big Int</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>2</td>
|
||||||
|
<td>Modulus</td>
|
||||||
|
<td>Big Int</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>3</td>
|
||||||
|
<td>Server Key</td>
|
||||||
|
<td>Big Int</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
#### Slave to Master
|
||||||
|
|
||||||
|
<table style="margin-right: 8px; margin-bottom: 8px;">
|
||||||
|
<thead>
|
||||||
|
<th colspan="100" class="center">
|
||||||
|
ID 0: Initiation Attempt<br />
|
||||||
|
Blind Requester
|
||||||
|
</th>
|
||||||
|
</thead>
|
||||||
|
<thead>
|
||||||
|
<th>#</th>
|
||||||
|
<th>Region</th>
|
||||||
|
<th>Type</th>
|
||||||
|
</thead>
|
||||||
|
<tr>
|
||||||
|
<td class="center">1</td>
|
||||||
|
<td>Secret</td>
|
||||||
|
<td>String</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table style="margin-right: 8px; margin-bottom: 8px;">
|
||||||
|
<thead>
|
||||||
|
<th colspan="100" class="center">
|
||||||
|
ID 1: Key Exchange<br />
|
||||||
|
Responder
|
||||||
|
</th>
|
||||||
|
</thead>
|
||||||
|
<thead>
|
||||||
|
<th>#</th>
|
||||||
|
<th>Region</th>
|
||||||
|
<th>Type</th>
|
||||||
|
</thead>
|
||||||
|
<tr>
|
||||||
|
<td class="center">1</td>
|
||||||
|
<td>Client Key</td>
|
||||||
|
<td>Big Int</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
### Master/Client Packet IDs
|
||||||
|
|
||||||
|
#### Master to Client
|
||||||
|
|
||||||
|
<table style="margin-right: 8px; margin-bottom: 8px;">
|
||||||
|
<thead>
|
||||||
|
<th colspan="100" class="center">
|
||||||
|
ID 1: Key Exchange<br />
|
||||||
Requester
|
Requester
|
||||||
</th>
|
</th>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -88,7 +163,7 @@ Communication between the master server and clients will be done over a WebSocke
|
||||||
<table style="margin-right: 8px; margin-bottom: 8px;">
|
<table style="margin-right: 8px; margin-bottom: 8px;">
|
||||||
<thead>
|
<thead>
|
||||||
<th colspan="100" class="center">
|
<th colspan="100" class="center">
|
||||||
ID 1: Login Attempt<br />
|
ID 2: Login Attempt<br />
|
||||||
[Encrypted] Responder
|
[Encrypted] Responder
|
||||||
</th>
|
</th>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -112,7 +187,7 @@ Communication between the master server and clients will be done over a WebSocke
|
||||||
<table style="margin-right: 8px; margin-bottom: 8px;">
|
<table style="margin-right: 8px; margin-bottom: 8px;">
|
||||||
<thead>
|
<thead>
|
||||||
<th colspan="100" class="center">
|
<th colspan="100" class="center">
|
||||||
ID 2: Registration Attempt<br />
|
ID 3: Registration Attempt<br />
|
||||||
[Encrypted] Responder
|
[Encrypted] Responder
|
||||||
</th>
|
</th>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -133,12 +208,12 @@ Communication between the master server and clients will be done over a WebSocke
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
#### Slave to Master
|
#### Client to Master
|
||||||
|
|
||||||
<table style="margin-right: 8px; margin-bottom: 8px;">
|
<table style="margin-right: 8px; margin-bottom: 8px;">
|
||||||
<thead>
|
<thead>
|
||||||
<th colspan="100" class="center">
|
<th colspan="100" class="center">
|
||||||
ID 0: Key Exchange<br />
|
ID 1: Key Exchange<br />
|
||||||
Responder
|
Responder
|
||||||
</th>
|
</th>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -149,15 +224,15 @@ Communication between the master server and clients will be done over a WebSocke
|
||||||
</thead>
|
</thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="center">1</td>
|
<td class="center">1</td>
|
||||||
<td>Client Key</td>
|
<td>Secret</td>
|
||||||
<td>Big Int</td>
|
<td>String</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<table style="margin-right: 8px; margin-bottom: 8px;">
|
<table style="margin-right: 8px; margin-bottom: 8px;">
|
||||||
<thead>
|
<thead>
|
||||||
<th colspan="100" class="center">
|
<th colspan="100" class="center">
|
||||||
ID 1: Login Attempt<br />
|
ID 2: Login Attempt<br />
|
||||||
[Encrypted] Requester
|
[Encrypted] Requester
|
||||||
</th>
|
</th>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -181,7 +256,7 @@ Communication between the master server and clients will be done over a WebSocke
|
||||||
<table style="margin-right: 8px; margin-bottom: 8px;">
|
<table style="margin-right: 8px; margin-bottom: 8px;">
|
||||||
<thead>
|
<thead>
|
||||||
<th colspan="100" class="center">
|
<th colspan="100" class="center">
|
||||||
ID 2: Registration Attempt<br />
|
ID 3: Registration Attempt<br />
|
||||||
[Encrypted] Requester
|
[Encrypted] Requester
|
||||||
</th>
|
</th>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -207,12 +282,6 @@ Communication between the master server and clients will be done over a WebSocke
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
### Master/Client Packet IDs
|
|
||||||
|
|
||||||
#### Master to Client
|
|
||||||
|
|
||||||
#### Client to Master
|
|
||||||
|
|
||||||
## Sockstamps
|
## Sockstamps
|
||||||
|
|
||||||
Because epoch time is not standardized across systems, an intermediate layer of date/time transmission must be used between the client and server so as to handle time dependent interactions. Therefore, a "sockstamp" will be used in place of the context-dependent implementations of epoch time.
|
Because epoch time is not standardized across systems, an intermediate layer of date/time transmission must be used between the client and server so as to handle time dependent interactions. Therefore, a "sockstamp" will be used in place of the context-dependent implementations of epoch time.
|
||||||
|
|
34
server/2config.ini
Normal file
34
server/2config.ini
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[General]
|
||||||
|
; determines if this server instance should run the master server
|
||||||
|
Run Master = false
|
||||||
|
|
||||||
|
; address and port of the master server
|
||||||
|
;; if master server is in this instance, addr should be localhost
|
||||||
|
;; and port determines what port the master server runs on
|
||||||
|
Master Addr = localhost
|
||||||
|
Master Port = 16670
|
||||||
|
|
||||||
|
; this value used if the max users isn't specified in a server instance
|
||||||
|
Max Users = 100
|
||||||
|
|
||||||
|
; url to a web page that prints out the public ip address of the requester
|
||||||
|
Ip Checker = http://aroltd.com/ip.php
|
||||||
|
|
||||||
|
[Database]
|
||||||
|
Server = aroltd.com
|
||||||
|
Username = alec
|
||||||
|
Password = Buddyman5
|
||||||
|
Database = scape
|
||||||
|
|
||||||
|
[Server]
|
||||||
|
Id = 1
|
||||||
|
Port = 6770
|
||||||
|
Max Users = 300
|
||||||
|
|
||||||
|
[Server]
|
||||||
|
Id = 2
|
||||||
|
Port = 6780
|
||||||
|
|
||||||
|
[Server]
|
||||||
|
Id = 3
|
||||||
|
Port = 6790
|
|
@ -17,7 +17,6 @@
|
||||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||||
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
|
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
|
||||||
</entityFramework>
|
</entityFramework>
|
||||||
<connectionStrings configSource="connectionStrings.config" />
|
|
||||||
<runtime>
|
<runtime>
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
|
|
|
@ -24,6 +24,17 @@ namespace SockScape {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
new SectionRules {
|
||||||
|
Name = "Database",
|
||||||
|
Required = true,
|
||||||
|
RequiredFields = new string[] {
|
||||||
|
"Server",
|
||||||
|
"Username",
|
||||||
|
"Password",
|
||||||
|
"Database"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
new SectionRules {
|
new SectionRules {
|
||||||
Name = "Server",
|
Name = "Server",
|
||||||
AllowMultiple = true,
|
AllowMultiple = true,
|
||||||
|
@ -47,6 +58,12 @@ namespace SockScape {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Instance Database {
|
||||||
|
get {
|
||||||
|
return Settings["Database"][0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Section Servers {
|
public static Section Servers {
|
||||||
get {
|
get {
|
||||||
return Settings["Server"];
|
return Settings["Server"];
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
namespace SockScape.DAL {
|
using System;
|
||||||
using System;
|
using System.Data.Entity;
|
||||||
using System.Data.Entity;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.Linq;
|
||||||
using System.Linq;
|
using Config = SockScape.Configuration;
|
||||||
|
|
||||||
|
namespace SockScape.DAL {
|
||||||
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
|
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
|
||||||
public partial class ScapeDb : DbContext {
|
public partial class ScapeDb : DbContext {
|
||||||
static ScapeDb() {
|
static ScapeDb() {
|
||||||
|
@ -11,7 +12,11 @@ namespace SockScape.DAL {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScapeDb()
|
public ScapeDb()
|
||||||
: base("name=ScapeDbDebug")
|
: base("server="+ Config.Database["Server"]
|
||||||
|
+";user id="+ Config.Database["Username"]
|
||||||
|
+";password="+ Config.Database["Password"]
|
||||||
|
+";persistsecurityinfo=True;"
|
||||||
|
+"database="+ Config.Database["Database"])
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,21 +23,43 @@ namespace SockScape.Encryption {
|
||||||
|
|
||||||
public Packet GenerateRequestPacket() {
|
public Packet GenerateRequestPacket() {
|
||||||
return new Packet(
|
return new Packet(
|
||||||
Packet.kId.KeyExchange,
|
1,
|
||||||
Generator.ToHexString(),
|
Generator.ToHexString(),
|
||||||
Modulus.ToHexString(),
|
Modulus.ToHexString(),
|
||||||
BigInteger.ModPow(Generator, Secret, Modulus).ToHexString()
|
BigInteger.ModPow(Generator, Secret, Modulus).ToHexString()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Packet ParseRequestPacket(Packet packet) {
|
||||||
|
if(packet.Id != 1 || packet.RegionCount != 3)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
bool check = BigInteger.TryParse(packet[0], NumberStyles.HexNumber,
|
||||||
|
NumberFormatInfo.InvariantInfo, out BigInteger generator);
|
||||||
|
check &= BigInteger.TryParse(packet[1], NumberStyles.HexNumber,
|
||||||
|
NumberFormatInfo.InvariantInfo, out BigInteger modulus);
|
||||||
|
check &= BigInteger.TryParse(packet[2], NumberStyles.HexNumber,
|
||||||
|
NumberFormatInfo.InvariantInfo, out BigInteger serverKey);
|
||||||
|
|
||||||
|
if(!check)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var clientKey = BigInteger.ModPow(generator, Secret, modulus);
|
||||||
|
PrivateKey = BigInteger.ModPow(serverKey, Secret, modulus);
|
||||||
|
return new Packet(
|
||||||
|
1,
|
||||||
|
clientKey.ToHexString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public BigInteger ParseResponsePacket(Packet packet) {
|
public BigInteger ParseResponsePacket(Packet packet) {
|
||||||
if(packet.Id != Packet.kId.KeyExchange || packet.RegionCount != 1)
|
if(packet.Id != 1 || packet.RegionCount != 1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if(!BigInteger.TryParse(packet[0], NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out BigInteger ClientKey))
|
if(!BigInteger.TryParse(packet[0], NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out BigInteger clientKey))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return (PrivateKey = BigInteger.ModPow(ClientKey, Secret, Modulus));
|
return (PrivateKey = BigInteger.ModPow(clientKey, Secret, Modulus));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,6 @@ namespace SockScape {
|
||||||
servers.Add(server["Id"], new Server<PlayerConnection>((ushort)server["Port"], pool, server));
|
servers.Add(server["Id"], new Server<PlayerConnection>((ushort)server["Port"], pool, server));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//var server = new Server<PlayerConnection>(6770, PoolManager.Pending);
|
//var server = new Server<PlayerConnection>(6770, PoolManager.Pending);
|
||||||
//server.Start();
|
//server.Start();
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<ProjectGuid>{438DBAC1-BA37-40BB-9CCE-0FE1F23C6DC5}</ProjectGuid>
|
<ProjectGuid>{438DBAC1-BA37-40BB-9CCE-0FE1F23C6DC5}</ProjectGuid>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>CircleScape</RootNamespace>
|
<RootNamespace>SockScape</RootNamespace>
|
||||||
<AssemblyName>server</AssemblyName>
|
<AssemblyName>server</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
|
@ -87,7 +87,10 @@
|
||||||
<Compile Include="Socks\MasterConnection.cs" />
|
<Compile Include="Socks\MasterConnection.cs" />
|
||||||
<Compile Include="Socks\MasterUdpClient.cs" />
|
<Compile Include="Socks\MasterUdpClient.cs" />
|
||||||
<Compile Include="Socks\MasterUdpServer.cs" />
|
<Compile Include="Socks\MasterUdpServer.cs" />
|
||||||
<Compile Include="Socks\Packet.cs" />
|
<Compile Include="Socks\Protocols\ClientServerIds.cs" />
|
||||||
|
<Compile Include="Socks\Protocols\InterMasterIds.cs" />
|
||||||
|
<Compile Include="Socks\Protocols\IntraMasterIds.cs" />
|
||||||
|
<Compile Include="Socks\Protocols\Packet.cs" />
|
||||||
<Compile Include="Entrypoint.cs" />
|
<Compile Include="Entrypoint.cs" />
|
||||||
<Compile Include="Socks\PlayerConnection.cs" />
|
<Compile Include="Socks\PlayerConnection.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
@ -96,10 +99,6 @@
|
||||||
<None Include="App.config">
|
<None Include="App.config">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</None>
|
</None>
|
||||||
<None Include="connectionStrings.config">
|
|
||||||
<DependentUpon>App.config</DependentUpon>
|
|
||||||
<SubType>Designer</SubType>
|
|
||||||
</None>
|
|
||||||
<None Include="packages.config">
|
<None Include="packages.config">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<DependentUpon>App.config</DependentUpon>
|
<DependentUpon>App.config</DependentUpon>
|
||||||
|
|
|
@ -5,9 +5,54 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kneesocks;
|
using Kneesocks;
|
||||||
using Glove;
|
using Glove;
|
||||||
|
using SockScape.Encryption;
|
||||||
|
|
||||||
namespace SockScape.Socks {
|
namespace SockScape {
|
||||||
class MasterConnection : Connection {
|
class MasterConnection : Connection {
|
||||||
|
private Key Key;
|
||||||
|
public Cipher Encryptor { get; private set; } = null;
|
||||||
|
|
||||||
|
protected override void OnOpen() {
|
||||||
|
Key = new Key();
|
||||||
|
Send(Key.GenerateRequestPacket().GetBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnParse() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnReceive(byte[] data) {
|
||||||
|
Packet packet =
|
||||||
|
Encryptor == null ? Packet.FromBytes(data)
|
||||||
|
: Packet.FromBytes(Encryptor.Parse(data));
|
||||||
|
|
||||||
|
if(packet == null) {
|
||||||
|
Disconnect(Frame.kClosingReason.ProtocolError, "Packet received was not legal.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch((kInterMasterId)packet.Id) {
|
||||||
|
case kInterMasterId.KeyExchange:
|
||||||
|
Key.ParseResponsePacket(packet);
|
||||||
|
if(!Key.Succeeded) {
|
||||||
|
Disconnect(Frame.kClosingReason.ProtocolError, "Could not exchange keys.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Encryptor = new Cipher(Key.PrivateKey);
|
||||||
|
break;
|
||||||
|
case kInterMasterId.LoginAttempt:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case kInterMasterId.RegistrationAttempt:
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Disconnect(Frame.kClosingReason.ProtocolError, "Packet ID could not be understood at this time.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine(Id + " says " + data.GetString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace SockScape.Socks {
|
||||||
public static void Listener() {
|
public static void Listener() {
|
||||||
while(IsOpen) {
|
while(IsOpen) {
|
||||||
while(Sock.Available > 0) {
|
while(Sock.Available > 0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.Sleep(1);
|
Thread.Sleep(1);
|
||||||
|
|
|
@ -11,14 +11,9 @@ using SockScape.Encryption;
|
||||||
namespace SockScape {
|
namespace SockScape {
|
||||||
class PlayerConnection : Connection {
|
class PlayerConnection : Connection {
|
||||||
private DateTime ConnectionOpened;
|
private DateTime ConnectionOpened;
|
||||||
private Key Key;
|
|
||||||
public Cipher Encryptor { get; private set; } = null;
|
|
||||||
|
|
||||||
protected override void OnOpen() {
|
protected override void OnOpen() {
|
||||||
ConnectionOpened = DateTime.UtcNow;
|
ConnectionOpened = DateTime.UtcNow;
|
||||||
Key = new Key();
|
|
||||||
|
|
||||||
Send(Key.GenerateRequestPacket().GetBytes());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnParse() {
|
protected override void OnParse() {
|
||||||
|
@ -28,28 +23,14 @@ namespace SockScape {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnReceive(byte[] data) {
|
protected override void OnReceive(byte[] data) {
|
||||||
Packet packet =
|
Packet packet = Packet.FromBytes(data);
|
||||||
Encryptor == null ? Packet.FromBytes(data)
|
|
||||||
: Packet.FromBytes(Encryptor.Parse(data));
|
|
||||||
|
|
||||||
if(packet == null) {
|
if(packet == null) {
|
||||||
Disconnect(Frame.kClosingReason.ProtocolError, "Packet received was not legal.");
|
Disconnect(Frame.kClosingReason.ProtocolError, "Packet received was not legal.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(packet.Id) {
|
switch((kClientServerId)packet.Id) {
|
||||||
case Packet.kId.KeyExchange:
|
|
||||||
Key.ParseResponsePacket(packet);
|
|
||||||
if(!Key.Succeeded) {
|
|
||||||
Disconnect(Frame.kClosingReason.ProtocolError, "Could not exchange keys.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Encryptor = new Cipher(Key.PrivateKey);
|
|
||||||
break;
|
|
||||||
case Packet.kId.LoginAttempt:
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
Disconnect(Frame.kClosingReason.ProtocolError, "Packet ID could not be understood at this time.");
|
Disconnect(Frame.kClosingReason.ProtocolError, "Packet ID could not be understood at this time.");
|
||||||
break;
|
break;
|
||||||
|
|
11
server/Socks/Protocols/ClientServerIds.cs
Normal file
11
server/Socks/Protocols/ClientServerIds.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SockScape {
|
||||||
|
public enum kClientServerId {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
server/Socks/Protocols/InterMasterIds.cs
Normal file
13
server/Socks/Protocols/InterMasterIds.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SockScape {
|
||||||
|
public enum kInterMasterId {
|
||||||
|
KeyExchange = 1,
|
||||||
|
LoginAttempt,
|
||||||
|
RegistrationAttempt
|
||||||
|
}
|
||||||
|
}
|
12
server/Socks/Protocols/IntraMasterIds.cs
Normal file
12
server/Socks/Protocols/IntraMasterIds.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SockScape {
|
||||||
|
public enum kIntraMasterId {
|
||||||
|
InitiationAttempt = 0,
|
||||||
|
KeyExchange
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,24 +9,16 @@ namespace SockScape {
|
||||||
class Packet {
|
class Packet {
|
||||||
private static readonly byte[] MagicNumber = { 0xF0, 0x9F, 0xA6, 0x91 };
|
private static readonly byte[] MagicNumber = { 0xF0, 0x9F, 0xA6, 0x91 };
|
||||||
|
|
||||||
public enum kId {
|
|
||||||
KeyExchange = 0,
|
|
||||||
LoginAttempt,
|
|
||||||
RegistrationAttempt
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Packet FromBytes(byte[] raw) {
|
public static Packet FromBytes(byte[] raw) {
|
||||||
if(raw.Length < 7)
|
if(raw.Length < 7)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Packet packet = new Packet();
|
Packet packet = new Packet();
|
||||||
if(!Enum.IsDefined(typeof(kId), (int)raw[4]))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if(!raw.Subset(0, 4).SequenceEqual(MagicNumber))
|
if(!raw.Subset(0, 4).SequenceEqual(MagicNumber))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
packet.Id = (kId)raw[4];
|
packet.Id = raw[4];
|
||||||
var regionCount = raw[5];
|
var regionCount = raw[5];
|
||||||
var regionLengths = new List<uint>();
|
var regionLengths = new List<uint>();
|
||||||
var headerPtr = 6;
|
var headerPtr = 6;
|
||||||
|
@ -66,15 +58,14 @@ namespace SockScape {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<byte[]> Regions = new List<byte[]>();
|
private List<byte[]> Regions = new List<byte[]>();
|
||||||
public kId Id { get; private set; } = kId.KeyExchange;
|
public int Id { get; private set; }
|
||||||
public bool IsLegal { get; private set; } = true;
|
|
||||||
public int RegionCount {
|
public int RegionCount {
|
||||||
get => Regions.Count;
|
get => Regions.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Packet() { }
|
protected Packet() { }
|
||||||
|
|
||||||
public Packet(kId id, params object[] regions) {
|
public Packet(int id, params object[] regions) {
|
||||||
Id = id;
|
Id = id;
|
||||||
|
|
||||||
foreach(var region in regions)
|
foreach(var region in regions)
|
||||||
|
@ -95,9 +86,6 @@ namespace SockScape {
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] GetBytes() {
|
public byte[] GetBytes() {
|
||||||
if(!IsLegal)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var header = new List<byte>();
|
var header = new List<byte>();
|
||||||
header.AddRange(MagicNumber);
|
header.AddRange(MagicNumber);
|
||||||
header.Add((byte)Id);
|
header.Add((byte)Id);
|
|
@ -13,6 +13,12 @@ Master Port = 16670
|
||||||
|
|
||||||
; url to a web page that prints out the public ip address of the requester
|
; url to a web page that prints out the public ip address of the requester
|
||||||
Ip Checker = http://aroltd.com/ip.php
|
Ip Checker = http://aroltd.com/ip.php
|
||||||
|
|
||||||
|
[Database]
|
||||||
|
Server = aroltd.com
|
||||||
|
Username = alec
|
||||||
|
Password = Buddyman5
|
||||||
|
Database = scape
|
||||||
|
|
||||||
[Server]
|
[Server]
|
||||||
Id = 1
|
Id = 1
|
||||||
|
|
Loading…
Reference in a new issue