コード例 #1
0
ファイル: datastructs.cpp プロジェクト: Chuvi-w/amxmodx
// native ArraySwap(Array:which, item1, item2);
static cell AMX_NATIVE_CALL ArraySwap(AMX* amx, cell* params)
{
	CellArray* vec = HandleToVector(amx, params[1]);
	
	if (vec == NULL)
	{
		return 0;
	}

	size_t idx1 = (size_t)params[2];
	size_t idx2 = (size_t)params[3];

	if (idx1 >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx1, vec->size());
		return 0;
	}

	if (idx2 >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx2, vec->size());
		return 0;
	}

	vec->swap(idx1, idx2);

	return 1;
}
コード例 #2
0
ファイル: smn_adt_array.cpp プロジェクト: MercureS/sourcemod
static cell_t SwapArrayItems(IPluginContext *pContext, const cell_t *params)
{
	CellArray *array;
	HandleError err;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) 
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
	}

	size_t idx1 = (size_t)params[2];
	size_t idx2 = (size_t)params[3];
	if (idx1 >= array->size())
	{
		return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx1, array->size());
	}
	if (idx2 >= array->size())
	{
		return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx2, array->size());
	}

	array->swap(idx1, idx2);

	return 1;
}
コード例 #3
0
ファイル: smn_adt_stack.cpp プロジェクト: asceth/synapi
static cell_t PopStackString(IPluginContext *pContext, const cell_t *params)
{
	HandleError err;
	CellArray *array;
	size_t idx, numWritten;
	cell_t *blk, *pWritten;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) 
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
	}

	if (array->size() == 0)
	{
		return 0;
	}

	idx = array->size() - 1;
	blk = array->at(idx);
	pContext->StringToLocalUTF8(params[2], params[3], (char *)blk, &numWritten);
	pContext->LocalToPhysAddr(params[4], &pWritten);
	*pWritten = (cell_t)numWritten;
	array->remove(idx);

	return 1;
}
コード例 #4
0
ファイル: datastructs.cpp プロジェクト: Javivi/amxmodx
// native ArraySetString(Array:which, item, const input[]);
static cell AMX_NATIVE_CALL ArraySetString(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	size_t idx = (size_t)params[2];

	if (idx >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
		return 0;
	}

	cell *blk = vec->at(idx);

	int len;
	char *str = get_amxstring(amx, params[3], 0, len);

	return strncopy(blk, str, ke::Min((size_t)len + 1, vec->blocksize()));
}
コード例 #5
0
ファイル: datastructs.cpp プロジェクト: Chuvi-w/amxmodx
// native ArrayGetArray(Array:which, item, any:output[], size = -1);
static cell AMX_NATIVE_CALL ArrayGetArray(AMX* amx, cell* params)
{
	CellArray* vec = HandleToVector(amx, params[1]);

	if (vec == NULL)
	{
		return 0;
	}

	size_t idx = (size_t)params[2];

	if (idx >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
		return 0;
	}

	cell *blk = vec->at(idx);
	size_t indexes = vec->blocksize();

	if (*params / sizeof(cell) == 4)
	{
		if (params[4] != -1 && (size_t)params[4] <= vec->blocksize())
		{
			indexes = params[4];
		}
	}

	cell *addr = get_amxaddr(amx, params[3]);

	memcpy(addr, blk, sizeof(cell) * indexes);

	return indexes;
}
コード例 #6
0
ファイル: datastructs.cpp プロジェクト: Javivi/amxmodx
// native DoNotUse : ArrayGetStringHandle(Array : which, item);
static cell AMX_NATIVE_CALL ArrayGetStringHandle(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	size_t idx = (size_t)params[2];

	if (idx >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
		return 0;
	}

	cell* ptr = vec->at(idx);

	if (ptr == NULL)
	{
		return 0;
	}

	return reinterpret_cast<cell>(ptr);
}
コード例 #7
0
ファイル: datastructs.cpp プロジェクト: Javivi/amxmodx
// native ArraySetArray(Array:which, item, const any:input[], size =-1);
static cell AMX_NATIVE_CALL ArraySetArray(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	size_t idx = (size_t)params[2];

	if (idx >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
		return 0;
	}

	cell *blk = vec->at(idx);
	size_t indexes = vec->blocksize();

	if (*params / sizeof(cell) == 4)
	{
		if (params[4] != -1 && (size_t)params[4] <= vec->blocksize())
		{
			indexes = params[4];
		}
	}

	cell *addr = get_amxaddr(amx, params[3]);

	memcpy(blk, addr, sizeof(cell) * indexes);

	return indexes;
}
コード例 #8
0
ファイル: datastructs.cpp プロジェクト: Javivi/amxmodx
// native ArraySwap(Array:which, item1, item2);
static cell AMX_NATIVE_CALL ArraySwap(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	size_t idx1 = (size_t)params[2];
	size_t idx2 = (size_t)params[3];

	if (idx1 >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx1, vec->size());
		return 0;
	}

	if (idx2 >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx2, vec->size());
		return 0;
	}

	vec->swap(idx1, idx2);

	return 1;
}
コード例 #9
0
ファイル: smn_adt_array.cpp プロジェクト: MercureS/sourcemod
static cell_t GetArrayString(IPluginContext *pContext, const cell_t *params)
{
	CellArray *array;
	HandleError err;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) 
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
	}

	size_t idx = (size_t)params[2];
	if (idx >= array->size())
	{
		return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, array->size());
	}

	cell_t *blk = array->at(idx);
	size_t numWritten = 0;

	pContext->StringToLocalUTF8(params[3], params[4], (char *)blk, &numWritten);

	return numWritten;
}
コード例 #10
0
ファイル: smn_adt_array.cpp プロジェクト: MercureS/sourcemod
static cell_t SetArrayString(IPluginContext *pContext, const cell_t *params)
{
	CellArray *array;
	HandleError err;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) 
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
	}

	size_t idx = (size_t)params[2];
	if (idx >= array->size())
	{
		return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, array->size());
	}

	cell_t *blk = array->at(idx);

	char *str;
	pContext->LocalToString(params[3], &str);

	return smcore.strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t));
}
コード例 #11
0
ファイル: stackstructs.cpp プロジェクト: Chuvi-w/amxmodx
// native bool:PopStackArray(Stack:handle, any:buffer[], size=-1);
static cell AMX_NATIVE_CALL PopStackArray(AMX* amx, cell* params)
{
	CellArray* vec = HandleToVector(amx, params[1]);

	if (vec == NULL)
	{
		return 0;
	}

	if (vec->size() == 0)
	{
		return 0;
	}

	size_t idx = vec->size() - 1;
	cell *blk = vec->at(idx);
	size_t indexes = vec->blocksize();

	if (params[3] != -1 && (size_t)params[3] <= vec->blocksize())
	{
		indexes = params[3];
	}

	cell *addr = get_amxaddr(amx, params[2]);
	memcpy(addr, blk, indexes * sizeof(cell));

	vec->remove(idx);

	return 1;
}
コード例 #12
0
ファイル: stackstructs.cpp プロジェクト: Arkshine/amxmodx
// native bool:PopStackArray(Stack:handle, any:buffer[], size=-1);
static cell AMX_NATIVE_CALL PopStackArray(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	if (vec->size() == 0)
	{
		return 0;
	}

	size_t idx = vec->size() - 1;
	cell *blk = vec->at(idx);
	size_t indexes = vec->blocksize();

	if (params[3] != -1 && (size_t)params[3] <= vec->blocksize())
	{
		indexes = params[3];
	}

	cell *addr = get_amxaddr(amx, params[2]);
	memcpy(addr, blk, indexes * sizeof(cell));

	vec->remove(idx);

	return 1;
}
コード例 #13
0
ファイル: stackstructs.cpp プロジェクト: Arkshine/amxmodx
// native bool:PopStackString(Stack:handle, buffer[], maxlength, &written = 0);
static cell AMX_NATIVE_CALL PopStackString(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	if (vec->size() == 0)
	{
		return 0;
	}

	size_t idx = vec->size() - 1;
	cell *blk = vec->at(idx);

	int numWritten = set_amxstring_utf8(amx, params[2], blk, amxstring_len(blk), params[3]);
	*get_amxaddr(amx, params[4]) = numWritten;

	vec->remove(idx);

	return 1;
}
コード例 #14
0
ファイル: smn_adt_array.cpp プロジェクト: MercureS/sourcemod
static cell_t SetArrayArray(IPluginContext *pContext, const cell_t *params)
{
	CellArray *array;
	HandleError err;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) 
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
	}

	size_t idx = (size_t)params[2];
	if (idx >= array->size())
	{
		return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, array->size());
	}

	cell_t *blk = array->at(idx);
	size_t indexes = array->blocksize();
	if (params[4] != -1 && (size_t)params[4] <= array->blocksize())
	{
		indexes = params[4];
	}

	cell_t *addr;
	pContext->LocalToPhysAddr(params[3], &addr);

	memcpy(blk, addr, sizeof(cell_t) * indexes);

	return indexes;
}
コード例 #15
0
ファイル: datastructs.cpp プロジェクト: Javivi/amxmodx
// native any:ArrayGetCell(Array:which, item, block = 0, bool:asChar = false);
static cell AMX_NATIVE_CALL ArrayGetCell(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	size_t idx = (size_t)params[2];

	if (idx >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
		return 0;
	}

	cell *blk = vec->at(idx);

	if (*params / sizeof(cell) <= 2)
	{
		return *blk;
	}

	idx = (size_t)params[3];

	if (!params[4])
	{
		if (idx >= vec->blocksize())
		{
			LogError(amx, AMX_ERR_NATIVE, "Invalid block %d (blocksize: %d)", idx, vec->blocksize());
			return 0;
		}

		return blk[idx];
	}
	else 
	{
		if (idx >= vec->blocksize() * 4)
		{
			LogError(amx, AMX_ERR_NATIVE, "Invalid byte %d (blocksize: %d bytes)", idx, vec->blocksize() * 4);
			return 0;
		}

		return (cell)*((char *)blk + idx);
	}

	return 0;
}
コード例 #16
0
ファイル: smn_adt_array.cpp プロジェクト: DJLaca/sourcemod
static cell_t FindValueInArray(IPluginContext *pContext, const cell_t *params)
{
	CellArray *array;
	HandleError err;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array))
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
	}

	// the blocknumber is not guaranteed to always be passed
	size_t blocknumber = 0;
	if (params[0] >= 3)
	{
		blocknumber = (size_t) params[3];
	}

	if (blocknumber >= array->blocksize())
	{
		return pContext->ThrowNativeError("Invalid block %d (blocksize: %d)", blocknumber, array->blocksize());
	}

	for (unsigned int i = 0; i < array->size(); i++)
	{
		cell_t *blk = array->at(i);
		if (params[2] == blk[blocknumber])
		{
			return (cell_t) i;
		}
	}

	return -1;
}
コード例 #17
0
ファイル: datastructs.cpp プロジェクト: Javivi/amxmodx
// native ArrayPushArray(Array:which, const any:input[], size = -1);
static cell AMX_NATIVE_CALL ArrayPushArray(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	cell *blk = vec->push();

	if (!blk)
	{
		LogError(amx, AMX_ERR_NATIVE, "Failed to grow array");
		return 0;
	}

	cell *addr = get_amxaddr(amx, params[2]);
	size_t indexes = vec->blocksize();

	if (*params / sizeof(cell) == 3)
	{
		if (params[3] != -1 && (size_t)params[3] <= vec->blocksize())
		{
			indexes = params[3];
		}
	}

	memcpy(blk, addr, sizeof(cell) * indexes);

	return static_cast<cell>((vec->size() - 1));
}
コード例 #18
0
ファイル: datastructs.cpp プロジェクト: Chuvi-w/amxmodx
// native ArrayFindString(Array:which, const item[]);
static cell AMX_NATIVE_CALL ArrayFindString(AMX* amx, cell* params)
{
	CellArray* vec = HandleToVector(amx, params[1]);

	if (vec == NULL)
	{
		return -1;
	}

	cell *b, *a = get_amxaddr(amx, params[2]);
	size_t cellcount = vec->blocksize();
	size_t a_len = ke::Max(1, amxstring_len(a));
	size_t len = a_len > cellcount ? cellcount : a_len;

	for (size_t i = 0; i < vec->size(); i++)
	{	
		b = vec->at(i);

		if (fastcellcmp(a, b, len))
		{
			return static_cast<cell>(i);
		}
	}

	return -1;
}
コード例 #19
0
ファイル: smn_adt_array.cpp プロジェクト: MercureS/sourcemod
static cell_t FindStringInArray(IPluginContext *pContext, const cell_t *params)
{
	CellArray *array;
	HandleError err;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) 
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
	}

	char *str;
	pContext->LocalToString(params[2], &str);

	for (unsigned int i = 0; i < array->size(); i++)
	{
		const char *array_str = (const char *)array->at(i);
		if (strcmp(str, array_str) == 0)
		{
			return (cell_t) i;
		}
	}

	return -1;
}
コード例 #20
0
ファイル: smn_adt_array.cpp プロジェクト: MercureS/sourcemod
static cell_t PushArrayArray(IPluginContext *pContext, const cell_t *params)
{
	CellArray *array;
	HandleError err;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) 
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
	}

	cell_t *blk = array->push();
	if (!blk)
	{
		return pContext->ThrowNativeError("Failed to grow array");
	}

	cell_t *addr;
	pContext->LocalToPhysAddr(params[2], &addr);

	size_t indexes = array->blocksize();
	if (params[3] != -1 && (size_t)params[3] <= array->blocksize())
	{
		indexes = params[3];
	}

	memcpy(blk, addr, sizeof(cell_t) * indexes);

	return (cell_t)(array->size() - 1);
}
コード例 #21
0
ファイル: smn_adt_array.cpp プロジェクト: MercureS/sourcemod
static cell_t PushArrayString(IPluginContext *pContext, const cell_t *params)
{
	CellArray *array;
	HandleError err;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) 
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
	}

	cell_t *blk = array->push();
	if (!blk)
	{
		return pContext->ThrowNativeError("Failed to grow array");
	}

	char *str;
	pContext->LocalToString(params[2], &str);

	smcore.strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t));

	return (cell_t)(array->size() - 1);
}
コード例 #22
0
ファイル: datastructs.cpp プロジェクト: Javivi/amxmodx
// native ArrayFindString(Array:which, const item[]);
static cell AMX_NATIVE_CALL ArrayFindString(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return -1;
	}

	cell *b, *a = get_amxaddr(amx, params[2]);
	size_t cellcount = vec->blocksize();
	size_t a_len = ke::Max(1, amxstring_len(a));
	size_t len = a_len > cellcount ? cellcount : a_len;

	for (size_t i = 0; i < vec->size(); i++)
	{	
		b = vec->at(i);

		if (fastcellcmp(a, b, len))
		{
			return static_cast<cell>(i);
		}
	}

	return -1;
}
コード例 #23
0
ファイル: datastructs.cpp プロジェクト: Chuvi-w/amxmodx
// native ArraySetCell(Array:which, item, any:input, block = 0, bool:asChar = false);
static cell AMX_NATIVE_CALL ArraySetCell(AMX* amx, cell* params)
{
	CellArray* vec = HandleToVector(amx, params[1]);

	if (vec == NULL)
	{
		return 0;
	}

	size_t idx = (size_t)params[2];

	if (idx >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
		return 0;
	}

	cell *blk = vec->at(idx);
	idx = (size_t)params[4];

	if (*params / sizeof(cell) <= 3)
	{
		*blk = params[3];
		return 1;
	}

	if (params[5] == 0)
	{
		if (idx >= vec->blocksize())
		{
			LogError(amx, AMX_ERR_NATIVE, "Invalid block %d (blocksize: %d)", idx, vec->blocksize());
			return 0;
		}
		blk[idx] = params[3];
	}
	else 
	{
		if (idx >= vec->blocksize() * 4)
		{
			LogError(amx, AMX_ERR_NATIVE, "Invalid byte %d (blocksize: %d bytes)", idx, vec->blocksize() * 4);
			return 0;
		}
		*((char *)blk + idx) = (char)params[3];
	}

	return 1;
}
コード例 #24
0
ファイル: stackstructs.cpp プロジェクト: Arkshine/amxmodx
// native bool:PopStackCell(Stack:handle, &any:value, block = 0, bool:asChar = false);
static cell AMX_NATIVE_CALL PopStackCell(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	if (vec->size() == 0)
	{
		return 0;
	}

	cell *buffer = get_amxaddr(amx, params[2]);
	size_t index = params[3];

	cell *blk = vec->at(vec->size() - 1);
	size_t idx = (size_t)params[3];

	if (params[4] == 0)
	{
		if (idx >= vec->blocksize())
		{
			LogError(amx, AMX_ERR_NATIVE, "Invalid block %d (blocksize: %d)", idx, vec->blocksize());
			return 0;
		}

		*buffer = blk[idx];
	}
	else
	{
		if (idx >= vec->blocksize() * 4)
		{
			LogError(amx, AMX_ERR_NATIVE, "Invalid byte %d (blocksize: %d bytes)", idx, vec->blocksize() * 4);
			return 0;
		}

		*buffer = (cell)*((char *)blk + idx);
	}

	vec->remove(vec->size() - 1);

	return 1;
}
コード例 #25
0
ファイル: smn_players.cpp プロジェクト: dvarnai/simillimum
	bool ProcessCommandTarget(cmd_target_info_t *info)
	{
		List<SimpleMultiTargetFilter *>::iterator iter;

		for (iter = simpleMultis.begin(); iter != simpleMultis.end(); iter++) {
			SimpleMultiTargetFilter *smtf = (*iter);
			if (strcmp(smtf->pattern.c_str(), info->pattern) == 0) {
				CellArray *array = new CellArray(1);
				HandleSecurity sec(g_pCoreIdent, g_pCoreIdent);
				Handle_t hndl = handlesys->CreateHandleEx(htCellArray, array, &sec, NULL, NULL);
				AutoHandleCloner ahc(hndl, sec);
				if (ahc.getClone() == BAD_HANDLE) {
					smcore.LogError("[SM] Could not allocate a handle (%s, %d)", __FILE__, __LINE__);
					delete array;
					return false;
				}

				smtf->fun->PushString(info->pattern);
				smtf->fun->PushCell(ahc.getClone());
				cell_t result = 0;
				if (smtf->fun->Execute(&result) != SP_ERROR_NONE || !result)
					return false;

				IGamePlayer *pAdmin = info->admin
				                      ? playerhelpers->GetGamePlayer(info->admin)
				                      : NULL;

				info->num_targets = 0;
				for (size_t i = 0; i < array->size(); i++) {
					cell_t client = *array->at(i);
					IGamePlayer *pClient = playerhelpers->GetGamePlayer(client);
					if (pClient == NULL || !pClient->IsConnected())
						continue;
					if (playerhelpers->FilterCommandTarget(pAdmin, pClient, info->flags) ==
					    COMMAND_TARGET_VALID)
					{
						info->targets[info->num_targets++] = client;
						if (info->num_targets >= unsigned(info->max_targets))
							break;
					}
				}

				info->reason = info->num_targets > 0
				               ? COMMAND_TARGET_VALID
				               : COMMAND_TARGET_EMPTY_FILTER;
				if (info->num_targets) {
					smcore.strncopy(info->target_name, smtf->phrase.c_str(), info->target_name_maxlength);
					info->target_name_style = smtf->phraseIsML
					                          ? COMMAND_TARGETNAME_ML
					                          : COMMAND_TARGETNAME_RAW;
				}

				return true;
			}
		}

		return false;
	}
