Skip to content

Commit

Permalink
Removed old tracking/http code
Browse files Browse the repository at this point in the history
  • Loading branch information
ccw808 committed Oct 21, 2015
1 parent 15e450e commit e319788
Show file tree
Hide file tree
Showing 24 changed files with 155 additions and 1,498 deletions.
4 changes: 0 additions & 4 deletions MTA10/core/CCommandFuncs.cpp
Expand Up @@ -24,10 +24,6 @@ extern bool g_bBoundsChecker;

#define MTA_HELP_SPACING 32

/* ACHTUNG */
#include "tracking/CTCPManager.h"
#include "tracking/CHTTPClient.h"

void CCommandFuncs::Help ( const char* szParameters )
{
CConsoleInterface* pConsole = g_pCore->GetConsole ();
Expand Down
81 changes: 52 additions & 29 deletions MTA10/core/CCommunity.cpp
Expand Up @@ -90,7 +90,8 @@ void CCommunity::Login ( VERIFICATIONCALLBACK pCallBack, void* pObject )
szSerial );

// Perform the HTTP request
m_HTTP.Get ( strURL );
GetHTTP()->Reset();
GetHTTP()->QueueFile( strURL, NULL, 0, NULL, 0, false, this, StaticDownloadFinished, false, 1/*uiConnectionAttempts*/ );

// Store the start time
m_ulStartTime = CClientTime::GetTime ();
Expand All @@ -101,34 +102,56 @@ void CCommunity::DoPulse ( void )
{
if ( m_ulStartTime )
{
eVerificationResult Status;
GetHTTP()->ProcessQueuedFiles();
}
}


// Get the HTTP download manager used for community stuff
CNetHTTPDownloadManagerInterface* CCommunity::GetHTTP( void )
{
return g_pCore->GetNetwork()->GetHTTPDownloadManager( EDownloadMode::CORE_UPDATER );
}

// Poll the HTTP client
CHTTPBuffer buffer;
if ( m_HTTP.GetData ( buffer ) ) {

char *szBuffer = buffer.GetData ();
// Handle server response
bool CCommunity::StaticDownloadFinished ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
{
if ( bSuccess )
((CCommunity*)pObj)->DownloadSuccess( pCompletedData, completedLength );
else
((CCommunity*)pObj)->DownloadFailed( iErrorCode );
return true;
}

void CCommunity::DownloadSuccess( char* pCompletedData, size_t completedLength )
{
// Get the returned status
eVerificationResult Status = VERIFY_ERROR_UNEXPECTED;
if ( completedLength > 0 )
{
Status = (eVerificationResult)(pCompletedData[0] - 48);
}

// Get the returned status
Status = (eVerificationResult)(szBuffer[0] - 48);
m_bLoggedIn = Status == VERIFY_ERROR_SUCCESS;
m_ulStartTime = 0;

// Change GUI
CLocalGUI::GetSingleton ().GetMainMenu()->ChangeCommunityState ( m_bLoggedIn, m_strUsername );
CLocalGUI::GetSingleton ().GetMainMenu()->GetSettingsWindow()->OnLoginStateChange ( m_bLoggedIn );

// Perform callback
if ( m_pCallback ) {
m_pCallback ( m_bLoggedIn, szVerificationMessages[Status], m_pVerificationObject );
m_pCallback = NULL;
m_pVerificationObject = NULL;
}
}
// Check for timeout
else if ( ( CClientTime::GetTime () - m_ulStartTime ) > VERIFICATION_DELAY ) {
g_pCore->ShowMessageBox ( _("Error")+_E("CC01"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
Logout ();
}
}
}
m_bLoggedIn = Status == VERIFY_ERROR_SUCCESS;
m_ulStartTime = 0;

// Change GUI
CLocalGUI::GetSingleton ().GetMainMenu()->ChangeCommunityState ( m_bLoggedIn, m_strUsername );
CLocalGUI::GetSingleton ().GetMainMenu()->GetSettingsWindow()->OnLoginStateChange ( m_bLoggedIn );

// Perform callback
if ( m_pCallback )
{
m_pCallback ( m_bLoggedIn, szVerificationMessages[Status], m_pVerificationObject );
m_pCallback = NULL;
m_pVerificationObject = NULL;
}
}

