add a couple of convenience features and clean up config file a bit

This commit is contained in:
Martin Michelsen
2019-08-10 00:08:40 -07:00
parent 9ee2e97738
commit 30516ccf50
4 changed files with 37 additions and 35 deletions
+16 -6
View File
@@ -7,6 +7,7 @@
#include <phosg/Strings.hh>
#include <phosg/Filesystem.hh>
#include <set>
#include <thread>
#include "NetworkAddresses.hh"
#include "SendCommands.hh"
@@ -97,6 +98,9 @@ void populate_state_from_config(shared_ptr<ServerState> 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<ServerState> 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);
+2 -2
View File
@@ -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",
+7 -1
View File
@@ -26,10 +26,16 @@ struct PortConfiguration {
};
struct ServerState {
enum class RunShellBehavior {
Default = 0,
Always,
Never,
};
std::u16string name;
std::unordered_map<std::string, PortConfiguration> port_configuration;
bool run_dns_server;
bool run_interactive_shell;
RunShellBehavior run_shell_behavior;
std::shared_ptr<const QuestIndex> quest_index;
std::shared_ptr<const LevelTable> level_table;
std::shared_ptr<const BattleParamTable> battle_params;
+12 -26
View File
@@ -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,