示例#1
0
void ConsoleVariableType::SendValueToClient(int clientIndex, std::string value) {
	if(clientIndex < 1 || clientIndex > g_Interfaces.GlobalVarsInstance->maxClients) {
		throw ClientIndexOutOfRangeExceptionType(clientIndex, g_Interfaces.GlobalVarsInstance->maxClients);
	}

	char data[256];
	bf_write buffer(data, sizeof(data));

	buffer.WriteUBitLong(NET_SETCONVAR, NETMSG_BITS);
	buffer.WriteByte(1);
	buffer.WriteString(ConVarInstance->GetName());
	buffer.WriteString(value.c_str());

	IGamePlayer *gamePlayer = playerhelpers->GetGamePlayer(clientIndex);

	if(!gamePlayer->IsConnected()) {
		throw ClientNotConnectedExceptionType(clientIndex);
	}

	if(gamePlayer->IsFakeClient()) {
		throw ClientIsFakeExceptionType(clientIndex);
	}

	INetChannel *netchan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(clientIndex));
	
	if (netchan == NULL) {
		throw ClientDataNotAvailableExceptionType(clientIndex, "net_chan");
	}

	netchan->SendData(buffer);
}
bool BaseBuiltinVoteStyle::DoClientVote(int clients[], unsigned int num_clients, IBaseBuiltinVote *vote, IBuiltinVoteHandler *bvh)
{
	unsigned int totalPlayers = 0;
	int realClients[256+1];

	for (unsigned int i=0; i<num_clients;i++)
	{
		IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(clients[i]);

		CBaseBuiltinVotePlayer *player = GetVotePlayer(clients[i]);
		vote_states_t &states = player->states;

		if (!pPlayer || pPlayer->IsFakeClient() || !pPlayer->IsInGame())
		{
			states.vote = NULL;
			states.bvh = NULL;
			continue;
		}

		states.vote = vote;
		states.bvh = bvh;
		states.apiVers = SMINTERFACE_BUILTINVOTES_VERSION;

		realClients[totalPlayers++] = clients[i];
	}

	if (totalPlayers > 0)
	{
		vote->Display(realClients, totalPlayers);
		//SendDisplay(realClients, totalPlayers, vote);
		return true;
	} else {
		return false;
	}
}
示例#3
0
/**
 * @brief Called when a client is authorized.
 *
 * @param client		Index of the client.
 * @param authstring	His SteamID.
 */	
