Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Commit

Permalink
self token getter added
Browse files Browse the repository at this point in the history
  • Loading branch information
rejchev committed Aug 18, 2023
1 parent 42ab908 commit 13865ec
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
8 changes: 4 additions & 4 deletions extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ void ClownCore::OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMa
if(object == nullptr)
return;

if(m_pConfig != nullptr)
if(pConfig != nullptr)
{
json_decref(m_pConfig);
m_pConfig = nullptr;
json_decref(pConfig);
pConfig = nullptr;
}

m_pConfig = object;
pConfig = object;

IExtensionInterface::OnCoreMapStart(pEdictList, edictCount, clientMax);
}
4 changes: 2 additions & 2 deletions extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class ClownCore : public SDKExtension

// void OnCore

private:
json_t* m_pConfig = nullptr;
public:
static json_t* pConfig;
};

extern ClownCore g_ClownCoreExt;
Expand Down
28 changes: 28 additions & 0 deletions natives.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "extension.h"
#include "natives.h"

cell_t SendData(IPluginContext *pContext, const cell_t *params)
Expand All @@ -22,8 +23,35 @@ cell_t SendSignal(IPluginContext *pContext, const cell_t *params)
return OnDataReceived(path, data);
}

cell_t ClownGetMyKey(IPluginContext *pContext, const cell_t *params)
{
char *buffer;
pContext->LocalToString(params[1], &buffer);

auto& size = (size_t&)params[2];

static const char* TOKEN = "api.key";

json_t* obj;
if(!(obj = json_object_get(ClownCore::pConfig, TOKEN)))
return 0;

const char* str = nullptr;
if(json_is_string(obj) && (str = json_string_value(obj)) != nullptr)
ke::SafeStrcpyN(buffer, size, str, strlen(str) + 1);

bool done;
if((done = str != nullptr))
free((void*) str);

json_decref(obj);

return done;
}

const sp_nativeinfo_t natives[] = {
{ "ClownCore.SendData", SendData },
{ "ClownCore.SendSignal", SendSignal },
{ "ClownCore.GetMyToken", ClownGetMyKey },
{ nullptr, nullptr }
};
1 change: 1 addition & 0 deletions natives.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

extern cell_t SendData(SourcePawn::IPluginContext *pContext, const cell_t *params);
extern cell_t SendSignal(SourcePawn::IPluginContext *pContext, const cell_t *params);
extern cell_t ClownGetMyKey(SourcePawn::IPluginContext *pContext, const cell_t *params);

extern const sp_nativeinfo_t natives[];

Expand Down
6 changes: 3 additions & 3 deletions pawn/scripting/clown-core-test.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <clown-core>

#define PING "core.ping"

public void OnMapStart() {

char data[] = "Hello";
ClownCore.SendSignal(PING, );

LogMessage("OnReceiveCode: %d", ClownCore.SendData("self.ping", data, sizeof(data)));
LogMessage("OnDataReceived: %s", data);
}

public DataAction clown_OnDataSent(const char[] path, char[] data, int maxLen) {
Expand Down
3 changes: 3 additions & 0 deletions pawn/scripting/include/clown-core.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ methodmap ClownCore
//
// @return custom things
public static native DataAction SendSignal(const char[] path, const char[] data = NULL_STRING);

// @return Self API key
public static native bool GetMyToken(char[] buffer, int maxLen);
};

/**
Expand Down

0 comments on commit 13865ec

Please sign in to comment.