dedicated_room: Support single Base64 token.
This commit is contained in:
parent
3a18039c53
commit
a1544d8669
@ -13,7 +13,7 @@ if (ENABLE_WEB_SERVICE)
|
|||||||
target_link_libraries(citra-room PRIVATE web_service)
|
target_link_libraries(citra-room PRIVATE web_service)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(citra-room PRIVATE glad)
|
target_link_libraries(citra-room PRIVATE cryptopp glad)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_link_libraries(citra-room PRIVATE getopt)
|
target_link_libraries(citra-room PRIVATE getopt)
|
||||||
endif()
|
endif()
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <cryptopp/base64.h>
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -66,6 +67,24 @@ static void PrintVersion() {
|
|||||||
/// The magic text at the beginning of a citra-room ban list file.
|
/// The magic text at the beginning of a citra-room ban list file.
|
||||||
static constexpr char BanListMagic[] = "CitraRoom-BanList-1";
|
static constexpr char BanListMagic[] = "CitraRoom-BanList-1";
|
||||||
|
|
||||||
|
static constexpr char token_delimiter{':'};
|
||||||
|
|
||||||
|
static std::string UsernameFromDisplayToken(const std::string& display_token) {
|
||||||
|
std::string unencoded_display_token;
|
||||||
|
CryptoPP::StringSource ss(
|
||||||
|
display_token, true,
|
||||||
|
new CryptoPP::Base64Decoder(new CryptoPP::StringSink(unencoded_display_token)));
|
||||||
|
return unencoded_display_token.substr(0, unencoded_display_token.find(token_delimiter));
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string TokenFromDisplayToken(const std::string& display_token) {
|
||||||
|
std::string unencoded_display_token;
|
||||||
|
CryptoPP::StringSource ss(
|
||||||
|
display_token, true,
|
||||||
|
new CryptoPP::Base64Decoder(new CryptoPP::StringSink(unencoded_display_token)));
|
||||||
|
return unencoded_display_token.substr(unencoded_display_token.find(token_delimiter) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
static Network::Room::BanList LoadBanList(const std::string& path) {
|
static Network::Room::BanList LoadBanList(const std::string& path) {
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
OpenFStream(file, path, std::ios_base::in);
|
OpenFStream(file, path, std::ios_base::in);
|
||||||
@ -158,7 +177,7 @@ int main(int argc, char** argv) {
|
|||||||
{"password", required_argument, 0, 'w'},
|
{"password", required_argument, 0, 'w'},
|
||||||
{"preferred-game", required_argument, 0, 'g'},
|
{"preferred-game", required_argument, 0, 'g'},
|
||||||
{"preferred-game-id", required_argument, 0, 'i'},
|
{"preferred-game-id", required_argument, 0, 'i'},
|
||||||
{"username", required_argument, 0, 'u'},
|
{"username", optional_argument, 0, 'u'},
|
||||||
{"token", required_argument, 0, 't'},
|
{"token", required_argument, 0, 't'},
|
||||||
{"web-api-url", required_argument, 0, 'a'},
|
{"web-api-url", required_argument, 0, 'a'},
|
||||||
{"ban-list-file", required_argument, 0, 'b'},
|
{"ban-list-file", required_argument, 0, 'b'},
|
||||||
@ -248,10 +267,6 @@ int main(int argc, char** argv) {
|
|||||||
"list.\nSet with --ban-list-file <file>\n\n";
|
"list.\nSet with --ban-list-file <file>\n\n";
|
||||||
}
|
}
|
||||||
bool announce = true;
|
bool announce = true;
|
||||||
if (username.empty()) {
|
|
||||||
announce = false;
|
|
||||||
std::cout << "username is empty: Hosting a private room\n\n";
|
|
||||||
}
|
|
||||||
if (token.empty() && announce) {
|
if (token.empty() && announce) {
|
||||||
announce = false;
|
announce = false;
|
||||||
std::cout << "token is empty: Hosting a private room\n\n";
|
std::cout << "token is empty: Hosting a private room\n\n";
|
||||||
@ -261,11 +276,18 @@ int main(int argc, char** argv) {
|
|||||||
std::cout << "endpoint url is empty: Hosting a private room\n\n";
|
std::cout << "endpoint url is empty: Hosting a private room\n\n";
|
||||||
}
|
}
|
||||||
if (announce) {
|
if (announce) {
|
||||||
|
if (username.empty()) {
|
||||||
|
std::cout << "Hosting a public room\n\n";
|
||||||
|
Settings::values.web_api_url = web_api_url;
|
||||||
|
Settings::values.citra_username = UsernameFromDisplayToken(token);
|
||||||
|
Settings::values.citra_token = TokenFromDisplayToken(token);
|
||||||
|
} else {
|
||||||
std::cout << "Hosting a public room\n\n";
|
std::cout << "Hosting a public room\n\n";
|
||||||
Settings::values.web_api_url = web_api_url;
|
Settings::values.web_api_url = web_api_url;
|
||||||
Settings::values.citra_username = username;
|
Settings::values.citra_username = username;
|
||||||
Settings::values.citra_token = token;
|
Settings::values.citra_token = token;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!announce && enable_citra_mods) {
|
if (!announce && enable_citra_mods) {
|
||||||
enable_citra_mods = false;
|
enable_citra_mods = false;
|
||||||
std::cout << "Can not enable Citra Moderators for private rooms\n\n";
|
std::cout << "Can not enable Citra Moderators for private rooms\n\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user