summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/core/tcp_content.cpp46
-rw-r--r--src/network/core/tcp_content.h33
-rw-r--r--src/network/network_content.cpp4
-rw-r--r--src/network/network_content.h4
4 files changed, 49 insertions, 38 deletions
diff --git a/src/network/core/tcp_content.cpp b/src/network/core/tcp_content.cpp
index 94e004be3..2b7f609a2 100644
--- a/src/network/core/tcp_content.cpp
+++ b/src/network/core/tcp_content.cpp
@@ -112,13 +112,13 @@ bool NetworkContentSocketHandler::HandlePacket(Packet *p)
PacketContentType type = (PacketContentType)p->Recv_uint8();
switch (this->HasClientQuit() ? PACKET_CONTENT_END : type) {
- CONTENT_COMMAND(PACKET_CONTENT_CLIENT_INFO_LIST);
- CONTENT_COMMAND(PACKET_CONTENT_CLIENT_INFO_ID);
- CONTENT_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID);
- CONTENT_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5);
- CONTENT_COMMAND(PACKET_CONTENT_SERVER_INFO);
- CONTENT_COMMAND(PACKET_CONTENT_CLIENT_CONTENT);
- CONTENT_COMMAND(PACKET_CONTENT_SERVER_CONTENT);
+ case PACKET_CONTENT_CLIENT_INFO_LIST: return this->Receive_CLIENT_INFO_LIST(p);
+ case PACKET_CONTENT_CLIENT_INFO_ID: return this->Receive_CLIENT_INFO_ID(p);
+ case PACKET_CONTENT_CLIENT_INFO_EXTID: return this->Receive_CLIENT_INFO_EXTID(p);
+ case PACKET_CONTENT_CLIENT_INFO_EXTID_MD5: return this->Receive_CLIENT_INFO_EXTID_MD5(p);
+ case PACKET_CONTENT_SERVER_INFO: return this->Receive_SERVER_INFO(p);
+ case PACKET_CONTENT_CLIENT_CONTENT: return this->Receive_CLIENT_CONTENT(p);
+ case PACKET_CONTENT_SERVER_CONTENT: return this->Receive_SERVER_CONTENT(p);
default:
if (this->HasClientQuit()) {
@@ -143,26 +143,24 @@ void NetworkContentSocketHandler::ReceivePackets()
}
}
+
/**
- * Create stub implementations for all receive commands that only
- * show a warning that the given command is not available for the
- * socket where the packet came from.
- * @param type the packet type to create the stub for
+ * Helper for logging receiving invalid packets.
+ * @param type The received packet type.
+ * @return Always false, as it's an error.
*/
-#define DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(type) \
-bool NetworkContentSocketHandler::NetworkPacketReceive_## type ##_command(Packet *p) \
-{ \
- DEBUG(net, 0, "[tcp/content] received illegal packet type %d from %s", \
- type, this->client_addr.GetAddressAsString()); \
- return false; \
+bool NetworkContentSocketHandler::ReceiveInvalidPacket(PacketContentType type)
+{
+ DEBUG(net, 0, "[tcp/content] received illegal packet type %d from %s", type, this->client_addr.GetAddressAsString());
+ return NETWORK_RECV_STATUS_MALFORMED_PACKET;
}
-DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_LIST)
-DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_ID)
-DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID)
-DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5)
-DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_INFO)
-DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_CONTENT)
-DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_CONTENT)
+bool NetworkContentSocketHandler::Receive_CLIENT_INFO_LIST(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_LIST); }
+bool NetworkContentSocketHandler::Receive_CLIENT_INFO_ID(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_ID); }
+bool NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_EXTID); }
+bool NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID_MD5(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5); }
+bool NetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_SERVER_INFO); }
+bool NetworkContentSocketHandler::Receive_CLIENT_CONTENT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_CONTENT); }
+bool NetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_SERVER_CONTENT); }
#endif /* ENABLE_NETWORK */
diff --git a/src/network/core/tcp_content.h b/src/network/core/tcp_content.h
index 07b7faa10..120324d48 100644
--- a/src/network/core/tcp_content.h
+++ b/src/network/core/tcp_content.h
@@ -47,9 +47,6 @@ enum PacketContentType {
PACKET_CONTENT_END ///< Must ALWAYS be on the end of this list!! (period)
};
-#define DECLARE_CONTENT_RECEIVE_COMMAND(type) virtual bool NetworkPacketReceive_## type ##_command(Packet *p)
-#define DEF_CONTENT_RECEIVE_COMMAND(cls, type) bool cls ##NetworkContentSocketHandler::NetworkPacketReceive_ ## type ## _command(Packet *p)
-
enum ContentID {
INVALID_CONTENT_ID = UINT32_MAX
};
@@ -98,19 +95,25 @@ protected:
NetworkAddress client_addr; ///< The address we're connected to.
virtual void Close();
+ bool ReceiveInvalidPacket(PacketContentType type);
+
/**
* Client requesting a list of content info:
* byte type
* uint32 openttd version
+ * @param p The packet that was just received.
+ * @return True upon success, otherwise false.
*/
- DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_LIST);
+ virtual bool Receive_CLIENT_INFO_LIST(Packet *p);
/**
* Client requesting a list of content info:
* uint16 count of ids
* uint32 id (count times)
+ * @param p The packet that was just received.
+ * @return True upon success, otherwise false.
*/
- DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_ID);
+ virtual bool Receive_CLIENT_INFO_ID(Packet *p);
/**
* Client requesting a list of content info based on an external
@@ -121,8 +124,10 @@ protected:
* for each request:
* uint8 type
* unique id (uint32)
+ * @param p The packet that was just received.
+ * @return True upon success, otherwise false.
*/
- DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID);
+ virtual bool Receive_CLIENT_INFO_EXTID(Packet *p);
/**
* Client requesting a list of content info based on an external
@@ -134,8 +139,10 @@ protected:
* uint8 type
* unique id (uint32)
* md5 (16 bytes)
+ * @param p The packet that was just received.
+ * @return True upon success, otherwise false.
*/
- DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5);
+ virtual bool Receive_CLIENT_INFO_EXTID_MD5(Packet *p);
/**
* Server sending list of content info:
@@ -150,15 +157,19 @@ protected:
* uint32 unique id of dependency (dependency count times)
* uint8 tag count
* string tag (max 32 characters for tag count times)
+ * @param p The packet that was just received.
+ * @return True upon success, otherwise false.
*/
- DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_INFO);
+ virtual bool Receive_SERVER_INFO(Packet *p);
/**
* Client requesting the actual content:
* uint16 count of unique ids
* uint32 unique id (count times)
+ * @param p The packet that was just received.
+ * @return True upon success, otherwise false.
*/
- DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_CONTENT);
+ virtual bool Receive_CLIENT_CONTENT(Packet *p);
/**
* Server sending list of content info:
@@ -167,8 +178,10 @@ protected:
* string file name (max 48 characters)
* After this initial packet, packets with the actual data are send using
* the same packet type.
+ * @param p The packet that was just received.
+ * @return True upon success, otherwise false.
*/
- DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_CONTENT);
+ virtual bool Receive_SERVER_CONTENT(Packet *p);
bool HandlePacket(Packet *p);
public:
diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp
index 9a1d862d1..aadca7ebb 100644
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -44,7 +44,7 @@ static bool HasGRFConfig(const ContentInfo *ci, bool md5sum)
*/
typedef bool (*HasProc)(const ContentInfo *ci, bool md5sum);
-DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_INFO)
+bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p)
{
ContentInfo *ci = new ContentInfo();
ci->type = (ContentType)p->Recv_uint8();
@@ -425,7 +425,7 @@ static bool GunzipFile(const ContentInfo *ci)
#endif /* defined(WITH_ZLIB) */
}
-DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT)
+bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p)
{
if (this->curFile == NULL) {
delete this->curInfo;
diff --git a/src/network/network_content.h b/src/network/network_content.h
index 4239a005f..37ce654fe 100644
--- a/src/network/network_content.h
+++ b/src/network/network_content.h
@@ -80,8 +80,8 @@ protected:
friend class NetworkContentConnecter;
- DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_INFO);
- DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_CONTENT);
+ virtual bool Receive_SERVER_INFO(Packet *p);
+ virtual bool Receive_SERVER_CONTENT(Packet *p);
ContentInfo *GetContent(ContentID cid);
void DownloadContentInfo(ContentID cid);