3
.gitignore
vendored
3
.gitignore
vendored
@@ -42,4 +42,5 @@ __pycache__/
|
||||
.tauri/
|
||||
dist.zip
|
||||
/scripts/
|
||||
.env
|
||||
.env
|
||||
/server/node/ssl/certificate
|
||||
@@ -9,6 +9,8 @@ app.use(express.static(path.join(process.cwd(), 'dist'), {index: false}));
|
||||
app.use(express.json({ limit: '50mb' }));
|
||||
app.use(express.raw({ type: 'application/octet-stream', limit: '50mb' }));
|
||||
const {pipeline} = require('stream/promises')
|
||||
const https = require('https');
|
||||
const sslPath = path.join(process.cwd(), 'server/node/ssl/certificate');
|
||||
|
||||
let password = ''
|
||||
|
||||
@@ -294,6 +296,57 @@ app.post('/api/write', async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(6001, () => {
|
||||
console.log("Server is listening on http://localhost:6001/");
|
||||
});
|
||||
async function getHttpsOptions() {
|
||||
|
||||
const keyPath = path.join(sslPath, 'server.key');
|
||||
const certPath = path.join(sslPath, 'server.crt');
|
||||
|
||||
console.log(keyPath)
|
||||
console.log(certPath)
|
||||
|
||||
try {
|
||||
|
||||
await fs.access(keyPath);
|
||||
await fs.access(certPath);
|
||||
|
||||
const [key, cert] = await Promise.all([
|
||||
fs.readFile(keyPath),
|
||||
fs.readFile(certPath)
|
||||
]);
|
||||
|
||||
return { key, cert };
|
||||
|
||||
} catch (error) {
|
||||
console.error('SSL setup errors:', error.message);
|
||||
console.log('Start the server with HTTP instead of HTTPS...');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function startServer() {
|
||||
const port = process.env.PORT || 6001;
|
||||
const httpsOptions = await getHttpsOptions();
|
||||
|
||||
if (httpsOptions) {
|
||||
// HTTPS
|
||||
https.createServer(httpsOptions, app).listen(port, () => {
|
||||
console.log("HTTPS server is running.");
|
||||
console.log("https://localhost:6001/");
|
||||
});
|
||||
|
||||
} else {
|
||||
// HTTP
|
||||
app.listen(port, () => {
|
||||
console.log("HTTP server is running.");
|
||||
console.log("http://localhost:6001/");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await startServer();
|
||||
} catch (error) {
|
||||
console.error('Fail to start server :', error);
|
||||
}
|
||||
})();
|
||||
5
server/node/ssl/Generate Certificate.bat
Normal file
5
server/node/ssl/Generate Certificate.bat
Normal file
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
mkdir certificate 2>nul
|
||||
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout certificate\ca.key -out certificate\ca.crt -config ca.conf
|
||||
openssl req -new -nodes -newkey rsa:2048 -keyout certificate\server.key -out certificate\server.csr -config server.conf
|
||||
openssl x509 -req -in certificate\server.csr -CA certificate\ca.crt -CAkey certificate\ca.key -CAcreateserial -out certificate\server.crt -days 3650 -extensions req_ext -extfile server.conf
|
||||
8
server/node/ssl/Generate Certificate.sh
Normal file
8
server/node/ssl/Generate Certificate.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
mkdir -p certificate
|
||||
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout certificate/ca.key -out certificate/ca.crt -config ca.conf
|
||||
openssl req -new -nodes -newkey rsa:2048 -keyout certificate/server.key -out certificate/server.csr -config server.conf
|
||||
openssl x509 -req -in certificate/server.csr -CA certificate/ca.crt -CAkey certificate/ca.key -CAcreateserial -out certificate/server.crt -days 3650 -extensions req_ext -extfile server.conf
|
||||
|
||||
chmod 644 certificate/ca.key certificate/server.key
|
||||
chmod 644 certificate/ca.crt certificate/server.crt certificate/server.csr
|
||||
19
server/node/ssl/ca.conf
Normal file
19
server/node/ssl/ca.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
[ req ]
|
||||
default_bits = 2048
|
||||
prompt = no
|
||||
default_md = sha256
|
||||
distinguished_name = dn
|
||||
x509_extensions = ca_ext
|
||||
|
||||
[ dn ]
|
||||
C = KR
|
||||
ST = Kivotos
|
||||
L = Millennium Science School
|
||||
O = Game Development Department
|
||||
OU = Certificate Authority
|
||||
CN = Aris CA
|
||||
|
||||
[ ca_ext ]
|
||||
basicConstraints = critical,CA:TRUE
|
||||
keyUsage = critical,keyCertSign,cRLSign
|
||||
subjectKeyIdentifier = hash
|
||||
23
server/node/ssl/server.conf
Normal file
23
server/node/ssl/server.conf
Normal file
@@ -0,0 +1,23 @@
|
||||
[ req ]
|
||||
default_bits = 2048
|
||||
prompt = no
|
||||
default_md = sha256
|
||||
distinguished_name = dn
|
||||
req_extensions = req_ext
|
||||
|
||||
[ dn ]
|
||||
C = KR
|
||||
ST = Kivotos
|
||||
L = Millennium Science School
|
||||
O = Game Development Department
|
||||
OU = Tendou Aris
|
||||
CN = localhost
|
||||
|
||||
[ req_ext ]
|
||||
subjectAltName = @alt_names
|
||||
basicConstraints = CA:FALSE
|
||||
keyUsage = digitalSignature, keyEncipherment
|
||||
|
||||
[ alt_names ]
|
||||
DNS.1 = localhost
|
||||
IP.1 = 127.0.0.1
|
||||
@@ -1278,7 +1278,7 @@ function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string
|
||||
}
|
||||
case 'getglobalvar':{
|
||||
return getGlobalChatVar(v)
|
||||
}
|
||||
} // setglobalvar cbs support?
|
||||
case 'button':{
|
||||
return `<button class="button-default" risu-trigger="${arra[2]}">${arra[1]}</button>`
|
||||
}
|
||||
@@ -2235,6 +2235,10 @@ export function getGlobalChatVar(key:string){
|
||||
return DBState.db.globalChatVariables[key] ?? 'null'
|
||||
}
|
||||
|
||||
export function setGlobalChatVar(key:string, value:string){
|
||||
DBState.db.globalChatVariables[key] = value // String to String Map(dictionary)
|
||||
}
|
||||
|
||||
export function setChatVar(key:string, value:string){
|
||||
const selectedChar = get(selectedCharID)
|
||||
if(!DBState.db.characters[selectedChar].chats[DBState.db.characters[selectedChar].chatPage].scriptstate){
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getChatVar, hasher, setChatVar, type simpleCharacterArgument } from "../parser.svelte";
|
||||
import { getChatVar, hasher, setChatVar, getGlobalChatVar, type simpleCharacterArgument } from "../parser.svelte";
|
||||
import { LuaEngine, LuaFactory } from "wasmoon";
|
||||
import { getCurrentCharacter, getCurrentChat, getDatabase, setCurrentChat, setDatabase, type Chat, type character, type groupChat } from "../storage/database.svelte";
|
||||
import { get } from "svelte/store";
|
||||
@@ -25,7 +25,8 @@ interface LuaEngineState {
|
||||
mutex: Mutex;
|
||||
chat: Chat;
|
||||
setVar: (key:string, value:string) => void,
|
||||
getVar: (key:string) => string
|
||||
getVar: (key:string) => string,
|
||||
getGlobalVar: (key:string) => any,
|
||||
}
|
||||
|
||||
let LuaEngines = new Map<string, LuaEngineState>()
|
||||
@@ -35,6 +36,7 @@ export async function runLua(code:string, arg:{
|
||||
chat?:Chat
|
||||
setVar?: (key:string, value:string) => void,
|
||||
getVar?: (key:string) => string,
|
||||
getGlobalVar?: (key:string) => any,
|
||||
lowLevelAccess?: boolean,
|
||||
mode?: string,
|
||||
data?: any
|
||||
@@ -42,6 +44,7 @@ export async function runLua(code:string, arg:{
|
||||
const char = arg.char ?? getCurrentCharacter()
|
||||
const setVar = arg.setVar ?? setChatVar
|
||||
const getVar = arg.getVar ?? getChatVar
|
||||
const getGlobalVar = arg.getGlobalVar ?? getGlobalChatVar
|
||||
const mode = arg.mode ?? 'manual'
|
||||
const data = arg.data ?? {}
|
||||
let chat = arg.chat ?? getCurrentChat()
|
||||
@@ -60,7 +63,8 @@ export async function runLua(code:string, arg:{
|
||||
mutex: new Mutex(),
|
||||
chat,
|
||||
setVar,
|
||||
getVar
|
||||
getVar,
|
||||
getGlobalVar
|
||||
}
|
||||
LuaEngines.set(mode, luaEngineState)
|
||||
wasEmpty = true
|
||||
@@ -68,6 +72,7 @@ export async function runLua(code:string, arg:{
|
||||
luaEngineState.chat = chat
|
||||
luaEngineState.setVar = setVar
|
||||
luaEngineState.getVar = getVar
|
||||
luaEngineState.getGlobalVar = getGlobalVar
|
||||
}
|
||||
return await luaEngineState.mutex.runExclusive(async () => {
|
||||
if (wasEmpty || code !== luaEngineState.code) {
|
||||
@@ -87,6 +92,12 @@ export async function runLua(code:string, arg:{
|
||||
}
|
||||
return luaEngineState.getVar(key)
|
||||
})
|
||||
luaEngine.global.set('getGlobalVar', (id:string, key:string) => {
|
||||
if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){
|
||||
return
|
||||
}
|
||||
return luaEngineState.getGlobalVar(key)
|
||||
})
|
||||
luaEngine.global.set('stopChat', (id:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user