From 30516ccf50dc07a081a3ce610382e80d12d03d0f Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sat, 10 Aug 2019 00:08:40 -0700 Subject: [PATCH] add a couple of convenience features and clean up config file a bit --- Main.cc | 22 ++++++++++++++++------ ServerState.cc | 4 ++-- ServerState.hh | 8 +++++++- system/config.json | 38 ++++++++++++-------------------------- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/Main.cc b/Main.cc index 31d9191b..54464753 100644 --- a/Main.cc +++ b/Main.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include "NetworkAddresses.hh" #include "SendCommands.hh" @@ -97,6 +98,9 @@ void populate_state_from_config(shared_ptr s, s->information_contents = information_contents; s->num_threads = d.at("Threads")->as_int(); + if (s->num_threads == 0) { + s->num_threads = thread::hardware_concurrency(); + } auto local_address_str = d.at("LocalAddress")->as_string(); s->local_address = address_for_string(local_address_str.c_str()); @@ -110,15 +114,16 @@ void populate_state_from_config(shared_ptr s, try { s->run_dns_server = d.at("RunDNSServer")->as_bool(); - } catch (const JSONObject::key_error&) { + } catch (const out_of_range&) { s->run_dns_server = true; } try { - s->run_interactive_shell = d.at("RunInteractiveShell")->as_bool(); - } catch (const JSONObject::key_error&) { - s->run_interactive_shell = true; - } + bool run_shell = d.at("RunInteractiveShell")->as_bool(); + s->run_shell_behavior = run_shell ? + ServerState::RunShellBehavior::Always : + ServerState::RunShellBehavior::Never; + } catch (const out_of_range&) { } } @@ -172,7 +177,12 @@ int main(int argc, char* argv[]) { } game_server->start(); - if (state->run_interactive_shell) { + bool should_run_shell = (state->run_shell_behavior == ServerState::RunShellBehavior::Always); + if (state->run_shell_behavior == ServerState::RunShellBehavior::Default) { + should_run_shell = isatty(fileno(stdin)); + } + + if (should_run_shell) { log(INFO, "starting interactive shell"); run_shell(state); diff --git a/ServerState.cc b/ServerState.cc index 931b3412..e3836fa7 100644 --- a/ServerState.cc +++ b/ServerState.cc @@ -10,8 +10,8 @@ using namespace std; -ServerState::ServerState() : run_dns_server(true), run_interactive_shell(true), - next_lobby_id(1) { +ServerState::ServerState() : run_dns_server(true), + 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); this->main_menu.emplace_back(MAIN_MENU_INFORMATION, u"Information", diff --git a/ServerState.hh b/ServerState.hh index b268c0d8..ea097c30 100644 --- a/ServerState.hh +++ b/ServerState.hh @@ -26,10 +26,16 @@ struct PortConfiguration { }; struct ServerState { + enum class RunShellBehavior { + Default = 0, + Always, + Never, + }; + std::u16string name; std::unordered_map port_configuration; bool run_dns_server; - bool run_interactive_shell; + RunShellBehavior run_shell_behavior; std::shared_ptr quest_index; std::shared_ptr level_table; std::shared_ptr battle_params; diff --git a/system/config.json b/system/config.json index fba35c23..df2bc27b 100755 --- a/system/config.json +++ b/system/config.json @@ -1,32 +1,25 @@ { - // ************************************** - // *** FUZZIQER SOFTWARE PSO SERVER *** - // *** CONFIGURATION FILE *** - // ************************************** + // Configuration file for newserv. This file is standard JSON with comments. - // ************** - // SERVER OPTIONS - // ************** - - // Server's name (max. 16 characters) + // Server's name (maximum 16 characters) "ServerName": "Alexandria", // Address to connect local clients to "LocalAddress": "192.168.0.5", // Address to connect external clients to "ExternalAddress": "10.0.1.6", - // Number of worker threads to run - "Threads": 1, + // Number of worker threads to run. If zero, use as many threads as there are + // CPU cores. + "Threads": 0, // Set to false to disable the DNS server "RunDNSServer": true, - // Set to false to disable the interactive shell (do this if stdin is - // /dev/null, for example) - "RunInteractiveShell": true, + // By default, the interactive shell runs if stdin is a terminal, and doesn't + // run if it's not. This option, if present, overrides that behavior. + // "RunInteractiveShell": false, - // **************** - // INFORMATION MENU - // **************** - - // Each entry is a 3-list of [title, short-description, full-contents]. + // Information menu contents. Each entry is a 3-list of + // [title, short description, full contents]. In the short description and + // full contents, you can use PSO escape codes with the $ character (for + // example, $Cx for colors). "InformationMenuContents": [ ["Text", "$C7Some things you\nmay need to know\nabout text on\nthis server", "$C7Everything you type will be filtered.\n\nDollar signs will become tab chars, which can be\nused to color team names and info boards.\nTo color your text, type %sCx, where x is a\nvalue from the Text Colors list.\n\nPound signs (number signs) will become returns\n(newlines), the sequence %%s will become %s,\nand the sequence %%%% will become %%."], ["Text colors", "$C7Display color values", "These values can be used to color text.\n\n$C0Color 0$C7 - Black\n$C1Color 1$C7 - Blue\n$C2Color 2$C7 - Green\n$C3Color 3$C7 - Cyan\n$C4Color 4$C7 - Red\n$C5Color 5$C7 - Purple\n$C6Color 6$C7 - Yellow\n$C7Color 7$C7 - White\n$C8Color 8$C7 - Pink\n$C9Color 9$C7 - Violet\n$CGColor G$C7 - Orange Pulse"], @@ -46,15 +39,9 @@ ["Area list", "$C7Display stage code\nlist", "These values can be used with the $C6%swarp$C7 command.\n\n$C2Green$C7 areas will be empty unless you are in a quest.\n$C6Yellow$C7 areas will not allow you to move.\n\n $C8Episode 1 / Episode 2 / Episode 4$C7\n0: Pioneer 2 / Pioneer 2 / Pioneer 2\n1: Forest 1 / Temple Alpha / Crater East\n2: Forest 2 / Temple Beta / Crater West\n3: Caves 1 / Spaceship Alpha / Crater South\n4: Caves 2 / Spaceship Beta / Crater North\n5: Caves 3 / CCA / Crater Interior\n6: Mines 1 / Jungle North / Desert 1\n7: Mines 2 / Jungle South / Desert 2\n8: Ruins 1 / Mountain / Desert 3\n9: Ruins 2 / Seaside / Saint Million\n10: Ruins 3 / Seabed Upper / $C6Purgatory$C7\n11: Dragon / Seabed Lower\n12: De Rol Le / Gal Gryphon\n13: Vol Opt / Olga Flow\n14: Dark Falz / Barba Ray\n15: $C2Lobby$C7 / Gol Dragon\n16: $C6Battle 1$C7 / $C6Seaside Night$C7\n17: $C6Battle 2$C7 / $C2Tower$C7"], ], - // *************** - // GAME PARAMETERS - // *************** - // Item drop rates for non-rare items. For each type (boxes or enemies), all // the categories must add up to a number less than 0x100000000. Each number // is a probability (out of 0x100000000) that the given item type will appear. - // The values in each list must sum to 0xFFFFFFFF or less. - "CommonItemDropRates-Enemy": [ 0x03000000, // material 0x20000000, // equipment @@ -79,7 +66,6 @@ // Unit drop rates for non-rare items. Each entry is an array of unit types, // one array per difficulty. Each entry in the array has an equal probability // of dropping. If a unit type is 0xFF, then no item will drop. - "CommonUnitTypes": [ // normal [0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x0C, 0x0C, 0x0C,