Update to 14.0-beta1
This commit is contained in:
@@ -9,8 +9,9 @@
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "../strings_func.h"
|
||||
#include "../date_func.h"
|
||||
#include "core/game_info.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "core/network_game_info.h"
|
||||
#include "network_admin.h"
|
||||
#include "network_base.h"
|
||||
#include "network_server.h"
|
||||
@@ -177,9 +178,9 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome()
|
||||
p->Send_string(""); // Used to be map-name.
|
||||
p->Send_uint32(_settings_game.game_creation.generation_seed);
|
||||
p->Send_uint8 (_settings_game.game_creation.landscape);
|
||||
p->Send_uint32(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
|
||||
p->Send_uint16(MapSizeX());
|
||||
p->Send_uint16(MapSizeY());
|
||||
p->Send_uint32(TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1).base());
|
||||
p->Send_uint16(Map::SizeX());
|
||||
p->Send_uint16(Map::SizeY());
|
||||
|
||||
this->SendPacket(p);
|
||||
|
||||
@@ -207,7 +208,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate()
|
||||
{
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_DATE);
|
||||
|
||||
p->Send_uint32(_date);
|
||||
p->Send_uint32(TimerGameCalendar::date.base());
|
||||
this->SendPacket(p);
|
||||
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
@@ -243,7 +244,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkC
|
||||
p->Send_string(cs == nullptr ? "" : const_cast<NetworkAddress &>(cs->client_address).GetHostname());
|
||||
p->Send_string(ci->client_name);
|
||||
p->Send_uint8 (0); // Used to be language
|
||||
p->Send_uint32(ci->join_date);
|
||||
p->Send_uint32(ci->join_date.base());
|
||||
p->Send_uint8 (ci->client_playas);
|
||||
|
||||
this->SendPacket(p);
|
||||
@@ -328,14 +329,10 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo(const Company
|
||||
p->Send_string(GetString(STR_PRESIDENT_NAME));
|
||||
p->Send_uint8 (c->colour);
|
||||
p->Send_bool (NetworkCompanyIsPassworded(c->index));
|
||||
p->Send_uint32(c->inaugurated_year);
|
||||
p->Send_uint32(c->inaugurated_year.base());
|
||||
p->Send_bool (c->is_ai);
|
||||
p->Send_uint8 (CeilDiv(c->months_of_bankruptcy, 3)); // send as quarters_of_bankruptcy
|
||||
|
||||
for (auto owner : c->share_owners) {
|
||||
p->Send_uint8(owner);
|
||||
}
|
||||
|
||||
this->SendPacket(p);
|
||||
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
@@ -359,10 +356,6 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyUpdate(const Compa
|
||||
p->Send_bool (NetworkCompanyIsPassworded(c->index));
|
||||
p->Send_uint8 (CeilDiv(c->months_of_bankruptcy, 3)); // send as quarters_of_bankruptcy
|
||||
|
||||
for (auto owner : c->share_owners) {
|
||||
p->Send_uint8(owner);
|
||||
}
|
||||
|
||||
this->SendPacket(p);
|
||||
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
@@ -390,10 +383,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
|
||||
{
|
||||
for (const Company *company : Company::Iterate()) {
|
||||
/* Get the income. */
|
||||
Money income = 0;
|
||||
for (uint i = 0; i < lengthof(company->yearly_expenses[0]); i++) {
|
||||
income -= company->yearly_expenses[0][i];
|
||||
}
|
||||
Money income = -std::reduce(std::begin(company->yearly_expenses[0]), std::end(company->yearly_expenses[0]));
|
||||
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_COMPANY_ECONOMY);
|
||||
|
||||
@@ -403,13 +393,13 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
|
||||
p->Send_uint64(company->money);
|
||||
p->Send_uint64(company->current_loan);
|
||||
p->Send_uint64(income);
|
||||
p->Send_uint16(static_cast<uint16>(std::min<uint64>(UINT16_MAX, company->cur_economy.delivered_cargo.GetSum<OverflowSafeInt64>())));
|
||||
p->Send_uint16(static_cast<uint16_t>(std::min<uint64_t>(UINT16_MAX, company->cur_economy.delivered_cargo.GetSum<OverflowSafeInt64>())));
|
||||
|
||||
/* Send stats for the last 2 quarters. */
|
||||
for (uint i = 0; i < 2; i++) {
|
||||
p->Send_uint64(company->old_economy[i].company_value);
|
||||
p->Send_uint16(company->old_economy[i].performance_history);
|
||||
p->Send_uint16(static_cast<uint16>(std::min<uint64>(UINT16_MAX, company->old_economy[i].delivered_cargo.GetSum<OverflowSafeInt64>())));
|
||||
p->Send_uint16(static_cast<uint16_t>(std::min<uint64_t>(UINT16_MAX, company->old_economy[i].delivered_cargo.GetSum<OverflowSafeInt64>())));
|
||||
}
|
||||
|
||||
this->SendPacket(p);
|
||||
@@ -455,7 +445,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
|
||||
* @param msg The actual message.
|
||||
* @param data Arbitrary extra data.
|
||||
*/
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64 data)
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64_t data)
|
||||
{
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_CHAT);
|
||||
|
||||
@@ -488,7 +478,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRconEnd(const std::string
|
||||
* @param colour The colour of the text.
|
||||
* @param result The result of the command.
|
||||
*/
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRcon(uint16 colour, const std::string_view result)
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendRcon(uint16_t colour, const std::string_view result)
|
||||
{
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_RCON);
|
||||
|
||||
@@ -508,7 +498,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet *p)
|
||||
Debug(net, 3, "[admin] Rcon command from '{}' ({}): {}", this->admin_name, this->admin_version, command);
|
||||
|
||||
_redirect_console_to_admin = this->index;
|
||||
IConsoleCmdExec(command.c_str());
|
||||
IConsoleCmdExec(command);
|
||||
_redirect_console_to_admin = INVALID_ADMIN_ID;
|
||||
return this->SendRconEnd(command);
|
||||
}
|
||||
@@ -529,7 +519,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_PING(Packet *p)
|
||||
{
|
||||
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||
|
||||
uint32 d1 = p->Recv_uint32();
|
||||
uint32_t d1 = p->Recv_uint32();
|
||||
|
||||
Debug(net, 6, "[admin] Ping from '{}' ({}): {}", this->admin_name, this->admin_version, d1);
|
||||
|
||||
@@ -564,11 +554,6 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendConsole(const std::string
|
||||
*/
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const std::string_view json)
|
||||
{
|
||||
/* At the moment we cannot transmit anything larger than MTU. So we limit
|
||||
* the maximum amount of json data that can be sent. Account also for
|
||||
* the trailing \0 of the string */
|
||||
if (json.size() + 1 >= NETWORK_GAMESCRIPT_JSON_LENGTH) return NETWORK_RECV_STATUS_OKAY;
|
||||
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_GAMESCRIPT);
|
||||
|
||||
p->Send_string(json);
|
||||
@@ -578,7 +563,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendGameScript(const std::str
|
||||
}
|
||||
|
||||
/** Send ping-reply (pong) to admin **/
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendPong(uint32 d1)
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendPong(uint32_t d1)
|
||||
{
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_PONG);
|
||||
|
||||
@@ -593,11 +578,11 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCmdNames()
|
||||
{
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_CMD_NAMES);
|
||||
|
||||
for (uint16 i = 0; i < CMD_END; i++) {
|
||||
for (uint16_t i = 0; i < CMD_END; i++) {
|
||||
const char *cmdname = GetCommandName(static_cast<Commands>(i));
|
||||
|
||||
/* Should COMPAT_MTU be exceeded, start a new packet
|
||||
* (magic 5: 1 bool "more data" and one uint16 "command id", one
|
||||
* (magic 5: 1 bool "more data" and one uint16_t "command id", one
|
||||
* byte for string '\0' termination and 1 bool "no more data" */
|
||||
if (!p->CanWriteToPacket(strlen(cmdname) + 5)) {
|
||||
p->Send_bool(false);
|
||||
@@ -669,7 +654,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_JOIN(Packet *p)
|
||||
return this->SendProtocol();
|
||||
}
|
||||
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_QUIT(Packet *p)
|
||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_QUIT(Packet *)
|
||||
{
|
||||
/* The admin is leaving nothing else to do */
|
||||
return this->CloseConnection();
|
||||
@@ -700,7 +685,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_POLL(Packet *p)
|
||||
if (this->status == ADMIN_STATUS_INACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||
|
||||
AdminUpdateType type = (AdminUpdateType)p->Recv_uint8();
|
||||
uint32 d1 = p->Recv_uint32();
|
||||
uint32_t d1 = p->Recv_uint32();
|
||||
|
||||
switch (type) {
|
||||
case ADMIN_UPDATE_DATE:
|
||||
@@ -797,7 +782,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_EXTERNAL_CHAT(P
|
||||
std::string msg = p->Recv_string(NETWORK_CHAT_LENGTH);
|
||||
|
||||
if (!IsValidConsoleColour(colour)) {
|
||||
Debug(net, 1, "[admin] Not supported chat colour {} ({}, {}, {}) from '{}' ({}).", (uint16)colour, source, user, msg, this->admin_name, this->admin_version);
|
||||
Debug(net, 1, "[admin] Not supported chat colour {} ({}, {}, {}) from '{}' ({}).", (uint16_t)colour, source, user, msg, this->admin_name, this->admin_version);
|
||||
return this->SendError(NETWORK_ERROR_ILLEGAL_PACKET);
|
||||
}
|
||||
|
||||
@@ -920,7 +905,7 @@ void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bc
|
||||
/**
|
||||
* Send chat to the admin network (if they did opt in for the respective update).
|
||||
*/
|
||||
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64 data, bool from_admin)
|
||||
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const std::string &msg, int64_t data, bool from_admin)
|
||||
{
|
||||
if (from_admin) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user