From 6ca8bade21fefa317f804f2c02010b827ac9cab5 Mon Sep 17 00:00:00 2001 From: Malloc of Kuzkycyziklistan Date: Mon, 22 May 2017 16:03:13 -0500 Subject: [PATCH] forgot to recompile lib.js do that at home --- client/lib/check.js | 2 +- client/src/Entrypoint.ts | 24 +++++++++++----------- client/src/Extensions.ts | 44 ++++++++++++++++++++-------------------- client/src/FileCache.ts | 22 ++++++++++---------- client/src/Packet.ts | 44 +++++++++++++++++++++++++++++++--------- client/src/Utilities.ts | 2 +- 6 files changed, 81 insertions(+), 57 deletions(-) diff --git a/client/lib/check.js b/client/lib/check.js index 4e6b280..fc57629 100644 --- a/client/lib/check.js +++ b/client/lib/check.js @@ -36,5 +36,5 @@ window.onload = function() { return; } - Entrypoint.Start(); + Entrypoint.start(); } diff --git a/client/src/Entrypoint.ts b/client/src/Entrypoint.ts index 3a30cbd..abc61bc 100644 --- a/client/src/Entrypoint.ts +++ b/client/src/Entrypoint.ts @@ -2,35 +2,35 @@ /// class Entrypoint { - private static InitStatus = { - FileCache: false + private static initStatus = { + fileCache: false } - private static InitCheck(): void { + private static initCheck(): void { var done = true; - for(var i in Entrypoint.InitStatus) - done = done && Entrypoint.InitStatus[i]; + for(var i in Entrypoint.initStatus) + done = done && Entrypoint.initStatus[i]; if(done) - Entrypoint.Initialized(); + Entrypoint.ready(); } - public static Start(): void { - FileCache.Initialize( + public static start(): void { + FileCache.initCache( // SUCCESS () => { - Entrypoint.InitStatus.FileCache = true; - this.InitCheck(); + Entrypoint.initStatus.fileCache = true; + this.initCheck(); }, // FAILURE (error: string) => { - CriticalStop.Redirect(error); + CriticalStop.redirect(error); } ); } - private static Initialized(): void { + private static ready(): void { } } \ No newline at end of file diff --git a/client/src/Extensions.ts b/client/src/Extensions.ts index 52149f5..aa94afd 100644 --- a/client/src/Extensions.ts +++ b/client/src/Extensions.ts @@ -3,19 +3,19 @@ // ** 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; + 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; + stripCharacters(chars: string): string; - HasUnicodeCharacters(): boolean; - ToByteArray(): Uint8Array; - ByteLength(): number; + hasUnicodeCharacters(): boolean; + toByteArray(): Uint8Array; + byteLength(): number; } -String.prototype.ReplaceAll = function(needle: any, replace: any, ignoreCase: boolean = false): string { +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 { @@ -30,13 +30,13 @@ String.prototype.ReplaceAll = function(needle: any, replace: any, ignoreCase: bo } }; -String.prototype.Contains = function(needle: string, ignoreCase: boolean = false): boolean { +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) { +String.prototype.stripCharacters = function(chars: string) { var copy = this; if(chars != "") copy = copy.replaceAll(chars.split(""), ""); @@ -44,18 +44,18 @@ String.prototype.StripCharacters = function(chars: string) { return copy; }; -String.prototype.HasUnicodeCharacters = function() { +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() { +String.prototype.byteLength = function() { return utf8.encode(this).length; }; -String.prototype.ToByteArray = function() { +String.prototype.toByteArray = function() { var str = utf8.encode(this); var ret = new Uint8Array(str.length); for(var i = 0; i < str.length; i++) @@ -73,7 +73,8 @@ interface DateConstructor { interface Date { toUnixTime(): number; - toDateTimeString(): string; + /*ToDateTimeString(): string; + ToTimeString(): string;*/ } Date.unixNow = function() { @@ -84,13 +85,13 @@ Date.prototype.toUnixTime = function() { return Math.floor(this.getTime()/1000); }; -Date.prototype.toDateTimeString = function() { +/*Date.prototype.ToDateTimeString = function() { return this.toDateString() +" @ "+ this.getHours().zeroPad() +":"+ this.getMinutes().zeroPad() +":"+ this.getSeconds().zeroPad(); }; -Date.prototype.toTimeString = function() { +Date.prototype.ToTimeString = function() { return this.getHours().zeroPad() +":"+ this.getMinutes().zeroPad() +":"+ this.getSeconds().zeroPad(); -}; +};*/ // ** NUMBER EXTENSIONS ** \\ @@ -119,18 +120,17 @@ Number.prototype.packBytes = function(bytes: number) { interface Uint8Array { unpackBytes(): number; - toString(): string; } -Uint8Array.prototype.unpackBytes = function() { +Uint8Array.prototype.unpackBytes = function(): number { 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; +Uint8Array.prototype.toString = function(): string { + var chunkSize = 4096; var raw = ""; for(var i = 0;; i++) { if(this.length < chunkSize*i) break; diff --git a/client/src/FileCache.ts b/client/src/FileCache.ts index 35c47ba..9e8053b 100644 --- a/client/src/FileCache.ts +++ b/client/src/FileCache.ts @@ -1,7 +1,7 @@ class FileCache { - private static DB: IDBDatabase = null; + private static dbHandle: IDBDatabase = null; - public static Initialize(success: ()=>void, error: (error: string)=>void): void { + public static initCache(success: ()=>void, error: (error: string)=>void): void { var request = window.indexedDB.open("fileCache", 2); request.onupgradeneeded = (event: any) => { @@ -21,13 +21,13 @@ class FileCache { }; request.onsuccess = (event: any) => { - FileCache.DB = request.result; + FileCache.dbHandle = request.result; success(); }; } - public static GetMeta(fileName: string, success: (meta: FileMeta)=>void, error: (error: string)=>void): void { - var query = FileCache.DB.transaction("metadata"); + public static getMeta(fileName: string, success: (meta: FileMeta)=>void, error: (error: string)=>void): void { + var query = FileCache.dbHandle.transaction("metadata"); var store = query.objectStore("metadata"); var request = store.get(fileName); @@ -40,14 +40,14 @@ class FileCache { }; } - public static SetMeta(meta: FileMeta) { - var query = FileCache.DB.transaction("metadata", "readwrite"); + public static setMeta(meta: FileMeta) { + var query = FileCache.dbHandle.transaction("metadata", "readwrite"); var store = query.objectStore("metadata"); store.put(meta); } - public static GetFile(fileName: string, success: (data: Uint8Array)=>void, error: (error: string)=>void): void { - var query = FileCache.DB.transaction("files"); + public static getFile(fileName: string, success: (data: Uint8Array)=>void, error: (error: string)=>void): void { + var query = FileCache.dbHandle.transaction("files"); var store = query.objectStore("files"); var request = store.get(fileName); @@ -60,8 +60,8 @@ class FileCache { }; } - public static SetFile(fileName: string, data: Uint8Array) { - var query = FileCache.DB.transaction("files", "readwrite"); + public static setFile(fileName: string, data: Uint8Array) { + var query = FileCache.dbHandle.transaction("files", "readwrite"); var store = query.objectStore("files"); store.put(data, fileName); } diff --git a/client/src/Packet.ts b/client/src/Packet.ts index 21c6f41..7ba5dc7 100644 --- a/client/src/Packet.ts +++ b/client/src/Packet.ts @@ -5,19 +5,43 @@ const enum kPacketId { } class Packet { - private _Id: kPacketId; - public get Id(): kPacketId { - return this._Id; + private _id: kPacketId; + public get id(): kPacketId { + return this._id; } - private _IsLegal: boolean = true; - public get IsLegal(): boolean { - return this._IsLegal; + private _isLegal: boolean = true; + public get isLegal(): boolean { + return this._isLegal; } - private Regions: Uint8Array[] = []; - - public get RegionCount(): number { - return this.Regions.length; + private _regions: Uint8Array[] = []; + public get regions(): Uint8Array[] { + return this._regions; + } + public get regionCount(): number { + return this._regions.length; + } + public getRegion(region: number): Uint8Array { + return this._regions[region]; + } + public getRegionString(region: number): string { + return this.getRegion(region).toString(); + } + + public getBytes(): Uint8Array { + var messageSize = 1; + this._regions.forEach(region => { + messageSize += region.byteLength + 1; + if(region.byteLength >= 254 && region.byteLength <= 0xFFFF) + messageSize += 2; + else + messageSize += 4; + }); + + var buffer = new Uint8Array(messageSize); + this._regions.forEach(region => { + + }); } } \ No newline at end of file diff --git a/client/src/Utilities.ts b/client/src/Utilities.ts index 2c260cc..5de5ba6 100644 --- a/client/src/Utilities.ts +++ b/client/src/Utilities.ts @@ -1,5 +1,5 @@ class CriticalStop { - public static Redirect(message: string): void { + public static redirect(message: string): void { window.location.href = "error.html?txt="+ encodeURIComponent(message) +"&rterr"; } } \ No newline at end of file