Advanced Strategic Command
pbem-server-interaction.h
Go to the documentation of this file.
1 
46 #ifndef __ASC_PBEM_H
47 #define __ASC_PBEM_H
48 
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <errno.h>
52 #include <string.h>
53 #include <iostream>
54 #include <vector>
55 
56 #include <SDL_stdinc.h>
57 
58 #include <curl/curl.h>
59 #include <curl/types.h>
60 #include <curl/easy.h>
61 
62 #include "../ascstring.h"
63 #include "serverinterface.h"
64 
65 class ASC_PBEM_FileUploadControl // just a better struct so we can use const data
66 {
67  public:
68  int step;
69  int sent_step;
70  const int size;
71  const Uint8* data;
74 
75  std::vector<ASCString> parameters;
76 
77  ASC_PBEM_FileUploadControl( const Uint8* dataParam, const int sizeParam ): size( sizeParam ), data( dataParam ) {};
78 
79 };
80 
81  struct TUserData
82 {
84  int userID;
85 };
86 
87  struct TFileData
88 {
90  Uint8* fileData;
91  int fileSize;
92 };
93 
94  struct TGameInfo
95 {
96  int gameID;
98  int projectID;
100  int turn;
104 };
105 
106  class ASC_PBEM: public ServerInterface
107 {
108  private:
109  ASCString serverBase;
110  bool usable;
111  bool loggedIn;
112  CURL *curl_handle;
113 
114  std::vector< ASCString > header;
115  std::vector< ASCString > body;
116  int statusCode;
117 
118  ASCString sessionID;
119 
120  // server data
121  int serverVersion;
122 
123  // serverVersion has to be greater or equal to this
124  static const int MIN_SERVER_VERSION = 1;
125 
126  // serverVersion has to be less than this;
127  // so, MAX_SERVER_VERSION = 0.02 means that _starting_ with version 0.2, this client wont work
128  static const int MAX_SERVER_VERSION = 2;
129 
130  public:
131 
132  static const char ROLE_SUPERVISOR = 's';
133  static const char ROLE_PLAYER = 'p';
134  static const char ROLE_HIDDEN = 'h';
135 
142  ASC_PBEM( ASCString serverBase );
143  ~ASC_PBEM();
144 
150  bool isUsable();
151 
156  bool login( ASCString user, ASCString passwd );
157 
164  bool createAccount( ASCString user, ASCString passwd, ASCString email );
165 
166 
172  bool activateAccount( ASCString user, ASCString code );
173 
174 
177  bool uploadFile( ASCString fileName, const Uint8* data, const int size, const int gameID );
178 
182  std::vector<TUserData> getUserList( bool activeOnly = true );
183 
186  bool createGame( ASCString fileName, const Uint8* data, const int size, ASCString gameName, ASCString fileNamePattern, char* roles, int* players, int projectID = -1, int turn = 1, int currentSlot = 1);
187 
191  std::vector<TGameInfo> getCurrentGamesInfo( bool myTurnOnly );
192 
196 
202  bool logout();
203 
204  // guess what ;)
205  bool isLoggedIn();
206 
207  // get _http_ header from last request
209 
210  // get _http_ body from last request
211  ASCString getBody();
212 
213  // get http status code from last request,
214  // as determined by checking of the header
215  // may be -1 if the last request header wasn't parsed,
216  // or no status code could be determined in the header
217  int getStatusCode();
218 
219  protected:
220 
221  private:
222 
223  // simple wrapper for bool request( ASCString url, std::vector<ASCString> parameters );
224  bool request( ASCString url );
225 
231  bool request( ASCString url, std::vector<ASCString> parameters );
232 
233  // similar to above, but for file uploads
234  bool request( ASCString url, ASC_PBEM_FileUploadControl* fileUploadControl );
235 
236  // breaks down the string into lines
237  void parseHeader( ASCString headerString );
238 
239  // parse a singular header line
240  void parseHeaderLine( ASCString line );
241 
242  // parse a singular game info line
243  TGameInfo parseGameInfoLine( ASCString line );
244 
245  // parse a singular game info line
246  TUserData parseUserInfoLine( ASCString line );
247 
248 
249  public:
250  std::vector<ASCString> listPlayers();
251 
252 
253 };
254 
255 #endif
bool createAccount(ASCString user, ASCString passwd, ASCString email)
bool login(ASCString user, ASCString passwd)
static const char ROLE_PLAYER
bool createGame(ASCString fileName, const Uint8 *data, const int size, ASCString gameName, ASCString fileNamePattern, char *roles, int *players, int projectID=-1, int turn=1, int currentSlot=1)
static const char ROLE_HIDDEN
ASCString currentPlayerName
ASCString currentSaveGameName
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
bool uploadFile(ASCString fileName, const Uint8 *data, const int size, const int gameID)
std::vector< ASCString > listPlayers()
bool activateAccount(ASCString user, ASCString code)
static const char ROLE_SUPERVISOR
std::vector< TGameInfo > getCurrentGamesInfo(bool myTurnOnly)
file: ASC_PBEM.h author: Jade Rogalski license: GPL warranty: none
ASC_PBEM_FileUploadControl(const Uint8 *dataParam, const int sizeParam)
std::vector< TUserData > getUserList(bool activeOnly=true)
TFileData * downloadGame(TGameInfo game)
std::vector< ASCString > parameters
ASC_PBEM(ASCString serverBase)
default constructor:
void line(int x1, int y1, int x2, int y2, Uint8 actcol)
draws a simple line on the screen. Not very fast...
Definition: basegfx.cpp:181
bool isUsable()
important: check this first after instantiation this class will be false after any ...