having a static class to drive socket comms is dumb

why did i do this
This commit is contained in:
Malloc of Kuzkycyziklistan 2017-09-14 16:00:24 -05:00
parent 4d281dac5a
commit 6026593287
6 changed files with 52 additions and 49 deletions

View file

@ -5,10 +5,6 @@
<link rel="stylesheet" type="text/css" href="style.css" />
<meta charset="UTF-8" />
<!-- LOGIN AND REGISTER SCRIPT -->
<script type="text/javascript" src="lib/loginstration.js"></script>
<!-- END -->
<script type="text/javascript" src="bin/lib.js"></script>
<script type="text/javascript" src="bin/scape.js"></script>
@ -25,7 +21,7 @@
</div>
<!-- THUGGINOMICS LOGIN CODE VERY FRAGILE -->
<!-- THUGGINOMICS LOGIN CODE VERY FRAGILE
<div id="loginstration-wrap">
<h1 id="loginstration-header" class="loginstration-header">

View file

@ -20,18 +20,16 @@ class Entrypoint {
() => {
Entrypoint.initStatus.fileCache = true;
this.initCheck();
},
},
// FAILURE
(error: string) => {
CriticalStop.redirect(error);
}
);
Connection.open();
}
private static ready(): void {
}
}

View file

@ -69,6 +69,10 @@ class FileCache {
var store = query.objectStore("files");
store.put({name: fileName, data: data});
}
public static deleteFile(fileName: string) {
}
}
class FileMeta {

View file

@ -1,38 +1,38 @@
class Connection {
private static sock: WebSocket = null;
private static _isOpen: boolean = false;
private static onOpenFunc: () => void = null;
private static onCloseFunc: () => void = null;
public static get isOpen(): boolean {
return Connection._isOpen;
private sock: WebSocket = null;
private _isOpen: boolean = false;
private onOpenFunc: () => void = null;
private onCloseFunc: () => void = null;
public get isOpen(): boolean {
return this._isOpen;
}
public static open(onOpen: () => void = null): void {
if(Connection._isOpen)
public open(onOpen: () => void = null): void {
if(this._isOpen)
return;
// FLAG replace hard coded url with one loaded from a config file
Connection.sock = new WebSocket("ws://localhost:6770");
Connection.sock.binaryType = "arraybuffer";
this.sock = new WebSocket("ws://localhost:6770");
this.sock.binaryType = "arraybuffer";
Connection.onOpenFunc = onOpen;
Connection.sock.onopen = Connection.onOpen;
Connection.sock.onmessage = Connection.onMessage;
Connection.sock.onclose = Connection.onClose;
this.onOpenFunc = onOpen;
this.sock.onopen = this.onOpen;
this.sock.onmessage = this.onMessage;
this.sock.onclose = this.onClose;
}
public static send(msg: Packet) {
Connection.sock.send(msg.getBytes());
public send(msg: Packet) {
this.sock.send(msg.getBytes());
}
private static onOpen(event: any): void {
Connection._isOpen = true;
private onOpen(event: any): void {
this._isOpen = true;
if(Connection.onOpenFunc)
Connection.onOpenFunc();
if(this.onOpenFunc)
this.onOpenFunc();
}
private static onMessage(event: any): void {
private onMessage(event: any): void {
var raw = new Uint8Array(event.data);
var msg: Packet;
try {
@ -45,36 +45,36 @@ class Connection {
console.log(msg);
switch(msg.id) {
case kPacketId.KeyExchange:
case kMasterId.KeyExchange:
var response = Key.generateResponsePacket(msg);
if(Key.succeeded) {
Cipher.init(Key.privateKey);
Connection.send(response);
this.send(response);
} else
CriticalStop.redirect("Could not establish an encrypted connection with the server.");
break;
case kPacketId.LoginAttempt:
case kMasterId.LoginAttempt:
break;
case kPacketId.RegistrationAttempt:
case kMasterId.RegistrationAttempt:
break;
}
}
private static onClose(event: any): void {
Connection._isOpen = false;
private onClose(event: any): void {
this._isOpen = false;
Cipher.close();
if(Connection.onCloseFunc)
Connection.onCloseFunc();
if(this.onCloseFunc)
this.onCloseFunc();
}
public static close(onClose: () => void = null): void {
if(!Connection._isOpen)
public close(onClose: () => void = null): void {
if(!this._isOpen)
return;
Connection.onCloseFunc = onClose;
Connection.sock.close();
this.onCloseFunc = onClose;
this.sock.close();
}
}

View file

@ -20,7 +20,7 @@ class Key {
var clientKey = generator.modPow(Key.secret, modulus);
Key._privateKey = serverKey.modPow(Key.secret, modulus);
return Packet.create(kPacketId.KeyExchange, [clientKey.toString(16)]);
return Packet.create(kMasterId.KeyExchange, [clientKey.toString(16)]);
}
}

View file

@ -1,14 +1,19 @@
const enum kPacketId {
KeyExchange = 0,
const enum kMasterId {
KeyExchange = 1,
LoginAttempt,
RegistrationAttempt
RegistrationAttempt,
ServerListing
}
const enum kSlaveId {
}
class Packet {
private static magicNumber: Uint8Array = new Uint8Array([0xF0, 0x9F, 0xA6, 0x91]);
private _id: kPacketId;
public get id(): kPacketId {
private _id: number;
public get id(): number {
return this._id;
}
@ -37,7 +42,7 @@ class Packet {
private constructor() {}
public static create(id: kPacketId, regions: any[]): Packet {
public static create(id: number, regions: any[]): Packet {
var packet = new Packet;
packet._id = id;
regions.forEach(region => {