# tcp_content.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00014 #ifndef NETWORK_CORE_CONTENT_H
    00015 #define NETWORK_CORE_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
    00050 #define DECLARE_CONTENT_RECEIVE_COMMAND(type) virtual bool NetworkPacketReceive_## type ##_command(Packet *p)
    00051 #define DEF_CONTENT_RECEIVE_COMMAND(cls, type) bool cls ##NetworkContentSocketHandler::NetworkPacketReceive_ ## type ## _command(Packet *p)
    00052
    00053 enum ContentID {
    00054   INVALID_CONTENT_ID = UINT32_MAX
    00055 };
    00056
    00058 struct ContentInfo {
    00059   enum State {
    00060     UNSELECTED,
    00061     SELECTED,
    00062     AUTOSELECTED,
    00063     ALREADY_HERE,
    00064     DOES_NOT_EXIST,
    00065     INVALID
    00066   };
    00067
    00068   ContentType type;
    00069   ContentID id;
    00070   uint32 filesize;
    00071   char filename[48];
    00072   char name[32];
    00073   char version[16];
    00074   char url[96];
    00075   char description[512];
    00076   uint32 unique_id;
    00077   byte md5sum[16];
    00078   uint8 dependency_count;
    00079   ContentID *dependencies;
    00080   uint8 tag_count;
    00081   char (*tags)[32];
    00082   State state;
    00083   bool upgrade;
    00084
    00086   ContentInfo();
    00087
    00089   ~ContentInfo();
    00090
    00095   size_t Size() const;
    00096
    00101   bool IsSelected() const;
    00102
    00107   bool IsValid() const;
    00108 };
    00109
    00111 class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
    00112 protected:
    00113   NetworkAddress client_addr;
    00114   virtual void Close();
    00115
    00121   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_LIST);
    00122
    00128   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_ID);
    00129
    00140   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID);
    00141
    00153   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5);
    00154
    00169   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_INFO);
    00170
    00176   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_CONTENT);
    00177
    00186   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_CONTENT);
    00187
    00194   bool HandlePacket(Packet *p);
    00195 public:
    00201   NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET, const NetworkAddress &address = NetworkAddress()) :
    00202     NetworkTCPSocketHandler(s),
    00203     client_addr(address)
    00204   {
    00205   }
    00206
    00208   virtual ~NetworkContentSocketHandler() { this->Close(); }
    00209
    00211   void Recv_Packets();
    00212 };
    00213
    00214 #endif /* ENABLE_NETWORK */
    00215
    00216 #endif /* NETWORK_CORE_CONTENT_H */