Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
D4edalus committed Sep 5, 2016
0 parents commit 66660aa
Show file tree
Hide file tree
Showing 9 changed files with 2,237 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.dub
dub.selections.json
*.so
10 changes: 10 additions & 0 deletions dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "cod4x_http_plugin",
"description": "CoD4X Server Plugin supporting http requests via gsc",
"copyright": "Copyright © 2015, dom",
"authors": ["dom"],
"targetType": "dynamicLibrary",
"dflags": ["-fPIC"],
"dependencies": {
}
}
26 changes: 26 additions & 0 deletions source/cod4x/callback_declarations.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module cod4x.callback_declarations;

import cod4x.structs;
import cod4x.server;

extern (C) void OnInfoRequest(pluginInfo_t *info);
extern (C) int OnInit();
extern (C) void OnMessageSent(char* message, int slot, qboolean *show, int mode);
extern (C) void OnPreFastRestart();
extern (C) void OnExitLevel();
extern (C) void OnPostFastRestart();
extern (C) void OnSpawnServer();
extern (C) void OnFrame();
extern (C) void OnOneSecond();
extern (C) void OnTenSeconds();
extern (C) void OnUdpNetEvent(netadr_t* from, void* data, int size, qboolean* returnNow);
extern (C) void OnUdpNetSend(netadr_t* to, void* data, int len, qboolean* returnNow);
extern (C) void OnPlayerConnect(int clientnum, netadr_t* netaddress, char* pbguid, char* userinfo, int authstatus, char* deniedmsg, int deniedmsgbufmaxlen);
extern (C) void OnPlayerConnectAuthFail(netadr_t* netaddress, char* pbguid, char* userinfo, int* authstatus, qboolean *denied);
extern (C) void OnPlayerDC(client_t* client, const char* reason);
extern (C) void OnClientSpawn(gentity_t* ent);
extern (C) void OnClientEnterWorld(client_t* client);
extern (C) void OnClientUserinfoChanged(client_t* client);
extern (C) void OnClientMoveCommand(client_t* client, usercmd_t* ucmd);
extern (C) void OnPlayerWantReservedSlot(netadr_t* from, char* pbguid, char* userinfo, int authstate, qboolean *isallowed);
extern (C) void OnModuleLoaded(client_t* client, char* fullpath, long checksum);
175 changes: 175 additions & 0 deletions source/cod4x/functions.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
module cod4x.functions;

import cod4x.server;

extern (C) char* Plugin_Cmd_Argv(int arg); // Get a command argument with index arg.
extern (C) int Plugin_Cmd_Argc(); // Get number of command arguments
extern (C) char *Plugin_Cmd_Args( char* buff, int bufsize );

// == Common ==
extern (C) void Plugin_G_LogPrintf( const char *fmt, ... );
extern (C) void Plugin_Printf( const char * fmt, ... ); // Print to a correct place (rcon, player console, logs)

extern (C) void Plugin_PrintWarning( const char *fmt, ...); // Print to a correct place (rcon, player console, logs)
extern (C) void Plugin_PrintError( const char *fmt, ...); // Print to a correct place (rcon, player console, logs)
extern (C) void Plugin_DPrintf( const char *fmt, ...); // Same as Com_Printf, only shows up when developer is set to 1
extern (C) char* Plugin_ParseGetToken(char* line); // Tokenize a string - get next token
extern (C) int Plugin_ParseTokenLength(char* token); // Tokenize a string - get the token's length
extern (C) void Plugin_ParseReset(); // Tokenize a string - Reset the parsers position
extern (C) void Plugin_Cbuf_AddText(const char* text);

// == Cvars ==

