//--------------------------------------------------------------------------------- // Purpose: Give everyone ammo //--------------------------------------------------------------------------------- void ManiWarmupTimer::GiveAllAmmo(void) { for (int i = 1; i <= max_players; i++) { player_t player; player.index = i; if (!FindPlayerByIndex(&player)) continue; if (player.is_dead) continue; if (player.player_info->IsHLTV()) continue; CBaseEntity *pPlayer = EdictToCBE(player.entity); CBaseCombatCharacter *pCombat = CBaseEntity_MyCombatCharacterPointer(pPlayer); CBaseCombatWeapon *pWeapon = CBaseCombatCharacter_Weapon_GetSlot(pCombat, 0); if (pWeapon) { int ammo_index; ammo_index = CBaseCombatWeapon_GetPrimaryAmmoType(pWeapon); CBaseCombatCharacter_GiveAmmo(pCombat, 999, ammo_index, true); ammo_index = CBaseCombatWeapon_GetSecondaryAmmoType(pWeapon); CBaseCombatCharacter_GiveAmmo(pCombat, 999, ammo_index, true); } pWeapon = CBaseCombatCharacter_Weapon_GetSlot(pCombat, 1); if (pWeapon) { int ammo_index; ammo_index = CBaseCombatWeapon_GetPrimaryAmmoType(pWeapon); CBaseCombatCharacter_GiveAmmo(pCombat, 999, ammo_index, true); ammo_index = CBaseCombatWeapon_GetSecondaryAmmoType(pWeapon); CBaseCombatCharacter_GiveAmmo(pCombat, 999, ammo_index, true); } } }
//--------------------------------------------------------------------------------- // Purpose: Round Started //--------------------------------------------------------------------------------- void ManiWarmupTimer::RoundStart(void) { if (war_mode) return; if (mani_warmup_timer.GetInt() == 0) return; if (!check_timer) return; if ((!gpManiGameType->IsGameType(MANI_GAME_CSS)) && (!gpManiGameType->IsGameType(MANI_GAME_CSGO))) return; for (int i = 1; i <= max_players; i++) { player_t player; player.index = i; if (!FindPlayerByIndex(&player)) continue; if (player.player_info->IsHLTV()) continue; CBaseEntity *pPlayer = EdictToCBE(player.entity); CBaseCombatCharacter *pCombat = CBaseEntity_MyCombatCharacterPointer(pPlayer); CBasePlayer *pBase = (CBasePlayer*) pPlayer; if (!pCombat) continue; for (int j = 0; j < MAX_WEAPONS_USED; j++) { CBaseCombatWeapon *pWeapon = CBaseCombatCharacter_Weapon_OwnsThisType(pCombat, gpManiWeaponMgr->GetWeaponName(j), 0); if (!pWeapon) continue; if (strcmp(CBaseCombatWeapon_GetName(pWeapon), "weapon_c4") != 0) { continue; } CBasePlayer_RemovePlayerItem(pBase, pWeapon); // Switch to knife pWeapon = CBaseCombatCharacter_Weapon_GetSlot(pCombat, 2); if (pWeapon) { CBaseCombatCharacter_Weapon_Switch(pCombat, pWeapon, 0); } } } CBaseEntity *weaponc4 = (CBaseEntity*)CGlobalEntityList_FindEntityByClassname(NULL, "weapon_c4"); if (weaponc4) { CCSUTILRemove(weaponc4); } CUtlVector<CBaseEntity*> hostages; CBaseEntity *hostage = (CBaseEntity*)CGlobalEntityList_FindEntityByClassname(NULL, "hostage_entity"); while (hostage) { hostages.AddToTail(hostage); hostage = (CBaseEntity*)CGlobalEntityList_FindEntityByClassname(hostage, "hostage_entity"); } for (int x = 0; x < hostages.Count(); x++) { CCSUTILRemove(hostages[x]); } }
void ManiWeaponMgr::RemoveWeapons(player_t *player_ptr, bool refund, bool show_refund) { int reason, limit, ratio; if (war_mode) return; CBaseEntity *pPlayer = EdictToCBE(player_ptr->entity); CBaseCombatCharacter *pCombat = CBaseEntity_MyCombatCharacterPointer(pPlayer); CBasePlayer *pBase = (CBasePlayer*) pPlayer; if (!pCombat) return; bool knife_mode = gpManiWarmupTimer->KnivesOnly(); // Check all weapons for (int i = 0; i < MAX_WEAPONS_USED; i++) { if ( !weapons[i] ) break; // for DS tool and listen servers ... order of processing different if (weapons[i]->GetDisplayID() == 0) continue; if (!weapons[i]->CanBuy(player_ptr, 1, reason, limit, ratio) || knife_mode) { CBaseCombatWeapon *pWeapon = CBaseCombatCharacter_Weapon_OwnsThisType(pCombat, weapons[i]->GetWeaponName(), 0); //CBaseCombatWeapon *pWeapon = CBaseCombatCharacter_GetWeapon(pCombat, j); if (!pWeapon) continue; if (strcmp(CBaseCombatWeapon_GetName(pWeapon), weapons[i]->GetWeaponName()) != 0) { continue; } CBasePlayer_RemovePlayerItem(pBase, pWeapon); if (!knife_mode) { ShowRestrictReason(player_ptr, weapons[i], reason, limit, ratio); ProcessPlayActionSound(player_ptr, MANI_ACTION_SOUND_RESTRICTWEAPON); } if (refund && !knife_mode) { CCSWeaponInfo *weapon_info = (CCSWeaponInfo *) CCSGetFileWeaponInfoFromHandle(i); if (weapon_info) { int cash = Prop_GetVal(player_ptr->entity, MANI_PROP_ACCOUNT,0); cash += weapon_info->standard_price; if (cash > 16000) cash = 16000; Prop_SetVal(player_ptr->entity, MANI_PROP_ACCOUNT, cash); if (show_refund) { OutputHelpText(GREEN_CHAT, player_ptr, "%s", Translate(player_ptr, 3042, "%i", weapon_info->standard_price)); } } } // Switch to knife pWeapon = CBaseCombatCharacter_Weapon_GetSlot(pCombat, 2); if (pWeapon) { CBaseCombatCharacter_Weapon_Switch(pCombat, pWeapon, 0); } } } }
//--------------------------------------------------------------------------------- // Purpose: called once per server frame, do recurring work here (like checking for timeouts) //--------------------------------------------------------------------------------- void WebSpecPlugin::GameFrame( bool simulating ) { if (gpGlobals->curtime - g_lastUpdateTime > WEBSPEC_UPDATE_RATE_IN_SECONDS && ws_spectators.Count() > 0) { char *buffer = (char *)malloc(MAX_BUFFER_SIZE); Vector playerOrigin; QAngle playerAngles; float playerUberCharge; int userid, health, playerClass; IPlayerInfo *playerInfo; CBaseEntity *playerEntity; int bufferLength; bufferLength = sprintf(buffer, "O"); for (int i = 1; i < gpGlobals->maxClients; i++) { playerInfo = playerInfoManager->GetPlayerInfo(engine->PEntityOfEntIndex(i)); if (playerInfo == NULL || !playerInfo->IsConnected() || playerInfo->IsDead()) continue; if (strlen(buffer) > 1) snprintf(buffer, MAX_BUFFER_SIZE, "%s|", buffer); userid = playerInfo->GetUserID(); health = playerInfo->GetHealth(); playerOrigin = playerInfo->GetAbsOrigin(); playerEntity = serverGameEnts->EdictToBaseEntity(engine->PEntityOfEntIndex(i)); playerClass = *MakePtr(int*, playerEntity, WSOffsets::pCTFPlayer__m_iClass); playerAngles = CBaseEntity_EyeAngles(playerEntity); if (playerClass == TFClass_Medic) { CBaseCombatCharacter *playerCombatCharacter = CBaseEntity_MyCombatCharacterPointer(playerEntity); CBaseCombatWeapon *slot1Weapon = CBaseCombatCharacter_Weapon_GetSlot(playerCombatCharacter, 1); playerUberCharge = *MakePtr(float*, slot1Weapon, WSOffsets::pCWeaponMedigun__m_flChargeLevel); } else {
//================================================================================= // Callback for the 'webspec' protocol // Manages spectator connections & sending Initial messages to new spectators //================================================================================= int webspec_callback(struct libwebsocket_context *ctx, struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, void *in, size_t len) { switch (reason) { case LWS_CALLBACK_ESTABLISHED: { Msg("[WS] New connection\n"); // New connection ws_spectators.AddToTail(wsi); // Send basic game info to let client set up // MapName, Server name (may remove), current team names char *buffer = (char*)malloc(MAX_BUFFER_SIZE); char *mapName = (char*) STRING(gpGlobals->mapname); ConVarRef hostNameCVar = ConVarRef("hostname"); string_t hostname; if (hostNameCVar.IsValid()) hostname = MAKE_STRING(hostNameCVar.GetString()); else hostname = MAKE_STRING("WebSpec Demo Server"); //Can't imagine when hostname would be invalid, but this is Source int length = snprintf(buffer, MAX_BUFFER_SIZE, "%c%s:%s:%s:%s", WSPacket_Init, mapName, STRING(hostname), STRING(ws_teamName[1]), STRING(ws_teamName[0])); SendPacketToOne(buffer, length, wsi); free(buffer); //Send connected players IPlayerInfo *playerInfo; for (int i=1; i<=gpGlobals->maxClients; i++) { playerInfo = playerInfoManager->GetPlayerInfo(engine->PEntityOfEntIndex(i)); if (playerInfo != NULL && playerInfo->IsConnected()) { buffer = (char *)malloc(MAX_BUFFER_SIZE); int userid = playerInfo->GetUserID(); int teamid = playerInfo->GetTeamIndex(); int health = playerInfo->GetHealth(); int maxHealth = playerInfo->GetMaxHealth(); bool alive = !playerInfo->IsDead(); string_t playerName = MAKE_STRING(playerInfo->GetName()); //Pointer magic to get TF2 class CBaseEntity *playerEntity = serverGameEnts->EdictToBaseEntity(engine->PEntityOfEntIndex(i)); int playerClass = *MakePtr(int*, playerEntity, WSOffsets::pCTFPlayer__m_iClass); float uberCharge = 0.0f; if (playerClass == TFClass_Medic) { //Way more pointer magic to get ubercharge from medigun CBaseCombatCharacter *playerCombatCharacter = CBaseEntity_MyCombatCharacterPointer(playerEntity); CBaseCombatWeapon *slot1Weapon = CBaseCombatCharacter_Weapon_GetSlot(playerCombatCharacter, 1); uberCharge = *MakePtr(float*, slot1Weapon, WSOffsets::pCWeaponMedigun__m_flChargeLevel); } int length = snprintf(buffer, MAX_BUFFER_SIZE, "%c%d:%d:%d:%d:%d:%d:0:%d:%s", 'C', userid, teamid, playerClass, health, maxHealth, alive, Round(uberCharge*100.0f), STRING(playerName)); SendPacketToOne(buffer, length, wsi); free(buffer); } } break; }
//--------------------------------------------------------------------------------- // Purpose: Level has initialised //--------------------------------------------------------------------------------- void ManiWarmupTimer::PlayerSpawn(player_t *player_ptr) { if (war_mode) return; if (mani_warmup_timer.GetInt() == 0) return; if (!check_timer) return; if (!gpManiGameType->IsValidActiveTeam(player_ptr->team)) return; if (fire_restart == false) return; respawn_list[player_ptr->index - 1].needs_respawn = false; if (player_ptr->is_bot) { if (mani_warmup_timer_knives_only.GetInt() == 1) { // Set cash to zero and strip weapons Prop_SetVal(player_ptr->entity, MANI_PROP_ACCOUNT, 0); CBaseEntity *pPlayer = player_ptr->entity->GetUnknown()->GetBaseEntity(); CBaseCombatCharacter *pCombat = CBaseEntity_MyCombatCharacterPointer(pPlayer); CBaseCombatWeapon *pWeapon1 = CBaseCombatCharacter_Weapon_GetSlot(pCombat, 0); CBaseCombatWeapon *pWeapon2 = CBaseCombatCharacter_Weapon_GetSlot(pCombat, 1); CBasePlayer *pBase = (CBasePlayer*) pPlayer; if (pWeapon1) { CBasePlayer_RemovePlayerItem(pBase, pWeapon1); } if (pWeapon2) { CBasePlayer_RemovePlayerItem(pBase, pWeapon2); } CBaseCombatWeapon *pWeapon = CBaseCombatCharacter_Weapon_GetSlot(pCombat, 2); if (pWeapon) { CBaseCombatCharacter_Weapon_Switch(pCombat, pWeapon, 0); } CBaseEntity *weaponc4 = (CBaseEntity*)CGlobalEntityList_FindEntityByClassname(NULL, "weapon_c4"); if (weaponc4) { CCSUTILRemove(weaponc4); } } } // Unlimited grenades if (mani_warmup_timer_unlimited_grenades.GetInt() == 1 && (gpManiGameType->IsGameType(MANI_GAME_CSS) || gpManiGameType->IsGameType(MANI_GAME_CSGO))) { GiveItem(player_ptr->entity, "weapon_hegrenade"); } for (int i = 0; i < 5; i ++) { if (item_name[i][0] != '\0') { // Ignore assault suit if not CSS if (i == 0 && (!gpManiGameType->IsGameType(MANI_GAME_CSS) && !gpManiGameType->IsGameType(MANI_GAME_CSGO)) && strcmp(item_name[i], "item_assaultsuit") == 0) { continue; } GiveItem(player_ptr->entity, item_name[i]); } } }
//--------------------------------------------------------------------------------- // Purpose: Checks if player can buy this weapon or not //--------------------------------------------------------------------------------- bool MWeapon::CanBuy(player_t *player_ptr, int offset, int &reason, int &limit, int &ratio) { // Msg("[%s] [%s] [%i] [%i] [%s]\n", weapon_name, display_name, team_limit, round_ratio, (restricted == true) ? "YES":"NO"); if (!restricted || war_mode) return true; if (!gpManiGameType->IsValidActiveTeam(player_ptr->team)) return true; if (translation_id == 0) return true; // Weapons are restricted, check if limit is 0 if (round_ratio != 0) { if (player_ptr->team == 2) { if (gpManiTeam->GetTeamScore(2) - gpManiTeam->GetTeamScore(3) >= round_ratio) { reason = WEAPON_RATIO; ratio = round_ratio; return false; } } else { if (gpManiTeam->GetTeamScore(3) - gpManiTeam->GetTeamScore(2) >= round_ratio) { reason = WEAPON_RATIO; ratio = round_ratio; return false; } } if (team_limit == 0) { return true; } } if (team_limit == 0 && round_ratio == 0) { reason = WEAPON_RESTRICT; return false; } count[2] = 0; count[3] = 0; int compare = team_limit + offset; // Count up number of weapons that players have for (int i = 1; i <= max_players; i++) { player_t player; player.index = i; if (!FindPlayerByIndex(&player)) continue; if (player.player_info->IsHLTV()) continue; CBaseEntity *pPlayer = EdictToCBE(player.entity); CBaseCombatCharacter *pCombat = CBaseEntity_MyCombatCharacterPointer(pPlayer); if (!pCombat) continue; for (int j = 0; j < MAX_WEAPONS_USED; j++) { CBaseCombatWeapon *pWeapon = CBaseCombatCharacter_Weapon_OwnsThisType(pCombat, gpManiWeaponMgr->GetWeaponName(j), 0); if (!pWeapon) continue; if (strcmp(weapon_name, CBaseCombatWeapon_GetName(pWeapon)) == 0) { count[player.team] ++; } } } if (count[player_ptr->team] >= compare) { reason = WEAPON_LIMIT; limit = team_limit; return false; } return true; }