Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
RoR::ServerScriptEngine Class Reference

Description

Definition at line 54 of file ServerScriptEngine.h.

Public Types

enum class  ThreadState
 

Public Member Functions

 ServerScriptEngine (ServerScriptSequencer *sequencer)
 
 ~ServerScriptEngine ()
 
int loadScript (std::string scriptName)
 
void unloadScript ()
 
AngelScript::asIScriptEngine * getEngine ()
 
void setException (const std::string &message)
 
void addCallback (const std::string &type, AngelScript::asIScriptFunction *func, AngelScript::asIScriptObject *obj)
 
void addCallbackScript (const std::string &type, const std::string &func, AngelScript::asIScriptObject *obj)
 
void deleteCallback (const std::string &type, AngelScript::asIScriptFunction *func, AngelScript::asIScriptObject *obj)
 
void deleteCallbackScript (const std::string &type, const std::string &_func, AngelScript::asIScriptObject *obj)
 
void deleteAllCallbacks ()
 
bool callbackExists (const std::string &type, AngelScript::asIScriptFunction *func, AngelScript::asIScriptObject *obj)
 
void EnsureTimerThreadRunning ()
 
void StopTimerThread ()
 
ThreadState GetTimerThreadState ()
 
callbacks
void playerDeleted (int uid, int crash=0)
 
void playerAdded (RoRnet::UserInfo &user)
 
int streamAdded (int uid, RoRnet::StreamRegister *reg)
 
int playerChat (int uid, std::string msg)
 
void gameCmd (int uid, const std::string &cmd)
 
void curlStatus (ServerScriptCurlStatusType type, int n1, int n2, std::string displayname, std::string message)
 
int frameStep (float dt)
 

Protected Member Functions

void init ()
 
void msgCallback (const AngelScript::asSMessageInfo *msg)
 
void ExceptionCallback (AngelScript::asIScriptContext *ctx, void *param)
 
void PrintVariables (AngelScript::asIScriptContext *ctx, int stackLevel)
 
void LineCallback (AngelScript::asIScriptContext *ctx, void *param)
 
void TimerThreadMain ()
 

Protected Attributes

ServerScriptSequencer * seq
 
AngelScript::asIScriptEngine * engine
 
AngelScript::asIScriptContext * context
 
std::map< std::string, callbackList > callbacks
 
std::thread m_timer_thread
 
ThreadState m_timer_thread_state = ThreadState::NOT_RUNNING
 
std::mutex m_timer_thread_mutex
 

Member Enumeration Documentation

◆ ThreadState

Enumerator
NOT_RUNNING 
RUNNING 
STOP_REQUESTED 

Definition at line 56 of file ServerScriptEngine.h.

Constructor & Destructor Documentation

◆ ServerScriptEngine()

ServerScriptEngine::ServerScriptEngine ( ServerScriptSequencer *  sequencer)

Definition at line 81 of file ServerScriptEngine.cpp.

◆ ~ServerScriptEngine()

ServerScriptEngine::~ServerScriptEngine ( )

Definition at line 89 of file ServerScriptEngine.cpp.

Member Function Documentation

◆ addCallback()

void ServerScriptEngine::addCallback ( const std::string &  type,
AngelScript::asIScriptFunction *  func,
AngelScript::asIScriptObject *  obj 
)

Adds a script callback.

Parameters
typeThe type of the callback. This can be one of the following: 'frameStep', 'playerChat', 'gameCmd', 'playerAdded', 'playerDeleted'.
funcA pointer to a script function.
objA pointer to the object of the method or NULL if func is a global function.

Definition at line 959 of file ServerScriptEngine.cpp.

◆ addCallbackScript()

void ServerScriptEngine::addCallbackScript ( const std::string &  type,
const std::string &  func,
AngelScript::asIScriptObject *  obj 
)

This method checks and converts the parameters and then adds a script callback.

