Make this a separate repo
Add job id to auth
This commit is contained in:
commit
9d216fdf9b
130
.gitignore
vendored
Normal file
130
.gitignore
vendored
Normal file
|
@ -0,0 +1,130 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
85
index.js
Normal file
85
index.js
Normal file
|
@ -0,0 +1,85 @@
|
|||
require("dotenv").config();
|
||||
const Crypto = require('crypto');
|
||||
const express = require('express');
|
||||
const PORT = process.env.SERVER_PORT || 3000;
|
||||
|
||||
var {
|
||||
WebSocket
|
||||
} = require('ws');
|
||||
const ws_ = [];
|
||||
const app = express();
|
||||
app.set('trust proxy', true);
|
||||
|
||||
app.set('view engine', 'ejs');
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.render('index');
|
||||
});
|
||||
|
||||
app.get('/api/connect/:jobid/:url', (req, res) => {
|
||||
var id = btoa(Crypto.randomBytes(10).toString('base64').slice(0, 10)).replaceAll("=", "");
|
||||
ws_[id] = {};
|
||||
ws_[id].jobid = req.params.jobid; // Roblox server ID, checked on all requests as a sort of username alongside the ID
|
||||
ws_[id].message = "";
|
||||
ws_[id].connection = new WebSocket(atob(req.params.url));
|
||||
ws_[id].connection.on('message', function(data) {
|
||||
ws_[id].message = data;
|
||||
})
|
||||
ws_[id].connection.on('close', function() {
|
||||
ws_[id].connection.terminate();
|
||||
})
|
||||
ws_[id].open = false;
|
||||
setInterval(() => {
|
||||
ws_[id].connection.on('open', () => {
|
||||
ws_[id].open = true;
|
||||
});
|
||||
})
|
||||
ws_[id].connection.on("error", () => {
|
||||
res.status(500);
|
||||
})
|
||||
res.send(id);
|
||||
});
|
||||
|
||||
app.get("/api/send/:jobid/:id/:data", (req, res) => {
|
||||
if (ws_[req.params.id].jobid !== req.params.jobid) {
|
||||
res.status(401).send({
|
||||
success: false,
|
||||
message: "Invalid job ID"
|
||||
});
|
||||
return;
|
||||
}
|
||||
var id = req.params.id;
|
||||
var stats = ws_[id];
|
||||
var socket = ws_[id].connection;
|
||||
req.params.data = atob(req.params.data);
|
||||
console.log("sent data: " + req.params.data)
|
||||
if (stats.open == true) {
|
||||
socket.send(req.params.data);
|
||||
} else {
|
||||
socket.on('open', () => {
|
||||
socket.send(req.params.data);
|
||||
});
|
||||
}
|
||||
res.send({
|
||||
success: true
|
||||
});
|
||||
})
|
||||
|
||||
app.get("/api/poll/:jobid/:id", (req, res) => {
|
||||
if (ws_[req.params.id].jobid !== req.params.jobid) {
|
||||
res.status(401).send({
|
||||
success: false,
|
||||
message: "Invalid job ID"
|
||||
});
|
||||
return;
|
||||
}
|
||||
var socket = ws_[req.params.id];
|
||||
if (!/^\s*$/.test(socket.message.toString())) {
|
||||
res.send(socket.message);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log('server started');
|
||||
});
|
1062
package-lock.json
generated
Normal file
1062
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
17
package.json
Normal file
17
package.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "rblx-unisocket3",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.18.1",
|
||||
"ws": "^8.5.0"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue