import seems to be working
This commit is contained in:
+6
-12
@@ -78,20 +78,17 @@ async function doImport (owner, repo, id) {
|
|||||||
.reduce((acc, cur) => acc.created_at < cur.created_at ? cur : acc)
|
.reduce((acc, cur) => acc.created_at < cur.created_at ? cur : acc)
|
||||||
artifactId = artifact.id
|
artifactId = artifact.id
|
||||||
const url = artifact.archive_download_url
|
const url = artifact.archive_download_url
|
||||||
if (!fs.existsSync("games")){
|
// Make sure the download folder exists
|
||||||
fs.mkdirSync("games");
|
if (!fs.existsSync("../../games")){
|
||||||
|
fs.mkdirSync("../../games");
|
||||||
}
|
}
|
||||||
if (!fs.existsSync("games/tmp")){
|
if (!fs.existsSync("../../games/tmp")){
|
||||||
fs.mkdirSync("games/tmp");
|
fs.mkdirSync("../../games/tmp");
|
||||||
}
|
|
||||||
if (!fs.existsSync(`games/${owner}`)){
|
|
||||||
fs.mkdirSync(`games/${owner}`);
|
|
||||||
}
|
}
|
||||||
progress[id].output += `Download from ${url}\n`
|
progress[id].output += `Download from ${url}\n`
|
||||||
// await download(id, url, `games/tmp/${owner.toLowerCase()}_${repo.toLowerCase()}_${artifactId}.zip`)
|
await download(id, url, `../../games/tmp/${owner.toLowerCase()}_${repo.toLowerCase()}_${artifactId}.zip`)
|
||||||
progress[id].output += `Download finished.\n`
|
progress[id].output += `Download finished.\n`
|
||||||
|
|
||||||
// BUG: it doesn't wait for this to finish
|
|
||||||
await runProcess(id, "/bin/bash", [`${__dirname}/unpack.sh`, artifactId, owner.toLowerCase(), repo.toLowerCase()], ".")
|
await runProcess(id, "/bin/bash", [`${__dirname}/unpack.sh`, artifactId, owner.toLowerCase(), repo.toLowerCase()], ".")
|
||||||
|
|
||||||
|
|
||||||
@@ -105,9 +102,6 @@ async function doImport (owner, repo, id) {
|
|||||||
// await runProcess(id, "tar", ["-cvf", `../archive_${artifactId}.tar`, "."], `tmp/artifact_${artifactId}_inner/`)
|
// await runProcess(id, "tar", ["-cvf", `../archive_${artifactId}.tar`, "."], `tmp/artifact_${artifactId}_inner/`)
|
||||||
// // await runProcess(id, "docker", ["load", "-i", `tmp/archive_${artifactId}.tar`])
|
// // await runProcess(id, "docker", ["load", "-i", `tmp/archive_${artifactId}.tar`])
|
||||||
|
|
||||||
|
|
||||||
// TODO: not implemented
|
|
||||||
|
|
||||||
progress[id].done = true
|
progress[id].done = true
|
||||||
progress[id].output += `Done.\n`
|
progress[id].output += `Done.\n`
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
+61
-51
@@ -6,30 +6,20 @@ import * as url from 'url';
|
|||||||
import * as rpc from 'vscode-ws-jsonrpc';
|
import * as rpc from 'vscode-ws-jsonrpc';
|
||||||
import * as jsonrpcserver from 'vscode-ws-jsonrpc/server';
|
import * as jsonrpcserver from 'vscode-ws-jsonrpc/server';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
import fs from 'fs';
|
||||||
import anonymize from 'ip-anonymize';
|
import anonymize from 'ip-anonymize';
|
||||||
import { importTrigger, importStatus } from './import.mjs'
|
import { importTrigger, importStatus } from './import.mjs'
|
||||||
// import fs from 'fs'
|
// import fs from 'fs'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Add a game here if the server should keep a queue of pre-loaded games ready at all times.
|
||||||
|
*
|
||||||
* IMPORTANT! Tags here need to be lower case!
|
* IMPORTANT! Tags here need to be lower case!
|
||||||
*/
|
*/
|
||||||
const games = {
|
const queueLength = {
|
||||||
"g/hhu-adam/robo": {
|
"g/hhu-adam/robo": 2,
|
||||||
dir: "Robo",
|
"g/hhu-adam/nng4": 5,
|
||||||
queueLength: 5
|
"g/djvelleman/stg4": 2,
|
||||||
},
|
|
||||||
"g/hhu-adam/nng4": {
|
|
||||||
dir: "NNG4",
|
|
||||||
queueLength: 5
|
|
||||||
},
|
|
||||||
"g/djvelleman/stg4": {
|
|
||||||
dir: "STG4",
|
|
||||||
queueLength: 5
|
|
||||||
},
|
|
||||||
"g/hhu-adam/nng4-old": {
|
|
||||||
dir: "NNG4-OLD",
|
|
||||||
queueLength: 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const __filename = url.fileURLToPath(import.meta.url);
|
const __filename = url.fileURLToPath(import.meta.url);
|
||||||
@@ -64,29 +54,32 @@ function tag(owner, repo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startServerProcess(owner, repo) {
|
function startServerProcess(owner, repo) {
|
||||||
let game_dir = (owner == 'local') ?
|
|
||||||
repo : games[tag(owner, repo)]?.dir
|
|
||||||
|
|
||||||
if (owner == 'local') {
|
if (owner == 'local') {
|
||||||
if(!isDevelopment) {
|
if(!isDevelopment) {
|
||||||
console.error(`No local games in production mode.`)
|
console.error(`No local games in production mode.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO: This test does not work
|
|
||||||
// if (!fs.existsSync(path.join("../", game_dir))) {
|
|
||||||
// console.error(`Game folder does not exists: ${game_dir}`)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!game_dir) {
|
let game_dir = (owner == 'local') ?
|
||||||
console.error(`Unknown game: ${tag(owner, repo)}`)
|
path.join(__dirname, '..', '..', repo) :
|
||||||
|
path.join(__dirname, '..', '..', 'games', `${owner}`, `${repo}`)
|
||||||
|
|
||||||
|
if(!fs.existsSync(path.join(__dirname, '..', '..', 'games'))) {
|
||||||
|
console.error(`Did not find the following folder: ${path.join(__dirname, '..', '..', 'games')}`)
|
||||||
|
console.error('Did you already import any games?')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!fs.existsSync(game_dir)) {
|
||||||
|
console.error(`Game 'games/${owner}/${repo}' does not exist!`)
|
||||||
|
cp.spawn("pwd")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let serverProcess
|
let serverProcess
|
||||||
if (isDevelopment) {
|
if (isDevelopment) {
|
||||||
let args = ["--server", path.join('..','..','games',`${owner}`,`${repo}`)]
|
let args = ["--server", game_dir]
|
||||||
serverProcess = cp.spawn("./gameserver", args,
|
serverProcess = cp.spawn("./gameserver", args,
|
||||||
{ cwd: path.join(__dirname, "./build/bin/") })
|
{ cwd: path.join(__dirname, "./build/bin/") })
|
||||||
} else {
|
} else {
|
||||||
@@ -107,18 +100,30 @@ function startServerProcess(owner, repo) {
|
|||||||
|
|
||||||
/** start Lean Server processes to refill the queue */
|
/** start Lean Server processes to refill the queue */
|
||||||
function fillQueue(owner, repo) {
|
function fillQueue(owner, repo) {
|
||||||
while (queue[tag(owner, repo)].length < games[tag(owner, repo)].queueLength) {
|
while (queue[tag(owner, repo)].length < queueLength[tag(owner, repo)]) {
|
||||||
const serverProcess = startServerProcess(tag(owner, repo))
|
let serverProcess
|
||||||
queue[tag(owner, repo)].push(serverProcess)
|
try {
|
||||||
|
serverProcess = startServerProcess(tag(owner, repo))
|
||||||
|
} catch (e) {
|
||||||
|
console.error('error starting the server')
|
||||||
|
console.error(e)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
if (serverProcess == null) {
|
||||||
|
console.error('serverProcess was undefined/null')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
queue[tag(owner, repo)].push(serverProcess)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (!isDevelopment) { // Don't use queue in development
|
// TODO: We disabled queue for now
|
||||||
// for (let tag in games) {
|
if (!isDevelopment) { // Don't use queue in development
|
||||||
// queue[tag] = []
|
for (let tag in games) {
|
||||||
// fillQueue(tag)
|
queue[tag] = []
|
||||||
// }
|
fillQueue(tag)
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const urlRegEx = /^\/websocket\/g\/([\w.-]+)\/([\w.-]+)$/
|
const urlRegEx = /^\/websocket\/g\/([\w.-]+)\/([\w.-]+)$/
|
||||||
|
|
||||||
@@ -127,21 +132,26 @@ wss.addListener("connection", function(ws, req) {
|
|||||||
if (!reRes) { console.error(`Connection refused because of invalid URL: ${req.url}`); return; }
|
if (!reRes) { console.error(`Connection refused because of invalid URL: ${req.url}`); return; }
|
||||||
const owner = reRes[1]
|
const owner = reRes[1]
|
||||||
const repo = reRes[2]
|
const repo = reRes[2]
|
||||||
// const tag = `g/${owner.toLowerCase()}/${repo.toLowerCase()}`
|
|
||||||
|
|
||||||
// // TODO
|
let ps
|
||||||
// if (isDevelopment && process.env.DEV_CONTAINER) {
|
|
||||||
// tag = `g/local/game`
|
|
||||||
// }
|
|
||||||
|
|
||||||
let ps;
|
|
||||||
if (!queue[tag(owner, repo)] || queue[tag(owner, repo)].length == 0) {
|
if (!queue[tag(owner, repo)] || queue[tag(owner, repo)].length == 0) {
|
||||||
|
try {
|
||||||
ps = startServerProcess(owner, repo)
|
ps = startServerProcess(owner, repo)
|
||||||
|
} catch (e) {
|
||||||
|
console.error('error starting the server')
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
console.info('Got process from the queue')
|
||||||
ps = queue[tag(owner, repo)].shift() // Pick the first Lean process; it's likely to be ready immediately
|
ps = queue[tag(owner, repo)].shift() // Pick the first Lean process; it's likely to be ready immediately
|
||||||
fillQueue(owner, repo)
|
fillQueue(owner, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ps == null) {
|
||||||
|
console.error('server process is undefined/null')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
socketCounter += 1;
|
socketCounter += 1;
|
||||||
const ip = anonymize(req.headers['x-forwarded-for'] || req.socket.remoteAddress)
|
const ip = anonymize(req.headers['x-forwarded-for'] || req.socket.remoteAddress)
|
||||||
console.log(`[${new Date()}] Socket opened - ${ip}`)
|
console.log(`[${new Date()}] Socket opened - ${ip}`)
|
||||||
@@ -152,14 +162,14 @@ wss.addListener("connection", function(ws, req) {
|
|||||||
onClose: (cb) => { ws.on("close", cb) },
|
onClose: (cb) => { ws.on("close", cb) },
|
||||||
send: (data, cb) => { ws.send(data,cb) }
|
send: (data, cb) => { ws.send(data,cb) }
|
||||||
}
|
}
|
||||||
const reader = new rpc.WebSocketMessageReader(socket);
|
const reader = new rpc.WebSocketMessageReader(socket)
|
||||||
const writer = new rpc.WebSocketMessageWriter(socket);
|
const writer = new rpc.WebSocketMessageWriter(socket)
|
||||||
const socketConnection = jsonrpcserver.createConnection(reader, writer, () => ws.close())
|
const socketConnection = jsonrpcserver.createConnection(reader, writer, () => ws.close())
|
||||||
const serverConnection = jsonrpcserver.createProcessStreamConnection(ps);
|
const serverConnection = jsonrpcserver.createProcessStreamConnection(ps)
|
||||||
socketConnection.forward(serverConnection, message => {
|
socketConnection.forward(serverConnection, message => {
|
||||||
if (isDevelopment) {console.log(`CLIENT: ${JSON.stringify(message)}`)}
|
if (isDevelopment) {console.log(`CLIENT: ${JSON.stringify(message)}`)}
|
||||||
return message;
|
return message;
|
||||||
});
|
})
|
||||||
serverConnection.forward(socketConnection, message => {
|
serverConnection.forward(socketConnection, message => {
|
||||||
if (isDevelopment) {console.log(`SERVER: ${JSON.stringify(message)}`)}
|
if (isDevelopment) {console.log(`SERVER: ${JSON.stringify(message)}`)}
|
||||||
return message;
|
return message;
|
||||||
@@ -170,9 +180,9 @@ wss.addListener("connection", function(ws, req) {
|
|||||||
|
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
console.log(`[${new Date()}] Socket closed - ${ip}`)
|
console.log(`[${new Date()}] Socket closed - ${ip}`)
|
||||||
socketCounter -= 1;
|
socketCounter -= 1
|
||||||
})
|
})
|
||||||
|
|
||||||
socketConnection.onClose(() => serverConnection.dispose());
|
socketConnection.onClose(() => serverConnection.dispose())
|
||||||
serverConnection.onClose(() => socketConnection.dispose());
|
serverConnection.onClose(() => socketConnection.dispose())
|
||||||
})
|
})
|
||||||
|
|||||||
+21
-8
@@ -4,16 +4,29 @@ ARTIFACT_ID=$1
|
|||||||
OWNER=$2
|
OWNER=$2
|
||||||
REPO=$3
|
REPO=$3
|
||||||
|
|
||||||
echo "Unpacking ZIP."
|
echo "Creating folders"
|
||||||
# unzip -o games/tmp/${OWNER}_${REPO}_${ARTIFACT_ID}.zip -d games/tmp/${OWNER}_${REPO}_${ARTIFACT_ID}
|
cd ../..
|
||||||
echo "Unpacking game."
|
# mkdir -p games
|
||||||
rm -rf games/${OWNER}/${REPO}
|
cd games
|
||||||
mkdir games/${OWNER}/${REPO}
|
pwd
|
||||||
|
# mkdir -p tmp
|
||||||
|
mkdir -p ${OWNER}
|
||||||
|
|
||||||
for f in games/tmp/${OWNER}_${REPO}_${ARTIFACT_ID}/* #Should only be one file
|
echo "Unpacking ZIP."
|
||||||
|
unzip -o tmp/${OWNER}_${REPO}_${ARTIFACT_ID}.zip -d tmp/${OWNER}_${REPO}_${ARTIFACT_ID}
|
||||||
|
echo "Unpacking game."
|
||||||
|
|
||||||
|
# exit the npm project to avoid reloading. TODO: Where should we actually save these?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
echo "Delete old version of the game"
|
||||||
|
rm -rf ${OWNER}/${REPO}
|
||||||
|
mkdir -p ${OWNER}/${REPO}
|
||||||
|
|
||||||
|
for f in tmp/${OWNER}_${REPO}_${ARTIFACT_ID}/* #Should only be one file
|
||||||
do
|
do
|
||||||
echo "Unpacking $f"
|
echo "Unpacking $f"
|
||||||
#tar -xvzf $f -C games/${OWNER}/${REPO}
|
#tar -xvzf $f -C games/${OWNER}/${REPO}
|
||||||
mkdir games/${OWNER}/${REPO}
|
unzip -q -o $f -d ${OWNER}/${REPO}
|
||||||
unzip -o $f -d games/${OWNER}/${REPO}
|
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user