forked from townforge/townforge
daemon: add cc_game_events command
This commit is contained in:
parent
f0539e2316
commit
14163824c2
@ -1377,4 +1377,89 @@ bool t_command_parser_executor::cc_merchant_ships(const std::vector<std::string>
|
||||
return m_executor.cc_merchant_ships();
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::cc_game_events(const std::vector<std::string>& args)
|
||||
{
|
||||
uint64_t min_height = 0, max_height = CRYPTONOTE_MAX_BLOCK_NUMBER;
|
||||
uint32_t account = 0, flag = 0;
|
||||
std::string filter;
|
||||
|
||||
for (size_t i = 0; i < args.size(); ++i)
|
||||
{
|
||||
if (args[i] == "-account")
|
||||
{
|
||||
if (i == args.size() - 1)
|
||||
{
|
||||
std::cout << "Missing argument to -account" << std::endl;
|
||||
return true;
|
||||
}
|
||||
if (!epee::string_tools::get_xtype_from_string(account, args[i+1]))
|
||||
{
|
||||
std::cout << "Invalid argument to -account" << std::endl;
|
||||
return true;
|
||||
}
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
if (args[i] == "-flag")
|
||||
{
|
||||
if (i == args.size() - 1)
|
||||
{
|
||||
std::cout << "Missing argument to -flag" << std::endl;
|
||||
return true;
|
||||
}
|
||||
if (!epee::string_tools::get_xtype_from_string(flag, args[i+1]))
|
||||
{
|
||||
std::cout << "Invalid argument to -flag" << std::endl;
|
||||
return true;
|
||||
}
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
if (args[i] == "-min_height")
|
||||
{
|
||||
if (i == args.size() - 1)
|
||||
{
|
||||
std::cout << "Missing argument to -min_height" << std::endl;
|
||||
return true;
|
||||
}
|
||||
if (!epee::string_tools::get_xtype_from_string(min_height, args[i+1]))
|
||||
{
|
||||
std::cout << "Invalid argument to -min_height" << std::endl;
|
||||
return true;
|
||||
}
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
if (args[i] == "-max_height")
|
||||
{
|
||||
if (i == args.size() - 1)
|
||||
{
|
||||
std::cout << "Missing argument to -max_height" << std::endl;
|
||||
return true;
|
||||
}
|
||||
if (!epee::string_tools::get_xtype_from_string(max_height, args[i+1]))
|
||||
{
|
||||
std::cout << "Invalid argument to -max_height" << std::endl;
|
||||
return true;
|
||||
}
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
if (args[i] == "-filter")
|
||||
{
|
||||
if (i == args.size() - 1)
|
||||
{
|
||||
std::cout << "Missing argument to -filter" << std::endl;
|
||||
return true;
|
||||
}
|
||||
filter = args[i+1];
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
std::cout << "Unknown argument: " << args[i] << std::endl;
|
||||
return true;
|
||||
}
|
||||
return m_executor.cc_game_events(min_height, max_height, account, flag, filter);
|
||||
}
|
||||
|
||||
} // namespace daemonize
|
||||
|
@ -175,6 +175,7 @@ public:
|
||||
bool cc_script_variables(const std::vector<std::string>& args);
|
||||
bool cc_merchant_ship_available_items(const std::vector<std::string>& args);
|
||||
bool cc_merchant_ships(const std::vector<std::string>& args);
|
||||
bool cc_game_events(const std::vector<std::string>& args);
|
||||
};
|
||||
|
||||
} // namespace daemonize
|
||||
|
@ -427,6 +427,12 @@ t_command_server::t_command_server(
|
||||
, "cc_merchant_ships"
|
||||
, "Show all merchant ships currently ashore"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"cc_game_events"
|
||||
, std::bind(&t_command_parser_executor::cc_game_events, &m_parser, p::_1)
|
||||
, "cc_game_events [-account <id>] [-flag <id>] [-min_height <height>] [-max_height <height>] [-filter <filter>]"
|
||||
, "Show filtered event history for a given account"
|
||||
);
|
||||
m_command_lookup.set_handler(
|
||||
"flush_cache"
|
||||
, std::bind(&t_command_parser_executor::flush_cache, &m_parser, p::_1)
|
||||
|
@ -3669,6 +3669,54 @@ bool t_rpc_command_executor::cc_merchant_ships()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::cc_game_events(uint64_t min_height, uint64_t max_height, uint32_t account, uint32_t flag, const std::string &filter)
|
||||
{
|
||||
cryptonote::COMMAND_RPC_CC_GET_GAME_EVENTS::request req;
|
||||
cryptonote::COMMAND_RPC_CC_GET_GAME_EVENTS::response res;
|
||||
std::string fail_message = "Unsuccessful";
|
||||
epee::json_rpc::error error_resp;
|
||||
|
||||
req.min_height = min_height;
|
||||
req.max_height = max_height;
|
||||
req.account = account;
|
||||
req.flag = flag;
|
||||
req.item = 0;
|
||||
req.cmd = 0;
|
||||
req.filter_news = false;
|
||||
|
||||
if (m_is_rpc)
|
||||
{
|
||||
if (!m_rpc_client->json_rpc_request(req, res, "cc_get_events", fail_message.c_str()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_rpc_server->on_cc_get_game_events(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
|
||||
{
|
||||
tools::fail_msg_writer() << make_error(fail_message, res.status);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &e: res.events)
|
||||
{
|
||||
if (!filter.empty() && !strstr(e.event.c_str(), filter.c_str()))
|
||||
continue;
|
||||
std::stringstream ss;
|
||||
std::string balance_string;
|
||||
if ((int64_t)e.balance < 0)
|
||||
balance_string = "-" + cryptonote::print_money(-(int64_t)e.balance);
|
||||
else
|
||||
balance_string = cryptonote::print_money(e.balance);
|
||||
ss << e.height << "\t" << e.account << "\t" << (e.flags.empty() ? 0 : e.flags.front()) << "\t" << balance_string << "\t" << e.event;
|
||||
tools::msg_writer() << ss.str();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool t_rpc_command_executor::flush_cache(bool bad_txs, bool bad_blocks)
|
||||
{
|
||||
cryptonote::COMMAND_RPC_FLUSH_CACHE::request req;
|
||||
|
@ -193,6 +193,7 @@ public:
|
||||
bool cc_script_variables(const std::string &filter);
|
||||
bool cc_merchant_ship_available_items();
|
||||
bool cc_merchant_ships();
|
||||
bool cc_game_events(uint64_t min_height, uint64_t max_height, uint32_t account, uint32_t flag, const std::string &filter);
|
||||
};
|
||||
|
||||
} // namespace daemonize
|
||||
|
Loading…
Reference in New Issue
Block a user