tcp_content.h

Go to the documentation of this file.
00001 /* $Id: tcp_content.h 20095 2010-07-08 19:59:13Z rubidium $ */
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 
00091   void TransferFrom(ContentInfo *other);
00092 
00097   size_t Size() const;
00098 
00103   bool IsSelected() const;
00104 
00109   bool IsValid() const;
00110 };
00111 
00113 class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
00114 protected:
00115   NetworkAddress client_addr; 
00116   virtual void Close();
00117 
00123   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_LIST);
00124 
00130   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_ID);
00131 
00142   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID);
00143 
00155   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_INFO_EXTID_MD5);
00156 
00171   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_INFO);
00172 
00178   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_CLIENT_CONTENT);
00179 
00188   DECLARE_CONTENT_RECEIVE_COMMAND(PACKET_CONTENT_SERVER_CONTENT);
00189 
00196   bool HandlePacket(Packet *p);
00197 public:
00203   NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET, const NetworkAddress &address = NetworkAddress()) :
00204     NetworkTCPSocketHandler(s),
00205     client_addr(address)
00206   {
00207   }
00208 
00210   virtual ~NetworkContentSocketHandler() { this->Close(); }
00211 
00213   void Recv_Packets();
00214 };
00215 
00216 #endif /* ENABLE_NETWORK */
00217 
00218 #endif /* NETWORK_CORE_CONTENT_H */

Generated on Sat Jul 31 21:37:47 2010 for OpenTTD by  doxygen 1.6.1