-
-
Notifications
You must be signed in to change notification settings - Fork 406
/
CCommunity.cpp
134 lines (107 loc) · 3.88 KB
/
CCommunity.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* LICENSE: See LICENSE in the top level directory
* FILE: core/CCommunity.cpp
* PURPOSE: Community connector class
* DEVELOPERS: Cecill Etheredge <ijsf@gmx.net>
* Stanislav Bobrov <lil_toady@hotmail.com>
* Sebas Lamers <sebasdevelopment@gmx.com>
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"
extern CCore* g_pCore;
template<> CCommunity * CSingleton< CCommunity >::m_pSingleton = NULL;
char *szVerificationMessages[] = {
"Unexpected error",
"Success",
"Your account does not seem to exist",
"Computer already in use",
"You have reached your serials quota",
"Invalid username/password",
"Account provided is already in use",
"Version error",
"Account is banned",
"Serial is banned",
"Could not connect to master server"
};
CCommunity::CCommunity ( void )
{
m_ulStartTime = 0;
m_pVerificationObject = 0;
m_pCallback = NULL;
m_bLoggedIn = false;
}
void CCommunity::Initialize ( void )
{
CVARS_GET ( "community_username", m_strUsername );
CVARS_GET ( "community_password", m_strPassword );
if ( !m_strUsername.empty() && !m_strPassword.empty() )
Login ();
}
CCommunity::~CCommunity ( void )
{
}
void CCommunity::Logout ( void )
{
m_ulStartTime = 0;
m_bLoggedIn = false;
CVARS_SET ( "community_username", std::string () );
CVARS_SET ( "community_password", std::string () );
// Change GUI
CLocalGUI::GetSingleton ().GetMainMenu()->ChangeCommunityState ( false, "" );
CLocalGUI::GetSingleton ().GetMainMenu()->GetSettingsWindow()->OnLoginStateChange ( false );
}
void CCommunity::Login ( VERIFICATIONCALLBACK pCallBack, void* pObject )
{
m_bLoggedIn = false;
if ( pCallBack && pObject )
{
m_pCallback = pCallBack;
m_pVerificationObject = pObject;
}
// Get our serial number
char szSerial [ 64 ];
g_pCore->GetNetwork ()->GetSerial ( szSerial, sizeof ( szSerial ) );
// Create the URL
SString strURL ( VERIFICATION_URL "?username=%s&password=%s&serial=%s",
m_strUsername.c_str(),
m_strPassword.c_str(),
szSerial );
// Perform the HTTP request
m_HTTP.Get ( strURL );
// Store the start time
m_ulStartTime = CClientTime::GetTime ();
}
void CCommunity::DoPulse ( void )
{
if ( m_ulStartTime )
{
eVerificationResult Status;
// Poll the HTTP client
CHTTPBuffer buffer;
if ( m_HTTP.GetData ( buffer ) ) {
char *szBuffer = buffer.GetData ();
// 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 ();
}
}
}