void Left4Downtown::OnClientAuthorized(int client, const char *authstring)
{
	/* 
		Credits to Scott "DS" Ehlert from the SourceMod Dev Team for providing me with
		this super-easy method of selective event broadcasting. If it wasn't for him,
		I'd be stuck with a bunch of nasty code -- i.e. my initial idea of a NET_SendPacket
		vcall(bitbuffers, serializing events, casting IPs to netadr_t etc.)
		/blog
	*/
	
	if (!g_AddonsEclipse.GetBool())
	{
		L4D_DEBUG_LOG("l4d2_addons_eclipse set to 0, skipping function");
		return;
	}
	
	IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
	if (pPlayer->IsFakeClient())
	{
		L4D_DEBUG_LOG("Fake client %d connected, ignoring...", client);
		return;
	}
	
	cell_t result = Pl_Continue;
	if (g_pFwdOnAddonsEclipseUpdate)
	{
		g_pFwdOnAddonsEclipseUpdate->PushCell(client);
		g_pFwdOnAddonsEclipseUpdate->Execute(&result);
		
		if(result == Pl_Handled)
		{
			L4D_DEBUG_LOG("L4D2_OnAddonsEclipseUpdate(%d) will be skipped", client);
			return;
		}
		L4D_DEBUG_LOG("L4D2_OnAddonsEclipseUpdate(%d) has been sent out...", client);
	}
	
	// Getting the client event listener
	INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(client));
	IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler());
	unsigned char *pBaseClient = reinterpret_cast<unsigned char *>(pClient) - 4;
	IGameEventListener2 *pClientListener = reinterpret_cast<IGameEventListener2 *>(pBaseClient);

	// Firing our event; it will tell the client to unload his addons
	IGameEvent *pEvent = gameeventmanager->CreateEvent("server_spawn");
	if (pEvent)
	{
		pEvent->SetString("address", "159.253.143.194:0");
        pEvent->SetString("mapname", STRING(gpGlobals->mapname));
		pClientListener->FireGameEvent(pEvent);
		
		L4D_DEBUG_LOG("Fired event for client %d", client);
	}

	// When done with event, must destroy it manually
	gameeventmanager->FreeEvent(pEvent);  
}
示例#4
0
DETOUR_DECL_MEMBER1(GetEventChangeAttributes, int, char const*, attribute)
{
	int index = gamehelpers->EntityToBCompatRef(reinterpret_cast<CBaseEntity *>(this));

	if (index > 0 && index <= playerhelpers->GetMaxClients())
	{
		IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index);
		if (pPlayer->IsConnected() && pPlayer->IsInGame() && !pPlayer->IsFakeClient())
		{
			return 0;
		}
	}

	return DETOUR_MEMBER_CALL(GetEventChangeAttributes)(attribute);
}
示例#5
0
static cell_t sm_IsClientFakeClient(IPluginContext *pCtx, const cell_t *params)
{
    int index = params[1];
    if ((index < 1) || (index > playerhelpers->GetMaxClients()))
    {
        return pCtx->ThrowNativeError("Client index %d is invalid", index);
    }

    IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index);
    if (!pPlayer->IsConnected())
    {
        return pCtx->ThrowNativeError("Client %d is not connected", index);
    }

    return (pPlayer->IsFakeClient()) ? 1 : 0;
}
示例#6
0
static cell_t KickClient(IPluginContext *pContext, const cell_t *params)
{
    int client = params[1];

    IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
    if (!pPlayer)
    {
        return pContext->ThrowNativeError("Client index %d is invalid", client);
    }
    else if (!pPlayer->IsConnected())
    {
        return pContext->ThrowNativeError("Client %d is not connected", client);
    }

    /* Ignore duplicate kicks */
    if (pPlayer->IsInKickQueue())
    {
        return 1;
    }

    g_pSM->SetGlobalTarget(client);

    char buffer[256];
    {
        DetectExceptions eh(pContext);
        g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2);
        if (eh.HasException())
            return 0;
    }

    if (pPlayer->IsFakeClient())
    {
        // Kick uses the kickid command for bots. It is already delayed
        // until the next frame unless someone flushes command buffer
        pPlayer->Kick(buffer);
        return 1;
    }

    gamehelpers->AddDelayedKick(client, pPlayer->GetUserId(), buffer);

    return 1;
}
示例#7
0
static void ReplicateConVar(ConVar *pConVar) {
	int maxClients = g_Interfaces.GlobalVarsInstance->maxClients;

	char data[256];
	bf_write buffer(data, sizeof(data));

	buffer.WriteUBitLong(NET_SETCONVAR, NETMSG_BITS);
	buffer.WriteByte(1);
	buffer.WriteString(pConVar->GetName());
	buffer.WriteString(pConVar->GetString());

	for(int i = 1; i <= maxClients; i++) {
		IGamePlayer *gamePlayer = playerhelpers->GetGamePlayer(i);

		if (gamePlayer->IsConnected() && gamePlayer->IsInGame() && !gamePlayer->IsFakeClient()) {
			if (INetChannel *netchan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(i)))
				netchan->SendData(buffer);
		}
	}
}
示例#8
0
static cell_t SteamIdToLocal(IPluginContext *pCtx, int index, AuthIdType authType, cell_t local_addr, size_t bytes, bool validate)
{
    pCtx->StringToLocal(local_addr, bytes, "STEAM_ID_STOP_IGNORING_RETVALS");

    if ((index < 1) || (index > playerhelpers->GetMaxClients()))
    {
        return pCtx->ThrowNativeError("Client index %d is invalid", index);
    }

    IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index);
    if (!pPlayer->IsConnected())
    {
        return pCtx->ThrowNativeError("Client %d is not connected", index);
    }

    const char *authstr;

    switch (authType)
    {
    case AuthIdType::Engine:
        authstr = pPlayer->GetAuthString(validate);
        if (!authstr || authstr[0] == '\0')
        {
            return 0;
        }

        pCtx->StringToLocal(local_addr, bytes, authstr);
        break;
    case AuthIdType::Steam2:
        authstr = pPlayer->GetSteam2Id(validate);
        if (!authstr || authstr[0] == '\0')
        {
            return 0;
        }

        pCtx->StringToLocal(local_addr, bytes, authstr);
        break;
    case AuthIdType::Steam3:
        authstr = pPlayer->GetSteam3Id(validate);
        if (!authstr || authstr[0] == '\0')
        {
            return 0;
        }

        pCtx->StringToLocal(local_addr, bytes, authstr);
        break;

    case AuthIdType::SteamId64:
    {
        if (pPlayer->IsFakeClient() || gamehelpers->IsLANServer())
        {
            return 0;
        }

        uint64_t steamId = pPlayer->GetSteamId64(validate);
        if (steamId == 0)
        {
            return 0;
        }

        char szAuth[64];
        snprintf(szAuth, sizeof(szAuth), "%" PRIu64, steamId);

        pCtx->StringToLocal(local_addr, bytes, szAuth);
    }
    break;
    }

    return 1;
}
示例#9
0
static cell_t _ShowActivity2(IPluginContext *pContext,
                             const cell_t *params,
                             const char *tag,
                             cell_t fmt_param)
{
    char message[255];
    char buffer[255];
    int value = bridge->GetActivityFlags();
    unsigned int replyto = playerhelpers->GetReplyTo();
    int client = params[1];

    const char *name = "Console";
    const char *sign = "ADMIN";
    if (client != 0)
    {
        IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
        if (!pPlayer || !pPlayer->IsConnected())
        {
            return pContext->ThrowNativeError("Client index %d is invalid", client);
        }
        name = pPlayer->GetName();
        AdminId id = pPlayer->GetAdminId();
        if (id == INVALID_ADMIN_ID
                || !adminsys->GetAdminFlag(id, Admin_Generic, Access_Effective))
        {
            sign = "PLAYER";
        }

        g_pSM->SetGlobalTarget(client);
        {
            DetectExceptions eh(pContext);
            g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
            if (eh.HasException())
                return 0;
        }

        /* We don't display directly to the console because the chat text
        * simply gets added to the console, so we don't want it to print
        * twice.
        */
        g_pSM->Format(message, sizeof(message), "%s%s", tag, buffer);
        gamehelpers->TextMsg(client, TEXTMSG_DEST_CHAT, message);
    }
    else
    {
        g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
        {
            DetectExceptions eh(pContext);
            g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
            if (eh.HasException())
                return 0;
        }

        g_pSM->Format(message, sizeof(message), "%s%s\n", tag, buffer);
        bridge->ConPrint(message);
    }

    if (value == kActivityNone)
    {
        return 1;
    }

    int maxClients = playerhelpers->GetMaxClients();
    for (int i = 1; i <= maxClients; i++)
    {
        IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i);
        if (!pPlayer->IsInGame()
                || pPlayer->IsFakeClient()
                || i == client)
        {
            continue;
        }
        AdminId id = pPlayer->GetAdminId();
        g_pSM->SetGlobalTarget(i);
        if (id == INVALID_ADMIN_ID
                || !adminsys->GetAdminFlag(id, Admin_Generic, Access_Effective))
        {
            /* Treat this as a normal user */
            if ((value & kActivityNonAdmins) || (value & kActivityNonAdminsNames))
            {
                const char *newsign = sign;
                if ((value & kActivityNonAdminsNames))
                {
                    newsign = name;
                }

                {
                    DetectExceptions eh(pContext);
                    g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
                    if (eh.HasException())
                        return 0;
                }

                g_pSM->Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
                gamehelpers->TextMsg(i, TEXTMSG_DEST_CHAT, message);
            }
        }
        else
        {
            /* Treat this as an admin user */
            bool is_root = adminsys->GetAdminFlag(id, Admin_Root, Access_Effective);
            if ((value & kActivityAdmins)
                    || (value & kActivityAdminsNames)
                    || ((value & kActivityRootNames) && is_root))
            {
                const char *newsign = sign;
                if ((value & kActivityAdminsNames) || ((value & kActivityRootNames) && is_root))
                {
                    newsign = name;
                }

                {
                    DetectExceptions eh(pContext);
                    g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
                    if (eh.HasException())
                        return 0;
                }

                g_pSM->Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
                gamehelpers->TextMsg(i, TEXTMSG_DEST_CHAT, message);
            }
        }
    }

    return 1;
}