Skip to content
Merged
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
33 changes: 23 additions & 10 deletions source/cConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,16 +992,7 @@ auto CConsole::Process(std::int32_t c) -> void
{
if( toFind->second.isEnabled )
{
cScript *toExecute = JSMapping->GetScript( toFind->second.scriptId );
if( toExecute )
{
// All commands that execute are of the form: command_commandname (to avoid possible clashes)
#if defined( UOX_DEBUG_MODE )
Print( oldstrutil::format( "Executing JS keystroke %c %s\n", c, toFind->second.cmdName.c_str() ));
#endif
JS::Value eventRetVal;
[[maybe_unused]] bool retVal = toExecute->CallParticularEvent( toFind->second.cmdName.c_str(), nullptr, 0, &eventRetVal );
}
messageLoop.NewMessage( MSG_CONSOLEJS, oldstrutil::number( c ));
return;
}
}
Expand Down Expand Up @@ -1393,6 +1384,28 @@ auto CConsole::DisplaySettings() -> void
(*this) << " -MessageBoards: " << cwmWorldState->ServerData()->Directory( CSDDP_MSGBOARD ) << myendl;
}

//o------------------------------------------------------------------------------------------------o
//| Function - CConsole::ExecuteJSCommand()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Executes a registered JavaScript console command on the main server thread
//o------------------------------------------------------------------------------------------------o
auto CConsole::ExecuteJSCommand( SI32 key ) -> void
{
auto toFind = JSKeyHandler.find( key );
if( toFind == JSKeyHandler.end() || !toFind->second.isEnabled )
return;

cScript *toExecute = JSMapping->GetScript( toFind->second.scriptId );
if( toExecute != nullptr )
{
#if defined( UOX_DEBUG_MODE )
Print( oldstrutil::format( "Executing JS keystroke %c %s\n", key, toFind->second.cmdName.c_str() ));
#endif
JS::Value eventRetVal;
[[maybe_unused]] bool retVal = toExecute->CallParticularEvent( toFind->second.cmdName.c_str(), nullptr, 0, &eventRetVal );
}
}

//o------------------------------------------------------------------------------------------------o
//| Function - void RegisterKey()
//o------------------------------------------------------------------------------------------------o
Expand Down
1 change: 1 addition & 0 deletions source/cConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class CConsole
auto SetKeyStatus( std::int32_t key, bool isEnabled ) -> void;
auto SetFuncStatus( const std::string &key, bool isEnabled ) -> void;
auto Registration() -> void;
auto ExecuteJSCommand( std::int32_t key ) -> void;

private:
auto Reset() -> void;
Expand Down
1 change: 1 addition & 0 deletions source/cThreadQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum MessageType
MSG_SECTIONBEGIN,
MSG_RELOAD,
MSG_RESTART,
MSG_CONSOLEJS,
MSG_COUNT
};

Expand Down
3 changes: 3 additions & 0 deletions source/uox3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,9 @@ auto DoMessageLoop() -> void
g_bPerformRestart = true;
cwmWorldState->SetKeepRun( false ); // This triggers the main loop to exit
break;
case MSG_CONSOLEJS:
Console.ExecuteJSCommand( oldstrutil::value<SI32>( tVal.data ));
break;
case MSG_COUNT: break;
case MSG_WORLDSAVE: cwmWorldState->SetOldTime( 0 ); break;
case MSG_PRINT: Console << tVal.data << myendl; break;
Expand Down
Loading