make log messages cleaner
This commit is contained in:
+15
-16
@@ -140,9 +140,9 @@ void populate_state_from_config(shared_ptr<ServerState> s,
|
||||
s->all_addresses.emplace("<external>", s->external_address);
|
||||
|
||||
try {
|
||||
s->run_dns_server = d.at("RunDNSServer")->as_bool();
|
||||
s->dns_server_port = d.at("RunDNSServer")->as_bool();
|
||||
} catch (const out_of_range&) {
|
||||
s->run_dns_server = true;
|
||||
s->dns_server_port = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -226,17 +226,16 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
shared_ptr<ServerState> state(new ServerState());
|
||||
|
||||
log(INFO, "starting network subsystem");
|
||||
shared_ptr<struct event_base> base(event_base_new(), event_base_free);
|
||||
|
||||
log(INFO, "reading network addresses");
|
||||
log(INFO, "Reading network addresses");
|
||||
state->all_addresses = get_local_addresses();
|
||||
for (const auto& it : state->all_addresses) {
|
||||
string addr_str = string_for_address(it.second);
|
||||
log(INFO, "found interface: %s = %s", it.first.c_str(), addr_str.c_str());
|
||||
log(INFO, "Found interface: %s = %s", it.first.c_str(), addr_str.c_str());
|
||||
}
|
||||
|
||||
log(INFO, "loading configuration");
|
||||
log(INFO, "Loading configuration");
|
||||
auto config_json = JSONObject::parse(load_file("system/config.json"));
|
||||
populate_state_from_config(state, config_json);
|
||||
|
||||
@@ -253,7 +252,7 @@ int main(int argc, char* argv[]) {
|
||||
shared_ptr<ProxyServer> proxy_server;
|
||||
shared_ptr<Server> game_server;
|
||||
if (proxy_port) {
|
||||
log(INFO, "starting proxy");
|
||||
log(INFO, "Starting proxy server");
|
||||
sockaddr_storage proxy_destination_ss = make_sockaddr_storage(
|
||||
proxy_hostname, proxy_port).first;
|
||||
proxy_server.reset(new ProxyServer(base, proxy_destination_ss,
|
||||
@@ -264,27 +263,27 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
} else {
|
||||
log(INFO, "starting game server");
|
||||
log(INFO, "Starting game server");
|
||||
game_server.reset(new Server(base, state));
|
||||
for (const auto& it : state->port_configuration) {
|
||||
game_server->listen("", it.second.port, it.second.version, it.second.behavior);
|
||||
}
|
||||
|
||||
log(INFO, "loading license list");
|
||||
log(INFO, "Loading license list");
|
||||
state->license_manager.reset(new LicenseManager("system/licenses.nsi"));
|
||||
|
||||
log(INFO, "loading battle parameters");
|
||||
log(INFO, "Loading battle parameters");
|
||||
state->battle_params.reset(new BattleParamTable("system/blueburst/BattleParamEntry"));
|
||||
|
||||
log(INFO, "loading level table");
|
||||
log(INFO, "Loading level table");
|
||||
state->level_table.reset(new LevelTable("system/blueburst/PlyLevelTbl.prs", true));
|
||||
|
||||
log(INFO, "collecting quest metadata");
|
||||
log(INFO, "Collecting quest metadata");
|
||||
state->quest_index.reset(new QuestIndex("system/quests"));
|
||||
}
|
||||
|
||||
if (!state->username.empty()) {
|
||||
log(INFO, "switching to user %s", state->username.c_str());
|
||||
log(INFO, "Switching to user %s", state->username.c_str());
|
||||
drop_privileges(state->username);
|
||||
}
|
||||
|
||||
@@ -295,7 +294,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
shared_ptr<Shell> shell;
|
||||
if (should_run_shell) {
|
||||
log(INFO, "starting interactive shell");
|
||||
log(INFO, "Starting interactive shell");
|
||||
if (proxy_port) {
|
||||
shell.reset(new ProxyShell(base, state, proxy_server));
|
||||
} else {
|
||||
@@ -303,9 +302,9 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
log(INFO, "ready");
|
||||
log(INFO, "Ready");
|
||||
event_base_dispatch(base.get());
|
||||
|
||||
log(INFO, "normal shutdown");
|
||||
log(INFO, "Normal shutdown");
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -420,7 +420,7 @@ static vector<PSOEnemy> parse_map(uint8_t episode, uint8_t difficulty,
|
||||
break;
|
||||
default:
|
||||
enemies[num_enemies].experience = 0xFFFFFFFF;
|
||||
log(WARNING, "unknown enemy type %08" PRIX32 " %08" PRIX32, map[y].base,
|
||||
log(WARNING, "Unknown enemy type %08" PRIX32 " %08" PRIX32, map[y].base,
|
||||
map[y].skin);
|
||||
break;
|
||||
}
|
||||
|
||||
+2
-2
@@ -112,11 +112,11 @@ void ProxyServer::on_listen_accept(struct evconnlistener*, evutil_socket_t fd,
|
||||
struct sockaddr*, int) {
|
||||
|
||||
if (this->client_bev.get()) {
|
||||
log(WARNING, "ignoring client connection because client already exists");
|
||||
log(WARNING, "Ignoring client connection because client already exists");
|
||||
close(fd);
|
||||
return;
|
||||
} else {
|
||||
log(INFO, "client connected");
|
||||
log(INFO, "Client connected");
|
||||
}
|
||||
|
||||
this->client_bev.reset(bufferevent_socket_new(this->base.get(), fd,
|
||||
|
||||
+11
-11
@@ -26,23 +26,23 @@ void ProxyShell::execute_command(const string& command) {
|
||||
|
||||
} else if (command_name == "help") {
|
||||
fprintf(stderr, "\
|
||||
commands:\n\
|
||||
Commands:\n\
|
||||
help\n\
|
||||
you\'re reading it now\n\
|
||||
You\'re reading it now.\n\
|
||||
exit (or ctrl+d)\n\
|
||||
shut down the proxy\n\
|
||||
Shut down the proxy.\n\
|
||||
sc <data>\n\
|
||||
send a command to the client\n\
|
||||
Send a command to the client.\n\
|
||||
ss <data>\n\
|
||||
send a command to the server\n\
|
||||
Send a command to the server.\n\
|
||||
chat <text>\n\
|
||||
send a chat message to the server\n\
|
||||
Send a chat message to the server.\n\
|
||||
dchat <data>\n\
|
||||
send a chat message to the server with arbitrary data in it\n\
|
||||
Send a chat message to the server with arbitrary data in it.\n\
|
||||
marker <color-id>\n\
|
||||
send a lobby marker message to the server\n\
|
||||
Send a lobby marker message to the server.\n\
|
||||
event <event-id>\n\
|
||||
send a lobby event update to yourself\n\
|
||||
Send a lobby event update to yourself.\n\
|
||||
");
|
||||
|
||||
} else if ((command_name == "sc") || (command_name == "ss")) {
|
||||
@@ -81,7 +81,7 @@ commands:\n\
|
||||
uint16_t* size_field = reinterpret_cast<uint16_t*>(data.data() + 2);
|
||||
*size_field = data.size();
|
||||
|
||||
log(INFO, "client (from proxy):");
|
||||
log(INFO, "Client (from proxy):");
|
||||
print_data(stderr, data);
|
||||
this->proxy_server->send_to_server(data);
|
||||
|
||||
@@ -89,7 +89,7 @@ commands:\n\
|
||||
string data("\x89\x00\x04\x00", 4);
|
||||
data[1] = stod(command_args);
|
||||
|
||||
log(INFO, "client (from proxy):");
|
||||
log(INFO, "Client (from proxy):");
|
||||
print_data(stderr, data);
|
||||
this->proxy_server->send_to_server(data);
|
||||
|
||||
|
||||
+5
-5
@@ -422,18 +422,18 @@ QuestIndex::QuestIndex(const char* directory) : directory(directory) {
|
||||
}
|
||||
|
||||
if (ends_with(filename, ".bin") || ends_with(filename, ".bin.gci")) {
|
||||
// try {
|
||||
try {
|
||||
shared_ptr<Quest> q(new Quest(full_path));
|
||||
this->version_id_to_quest.emplace(make_pair(q->version, q->quest_id), q);
|
||||
this->version_name_to_quest.emplace(make_pair(q->version, q->name), q);
|
||||
string ascii_name = encode_sjis(q->name);
|
||||
log(INFO, "indexed quest %s (%s-%" PRId64 ", %s, episode=%hhu, joinable=%s, dcv1=%s)",
|
||||
log(INFO, "Indexed quest %s (%s-%" PRId64 ", %s, episode=%hhu, joinable=%s, dcv1=%s)",
|
||||
ascii_name.c_str(), name_for_version(q->version), q->quest_id,
|
||||
name_for_category(q->category), q->episode,
|
||||
q->joinable ? "true" : "false", q->is_dcv1 ? "true" : "false");
|
||||
// } catch (const exception& e) {
|
||||
// log(WARNING, "failed to parse quest file %s (%s)", filename.c_str(), e.what());
|
||||
// }
|
||||
} catch (const exception& e) {
|
||||
log(WARNING, "Failed to parse quest file %s (%s)", filename.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ void process_connect(std::shared_ptr<ServerState> s, std::shared_ptr<Client> c)
|
||||
break;
|
||||
|
||||
default:
|
||||
log(ERROR, "unimplemented behavior: %" PRId64,
|
||||
log(ERROR, "Unimplemented behavior: %" PRId64,
|
||||
static_cast<int64_t>(c->server_behavior));
|
||||
}
|
||||
}
|
||||
@@ -525,7 +525,7 @@ void process_ep3_server_data_request(shared_ptr<ServerState> s, shared_ptr<Clien
|
||||
CommandEp3InitBegin(s, c);
|
||||
break; */
|
||||
default:
|
||||
log(WARNING, "unknown Ep3 server data request: %02X", cmds[1].byte[0]);
|
||||
log(WARNING, "Unknown Episode III server data request: %02X", cmds[1].byte[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1762,7 +1762,7 @@ void process_ignored_command(shared_ptr<ServerState>, shared_ptr<Client>,
|
||||
|
||||
void process_unimplemented_command(shared_ptr<ServerState>, shared_ptr<Client>,
|
||||
uint16_t command, uint32_t flag, uint16_t size, const void*) {
|
||||
log(WARNING, "unknown command: size=%04X command=%04X flag=%08X\n",
|
||||
log(WARNING, "Unknown command: size=%04X command=%04X flag=%08X\n",
|
||||
size, command, flag);
|
||||
throw invalid_argument("unimplemented command");
|
||||
}
|
||||
@@ -2213,7 +2213,7 @@ void process_command(shared_ptr<ServerState> s, shared_ptr<Client> c,
|
||||
uint16_t command, uint32_t flag, uint16_t size, const void* data) {
|
||||
// TODO: this is slow; make it better somehow
|
||||
{
|
||||
log(INFO, "received version=%d size=%04hX command=%04hX flag=%08X",
|
||||
log(INFO, "Received version=%d size=%04hX command=%04hX flag=%08X",
|
||||
static_cast<int>(c->version), size, command, flag);
|
||||
|
||||
string data_to_print;
|
||||
|
||||
@@ -869,28 +869,26 @@ static void process_subcommand_forward_check_size_game(shared_ptr<ServerState>,
|
||||
forward_subcommand(l, c, command, flag, p, count);
|
||||
}
|
||||
|
||||
// used for invalid commands. normally, clients should be disconnected - to restore this behavior, change the return value back to SUBCOMMAND_ERROR_INVALID_COMMAND.
|
||||
static void process_subcommand_invalid(shared_ptr<ServerState>,
|
||||
shared_ptr<Lobby>, shared_ptr<Client>, uint8_t command, uint8_t flag,
|
||||
const PSOSubcommand* p, size_t count) {
|
||||
if (command_is_private(command)) {
|
||||
log(WARNING, "invalid subcommand: %02hhX (%zu of them) (private to player %hhu)",
|
||||
log(WARNING, "Invalid subcommand: %02hhX (%zu of them) (private to player %hhu)",
|
||||
p->byte[0], count, flag);
|
||||
} else {
|
||||
log(WARNING, "invalid subcommand: %02hhX (%zu of them) (public)",
|
||||
log(WARNING, "Invalid subcommand: %02hhX (%zu of them) (public)",
|
||||
p->byte[0], count);
|
||||
}
|
||||
}
|
||||
|
||||
// used when an error occurs (unknown commands, etc). normally, clients should be disconnected - to restore this behavior, change the return value back to SUBCOMMAND_ERROR_INVALID_COMMAND.
|
||||
static void process_subcommand_unimplemented(shared_ptr<ServerState>,
|
||||
shared_ptr<Lobby>, shared_ptr<Client>, uint8_t command, uint8_t flag,
|
||||
const PSOSubcommand* p, size_t count) {
|
||||
if (command_is_private(command)) {
|
||||
log(WARNING, "unknown subcommand: %02hhX (%zu of them) (private to player %hhu)",
|
||||
log(WARNING, "Unknown subcommand: %02hhX (%zu of them) (private to player %hhu)",
|
||||
p->byte[0], count, flag);
|
||||
} else {
|
||||
log(WARNING, "unknown subcommand: %02hhX (%zu of them) (public)",
|
||||
log(WARNING, "Unknown subcommand: %02hhX (%zu of them) (public)",
|
||||
p->byte[0], count);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ void send_command(shared_ptr<Client> c, uint16_t command, uint32_t flag,
|
||||
throw logic_error("unimplemented game version in send_command");
|
||||
}
|
||||
|
||||
log(INFO, "sending command");
|
||||
log(INFO, "Sending command");
|
||||
print_data(stderr, send_data.data(), send_data.size());
|
||||
|
||||
c->send(move(send_data));
|
||||
|
||||
+9
-9
@@ -92,13 +92,13 @@ void Server::on_listen_accept(struct evconnlistener* listener,
|
||||
try {
|
||||
listening_socket = &this->listening_sockets.at(listen_fd);
|
||||
} catch (const out_of_range& e) {
|
||||
log(WARNING, "[Server] can\'t determine version for socket %d; disconnecting client",
|
||||
log(WARNING, "[Server] Can\'t determine version for socket %d; disconnecting client",
|
||||
listen_fd);
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
log(INFO, "[Server] client connected via fd %d", listen_fd);
|
||||
log(INFO, "[Server] Client connected via fd %d", listen_fd);
|
||||
|
||||
struct bufferevent *bev = bufferevent_socket_new(this->base.get(), fd,
|
||||
BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS);
|
||||
@@ -115,7 +115,7 @@ void Server::on_listen_accept(struct evconnlistener* listener,
|
||||
|
||||
void Server::on_listen_error(struct evconnlistener* listener) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
log(ERROR, "[Server] failure on listening socket %d: %d (%s)",
|
||||
log(ERROR, "[Server] Failure on listening socket %d: %d (%s)",
|
||||
evconnlistener_get_fd(listener), err, evutil_socket_error_to_string(err));
|
||||
event_base_loopexit(this->base.get(), NULL);
|
||||
}
|
||||
@@ -125,7 +125,7 @@ void Server::on_client_input(struct bufferevent* bev) {
|
||||
try {
|
||||
c = this->bev_to_client.at(bev);
|
||||
} catch (const out_of_range& e) {
|
||||
log(WARNING, "[Server] received message from client with no configuration");
|
||||
log(WARNING, "[Server] Received message from client with no configuration");
|
||||
|
||||
// ignore all the data
|
||||
// TODO: we probably should disconnect them or something
|
||||
@@ -155,7 +155,7 @@ void Server::on_disconnecting_client_output(struct bufferevent* bev) {
|
||||
void Server::on_client_error(struct bufferevent* bev, short events) {
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
log(WARNING, "[Server] client caused %d (%s)", err,
|
||||
log(WARNING, "[Server] Client caused error %d (%s)", err,
|
||||
evutil_socket_error_to_string(err));
|
||||
}
|
||||
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
|
||||
@@ -167,7 +167,7 @@ void Server::on_disconnecting_client_error(struct bufferevent* bev,
|
||||
short events) {
|
||||
if (events & BEV_EVENT_ERROR) {
|
||||
int err = EVUTIL_SOCKET_ERROR();
|
||||
log(WARNING, "[Server] disconnecting client caused %d (%s)", err,
|
||||
log(WARNING, "[Server] Disconnecting client caused error %d (%s)", err,
|
||||
evutil_socket_error_to_string(err));
|
||||
}
|
||||
if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
|
||||
@@ -213,7 +213,7 @@ void Server::receive_and_process_commands(shared_ptr<Client> c) {
|
||||
process_command(this->state, c, header->command(c->version),
|
||||
header->flag(c->version), size - header_size, data.data());
|
||||
} catch (const exception& e) {
|
||||
log(INFO, "[Server] error in client stream: %s", e.what());
|
||||
log(INFO, "[Server] Error in client stream: %s", e.what());
|
||||
c->should_disconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -233,7 +233,7 @@ Server::Server(shared_ptr<struct event_base> base,
|
||||
void Server::listen(const string& socket_path, GameVersion version,
|
||||
ServerBehavior behavior) {
|
||||
int fd = ::listen(socket_path, 0, SOMAXCONN);
|
||||
log(INFO, "[Server] listening on unix socket %s (version %s) on fd %d",
|
||||
log(INFO, "[Server] Listening on unix socket %s (version %s) on fd %d",
|
||||
socket_path.c_str(), name_for_version(version), fd);
|
||||
this->add_socket(fd, version, behavior);
|
||||
}
|
||||
@@ -242,7 +242,7 @@ void Server::listen(const string& addr, int port, GameVersion version,
|
||||
ServerBehavior behavior) {
|
||||
int fd = ::listen(addr, port, SOMAXCONN);
|
||||
string netloc_str = render_netloc(addr, port);
|
||||
log(INFO, "[Server] listening on tcp interface %s (version %s) on fd %d",
|
||||
log(INFO, "[Server] Listening on tcp interface %s (version %s) on fd %d",
|
||||
netloc_str.c_str(), name_for_version(version), fd);
|
||||
this->add_socket(fd, version, behavior);
|
||||
}
|
||||
|
||||
+15
-15
@@ -34,32 +34,32 @@ void ServerShell::execute_command(const string& command) {
|
||||
|
||||
} else if (command_name == "help") {
|
||||
fprintf(stderr, "\
|
||||
commands:\n\
|
||||
Commands:\n\
|
||||
help\n\
|
||||
you\'re reading it now\n\
|
||||
You\'re reading it now.\n\
|
||||
exit (or ctrl+d)\n\
|
||||
shut down the server\n\
|
||||
Shut down the server.\n\
|
||||
reload <item> ...\n\
|
||||
reload data. <item> can be licenses, battle-params, level-table, or quests.\n\
|
||||
Reload data. <item> can be licenses, battle-params, level-table, or quests.\n\
|
||||
add-license <parameters>\n\
|
||||
add a license to the server. <parameters> is some subset of the following:\n\
|
||||
username=<username> (bb username)\n\
|
||||
bb-password=<password> (bb password)\n\
|
||||
gc-password=<password> (gc password)\n\
|
||||
access-key=<access-key> (gc/pc access key)\n\
|
||||
serial=<serial-number> (gc/pc serial number; required for all licenses)\n\
|
||||
Add a license to the server. <parameters> is some subset of the following:\n\
|
||||
username=<username> (BB username)\n\
|
||||
bb-password=<password> (BB password)\n\
|
||||
gc-password=<password> (GC password)\n\
|
||||
access-key=<access-key> (GC/PC access key)\n\
|
||||
serial=<serial-number> (GC/PC serial number; required for all licenses)\n\
|
||||
privileges=<privilege-mask> (can be normal, mod, admin, root, or numeric)\n\
|
||||
delete-license <serial-number>\n\
|
||||
delete a license from the server\n\
|
||||
Delete a license from the server.\n\
|
||||
list-licenses\n\
|
||||
list all licenses registered on the server\n\
|
||||
List all licenses registered on the server.\n\
|
||||
set-allow-unregistered-users <true/false>\n\
|
||||
enable or disable allowing unregistered users on the server. disabling this\n\
|
||||
Enable or disable allowing unregistered users on the server. Disabling this\n\
|
||||
does not disconnect unregistered users who are already connected.\n\
|
||||
set-event <event>\n\
|
||||
set the event in all lobbies\n\
|
||||
Set the event in all lobbies.\n\
|
||||
announce <message>\n\
|
||||
send an announcement message to all players\n\
|
||||
Send an announcement message to all players.\n\
|
||||
");
|
||||
|
||||
} else if (command_name == "reload") {
|
||||
|
||||
Reference in New Issue
Block a user