more cleaned-up code

This commit is contained in:
Borja Ferrer 2005-09-10 20:09:14 +00:00
parent 612a86dbef
commit 76760b221d
20 changed files with 1537 additions and 1155 deletions

View File

@ -111,8 +111,7 @@ CmdMngr::Command* CmdMngr::getCmd(long int id, int type, int access)
while (buf_cmdptr) while (buf_cmdptr)
{ {
if ((*buf_cmdptr).gotAccess(access) && (*buf_cmdptr).getPlugin()->isExecutable((*buf_cmdptr).getFunction()) if ((*buf_cmdptr).gotAccess(access) && (*buf_cmdptr).getPlugin()->isExecutable((*buf_cmdptr).getFunction()) && (*buf_cmdptr).isViewable())
&& (*buf_cmdptr).isViewable())
{ {
if (id-- == 0) if (id-- == 0)
return &(*buf_cmdptr); return &(*buf_cmdptr);

View File

@ -556,10 +556,12 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
} else { } else {
cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang"); cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang");
} }
} else if (*pAmxLangName == LANG_SERVER) // LANG_SERVER }
else if (*pAmxLangName == LANG_SERVER) // LANG_SERVER
{ {
cpLangName = g_vault.get("server_language"); cpLangName = g_vault.get("server_language");
} else if (*pAmxLangName >= 1 && *pAmxLangName <= 32) // Direct Client Id }
else if (*pAmxLangName >= 1 && *pAmxLangName <= 32) // Direct Client Id
{ {
if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0) if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0)
{ {
@ -629,7 +631,6 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
cell *tmpCell = get_amxaddr(amx, params[parm++]); cell *tmpCell = get_amxaddr(amx, params[parm++]);
while (tmpPtr-tmpString < sizeof(tmpString) && *tmpCell) while (tmpPtr-tmpString < sizeof(tmpString) && *tmpCell)
*tmpPtr++ = static_cast<char>(*tmpCell++); *tmpPtr++ = static_cast<char>(*tmpCell++);
*tmpPtr = 0; *tmpPtr = 0;
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, tmpString); _snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, tmpString);
ZEROTERM(outbuf); ZEROTERM(outbuf);
@ -815,10 +816,12 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
} else { } else {
cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang"); cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang");
} }
} else if (pAmxLangName == (const char *)LANG_SERVER) // LANG_SERVER }
else if (pAmxLangName == (const char *)LANG_SERVER) // LANG_SERVER
{ {
cpLangName = g_vault.get("server_language"); cpLangName = g_vault.get("server_language");
} else if (pAmxLangName >= (const char *)1 && pAmxLangName <= (const char *)32) // Direct Client Id }
else if (pAmxLangName >= (const char *)1 && pAmxLangName <= (const char *)32) // Direct Client Id
{ {
if ((int)CVAR_GET_FLOAT("amx_client_languages")) if ((int)CVAR_GET_FLOAT("amx_client_languages"))
{ {
@ -1126,6 +1129,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
} // if !multiline } // if !multiline
} //if - main } //if - main
} }
// merge last section // merge last section
if (!Defq.empty()) if (!Defq.empty())
{ {
@ -1170,6 +1174,7 @@ const char *CLangMngr::GetDef(const char *langName, const char *key)
CLang *lang = GetLangR(langName); CLang *lang = GetLangR(langName);
if (lang) if (lang)
return lang->GetDef(key); return lang->GetDef(key);
return "ML_NOTFOUND(LANG)"; return "ML_NOTFOUND(LANG)";
} }

View File

@ -35,7 +35,8 @@
// ***************************************************** // *****************************************************
// class MenuMngr // class MenuMngr
// ***************************************************** // *****************************************************
MenuMngr::MenuCommand::MenuCommand( CPluginMngr::CPlugin *a, int mi, int k, int f ) { MenuMngr::MenuCommand::MenuCommand(CPluginMngr::CPlugin *a, int mi, int k, int f)
{
plugin = a; plugin = a;
keys = k; keys = k;
menuid = mi; menuid = mi;
@ -50,10 +51,12 @@ MenuMngr::~MenuMngr()
int MenuMngr::findMenuId(const char* name, AMX* amx) int MenuMngr::findMenuId(const char* name, AMX* amx)
{ {
for( MenuIdEle* b = headid; b ; b = b->next) { for (MenuIdEle* b = headid; b; b = b->next)
{
if ((!amx || !b->amx || amx == b->amx) && strstr(name,b->name.c_str())) if ((!amx || !b->amx || amx == b->amx) && strstr(name,b->name.c_str()))
return b->id; return b->id;
} }
return 0; return 0;
} }
@ -62,8 +65,10 @@ int MenuMngr::registerMenuId(const char* n, AMX* a )
int id = findMenuId(n, a); int id = findMenuId(n, a);
if (id) return id; if (id) return id;
headid = new MenuIdEle(n, a, headid); headid = new MenuIdEle(n, a, headid);
if (!headid) if (!headid)
return 0; // :TODO: Better error report return 0; // :TODO: Better error report
return headid->id; return headid->id;
} }

View File

@ -55,7 +55,8 @@ void CPlayer::Init( edict_t* e , int i )
team.clear(); team.clear();
} }
void CPlayer::Disconnect() { void CPlayer::Disconnect()
{
ingame = false; ingame = false;
initialized = false; initialized = false;
authorized = false; authorized = false;
@ -64,8 +65,10 @@ void CPlayer::Disconnect() {
{ {
ClientCvarQuery_Info *pQuery = cvarQueryQueue.front(); ClientCvarQuery_Info *pQuery = cvarQueryQueue.front();
unregisterSPForward(pQuery->resultFwd); unregisterSPForward(pQuery->resultFwd);
if (pQuery->params) if (pQuery->params)
delete [] pQuery->params; delete [] pQuery->params;
delete pQuery; delete pQuery;
cvarQueryQueue.pop(); cvarQueryQueue.pop();
} }
@ -73,11 +76,14 @@ void CPlayer::Disconnect() {
bot = 0; bot = 0;
} }
void CPlayer::PutInServer() { void CPlayer::PutInServer()
{
playtime = gpGlobals->time; playtime = gpGlobals->time;
ingame = true; ingame = true;
} }
bool CPlayer::Connect(const char* connectname,const char* ipaddress) {
bool CPlayer::Connect(const char* connectname, const char* ipaddress)
{
name.assign(connectname); name.assign(connectname);
ip.assign(ipaddress); ip.assign(ipaddress);
time = gpGlobals->time; time = gpGlobals->time;
@ -90,18 +96,16 @@ bool CPlayer::Connect(const char* connectname,const char* ipaddress) {
const char* authid = GETPLAYERAUTHID(pEdict); const char* authid = GETPLAYERAUTHID(pEdict);
if ( (authid == 0) || (*authid == 0) if ((authid == 0) || (*authid == 0) || (strcmp(authid, "STEAM_ID_PENDING") == 0))
|| (strcmp( authid , "STEAM_ID_PENDING") == 0) )
return true; return true;
return false; return false;
} }
// ***************************************************** // *****************************************************
// class Grenades // class Grenades
// ***************************************************** // *****************************************************
void Grenades::put(edict_t* grenade, float time, int type, CPlayer* player) void Grenades::put(edict_t* grenade, float time, int type, CPlayer* player)
{ {
Obj* a = new Obj; Obj* a = new Obj;
@ -118,30 +122,33 @@ bool Grenades::find( edict_t* enemy, CPlayer** p, int& type )
{ {
bool found = false; bool found = false;
Obj** a = &head; Obj** a = &head;
while ( *a ){
if ( (*a)->time > gpGlobals->time ) { while (*a)
if ( (*a)->grenade == enemy ) { {
if ((*a)->time > gpGlobals->time)
{
if ((*a)->grenade == enemy)
{
found = true; found = true;
(*p) = (*a)->player; (*p) = (*a)->player;
type = (*a)->type; type = (*a)->type;
} }
} } else {
else {
Obj* b = (*a)->next; Obj* b = (*a)->next;
delete *a; delete *a;
*a = b; *a = b;
continue; continue;
} }
a = &(*a)->next; a = &(*a)->next;
} }
return found; return found;
} }
void Grenades::clear() void Grenades::clear()
{ {
while(head){ while (head)
{
Obj* a = head->next; Obj* a = head->next;
delete head; delete head;
head = a; head = a;
@ -151,7 +158,9 @@ void Grenades::clear()
// ***************************************************** // *****************************************************
// class XVars // class XVars
// ***************************************************** // *****************************************************
void XVars::clear() {
void XVars::clear()
{
delete[] head; delete[] head;
head = 0; head = 0;
num = 0; num = 0;
@ -160,7 +169,8 @@ void XVars::clear() {
int XVars::put(AMX* p, cell* v) int XVars::put(AMX* p, cell* v)
{ {
for(int a = 0; a < num; ++a) { for (int a = 0; a < num; ++a)
{
if ((head[a].amx == p) && (head[a].value == v)) if ((head[a].amx == p) && (head[a].value == v))
return a; return a;
} }
@ -176,23 +186,31 @@ int XVars::put( AMX* p, cell* v )
int XVars::realloc_array(int nsize) int XVars::realloc_array(int nsize)
{ {
XVarEle* me = new XVarEle[nsize]; XVarEle* me = new XVarEle[nsize];
if ( me ){
if (me)
{
for (int a = 0 ; a < num; ++a) for (int a = 0 ; a < num; ++a)
me[a] = head[a]; me[a] = head[a];
delete[] head; delete[] head;
head = me; head = me;
size = nsize; size = nsize;
return 0; return 0;
} }
return 1; return 1;
} }
// ***************************************************** // *****************************************************
// class TeamIds // class TeamIds
// ***************************************************** // *****************************************************
TeamIds::TeamIds() { head = 0; newTeam = 0; } TeamIds::TeamIds() { head = 0; newTeam = 0; }
TeamIds::~TeamIds() {
while( head ) { TeamIds::~TeamIds()
{
while (head)
{
TeamEle* a = head->next; TeamEle* a = head->next;
delete head; delete head;
head = a; head = a;
@ -202,16 +220,22 @@ TeamIds::~TeamIds() {
void TeamIds::registerTeam(const char* n, int s) void TeamIds::registerTeam(const char* n, int s)
{ {
TeamEle** a = &head; TeamEle** a = &head;
while( *a ){
if ( strcmp((*a)->name.c_str(),n) == 0 ){ while (*a)
if (s != -1){ {
if (strcmp((*a)->name.c_str(),n) == 0)
{
if (s != -1)
{
(*a)->id = s; (*a)->id = s;
newTeam &= ~(1<<(*a)->tid); newTeam &= ~(1<<(*a)->tid);
} }
return; return;
} }
a = &(*a)->next; a = &(*a)->next;
} }
*a = new TeamEle(n, s); *a = new TeamEle(n, s);
if (*a == 0) return; if (*a == 0) return;
newTeam |= (1<<(*a)->tid); newTeam |= (1<<(*a)->tid);
@ -220,24 +244,29 @@ void TeamIds::registerTeam( const char* n ,int s )
int TeamIds::findTeamId(const char* n) int TeamIds::findTeamId(const char* n)
{ {
TeamEle* a = head; TeamEle* a = head;
while( a ){
while (a)
{
if (!stricmp(a->name.c_str(), n)) if (!stricmp(a->name.c_str(), n))
return a->id; return a->id;
a = a->next; a = a->next;
} }
return -1; return -1;
} }
int TeamIds::findTeamIdCase(const char* n) int TeamIds::findTeamIdCase(const char* n)
{ {
TeamEle* a = head; TeamEle* a = head;
while( a ){
while (a)
{
if (!strcmp(a->name.c_str(), n)) if (!strcmp(a->name.c_str(), n))
return a->id; return a->id;
a = a->next; a = a->next;
} }
return -1; return -1;
} }
char TeamIds::TeamEle::uid = 0; char TeamIds::TeamEle::uid = 0;

View File

@ -67,6 +67,7 @@ void CModule::clear(bool clearFilename)
m_Metamod = false; m_Metamod = false;
m_Handle = NULL; m_Handle = NULL;
m_Status = MODULE_NONE; m_Status = MODULE_NONE;
if (clearFilename) if (clearFilename)
m_Filename.assign("unknown"); m_Filename.assign("unknown");
@ -114,6 +115,7 @@ bool CModule::attachModule()
if (!AttachFunc_New) if (!AttachFunc_New)
return false; return false;
g_ModuleCallReason = ModuleCall_Attach; g_ModuleCallReason = ModuleCall_Attach;
g_CurrentlyCalledModule = this; g_CurrentlyCalledModule = this;
int retVal = (*AttachFunc_New)(Module_ReqFnptr); int retVal = (*AttachFunc_New)(Module_ReqFnptr);
@ -163,6 +165,7 @@ bool CModule::queryModule()
// Try new interface first // Try new interface first
QUERYMOD_NEW queryFunc_New = (QUERYMOD_NEW)DLPROC(m_Handle, "AMXX_Query"); QUERYMOD_NEW queryFunc_New = (QUERYMOD_NEW)DLPROC(m_Handle, "AMXX_Query");
if (queryFunc_New) if (queryFunc_New)
{ {
m_Amxx = true; m_Amxx = true;
@ -172,6 +175,7 @@ bool CModule::queryModule()
int retVal = (*queryFunc_New)(&ifVers, &m_InfoNew); int retVal = (*queryFunc_New)(&ifVers, &m_InfoNew);
g_CurrentlyCalledModule = NULL; g_CurrentlyCalledModule = NULL;
g_ModuleCallReason = ModuleCall_NotCalled; g_ModuleCallReason = ModuleCall_NotCalled;
switch (retVal) switch (retVal)
{ {
case AMXX_PARAM: case AMXX_PARAM:
@ -201,9 +205,7 @@ bool CModule::queryModule()
m_Status = MODULE_QUERY; m_Status = MODULE_QUERY;
return true; return true;
} } else {
else
{
m_Status = MODULE_NOQUERY; m_Status = MODULE_NOQUERY;
m_Amxx = false; m_Amxx = false;
return false; return false;
@ -218,6 +220,7 @@ bool CModule::detachModule()
if (m_Amxx) if (m_Amxx)
{ {
DETACHMOD_NEW detachFunc_New = (DETACHMOD_NEW)DLPROC(m_Handle, "AMXX_Detach"); DETACHMOD_NEW detachFunc_New = (DETACHMOD_NEW)DLPROC(m_Handle, "AMXX_Detach");
if (detachFunc_New) if (detachFunc_New)
{ {
g_ModuleCallReason = ModuleCall_Detach; g_ModuleCallReason = ModuleCall_Detach;
@ -227,14 +230,17 @@ bool CModule::detachModule()
g_ModuleCallReason = ModuleCall_NotCalled; g_ModuleCallReason = ModuleCall_NotCalled;
} }
} }
#ifndef FAKEMETA #ifndef FAKEMETA
if (IsMetamod()) if (IsMetamod())
{ {
UnloadMetamodPlugin(m_Handle); UnloadMetamodPlugin(m_Handle);
} }
#endif #endif
DLFREE(m_Handle); DLFREE(m_Handle);
clear(); clear();
return true; return true;
} }
@ -247,8 +253,10 @@ void CModule::CallPluginsLoaded()
return; return;
PLUGINSLOADED_NEW func = (PLUGINSLOADED_NEW)DLPROC(m_Handle, "AMXX_PluginsLoaded"); PLUGINSLOADED_NEW func = (PLUGINSLOADED_NEW)DLPROC(m_Handle, "AMXX_PluginsLoaded");
if (!func) if (!func)
return; return;
func(); func();
} }
@ -270,5 +278,6 @@ const char* CModule::getStatus() const
case MODULE_NOT64BIT: return "not 64bit"; case MODULE_NOT64BIT: return "not 64bit";
default: break; default: break;
} }
return "unknown"; return "unknown";
} }

View File

@ -33,6 +33,7 @@
#include "CTask.h" #include "CTask.h"
/*********************** CTask ***********************/ /*********************** CTask ***********************/
int CTaskMngr::CTask::getTaskId() const int CTaskMngr::CTask::getTaskId() const
{ {
return m_iId; return m_iId;
@ -57,10 +58,13 @@ void CTaskMngr::CTask::set(CPluginMngr::CPlugin *pPlugin, int iFunc, int iFlags,
{ {
m_bLoop = true; m_bLoop = true;
m_iRepeat = -1; m_iRepeat = -1;
} else if (iFlags & 1) { }
else if (iFlags & 1)
{
m_bLoop = true; m_bLoop = true;
m_iRepeat = iRepeat; m_iRepeat = iRepeat;
} }
m_bAfterStart = (iFlags & 4) ? true : false; m_bAfterStart = (iFlags & 4) ? true : false;
m_bBeforeEnd = (iFlags & 8) ? true : false; m_bBeforeEnd = (iFlags & 8) ? true : false;
@ -125,6 +129,7 @@ void CTaskMngr::CTask::executeIfRequired(float fCurrentTime, float fTimeLimit, f
{ {
bool execute = false; bool execute = false;
bool done = false; bool done = false;
if (m_bAfterStart) if (m_bAfterStart)
{ {
if (fCurrentTime - fTimeLeft + 1.0f >= m_fBase) if (fCurrentTime - fTimeLeft + 1.0f >= m_fBase)
@ -134,7 +139,9 @@ void CTaskMngr::CTask::executeIfRequired(float fCurrentTime, float fTimeLimit, f
{ {
if (fTimeLimit != 0.0f && (fTimeLeft + fTimeLimit * 60.0f) - fCurrentTime - 1.0f <= m_fBase) if (fTimeLimit != 0.0f && (fTimeLeft + fTimeLimit * 60.0f) - fCurrentTime - 1.0f <= m_fBase)
execute = true; execute = true;
} else if (m_fNextExecTime <= fCurrentTime) { }
else if (m_fNextExecTime <= fCurrentTime)
{
execute = true; execute = true;
} }
@ -199,6 +206,7 @@ CTaskMngr::CTask::~CTask()
} }
/*********************** CTaskMngr ***********************/ /*********************** CTaskMngr ***********************/
CTaskMngr::CTaskMngr() CTaskMngr::CTaskMngr()
{ {
m_pTmr_CurrentTime = NULL; m_pTmr_CurrentTime = NULL;
@ -222,17 +230,18 @@ void CTaskMngr::registerTask(CPluginMngr::CPlugin *pPlugin, int iFunc, int iFlag
{ {
// first, search for free tasks // first, search for free tasks
TaskListIter iter = m_Tasks.find(CTaskDescriptor(0, NULL, true)); TaskListIter iter = m_Tasks.find(CTaskDescriptor(0, NULL, true));
if (iter) if (iter)
{ {
// found: reuse it // found: reuse it
iter->set(pPlugin, iFunc, iFlags, iId, fBase, iParamsLen, pParams, iRepeat, *m_pTmr_CurrentTime); iter->set(pPlugin, iFunc, iFlags, iId, fBase, iParamsLen, pParams, iRepeat, *m_pTmr_CurrentTime);
} } else {
else
{
// not found: make a new one // not found: make a new one
CTask *pTmp = new CTask; CTask *pTmp = new CTask;
if (!pTmp) if (!pTmp)
return; return;
pTmp->set(pPlugin, iFunc, iFlags, iId, fBase, iParamsLen, pParams, iRepeat, *m_pTmr_CurrentTime); pTmp->set(pPlugin, iFunc, iFlags, iId, fBase, iParamsLen, pParams, iRepeat, *m_pTmr_CurrentTime);
m_Tasks.put(pTmp); m_Tasks.put(pTmp);
} }
@ -243,12 +252,14 @@ int CTaskMngr::removeTasks(int iId, AMX *pAmx)
CTaskDescriptor descriptor(iId, pAmx); CTaskDescriptor descriptor(iId, pAmx);
TaskListIter iter = m_Tasks.find(descriptor); TaskListIter iter = m_Tasks.find(descriptor);
int i = 0; int i = 0;
while (iter) while (iter)
{ {
iter->clear(); iter->clear();
++i; ++i;
iter = m_Tasks.find(++iter, descriptor); iter = m_Tasks.find(++iter, descriptor);
} }
return i; return i;
} }
@ -257,6 +268,7 @@ int CTaskMngr::changeTasks(int iId, AMX *pAmx, float fNewBase)
CTaskDescriptor descriptor(iId, pAmx); CTaskDescriptor descriptor(iId, pAmx);
TaskListIter iter = m_Tasks.find(descriptor); TaskListIter iter = m_Tasks.find(descriptor);
int i = 0; int i = 0;
while (iter) while (iter)
{ {
iter->changeBase(fNewBase); iter->changeBase(fNewBase);
@ -264,6 +276,7 @@ int CTaskMngr::changeTasks(int iId, AMX *pAmx, float fNewBase)
++i; ++i;
iter = m_Tasks.find(++iter, descriptor); iter = m_Tasks.find(++iter, descriptor);
} }
return i; return i;
} }

View File

@ -39,6 +39,7 @@
// ***************************************************** // *****************************************************
// class Vault // class Vault
// ***************************************************** // *****************************************************
bool Vault::exists(const char* k) bool Vault::exists(const char* k)
{ {
if (*k == 0) return false; if (*k == 0) return false;
@ -65,10 +66,10 @@ void Vault::put( const char* k, const char* v )
} }
else else
*a = new Obj(k, v); *a = new Obj(k, v);
} }
Vault::Obj::Obj( const char* k, const char* v): key(k) , value(v) , next(0) { Vault::Obj::Obj(const char* k, const char* v): key(k), value(v), next(0)
{
number = atoi(v); number = atoi(v);
} }
@ -136,7 +137,6 @@ void Vault::setSource( const char* n )
path.assign(n); path.assign(n);
} }
bool Vault::loadVault() bool Vault::loadVault()
{ {
if (path.empty()) return false; if (path.empty()) return false;

View File

@ -105,7 +105,8 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
m_pFile = NULL; m_pFile = NULL;
return; return;
} else if (magic == MAGIC_HEADER2) }
else if (magic == MAGIC_HEADER2)
{ {
DATAREAD(&m_Bh.version, sizeof(int16_t), 1); DATAREAD(&m_Bh.version, sizeof(int16_t), 1);
@ -155,7 +156,8 @@ CAmxxReader::CAmxxReader(const char *filename, int cellsize)
pe = &(m_Bh.plugins[m_Entry]); pe = &(m_Bh.plugins[m_Entry]);
m_SectionLength = pe->disksize; m_SectionLength = pe->disksize;
} else if (magic == MAGIC_HEADER) }
else if (magic == MAGIC_HEADER)
{ {
// try to find the section // try to find the section
mint8_t numOfPlugins; mint8_t numOfPlugins;
@ -274,7 +276,8 @@ size_t CAmxxReader::GetBufferSize()
DATAREAD(&hdr, sizeof(hdr), 1); DATAREAD(&hdr, sizeof(hdr), 1);
fseek(m_pFile, save, SEEK_SET); fseek(m_pFile, save, SEEK_SET);
return hdr.stp; return hdr.stp;
} else if (m_AmxxFile) }
else if (m_AmxxFile)
{ {
PluginEntry *pe = &(m_Bh.plugins[m_Entry]); PluginEntry *pe = &(m_Bh.plugins[m_Entry]);
@ -321,7 +324,8 @@ CAmxxReader::Error CAmxxReader::GetSection(void *buffer)
m_Status = Err_None; m_Status = Err_None;
return m_Status; return m_Status;
} else if (m_AmxxFile) }
else if (m_AmxxFile)
{ {
PluginEntry *pe = &(m_Bh.plugins[m_Entry]); PluginEntry *pe = &(m_Bh.plugins[m_Entry]);
char *tempBuffer = new char[m_SectionLength + 1]; char *tempBuffer = new char[m_SectionLength + 1];

View File

@ -58,7 +58,9 @@ WeaponsVault g_weaponsData[MAX_WEAPONS];
void Client_VGUIMenu(void* mValue) void Client_VGUIMenu(void* mValue)
{ {
if (!mPlayer) return; if (!mPlayer) return;
switch (mState++){
switch (mState++)
{
case 0: case 0:
mPlayer->menu = -(*(int*)mValue); mPlayer->menu = -(*(int*)mValue);
break; break;
@ -70,7 +72,9 @@ void Client_VGUIMenu(void* mValue)
void Client_ShowMenu(void* mValue) void Client_ShowMenu(void* mValue)
{ {
if (!mPlayer) return; if (!mPlayer) return;
switch (mState++){
switch (mState++)
{
case 0: case 0:
mPlayer->keys = *(int*)mValue; mPlayer->keys = *(int*)mValue;
break; break;
@ -83,7 +87,9 @@ void Client_TeamInfo(void* mValue)
{ {
if (mPlayer) return; if (mPlayer) return;
static int index; static int index;
switch (mState++) {
switch (mState++)
{
case 0: case 0:
index = *(int*)mValue; index = *(int*)mValue;
break; break;
@ -98,44 +104,57 @@ void Client_TeamInfo(void* mValue)
void Client_TextMsg(void* mValue) void Client_TextMsg(void* mValue)
{ {
if (mPlayer) return; if (mPlayer) return;
switch (mState++) {
case 1:{ switch (mState++)
{
case 1:
{
char * msg = (char*)mValue; char * msg = (char*)mValue;
if (!msg) break; if (!msg) break;
if ( !strncmp("#Game_C", msg , 7) ) {
if (!strncmp("#Game_C", msg, 7))
{
g_game_timeleft = g_game_restarting = gpGlobals->time + 3; g_game_timeleft = g_game_restarting = gpGlobals->time + 3;
//g_endround_time = gpGlobals->time; //g_endround_time = gpGlobals->time;
//g_newround_time = gpGlobals->time + CVAR_GET_FLOAT("mp_freezetime") + 3; //g_newround_time = gpGlobals->time + CVAR_GET_FLOAT("mp_freezetime") + 3;
} }
else if (!strncmp("#Game_w", msg , 7) ) { else if (!strncmp("#Game_w", msg, 7))
{
g_game_timeleft = -2; g_game_timeleft = -2;
} }
else if ( !strncmp("#game_clan_s", msg , 12) ){ else if (!strncmp("#game_clan_s", msg, 12))
{
g_game_timeleft = -3; g_game_timeleft = -3;
} }
break; break;
} }
case 2:{ case 2:
{
char * msg = (char*)mValue; char * msg = (char*)mValue;
if (!msg) break; if (!msg) break;
if (g_game_timeleft == -2 ){
if (g_game_timeleft == -2)
{
g_game_timeleft = g_game_restarting = gpGlobals->time + atoi(msg); g_game_timeleft = g_game_restarting = gpGlobals->time + atoi(msg);
//g_newround_time = g_game_timeleft + CVAR_GET_FLOAT("mp_freezetime"); //g_newround_time = g_game_timeleft + CVAR_GET_FLOAT("mp_freezetime");
} }
else if (g_game_timeleft == -3) else if (g_game_timeleft == -3)
g_game_restarting = atoi(msg) * 60.0f; g_game_restarting = atoi(msg) * 60.0f;
break; break;
} }
case 3:{ case 3:
{
char * msg = (char*)mValue; char * msg = (char*)mValue;
if (!msg) break; if (!msg) break;
if (g_game_timeleft != -3) break; if (g_game_timeleft != -3) break;
g_game_restarting += atoi(msg); g_game_restarting += atoi(msg);
g_game_timeleft = g_game_restarting = gpGlobals->time + g_game_restarting; g_game_timeleft = g_game_restarting = gpGlobals->time + g_game_restarting;
break; break;
} }
} }
} }
void Client_WeaponList(void* mValue) void Client_WeaponList(void* mValue)
@ -144,7 +163,9 @@ void Client_WeaponList(void* mValue)
//static int wpnList2; //static int wpnList2;
static int iSlot; static int iSlot;
static const char* wpnName; static const char* wpnName;
switch (mState++) {
switch (mState++)
{
case 0: case 0:
wpnName = (char*)mValue; wpnName = (char*)mValue;
break; break;
@ -159,7 +180,6 @@ void Client_WeaponList(void* mValue)
g_weaponsData[iId].iId = iId; g_weaponsData[iId].iId = iId;
g_weaponsData[iId].ammoSlot = iSlot; g_weaponsData[iId].ammoSlot = iSlot;
g_weaponsData[iId].fullName.assign(wpnName); g_weaponsData[iId].fullName.assign(wpnName);
} }
} }
@ -167,7 +187,9 @@ void Client_CurWeapon(void* mValue)
{ {
static int iState; static int iState;
static int iId; static int iId;
switch (mState++){
switch (mState++)
{
case 0: case 0:
iState = *(int*)mValue; iState = *(int*)mValue;
break; break;
@ -186,9 +208,10 @@ void Client_CurWeapon(void* mValue)
void Client_AmmoX(void* mValue) void Client_AmmoX(void* mValue)
{ {
static int iAmmo; static int iAmmo;
switch (mState++){
switch (mState++)
{
case 0: case 0:
iAmmo = *(int*)mValue; iAmmo = *(int*)mValue;
break; break;
@ -203,7 +226,9 @@ void Client_AmmoX(void* mValue)
void Client_AmmoPickup(void* mValue) void Client_AmmoPickup(void* mValue)
{ {
static int iSlot; static int iSlot;
switch (mState++){
switch (mState++)
{
case 0: case 0:
iSlot = *(int*)mValue; iSlot = *(int*)mValue;
break; break;
@ -219,7 +244,9 @@ void Client_ScoreInfo(void* mValue)
{ {
static int index; static int index;
static int deaths; static int deaths;
switch (mState++){
switch (mState++)
{
case 0: case 0:
index = *(int*)mValue; index = *(int*)mValue;
break; break;
@ -261,24 +288,21 @@ void Client_DeathMsg(void* mValue)
static int victim_id; static int victim_id;
static int hs; static int hs;
switch (mState++){ switch (mState++)
{
case 0: case 0:
killer_id = *(int*)mValue; killer_id = *(int*)mValue;
killer = (killer_id > 0 && killer_id < 33) ? killer = (killer_id > 0 && killer_id < 33) ? GET_PLAYER_POINTER_I(killer_id) : 0;
GET_PLAYER_POINTER_I(killer_id) : 0;
break; break;
case 1: case 1:
victim_id = *(int*)mValue; victim_id = *(int*)mValue;
victim = (victim_id > 0 && victim_id < 33) ? victim = (victim_id > 0 && victim_id < 33) ? GET_PLAYER_POINTER_I(victim_id) : 0;
GET_PLAYER_POINTER_I(victim_id) : 0;
break; break;
case 2: case 2:
hs = *(int*)mValue; hs = *(int*)mValue;
break; break;
case 3: case 3:
if (!killer || !victim) break; if (!killer || !victim) break;
victim->death_killer = killer_id; victim->death_killer = killer_id;
victim->death_weapon.assign((char*)mValue); victim->death_weapon.assign((char*)mValue);
victim->death_headshot = hs; victim->death_headshot = hs;
@ -313,4 +337,3 @@ void Client_ResetHUD(void* mValue)
} }
*/ */

View File

@ -5,7 +5,7 @@
* *
* *
* This program 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.
* *
@ -63,11 +63,13 @@ class AutoFilePtr
public: public:
AutoFilePtr(FILE *fp) : m_FP(fp) AutoFilePtr(FILE *fp) : m_FP(fp)
{ } { }
~AutoFilePtr() ~AutoFilePtr()
{ {
if (m_FP) if (m_FP)
fclose(m_FP); fclose(m_FP);
} }
operator FILE* () operator FILE* ()
{ {
return m_FP; return m_FP;
@ -82,18 +84,23 @@ static cell AMX_NATIVE_CALL read_dir(AMX *amx, cell *params)
DIR *dp; DIR *dp;
char* dirname = build_pathname("%s", get_amxstring(amx, params[1], 0, a)); char* dirname = build_pathname("%s", get_amxstring(amx, params[1], 0, a));
a = params[2]; a = params[2];
if ((dp = opendir (dirname)) == NULL) if ((dp = opendir (dirname)) == NULL)
return 0; return 0;
seekdir(dp, a); seekdir(dp, a);
if ( (ep = readdir (dp)) != NULL ) {
if ((ep = readdir (dp)) != NULL)
{
cell *length = get_amxaddr(amx, params[5]); cell *length = get_amxaddr(amx, params[5]);
*length = set_amxstring(amx, params[3], ep->d_name, params[4]); *length = set_amxstring(amx, params[3], ep->d_name, params[4]);
a = telldir(dp); a = telldir(dp);
} } else
else
a = 0; a = 0;
closedir (dp); closedir (dp);
return a; return a;
#else #else
int tmp; int tmp;
char *dirname = build_pathname("%s/*", get_amxstring(amx, params[1], 0, tmp)); char *dirname = build_pathname("%s/*", get_amxstring(amx, params[1], 0, tmp));
@ -101,10 +108,12 @@ static cell AMX_NATIVE_CALL read_dir(AMX *amx, cell *params)
_finddata_t fd; _finddata_t fd;
intptr_t handle = _findfirst(dirname, &fd); intptr_t handle = _findfirst(dirname, &fd);
if (handle < 0) if (handle < 0)
return 0; return 0;
++tmp; ++tmp;
for (int i = 0; i < tmp; ++i) for (int i = 0; i < tmp; ++i)
{ {
if (_findnext(handle, &fd) < 0) if (_findnext(handle, &fd) < 0)
@ -113,6 +122,7 @@ static cell AMX_NATIVE_CALL read_dir(AMX *amx, cell *params)
break; break;
} }
} }
// current data in fd // current data in fd
cell *length = get_amxaddr(amx, params[5]); // pointer to the outLen parameter cell *length = get_amxaddr(amx, params[5]); // pointer to the outLen parameter
*length = set_amxstring(amx, params[3], fd.name, params[4]); // set output and outLen parameters *length = set_amxstring(amx, params[3], fd.name, params[4]); // set output and outLen parameters
@ -127,16 +137,22 @@ static cell AMX_NATIVE_CALL read_file(AMX *amx, cell *params) /* 5 param */
int iLen; int iLen;
char* szFile = get_amxstring(amx, params[1], 0, iLen); char* szFile = get_amxstring(amx, params[1], 0, iLen);
FILE *fp; FILE *fp;
if ( (fp =fopen(build_pathname("%s",szFile),"r")) == NULL) {
if ((fp =fopen(build_pathname("%s", szFile), "r")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE); amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0; return 0;
} }
char buffor[1024]; char buffor[1024];
int i = 0, iLine = params[2]; int i = 0, iLine = params[2];
while ((i <= iLine) && fgets(buffor, 1023, fp)) while ((i <= iLine) && fgets(buffor, 1023, fp))
i++; i++;
fclose(fp); fclose(fp);
if (i > iLine){
if (i > iLine)
{
int len = strlen(buffor); int len = strlen(buffor);
if (buffor[len - 1] == '\n') if (buffor[len - 1] == '\n')
buffor[--len] = 0; buffor[--len] = 0;
@ -146,6 +162,7 @@ static cell AMX_NATIVE_CALL read_file(AMX *amx, cell *params) /* 5 param */
*length = set_amxstring(amx, params[3], buffor, params[4]); *length = set_amxstring(amx, params[3], buffor, params[4]);
return i; return i;
} }
return 0; return 0;
} }
@ -158,11 +175,14 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
int iLine = params[3]; int iLine = params[3];
// apending to the end // apending to the end
if (iLine < 0) { if (iLine < 0)
if ( (pFile = fopen( sFile ,"a")) == NULL ){ {
if ((pFile = fopen(sFile, "a")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE); amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0; return 0;
} }
fputs(sText, pFile); fputs(sText, pFile);
fputc('\n', pFile); fputc('\n', pFile);
fclose(pFile); fclose(pFile);
@ -170,13 +190,17 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
} }
// creating a new file with a line in a middle // creating a new file with a line in a middle
if ( (pFile = fopen(sFile,"r")) == NULL ) { if ((pFile = fopen(sFile, "r")) == NULL)
if ( (pFile = fopen(sFile,"w")) == NULL ){ {
if ((pFile = fopen(sFile, "w")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE); amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0; return 0;
} }
for (i = 0; i < iLine; ++i) for (i = 0; i < iLine; ++i)
fputc('\n', pFile); fputc('\n', pFile);
fputs(sText, pFile); fputs(sText, pFile);
fputc('\n', pFile); fputc('\n', pFile);
fclose(pFile); fclose(pFile);
@ -187,21 +211,26 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
FILE* pTemp; FILE* pTemp;
char buffor[2048]; char buffor[2048];
if ( (pTemp = tmpfile()) == NULL ){ if ((pTemp = tmpfile()) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE); amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0; return 0;
} }
for(i=0;;++i){ for (i = 0; ; ++i)
if ( i == iLine ){ {
if (i == iLine)
{
fgets(buffor, 2047, pFile); fgets(buffor, 2047, pFile);
fputs(sText, pTemp); fputs(sText, pTemp);
fputc('\n', pTemp); fputc('\n', pTemp);
} }
else if ( fgets(buffor,2047,pFile) ){ else if (fgets(buffor, 2047, pFile))
{
fputs(buffor, pTemp); fputs(buffor, pTemp);
} }
else if ( i < iLine ) { else if (i < iLine)
{
fputc('\n', pTemp); fputc('\n', pTemp);
} }
else break; else break;
@ -211,7 +240,8 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
rewind(pTemp); rewind(pTemp);
// now rewrite because file can be now smaller... // now rewrite because file can be now smaller...
if ( (pFile = fopen(sFile,"w")) == NULL ){ if ((pFile = fopen(sFile, "w")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE); amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0; return 0;
} }
@ -221,6 +251,7 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
fclose(pTemp); fclose(pTemp);
fclose(pFile); fclose(pFile);
return 1; return 1;
} }
@ -236,6 +267,7 @@ static cell AMX_NATIVE_CALL file_exists(AMX *amx, cell *params) /* 1 param */
int iLen; int iLen;
char *sFile = get_amxstring(amx, params[1], 0, iLen); char *sFile = get_amxstring(amx, params[1], 0, iLen);
char *file = build_pathname("%s", sFile); char *file = build_pathname("%s", sFile);
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
DWORD attr = GetFileAttributes(file); DWORD attr = GetFileAttributes(file);
if (attr == INVALID_FILE_ATTRIBUTES) if (attr == INVALID_FILE_ATTRIBUTES)
@ -258,6 +290,7 @@ static cell AMX_NATIVE_CALL dir_exists(AMX *amx, cell *params) /* 1 param */
int iLen; int iLen;
char *sFile = get_amxstring(amx, params[1], 0, iLen); char *sFile = get_amxstring(amx, params[1], 0, iLen);
char *file = build_pathname("%s", sFile); char *file = build_pathname("%s", sFile);
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
DWORD attr = GetFileAttributes(file); DWORD attr = GetFileAttributes(file);
if (attr == INVALID_FILE_ATTRIBUTES) if (attr == INVALID_FILE_ATTRIBUTES)
@ -280,6 +313,7 @@ static cell AMX_NATIVE_CALL file_size(AMX *amx, cell *params) /* 1 param */
int iLen; int iLen;
char* sFile = get_amxstring(amx, params[1], 0, iLen); char* sFile = get_amxstring(amx, params[1], 0, iLen);
AutoFilePtr fp(fopen(build_pathname("%s", sFile), "r")); AutoFilePtr fp(fopen(build_pathname("%s", sFile), "r"));
if (fp != NULL) if (fp != NULL)
{ {
if (params[0] < 2 || params[2] == 0) if (params[0] < 2 || params[2] == 0)
@ -291,11 +325,11 @@ static cell AMX_NATIVE_CALL file_size(AMX *amx, cell *params) /* 1 param */
else if (params[2] == 1) else if (params[2] == 1)
{ {
int a = 0,lines = 0; int a = 0,lines = 0;
while (a != EOF) while (a != EOF)
{ {
++lines; ++lines;
while ( (a = fgetc(fp)) != '\n' && a != EOF ) while ((a = fgetc(fp)) != '\n' && a != EOF);
;
} }
//int a, b = '\n'; //int a, b = '\n';
//while( (a = fgetc(fp)) != EOF ){ //while( (a = fgetc(fp)) != EOF ){
@ -307,13 +341,16 @@ static cell AMX_NATIVE_CALL file_size(AMX *amx, cell *params) /* 1 param */
// ++lines; // ++lines;
return lines; return lines;
} }
else if ( params[2] == 2 ){ else if (params[2] == 2)
{
fseek(fp, -1, SEEK_END); fseek(fp, -1, SEEK_END);
if (fgetc(fp) == '\n') if (fgetc(fp) == '\n')
return 1; return 1;
return 0; return 0;
} }
} }
return -1; return -1;
} }
@ -327,7 +364,8 @@ static cell AMX_NATIVE_CALL amx_fopen(AMX *amx, cell *params)
char *flags = get_amxstring(amx, params[2], 0, len); char *flags = get_amxstring(amx, params[2], 0, len);
FILE *fp = fopen(file, flags); FILE *fp = fopen(file, flags);
if (fp == NULL) { if (fp == NULL)
{
// Failed // Failed
return 0; return 0;
} }
@ -340,6 +378,7 @@ static cell AMX_NATIVE_CALL amx_fopen(AMX *amx, cell *params)
break; break;
} }
} }
if (j == -1) if (j == -1)
{ {
FileList.push_back(fp); FileList.push_back(fp);
@ -354,10 +393,13 @@ static cell AMX_NATIVE_CALL amx_fopen(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_fclose(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fclose(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
if (fp) {
if (fp)
{
return fclose(fp); return fclose(fp);
} else { } else {
return -1; return -1;
@ -367,17 +409,22 @@ static cell AMX_NATIVE_CALL amx_fclose(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_fread(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fread(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
char *buffer; char *buffer;
if (fp) {
if (fp)
{
buffer = new char[params[3]]; // SLOW!!! :TODO: Find a better way (auto pointers?) buffer = new char[params[3]]; // SLOW!!! :TODO: Find a better way (auto pointers?)
fread(buffer, sizeof(char), params[3], fp); fread(buffer, sizeof(char), params[3], fp);
set_amxstring(amx, params[2], buffer, params[3]); set_amxstring(amx, params[2], buffer, params[3]);
delete [] buffer; delete [] buffer;
return 1; return 1;
} }
return -1; return -1;
} }
@ -385,10 +432,13 @@ static cell AMX_NATIVE_CALL amx_fread(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_fgetc(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fgetc(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
if (fp) {
if (fp)
{
return fgetc(fp); return fgetc(fp);
} else { } else {
return -1; return -1;
@ -398,89 +448,111 @@ static cell AMX_NATIVE_CALL amx_fgetc(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_fwrite(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fwrite(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
char *buf; char *buf;
int len; int len;
if (fp) {
if (fp)
{
buf = format_amxstring(amx, params, 2, len); buf = format_amxstring(amx, params, 2, len);
return fwrite(buf, sizeof(char), strlen(buf), fp); return fwrite(buf, sizeof(char), strlen(buf), fp);
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_feof(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_feof(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
if (fp) {
if (feof(fp)) { if (fp)
{
if (feof(fp))
{
return 1; return 1;
} }
return 0; return 0;
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fseek(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fseek(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
if (fp) { if (fp)
{
return fseek(fp, (long)params[2], params[3]); return fseek(fp, (long)params[2], params[3]);
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fputc(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fputc(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
if (fp) { if (fp)
{
return fputc(params[2], fp); return fputc(params[2], fp);
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_rewind(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_rewind(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
if (fp) { if (fp)
{
rewind(fp); rewind(fp);
return 1; return 1;
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fflush(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fflush(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
if (fp) { if (fp)
{
return fflush(fp); return fflush(fp);
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fscanf(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fscanf(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
@ -488,7 +560,9 @@ static cell AMX_NATIVE_CALL amx_fscanf(AMX *amx, cell *params)
char *buf; char *buf;
int len; int len;
buf = format_amxstring(amx, params, 2, len); buf = format_amxstring(amx, params, 2, len);
if (fp) {
if (fp)
{
return fscanf(fp, "%s", buf); return fscanf(fp, "%s", buf);
} }
@ -498,13 +572,16 @@ static cell AMX_NATIVE_CALL amx_fscanf(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_ftell(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_ftell(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
if (fp) { if (fp)
{
return ftell(fp); return ftell(fp);
} }
return -1; return -1;
} }
#endif //UNUSED #endif //UNUSED
@ -515,11 +592,14 @@ static cell AMX_NATIVE_CALL amx_filesize(AMX *amx, cell *params)
char *file = build_pathname("%s", format_amxstring(amx, params, 1, len)); char *file = build_pathname("%s", format_amxstring(amx, params, 1, len));
long size; long size;
AutoFilePtr fp(fopen(file, "rb")); AutoFilePtr fp(fopen(file, "rb"));
if (fp) {
if (fp)
{
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
size = ftell(fp); size = ftell(fp);
return size; return size;
} }
return -1; return -1;
} }
@ -527,116 +607,148 @@ static cell AMX_NATIVE_CALL amx_filesize(AMX *amx, cell *params)
static cell AMX_NATIVE_CALL amx_fgetl(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fgetl(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
long t; long t;
if (fp) {
if (fp)
{
fread(&t, sizeof(long), 1, fp); fread(&t, sizeof(long), 1, fp);
return t; return t;
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fgeti(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fgeti(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
int t; int t;
if (fp) {
if (fp)
{
fread(&t, sizeof(int), 1, fp); fread(&t, sizeof(int), 1, fp);
return t; return t;
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fgets(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fgets(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
short t; short t;
if (fp) {
if (fp)
{
fread(&t, sizeof(short), 1, fp); fread(&t, sizeof(short), 1, fp);
return t; return t;
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fputs(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fputs(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
short size = params[2]; short size = params[2];
if (fp) {
if (fp)
{
return fwrite(&size, sizeof(short), 1, fp); return fwrite(&size, sizeof(short), 1, fp);
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fputl(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fputl(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
long size = params[2]; long size = params[2];
if (fp) {
if (fp)
{
return fwrite(&size, sizeof(long), 1, fp); return fwrite(&size, sizeof(long), 1, fp);
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fputi(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fputi(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
int size = params[2]; int size = params[2];
if (fp) {
if (fp)
{
return fwrite(&size, sizeof(int), 1, fp); return fwrite(&size, sizeof(int), 1, fp);
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fgetf(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fgetf(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
float t; float t;
if (fp) {
if (fp)
{
fread(&t, sizeof(float), 1, fp); fread(&t, sizeof(float), 1, fp);
return *(cell*)&t; return *(cell*)&t;
} }
return -1; return -1;
} }
static cell AMX_NATIVE_CALL amx_fputf(AMX *amx, cell *params) static cell AMX_NATIVE_CALL amx_fputf(AMX *amx, cell *params)
{ {
unsigned int id = params[1] - 1; unsigned int id = params[1] - 1;
if (id >= FileList.size() || FileList.at(id) == NULL) if (id >= FileList.size() || FileList.at(id) == NULL)
return 0; return 0;
FILE *fp = FileList.at(id); FILE *fp = FileList.at(id);
float size = *(float *)((void *)&params[2]); float size = *(float *)((void *)&params[2]);
if (fp) {
if (fp)
{
return fwrite(&size, sizeof(float), 1, fp); return fwrite(&size, sizeof(float), 1, fp);
} }
return -1; return -1;
} }
#endif //UNUSED #endif //UNUSED
@ -657,22 +769,28 @@ static cell AMX_NATIVE_CALL amx_open_dir(AMX *amx, cell *params)
char *dirname = build_pathname("%s\\*", path); char *dirname = build_pathname("%s\\*", path);
WIN32_FIND_DATA fd; WIN32_FIND_DATA fd;
HANDLE hFile = FindFirstFile(dirname, &fd); HANDLE hFile = FindFirstFile(dirname, &fd);
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
return 0; return 0;
set_amxstring(amx, params[2], fd.cFileName, params[3]); set_amxstring(amx, params[2], fd.cFileName, params[3]);
return (DWORD)hFile; return (DWORD)hFile;
#else #else
char *dirname = build_pathname("%s", path); char *dirname = build_pathname("%s", path);
DIR *dp = opendir(dirname); DIR *dp = opendir(dirname);
if (!dp) if (!dp)
return NULL; return NULL;
struct dirent *ep = readdir(dp); struct dirent *ep = readdir(dp);
if (!ep) if (!ep)
{ {
closedir(dp); closedir(dp);
return NULL; return NULL;
} }
set_amxstring(amx, params[2], ep->d_name, params[3]); set_amxstring(amx, params[2], ep->d_name, params[3]);
return (cell)dp; return (cell)dp;
#endif #endif
} }
@ -681,14 +799,18 @@ static cell AMX_NATIVE_CALL amx_close_dir(AMX *amx, cell *params)
{ {
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
HANDLE hFile = (HANDLE)((DWORD)params[1]); HANDLE hFile = (HANDLE)((DWORD)params[1]);
if (hFile == INVALID_HANDLE_VALUE || hFile == NULL) if (hFile == INVALID_HANDLE_VALUE || hFile == NULL)
return 0; return 0;
FindClose(hFile); FindClose(hFile);
return 1; return 1;
#else #else
DIR *dp = (DIR *)params[1]; DIR *dp = (DIR *)params[1];
if (!dp) if (!dp)
return 0; return 0;
closedir(dp); closedir(dp);
return 1; return 1;
#endif #endif
@ -698,26 +820,33 @@ static cell AMX_NATIVE_CALL amx_get_dir(AMX *amx, cell *params)
{ {
#if defined WIN32 || defined _WIN32 #if defined WIN32 || defined _WIN32
HANDLE hFile = (HANDLE)((DWORD)params[1]); HANDLE hFile = (HANDLE)((DWORD)params[1]);
if (hFile == INVALID_HANDLE_VALUE || hFile == NULL) if (hFile == INVALID_HANDLE_VALUE || hFile == NULL)
return 0; return 0;
WIN32_FIND_DATA fd; WIN32_FIND_DATA fd;
if (!FindNextFile(hFile, &fd)) if (!FindNextFile(hFile, &fd))
return 0; return 0;
set_amxstring(amx, params[2], fd.cFileName, params[3]); set_amxstring(amx, params[2], fd.cFileName, params[3]);
return 1; return 1;
#else #else
DIR *dp = (DIR *)params[1]; DIR *dp = (DIR *)params[1];
if (!dp) if (!dp)
return 0; return 0;
struct dirent *ep = readdir(dp); struct dirent *ep = readdir(dp);
if (!ep) if (!ep)
return 0; return 0;
set_amxstring(amx, params[2], ep->d_name, params[3]); set_amxstring(amx, params[2], ep->d_name, params[3]);
return 1; return 1;
#endif #endif
} }
AMX_NATIVE_INFO file_Natives[] = { AMX_NATIVE_INFO file_Natives[] =
{
{"delete_file", delete_file}, {"delete_file", delete_file},
{"file_exists", file_exists}, {"file_exists", file_exists},
{"file_size", file_size}, {"file_size", file_size},
@ -754,8 +883,5 @@ AMX_NATIVE_INFO file_Natives[] = {
{"open_dir", amx_open_dir}, {"open_dir", amx_open_dir},
{"close_dir", amx_close_dir}, {"close_dir", amx_close_dir},
{"next_file", amx_get_dir}, {"next_file", amx_get_dir},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -718,16 +718,19 @@ void C_ClientCommand(edict_t *pEntity)
ret = executeForwards((*a).getFunction(), pPlayer->index, menu, item); ret = executeForwards((*a).getFunction(), pPlayer->index, menu, item);
if (ret & 2) result = MRES_SUPERCEDE; if (ret & 2) result = MRES_SUPERCEDE;
else if (ret & 1) RETURN_META(MRES_SUPERCEDE); else
if (ret & 1) RETURN_META(MRES_SUPERCEDE);
else else
{ {
if (item == MENU_BACK) if (item == MENU_BACK)
{ {
pMenu->Display(pPlayer->index, pPlayer->page-1); pMenu->Display(pPlayer->index, pPlayer->page-1);
} else if (item == MENU_MORE) }
else if (item == MENU_MORE)
{ {
pMenu->Display(pPlayer->index, pPlayer->page + 1); pMenu->Display(pPlayer->index, pPlayer->page + 1);
} else if (item == MENU_EXIT) }
else if (item == MENU_EXIT)
{ {
//nothing //nothing
} }
@ -1119,11 +1122,13 @@ C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_
{ {
LOG_ERROR(PLID, "metamod version is too old for this plugin; update metamod"); LOG_ERROR(PLID, "metamod version is too old for this plugin; update metamod");
return (FALSE); return (FALSE);
} else if (pmajor < mmajor) }
else if (pmajor < mmajor)
{ {
LOG_ERROR(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin"); LOG_ERROR(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin");
return (FALSE); return (FALSE);
} else if (pmajor == mmajor) }
else if (pmajor == mmajor)
{ {
#ifdef FAKEMETA #ifdef FAKEMETA
if (mminor == 10) if (mminor == 10)
@ -1138,14 +1143,17 @@ C_DLLEXPORT int Meta_Query(char *ifvers, plugin_info_t **pPlugInfo, mutil_funcs_
{ {
g_NeedsP = true; g_NeedsP = true;
#endif #endif
} else if (mminor >= 11) }
else if (mminor >= 11)
{ {
g_IsNewMM = true; g_IsNewMM = true;
} else if (pminor > mminor) }
else if (pminor > mminor)
{ {
LOG_ERROR(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin"); LOG_ERROR(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin");
return FALSE; return FALSE;
} else if (pminor < mminor) }
else if (pminor < mminor)
{ {
LOG_MESSAGE(PLID, "WARNING: metamod version is newer than expected; consider finding a newer version of this plugin"); LOG_MESSAGE(PLID, "WARNING: metamod version is newer than expected; consider finding a newer version of this plugin");

View File

@ -1,3 +1,33 @@
/* AMX Mod X
*
* by the AMX Mod X Development Team
* originally developed by OLO
*
* 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
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* 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 "amxmodx.h" #include "amxmodx.h"
#include "newmenus.h" #include "newmenus.h"
@ -86,10 +116,14 @@ int Menu::PagekeyToItem(page_t page, item_t key)
return MENU_MORE; return MENU_MORE;
else else
return MENU_EXIT; return MENU_EXIT;
} else if (key == rem+1) { }
else if (key == rem + 1)
{
return MENU_EXIT; return MENU_EXIT;
} }
} else if (page == pages - 1) { }
else if (page == pages - 1)
{
//find number of remaining items //find number of remaining items
//for example, 11 items on page 1... means start=7, 11-7=4 //for example, 11 items on page 1... means start=7, 11-7=4
item_t rem = numItems - start; item_t rem = numItems - start;
@ -97,14 +131,18 @@ int Menu::PagekeyToItem(page_t page, item_t key)
if (key == rem) if (key == rem)
{ {
return MENU_EXIT; return MENU_EXIT;
} else if (key == rem+1) { }
else if (key == rem + 1)
{
return MENU_BACK; return MENU_BACK;
} }
} else { } else {
if (key == 7) if (key == 7)
{ {
return MENU_MORE; return MENU_MORE;
} else if (key == 8) { }
else if (key == 8)
{
return MENU_BACK; return MENU_BACK;
} }
} }

View File

@ -31,34 +31,28 @@
#include "amxmodx.h" #include "amxmodx.h"
void amx_command(){ void amx_command()
{
const char* cmd = CMD_ARGV(1); const char* cmd = CMD_ARGV(1);
if (!strcmp(cmd, "plugins") || !strcmp(cmd, "list")) if (!strcmp(cmd, "plugins") || !strcmp(cmd, "list"))
{ {
print_srvconsole("Currently loaded plugins:\n"); print_srvconsole("Currently loaded plugins:\n");
print_srvconsole( " %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s\n", print_srvconsole(" %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s\n", "name", "version", "author", "file", "status");
"name","version","author","file","status");
int plugins = 0; int plugins = 0;
int running = 0; int running = 0;
CPluginMngr::iterator a = g_plugins.begin(); CPluginMngr::iterator a = g_plugins.begin();
while (a) while (a)
{ {
++plugins; ++plugins;
if ((*a).isValid() && !(*a).isPaused()) if ((*a).isValid() && !(*a).isPaused())
++running; ++running;
print_srvconsole( " [%3d] %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s\n", print_srvconsole(" [%3d] %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s\n", plugins, (*a).getTitle(), (*a).getVersion(), (*a).getAuthor(), (*a).getName(), (*a).getStatus());
plugins,(*a).getTitle(),(*a).getVersion(),
(*a).getAuthor(), (*a).getName(), (*a).getStatus() );
++a; ++a;
} }
@ -75,7 +69,6 @@ void amx_command(){
} }
print_srvconsole("%d plugins, %d running\n", plugins, running); print_srvconsole("%d plugins, %d running\n", plugins, running);
} }
else if (!strcmp(cmd, "pause") && CMD_ARGC() > 2) else if (!strcmp(cmd, "pause") && CMD_ARGC() > 2)
{ {
@ -88,8 +81,8 @@ void amx_command(){
plugin->pausePlugin(); plugin->pausePlugin();
print_srvconsole("Paused plugin \"%s\"\n", plugin->getName()); print_srvconsole("Paused plugin \"%s\"\n", plugin->getName());
} }
else print_srvconsole("Couldn't find plugin matching \"%s\"\n",sPlugin); else
print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin);
} }
else if (!strcmp(cmd, "unpause") && CMD_ARGC() > 2) else if (!strcmp(cmd, "unpause") && CMD_ARGC() > 2)
{ {
@ -101,38 +94,34 @@ void amx_command(){
{ {
plugin->unpausePlugin(); plugin->unpausePlugin();
print_srvconsole("Unpaused plugin \"%s\"\n", plugin->getName()); print_srvconsole("Unpaused plugin \"%s\"\n", plugin->getName());
} else if (!plugin) { }
else if (!plugin)
{
print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin); print_srvconsole("Couldn't find plugin matching \"%s\"\n", sPlugin);
} else { } else {
print_srvconsole("Plugin %s can't be unpaused right now.", sPlugin); print_srvconsole("Plugin %s can't be unpaused right now.", sPlugin);
} }
} }
else if (!strcmp(cmd, "cvars")) else if (!strcmp(cmd, "cvars"))
{ {
print_srvconsole("Registered cvars:\n"); print_srvconsole("Registered cvars:\n");
print_srvconsole( " %-24.23s %-24.23s %-16.15s\n", print_srvconsole(" %-24.23s %-24.23s %-16.15s\n", "name", "value", "plugin");
"name","value","plugin");
int ammount = 0; int ammount = 0;
for (CList<CCVar>::iterator a = g_cvars.begin(); a; ++a) for (CList<CCVar>::iterator a = g_cvars.begin(); a; ++a)
{ {
print_srvconsole( " [%3d] %-24.23s %-24.23s %-16.15s\n",++ammount, print_srvconsole(" [%3d] %-24.23s %-24.23s %-16.15s\n", ++ammount, (*a).getName(), CVAR_GET_STRING((*a).getName()), (*a).getPluginName());
(*a).getName() ,CVAR_GET_STRING( (*a).getName() ),(*a).getPluginName() );
} }
print_srvconsole("%d cvars\n", ammount); print_srvconsole("%d cvars\n", ammount);
} }
else if (!strcmp(cmd, "cmds")) else if (!strcmp(cmd, "cmds"))
{ {
print_srvconsole("Registered commands:\n"); print_srvconsole("Registered commands:\n");
print_srvconsole( " %-24.23s %-16.15s %-8.7s %-16.15s\n", print_srvconsole(" %-24.23s %-16.15s %-8.7s %-16.15s\n", "name", "access", "type", "plugin");
"name","access" ,"type" ,"plugin");
int ammount = 0; int ammount = 0;
char access[32]; char access[32];
CmdMngr::iterator a = g_commands.begin(CMD_ConsoleCommand); CmdMngr::iterator a = g_commands.begin(CMD_ConsoleCommand);
@ -140,8 +129,7 @@ void amx_command(){
while (a) while (a)
{ {
UTIL_GetFlags(access, (*a).getFlags()); UTIL_GetFlags(access, (*a).getFlags());
print_srvconsole( " [%3d] %-24.23s %-16.15s %-8.7s %-16.15s\n", print_srvconsole(" [%3d] %-24.23s %-16.15s %-8.7s %-16.15s\n", ++ammount, (*a).getCmdLine(), access, (*a).getCmdType(), (*a).getPlugin()->getName());
++ammount,(*a).getCmdLine() , access , (*a).getCmdType() , (*a).getPlugin()->getName());
++a; ++a;
} }
@ -149,7 +137,6 @@ void amx_command(){
} }
else if (!strcmp(cmd, "version")) else if (!strcmp(cmd, "version"))
{ {
print_srvconsole("%s %s\n", Plugin_info.name, Plugin_info.version); print_srvconsole("%s %s\n", Plugin_info.name, Plugin_info.version);
print_srvconsole("Authors: %s (%s)\n", "Felix \"SniperBeamer\" Geyer, David \"BAILOPAN\" Anderson, Pavol \"PM OnoTo\" Marko, Jonny \"Got His Gun\" Bergstrom, and Lukasz \"SidLuke\" Wlasinski.", Plugin_info.url); print_srvconsole("Authors: %s (%s)\n", "Felix \"SniperBeamer\" Geyer, David \"BAILOPAN\" Anderson, Pavol \"PM OnoTo\" Marko, Jonny \"Got His Gun\" Bergstrom, and Lukasz \"SidLuke\" Wlasinski.", Plugin_info.url);
print_srvconsole("Compiled: %s\n", __DATE__ ", " __TIME__); print_srvconsole("Compiled: %s\n", __DATE__ ", " __TIME__);
@ -166,8 +153,7 @@ void amx_command(){
else if (!strcmp(cmd, "modules")) else if (!strcmp(cmd, "modules"))
{ {
print_srvconsole("Currently loaded modules:\n"); print_srvconsole("Currently loaded modules:\n");
print_srvconsole( " %-23.22s %-8.7s %-20.19s %-11.10s\n", print_srvconsole(" %-23.22s %-8.7s %-20.19s %-11.10s\n", "name", "version", "author", "status");
"name", "version", "author", "status");
int running = 0; int running = 0;
int modules = 0; int modules = 0;
@ -178,17 +164,15 @@ void amx_command(){
{ {
if ((*a).getStatusValue() == MODULE_LOADED) if ((*a).getStatusValue() == MODULE_LOADED)
++running; ++running;
++modules; ++modules;
print_srvconsole( " [%2d] %-23.22s %-8.7s %-20.19s %-11.10s\n", modules, print_srvconsole(" [%2d] %-23.22s %-8.7s %-20.19s %-11.10s\n", modules, (*a).getName(), (*a).getVersion(), (*a).getAuthor(), (*a).getStatus());
(*a).getName(), (*a).getVersion(), (*a).getAuthor() , (*a).getStatus() );
++a; ++a;
} }
print_srvconsole("%d modules, %d correct\n", modules, running); print_srvconsole("%d modules, %d correct\n", modules, running);
} else if (!strcmp(cmd, "gpl")) }
else if (!strcmp(cmd, "gpl"))
{ {
print_srvconsole("AMX Mod X\n"); print_srvconsole("AMX Mod X\n");
print_srvconsole("\n"); print_srvconsole("\n");
@ -245,11 +229,7 @@ void amx_command(){
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3A\x78\x78\x24\x40\x4E\x4E\x4D\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x5E\x3E\x3E\x3F\x3E\x3E\x3E\x3E\x3B\x3B\x3B\x3A\x3A\x3F\x3E\x3A\x2E\x2E\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2E\x45\x4D\x40\x45\x78\x5E\x33\x68\x33\x2B\n"); print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x3A\x78\x78\x24\x40\x4E\x4E\x4D\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x5E\x3E\x3E\x3F\x3E\x3E\x3E\x3E\x3B\x3B\x3B\x3A\x3A\x3F\x3E\x3A\x2E\x2E\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2E\x45\x4D\x40\x45\x78\x5E\x33\x68\x33\x2B\n");
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x24\x48\x45\x48\x78\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x4E\x40\x2B\x66\x33\x78\x20\x20\n"); print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x24\x48\x45\x48\x78\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x4E\x40\x2B\x66\x33\x78\x20\x20\n");
print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x2C\x20\x3A\x20\x20\n"); print_srvconsole("\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2B\x2C\x20\x3A\x20\x20\n");
} } else {
else
{
print_srvconsole("Usage: amxx < command > [ argument ]\n"); print_srvconsole("Usage: amxx < command > [ argument ]\n");
print_srvconsole("Commands:\n"); print_srvconsole("Commands:\n");
print_srvconsole(" version - display amxx version info\n"); print_srvconsole(" version - display amxx version info\n");
@ -260,11 +240,9 @@ void amx_command(){
print_srvconsole(" cmds - list commands registered by plugins\n"); print_srvconsole(" cmds - list commands registered by plugins\n");
print_srvconsole(" pause < plugin > - pause a running plugin\n"); print_srvconsole(" pause < plugin > - pause a running plugin\n");
print_srvconsole(" unpause < plugin > - unpause a previously paused plugin\n"); print_srvconsole(" unpause < plugin > - unpause a previously paused plugin\n");
} }
} }
void plugin_srvcmd() void plugin_srvcmd()
{ {
cell ret = 0; cell ret = 0;
@ -274,8 +252,7 @@ void plugin_srvcmd()
while (a) while (a)
{ {
if ( (*a).matchCommand( cmd ) && if ((*a).matchCommand(cmd) && (*a).getPlugin()->isExecutable((*a).getFunction()))
(*a).getPlugin()->isExecutable( (*a).getFunction() ) )
{ {
cell ret = executeForwards((*a).getFunction(), g_srvindex, (*a).getFlags(), (*a).getId()); cell ret = executeForwards((*a).getFunction(), g_srvindex, (*a).getFlags(), (*a).getId());
if (ret) break; if (ret) break;

View File

@ -38,13 +38,14 @@ const char* stristr(const char* str,const char* substr)
register char *prevloc = (char *)str; register char *prevloc = (char *)str;
register char *haystack = (char *)str; register char *haystack = (char *)str;
while (*haystack) { while (*haystack)
if (tolower(*haystack) == tolower(*needle)) { {
if (tolower(*haystack) == tolower(*needle))
{
haystack++; haystack++;
if (!*++needle) if (!*++needle)
return prevloc; return prevloc;
} } else {
else {
haystack = ++prevloc; haystack = ++prevloc;
needle = (char *)substr; needle = (char *)substr;
} }
@ -77,9 +78,12 @@ int set_amxstring(AMX *amx,cell amx_addr,const char *source,int max)
{ {
cell* dest = (cell *)(amx->base + (int)(((AMX_HEADER *)amx->base)->dat + amx_addr)); cell* dest = (cell *)(amx->base + (int)(((AMX_HEADER *)amx->base)->dat + amx_addr));
cell* start = dest; cell* start = dest;
while (max-- && *source) while (max-- && *source)
*dest++ = (cell)*source++; *dest++ = (cell)*source++;
*dest = 0; *dest = 0;
return dest - start; return dest - start;
} }
@ -89,9 +93,11 @@ char* get_amxstring(AMX *amx,cell amx_addr,int id, int& len)
register cell* source = (cell *)(amx->base + (int)(((AMX_HEADER *)amx->base)->dat + amx_addr)); register cell* source = (cell *)(amx->base + (int)(((AMX_HEADER *)amx->base)->dat + amx_addr));
register char* dest = buffor[id]; register char* dest = buffor[id];
char* start = dest; char* start = dest;
while ((*dest++=(char)(*source++)))
; while ((*dest++=(char)(*source++)));
len = --dest - start; len = --dest - start;
return start; return start;
} }
@ -107,26 +113,36 @@ char* parse_arg(char** line,int& state)
static char arg[3072]; static char arg[3072];
char* dest = arg; char* dest = arg;
state = 0; state = 0;
while(**line) {
if ( isspace(**line) ) { while (**line)
{
if (isspace(**line))
{
if (state == 1) if (state == 1)
break; break;
else if (!state) { else if (!state)
{
(*line)++; (*line)++;
continue; continue;
} }
} }
else if (state != 2) else if (state != 2)
state = 1; state = 1;
if (**line=='"') {
if (**line == '"')
{
(*line)++; (*line)++;
if (state == 2) if (state == 2)
break; break;
state = 2; state = 2;
continue; continue;
} }
*dest++ = *(*line)++; *dest++ = *(*line)++;
} }
*dest = '\0'; *dest = '\0';
return arg; return arg;
} }
@ -141,23 +157,32 @@ static cell AMX_NATIVE_CALL replace(AMX *amx, cell *params) /* 4 param */
int iWhat = amxstring_len(b); int iWhat = amxstring_len(b);
int iWith = amxstring_len(c); int iWith = amxstring_len(c);
int iPot = iMain + iWith - iWhat; int iPot = iMain + iWith - iWhat;
if (iPot>=params[2]){
if (iPot >= params[2])
{
amx_RaiseError(amx,AMX_ERR_NATIVE); amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0; return 0;
} }
char *d = buffor; char *d = buffor;
cell *x, *y, *z = a, *l = a; cell *x, *y, *z = a, *l = a;
int p = 0; int p = 0;
while(*a){
if (*a==*b){ while (*a)
{
if (*a == *b)
{
x = a + 1; x = a + 1;
y = b + 1; y = b + 1;
p = 1; p = 1;
if (!*y) break; if (!*y) break;
while(*x==*y){
while (*x == *y)
{
x++; y++; p++; x++; y++; p++;
if (!*y) break; if (!*y) break;
} }
if (!*y) break; if (!*y) break;
p = 0; p = 0;
*d++ = (char)*a++; *d++ = (char)*a++;
@ -165,7 +190,9 @@ static cell AMX_NATIVE_CALL replace(AMX *amx, cell *params) /* 4 param */
} }
*d++ = (char)*a++; *d++ = (char)*a++;
} }
if (p){
if (p)
{
while (*c) *d++ = (char)*c++; while (*c) *d++ = (char)*c++;
a += p; a += p;
while (*a) *d++ = (char)*a++; while (*a) *d++ = (char)*a++;
@ -175,6 +202,7 @@ static cell AMX_NATIVE_CALL replace(AMX *amx, cell *params) /* 4 param */
*z = 0; *z = 0;
return (z - l); return (z - l);
} }
return 0; return 0;
} }
@ -185,17 +213,20 @@ static cell AMX_NATIVE_CALL contain(AMX *amx, cell *params) /* 2 param */
register cell *c = b; register cell *c = b;
cell* str = b; cell* str = b;
cell* substr = a; cell* substr = a;
while (*c) {
if (*c == *a) { while (*c)
{
if (*c == *a)
{
c++; c++;
if (!*++a) if (!*++a)
return b - str; return b - str;
} } else {
else {
c = ++b; c = ++b;
a = substr; a = substr;
} }
} }
return -1; return -1;
} }
@ -206,17 +237,20 @@ static cell AMX_NATIVE_CALL containi(AMX *amx, cell *params) /* 2 param */
register cell *c = b; register cell *c = b;
cell* str = b; cell* str = b;
cell* substr = a; cell* substr = a;
while (*c) {
if (tolower(*c) == tolower(*a)) { while (*c)
{
if (tolower(*c) == tolower(*a))
{
c++; c++;
if (!*++a) if (!*++a)
return b - str; return b - str;
} } else {
else {
c = ++b; c = ++b;
a = substr; a = substr;
} }
} }
return -1; return -1;
} }
@ -255,6 +289,7 @@ static cell AMX_NATIVE_CALL str_to_float(AMX *amx, cell *params)
++str; ++str;
break; break;
} }
if (*str < '0' || *str > '9') if (*str < '0' || *str > '9')
{ {
REAL fl = neg ? -static_cast<REAL>(part1) : static_cast<REAL>(part1); REAL fl = neg ? -static_cast<REAL>(part1) : static_cast<REAL>(part1);
@ -269,6 +304,7 @@ static cell AMX_NATIVE_CALL str_to_float(AMX *amx, cell *params)
unsigned long part2 = 0; unsigned long part2 = 0;
unsigned long div = 1; unsigned long div = 1;
while (*str) while (*str)
{ {
if (*str < '0' || *str > '9') if (*str < '0' || *str > '9')
@ -281,8 +317,10 @@ static cell AMX_NATIVE_CALL str_to_float(AMX *amx, cell *params)
} }
REAL fl = static_cast<REAL>(part1) + (static_cast<REAL>(part2) / div); REAL fl = static_cast<REAL>(part1) + (static_cast<REAL>(part2) / div);
if (neg) if (neg)
fl = -fl; fl = -fl;
return amx_ftoc(fl); return amx_ftoc(fl);
} }
@ -299,17 +337,23 @@ static cell AMX_NATIVE_CALL add(AMX *amx, cell *params) /* 4 param */
cell *dest = get_amxaddr(amx, params[1]); cell *dest = get_amxaddr(amx, params[1]);
cell *start = dest; cell *start = dest;
int c = params[2], d = params[4]; int c = params[2], d = params[4];
while (*dest && c--) while (*dest && c--)
++dest; ++dest;
if (d){
if (d)
{
while (c-- && d-- && *src) while (c-- && d-- && *src)
*dest++ =* src++; *dest++ =* src++;
*dest = 0; *dest = 0;
return (dest - start); return (dest - start);
} }
while (c-- && *src) while (c-- && *src)
*dest++ =* src++; *dest++ =* src++;
*dest = 0; *dest = 0;
return (dest-start); return (dest-start);
} }
@ -319,9 +363,11 @@ static cell AMX_NATIVE_CALL copy(AMX *amx, cell *params) /* 4 param */
cell *dest = get_amxaddr(amx, params[1]); cell *dest = get_amxaddr(amx, params[1]);
cell *start = dest; cell *start = dest;
int c = params[2]; int c = params[2];
while (c-- && *src) while (c-- && *src)
*dest++ =* src++; *dest++ =* src++;
*dest = 0; *dest = 0;
return (dest - start); return (dest - start);
} }
@ -332,9 +378,11 @@ static cell AMX_NATIVE_CALL copyc(AMX *amx, cell *params) /* 4 param */
cell *start = dest; cell *start = dest;
int c = params[2]; int c = params[2];
cell ch = params[4]; cell ch = params[4];
while (c-- && *src && *src != ch) while (c-- && *src && *src != ch)
*dest++ =* src++; *dest++ =* src++;
*dest = 0; *dest = 0;
return (dest - start); return (dest - start);
} }
@ -343,8 +391,10 @@ static cell AMX_NATIVE_CALL setc(AMX *amx, cell *params) /* 4 param */
cell *src = get_amxaddr(amx, params[1]); cell *src = get_amxaddr(amx, params[1]);
int c = params[2]; int c = params[2];
cell ch = params[3]; cell ch = params[3];
while (c--) while (c--)
*src++ = ch; *src++ = ch;
return 1; return 1;
} }
@ -353,14 +403,19 @@ static cell AMX_NATIVE_CALL equal(AMX *amx, cell *params) /* 3 param */
cell *a = get_amxaddr(amx, params[1]); cell *a = get_amxaddr(amx, params[1]);
cell *b = get_amxaddr(amx, params[2]); cell *b = get_amxaddr(amx, params[2]);
int c = params[3]; int c = params[3];
if (c) {
if (c)
{
while (--c && *a && (*a == *b)) while (--c && *a && (*a == *b))
++a, ++b; ++a, ++b;
return (*a-*b)?0:1; return (*a-*b)?0:1;
} }
int ret; int ret;
while (!(ret = *a - *b) && *b) while (!(ret = *a - *b) && *b)
++a, ++b; ++a, ++b;
return ret ? 0 : 1; return ret ? 0 : 1;
} }
@ -369,18 +424,24 @@ static cell AMX_NATIVE_CALL equali(AMX *amx, cell *params) /* 3 param */
cell *a = get_amxaddr(amx, params[1]); cell *a = get_amxaddr(amx, params[1]);
cell *b = get_amxaddr(amx, params[2]); cell *b = get_amxaddr(amx, params[2]);
int f, l, c = params[3]; int f, l, c = params[3];
if (c) {
do { if (c)
{
do
{
f = tolower(*a++); f = tolower(*a++);
l = tolower(*b++); l = tolower(*b++);
} } while (--c && l && f && f == l);
while (--c &&l&&f&& f==l);
return (f - l) ? 0 : 1; return (f - l) ? 0 : 1;
} }
do {
do
{
f = tolower(*a++); f = tolower(*a++);
l = tolower(*b++); l = tolower(*b++);
} while (f && f == l); } while (f && f == l);
return (f - l) ? 0 : 1; return (f - l) ? 0 : 1;
} }
@ -396,13 +457,19 @@ static cell AMX_NATIVE_CALL parse(AMX *amx, cell *params) /* 3 param */
char* arg, *parse = get_amxstring(amx, params[1], 0, c); char* arg, *parse = get_amxstring(amx, params[1], 0, c);
cell *cptr; cell *cptr;
int state; int state;
while(*parse){
while (*parse)
{
arg = parse_arg(&parse,state); arg = parse_arg(&parse,state);
if (state){
if (state)
{
if (inum <= iarg) if (inum <= iarg)
return ((iarg - 2)>>1); return ((iarg - 2)>>1);
cptr = get_amxaddr(amx, params[iarg++]); cptr = get_amxaddr(amx, params[iarg++]);
c = *get_amxaddr(amx, params[iarg++]); c = *get_amxaddr(amx, params[iarg++]);
while (c-- && *arg) while (c-- && *arg)
*cptr++ = (cell)*arg++; *cptr++ = (cell)*arg++;
*cptr = 0; *cptr = 0;
@ -416,10 +483,13 @@ static cell AMX_NATIVE_CALL strtolower(AMX *amx, cell *params) /* 1 param */
{ {
cell *cptr = get_amxaddr(amx, params[1]); cell *cptr = get_amxaddr(amx, params[1]);
cell *begin = cptr; cell *begin = cptr;
while(*cptr){
while (*cptr)
{
*cptr = tolower(*cptr); *cptr = tolower(*cptr);
cptr++; cptr++;
} }
return cptr - begin; return cptr - begin;
} }
@ -427,10 +497,13 @@ static cell AMX_NATIVE_CALL strtoupper(AMX *amx, cell *params) /* 1 param */
{ {
cell *cptr = get_amxaddr(amx, params[1]); cell *cptr = get_amxaddr(amx, params[1]);
cell *begin = cptr; cell *begin = cptr;
while(*cptr){
while (*cptr)
{
*cptr = toupper(*cptr); *cptr = toupper(*cptr);
cptr++; cptr++;
} }
return cptr - begin; return cptr - begin;
} }
@ -464,7 +537,9 @@ char* fo_getargstr(AMX *amx, int swap, int pos)
static char buffer[2][3072]; static char buffer[2][3072];
char* b = buffer[swap]; char* b = buffer[swap];
int a = 0; int a = 0;
do {
do
{
value = src_value + a++ * sizeof(cell); value = src_value + a++ * sizeof(cell);
value = *(cell *)(data + (int)value); value = *(cell *)(data + (int)value);
*b++ = static_cast<char>(value); *b++ = static_cast<char>(value);
@ -480,31 +555,42 @@ char* format_arguments(AMX *amx, int parm,int& len)
char *ptr, *arg, *dest = *buffer; char *ptr, *arg, *dest = *buffer;
char *src = fo_getargstr(amx, 0, parm++); char *src = fo_getargstr(amx, 0, parm++);
int numparam = fo_numargs(amx); int numparam = fo_numargs(amx);
while(*src) {
if (*src=='%'&&*(src+1)) { while (*src)
{
if (*src == '%' && *(src + 1))
{
ptr = format; ptr = format;
*ptr++ = *src++; *ptr++ = *src++;
if (*src=='%'){
if (*src == '%')
{
*dest++ = *src++; *dest++ = *src++;
continue; continue;
} }
while (!isalpha(*ptr++=*src++))
; while (!isalpha(*ptr++ = *src++));
*ptr='\0'; *ptr='\0';
if (numparam < parm) continue; if (numparam < parm) continue;
arg = buffer[1]; arg = buffer[1];
switch(*(ptr-1)){
switch (*(ptr - 1))
{
case 's': sprintf(arg, format, fo_getargstr(amx, 1, parm++)); break; case 's': sprintf(arg, format, fo_getargstr(amx, 1, parm++)); break;
case 'f': case 'g': sprintf(arg, format, fo_getargfloat(amx, parm++)); break; case 'f': case 'g': sprintf(arg, format, fo_getargfloat(amx, parm++)); break;
default: sprintf(arg, format, fo_getargnum(amx, parm++)); default: sprintf(arg, format, fo_getargnum(amx, parm++));
} }
while (*arg) *dest++ = *arg++; while (*arg) *dest++ = *arg++;
continue; continue;
} }
*dest++ = *src++; *dest++ = *src++;
} }
*dest = '\0'; *dest = '\0';
len = dest - *buffer; len = dest - *buffer;
return *buffer; return *buffer;
} }
@ -531,6 +617,7 @@ static cell AMX_NATIVE_CALL amx_strtok(AMX *amx, cell *params)
char token = static_cast<char>(params[6]); char token = static_cast<char>(params[6]);
//trim //trim
int trim = params[7]; int trim = params[7];
for (i = 0; i < (unsigned int)len; i++) for (i = 0; i < (unsigned int)len; i++)
{ {
if (trim && !done_flag) if (trim && !done_flag)
@ -541,11 +628,13 @@ static cell AMX_NATIVE_CALL amx_strtok(AMX *amx, cell *params)
done_flag = true; done_flag = true;
} }
} }
if (!done_flag && string[i] == token) if (!done_flag && string[i] == token)
{ {
done_flag = true; done_flag = true;
i++; i++;
} }
if (done_flag) if (done_flag)
{ {
right[right_pos++] = string[i]; right[right_pos++] = string[i];
@ -553,12 +642,14 @@ static cell AMX_NATIVE_CALL amx_strtok(AMX *amx, cell *params)
left[left_pos++] = string[i]; left[left_pos++] = string[i];
} }
} }
right[right_pos] = 0; right[right_pos] = 0;
left[left_pos] = 0; left[left_pos] = 0;
set_amxstring(amx, params[2], left, leftMax); set_amxstring(amx, params[2], left, leftMax);
set_amxstring(amx, params[4], right, rightMax); set_amxstring(amx, params[4], right, rightMax);
delete [] left; delete [] left;
delete [] right; delete [] right;
return 1; return 1;
} }
@ -581,36 +672,53 @@ static cell AMX_NATIVE_CALL strbreak(AMX *amx, cell *params) /* 5 param */
int LeftMax = params[3]; int LeftMax = params[3];
int RightMax = params[5]; int RightMax = params[5];
for (i=0; i<(unsigned int)l; i++) { for (i = 0; i < (unsigned int)l; i++)
if (string[i] == '"' && !quote_flag) { {
if (string[i] == '"' && !quote_flag)
{
quote_flag = true; quote_flag = true;
} else if (string[i] == '"' && quote_flag) { }
else if (string[i] == '"' && quote_flag)
{
quote_flag = false; quote_flag = false;
} }
if (isspace(string[i]) && !quote_flag && !done_flag) {
if (isspace(string[i]) && !quote_flag && !done_flag)
{
done_flag = true; done_flag = true;
i++; i++;
} }
if (!done_flag && string[i]!='"') {
if (left_pos < LeftMax) { if (!done_flag && string[i]!='"')
{
if (left_pos < LeftMax)
{
left[left_pos] = string[i]; left[left_pos] = string[i];
if (left[left_pos] == '\'') {
if (left[left_pos] == '\'')
{
left[left_pos] = hold; left[left_pos] = hold;
} }
left_pos++; left_pos++;
} else { } else {
done_flag = true; done_flag = true;
} }
} else { } else {
if (right_pos < RightMax && string[i]!='"') { if (right_pos < RightMax && string[i]!='"')
{
right[right_pos] = string[i]; right[right_pos] = string[i];
if (right[right_pos] == '\'') {
if (right[right_pos] == '\'')
{
right[right_pos] = hold; right[right_pos] = hold;
} }
right_pos++; right_pos++;
} }
} }
} }
left[left_pos] = '\0'; left[left_pos] = '\0';
right[right_pos] = '\0'; right[right_pos] = '\0';
set_amxstring(amx, params[2], left, params[3]); set_amxstring(amx, params[2], left, params[3]);
@ -625,10 +733,13 @@ static cell AMX_NATIVE_CALL format_args(AMX *amx, cell *params)
{ {
int len; int len;
int pos = params[3]; int pos = params[3];
if (pos < 0){
if (pos < 0)
{
amx_RaiseError(amx, AMX_ERR_NATIVE); amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0; return 0;
} }
char* string = format_arguments(amx, pos, len); // indexed from 0 char* string = format_arguments(amx, pos, len); // indexed from 0
return set_amxstring(amx, params[1], string, params[2]); return set_amxstring(amx, params[1], string, params[2]);
} }
@ -657,9 +768,11 @@ static cell AMX_NATIVE_CALL amx_ucfirst(AMX *amx, cell *params)
{ {
int len = 0; int len = 0;
cell *str = get_amxaddr(amx, params[1]); cell *str = get_amxaddr(amx, params[1]);
if (!isalpha((char)str[0]) || !(str[0] & (1<<5))) if (!isalpha((char)str[0]) || !(str[0] & (1<<5)))
return 0; return 0;
str[0] &= ~(1<<5); str[0] &= ~(1<<5);
return 1; return 1;
} }
@ -679,6 +792,7 @@ static cell AMX_NATIVE_CALL amx_trim(AMX *amx, cell *params)
while (*cptr++) len++; while (*cptr++) len++;
int flag = 0, incr = 0; int flag = 0, incr = 0;
register int i = 0; register int i = 0;
for (i = len - 1; i >= 0; i--) for (i = len - 1; i >= 0; i--)
{ {
if (!isspace(asdf[i])) if (!isspace(asdf[i]))
@ -716,13 +830,16 @@ static cell AMX_NATIVE_CALL n_strcat(AMX *amx,cell *params)
cdest = get_amxaddr(amx, params[1]); cdest = get_amxaddr(amx, params[1]);
csrc = get_amxaddr(amx, params[2]); csrc = get_amxaddr(amx, params[2]);
int num = params[3]; int num = params[3];
while (*cdest && num) while (*cdest && num)
{ {
cdest++; cdest++;
num--; num--;
} }
if (!num) if (!num)
return 0; return 0;
while (*csrc && num) while (*csrc && num)
{ {
*cdest++ = *csrc++; *cdest++ = *csrc++;
@ -754,6 +871,7 @@ static cell AMX_NATIVE_CALL n_strfind(AMX *amx, cell *params)
bool found = false; bool found = false;
bool igcase = params[3] ? true : false; bool igcase = params[3] ? true : false;
if (igcase) if (igcase)
{ {
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
@ -767,8 +885,10 @@ static cell AMX_NATIVE_CALL n_strfind(AMX *amx, cell *params)
str[i] &= ~(1<<5); str[i] &= ~(1<<5);
} }
} }
if (params[4] > len) if (params[4] > len)
return -1; return -1;
char *pos = &(str[params[4]]); char *pos = &(str[params[4]]);
char *find = strstr(str, sub); char *find = strstr(str, sub);
@ -778,7 +898,8 @@ static cell AMX_NATIVE_CALL n_strfind(AMX *amx, cell *params)
return (find - str); return (find - str);
} }
AMX_NATIVE_INFO string_Natives[] = { AMX_NATIVE_INFO string_Natives[] =
{
{"add", add}, {"add", add},
{"contain", contain}, {"contain", contain},
{"containi", containi}, {"containi", containi},
@ -811,6 +932,5 @@ AMX_NATIVE_INFO string_Natives[] = {
{"strcmp", n_strcmp}, {"strcmp", n_strcmp},
{"str_to_float", str_to_float}, {"str_to_float", str_to_float},
{"float_to_str", float_to_str}, {"float_to_str", float_to_str},
{NULL, NULL } {NULL, NULL }
}; };

View File

@ -30,7 +30,6 @@
*/ */
#include <time.h> #include <time.h>
#include "amxmodx.h" #include "amxmodx.h"
#ifdef __linux__ #ifdef __linux__
@ -52,16 +51,21 @@ char *UTIL_VarArgs(const char *fmt, ...)
int UTIL_ReadFlags(const char* c) int UTIL_ReadFlags(const char* c)
{ {
int flags = 0; int flags = 0;
while (*c) flags |= ( 1 << ( *c++ - 'a' ) );
while (*c)
flags |= (1<<(*c++ - 'a'));
return flags; return flags;
} }
void UTIL_GetFlags(char* f, int a) void UTIL_GetFlags(char* f, int a)
{ {
for(int i='a';i<='z';++i){ for (int i = 'a'; i <= 'z'; ++i)
{
if (a & 1) *f++ = i; if (a & 1) *f++ = i;
a >>= 1; a >>= 1;
} }
*f = 0; *f = 0;
} }
@ -75,12 +79,14 @@ void UTIL_ShowMenu( edict_t* pEdict, int slots, int time, char *menu, int mlen )
if (!gmsgShowMenu) if (!gmsgShowMenu)
return; // some games don't support ShowMenu (Firearms) return; // some games don't support ShowMenu (Firearms)
while ( *n ) { while (*n)
{
a = mlen; a = mlen;
if (a > 175) a = 175; if (a > 175) a = 175;
mlen -= a; mlen -= a;
c = *(n+=a); c = *(n+=a);
*n = 0; *n = 0;
MESSAGE_BEGIN(MSG_ONE, gmsgShowMenu, NULL, pEdict); MESSAGE_BEGIN(MSG_ONE, gmsgShowMenu, NULL, pEdict);
WRITE_SHORT(slots); WRITE_SHORT(slots);
WRITE_CHAR(time); WRITE_CHAR(time);
@ -109,12 +115,14 @@ void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name)
char c = 0; char c = 0;
int a; int a;
while ( *n ) { while (*n)
{
a = mlen; a = mlen;
if (a > 175) a = 175; if (a > 175) a = 175;
mlen -= a; mlen -= a;
c = *(n += a); c = *(n += a);
*n = 0; *n = 0;
MESSAGE_BEGIN(MSG_ONE, gmsgMOTD, NULL, client); MESSAGE_BEGIN(MSG_ONE, gmsgMOTD, NULL, client);
WRITE_BYTE(c ? FALSE : TRUE); WRITE_BYTE(c ? FALSE : TRUE);
WRITE_STRING(motd); WRITE_STRING(motd);
@ -133,32 +141,42 @@ void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name)
void UTIL_IntToString(int value, char *output) void UTIL_IntToString(int value, char *output)
{ {
static const char *words[] = {"zero ","one ","two ","three ","four ", static const char *words[] =
{"zero ","one ","two ","three ","four ",
"five ", "six ","seven ","eight ","nine ","ten ", "five ", "six ","seven ","eight ","nine ","ten ",
"eleven ","twelve ","thirteen ","fourteen ","fifteen ", "eleven ","twelve ","thirteen ","fourteen ","fifteen ",
"sixteen ","seventeen ","eighteen ","nineteen ", "sixteen ","seventeen ","eighteen ","nineteen ",
"twenty ","thirty ","fourty ", "fifty ","sixty ", "twenty ","thirty ","fourty ", "fifty ","sixty ",
"seventy ","eighty ","ninety ", "seventy ","eighty ","ninety ",
"hundred ","thousand "}; "hundred ","thousand "};
*output = 0; *output = 0;
if (value < 0) value = -value; if (value < 0) value = -value;
int tho = value / 1000; int tho = value / 1000;
int aaa = 0; int aaa = 0;
if (tho){
if (tho)
{
aaa += sprintf(&output[aaa], words[tho]); aaa += sprintf(&output[aaa], words[tho]);
aaa += sprintf(&output[aaa], words[29]); aaa += sprintf(&output[aaa], words[29]);
value = value % 1000; value = value % 1000;
} }
int hun = value / 100; int hun = value / 100;
if (hun) {
if (hun)
{
aaa += sprintf(&output[aaa], words[hun]); aaa += sprintf(&output[aaa], words[hun]);
aaa += sprintf(&output[aaa], words[28]); aaa += sprintf(&output[aaa], words[28]);
value = value % 100; value = value % 100;
} }
int ten = value / 10; int ten = value / 10;
int unit = value % 10; int unit = value % 10;
if (ten) if (ten)
aaa += sprintf(&output[aaa], words[(ten > 1) ? (ten + 18) : (unit + 10)]); aaa += sprintf(&output[aaa], words[(ten > 1) ? (ten + 18) : (unit + 10)]);
if (ten != 1 && (unit || (!value && !hun && !tho))) if (ten != 1 && (unit || (!value && !hun && !tho)))
sprintf(&output[aaa], words[unit]); sprintf(&output[aaa], words[unit]);
} }
@ -168,27 +186,34 @@ char* UTIL_SplitHudMessage(const char *src)
static char message[512]; static char message[512];
short b = 0, d = 0, e = 0, c = -1; short b = 0, d = 0, e = 0, c = -1;
while ( src[ d ] && e < 480 ) { while (src[d] && e < 480)
if ( src[ d ] == ' ' ) { {
if (src[d] == ' ')
{
c = e; c = e;
} }
else if ( src[ d ] == '\n' ) { else if (src[d] == '\n')
{
c = -1; c = -1;
b = 0; b = 0;
} }
message[e++] = src[d++]; message[e++] = src[d++];
if ( ++b == 69 ) {
if ( c == -1 ) { if (++b == 69)
{
if (c == -1)
{
message[e++] = '\n'; message[e++] = '\n';
b = 0; b = 0;
} } else {
else {
message[c] = '\n'; message[c] = '\n';
b = e - c - 1; b = e - c - 1;
c = -1; c = -1;
} }
} }
} }
message[e] = 0; message[e] = 0;
return message; return message;
} }
@ -240,8 +265,10 @@ void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pM
WRITE_SHORT(FixedUnsigned16(textparms.fadeinTime, (1<<8))); WRITE_SHORT(FixedUnsigned16(textparms.fadeinTime, (1<<8)));
WRITE_SHORT(FixedUnsigned16(textparms.fadeoutTime, (1<<8))); WRITE_SHORT(FixedUnsigned16(textparms.fadeoutTime, (1<<8)));
WRITE_SHORT(FixedUnsigned16(textparms.holdTime, (1<<8))); WRITE_SHORT(FixedUnsigned16(textparms.holdTime, (1<<8)));
if (textparms.effect == 2) if (textparms.effect == 2)
WRITE_SHORT(FixedUnsigned16(textparms.fxTime, (1<<8))); WRITE_SHORT(FixedUnsigned16(textparms.fxTime, (1<<8)));
WRITE_STRING(pMessage); WRITE_STRING(pMessage);
MESSAGE_END(); MESSAGE_END();
} }
@ -255,10 +282,12 @@ void UTIL_ClientPrint( edict_t *pEntity, int msg_dest, char *msg )
char c = msg[190]; char c = msg[190];
msg[190] = 0; // truncate without checking with strlen() msg[190] = 0; // truncate without checking with strlen()
if (pEntity) if (pEntity)
MESSAGE_BEGIN(MSG_ONE, gmsgTextMsg, NULL, pEntity); MESSAGE_BEGIN(MSG_ONE, gmsgTextMsg, NULL, pEntity);
else else
MESSAGE_BEGIN(MSG_BROADCAST, gmsgTextMsg); MESSAGE_BEGIN(MSG_BROADCAST, gmsgTextMsg);
WRITE_BYTE(msg_dest); WRITE_BYTE(msg_dest);
WRITE_STRING(msg); WRITE_STRING(msg);
MESSAGE_END(); MESSAGE_END();

View File

@ -47,7 +47,6 @@ static cell AMX_NATIVE_CALL set_vaultdata(AMX *amx,cell *params)
static cell AMX_NATIVE_CALL get_vaultdata(AMX *amx, cell *params) static cell AMX_NATIVE_CALL get_vaultdata(AMX *amx, cell *params)
{ {
int iLen; int iLen;
const char* key = get_amxstring(amx, params[1], 0, iLen); const char* key = get_amxstring(amx, params[1], 0, iLen);
if (params[3]) if (params[3])
@ -69,11 +68,11 @@ static cell AMX_NATIVE_CALL remove_vaultdata(AMX *amx,cell *params)
static cell AMX_NATIVE_CALL vaultdata_exists(AMX *amx, cell *params) static cell AMX_NATIVE_CALL vaultdata_exists(AMX *amx, cell *params)
{ {
int iLen; int iLen;
return g_vault.exists(get_amxstring(amx, params[1], 0, iLen)) ? 1 : 0; return g_vault.exists(get_amxstring(amx, params[1], 0, iLen)) ? 1 : 0;
} }
AMX_NATIVE_INFO vault_Natives[] = { AMX_NATIVE_INFO vault_Natives[] =
{
{"set_vaultdata", set_vaultdata}, {"set_vaultdata", set_vaultdata},
{"get_vaultdata", get_vaultdata}, {"get_vaultdata", get_vaultdata},
{"remove_vaultdata", remove_vaultdata}, {"remove_vaultdata", remove_vaultdata},
@ -81,5 +80,3 @@ AMX_NATIVE_INFO vault_Natives[] = {
{"vaultdata_exists", vaultdata_exists}, {"vaultdata_exists", vaultdata_exists},
{0, 0} {0, 0}
}; };