Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <sockets>
#define PLUGIN "Steam Community Nick"
#define VERSION "1.0.4"
#define AUTHOR "Kia"
// ===============================================================================
// Editing begins here
// ===============================================================================
// API Key from http://steamcommunity.com/dev/apikey
#define API_KEY "YOURAPIKEYHERE"
// Site where PHP Script is hosted
#define API_HOST "kiasserver.tk"
// Name of PHP Script
#define API_SCRIPT "steamparser.php"
// Flag for bypassing plugin
#define FLAG_BYPASS ADMIN_BAN
// ===============================================================================
// and stops here. DO NOT MODIFY BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
// ===============================================================================
// ===============================================================================
// Variables
// ===============================================================================
/* Task IDs */
#define TASK_ID_ANSWER 1921
#define TASK_ID_KILL 9192
/* Strings */
new g_szSteamName[33][33]
/* Booleans */
new bool:g_bHasName[33]
/* Sockets */
new g_Socket
/* Pointers */
new g_pAffecting, g_pBlockChange
// ===============================================================================
// plugin_init
// ===============================================================================
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
/* Forwards */
register_forward(FM_ClientUserInfoChanged, "Forward_UsrInfoChanged")
/* CVars */
g_pAffecting = register_cvar("steamcomnick_affecting", "1")
g_pBlockChange = register_cvar("steamcomnick_block", "0")
}
// ===============================================================================
// Forward_UsrInfoChanged - Called when someone changes his name
// ===============================================================================
public Forward_UsrInfoChanged(id)
{
if (!is_user_bot(id) && !is_user_hltv(id))
{
if(get_pcvar_num(g_pBlockChange) != 1)
return FMRES_HANDLED
if(!is_user_connected(id) || !g_bHasName[id])
return FMRES_HANDLED
new szOldName[33]
get_user_name(id, szOldName, charsmax(szOldName))
if( !equali(szOldName, g_szSteamName[id]) )
{
set_user_info(id, "name", g_szSteamName[id])
return FMRES_IGNORED
}
}
return FMRES_IGNORED
}
// ===============================================================================
// client_authorized - Called when someone joins the game
// ===============================================================================
public client_authorized(id)
{
if (!is_user_bot(id) && !is_user_hltv(id))
{
// Setting new Name
g_bHasName[id] = false
new szFlags = get_user_flags(id)
if(get_pcvar_num(g_pAffecting))
{
new szName[33]
get_user_name(id, szName, charsmax(szName))
if(equal("Player", szName))
SetPlayersSteamName(id)
}
else
{
if(!(szFlags & FLAG_BYPASS))
SetPlayersSteamName(id)
}
}
}
// ===============================================================================
// client_disconnect - Called when someone leaves the game
// ===============================================================================
public client_disconnect(id)
{
// Cleaning the string
g_bHasName[id] = false
g_szSteamName[id][0] = EOS
}
// ===============================================================================
// SetPlayersSteamName - Sets the Steam Name from the Player
// ===============================================================================
public SetPlayersSteamName(id)
{
// Opening Socket to Script
new iError
g_Socket = socket_open(API_HOST, 80, SOCKET_TCP, iError)
// If there was an error, we'll show why.
switch (iError)
{
case 1:
{
log_amx("[Steam Community Nick] Unable to create socket.")
return
}
case 2:
{
log_amx("[Steam Community Nick] Unable to connect to hostname.")
return
}
case 3:
{
log_amx("[Steam Community Nick] Unable to connect to the HTTP port.")
return
}
}
// Get Players Steam ID
new szAuthID[64]
get_user_authid(id, szAuthID, charsmax(szAuthID))
// Preparing parameters
new szMessage[512]
formatex(szMessage, charsmax(szMessage), "/%s?key=%s&steamid=%s", API_SCRIPT, API_KEY, szAuthID)
// Preparing the "message" we send to the script
new szMessageBuffer[512]
formatex(szMessageBuffer, charsmax(szMessageBuffer), "GET %s HTTP/1.1^nHost:%s^r^n^r^n", szMessage, API_HOST)
// Requesting Name from Script
socket_send(g_Socket, szMessageBuffer, charsmax(szMessageBuffer))
// We repeat the first task 15 times in order to check 15 times every second if we get the response and to see if the info that we want to search is in that response.
set_task(1.0, "Socket_WaitForAnswer", TASK_ID_ANSWER + id, "", 0, "a", 15)
// The second task closes the connection if in the first task nothing has been done.
set_task(16.0, "Socket_CloseConnection", TASK_ID_KILL + id, "", 0, "", 0)
}
// ===============================================================================
// Socket_WaitForAnswer
// ===============================================================================
public Socket_WaitForAnswer(iTask)
{
// The player is the Task Number, minus the predefined number
new iPlayer = iTask - TASK_ID_ANSWER
// If we got data
if(socket_change(g_Socket))
{
// Save them
new szData[1066]
socket_recv(g_Socket, szData, charsmax(szData))
// Cut the Name off
new szDummy[1067]
split(szData, szDummy, charsmax(szDummy), g_szSteamName[iPlayer], charsmax(g_szSteamName), "lamboon") // Hi Serkan :)
// Close the connection
socket_close(g_Socket)
// Remove the tasks
remove_task(TASK_ID_KILL + iPlayer)
// Set the new name
g_bHasName[iPlayer] = true
set_user_info(iPlayer, "name", g_szSteamName[iPlayer])
}
}
// ===============================================================================
// Socket_CloseConnection
// ===============================================================================
public Socket_CloseConnection(id)
socket_close(g_Socket)