Skip to content

Commit 046a083

Browse files
committed
POST code to url
1 parent bb4a7b2 commit 046a083

File tree

3 files changed

+194
-52
lines changed

3 files changed

+194
-52
lines changed

package-lock.json

Lines changed: 146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@
4141
"configuration": {
4242
"title": "GMod LuaDev Settings",
4343
"properties": {
44-
"gmod-luadev.host": {
44+
"gmod-luadev.posturl": {
4545
"type": "string",
46-
"default": "",
47-
"description": "Game server address. Leave blank to use localhost"
46+
"default": "https://httpbin.org/post",
47+
"description": "Set the url of webhook. We will send HTTP POST query to it"
4848
},
49-
"gmod-luadev.port": {
50-
"type": "integer",
51-
"default": 27099,
52-
"description": "Port number to communicate with LuaDev over."
49+
"gmod-luadev.hashsalt": {
50+
"type": "string",
51+
"default": "change_me",
52+
"description": "Any secret string. It will be added to code as salt for hash"
5353
},
5454
"gmod-luadev.hidescriptname": {
5555
"type": "boolean",
@@ -94,7 +94,11 @@
9494
},
9595
"devDependencies": {
9696
"@types/node": "^14.14.37",
97+
"@types/node-fetch": "^2.5.12",
9798
"typescript": "^4.2.4",
9899
"vscode": "^1.1.10"
100+
},
101+
"dependencies": {
102+
"node-fetch": "^2.6.1"
99103
}
100-
}
104+
}

src/extension.ts

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// Imports /////////////////////////////////////////////////////////////////////
44

55
import * as path from "path";
6-
import * as net from "net";
76
import * as vscode from "vscode";
87

8+
import fetch from 'node-fetch';
9+
var crypto = require('crypto');
10+
911
// Functions ///////////////////////////////////////////////////////////////////
1012

1113
function 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

5345
function 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-
8477
export function activate( context: vscode.ExtensionContext ): void {
85-
8678
const command = vscode.commands.registerCommand;
8779

8880
context.subscriptions.push(

0 commit comments

Comments
 (0)