Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00014 #ifndef NETWORK_CORE_TCP_CONTENT_H
00015 #define NETWORK_CORE_TCP_CONTENT_H
00016
00017 #include "os_abstraction.h"
00018 #include "tcp.h"
00019 #include "packet.h"
00020 #include "../../debug.h"
00021
00022 #ifdef ENABLE_NETWORK
00023
00025 enum ContentType {
00026 CONTENT_TYPE_BEGIN = 1,
00027 CONTENT_TYPE_BASE_GRAPHICS = 1,
00028 CONTENT_TYPE_NEWGRF = 2,
00029 CONTENT_TYPE_AI = 3,
00030 CONTENT_TYPE_AI_LIBRARY = 4,
00031 CONTENT_TYPE_SCENARIO = 5,
00032 CONTENT_TYPE_HEIGHTMAP = 6,
00033 CONTENT_TYPE_BASE_SOUNDS = 7,
00034 CONTENT_TYPE_BASE_MUSIC = 8,
00035 CONTENT_TYPE_GAME = 9,
00036 CONTENT_TYPE_GAME_LIBRARY = 10,
00037 CONTENT_TYPE_END,
00038 };
00039
00041 enum PacketContentType {
00042 PACKET_CONTENT_CLIENT_INFO_LIST,
00043 PACKET_CONTENT_CLIENT_INFO_ID,
00044 PACKET_CONTENT_CLIENT_INFO_EXTID,
00045 PACKET_CONTENT_CLIENT_INFO_EXTID_MD5,
00046 PACKET_CONTENT_SERVER_INFO,
00047 PACKET_CONTENT_CLIENT_CONTENT,
00048 PACKET_CONTENT_SERVER_CONTENT,
00049 PACKET_CONTENT_END,
00050 };
00051
00053 enum ContentID {
00054 INVALID_CONTENT_ID = UINT32_MAX,
00055 };
00056
00058 struct ContentInfo {
00060 enum State {
00061 UNSELECTED,
00062 SELECTED,
00063 AUTOSELECTED,
00064 ALREADY_HERE,
00065 DOES_NOT_EXIST,
00066 INVALID,
00067 };
00068
00069 ContentType type;
00070 ContentID id;
00071 uint32 filesize;
00072 char filename[48];
00073 char name[32];
00074 char version[16];
00075 char url[96];
00076 char description[512];
00077 uint32 unique_id;
00078 byte md5sum[16];
00079 uint8 dependency_count;
00080 ContentID *dependencies;
00081 uint8 tag_count;
00082 char (*tags)[32];
00083 State state;
00084 bool upgrade;
00085
00086 ContentInfo();
00087 ~ContentInfo();
00088
00089 void TransferFrom(ContentInfo *other);
00090
00091 size_t Size() const;
00092 bool IsSelected() const;
00093 bool IsValid() const;
00094 };
00095
00097 class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
00098 protected:
00099 NetworkAddress client_addr;
00100 virtual void Close();
00101
00102 bool ReceiveInvalidPacket(PacketContentType type);
00103
00111 virtual bool Receive_CLIENT_INFO_LIST(Packet *p);
00112
00120 virtual bool Receive_CLIENT_INFO_ID(Packet *p);
00121
00134 virtual bool Receive_CLIENT_INFO_EXTID(Packet *p);
00135
00149 virtual bool Receive_CLIENT_INFO_EXTID_MD5(Packet *p);
00150
00167 virtual bool Receive_SERVER_INFO(Packet *p);
00168
00176 virtual bool Receive_CLIENT_CONTENT(Packet *p);
00177
00188 virtual bool Receive_SERVER_CONTENT(Packet *p);
00189
00190 bool HandlePacket(Packet *p);
00191 public:
00197 NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET, const NetworkAddress &address = NetworkAddress()) :
00198 NetworkTCPSocketHandler(s),
00199 client_addr(address)
00200 {
00201 }
00202
00204 virtual ~NetworkContentSocketHandler() { this->Close(); }
00205
00206 void ReceivePackets();
00207 };
00208
00209 Subdirectory GetContentInfoSubDir(ContentType type);
00210
00211 #endif
00212
00213 #endif