This commit is contained in:
kwaroran
2025-04-13 00:34:01 +09:00
19 changed files with 347 additions and 206 deletions

1
.gitignore vendored
View File

@@ -43,3 +43,4 @@ __pycache__/
dist.zip
/scripts/
.env
/server/node/ssl/certificate

View File

@@ -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);
}
})();

View 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

View 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
View 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

View 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

View File

@@ -379,7 +379,8 @@ export const languageChinese = {
"globalLoreBook": "全局世界书",
"globalRegexScript": "全局正则表达式",
"accessibility": "辅助功能",
"sendWithEnter": "使用 Enter 键发送",
"sendWithEnter": "使用 Enter 键发送取消检查时Shift + Enter更改为消息传送。",
"fixedChatTextarea": "固定聊天窗口底部",
"clickToEdit": "点击文字进行编辑",
"setNodePassword": "设置密码以提升安全性",
"inputNodePassword": "输入密码。如果忘记密码,请删除服务器文档中的 save/__password.txt 并重启服务器。",

View File

@@ -291,7 +291,8 @@ export const languageGerman = {
globalLoreBook: 'Lore Buch',
globalRegexScript: "Regex",
accessibility: "Barrierefreiheit",
sendWithEnter: "Mit Enter senden",
sendWithEnter: "Mit Enter senden(Umschalt + Enter beim Entpacken zu senden)",
fixedChatTextarea: "Unten im Chatfenster fixieren",
clickToEdit: "Text zum Bearbeiten anklicken",
setNodePassword: "Legen Sie Ihr Passwort für die Sicherheit fest",
inputNodePassword: "Geben Sie Ihr Passwort ein. Wenn Sie sich nicht erinnern können, entfernen Sie save/__password.txt in Ihren Serverdateien und starten Sie den Server neu",

View File

@@ -570,6 +570,7 @@ export const languageEnglish = {
globalRegexScript: "Global Regex",
accessibility: "Accessibility",
sendWithEnter: "Send with Enter Key",
fixedChatTextarea: "Fixed at the bottom of the chat window(When unchecked, Shift + Enter changes to send a message.)",
clickToEdit: "Click Text to Edit",
setNodePassword: "Set your password to security",
inputNodePassword: "Input your password. if you can't remember, remove save/__password.txt in your server files and restart the server.",

View File

@@ -341,7 +341,8 @@ export const languageSpanish = {
globalLoreBook: 'Libro de Lore Global',
globalRegexScript: "Regex Global",
accessibility: "Accesibilidad",
sendWithEnter: "Enviar con la Tecla Enter",
sendWithEnter: "Enviar con la Tecla Enter(Al desactivar la verificación, Shift + Enter cambia a Transmisión de Mensajes.)",
fixedChatTextarea: "Fijación en la parte inferior de la ventana de chat",
clickToEdit: "Haz Clic en el Texto para Editar",
setNodePassword: "Establece tu contraseña para la seguridad",
inputNodePassword: "Ingresa tu contraseña. si no la recuerdas, elimina save/__password.txt en tus archivos de servidor y reinicia el servidor.",

View File

@@ -517,7 +517,8 @@ export const languageKorean = {
"globalLoreBook": "글로벌 로어북",
"globalRegexScript": "글로벌 정규식",
"accessibility": "접근성",
"sendWithEnter": "엔터키로 메세지 보내기",
"sendWithEnter": "엔터키로 메세지 보내기(체크 해제시 Shift + Enter가 메세지 전송으로 변경.)",
"fixedChatTextarea": "채팅창 하단 고정",
"clickToEdit": "클릭해서 수정하기",
"setNodePassword": "보안을 위해 비밀번호를 정해주세요",
"inputNodePassword": "비밀번호를 입력해주세요. 기억이 안나신다면, save/__password를 지우고 서버를 재시작해주세요.",

View File

@@ -262,7 +262,8 @@ export const LanguageVietnamese = {
"globalLoreBook": "Sách truyền thuyết toàn cầu",
"globalRegexScript": "Regex toàn cầu",
"accessibility": "Khả năng tiếp cận",
"sendWithEnter": "Gửi bằng phím Enter",
"sendWithEnter": "Gửi bằng phím Enter(Shift + Enter chuyển sang gửi tin nhắn khi không kiểm tra.)",
"fixedChatTextarea": "Cố định ở dưới khung chat",
"clickToEdit": "Bấm vào văn bản để chỉnh sửa",
"setNodePassword": "Đặt mật khẩu của bạn để bảo mật",
"inputNodePassword": "Nhập mật khẩu của bạn. nếu bạn không nhớ, hãy xóa save/__password.txt trong tệp máy chủ của bạn và khởi động lại máy chủ.",

View File

@@ -384,7 +384,8 @@ export const languageChineseTraditional = {
"globalLoreBook": "全域 Lorebook",
"globalRegexScript": "全域正規表達式",
"accessibility": "輔助功能",
"sendWithEnter": "使用 Enter 鍵發送",
"sendWithEnter": "使用 Enter 鍵發送取消检查时Shift + Enter更改为消息传送。",
"fixedChatTextarea": "固定聊天窗口底部",
"clickToEdit": "點擊文字進行編輯",
"setNodePassword": "設定密碼以提升安全性",
"inputNodePassword": "輸入密碼。如果忘記密碼,請刪除伺服器文件中的 save/__password.txt 並重啟伺服器。",

View File

@@ -442,7 +442,10 @@
loadPages += 15
}
}}>
<div class="flex items-stretch mt-2 mb-2 w-full">
<div
class="{DBState.db.fixedChatTextarea ? 'sticky pt-2 pb-2 right-0 bottom-0 bg-bgcolor' : 'mt-2 mb-2'} flex items-stretch w-full"
style="{DBState.db.fixedChatTextarea ? 'z-index:29;' : ''}"
>
{#if DBState.db.useChatSticker && currentCharacter.type !== 'group'}
<div onclick={()=>{toggleStickers = !toggleStickers}}
class={"ml-4 bg-textcolor2 flex justify-center items-center w-12 h-12 rounded-md hover:bg-green-500 transition-colors "+(toggleStickers ? 'text-green-500':'text-textcolor')}>
@@ -455,8 +458,11 @@
bind:value={messageInput}
bind:this={inputEle}
onkeydown={(e) => {
if(e.key.toLocaleLowerCase() === "enter" && (!e.shiftKey) && !e.isComposing){
if(DBState.db.sendWithEnter){
if(e.key.toLocaleLowerCase() === "enter" && !e.isComposing){
if(DBState.db.sendWithEnter && (!e.shiftKey)){
send()
e.preventDefault()
}else if(!DBState.db.sendWithEnter && e.shiftKey){
send()
e.preventDefault()
}
@@ -753,7 +759,7 @@
{/if}
{#if openMenu}
<div class="absolute right-2 bottom-16 p-5 bg-darkbg flex flex-col gap-3 text-textcolor rounded-md" onclick={(e) => {
<div class="{DBState.db.fixedChatTextarea ? 'fixed' : 'absolute'} right-2 bottom-16 p-5 bg-darkbg flex flex-col gap-3 text-textcolor rounded-md" onclick={(e) => {
e.stopPropagation()
}}>
{#if DBState.db.characters[$selectedCharID].type === 'group'}

View File

@@ -1,7 +1,6 @@
<script lang="ts">
import Check from "src/lib/UI/GUI/CheckInput.svelte";
import { language } from "src/lang";
import { DBState } from 'src/ts/stores.svelte';
</script>
@@ -24,6 +23,10 @@
<Check bind:check={DBState.db.sendWithEnter} name={language.sendWithEnter}/>
</div>
<div class="flex items-center mt-2">
<Check bind:check={DBState.db.fixedChatTextarea} name={language.fixedChatTextarea}/>
</div>
<div class="flex items-center mt-2">
<Check bind:check={DBState.db.clickToEdit} name={language.clickToEdit}/>
</div>

View File

@@ -56,7 +56,7 @@
<button class={(DBState.db.enabledModules.includes(rmodule.id)) ?
"mr-2 cursor-pointer text-blue-500" :
rmodule.namespace &&
DBState.db.moduleIntergration.split(',').map((s) => s.trim()).includes(rmodule.namespace) ?
DBState.db.moduleIntergration?.split(',').map((s) => s.trim()).includes(rmodule.namespace) ?
"text-amber-500 hover:text-green-500 mr-2 cursor-pointer" :
"text-textcolor2 hover:text-green-500 mr-2 cursor-pointer"
} use:tooltip={language.enableGlobal} onclick={async (e) => {

View File

@@ -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>`
}
@@ -1379,7 +1379,7 @@ function basicMatcher (p1:string,matcherArg:matcherArg,vars:{[key:string]:string
case 'previous_chat_log':{
const selchar = db.characters[get(selectedCharID)]
const chat = selchar?.chats?.[selchar.chatPage]
return chat?.message[chatID - 1]?.data ?? 'Out of range'
return chat?.message[Number(arra[1])]?.data ?? 'Out of range'
}
case 'tonumber':{
@@ -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){

View File

@@ -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

View File

@@ -694,6 +694,7 @@ export interface Database{
}
globalscript: customscript[],
sendWithEnter:boolean
fixedChatTextarea:boolean
clickToEdit: boolean
koboldURL:string
advancedBotSettings:boolean