tcp_content.h

Go to the documentation of this file.
00001 /* $Id: tcp_content.h 24900 2013-01-08 22:46:42Z planetmaker $ */
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_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 #ifndef OPENTTD_MSU
00095   const char *GetTextfile(TextfileType type) const;
00096 #endif /* OPENTTD_MSU */
00097 };
00098 
00100 class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
00101 protected:
00102   NetworkAddress client_addr; 
00103   virtual void Close();
00104 
00105   bool ReceiveInvalidPacket(PacketContentType type);
00106 
00114   virtual bool Receive_CLIENT_INFO_LIST(Packet *p);
00115 
00123   virtual bool Receive_CLIENT_INFO_ID(Packet *p);
00124 
00137   virtual bool Receive_CLIENT_INFO_EXTID(Packet *p);
00138 
00152   virtual bool Receive_CLIENT_INFO_EXTID_MD5(Packet *p);
00153 
00170   virtual bool Receive_SERVER_INFO(Packet *p);
00171 
00179   virtual bool Receive_CLIENT_CONTENT(Packet *p);
00180 
00191   virtual bool Receive_SERVER_CONTENT(Packet *p);
00192 
00193   bool HandlePacket(Packet *p);
00194 public:
00200   NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET, const NetworkAddress &address = NetworkAddress()) :
00201     NetworkTCPSocketHandler(s),
00202     client_addr(address)
00203   {
00204   }
00205 
00207   virtual ~NetworkContentSocketHandler() { this->Close(); }
00208 
00209   void ReceivePackets();
00210 };
00211 
00212 #ifndef OPENTTD_MSU
00213 Subdirectory GetContentInfoSubDir(ContentType type);
00214 #endif /* OPENTTD_MSU */
00215 
00216 #endif /* ENABLE_NETWORK */
00217 
00218 #endif /* NETWORK_CORE_TCP_CONTENT_H */