Skip to content

Commit 98d9c56

Browse files
committed
Removed old tracking/http code
1 parent fbeff89 commit 98d9c56

24 files changed

+155
-1498
lines changed

MTA10/core/CCommandFuncs.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ extern bool g_bBoundsChecker;
2424

2525
#define MTA_HELP_SPACING 32
2626

27-
/* ACHTUNG */
28-
#include "tracking/CTCPManager.h"
29-
#include "tracking/CHTTPClient.h"
30-
3127
void CCommandFuncs::Help ( const char* szParameters )
3228
{
3329
CConsoleInterface* pConsole = g_pCore->GetConsole ();

MTA10/core/CCommunity.cpp

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ void CCommunity::Login ( VERIFICATIONCALLBACK pCallBack, void* pObject )
9090
szSerial );
9191

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

9596
// Store the start time
9697
m_ulStartTime = CClientTime::GetTime ();
@@ -101,34 +102,56 @@ void CCommunity::DoPulse ( void )
101102
{
102103
if ( m_ulStartTime )
103104
{
104-
eVerificationResult Status;
105+
GetHTTP()->ProcessQueuedFiles();
106+
}
107+
}
108+
109+
110+
// Get the HTTP download manager used for community stuff
111+
CNetHTTPDownloadManagerInterface* CCommunity::GetHTTP( void )
112+
{
113+
return g_pCore->GetNetwork()->GetHTTPDownloadManager( EDownloadMode::CORE_UPDATER );
114+
}
105115

