ConsoleCommand ConsoleCommand::fromString( const QString &str )
{
    if ( str.isEmpty() ) {
        return ConsoleCommand( InvalidCommand );
    }

    const QStringList words = str.split( ' ', QString::SkipEmptyParts );
    QString commandName = words.first().trimmed().toLower();
    if ( commandName.startsWith('.') ) {
        commandName = commandName.mid( 1 ); // Cut the '.'
        return ConsoleCommand( commandName, words.mid(1) );
    }

    return ConsoleCommand( InvalidCommand );
}
void AShooterPlayerController::ServerCheat_Implementation(const FString& Msg)
{
	if (CheatManager)
	{
		ClientMessage(ConsoleCommand(Msg));
	}
}
Esempio n. 3
0
void Game::Run(HWND hwnd)
{
	if(graphics == NULL) // if graphics not initialized
		return;

	// Calculate elapsed time of last frame, save in frameTime
	QueryPerformanceCounter(&timeEnd);
	frameTime = (float)(timeEnd.QuadPart - timeStart.QuadPart ) / (float)timerFreq.QuadPart;

	// Power saving code, requires winmm.lib
	// if not enough time has elapsed for desired frame rate
	if (frameTime < MIN_FRAME_TIME)
	{
		sleepTime = (DWORD)((MIN_FRAME_TIME - frameTime)*1000);
		timeBeginPeriod(1);			// request 1mS resolution for windows timer
		Sleep(sleepTime);			// release cpu for sleepTime
		timeEndPeriod(1);			// end 1mS timer resolution
		return;
	}

	if (frameTime > 0.0)
		fps = (fps*0.99f) + (0.01f/frameTime); // average fps
	if (frameTime > MAX_FRAME_TIME) // if frame rate is very slow
		frameTime = MAX_FRAME_TIME; // limit maximum frameTime
	timeStart = timeEnd;

	// Update(), AI(), and Collisions() are pure virtual functions.
	// These functions must be provided in the class that inherits from Game.
	if (!paused)
	{
		Collisions(); // handle collisions
		Update(); // update all game items
		AI(); // artificial intelligence
		//input->VibrateControllers(frameTime); // handle controller vibration
	}
	RenderGame();

	//check for console key
	if (input->WasKeyPressed(Key::TILDE))
	{
		console->showHide();
		paused = console->getVisible(); // pause game when console is visible
	}
	ConsoleCommand();               // process user entered console command

	input->ReadControllers(); // read state of controllers

	// if Alt+Enter toggle fullscreen/window
	if (input->IsKeyDown(Key::ALT) && input->WasKeyPressed(Key::ENTER))
		SetDisplayMode(GraphicsNS::TOGGLE); // toggle fullscreen/window

	// if Esc key, set window mode
	//if (input->IsKeyDown(Key::ESC))
		//SetDisplayMode(GraphicsNS::WINDOW); // set window mode

	// Clear input
	// Call this after all key checks are done
	input->Clear(InputNS::KEYS_PRESSED);
}
Esempio n. 4
0
ConsoleCommand ConsoleModel::GetCurrentCommand()
{
	if(currentCommandIndex < 0 || currentCommandIndex >= previousCommands.size())
	{
		return ConsoleCommand("", 0, "");
	}
	return previousCommands[currentCommandIndex];
}
Esempio n. 5
0
void ABerserkGameMode::ExitGame()
{
	if (GEngine)
	{
		auto playerController = GEngine->GetFirstLocalPlayerController(GetWorld());
		if (playerController) playerController->ConsoleCommand(TEXT("quit"));
	}
}
Esempio n. 6
0
void ConsoleController::EvaluateCommand(std::string command)
{
	int returnCode = commandInterface->Command(command);
	if(command.length())
		consoleModel->AddLastCommand(ConsoleCommand(command, returnCode, commandInterface->GetLastError()));
	else
		if(ui::Engine::Ref().GetWindow() == consoleView)
			ui::Engine::Ref().CloseWindow();
}
Esempio n. 7
0
ConsoleModel::ConsoleModel() {
	std::vector<std::string> previousHistory = Client::Ref().GetPrefStringArray("Console.History");
	for(std::vector<std::string>::reverse_iterator iter = previousHistory.rbegin(), end = previousHistory.rend(); iter != end; ++iter)
	{
		if(previousCommands.size()<25)
		{
			previousCommands.push_front(ConsoleCommand(*iter, 0, ""));
			currentCommandIndex = previousCommands.size();
		}
	}
}
void ADebugCameraController::OnDeactivate( APlayerController* RestoredPC )
{
	// restore FreezeRendering command state
	if (bIsFrozenRendering) 
	{
		ConsoleCommand(TEXT("FreezeRendering"));
		bIsFrozenRendering = false;
	}

	DrawFrustum->SetVisibility(false);
	ConsoleCommand(TEXT("show camfrustums"));
	DrawFrustum->UnregisterComponent();
	RestoredPC->SetActorHiddenInGame(true);
	RestoredPC->PlayerCameraManager->SetActorHiddenInGame(true);

	OriginalControllerRef = NULL;
	OriginalPlayer = NULL;

	ChangeState(NAME_Inactive);
	GetWorld()->RemoveController(this);
}
void ConsoleController::EvaluateCommand(std::string command)
{
	if(command.length())
	{
		if (command.substr(0, 6) == "!load ")
			CloseConsole();
		int returnCode = commandInterface->Command(command);
		consoleModel->AddLastCommand(ConsoleCommand(command, returnCode, commandInterface->GetLastError()));
	}
	else
		CloseConsole();
}
Esempio n. 10
0
int baseq3_qagame_vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11  ) {
#else
int vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11  ) {
#endif // IOS
	switch ( command ) {
	case GAME_INIT:
		G_InitGame( arg0, arg1, arg2 );
		return 0;
	case GAME_SHUTDOWN:
		G_ShutdownGame( arg0 );
		return 0;
	case GAME_CLIENT_CONNECT:
		return (int)ClientConnect( arg0, arg1, arg2 );
	case GAME_CLIENT_THINK:
		ClientThink( arg0 );
		return 0;
	case GAME_CLIENT_USERINFO_CHANGED:
		ClientUserinfoChanged( arg0 );
		return 0;
	case GAME_CLIENT_DISCONNECT:
		ClientDisconnect( arg0 );
		return 0;
	case GAME_CLIENT_BEGIN:
		ClientBegin( arg0 );
		return 0;
	case GAME_CLIENT_COMMAND:
		ClientCommand( arg0 );
		return 0;
	case GAME_RUN_FRAME:
		G_RunFrame( arg0 );
		return 0;
	case GAME_CONSOLE_COMMAND:
		return ConsoleCommand();
	case BOTAI_START_FRAME:
		return BotAIStartFrame( arg0 );
	}

	return -1;
}


