修复了关闭系统无需鉴权的问题

This commit is contained in:
2023-12-15 10:33:19 +00:00
parent da2c61089b
commit 467e6e2a61
3 changed files with 38 additions and 10 deletions

View File

@ -46,9 +46,32 @@ void BookStoreMain(bool is_server, std::string config_dir) {
std::cout << temp_channel_id << " Init 1\n" std::cout << temp_channel_id << " Init 1\n"
<< new_session_token << ' ' << new_outh_token << std::endl; << new_session_token << ' ' << new_outh_token << std::endl;
std::cout.flush(); std::cout.flush();
} else if (cmd[1] == 'S') } else if (cmd[1] == 'S') {
std::stringstream ss(cmd);
std::string session_token, operation_token, authentic_key;
ss >> session_token;
ss >> session_token >> operation_token >> authentic_key;
if (session_map.find(session_token) == session_map.end()) {
std::cout << session_token << ' ' << operation_token << " -1"
<< std::endl;
std::cout.flush();
continue;
}
if (session_map[session_token].OuthorizationKey != authentic_key) {
std::cout << session_token << ' ' << operation_token << " -1"
<< std::endl;
std::cout.flush();
continue;
}
if (session_map[session_token].login_stack.empty() ||
session_map[session_token].login_stack.top().first != "root") {
std::cout << session_token << ' ' << operation_token << " -1"
<< std::endl;
std::cout.flush();
continue;
}
return; return;
else if (cmd[1] == 'C') { } else if (cmd[1] == 'C') {
std::stringstream ss(cmd); std::stringstream ss(cmd);
std::string session_token, operation_token, authentic_key; std::string session_token, operation_token, authentic_key;
ss >> session_token; ss >> session_token;

View File

@ -71,7 +71,7 @@ memoryriver类维护一个缓存简单地缓存高频访问和连续访问
- `#CloseSession [SessionToken] [OperationToken] [OuthenticationKey]`:显示地告知调度模块停止某个会话 - `#CloseSession [SessionToken] [OperationToken] [OuthenticationKey]`:显示地告知调度模块停止某个会话
- `#Request [SessionToken] [OperationToken] [OuthenticationKey]\n[UserCommand]`:向后端发送一个请求 - `#Request [SessionToken] [OperationToken] [OuthenticationKey]\n[UserCommand]`:向后端发送一个请求
- `#Who [SessionToken] [OperationToken] [OuthenticationKey]`:查询自己是谁和权限 - `#Who [SessionToken] [OperationToken] [OuthenticationKey]`:查询自己是谁和权限
- `#ShutDownSystem`:关闭整个系统 - `#ShutDownSystem [SessionToken] [OperationToken] [OuthenticationKey]`:关闭整个系统
### 后端向前端 ### 后端向前端
- 字符串,`[SessionToken] [OperationToken] [LineCounter]\n[ResponseContent]`,其中,`[ResponseContent]`恰有`[LineCounter]`行,每行行末有且仅有一个`\n`。输出为空通过把`[LineCounter]`设置为0来实现若对话验证失败`[LineCounter]`设为-1 - 字符串,`[SessionToken] [OperationToken] [LineCounter]\n[ResponseContent]`,其中,`[ResponseContent]`恰有`[LineCounter]`行,每行行末有且仅有一个`\n`。输出为空通过把`[LineCounter]`设置为0来实现若对话验证失败`[LineCounter]`设为-1

View File

@ -113,12 +113,6 @@ io.on('connection', async (socket) => {
console.log('message: ' + msg); console.log('message: ' + msg);
const substrings = msg.trim().split('\n')[0].split(' '); const substrings = msg.trim().split('\n')[0].split(' ');
const head=substrings[0]; const head=substrings[0];
if(head[1]=='S')
{
backend.stdin.write("#ShutDownSystem\n");
sleep(1000);
process.exit(0);
}
const session_token=substrings[1]; const session_token=substrings[1];
if(head[1]=='O') if(head[1]=='O')
{ {
@ -146,6 +140,17 @@ io.on('connection', async (socket) => {
}); });
}); });
backend.on('exit', (code, signal) => {
if (code !== null) {
console.log(`子进程退出,退出码: ${code}`);
} else if (signal !== null) {
console.log(`子进程被信号中断,信号: ${signal}`);
} else {
console.log('子进程退出');
}
process.exit(0);
});
server.listen(3000, () => { server.listen(3000, () => {
console.log('server running at http://localhost:3000'); console.log('server running at http://localhost:3000');
}); });