Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pbem-server-interaction.h

Go to the documentation of this file.
00001 
00046 #ifndef __ASC_PBEM_H
00047 #define __ASC_PBEM_H
00048 
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <errno.h>
00052 #include <string.h>
00053 #include <iostream>
00054 #include <vector>
00055 
00056 #include <curl/curl.h>
00057 #include <curl/types.h>
00058 #include <curl/easy.h>
00059 
00060 #include "../ascstring.h"
00061 #include "serverinterface.h"
00062 
00063 class ASC_PBEM_FileUploadControl // just a better struct so we can use const data
00064 {
00065    public:
00066       int step;
00067       int sent_step;
00068       const int size;
00069       const char* data;
00070       ASCString fileName;
00071       ASCString boundary;
00072       
00073       std::vector<ASCString> parameters;
00074       
00075       ASC_PBEM_FileUploadControl( const char* dataParam, const int sizeParam ): size( sizeParam ), data( dataParam ) {};
00076       
00077 };
00078 
00079  struct TUserData
00080 {
00081    ASCString userName;
00082    int userID;
00083 };
00084 
00085  struct TFileData
00086 {
00087    ASCString fileName;
00088    char* fileData;
00089    int fileSize;
00090 };
00091 
00092  struct TGameInfo
00093 {
00094    int gameID;
00095    ASCString name;
00096    int projectID;
00097    int currentSlot;
00098    int turn;
00099    ASCString currentSaveGameName;
00100    ASCString lastActive;
00101    ASCString currentPlayerName;
00102 };
00103 
00104  class ASC_PBEM: public ServerInterface
00105 {
00106    private:
00107       ASCString serverBase;
00108       bool usable;
00109       bool loggedIn;
00110       CURL *curl_handle;
00111       
00112       std::vector< ASCString > header;
00113       std::vector< ASCString > body;
00114       int statusCode;
00115       
00116       ASCString sessionID;
00117 
00118       // server data
00119       int serverVersion;
00120       
00121       // serverVersion has to be greater or equal to this
00122       static const int MIN_SERVER_VERSION = 1; 
00123 
00124       // serverVersion has to be less than this; 
00125       // so, MAX_SERVER_VERSION = 0.02 means that _starting_ with version 0.2, this client wont work
00126       static const int MAX_SERVER_VERSION = 2; 
00127       
00128    public:
00129    
00130       static const char ROLE_SUPERVISOR = 's';
00131       static const char ROLE_PLAYER = 'p';
00132       static const char ROLE_HIDDEN = 'h';
00133    
00140       ASC_PBEM( ASCString serverBase );
00141       ~ASC_PBEM();
00142       
00148       bool isUsable();
00149       
00154       bool login( ASCString user, ASCString passwd );
00155       
00162       bool createAccount( ASCString user, ASCString passwd, ASCString email );
00163       
00164       
00170       bool activateAccount( ASCString user, ASCString code );
00171 
00172       
00175       bool uploadFile( ASCString fileName, const char* data, const int size, const int gameID );
00176 
00180       std::vector<TUserData> getUserList( bool activeOnly = true );
00181       
00184       bool createGame( ASCString fileName, const char* data, const int size, ASCString gameName, ASCString fileNamePattern, char* roles, int* players, int projectID = -1, int turn = 1, int currentSlot = 1);
00185       
00189       std::vector<TGameInfo> getCurrentGamesInfo( bool myTurnOnly );
00190       
00193       TFileData* downloadGame( TGameInfo game );
00194       
00200       bool logout();
00201       
00202       // guess what ;)
00203       bool isLoggedIn();
00204       
00205       // get _http_ header from last request
00206       ASCString getHeader();
00207       
00208       // get _http_ body from last request
00209       ASCString getBody();
00210       
00211       // get http status code from last request, 
00212       // as determined by checking of the header
00213       // may be -1 if the last request header wasn't parsed,
00214       // or no status code could be determined in the header
00215       int getStatusCode();
00216 
00217    protected:
00218    
00219    private:
00220       
00221       // simple wrapper for bool request( ASCString url, std::vector<ASCString> parameters );
00222       bool request( ASCString url );
00223       
00229       bool request( ASCString url, std::vector<ASCString> parameters );
00230       
00231       // similar to above, but for file uploads
00232       bool request( ASCString url, ASC_PBEM_FileUploadControl* fileUploadControl );
00233       
00234       // breaks down the string into lines
00235       void parseHeader( ASCString headerString );
00236       
00237       // parse a singular header line
00238       void parseHeaderLine( ASCString line );
00239       
00240       // parse a singular game info line
00241       TGameInfo parseGameInfoLine( ASCString line );
00242 
00243       // parse a singular game info line
00244       TUserData parseUserInfoLine( ASCString line );
00245 
00246 
00247    public:
00248       std::vector<ASCString> listPlayers();
00249 
00250       
00251 };
00252 
00253 #endif

Generated on Tue Jun 24 01:27:46 2008 for Advanced Strategic Command by  doxygen 1.4.2