Skip to content

Commit

Permalink
Revert everything since 6th September 2015
Browse files Browse the repository at this point in the history
This is commit 73786dc
  • Loading branch information
qaisjp committed Dec 9, 2015
1 parent 056f668 commit 8d2828a
Show file tree
Hide file tree
Showing 830 changed files with 15,983 additions and 139,147 deletions.
10 changes: 10 additions & 0 deletions MTA10/ceflauncher/CCefApp.h
Expand Up @@ -72,6 +72,7 @@ class CCefApp : public CefApp, public CefRenderProcessHandler

// Bind V8 --> C++ functions
V8Helpers::BindV8Function ( handler, mtaObject, "triggerEvent", Javascript_triggerEvent );
// V8Helpers::BindV8Function ( handler, mtaObject, "triggerServerEvent", Javascript_triggerServerEvent ); // Disabled due to security issues

// Assign mtaObject to global object
globalObject->SetValue ( "mta", mtaObject, V8_PROPERTY_ATTRIBUTE_NONE );
Expand All @@ -86,6 +87,15 @@ class CCefApp : public CefApp, public CefRenderProcessHandler
frame->GetBrowser ()->SendProcessMessage ( PID_BROWSER, message );
}

static void Javascript_triggerServerEvent ( CefRefPtr<CefFrame> frame, const CefV8ValueList& arguments )
{
if ( arguments.size () == 0 )
return;

CefRefPtr<CefProcessMessage> message = V8Helpers::SerialiseV8Arguments ( "TriggerServerLuaEvent", arguments );
frame->GetBrowser ()->SendProcessMessage ( PID_BROWSER, message );
}

public:
IMPLEMENT_REFCOUNTING(CCefApp);

Expand Down
4 changes: 4 additions & 0 deletions MTA10/core/CCommandFuncs.cpp
Expand Up @@ -24,6 +24,10 @@ 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: 29 additions & 52 deletions MTA10/core/CCommunity.cpp
Expand Up @@ -90,8 +90,7 @@ void CCommunity::Login ( VERIFICATIONCALLBACK pCallBack, void* pObject )
szSerial );

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

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


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

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

// 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);
}
char *szBuffer = buffer.GetData ();

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 ();
}
// 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 ();
}
}
}
8 changes: 3 additions & 5 deletions MTA10/core/CCommunity.h
Expand Up @@ -15,6 +15,7 @@
#define __CCOMMUNITY_H

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

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

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

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:
CHTTPClient m_HTTP;

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

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

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

// Store the start time
m_ulStartTime = CClientTime::GetTime ();
Expand Down Expand Up @@ -155,101 +154,81 @@ void CCommunityRegistration::DoPulse ( void )
{
if ( m_ulStartTime > 0 )
{
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 ();

// Sure we have it all right?
if ( uiBufferLength > 32 )
CHTTPBuffer buffer;
if ( m_HTTP.GetData ( buffer ) )
{
// Get the hash
m_strCommunityHash = std::string ( &szBuffer[1], 32 );
char* szBuffer = buffer.GetData ();
unsigned int uiBufferLength = buffer.GetSize ();

// TODO: Load it without a temp file
// Succeed, deal with the response
m_ulStartTime = 0;

// 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 ();
// ID
eRegistrationResult Result = (eRegistrationResult)(szBuffer[0] - 48);

// Delete the temp file
remove ( CalcMTASAPath( REGISTRATION_TEMP_FILE ) );
return;
if ( Result == REGISTRATION_ERROR_REQUEST )
{
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 ();
}
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 @@ -290,7 +269,7 @@ bool CCommunityRegistration::OnButtonRegisterClick ( CGUIElement* pElement )
Md5HashString ( m_pEditPassword->GetText().c_str(), strPassword );

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

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

// Store the start time
m_ulStartTime = CClientTime::GetTime ();
Expand Down
7 changes: 3 additions & 4 deletions MTA10/core/CCommunityRegistration.h
Expand Up @@ -49,10 +49,6 @@ 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 @@ -79,6 +75,9 @@ class CCommunityRegistration
CGUIButton* m_pButtonRegister;
CGUIButton* m_pButtonCancel;

// Community stuff
CHTTPClient m_HTTP;

std::string m_strCommunityHash;

unsigned long m_ulStartTime;
Expand Down
5 changes: 1 addition & 4 deletions MTA10/core/CConnectManager.cpp
Expand Up @@ -60,9 +60,6 @@ bool CConnectManager::Connect ( const char* szHost, unsigned short usPort, const

m_bNotifyServerBrowser = bNotifyServerBrowser;

// For detecting startup problems
WatchDogUserDidInteractWithMenu();

// Hide certain questions
CCore::GetSingleton ().GetLocalGUI ()->GetMainMenu ()->GetQuestionWindow ()->OnConnect ();

Expand Down Expand Up @@ -479,6 +476,6 @@ void CConnectManager::OpenServerFirewall( in_addr Address, ushort usHttpPort, bo
uiTimeOut = 1000;
}

SString strDummyUrl( "http://%s:%d/mta_client_firewall_probe/", inet_ntoa( Address ), usHttpPort );
SString strDummyUrl( "http://%s:%d/.dummy/", inet_ntoa( Address ), usHttpPort );
g_pCore->GetNetwork()->GetHTTPDownloadManager( EDownloadMode::CONNECT_TCP_SEND )->QueueFile( strDummyUrl, NULL, 0, "", 0, true, NULL, NULL, false, 1, uiTimeOut );
}

0 comments on commit 8d2828a

Please sign in to comment.