added central logging system, callfunc natives

This commit is contained in:
Pavol Marko 2004-03-04 18:16:51 +00:00
parent 0f497e2dc4
commit e72a36dd37
9 changed files with 519 additions and 226 deletions

View File

@ -328,7 +328,7 @@ void EventsMngr::parseValue(const char *sz)
switch(condIter->second.type) switch(condIter->second.type)
{ {
case '=': if (!strcmp(sz, condIter->second.sValue.c_str())) skip=true; break; case '=': if (!strcmp(sz, condIter->second.sValue.c_str())) skip=true; break;
case '!': if (strcmp(sz, condIter->second.sValue.c_str())) skip=true; break; case '!': if (!strstr(sz, condIter->second.sValue.c_str())) skip=true; break;
case '&': if (strstr(sz, condIter->second.sValue.c_str())) skip=true; break; case '&': if (strstr(sz, condIter->second.sValue.c_str())) skip=true; break;
} }
if (skip) if (skip)
@ -361,7 +361,7 @@ void EventsMngr::executeEvents()
if ((err = amx_Exec((*iter)->m_Plugin->getAMX(), NULL, (*iter)->m_Func, 1, m_ParseVault.size() ? m_ParseVault[0].iValue : 0)) != AMX_ERR_NONE) if ((err = amx_Exec((*iter)->m_Plugin->getAMX(), NULL, (*iter)->m_Func, 1, m_ParseVault.size() ? m_ParseVault[0].iValue : 0)) != AMX_ERR_NONE)
{ {
print_srvconsole("[AMX] Run time error %d on line %ld (plugin \"%s\")\n", err, UTIL_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")", err,
(*iter)->m_Plugin->getAMX()->curline, (*iter)->m_Plugin->getName()); (*iter)->m_Plugin->getAMX()->curline, (*iter)->m_Plugin->getName());
} }
} }
@ -370,7 +370,7 @@ void EventsMngr::executeEvents()
} }
catch( ... ) catch( ... )
{ {
print_srvconsole( "[AMX] fatal error at event execution\n"); UTIL_Log( "[AMXX] fatal error at event execution");
} }
#endif // #ifdef ENABLEEXEPTIONS #endif // #ifdef ENABLEEXEPTIONS
} }
@ -447,6 +447,7 @@ void EventsMngr::clearEvents(void)
int EventsMngr::getEventId(const char* msg) int EventsMngr::getEventId(const char* msg)
{ {
// :TODO: Remove this somehow!!! :)
const struct CS_Events const struct CS_Events
{ {
const char* name; const char* name;
@ -459,6 +460,7 @@ int EventsMngr::getEventId(const char* msg)
// { "CS_Restart" , CS_Restart }, // { "CS_Restart" , CS_Restart },
{ "" , CS_Null } { "" , CS_Null }
}; };
// if msg is a number, return it // if msg is a number, return it
int pos = atoi(msg); int pos = atoi(msg);
if (pos != 0) if (pos != 0)
@ -469,6 +471,6 @@ int EventsMngr::getEventId(const char* msg)
if ( !strcmp( table[ pos ].name , msg ) ) if ( !strcmp( table[ pos ].name , msg ) )
return table[ pos ].id; return table[ pos ].id;
// not found // find the id of the message
return pos = GET_USER_MSG_ID(PLID, msg , 0 ); return pos = GET_USER_MSG_ID(PLID, msg , 0 );
} }

View File

@ -58,8 +58,6 @@ class EventsMngr
MSG_STRING, MSG_STRING,
}; };
public:
enum CS_EventsIds enum CS_EventsIds
{ {
CS_Null = 0, CS_Null = 0,
@ -69,6 +67,8 @@ public:
// CS_Restart, // CS_Restart,
}; };
public:
class ClEvent class ClEvent
{ {
friend class EventsMngr; // events manager may access our private members friend class EventsMngr; // events manager may access our private members

View File

@ -1,33 +1,33 @@
/* AMX Mod X /*
* * Copyright (c) 2002-2003 Aleksander Naszko
* by the AMX Mod X Development Team *
* originally developed by OLO * This file is part of AMX Mod.
* *
* * AMX Mod is free software; you can redistribute it and/or modify it
* This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the
* under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at
* Free Software Foundation; either version 2 of the License, or (at * your option) any later version.
* your option) any later version. *
* * AMX Mod is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of
* WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* General Public License for more details. *
* * You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License * along with AMX Mod; if not, write to the Free Software Foundation,
* along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
* * In addition, as a special exception, the author gives permission to
* In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL
* link the code of this program with the Half-Life Game Engine ("HL * Engine") and Modified Game Libraries ("MODs") developed by Valve,
* Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all
* L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs
* respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception
* from Valve. If you modify this file, you may extend this exception * to your version of the file, but you are not obligated to do so. If
* to your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from your
* you do not wish to do so, delete this exception statement from your * version.
* version. *
*/ */
#include <extdll.h> #include <extdll.h>
#include <meta_api.h> #include <meta_api.h>
@ -175,15 +175,15 @@ void LogEventsMngr::executeLogEvents()
if (valid){ if (valid){
if ((err = amx_Exec(a->plugin->getAMX(), NULL , a->func , 0)) != AMX_ERR_NONE) if ((err = amx_Exec(a->plugin->getAMX(), NULL , a->func , 0)) != AMX_ERR_NONE)
print_srvconsole("[AMX] Run time error %d on line %ld (plugin \"%s\")\n", UTIL_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")",
err,a->plugin->getAMX()->curline,a->plugin->getName()); err,a->plugin->getAMX()->curline,a->plugin->getName());
} }
#ifdef ENABLEEXEPTIONS #ifdef ENABLEEXEPTIONS
} }
catch( ... ) catch( ... )
{ {
print_srvconsole( "[AMX] fatal error at log forward function execution\n"); UTIL_Log( "[AMXX] fatal error at log forward function execution");
} }
#endif #endif

View File

