many changes
that didn't add up to much
This commit is contained in:
parent
6cfb66a2b3
commit
2524d88561
18 changed files with 244 additions and 30 deletions
17
client/src/Connection.ts
Normal file
17
client/src/Connection.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
class Connection {
|
||||
private static Sock: WebSocket = null;
|
||||
private static _IsOpen: boolean = false;
|
||||
public static get IsOpen(): boolean {
|
||||
return Connection._IsOpen;
|
||||
}
|
||||
|
||||
public static Initialize(): void {
|
||||
Connection.Sock
|
||||
}
|
||||
|
||||
public static Close(): void {
|
||||
|
||||
}
|
||||
|
||||
private static
|
||||
}
|
0
client/src/Crypto.ts
Normal file
0
client/src/Crypto.ts
Normal file
140
client/src/Extensions.ts
Normal file
140
client/src/Extensions.ts
Normal file
|
@ -0,0 +1,140 @@
|
|||
/// <reference path="def/UTF8.d.ts" />
|
||||
|
||||
// ** STRING EXTENSIONS ** \\
|
||||
|
||||
interface String {
|
||||
ReplaceAll(needle: string[], replace: string, ignoreCase?: boolean): string;
|
||||
ReplaceAll(needle: string[], replace: string[], ignoreCase?: boolean): string;
|
||||
ReplaceAll(needle: string, replace: string, ignoreCase?: boolean): string;
|
||||
Contains(needle: string, ignoreCase?: boolean): boolean;
|
||||
|
||||
StripCharacters(chars: string): string;
|
||||
|
||||
HasUnicodeCharacters(): boolean;
|
||||
ToByteArray(): Uint8Array;
|
||||
ByteLength(): number;
|
||||
}
|
||||
|
||||
String.prototype.ReplaceAll = function(needle: any, replace: any, ignoreCase: boolean = false): string {
|
||||
if((typeof needle) == "string")
|
||||
return this.replace(new RegExp(needle.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignoreCase?"gi":"g")),(typeof(replace)=="string")?replace.replace(/\$/g,"$$$$"):replace);
|
||||
else {
|
||||
var retval = this;
|
||||
for(var i in needle) {
|
||||
if((typeof replace) == "string")
|
||||
retval = retval.replaceAll(needle[i], replace, ignoreCase);
|
||||
else
|
||||
retval = retval.replaceAll(needle[i], replace[i], ignoreCase);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
};
|
||||
|
||||
String.prototype.Contains = function(needle: string, ignoreCase: boolean = false): boolean {
|
||||
return ignoreCase
|
||||
? this.toLowerCase().indexOf(needle.toLowerCase()) != -1
|
||||
: this.indexOf(needle) != -1;
|
||||
};
|
||||
|
||||
String.prototype.StripCharacters = function(chars: string) {
|
||||
var copy = this;
|
||||
if(chars != "")
|
||||
copy = copy.replaceAll(chars.split(""), "");
|
||||
|
||||
return copy;
|
||||
};
|
||||
|
||||
String.prototype.HasUnicodeCharacters = function() {
|
||||
for(var i = 0; i < this.length; i++) {
|
||||
if(this.charCodeAt(i) > 127) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
String.prototype.ByteLength = function() {
|
||||
return utf8.encode(this).length;
|
||||
};
|
||||
|
||||
String.prototype.ToByteArray = function() {
|
||||
var str = utf8.encode(this);
|
||||
var ret = new Uint8Array(str.length);
|
||||
for(var i = 0; i < str.length; i++)
|
||||
ret[i] = str.charCodeAt(i);
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
// ** DATE EXTENSIONS ** \\
|
||||
|
||||
interface DateConstructor {
|
||||
unixNow(): number;
|
||||
}
|
||||
|
||||
interface Date {
|
||||
toUnixTime(): number;
|
||||
toDateTimeString(): string;
|
||||
}
|
||||
|
||||
Date.unixNow = function() {
|
||||
return (new Date()).toUnixTime();
|
||||
};
|
||||
|
||||
Date.prototype.toUnixTime = function() {
|
||||
return Math.floor(this.getTime()/1000);
|
||||
};
|
||||
|
||||
Date.prototype.toDateTimeString = function() {
|
||||
return this.toDateString() +" @ "+ this.getHours().zeroPad() +":"+ this.getMinutes().zeroPad() +":"+ this.getSeconds().zeroPad();
|
||||
};
|
||||
|
||||
Date.prototype.toTimeString = function() {
|
||||
return this.getHours().zeroPad() +":"+ this.getMinutes().zeroPad() +":"+ this.getSeconds().zeroPad();
|
||||
};
|
||||
|
||||
|
||||
// ** NUMBER EXTENSIONS ** \\
|
||||
|
||||
interface Number {
|
||||
zeroPad(mag?: number): string;
|
||||
packBytes(bytes: number): Uint8Array;
|
||||
}
|
||||
|
||||
Number.prototype.zeroPad = function(mag: number = 1): string {
|
||||
var ret = ""+ this;
|
||||
for(; this < Math.pow(10, mag) && mag != 0; --mag)
|
||||
ret = "0" + ret;
|
||||
return ret;
|
||||
};
|
||||
|
||||
Number.prototype.packBytes = function(bytes: number) {
|
||||
var ret = new Uint8Array(bytes);
|
||||
for(var i = 0; i < bytes; i++)
|
||||
ret[i] = (this & (0xFF << 8 * (bytes - 1 - i))) >>> 8 * (bytes - 1 - i);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
// ** UINT8ARRAY EXTENSIONS ** \\
|
||||
|
||||
interface Uint8Array {
|
||||
unpackBytes(): number;
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
Uint8Array.prototype.unpackBytes = function() {
|
||||
var ret = 0;
|
||||
for(var i = 0; i < this.length; i++)
|
||||
ret = ret | ((this[i] & 0xFF) << 8*(this.length - 1 - i));
|
||||
return ret;
|
||||
};
|
||||
|
||||
Uint8Array.prototype.toString = function() {
|
||||
var chunkSize = 10000;
|
||||
var raw = "";
|
||||
for(var i = 0;; i++) {
|
||||
if(this.length < chunkSize*i) break;
|
||||
raw += String.fromCharCode.apply(null, this.subarray(chunkSize*i, chunkSize*i + chunkSize));
|
||||
}
|
||||
return utf8.decode(raw);
|
||||
};
|
23
client/src/Packet.ts
Normal file
23
client/src/Packet.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
const enum kPacketId {
|
||||
KeyExchange = 0,
|
||||
LoginAttempt,
|
||||
RegistrationAttempt
|
||||
}
|
||||
|
||||
class Packet {
|
||||
private _Id: kPacketId;
|
||||
public get Id(): kPacketId {
|
||||
return this._Id;
|
||||
}
|
||||
|
||||
private _IsLegal: boolean = true;
|
||||
public get IsLegal(): boolean {
|
||||
return this._IsLegal;
|
||||
}
|
||||
|
||||
private Regions: Uint8Array[] = [];
|
||||
|
||||
public get RegionCount(): number {
|
||||
return this.Regions.length;
|
||||
}
|
||||
}
|
|
@ -38,6 +38,10 @@
|
|||
<PropertyGroup>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>
|
||||
</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26403.7
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CircleScape", "CircleScape.csproj", "{438DBAC1-BA37-40BB-9CCE-0FE1F23C6DC5}"
|
||||
EndProject
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace CircleScape.DAL
|
||||
namespace Server.DAL
|
||||
{
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace CircleScape.DAL
|
||||
namespace Server.DAL
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace CircleScape.DAL
|
||||
namespace Server.DAL
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
@ -3,34 +3,48 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Numerics;
|
||||
using Square;
|
||||
|
||||
namespace CircleScape.Encryption {
|
||||
namespace Server.Encryption {
|
||||
class Cipher {
|
||||
private byte[] Key = new byte[512 / 8];
|
||||
private byte[] State = new byte[256];
|
||||
|
||||
static void ksa(byte[] state, byte[] key) {
|
||||
int i, j = 0, t;
|
||||
for(i = 0; i < 256; ++i)
|
||||
state[i] = (byte)i;
|
||||
public Cipher(BigInteger key) {
|
||||
int i = 0, j = 0;
|
||||
State = State.Select(x => (byte)i++).ToArray();
|
||||
Key = Key.Select(x => (byte)0).ToArray();
|
||||
Array.Copy(key.ToByteArray(), Key, Key.Length);
|
||||
|
||||
for(i = 0; i < 256; ++i) {
|
||||
j = (j + state[i] + key[i % key.Length]) % 256;
|
||||
t = state[i];
|
||||
state[i] = state[j];
|
||||
state[j] = (byte)t;
|
||||
for(i = 0; i < State.Length; ++i) {
|
||||
j = (j + State[i] + Key[i % Key.Length]) % 256;
|
||||
Utils.Swap(ref State[i], ref State[j]);
|
||||
}
|
||||
|
||||
GenerateStream(1024);
|
||||
}
|
||||
|
||||
static void prga(byte[] state, byte[] cipher) {
|
||||
int i = 0, j = 0, x, t;
|
||||
private byte[] GenerateStream(long length) {
|
||||
var stream = new byte[length];
|
||||
int i = 0, j = 0;
|
||||
|
||||
for(x = 0; x < cipher.Length; ++x) {
|
||||
for(long x = 0; x < length; ++x) {
|
||||
i = (i + 1) % 256;
|
||||
j = (j + state[i]) % 256;
|
||||
t = state[i];
|
||||
state[i] = state[j];
|
||||
state[j] = (byte)t;
|
||||
cipher[x] = state[(state[i] + state[j]) % 256];
|
||||
j = (j + State[i]) % 256;
|
||||
Utils.Swap(ref State[i], ref State[j]);
|
||||
stream[x] = State[(State[i] + State[j]) % 256];
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
public byte[] Parse(byte[] data) {
|
||||
var stream = GenerateStream(data.LongLength);
|
||||
for(long i = 0; i < data.LongLength; ++i)
|
||||
data[i] ^= stream[i];
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||
using System.Numerics;
|
||||
using Square;
|
||||
|
||||
namespace CircleScape.Encryption {
|
||||
namespace Server.Encryption {
|
||||
class KeyExchange {
|
||||
private BigInteger Secret;
|
||||
public BigInteger Generator { get; private set; } = 2;
|
||||
|
|
|
@ -4,11 +4,11 @@ using System.Data.SQLite;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CircleScape.DAL;
|
||||
using Server.DAL;
|
||||
using System.Numerics;
|
||||
using Square;
|
||||
|
||||
namespace CircleScape {
|
||||
namespace Server {
|
||||
class Entrypoint {
|
||||
static void Main(string[] args) {
|
||||
var server = new Kneesocks.Server<PendingConnection>(6770, PoolManager.Pending);
|
||||
|
|
15
server/Libraries/Square/General.cs
Normal file
15
server/Libraries/Square/General.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Square {
|
||||
public static class Utils {
|
||||
public static void Swap<T>(ref T a, ref T b) {
|
||||
T c = a;
|
||||
a = b;
|
||||
b = c;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="ArrayExtensions.cs" />
|
||||
<Compile Include="CryptoExtensions.cs" />
|
||||
<Compile Include="General.cs" />
|
||||
<Compile Include="NumericExtensions.cs" />
|
||||
<Compile Include="RandomContext.cs" />
|
||||
<Compile Include="StringExtensions.cs" />
|
||||
|
|
|
@ -5,7 +5,7 @@ using System.Net.Sockets;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CircleScape {
|
||||
namespace Server {
|
||||
class ActiveConnection : Kneesocks.Connection {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using Square;
|
||||
|
||||
namespace CircleScape {
|
||||
namespace Server {
|
||||
class Packet {
|
||||
public enum kId {
|
||||
KeyExchange = 0,
|
||||
|
|
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||
using Square;
|
||||
using Kneesocks;
|
||||
|
||||
namespace CircleScape {
|
||||
namespace Server {
|
||||
class PendingConnection : Connection {
|
||||
private DateTime ConnectionOpened;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||
using Kneesocks;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace CircleScape {
|
||||
namespace Server {
|
||||
static class PoolManager {
|
||||
private static Pool<PendingConnection> PendingConnectionsPool;
|
||||
private static Pool<ActiveConnection> ActiveConnectionsPool;
|
||||
|
|
Loading…
Reference in a new issue