void QDECL G_Printf( const char *fmt, ... ) {
	va_list		argptr;
	char		text[1024];

	va_start (argptr, fmt);
	vsprintf (text, fmt, argptr);
	va_end (argptr);

	trap_Printf( text );
}
void ADebugCameraController::OnActivate( APlayerController* OriginalPC )
{
	// keep these around
	OriginalPlayer = OriginalPC->Player;
	OriginalControllerRef = OriginalPC;
	
	FVector OrigCamLoc;
	FRotator OrigCamRot;
	OriginalPC->GetPlayerViewPoint(OrigCamLoc, OrigCamRot);
	float const OrigCamFOV = OriginalPC->PlayerCameraManager->GetFOVAngle();

	ChangeState(NAME_Spectating);

	// start debug camera at original camera pos
	SetInitialLocationAndRotation(OrigCamLoc, OrigCamRot);

	if (PlayerCameraManager)
	{
		PlayerCameraManager->SetFOV( OrigCamFOV );
		PlayerCameraManager->UpdateCamera(0.0f);
	}

	// draw frustum of original camera (where you detached)
	if (DrawFrustum == NULL)
	{
		DrawFrustum = NewObject<UDrawFrustumComponent>(OriginalPC->PlayerCameraManager);
	}
	if (DrawFrustum)
	{
		DrawFrustum->SetVisibility(true);
		OriginalPC->SetActorHiddenInGame(false);
		OriginalPC->PlayerCameraManager->SetActorHiddenInGame(false);

		DrawFrustum->FrustumAngle = OrigCamFOV;
		DrawFrustum->SetAbsolute(true, true, false);
		DrawFrustum->SetRelativeLocation(OrigCamLoc);
		DrawFrustum->SetRelativeRotation(OrigCamRot);
		DrawFrustum->RegisterComponent();

		ConsoleCommand(TEXT("show camfrustums")); //called to render camera frustums from original player camera
	}

	GetWorld()->AddController(this);
}
/*
================
vmMain

This is the only way control passes into the module.
This must be the very first function compiled into the .q3vm file
================
*/
Q_EXPORT intptr_t vmMain( int command, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11  ) {
	switch ( command ) {
	case GAME_INIT:
		G_InitGame( arg0, arg1, arg2 );
		return 0;
	case GAME_SHUTDOWN:
		G_ShutdownGame( arg0 );
		return 0;
	case GAME_CLIENT_CONNECT:
		return (intptr_t)ClientConnect( arg0, arg1, arg2 );
	case GAME_CLIENT_THINK:
		ClientThink( arg0 );
		return 0;
	case GAME_CLIENT_USERINFO_CHANGED:
		ClientUserinfoChanged( arg0 );
		return 0;
	case GAME_CLIENT_DISCONNECT:
		ClientDisconnect( arg0 );
		return 0;
	case GAME_CLIENT_BEGIN:
		ClientBegin( arg0 );
		return 0;
	case GAME_CLIENT_COMMAND:
		ClientCommand( arg0 );
		return 0;
	case GAME_RUN_FRAME:
		G_RunFrame( arg0 );
		return 0;
	case GAME_CONSOLE_COMMAND:
		return ConsoleCommand();
	case BOTAI_START_FRAME:
		return BotAIStartFrame( arg0 );
	}

	return -1;
}
Esempio n. 13
0
bool
ServerGame::consoleCommand() const
{
	return ConsoleCommand();
}
Esempio n. 14
0
// Module RPC entry point
static void VMMain(int index, RPC::Reader& inputs, RPC::Writer& outputs)
{
	switch (index) {
	case GAME_INIT:
	{
		int levelTime = inputs.ReadInt();
		int randomSeed = inputs.ReadInt();
		qboolean restart = inputs.ReadInt();
		G_InitGame(levelTime, randomSeed, restart);
		break;
	}

	case GAME_SHUTDOWN:
		G_ShutdownGame(inputs.ReadInt());
		break;

	case GAME_CLIENT_CONNECT:
	{
		int clientNum = inputs.ReadInt();
		qboolean firstTime = inputs.ReadInt();
		qboolean isBot = inputs.ReadInt();
		const char* denied = isBot ? ClientBotConnect(clientNum, firstTime, TEAM_NONE) : ClientConnect(clientNum, firstTime);
		outputs.WriteInt(denied ? qtrue : qfalse);
		if (denied)
			outputs.WriteString(denied);
		break;
	}

	case GAME_CLIENT_THINK:
		ClientThink(inputs.ReadInt());
		break;

	case GAME_CLIENT_USERINFO_CHANGED:
		ClientUserinfoChanged(inputs.ReadInt(), qfalse);
		break;

	case GAME_CLIENT_DISCONNECT:
		ClientDisconnect(inputs.ReadInt());
		break;

	case GAME_CLIENT_BEGIN:
		ClientBegin(inputs.ReadInt());
		break;

	case GAME_CLIENT_COMMAND:
		ClientCommand(inputs.ReadInt());
		break;

	case GAME_RUN_FRAME:
		G_RunFrame(inputs.ReadInt());
		break;

	case GAME_CONSOLE_COMMAND:
		outputs.WriteInt(ConsoleCommand());
		break;

	case GAME_SNAPSHOT_CALLBACK:
		G_Error("GAME_SNAPSHOT_CALLBACK not implemented");
		break;

	case BOTAI_START_FRAME:
		G_Error("BOTAI_START_FRAME not implemented");
		break;

	case GAME_MESSAGERECEIVED:
		G_Error("GAME_MESSAGERECEIVED not implemented");
		break;

	default:
		G_Error("VMMain(): unknown game command %i", index);
	}
}
void ADebugCameraController::ToggleFreezeRendering()
{
	ConsoleCommand(TEXT("FreezeRendering"));
	bIsFrozenRendering = !bIsFrozenRendering;
}
Esempio n. 16
0
bool UConsole::InputKey_InputLine( int32 ControllerId, FKey Key, EInputEvent Event, float AmountDepressed, bool bGamepad)
{
	//`log(`location@`showvar(Key));

	if ( Event == IE_Pressed )
	{
		bCaptureKeyInput = false;
	}

	// cycle between console states
	bool bModifierDown = bCtrl;
	FModifierKeysState KeyState = FSlateApplication::Get().GetModifierKeys();
	bModifierDown |= KeyState.IsAltDown() || KeyState.IsCommandDown() || KeyState.IsShiftDown() || KeyState.IsControlDown();
	if ( GetDefault<UInputSettings>()->ConsoleKeys.Contains(Key) && Event == IE_Pressed && !bModifierDown )
	{
		if (ConsoleState == NAME_Typing)
		{
			FakeGotoState(NAME_Open);
			bCaptureKeyInput = true;
		}
		else if (ConsoleState == NAME_Open)
		{
			FakeGotoState(NAME_None);
			bCaptureKeyInput = true;
		}
		else if (ConsoleState == NAME_None)
		{
			FakeGotoState(NAME_Typing);
			bCaptureKeyInput = true;
		}
		return true;
	}

	// if user input is open
	if(ConsoleState != NAME_None)
	{
		if (ProcessControlKey(Key, Event))
		{
			return true;
		}
		else if( bGamepad )
		{
			return false;
		}
		else if( Key == EKeys::Escape && Event == IE_Released )
		{
			if( !TypedStr.IsEmpty() )
			{
				SetInputText("");
				SetCursorPos(0);

				AutoCompleteIndex = 0;
				AutoCompleteCursor = -1;
				AutoComplete.Empty();
				bAutoCompleteLocked = false;

				return true;
			}
			else
			{
				FakeGotoState( NAME_None );
			}

			return true;
		}
		else if (Key == EKeys::Tab && Event == IE_Pressed)
		{
			if (!bAutoCompleteLocked)
			{
				SetInputLineFromAutoComplete();
			}

			return true;
		}
		else if( Key == EKeys::Enter && Event == IE_Released )
		{
			if( !TypedStr.IsEmpty() )
			{
				// Make a local copy of the string.
				FString Temp=TypedStr;

				SetInputText(TEXT(""));
				SetCursorPos(0);

				ConsoleCommand(Temp);

				//OutputText( Localize("Errors","Exec","Core") );

				OutputText( TEXT("") );

				if(ConsoleState == NAME_Typing)
				{
					// close after each command when in typing mode (single line)
					FakeGotoState(NAME_None);
				}

				UpdateCompleteIndices();
			}
			else
			{
				FakeGotoState(NAME_None);
			}

			return true;
		}
		else if( Event != IE_Pressed && Event != IE_Repeat )
		{
			if( !bGamepad )
			{
				return	Key != EKeys::LeftMouseButton
					&&	Key != EKeys::MiddleMouseButton
					&&	Key != EKeys::RightMouseButton;
			}
			return false;
		}
		else if( Key == EKeys::Up )
		{
			if (!bCtrl)
			{
				if(AutoComplete.Num())
				{
					if(AutoCompleteCursor + 1 < FMath::Min((int32)MAX_AUTOCOMPLETION_LINES, AutoComplete.Num()))
					{
						// move cursor within displayed region
						++AutoCompleteCursor;
					}
					else 
					{
						// can be negative
						int32 ScrollRegionSize = AutoComplete.Num() - (int32)MAX_AUTOCOMPLETION_LINES;

						// can we scroll?
						if(AutoCompleteIndex + 1 < ScrollRegionSize)
						{
							++AutoCompleteIndex;
						}
					}
					SetInputLineFromAutoComplete();
				}
				else
				{
					SetAutoCompleteFromHistory();
					SetInputLineFromAutoComplete();
				}
			}
			return true;
		}
		else if( Key == EKeys::Down )
		{
			if (!bCtrl && AutoComplete.Num() > 1)
			{
				if(AutoCompleteCursor > 0)
				{
					// move cursor within displayed region
					--AutoCompleteCursor;
				}
				else
				{
					// can we scroll?
					if(AutoCompleteIndex > 0)
					{
						--AutoCompleteIndex;
					}
					bAutoCompleteLocked = false;
				}
				SetInputLineFromAutoComplete();
			}
		}
		else if( Key==EKeys::BackSpace )
		{
			if( TypedStrPos>0 )
			{
				SetInputText(FString::Printf(TEXT("%s%s"), *TypedStr.Left(TypedStrPos-1), *TypedStr.Right( TypedStr.Len() - TypedStrPos)));
				SetCursorPos(TypedStrPos-1);
				// unlock auto-complete (@todo - track the lock position so we don't bother unlocking under bogus cases)
				bAutoCompleteLocked = false;
			}

			return true;
		}
		else if ( Key== EKeys::Delete )
		{
			if ( TypedStrPos < TypedStr.Len() )
			{
				SetInputText(FString::Printf(TEXT("%s%s"), *TypedStr.Left(TypedStrPos), *TypedStr.Right( TypedStr.Len() - TypedStrPos - 1)));
			}
			return true;
		}
		else if ( Key==EKeys::Left )
		{
			if (bCtrl)
			{
				// find the nearest '.' or ' '
				int32 NewPos = FMath::Max(TypedStr.Find(TEXT("."), ESearchCase::CaseSensitive, ESearchDir::FromEnd, TypedStrPos),TypedStr.Find(TEXT(" "),ESearchCase::CaseSensitive, ESearchDir::FromEnd,TypedStrPos));
				SetCursorPos(FMath::Max(0,NewPos));
			}
			else
			{
				SetCursorPos(FMath::Max(0, TypedStrPos - 1));
			}
			return true;
		}
		else if ( Key==EKeys::Right )
		{
			if (bCtrl)
			{
				// find the nearest '.' or ' '
				int32 SpacePos = TypedStr.Find(TEXT(" "));
				int32 PeriodPos = TypedStr.Find(TEXT("."));
				// pick the closest valid index
				int32 NewPos = SpacePos < 0 ? PeriodPos : (PeriodPos < 0 ? SpacePos : FMath::Min(SpacePos,PeriodPos));
				// jump to end if nothing in between
				if (NewPos == INDEX_NONE)
				{
					NewPos = TypedStr.Len();
				}
				SetCursorPos(FMath::Min(TypedStr.Len(),FMath::Max(TypedStrPos,NewPos)));
			}
			else
			{
				SetCursorPos(FMath::Min(TypedStr.Len(), TypedStrPos + 1));
			}
			return true;
		}
		else if ( Key==EKeys::Home )
		{
			SetCursorPos(0);
			return true;
		}
		else if ( Key==EKeys::End )
		{
			SetCursorPos(TypedStr.Len());
			return true;
		}
		else
		{
			// auto complete is open and the user adds a key
			if (AutoComplete.Num() > 0 && !bAutoCompleteLocked && AutoCompleteCursor >= 0)
			{
				const FAutoCompleteCommand& Cmd = AutoComplete[AutoCompleteIndex + AutoCompleteCursor];

				TypedStr = Cmd.Command;
				SetCursorPos(TypedStr.Len());
				bAutoCompleteLocked = true;

				// no "return true" so that the following key will be added the auto completed string
			}
		}
	}

	return false;
}
Esempio n. 17
0
	void Console::addConsoleCommand(std::string str, void(*fnc)(std::vector<std::string>&))
	{
		commands.push_back(ConsoleCommand(str, fnc));
	}