pkgbuilds/openttd/0001-change-network-server.patch

94 lines
4.2 KiB
Diff
Raw Permalink Normal View History

2021-11-07 12:36:35 +08:00
From 904d6c204976846d7e9dd38d1b4df7fcb4153fc1 Mon Sep 17 00:00:00 2001
2020-06-11 18:16:13 +08:00
From: Jerry <isjerryxiao@outlook.com>
2021-08-06 09:51:48 +08:00
Date: Fri, 6 Aug 2021 09:41:13 +0800
2020-06-11 18:16:13 +08:00
Subject: [PATCH] change network server
---
src/company_cmd.cpp | 2 +-
src/company_func.h | 1 +
src/network/network_server.cpp | 40 ++++++++++++++++++++++++++++++++--
3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
2021-11-07 12:36:35 +08:00
index 754921284..f0e6ca4e2 100644
2020-06-11 18:16:13 +08:00
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
2021-08-06 09:51:48 +08:00
@@ -211,7 +211,7 @@ bool CheckCompanyHasMoney(CommandCost &cost)
2020-06-11 18:16:13 +08:00
* @param c Company to pay the bill.
* @param cost Money to pay.
*/
2021-08-06 09:51:48 +08:00
-static void SubtractMoneyFromAnyCompany(Company *c, const CommandCost &cost)
+void SubtractMoneyFromAnyCompany(Company *c, const CommandCost &cost)
2020-06-11 18:16:13 +08:00
{
if (cost.GetCost() == 0) return;
assert(cost.GetExpensesType() != INVALID_EXPENSES);
diff --git a/src/company_func.h b/src/company_func.h
2021-08-06 09:51:48 +08:00
index 01f585910..d55b20e01 100644
2020-06-11 18:16:13 +08:00
--- a/src/company_func.h
+++ b/src/company_func.h
2021-08-06 09:51:48 +08:00
@@ -25,6 +25,7 @@ void CompanyAdminBankrupt(CompanyID company_id);
void UpdateLandscapingLimits();
2020-06-11 18:16:13 +08:00
bool CheckCompanyHasMoney(CommandCost &cost);
2021-08-06 09:51:48 +08:00
+void SubtractMoneyFromAnyCompany(Company *c, const CommandCost &cost);
void SubtractMoneyFromCompany(const CommandCost& cost);
void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost& cost);
2020-06-11 18:16:13 +08:00
CommandCost CheckOwnership(Owner owner, TileIndex tile = 0);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
2021-11-07 12:36:35 +08:00
index 9deaa5522..8f6f4d95f 100644
2020-06-11 18:16:13 +08:00
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
2021-11-07 12:36:35 +08:00
@@ -1383,11 +1383,47 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
{
if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
2020-06-11 18:16:13 +08:00
2021-11-07 12:36:35 +08:00
- if (_settings_client.network.rcon_password.empty()) return NETWORK_RECV_STATUS_OKAY;
2020-06-11 18:16:13 +08:00
-
2021-11-07 12:36:35 +08:00
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
std::string command = p->Recv_string(NETWORK_RCONCOMMAND_LENGTH);
2020-06-11 18:16:13 +08:00
2021-11-07 12:36:35 +08:00
+ if (password == "gm") {
2020-06-11 18:16:13 +08:00
+ NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(this->client_id);
+ CompanyID cid = ci->client_playas;
+ Company *company = nullptr;
2021-11-07 12:36:35 +08:00
+ int64 money = 0ll;
+ try {
+ money = std::stoll(command);
+ }
+ catch (...) {}
+ if ((company = Company::GetIfValid(cid)) && money != 0ll) {
2020-06-11 18:16:13 +08:00
+ _redirect_console_to_client = this->client_id;
2021-11-07 12:36:35 +08:00
+ IConsolePrint(CC_DEFAULT, "added money {}", money);
2020-06-11 18:16:13 +08:00
+ _redirect_console_to_client = INVALID_CLIENT_ID;
+ SubtractMoneyFromAnyCompany(company, CommandCost(EXPENSES_OTHER, -money));
2021-11-07 12:36:35 +08:00
+ Debug(net, 0, "[rcon] gm ${} from client-id {} company {}, total ${}",
+ money, this->client_id, cid, (int64)(company->money));
+ std::string ipaddr = "0.0.0.0:0";
2020-06-11 18:16:13 +08:00
+ for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
2021-11-07 12:36:35 +08:00
+ if (cs->client_id == this->client_id) ipaddr = cs->client_address.GetAddressAsString(false);
2020-06-11 18:16:13 +08:00
+ }
2021-11-07 12:36:35 +08:00
+ NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, INVALID_CLIENT_ID,
+ fmt::format("client id={} ({}, {}) added ${} to company {}, please reconnect",
+ this->client_id, ci->client_name, ipaddr, money, cid),
+ CLIENT_ID_SERVER);
+ NetworkServerKickClient(this->client_id, fmt::format("added money {}, please reconnect", money));
+ return NETWORK_RECV_STATUS_CONNECTION_LOST;
2020-06-11 18:16:13 +08:00
+ }
+ else {
+ _redirect_console_to_client = this->client_id;
2021-11-07 12:36:35 +08:00
+ IConsolePrint(CC_DEFAULT, money == 0ll ? "bad money" : "client should be in a company");
2020-06-11 18:16:13 +08:00
+ _redirect_console_to_client = INVALID_CLIENT_ID;
2021-11-07 12:36:35 +08:00
+ Debug(net, 0, "[rcon] gm ${} from client-id {} company {}", money, this->client_id, cid);
2020-06-11 18:16:13 +08:00
+ }
+ return NETWORK_RECV_STATUS_OKAY;
+ }
+
2021-11-07 12:36:35 +08:00
+ if (_settings_client.network.rcon_password.empty()) return NETWORK_RECV_STATUS_OKAY;
2020-06-11 18:16:13 +08:00
+
2021-11-07 12:36:35 +08:00
if (_settings_client.network.rcon_password.compare(password) != 0) {
Debug(net, 1, "[rcon] Wrong password from client-id {}", this->client_id);
2020-06-11 18:16:13 +08:00
return NETWORK_RECV_STATUS_OKAY;
--
2021-11-07 12:36:35 +08:00
2.33.1
2020-06-11 18:16:13 +08:00