static cell_t sm_GetClientIP(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); } char buf[64], *ptr; strcpy(buf, pPlayer->GetIPAddress()); if (params[4] && (ptr = strchr(buf, ':'))) { *ptr = '\0'; } pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf); return 1; }
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); } }