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 
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 /* ENABLE_NETWORK */
00208 
00209 #endif /* NETWORK_CORE_TCP_CONTENT_H */

Generated on Fri Jun 3 05:18:52 2011 for OpenTTD by  doxygen 1.6.1