@rithien/comfy_adapter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -0
- package/controller.js +453 -0
- package/dist/web/manifest.json +6 -0
- package/dist/web/static/comfy_adapter.1ca70d5b170a77bb6963.js +526 -0
- package/dist/web/static/info_js.9ad5f016be3454c1a255.js +22 -0
- package/dist/web/static/main.761df12d5815fb8e02fa.js +121 -0
- package/dist/web/static/package_json.b88ad27d58c1784bb20f.js +22 -0
- package/info.js +245 -0
- package/instance.js +303 -0
- package/package.json +33 -0
- package/web/index.jsx +10 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ATTENTION: An "eval-source-map" devtool has been used.
|
|
3
|
+
* This devtool is neither made for production nor for readable output files.
|
|
4
|
+
* It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
|
|
5
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
6
|
+
* or disable the default devtool with "devtool: false".
|
|
7
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
8
|
+
*/
|
|
9
|
+
/******/ (() => { // webpackBootstrap
|
|
10
|
+
/******/ "use strict";
|
|
11
|
+
/******/ var __webpack_modules__ = ({
|
|
12
|
+
|
|
13
|
+
/***/ 162
|
|
14
|
+
/*!***********************!*\
|
|
15
|
+
!*** ./web/index.jsx ***!
|
|
16
|
+
\***********************/
|
|
17
|
+
() {
|
|
18
|
+
|
|
19
|
+
eval("{ // factorio-polska / comfy_adapter — web UI bundle (placeholder Faza 2.5).\n //\n // Plugin manifest jest eksportowany przez `./info.js` (zgodnie z webpack.config.js\n // `exposes: { \"./\" : \"./info.js\" }`). Ten plik istnieje jako entry point webpack'a;\n // faktyczne komponenty React per-instance panel (Faza 2.X: lista trusted, historia\n // eventów anti-grief, ręczne /trust) zostaną dodane w kolejnych iteracjach.\n //\n // W obecnej fazie (2.5) plugin nie eksponuje żadnego web UI — clusterio admin panel\n // pokazuje tylko config fields z info.js (controllerConfigFields).\n//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMTYyLmpzIiwibWFwcGluZ3MiOiJBQUFhLENBQ2IsMEVBQTBFO0NBQzFFLEVBQUU7Q0FDRixtRkFBbUY7Q0FDbkYsb0ZBQW9GO0NBQ3BGLG1GQUFtRjtDQUNuRiw0RUFBNEU7Q0FDNUUsRUFBRTtDQUNGLG9GQUFvRjtDQUNwRixtRUFBbUUiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9Acml0aGllbi9jb21meV9hZGFwdGVyLy4vd2ViL2luZGV4LmpzeD9lMjIzIl0sInNvdXJjZXNDb250ZW50IjpbIlwidXNlIHN0cmljdFwiO1xuLy8gZmFjdG9yaW8tcG9sc2thIC8gY29tZnlfYWRhcHRlciDigJQgd2ViIFVJIGJ1bmRsZSAocGxhY2Vob2xkZXIgRmF6YSAyLjUpLlxuLy9cbi8vIFBsdWdpbiBtYW5pZmVzdCBqZXN0IGVrc3BvcnRvd2FueSBwcnpleiBgLi9pbmZvLmpzYCAoemdvZG5pZSB6IHdlYnBhY2suY29uZmlnLmpzXG4vLyBgZXhwb3NlczogeyBcIi4vXCIgOiBcIi4vaW5mby5qc1wiIH1gKS4gVGVuIHBsaWsgaXN0bmllamUgamFrbyBlbnRyeSBwb2ludCB3ZWJwYWNrJ2E7XG4vLyBmYWt0eWN6bmUga29tcG9uZW50eSBSZWFjdCBwZXItaW5zdGFuY2UgcGFuZWwgKEZhemEgMi5YOiBsaXN0YSB0cnVzdGVkLCBoaXN0b3JpYVxuLy8gZXZlbnTDs3cgYW50aS1ncmllZiwgcsSZY3puZSAvdHJ1c3QpIHpvc3RhbsSFIGRvZGFuZSB3IGtvbGVqbnljaCBpdGVyYWNqYWNoLlxuLy9cbi8vIFcgb2JlY25laiBmYXppZSAoMi41KSBwbHVnaW4gbmllIGVrc3BvbnVqZSDFvGFkbmVnbyB3ZWIgVUkg4oCUIGNsdXN0ZXJpbyBhZG1pbiBwYW5lbFxuLy8gcG9rYXp1amUgdHlsa28gY29uZmlnIGZpZWxkcyB6IGluZm8uanMgKGNvbnRyb2xsZXJDb25maWdGaWVsZHMpLlxuIl0sIm5hbWVzIjpbXSwic291cmNlUm9vdCI6IiJ9\n//# sourceURL=webpack-internal:///162\n\n}");
|
|
20
|
+
|
|
21
|
+
/***/ }
|
|
22
|
+
|
|
23
|
+
/******/ });
|
|
24
|
+
/************************************************************************/
|
|
25
|
+
/******/ // The module cache
|
|
26
|
+
/******/ var __webpack_module_cache__ = {};
|
|
27
|
+
/******/
|
|
28
|
+
/******/ // The require function
|
|
29
|
+
/******/ function __webpack_require__(moduleId) {
|
|
30
|
+
/******/ // Check if module is in cache
|
|
31
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
32
|
+
/******/ if (cachedModule !== undefined) {
|
|
33
|
+
/******/ return cachedModule.exports;
|
|
34
|
+
/******/ }
|
|
35
|
+
/******/ // Create a new module (and put it into the cache)
|
|
36
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
37
|
+
/******/ // no module.id needed
|
|
38
|
+
/******/ // no module.loaded needed
|
|
39
|
+
/******/ exports: {}
|
|
40
|
+
/******/ };
|
|
41
|
+
/******/
|
|
42
|
+
/******/ // Execute the module function
|
|
43
|
+
/******/ if (!(moduleId in __webpack_modules__)) {
|
|
44
|
+
/******/ delete __webpack_module_cache__[moduleId];
|
|
45
|
+
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
|
|
46
|
+
/******/ e.code = 'MODULE_NOT_FOUND';
|
|
47
|
+
/******/ throw e;
|
|
48
|
+
/******/ }
|
|
49
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
50
|
+
/******/
|
|
51
|
+
/******/ // Return the exports of the module
|
|
52
|
+
/******/ return module.exports;
|
|
53
|
+
/******/ }
|
|
54
|
+
/******/
|
|
55
|
+
/******/ // expose the modules object (__webpack_modules__)
|
|
56
|
+
/******/ __webpack_require__.m = __webpack_modules__;
|
|
57
|
+
/******/
|
|
58
|
+
/******/ // expose the module cache
|
|
59
|
+
/******/ __webpack_require__.c = __webpack_module_cache__;
|
|
60
|
+
/******/
|
|
61
|
+
/************************************************************************/
|
|
62
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
63
|
+
/******/ (() => {
|
|
64
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
65
|
+
/******/ })();
|
|
66
|
+
/******/
|
|
67
|
+
/******/ /* webpack/runtime/sharing */
|
|
68
|
+
/******/ (() => {
|
|
69
|
+
/******/ __webpack_require__.S = {};
|
|
70
|
+
/******/ var initPromises = {};
|
|
71
|
+
/******/ var initTokens = {};
|
|
72
|
+
/******/ __webpack_require__.I = (name, initScope) => {
|
|
73
|
+
/******/ if(!initScope) initScope = [];
|
|
74
|
+
/******/ // handling circular init calls
|
|
75
|
+
/******/ var initToken = initTokens[name];
|
|
76
|
+
/******/ if(!initToken) initToken = initTokens[name] = {};
|
|
77
|
+
/******/ if(initScope.indexOf(initToken) >= 0) return;
|
|
78
|
+
/******/ initScope.push(initToken);
|
|
79
|
+
/******/ // only runs once
|
|
80
|
+
/******/ if(initPromises[name]) return initPromises[name];
|
|
81
|
+
/******/ // creates a new share scope if needed
|
|
82
|
+
/******/ if(!__webpack_require__.o(__webpack_require__.S, name)) __webpack_require__.S[name] = {};
|
|
83
|
+
/******/ // runs all init snippets from all modules reachable
|
|
84
|
+
/******/ var scope = __webpack_require__.S[name];
|
|
85
|
+
/******/ var warn = (msg) => {
|
|
86
|
+
/******/ if (typeof console !== "undefined" && console.warn) console.warn(msg);
|
|
87
|
+
/******/ };
|
|
88
|
+
/******/ var uniqueName = "@rithien/comfy_adapter";
|
|
89
|
+
/******/ var register = (name, version, factory, eager) => {
|
|
90
|
+
/******/ var versions = scope[name] = scope[name] || {};
|
|
91
|
+
/******/ var activeVersion = versions[version];
|
|
92
|
+
/******/ if(!activeVersion || (!activeVersion.loaded && (!eager != !activeVersion.eager ? eager : uniqueName > activeVersion.from))) versions[version] = { get: factory, from: uniqueName, eager: !!eager };
|
|
93
|
+
/******/ };
|
|
94
|
+
/******/ var initExternal = (id) => {
|
|
95
|
+
/******/ var handleError = (err) => (warn("Initialization of sharing external failed: " + err));
|
|
96
|
+
/******/ try {
|
|
97
|
+
/******/ var module = __webpack_require__(id);
|
|
98
|
+
/******/ if(!module) return;
|
|
99
|
+
/******/ var initFn = (module) => (module && module.init && module.init(__webpack_require__.S[name], initScope))
|
|
100
|
+
/******/ if(module.then) return promises.push(module.then(initFn, handleError));
|
|
101
|
+
/******/ var initResult = initFn(module);
|
|
102
|
+
/******/ if(initResult && initResult.then) return promises.push(initResult['catch'](handleError));
|
|
103
|
+
/******/ } catch(err) { handleError(err); }
|
|
104
|
+
/******/ }
|
|
105
|
+
/******/ var promises = [];
|
|
106
|
+
/******/ switch(name) {
|
|
107
|
+
/******/ }
|
|
108
|
+
/******/ if(!promises.length) return initPromises[name] = 1;
|
|
109
|
+
/******/ return initPromises[name] = Promise.all(promises).then(() => (initPromises[name] = 1));
|
|
110
|
+
/******/ };
|
|
111
|
+
/******/ })();
|
|
112
|
+
/******/
|
|
113
|
+
/************************************************************************/
|
|
114
|
+
/******/
|
|
115
|
+
/******/ // module cache are used so entry inlining is disabled
|
|
116
|
+
/******/ // startup
|
|
117
|
+
/******/ // Load entry module and return exports
|
|
118
|
+
/******/ var __webpack_exports__ = __webpack_require__(162);
|
|
119
|
+
/******/
|
|
120
|
+
/******/ })()
|
|
121
|
+
;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* ATTENTION: An "eval-source-map" devtool has been used.
|
|
4
|
+
* This devtool is neither made for production nor for readable output files.
|
|
5
|
+
* It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
|
|
6
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
7
|
+
* or disable the default devtool with "devtool: false".
|
|
8
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
9
|
+
*/
|
|
10
|
+
(self["webpackChunk_rithien_comfy_adapter"] = self["webpackChunk_rithien_comfy_adapter"] || []).push([["package_json"],{
|
|
11
|
+
|
|
12
|
+
/***/ 330
|
|
13
|
+
/*!**********************!*\
|
|
14
|
+
!*** ./package.json ***!
|
|
15
|
+
\**********************/
|
|
16
|
+
(module) {
|
|
17
|
+
|
|
18
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rithien/comfy_adapter","version":"0.1.0","description":"Clusterio plugin: parses Comfy/factorio-polska scenario stdout tags ([DISCORD*], [ANTIGRIEF-LOG], [DATA-SET/GET]) and bridges to Discord + JSON datastore","main":"info.js","scripts":{"test":"echo \\"Error: no test specified\\" && exit 1","prepare":"webpack-cli --env production"},"keywords":["clusterio","clusterio-plugin","factorio","factorio-polska","discord","comfyfactorio"],"author":"rithien <jacek@zaluzje.bialystok.pl>","license":"MIT","peerDependencies":{"@clusterio/lib":"^2.0.0-alpha.14"},"devDependencies":{"@clusterio/lib":"^2.0.0-alpha.14","@clusterio/web_ui":"^2.0.0-alpha.14","webpack":"^5.88.2","webpack-cli":"^5.1.4","webpack-merge":"^5.9.0"},"publishConfig":{"access":"public"}}');
|
|
19
|
+
|
|
20
|
+
/***/ }
|
|
21
|
+
|
|
22
|
+
}]);
|
package/info.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// factorio-polska / comfy_adapter — plugin manifest + event schemas (Faza 2.5).
|
|
3
|
+
//
|
|
4
|
+
// Plugin parsuje tagowany stdout scenariusza Lua (`@rithien/factorio-polska` v0.1.0+) i:
|
|
5
|
+
// 1. Forwarduje `[DISCORD*]` + `[ANTIGRIEF-LOG]` tagi do Discord przez współistniejący
|
|
6
|
+
// `@rithien/discord_bridge` (channel routing per instancja z Fazy 1).
|
|
7
|
+
// 2. Trzyma persistent JSON datastore na kontrolerze (`storage_path`) dla
|
|
8
|
+
// `[DATA-SET]` (UPSERT) i `[DATA-GET]` (read + RCON callback przez `/cc`).
|
|
9
|
+
//
|
|
10
|
+
// Architektura messaging:
|
|
11
|
+
// - Instance → Controller: 4 typy eventów (ScenarioDiscordEvent, AntigriefLogEvent,
|
|
12
|
+
// DataSetEvent, DataGetRequest).
|
|
13
|
+
// - Controller → Instance: brak eventów custom (responses do scenariusza idą przez
|
|
14
|
+
// `host.sendRconCommand('/cc ...')` które trzyma host clusterio; nie potrzebujemy
|
|
15
|
+
// own event schema dla controller→instance pipe).
|
|
16
|
+
|
|
17
|
+
const lib = require("@clusterio/lib");
|
|
18
|
+
|
|
19
|
+
// =========================================================================
|
|
20
|
+
// Events: Instance → Controller
|
|
21
|
+
// =========================================================================
|
|
22
|
+
|
|
23
|
+
// Wysyłany przez instance.js gdy stdout match'uje `[DISCORD]`, `[DISCORD-RAW]`,
|
|
24
|
+
// `[DISCORD-BOLD]`, `[DISCORD-ADMIN]`, `[DISCORD-ADMIN-RAW]`, `[DISCORD-EMBED]`,
|
|
25
|
+
// `[DISCORD-EMBED-RAW]`, `[DISCORD-EMBED-PARSED]`, `[DISCORD-ADMIN-EMBED]`,
|
|
26
|
+
// `[DISCORD-ADMIN-EMBED-RAW]`.
|
|
27
|
+
//
|
|
28
|
+
// variant: nazwa tagu bez prefiksu '[' i sufiksu ']' (np. "DISCORD", "DISCORD-EMBED-PARSED").
|
|
29
|
+
// content: dla zwykłych tagów = surowy string wiadomości; dla `DISCORD-EMBED-PARSED` =
|
|
30
|
+
// JSON `{title, description, color?, fields?}` (string).
|
|
31
|
+
class ScenarioDiscordEvent {
|
|
32
|
+
static type = "event";
|
|
33
|
+
static src = "instance";
|
|
34
|
+
static dst = "controller";
|
|
35
|
+
static plugin = "comfy_adapter";
|
|
36
|
+
|
|
37
|
+
constructor(instanceName, variant, content) {
|
|
38
|
+
this.instanceName = instanceName;
|
|
39
|
+
this.variant = variant;
|
|
40
|
+
this.content = content;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static jsonSchema = {
|
|
44
|
+
type: "object",
|
|
45
|
+
required: ["instanceName", "variant", "content"],
|
|
46
|
+
properties: {
|
|
47
|
+
"instanceName": { type: "string" },
|
|
48
|
+
"variant": { type: "string" },
|
|
49
|
+
"content": { type: "string" },
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
static fromJSON(json) {
|
|
54
|
+
return new this(json.instanceName, json.variant, json.content);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Wysyłany przez instance.js gdy stdout match'uje `[ANTIGRIEF-LOG]{category, action}`.
|
|
59
|
+
class AntigriefLogEvent {
|
|
60
|
+
static type = "event";
|
|
61
|
+
static src = "instance";
|
|
62
|
+
static dst = "controller";
|
|
63
|
+
static plugin = "comfy_adapter";
|
|
64
|
+
|
|
65
|
+
constructor(instanceName, category, action) {
|
|
66
|
+
this.instanceName = instanceName;
|
|
67
|
+
this.category = category;
|
|
68
|
+
this.action = action;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static jsonSchema = {
|
|
72
|
+
type: "object",
|
|
73
|
+
required: ["instanceName", "category", "action"],
|
|
74
|
+
properties: {
|
|
75
|
+
"instanceName": { type: "string" },
|
|
76
|
+
"category": { type: "string" },
|
|
77
|
+
"action": { type: "string" },
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
static fromJSON(json) {
|
|
82
|
+
return new this(json.instanceName, json.category, json.action);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Wysyłany przez instance.js gdy stdout match'uje `[DATA-SET]{data_set, key, value?}`.
|
|
87
|
+
// value === null oznacza usunięcie wpisu (DELETE).
|
|
88
|
+
// value może być: string, number, boolean, object (deserializowany z formatu Lua serpent).
|
|
89
|
+
class DataSetEvent {
|
|
90
|
+
static type = "event";
|
|
91
|
+
static src = "instance";
|
|
92
|
+
static dst = "controller";
|
|
93
|
+
static plugin = "comfy_adapter";
|
|
94
|
+
|
|
95
|
+
constructor(instanceName, dataSet, key, value) {
|
|
96
|
+
this.instanceName = instanceName;
|
|
97
|
+
this.dataSet = dataSet;
|
|
98
|
+
this.key = key;
|
|
99
|
+
this.value = value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static jsonSchema = {
|
|
103
|
+
type: "object",
|
|
104
|
+
required: ["instanceName", "dataSet", "key"],
|
|
105
|
+
properties: {
|
|
106
|
+
"instanceName": { type: "string" },
|
|
107
|
+
"dataSet": { type: "string" },
|
|
108
|
+
"key": { type: "string" },
|
|
109
|
+
// value może być dowolnego typu (string|number|boolean|object|null) — bez `type:` constraint.
|
|
110
|
+
"value": {},
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
static fromJSON(json) {
|
|
115
|
+
return new this(json.instanceName, json.dataSet, json.key, json.value ?? null);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Wysyłany przez instance.js gdy stdout match'uje `[DATA-GET]<token>{data_set, key}`,
|
|
120
|
+
// `[DATA-GET-AND-PRINT]<token>{...,to_print}`, `[DATA-GET-ALL]<token>{data_set}`.
|
|
121
|
+
//
|
|
122
|
+
// mode: "get" | "get_and_print" | "get_all" — determinuje response shape.
|
|
123
|
+
// token: callback_token Lua (Token.uid) — plugin echo'uje go w RCON response żeby
|
|
124
|
+
// Token.get(<token>)({...}) zadziałał lokalnie w scenariuszu.
|
|
125
|
+
// key: dla "get_all" pole nieobecne (data_set entire dump).
|
|
126
|
+
// toPrint: tylko dla "get_and_print" — nazwa gracza do print'u.
|
|
127
|
+
class DataGetRequest {
|
|
128
|
+
static type = "event";
|
|
129
|
+
static src = "instance";
|
|
130
|
+
static dst = "controller";
|
|
131
|
+
static plugin = "comfy_adapter";
|
|
132
|
+
|
|
133
|
+
constructor(instanceName, instanceId, mode, token, dataSet, key, toPrint) {
|
|
134
|
+
this.instanceName = instanceName;
|
|
135
|
+
this.instanceId = instanceId;
|
|
136
|
+
this.mode = mode;
|
|
137
|
+
this.token = token;
|
|
138
|
+
this.dataSet = dataSet;
|
|
139
|
+
this.key = key ?? null;
|
|
140
|
+
this.toPrint = toPrint ?? null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static jsonSchema = {
|
|
144
|
+
type: "object",
|
|
145
|
+
required: ["instanceName", "instanceId", "mode", "token", "dataSet"],
|
|
146
|
+
properties: {
|
|
147
|
+
"instanceName": { type: "string" },
|
|
148
|
+
"instanceId": { type: "integer" },
|
|
149
|
+
"mode": { type: "string", enum: ["get", "get_and_print", "get_all"] },
|
|
150
|
+
"token": { type: "integer" },
|
|
151
|
+
"dataSet": { type: "string" },
|
|
152
|
+
"key": { type: ["string", "null"] },
|
|
153
|
+
"toPrint": { type: ["string", "null"] },
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
static fromJSON(json) {
|
|
158
|
+
return new this(
|
|
159
|
+
json.instanceName,
|
|
160
|
+
json.instanceId,
|
|
161
|
+
json.mode,
|
|
162
|
+
json.token,
|
|
163
|
+
json.dataSet,
|
|
164
|
+
json.key,
|
|
165
|
+
json.toPrint,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// =========================================================================
|
|
171
|
+
// Plugin manifest
|
|
172
|
+
// =========================================================================
|
|
173
|
+
|
|
174
|
+
const plugin = {
|
|
175
|
+
name: "comfy_adapter",
|
|
176
|
+
title: "Comfy Adapter",
|
|
177
|
+
description:
|
|
178
|
+
"Parses stdout tags from factorio-polska scenario: forwards [DISCORD*]/[ANTIGRIEF-LOG] to Discord " +
|
|
179
|
+
"(via discord_bridge channel routing) and persists [DATA-SET]/[DATA-GET] in a JSON file on the controller.",
|
|
180
|
+
instanceEntrypoint: "instance",
|
|
181
|
+
controllerEntrypoint: "controller",
|
|
182
|
+
instanceConfigFields: {},
|
|
183
|
+
controllerConfigFields: {
|
|
184
|
+
"comfy_adapter.storage_path": {
|
|
185
|
+
title: "Datastore path",
|
|
186
|
+
description:
|
|
187
|
+
"Path to the JSON file where comfy_adapter persists scenario datasets " +
|
|
188
|
+
"(sessions, future: jailed, warnings, ...). Path is relative to the controller's " +
|
|
189
|
+
"working directory unless absolute. Created on first write.",
|
|
190
|
+
type: "string",
|
|
191
|
+
initialValue: "comfy_adapter_storage.json",
|
|
192
|
+
},
|
|
193
|
+
"comfy_adapter.write_debounce_ms": {
|
|
194
|
+
title: "Write debounce (ms)",
|
|
195
|
+
description:
|
|
196
|
+
"Coalesce multiple [DATA-SET] writes within this window into a single disk flush. " +
|
|
197
|
+
"Reduces fsync churn at the cost of risking up to N ms of data loss on crash.",
|
|
198
|
+
type: "number",
|
|
199
|
+
initialValue: 1000,
|
|
200
|
+
},
|
|
201
|
+
"comfy_adapter.antigrief_log_as_embed": {
|
|
202
|
+
title: "Antigrief log as embed",
|
|
203
|
+
description:
|
|
204
|
+
"If true, [ANTIGRIEF-LOG] events are sent to Discord as color-coded embeds. " +
|
|
205
|
+
"If false, sent as plain `[ANTIGRIEF: <category>] <action>` messages.",
|
|
206
|
+
type: "boolean",
|
|
207
|
+
initialValue: true,
|
|
208
|
+
},
|
|
209
|
+
"comfy_adapter.admin_prefix": {
|
|
210
|
+
title: "Admin message prefix",
|
|
211
|
+
description:
|
|
212
|
+
"Prefix prepended to messages from [DISCORD-ADMIN*] tags before sending to the instance " +
|
|
213
|
+
"channel. The factorio-polska model uses a single Discord channel per instance, so admin " +
|
|
214
|
+
"messages are distinguished by prefix rather than a separate channel.",
|
|
215
|
+
type: "string",
|
|
216
|
+
initialValue: "[ADMIN] ",
|
|
217
|
+
},
|
|
218
|
+
"comfy_adapter.broadcast_data_sets": {
|
|
219
|
+
title: "Broadcast datasets",
|
|
220
|
+
description:
|
|
221
|
+
"Comma-separated list of dataset names whose [DATA-SET] writes are broadcast to ALL OTHER " +
|
|
222
|
+
"instances via /cc Server.raise_data_set(...). Enables cross-server sync (e.g., player trust " +
|
|
223
|
+
"earned on instance A is propagated to instance B immediately, instead of requiring B to " +
|
|
224
|
+
"refetch on next join). Leave empty to disable broadcast entirely. Default 'sessions' covers " +
|
|
225
|
+
"auto-trust playtime; add other datasets here as the scenario grows.",
|
|
226
|
+
type: "string",
|
|
227
|
+
initialValue: "sessions",
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
messages: [
|
|
232
|
+
ScenarioDiscordEvent,
|
|
233
|
+
AntigriefLogEvent,
|
|
234
|
+
DataSetEvent,
|
|
235
|
+
DataGetRequest,
|
|
236
|
+
],
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
module.exports = {
|
|
240
|
+
plugin,
|
|
241
|
+
ScenarioDiscordEvent,
|
|
242
|
+
AntigriefLogEvent,
|
|
243
|
+
DataSetEvent,
|
|
244
|
+
DataGetRequest,
|
|
245
|
+
};
|
package/instance.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// factorio-polska / comfy_adapter — instance plugin (Faza 2.5).
|
|
3
|
+
//
|
|
4
|
+
// Hook `onOutput` łapie każdą linię stdout scenariusza (output.message). Linie zaczynające się
|
|
5
|
+
// od `[<TAG>]` parsuje wg jednej z 13 form:
|
|
6
|
+
//
|
|
7
|
+
// Discord (10 wariantów):
|
|
8
|
+
// [DISCORD]<msg> [DISCORD-RAW]<msg> [DISCORD-BOLD]<msg>
|
|
9
|
+
// [DISCORD-ADMIN]<msg> [DISCORD-ADMIN-RAW]<msg>
|
|
10
|
+
// [DISCORD-EMBED]<msg> [DISCORD-EMBED-RAW]<msg> [DISCORD-EMBED-PARSED]<json>
|
|
11
|
+
// [DISCORD-ADMIN-EMBED]<msg> [DISCORD-ADMIN-EMBED-RAW]<msg>
|
|
12
|
+
//
|
|
13
|
+
// Antigrief log (1):
|
|
14
|
+
// [ANTIGRIEF-LOG]{category:"X",action:"Y"}
|
|
15
|
+
//
|
|
16
|
+
// Datastore (4):
|
|
17
|
+
// [DATA-SET]{data_set:"X",key:"Y",value:Z?} (Z = nil → DELETE)
|
|
18
|
+
// [DATA-GET]<token> {data_set:"X",key:"Y"}
|
|
19
|
+
// [DATA-GET-AND-PRINT]<token> {data_set:"X",key:"Y",to_print:"Z"}
|
|
20
|
+
// [DATA-GET-ALL]<token> {data_set:"X"}
|
|
21
|
+
//
|
|
22
|
+
// Payload format (`{key:"val",...}`) to **pseudo-JSON Comfy** — keys bez cudzysłowów,
|
|
23
|
+
// values w double-quotes (string/number/boolean) lub single-quotes (serpent table).
|
|
24
|
+
// Specjalna funkcja `parseComfyPayload` poniżej robi minimalny parser pod ten format.
|
|
25
|
+
|
|
26
|
+
const { BaseInstancePlugin } = require("@clusterio/host");
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
ScenarioDiscordEvent,
|
|
30
|
+
AntigriefLogEvent,
|
|
31
|
+
DataSetEvent,
|
|
32
|
+
DataGetRequest,
|
|
33
|
+
} = require("./info.js");
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
// Stały zbiór nazw tagów Discord → variant string przekazywany w ScenarioDiscordEvent.
|
|
37
|
+
const DISCORD_VARIANTS = new Set([
|
|
38
|
+
"DISCORD",
|
|
39
|
+
"DISCORD-RAW",
|
|
40
|
+
"DISCORD-BOLD",
|
|
41
|
+
"DISCORD-ADMIN",
|
|
42
|
+
"DISCORD-ADMIN-RAW",
|
|
43
|
+
"DISCORD-EMBED",
|
|
44
|
+
"DISCORD-EMBED-RAW",
|
|
45
|
+
"DISCORD-EMBED-PARSED",
|
|
46
|
+
"DISCORD-ADMIN-EMBED",
|
|
47
|
+
"DISCORD-ADMIN-EMBED-RAW",
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
// `[TAG]<reszta>` — TAG to wielkie litery + myślniki.
|
|
51
|
+
const TAG_RE = /^\[([A-Z][A-Z0-9-]*)\](.*)$/;
|
|
52
|
+
|
|
53
|
+
// `[DATA-GET]<token> {payload}` (i warianty get_and_print / get_all).
|
|
54
|
+
const DATA_GET_RE = /^(\d+)\s*(\{.*\})$/;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Mini-parser pseudo-Lua-JSON format z Comfy: `{key:"val",key2:N,key3:"str"}`.
|
|
59
|
+
* - Klucze bez cudzysłowów (identyfikatory: [a-zA-Z_][a-zA-Z0-9_]*).
|
|
60
|
+
* - Stringi w double-quotes z escapami: \" \\ \n
|
|
61
|
+
* - Numery bez cudzysłowów (mimo że Lua side często wrapuje liczby w stringi).
|
|
62
|
+
* - Boolean: true / false.
|
|
63
|
+
* - Nested object: { ... }
|
|
64
|
+
*
|
|
65
|
+
* Zwraca obiekt JS lub rzuca Error przy malformed input.
|
|
66
|
+
*/
|
|
67
|
+
function parseComfyPayload(s) {
|
|
68
|
+
let i = 0;
|
|
69
|
+
const len = s.length;
|
|
70
|
+
|
|
71
|
+
function skipWs() {
|
|
72
|
+
while (i < len && (s[i] === " " || s[i] === "\t" || s[i] === "\n")) {
|
|
73
|
+
i++;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function expect(ch) {
|
|
78
|
+
if (s[i] !== ch) {
|
|
79
|
+
throw new Error(`parseComfyPayload: expected '${ch}' at pos ${i} in: ${s}`);
|
|
80
|
+
}
|
|
81
|
+
i++;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function parseString() {
|
|
85
|
+
const quote = s[i];
|
|
86
|
+
if (quote !== '"' && quote !== "'") {
|
|
87
|
+
throw new Error(`parseComfyPayload: expected string at pos ${i} in: ${s}`);
|
|
88
|
+
}
|
|
89
|
+
i++;
|
|
90
|
+
let out = "";
|
|
91
|
+
while (i < len && s[i] !== quote) {
|
|
92
|
+
if (s[i] === "\\" && i + 1 < len) {
|
|
93
|
+
const next = s[i + 1];
|
|
94
|
+
if (next === "n") { out += "\n"; }
|
|
95
|
+
else if (next === "t") { out += "\t"; }
|
|
96
|
+
else if (next === "r") { out += "\r"; }
|
|
97
|
+
else { out += next; }
|
|
98
|
+
i += 2;
|
|
99
|
+
} else {
|
|
100
|
+
out += s[i];
|
|
101
|
+
i++;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (i >= len) {
|
|
105
|
+
throw new Error(`parseComfyPayload: unterminated string in: ${s}`);
|
|
106
|
+
}
|
|
107
|
+
i++; // closing quote
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parseIdent() {
|
|
112
|
+
const start = i;
|
|
113
|
+
while (i < len && /[a-zA-Z0-9_]/.test(s[i])) {
|
|
114
|
+
i++;
|
|
115
|
+
}
|
|
116
|
+
if (i === start) {
|
|
117
|
+
throw new Error(`parseComfyPayload: expected identifier at pos ${i} in: ${s}`);
|
|
118
|
+
}
|
|
119
|
+
return s.slice(start, i);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function parseValue() {
|
|
123
|
+
skipWs();
|
|
124
|
+
const ch = s[i];
|
|
125
|
+
if (ch === '"' || ch === "'") {
|
|
126
|
+
return parseString();
|
|
127
|
+
}
|
|
128
|
+
if (ch === "{") {
|
|
129
|
+
return parseObject();
|
|
130
|
+
}
|
|
131
|
+
// Number / boolean / bareword (np. nil).
|
|
132
|
+
const start = i;
|
|
133
|
+
while (i < len && /[^,}\s]/.test(s[i])) {
|
|
134
|
+
i++;
|
|
135
|
+
}
|
|
136
|
+
const raw = s.slice(start, i);
|
|
137
|
+
if (raw === "true") return true;
|
|
138
|
+
if (raw === "false") return false;
|
|
139
|
+
if (raw === "nil") return null;
|
|
140
|
+
const num = Number(raw);
|
|
141
|
+
if (!Number.isNaN(num)) return num;
|
|
142
|
+
// Fallback: traktuj jako string bez cudzysłowów (defensive).
|
|
143
|
+
return raw;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function parseObject() {
|
|
147
|
+
expect("{");
|
|
148
|
+
const out = {};
|
|
149
|
+
skipWs();
|
|
150
|
+
if (s[i] === "}") { i++; return out; }
|
|
151
|
+
while (i < len) {
|
|
152
|
+
skipWs();
|
|
153
|
+
const key = parseIdent();
|
|
154
|
+
skipWs();
|
|
155
|
+
expect(":");
|
|
156
|
+
out[key] = parseValue();
|
|
157
|
+
skipWs();
|
|
158
|
+
if (s[i] === ",") { i++; continue; }
|
|
159
|
+
if (s[i] === "}") { i++; break; }
|
|
160
|
+
throw new Error(`parseComfyPayload: expected ',' or '}' at pos ${i} in: ${s}`);
|
|
161
|
+
}
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
skipWs();
|
|
166
|
+
const obj = parseObject();
|
|
167
|
+
skipWs();
|
|
168
|
+
if (i < len) {
|
|
169
|
+
throw new Error(`parseComfyPayload: trailing data at pos ${i} in: ${s}`);
|
|
170
|
+
}
|
|
171
|
+
return obj;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class InstancePlugin extends BaseInstancePlugin {
|
|
176
|
+
async init() {
|
|
177
|
+
this.messageQueue = [];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
onControllerConnectionEvent(event) {
|
|
181
|
+
if (event === "connect" && this.messageQueue.length > 0) {
|
|
182
|
+
for (const ev of this.messageQueue) {
|
|
183
|
+
this.instance.sendTo("controller", ev);
|
|
184
|
+
}
|
|
185
|
+
this.messageQueue = [];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Wysyła event do kontrolera, lub buforuje gdy host disconnected.
|
|
191
|
+
*/
|
|
192
|
+
sendOrQueue(event) {
|
|
193
|
+
if (this.host.connector.connected) {
|
|
194
|
+
this.instance.sendTo("controller", event);
|
|
195
|
+
} else {
|
|
196
|
+
this.messageQueue.push(event);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Hook clusterio: każda linia stdout scenariusza.
|
|
202
|
+
*/
|
|
203
|
+
async onOutput(output) {
|
|
204
|
+
// `output.type` może być "action" (Factorio's [JOIN]/[LEAVE]/... built-in tags handled
|
|
205
|
+
// przez discord_bridge) lub generic. Tagi naszego scenariusza idą zwykle przez
|
|
206
|
+
// `raw_print` (Lua native `print` → stdout) co clusterio kategorizuje jako "generic".
|
|
207
|
+
// Akceptujemy wszystkie typy — filtr jest na regex tagu.
|
|
208
|
+
const line = output.message;
|
|
209
|
+
if (!line || typeof line !== "string") return;
|
|
210
|
+
|
|
211
|
+
const match = line.match(TAG_RE);
|
|
212
|
+
if (!match) return;
|
|
213
|
+
|
|
214
|
+
const tag = match[1];
|
|
215
|
+
const rest = match[2];
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
if (DISCORD_VARIANTS.has(tag)) {
|
|
219
|
+
this.handleDiscordTag(tag, rest);
|
|
220
|
+
} else if (tag === "ANTIGRIEF-LOG") {
|
|
221
|
+
this.handleAntigriefLog(rest);
|
|
222
|
+
} else if (tag === "DATA-SET") {
|
|
223
|
+
this.handleDataSet(rest);
|
|
224
|
+
} else if (tag === "DATA-GET") {
|
|
225
|
+
this.handleDataGet(rest, "get");
|
|
226
|
+
} else if (tag === "DATA-GET-AND-PRINT") {
|
|
227
|
+
this.handleDataGet(rest, "get_and_print");
|
|
228
|
+
} else if (tag === "DATA-GET-ALL") {
|
|
229
|
+
this.handleDataGet(rest, "get_all");
|
|
230
|
+
}
|
|
231
|
+
// Pozostałe tagi (np. [BAN-SYNC], [PING], [START-SCENARIO]) — silent skip.
|
|
232
|
+
// Bany robi clusterio natywnie, lifecycle nie używamy w naszym modelu.
|
|
233
|
+
} catch (err) {
|
|
234
|
+
this.logger.warn(`comfy_adapter parse error for "${tag}": ${err.message}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
handleDiscordTag(variant, content) {
|
|
239
|
+
this.sendOrQueue(new ScenarioDiscordEvent(this.instance.name, variant, content));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
handleAntigriefLog(payload) {
|
|
243
|
+
const obj = parseComfyPayload(payload);
|
|
244
|
+
const category = String(obj.category ?? "unknown");
|
|
245
|
+
const action = String(obj.action ?? "");
|
|
246
|
+
this.sendOrQueue(new AntigriefLogEvent(this.instance.name, category, action));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
handleDataSet(payload) {
|
|
250
|
+
const obj = parseComfyPayload(payload);
|
|
251
|
+
const dataSet = String(obj.data_set ?? "");
|
|
252
|
+
const key = String(obj.key ?? "");
|
|
253
|
+
// Lua side wrapuje numery jako stringi (`value:"648000"`); spróbuj odzyskać typ.
|
|
254
|
+
let value = obj.value;
|
|
255
|
+
if (value === undefined) {
|
|
256
|
+
value = null; // DELETE
|
|
257
|
+
} else if (typeof value === "string") {
|
|
258
|
+
// String z escapowanym wewnętrznym cudzysłowem (`value:"\"actual\""`) → unwrap.
|
|
259
|
+
if (value.length >= 2 && value[0] === '"' && value[value.length - 1] === '"') {
|
|
260
|
+
value = value.slice(1, -1);
|
|
261
|
+
} else if (value === "true") {
|
|
262
|
+
value = true;
|
|
263
|
+
} else if (value === "false") {
|
|
264
|
+
value = false;
|
|
265
|
+
} else {
|
|
266
|
+
const num = Number(value);
|
|
267
|
+
if (!Number.isNaN(num) && value.trim() !== "") {
|
|
268
|
+
value = num;
|
|
269
|
+
}
|
|
270
|
+
// Else: pozostaje string (np. serpent-serialized table — controller deserializuje).
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
this.sendOrQueue(new DataSetEvent(this.instance.name, dataSet, key, value));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
handleDataGet(rest, mode) {
|
|
277
|
+
// Format: `<token> {payload}` (z opcjonalnym whitespace).
|
|
278
|
+
const m = rest.match(DATA_GET_RE);
|
|
279
|
+
if (!m) {
|
|
280
|
+
throw new Error(`malformed DATA-GET payload: ${rest}`);
|
|
281
|
+
}
|
|
282
|
+
const token = parseInt(m[1], 10);
|
|
283
|
+
const obj = parseComfyPayload(m[2]);
|
|
284
|
+
const dataSet = String(obj.data_set ?? "");
|
|
285
|
+
const key = obj.key !== undefined ? String(obj.key) : null;
|
|
286
|
+
const toPrint = obj.to_print !== undefined ? String(obj.to_print) : null;
|
|
287
|
+
this.sendOrQueue(new DataGetRequest(
|
|
288
|
+
this.instance.name,
|
|
289
|
+
this.instance.id,
|
|
290
|
+
mode,
|
|
291
|
+
token,
|
|
292
|
+
dataSet,
|
|
293
|
+
key,
|
|
294
|
+
toPrint,
|
|
295
|
+
));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
module.exports = {
|
|
300
|
+
InstancePlugin,
|
|
301
|
+
// Eksport dla unit testów (przyszłość — żaden plik testowy w Fazie 2.5).
|
|
302
|
+
_parseComfyPayload: parseComfyPayload,
|
|
303
|
+
};
|