Example #1
0
void FakeClientCommand (edict_t *fakeClient, const char *format, ...)
{
   // the purpose of this function is to provide fakeclients (bots) with the same client
   // command-scripting advantages (putting multiple commands in one line between semicolons)
   // as real players. It is an improved version of botman's FakeClientCommand, in which you
   // supply directly the whole string as if you were typing it in the bot's "console". It
   // is supposed to work exactly like the pfnClientCommand (server-sided client command).

   va_list ap;
   static char command[256];
   int start, stop, i, index, stringIndex = 0;

   if (FNullEnt (fakeClient))
      return; // reliability check

   // concatenate all the arguments in one string
   va_start (ap, format);
   _vsnprintf (command, sizeof (command), format, ap);
   va_end (ap);

   if (IsNullString (command))
      return; // if nothing in the command buffer, return

   g_isFakeCommand = true; // set the "fakeclient command" flag
   int length = strlen (command); // get the total length of the command string

   // process all individual commands (separated by a semicolon) one each a time
   while (stringIndex < length)
   {
      start = stringIndex; // save field start position (first character)

      while (stringIndex < length && command[stringIndex] != ';')
         stringIndex++; // reach end of field

      if (command[stringIndex - 1] == '\n')
         stop = stringIndex - 2; // discard any trailing '\n' if needed
      else
         stop = stringIndex - 1; // save field stop position (last character before semicolon or end)

      for (i = start; i <= stop; i++)
         g_fakeArgv[i - start] = command[i]; // store the field value in the g_fakeArgv global string

      g_fakeArgv[i - start] = 0; // terminate the string
      stringIndex++; // move the overall string index one step further to bypass the semicolon

      index = 0;
      g_fakeArgc = 0; // let's now parse that command and count the different arguments

      // count the number of arguments
      while (index < i - start)
      {
         while (index < i - start && g_fakeArgv[index] == ' ')
            index++; // ignore spaces

         // is this field a group of words between quotes or a single word ?
         if (g_fakeArgv[index] == '"')
         {
            index++; // move one step further to bypass the quote

            while (index < i - start && g_fakeArgv[index] != '"')
               index++; // reach end of field

            index++; // move one step further to bypass the quote
         }
         else
            while (index < i - start && g_fakeArgv[index] != ' ')
               index++; // this is a single word, so reach the end of field

         g_fakeArgc++; // we have processed one argument more
      }

      // tell now the MOD DLL to execute this ClientCommand...
      MDLL_ClientCommand (fakeClient);
   }

   g_fakeArgv[0] = 0; // when it's done, reset the g_fakeArgv field
   g_isFakeCommand = false; // reset the "fakeclient command" flag
   g_fakeArgc = 0; // and the argument count
}
Example #2
0
Bot::Bot (edict_t *bot, int skill, int personality, int team, int member)
{
   // this function does core operation of creating bot, it's called by CreateBot (),
   // when bot setup completed, (this is a bot class constructor)

   char rejectReason[128];
   int clientIndex = ENTINDEX (bot);

   memset (this, 0, sizeof (Bot));

   pev = VARS (bot);

   if (bot->pvPrivateData != null)
      FREE_PRIVATE (bot);

   bot->pvPrivateData = null;
   bot->v.frags = 0;

   // create the player entity by calling MOD's player function
   BotControl::CallGameEntity (&bot->v);

   // set all info buffer keys for this bot
   char *buffer = GET_INFOKEYBUFFER (bot);

   SET_CLIENT_KEYVALUE (clientIndex, buffer, "model", "");
   SET_CLIENT_KEYVALUE (clientIndex, buffer, "rate", "3500.000000");
   SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_updaterate", "20");
   SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_lw", "1");
   SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_lc", "1");
   SET_CLIENT_KEYVALUE (clientIndex, buffer, "tracker", "0");
   SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_dlmax", "128");
   SET_CLIENT_KEYVALUE (clientIndex, buffer, "friends", "0");
   SET_CLIENT_KEYVALUE (clientIndex, buffer, "dm", "0");
   SET_CLIENT_KEYVALUE (clientIndex, buffer, "_ah", "0");

   if (yb_tagbots.GetBool ())
      SET_CLIENT_KEYVALUE (clientIndex, buffer, "*bot", "1");

   SET_CLIENT_KEYVALUE (clientIndex, buffer, "_vgui_menus", "0");

   memset (rejectReason, 0, sizeof (rejectReason)); // reset the reject reason template string
   MDLL_ClientConnect (bot, "fakeclient", FormatBuffer ("192.168.1.%d", ENTINDEX (bot) + 100), rejectReason);

   if (!IsNullString (rejectReason))
   {
      AddLogEntry (true, LOG_WARNING, "Server refused '%s' connection (%s)", STRING (bot->v.netname), rejectReason);
      ServerCommand ("kick \"%s\"", STRING (bot->v.netname)); // kick the bot player if the server refused it

      bot->v.flags |= FL_KILLME;
   }

   if (IsDedicatedServer () && engine->GetDeveloperLevel () > 0)
   {
      if (engine->GetDeveloperLevel () == 2)
      {
          ServerPrint ("Server requiring authentication");
          ServerPrint ("Client '%s' connected", STRING (bot->v.netname));
          ServerPrint ("Adr: 127.0.0.%d:27005", ENTINDEX (bot) + 100);
      }

      ServerPrint ("Verifying and uploading resources...");
      ServerPrint ("Custom resources total 0 bytes");
      ServerPrint ("  Decals:  0 bytes");
      ServerPrint ("----------------------");
      ServerPrint ("Resources to request: 0 bytes");
   }

   MDLL_ClientPutInServer (bot);

   bot->v.flags = 0;
   bot->v.flags |= FL_FAKECLIENT | FL_CLIENT; // set this player as fakeclient

   // initialize all the variables for this bot...
   m_notStarted = true;  // hasn't joined game yet

   m_startAction = CMENU_IDLE;
   m_moneyAmount = 0;
   m_logotypeIndex = engine->RandomInt (0, 5);


   // initialize msec value
   m_msecNum = m_msecDel = 0.0f;
   m_msecInterval = engine->GetTime ();
   m_msecVal = static_cast <uint8_t> (g_pGlobals->frametime * 1000.0f);
   m_msecBuiltin = engine->RandomInt (1, 4);

   // assign how talkative this bot will be
   m_sayTextBuffer.chatDelay = engine->RandomFloat (3.8f, 10.0f);
   m_sayTextBuffer.chatProbability = engine->RandomInt (1, 100);

   m_notKilled = false;
   m_skill = skill;
   m_weaponBurstMode = BURST_DISABLED;

   m_lastThinkTime = engine->GetTime ();
   m_frameInterval = engine->GetTime ();

   bot->v.idealpitch = bot->v.v_angle.x;
   bot->v.ideal_yaw = bot->v.v_angle.y;

   bot->v.yaw_speed = engine->RandomFloat (g_skillTab[m_skill / 20].minTurnSpeed, g_skillTab[m_skill / 20].maxTurnSpeed);
   bot->v.pitch_speed = engine->RandomFloat (g_skillTab[m_skill / 20].minTurnSpeed, g_skillTab[m_skill / 20].maxTurnSpeed);

   switch (personality)
   {
   case 1:
      m_personality = PERSONALITY_RUSHER;
      m_baseAgressionLevel = engine->RandomFloat (0.7f, 1.0f);
      m_baseFearLevel = engine->RandomFloat (0.0f, 0.4f);
      break;

   case 2:
      m_personality = PERSONALITY_CAREFUL;
      m_baseAgressionLevel = engine->RandomFloat (0.0f, 0.4f);
      m_baseFearLevel = engine->RandomFloat (0.7f, 1.0f);
      break;

   default:
      m_personality = PERSONALITY_NORMAL;
      m_baseAgressionLevel = engine->RandomFloat (0.4f, 0.7f);
      m_baseFearLevel = engine->RandomFloat (0.4f, 0.7f);
      break;
   }

   memset (&m_ammoInClip, 0, sizeof (m_ammoInClip));
   memset (&m_ammo, 0, sizeof (m_ammo));

   m_currentWeapon = 0; // current weapon is not assigned at start
   m_voicePitch = engine->RandomInt (166, 250) / 2; // assign voice pitch

   // copy them over to the temp level variables
   m_agressionLevel = m_baseAgressionLevel;
   m_fearLevel = m_baseFearLevel;
   m_nextEmotionUpdate = engine->GetTime () + 0.5f;

   // just to be sure
   m_actMessageIndex = 0;
   m_pushMessageIndex = 0;

   // assign team and class
   m_wantedTeam = team;
   m_wantedClass = member;

   NewRound ();
}
Example #3
0
int BotControl::CreateBot (String name, int skill, int personality, int team, int member)
{
   // this function completely prepares bot entity (edict) for creation, creates team, skill, sets name etc, and
   // then sends result to bot constructor

   edict_t *bot = null;
   char outputName[33];

   if (g_numWaypoints < 1) // don't allow creating bots with no waypoints loaded
   {
      CenterPrint ("Map not waypointed. Can't Create Bot");
      return 0;
   }
   else if (g_waypointsChanged) // don't allow creating bots with changed waypoints (distance tables are messed up)
   {
      CenterPrint ("Waypoints has been changed. Load waypoints again...");
      return 0;
   }


   if (skill < 0 || skill > 100)
      skill = engine->RandomInt (yb_minskill.GetInt (), yb_maxskill.GetInt ());

   if (skill > 100 || skill < 0)
      skill = engine->RandomInt (0, 100);

   if (personality < 0 || personality > 2)
   {
      int randomPrecent = engine->RandomInt (0, 100);

      if (randomPrecent < 50)
         personality = PERSONALITY_NORMAL;
      else
      {
         if (engine->RandomInt (0, randomPrecent) < randomPrecent * 0.5)
            personality = PERSONALITY_CAREFUL;
         else
            personality = PERSONALITY_RUSHER;
      }
   }

   // setup name
   if (name.IsEmpty ())
   {
      if (!g_botNames.IsEmpty ())
      {
         bool nameFound = false;

         for (int i = 0; i < 8; i++)
         {
            if (nameFound)
               break;

            NameItem &botName = g_botNames.GetRandomElement ();

            if (botName.isUsed)
               continue;

            botName.isUsed = nameFound = true;
            strcpy (outputName, botName.name);
         }
      }
      else
         sprintf (outputName, "bot%i", engine->RandomInt (0, 100)); // just pick ugly random name
   }
   else
      strncpy (outputName, name, 21);

   if (!IsNullString (yb_nameprefix.GetString ()) || yb_skilltags.GetBool ())
   {
      char prefixedName[33]; // temp buffer for storing modified name

      if (!IsNullString (yb_nameprefix.GetString ()))
         sprintf (prefixedName, "%s %s", yb_nameprefix.GetString (), outputName);

      else if (yb_skilltags.GetBool ())
         sprintf  (prefixedName, "%s (%d)", outputName, skill);

      else if (!IsNullString (yb_nameprefix.GetString ()) && yb_skilltags.GetBool ())
         sprintf  (prefixedName, "%s %s (%d)", yb_nameprefix.GetString (), outputName, skill);

      // buffer has been modified, copy to real name
      if (!IsNullString (prefixedName))
         sprintf (outputName, prefixedName);
   }

   if (FNullEnt ((bot = (*g_engfuncs.pfnCreateFakeClient) (outputName))))
   {
      CenterPrint ("Maximum players reached (%d/%d). Unable to create Bot.", engine->GetMaxClients (), engine->GetMaxClients ());
      return 2;
   }

   int index = ENTINDEX (bot) - 1;

   InternalAssert (index >= 0 && index <= 32); // check index
   InternalAssert (m_bots[index] == null); // check bot slot

   m_bots[index] = new Bot (bot, skill, personality, team, member);
 
   if (m_bots == null)
      TerminateOnMalloc ();

   if (engine->GetDeveloperLevel () > 0)
      ServerPrint ("Connecting '%s'... (Skill %d)", STRING (bot->v.netname), skill);
   else
      ServerPrint ("Connecting YaPB... (Skill %d)", skill);

   return 1;
}
void* KaiXinAPI_CommentDetail_JsonParse(char *text)
{
	cJSON *json;
	cJSON *pTemp0;
	tResponseCommentDetail*  Response = new tResponseCommentDetail;
	memset(Response, 0 , sizeof(tResponseCommentDetail));

	json = cJSON_Parse(text);

	pTemp0 = cJSON_GetObjectItem(json,"ret");
	if (pTemp0)
	{
		Response->ret = pTemp0->valueint;	
	}

	//Success
	if(Response->ret == 1)
	{
		pTemp0 = cJSON_GetObjectItem(json, "uid");
		if(pTemp0)
		{
			if(pTemp0->valueint > 0)
				sprintf(Response->uid, "%d", pTemp0->valueint );
			else
				STRCPY_Ex(Response->uid, pTemp0->valuestring);
		}
		pTemp0 = cJSON_GetObjectItem(json, "n");
		if(pTemp0)
		{
			Response->n = pTemp0->valueint;
		}
		pTemp0 = cJSON_GetObjectItem(json, "thread_cid");
		if(pTemp0)
		{
			if(pTemp0->valuedouble > 0)
				DoubleToChar(pTemp0->valuedouble, Response->thread_cid);
			else
				STRCPY_Ex(Response->thread_cid, pTemp0->valuestring);
		}
		pTemp0 = cJSON_GetObjectItem(json, "mtype");
		if(pTemp0)
		{
			if(IsNullString(pTemp0->valuestring))
				sprintf(Response->mtype, "%d", pTemp0->valueint);
			else
				STRCPY_Ex(Response->mtype, pTemp0->valuestring);			
		}
		
		pTemp0 = cJSON_GetObjectItem(json, "flogo");
		if(pTemp0)
		{
			STRCPY_Ex(Response->flogo, pTemp0->valuestring);
		}
		pTemp0 = cJSON_GetObjectItem(json, "cnum");
		if(pTemp0)
		{
			Response->cnum = pTemp0->valueint;
		}
		pTemp0 = cJSON_GetObjectItem(json, "more");
		if(pTemp0)
		{
			Response->more = pTemp0->valueint;
		}

		//new added
		pTemp0 = cJSON_GetObjectItem(json, "title");				
		if(pTemp0)
		{
			STRCPY_Ex(Response->title, pTemp0->valuestring);
		}

		pTemp0 = cJSON_GetObjectItem(json, "thumbnail");

		if(pTemp0)

		{

			STRCPY_Ex(Response->thumbnail, pTemp0->valuestring);

		}

		pTemp0 = cJSON_GetObjectItem(json, "appid");

		if(pTemp0)
		{

			STRCPY_Ex(Response->appid, pTemp0->valuestring);

		}

		pTemp0 = cJSON_GetObjectItem(json, "comments");
		if(pTemp0)
		{
			int nSize1 = 0, i = 0;
			nSize1 = cJSON_GetArraySize(pTemp0);
			Response->nSize = nSize1;
			if( nSize1 != 0 )
			{
				Response->comments = NULL;
				Response->comments = (CommentDetail_comments*) malloc(sizeof( CommentDetail_comments ) * nSize1 );
				memset(Response->comments, 0 , sizeof(CommentDetail_comments) * nSize1 );
			}
			for ( i = 0; i < nSize1; i++ )
			{
				cJSON *Item1 = NULL, *pTemp1 = NULL;
				Item1 = cJSON_GetArrayItem(pTemp0,i);
				pTemp1 = cJSON_GetObjectItem(Item1, "flogo");
				if(pTemp1)
				{
					STRCPY_Ex(Response->comments[i].flogo, pTemp1->valuestring);
				}
				pTemp1 = cJSON_GetObjectItem(Item1, "cid");
				if(pTemp1)
				{
					Response->comments[i].cid = pTemp1->valueint;
				}
				pTemp1 = cJSON_GetObjectItem(Item1, "fuid");
				if(pTemp1)
				{
					Response->comments[i].fuid = pTemp1->valueint;
				}
				pTemp1 = cJSON_GetObjectItem(Item1, "fname");
				if(pTemp1)
				{
					STRCPY_Ex(Response->comments[i].fname, pTemp1->valuestring);
				}
				pTemp1 = cJSON_GetObjectItem(Item1, "abscont");
				if(pTemp1)
				{
					STRCPY_Ex(Response->comments[i].abscont, pTemp1->valuestring);
				}
				pTemp1 = cJSON_GetObjectItem(Item1, "ctime");
				if(pTemp1)
				{
					Response->comments[i].ctime = pTemp1->valueint;
				}
				pTemp1 = cJSON_GetObjectItem(Item1, "strctime");
				if(pTemp1)
				{
					STRCPY_Ex(Response->comments[i].strctime, pTemp1->valuestring);
				}

			}
		}

	}
	//Failue
	else
	{
		//pTemp0 = cJSON_GetObjectItem(json,"msg");
		//if (pTemp0)
		//{
		//	strcpy(Response->msg, pTemp0 ->valuestring);	
		//}
	}
	cJSON_Delete(json);
	return Response;
}