3
3
// Imports /////////////////////////////////////////////////////////////////////
4
4
5
5
import * as path from "path" ;
6
- import * as net from "net" ;
7
6
import * as vscode from "vscode" ;
8
7
8
+ import fetch from 'node-fetch' ;
9
+ var crypto = require ( 'crypto' ) ;
10
+
9
11
// Functions ///////////////////////////////////////////////////////////////////
10
12
11
13
function send ( realm : string , client ?: string ) : void {
@@ -26,63 +28,53 @@ function send( realm: string, client?: string ): void {
26
28
? "_"
27
29
: path . basename ( document . uri . fsPath ) ;
28
30
29
- // Open Socket //
31
+ const postUrl = config . get ( "posturl" , "https://httpbin.org/post" ) ;
32
+ const hashSalt = config . get ( "hashsalt" , "changeme" ) ;
30
33
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 }
33
37
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' } ,
48
42
} ) ;
49
- socket . end ( ) ;
50
-
51
43
}
52
44
53
45
function getPlayerList ( ) : void {
54
46
55
- const config = vscode . workspace . getConfiguration ( "gmod-luadev" )
47
+ // #todo
56
48
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" )
77
50
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
+ // });
79
73
80
74
}
81
75
82
76
// Exports /////////////////////////////////////////////////////////////////////
83
-
84
77
export function activate ( context : vscode . ExtensionContext ) : void {
85
-
86
78
const command = vscode . commands . registerCommand ;
87
79
88
80
context . subscriptions . push (
0 commit comments