Parameters
typeThe type of the callback.
See also
addCallback
Parameters
funcThe name of a script function.
objA pointer to the object of the method or NULL if func is a global function.

Definition at line 896 of file ServerScriptEngine.cpp.

◆ callbackExists()

bool ServerScriptEngine::callbackExists ( const std::string &  type,
AngelScript::asIScriptFunction *  func,
AngelScript::asIScriptObject *  obj 
)

This checks if a script callback exists.

Parameters
typeThe type of the callback.
See also
addCallback
Parameters
funcA pointer to a script function.
objA pointer to the object of the method or NULL if func is a global function.
Returns
true if the callback exists

Definition at line 1062 of file ServerScriptEngine.cpp.

◆ curlStatus()

void ServerScriptEngine::curlStatus ( ServerScriptCurlStatusType  type,
int  n1,
int  n2,
std::string  displayname,
std::string  message 
)

Params n1, n2 and message depend on status type :

  • CURL_STATUS_PROGRESS: n1 = bytes downloaded, n2 = total bytes, message = empty
  • CURL_STATUS_SUCCESS: n1 = CURL return code, n2 = HTTP result code, message = payload as string
  • CURL_STATUS_FAILURE: n1 = CURL return code, n2 = HTTP result code, message = CURL error string

Definition at line 802 of file ServerScriptEngine.cpp.

◆ deleteAllCallbacks()

void ServerScriptEngine::deleteAllCallbacks ( )

Deletes all script callbacks.

Definition at line 99 of file ServerScriptEngine.cpp.

◆ deleteCallback()

void ServerScriptEngine::deleteCallback ( const std::string &  type,
AngelScript::asIScriptFunction *  func,
AngelScript::asIScriptObject *  obj 
)

Deletes a script callback.

Parameters
typeThe type of the callback.
See also
addCallback
Parameters
funcA pointer to a script function.
objA pointer to the object of the method or NULL if func is a global function.

Definition at line 1046 of file ServerScriptEngine.cpp.

◆ deleteCallbackScript()

void ServerScriptEngine::deleteCallbackScript ( const std::string &  type,
const std::string &  _func,
AngelScript::asIScriptObject *  obj 
)

This method checks and converts the parameters and then deletes a script callback.

Parameters
typeThe type of the callback.
See also
addCallback
Parameters
funcThe name of a script function.
objA pointer to the object of the method or NULL if func is a global function.

Definition at line 985 of file ServerScriptEngine.cpp.

◆ EnsureTimerThreadRunning()

void ServerScriptEngine::EnsureTimerThreadRunning ( )

Definition at line 854 of file ServerScriptEngine.cpp.

◆ ExceptionCallback()

void ServerScriptEngine::ExceptionCallback ( AngelScript::asIScriptContext *  ctx,
void *  param 
)
protected

This callback gets called when an exception occurs in the script.

It logs the exception message together with the place in the script where the error occurs.

Parameters
ctxThe context in which the exception ocurred.
paramAn unused parameter.

Definition at line 229 of file ServerScriptEngine.cpp.

◆ frameStep()

int ServerScriptEngine::frameStep ( float  dt)

Definition at line 589 of file ServerScriptEngine.cpp.

◆ gameCmd()

void ServerScriptEngine::gameCmd ( int  uid,
const std::string &  cmd 
)

Definition at line 770 of file ServerScriptEngine.cpp.

◆ getEngine()

AngelScript::asIScriptEngine * RoR::ServerScriptEngine::getEngine ( )
inline

Gets the currently used AngelScript script engine.

Returns
a pointer to the currently used AngelScript script engine

Definition at line 100 of file ServerScriptEngine.h.

◆ GetTimerThreadState()

ServerScriptEngine::ThreadState ServerScriptEngine::GetTimerThreadState ( )

Definition at line 863 of file ServerScriptEngine.cpp.

◆ init()

void ServerScriptEngine::init ( )
protected

This function initialzies the engine and registeres all types.

