diff --git a/Source/HTTPServer.js b/Source/HTTPServer.js index a28c886..991dfd7 100644 --- a/Source/HTTPServer.js +++ b/Source/HTTPServer.js @@ -19,6 +19,9 @@ exports.http = server; app.get("/script",(request, response)=>{ response.sendFile(resolve("./script/index.js")) }); +app.get("/index.js.map",(request, response)=>{ + response.sendFile(resolve("./script/index.js.map")) +}); app.get("*",(request, response)=>{ response.sendFile(resolve("./script/status.xml")) }); \ No newline at end of file diff --git a/Source/Services/IPPressure.js b/Source/Services/IPPressure.js index e73f8a5..c749f68 100644 --- a/Source/Services/IPPressure.js +++ b/Source/Services/IPPressure.js @@ -178,6 +178,12 @@ addService(({ switch(type) { case "alloc/APIPAddress":{ + if(client.APIPAddress) { + end({ + status : "sucess", + ip : client.APIPAddress + }) + }; let value = APIPAddress.lock(client); end({ status : "sucess", @@ -186,6 +192,12 @@ addService(({ break; } case "alloc/APNumber":{ + if(client.APNumber) { + end({ + status : "sucess", + number : client.APNumber + }) + }; let value = APNumber.lock(client); end({ status : "sucess", @@ -194,6 +206,12 @@ addService(({ break; } case "alloc/APShortCode":{ + if(client.APShortCode) { + end({ + status : "sucess", + code : client.APShortCode + }) + }; let value = APShortCode.lock(client); end({ status : "sucess", @@ -202,6 +220,11 @@ addService(({ break; } case "realloc/APIPAddress":{ + if(client.APIPAddress == 0){ + return end({ + status : "fail" + }) + } APIPAddress.release(client.APIPAddress); let value = APIPAddress.lock(client); end({ @@ -211,6 +234,11 @@ addService(({ break; } case "realloc/APNumber":{ + if(client.APNumber == 0){ + return end({ + status : "fail" + }) + } APNumber.release(client.APNumber); let value = APNumber.lock(client); end({ @@ -220,6 +248,11 @@ addService(({ break; } case "realloc/APShortCode":{ + if(client.APShortCode == 0){ + return end({ + status : "fail" + }) + } APShortCode.release(client.APShortCode); let value = APShortCode.lock(client); end({ @@ -257,6 +290,10 @@ addService(({ status : "sucess", socket : socketId }) + }else{ + end({ + status : "fail" + }) } break; } @@ -268,6 +305,10 @@ addService(({ status : "sucess", socket : socketId }) + }else{ + end({ + status : "fail" + }) } break; } @@ -279,6 +320,10 @@ addService(({ status : "sucess", socket : socketId }) + }else{ + end({ + status : "fail" + }) } break; } diff --git a/Source/index.js b/Source/index.js index 0d4b10d..3ad0704 100644 --- a/Source/index.js +++ b/Source/index.js @@ -4,4 +4,5 @@ require("./WebSocket.js"); require("./Services/YourID.js"); require("./Services/Auth.js"); require("./Services/Room.js"); -require("./Services/DataTransfer.js"); \ No newline at end of file +require("./Services/DataTransfer.js"); +require("./Services/IPPressure.js"); \ No newline at end of file diff --git a/frontend/IPPressure.ts b/frontend/IPPressure.ts new file mode 100644 index 0000000..909e75d --- /dev/null +++ b/frontend/IPPressure.ts @@ -0,0 +1,198 @@ +import MWSE from "frontend"; + +export class IPPressure +{ + public mwse : MWSE; + public APNumber? : number; + public APShortCode? : string; + public APIPAddress? : string; + constructor(mwse : MWSE){ + this.mwse = mwse; + }; + public async allocAPIPAddress() + { + let {status,ip} = await this.mwse.EventPooling.request({ + type: 'alloc/APIPAddress' + }) as { + status:"fail"|"success", + ip?:string + }; + if(status == 'success') + { + this.APIPAddress = ip; + return ip; + }else{ + throw new Error("Error Allocated Access Point IP Address"); + } + } + public async allocAPNumber() + { + let {status,number} = await this.mwse.EventPooling.request({ + type: 'alloc/APNumber' + }) as { + status:"fail"|"success", + number?:number + }; + if(status == 'success') + { + this.APNumber = number; + return number; + }else{ + throw new Error("Error Allocated Access Point Number"); + } + } + public async allocAPShortCode() + { + let {status,code} = await this.mwse.EventPooling.request({ + type: 'alloc/APShortCode' + }) as { + status:"fail"|"success", + code?:string + }; + if(status == 'success') + { + this.APShortCode = code; + return code; + }else{ + throw new Error("Error Allocated Access Point Short Code"); + } + } + public async reallocAPIPAddress() + { + let {status,ip} = await this.mwse.EventPooling.request({ + type: 'realloc/APIPAddress' + }) as { + status:"fail"|"success", + ip?:string + }; + if(status == 'success') + { + this.APIPAddress = ip; + return ip; + }else{ + throw new Error("Error Reallocated Access Point IP Address"); + } + } + public async reallocAPNumber() + { + let {status,number} = await this.mwse.EventPooling.request({ + type: 'realloc/APNumber' + }) as { + status:"fail"|"success", + number?:number + }; + if(status == 'success') + { + this.APNumber = number; + return number; + }else{ + throw new Error("Error Reallocated Access Point Number"); + } + } + public async reallocAPShortCode() + { + let {status,code} = await this.mwse.EventPooling.request({ + type: 'realloc/APShortCode' + }) as { + status:"fail"|"success", + code?:string + }; + if(status == 'success') + { + this.APShortCode = code; + return code; + }else{ + throw new Error("Error Reallocated Access Point Short Code"); + } + } + public async releaseAPIPAddress() + { + let {status} = await this.mwse.EventPooling.request({ + type: 'release/APIPAddress' + }) as { + status:"fail"|"success", + }; + if(status == 'success') + { + this.APIPAddress = undefined; + }else{ + throw new Error("Error release Access Point IP Address"); + } + } + public async releaseAPNumber() + { + let {status} = await this.mwse.EventPooling.request({ + type: 'release/APNumber' + }) as { + status:"fail"|"success", + }; + if(status == 'success') + { + this.APNumber = undefined; + }else{ + throw new Error("Error release Access Point Number"); + } + } + public async releaseAPShortCode() + { + let {status} = await this.mwse.EventPooling.request({ + type: 'release/APShortCode' + }) as { + status:string + }; + if(status == 'success') + { + this.APShortCode = undefined; + }else{ + throw new Error("Error release Access Point Short Code"); + } + } + public async queryAPIPAddress(ip:string) + { + let {status,socket} = await this.mwse.EventPooling.request({ + type: 'alloc/APIPAddress', + whois: ip + }) as { + status:"fail"|"success", + socket?:string + }; + if(status == "success") + { + return socket; + }else{ + return null; + } + } + public async queryAPNumber(number:number) + { + let {status,socket} = await this.mwse.EventPooling.request({ + type: 'alloc/APNumber', + whois: number + }) as { + status:"fail"|"success", + socket?:string + }; + if(status == "success") + { + return socket; + }else{ + return null; + } + } + public async queryAPShortCode(code:string) + { + let {status,socket} = await this.mwse.EventPooling.request({ + type: 'alloc/APShortCode', + whois: code + }) as { + status:"fail"|"success", + socket?:string + }; + if(status == "success") + { + return socket; + }else{ + return null; + } + } +} \ No newline at end of file diff --git a/frontend/index.ts b/frontend/index.ts index 406fc70..e41f822 100644 --- a/frontend/index.ts +++ b/frontend/index.ts @@ -1,6 +1,7 @@ import {Connection,IConnection} from "./Connection"; import EventPool from "./EventPool"; import EventTarget from "./EventTarget"; +import { IPPressure } from "./IPPressure"; import Peer from "./Peer"; import Room, { IRoomOptions } from "./Room"; import WSTSProtocol, { Message } from "./WSTSProtocol"; @@ -11,13 +12,15 @@ export default class MWSE extends EventTarget { public rooms : Map = new Map(); public pairs : Map = new Map(); public peers : Map = new Map(); + public virtualPressure : IPPressure; public me! : Peer; constructor(options: IConnection){ super(); this.server = new Connection(options); - this.server.connect(); this.WSTSProtocol = new WSTSProtocol(this); this.EventPooling = new EventPool(this); + this.virtualPressure = new IPPressure(this); + this.server.connect(); this.me = new Peer(this); this.me.scope(()=>{ this.peers.set('me', this.me);