// All of the Cvars module functions are self explanatory
extern (C) void* Plugin_Cvar_RegisterString(const char *var_name, const char *var_value, int flags, const char *var_description);
extern (C) void* Plugin_Cvar_RegisterBool(const char *var_name, qboolean var_value, int flags, const char *var_description);
extern (C) void* Plugin_Cvar_RegisterInt(const char *var_name, int var_value, int min_value, int max_value, int flags, const char *var_description);
// extern (C) void* Plugin_Cvar_RegisterEnum(const char *var_name, char** valnames, int defaultval, int flags, const char *var_description);
extern (C) void* Plugin_Cvar_RegisterFloat(const char *var_name, float var_value, float min_value, float max_value, int flags, const char *var_description);
extern (C) void Plugin_Cvar_SetInt(void* var, int val);
extern (C) void Plugin_Cvar_SetBool(void* var, qboolean val);
extern (C) void Plugin_Cvar_SetString(void* var, char* string);
extern (C) void Plugin_Cvar_SetFloat(void* var, float val);
extern (C) int Plugin_Cvar_GetInteger(void *var);
extern (C) qboolean Plugin_Cvar_GetBoolean(void *var);
extern (C) float Plugin_Cvar_GetValue(void *var);
extern (C) immutable(char)* Plugin_Cvar_GetString(immutable(char)* var);

extern (C) void Plugin_Cvar_VariableStringBuffer(const char* cvarname, char* buff, size_t size);
extern (C) float Plugin_Cvar_VariableValue( const char *var_name );
extern (C) int Plugin_Cvar_VariableIntegerValue( const char *var_name );
extern (C) int Plugin_Cvar_VariableBooleanValue( const char *var_name );
//extern (C) char* Plugin_Cvar_VariableString( const char *var_name );
// Sets a cvar by name and by a string value which gets interpreted correctly depending on the cvar type
extern (C) void Plugin_Cvar_Set( const char *var_name, const char* value );


// == File handling functions == - Do we really need those?

extern (C) int Plugin_FS_SV_FOpenFileRead(const char *filename, void *fp); // Open a file for reading
extern (C) void Plugin_FS_SV_FOpenFileWrite(const char *filename); // Open a file for writing
//extern (C) int Plugin_FS_Read(void *buffer, int len, void f); // Read data from file
//extern (C) int Plugin_FS_ReadLine(void *buffer, int len, void f); // Read a line from file
//extern (C) int Plugin_FS_Write(const void *buffer, int len, void h); // Write to file
//extern (C) qboolean Plugin_FS_FCloseFile(void f); // Cloase an open file

//Writes the provided buffer into the file named by qpath. This is the most easiest way to write a file
extern (C) int Plugin_FS_SV_WriteFile( const char *qpath, const void *buffer, int size);


// == Networking ==

extern (C) int Plugin_NET_StringToAdr(const char* string, netadr_t* , netadrtype_t);
extern (C) qboolean Plugin_NET_CompareAdr (netadr_t *a, netadr_t *b);
extern (C) qboolean Plugin_NET_CompareBaseAdrMask(netadr_t *a, netadr_t *b, int netmask);
extern (C) qboolean Plugin_NET_CompareBaseAdr (netadr_t *a, netadr_t *b);
extern (C) char *Plugin_NET_AdrToString (netadr_t *a);
extern (C) char *Plugin_NET_AdrToStringShort (netadr_t *a);



// == Plugin Handler's functions ==

extern (C) clientScoreboard_t Plugin_GetClientScoreboard(int clientNum); // Get the scoreboard of a player
extern (C) int Plugin_Cmd_GetInvokerUid(); // Get UID of command invoker
extern (C) int Plugin_Cmd_GetInvokerSlot(); // Get slot number of command invoker
extern (C) int Plugin_GetPlayerUid(int slot); // Get UID of a plyer
extern (C) int Plugin_GetSlotCount(); // Get number of server slots
extern (C) qboolean Plugin_IsSvRunning(); // Is server running?
extern (C) void Plugin_ChatPrintf(int slot, const char *fmt, ...); // Print to player's chat (-1 for all)
extern (C) void Plugin_BoldPrintf(int slot, const char *fmt, ...); // Print to the player's screen (-1 for all)
extern (C) char *Plugin_GetPlayerName(int slot); // Get a name of a player
//extern (C) void Plugin_AddCommand(char *name, xcommand_t command, int defaultpower); // Add a server command
extern (C) void *Plugin_Malloc(size_t size); // Same as stdlib.h function malloc
extern (C) void Plugin_Free(void *ptr); // Same as stdlib.h function free
extern (C) void Plugin_Error(int code, const char *fmt, ...); // Notify the server of an error, action depends on code parameter
extern (C) int Plugin_GetLevelTime(); // Self explanatory
extern (C) int Plugin_GetServerTime(); // Self explanatory

