示例#1
0
文件: map.hpp 项目: klimoqu/Arawn
    void PlayerDie(uchar id,uchar murderid)
    {
		deadplayersnumber++;
        Command ret=Command(id,5,murderid);
        emit ServerCommand(ret);
		if(deadplayersnumber==playersnumber-1)
		{
			for(uchar i=0;i<playersnumber;i++)if(players[i]->IsAlive())emit ServerCommand(Command(i,253,1));
		}
    }
示例#2
0
文件: game.cpp 项目: klimoqu/Arawn
Game::Game(uchar playersnumber,int bombtimeout,ArawnSettings *settings,bool survive)
{
	activegame=false;
	this->cup=0;
	this->survive=survive;
	this->settings=settings;
	this->playersnumber=playersnumber;
	this->bombtimeout=bombtimeout;
	this->playerid=0;
	gametimer=new QTimer(this);
	destroymap=new QTimer(this);
	map=new Map(playersnumber,settings);
	map->Upload(1);
	clientconnection=0;
	serverconnection=new Servernet();
	serverconnection->SetSurviveCup(survive);
	serverconnection->SetPlayerNumber(playersnumber);
	serverconnection->SetLocalPlayername(settings->defaultPlayer1Name);
	connect(map,SIGNAL(ServerCommand(Command)),this,SIGNAL(ServerValidate(Command)));
	connect(this,SIGNAL(ClientValidate(Command)),this,SLOT(ClientExecute(Command)));
	connect(this,SIGNAL(ServerValidate(Command)),serverconnection,SLOT(SendCommandToClients(Command)));
	connect(this,SIGNAL(ServerValidate(Command)),this,SLOT(ServerExecute(Command)));
	connect(serverconnection,SIGNAL(CommandReceivedFromClients(Command)),this,SLOT(ClientExecute(Command)));
	connect(serverconnection,SIGNAL(ServerIsRunning()),this,SIGNAL(ServerIsRunning()));
	connect(serverconnection,SIGNAL(NewPlayerConnected()),this,SIGNAL(NewPlayer()));
	connect(serverconnection,SIGNAL(ServerNetworkError()),this,SIGNAL(ConnectionFailed()));
	connect(serverconnection,SIGNAL(AllPlayersConnected()),this,SLOT(AllReady()));
	connect(this,SIGNAL(FieldDestroyedByMap(uchar,uchar)),map,SIGNAL(FieldDestroyed(uchar,uchar)));
	connect(serverconnection,SIGNAL(PlayerDisconnected()),this,SIGNAL(Disconnected()));
}
示例#3
0
void ConnectAsFirstBtn::EventHandle (Event e, Info I)
{
	Client* client = Client::GetInstance();
	switch (e)
	{
	case MouseClick:

		if (client -> isConnected()) return;
		if (!client -> isConnected())
		{
			try
			{
				client -> Connect(SinglePlayer);
			}
			catch (ENoServerAvailable* e)
			{
				Window* window = Window::GetInstance();
				ServerCommand cmd = ServerCommand();
				cmd.SetType(SSetTextNoServerAvailable);
				window -> CommandHandle(cmd);
			}
			catch (EConnectionFailed* e)
			{
				Window* window = Window::GetInstance();
				ServerCommand cmd = ServerCommand();
				cmd.SetType(SSetTextConnectionError);
				window -> CommandHandle(cmd);
			}
			catch(IException* e)
			{
				Window* window = Window::GetInstance();
				ServerCommand cmd = ServerCommand();
				cmd.SetType(SSetTextWrong);
				window -> CommandHandle(cmd);
			}
		}
		break;
	case MouseOn:
		this -> _isActive = true;
		this -> Draw();
		break;
	case MouseOut:
		this -> _isActive = false;
		this -> Draw();
		break;
	}
}
示例#4
0
	void TeleportBot(const char *name, const Vector& origin, const QAngle& angles)
	{
		ServerCommand("bot_teleport %s %f %f %f %f %f %f\n", name,
			origin.x, origin.y, origin.z,
			angles.x, angles.y, angles.x);
		
	//	constexpr int damage = -1000000;
	//	ServerCommand("bot_hurt -name %s -damage %d\n", name, damage);
	}
