-
Notifications
You must be signed in to change notification settings - Fork 7
/
SteamAuth.php
138 lines (124 loc) · 4.17 KB
/
SteamAuth.php
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
135
136
137
138
<?php
// Version: 1.0: SteamAuth.php
// Licence: ISC
if (!defined('SMF'))
die('Hacking attempt...');
function steam_auth_load_theme()
{
global $context, $modSettings, $smcFunc, $sourcedir, $user_settings, $txt;
if ($context['current_action'] == 'login' && !empty($modSettings['steam_auth_api_key']))
{
loadLanguage('SteamAuth');
try
{
require_once($sourcedir . '/openid.php');
$openid = new LightOpenID($_SERVER['SERVER_NAME']);
if (!$openid->mode)
{
if (isset($_GET['steam']))
{
$openid->identity = 'http://steamcommunity.com/openid/?l=english'; // This is forcing english because it has a weird habit of selecting a random language otherwise
header('Location: ' . $openid->authUrl());
}
else
{
loadTemplate('SteamAuth');
$context['template_layers'][] = 'steam_login';
}
}
elseif ($openid->mode == 'cancel')
$context['login_errors'] = array($txt['steam_auth_x']);
else
{
if ($openid->validate())
{
$id = $openid->identity;
$ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
preg_match($ptn, $id, $matches);
$steamid = $matches[1];
//looks like there was a breaking change in the response - this will patch it up
if (empty($steamid))
{
$ptn = "/^https:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
preg_match($ptn, $id, $matches);
$steamid = $matches[1];
}
$request = $smcFunc['db_query']('', '
SELECT passwd, id_member, id_group, lngfile, is_activated, email_address, additional_groups, member_name, password_salt,
openid_uri, passwd_flood
FROM {db_prefix}members
WHERE member_name = {string:steamid}
LIMIT 1',
array(
'steamid' => 'steamuser-' . $steamid,
)
);
$user_settings = $smcFunc['db_fetch_assoc']($request);
$smcFunc['db_free_result']($request);
if (empty($user_settings))
{
require_once($sourcedir . '/Subs-Package.php');
$url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$modSettings[steam_auth_api_key]&steamids=$matches[1]";
$json_object= fetch_web_data($url);
$json_decoded = json_decode($json_object);
foreach ($json_decoded->response->players as $player)
{
$regOptions = array(
'interface' => '',
'username' => 'steamuser',
'email' => 'steamuser-' . $steamid . '@' . $_SERVER['SERVER_NAME'],
'check_reserved_name' => false,
'check_password_strength' => false,
'check_email_ban' => false,
'send_welcome_email' => false,
'require' => 'nothing',
'extra_register_vars' => array(
'member_name' => 'steamuser-' . $steamid,
'real_name' => $player->personaname,
'avatar' => str_replace('https://', 'http://', $player->avatarmedium),
),
'theme_vars' => array(),
);
require_once($sourcedir . '/Subs-Members.php');
mt_srand(time() + 1277);
$regOptions['password'] = generateValidationCode();
$regOptions['password_check'] = $regOptions['password'];
if (is_array($errors = registerMember($regOptions, true)))
$context['login_errors'] = $errors;
}
$request = $smcFunc['db_query']('', '
SELECT passwd, id_member, id_group, lngfile, is_activated, email_address, additional_groups, member_name, password_salt,
openid_uri, passwd_flood
FROM {db_prefix}members
WHERE member_name = {string:steamid}
LIMIT 1',
array(
'steamid' => 'steamuser-' . $steamid,
)
);
$user_settings = $smcFunc['db_fetch_assoc']($request);
$smcFunc['db_free_result']($request);
}
require_once($sourcedir . '/LogInOut.php');
DoLogin();
}
else
$context['login_errors'] = array($txt['error_occured']);
}
}
catch (ErrorException $e)
{
$context['login_errors'] = array($e->getMessage());
}
}
}
function steam_auth_general_mod_settings(&$config_vars)
{
global $txt;
loadLanguage('SteamAuth');
$config_vars = array_merge($config_vars, array(
'',
array('text', 'steam_auth_api_key', 80, 'postinput' => $txt['steam_auth_api_key_link']),
));
}
?>