33// Imports /////////////////////////////////////////////////////////////////////
44
55import * as path from "path" ;
6- import * as net from "net" ;
76import * as vscode from "vscode" ;
87
8+ import fetch from 'node-fetch' ;
9+ var crypto = require ( 'crypto' ) ;
10+
911// Functions ///////////////////////////////////////////////////////////////////
1012
1113function send ( realm : string , client ?: string ) : void {
@@ -26,63 +28,53 @@ function send( realm: string, client?: string ): void {
2628 ? "_"
2729 : path . basename ( document . uri . fsPath ) ;
2830
29- // Open Socket //
31+ const postUrl = config . get ( "posturl" , "https://httpbin.org/post" ) ;
32+ const hashSalt = config . get ( "hashsalt" , "changeme" ) ;
3033
31- let host = config . get ( "host" , "127.0.0.1" )
32- if ( host . trim ( ) === "" ) host = "127.0.0.1"
34+ const code = document . getText ( ) ;
35+ const hash = crypto . createHash ( 'sha256' ) . update ( hashSalt + code ) . digest ( 'hex' ) ;
36+ const data = { source : document_title , code : code , hash : hash , realm : realm }
3337
34- const socket = new net . Socket ( ) ;
35- socket . connect ( config . get ( "port" , 27099 ) , host ) ;
36- socket . write (
37- realm + "\n" +
38- document_title + "\n" +
39- client + "\n" +
40- document . getText ( )
41- ) ;
42- socket . on ( "error" , ( ex ) => {
43- if ( ex . name == "ECONNREFUSED" )
44- vscode . window . showErrorMessage (
45- "Could not connect to LuaDev!" ) ;
46- else
47- vscode . window . showErrorMessage ( ex . message ) ;
38+ fetch ( postUrl , {
39+ method : 'POST' ,
40+ body : JSON . stringify ( data ) ,
41+ headers : { 'Content-Type' : 'application/json' } ,
4842 } ) ;
49- socket . end ( ) ;
50-
5143}
5244
5345function getPlayerList ( ) : void {
5446
55- const config = vscode . workspace . getConfiguration ( "gmod-luadev" )
47+ // #todo
5648
57- const socket = new net . Socket ( ) ;
58- socket . connect ( config . get ( "port" , 27099 ) ) ;
59- socket . write ( "requestPlayers\n" ) ;
60- socket . setEncoding ( "utf8" ) ;
61- socket . on ( "data" , function ( data : string ) : void {
62-
63- const clients = data . split ( "\n" ) ;
64- clients . sort ( ) ;
65-
66- vscode . window . showQuickPick (
67- clients ,
68- {
69- placeHolder : "Select Client to send to"
70- }
71- ) . then ( function ( client : string ) : void {
72- // Dialogue cancelled
73- if ( client == null ) return ;
74- // Send to client
75- send ( "client" , client ) ;
76- } ) ;
49+ // const config = vscode.workspace.getConfiguration( "gmod-luadev" )
7750
78- } ) ;
51+ // const socket = new net.Socket();
52+ // socket.connect( config.get( "port", 27099 ) );
53+ // socket.write( "requestPlayers\n" );
54+ // socket.setEncoding( "utf8" );
55+ // socket.on( "data", function ( data: string ): void {
56+
57+ // const clients = data.split( "\n" );
58+ // clients.sort();
59+
60+ // vscode.window.showQuickPick(
61+ // clients,
62+ // {
63+ // placeHolder: "Select Client to send to"
64+ // }
65+ // ).then( function ( client: string ): void {
66+ // // Dialogue cancelled
67+ // if ( client == null ) return;
68+ // // Send to client
69+ // send( "client", client );
70+ // });
71+
72+ // });
7973
8074}
8175
8276// Exports /////////////////////////////////////////////////////////////////////
83-
8477export function activate ( context : vscode . ExtensionContext ) : void {
85-
8678 const command = vscode . commands . registerCommand ;
8779
8880 context . subscriptions . push (
0 commit comments