Definition at line 317 of file ServerScriptEngine.cpp.

◆ LineCallback()

void ServerScriptEngine::LineCallback ( AngelScript::asIScriptContext *  ctx,
void *  param 
)
protected

unused

Definition at line 257 of file ServerScriptEngine.cpp.

◆ loadScript()

int ServerScriptEngine::loadScript ( std::string  scriptName)

Definition at line 113 of file ServerScriptEngine.cpp.

◆ msgCallback()

void ServerScriptEngine::msgCallback ( const AngelScript::asSMessageInfo *  msg)
protected

This is the callback function that gets called when script error occur.

When the script crashes, this function will provide you with more detail

Parameters
msgarguments that contain details about the crash
paramunkown?

Definition at line 579 of file ServerScriptEngine.cpp.

◆ playerAdded()

void ServerScriptEngine::playerAdded ( RoRnet::UserInfo &  user)

Definition at line 659 of file ServerScriptEngine.cpp.

◆ playerChat()

int ServerScriptEngine::playerChat ( int  uid,
std::string  msg 
)

Definition at line 730 of file ServerScriptEngine.cpp.

◆ playerDeleted()

void ServerScriptEngine::playerDeleted ( int  uid,
int  crash = 0 
)

Definition at line 624 of file ServerScriptEngine.cpp.

◆ PrintVariables()

void ServerScriptEngine::PrintVariables ( AngelScript::asIScriptContext *  ctx,
int  stackLevel 
)
protected

This logs all variables and their values at the specified stack level.

Parameters
ctxThe context that should be used.
stackLevelA number representing the level in the stack that should be logged.

Definition at line 277 of file ServerScriptEngine.cpp.

◆ setException()

void ServerScriptEngine::setException ( const std::string &  message)

Sets an exception that aborts the currently running script and shows the exception in the log file.

Parameters
messageA descriptive error message.

Definition at line 886 of file ServerScriptEngine.cpp.

◆ StopTimerThread()

void ServerScriptEngine::StopTimerThread ( )

Definition at line 868 of file ServerScriptEngine.cpp.

◆ streamAdded()

int ServerScriptEngine::streamAdded ( int  uid,
RoRnet::StreamRegister *  reg 
)

Definition at line 690 of file ServerScriptEngine.cpp.

◆ TimerThreadMain()

void ServerScriptEngine::TimerThreadMain ( )
protected

A loop that periodically the frameStep() script callback.

Definition at line 840 of file ServerScriptEngine.cpp.

◆ unloadScript()

void ServerScriptEngine::unloadScript ( )

Definition at line 212 of file ServerScriptEngine.cpp.

Field Documentation

◆ callbacks

std::map<std::string, callbackList> RoR::ServerScriptEngine::callbacks
protected

A map containing the script callbacks by type.

Definition at line 163 of file ServerScriptEngine.h.

◆ context

AngelScript::asIScriptContext* RoR::ServerScriptEngine::context
protected

context in which all scripting happens

Definition at line 162 of file ServerScriptEngine.h.

◆ engine

AngelScript::asIScriptEngine* RoR::ServerScriptEngine::engine
protected

instance of the scripting engine

Definition at line 161 of file ServerScriptEngine.h.

◆ m_timer_thread

std::thread RoR::ServerScriptEngine::m_timer_thread
protected

Definition at line 166 of file ServerScriptEngine.h.

◆ m_timer_thread_mutex

std::mutex RoR::ServerScriptEngine::m_timer_thread_mutex
protected

Definition at line 168 of file ServerScriptEngine.h.

◆ m_timer_thread_state

ThreadState RoR::ServerScriptEngine::m_timer_thread_state = ThreadState::NOT_RUNNING
protected

Definition at line 167 of file ServerScriptEngine.h.

◆ seq

ServerScriptSequencer* RoR::ServerScriptEngine::seq
protected

Definition at line 160 of file ServerScriptEngine.h.


The documentation for this class was generated from the following files: