1
0
Fork 0

(svn r22399) -Codechange: replace some defines in the tcp/content code so doxygen can create better documentation

release/1.2
rubidium 2011-05-01 11:13:11 +00:00
parent b2efd73773
commit d4737e0724
4 changed files with 49 additions and 38 deletions

View File

@ -112,13 +112,13 @@ bool NetworkContentSocketHandler::HandlePacket(Packet *p)
PacketContentType type = (PacketContentType)p->Recv_uint8(); PacketContentType type = (PacketContentType)p->Recv_uint8();
switch (this->HasClientQuit() ? PACKET_CONTENT_END : type) { switch (this->HasClientQuit() ? PACKET_CONTENT_END : type) {
CONTENT_COMMAND(PACKET_CONTENT_CLIENT_INFO_LIST); case PACKET_CONTENT_CLIENT_INFO_LIST: return this->Receive_CLIENT_INFO_LIST(p);
CONTENT_COMMAND(PACKET_CONTENT_CLIENT_INFO_ID); case PACKET_CONTENT_CLIENT_INFO_ID: return this->Receive_CLIENT_INFO_ID(p);
CONTENT_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID); case PACKET_CONTENT_CLIENT_INFO_EXTID: return this->Receive_CLIENT_INFO_EXTID(p);
CONTENT_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5); case PACKET_CONTENT_CLIENT_INFO_EXTID_MD5: return this->Receive_CLIENT_INFO_EXTID_MD5(p);
CONTENT_COMMAND(PACKET_CONTENT_SERVER_INFO); case PACKET_CONTENT_SERVER_INFO: return this->Receive_SERVER_INFO(p);
CONTENT_COMMAND(PACKET_CONTENT_CLIENT_CONTENT); case PACKET_CONTENT_CLIENT_CONTENT: return this->Receive_CLIENT_CONTENT(p);
CONTENT_COMMAND(PACKET_CONTENT_SERVER_CONTENT); case PACKET_CONTENT_SERVER_CONTENT: return this->Receive_SERVER_CONTENT(p);
default: default:
if (this->HasClientQuit()) { if (this->HasClientQuit()) {
@ -143,26 +143,24 @@ void NetworkContentSocketHandler::ReceivePackets()
} }
} }
/** /**
* Create stub implementations for all receive commands that only * Helper for logging receiving invalid packets.
* show a warning that the given command is not available for the * @param type The received packet type.
* socket where the packet came from. * @return Always false, as it's an error.
* @param type the packet type to create the stub for
*/ */
#define DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(type) \ bool NetworkContentSocketHandler::ReceiveInvalidPacket(PacketContentType 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());
DEBUG(net, 0, "[tcp/content] received illegal packet type %d from %s", \ return NETWORK_RECV_STATUS_MALFORMED_PACKET;
type, this->client_addr.GetAddressAsString()); \
return false; \
} }
DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_LIST) bool NetworkContentSocketHandler::Receive_CLIENT_INFO_LIST(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_LIST); }
DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_ID) bool NetworkContentSocketHandler::Receive_CLIENT_INFO_ID(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_ID); }
DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID) bool NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_EXTID); }
DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5) bool NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID_MD5(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5); }
DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_INFO) bool NetworkContentSocketHandler::Receive_SERVER_INFO(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_SERVER_INFO); }
DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_CONTENT) bool NetworkContentSocketHandler::Receive_CLIENT_CONTENT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_CLIENT_CONTENT); }
DEFINE_UNAVAILABLE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_CONTENT) bool NetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_CONTENT_SERVER_CONTENT); }
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */

View File

@ -47,9 +47,6 @@ enum PacketContentType {
PACKET_CONTENT_END ///< Must ALWAYS be on the end of this list!! (period) 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 { enum ContentID {
INVALID_CONTENT_ID = UINT32_MAX INVALID_CONTENT_ID = UINT32_MAX
}; };
@ -98,19 +95,25 @@ protected:
NetworkAddress client_addr; ///< The address we're connected to. NetworkAddress client_addr; ///< The address we're connected to.
virtual void Close(); virtual void Close();
bool ReceiveInvalidPacket(PacketContentType type);
/** /**
* Client requesting a list of content info: * Client requesting a list of content info:
* byte type * byte type
* uint32 openttd version * 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: * Client requesting a list of content info:
* uint16 count of ids * uint16 count of ids
* uint32 id (count times) * 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 * Client requesting a list of content info based on an external
@ -121,8 +124,10 @@ protected:
* for each request: * for each request:
* uint8 type * uint8 type
* unique id (uint32) * 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 * Client requesting a list of content info based on an external
@ -134,8 +139,10 @@ protected:
* uint8 type * uint8 type
* unique id (uint32) * unique id (uint32)
* md5 (16 bytes) * 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: * Server sending list of content info:
@ -150,15 +157,19 @@ protected:
* uint32 unique id of dependency (dependency count times) * uint32 unique id of dependency (dependency count times)
* uint8 tag count * uint8 tag count
* string tag (max 32 characters for tag count times) * 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: * Client requesting the actual content:
* uint16 count of unique ids * uint16 count of unique ids
* uint32 unique id (count times) * 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: * Server sending list of content info:
@ -167,8 +178,10 @@ protected:
* string file name (max 48 characters) * string file name (max 48 characters)
* After this initial packet, packets with the actual data are send using * After this initial packet, packets with the actual data are send using
* the same packet type. * 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); bool HandlePacket(Packet *p);
public: public:

View File

@ -44,7 +44,7 @@ static bool HasGRFConfig(const ContentInfo *ci, bool md5sum)
*/ */
typedef bool (*HasProc)(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(); ContentInfo *ci = new ContentInfo();
ci->type = (ContentType)p->Recv_uint8(); ci->type = (ContentType)p->Recv_uint8();
@ -425,7 +425,7 @@ static bool GunzipFile(const ContentInfo *ci)
#endif /* defined(WITH_ZLIB) */ #endif /* defined(WITH_ZLIB) */
} }
DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT) bool ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(Packet *p)
{ {
if (this->curFile == NULL) { if (this->curFile == NULL) {
delete this->curInfo; delete this->curInfo;

View File

@ -80,8 +80,8 @@ protected:
friend class NetworkContentConnecter; friend class NetworkContentConnecter;
DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_INFO); virtual bool Receive_SERVER_INFO(Packet *p);
DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_CONTENT); virtual bool Receive_SERVER_CONTENT(Packet *p);
ContentInfo *GetContent(ContentID cid); ContentInfo *GetContent(ContentID cid);
void DownloadContentInfo(ContentID cid); void DownloadContentInfo(ContentID cid);