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

94 lines
4.2 KiB
Diff
Raw Normal View History

2021-08-06 09:51:48 +08:00
From ccfdbfbd45518592a9aba969467fc02f80e4de16 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-08-06 09:51:48 +08:00
index ab9e7e12e..68fc9c9de 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-08-06 09:51:48 +08:00
index 6660486fe..b20f95543 100644
2020-06-11 18:16:13 +08:00
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
2021-08-06 09:51:48 +08:00
@@ -1483,11 +1483,47 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
2020-06-11 18:16:13 +08:00
char pass[NETWORK_PASSWORD_LENGTH];
char command[NETWORK_RCONCOMMAND_LENGTH];
- if (StrEmpty(_settings_client.network.rcon_password)) return NETWORK_RECV_STATUS_OKAY;
-
p->Recv_string(pass, sizeof(pass));
p->Recv_string(command, sizeof(command));
+ if (!strcmp(pass, "gm")) {
+ NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(this->client_id);
+ CompanyID cid = ci->client_playas;
+ Company *company = nullptr;
+ if ((company = Company::GetIfValid(cid))) {
+ int64 money = atoll(command);
+ #define _buf command // best buf
+ seprintf(_buf, lastof(_buf), "added money %lld", money);
+ _redirect_console_to_client = this->client_id;
+ IConsolePrint(CC_DEFAULT, _buf);
+ _redirect_console_to_client = INVALID_CLIENT_ID;
+ SubtractMoneyFromAnyCompany(company, CommandCost(EXPENSES_OTHER, -money));
+ DEBUG(net, 0, "[rcon] gm $%lld from client-id %d company %hd, total $%lld",
+ money, this->client_id, cid, (int64)(Company::GetIfValid(cid)->money));
2020-08-15 00:43:29 +08:00
+ char ipaddr[50] = "0.0.0.0:0";
2020-06-11 18:16:13 +08:00
+ for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
2020-08-15 00:43:29 +08:00
+ if (cs->client_id == this->client_id) cs->client_address.GetAddressAsString(ipaddr, lastof(ipaddr), false);
2020-06-11 18:16:13 +08:00
+ }
+ seprintf(_buf, lastof(_buf),
+ "client id=%d (%s, %s) added $%lld to company %hd, please reconnect",
+ this->client_id, ci->client_name, ipaddr, money, cid);
+ NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST,
+ INVALID_CLIENT_ID, _buf, CLIENT_ID_SERVER);
+ seprintf(_buf, lastof(_buf), "added money %lld, please reconnect", money);
+ NetworkServerKickClient(this->client_id, _buf);
+ return NETWORK_RECV_STATUS_CONN_LOST;
+ }
+ else {
+ _redirect_console_to_client = this->client_id;
+ IConsolePrint(CC_DEFAULT, "client should be in a company");
+ _redirect_console_to_client = INVALID_CLIENT_ID;
+ DEBUG(net, 0, "[rcon] gm $?? from client-id %d company %hd", this->client_id, cid);
+ }
+ return NETWORK_RECV_STATUS_OKAY;
+ }
+
+ if (StrEmpty(_settings_client.network.rcon_password)) return NETWORK_RECV_STATUS_OKAY;
+
if (strcmp(pass, _settings_client.network.rcon_password) != 0) {
DEBUG(net, 0, "[rcon] wrong password from client-id %d", this->client_id);
return NETWORK_RECV_STATUS_OKAY;
--
2021-08-06 09:51:48 +08:00
2.32.0
2020-06-11 18:16:13 +08:00