Skip to content

Commit

Permalink
Merge pull request #1 from Jump-Academy/master
Browse files Browse the repository at this point in the history
Natives refactoring and Layout in jse_mapinfo addition
  • Loading branch information
LapplandBro committed Sep 4, 2023
2 parents 801b808 + 638f5f1 commit c469e21
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
6 changes: 4 additions & 2 deletions scripting/include/jse_mapinfo.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ native void MapInfo_CurrentMap(MapInfoResponse fnCallback, any aData);
* @param iIntendedTier Map tier for intended class
* @param iTierS Map tier for soldier (regardless of intended class)
* @param iTierD Map tier for demoman (regardless of intended class)
* @param bLayout Include map layout details
*/
native void MapInfo_Lookup(MapInfoResponse fnCallback, any aData, bool bExtendedTiers, bool bExactMatch=false, const char[] sSearchTerm=NULL_STRING, const char[] sAuthorAuthID=NULL_STRING, const char[] sAuthorName=NULL_STRING, TFClassType iClassType=TFClass_Unknown, int iIntendedTier=0, int iTierS=0, int iTierD=0);
native void MapInfo_Lookup(MapInfoResponse fnCallback, any aData, bool bExtendedTiers, bool bExactMatch=false, const char[] sSearchTerm=NULL_STRING, const char[] sAuthorAuthID=NULL_STRING, const char[] sAuthorName=NULL_STRING, TFClassType iClassType=TFClass_Unknown, int iIntendedTier=0, int iTierS=0, int iTierD=0, bool bLayout=false);

/**
* Looks up information for multiple maps
Expand All @@ -72,8 +73,9 @@ native void MapInfo_Lookup(MapInfoResponse fnCallback, any aData, bool bExtended
* @param iIntendedTier Map tier for intended class
* @param iTierS Map tier for soldier (regardless of intended class)
* @param iTierD Map tier for demoman (regardless of intended class)
* @param bLayout Include map layout details
*/
native void MapInfo_LookupAll(MapInfoResponse fnCallback, any aData, bool bExtendedTiers, bool bExactMatch=false, const char[] sSearchTerms=NULL_STRING, const char[] sSplit, const char[] sAuthorAuthID=NULL_STRING, const char[] sAuthorName=NULL_STRING, TFClassType iClassType=TFClass_Unknown, int iIntendedTier=0, int iTierS=0, int iTierD=0);
native void MapInfo_LookupAll(MapInfoResponse fnCallback, any aData, bool bExtendedTiers, bool bExactMatch=false, const char[] sSearchTerms=NULL_STRING, const char[] sSplit, const char[] sAuthorAuthID=NULL_STRING, const char[] sAuthorName=NULL_STRING, TFClassType iClassType=TFClass_Unknown, int iIntendedTier=0, int iTierS=0, int iTierD=0, bool bLayout=false);