void ServerConsole::executeCommand(const std::string& commandline)
{
    std::string command, argument;
    size_t i;
    for(i = 0; i < commandline.size() && !isspace(commandline[i]); ++i) {
        command += commandline[i];
    }
    ++i;
    for( ; i < commandline.size(); ++i)
        argument += commandline[i];
            
    if(command == "help") {
        std::cout << "Commands:\n";
        for(size_t i = 0; commands[i].name != 0; ++i) {
            std::cout << "   " << commands[i].name;
            for(size_t a = 0; a < 12-strlen(commands[i].name); ++a)
                std::cout << ' ';
            std::cout << commands[i].help << "\n";
        }
    } else if(command == "quit") {
        manager->pushCommand(ServerCommand(ServerCommand::QUIT));
        running = false;
    } else if(command == "status") {
        manager->pushCommand(ServerCommand(ServerCommand::STATUS));
    } else if(command == "kick") {
        if(argument != "")
            manager->pushCommand(ServerCommand(ServerCommand::KICK, argument));
        else
            std::cout << "Please specify the number of a player.\n";
    } else if(command == "map") {
        if(argument != "")
            manager->pushCommand(
                    ServerCommand(ServerCommand::MAPCHANGE, argument));
        else
            std::cout << "Please specify the name of a map.\n";
    } else if(command == "say") {
        if(argument != "")
            manager->pushCommand(
                    ServerCommand(ServerCommand::CHAT, argument));
    } else {
        if(command != "")
            std::cout << "Unknown command.\n";
    }
}
示例#6
0
void HexarcTest (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	int i, j;

	CString sHostspec = pCmdLine->GetAttribute(OPTION_HOST);
	if (sHostspec.IsBlank())
		sHostspec = HOSTSPEC_DEFAULT;

	CHTTPClientSession Session;

	if (!Connect(sHostspec, Session))
		return;

	//	Read the list of high scores

	for (j = 0; j < 5; j++)
		{
		CJSONValue Payload = CJSONValue(CJSONValue::typeObject);
		Payload.InsertHandoff(FIELD_MAX_GAMES, CJSONValue(100));
		CJSONValue Result;
		if (!ServerCommand(Session, METHOD_OPTIONS, FUNC_HIGH_SCORE_GAMES, Payload, &Result))
			{
			printf("%s\n", Result.AsString().GetASCIIZPointer());
			return;
			}

		//	For each adventure, print high score

		if (Result.GetCount() == 0)
			printf("No game records.\n");
		else
			{
			for (i = 0; i < Result.GetCount(); i++)
				{
				const CJSONValue &Record = Result.GetElement(i);
				DWORD dwAdventure = (DWORD)Record.GetElement(FIELD_ADVENTURE).AsInt32();
				if (dwAdventure == 0)
					continue;

				CGameRecord GameRecord;
				if (GameRecord.InitFromJSON(Record) != NOERROR)
					{
					printf("Unable to parse JSON record.\n");
					continue;
					}

				DWORD dwAdventureUNID = GameRecord.GetAdventureUNID();
				CString sUsername = GameRecord.GetUsername();
				int iScore = GameRecord.GetScore();

				printf("%x %s %d\n", dwAdventureUNID, sUsername.GetASCIIZPointer(), iScore);
				}
			}
		}
	}
示例#7
0
文件: control.cpp 项目: xurubin/yapb
void Bot::Kick (void)
{
   // this function kick off one bot from the server.

   ServerCommand ("kick #%d", GETPLAYERUSERID (GetEntity ()));
   CenterPrint ("Bot '%s' kicked", STRING (pev->netname));

   // balances quota
   if (g_botManager->GetBotsNum () - 1 < yb_quota.GetInt ())
      yb_quota.SetInt (g_botManager->GetBotsNum () - 1);
}
示例#8
0
void ClientApp::Run()
{
	Window* mw = Window::GetInstance();
	try
	{
		mw -> Initialize();
	}
	catch (...)
	{
		ServerCommand cmd = ServerCommand();
		cmd.SetType(SSetTextWrong);
		mw -> CommandHandle(cmd);
	}
}
示例#9
0
ALERROR CHexarcSession::ServerCommand (const CString &sMethod, const CString &sFunc, CJSONValue &Payload, CJSONValue *retResult)

//	ServerCommand
//
//	Sends a command to the server and gets back a result. We assume that we are
//	connected.
//
//	NOTE: We clobber the Payload.

	{
	//	Create the message

	CHTTPMessage Request;
	InitRequest(sMethod, sFunc, &Request);
	Request.SetBody(new CJSONMessage(Payload));

	//	Send

	return ServerCommand(Request, retResult);
	}
示例#10
0
ALERROR CHexarcSession::ServerCommand (const CHTTPMessage &Request, CJSONValue *retResult)

