#ifndef SPRINGLOBBY_HEADERGUARD_TORRENTWRAPPER_H #define SPRINGLOBBY_HEADERGUARD_TORRENTWRAPPER_H #ifndef NO_TORRENT_SYSTEM #include #include #include #include "inetclass.h" #define DEFAULT_P2P_COORDINATOR_PORT 8202 #define DEFAULT_P2P_TRACKER_PORT 8201 namespace libtorrent{ class session; }; class Socket; enum MediaType { map, mod }; struct TorrentInfos { float numcopies; wxString name; unsigned int downloaded; unsigned int uploaded; bool leeching; float progress; float inspeed; float outspeed; int filehash; }; struct TorrentData { wxString hash; wxString name; MediaType type; wxString infohash; }; class TorrentWrapper : public iNetClass { public: TorrentWrapper(); ~TorrentWrapper(); /// gui interface void ConnectToP2PSystem(); void DisconnectToP2PSystem(); bool IsConnectedToP2PSystem(); bool IsFileInSystem( const wxString& uhash ); /// lobby interface void SetIngameStatus( bool status ); void ReloadLocalFileList(); bool RequestFile( const wxString& hash ); void UpdateSettings(); void UpdateFromTimer( int mselapsed ); std::map CollectGuiInfos(); private: void CreateTorrent( const wxString& uhash, const wxString& name, MediaType type ); bool JoinTorrent( const wxString& name ); bool DownloadTorrentFileFromTracker( const wxString& shash ); void FixTorrentList(); void ReceiveandExecute( const wxString& msg ); void OnConnected( Socket* sock ); void OnDisconnected( Socket* sock ); void OnDataReceived( Socket* sock ); bool m_connected; bool ingame; unsigned int m_seed_count; unsigned int m_leech_count; unsigned int m_timer_count; wxArrayString m_tracker_urls; std::map m_torrents_infos; /// shash -> torr infos typedef std::map::iterator TorrentsIter; std::map m_seed_requests; ///name -> hash typedef std::map::iterator SeedReqIter; std::map m_local_files; /// shash -> torrent data typedef std::map::iterator LocalFilesIter; std::map m_open_torrents; /// name -> is seed typedef std::map::iterator OpenIter; libtorrent::session* m_torr; Socket* m_socket_class; unsigned int m_connected_tracker_index; }; TorrentWrapper* torrent(); #endif #endif // SPRINGLOBBY_HEADERGUARD_TORRENTWRAPPER_H