Began AMXx bindings

This commit is contained in:
David Anderson 2005-04-03 03:26:35 +00:00
parent abbb2f2cc2
commit acb2b27852
7 changed files with 128 additions and 4 deletions

51
dlls/nvault/amxxapi.cpp Executable file
View File

@ -0,0 +1,51 @@
#include "amxxapi.h"
CVector<Vault *> Vaults;
static cell nvault_open(AMX *amx, cell *params)
{
int len, id=-1;
char *name = MF_GetAmxString(amx, params[1], 0, &len);
char *file = MF_BuildPathname("%s/nvault/%s", LOCALINFO("amxx_datadir"), name);
for (size_t i=0; i<Vaults.size(); i++)
{
if (!Vaults.at(i))
{
id = i;
} else if (strcmp(Vaults.at(i)->GetFileName(), file) == 0) {
return i;
}
}
Vault *v = new Vault(file);
if (id != -1)
{
Vaults[id] = v;
} else {
Vaults.push_back(v);
id = (int)Vaults.size()-1;
}
return id;
}
static cell nvault_get(AMX *amx, cell *params)
{
unsigned int id = params[1];
if (id > Vaults.size() || !Vaults.at(i))
{
MF_LogError(amx, AMX_ERR_NATIVE, "Invalid vault id: %d\n", id);
return 0;
}
}
void OnAmxxAttach()
{
//create the dir if it doesn't exist
#ifdef __linux__
mkdir(MF_BuildPathname("%s/nvault", LOCALINFO("amxx_datadir")), 0700);
#else
mkdir(MF_BuildPathname("%s/nvault", LOCALINFO("amxx_datadir"));
#endif
}

13
dlls/nvault/amxxapi.h Executable file
View File

@ -0,0 +1,13 @@
#ifndef _INCLUDE_AMXXAPI_H
#define _INCLUDE_AMXXAPI_H
#include "sdk/CVector.h"
#include "hash.h"
#include "nvault.h"
#include "journal.h"
#include "sdk/amxxmodule.h"
AMX_NATIVE_INFO nVault_natives[];
#endif //_INCLUDE_AMXXAPI_H

View File

@ -15,6 +15,11 @@ Vault::~Vault()
}
}
const char *Vault::GetFileName()
{
return m_File.c_str();
}
void Vault::Clear()
{
if (m_Vault)

View File

@ -46,6 +46,7 @@ public:
bool KeyExists(const char *key);
void Clear();
void EraseKey(const char *key);
const char *GetFileName();
private:
void _WriteHeaders(FILE *fp, uint32_t hashes);
private:

37
dlls/nvault/nvault.inc Executable file
View File

@ -0,0 +1,37 @@
/* nVault
*
* A binary (hash table) vault with journaling.
* (C)2005 David "BAILOPAN" Anderson
*/
#if defined _nvault_included
#endinput
#endif
#define _nvault_included
/* Opens a vault and returns an id to it
* The vault name is appended with ".nvt" and stored in
* datadir/vault.
*/
native vault_open(const name[]);
/* Reads from a vault.
* No extra params - gets as an int
* One extra param - Float byref
* Two extra params - gets as a string
*/
native nvault_get(id, const name[], ...);
/* Reads a data from given key.
* If len is set to zero then get_vaultdata
* returns value as an number. */
native get_vaultdata(const key[], data[] = "", len = 0);
/* Sets a data under given key. */
native set_vaultdata(const key[], const data[] = "" );
/* Removes a key from vault.*/
native remove_vaultdata(const key[]);
/* Checks if a key exists in the vault.*/
native vaultdata_exists(const key[]);

View File

@ -21,17 +21,19 @@
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;NVAULT_EXPORTS"
MinimalRebuild="TRUE"
ExceptionHandling="FALSE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
RuntimeLibrary="5"
StructMemberAlignment="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
Detect64BitPortabilityProblems="FALSE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/nvault.dll"
OutputFile="$(OutDir)/nvault_amxx.dll"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/nvault.pdb"
@ -115,6 +117,18 @@
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\amxxapi.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
ExceptionHandling="FALSE"
RuntimeLibrary="5"
StructMemberAlignment="3"
Detect64BitPortabilityProblems="FALSE"/>
</FileConfiguration>
</File>
<File
RelativePath=".\hash.cpp">
<FileConfiguration
@ -141,6 +155,9 @@
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\amxxapi.h">
</File>
<File
RelativePath=".\hash.h">
</File>

View File

@ -27,7 +27,7 @@
//#define FN_AMXX_QUERY OnAmxxQuery
// AMXX attach
// Do native functions init here (MF_AddNatives)
// #define FN_AMXX_ATTACH OnAmxxAttach
#define FN_AMXX_ATTACH OnAmxxAttach
// AMXX detach
//#define FN_AMXX_DETACH OnAmxxDetach
// All plugins loaded