/**
* Callback for receiving MapInfo query results
Expand Down
28 changes: 14 additions & 14 deletions scripting/jse_core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,6 @@ public Plugin myinfo = {
url = "https://jumpacademy.tf"
};

public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int sErrMax) {
RegPluginLibrary("jse_core");
CreateNative("GetBlockEquip", Native_GetBlockEquip);
CreateNative("GetBlockRegen", Native_GetBlockRegen);
CreateNative("GetRegen", Native_GetRegen);
CreateNative("SetBlockEquip", Native_SetBlockEquip);
CreateNative("SetBlockRegen", Native_SetBlockRegen);
CreateNative("SetRegen", Native_SetRegen);
CreateNative("ClearControlPointCapture", Native_ClearControlPointCapture);
CreateNative("ClearScore", Native_ClearScore);

return APLRes_Success;
}

public void OnPluginStart() {
CreateConVar("jse_core_version", PLUGIN_VERSION, "Jump Server Essentials core version -- Do not modify", FCVAR_NOTIFY | FCVAR_DONTRECORD);

Expand Down Expand Up @@ -226,6 +212,20 @@ public void OnPluginEnd() {
}
}

public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int sErrMax) {
RegPluginLibrary("jse_core");
CreateNative("GetBlockEquip", Native_GetBlockEquip);
CreateNative("GetBlockRegen", Native_GetBlockRegen);
CreateNative("GetRegen", Native_GetRegen);
CreateNative("SetBlockEquip", Native_SetBlockEquip);
CreateNative("SetBlockRegen", Native_SetBlockRegen);
CreateNative("SetRegen", Native_SetRegen);
CreateNative("ClearControlPointCapture", Native_ClearControlPointCapture);
CreateNative("ClearScore", Native_ClearScore);

return APLRes_Success;
}

public void OnConfigsExecuted() {
g_hBlockSounds.Clear();

Expand Down
23 changes: 16 additions & 7 deletions scripting/jse_mapinfo.sp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// #define DEBUG

#define PLUGIN_AUTHOR "AI"
#define PLUGIN_VERSION "0.2.3"
#define PLUGIN_VERSION "0.2.4"

#include <sourcemod>
#include <clientprefs>
Expand Down Expand Up @@ -185,12 +185,14 @@ public int Native_Lookup(Handle hPlugin, int iArgC) {
int iTierS = GetNativeCell(10);
int iTierD = GetNativeCell(11);

bool bLayout = GetNativeCell(12);

DataPack hRequestDataPack = new DataPack();
hRequestDataPack.WriteCell(hPlugin);
hRequestDataPack.WriteFunction(fnCallback);
hRequestDataPack.WriteCell(aData);

FetchFromAPI(HTTPRequestCallback_NativeFetchFromAPI, hRequestDataPack, bExtendedTiers, bExactMatch, sSearchTerm, sAuthorAuthID, sAuthorName, iClassType, iIntendedTier, iTierS, iTierD);
FetchFromAPI(HTTPRequestCallback_NativeFetchFromAPI, hRequestDataPack, bExtendedTiers, bExactMatch, sSearchTerm, sAuthorAuthID, sAuthorName, iClassType, iIntendedTier, iTierS, iTierD, bLayout);

return 0;
}
Expand Down Expand Up @@ -221,6 +223,8 @@ public int Native_LookupAll(Handle hPlugin, int iArgC) {
int iTierS = GetNativeCell(11);
int iTierD = GetNativeCell(12);

bool bLayout = GetNativeCell(13);

char sSearchTermsArray[1024][32];
int iSearchTerms = ExplodeString(sSearchTerms, sSplit, sSearchTermsArray, sizeof(sSearchTermsArray), sizeof(sSearchTermsArray[]));

Expand All @@ -229,7 +233,7 @@ public int Native_LookupAll(Handle hPlugin, int iArgC) {
hRequestDataPack.WriteFunction(fnCallback);
hRequestDataPack.WriteCell(aData);

FetchFromAPI_Multiple(HTTPRequestCallback_NativeFetchFromAPI, hRequestDataPack, bExtendedTiers, bExactMatch, sSearchTermsArray, iSearchTerms, sAuthorAuthID, sAuthorName, iClassType, iIntendedTier, iTierS, iTierD);
FetchFromAPI_Multiple(HTTPRequestCallback_NativeFetchFromAPI, hRequestDataPack, bExtendedTiers, bExactMatch, sSearchTermsArray, iSearchTerms, sAuthorAuthID, sAuthorName, iClassType, iIntendedTier, iTierS, iTierD, bLayout);

return 0;
}
Expand Down Expand Up @@ -400,14 +404,14 @@ public Action Timer_MapChange(Handle hTimer, Handle hHandle) {

// Helpers

void FetchFromAPI(HTTPRequestCallback fnCallback, any aData, bool bExtendedTiers, bool bExactMatch, const char sSearchTerm[32]="", const char[] sAuthorAuthID=NULL_STRING, const char[] sAuthorName=NULL_STRING, TFClassType iClassType=TFClass_Unknown, int iIntendedTier=0, int iTierS=0, int iTierD=0) {
void FetchFromAPI(HTTPRequestCallback fnCallback, any aData, bool bExtendedTiers, bool bExactMatch, const char sSearchTerm[32]="", const char[] sAuthorAuthID=NULL_STRING, const char[] sAuthorName=NULL_STRING, TFClassType iClassType=TFClass_Unknown, int iIntendedTier=0, int iTierS=0, int iTierD=0, bool bLayout=false) {
char[][] sSearchTerms = new char[1][32];
strcopy(sSearchTerms[0], 32, sSearchTerm);

FetchFromAPI_Multiple(fnCallback, aData, bExtendedTiers, bExactMatch, sSearchTerms, sSearchTerm[0] ? 1 : 0, sAuthorAuthID, sAuthorName, iClassType, iIntendedTier, iTierS, iTierD);
FetchFromAPI_Multiple(fnCallback, aData, bExtendedTiers, bExactMatch, sSearchTerms, sSearchTerm[0] ? 1 : 0, sAuthorAuthID, sAuthorName, iClassType, iIntendedTier, iTierS, iTierD, bLayout);
}

void FetchFromAPI_Multiple(HTTPRequestCallback fnCallback, any aData, bool bExtendedTiers, bool bExactMatch, const char[][] sSearchTerms={}, int iSearchTermsTotal=0, const char[] sAuthorAuthID=NULL_STRING, const char[] sAuthorName=NULL_STRING, TFClassType iClassType=TFClass_Unknown, int iIntendedTier=0, int iTierS=0, int iTierD=0) {
void FetchFromAPI_Multiple(HTTPRequestCallback fnCallback, any aData, bool bExtendedTiers, bool bExactMatch, const char[][] sSearchTerms={}, int iSearchTermsTotal=0, const char[] sAuthorAuthID=NULL_STRING, const char[] sAuthorName=NULL_STRING, TFClassType iClassType=TFClass_Unknown, int iIntendedTier=0, int iTierS=0, int iTierD=0, bool bLayout=false) {
char sExtendedFilter[13];
if (bExtendedTiers) {
sExtendedFilter = "&extended=1";
Expand Down Expand Up @@ -451,8 +455,13 @@ void FetchFromAPI_Multiple(HTTPRequestCallback fnCallback, any aData, bool bExte
Format(sSearchTermsFilter, sizeof(sSearchTermsFilter), "&filename=%s", sSearchTermsFilter);
}

char sLayoutFilter[16];
if (bLayout) {
sLayoutFilter = "&layout=1";
}

char sURL[8190];
FormatEx(sURL, sizeof(sURL), "%s?version=%s%s%s%s%s%s%s%s", API_URL, API_VERSION, sExtendedFilter, sExactFilter, sClassIntendedTierFilter, sTierFilters, sAuthorAuthIDFilter, sAuthorFilter, sSearchTermsFilter);
FormatEx(sURL, sizeof(sURL), "%s?version=%s%s%s%s%s%s%s%s%s", API_URL, API_VERSION, sExtendedFilter, sExactFilter, sClassIntendedTierFilter, sTierFilters, sAuthorAuthIDFilter, sAuthorFilter, sSearchTermsFilter, sLayoutFilter);

#if defined DEBUG
PrintToServer("Calling API: %s", sURL);
Expand Down

0 comments on commit c469e21

Please sign in to comment.