changeset 17629:86a485e12c9c draft

(svn r22399) -Codechange: replace some defines in the tcp/content code so doxygen can create better documentation
author rubidium <rubidium@openttd.org>
date Sun, 01 May 2011 11:13:11 +0000 (2011-05-01)
parents fcd0ff5d6f5f
children f65933f87e02
files src/network/core/tcp_content.cpp src/network/core/tcp_content.h src/network/network_content.cpp src/network/network_content.h
diffstat 4 files changed, 49 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/network/core/tcp_content.cpp
+++ b/src/network/core/tcp_content.cpp
@@ -112,13 +112,13 @@
 	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 @@
 	}
 }
 
+
 /**
- * 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 */
--- a/src/network/core/tcp_content.h
+++ b/src/network/core/tcp_content.h
@@ -47,9 +47,6 @@
 	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 @@
 	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 @@
 	 *  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 @@
 	 *    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 @@
 	 *  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 @@
 	 *  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:
--- a/src/network/network_content.cpp
+++ b/src/network/network_content.cpp
@@ -44,7 +44,7 @@
  */
 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 @@
 #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;
--- a/src/network/network_content.h
+++ b/src/network/network_content.h
@@ -80,8 +80,8 @@
 
 	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);