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_END,
00036 };
00037
00039 enum PacketContentType {
00040 PACKET_CONTENT_CLIENT_INFO_LIST,
00041 PACKET_CONTENT_CLIENT_INFO_ID,
00042 PACKET_CONTENT_CLIENT_INFO_EXTID,
00043 PACKET_CONTENT_CLIENT_INFO_EXTID_MD5,
00044 PACKET_CONTENT_SERVER_INFO,
00045 PACKET_CONTENT_CLIENT_CONTENT,
00046 PACKET_CONTENT_SERVER_CONTENT,
00047 PACKET_CONTENT_END
00048 };
00049
00051 enum ContentID {
00052 INVALID_CONTENT_ID = UINT32_MAX
00053 };
00054
00056 struct ContentInfo {
00058 enum State {
00059 UNSELECTED,
00060 SELECTED,
00061 AUTOSELECTED,
00062 ALREADY_HERE,
00063 DOES_NOT_EXIST,
00064 INVALID
00065 };
00066
00067 ContentType type;
00068 ContentID id;
00069 uint32 filesize;
00070 char filename[48];
00071 char name[32];
00072 char version[16];
00073 char url[96];
00074 char description[512];
00075 uint32 unique_id;
00076 byte md5sum[16];
00077 uint8 dependency_count;
00078 ContentID *dependencies;
00079 uint8 tag_count;
00080 char (*tags)[32];
00081 State state;
00082 bool upgrade;
00083
00084 ContentInfo();
00085 ~ContentInfo();
00086
00087 void TransferFrom(ContentInfo *other);
00088
00089 size_t Size() const;
00090 bool IsSelected() const;
00091 bool IsValid() const;
00092 };
00093
00095 class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
00096 protected:
00097 NetworkAddress client_addr;
00098 virtual void Close();
00099
00100 bool ReceiveInvalidPacket(PacketContentType type);
00101
00109 virtual bool Receive_CLIENT_INFO_LIST(Packet *p);
00110
00118 virtual bool Receive_CLIENT_INFO_ID(Packet *p);
00119
00132 virtual bool Receive_CLIENT_INFO_EXTID(Packet *p);
00133
00147 virtual bool Receive_CLIENT_INFO_EXTID_MD5(Packet *p);
00148
00165 virtual bool Receive_SERVER_INFO(Packet *p);
00166
00174 virtual bool Receive_CLIENT_CONTENT(Packet *p);
00175
00186 virtual bool Receive_SERVER_CONTENT(Packet *p);
00187
00188 bool HandlePacket(Packet *p);
00189 public:
00195 NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET, const NetworkAddress &address = NetworkAddress()) :
00196 NetworkTCPSocketHandler(s),
00197 client_addr(address)
00198 {
00199 }
00200
00202 virtual ~NetworkContentSocketHandler() { this->Close(); }
00203
00204 void ReceivePackets();
00205 };
00206
00207 #endif
00208
00209 #endif