Import combined Enhanced viewport: zoom out, overlays & tooltips (r53_27127) patch

https://www.tt-forums.net/viewtopic.php?f=33&t=53394
This commit is contained in:
patch-import
2015-08-02 19:37:42 +01:00
committed by Jonathan G Rennison
parent fd3388467f
commit 536a95dfd0
105 changed files with 3509 additions and 325 deletions

View File

@@ -15,6 +15,7 @@
#include "../../stdafx.h"
#include "../../string_func.h"
#include "../../command_type.h"
#include "packet.h"
@@ -32,7 +33,7 @@ Packet::Packet(NetworkSocketHandler *cs)
this->next = NULL;
this->pos = 0; // We start reading from here
this->size = 0;
this->buffer = MallocT<byte>(SEND_MTU);
this->buffer = MallocT<byte>(SHRT_MAX);
}
/**
@@ -47,7 +48,7 @@ Packet::Packet(PacketType type)
/* Skip the size so we can write that in before sending the packet */
this->pos = 0;
this->size = sizeof(PacketSize);
this->buffer = MallocT<byte>(SEND_MTU);
this->buffer = MallocT<byte>(SHRT_MAX);
this->buffer[this->size++] = type;
}
@@ -99,7 +100,7 @@ void Packet::Send_bool(bool data)
*/
void Packet::Send_uint8(uint8 data)
{
assert(this->size < SEND_MTU - sizeof(data));
assert(this->size < SHRT_MAX - sizeof(data));
this->buffer[this->size++] = data;
}
@@ -109,7 +110,7 @@ void Packet::Send_uint8(uint8 data)
*/
void Packet::Send_uint16(uint16 data)
{
assert(this->size < SEND_MTU - sizeof(data));
assert(this->size < SHRT_MAX - sizeof(data));
this->buffer[this->size++] = GB(data, 0, 8);
this->buffer[this->size++] = GB(data, 8, 8);
}
@@ -120,7 +121,7 @@ void Packet::Send_uint16(uint16 data)
*/
void Packet::Send_uint32(uint32 data)
{
assert(this->size < SEND_MTU - sizeof(data));
assert(this->size < SHRT_MAX - sizeof(data));
this->buffer[this->size++] = GB(data, 0, 8);
this->buffer[this->size++] = GB(data, 8, 8);
this->buffer[this->size++] = GB(data, 16, 8);
@@ -133,7 +134,7 @@ void Packet::Send_uint32(uint32 data)
*/
void Packet::Send_uint64(uint64 data)
{
assert(this->size < SEND_MTU - sizeof(data));
assert(this->size < SHRT_MAX - sizeof(data));
this->buffer[this->size++] = GB(data, 0, 8);
this->buffer[this->size++] = GB(data, 8, 8);
this->buffer[this->size++] = GB(data, 16, 8);
@@ -153,10 +154,22 @@ void Packet::Send_string(const char *data)
{
assert(data != NULL);
/* The <= *is* valid due to the fact that we are comparing sizes and not the index. */
assert(this->size + strlen(data) + 1 <= SEND_MTU);
assert(this->size + strlen(data) + 1 <= SHRT_MAX);
while ((this->buffer[this->size++] = *data++) != '\0') {}
}
/**
* Sends a binary data over the network.
* @param data The data to send
*/
void Packet::Send_binary(const char *data, const size_t size)
{
assert(data != NULL);
assert(size < MAX_CMD_TEXT_LENGTH);
memcpy(&this->buffer[this->size], data, size);
this->size += (PacketSize) size;
}
/*
* Receiving commands
@@ -311,4 +324,18 @@ void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings set
str_validate(bufp, last, settings);
}
/**
* Reads binary data.
* @param buffer The buffer to put the data into.
* @param size The size of the buffer.
*/
void Packet::Recv_binary(char *buffer, size_t size)
{
/* Don't allow reading from a closed socket */
if (cs->HasClientQuit()) return;
memcpy(buffer, &this->buffer[this->pos], size);
this->pos += (PacketSize) size;
}
#endif /* ENABLE_NETWORK */

View File

@@ -52,7 +52,7 @@ struct Packet {
PacketSize size;
/** The current read/write position in the packet */
PacketSize pos;
/** The buffer of this packet, of basically variable length up to SEND_MTU. */
/** The buffer of this packet, of basically variable length up to SHRT_MAX. */
byte *buffer;
private:
@@ -73,6 +73,7 @@ public:
void Send_uint32(uint32 data);
void Send_uint64(uint64 data);
void Send_string(const char *data);
void Send_binary(const char *data, const size_t size);
/* Reading/receiving of packets */
void ReadRawPacketSize();
@@ -85,6 +86,7 @@ public:
uint32 Recv_uint32();
uint64 Recv_uint64();
void Recv_string(char *buffer, size_t size, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
void Recv_binary(char *buffer, size_t size);
};
#endif /* ENABLE_NETWORK */

View File

@@ -862,7 +862,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
* the server will give us a client-id and let us in */
_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
ShowJoinStatusWindow();
NetworkSendCommand(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
NetworkSendCommand(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company, 0);
}
} else {
/* take control over an existing company */

View File

@@ -51,6 +51,7 @@ static CommandCallback * const _callback_table[] = {
/* 0x19 */ CcStartStopVehicle,
/* 0x1A */ CcGame,
/* 0x1B */ CcAddVehicleNewGroup,
/* 0x1C */ CcAddPlan,
};
/**
@@ -136,8 +137,9 @@ static CommandQueue _local_execution_queue;
* @param callback A callback function to call after the command is finished
* @param text The text to pass
* @param company The company that wants to send the command
* @param binary_length The quantity of binary data in text
*/
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company, uint32 binary_length)
{
assert((cmd & CMD_FLAGS_MASK) == 0);
@@ -149,7 +151,12 @@ void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, Comman
c.cmd = cmd;
c.callback = callback;
strecpy(c.text, (text != NULL) ? text : "", lastof(c.text));
c.binary_length = binary_length;
if (binary_length == 0) {
strecpy(c.text, (text != NULL) ? text : "", lastof(c.text));
} else {
memcpy(c.text, text, binary_length);
}
if (_network_server) {
/* If we are the server, we queue the command in our 'special' queue.
@@ -310,7 +317,13 @@ const char *NetworkGameSocketHandler::ReceiveCommand(Packet *p, CommandPacket *c
cp->p1 = p->Recv_uint32();
cp->p2 = p->Recv_uint32();
cp->tile = p->Recv_uint32();
p->Recv_string(cp->text, lengthof(cp->text), (!_network_server && GetCommandFlags(cp->cmd) & CMD_STR_CTRL) != 0 ? SVS_ALLOW_CONTROL_CODE | SVS_REPLACE_WITH_QUESTION_MARK : SVS_REPLACE_WITH_QUESTION_MARK);
cp->binary_length = p->Recv_uint32();
if (cp->binary_length == 0) {
p->Recv_string(cp->text, lengthof(cp->text), (!_network_server && GetCommandFlags(cp->cmd) & CMD_STR_CTRL) != 0 ? SVS_ALLOW_CONTROL_CODE | SVS_REPLACE_WITH_QUESTION_MARK : SVS_REPLACE_WITH_QUESTION_MARK);
} else {
if ((p->pos + (PacketSize) cp->binary_length + /* callback index */ 1) > p->size) return "invalid binary data length";
p->Recv_binary(cp->text, cp->binary_length);
}
byte callback = p->Recv_uint8();
if (callback >= lengthof(_callback_table)) return "invalid callback";
@@ -331,7 +344,12 @@ void NetworkGameSocketHandler::SendCommand(Packet *p, const CommandPacket *cp)
p->Send_uint32(cp->p1);
p->Send_uint32(cp->p2);
p->Send_uint32(cp->tile);
p->Send_string(cp->text);
p->Send_uint32(cp->binary_length);
if (cp->binary_length == 0) {
p->Send_string(cp->text);
} else {
p->Send_binary(cp->text, cp->binary_length);
}
byte callback = 0;
while (callback < lengthof(_callback_table) && _callback_table[callback] != cp->callback) {

View File

@@ -2192,7 +2192,7 @@ void NetworkServerNewCompany(const Company *c, NetworkClientInfo *ci)
/* ci is NULL when replaying, or for AIs. In neither case there is a client. */
ci->client_playas = c->index;
NetworkUpdateClientInfo(ci->client_id);
NetworkSendCommand(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name, c->index);
NetworkSendCommand(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name, c->index, 0);
}
/* Announce new company on network. */