Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocompletion added #10

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Source/DedicatedServer/Private/DedicatedServer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright 2004-2016 YaS-Online, Inc. All Rights Reserved.

#include "DedicatedServer.h"
#include "DedicatedServerPrivatePCH.h"
#include "ServerConsole.h"

#include "Http.h"
#include "OnlineSubsystemSteam.h"


DEFINE_LOG_CATEGORY( LogDedicatedServer );

Expand Down
13 changes: 0 additions & 13 deletions Source/DedicatedServer/Private/DedicatedServerPrivatePCH.h

This file was deleted.

21 changes: 20 additions & 1 deletion Source/DedicatedServer/Private/ServerConsole.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2004-2016 YaS-Online, Inc. All Rights Reserved.

#include "ServerConsole.h"
#include "DedicatedServer.h"
#include "DedicatedServerPrivatePCH.h"

DEFINE_LOG_CATEGORY( LogServerConsole );

Expand Down Expand Up @@ -58,6 +58,7 @@ void DumpConsoleHelp()
{
m_pConsole = static_cast<FOutputDeviceConsolePlatform*>( GLogConsole );
m_iCommandHistoryIndex = -1;
m_bRepeatedTab = false;

#if PLATFORM_WINDOWS
m_hOutputHandle = INVALID_HANDLE_VALUE;
Expand Down Expand Up @@ -124,4 +125,22 @@ void DumpConsoleHelp()
{
Serialize( sData, eVerbosity, sCategory, -1.0 );
}

void FServerConsole::InitLocalConsoleCommandsArray()
{
// Do once
if ( !m_hLocalConsoleCommandLibrary.Num() )
{
auto OnConsoleVariable = [this]( const TCHAR *Name, IConsoleObject* CVar )
{
m_hLocalConsoleCommandLibrary.Add( Name );
};

// Missing 183 commands that are directly parsed. Not available without modification to the engine code.
// See UGameEngine::Exec for some of them. They only getm stored in GConsoleCommandLibrary if you use DumpConsoleCommands
IConsoleManager::Get().ForEachConsoleObjectThatStartsWith( FConsoleObjectVisitor::CreateLambda( OnConsoleVariable ) );

m_hLocalConsoleCommandLibrary.Sort( TLess<FString>() );
}
}
#endif
3 changes: 2 additions & 1 deletion Source/DedicatedServer/Private/ServerConsoleLinux.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2004-2016 YaS-Online, Inc. All Rights Reserved.

#include "DedicatedServerPrivatePCH.h"
#include "ServerConsole.h"


void DumpConsoleHelp();

Expand Down
3 changes: 2 additions & 1 deletion Source/DedicatedServer/Private/ServerConsoleMac.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2004-2016 YaS-Online, Inc. All Rights Reserved.

#include "DedicatedServerPrivatePCH.h"
#include "ServerConsole.h"


void DumpConsoleHelp();

Expand Down
86 changes: 81 additions & 5 deletions Source/DedicatedServer/Private/ServerConsoleWindows.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright 2004-2016 YaS-Online, Inc. All Rights Reserved.

#include "DedicatedServerPrivatePCH.h"
#include "Engine/World.h"
#include "Engine/Console.h"
#include "ServerConsole.h"
#include "GameFramework/GameModeBase.h"

void DumpConsoleHelp();

Expand Down Expand Up @@ -40,6 +39,12 @@ void DumpConsoleHelp();
{
KEY_EVENT_RECORD hEvent = hInputEvents[0].Event.KeyEvent;

if ( hEvent.wVirtualKeyCode != VK_TAB && hEvent.wVirtualKeyCode != VK_SHIFT )
{
// For AutoCompletion
m_bRepeatedTab = false;
}

if( hEvent.wVirtualKeyCode == VK_RETURN )
{
FScopeLock hLock( &m_hLock );
Expand Down Expand Up @@ -78,7 +83,7 @@ void DumpConsoleHelp();

m_hCommandHistory.Add( sInput );
}
else
else if ( !sInput.IsEmpty() )
{
FCString::Sprintf( sOutput, TEXT( "Unknown Command: %s%s" ), *sInput, LINE_TERMINATOR );
::WriteConsole( m_hOutputHandle, sOutput, FCString::Strlen( sOutput ), &iCharsWritten, NULL );
Expand Down Expand Up @@ -112,7 +117,78 @@ void DumpConsoleHelp();
{
FScopeLock hLock( &m_hLock );

// ToDo: AutoCompletion
// AutoCompletion section

// Do the initialization late, so late registrations are captured
// Alternatively it can be done in FServerConsole::Show
InitLocalConsoleCommandsArray();

static uint32 iMaxIndex = m_hLocalConsoleCommandLibrary.Num();

if ( iMaxIndex == 0 )
{
// Avoiding division by zero in a project with zero console commands
return;
}

if ( !m_bRepeatedTab )
{
//Reset the index and get current input
m_iCurrentIndex = 0;
m_sAutocompleteInput = m_sInput;
m_bRepeatedTab = true;
}
else if ( hEvent.dwControlKeyState & SHIFT_PRESSED )
{
// Reverse the order, shift is pressed
if ( m_iCurrentIndex != 0 )
{
--m_iCurrentIndex;
}
else
{
// Loop around to the end
m_iCurrentIndex = iMaxIndex - 1;
}
}
else
{
m_iCurrentIndex = (m_iCurrentIndex + 1) % iMaxIndex;
}

bool bLoopAroundOnce = false;
while ( m_iCurrentIndex < iMaxIndex )
{
if ( m_hLocalConsoleCommandLibrary[m_iCurrentIndex].StartsWith( m_sAutocompleteInput ) )
{
m_sInput = m_hLocalConsoleCommandLibrary[m_iCurrentIndex];
RedrawInputLine();

break;
}

if ( hEvent.dwControlKeyState & SHIFT_PRESSED )
{
--m_iCurrentIndex;
}
else
{
++m_iCurrentIndex;
}

if ( !bLoopAroundOnce && m_iCurrentIndex > iMaxIndex )
{
// Reverse order, loop around to the end
bLoopAroundOnce = true;
m_iCurrentIndex = iMaxIndex - 1;
}
else if ( !bLoopAroundOnce && m_iCurrentIndex == iMaxIndex )
{
// Loop around to the start
bLoopAroundOnce = true;
m_iCurrentIndex = 0;
}
}
}
else if( hEvent.wVirtualKeyCode == VK_UP )
{
Expand Down
10 changes: 10 additions & 0 deletions Source/DedicatedServer/Public/ServerConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ DECLARE_LOG_CATEGORY_EXTERN( LogServerConsole, Log, All );
FOutputDeviceConsolePlatform* m_pConsole;
FString m_sInput;
FString m_sUserInput;

// AutoCompletion
void InitLocalConsoleCommandsArray();
FString m_sAutocompleteInput;
bool m_bRepeatedTab;
bool m_bShiftPressed;
uint32 m_iCurrentIndex;
TArray<FString> m_hLocalConsoleCommandLibrary;

// History
TArray<FString> m_hCommandHistory;
int32 m_iCommandHistoryIndex;

Expand Down