@ -1,34 +1,33 @@
/* AMX Mod X /*
* * Copyright (c) 2002-2003 Aleksander Naszko
* by the AMX Mod X Development Team *
* originally developed by OLO * This file is part of AMX Mod.
* *
* * AMX Mod is free software; you can redistribute it and/or modify it
* This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the
* under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at
* Free Software Foundation; either version 2 of the License, or (at * your option) any later version.
* your option) any later version. *
* * AMX Mod is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of
* WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* General Public License for more details. *
* * You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License * along with AMX Mod; if not, write to the Free Software Foundation,
* along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
* * In addition, as a special exception, the author gives permission to
* In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL
* link the code of this program with the Half-Life Game Engine ("HL * Engine") and Modified Game Libraries ("MODs") developed by Valve,
* Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all
* L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs
* respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception
* from Valve. If you modify this file, you may extend this exception * to your version of the file, but you are not obligated to do so. If
* to your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from your
* you do not wish to do so, delete this exception statement from your * version.
* version. *
*/ */
#include <extdll.h> #include <extdll.h>
#include <meta_api.h> #include <meta_api.h>
#include "amxmod.h" #include "amxmod.h"
@ -56,7 +55,7 @@ int CPluginMngr::loadPluginsFromFile( const char* filename )
if ( !fp ) if ( !fp )
{ {
print_srvconsole( "[AMX] Plugins list not found (file \"%s\")\n",filename); UTIL_Log( "[AMXX] Plugins list not found (file \"%s\")",filename);
return 1; return 1;
} }
@ -111,7 +110,7 @@ int CPluginMngr::loadPluginsFromFile( const char* filename )
} }
else else
{ {
print_srvconsole("[AMX] %s (plugin \"%s\")\n", error, pluginName ); UTIL_Log("[AMXX] %s (plugin \"%s\")", error, pluginName );
} }
} }

View File

