From 8f68eb945705fbe4ad64db47e81075a1f2479b33 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 7 Feb 2004 21:23:24 +0000 Subject: [PATCH] Touches.. --- dlls/engine/engine.h | 23 +++++++++++- dlls/engine/meta_api.cpp | 77 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/dlls/engine/engine.h b/dlls/engine/engine.h index cda8f7ee..ab29584f 100755 --- a/dlls/engine/engine.h +++ b/dlls/engine/engine.h @@ -1,4 +1,11 @@ -#define VERSION "0.73" +#ifdef __linux__ +#include +#include +#include +#include +#include +#endif +#define VERSION "0.74" plugin_info_t Plugin_info = { @@ -85,6 +92,10 @@ void (*function)(void*); void (*endfunction)(void*); +#ifdef __linux__ +int thread_fork(void *arg); +#endif + #define AMS_OFFSET 0.01 #define SPEAK_NORMAL 0 @@ -886,3 +897,13 @@ struct MsgSets MessageInfo *msg; AmxCallList msgCalls; }; + +#ifdef __linux__ +int thread_fork(void *arg) +{ + char *szCmd; + szCmd = (char*)arg; + system(szCmd); + return 0; +} +#endif diff --git a/dlls/engine/meta_api.cpp b/dlls/engine/meta_api.cpp index 8a18d512..2fb91056 100755 --- a/dlls/engine/meta_api.cpp +++ b/dlls/engine/meta_api.cpp @@ -47,6 +47,8 @@ MsgSets Msg[MAX_MESSAGES]; int LastMessage; cvar_t amxxe_version = {"amxxe_version", VERSION, FCVAR_SERVER, 0}; + + /******************************************************** vexd's utility funcs @@ -475,6 +477,78 @@ static cell AMX_NATIVE_CALL get_offset_float(AMX *amx, cell *params) return 1; } +//(BAILOPAN) +//return operating system +static cell AMX_NATIVE_CALL get_system_os(AMX *amx, cell *params) +{ + int iLen = params[2]; +#ifndef __linux__ + char *szOS = "win32"; +#else + char *szOS = "linux"; +#endif + return SET_AMXSTRING(amx, params[1], szOS, iLen); +} + +//(BAILOPAN) +//Allows you to issue a command to the operating system. +static cell AMX_NATIVE_CALL system_cmd(AMX *amx, cell *params) +{ + int i_apptype = params[1]; + int iLen, retVal, iLen2; + char *szCommand = AMX_GET_STRING(amx, params[2], iLen); + char *szDirectory = AMX_GET_STRING(amx, params[3], iLen2); +#ifndef __linux__ + STARTUPINFO si; + PROCESS_INFORMATION pi; + + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + ZeroMemory(&pi, sizeof(pi)); + + if (!i_apptype) { + if (!CreateProcess(NULL, (LPTSTR)szCommand, NULL, NULL, FALSE, 0, NULL, (LPCTSTR)szDirectory, &si, &pi)) { + return 0; + } else { + retVal = 1; + } + } else if (i_apptype == 1) { + if (!CreateProcess((LPCTSTR)szCommand, NULL, NULL, NULL, FALSE, 0, NULL, (LPCTSTR)szDirectory, &si, &pi)) { + return 0; + } else { + retVal = 1; + } + } + + WaitForSingleObject(pi.hProcess, INFINITE); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); +#else + void *stack; + pid_t pid; + + if (!app_type) { + app_type = 64; + } + + stack = malloc(app_type * 64); + if (stack == 0) { + return -1; + } + + pid = clone(&thread_fork, (char *)stack + app_type*64, 0, szCommand); + if (pid == -1) { + return -1; + } + pid = waitpid(pid, 0, 0); + if (pid == -1) { + return -1; + } + free(stack); + retval = 1; +#endif + return retVal; +} // Get an integer from an entities entvars. // (vexd) @@ -3135,6 +3209,9 @@ AMX_NATIVE_INFO Engine_Natives[] = { {"get_msg_args", get_msg_args}, {"get_msg_argtype", get_msg_argtype}, + {"get_system_os", get_system_os}, + {"system_cmd", system_cmd}, + { NULL, NULL } }; \ No newline at end of file