//	ServerCommand
//
//	Sends a command to the server and gets back a result.

	{
	//	If we're currently connected (or think we are) do a reconnect on failure.

	bool bReconnectOnFailure = m_Session.IsConnected();

	//	Make sure we're connected

	CString sError;
	if (!Connect(&sError))
		{
		if (!m_Session.IsInternetAvailable())
			{
			*retResult = CJSONValue(ERR_NO_INTERNET);
			kernelDebugLogMessage("Unable to verify connection to the Internet.");
			}
		else
			*retResult = CJSONValue(sError);
		return ERR_FAIL;
		}

	//	Send the request and wait for response

	EInetsErrors iError;
	CHTTPMessage Response;
	if (iError = m_Session.Send(Request, &Response))
		{
		//	Reconnect, if necessary

		if (bReconnectOnFailure)
			{
			m_Session.Disconnect();
			return ServerCommand(Request, retResult);
			}

		//	Check to see if we have internet access. If we don't then that
		//	explains the problem.

		else if (!m_Session.IsInternetAvailable())
			{
			*retResult = CJSONValue(ERR_NO_INTERNET);
			kernelDebugLogMessage("Unable to verify connection to the Internet.");
			return ERR_FAIL;
			}

		//	Otherwise, error

		else
			{
			*retResult = CJSONValue(ERR_CANNOT_SEND);
			kernelDebugLogMessage(strPatternSubst(CONSTLIT("%s: Unable to send command to server."), Request.GetURL()));
			return ERR_FAIL;
			}
		}

	//	If we get an error, return

	if (Response.GetStatusCode() != 200)
		{
		*retResult = CJSONValue(Response.GetStatusMsg());
		kernelDebugLogMessage(strPatternSubst(CONSTLIT("%s: %s."), Request.GetURL(), Response.GetStatusMsg()));
		return ERR_FAIL;
		}

	//	Get the JSON response

	if (!GetJSONResponse(Response, retResult, &sError))
		{
		sError = strPatternSubst(ERR_INVALID_JSON, GetHostspec(), sError);
		*retResult = CJSONValue(sError);
		kernelDebugLogMessage(strPatternSubst(CONSTLIT("%s: %s"), Request.GetURL(), sError));
		return ERR_FAIL;
		}

	//	See if it is a server error code

	CString sErrorCode;
	CString sErrorDesc;
	if (CHexarc::IsError(*retResult, &sErrorCode, &sErrorDesc))
		{
		*retResult = CJSONValue(sErrorDesc);
		kernelDebugLogMessage(strPatternSubst(CONSTLIT("%s: Server returned error: %s"), Request.GetURL(), sErrorDesc));

		//	If this is Error.outOfDate then we return a different error code

		if (strEquals(sErrorCode, MSG_ERROR_OUT_OF_DATE))
			return ERR_OUTOFDATE;
		else
			return ERR_FAIL;
		}

	//	Done

	return NOERROR;
	}
示例#11
0
	void AddPuppetBot(const char *team, const char *playerclass, const char *name)
	{
		ServerCommand("bot -team %s -class %s -name %s\n", team, playerclass, name);
	}
示例#12
0
文件: map.hpp 项目: klimoqu/Arawn
 void PlayerInvisibility(uchar playerid,bool visible)
 {
     Command ret=Command(playerid,7,(((visible?3:4))*256*256*256));
     if(activegame)emit ServerCommand(ret);
 }
示例#13
0
文件: map.hpp 项目: klimoqu/Arawn
 void PlayerBlast(uchar id)
 {
     Command ret=Command(id,5,256);
     if(activegame)emit ServerCommand(ret);
 }
示例#14
0
文件: map.hpp 项目: klimoqu/Arawn
 void FieldChange(uchar x, uchar y,uchar newtype)
 {
     Command ret=Command(255,6,256*256*newtype+256*x+y);
     if(activegame)emit ServerCommand(ret);
 }
示例#15
0
文件: map.hpp 项目: klimoqu/Arawn
 void FieldExcinguish(uchar x, uchar y)
 {
     Command ret=Command(255,4,256*x+y);
     if(activegame)emit ServerCommand(ret);
 }
示例#16
0
文件: map.hpp 项目: klimoqu/Arawn
 void FieldBurning(uchar x, uchar y,uchar size, uchar id,uchar direction)
 {
     Command ret=Command(id,3,256*256*direction+256*x+y);
     if(activegame)emit ServerCommand(ret);
 }
示例#17
0
文件: control.cpp 项目: xurubin/yapb
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 ();
}
示例#18
0
文件: map.hpp 项目: klimoqu/Arawn
 void ChangeBonus(uchar x, uchar y, uchar type,uchar visibleorstate)
 {
     Command ret=Command(0,7,(visibleorstate*256*256*256)+(256*256*type)+(256*x)+y);
     if(activegame)emit ServerCommand(ret);
 }