View Single Post
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