bool CLoginHelper::CheckSteamLogin() { r3d_assert(gSteam.steamID); r3d_assert(gSteam.authToken.getSize() > 0); CkString ticket; gSteam.authToken.encode("hex", ticket); CWOBackendReq req("api_SteamLogin.aspx"); req.AddParam("ticket", ticket.getAnsi()); if(!req.Issue()) { r3dOutToLog("CheckSteamLogin: failed %d\n", req.resultCode_); return false; } int n = sscanf(req.bodyStr_, "%d %d %d", &CustomerID, &SessionID, &AccountStatus); if(n != 3) { r3dOutToLog("CheckSteamLogin: bad answer %s\n", req.bodyStr_); return false; } return true; }
void CClientUserProfile::GenerateSessionKey(char* outKey) { char sessionInfo[128]; sprintf(sessionInfo, "%d:%d", CustomerID, SessionID); for(size_t i=0; i<strlen(sessionInfo); ++i) sessionInfo[i] = sessionInfo[i]^0x64; CkString str; str = sessionInfo; str.base64Encode("utf-8"); strcpy(outKey, str.getUtf8()); return; }
void CLoginHelper::CreateAuthToken(char* token) const { char sessionInfo[512]; sprintf(sessionInfo, "%d:%d:%d", CustomerID, SessionID, AccountStatus); for(size_t i=0; i<strlen(sessionInfo); ++i) sessionInfo[i] = sessionInfo[i] ^ 0x64; CkString encoded; encoded = sessionInfo; encoded.base64Encode("utf-8"); strcpy(token, encoded.getAnsi()); return; }
/*Realiza a contagem de níveis de uma dada URL. Essa contagem é feita da seguinte maneira, primeiramente efetuo a remoção de protolos e www's. Após feito isso, conto a quantidade de 'Pontos' contidas no URLDomain e BaseDomain, realizo a subtração entre BaseDomain-UrlDomain, dessa forma eu verifico a quantidade de níveis existentes no domínio. Em seguida, verifico a quantidade de '/' e multiplico por 10. Realizo a soma desses valores e obtenho assim o level do url passado. Por último, retorno o Link; */ Links getLevelUrl(CkString url){ CkSpider tempSpider; int i = 0,level = 0; CkString urls, DomaintempUrl,BaseDomainTemp,tempUrl, checkbr; tempUrl = url; CkString aux1, aux2, aux3, aux4; aux1 = "http://"; aux2 = "https://"; aux3 = "www."; aux4 = "ftp://"; tempUrl.removeFirst(aux1); tempUrl.removeFirst(aux2); tempUrl.removeFirst(aux3); tempUrl.removeFirst(aux4); tempSpider.GetUrlDomain(tempUrl,DomaintempUrl); BaseDomainTemp = tempSpider.getBaseDomain(url); // cout << "BaseDomain: " << BaseDomainTemp.getString() <<" URLDOMAIN: "<< DomaintempUrl.getString()<<endl; level = DomaintempUrl.countCharOccurances('.') - BaseDomainTemp.countCharOccurances('.'); if (tempUrl.getNumChars()>0){ tempUrl.shorten(1); } level += 10 * tempUrl.countCharOccurances('/'); Links newLink; newLink.url = url.getString(); newLink.level = level; return newLink; }
void CSupervisorServer::StartGame(const SBPKT_M2S_StartGameReq_s& n) { r3dCSHolder cs1(csGames_); const int slot = n.port - gSupervisorConfig->portStart_; if(slot < 0 || slot >= gSupervisorConfig->maxGames_) { r3dOutToLog("!!!warning!!! invalid StartGame request port %d", n.port); return; } if(games_[slot].hProcess != 0) { r3dOutToLog("!!!warning!!! invalid StartGame request, slot %d already used\n", slot); // this may be because of previous instance crash, so terminate it TerminateProcess(games_[slot].hProcess, 0); games_[slot].Reset(); } r3dOutToLog("StartGame %I64x slot:%d, users:%d, id:%08x, creatorID:%u\n", n.sessionId, slot, n.ginfo.maxPlayers, n.gameId, n.creatorID); CLOG_INDENT; games_[slot].Init(n.gameId, n.sessionId); STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); PROCESS_INFORMATION pi; ZeroMemory(&pi, sizeof(pi)); char arg1[128]; char arg2[128]; char arg3[128]; sprintf(arg1, "%u %u %u", n.gameId, n.port, n.creatorID); n.ginfo.ToString(arg2); r3dscpy(arg3, gSupervisorConfig->masterIp_.c_str()); CkString ckGameName; CkString ckGamepwd; ckGameName.setString(n.ginfo.name); ckGameName.base64Encode("utf-8"); // ckGamepwd.setString(n.ginfo.IsPassword); //ckGamepwd.base64Encode("utf-8"); char argfap[128]; sprintf(argfap,arg2); sprintf(arg2,"%d %s %d",(int)n.ginfo.ispre,argfap,(int)n.ginfo.ispass); char params[512]; sprintf(params, "\"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%d\"", gSupervisorConfig->gameServerExe_.c_str(), arg1, arg2, arg3, ckGameName.getString(), gSupervisorConfig->uploadLogs_ ); r3dOutToLog("CreateProcess: %s\n", params); BOOL res = CreateProcess( NULL, params, NULL, NULL, FALSE, DETACHED_PROCESS, // no console by default, if needed game server will alloc it NULL, NULL, &si, &pi); if(res == 0) { r3dOutToLog("!!!warning!!! unable to spawn game servers, hr:%d\n", GetLastError()); games_[slot].Reset(); return; } // set process handle games_[slot].hProcess = pi.hProcess; return; }
//--------------------------------------------------------------------------------------- void envelope_parser::fetch_addrs( addr_type at ) { //cached line string cached_addr{}; //cached address string cached_from{}; //addr line ostringstream line_strm; //// while( at != addr_type::atNoMoreAddrs ) { switch ( at ) { case addr_type::atFrom : { CkString cks; //personal m_email_ptr->get_FromName( cks ); string str( cks.getString() ); line_strm << addr_atom( str ); //smtp route str = empty; line_strm << addr_atom( str ); m_email_ptr->get_FromAddress( cks ); str = cks.getString(); //friendly name string friendly( friendly_name( str ) ); line_strm << addr_atom( friendly ); //address line_strm << addr_atom( str ); str = line_strm.str(); boost::algorithm::trim( str ); cached_addr = str; m_email_ptr->get_From( cks ); cached_from = cks.getString(); single_addr_line( str ); at = addr_type::atSender; continue; } case addr_type::atSender : { CkString cks; //treatment often ambigous by client and server bool b_ret = m_email_ptr->GetHeaderField( sender.c_str() , cks ); //no sender , use from if( b_ret == false ) { single_addr_line( cached_addr ); } else single_sender_addr_line( cks.getString() ); at = addr_type::atReplyTo ; continue; } case addr_type::atReplyTo : { CkString cks; bool b_ret = m_email_ptr->GetHeaderField( reply_to.c_str() , cks ); //no reply to , use from if( b_ret == false ) { single_addr_line( cached_addr ); } else single_sender_addr_line( cks.getString() ); at = addr_type::atTo ; continue; } case addr_type::atTo : case addr_type::atCC : case addr_type::atBCC : { line_strm.str( empty ); unsigned long dw = m_email_ptr->get_NumTo(); addr_pr apr; addr_container actr; //to for ( unsigned long i = 0; i <= dw - 1; i++ ) { apr.first = m_email_ptr->getToName( i ); apr.second = m_email_ptr->getToAddr( i ); actr.push_back( apr ); process_multiple_addrs( actr ); } //cc actr.clear(); dw = m_email_ptr->get_NumCC(); if( dw == 0 ) { nil_addr_line(); } else { for ( unsigned long i = 0; i <= dw - 1; i++ ) { apr.first = m_email_ptr->getCcAddr( i ); apr.second = m_email_ptr->getCcName( i ) ; actr.push_back( apr ); process_multiple_addrs( actr ); } } //bcc actr.clear(); dw = m_email_ptr->get_NumBcc(); if( dw == 0 ) { nil_addr_line(); } else { for ( unsigned long i = 0; i <= dw - 1; i++ ) { apr.first = m_email_ptr->getBccAddr( i ); apr.second = m_email_ptr->getBccName( i ) ; actr.push_back( apr ); process_multiple_addrs( actr ); } } at = addr_type::atNoMoreAddrs; } } } }
bool SmtpThread::sendEmail(bool &bFailureIsFinal) { // This must get set to false for a known case where it might be possible // to retry... bFailureIsFinal = true; CkString strEmlPath; fullFilePath(m_queueDir.c_str(),m_filename.c_str(),strEmlPath); // First load the email. CkByteData mimeData; bool success = mimeData.loadFile(strEmlPath.getString()); if (!success) { // Does the file exist? logNameValue("FailedToLoad",m_filename); CkFileAccess fac; if (fac.FileExists(strEmlPath.getString())) { logString("File may be locked by another process, will retry..."); bFailureIsFinal = false; } else { logString("File does not exist."); } return false; } // We pass 0 for the From and Recipients args because that info is embedded within the mimeData. // The special x-smtp* headers will be decoded and removed before sending. // All of the MailMan property settings (SMTP host, login, password, etc.) as well as the From/Recipient // information is contained in the x-smtp* headers. success = m_mailman->SendMimeBytes((const char *)0,(const char *)0,mimeData); if (!success) { string errText = m_mailman->lastErrorText(); logNameValue("SendMimeBytes",errText); // We can retry from some errors... string failReason = m_mailman->smtpFailReason(); logNameValue("SmtpFailReason",failReason); if (failReason == "Timeout" || failReason == "ConnectionLost" || failReason == "FromFailure" || failReason == "DataFailure" || failReason == "GreetingError" || failReason == "ConnectFailed") { bFailureIsFinal = false; } // Make sure the SMTP connection is closed after a failure. m_mailman->CloseSmtpConnection(); } return success; }
// Loads the file, sends the email, and logs the results. // Sets the m_running flag to false when done. void SmtpThread::runThread(void) { int tryCount = 0; CkString lastErrorText; tryAgain: if (!m_logErrorsOnly) { if (tryCount > 0) { logNameValue("Re-trying",m_filename); logNameValueInt("TryCount",tryCount + 1); } else { logNameValue("Sending",m_filename); } } bool success = false; bool bFailureIsFinal = true; success = sendEmail(bFailureIsFinal); m_mailman->get_LastErrorText(lastErrorText); if (success) { if (m_saveSent) { moveToSentDir(); } else { CkString strEmlPath; fullFilePath(m_queueDir.c_str(),m_filename.c_str(),strEmlPath); #if defined(TEST_SMTPQ) logNameValue("deletingFile3",strEmlPath.getString()); #endif BOOL b = DeleteFile(strEmlPath.getString()); if (!b) { CkString strWindowsError; strWindowsError.appendLastWindowsError(); logNameValue("Failed to delete file",m_filename); logNameValue("WindowsError",strWindowsError.getString()); // This EML was abandoned in the queue directory.. m_emlAbandoned = true; } } if (!m_logErrorsOnly) { logNameValue("Send successful",m_filename); } } else if (bFailureIsFinal || (!m_maxRetryCount) || (tryCount > m_maxRetryCount)) { if (bFailureIsFinal) { logNameValue("Send Failed, error is final and a retry won't succeed.",m_filename); } else { logNameValue("Send Failed, no more retries",m_filename); } CkString strEmlPath; fullFilePath(m_queueDir.c_str(),m_filename.c_str(),strEmlPath); CkString strToPath; fullFilePath(m_undeliverableDir.c_str(),m_filename.c_str(),strToPath); #if defined(TEST_SMTPQ) logNameValue("movingFile2",strEmlPath.getString()); logNameValue("movingTo2",strToPath.getString()); #endif if (!MoveFile(strEmlPath.getString(),strToPath.getString())) //if (!MoveFile(strEmlPath.getString(),m_undeliverableDir.c_str())) { #if defined(TEST_SMTPQ) logNameValue("deletingFile2",strEmlPath.getString()); #endif if (!DeleteFile(strEmlPath.getString())) { // This EML was abandoned in the queue directory.. m_emlAbandoned = true; } } } else { logString(lastErrorText.getString()); logNameValue("Send Failed, will try again",m_filename); tryCount++; int delayMs = 1000; /* tryCount delayTime -------- --------- 1 5 sec 2 10 sec 3 15 sec 4 1 min 5 1.5 minutes 6 2 minutes 7 5 minutes 8 10 minutes 9 15 minutes 10 20 minutes */ if (tryCount < 4) { // 5 seconds * tryCount delayMs = 5000 * tryCount; } else if (tryCount < 7) { delayMs = 30000 * (tryCount-2); } else // up to g_maxRetryCount (max 10) tries { delayMs = 300000 * (tryCount-6); } logNameValueInt("tryCount",tryCount); logNameValueInt("sleepMillisec",delayMs); // When waiting for the retry, continue updating the heartbeat so that the ThreadManager // knows the thread is not dead. while (delayMs) { int t = delayMs > 1000 ? 1000 : delayMs; ::Sleep(t); delayMs -= t; } goto tryAgain; } m_running = false; return; }
void SmtpThread::moveToSentDir(void) { CkString strEmlPath; fullFilePath(m_queueDir.c_str(),m_filename.c_str(),strEmlPath); CkString strToPath; fullFilePath(m_sentDir.c_str(),m_filename.c_str(),strToPath); #if defined(TEST_SMTPQ) logNameValue("movingFile",strEmlPath.getString()); logNameValue("movingTo",strToPath.getString()); #endif if (!MoveFile(strEmlPath.getString(),strToPath.getString())) { CkString strWindowsError; strWindowsError.appendLastWindowsError(); logString("Failed to move file to sent directory.."); logNameValue("WindowsError",strWindowsError.getString()); logNameValue("EML file",m_filename); logNameValue("Sent directory",m_sentDir); #if defined(TEST_SMTPQ) logNameValue("deletingFile4",strEmlPath.getString()); #endif if (!DeleteFile(strEmlPath.getString())) { CkString strWindowsError; strWindowsError.appendLastWindowsError(); logNameValue("Failed to delete file",m_filename); logNameValue("WindowsError",strWindowsError.getString()); // This EML was abandoned in the queue directory.. m_emlAbandoned = true; } } return; }