准备完成通讯模块
This commit is contained in:
@ -29,7 +29,10 @@ void BookStoreMain(bool is_server, std::string config_dir) {
|
||||
// throw FatalError("Server mode has not been implemented yet", 1);
|
||||
std::unordered_map<std::string, SessionClass> session_map;
|
||||
std::string cmd;
|
||||
std::ofstream fout("/tmp/log.txt");
|
||||
while (std::getline(std::cin, cmd)) {
|
||||
fout << cmd << std::endl;
|
||||
fout.flush();
|
||||
if (cmd[1] == 'O') //`#OpenSession [TempChannelID]`
|
||||
{
|
||||
std::string new_session_token = GenerateRandomString(10);
|
||||
@ -42,6 +45,7 @@ void BookStoreMain(bool is_server, std::string config_dir) {
|
||||
ss >> temp_channel_id;
|
||||
std::cout << temp_channel_id << " Init 1\n"
|
||||
<< new_session_token << ' ' << new_outh_token << std::endl;
|
||||
std::cout.flush();
|
||||
} else if (cmd[1] == 'S')
|
||||
return;
|
||||
else if (cmd[1] == 'C') {
|
||||
@ -52,16 +56,19 @@ void BookStoreMain(bool is_server, std::string config_dir) {
|
||||
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;
|
||||
}
|
||||
session_map.erase(session_token);
|
||||
std::cout << session_token << ' ' << operation_token << " 0"
|
||||
<< std::endl;
|
||||
std::cout.flush();
|
||||
} else if (cmd[1] == 'W') {
|
||||
std::stringstream ss(cmd);
|
||||
std::string session_token, operation_token, authentic_key;
|
||||
@ -70,21 +77,25 @@ void BookStoreMain(bool is_server, std::string config_dir) {
|
||||
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.size())
|
||||
if (session_map[session_token].login_stack.size()) {
|
||||
std::cout << session_token << ' ' << operation_token << " 1\n"
|
||||
<< engine.QueryUserInfo(
|
||||
session_map[session_token].login_stack.top().first)
|
||||
<< std::endl;
|
||||
else {
|
||||
std::cout.flush();
|
||||
} else {
|
||||
std::cout << session_token << ' ' << operation_token
|
||||
<< " 1\n[nobody] -1" << std::endl;
|
||||
std::cout.flush();
|
||||
}
|
||||
} else if (cmd[1] == 'R') {
|
||||
std::stringstream ss(cmd);
|
||||
@ -94,11 +105,13 @@ void BookStoreMain(bool is_server, std::string config_dir) {
|
||||
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;
|
||||
}
|
||||
std::getline(std::cin, cmd);
|
||||
@ -107,6 +120,7 @@ void BookStoreMain(bool is_server, std::string config_dir) {
|
||||
std::cout << session_token << ' ' << operation_token << " "
|
||||
<< ret.size() << std::endl;
|
||||
for (auto &line : ret) std::cout << line << std::endl;
|
||||
std::cout.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user