# 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_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
    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
    00085   ContentInfo();
    00086   ~ContentInfo();
    00087
    00088   void TransferFrom(ContentInfo *other);
    00089
    00090   size_t Size() const;
    00091   bool IsSelected() const;
    00092   bool IsValid() const;
    00093 };
    00094
    00096 class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
    00097 protected:
    00098   NetworkAddress client_addr;
    00099   virtual void Close();
    00100
    00106   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_LIST);
    00107
    00113   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_ID);
    00114
    00125   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID);
    00126
    00138   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5);
    00139
    00154   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_INFO);
    00155
    00161   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_CONTENT);
    00162
    00171   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_CONTENT);
    00172
    00173   bool HandlePacket(Packet *p);
    00174 public:
    00180   NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET, const NetworkAddress &address = NetworkAddress()) :
    00181     NetworkTCPSocketHandler(s),
    00182     client_addr(address)
    00183   {
    00184   }
    00185
    00187   virtual ~NetworkContentSocketHandler() { this->Close(); }
    00188
    00189   void ReceivePackets();
    00190 };
    00191
    00192 #endif /* ENABLE_NETWORK */
    00193
    00194 #endif /* NETWORK_CORE_TCP_CONTENT_H */