Exemplo n.º 1
0
void Engine::PrintAllClients (PrintType printType, const char *format, ...)
{
   char buffer[1024];
   va_list ap;

   va_start (ap, format);
   vsprintf (buffer, format, ap);
   va_end (ap);

   if (printType == PRINT_CONSOLE)
   {
      for (int i = 0; i < GetMaxClients (); i++)
      {
         const Client &client = GetClientByIndex (i);

         if (client.IsPlayer ())
            client.Print (PRINT_CONSOLE, buffer);
      }
   }
   else
   {
      strcat (buffer, "\n");

      g_engfuncs.pfnMessageBegin (MSG_BROADCAST, g_netMsg->GetId (NETMSG_TEXTMSG), null, null);
      g_engfuncs.pfnWriteByte (printType == PRINT_CENTER ? 4 : 3);
      g_engfuncs.pfnWriteString (buffer);
      g_engfuncs.pfnMessageEnd ();
   }
}
Exemplo n.º 2
0
// find a pointer to a client with the specified name
CClient *CServer::FindClientByName(const char *netname)
{
   for (int i = 0; i < GetMaxClients(); i++) {
      CClient *pClient = m_rgpClients[i];
      if (pClient && !strcmp(pClient->GetNetName(), netname))
         return pClient;
   }

   return NULL; // client with this name is not found
}
IPlayerInfo *CSizzPluginContext::GetPlayerInfo( int ent_index )
{
	if ((1 <= ent_index) && (ent_index <= GetMaxClients()))
	{
		edict_t *pEdict = EdictFromEntIndex(ent_index);
		if (pEdict && !pEdict->IsFree())
		{
			return m_pPlayerInfoManager->GetPlayerInfo(pEdict);
		}
	}
	return nullptr;
}
bool CSizzPluginContext::CanRecordDemo()
{
	for (int i = 1; i <= GetMaxClients(); ++i)
	{
		edict_t *pEdict = EdictFromEntIndex(i);
		IPlayerInfo *pInfo = m_pPlayerInfoManager->GetPlayerInfo(pEdict);
		if (pInfo && pInfo->IsHLTV())
		{
			return true;
		}
	}
	return false;
}
Exemplo n.º 5
0
void CServer::Think()
{
   int i;

   UpdateMsec(); // calculate the msec value
   CheckClients(); // check and update our client list

   BotManager()->Think();
   World()->Think();

   for (i = 0; i < GetMaxClients(); i++) {
      if (m_rgpClients[i] != NULL) {
         // check if this client is a bot
         CBaseBot *pBot = m_rgpClients[i]->GetBotPointer();
         if (pBot) {
            // this is a bot...
            pBot->BotThink(); // call its think function to make it run
         }
      }
   }
}
Exemplo n.º 6
0
void CServer::CheckClients()
{
   // check if any clients (or bots) have joined the game or
   // disconnected, so that we can update the list we have...
   for (int i = 0; i < GetMaxClients(); i++) {
      edict_t *pPlayer = INDEXENT(i + 1);
      if (!FNullEnt(pPlayer) && !pPlayer->free && STRING(pPlayer->v.netname)[0]) {
         if (m_rgpClients[i] == NULL) {
            // a client has joined the game
            g_Debug.DebugLog(DEBUG_GENERAL, "client index #%d joined the game", i + 1);
            m_rgpClients[i] = new CClient; // add him/her to the list
            m_rgpClients[i]->pev = VARS(pPlayer);
         }
      } else {
         if (m_rgpClients[i] != NULL) {
            // a client (or bot) has disconnected from the game
            g_Debug.DebugLog(DEBUG_GENERAL, "client index #%d left the game", i + 1);
            delete m_rgpClients[i]; // delete him/her/it from the list
            m_rgpClients[i] = NULL;
         }
      }
   }
}
void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info)
{
	CPlayer *pTarget, *pAdmin;
	int max_clients, total = 0;

	max_clients = GetMaxClients();

	if (info->max_targets < 1)
	{
		info->reason = COMMAND_TARGET_NONE;
		info->num_targets = 0;
	}

	if (info->admin == 0)
	{
		pAdmin = NULL;
	}
	else
	{
		pAdmin = GetPlayerByIndex(info->admin);
	}

	if (info->pattern[0] == '#')
	{
		int userid = atoi(&info->pattern[1]);
		int client = GetClientOfUserId(userid);

		/* See if a valid userid matched */
		if (client > 0)
		{
			IGamePlayer *pTarget = GetPlayerByIndex(client);
			if (pTarget != NULL)
			{
				if ((info->reason = FilterCommandTarget(pAdmin, pTarget, info->flags)) == COMMAND_TARGET_VALID)
				{
					info->targets[0] = client;
					info->num_targets = 1;
					strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength);
					info->target_name_style = COMMAND_TARGETNAME_RAW;
				}
				else
				{
					info->num_targets = 0;
				}
				return;
			}
		}

		/* Do we need to look for a steam id? */
		if (strncmp(&info->pattern[1], "STEAM_", 6) == 0)
		{
			size_t p, len;
			char new_pattern[256];

			strcpy(new_pattern, "STEAM_");
			len = strlen(&info->pattern[7]);
			for (p = 0; p < len; p++)
			{
				new_pattern[6 + p] = info->pattern[7 + p];
				if (new_pattern[6 + p] == '_')
				{
					new_pattern[6 + p] = ':';
				}
			}
			new_pattern[6 + p] = '\0';

			for (int i = 1; i <= max_clients; i++)
			{
				if ((pTarget = GetPlayerByIndex(i)) == NULL)
				{
					continue;
				}
				if (!pTarget->IsConnected() || !pTarget->IsAuthorized())
				{
					continue;
				}
				if (strcmp(pTarget->GetAuthString(), new_pattern) == 0)
				{
					if ((info->reason = FilterCommandTarget(pAdmin, pTarget, info->flags))
						== COMMAND_TARGET_VALID)
					{
						info->targets[0] = i;
						info->num_targets = 1;
						strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength);
						info->target_name_style = COMMAND_TARGETNAME_RAW;
					}
					else
					{
						info->num_targets = 0;
					}
					return;
				}
			}
		}

		/* See if an exact name matches */
		for (int i = 1; i <= max_clients; i++)
		{
			if ((pTarget = GetPlayerByIndex(i)) == NULL)
			{
				continue;
			}
			if  (!pTarget->IsConnected())
			{
				continue;
			}
			if (strcmp(pTarget->GetName(), &info->pattern[1]) == 0)
			{
				if ((info->reason = FilterCommandTarget(pAdmin, pTarget, info->flags))
					== COMMAND_TARGET_VALID)
				{
					info->targets[0] = i;
					info->num_targets = 1;
					strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength);
					info->target_name_style = COMMAND_TARGETNAME_RAW;
				}
				else
				{
					info->num_targets = 0;
				}
				return;
			}
		}
	}

	if (strcmp(info->pattern, "@me") == 0 && info->admin != 0)
	{
		info->targets[0] = info->admin;
		info->num_targets = 1;
		strncopy(info->target_name, pAdmin->GetName(), info->target_name_maxlength);
		info->target_name_style = COMMAND_TARGETNAME_RAW;
		return;
	}

	if ((info->flags & COMMAND_FILTER_NO_MULTI) != COMMAND_FILTER_NO_MULTI)
	{
		bool is_multi = false;
		bool bots_only = false;
		int skip_client = -1;

		if (strcmp(info->pattern, "@all") == 0)
		{
			is_multi = true;
			strncopy(info->target_name, "all players", info->target_name_maxlength);
			info->target_name_style = COMMAND_TARGETNAME_ML;
		}
		else if (strcmp(info->pattern, "@dead") == 0)
		{
			is_multi = true;
			if ((info->flags & COMMAND_FILTER_ALIVE) == COMMAND_FILTER_ALIVE)
			{
				info->num_targets = 0;
				info->reason = COMMAND_TARGET_NOT_ALIVE;
				return;
			}
			info->flags |= COMMAND_FILTER_DEAD;
			strncopy(info->target_name, "all dead players", info->target_name_maxlength);
			info->target_name_style = COMMAND_TARGETNAME_ML;
		}
		else if (strcmp(info->pattern, "@alive") == 0)
		{
			is_multi = true;
			if ((info->flags & COMMAND_FILTER_DEAD) == COMMAND_FILTER_DEAD)
			{
				info->num_targets = 0;
				info->reason = COMMAND_TARGET_NOT_DEAD;
				return;
			}
			strncopy(info->target_name, "all alive players", info->target_name_maxlength);
			info->target_name_style = COMMAND_TARGETNAME_ML;
			info->flags |= COMMAND_FILTER_ALIVE;
		}
		else if (strcmp(info->pattern, "@bots") == 0)
		{
			is_multi = true;
			if ((info->flags & COMMAND_FILTER_NO_BOTS) == COMMAND_FILTER_NO_BOTS)
			{
				info->num_targets = 0;
				info->reason = COMMAND_FILTER_NO_BOTS;
				return;
			}
			strncopy(info->target_name, "all bots", info->target_name_maxlength);
			info->target_name_style = COMMAND_TARGETNAME_ML;
			bots_only = true;
		}
		else if (strcmp(info->pattern, "@humans") == 0)
		{
			is_multi = true;
			strncopy(info->target_name, "all humans", info->target_name_maxlength);
			info->target_name_style = COMMAND_TARGETNAME_ML;
			info->flags |= COMMAND_FILTER_NO_BOTS;
		}
		else if (strcmp(info->pattern, "@!me") == 0)
		{
			is_multi = true;
			strncopy(info->target_name, "all players", info->target_name_maxlength);
			info->target_name_style = COMMAND_TARGETNAME_ML;
			skip_client = info->admin;
		}

		if (is_multi)
		{
			for (int i = 1; i <= max_clients && total < info->max_targets; i++)
			{
				if ((pTarget = GetPlayerByIndex(i)) == NULL)
				{
					continue;
				}
				if (FilterCommandTarget(pAdmin, pTarget, info->flags) > 0)
				{
					if ((!bots_only || pTarget->IsFakeClient())
						&& skip_client != i)
					{
						info->targets[total++] = i;
					}
				}
			}

			info->num_targets = total;
			info->reason = (info->num_targets) ? COMMAND_TARGET_VALID : COMMAND_TARGET_EMPTY_FILTER;
			return;
		}
	}

	List<ICommandTargetProcessor *>::iterator iter;
	for (iter = target_processors.begin(); iter != target_processors.end(); iter++)
	{
		ICommandTargetProcessor *pProcessor = (*iter);
		if (pProcessor->ProcessCommandTarget(info))
		{
			return;
		}
	}

	/* Check partial names */
	int found_client = 0;
	CPlayer *pFoundClient = NULL;
	for (int i = 1; i <= max_clients; i++)
	{
		if ((pTarget = GetPlayerByIndex(i)) == NULL)
		{
			continue;
		}

		if (stristr(pTarget->GetName(), info->pattern) != NULL)
		{
			if (found_client)
			{
				info->num_targets = 0;
				info->reason = COMMAND_TARGET_AMBIGUOUS;
				return;
			}
			else
			{
				found_client = i;
				pFoundClient = pTarget;
			}
		}
	}

	if (found_client)
	{
		if ((info->reason = FilterCommandTarget(pAdmin, pFoundClient, info->flags)) 
			== COMMAND_TARGET_VALID)
		{
			info->targets[0] = found_client;
			info->num_targets = 1;
			strncopy(info->target_name, pFoundClient->GetName(), info->target_name_maxlength);
			info->target_name_style = COMMAND_TARGETNAME_RAW;
		}
		else
		{
			info->num_targets = 0;
		}
	}
	else
	{
		info->num_targets = 0;
		info->reason = COMMAND_TARGET_NONE;
	}
}
Exemplo n.º 8
0
void Engine::MaintainClients (void)
{
   for (int i = 0; i < GetMaxClients (); i++)
      m_clients[i].Maintain (g_engfuncs.pfnPEntityOfEntIndex (i));
}