Codechange: rename byte to uint8_t (#12308)
This commit is contained in:
@@ -45,10 +45,10 @@ static const std::string NETWORK_SURVEY_DETAILS_LINK = "https://survey.openttd.o
|
||||
static const size_t TCP_MTU = 32767; ///< Number of bytes we can pack in a single TCP packet
|
||||
static const size_t COMPAT_MTU = 1460; ///< Number of bytes we can pack in a single packet for backward compatibility
|
||||
|
||||
static const byte NETWORK_GAME_ADMIN_VERSION = 3; ///< What version of the admin network do we use?
|
||||
static const byte NETWORK_GAME_INFO_VERSION = 7; ///< What version of game-info do we use?
|
||||
static const byte NETWORK_COORDINATOR_VERSION = 6; ///< What version of game-coordinator-protocol do we use?
|
||||
static const byte NETWORK_SURVEY_VERSION = 2; ///< What version of the survey do we use?
|
||||
static const uint8_t NETWORK_GAME_ADMIN_VERSION = 3; ///< What version of the admin network do we use?
|
||||
static const uint8_t NETWORK_GAME_INFO_VERSION = 7; ///< What version of game-info do we use?
|
||||
static const uint8_t NETWORK_COORDINATOR_VERSION = 6; ///< What version of game-coordinator-protocol do we use?
|
||||
static const uint8_t NETWORK_SURVEY_VERSION = 2; ///< What version of the survey do we use?
|
||||
|
||||
static const uint NETWORK_NAME_LENGTH = 80; ///< The maximum length of the server name and map name, in bytes including '\0'
|
||||
static const uint NETWORK_COMPANY_NAME_LENGTH = 128; ///< The maximum length of the company name, in bytes including '\0'
|
||||
|
||||
@@ -148,7 +148,7 @@ const NetworkServerGameInfo &GetCurrentNetworkServerGameInfo()
|
||||
* - invite_code
|
||||
* These don't need to be updated manually here.
|
||||
*/
|
||||
_network_game_info.companies_on = (byte)Company::GetNumItems();
|
||||
_network_game_info.companies_on = (uint8_t)Company::GetNumItems();
|
||||
_network_game_info.spectators_on = NetworkSpectatorCount();
|
||||
_network_game_info.calendar_date = TimerGameCalendar::date;
|
||||
_network_game_info.ticks_playing = TimerGameTick::counter;
|
||||
@@ -260,7 +260,7 @@ void SerializeNetworkGameInfo(Packet &p, const NetworkServerGameInfo &info, bool
|
||||
*/
|
||||
void DeserializeNetworkGameInfo(Packet &p, NetworkGameInfo &info, const GameInfoNewGRFLookupTable *newgrf_lookup_table)
|
||||
{
|
||||
byte game_info_version = p.Recv_uint8();
|
||||
uint8_t game_info_version = p.Recv_uint8();
|
||||
NewGRFSerializationType newgrf_serialisation = NST_GRFID_MD5;
|
||||
|
||||
/*
|
||||
|
||||
@@ -104,12 +104,12 @@ struct NetworkServerGameInfo {
|
||||
std::string server_revision; ///< The version number the server is using (e.g.: 'r304' or 0.5.0)
|
||||
bool dedicated; ///< Is this a dedicated server?
|
||||
bool use_password; ///< Is this server passworded?
|
||||
byte clients_on; ///< Current count of clients on server
|
||||
byte clients_max; ///< Max clients allowed on server
|
||||
byte companies_on; ///< How many started companies do we have
|
||||
byte companies_max; ///< Max companies allowed on server
|
||||
byte spectators_on; ///< How many spectators do we have?
|
||||
byte landscape; ///< The used landscape
|
||||
uint8_t clients_on; ///< Current count of clients on server
|
||||
uint8_t clients_max; ///< Max clients allowed on server
|
||||
uint8_t companies_on; ///< How many started companies do we have
|
||||
uint8_t companies_max; ///< Max companies allowed on server
|
||||
uint8_t spectators_on; ///< How many spectators do we have?
|
||||
uint8_t landscape; ///< The used landscape
|
||||
int gamescript_version; ///< Version of the gamescript.
|
||||
std::string gamescript_name; ///< Name of the gamescript.
|
||||
};
|
||||
|
||||
@@ -166,7 +166,7 @@ void Packet::Send_string(const std::string_view data)
|
||||
* Copy a sized byte buffer into the packet.
|
||||
* @param data The data to send.
|
||||
*/
|
||||
void Packet::Send_buffer(const std::vector<byte> &data)
|
||||
void Packet::Send_buffer(const std::vector<uint8_t> &data)
|
||||
{
|
||||
assert(this->CanWriteToPacket(sizeof(uint16_t) + data.size()));
|
||||
this->Send_uint16((uint16_t)data.size());
|
||||
@@ -180,7 +180,7 @@ void Packet::Send_buffer(const std::vector<byte> &data)
|
||||
* @param span The span describing the range of bytes to send.
|
||||
* @return The span of bytes that were not written.
|
||||
*/
|
||||
std::span<const byte> Packet::Send_bytes(const std::span<const byte> span)
|
||||
std::span<const uint8_t> Packet::Send_bytes(const std::span<const uint8_t> span)
|
||||
{
|
||||
size_t amount = std::min<size_t>(span.size(), this->limit - this->Size());
|
||||
this->buffer.insert(this->buffer.end(), span.data(), span.data() + amount);
|
||||
@@ -356,12 +356,12 @@ uint64_t Packet::Recv_uint64()
|
||||
* Extract a sized byte buffer from the packet.
|
||||
* @return The extracted buffer.
|
||||
*/
|
||||
std::vector<byte> Packet::Recv_buffer()
|
||||
std::vector<uint8_t> Packet::Recv_buffer()
|
||||
{
|
||||
uint16_t size = this->Recv_uint16();
|
||||
if (size == 0 || !this->CanReadFromPacket(size, true)) return {};
|
||||
|
||||
std::vector<byte> data;
|
||||
std::vector<uint8_t> data;
|
||||
while (size-- > 0) {
|
||||
data.push_back(this->buffer[this->pos++]);
|
||||
}
|
||||
@@ -374,9 +374,9 @@ std::vector<byte> Packet::Recv_buffer()
|
||||
* @param span The span to write the bytes to.
|
||||
* @return The number of bytes that were actually read.
|
||||
*/
|
||||
size_t Packet::Recv_bytes(std::span<byte> span)
|
||||
size_t Packet::Recv_bytes(std::span<uint8_t> span)
|
||||
{
|
||||
auto tranfer_to_span = [](std::span<byte> destination, const char *source, size_t amount) {
|
||||
auto tranfer_to_span = [](std::span<uint8_t> destination, const char *source, size_t amount) {
|
||||
size_t to_copy = std::min(amount, destination.size());
|
||||
std::copy(source, source + to_copy, destination.data());
|
||||
return to_copy;
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
/** The current read/write position in the packet */
|
||||
PacketSize pos;
|
||||
/** The buffer of this packet. */
|
||||
std::vector<byte> buffer;
|
||||
std::vector<uint8_t> buffer;
|
||||
/** The limit for the packet size. */
|
||||
size_t limit;
|
||||
|
||||
@@ -65,8 +65,8 @@ public:
|
||||
void Send_uint32(uint32_t data);
|
||||
void Send_uint64(uint64_t data);
|
||||
void Send_string(const std::string_view data);
|
||||
void Send_buffer(const std::vector<byte> &data);
|
||||
std::span<const byte> Send_bytes(const std::span<const byte> span);
|
||||
void Send_buffer(const std::vector<uint8_t> &data);
|
||||
std::span<const uint8_t> Send_bytes(const std::span<const uint8_t> span);
|
||||
|
||||
/* Reading/receiving of packets */
|
||||
bool HasPacketSizeData() const;
|
||||
@@ -81,8 +81,8 @@ public:
|
||||
uint16_t Recv_uint16();
|
||||
uint32_t Recv_uint32();
|
||||
uint64_t Recv_uint64();
|
||||
std::vector<byte> Recv_buffer();
|
||||
size_t Recv_bytes(std::span<byte> span);
|
||||
std::vector<uint8_t> Recv_buffer();
|
||||
size_t Recv_bytes(std::span<uint8_t> span);
|
||||
std::string Recv_string(size_t length, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
|
||||
|
||||
size_t RemainingBytesToTransfer() const;
|
||||
|
||||
@@ -25,7 +25,7 @@ protected:
|
||||
|
||||
/**
|
||||
* Client requesting a list of content info:
|
||||
* byte type
|
||||
* uint8_t type
|
||||
* uint32_t openttd version (or 0xFFFFFFFF if using a list)
|
||||
* Only if the above value is 0xFFFFFFFF:
|
||||
* uint8_t count
|
||||
@@ -76,7 +76,7 @@ protected:
|
||||
|
||||
/**
|
||||
* Server sending list of content info:
|
||||
* byte type (invalid ID == does not exist)
|
||||
* uint8_t type (invalid ID == does not exist)
|
||||
* uint32_t id
|
||||
* uint32_t file_size
|
||||
* string name (max 32 characters)
|
||||
|
||||
@@ -277,7 +277,7 @@ protected:
|
||||
* uint16_t Number of NewGRFs in the packet, with for each of the NewGRFs:
|
||||
* uint32_t Lookup table index for the NewGRF.
|
||||
* uint32_t Unique NewGRF ID.
|
||||
* byte[16] MD5 checksum of the NewGRF
|
||||
* uint8_t[16] MD5 checksum of the NewGRF
|
||||
* string Name of the NewGRF.
|
||||
*
|
||||
* The lookup table built using these packets are used by the deserialisation
|
||||
|
||||
@@ -84,7 +84,7 @@ CompanyMask _network_company_passworded; ///< Bitmask of the password status of
|
||||
static_assert((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH);
|
||||
|
||||
/** The amount of clients connected */
|
||||
byte _network_clients_connected = 0;
|
||||
uint8_t _network_clients_connected = 0;
|
||||
|
||||
extern std::string GenerateUid(std::string_view subject);
|
||||
|
||||
@@ -134,9 +134,9 @@ NetworkClientInfo::~NetworkClientInfo()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
byte NetworkSpectatorCount()
|
||||
uint8_t NetworkSpectatorCount()
|
||||
{
|
||||
byte count = 0;
|
||||
uint8_t count = 0;
|
||||
|
||||
for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
|
||||
if (ci->client_playas == COMPANY_SPECTATOR) count++;
|
||||
@@ -1130,10 +1130,10 @@ void NetworkGameLoop()
|
||||
cp->cmd = (Commands)cmd;
|
||||
|
||||
/* Parse command data. */
|
||||
std::vector<byte> args;
|
||||
std::vector<uint8_t> args;
|
||||
size_t arg_len = strlen(buffer);
|
||||
for (size_t i = 0; i + 1 < arg_len; i += 2) {
|
||||
byte e = 0;
|
||||
uint8_t e = 0;
|
||||
std::from_chars(buffer + i, buffer + i + 2, e, 16);
|
||||
args.emplace_back(e);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
AdminIndex _redirect_console_to_admin = INVALID_ADMIN_ID;
|
||||
|
||||
/** The amount of admins connected. */
|
||||
byte _network_admins_connected = 0;
|
||||
uint8_t _network_admins_connected = 0;
|
||||
|
||||
/** The pool with sockets/clients. */
|
||||
NetworkAdminSocketPool _networkadminsocket_pool("NetworkAdminSocket");
|
||||
|
||||
@@ -43,10 +43,10 @@
|
||||
struct PacketReader : LoadFilter {
|
||||
static const size_t CHUNK = 32 * 1024; ///< 32 KiB chunks of memory.
|
||||
|
||||
std::vector<byte *> blocks; ///< Buffer with blocks of allocated memory.
|
||||
byte *buf; ///< Buffer we're going to write to/read from.
|
||||
byte *bufe; ///< End of the buffer we write to/read from.
|
||||
byte **block; ///< The block we're reading from/writing to.
|
||||
std::vector<uint8_t *> blocks; ///< Buffer with blocks of allocated memory.
|
||||
uint8_t *buf; ///< Buffer we're going to write to/read from.
|
||||
uint8_t *bufe; ///< End of the buffer we write to/read from.
|
||||
uint8_t **block; ///< The block we're reading from/writing to.
|
||||
size_t written_bytes; ///< The total number of bytes we've written.
|
||||
size_t read_bytes; ///< The total number of read bytes.
|
||||
|
||||
@@ -90,18 +90,18 @@ struct PacketReader : LoadFilter {
|
||||
if (p.RemainingBytesToTransfer() == 0) return;
|
||||
|
||||
/* Allocate a new chunk and add the remaining data. */
|
||||
this->blocks.push_back(this->buf = CallocT<byte>(CHUNK));
|
||||
this->blocks.push_back(this->buf = CallocT<uint8_t>(CHUNK));
|
||||
this->bufe = this->buf + CHUNK;
|
||||
|
||||
p.TransferOutWithLimit(TransferOutMemCopy, this->bufe - this->buf, this);
|
||||
}
|
||||
|
||||
size_t Read(byte *rbuf, size_t size) override
|
||||
size_t Read(uint8_t *rbuf, size_t size) override
|
||||
{
|
||||
/* Limit the amount to read to whatever we still have. */
|
||||
size_t ret_size = size = std::min(this->written_bytes - this->read_bytes, size);
|
||||
this->read_bytes += ret_size;
|
||||
const byte *rbufe = rbuf + ret_size;
|
||||
const uint8_t *rbufe = rbuf + ret_size;
|
||||
|
||||
while (rbuf != rbufe) {
|
||||
if (this->buf == this->bufe) {
|
||||
|
||||
@@ -17,7 +17,7 @@ class ClientNetworkGameSocketHandler : public ZeroedMemoryAllocator, public Netw
|
||||
private:
|
||||
std::string connection_string; ///< Address we are connected to.
|
||||
std::shared_ptr<struct PacketReader> savegame; ///< Packet reader for reading the savegame.
|
||||
byte token; ///< The token we need to send back to the server to prove we're the right client.
|
||||
uint8_t token; ///< The token we need to send back to the server to prove we're the right client.
|
||||
|
||||
/** Status of the connection with the server. */
|
||||
enum ServerStatus {
|
||||
|
||||
@@ -369,7 +369,7 @@ const char *NetworkGameSocketHandler::ReceiveCommand(Packet &p, CommandPacket &c
|
||||
cp.err_msg = p.Recv_uint16();
|
||||
cp.data = _cmd_dispatch[cp.cmd].Sanitize(p.Recv_buffer());
|
||||
|
||||
byte callback = p.Recv_uint8();
|
||||
uint8_t callback = p.Recv_uint8();
|
||||
if (callback >= _callback_table.size() || _cmd_dispatch[cp.cmd].Unpack[callback] == nullptr) return "invalid callback";
|
||||
|
||||
cp.callback = _callback_table[callback];
|
||||
|
||||
@@ -205,7 +205,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentType type)
|
||||
this->Connect();
|
||||
|
||||
auto p = std::make_unique<Packet>(this, PACKET_CONTENT_CLIENT_INFO_LIST);
|
||||
p->Send_uint8 ((byte)type);
|
||||
p->Send_uint8 ((uint8_t)type);
|
||||
p->Send_uint32(0xffffffff);
|
||||
p->Send_uint8 (1);
|
||||
p->Send_string("vanilla");
|
||||
@@ -238,7 +238,7 @@ void ClientNetworkContentSocketHandler::RequestContentList(uint count, const Con
|
||||
* A packet begins with the packet size and a byte for the type.
|
||||
* Then this packet adds a uint16_t for the count in this packet.
|
||||
* The rest of the packet can be used for the IDs. */
|
||||
uint p_count = std::min<uint>(count, (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16_t)) / sizeof(uint32_t));
|
||||
uint p_count = std::min<uint>(count, (TCP_MTU - sizeof(PacketSize) - sizeof(uint8_t) - sizeof(uint16_t)) / sizeof(uint32_t));
|
||||
|
||||
auto p = std::make_unique<Packet>(this, PACKET_CONTENT_CLIENT_INFO_ID, TCP_MTU);
|
||||
p->Send_uint16(p_count);
|
||||
@@ -265,14 +265,14 @@ void ClientNetworkContentSocketHandler::RequestContentList(ContentVector *cv, bo
|
||||
this->Connect();
|
||||
|
||||
assert(cv->size() < 255);
|
||||
assert(cv->size() < (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint8_t)) /
|
||||
assert(cv->size() < (TCP_MTU - sizeof(PacketSize) - sizeof(uint8_t) - sizeof(uint8_t)) /
|
||||
(sizeof(uint8_t) + sizeof(uint32_t) + (send_md5sum ? MD5_HASH_BYTES : 0)));
|
||||
|
||||
auto p = std::make_unique<Packet>(this, send_md5sum ? PACKET_CONTENT_CLIENT_INFO_EXTID_MD5 : PACKET_CONTENT_CLIENT_INFO_EXTID, TCP_MTU);
|
||||
p->Send_uint8((uint8_t)cv->size());
|
||||
|
||||
for (const ContentInfo *ci : *cv) {
|
||||
p->Send_uint8((byte)ci->type);
|
||||
p->Send_uint8((uint8_t)ci->type);
|
||||
p->Send_uint32(ci->unique_id);
|
||||
if (!send_md5sum) continue;
|
||||
|
||||
@@ -363,7 +363,7 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const Co
|
||||
* A packet begins with the packet size and a byte for the type.
|
||||
* Then this packet adds a uint16_t for the count in this packet.
|
||||
* The rest of the packet can be used for the IDs. */
|
||||
uint p_count = std::min<uint>(count, (TCP_MTU - sizeof(PacketSize) - sizeof(byte) - sizeof(uint16_t)) / sizeof(uint32_t));
|
||||
uint p_count = std::min<uint>(count, (TCP_MTU - sizeof(PacketSize) - sizeof(uint8_t) - sizeof(uint16_t)) / sizeof(uint32_t));
|
||||
|
||||
auto p = std::make_unique<Packet>(this, PACKET_CONTENT_CLIENT_CONTENT, TCP_MTU);
|
||||
p->Send_uint16(p_count);
|
||||
@@ -420,7 +420,7 @@ static bool GunzipFile(const ContentInfo *ci)
|
||||
if (fin == nullptr || fout == nullptr) {
|
||||
ret = false;
|
||||
} else {
|
||||
byte buff[8192];
|
||||
uint8_t buff[8192];
|
||||
for (;;) {
|
||||
int read = gzread(fin, buff, sizeof(buff));
|
||||
if (read == 0) {
|
||||
|
||||
@@ -33,7 +33,7 @@ extern StringList _network_bind_list;
|
||||
extern StringList _network_host_list;
|
||||
extern StringList _network_ban_list;
|
||||
|
||||
byte NetworkSpectatorCount();
|
||||
uint8_t NetworkSpectatorCount();
|
||||
bool NetworkIsValidClientName(const std::string_view client_name);
|
||||
bool NetworkValidateOurClientName();
|
||||
bool NetworkValidateClientName(std::string &client_name);
|
||||
|
||||
@@ -136,7 +136,7 @@ struct PacketWriter : SaveFilter {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Write(byte *buf, size_t size) override
|
||||
void Write(uint8_t *buf, size_t size) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
|
||||
@@ -145,7 +145,7 @@ struct PacketWriter : SaveFilter {
|
||||
|
||||
if (this->current == nullptr) this->current = std::make_unique<Packet>(this->cs, PACKET_SERVER_MAP_DATA, TCP_MTU);
|
||||
|
||||
std::span<const byte> to_write(buf, size);
|
||||
std::span<const uint8_t> to_write(buf, size);
|
||||
while (!to_write.empty()) {
|
||||
to_write = this->current->Send_bytes(to_write);
|
||||
|
||||
@@ -267,7 +267,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta
|
||||
|
||||
/* We just lost one client :( */
|
||||
if (this->status >= STATUS_AUTHORIZED) _network_game_info.clients_on--;
|
||||
extern byte _network_clients_connected;
|
||||
extern uint8_t _network_clients_connected;
|
||||
_network_clients_connected--;
|
||||
|
||||
this->SendPackets(true);
|
||||
@@ -285,7 +285,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta
|
||||
*/
|
||||
/* static */ bool ServerNetworkGameSocketHandler::AllowConnection()
|
||||
{
|
||||
extern byte _network_clients_connected;
|
||||
extern uint8_t _network_clients_connected;
|
||||
bool accept = _network_clients_connected < MAX_CLIENTS;
|
||||
|
||||
/* We can't go over the MAX_CLIENTS limit here. However, the
|
||||
@@ -1520,7 +1520,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
|
||||
/* Go through all vehicles and count the type of vehicles */
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
|
||||
byte type = 0;
|
||||
uint8_t type = 0;
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN: type = NETWORK_VEH_TRAIN; break;
|
||||
case VEH_ROAD: type = RoadVehicle::From(v)->IsBus() ? NETWORK_VEH_BUS : NETWORK_VEH_LORRY; break;
|
||||
|
||||
@@ -64,8 +64,8 @@ public:
|
||||
STATUS_END, ///< Must ALWAYS be on the end of this list!! (period).
|
||||
};
|
||||
|
||||
byte lag_test; ///< Byte used for lag-testing the client
|
||||
byte last_token; ///< The last random token we did send to verify the client is listening
|
||||
uint8_t lag_test; ///< Byte used for lag-testing the client
|
||||
uint8_t last_token; ///< The last random token we did send to verify the client is listening
|
||||
uint32_t last_token_frame; ///< The last frame we received the right token
|
||||
ClientStatus status; ///< Status of this client
|
||||
CommandQueue outgoing_queue; ///< The command-queue awaiting delivery; conceptually more a bucket to gather commands in, after which the whole bucket is sent to the client.
|
||||
|
||||
@@ -88,7 +88,7 @@ enum NetworkPasswordType {
|
||||
* Destination of our chat messages.
|
||||
* @warning The values of the enum items are part of the admin network API. Only append at the end.
|
||||
*/
|
||||
enum DestType : byte {
|
||||
enum DestType : uint8_t {
|
||||
DESTTYPE_BROADCAST, ///< Send message/notice to all clients (All)
|
||||
DESTTYPE_TEAM, ///< Send message/notice to everyone playing the same company (Team)
|
||||
DESTTYPE_CLIENT, ///< Send message/notice to only a certain client (Private)
|
||||
|
||||
Reference in New Issue
Block a user