Beispiel #1
0
qboolean Sys_CreateNewThread(void* (*ThreadMain)(void*), threadid_t *tid, void* arg)
{
	char errMessageBuf[512];
	DWORD lastError;

	
	HANDLE thid = CreateThread(	NULL, // LPSECURITY_ATTRIBUTES lpsa,
								0, // DWORD cbStack,
								(LPTHREAD_START_ROUTINE)ThreadMain, // LPTHREAD_START_ROUTINE lpStartAddr,
								arg, // LPVOID lpvThreadParm,
								0, // DWORD fdwCreate,
								tid );
	
	if(thid == NULL)
	{
		lastError = GetLastError();
		
		if(lastError != 0)
		{
			FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, lastError, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (LPSTR)errMessageBuf, sizeof(errMessageBuf) -1, NULL);
			Com_PrintError("Failed to start thread with error: %s\n", errMessageBuf);
		
		}else{
			Com_PrintError("Failed to start thread!\n");
		}
		return qfalse;
	}
	return qtrue;
}
Beispiel #2
0
P_P_F qboolean Plugin_TcpSendData(int connection, void* data, int len)
{


    int pID;
    //Identify the calling plugin
    pID = PHandler_CallerID();
    if(pID<0){
        Com_Printf("Plugin_TcpSendData: Error! Tried get TCP data for unknown plugin!\n");
        return qfalse;
    }
    if(pluginFunctions.plugins[pID].enabled==qfalse){
        Com_Printf("^1WARNING^7: Plugin_TcpSendData: Tried get TCP data for a disabled plugin!\n");
        return qfalse;
    }
    if(connection >= PLUGIN_MAX_SOCKETS || connection < 0){
        Com_PrintError("Plugin_TcpSendData: Second argument can only be a value inside the range: 0...%d plugin ID: #%d\n", PLUGIN_MAX_SOCKETS, pID);
        return qfalse;
    }
    if(data == NULL){
        Com_PrintError("Plugin_TcpSendData: Second argument can not be a NULL-Pointer for plugin ID: #%d\n", pID);
        return qfalse;
    }

    return PHandler_TcpSendData(pID, connection, data, len);
}
void PHandler_ScrAddMethod(char *name, xfunction_t function, qboolean replace, int pID)
{
    int i;

    if(pID>=MAX_PLUGINS){
        Com_Printf("Error: tried adding a script command for a plugin with non existent pID. pID supplied: %d.\n",pID);
        return;
    }else if(pID<0){
        Com_Printf("Plugin Handler error: Plugin_ScrAddMethod or Plugin_ScrReplaceMethod called from not within a plugin or from a disabled plugin!\n");
        return;
    }
    if(!pluginFunctions.plugins[pID].loaded){
        Com_Printf("Error: Tried adding a command for not loaded plugin! PID: %d.\n",pID);
    }
    Com_Printf("Adding a plugin script method for plugin %d, command name: %s.\n",pID, name);
    for(i = 0; i < MAX_SCRIPTFUNCTIONS; i++ )
    {
        if(pluginScriptCallStubs.s[pID * MAX_SCRIPTFUNCTIONS + i].name[0] == 0)
        {
            break;
        }
    }
    if(i == MAX_SCRIPTFUNCTIONS)
    {
        Com_PrintError("Exceeded maximum number of scrip-functions (%d) for plugin\n", MAX_SCRIPTFUNCTIONS);
        return;
    }
    if(strlen(name) >= sizeof(pluginScriptCallStubs.s[pID * MAX_SCRIPTFUNCTIONS + i].name))
    {
        Com_PrintError("Exceeded maximum length of name for scrip-method: %s (%d) for plugin.\n", name, sizeof(pluginScriptCallStubs.s[pID * MAX_SCRIPTFUNCTIONS + i].name) );
        return;
    }
    if(replace == qtrue)
    {
        Scr_RemoveMethod(name);
    }
    if(Scr_AddMethod(name, (xfunction_t)&pluginScriptCallStubs.s[pID * MAX_SCRIPTFUNCTIONS + i].dyncallstub, qfalse) == qfalse)
    {
        Com_PrintError("Failed to add this script method: %s for plugin\n", name);
        return;
    }
    Sys_MemoryProtectWrite(pluginScriptCallStubs.s, sizeof(pluginScriptCallStubs.s));
    Q_strncpyz(pluginScriptCallStubs.s[pID * MAX_SCRIPTFUNCTIONS + i].name, name, sizeof(pluginScriptCallStubs.s[pID * MAX_SCRIPTFUNCTIONS + i].name));
    pluginScriptCallStubs.s[pID * MAX_SCRIPTFUNCTIONS + i].isMethod = qtrue;
    PHandler_InitDynCallStub(&pluginScriptCallStubs.s[pID * MAX_SCRIPTFUNCTIONS + i].dyncallstub, function, pID);
    Sys_MemoryProtectExec(pluginScriptCallStubs.s, sizeof(pluginScriptCallStubs.s));
    pluginFunctions.plugins[pID].scriptmethods++;
}
void dMessage (int num, const char *msg, ...)
{
  va_list ap;
  char buf[2048];

  va_start (ap, msg);
  Q_vsnprintf(buf, sizeof(buf), msg, ap);
  va_end(ap);

  if(num)
  {
    Com_PrintError("\nODE Message %d: %s\n", num, buf);
  }else{
    Com_PrintError("\nODE Message: %s\n", buf);
  }
}
Beispiel #5
0
ftRequest_t* FileDownloadRequest( const char* url)
{
	/* Strip away trailing spaces */
	ftprotocols_t proto;

	
	while(*url == ' ')
		url++;
	
	if(!Q_stricmpn("ftp://", url, 6)){
		
		url += 6;
		proto = FT_PROTO_FTP;
	}else if(!Q_stricmpn("http://", url, 7)){
		
		url += 7;
		proto = FT_PROTO_HTTP;
	}else {
		proto = -1;
	}

	
	switch(proto)
	{
		case FT_PROTO_FTP:
			return FTP_DLRequest(url);
		case FT_PROTO_HTTP:
			return HTTPGetRequest(url);
		default:
			Com_PrintError("Unsupported File Transfer Protocol in url: %s!\n", url);
			return NULL;
	}
	return NULL;
}
void NET_TCPPacketEvent(netadr_t* from, byte* bufData, int len, int socketfd, int connectionId, int serviceId)
{
        int i;
        msg_t msg;

        for(i = 0; i < MAX_TCPEVENTS; i++)
        {
            if(tcpevents[i].serviceId == serviceId)
            {

                msg.data = bufData;
                msg.cursize = len;
                msg.maxsize = len;
                msg.readcount = 0;
                msg.bit = 0;
                msg.readonly = qtrue;
                msg.overflowed = qfalse;

                if(tcpevents[i].tcpevent(from, &msg, socketfd, connectionId))
                {
                    NET_TcpCloseSocket(socketfd);
                }
                return;
            }
        }

        Com_PrintError("NET_TCPPacketEvent: Bad serviceId: %d\n", serviceId);
        NET_TcpCloseSocket(socketfd);
        return; //Close connection
}
Beispiel #7
0
void HStorage_WriteDataToFile(varStorage_t* vobj, const char* filename){

    fileHandle_t file;
    char infostring[8192], buf[128];
    int i;
    char name[MAX_VARNAME];
    char *string;
    int count;
    vsMemObj_t* obj;
    vsValue_t value;
    varType_t type;
    mvabuf;

    obj = vobj->memObj;

    file = FS_SV_FOpenFileWrite(va("%s.tmp", filename));
    if(!file){
        Com_PrintError("HStorage_WriteDataToFile: Can not open %s for writing\n", filename);
        return;
    }

    HStorage_IterInit( obj );

    while(HStorage_IterHasNext( obj ))
    {
            count = HStorage_IterGetNextInfo( obj, name, &type );

            if(count == 0)
            {
                continue;
            }

            *infostring = 0;
            BigInfo_SetValueForKey(infostring, "name", name);
            BigInfo_SetValueForKey(infostring, "type", HStorage_EnumToVarType(type));
            BigInfo_SetValueForKey(infostring, "count", va("%d", count));

            for(i = 0; i < count; i++)
            {
                if(HStorage_GetDataInternal(obj, &value) == 0)
                {
                    break;
                }

                if(type == VSVAR_STRING)
                {
                    string = HStorage_ValueToString(type, &value, buf, sizeof(buf));
                    BigInfo_SetEncodedValueForKey(infostring, va("v%d", i), string, strlen(string));
                }else{
                    BigInfo_SetValueForKey(infostring, va("v%d", i), HStorage_ValueToString(type, &value, buf, sizeof(buf)));
                }
            }

            Q_strcat(infostring, sizeof(infostring), "\\\n");
            FS_Write(infostring, strlen(infostring), file);
    }
    FS_FCloseFile(file);
    FS_SV_HomeCopyFile(va("%s.tmp", filename) , (char*)filename);
}
Beispiel #8
0
P_P_F qboolean Plugin_UdpSendData(netadr_t* to, void* data, int len)
{
    int pID;

    if(to == NULL){
        pID = PHandler_CallerID();
        Com_PrintError("Plugin_UdpSendData: First argument can not be a NULL-Pointer for plugin ID: #%d\n", pID);
        return qfalse;
    }

    if(data == NULL){
        pID = PHandler_CallerID();
        Com_PrintError("Plugin_UdpSendData: First argument can not be a NULL-Pointer for plugin ID: #%d\n", pID);
        return qfalse;
    }
    return Sys_SendPacket( len, data, to);
}
void Sys_SetExitCmdline(const char* cmdline)
{
	if(strlen(cmdline) >= sizeof(exit_cmdline))
	{
		Com_PrintError("Sys_SetExitCmdline: Exceeded length of %d characters.\n", sizeof(exit_cmdline) -1);
	}
	Q_strncpyz(exit_cmdline, cmdline, sizeof(exit_cmdline));
}
//duration is in minutes
void SV_PlayerAddBanByip(netadr_t *remote, char *reason, int uid, char* guid, int adminuid, int expire){		//Gets called by future implemented ban-commands and if a prior ban got enforced again

    ipBanList_t *list;
    int i;
    int oldest =	0;
    unsigned int oldestTime = 0;
    int duration;

    if(!remote)
    {
        Com_PrintError("SV_PlayerAddBanByip: IP address is NULL\n");
        return;

    }

    if(!ipbantime || ipbantime->integer == 0)
        return;

    for(list = &ipBans[0], i = 0; i < 1024; list++, i++){	//At first check whether we have already an entry for this player
        if(NET_CompareBaseAdr(remote, &list->remote)){
            break;
        }
	if (list->systime < oldestTime) {
		oldestTime = list->systime;
		oldest = i;
	}
    }

    if(i == 1024){
	 list = &ipBans[oldest];
    }
    list->remote = *remote;

    Q_strncpyz(list->banmsg, reason, 128);

    if(guid && strlen(guid) == 32)
        guid += 24;

    if(guid && strlen(guid) == 8)
    {

        Q_strncpyz(list->guid, guid, sizeof(list->guid));

    }

    list->expire = expire;
    list->uid = uid;
    list->adminuid = adminuid;

    duration = expire - Com_GetRealtime();
    if(duration > ipbantime->integer*60 || expire == -1)
        duration = ipbantime->integer*60;	//Don't ban IPs for more than MAX_IPBAN_MINUTES minutes as they can be shared (Carrier-grade NAT)

    list->systime = Sys_Milliseconds();

    list->timeout = Com_GetRealtime() + duration;

}
void PHandler_ScrAddMethod(char *name, xfunction_t function, qboolean replace, int pID)
{
    int i;

    if(pID>=MAX_PLUGINS){
        Com_Printf("Error: tried adding a script command for a plugin with non existent pID. pID supplied: %d.\n",pID);
        return;
    }else if(pID<0){
        Com_Printf("Plugin Handler error: Plugin_ScrAddMethod or Plugin_ScrReplaceMethod called from not within a plugin or from a disabled plugin!\n");
        return;
    }
    if(!pluginFunctions.plugins[pID].loaded){
        Com_Printf("Error: Tried adding a command for not loaded plugin! PID: %d.\n",pID);
    }
    Com_Printf("Adding a plugin script method for plugin %d, method name: %s.\n",pID, name);
    for(i = 0; i < (sizeof(pluginFunctions.plugins[0].scr_methods) / sizeof(pluginCmd_t)); i++ )
    {
        if(pluginFunctions.plugins[pID].scr_methods[i].xcommand == NULL)
        {
            break;
        }
    }
    if(i == (sizeof(pluginFunctions.plugins[0].scr_methods) / sizeof(pluginCmd_t)))
    {
        Com_PrintError("Exceeded maximum number of scrip-methods (%d) for plugin\n", (sizeof(pluginFunctions.plugins[0].scr_methods) / sizeof(pluginCmd_t)));
        return;
    }
    if(strlen(name) >= sizeof(pluginFunctions.plugins[0].scr_methods[0].name))
    {
        Com_PrintError("Exceeded maximum length of name for scrip-method: %s (%d) for plugin %s\n", name, sizeof(pluginFunctions.plugins[0].scr_methods[0].name) ,name);
        return;
    }
    if(replace == qtrue)
    {
        Scr_RemoveMethod(name);
    }
    if(Scr_AddMethod(name, function, qfalse) == qfalse)
    {
        Com_PrintError("Failed to add this script function: %s for plugin\n", name);
        return;
    }
    Q_strncpyz(pluginFunctions.plugins[pID].scr_methods[i].name, name, sizeof(pluginFunctions.plugins[0].scr_methods[0].name));
    pluginFunctions.plugins[pID].scr_methods[i].xcommand = function;
    pluginFunctions.plugins[pID].scriptmethods ++;
}
Beispiel #12
0
void PHandler_Unload(int id) // Unload a plugin, safe for use.
{
    static qboolean unloading = qfalse;
    void *lib_handle;
    int i;
    
    if(unloading){
	Com_PrintError("PHandler_Unload: tried to unload plugin #%d from it's destructor!\n",id);
	return;
    }
    
    
    if(pluginFunctions.plugins[id].loaded){
        if(pluginFunctions.plugins[id].exports != 0){ // Library-plugins cannot be unloaded, see plugins/readme.txt
            Com_PrintError("PHandler_Unload: Cannot unload a library plugin!\n");
            return;
        }
        if(pluginFunctions.plugins[id].scriptfunctions != 0 || pluginFunctions.plugins[id].scriptmethods != 0){
            // Script-library plugins cannot be unloaded, see plugins/readme.txt
            Com_PrintError("PHandler_Unload: Cannot unload a script-library plugin!\n");
            return;
        }
        unloading = qtrue; // Preventing endless recursion...
        if(pluginFunctions.plugins[id].OnUnload != NULL){
            pluginFunctions.hasControl = id;
            (*pluginFunctions.plugins[id].OnUnload)();
            pluginFunctions.hasControl = PLUGIN_UNKNOWN;
        }
        unloading = qfalse;
        // Remove all server commands of the plugin
        for(i=0;i<pluginFunctions.plugins[id].cmds;i++){
            if(pluginFunctions.plugins[id].cmd[i].xcommand!=NULL){
                Com_DPrintf("Removing command \"%s\"...\n",pluginFunctions.plugins[id].cmd[i].name);
                Cmd_RemoveCommand(pluginFunctions.plugins[id].cmd[i].name);
            }

        }
        lib_handle = pluginFunctions.plugins[id].lib_handle;                // Save the lib handle
        Com_Memset(&(pluginFunctions.plugins[id]), 0x00, sizeof(plugin_t));     // Wipe out all the data
        Sys_CloseLibrary(lib_handle);                                                // Close the dll as there are no more references to it
        --pluginFunctions.loadedPlugins;
    }else{
        Com_Printf("Tried unloading a not loaded plugin!\nPlugin ID: %d.",id);
    }
}
P_P_F void Plugin_Error(int code, char *string)
{
    volatile int pID = PHandler_CallerID();
    if(pID<0){
        Com_PrintError("Plugin Error called from unknown plugin!\n");
        return;
    }
    PHandler_Error(pID,code,string);
}
Beispiel #14
0
void* Sys_LoadLibrary(const char* dlfile)
{
	void* handle = dlopen(dlfile, RTLD_LAZY);
	currentLibHandle = handle;
	if(handle == NULL)
	{
		Com_PrintError("Sys_LoadLibrary error: %s\n", dlerror());
	}
	return handle;
}
Beispiel #15
0
qboolean Sys_CreateNewThread(void* (*ThreadMain)(void*), threadid_t *tid, void* arg)
{
	int err;

	err = pthread_create(tid, NULL, ThreadMain, arg);
	if(err != 0)
	{
		Com_PrintError("Thread creation failed with the following error: %s\n", strerror(errno));
		return qfalse;
	}
	return qtrue;
}
Beispiel #16
0
const char* PHandler_OpenTempFile(char* name, char* fullfilepath, int fplen){ // Load a plugin, safe for use

    void *buf;
    int len;
    int wlen;
    char* file;
    char tmpfile[MAX_QPATH];
    char filepath[MAX_QPATH];
	
    Com_sprintf(filepath, sizeof(filepath),"plugins/%s" DLL_EXT, name);

    len = FS_ReadFile(filepath, &buf);

    if(len < 100)
        len = FS_SV_ReadFile( filepath, &buf );

    if(len < 100)
    {
        Com_Printf("No such file found: %s. Can not load this plugin.\n", filepath);
        return NULL;

    }
	
	if(PHandler_VerifyPlugin(buf, len) == qfalse)
	{
	    Com_Printf("%s is not a plugin file or is corrupt or contains disallowed functions.\n", filepath);
		FS_FreeFile(buf);
		return NULL;
	}
	Com_sprintf(tmpfile, sizeof(tmpfile), "plugin.%s.tmp", name);
    /* If there is already such a file remove it now */
    file = FS_SV_GetFilepath( tmpfile, fullfilepath, fplen );
    if(file)
    {
        FS_RemoveOSPath(file);
        file = FS_SV_GetFilepath( tmpfile, fullfilepath, fplen );
        if(file)
        {
            FS_RemoveOSPath(file);
        }
    }
    wlen = FS_SV_HomeWriteFile( tmpfile, buf, len);
    if(wlen != len)
    {
            Com_PrintError("fs_homepath is readonly. Can not load this plugin.\n");
            FS_FreeFile(buf);
            return NULL;
    }
    //Additional test if a file is there and creation of full filepath
    FS_FreeFile(buf);
    return FS_SV_GetFilepath( tmpfile, fullfilepath, fplen );
}
Beispiel #17
0
void SV_InitBanlist(){

    Com_Memset(svse.ipBans,0,sizeof(svse.ipBans));
    banlist = Cvar_RegisterString("banlistfile", "banlist.dat", CVAR_INIT, "Name of the file which holds the banlist");
    current_banlist_size = BANLIST_DEFAULT_SIZE;
    current_banindex = 0;
    svse.banList = realloc(NULL, current_banlist_size);//Test for NULL ?
    if(svse.banList){
        SV_LoadBanlist();
    }else{
        Com_PrintError("Failed to allocate memory for the banlist. Banlist is disabled\n");
    }
}
void SV_InitBanlist(){

    Com_Memset(ipBans,0,sizeof(ipBans));
    banlistfile = Cvar_RegisterString("banlist_filename", "banlist.dat", CVAR_INIT, "Name of the file which holds the banlist");
    ipbantime = Cvar_RegisterInt("banlist_maxipbantime", MAX_DEFAULT_IPBAN_MINUTES, 0, 20160, 0, "Limit of minutes to keep a ban against an ip-address up");
    current_banlist_size = BANLIST_DEFAULT_SIZE;
    current_banindex = 0;
    banlist = realloc(NULL, current_banlist_size);//Test for NULL ?
    if(banlist){
        SV_LoadBanlist();
    }else{
        Com_PrintError("Failed to allocate memory for the banlist. Banlist is disabled\n");
    }
}
Beispiel #19
0
void Sys_ReplaceProcess( char *cmdline )
{

	int i;
	char *argv[256];

	Cmd_TokenizeString(cmdline);
	if(Cmd_Argc() < 256)
	{
		for(i = 0; i < Cmd_Argc(); i++)
		{
			argv[i] = CopyString(Cmd_Argv(i));
		}
		argv[i] = NULL;

		execv( argv[0], argv );
		Com_PrintError( "Sys_ReplaceProcess: execv failed: %s\n", strerror( errno ) );
	}else{
		Com_PrintError( "Sys_ReplaceProcess: Exceeded limit of 256 commandline arguments.\nCommandline is: %s\n", cmdline);
	}
	Cmd_EndTokenizedString();
	_exit( 0 );
}
Beispiel #20
0
/*
============
Cbuf_InsertText

Adds command text immediately after the current command
Adds a \n to the text
============
*/
void Cbuf_InsertText( const char *text ) {
	int		len;
	int		i;
	byte*		new_buf;

	len = strlen( text ) + 1;

	Sys_EnterCriticalSection(CRIT_CBUF);

	
	if ( len + cmd_text.cursize > cmd_text.maxsize ) {

		if(cmd_text.data == cmd_text_buf)
		{
			new_buf = realloc(NULL, len + cmd_text.cursize);
			if(new_buf != NULL)
			{
				Com_Memcpy(new_buf, cmd_text_buf, len + cmd_text.cursize);
			}
		}else{
			new_buf = realloc(cmd_text.data, len + cmd_text.cursize);
		}

		if(new_buf == NULL)
		{
			Com_PrintError( "Cbuf_InsertText overflowed ; realloc failed\n" );
			
			Sys_LeaveCriticalSection(CRIT_CBUF);
			return;
		}
		cmd_text.data = new_buf;
		cmd_text.maxsize = len + cmd_text.cursize;
	}

	// move the existing command text
	for ( i = cmd_text.cursize - 1 ; i >= 0 ; i-- ) {
		cmd_text.data[ i + len ] = cmd_text.data[ i ];
	}

	// copy the new text in
	Com_Memcpy( cmd_text.data, text, len - 1 );

	// add a \n
	cmd_text.data[ len - 1 ] = '\n';

	cmd_text.cursize += len;
	
	Sys_LeaveCriticalSection(CRIT_CBUF);
}
Beispiel #21
0
P_P_F int Plugin_TcpGetData(int connection, void* buf, int size)
{
    int pID;
    //Identify the calling plugin
    pID = PHandler_CallerID();
    if(pID<0){
        Com_Printf("Plugin_TcpGetData: Error! Tried get TCP data for unknown plugin!\n");
        return -1;
    }
    if(pluginFunctions.plugins[pID].enabled==qfalse){
        Com_Printf("^1WARNING^7: Plugin_TcpGetData: Tried get TCP data for a disabled plugin!\n");
        return -1;
    }
    if(connection >= PLUGIN_MAX_SOCKETS || connection < 0){
        Com_PrintError("Plugin_TcpGetData: First argument can only be a value inside the range: 0...%d plugin ID: #%d\n", PLUGIN_MAX_SOCKETS, pID);
        return -1;
    }
    if(buf == NULL){
        Com_PrintError("Plugin_TcpGetData: Third argument can not be a NULL-Pointer for plugin ID: #%d\n", pID);
        return -1;
    }

    return PHandler_TcpGetData(pID, connection, buf, size);
}
Beispiel #22
0
P_P_F void Plugin_AddCommand(char *name, xcommand_t xcommand, int power)
{
    volatile int pID;
    pID = PHandler_CallerID();
    if(pID>=MAX_PLUGINS){
        Com_PrintError("Tried adding a command for a plugin with non existent pID. pID supplied: %d.\n",pID);
        return;
    }else if(pID<0){
        Com_PrintError("Plugin_AddCommand called from not within a plugin or from a disabled plugin!\n");
        return;
    }
    if(!pluginFunctions.plugins[pID].loaded){
        Com_PrintError("Tried adding a command for not loaded plugin! PID: %d.\n",pID);
    }
    Com_DPrintf("Adding a plugin command for plugin %d, command name: %s.\n",pID,name);
    Cmd_AddCommand(name,PHandler_CmdExecute_f);
    Cmd_SetPower(name, power);
    pluginFunctions.plugins[pID].cmd[pluginFunctions.plugins[pID].cmds].xcommand = xcommand;
    strcpy(pluginFunctions.plugins[pID].cmd[pluginFunctions.plugins[pID].cmds++].name,name);
    Com_DPrintf("Command added.\n");
   // pluginFunctions.plugins[pID].


}
qboolean PHandler_TcpConnect(int pID, const char* remote, int connection)
{
    if(pluginFunctions.plugins[pID].sockets[connection].sock < 1){
        pluginFunctions.plugins[pID].sockets[connection].sock = NET_TcpClientConnect( remote );

        if(pluginFunctions.plugins[pID].sockets[connection].sock < 1){
            Com_Printf("Plugins: Notice! Error connecting to server: %s for plugin #%d!\n", remote, pID);
            return qfalse;
        }
        NET_StringToAdr(remote, &pluginFunctions.plugins[pID].sockets[connection].remote, NA_UNSPEC);
        return qtrue;
    }
    Com_PrintError("Plugin_TcpConnect: Connection id %d is already in use for plugin #%d!\n",connection ,pID );

    return qfalse;
}
Beispiel #24
0
P_P_F void Plugin_SetPlayerUID(unsigned int clientslot, unsigned int uid)
{
    client_t *cl;
    int PID = PHandler_CallerID();
	mvabuf;
#ifndef COD4X17A	
	Com_PrintError("Plugin_SetPlayerUID: This command is in CoD4X18+ deprecated. Nothing is set\n");
    return;
#endif
	if(clientslot > sv_maxclients->integer)
    {
        PHandler_Error(PID,P_ERROR_DISABLE, va("Plugin tried to set UID for bad client: %d\n", clientslot));
    }
    cl = &svs.clients[clientslot];
    cl->uid = uid;
}
Beispiel #25
0
P_P_F void Plugin_Error(int code, const char *fmt, ...)
{
    va_list argptr;
    char msg[1024];

    volatile int pID = PHandler_CallerID();

    if(pID<0){
        Com_PrintError("Plugin Error called from unknown plugin!\n");
        return;
    }

    va_start (argptr,fmt);
    Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
    va_end (argptr);

    PHandler_Error(pID,code,msg);
}
void SV_WriteBanlist(){

    banList_t *this;
    time_t aclock;
    time(&aclock);
    fileHandle_t file;
    char infostring[1024];
    int i;

    file = FS_SV_FOpenFileWrite(va("%s.tmp", banlistfile->string));
    if(!file){
        Com_PrintError("SV_WriteBanlist: Can not open %s for writing\n",banlistfile->string);
        return;
    }

    this = banlist;
    if(!this)
        return;

    for(i = 0 ; i < current_banindex; this++, i++){

        if(this->expire == (time_t)-1 || this->expire > aclock){

            *infostring = 0;
            if(this->playeruid > 0){
                Info_SetValueForKey(infostring, "uid", va("%i", this->playeruid));
            }else if(this->pbguid[7]){
                Info_SetValueForKey(infostring, "guid", this->pbguid);
            }else{
                continue;
            }
            Info_SetValueForKey(infostring, "nick", this->playername);
            Info_SetValueForKey(infostring, "rsn", this->reason);
            Info_SetValueForKey(infostring, "exp", va("%i", this->expire));
            Info_SetValueForKey(infostring, "auid", va("%i", this->adminuid));
            Q_strcat(infostring, sizeof(infostring), "\\\n");
            FS_Write(infostring,strlen(infostring),file);
        }
    }
    FS_FCloseFile(file);
    FS_SV_HomeCopyFile(va("%s.tmp", banlistfile->string) ,banlistfile->string);
//    FS_SV_Rename(va("%s.tmp", banlist->string),banlist->string);
}
qboolean SV_OversizeBanlistAlign(){

    banList_t *new_blist;
    int newSize;

    if(current_banlist_size <= (current_banindex + 1) * sizeof(banList_t)){//Memory extension
        newSize = current_banlist_size + current_banlist_size / 4;
        new_blist = realloc(banlist, newSize);
        if(new_blist){
            banlist = new_blist;
            current_banlist_size = newSize;

        }else{
            Com_PrintError("Could not allocate enougth memory to extend the size of banlist. Failed to add new bans\n");
            return qfalse;
        }
    }
    return qtrue;
}
Beispiel #28
0
P_P_F void Plugin_TcpCloseConnection(int connection)
{
    int pID;
    //Identify the calling plugin
    pID = PHandler_CallerID();
    if(pID<0){
        Com_Printf("Plugin_TcpCloseConnection: Error! Tried get close a connection for unknown plugin!\n");
        return;
    }
    if(pluginFunctions.plugins[pID].enabled==qfalse){
        Com_Printf("^1WARNING^7: Plugin_TcpCloseConnection: Tried to close a connection for a disabled plugin!\n");
        return;
    }
    if(connection >= PLUGIN_MAX_SOCKETS || connection < 0){
        Com_PrintError("Plugin_TcpCloseConnection: Second argument can only be a value inside the range: 0...%d plugin ID: #%d\n", PLUGIN_MAX_SOCKETS, pID);
        return;
    }
    PHandler_TcpCloseConnection(pID, connection);
}
Beispiel #29
0
P_P_F qboolean Plugin_TcpConnect( int connection, const char* remote)
{
    int pID;
    //Identify the calling plugin
    pID = PHandler_CallerID();
    if(pID<0){
        Com_Printf("Plugins: Error! Tried open a TCP-Connection for unknown plugin!\n");
        return qfalse;
    }
    if(pluginFunctions.plugins[pID].enabled==qfalse){
        Com_Printf("^1WARNING^7: Tried open a TCP-Connection for a disabled plugin!\n");
        return qfalse;
    }
    if(connection >= PLUGIN_MAX_SOCKETS || connection < 0){
        Com_PrintError("Plugin_TcpConnect: Second argument can only be a value inside the range: 0...%d plugin ID: #%d\n", PLUGIN_MAX_SOCKETS);
        return qfalse;
    }
    return PHandler_TcpConnect(pID, remote, connection);

}
Beispiel #30
0
/*
============
Cmd_TokenizeString
============
*/
static void Cmd_TokenizeString2( const char *text_in, qboolean ignore_quotes ) {

	cmdTokenizeParams_t param;
	int oldargc;
	int occupiedBuf;

	oldargc = tokenStrings.cmd_argc;

	if(tokenStrings.currentString < MAX_TOKENIZE_STRINGS)
	{

		param.cmd_argc = tokenStrings.cmd_argc;
		param.cmd_argv = tokenStrings.cmd_argv;

		if(tokenStrings.currentString > 0)
		{
			if(tokenStrings.cmd_argv[tokenStrings.cmd_argc] == NULL)
			{
				Com_Error(ERR_FATAL, "Cmd_TokenizeString( ): Free string is a NULL pointer...");
			}
			param.cmd_tokenized = tokenStrings.cmd_argv[tokenStrings.cmd_argc];
		}else{
			param.cmd_tokenized = tokenStrings.cmd_tokenized;
		}

		occupiedBuf = param.cmd_tokenized - tokenStrings.cmd_tokenized;
		param.availableBuf = sizeof(tokenStrings.cmd_tokenized) - occupiedBuf;

		Cmd_TokenizeStringInternal( text_in, ignore_quotes, &param );

		tokenStrings.cmd_argcList[tokenStrings.currentString] = param.cmd_argc - oldargc;
		tokenStrings.cmd_argc = param.cmd_argc;
	}else{
		Com_PrintError("Cmd_TokenizeString(): MAX_TOKENIZE_STRINGS exceeded\n");
	}
	tokenStrings.currentString++;
}