// BT - 12/21/2010 - CSS - Get all rank details from the lobby web service bool CCssSoap::GetRankForCallsign(const char* szPlayerName, int *rank, double *sigma, double *mu, int *commandRank, double *commandSigma, double *commandMu, char *rankName, int rankNameLen) { char resultMessage[1024]; char szURL[2064]; char szHdrs[512]; sprintf(szHdrs, ""); // the player callsign has to be urlencoded, because it may contain '+', '?', etc. char callsign[128]; char playername[128]; Strcpy(playername, szPlayerName); strcpy(callsign, ""); EncodeURL(callsign, playername); sprintf(szURL, "%s?Action=GetRank&Callsign=%s", m_szCssLobbyServicePath, callsign); ZString Response = UTL::DoHTTP(szHdrs, m_szCssServerDomain, "GET", szURL, "", 0, false); strcpy(resultMessage, "Rank Retrieve Failed.\n\nPlease contact system admin."); char szResponse[10000]; strcpy(szResponse, (PCC)Response); debugf("CssGetRankForCallsign(): contentLen = %ld, content = %s\r\n", Response.GetLength(), szResponse); int resultCode = -1; char localRankName[50]; if (sscanf(szResponse, "%ld|%ld|%[^|]|%lf|%lf|%ld|%lf|%lf", &resultCode, rank, localRankName, sigma, mu, commandRank, commandSigma, commandMu) == EOF) resultCode = -1; strncpy(rankName, localRankName, rankNameLen); if (resultCode == 0) strcpy(resultMessage, "Rank retrieved."); debugf(resultMessage); return resultCode == 0; }
vector<Score> GameJoltAPI::GetScores( int tableId /* = 0 */, bool user /* = false */, int limit /* = -1 */ ) { CStdString output; CStdString gameIDString; CStdString tableIdString; CStdString limitString; CStdString requestURL; vector<map<CStdString, CStdString>> parsedOutput; vector<map<CStdString, CStdString>>::iterator it; map<CStdString, CStdString> scoreInfo; vector<Score> scores; bool ret = true; // Game ID must be set. if ( m_GameID <= 0 ) { m_ErrorMessage += _T("(The game ID must be set.)"); return scores; } // We must format the Game ID to a string. gameIDString.Format( _T("%d"), m_GameID ); tableIdString.Format( _T("%d"), tableId ); limitString.Format( _T("%d"), limit ); requestURL = _T("/scores/?game_id=") + gameIDString; if ( user ) { // Username must be set. if ( m_Username == _T("") ) { m_ErrorMessage += _T("(The username must be set.)"); return scores; } // User token must be set. if ( m_UserToken == _T("") ) { m_ErrorMessage += _T("(The user token must be set.)"); return scores; } requestURL += _T("&username="******"&user_token=") + EncodeURL( m_UserToken ); } if ( limit > 0 ) { requestURL += _T("&limit=") + limitString; } if ( tableId > 0 ) { requestURL += _T("&table_id=") + tableIdString; } // Send the request. ret = SendRequest( output, requestURL ); if ( !ret ) { m_ErrorMessage += _T("(Could not get the scores.)"); return scores; } // Parse the output. ret = ParseOutputString( output, parsedOutput ); if ( !ret ) { m_ErrorMessage += _T("(Could not get the scores.)"); return scores; } Score score; for ( it = parsedOutput.begin(); it != parsedOutput.end(); it++ ) { scoreInfo = (*it); score = Score(); score.Initialize( this, scoreInfo ); scores.push_back( score ); } return scores; }
bool GameJoltAPI::RemoveDataStoreItem( DataStoreItem item ) { CStdString output; CStdString gameIDString; CStdString requestURL; vector<map<CStdString, CStdString>> parsedOutput; bool ret = true; // Game ID must be set. if ( m_GameID <= 0 ) { m_ErrorMessage += _T("(The game ID must be set.)"); return false; } // We must format the Game ID to a string. gameIDString.Format( _T("%d"), m_GameID ); requestURL = _T("/data-store/remove/?game_id=") + gameIDString + _T("&key=") + EncodeURL( item.GetKey() ); if ( item.GetType() == DataStoreItem::USER ) { // Username must be set. if ( m_Username == _T("") ) { m_ErrorMessage += _T("(The username must be set.)"); return false; } // User token must be set. if ( m_UserToken == _T("") ) { m_ErrorMessage += _T("(The user token must be set.)"); return false; } requestURL += _T("&username="******"&user_token=") + EncodeURL( m_UserToken ); } // Send the request. ret = SendRequest( output, requestURL ); if ( !ret ) { m_ErrorMessage += _T("(Could not remove the data item.)"); return false; } // Parse the output. ret = ParseOutputString( output, parsedOutput ); if ( !ret ) { m_ErrorMessage += _T("(Could not remove the data item.)"); return false; } if ( parsedOutput.front()["success"] == _T("false") ) { m_ErrorMessage += parsedOutput.front()["message"]; return false; } return true; }
bool GameJoltAPI::AddScore( CStdString score, int sort, int tableId /* = 0 */, CStdString extraData /* = _T("") */, CStdString guest /* = _T("") */ ) { CStdString output; CStdString gameIDString; CStdString tableIdString; CStdString sortString; CStdString requestURL; vector<map<CStdString, CStdString>> parsedOutput; bool ret = true; // Game ID must be set. if ( m_GameID <= 0 ) { m_ErrorMessage += _T("(The game ID must be set.)"); return false; } // We must format the Game ID to a string. gameIDString.Format( _T("%d"), m_GameID ); sortString.Format( _T("%d"), sort ); tableIdString.Format( _T("%d"), tableId ); requestURL = _T("/scores/add/?game_id=") + gameIDString + _T("&score=") + EncodeURL( score ) + _T("&sort=") + sortString + _T("&extra_data=") + EncodeURL( extraData ); if ( guest == _T("") ) { // Username must be set. if ( m_Username == _T("") ) { m_ErrorMessage += _T("(The username must be set.)"); return false; } // User token must be set. if ( m_UserToken == _T("") ) { m_ErrorMessage += _T("(The user token must be set.)"); return false; } requestURL += _T("&username="******"&user_token=") + EncodeURL( m_UserToken ); } else { requestURL += _T("&guest=") + EncodeURL( guest ); } // Did they pass in a table ID? if ( tableId > 0 ) { requestURL += _T("&table_id=") + tableIdString; } // Send the request. ret = SendRequest( output, requestURL ); if ( !ret ) { m_ErrorMessage += _T("(Could not add the score.)"); return false; } // Parse the output. ret = ParseOutputString( output, parsedOutput ); if ( !ret ) { m_ErrorMessage += _T("(Could not add the score.)"); return false; } if ( parsedOutput.front()["success"] == _T("false") ) { m_ErrorMessage += parsedOutput.front()["message"]; return false; } return true; }
vector<CStdString> GameJoltAPI::GetDataStoreKeys( DataStoreItem::Type type ) { CStdString output; CStdString gameIDString; CStdString requestURL; vector<map<CStdString, CStdString>> parsedOutput; vector<map<CStdString, CStdString>>::iterator it; vector<CStdString> dataKeys; bool ret = true; // Game ID must be set. if ( m_GameID <= 0 ) { m_ErrorMessage += _T("(The game ID must be set.)"); return dataKeys; } // We must format the Game ID to a string. gameIDString.Format( _T("%d"), m_GameID ); requestURL = _T("/data-store/get-keys/?game_id=") + gameIDString; if ( type == DataStoreItem::USER ) { // Username must be set. if ( m_Username == _T("") ) { m_ErrorMessage += _T("(The username must be set.)"); return dataKeys; } // User token must be set. if ( m_UserToken == _T("") ) { m_ErrorMessage += _T("(The user token must be set.)"); return dataKeys; } requestURL += _T("&username="******"&user_token=") + EncodeURL( m_UserToken ); } // Send the request. ret = SendRequest( output, requestURL ); if ( !ret ) { m_ErrorMessage += _T("(Could not get the data storage keys.)"); return dataKeys; } // Parse the output. ret = ParseOutputString( output, parsedOutput ); if ( !ret ) { m_ErrorMessage += _T("(Could not get the data storage keys.)"); return dataKeys; } for ( it = parsedOutput.begin(); it != parsedOutput.end(); it++ ) { dataKeys.push_back( (*it)["key"] ); } return dataKeys; }
bool GameJoltAPI::PopulateTrophyInfo() { CStdString output; CStdString gameIDString; vector<map<CStdString, CStdString>> parsedOutput; vector<map<CStdString, CStdString>>::iterator it; map<CStdString, CStdString> trophyInfo; bool ret = true; int trophyID = 0; // Game ID must be set. if ( m_GameID <= 0 ) { m_ErrorMessage += _T("(The game ID must be set.)"); return false; } // Username must be set. if ( m_Username == _T("") ) { m_ErrorMessage += _T("(The username must be set.)"); return false; } // User token must be set. if ( m_UserToken == _T("") ) { m_ErrorMessage += _T("(The user token must be set.)"); return false; } // We must format the Game ID to a string. gameIDString.Format( _T("%d"), m_GameID ); // Send the request. ret = SendRequest( output, _T("/trophies/?game_id=") + gameIDString + _T("&username="******"&user_token=") + EncodeURL( m_UserToken ) ); if ( !ret ) { m_ErrorMessage += _T("(Could not populate the trophy information.)"); return false; } // Parse the output. ret = ParseOutputString( output, parsedOutput ); if ( !ret ) { m_ErrorMessage += _T("(Could not populate the trophy information.)"); return false; } for ( it = parsedOutput.begin(); it != parsedOutput.end(); it++ ) { trophyInfo = (*it); trophyID = atoi( CStdStringA( trophyInfo["id"] ) ); m_Trophies[trophyID] = Trophy(); m_Trophies[trophyID].Initialize( this, trophyInfo ); } m_TrophiesPopulated = true; return true; }
bool GameJoltAPI::AddAchievedTrophy( int trophyID ) { m_ErrorMessage = _T(""); bool ret; CStdString output; CStdString gameIDString; CStdString trophyIDString; // Game ID must be set. if ( m_GameID <= 0 ) { m_ErrorMessage += _T("(The game ID must be set.)"); return false; } // Username must be set. if ( m_Username == _T("") ) { m_ErrorMessage += _T("(The username must be set.)"); return false; } // User token must be set. if ( m_UserToken == _T("") ) { m_ErrorMessage += _T("(The user token must be set.)"); return false; } // Trophy ID must be set. if ( trophyID <= 0 ) { m_ErrorMessage += _T("(The trophy ID is wrong.)"); return false; } // Format ints to strings. gameIDString.Format( _T("%d"), m_GameID ); trophyIDString.Format( _T("%d"), trophyID ); ret = SendRequest( output, _T("/trophies/add-achieved/?game_id=") + gameIDString + _T("&username="******"&user_token=") + EncodeURL( m_UserToken ) + _T("&trophy_id=") + trophyIDString ); if ( !ret ) { m_ErrorMessage += _T("(Could not add the trophy for the user.)"); return false; } return true; }
bool GameJoltAPI::AuthUser() { m_ErrorMessage = _T(""); bool ret = true; CStdString output; CStdString gameIDString; vector<map<CStdString, CStdString>> parsedOutput; // Game ID must be set. if ( m_GameID <= 0 ) { m_ErrorMessage += _T("(The game ID must be set.)"); return true; } // Username must be set. if ( m_Username == _T("") ) { m_ErrorMessage += _T("(The username must be set.)"); return false; } // User token must be set. if ( m_UserToken == _T("") ) { m_ErrorMessage += _T("(The user token must be set.)"); return false; } // We must format the Game ID to a string. gameIDString.Format( _T("%d"), m_GameID ); ret = SendRequest( output, _T("/users/auth/?game_id=") + gameIDString + _T("&username="******"&user_token=") + EncodeURL( m_UserToken ) ); if ( !ret ) { return false; m_ErrorMessage += _T("(Could not authenticate the user.)"); } ret = ParseOutputString( output, parsedOutput ); if ( !ret ) { m_ErrorMessage += _T("(Could not authenticate the user.)"); return false; } if ( parsedOutput.front()["success"] == _T("true") ) return true; return false; }
FAR ULONG PASCAL MAPISendMail( LHANDLE lhSession, ULONG ulUIParam, lpMapiMessage lpMessage, FLAGS flFlags, ULONG ulReserved ) { #ifdef DEBUG_BOX MessageBox(NULL, "MAPISendMail", NULL, MB_OK); #endif ostrstream out; bool q_mark = true; // Do basic mailto out << "mailto:"; // Look for recipients for(int i = 0; i < lpMessage->nRecipCount; i++) { // Check on recip type and copy in header detail switch(lpMessage->lpRecips[i].ulRecipClass) { case MAPI_ORIG: continue; case MAPI_TO: out << (q_mark ? "?" : "&") << "to="; break; case MAPI_CC: out << (q_mark ? "?" : "&") << "cc="; break; case MAPI_BCC: out << (q_mark ? "?" : "&") << "bcc="; break; } q_mark = false; // copy in address detail const char* p = lpMessage->lpRecips[i].lpszAddress; if (!::strncmp(p, "SMTP:", 5)) p += 5; char* encoded = EncodeURL(p); out << (encoded ? encoded : p); if (encoded) free(encoded); } // Look for subject if (lpMessage->lpszSubject && *lpMessage->lpszSubject) { char* encoded = EncodeURL(lpMessage->lpszSubject); out << (q_mark ? "?" : "&") << "subject=" << (encoded ? encoded : lpMessage->lpszSubject); q_mark = false; if (encoded) free(encoded); } // Look for body if (lpMessage->lpszNoteText && *lpMessage->lpszNoteText) { char* encoded = EncodeURL(lpMessage->lpszNoteText); out << (q_mark ? "?" : "&") << "body=" << (encoded ? encoded : lpMessage->lpszNoteText); q_mark = false; if (encoded) free(encoded); } // Look for files for(int i = 0; i < lpMessage->nFileCount; i++) { // Get name of attachment const char* fpath = lpMessage->lpFiles[i].lpszPathName; const char* fname = lpMessage->lpFiles[i].lpszFileName; if (!fname || !*fname || strrchr(fname, '\\')) { fname = strrchr(fpath, '\\'); if (fname) fname++; } // Must duplicate this attachment into Temp char temp_path[MAX_PATH]; char temp_path_[MAX_PATH]; char temp_dir[MAX_PATH]; if (GetTempPath(MAX_PATH, temp_dir)) { strcpy(temp_path, temp_dir); strcpy(temp_path_, temp_dir); strcat(temp_path_, "_"); strcat(temp_path, fname); strcat(temp_path_, fname); } else { #ifdef DEBUG_BOX DWORD err = GetLastError(); char temp_err[1024]; snprintf(temp_err, 1024, "No temp directory, errno = %ld", err); MessageBox(NULL, temp_err, NULL, MB_OK); #endif // Fail if no temp directory return MAPI_E_FAILURE; } // If source file is in TEMP then we must copy it if (!strncmp(temp_dir, fpath, strlen(temp_dir))) { // Do copy to standard name if (!CopyFile(fpath, temp_path_, true)) { DWORD last_err = GetLastError(); #ifdef DEBUG_BOX char temp_err[1024]; snprintf(temp_err, 1024, "Orig. file: \"%s\" Temp. file: \"%s\" errno = %ld", fpath, temp_path_, last_err); MessageBox(NULL, temp_err, NULL, MB_OK); #endif if (last_err == ERROR_FILE_EXISTS) { DeleteFile(temp_path_); if (!CopyFile(fpath, temp_path_, true)) { #ifdef DEBUG_BOX DWORD err = GetLastError(); char temp_err[1024]; snprintf(temp_err, 1024, "Unable to copy to temp directory after removal, errno = %ld", err); MessageBox(NULL, temp_err, NULL, MB_OK); #endif return MAPI_E_FAILURE; } } else { return MAPI_E_FAILURE; } } strcpy(temp_path, temp_path_); } else strcpy(temp_path, fpath); // Encode attachment name and add to URL char* encoded = EncodeURL(temp_path); out << (q_mark ? "?" : "&") << "x-mulberry-file=" << (encoded ? encoded : temp_path); q_mark = false; if (encoded) free(encoded); } // NULL terminate the string out << ends; #ifdef DEBUG_BOX MessageBox(NULL, out.str(), NULL, MB_OK); out.freeze(false); #endif // Now do Shell open of mailto URL char dir[MAX_PATH]; if (GetCurrentDirectory(MAX_PATH, dir)) { ShellExecute((HWND) ulUIParam, "open", out.str(), 0L, dir, 0); out.freeze(false); } return SUCCESS_SUCCESS; }