Quote:
Originally Posted by Lubricant Jam
Thanks for this, I will look at this when I can. Do you know if it's possible to pull someones profileurl & profileimg for example;
HTML Code:
https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/af/aff0c5bb68643aea1828cc4eaec039417d10b436_full.jpg
|
You can fetch user data via Steam API -
https://developer.valvesoftware.com/...es_.28v0002.29 (SteamWorks GET request), but I don't recommend it ingame (in plugin - on connect).
If you need these data (avatar, personastate, ...) eg. on the website, you can get it after Steam Login (
https://github.com/SmItH197/SteamAuthentication,
https://github.com/invisnik/laravel-steam-auth) or without login
- Steam API (
https://github.com/DaMitchell/steam-api-php,
https://github.com/syntaxerrors/Steam).
So ingame (in plugin) only create user - steamid, name, created_at, updated_at and on the website after login fetch another information (avatar, personastate, ...).
Here is an example of SteamWorks GET request to Steam API (steamid, personaname, personastate, avatar):
PHP Code:
// https://steamcommunity.com/dev/apikey
#define STEAM_API_KEY "xxxxxxxxxxxx"
public void OnClientPostAdminCheck(int client)
{
if(IsValidClient(client)) {
Api_OnClientConnect(client);
}
}
public void Api_OnClientConnect(int client)
{
char sURLAddress[1024];
char szSteamId[64];
GetClientAuthId(client, AuthId_SteamID64, szSteamId, sizeof(szSteamId));
Format(sURLAddress, sizeof(sURLAddress), "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s&format=vdf", STEAM_API_KEY, szSteamId);
Handle hHTTPRequest = SteamWorks_CreateHTTPRequest(k_EHTTPMethodGET, sURLAddress);
bool bNetwork = SteamWorks_SetHTTPRequestNetworkActivityTimeout(hHTTPRequest, 10);
bool bCallback = SteamWorks_SetHTTPCallbacks(hHTTPRequest, Api_OnClientCallback);
if (bNetwork == false || bHeader == false || bCallback == false) {
delete hHTTPRequest;
return;
}
bool bRequest = SteamWorks_SendHTTPRequest(hHTTPRequest);
if (bRequest == false) {
delete hHTTPRequest;
return;
}
SteamWorks_PrioritizeHTTPRequest(hHTTPRequest);
}
public int Api_OnClientCallback(Handle hRequest, bool bFailure, bool bRequestSuccessful, EHTTPStatusCode eStatusCode, any data)
{
if (bFailure || !bRequestSuccessful) {
delete hRequest;
return;
}
int iBodySize;
if (!SteamWorks_GetHTTPResponseBodySize(hRequest, iBodySize)) {
delete hRequest;
return;
}
char[] szBody = new char[iBodySize + 1];
if (!SteamWorks_GetHTTPResponseBodyData(hRequest, szBody, iBodySize)) {
delete hRequest;
return;
}
Api_FetchUserData(szBody);
}
public void Api_FetchUserData(const char[] responseBody)
{
KeyValues hKeyValues = new KeyValues("response");
if (hKeyValues.ImportFromString(responseBody)) {
if (hKeyValues.JumpToKey("players")) {
if (hKeyValues.GotoFirstSubKey()) {
char sPersonastate[2];
char sPersonaName[128];
char sSteamId64[18];
char sAvatarFull[256];
hKeyValues.GetString("steamid", sSteamId64, sizeof(sSteamId64));
hKeyValues.GetString("personaname", sPersonaName, sizeof(sPersonaName));
hKeyValues.GetString("avatarfull", sAvatarFull, sizeof(sAvatarFull));
hKeyValues.GetString("personastate", sPersonastate, sizeof(sPersonastate));
Database_OnClientConnect(sSteamId64, sPersonaName, sPersonastate, sAvatarFull);
}
}
}
delete hKeyValues;
}
public void Database_OnClientConnect(const char[] sSteamId64, const char[] sPersonaName, const char[] sPersonastate, const char[] sAvatarFull)
{
if(g_hDatabase != null) {
char szBuffer[1024];
char szClientNameEscaped[128];
g_hDatabase.Escape(sPersonaName, szClientNameEscaped, sizeof(szClientNameEscaped));
Format(szBuffer, sizeof(szBuffer), "INSERT INTO users (name, steamid, persona_state, avatar, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', NOW(), NOW()) ON DUPLICATE KEY UPDATE name = '%s', avatar = '%s' updated_at = NOW()", szClientNameEscaped, sSteamId64, sPersonastate, sAvatarFull, szClientNameEscaped, sAvatarFull);
g_hDatabase.Query(Database_OnClientConnected, szBuffer);
}
}
... the rest of the code
Steam API response (VDF format):
PHP Code:
"response"
{
"players"
{
"0"
{
"steamid" "76561198364662582"
"communityvisibilitystate" "3"
"profilestate" "1"
"personaname" "NomisCZ (-N-)"
"lastlogoff" "1551118716"
"commentpermission" "1"
"profileurl" "https://steamcommunity.com/id/olympic-nomis/"
"avatar" "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/fb/fbaed0beb2e56a2d30abf2e0b2aeaeb4db513dbd.jpg"
"avatarmedium" "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/fb/fbaed0beb2e56a2d30abf2e0b2aeaeb4db513dbd_medium.jpg"
"avatarfull" "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/fb/fbaed0beb2e56a2d30abf2e0b2aeaeb4db513dbd_full.jpg"
"personastate" "1"
"primaryclanid" "103582791430395180"
"timecreated" "1486318143"
"personastateflags" "0"
"loccountrycode" "CZ"
}
}
}
PHP (Laravel) Steam login & user update example (Controller):
PHP Code:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Invisnik\LaravelSteamAuth\SteamAuth;
use App\User;
class SteamController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* @var object
*/
private $steam;
private $user;
/**
* SteamController constructor.
* @param SteamAuth $steam
* @param User $user
*/
public function __construct(SteamAuth $steam, User $user)
{
$this->middleware('guest')->except('logout');
$this->steam = $steam;
$this->user = $user;
}
public function login()
{
// Steam login success
if ($this->steam->validate()) {
// Get user data
$steamUserData = $this->steam->getUserInfo();
if ($steamUserData) {
// Get user from DB
$user = $this->user->getBySteam($steamUserData->steamID64);
if (!$user) {
return redirect()->route('auth.login')->with(['message_status' => 'info', 'flash_message' => 'auth.steam.failed']);
}
// Update user
$user->update([
'name' => $steamUserData->personaname,
'avatar' => $steamUserData->avatarfull,
]);
// Login user (session)
auth()->login($user, false);
return redirect()->route('index');
}
}
return $this->steam->redirect();
}
}
__________________