From 5e091852c4137d114de9c300c4fe8f782e024664 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Thu, 20 Feb 2020 10:52:45 -0800 Subject: [PATCH] implement AllowUnregisteredUsers --- Main.cc | 6 ++++++ ReceiveCommands.cc | 40 ++++++++++++++++++++++++---------------- ServerState.cc | 1 + ServerState.hh | 1 + system/config.json | 6 ++++++ 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Main.cc b/Main.cc index 425d881a..3f858470 100644 --- a/Main.cc +++ b/Main.cc @@ -144,6 +144,12 @@ void populate_state_from_config(shared_ptr s, s->run_dns_server = true; } + try { + s->allow_unregistered_users = d.at("AllowUnregisteredUsers")->as_bool(); + } catch (const out_of_range&) { + s->allow_unregistered_users = true; + } + try { bool run_shell = d.at("RunInteractiveShell")->as_bool(); s->run_shell_behavior = run_shell ? diff --git a/ReceiveCommands.cc b/ReceiveCommands.cc index 1a662c6e..3f699dc5 100644 --- a/ReceiveCommands.cc +++ b/ReceiveCommands.cc @@ -179,10 +179,12 @@ void process_verify_license_gc(shared_ptr s, shared_ptr c, c->license = s->license_manager->verify_gc(serial_number, cmd->access_key, cmd->password); } catch (const exception& e) { - u16string message = u"Login failed: " + decode_sjis(e.what()); - send_message_box(c, message.c_str()); - c->should_disconnect = true; - return; + if (!s->allow_unregistered_users) { + u16string message = u"Login failed: " + decode_sjis(e.what()); + send_message_box(c, message.c_str()); + c->should_disconnect = true; + return; + } } c->flags |= flags_for_version(c->version, cmd->sub_version); @@ -210,10 +212,12 @@ void process_login_a_dc_pc_gc(shared_ptr s, shared_ptr c, NULL); } } catch (const exception& e) { - u16string message = u"Login failed: " + decode_sjis(e.what()); - send_message_box(c, message.c_str()); - c->should_disconnect = true; - return; + if (!s->allow_unregistered_users) { + u16string message = u"Login failed: " + decode_sjis(e.what()); + send_message_box(c, message.c_str()); + c->should_disconnect = true; + return; + } } send_command(c, 0x9C, 0x01); @@ -245,10 +249,12 @@ void process_login_c_dc_pc_gc(shared_ptr s, shared_ptr c, cmd->password); } } catch (const exception& e) { - u16string message = u"Login failed: " + decode_sjis(e.what()); - send_message_box(c, message.c_str()); - c->should_disconnect = true; - return; + if (!s->allow_unregistered_users) { + u16string message = u"Login failed: " + decode_sjis(e.what()); + send_message_box(c, message.c_str()); + c->should_disconnect = true; + return; + } } send_command(c, 0x9C, 0x01); @@ -284,10 +290,12 @@ void process_login_d_e_pc_gc(shared_ptr s, shared_ptr c, NULL); } } catch (const exception& e) { - u16string message = u"Login failed: " + decode_sjis(e.what()); - send_message_box(c, message.c_str()); - c->should_disconnect = true; - return; + if (!s->allow_unregistered_users) { + u16string message = u"Login failed: " + decode_sjis(e.what()); + send_message_box(c, message.c_str()); + c->should_disconnect = true; + return; + } } memcpy(&c->config.cfg, &cmd->cfg, sizeof(ClientConfig)); diff --git a/ServerState.cc b/ServerState.cc index 524fd9b5..bbe9f56c 100644 --- a/ServerState.cc +++ b/ServerState.cc @@ -11,6 +11,7 @@ using namespace std; ServerState::ServerState() : run_dns_server(true), + allow_unregistered_users(false), run_shell_behavior(RunShellBehavior::Default), next_lobby_id(1) { this->main_menu.emplace_back(MAIN_MENU_GO_TO_LOBBY, u"Go to lobby", u"Join the lobby.", 0); diff --git a/ServerState.hh b/ServerState.hh index 6569af03..cbf1c85d 100644 --- a/ServerState.hh +++ b/ServerState.hh @@ -36,6 +36,7 @@ struct ServerState { std::unordered_map port_configuration; std::string username; bool run_dns_server; + bool allow_unregistered_users; RunShellBehavior run_shell_behavior; std::shared_ptr quest_index; std::shared_ptr level_table; diff --git a/system/config.json b/system/config.json index 0a1a3b6e..f59ce68d 100755 --- a/system/config.json +++ b/system/config.json @@ -13,6 +13,12 @@ // run if it's not. This option, if present, overrides that behavior. // "RunInteractiveShell": false, + // By default, the server only allows users who are registered in the license + // file. By enabling this option, all users will be allowed to connect. This + // option has no effect for Blue Burst clients. Keep in mind that unregistered + // users cannot be banned! + "AllowUnregisteredUsers": false, + // User to run the server as. If present, newserv will attempt to switch to // this user's permissions after loading its configuration and opening // listening sockets. The special value $SUDO_USER causes newserv to look up