// -- Functions for clients --

extern (C) void Plugin_DropClient( int clientnum, const char *reason ); // Kicks the client from server
extern (C) void Plugin_BanClient( uint clientnum, int seconds, int invokerid, char *reason ); //Bans the client for seconds from server. Seconds can be "-1" to create a permanent ban. invokerid can be 0 or the numeric uid. banreason can be NULL or a valid char* pointer.

// -- TCP Connection functions --
/*
connection is a static constant number. Every plugin can use a connection 0 up to 3. This is not a socket. This is handled internal.
You can not use the same number for 2 open connections on the same time.
*/
extern (C) qboolean Plugin_TcpConnect(int connection, const char* remote); // Open a new TCP connection - Returns qfalse if failed, remote can be a domainname
extern (C) int Plugin_TcpGetData(int connection, void *buf, int size); // Receive TCP data - buf and size is the receiving buffer. It returns -1 if the connection is closed. It returns 0 when no new data is available. All other return values is the number of bytes received.
extern (C) qboolean Plugin_TcpSendData(int connection, void *data, int len); // Send TCP data - buf and len point to the buffer which has the data to send. Len is the amount to bytes to send. Returns qfalse if something has failed.
extern (C) void Plugin_TcpCloseConnection(int connection); // Close an open TCP connection
extern (C) qboolean Plugin_UdpSendData(netadr_t* to, void* data, int len); // Send UDP data
extern (C) void Plugin_ServerPacketEvent(netadr_t* to, void* data, int len); // Receive UDP data


// -- UIDS / GUIDs --

extern (C) void Plugin_SetPlayerUID(int clientslot, int uid); // Set player's UID
extern (C) uint Plugin_GetPlayerUID(uint clientslot); // Get player's UID
extern (C) immutable(char)* Plugin_GetPlayerGUID(int clientslot); // Get player's GUID
extern (C) void Plugin_SetPlayerGUID(int clientslot, const char* guid); // Set player's GUID
extern (C) int Plugin_DoesServerUseUids(); // Self explanatory
extern (C) void Plugin_SetServerToUseUids(int useuids); // Self explanatory

extern (C) ulong Plugin_GetPlayerID(int clientslot);//Get the ID from player
extern (C) ulong Plugin_GetPlayerSteamID(int clientslot);//Get the ID from player


// == System functions ==

extern (C) int Plugin_Milliseconds(); // Milliseconds since server start
extern (C) void Plugin_RandomBytes( byte *string, int len );

// == Scriptfunctions ==

extern(C) alias Fun = void function();
extern (C) void Plugin_ScrAddFunction(immutable(char)* name, Fun fun);
//extern (C) void Plugin_ScrAddMethod(char *name, void (*function)(scr_entref_t object));
extern (C) void Plugin_ScrReplaceFunction(immutable(char)* name, Fun fun);
//extern (C) void Plugin_ScrReplaceMethod(char *name, xfunction_t function);

extern (C) void Plugin_Scr_AddEntity(gentity_t* ent);
extern (C) int Plugin_Scr_GetNumParam();
extern (C) int Plugin_Scr_GetInt( int );
extern (C) float Plugin_Scr_GetFloat( int );
extern (C) immutable(char*) Plugin_Scr_GetString( int );
extern (C) gentity_t* Plugin_Scr_GetEntity( int );
extern (C) short Plugin_Scr_GetConstString( int );
extern (C) int Plugin_Scr_GetType( int );
extern (C) void Plugin_Scr_GetVector( int, vec3_t* );
extern (C) void Plugin_Scr_Error( const char *string);
extern (C) void Plugin_Scr_ParamError( int, const char *string);
extern (C) void Plugin_Scr_ObjectError( const char *string);
extern (C) void Plugin_Scr_AddInt(int value);
extern (C) void Plugin_Scr_AddFloat(float);
extern (C) void Plugin_Scr_AddBool(qboolean);
extern (C) void Plugin_Scr_AddString(const char *string);
extern (C) void Plugin_Scr_AddUndefined();
extern (C) void Plugin_Scr_AddVector( vec3_t vec );
extern (C) void Plugin_Scr_AddArray( );
extern (C) void Plugin_Scr_MakeArray( );
extern (C) short Plugin_Scr_ExecEntThread( gentity_t* ent, int callbackHook, int numArgs);
extern (C) short Plugin_Scr_ExecThread( int callbackHook, int numArgs);
extern (C) void Plugin_Scr_FreeThread( short threadId);