@ -646,7 +646,7 @@ static cell AMX_NATIVE_CALL register_menucmd(AMX *amx, cell *params) /* 3 param
char* sptemp = get_amxstring(amx,params[3],0,ilen); char* sptemp = get_amxstring(amx,params[3],0,ilen);
if(amx_FindPublic(amx, sptemp ,&idx)!=AMX_ERR_NONE) { if(amx_FindPublic(amx, sptemp ,&idx)!=AMX_ERR_NONE) {
print_srvconsole("[AMX] Function is not present (function \"%s\") (plugin \"%s\")\n",sptemp,plugin->getName() ); UTIL_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")",sptemp,plugin->getName() );
amx_RaiseError(amx,AMX_ERR_NATIVE); amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0; return 0;
} }
@ -689,7 +689,7 @@ static cell AMX_NATIVE_CALL register_concmd(AMX *amx, cell *params) /* 4 param *
int i, idx = 0; int i, idx = 0;
char* temp = get_amxstring(amx,params[2],0, i ); char* temp = get_amxstring(amx,params[2],0, i );
if(amx_FindPublic(amx, temp ,&idx)!=AMX_ERR_NONE) { if(amx_FindPublic(amx, temp ,&idx)!=AMX_ERR_NONE) {
print_srvconsole("[AMX] Function is not present (function \"%s\") (plugin \"%s\")\n",temp,plugin->getName() ); UTIL_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")",temp,plugin->getName() );
amx_RaiseError(amx,AMX_ERR_NATIVE); amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0; return 0;
} }
@ -716,7 +716,7 @@ static cell AMX_NATIVE_CALL register_clcmd(AMX *amx, cell *params) /* 4 param */
int i, idx = 0; int i, idx = 0;
char* temp = get_amxstring(amx,params[2],0, i ); char* temp = get_amxstring(amx,params[2],0, i );
if(amx_FindPublic(amx, temp ,&idx)!=AMX_ERR_NONE) { if(amx_FindPublic(amx, temp ,&idx)!=AMX_ERR_NONE) {
print_srvconsole("[AMX] Function is not present (function \"%s\") (plugin \"%s\")\n",temp,plugin->getName() ); UTIL_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")",temp,plugin->getName() );
amx_RaiseError(amx,AMX_ERR_NATIVE); amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0; return 0;
} }
@ -741,7 +741,7 @@ static cell AMX_NATIVE_CALL register_srvcmd(AMX *amx, cell *params) /* 2 param *
int i, idx = 0; int i, idx = 0;
char* temp = get_amxstring(amx,params[2],0, i ); char* temp = get_amxstring(amx,params[2],0, i );
if(amx_FindPublic(amx, temp ,&idx)!=AMX_ERR_NONE) { if(amx_FindPublic(amx, temp ,&idx)!=AMX_ERR_NONE) {
print_srvconsole("[AMX] Function is not present (function \"%s\") (plugin \"%s\")\n",temp,plugin->getName() ); UTIL_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")",temp,plugin->getName() );
amx_RaiseError(amx,AMX_ERR_NATIVE); amx_RaiseError(amx,AMX_ERR_NATIVE);
return NULL; return NULL;
} }
@ -835,7 +835,7 @@ static cell AMX_NATIVE_CALL register_event(AMX *amx, cell *params) /* 2 param */
char* sTemp = get_amxstring(amx,params[1],0,len); char* sTemp = get_amxstring(amx,params[1],0,len);
if ( (pos = g_events.getEventId( sTemp )) == 0 ) { if ( (pos = g_events.getEventId( sTemp )) == 0 ) {
print_srvconsole("[AMX] Invalid event (name \"%s\") (plugin \"%s\")\n", sTemp , plugin->getName() ); UTIL_Log("[AMXX] Invalid event (name \"%s\") (plugin \"%s\")", sTemp , plugin->getName() );
amx_RaiseError(amx,AMX_ERR_NATIVE); amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0; return 0;
} }
@ -843,7 +843,7 @@ static cell AMX_NATIVE_CALL register_event(AMX *amx, cell *params) /* 2 param */
sTemp = get_amxstring(amx,params[2],0,len); sTemp = get_amxstring(amx,params[2],0,len);
if ( amx_FindPublic(amx, sTemp , &iFunction) != AMX_ERR_NONE){ if ( amx_FindPublic(amx, sTemp , &iFunction) != AMX_ERR_NONE){
print_srvconsole("[AMX] Function is not present (function \"%s\") (plugin \"%s\")\n",sTemp,plugin->getName() ); UTIL_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")",sTemp,plugin->getName() );
amx_RaiseError(amx,AMX_ERR_NATIVE); amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0; return 0;
} }
@ -1498,7 +1498,7 @@ static cell AMX_NATIVE_CALL set_task(AMX *amx, cell *params) /* 2 param */
char* stemp = get_amxstring(amx,params[2],1, a ); char* stemp = get_amxstring(amx,params[2],1, a );
if (amx_FindPublic(amx, stemp , &iFunc) != AMX_ERR_NONE){ if (amx_FindPublic(amx, stemp , &iFunc) != AMX_ERR_NONE){
print_srvconsole("[AMX] Function is not present (function \"%s\") (plugin \"%s\")\n",stemp,plugin->getName() ); UTIL_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")",stemp,plugin->getName() );
amx_RaiseError(amx,AMX_ERR_NATIVE); amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0; return 0;
} }
@ -1643,7 +1643,7 @@ static cell AMX_NATIVE_CALL pause(AMX *amx, cell *params) /* 3 param */
temp = get_amxstring(amx,params[2],0,ilen); temp = get_amxstring(amx,params[2],0,ilen);
int err, index; int err, index;
if ((err = amx_FindPublic( plugin->getAMX(), temp , &index) )!= AMX_ERR_NONE){ if ((err = amx_FindPublic( plugin->getAMX(), temp , &index) )!= AMX_ERR_NONE){
print_srvconsole("[AMX] Function is not present (function \"%s\") (plugin \"%s\")\n", temp,plugin->getName() ); UTIL_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")", temp,plugin->getName() );
return 0; return 0;
} }
plugin->pauseFunction( index ); plugin->pauseFunction( index );
@ -1685,7 +1685,7 @@ static cell AMX_NATIVE_CALL unpause(AMX *amx, cell *params) /* 3 param */
sptemp = get_amxstring(amx,params[2],0,ilen); sptemp = get_amxstring(amx,params[2],0,ilen);
int err, index; int err, index;
if ((err = amx_FindPublic(plugin->getAMX(), sptemp , &index) )!= AMX_ERR_NONE){ if ((err = amx_FindPublic(plugin->getAMX(), sptemp , &index) )!= AMX_ERR_NONE){
print_srvconsole("[AMX] Function is not present (function \"%s\") (plugin \"%s\")\n", sptemp,plugin->getName() ); UTIL_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")", sptemp,plugin->getName() );
return 0; return 0;
} }
plugin->unpauseFunction( index ); plugin->unpauseFunction( index );
@ -2041,7 +2041,7 @@ static cell AMX_NATIVE_CALL register_logevent(AMX *amx, cell *params)
char* temp = get_amxstring(amx,params[1],0, a ); char* temp = get_amxstring(amx,params[1],0, a );
if (amx_FindPublic(amx, temp , &iFunc) != AMX_ERR_NONE){ if (amx_FindPublic(amx, temp , &iFunc) != AMX_ERR_NONE){
print_srvconsole("[AMX] Function is not present (function \"%s\") (plugin \"%s\")\n", UTIL_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")",
temp,plugin->getName() ); temp,plugin->getName() );
amx_RaiseError(amx,AMX_ERR_NATIVE); amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0; return 0;
@ -2116,6 +2116,228 @@ static cell AMX_NATIVE_CALL get_module(AMX *amx, cell *params)
return params[1]; return params[1];
} }
// native log_amx(const msg[], ...);
static cell AMX_NATIVE_CALL log_amx(AMX *amx, cell *params)
{
CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx);
int len;
UTIL_Log("[%s] %s", plugin->getName(), format_amxstring(amx, params, 1, len));
return 0;
}
/*********************************************************************/
CPluginMngr::CPlugin *g_CallFunc_Plugin = NULL; // The plugin
int g_CallFunc_Func = 0; // The func
struct CallFunc_ParamInfo
{
unsigned char flags; // flags
cell byrefAddr; // byref address in caller plugin
cell size; // byref size
};
// :TODO: Overflow possible
#define CALLFUNC_MAXPARAMS 64 /* Maximal params number */
cell g_CallFunc_Params[CALLFUNC_MAXPARAMS] = {0}; // Params
CallFunc_ParamInfo g_CallFunc_ParamInfo[CALLFUNC_MAXPARAMS] = {0}; // Flags
int g_CallFunc_CurParam = 0; // Current param id
#define CALLFUNC_FLAG_BYREF 1 /* Byref flag so that mem is released */
// native callfunc_begin(const plugin[], const func[]);
static cell AMX_NATIVE_CALL callfunc_begin(AMX *amx, cell *params)
{
CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx);
if (g_CallFunc_Plugin)
{
// scripter's fault
UTIL_Log("[AMXX] callfunc_begin called without callfunc_end (plugin \"%s\", line %d)", curPlugin->getName(), amx->curline);
amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0;
}
int numparams = *params / sizeof(cell);
int len;
char *pluginStr = get_amxstring(amx, params[1], 0, len);
char *funcStr = get_amxstring(amx, params[2], 1, len);
CPluginMngr::CPlugin *plugin = NULL;
if (!pluginStr || !*pluginStr)
plugin = curPlugin;
else
plugin = g_plugins.findPlugin(pluginStr);
if (!plugin)
{
return -1; // plugin not found: -1
}
int func;
if (amx_FindPublic(plugin->getAMX(), funcStr, &func) != AMX_ERR_NONE)
{
return -2; // func not found: -2
}
// set globals
g_CallFunc_Plugin = plugin;
g_CallFunc_Func = func;
return 1; // success: 1
}
// native callfunc_end();
static cell AMX_NATIVE_CALL callfunc_end(AMX *amx, cell *params)
{
CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx);
if (!g_CallFunc_Plugin)
{
// scripter's fault
UTIL_Log("[AMXX] callfunc_end called without callfunc_begin (plugin \"%s\", line %d)", curPlugin->getName(), amx->curline);
amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0;
}
// call the func
cell retVal;
int err;
// copy the globs so the called func can also use callfunc
cell gparams[CALLFUNC_MAXPARAMS];
CallFunc_ParamInfo gparamInfo[CALLFUNC_MAXPARAMS];
CPluginMngr::CPlugin *plugin = g_CallFunc_Plugin;
int func = g_CallFunc_Func;
int curParam = g_CallFunc_CurParam;
memcpy(gparams, g_CallFunc_Params, sizeof(cell) * curParam);
memcpy(gparamInfo, g_CallFunc_ParamInfo, sizeof(CallFunc_ParamInfo) * curParam);
// cleanup
g_CallFunc_Plugin = NULL;
g_CallFunc_CurParam = 0;
// actual call
if ((err = amx_Execv(plugin->getAMX(), &retVal, func, curParam, gparams)) != AMX_ERR_NONE)
{
UTIL_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")", err, curPlugin->getAMX()->curline, curPlugin->getName());
return 0;
}
// process byref params
for (int i = 0; i < curParam; ++i)
{
if (gparamInfo[i].flags & CALLFUNC_FLAG_BYREF)
{
// copy back so that references work
AMX *amxCaller = curPlugin->getAMX();
AMX *amxCalled = plugin->getAMX();
AMX_HEADER *hdrCaller = (AMX_HEADER *)amxCaller->base;
AMX_HEADER *hdrCalled = (AMX_HEADER *)amxCalled->base;
memcpy( /** DEST ADDR **/
(amxCaller->data ? amxCaller->data : (amxCaller->base + hdrCaller->dat)) + gparamInfo[i].byrefAddr,
/** SOURCE ADDR **/
(amxCalled->data ? amxCalled->data : (amxCalled->base + hdrCalled->dat)) + gparams[i],
/** SIZE **/
gparamInfo[i].size * sizeof(cell));
// free memory used for params passed by reference
amx_Release(amxCalled, gparams[i]);
}
}
return retVal;
}
// native callfunc_push_int(value);
// native callfunc_push_float(Float: value);
static cell callfunc_push_byval(AMX *amx, cell *params)
{
CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx);
if (!g_CallFunc_Plugin)
{
// scripter's fault
UTIL_Log("[AMXX] callfunc_push_xxx called without callfunc_begin (plugin \"%s\", line %d)", curPlugin->getName(), amx->curline);
amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0;
}
g_CallFunc_ParamInfo[g_CallFunc_CurParam].flags = 0;
g_CallFunc_Params[g_CallFunc_CurParam++] = params[1];
return 0;
}
// native callfunc_push_intref(&value);
// native callfunc_push_floatref(Float: &value);
static cell callfunc_push_byref(AMX *amx, cell *params)
{
CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx);
if (!g_CallFunc_Plugin)
{
// scripter's fault
UTIL_Log("[AMXX] callfunc_push_xxx called without callfunc_begin (plugin \"%s\", line %d)", curPlugin->getName(), amx->curline);
amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0;
}
// allocate memory
cell *phys_addr;
cell amx_addr;
amx_Allot(g_CallFunc_Plugin->getAMX(),
1, // 1 cell
&amx_addr,
&phys_addr);
// copy the value to the allocated memory
cell *phys_addr2;
amx_GetAddr(curPlugin->getAMX(), params[1], &phys_addr2);
*phys_addr = *phys_addr2;
// push the address and set the reference flag so that memory is released after function call.
g_CallFunc_ParamInfo[g_CallFunc_CurParam].flags = CALLFUNC_FLAG_BYREF;
g_CallFunc_ParamInfo[g_CallFunc_CurParam].byrefAddr = params[1];
g_CallFunc_ParamInfo[g_CallFunc_CurParam].size = 1;
g_CallFunc_Params[g_CallFunc_CurParam++] = amx_addr;
return 0;
}
// native callfunc_push_str(value[]);
static cell callfunc_push_str(AMX *amx, cell *params)
{
CPluginMngr::CPlugin *curPlugin = g_plugins.findPluginFast(amx);
if (!g_CallFunc_Plugin)
{
// scripter's fault
UTIL_Log("[AMXX] callfunc_push_xxx called without callfunc_begin (plugin \"%s\", line %d)", curPlugin->getName(), amx->curline);
amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0;
}
// get the string and its length
int len;
char *str = get_amxstring(amx, params[1], 0, len);
// allocate enough memory for the string
cell *phys_addr;
cell amx_addr;
amx_Allot(g_CallFunc_Plugin->getAMX(),
len + 1, // length + terminator
&amx_addr,
&phys_addr);
// copy it to the allocated memory
// we assume it's unpacked
amx_SetString(phys_addr, str, 0);
// push the address and set the reference flag so that memory is released after function call.
g_CallFunc_ParamInfo[g_CallFunc_CurParam].flags = CALLFUNC_FLAG_BYREF;
g_CallFunc_ParamInfo[g_CallFunc_CurParam].byrefAddr = params[1];
g_CallFunc_ParamInfo[g_CallFunc_CurParam].size = len + 1;
g_CallFunc_Params[g_CallFunc_CurParam++] = amx_addr;
return 0;
}
AMX_NATIVE_INFO amxmod_Natives[] = { AMX_NATIVE_INFO amxmod_Natives[] = {
{ "client_cmd", client_cmd }, { "client_cmd", client_cmd },
{ "client_print", client_print }, { "client_print", client_print },
@ -2256,5 +2478,13 @@ AMX_NATIVE_INFO amxmod_Natives[] = {
{ "is_plugin_loaded", is_plugin_loaded }, { "is_plugin_loaded", is_plugin_loaded },
{ "get_modulesnum", get_modulesnum }, { "get_modulesnum", get_modulesnum },
{ "get_module", get_module }, { "get_module", get_module },
{ "log_amx", log_amx },
{ "callfunc_begin", callfunc_begin },
{ "callfunc_end", callfunc_end },
{ "callfunc_push_int", callfunc_push_byval },
{ "callfunc_push_str", callfunc_push_str },
{ "callfunc_push_float", callfunc_push_byval },
{ "callfunc_push_intrf", callfunc_push_byref },
{ "callfunc_push_floatrf", callfunc_push_byref },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -1,33 +1,33 @@
/* AMX Mod X /*
* * Copyright (c) 2002-2003 Aleksander Naszko
* by the AMX Mod X Development Team *
* originally developed by OLO * This file is part of AMX Mod.
* *
* * AMX Mod is free software; you can redistribute it and/or modify it
* This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the
* under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at
* Free Software Foundation; either version 2 of the License, or (at * your option) any later version.
* your option) any later version. *
* * AMX Mod is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of
* WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* General Public License for more details. *
* * You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License * along with AMX Mod; if not, write to the Free Software Foundation,
* along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
* * In addition, as a special exception, the author gives permission to
* In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL
* link the code of this program with the Half-Life Game Engine ("HL * Engine") and Modified Game Libraries ("MODs") developed by Valve,
* Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all
* L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs
* respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception
* from Valve. If you modify this file, you may extend this exception * to your version of the file, but you are not obligated to do so. If
* to your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from your
* you do not wish to do so, delete this exception statement from your * version.
* version. *
*/ */
#ifndef AMXMOD_H #ifndef AMXMOD_H
#define AMXMOD_H #define AMXMOD_H
@ -100,6 +100,8 @@ void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pM
void UTIL_IntToString(int value, char *output); void UTIL_IntToString(int value, char *output);
void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name); void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name);
void UTIL_ShowMenu( edict_t* pEntity, int slots, int time, char *menu, int mlen ); void UTIL_ShowMenu( edict_t* pEntity, int slots, int time, char *menu, int mlen );
void UTIL_MakeNewLogFile();
void UTIL_Log(const char *fmt, ...);
#define GET_PLAYER_POINTER(e) (&g_players[ENTINDEX(e)]) #define GET_PLAYER_POINTER(e) (&g_players[ENTINDEX(e)])
//#define GET_PLAYER_POINTER(e) (&g_players[(((int)e-g_edict_point)/sizeof(edict_t ))]) //#define GET_PLAYER_POINTER(e) (&g_players[(((int)e-g_edict_point)/sizeof(edict_t ))])

View File

@ -1,32 +1,32 @@
/* AMX Mod X /*
* Copyright (c) 2002-2003 Aleksander Naszko
* *
* by the AMX Mod X Development Team * This file is part of AMX Mod.
* originally developed by OLO
* *
* AMX Mod is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
* *
* This program is free software; you can redistribute it and/or modify it * AMX Mod is distributed in the hope that it will be useful, but
* under the terms of the GNU General Public License as published by the * WITHOUT ANY WARRANTY; without even the implied warranty of
* Free Software Foundation; either version 2 of the License, or (at * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* your option) any later version. * General Public License for more details.
* *
* This program is distributed in the hope that it will be useful, but * You should have received a copy of the GNU General Public License
* WITHOUT ANY WARRANTY; without even the implied warranty of * along with AMX Mod; if not, write to the Free Software Foundation,
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * In addition, as a special exception, the author gives permission to
* along with this program; if not, write to the Free Software Foundation, * link the code of this program with the Half-Life Game Engine ("HL
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
* *
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*/ */
#include <extdll.h> #include <extdll.h>
@ -39,8 +39,8 @@ plugin_info_t Plugin_info = {
AMX_VERSION, // version AMX_VERSION, // version
__DATE__, // date __DATE__, // date
"AMX Mod X Dev Team", // author "AMX Mod X Dev Team", // author
"http://www.amxmodx.org", // url "http://www.amxmod.info", // url
"AMXX", // logtag "AMX", // logtag
PT_ANYTIME,// (when) loadable PT_ANYTIME,// (when) loadable
PT_ANYTIME,// (when) unloadable PT_ANYTIME,// (when) unloadable
}; };
@ -154,14 +154,14 @@ int InconsistentFile( const edict_t *player, const char *filename, char *disconn
cell amx_addr2, *phys_addr2; cell amx_addr2, *phys_addr2;
if ((amx_Allot(c, 64 , &amx_addr1, &phys_addr1) != AMX_ERR_NONE) || if ((amx_Allot(c, 64 , &amx_addr1, &phys_addr1) != AMX_ERR_NONE) ||
(amx_Allot(c, 64 , &amx_addr2, &phys_addr2) != AMX_ERR_NONE) ){ (amx_Allot(c, 64 , &amx_addr2, &phys_addr2) != AMX_ERR_NONE) ){
print_srvconsole("[AMX] Failed to allocate AMX memory (plugin \"%s\")\n",(*a).getPlugin()->getName()); UTIL_Log("[AMXX] Failed to allocate AMX memory (plugin \"%s\")",(*a).getPlugin()->getName());
} }
else { else {
int err; int err;
set_amxstring(c,amx_addr1,filename,63); set_amxstring(c,amx_addr1,filename,63);
set_amxstring(c,amx_addr2,disconnect_message,63); set_amxstring(c,amx_addr2,disconnect_message,63);
if ((err = amx_Exec(c,&ret, (*a).getFunction() , 3, pPlayer->index, amx_addr1, amx_addr2)) != AMX_ERR_NONE) if ((err = amx_Exec(c,&ret, (*a).getFunction() , 3, pPlayer->index, amx_addr1, amx_addr2)) != AMX_ERR_NONE)
print_srvconsole("[AMX] Run time error %d on line %ld (plugin \"%s\")\n", UTIL_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")",
err,c->curline,(*a).getPlugin()->getName()); err,c->curline,(*a).getPlugin()->getName());
int len; int len;
strcpy(disconnect_message,get_amxstring(c,amx_addr2,0,len)); strcpy(disconnect_message,get_amxstring(c,amx_addr2,0,len));
@ -177,7 +177,7 @@ int InconsistentFile( const edict_t *player, const char *filename, char *disconn
#ifdef ENABLEEXEPTIONS #ifdef ENABLEEXEPTIONS
}catch( ... ) }catch( ... )
{ {
print_srvconsole( "[AMX] fatal error at inconsistent file forward execution\n"); UTIL_Log( "[AMXX] fatal error at inconsistent file forward execution");
} }
#endif #endif
@ -212,6 +212,10 @@ int Spawn( edict_t *pent ) {
hostname = CVAR_GET_POINTER("hostname"); hostname = CVAR_GET_POINTER("hostname");
mp_timelimit = CVAR_GET_POINTER("mp_timelimit"); mp_timelimit = CVAR_GET_POINTER("mp_timelimit");
// ###### Initialize logging]
g_log_dir.set( get_localinfo("amx_logdir" , "addons/amx/logs" ) );
UTIL_MakeNewLogFile();
// ###### Initialize task manager // ###### Initialize task manager
g_tasksMngr.registerTimers( &gpGlobals->time, &mp_timelimit->value, &g_game_timeleft ); g_tasksMngr.registerTimers( &gpGlobals->time, &mp_timelimit->value, &g_game_timeleft );
@ -255,9 +259,6 @@ int Spawn( edict_t *pent ) {
CVAR_SET_STRING( "amxmodx_version", AMX_VERSION ); CVAR_SET_STRING( "amxmodx_version", AMX_VERSION );
} }
// ###### Save log dir
g_log_dir.set( get_localinfo("amx_logdir" , "addons/amx/logs" ) );
// ###### Load Vault // ###### Load Vault
g_vault.setSource( build_pathname("%s", g_vault.setSource( build_pathname("%s",
get_localinfo("amx_vault" , "addons/amx/vault.ini" ) ) ); get_localinfo("amx_vault" , "addons/amx/vault.ini" ) ) );
@ -439,6 +440,8 @@ void ServerDeactivate_Post() {
g_xvars.clear(); g_xvars.clear();
g_plugins.clear(); g_plugins.clear();
UTIL_Log("Log file closed.");
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
@ -537,7 +540,7 @@ void ClientCommand( edict_t *pEntity ) {
{ {
if ((err = amx_Exec((*a).getPlugin()->getAMX(), &ret , (*a).getFunction(), 1, pPlayer->index)) != AMX_ERR_NONE) if ((err = amx_Exec((*a).getPlugin()->getAMX(), &ret , (*a).getFunction(), 1, pPlayer->index)) != AMX_ERR_NONE)
print_srvconsole("[AMX] Run time error %d on line %ld (plugin \"%s\")\n", UTIL_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")",
err,(*a).getPlugin()->getAMX()->curline,(*a).getPlugin()->getName() ); err,(*a).getPlugin()->getAMX()->curline,(*a).getPlugin()->getName() );
if ( ret & 2 ) result = MRES_SUPERCEDE; if ( ret & 2 ) result = MRES_SUPERCEDE;
@ -552,7 +555,7 @@ void ClientCommand( edict_t *pEntity ) {
#ifdef ENABLEEXEPTIONS #ifdef ENABLEEXEPTIONS
}catch( ... ) }catch( ... )
{ {
print_srvconsole( "[AMX] fatal error at commmand forward execution\n"); UTIL_Log( "[AMXX] fatal error at commmand forward execution");
} }
#endif #endif
@ -575,7 +578,7 @@ void ClientCommand( edict_t *pEntity ) {
{ {
if ((err =amx_Exec((*aa).getPlugin()->getAMX(), &ret , (*aa).getFunction() , 3, pPlayer->index, (*aa).getFlags(),(*aa).getId() )) != AMX_ERR_NONE) if ((err =amx_Exec((*aa).getPlugin()->getAMX(), &ret , (*aa).getFunction() , 3, pPlayer->index, (*aa).getFlags(),(*aa).getId() )) != AMX_ERR_NONE)
print_srvconsole("[AMX] Run time error %d on line %ld (plugin \"%s\")\n", UTIL_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")",
err,(*aa).getPlugin()->getAMX()->curline,(*aa).getPlugin()->getName()); err,(*aa).getPlugin()->getAMX()->curline,(*aa).getPlugin()->getName());
if ( ret & 2 ) result = MRES_SUPERCEDE; if ( ret & 2 ) result = MRES_SUPERCEDE;
@ -588,7 +591,7 @@ void ClientCommand( edict_t *pEntity ) {
#ifdef ENABLEEXEPTIONS #ifdef ENABLEEXEPTIONS
}catch( ... ) }catch( ... )
{ {
print_srvconsole( "[AMX] fatal error at client commmand execution\n"); UTIL_Log( "[AMXX] fatal error at client commmand execution");
} }
#endif #endif
/* check menu commands */ /* check menu commands */
@ -615,7 +618,7 @@ void ClientCommand( edict_t *pEntity ) {
{ {
if ( ( err = amx_Exec((*a).getPlugin()->getAMX(), &ret ,(*a).getFunction() , 2, pPlayer->index,pressed_key)) != AMX_ERR_NONE) if ( ( err = amx_Exec((*a).getPlugin()->getAMX(), &ret ,(*a).getFunction() , 2, pPlayer->index,pressed_key)) != AMX_ERR_NONE)
print_srvconsole("[AMX] Run time error %d on line %ld (plugin \"%s\")\n", UTIL_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")",
err,(*a).getPlugin()->getAMX()->curline,(*a).getPlugin()->getName()); err,(*a).getPlugin()->getAMX()->curline,(*a).getPlugin()->getName());
if ( ret & 2 ) result = MRES_SUPERCEDE; if ( ret & 2 ) result = MRES_SUPERCEDE;
@ -629,7 +632,7 @@ void ClientCommand( edict_t *pEntity ) {
} }
catch( ... ) catch( ... )
{ {
print_srvconsole( "[AMX] fatal error at menu commmand execution\n"); UTIL_Log( "[AMXX] fatal error at menu commmand execution");
} }
#endif #endif
} }
@ -690,14 +693,14 @@ void StartFrame_Post( void ) {
if (amx_Allot(plugin->getAMX(), task.getParamLen() , &amx_addr, &phys_addr) != AMX_ERR_NONE) if (amx_Allot(plugin->getAMX(), task.getParamLen() , &amx_addr, &phys_addr) != AMX_ERR_NONE)
{ {
print_srvconsole("[AMX] Failed to allocate AMX memory (task \"%d\") (plugin \"%s\")\n", task.getTaskId(),plugin->getName()); UTIL_Log("[AMXX] Failed to allocate AMX memory (task \"%d\") (plugin \"%s\")", task.getTaskId(),plugin->getName());
} }
else else
{ {
copy_amxmemory(phys_addr, task.getParam() , task.getParamLen() ); copy_amxmemory(phys_addr, task.getParam() , task.getParamLen() );
if ((err = amx_Exec(plugin->getAMX(),NULL, task.getFunction() , 2, amx_addr, task.getTaskId() )) != AMX_ERR_NONE) if ((err = amx_Exec(plugin->getAMX(),NULL, task.getFunction() , 2, amx_addr, task.getTaskId() )) != AMX_ERR_NONE)
print_srvconsole("[AMX] Run time error %d on line %ld (task \"%d\") (plugin \"%s\")\n", err,plugin->getAMX()->curline,task.getTaskId(),plugin->getName()); UTIL_Log("[AMXX] Run time error %d on line %ld (task \"%d\") (plugin \"%s\")", err,plugin->getAMX()->curline,task.getTaskId(),plugin->getName());
amx_Release(plugin->getAMX(), amx_addr); amx_Release(plugin->getAMX(), amx_addr);
} }
@ -705,7 +708,7 @@ void StartFrame_Post( void ) {
else // call without arguments else // call without arguments
{ {
if ((err = amx_Exec(plugin->getAMX(),NULL, task.getFunction() ,1, task.getTaskId() )) != AMX_ERR_NONE) if ((err = amx_Exec(plugin->getAMX(),NULL, task.getFunction() ,1, task.getTaskId() )) != AMX_ERR_NONE)
print_srvconsole("[AMX] Run time error %d on line %ld (task \"%d\") (plugin \"%s\")\n", err,plugin->getAMX()->curline,task.getTaskId(),plugin->getName()); UTIL_Log("[AMXX] Run time error %d on line %ld (task \"%d\") (plugin \"%s\")", err,plugin->getAMX()->curline,task.getTaskId(),plugin->getName());
} }
} }
} }
@ -802,7 +805,7 @@ void MessageEnd_Post(void) {
{ {
if ((err = amx_Exec((*a).getPlugin()->getAMX(), NULL , (*a).getFunction() , 1, mPlayerIndex /*g_events.getArgInteger(0)*/ )) != AMX_ERR_NONE) if ((err = amx_Exec((*a).getPlugin()->getAMX(), NULL , (*a).getFunction() , 1, mPlayerIndex /*g_events.getArgInteger(0)*/ )) != AMX_ERR_NONE)
print_srvconsole("[AMX] Run time error %d on line %ld (plugin \"%s\")\n",err,(*a).getPlugin()->getAMX()->curline,(*a).getPlugin()->getName()); UTIL_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")",err,(*a).getPlugin()->getAMX()->curline,(*a).getPlugin()->getName());
++a; ++a;
@ -813,7 +816,7 @@ void MessageEnd_Post(void) {
} }
catch( ... ) catch( ... )
{ {
print_srvconsole( "[AMX] fatal error at event execution\n"); UTIL_Log( "[AMXX] fatal error at event execution");
} }
#endif #endif
#endif #endif
@ -889,7 +892,7 @@ void AlertMessage_Post(ALERT_TYPE atype, char *szFmt, ...) {
while ( a ) while ( a )
{ {
if ((err = amx_Exec((*a).getPlugin()->getAMX(), NULL , (*a).getFunction() , 1,mPlayerIndex)) != AMX_ERR_NONE) if ((err = amx_Exec((*a).getPlugin()->getAMX(), NULL , (*a).getFunction() , 1,mPlayerIndex)) != AMX_ERR_NONE)
print_srvconsole("[AMX] Run time error %d on line %ld (plugin \"%s\")\n",err,(*a).getPlugin()->getAMX()->curline,(*a).getPlugin()->getName()); UTIL_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")",err,(*a).getPlugin()->getAMX()->curline,(*a).getPlugin()->getName());
++a; ++a;
@ -899,7 +902,7 @@ void AlertMessage_Post(ALERT_TYPE atype, char *szFmt, ...) {
} }
catch( ... ) catch( ... )
{ {
print_srvconsole( "[AMX] fatal error at log event execution\n"); UTIL_Log( "[AMXX] fatal error at log event execution");
} }
#endif #endif
#endif #endif

View File

@ -1,33 +1,33 @@
/* AMX Mod X /*
* * Copyright (c) 2002-2003 Aleksander Naszko
* by the AMX Mod X Development Team *
* originally developed by OLO * This file is part of AMX Mod.
* *
* * AMX Mod is free software; you can redistribute it and/or modify it
* This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the
* under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at
* Free Software Foundation; either version 2 of the License, or (at * your option) any later version.
* your option) any later version. *
* * AMX Mod is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of
* WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* General Public License for more details. *
* * You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License * along with AMX Mod; if not, write to the Free Software Foundation,
* along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
* * In addition, as a special exception, the author gives permission to
* In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL
* link the code of this program with the Half-Life Game Engine ("HL * Engine") and Modified Game Libraries ("MODs") developed by Valve,
* Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all
* L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs
* respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception
* from Valve. If you modify this file, you may extend this exception * to your version of the file, but you are not obligated to do so. If
* to your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from your
* you do not wish to do so, delete this exception statement from your * version.
* version. *
*/ */
#include <extdll.h> #include <extdll.h>
#include <meta_api.h> #include <meta_api.h>
@ -59,8 +59,8 @@ void report_error( int code, char* fmt, ... )
//File fp( "error_amx.log","a" ); //File fp( "error_amx.log","a" );
//fp << string; //fp << string;
print_srvconsole( string ); print_srvconsole( string );
print_srvconsole("[AMX] Make sure that modules are compatible with AMX Mod X %s\n" , AMX_VERSION ); UTIL_Log("[AMXX] Make sure that modules are compatible with AMX Mod X %s" , AMX_VERSION );
print_srvconsole("[AMX] Please fix the problem then start the server again\n" ); UTIL_Log("[AMXX] Please fix the problem then start the server again" );
} }
sleep( 5 ); sleep( 5 );
exit( code ); exit( code );
@ -322,7 +322,7 @@ int loadModules(const char* filename)
if ( !fp ) if ( !fp )
{ {
print_srvconsole( "[AMX] Modules list not found (file \"%s\")\n",filename); UTIL_Log( "[AMXX] Modules list not found (file \"%s\")",filename);
return 0; return 0;
} }
@ -351,19 +351,19 @@ int loadModules(const char* filename)
switch( cc->getStatusValue() ) { switch( cc->getStatusValue() ) {
case MODULE_BADLOAD: case MODULE_BADLOAD:
report_error( 1 , "[AMX] Module is not a valid library (file \"%s\")\n",pathname ); report_error( 1 , "[AMXX] Module is not a valid library (file \"%s\")",pathname );
break; break;
case MODULE_NOINFO: case MODULE_NOINFO:
report_error( 1 ,"[AMX] Couldn't find info. about module (file \"%s\")\n",pathname ); report_error( 1 ,"[AMXX] Couldn't find info. about module (file \"%s\")",pathname );
break; break;
case MODULE_NOQUERY: case MODULE_NOQUERY:
report_error( 1 , "[AMX] Couldn't find \"AMX_Query\" (file \"%s\")\n", pathname ); report_error( 1 , "[AMXX] Couldn't find \"AMX_Query\" (file \"%s\")", pathname );
break; break;
case MODULE_NOATTACH: case MODULE_NOATTACH:
report_error( 1 , "[AMX] Couldn't find \"AMX_Attach\" (file \"%s\")\n", pathname ); report_error( 1 , "[AMXX] Couldn't find \"AMX_Attach\" (file \"%s\")", pathname );
break; break;
case MODULE_OLD: case MODULE_OLD:
report_error( 1 , "[AMX] Module has a different interface version (file \"%s\")\n",pathname ); report_error( 1 , "[AMXX] Module has a different interface version (file \"%s\")",pathname );
break; break;
default: default:
++loaded; ++loaded;
@ -436,7 +436,7 @@ void dettachMetaModModules( const char* filename )
if ( !fp ) if ( !fp )
{ {
print_srvconsole( "[AMX] Modules list not found (file \"%s\")\n",filename); UTIL_Log( "[AMXX] Modules list not found (file \"%s\")",filename);
return; return;
} }
@ -477,7 +477,7 @@ void attachMetaModModules( const char* filename )
if ( !fp ) if ( !fp )
{ {
print_srvconsole( "[AMX] Modules list not found (file \"%s\")\n",filename); UTIL_Log( "[AMXX] Modules list not found (file \"%s\")",filename);
return; return;
} }

View File

@ -1,36 +1,38 @@
/* AMX Mod X /*
* * Copyright (c) 2002-2003 Aleksander Naszko
* by the AMX Mod X Development Team *
* originally developed by OLO * This file is part of AMX Mod.
* *
* * AMX Mod is free software; you can redistribute it and/or modify it
* This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the
* under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at
* Free Software Foundation; either version 2 of the License, or (at * your option) any later version.
* your option) any later version. *
* * AMX Mod is distributed in the hope that it will be useful, but
* This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of
* WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* General Public License for more details. *
* * You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License * along with AMX Mod; if not, write to the Free Software Foundation,
* along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
* * In addition, as a special exception, the author gives permission to
* In addition, as a special exception, the author gives permission to * link the code of this program with the Half-Life Game Engine ("HL
* link the code of this program with the Half-Life Game Engine ("HL * Engine") and Modified Game Libraries ("MODs") developed by Valve,
* Engine") and Modified Game Libraries ("MODs") developed by Valve, * L.L.C ("Valve"). You must obey the GNU General Public License in all
* L.L.C ("Valve"). You must obey the GNU General Public License in all * respects for all of the code used other than the HL Engine and MODs
* respects for all of the code used other than the HL Engine and MODs * from Valve. If you modify this file, you may extend this exception
* from Valve. If you modify this file, you may extend this exception * to your version of the file, but you are not obligated to do so. If
* to your version of the file, but you are not obligated to do so. If * you do not wish to do so, delete this exception statement from your
* you do not wish to do so, delete this exception statement from your * version.
* version. *
*/ */
#include <extdll.h> #include <extdll.h>
#include <meta_api.h> #include <meta_api.h>
#include <time.h>
#include "amxmod.h" #include "amxmod.h"
int UTIL_ReadFlags(const char* c) int UTIL_ReadFlags(const char* c)
@ -268,4 +270,59 @@ void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1,
g_fakecmd.fake = true; g_fakecmd.fake = true;
MDLL_ClientCommand(pEdict); MDLL_ClientCommand(pEdict);
g_fakecmd.fake = false; g_fakecmd.fake = false;
}
std::string g_UTIL_LogFile;
void UTIL_MakeNewLogFile()
{
// build filename
time_t td;
time(&td);
tm *curTime = localtime(&td);
// create dir if not existing
mkdir(build_pathname("%s", g_log_dir.str()));
int i = 0;
while (true)
{
g_UTIL_LogFile = build_pathname("%s/L%02d%02d%03d.log", g_log_dir.str(), curTime->tm_mon + 1, curTime->tm_mday, i);
FILE *pTmpFile = fopen(g_UTIL_LogFile.c_str(), "r"); // open for reading to check whether the file exists
if (!pTmpFile)
break;
fclose(pTmpFile);
++i;
}
// Log logfile start
UTIL_Log("AMX Mod X log file started (file \"%s/L%02d%02d%03d.log\") (version \"%s\")", g_log_dir.str(), curTime->tm_mon + 1, curTime->tm_mday, i, AMX_VERSION);
}
void UTIL_Log(const char *fmt, ...)
{
// build message
// :TODO: Overflow possible here
char msg[3072];
va_list arglst;
va_start(arglst, fmt);
vsprintf(msg, fmt, arglst);
va_end(arglst);
// get time
time_t td;
time(&td);
tm *curTime = localtime(&td);
char date[32];
strftime(date, 31, "%m/%d/%Y - %H:%M:%S", curTime);
// log msg now
FILE *pF = fopen(g_UTIL_LogFile.c_str(), "a+");
if (!pF)
return; // don't try to create a new logfile to prevent recursion crashes if there is an unforseen error
fprintf(pF, "L %s: %s\n", date, msg);
fclose(pF);
print_srvconsole("L %s: %s\n", date, msg);
} }