コード例 #26
0
ファイル: smn_adt_stack.cpp プロジェクト: asceth/synapi
static cell_t PopStackCell(IPluginContext *pContext, const cell_t *params)
{
	size_t idx;
	HandleError err;
	CellArray *array;
	cell_t *blk, *buffer;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) 
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
	}

	if (array->size() == 0)
	{
		return 0;
	}

	pContext->LocalToPhysAddr(params[2], &buffer);

	blk = array->at(array->size() - 1);
	idx = (size_t)params[3];

	if (params[4] == 0)
	{
		if (idx >= array->blocksize())
		{
			return pContext->ThrowNativeError("Invalid block %d (blocksize: %d)", idx, array->blocksize());
		}
		*buffer = blk[idx];
	}
	else
	{
		if (idx >= array->blocksize() * 4)
		{
			return pContext->ThrowNativeError("Invalid byte %d (blocksize: %d bytes)", idx, array->blocksize() * 4);
		}
		*buffer = (cell_t)*((char *)blk + idx);
	}

	array->remove(array->size() - 1);

	return 1;
}
コード例 #27
0
ファイル: stackstructs.cpp プロジェクト: Chuvi-w/amxmodx
// native bool:IsStackEmpty(Stack:handle);
static cell AMX_NATIVE_CALL IsStackEmpty(AMX* amx, cell* params)
{
	CellArray* vec = HandleToVector(amx, params[1]);

	if (vec == NULL)
	{
		return 0;
	}

	return vec->size() == 0;
}
コード例 #28
0
ファイル: datastructs.cpp プロジェクト: Chuvi-w/amxmodx
// native ArrayGetString(Array:which, item, output[], size);
static cell AMX_NATIVE_CALL ArrayGetString(AMX* amx, cell* params)
{
	CellArray* vec = HandleToVector(amx, params[1]);

	if (vec == NULL)
	{
		return 0;
	}

	size_t idx = (size_t)params[2];

	if (idx >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
		return 0;
	}

	cell *blk = vec->at(idx);
	return set_amxstring_utf8(amx, params[3], blk, amxstring_len(blk), params[4] + 1); // + EOS.
}
コード例 #29
0
ファイル: datastructs.cpp プロジェクト: Javivi/amxmodx
// native ArrayGetString(Array:which, item, output[], size);
static cell AMX_NATIVE_CALL ArrayGetString(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	size_t idx = (size_t)params[2];

	if (idx >= vec->size())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size());
		return 0;
	}

	cell *blk = vec->at(idx);
	return set_amxstring_utf8(amx, params[3], blk, amxstring_len(blk), params[4]);
}
コード例 #30
0
ファイル: datastructs.cpp プロジェクト: Javivi/amxmodx
// native ArraySize(Array:which);
static cell AMX_NATIVE_CALL ArraySize(AMX* amx, cell* params)
{
	CellArray* vec = ArrayHandles.lookup(params[1]);

	if (!vec)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]);
		return 0;
	}

	return vec->size();
}