void CCommunity::DownloadFailed( int iErrorCode )
{
m_ulStartTime = 0;
g_pCore->ShowMessageBox ( _("Error")+_E("CC01"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
Logout ();
}
8 changes: 5 additions & 3 deletions MTA10/core/CCommunity.h
Expand Up @@ -15,7 +15,6 @@
#define __CCOMMUNITY_H

#include <core/CCommunityInterface.h>
#include "tracking/CHTTPClient.h"

typedef void (*VERIFICATIONCALLBACK) ( bool, char*, void* obj );

Expand Down Expand Up @@ -61,9 +60,12 @@ class CCommunity : public CCommunityInterface, public CSingleton < CCommunity >
void Login ( VERIFICATIONCALLBACK pCallBack = NULL, void* pObject = NULL );
void Logout ( void );

private:
CHTTPClient m_HTTP;
CNetHTTPDownloadManagerInterface* GetHTTP ( void );
static bool StaticDownloadFinished ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode );
void DownloadFailed ( int iErrorCode );
void DownloadSuccess ( char* pCompletedData, size_t completedLength );

private:
std::string m_strUsername;
std::string m_strPassword;

Expand Down
166 changes: 94 additions & 72 deletions MTA10/core/CCommunityRegistration.cpp
Expand Up @@ -121,10 +121,11 @@ void CCommunityRegistration::Open ( void )
if ( m_ulStartTime == 0 )
{
// Create the URL
std::string strURL = std::string ( REGISTRATION_URL ) + "?action=request";
SString strURL = std::string ( REGISTRATION_URL ) + "?action=request";

// Perform the HTTP request
m_HTTP.Get ( strURL );
GetHTTP()->Reset();
GetHTTP()->QueueFile( strURL, NULL, 0, NULL, 0, false, this, StaticDownloadFinished, false, 1/*uiConnectionAttempts*/ );

// Store the start time
m_ulStartTime = CClientTime::GetTime ();
Expand Down Expand Up @@ -154,81 +155,101 @@ void CCommunityRegistration::DoPulse ( void )
{
if ( m_ulStartTime > 0 )
{
CHTTPBuffer buffer;
if ( m_HTTP.GetData ( buffer ) )
{
char* szBuffer = buffer.GetData ();
unsigned int uiBufferLength = buffer.GetSize ();
GetHTTP()->ProcessQueuedFiles();
}
}


// Get the HTTP download manager used for community stuff
CNetHTTPDownloadManagerInterface* CCommunityRegistration::GetHTTP( void )
{
return g_pCore->GetNetwork()->GetHTTPDownloadManager( EDownloadMode::CORE_UPDATER );
}


// Handle server response
bool CCommunityRegistration::StaticDownloadFinished ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
{
if ( bSuccess )
((CCommunityRegistration*)pObj)->DownloadSuccess( pCompletedData, completedLength );
else
((CCommunityRegistration*)pObj)->DownloadFailed( iErrorCode );
return true;
}

void CCommunityRegistration::DownloadSuccess( char* szBuffer, size_t uiBufferLength )
{
// Succeed, deal with the response
m_ulStartTime = 0;

// ID
eRegistrationResult Result = REGISTRATION_ERROR_UNEXPECTED;
if ( uiBufferLength > 0 )
(eRegistrationResult)(szBuffer[0] - 48);

if ( Result == REGISTRATION_ERROR_REQUEST )
{
CGUI *pManager = g_pCore->GetGUI ();

// Succeed, deal with the response
m_ulStartTime = 0;
// Sure we have it all right?
if ( uiBufferLength > 32 )
{
// Get the hash
m_strCommunityHash = std::string ( &szBuffer[1], 32 );

// ID
eRegistrationResult Result = (eRegistrationResult)(szBuffer[0] - 48);
// TODO: Load it without a temp file

if ( Result == REGISTRATION_ERROR_REQUEST )
// Create a temp file for the png
FILE * fp = fopen ( CalcMTASAPath( REGISTRATION_TEMP_FILE ), "wb" );
if ( fp )
{
CGUI *pManager = g_pCore->GetGUI ();

// Sure we have it all right?
if ( uiBufferLength > 32 )
{
// Get the hash
m_strCommunityHash = std::string ( &szBuffer[1], 32 );

// TODO: Load it without a temp file

// Create a temp file for the png
FILE * fp = fopen ( CalcMTASAPath( REGISTRATION_TEMP_FILE ), "wb" );
if ( fp )
{
fwrite ( &szBuffer[33], uiBufferLength, 1, fp );
fclose ( fp );

m_pImageCode->LoadFromFile ( "temp.png" );
m_pImageCode->SetSize ( CVector2D ( 65.0f, 20.0f ), false );
m_pWindow->SetVisible ( true );
m_pWindow->BringToFront ();

// Delete the temp file
remove ( CalcMTASAPath( REGISTRATION_TEMP_FILE ) );
return;
}
}
g_pCore->ShowMessageBox ( _("Error")+_E("CC04"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
}
else if ( Result == REGISTRATION_ERROR_SUCCESS )
{
g_pCore->ShowMessageBox ( _("Success")+_E("CC05"), _("Successfully registered!"), MB_BUTTON_OK | MB_ICON_INFO );

m_pWindow->SetVisible ( false );
SetFrozen ( false );
m_strCommunityHash.clear ();
m_pImageCode->Clear ();
fwrite ( &szBuffer[33], uiBufferLength, 1, fp );
fclose ( fp );

m_pImageCode->LoadFromFile ( "temp.png" );
m_pImageCode->SetSize ( CVector2D ( 65.0f, 20.0f ), false );
m_pWindow->SetVisible ( true );
m_pWindow->BringToFront ();

// Delete the temp file
remove ( CalcMTASAPath( REGISTRATION_TEMP_FILE ) );
return;
}
else if ( Result == REGISTRATION_ERROR_ERROR )
{
if ( strlen ( &szBuffer[1] ) > 0 )
g_pCore->ShowMessageBox ( _("Error")+_E("CC06"), &szBuffer[1], MB_BUTTON_OK | MB_ICON_ERROR );
else
g_pCore->ShowMessageBox ( _("Error")+_E("CC07"), "Unexpected error", MB_BUTTON_OK | MB_ICON_ERROR );

SetFrozen ( false );
}
else
{
g_pCore->ShowMessageBox ( _("Error")+_E("CC08"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
SetFrozen ( false );
}
}
else if ( ( CClientTime::GetTime () - m_ulStartTime ) > REGISTRATION_DELAY )
{
g_pCore->ShowMessageBox ( _("Error")+_E("CC10"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
SetFrozen ( false );
// Timed out
m_ulStartTime = 0;
}
g_pCore->ShowMessageBox ( _("Error")+_E("CC04"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
}
else if ( Result == REGISTRATION_ERROR_SUCCESS )
{
g_pCore->ShowMessageBox ( _("Success")+_E("CC05"), _("Successfully registered!"), MB_BUTTON_OK | MB_ICON_INFO );

m_pWindow->SetVisible ( false );
SetFrozen ( false );
m_strCommunityHash.clear ();
m_pImageCode->Clear ();
}
else if ( Result == REGISTRATION_ERROR_ERROR )
{
if ( strlen ( &szBuffer[1] ) > 0 )
g_pCore->ShowMessageBox ( _("Error")+_E("CC06"), &szBuffer[1], MB_BUTTON_OK | MB_ICON_ERROR );
else
g_pCore->ShowMessageBox ( _("Error")+_E("CC07"), "Unexpected error", MB_BUTTON_OK | MB_ICON_ERROR );

SetFrozen ( false );
}
else
{
g_pCore->ShowMessageBox ( _("Error")+_E("CC08"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
SetFrozen ( false );
}
}


void CCommunityRegistration::DownloadFailed( int iErrorCode )
{
g_pCore->ShowMessageBox ( _("Error")+_E("CC10"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
SetFrozen ( false );
// Timed out
m_ulStartTime = 0;
}


Expand Down Expand Up @@ -269,7 +290,7 @@ bool CCommunityRegistration::OnButtonRegisterClick ( CGUIElement* pElement )
Md5HashString ( m_pEditPassword->GetText().c_str(), strPassword );

// Create the URL
std::string strURL =
SString strURL =
std::string ( REGISTRATION_URL ) +
"?action=register" +
"&username=" + m_pEditUsername->GetText() +
Expand All @@ -279,7 +300,8 @@ bool CCommunityRegistration::OnButtonRegisterClick ( CGUIElement* pElement )
"&hash=" + m_strCommunityHash;

// Perform the HTTP request
m_HTTP.Get ( strURL );
GetHTTP()->Reset();
GetHTTP()->QueueFile( strURL, NULL, 0, NULL, 0, false, this, StaticDownloadFinished, false, 1/*uiConnectionAttempts*/ );

// Store the start time
m_ulStartTime = CClientTime::GetTime ();
Expand Down
7 changes: 4 additions & 3 deletions MTA10/core/CCommunityRegistration.h
Expand Up @@ -49,6 +49,10 @@ class CCommunityRegistration

protected:
void CreateWindows ( void );
static bool StaticDownloadFinished ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode );
void DownloadSuccess ( char* pCompletedData, size_t completedLength );
void DownloadFailed ( int iErrorCode );
CNetHTTPDownloadManagerInterface* GetHTTP ( void );

private:

Expand All @@ -75,9 +79,6 @@ class CCommunityRegistration
CGUIButton* m_pButtonRegister;
CGUIButton* m_pButtonCancel;

// Community stuff
CHTTPClient m_HTTP;

std::string m_strCommunityHash;

unsigned long m_ulStartTime;
Expand Down
2 changes: 0 additions & 2 deletions MTA10/core/CCore.cpp
Expand Up @@ -163,7 +163,6 @@ CCore::CCore ( void )
m_pDirectInputHookManager = new CDirectInputHookManager ( );
m_pMessageLoopHook = new CMessageLoopHook ( );
m_pSetCursorPosHook = new CSetCursorPosHook ( );
m_pTCPManager = new CTCPManager ( );

// Register internal commands.
RegisterCommands ( );
Expand Down Expand Up @@ -221,7 +220,6 @@ CCore::~CCore ( void )
//delete m_pFileSystemHook;
delete m_pDirect3DHookManager;
delete m_pDirectInputHookManager;
delete m_pTCPManager;

// Delete the GUI manager
delete m_pLocalGUI;
Expand Down
2 changes: 0 additions & 2 deletions MTA10/core/CCore.h
Expand Up @@ -39,7 +39,6 @@ class CCore;
#include <core/CClientEntityBase.h>
#include <core/CCoreInterface.h>
#include "CDirect3DData.h"
#include "tracking/CTCPManager.h"
#include "CClientVariables.h"
#include "CKeyBinds.h"
#include "CMouseControl.h"
Expand Down Expand Up @@ -297,7 +296,6 @@ class CCore : public CCoreInterface, public CSingleton < CCore >
CDirect3DHookManager * m_pDirect3DHookManager;
//CFileSystemHook * m_pFileSystemHook;
CSetCursorPosHook * m_pSetCursorPosHook;
CTCPManager * m_pTCPManager;

bool m_bLastFocused;
int m_iUnminimizeFrameCounter;
Expand Down
8 changes: 0 additions & 8 deletions MTA10/core/CMessageLoopHook.cpp
Expand Up @@ -249,14 +249,6 @@ LRESULT CALLBACK CMessageLoopHook::ProcessMessage ( HWND hwnd,
if ( CKeyBinds::IsFakeCtrl_L ( uMsg, wParam, lParam ) )
return true;

// See if this is message was caused by our asynchronous sockets
if ( uMsg >= WM_ASYNCTRAP && uMsg <= ( WM_ASYNCTRAP + 511 ))
{
/* ACHTUNG: uMsg - 10? Windows seems to add 10 or there's a bug in the message code. Hack! */
// Let the CTCPManager handle it
CTCPManager::GetSingletonPtr ()->HandleEvent ( ( uMsg - WM_ASYNCTRAP ), wParam, lParam );
}

bool bWasCaptureKey = false;
CMainMenu* pMainMenu = g_pCore->GetLocalGUI ()->GetMainMenu ();
if ( pMainMenu )
Expand Down

0 comments on commit e319788

Please sign in to comment.