Skip to content

Commit

Permalink
TGS Test Merge (#6641)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevinz authored and Kevinz committed Aug 10, 2024
2 parents b1a25c7 + f19d906 commit 0227a74
Show file tree
Hide file tree
Showing 91 changed files with 313 additions and 5,444 deletions.
5 changes: 4 additions & 1 deletion code/controllers/subsystem/assets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,16 @@ SUBSYSTEM_DEF(assets)

set_transport_to(newtransport)

/datum/controller/subsystem/assets/proc/reload_transport()
set_transport_to(new transport.type)

/datum/controller/subsystem/assets/proc/set_transport_to(datum/asset_transport/new_transport)
QDEL_NULL(transport)
transport = new_transport

// unload all asset packs
for(var/datum/asset_pack/pack in asset_packs)
pack.loaded_urls = null
pack.unload()
// unload all dynamic items
for(var/name in dynamic_asset_items_by_name)
var/datum/asset_item/dynamic/item = dynamic_asset_items_by_name[name]
Expand Down
3 changes: 3 additions & 0 deletions code/datums/changelog.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
if(.)
return
if(action == "get_month")
if(!params["date"] || !fexists("html/changelogs/archive/[params["date"]].yml"))
return TRUE
var/datum/asset_pack/changelog_item/changelog_item = changelog_items[params["date"]]
if (!changelog_item)
changelog_item = new /datum/asset_pack/changelog_item(params["date"])
SSassets.register_asset_pack(changelog_item)
changelog_items[params["date"]] = changelog_item
ui.send_asset(changelog_item)
return TRUE
Expand Down
9 changes: 9 additions & 0 deletions code/modules/asset_cache/asset_pack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@
src.packed_items = list_values(items)
loaded = ASSET_FULLY_LOADED

/**
* unload / reset
*/
/datum/asset_pack/proc/unload()
item_lookup = null
packed_items = null
loaded_urls = null
loaded = ASSET_NOT_LOADED

/**
* ensures we are pushed to a transport
*/
Expand Down
10 changes: 8 additions & 2 deletions code/modules/asset_cache/assets/tgui.dm
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
/datum/asset_pack/simple/tgui
// keep_local_name = TRUE
// debug server requires unmangled names to target
do_not_mangle = TRUE
// do not separate for debugging purposes
do_not_separate = TRUE
assets = list(
"tgui.bundle.js" = file("tgui/public/tgui.bundle.js"),
"tgui.bundle.css" = file("tgui/public/tgui.bundle.css"),
)

/datum/asset_pack/simple/tgui_panel
// keep_local_name = TRUE
// debug server requires unmangled names to target
do_not_mangle = TRUE
// do not separate for debugging purposes
do_not_separate = TRUE
assets = list(
"tgui-panel.bundle.js" = file("tgui/public/tgui-panel.bundle.js"),
"tgui-panel.bundle.css" = file("tgui/public/tgui-panel.bundle.css"),
Expand Down
11 changes: 7 additions & 4 deletions code/modules/asset_cache/packs/changelog_item.dm
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

/datum/asset_pack/changelog_item
abstract_type = /datum/asset_pack/changelog_item
var/item_name
var/item_filename

/datum/asset_pack/changelog_item/New(date)
item_filename = SANITIZE_FILENAME("[date].yml")
/datum/asset_pack/changelog_item/New(id)
..()
item_name = "[id].yml"
item_filename = SANITIZE_FILENAME("[id].yml")

/datum/asset_pack/changelog_item/register()
/datum/asset_pack/changelog_item/register(generation)
return list(
item_filename = file("html/changelogs/archive/" + item_filename),
(item_name) = file("html/changelogs/archive/" + item_filename),
)
2 changes: 1 addition & 1 deletion tgui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"terser-webpack-plugin": "^5.1.4",
"typescript": "4.9.5",
"url-loader": "^4.1.1",
"webpack": "^5.89.0",
"webpack": "^5.93.0",
"webpack-bundle-analyzer": "^4.10.1",
"webpack-cli": "^5.1.4"
},
Expand Down
129 changes: 71 additions & 58 deletions tgui/packages/tgui-dev-server/dreamseeker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ import { exec } from 'child_process';
import { promisify } from 'util';
import { createLogger } from './logging.js';
import { require } from './require.js';
// import axios from 'axios';

const axios = require('axios');
const logger = createLogger('dreamseeker');

// const instanceByPid: Map<number, DreamSeeker> = new Map();
const instanceByPid = new Map();

export class DreamSeeker {
// pid: number;
// addr: string;
// client: AxiosInstance;

constructor(pid, addr) {
this.pid = pid;
this.addr = addr;
Expand All @@ -28,73 +34,80 @@ export class DreamSeeker {
.map(key => encodeURIComponent(key)
+ '=' + encodeURIComponent(params[key]))
.join('&');
return this.client.get('/dummy?' + query);
logger.log(
`topic call at ${this.client.defaults.baseURL + '/dummy?' + query}`,
);
this.client.get('/dummy?' + query).catch((e) => logger.log(`topic call failed with ${e}`));
}
}

/**
* @param {number[]} pids
* @returns {DreamSeeker[]}
*/
DreamSeeker.getInstancesByPids = async pids => {
if (process.platform !== 'win32') {
return [];
}
const instances = [];
const pidsToResolve = [];
for (let pid of pids) {
const instance = instanceByPid.get(pid);
if (instance) {
instances.push(instance);
}
else {
pidsToResolve.push(pid);
/**
* @param {number[]} pids
* @returns {DreamSeeker[]}
*/
// static async getInstancesByPids(pids: number[]) {
static async getInstancesByPids(pids) {
if (process.platform !== 'win32') {
return [];
}
}
if (pidsToResolve.length > 0) {
try {
const command = 'netstat -ano | findstr TCP | findstr 0.0.0.0:0';
const { stdout } = await promisify(exec)(command, {
// Max buffer of 1MB (default is 200KB)
maxBuffer: 1024 * 1024,
});
// Line format:
// proto addr mask mode pid
const entries = [];
const lines = stdout.split('\r\n');
for (let line of lines) {
const words = line.match(/\S+/g);
if (!words || words.length === 0) {
continue;
}
const entry = {
addr: words[1],
pid: parseInt(words[4], 10),
};
if (pidsToResolve.includes(entry.pid)) {
entries.push(entry);
}
}
const len = entries.length;
logger.log('found', len, plural('instance', len));
for (let entry of entries) {
const { pid, addr } = entry;
const instance = new DreamSeeker(pid, addr);
// const instances: DreamSeeker[] = [];
// const pidsToResolve: number[] = [];
const instances = [];
const pidsToResolve = [];
for (let pid of pids) {
const instance = instanceByPid.get(pid);
if (instance) {
instances.push(instance);
instanceByPid.set(pid, instance);
}
else {
pidsToResolve.push(pid);
}
}
catch (err) {
if (err.code === 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER') {
logger.error(err.message, err.code);
if (pidsToResolve.length > 0) {
try {
const command = 'netstat -ano | findstr TCP | findstr 0.0.0.0:0';
const { stdout } = await promisify(exec)(command, {
// Max buffer of 1MB (default is 200KB)
maxBuffer: 1024 * 1024,
});
// Line format:
// proto addr mask mode pid
// const entries: {addr: string, pid: number}[] = [];
const entries = [];
const lines = stdout.split('\r\n');
for (let line of lines) {
const words = line.match(/\S+/g);
if (!words || words.length === 0) {
continue;
}
const entry = {
addr: words[1],
pid: parseInt(words[4], 10),
};
if (pidsToResolve.includes(entry.pid)) {
entries.push(entry);
}
}
const len = entries.length;
logger.log('found', len, plural('instance', len), ": ", JSON.stringify(entries));
for (let entry of entries) {
const { pid, addr } = entry;
const instance = new DreamSeeker(pid, addr);
instances.push(instance);
instanceByPid.set(pid, instance);
}
}
else {
logger.error(err);
catch (err) {
if (err.code === 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER') {
logger.error(err.message, err.code);
}
else {
logger.error(err);
}
return [];
}
return [];
}
return instances;
}
return instances;
};
}

const plural = (word, n) => n !== 1 ? word + 's' : word;
8 changes: 4 additions & 4 deletions tgui/packages/tgui-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"version": "4.3.1",
"type": "module",
"dependencies": {
"axios": "^1.6.0",
"glob": "^7.1.7",
"source-map": "^0.7.3",
"axios": "^1.7.3",
"glob": "7.1.7",
"source-map": "^0.7.4",
"stacktrace-parser": "^0.1.10",
"ws": "^7.5.3"
"ws": "^8.18.0"
}
}
1 change: 1 addition & 0 deletions tgui/packages/tgui-dev-server/reloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const reloadByondCache = async bundleDir => {
logger.log('found no tmp folder in cache');
return;
}
cacheDirs.forEach((dir) => fs.closeSync(fs.openSync(dir + '/dummy', 'w')));
// Get dreamseeker instances
const pids = cacheDirs.map(cacheDir => (
parseInt(cacheDir.split('/cache/tmp').pop(), 10)
Expand Down
Loading

0 comments on commit 0227a74

Please sign in to comment.