add $si command
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "Loggers.hh"
|
||||
#include "ProxyServer.hh"
|
||||
#include "ReceiveCommands.hh"
|
||||
#include "Revision.hh"
|
||||
#include "SendCommands.hh"
|
||||
#include "Server.hh"
|
||||
#include "StaticGameData.hh"
|
||||
@@ -91,6 +92,20 @@ static void check_is_leader(shared_ptr<Lobby> l, shared_ptr<Client> c) {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Message commands
|
||||
|
||||
static void server_command_server_info(shared_ptr<Client> c, const std::string&) {
|
||||
auto s = c->require_server_state();
|
||||
string uptime_str = format_duration(now() - s->creation_time);
|
||||
string build_date = format_time(BUILD_TIMESTAMP);
|
||||
send_text_message_printf(c,
|
||||
"Revision: $C6%s$C7\n$C6%s$C7\nUptime: $C6%s$C7\nLobbies: $C6%zu$C7\nClients: $C6%zu$C7(g) $C6%zu$C7(p)",
|
||||
GIT_REVISION_HASH,
|
||||
build_date.c_str(),
|
||||
uptime_str.c_str(),
|
||||
s->id_to_lobby.size(),
|
||||
s->channel_to_client.size(),
|
||||
s->proxy_server->num_sessions());
|
||||
}
|
||||
|
||||
static void server_command_lobby_info(shared_ptr<Client> c, const std::string&) {
|
||||
vector<string> lines;
|
||||
|
||||
@@ -1906,6 +1921,7 @@ static const unordered_map<string, ChatCommandDefinition> chat_commands({
|
||||
{"$saverec", {server_command_saverec, nullptr}},
|
||||
{"$sc", {server_command_send_client, proxy_command_send_client}},
|
||||
{"$secid", {server_command_secid, proxy_command_secid}},
|
||||
{"$si", {server_command_server_info, nullptr}},
|
||||
{"$silence", {server_command_silence, nullptr}},
|
||||
{"$song", {server_command_song, proxy_command_song}},
|
||||
{"$spec", {server_command_toggle_spectator_flag, nullptr}},
|
||||
|
||||
+17
-1
@@ -35,6 +35,7 @@
|
||||
#include "Quest.hh"
|
||||
#include "QuestScript.hh"
|
||||
#include "ReplaySession.hh"
|
||||
#include "Revision.hh"
|
||||
#include "SaveFileFormats.hh"
|
||||
#include "SendCommands.hh"
|
||||
#include "Server.hh"
|
||||
@@ -49,6 +50,7 @@ using namespace std;
|
||||
|
||||
bool use_terminal_colors = false;
|
||||
|
||||
void print_version_info();
|
||||
void print_usage();
|
||||
|
||||
template <typename T>
|
||||
@@ -204,6 +206,14 @@ Action a_help(
|
||||
print_usage();
|
||||
});
|
||||
|
||||
Action a_version(
|
||||
"version", "\
|
||||
version\n\
|
||||
Show newserv\'s revision and build date.\n",
|
||||
+[](Arguments&) -> void {
|
||||
print_version_info();
|
||||
});
|
||||
|
||||
static void a_compress_decompress_fn(Arguments& args) {
|
||||
const auto& action = args.get<string>(0);
|
||||
bool is_prs = ends_with(action, "-prs");
|
||||
@@ -1890,8 +1900,14 @@ Action a_run_server_replay_log(
|
||||
state->proxy_server.reset(); // Break reference cycle
|
||||
});
|
||||
|
||||
void print_version_info() {
|
||||
string build_date = format_time(BUILD_TIMESTAMP);
|
||||
fprintf(stderr, "newserv-%s built %s UTC\n", GIT_REVISION_HASH, build_date.c_str());
|
||||
}
|
||||
|
||||
void print_usage() {
|
||||
fputs("\
|
||||
print_version_info();
|
||||
fputs("\n\
|
||||
Usage:\n\
|
||||
newserv [ACTION] [OPTIONS...]\n\
|
||||
\n\
|
||||
|
||||
@@ -910,6 +910,10 @@ void ProxyServer::destroy_sessions() {
|
||||
this->unlinked_sessions_to_destroy.clear();
|
||||
}
|
||||
|
||||
size_t ProxyServer::num_sessions() const {
|
||||
return this->id_to_session.size();
|
||||
}
|
||||
|
||||
size_t ProxyServer::delete_disconnected_sessions() {
|
||||
size_t count = 0;
|
||||
for (auto it = this->id_to_session.begin(); it != this->id_to_session.end();) {
|
||||
|
||||
@@ -190,6 +190,8 @@ public:
|
||||
void delete_session(uint64_t id);
|
||||
void delete_session(struct bufferevent* bev);
|
||||
|
||||
size_t num_sessions() const;
|
||||
|
||||
size_t delete_disconnected_sessions();
|
||||
|
||||
private:
|
||||
|
||||
@@ -2959,12 +2959,18 @@ static void on_quest_F960_result_bb(shared_ptr<Client> c, uint8_t, uint8_t, void
|
||||
G_SetMesetaSlotPrizeResult_BB_6xE3 cmd_6xE3 = {{0xE3, sizeof(G_SetMesetaSlotPrizeResult_BB_6xE3) >> 2, 0x0000}, item};
|
||||
send_command_t(c, 0x60, 0x00, cmd_6xE3);
|
||||
|
||||
p->add_item(item);
|
||||
send_create_inventory_item_to_lobby(c, c->lobby_client_id, item);
|
||||
|
||||
if (c->log.should_log(LogLevel::INFO)) {
|
||||
string name = s->item_name_index->describe_item(c->version(), item);
|
||||
c->log.info("Awarded item %s", name.c_str());
|
||||
try {
|
||||
p->add_item(item);
|
||||
send_create_inventory_item_to_lobby(c, c->lobby_client_id, item);
|
||||
if (c->log.should_log(LogLevel::INFO)) {
|
||||
string name = s->item_name_index->describe_item(c->version(), item);
|
||||
c->log.info("Awarded item %s", name.c_str());
|
||||
}
|
||||
} catch (const out_of_range&) {
|
||||
if (c->log.should_log(LogLevel::INFO)) {
|
||||
string name = s->item_name_index->describe_item(c->version(), item);
|
||||
c->log.info("Attempted to award item %s, but inventory was full", name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
GIT_REVISION_HASH=$(git rev-parse --short HEAD)
|
||||
TIMESTAMP_SECS=$(date +%s)
|
||||
|
||||
if [ -z "$GIT_REVISION_HASH" ]; then
|
||||
GIT_REVISION_HASH="????"
|
||||
else
|
||||
if ! git diff-index --quiet HEAD -- ; then
|
||||
GIT_REVISION_HASH="$GIT_REVISION_HASH+"
|
||||
fi
|
||||
fi
|
||||
|
||||
cat > Revision.cc <<EOF
|
||||
#include "Revision.hh"
|
||||
|
||||
const char* GIT_REVISION_HASH = "$GIT_REVISION_HASH";
|
||||
const uint64_t BUILD_TIMESTAMP = static_cast<uint64_t>($TIMESTAMP_SECS) * 1000000;
|
||||
EOF
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern const char* GIT_REVISION_HASH;
|
||||
extern const uint64_t BUILD_TIMESTAMP;
|
||||
+2
-1
@@ -30,7 +30,8 @@ ServerState::QuestF960Result::QuestF960Result(const JSON& json, std::shared_ptr<
|
||||
}
|
||||
|
||||
ServerState::ServerState(shared_ptr<struct event_base> base, const string& config_filename, bool is_replay)
|
||||
: base(base),
|
||||
: creation_time(now()),
|
||||
base(base),
|
||||
config_filename(config_filename),
|
||||
is_replay(is_replay),
|
||||
dns_server_port(0),
|
||||
|
||||
@@ -59,6 +59,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
|
||||
return (b == BehaviorSwitch::OFF_BY_DEFAULT) || (b == BehaviorSwitch::ON_BY_DEFAULT);
|
||||
}
|
||||
|
||||
uint64_t creation_time;
|
||||
std::shared_ptr<struct event_base> base;
|
||||
|
||||
std::string config_filename;
|
||||
|
||||
Reference in New Issue
Block a user