Raised This Month: $32 Target: $400
 8% 

Need assistance with private API key script (And Parsing?)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Miggy
Member
Join Date: Mar 2015
Old 04-29-2016 , 10:57   Need assistance with private API key script (And Parsing?)
Reply With Quote #1

Hi folks,

Thank you so much for even giving this thread a glance. Despite having worked on my plugin for almost a year now I still consider myself very new and extremely ignorant (read: dumb) when it comes to scripting. My brain just doesn't seem to function like a programmer, I'm more of a design guy

Anyways. Part of the function in my script is that it pulls information from UGC's Banlist via API.
Currently I think I have it scripted correctly thus far in terms terms of setting up the API right, I also have it set up so that the private API is read from a cfg file in the sourcemod/configs folder as every server owner who decides to use this plugin will get their own key. I'm stuck at the following part, Now that I have the API url and a function to READ from that, how do I tell my plugin to USE the API Key Cvar? I tried looking it up on the wiki and sourcemod API page and either I'm searching using the wrong terms or I'm just not understanding what I'm finding. I would greatly appreciate some assistance in this.

Here's the relevant sections of my script:

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <geoipcity>
#include <socket>
#include <smjansson>
#undef REQUIRE_PLUGIN
#include <updater>

#define PLUGIN_VERSION "2.3"

#define CVAR_MAXLEN 64


//Current Banlist API info
#define API_BANLIST_HOST "ugcleague.com"
#define API_BANLIST_DIR "/api/api.php?key={key}&ban_list"
#define API_BANLIST_URL "http://www.ugcleague.com/api/api.php?key={key}&ban_list"

#define MAX_URL_LENGTH 256
#define UPDATE_URL "http://miggthulu.com/integritf2/updatefile.txt"

#include helpers/download_socket.sp
#include helpers/filesys.sp

public Plugin myinfo = {
    
name        "IntegriTF2",
    
author      "Miggy",
    
description "Plugin that verifies the integrity of the Server and Player settings.",
    
version        PLUGIN_VERSION,
    
url         "miggthulu.com"
};


//Banlist API Cvar
new Handle:g_Cvar_API INVALID_HANDLE;


public 
void OnPluginStart()
{

    
/**Reads Ban List API Key**/
    //This creates a file named "IntegriTF2api.cfg" in your tf/cfg/sourcemod/ folder. Place your API keys here
    //In the IntegriTF2api.cfg write the following line:        sm_ugcbanapi "PLACEYOURAPIKEYHERE"
    
g_Cvar_API CreateConVar("sm_ugcbanapi""""Place your Api key here");
    
AutoExecConfig(true"IntegriTF2api");
    
    
PrintToChatAll("[IntegriTF2] has been loaded.");
}

public 
OnLibraryAdded(const String:name[])
{
    if (
StrEqual(name"updater"))
    {
        
Updater_AddPlugin(UPDATE_URL);
    }
}

void CheckBanlistApi()
{
    
Download_Socket(API_BANLIST_URL"ugc_banlist.json");
    
}



void DownloadEnded(bool successfulchar error[]="")
{
    if ( ! 
successful) {
        
LogError("Download attempt failed: %s"error);
        return;
    }
}

public 
void OnPluginEnd()
{
    
PrintToChatAll("[IntegriTF2] has been unloaded.");

I also have a question regarding my next step once the api is working.
My goal is to check the steamIDs of clients and compare them to those that are show in via API and if there's a match to put a notification in chat.

The issues I KNOW I'll have and I THINK I'll have are:
I KNOW I have zero idea on how to parse the data and turn alllllll those SteamID64s into strings.
The problem I THINK I'll have is that, I already have a function in another area of the script that loads up a clients SteamID on connect, however, these two SteamID formats are different. I'm guessing it will matter. Would it be easier to convert SteamIDs? Or attempt to change what kind of SteamID format is loaded on client connect?

Last edited by Miggy; 04-29-2016 at 11:09.
Miggy is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-29-2016 , 11:07   Re: Need assistance with private API key script (And Parsing?)
Reply With Quote #2

g_Cvar_API.GetString will get the value of your convar at runtime, and you can use GetClientAuthId with AuthId_SteamID64 to get a client's 64-bit steamid as a string (only available after they're authenticated) for comparing to whatever the API returns.

That said, neither your server nor theirs will be very happy with you if you're checking the entire list on every connection - you should strongly consider fetching it periodically and creating an efficient in-memory data structure to check for existence (I'd recommend a StringMap keyed on the 64-bit steamid string, if a given key exists in the map, then they're on the ban list).
__________________
asherkin is offline
Miggy
Member
Join Date: Mar 2015
Old 04-29-2016 , 11:41   Re: Need assistance with private API key script (And Parsing?)
Reply With Quote #3

I'll modify my public void OnClientAuthorized to pull those AuthId_SteamID64 and see if that works out for me
And I'll see if I can get g_Cvar_API.GetString working.

Also, do you think it would be too taxing ifffff I downloaded the SteamID64's into a cfg file on map/plugin load, then compare the SteamIDs of connected users to that cfg file? That way I'm not constantly slamming UGCs system.

Thanks for the response btw, didn't expect one so quickly and now I'm stuck at work unable to make any changes until my break x.x
Miggy is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 04-29-2016 , 12:27   Re: Need assistance with private API key script (And Parsing?)
Reply With Quote #4

Quote:
Originally Posted by Miggy View Post
Also, do you think it would be too taxing ifffff I downloaded the SteamID64's into a cfg file on map/plugin load, then compare the SteamIDs of connected users to that cfg file? That way I'm not constantly slamming UGCs system.
That's pretty much what asherkin suggested. Don't write it to a file, just keep it in memory using a StringMap and check that for each connection.
__________________
Dr. McKay is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode