class MWSECloser{ stdin = null; stdout = null; stderr = null; endpoint = null; static mwse = null; constructor(pipe){ this.stdin = pipe.stdin; this.stdout = pipe.stdout; this.stderr = pipe.stderr; } greenText(text){ this.stdout.writeln(`${this.stdout.COLOR_TEXT(0,255,0)}${text}${this.stdout.COLOR_RESET()}`); } async main(args) { this.stdout.write("Endpoint: "); let answer = await this.stdin.readline(); let url; try{ url = new URL(answer) }catch{ this.stderr.writeln('Bilinmeyen path yapısı'); return this.exit(); }; this.greenText('Path doğrulandı'); if(url.protocol.toLowerCase() != 'wss:' && url.protocol.toLowerCase() != 'ws:'){ this.stderr.writeln('Bilinmeyen protokol'); return this.exit(); } this.greenText('Şema doğrulandı'); this.endpoint = url; try{ await this.scriptImport(); }catch{ this.stderr.writeln('MWSE bağlayıcısı indirilemedi'); return this.exit(); }; this.greenText(`${url.host} üzerinden bağlanılıyor : ${url.href}`); let mwse; try{ mwse = new MWSE({ endpoint: url.href }); await new Promise(ok => { mwse.scope(async ()=>{ this.greenText(`\n\nMWSE üzerinden ${url.host} makinesine bağlısınız\n\n`); ok(); }) }); MWSECloser.mwse = mwse; }catch{ this.stderr.writeln(`${url.host} makinesine bağlanırken bir sorun oluştu`); return this.exit(); }finally{ this.exit(); } } async scriptImport() { let t = new URL("script",this.endpoint); if(t.protocol == 'wss:'){ t.protocol = 'https:'; }else{ t.protocol = 'http:'; } let script = document.createElement("script"); await new Promise((ok,rej) => { script.onload = () => ok(); script.onerror = () => rej(); script.setAttribute("src",t.href); document.head.appendChild(script); }); if(window.MWSE === void 0){ this.stderr.writeln('MWSE bağlayıcısı indirilemedi'); return this.exit(); } } }; CommandNamespace.namespaces.set('mwse-socket', MWSECloser);