extern (C) void Plugin_Scr_NotifyLevel(int constString, int numArgs);
extern (C) void Plugin_Scr_NotifyNum(int entityNum, int entType, int constString, int numArgs);
extern (C) void Plugin_Scr_Notify(gentity_t* ent, ushort constString, int numArgs);
extern (C) ushort Plugin_Scr_AllocString(const char*);



extern (C) playerState_t *Plugin_SV_GameClientNum( int num ); //Retrives the playerState_t* object from a client number

extern (C) gentity_t* Plugin_GetGentityForEntityNum(int entnum);
extern (C) client_t* Plugin_GetClientForClientNum(int clientnum);

extern (C) char* Plugin_SL_ConvertToString(int index);

extern (C) void Plugin_SV_SetConfigstring(int index, const char *text);
extern (C) void Plugin_SV_GetConfigstring( int index, char *buffer, int bufferSize );
90 changes: 90 additions & 0 deletions source/cod4x/plugin_declarations.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* Converted to D from plugin_declarations.h by htod */
module cod4x.plugin_declarations;
/*
===========================================================================
Copyright (C) 2010-2013 Ninja and TheKelm of the IceOps-Team
This file is part of IceOps Plugin Handler source code.
IceOps Plugin Handler source code is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
IceOps Plugin Handler source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
===========================================================================
*/

//C #define PLUGIN_HANDLER_VERSION_MAJOR 2
//C #define PLUGIN_HANDLER_VERSION_MINOR 302
const PLUGIN_HANDLER_VERSION_MAJOR = 2;
//PHandler v. 2.2
const PLUGIN_HANDLER_VERSION_MINOR = 302;

//C enum Plugin_Err{ // To be used as the code argument for Plugin_Error()
//C P_ERROR_WARNING, // Save the error string to serverlog - for minor errors
//C P_ERROR_DISABLE, // Save the error string to serverlog and disable the plugin - for serious errors
//C P_ERROR_TERMINATE // Save the error string to serverlog and close the server - for critical errors
//C };
enum Plugin_Err
{
P_ERROR_WARNING,
P_ERROR_DISABLE,
P_ERROR_TERMINATE,
}
//C typedef enum{
//C P_HASH_SHA1,
//C P_HASH_SHA256,
//C P_HASH_TIGER
//C }pluginHash_t;
enum
{
P_HASH_SHA1,
P_HASH_SHA256,
P_HASH_TIGER,
}
extern (C):
alias int pluginHash_t;

//C typedef enum{
//C P_CIPHER_AES,
//C P_CIPHER_SERPENT
//C }pluginCipher_t;
enum
{
P_CIPHER_AES,
P_CIPHER_SERPENT,
}
alias int pluginCipher_t;

//C typedef struct{
//C int major;
//C int minor;
//C }version_t;
struct version_t
{
int major;
int minor;
}

//C typedef struct{ // To be used in OnInfoRequest
//C version_t handlerVersion; // Requested plugin handler version - mandatory field
//C version_t pluginVersion; // Version of your plugin - optional
//C char fullName[64]; // Full plugin name, short name is the filename without extension - optional
//C char shortDescription[128]; // Describe in a few words what this plugin does - optional
//C char longDescription[1024]; // Full description - optional
//C }pluginInfo_t;
struct pluginInfo_t
{
version_t handlerVersion;
version_t pluginVersion;
char [64]fullName;
char [128]shortDescription;
char [1024]longDescription;
}
Loading

0 comments on commit 66660aa

Please sign in to comment.