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; } gamehelpers->AddDelayedKick(client, pPlayer->GetUserId(), buffer); return 1; }
static cell_t GetClientUserId(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); } if (!pPlayer->IsConnected()) { return pContext->ThrowNativeError("Client %d is not connected", client); } return pPlayer->GetUserId(); }
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; }
void TopMenu::UpdateClientRoot(int client, IGamePlayer *pGamePlayer) { topmenu_player_t *pClient = &m_clients[client]; IGamePlayer *pPlayer = pGamePlayer ? pGamePlayer : playerhelpers->GetGamePlayer(client); /* Determine if an update is necessary */ bool is_update_needed = false; if (pClient->menu_serial != m_SerialNo) { is_update_needed = true; } else if (pPlayer->GetUserId() != pClient->user_id) { is_update_needed = true; } /* If no update is needed at the root level, just leave now */ if (!is_update_needed) { return; } /* First we need to flush the cache... */ TearDownClient(pClient); /* Now, rebuild the category list, but don't create menus */ if (m_Categories.size() == 0) { pClient->cat_count = 0; pClient->cats = NULL; } else { pClient->cat_count = (unsigned int)m_Categories.size(); pClient->cats = new topmenu_player_category_t[pClient->cat_count]; memset(pClient->cats, 0, sizeof(topmenu_player_category_t) * pClient->cat_count); } /* Re-sort the root categories if needed */ SortCategoriesIfNeeded(); /* Build the root menu */ IBaseMenu *root_menu = menus->GetDefaultStyle()->CreateMenu(this, myself->GetIdentity()); /* Add the sorted items */ for (size_t i = 0; i < m_SortedCats.size(); i++) { if (m_Categories[m_SortedCats[i]]->obj_list.size() == 0) { continue; } root_menu->AppendItem(m_Categories[m_SortedCats[i]]->obj->name, ItemDrawInfo("")); } /* Now we need to handle un-sorted items. This is slightly trickier, as we need to * pre-render each category name, and cache those names. Phew! */ if (m_UnsortedCats.size()) { obj_by_name_t *item_list = new obj_by_name_t[m_UnsortedCats.size()]; for (size_t i = 0; i < m_UnsortedCats.size(); i++) { obj_by_name_t *temp_obj = &item_list[i]; topmenu_object_t *obj = m_Categories[m_UnsortedCats[i]]->obj; obj->callbacks->OnTopMenuDisplayOption(this, client, obj->object_id, temp_obj->name, sizeof(temp_obj->name)); temp_obj->obj_index = m_UnsortedCats[i]; } /* Sort our temp list */ qsort(item_list, m_UnsortedCats.size(), sizeof(obj_by_name_t), _SortObjectNamesDescending); /* Add the new sorted categories */ for (size_t i = 0; i < m_UnsortedCats.size(); i++) { if (m_Categories[item_list[i].obj_index]->obj_list.size() == 0) { continue; } root_menu->AppendItem(m_Categories[item_list[i].obj_index]->obj->name, ItemDrawInfo("")); } delete [] item_list; } /* Set the menu's title */ if (m_bCacheTitles) { char renderbuf[128]; m_pTitle->OnTopMenuDisplayTitle(this, client, 0, renderbuf, sizeof(renderbuf)); root_menu->SetDefaultTitle(renderbuf); } /* The client is now fully updated */ pClient->root = root_menu; pClient->user_id = pPlayer->GetUserId(); pClient->menu_serial = m_SerialNo; pClient->last_position = 0; pClient->last_category = 0; pClient->last_root_pos = 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); } }