Move some string functions from core to logic (bug 4406 part 4, r=fyren).
This commit is contained in:
parent
b5b002aa4b
commit
1cdacf69be
@ -49,6 +49,7 @@
|
|||||||
#include "ExtensionSys.h"
|
#include "ExtensionSys.h"
|
||||||
#include <sourcemod_version.h>
|
#include <sourcemod_version.h>
|
||||||
#include "ConsoleDetours.h"
|
#include "ConsoleDetours.h"
|
||||||
|
#include "logic_bridge.h"
|
||||||
|
|
||||||
PlayerManager g_Players;
|
PlayerManager g_Players;
|
||||||
bool g_OnMapStarted = false;
|
bool g_OnMapStarted = false;
|
||||||
@ -1300,7 +1301,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stristr(pTarget->GetName(), info->pattern) != NULL)
|
if (logicore.stristr(pTarget->GetName(), info->pattern) != NULL)
|
||||||
{
|
{
|
||||||
if (found_client)
|
if (found_client)
|
||||||
{
|
{
|
||||||
|
@ -35,6 +35,7 @@ files = [
|
|||||||
'MemoryUtils.cpp',
|
'MemoryUtils.cpp',
|
||||||
'smn_admin.cpp',
|
'smn_admin.cpp',
|
||||||
'smn_banning.cpp',
|
'smn_banning.cpp',
|
||||||
|
'stringutil.cpp',
|
||||||
'sm_crc32.cpp'
|
'sm_crc32.cpp'
|
||||||
]
|
]
|
||||||
if AMBuild.target['platform'] == 'windows':
|
if AMBuild.target['platform'] == 'windows':
|
||||||
|
@ -31,6 +31,7 @@ OBJECTS = \
|
|||||||
MemoryUtils.cpp \
|
MemoryUtils.cpp \
|
||||||
smn_admin.cpp \
|
smn_admin.cpp \
|
||||||
smn_banning.cpp \
|
smn_banning.cpp \
|
||||||
|
stringutil.cpp \
|
||||||
smn_players.cpp
|
smn_players.cpp
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "Profiler.h"
|
#include "Profiler.h"
|
||||||
#include "sm_crc32.h"
|
#include "sm_crc32.h"
|
||||||
#include "MemoryUtils.h"
|
#include "MemoryUtils.h"
|
||||||
|
#include "stringutil.h"
|
||||||
|
|
||||||
sm_core_t smcore;
|
sm_core_t smcore;
|
||||||
IHandleSys *handlesys;
|
IHandleSys *handlesys;
|
||||||
@ -63,7 +64,8 @@ static sm_logic_t logic =
|
|||||||
g_pThreader,
|
g_pThreader,
|
||||||
sm_profiler,
|
sm_profiler,
|
||||||
&g_MemUtils,
|
&g_MemUtils,
|
||||||
UTIL_CRC32
|
UTIL_CRC32,
|
||||||
|
stristr
|
||||||
};
|
};
|
||||||
|
|
||||||
static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
|
static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
|
||||||
|
@ -42,7 +42,7 @@ using namespace SourceMod;
|
|||||||
* Add 1 to the RHS of this expression to bump the intercom file
|
* Add 1 to the RHS of this expression to bump the intercom file
|
||||||
* This is to prevent mismatching core/logic binaries
|
* This is to prevent mismatching core/logic binaries
|
||||||
*/
|
*/
|
||||||
#define SM_LOGIC_MAGIC (0x0F47C0DE - 8)
|
#define SM_LOGIC_MAGIC (0x0F47C0DE - 9)
|
||||||
|
|
||||||
#if defined SM_LOGIC
|
#if defined SM_LOGIC
|
||||||
class IVEngineServer
|
class IVEngineServer
|
||||||
@ -118,6 +118,7 @@ struct sm_logic_t
|
|||||||
IProfiler *profiler;
|
IProfiler *profiler;
|
||||||
IMemoryUtils *memutils;
|
IMemoryUtils *memutils;
|
||||||
unsigned int (*CRC32)(const void *, size_t);
|
unsigned int (*CRC32)(const void *, size_t);
|
||||||
|
const char *(*stristr)(const char *, const char *);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*LogicInitFunction)(const sm_core_t *core, sm_logic_t *logic);
|
typedef void (*LogicInitFunction)(const sm_core_t *core, sm_logic_t *logic);
|
||||||
|
67
core/logic/stringutil.cpp
Normal file
67
core/logic/stringutil.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/**
|
||||||
|
* vim: set ts=4 sw=4 tw=99 et :
|
||||||
|
* =============================================================================
|
||||||
|
* SourceMod
|
||||||
|
* Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved.
|
||||||
|
* =============================================================================
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||||
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||||
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||||
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||||
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||||
|
* this exception to all derivative works. AlliedModders LLC defines further
|
||||||
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||||
|
* or <http://www.sourcemod.net/license.php>.
|
||||||
|
*
|
||||||
|
* Version: $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include "stringutil.h"
|
||||||
|
|
||||||
|
const char *stristr(const char *str, const char *substr)
|
||||||
|
{
|
||||||
|
if (!*substr)
|
||||||
|
{
|
||||||
|
return ((char *)str);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *needle = (char *)substr;
|
||||||
|
char *prevloc = (char *)str;
|
||||||
|
char *haystack = (char *)str;
|
||||||
|
|
||||||
|
while (*haystack)
|
||||||
|
{
|
||||||
|
if (tolower(*haystack) == tolower(*needle))
|
||||||
|
{
|
||||||
|
haystack++;
|
||||||
|
if (!*++needle)
|
||||||
|
{
|
||||||
|
return prevloc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
haystack = ++prevloc;
|
||||||
|
needle = (char *)substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
38
core/logic/stringutil.h
Normal file
38
core/logic/stringutil.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* vim: set ts=4 sw=4 tw=99 et :
|
||||||
|
* =============================================================================
|
||||||
|
* SourceMod
|
||||||
|
* Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved.
|
||||||
|
* =============================================================================
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
||||||
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
||||||
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
||||||
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
||||||
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
||||||
|
* this exception to all derivative works. AlliedModders LLC defines further
|
||||||
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
||||||
|
* or <http://www.sourcemod.net/license.php>.
|
||||||
|
*
|
||||||
|
* Version: $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_
|
||||||
|
#define _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_
|
||||||
|
|
||||||
|
const char *stristr(const char *str, const char *substr);
|
||||||
|
|
||||||
|
#endif /* _INCLUDE_SOURCEMOD_COMMON_STRINGUTIL_H_ */
|
||||||
|
|
@ -57,6 +57,7 @@ IThreader *g_pThreader;
|
|||||||
ITextParsers *textparsers;
|
ITextParsers *textparsers;
|
||||||
SM_FN_CRC32 UTIL_CRC32;
|
SM_FN_CRC32 UTIL_CRC32;
|
||||||
IMemoryUtils *memutils;
|
IMemoryUtils *memutils;
|
||||||
|
sm_logic_t logicore;
|
||||||
|
|
||||||
class VEngineServer_Logic : public IVEngineServer_Logic
|
class VEngineServer_Logic : public IVEngineServer_Logic
|
||||||
{
|
{
|
||||||
@ -140,14 +141,12 @@ static sm_core_t core_bridge =
|
|||||||
|
|
||||||
void InitLogicBridge()
|
void InitLogicBridge()
|
||||||
{
|
{
|
||||||
sm_logic_t logic;
|
|
||||||
|
|
||||||
serverGlobals.universalTime = g_pUniversalTime;
|
serverGlobals.universalTime = g_pUniversalTime;
|
||||||
serverGlobals.frametime = &gpGlobals->frametime;
|
serverGlobals.frametime = &gpGlobals->frametime;
|
||||||
serverGlobals.interval_per_tick = &gpGlobals->interval_per_tick;
|
serverGlobals.interval_per_tick = &gpGlobals->interval_per_tick;
|
||||||
|
|
||||||
core_bridge.core_ident = g_pCoreIdent;
|
core_bridge.core_ident = g_pCoreIdent;
|
||||||
logic_init_fn(&core_bridge, &logic);
|
logic_init_fn(&core_bridge, &logicore);
|
||||||
|
|
||||||
/* Add SMGlobalClass instances */
|
/* Add SMGlobalClass instances */
|
||||||
SMGlobalClass* glob = SMGlobalClass::head;
|
SMGlobalClass* glob = SMGlobalClass::head;
|
||||||
@ -156,12 +155,12 @@ void InitLogicBridge()
|
|||||||
glob = glob->m_pGlobalClassNext;
|
glob = glob->m_pGlobalClassNext;
|
||||||
}
|
}
|
||||||
assert(glob->m_pGlobalClassNext == NULL);
|
assert(glob->m_pGlobalClassNext == NULL);
|
||||||
glob->m_pGlobalClassNext = logic.head;
|
glob->m_pGlobalClassNext = logicore.head;
|
||||||
|
|
||||||
g_pThreader = logic.threader;
|
g_pThreader = logicore.threader;
|
||||||
g_pSourcePawn2->SetProfiler(logic.profiler);
|
g_pSourcePawn2->SetProfiler(logicore.profiler);
|
||||||
UTIL_CRC32 = logic.CRC32;
|
UTIL_CRC32 = logicore.CRC32;
|
||||||
memutils = logic.memutils;
|
memutils = logicore.memutils;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StartLogicBridge(char *error, size_t maxlength)
|
bool StartLogicBridge(char *error, size_t maxlength)
|
||||||
|
@ -31,13 +31,18 @@
|
|||||||
#ifndef _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_
|
#ifndef _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_
|
||||||
#define _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_
|
#define _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_
|
||||||
|
|
||||||
|
#include "logic/intercom.h"
|
||||||
|
|
||||||
void InitLogicBridge();
|
void InitLogicBridge();
|
||||||
bool StartLogicBridge(char *error, size_t maxlength);
|
bool StartLogicBridge(char *error, size_t maxlength);
|
||||||
void ShutdownLogicBridge();
|
void ShutdownLogicBridge();
|
||||||
|
|
||||||
|
struct sm_logic_t;
|
||||||
|
|
||||||
typedef unsigned int (*SM_FN_CRC32)(const void *, size_t);
|
typedef unsigned int (*SM_FN_CRC32)(const void *, size_t);
|
||||||
|
|
||||||
extern SM_FN_CRC32 UTIL_CRC32;
|
extern SM_FN_CRC32 UTIL_CRC32;
|
||||||
|
extern sm_logic_t logicore;
|
||||||
|
|
||||||
#endif /* _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_ */
|
#endif /* _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_ */
|
||||||
|
|
||||||
|
@ -1274,37 +1274,6 @@ done:
|
|||||||
return (maxlen - llen - 1);
|
return (maxlen - llen - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *stristr(const char *str, const char *substr)
|
|
||||||
{
|
|
||||||
if (!*substr)
|
|
||||||
{
|
|
||||||
return ((char *)str);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *needle = (char *)substr;
|
|
||||||
char *prevloc = (char *)str;
|
|
||||||
char *haystack = (char *)str;
|
|
||||||
|
|
||||||
while (*haystack)
|
|
||||||
{
|
|
||||||
if (tolower(*haystack) == tolower(*needle))
|
|
||||||
{
|
|
||||||
haystack++;
|
|
||||||
if (!*++needle)
|
|
||||||
{
|
|
||||||
return prevloc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
haystack = ++prevloc;
|
|
||||||
needle = (char *)substr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int strncopy(char *dest, const char *src, size_t count)
|
unsigned int strncopy(char *dest, const char *src, size_t count)
|
||||||
{
|
{
|
||||||
if (!count)
|
if (!count)
|
||||||
|
@ -43,7 +43,6 @@ using namespace SourceMod;
|
|||||||
#define IS_STR_FILLED(var) (var[0] != '\0')
|
#define IS_STR_FILLED(var) (var[0] != '\0')
|
||||||
|
|
||||||
size_t atcprintf(char *buffer, size_t maxlen, const char *format, IPluginContext *pCtx, const cell_t *params, int *param);
|
size_t atcprintf(char *buffer, size_t maxlen, const char *format, IPluginContext *pCtx, const cell_t *params, int *param);
|
||||||
const char *stristr(const char *str, const char *substr);
|
|
||||||
unsigned int strncopy(char *dest, const char *src, size_t count);
|
unsigned int strncopy(char *dest, const char *src, size_t count);
|
||||||
bool gnprintf(char *buffer,
|
bool gnprintf(char *buffer,
|
||||||
size_t maxlen,
|
size_t maxlen,
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "sm_stringutil.h"
|
#include "sm_stringutil.h"
|
||||||
#include <ITextParsers.h>
|
#include <ITextParsers.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include "logic_bridge.h"
|
||||||
|
|
||||||
inline const char *_strstr(const char *str, const char *substr)
|
inline const char *_strstr(const char *str, const char *substr)
|
||||||
{
|
{
|
||||||
@ -68,7 +69,7 @@ static cell_t sm_contain(IPluginContext *pCtx, const cell_t *params)
|
|||||||
pCtx->LocalToString(params[1], &str);
|
pCtx->LocalToString(params[1], &str);
|
||||||
pCtx->LocalToString(params[2], &substr);
|
pCtx->LocalToString(params[2], &substr);
|
||||||
|
|
||||||
func = (params[3]) ? _strstr : stristr;
|
func = (params[3]) ? _strstr : logicore.stristr;
|
||||||
const char *pos = func(str, substr);
|
const char *pos = func(str, substr);
|
||||||
if (pos)
|
if (pos)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user