# tcp_content.h

Go to the documentation of this file.

    00001 /* $Id: tcp_content.h 15206 2009-01-22 10:09:56Z rubidium $ */
    00002
    00007 #ifndef NETWORK_CORE_CONTENT_H
    00008 #define NETWORK_CORE_CONTENT_H
    00009
    00010 #ifdef ENABLE_NETWORK
    00011
    00012 #include "os_abstraction.h"
    00013 #include "tcp.h"
    00014 #include "packet.h"
    00015 #include "../../debug.h"
    00016
    00018 enum ContentType {
    00019   CONTENT_TYPE_BEGIN         = 1,
    00020   CONTENT_TYPE_BASE_GRAPHICS = 1,
    00021   CONTENT_TYPE_NEWGRF        = 2,
    00022   CONTENT_TYPE_AI            = 3,
    00023   CONTENT_TYPE_AI_LIBRARY    = 4,
    00024   CONTENT_TYPE_SCENARIO      = 5,
    00025   CONTENT_TYPE_HEIGHTMAP     = 6,
    00026   CONTENT_TYPE_END,
    00027 };
    00028
    00030 enum PacketContentType {
    00031   PACKET_CONTENT_CLIENT_INFO_LIST,
    00032   PACKET_CONTENT_CLIENT_INFO_ID,
    00033   PACKET_CONTENT_CLIENT_INFO_EXTID,
    00034   PACKET_CONTENT_CLIENT_INFO_EXTID_MD5,
    00035   PACKET_CONTENT_SERVER_INFO,
    00036   PACKET_CONTENT_CLIENT_CONTENT,
    00037   PACKET_CONTENT_SERVER_CONTENT,
    00038   PACKET_CONTENT_END
    00039 };
    00040
    00041 #define DECLARE_CONTENT_RECEIVE_COMMAND(type) virtual bool NetworkPacketReceive_## type ##_command(Packet *p)
    00042 #define DEF_CONTENT_RECEIVE_COMMAND(cls, type) bool cls ##NetworkContentSocketHandler::NetworkPacketReceive_ ## type ## _command(Packet *p)
    00043
    00044 enum ContentID {
    00045   INVALID_CONTENT_ID = UINT32_MAX
    00046 };
    00047
    00049 struct ContentInfo {
    00050   enum State {
    00051     UNSELECTED,
    00052     SELECTED,
    00053     AUTOSELECTED,
    00054     ALREADY_HERE,
    00055     DOES_NOT_EXIST,
    00056     INVALID
    00057   };
    00058
    00059   ContentType type;
    00060   ContentID id;
    00061   uint32 filesize;
    00062   char filename[48];
    00063   char name[32];
    00064   char version[16];
    00065   char url[96];
    00066   char description[512];
    00067   uint32 unique_id;
    00068   byte md5sum[16];
    00069   uint8 dependency_count;
    00070   ContentID *dependencies;
    00071   uint8 tag_count;
    00072   char (*tags)[32];
    00073   State state;
    00074   bool upgrade;
    00075
    00077   ContentInfo();
    00078
    00080   ~ContentInfo();
    00081
    00086   size_t Size() const;
    00087
    00092   bool IsSelected() const;
    00093
    00098   bool IsValid() const;
    00099 };
    00100
    00102 class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
    00103 protected:
    00104   struct sockaddr_in client_addr;
    00105   virtual void Close();
    00106
    00112   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_LIST);
    00113
    00119   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_ID);
    00120
    00131   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID);
    00132
    00144   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5);
    00145
    00160   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_INFO);
    00161
    00167   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_CONTENT);
    00168
    00177   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_CONTENT);
    00178
    00185   bool HandlePacket(Packet *p);
    00186 public:
    00192   NetworkContentSocketHandler(SOCKET s, const struct sockaddr_in *sin) :
    00193     NetworkTCPSocketHandler(s)
    00194   {
    00195     if (sin != NULL) this->client_addr = *sin;
    00196   }
    00197
    00199   virtual ~NetworkContentSocketHandler() { this->Close(); }
    00200
    00202   void Recv_Packets();
    00203 };
    00204
    00205 #endif /* ENABLE_NETWORK */
    00206
    00207 #endif /* NETWORK_CORE_CONTENT_H */