Пример #1
0
void CookieManager::OnClientDisconnecting(int client)
{
    connected[client] = false;
    statsLoaded[client] = false;

    SourceHook::List<CookieData *>::iterator _iter;

    CookieData *current;

    _iter = clientData[client].begin();

    while (_iter != clientData[client].end())
    {
        current = (CookieData *)*_iter;

        if (!current->changed)
        {
            current->parent->data[client] = NULL;
            delete current;
            _iter = clientData[client].erase(_iter);
            continue;
        }

        /* Save this cookie to the database */
        IGamePlayer *player = playerhelpers->GetGamePlayer(client);

        if (player == NULL)
        {
            /* panic! */
            return;
        }

        int dbId = current->parent->dbid;

        if (dbId == -1)
        {
            /* Insert/Find Query must be still running or failed. */
            return;
        }

        TQueryOp *op = new TQueryOp(Query_InsertData, client);

        strcpy(op->m_params.steamId, player->GetAuthString());
        op->m_params.cookieId = dbId;
        op->m_params.data = current;

        g_ClientPrefs.AddQueryToQueue(op);

        current->parent->data[client] = NULL;


        /* We don't delete here, it will be removed when the query is completed */

        _iter = clientData[client].erase(_iter);
    }
}
Пример #2
0
size_t IsAuthIdConnected(char *authID)
{
	IGamePlayer *player;
	const char *authString;
	
	for (int playerIndex = playerhelpers->GetMaxClients()+1; --playerIndex > 0;)
	{
		player = playerhelpers->GetGamePlayer(playerIndex);
		if (player == NULL || !player->IsAuthorized())
		{
			continue;
		}
		
		if (!strcmp(player->GetAuthString(), authID)
			|| !strcmp(player->GetSteam2Id(), authID)
			|| !strcmp(player->GetSteam3Id(), authID)
			)
		{
			return playerIndex;
		}
	}

	return 0;
}
Пример #3
0
		void Line(std::string &line, const dlib::incoming_things& incoming, dlib::outgoing_things& outgoing)
		{
			size_t posStart, posEnd, posTemp;

			// Search for "gets"
			for (posStart = line.find("ec::GET["); posStart != std::string::npos; posStart = line.find("ec::GET["))
			{
				std::string get = &line[posStart+8];
				posEnd = get.find(']');

				get = get.substr(0, posEnd);

				std::string result = incoming.queries[get];
				if (result.empty())
					result = "Unknown GET[" + get + ']';

				// Delete functioncall
				line.erase(posStart, posEnd+9);
				line.insert(posStart, result);
			}

			// Now interpret all functions
			for (posStart = line.find("ec::"); posStart != std::string::npos; posStart = line.find("ec::"))
			{
				std::vector<std::string> params;
				std::string function = &line[posStart+4], arg, result;

				posTemp = function.find('(');
				posEnd = function.find(')');

				arg = function.substr(posTemp+1, posEnd-posTemp-1);
				if (line.find(";") != std::string::npos)
					params = dlib::split(arg.c_str(), ";");
				else
					params.emplace_back(arg);
				function = function.substr(0, posTemp);

				if (function == "GetMapName")
				{
					result = gamehelpers->GetCurrentMap();
				}
				else if (function == "GetGameFolder")
				{
					result = g_pSM->GetGameFolderName();
				}
				else if (function == "GetHTMLFormatedPlayerInfo")
				{
					IGamePlayer *player = Helper::GetPlayerByIP(incoming.foreign_ip);
					if (player)
					{
						result = "<b>" + std::string(player->GetName()) + "</b>";
						result += "<br/>IP: ";
						result += player->GetIPAddress();
						result += "<br/>Auth:";
						result += player->GetAuthString();
						result += "<br/>Steam:";
						result += player->GetSteamAccountID();

						AdminId adminID = player->GetAdminId();
						if (adminID != INVALID_ADMIN_ID)
							result += "<br/>You are an admin";
						else
							result += "<br/>You are no admin";
					}
					else
					{
						result = "You are not connected!";
					}
				}
				else if (function == "GetNavHidingSpots")
				{
					if (Navigation::gNavMesh)
						result = dlib::cast_to_string(Navigation::gHidingSpotsCount);
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavAreas")
				{
					if (Navigation::gNavMesh && Navigation::gNavMesh->GetAreas())
						result = dlib::cast_to_string(Navigation::gNavMesh->GetAreas()->Size());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavPlaces")
				{
					if (Navigation::gNavMesh && Navigation::gNavMesh->GetPlaces())
						result = dlib::cast_to_string(Navigation::gNavMesh->GetPlaces()->Size());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavLadders")
				{
					if (Navigation::gNavMesh && Navigation::gNavMesh->GetLadders())
						result = dlib::cast_to_string(Navigation::gNavMesh->GetLadders()->Size());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavMagicNumber")
				{
					if (Navigation::gNavMesh)
						result = dlib::cast_to_string(Navigation::gNavMesh->GetMagicNumber());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavSaveBSPSize")
				{
					if (Navigation::gNavMesh)
						result = dlib::cast_to_string(Navigation::gNavMesh->GetSaveBSPSize());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavVersion")
				{
					if (Navigation::gNavMesh)
						result = dlib::cast_to_string(Navigation::gNavMesh->GetVersion());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "GetNavSubVersion")
				{
					if (Navigation::gNavMesh)
						result = dlib::cast_to_string(Navigation::gNavMesh->GetSubVersion());
					else
						result = "Navigation not loaded.";
				}
				else if (function == "IsLANServer")
				{
					result = gamehelpers->IsLANServer() ? "true" : "false";
				}
				else if (function == "GetMaxClients")
				{
					result = dlib::cast_to_string(playerhelpers->GetMaxClients());
				}
				else if (function == "GetPlayerCount")
				{
					result = dlib::cast_to_string(playerhelpers->GetNumPlayers());
				}
				else if (function == "GetEntityClassname")
				{
					if (params.size() == 1)
					{
						CBaseEntity *entity = gamehelpers->ReferenceToEntity(dlib::string_cast<int>(params.at(0)));
						if (entity)
							result = gamehelpers->GetEntityClassname(entity);
						else
							result = "Entity(" + params.at(0) + ") is invalid!";
					}
					else
					{
						result = "Usage:GetEntityClassname(entity)";
					}
				}
				else if (function == "ServerCommand")
				{
					if (params.size() == 1)
					{
						gamehelpers->ServerCommand(params.at(0).append("\n").c_str());
						result = "";
					}
					else
					{
						result = "Usage:ServerCommand(COMMAND)";
					}
				}
				else if (function == "ReadFile")
				{
					if (params.size() == 1)
					{
						result = HTTP::ReadFile(lastFilePath.substr(0, lastFilePath.find_last_of('/')+1) + params.at(0), incoming, outgoing);
					}
					else
					{
						result = "Usage:ReadFile(filename)";
					}
				}
				else if (function == "MostRecentVersion")
				{
					std::string newVersion;

					newVersion = LGN::get_most_recent_version();
					if (!newVersion.empty())
					{
						result = newVersion;
					}
					else
					{
						result = "Unable to receive the most recent version";
					}
				}
				else if (function == "CurrentVersion")
				{
					result = SMEXT_CONF_VERSION;
				}
				else
				{
					IGamePlayer *player = Helper::GetPlayerByIP(incoming.foreign_ip);
					if (player)
						ForwardFunction(player->GetUserId(), function, arg, result);
					else
						ForwardFunction(0, function, arg, result);
				}

				// Delete functioncallname
				line.erase(posStart, posEnd+5);

				// Insert the result
				line.insert(posStart, result);
			}
		}
Пример #4
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;
}