106-
// Poll the HTTP client
107-
CHTTPBuffer buffer;
108-
if ( m_HTTP.GetData ( buffer ) ) {
109116

110-
char *szBuffer = buffer.GetData ();
117+
// Handle server response
118+
bool CCommunity::StaticDownloadFinished ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
119+
{
120+
if ( bSuccess )
121+
((CCommunity*)pObj)->DownloadSuccess( pCompletedData, completedLength );
122+
else
123+
((CCommunity*)pObj)->DownloadFailed( iErrorCode );
124+
return true;
125+
}
126+
127+
void CCommunity::DownloadSuccess( char* pCompletedData, size_t completedLength )
128+
{
129+
// Get the returned status
130+
eVerificationResult Status = VERIFY_ERROR_UNEXPECTED;
131+
if ( completedLength > 0 )
132+
{
133+
Status = (eVerificationResult)(pCompletedData[0] - 48);
134+
}
111135

112-
// Get the returned status
113-
Status = (eVerificationResult)(szBuffer[0] - 48);
114-
m_bLoggedIn = Status == VERIFY_ERROR_SUCCESS;
115-
m_ulStartTime = 0;
116-
117-
// Change GUI
118-
CLocalGUI::GetSingleton ().GetMainMenu()->ChangeCommunityState ( m_bLoggedIn, m_strUsername );
119-
CLocalGUI::GetSingleton ().GetMainMenu()->GetSettingsWindow()->OnLoginStateChange ( m_bLoggedIn );
120-
121-
// Perform callback
122-
if ( m_pCallback ) {
123-
m_pCallback ( m_bLoggedIn, szVerificationMessages[Status], m_pVerificationObject );
124-
m_pCallback = NULL;
125-
m_pVerificationObject = NULL;
126-
}
127-
}
128-
// Check for timeout
129-
else if ( ( CClientTime::GetTime () - m_ulStartTime ) > VERIFICATION_DELAY ) {
130-
g_pCore->ShowMessageBox ( _("Error")+_E("CC01"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
131-
Logout ();
132-
}
133-
}
134-
}
136+
m_bLoggedIn = Status == VERIFY_ERROR_SUCCESS;
137+
m_ulStartTime = 0;
138+
139+
// Change GUI
140+
CLocalGUI::GetSingleton ().GetMainMenu()->ChangeCommunityState ( m_bLoggedIn, m_strUsername );
141+
CLocalGUI::GetSingleton ().GetMainMenu()->GetSettingsWindow()->OnLoginStateChange ( m_bLoggedIn );
142+
143+
// Perform callback
144+
if ( m_pCallback )
145+
{
146+
m_pCallback ( m_bLoggedIn, szVerificationMessages[Status], m_pVerificationObject );
147+
m_pCallback = NULL;
148+
m_pVerificationObject = NULL;
149+
}
150+
}
151+
152+
void CCommunity::DownloadFailed( int iErrorCode )
153+
{
154+
m_ulStartTime = 0;
155+
g_pCore->ShowMessageBox ( _("Error")+_E("CC01"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
156+
Logout ();
157+
}

MTA10/core/CCommunity.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#define __CCOMMUNITY_H
1616

1717
#include <core/CCommunityInterface.h>
18-
#include "tracking/CHTTPClient.h"
1918

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

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

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

68+
private:
6769
std::string m_strUsername;
6870
std::string m_strPassword;
6971

MTA10/core/CCommunityRegistration.cpp

Lines changed: 94 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ void CCommunityRegistration::Open ( void )
121121
if ( m_ulStartTime == 0 )
122122
{
123123
// Create the URL
124-
std::string strURL = std::string ( REGISTRATION_URL ) + "?action=request";
124+
SString strURL = std::string ( REGISTRATION_URL ) + "?action=request";
125125

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

129130
// Store the start time
130131
m_ulStartTime = CClientTime::GetTime ();
@@ -154,81 +155,101 @@ void CCommunityRegistration::DoPulse ( void )
154155
{
155156
if ( m_ulStartTime > 0 )
156157
{
157-
CHTTPBuffer buffer;
158-
if ( m_HTTP.GetData ( buffer ) )
159-
{
160-
char* szBuffer = buffer.GetData ();
161-
unsigned int uiBufferLength = buffer.GetSize ();
158+
GetHTTP()->ProcessQueuedFiles();
159+
}
160+
}
161+
162+
163+
// Get the HTTP download manager used for community stuff
164+
CNetHTTPDownloadManagerInterface* CCommunityRegistration::GetHTTP( void )
165+
{
166+
return g_pCore->GetNetwork()->GetHTTPDownloadManager( EDownloadMode::CORE_UPDATER );
167+
}
168+
169+
170+
// Handle server response
171+
bool CCommunityRegistration::StaticDownloadFinished ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
172+
{
173+
if ( bSuccess )
174+
((CCommunityRegistration*)pObj)->DownloadSuccess( pCompletedData, completedLength );
175+
else
176+
((CCommunityRegistration*)pObj)->DownloadFailed( iErrorCode );
177+
return true;
178+
}
179+
180+
void CCommunityRegistration::DownloadSuccess( char* szBuffer, size_t uiBufferLength )
181+
{
182+
// Succeed, deal with the response
183+
m_ulStartTime = 0;
184+
185+
// ID
186+
eRegistrationResult Result = REGISTRATION_ERROR_UNEXPECTED;
187+
if ( uiBufferLength > 0 )
188+
(eRegistrationResult)(szBuffer[0] - 48);
189+
190+
if ( Result == REGISTRATION_ERROR_REQUEST )
191+
{
192+
CGUI *pManager = g_pCore->GetGUI ();
162193

163-
// Succeed, deal with the response
164-
m_ulStartTime = 0;
194+
// Sure we have it all right?
195+
if ( uiBufferLength > 32 )
196+
{
197+
// Get the hash
198+
m_strCommunityHash = std::string ( &szBuffer[1], 32 );
165199

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

169-
if ( Result == REGISTRATION_ERROR_REQUEST )
202+
// Create a temp file for the png
203+
FILE * fp = fopen ( CalcMTASAPath( REGISTRATION_TEMP_FILE ), "wb" );
204+
if ( fp )
170205
{
171-
CGUI *pManager = g_pCore->GetGUI ();
172-
173-
// Sure we have it all right?
174-
if ( uiBufferLength > 32 )
175-
{
176-
// Get the hash
177-
m_strCommunityHash = std::string ( &szBuffer[1], 32 );
178-
179-
// TODO: Load it without a temp file
180-
181-
// Create a temp file for the png
182-
FILE * fp = fopen ( CalcMTASAPath( REGISTRATION_TEMP_FILE ), "wb" );
183-
if ( fp )
184-
{
185-
fwrite ( &szBuffer[33], uiBufferLength, 1, fp );
186-
fclose ( fp );
187-
188-
m_pImageCode->LoadFromFile ( "temp.png" );
189-
m_pImageCode->SetSize ( CVector2D ( 65.0f, 20.0f ), false );
190-
m_pWindow->SetVisible ( true );
191-
m_pWindow->BringToFront ();
192-
193-
// Delete the temp file
194-
remove ( CalcMTASAPath( REGISTRATION_TEMP_FILE ) );
195-
return;
196-
}
197-
}
198-
g_pCore->ShowMessageBox ( _("Error")+_E("CC04"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
199-
}
200-
else if ( Result == REGISTRATION_ERROR_SUCCESS )
201-
{
202-
g_pCore->ShowMessageBox ( _("Success")+_E("CC05"), _("Successfully registered!"), MB_BUTTON_OK | MB_ICON_INFO );
203-
204-
m_pWindow->SetVisible ( false );
205-
SetFrozen ( false );
206-
m_strCommunityHash.clear ();
207-
m_pImageCode->Clear ();
206+
fwrite ( &szBuffer[33], uiBufferLength, 1, fp );
207+
fclose ( fp );
208+
209+
m_pImageCode->LoadFromFile ( "temp.png" );
210+
m_pImageCode->SetSize ( CVector2D ( 65.0f, 20.0f ), false );
211+
m_pWindow->SetVisible ( true );
212+
m_pWindow->BringToFront ();
213+
214+
// Delete the temp file
215+
remove ( CalcMTASAPath( REGISTRATION_TEMP_FILE ) );
216+
return;
208217
}
209-
else if ( Result == REGISTRATION_ERROR_ERROR )
210-
{
211-
if ( strlen ( &szBuffer[1] ) > 0 )
212-
g_pCore->ShowMessageBox ( _("Error")+_E("CC06"), &szBuffer[1], MB_BUTTON_OK | MB_ICON_ERROR );
213-
else
214-
g_pCore->ShowMessageBox ( _("Error")+_E("CC07"), "Unexpected error", MB_BUTTON_OK | MB_ICON_ERROR );
215-
216-
SetFrozen ( false );
217-
}
218-
else
219-
{
220-
g_pCore->ShowMessageBox ( _("Error")+_E("CC08"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
221-
SetFrozen ( false );
222-
}
223-
}
224-
else if ( ( CClientTime::GetTime () - m_ulStartTime ) > REGISTRATION_DELAY )
225-
{
226-
g_pCore->ShowMessageBox ( _("Error")+_E("CC10"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
227-
SetFrozen ( false );
228-
// Timed out
229-
m_ulStartTime = 0;
230218
}
219+
g_pCore->ShowMessageBox ( _("Error")+_E("CC04"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
220+
}
221+
else if ( Result == REGISTRATION_ERROR_SUCCESS )
222+
{
223+
g_pCore->ShowMessageBox ( _("Success")+_E("CC05"), _("Successfully registered!"), MB_BUTTON_OK | MB_ICON_INFO );
224+
225+
m_pWindow->SetVisible ( false );
226+
SetFrozen ( false );
227+
m_strCommunityHash.clear ();
228+
m_pImageCode->Clear ();
229+
}
230+
else if ( Result == REGISTRATION_ERROR_ERROR )
231+
{
232+
if ( strlen ( &szBuffer[1] ) > 0 )
233+
g_pCore->ShowMessageBox ( _("Error")+_E("CC06"), &szBuffer[1], MB_BUTTON_OK | MB_ICON_ERROR );
234+
else
235+
g_pCore->ShowMessageBox ( _("Error")+_E("CC07"), "Unexpected error", MB_BUTTON_OK | MB_ICON_ERROR );
236+
237+
SetFrozen ( false );
231238
}
239+
else
240+
{
241+
g_pCore->ShowMessageBox ( _("Error")+_E("CC08"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
242+
SetFrozen ( false );
243+
}
244+
}
245+
246+
247+
void CCommunityRegistration::DownloadFailed( int iErrorCode )
248+
{
249+
g_pCore->ShowMessageBox ( _("Error")+_E("CC10"), _("Services currently unavailable"), MB_BUTTON_OK | MB_ICON_ERROR );
250+
SetFrozen ( false );
251+
// Timed out
252+
m_ulStartTime = 0;
232253
}
233254

234255

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

271292
// Create the URL
272-
std::string strURL =
293+
SString strURL =
273294
std::string ( REGISTRATION_URL ) +
274295
"?action=register" +
275296
"&username=" + m_pEditUsername->GetText() +
@@ -279,7 +300,8 @@ bool CCommunityRegistration::OnButtonRegisterClick ( CGUIElement* pElement )
279300
"&hash=" + m_strCommunityHash;
280301

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

284306
// Store the start time
285307
m_ulStartTime = CClientTime::GetTime ();

MTA10/core/CCommunityRegistration.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class CCommunityRegistration
4949

5050
protected:
5151
void CreateWindows ( void );
52+
static bool StaticDownloadFinished ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode );
53+
void DownloadSuccess ( char* pCompletedData, size_t completedLength );
54+
void DownloadFailed ( int iErrorCode );
55+
CNetHTTPDownloadManagerInterface* GetHTTP ( void );
5256

5357
private:
5458

@@ -75,9 +79,6 @@ class CCommunityRegistration
7579
CGUIButton* m_pButtonRegister;
7680
CGUIButton* m_pButtonCancel;
7781

78-
// Community stuff
79-
CHTTPClient m_HTTP;
80-
8182
std::string m_strCommunityHash;
8283

8384
unsigned long m_ulStartTime;

MTA10/core/CCore.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ CCore::CCore ( void )
163163
m_pDirectInputHookManager = new CDirectInputHookManager ( );
164164
m_pMessageLoopHook = new CMessageLoopHook ( );
165165
m_pSetCursorPosHook = new CSetCursorPosHook ( );
166-
m_pTCPManager = new CTCPManager ( );
167166

168167
// Register internal commands.
169168
RegisterCommands ( );
@@ -221,7 +220,6 @@ CCore::~CCore ( void )
221220
//delete m_pFileSystemHook;
222221
delete m_pDirect3DHookManager;
223222
delete m_pDirectInputHookManager;
224-
delete m_pTCPManager;
225223

226224
// Delete the GUI manager
227225
delete m_pLocalGUI;

MTA10/core/CCore.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class CCore;
3939
#include <core/CClientEntityBase.h>
4040
#include <core/CCoreInterface.h>
4141
#include "CDirect3DData.h"
42-
#include "tracking/CTCPManager.h"
4342
#include "CClientVariables.h"
4443
#include "CKeyBinds.h"
4544
#include "CMouseControl.h"
@@ -297,7 +296,6 @@ class CCore : public CCoreInterface, public CSingleton < CCore >
297296
CDirect3DHookManager * m_pDirect3DHookManager;
298297
//CFileSystemHook * m_pFileSystemHook;
299298
CSetCursorPosHook * m_pSetCursorPosHook;
300-
CTCPManager * m_pTCPManager;
301299

302300
bool m_bLastFocused;
303301
int m_iUnminimizeFrameCounter;

MTA10/core/CMessageLoopHook.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,6 @@ LRESULT CALLBACK CMessageLoopHook::ProcessMessage ( HWND hwnd,
249249
if ( CKeyBinds::IsFakeCtrl_L ( uMsg, wParam, lParam ) )
250250
return true;
251251

252-
// See if this is message was caused by our asynchronous sockets
253-
if ( uMsg >= WM_ASYNCTRAP && uMsg <= ( WM_ASYNCTRAP + 511 ))
254-
{
255-
/* ACHTUNG: uMsg - 10? Windows seems to add 10 or there's a bug in the message code. Hack! */
256-
// Let the CTCPManager handle it
257-
CTCPManager::GetSingletonPtr ()->HandleEvent ( ( uMsg - WM_ASYNCTRAP ), wParam, lParam );
258-
}
259-
260252
bool bWasCaptureKey = false;
261253
CMainMenu* pMainMenu = g_pCore->GetLocalGUI ()->GetMainMenu ();
262254
if ( pMainMenu )

0 commit comments

Comments
 (0)