mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 07:13:58 -05:00
add example module to game interface. convert gi command registration to a iw4madmin request
This commit is contained in:
@ -542,11 +542,11 @@ OnExecuteCommand( event )
|
||||
{
|
||||
if ( IsDefined( executionContextEntity ) )
|
||||
{
|
||||
response = executionContextEntity [[command]]( event, data );
|
||||
response = executionContextEntity thread [[command]]( event, data );
|
||||
}
|
||||
else
|
||||
{
|
||||
[[command]]( event );
|
||||
thread [[command]]( event );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -52,9 +52,9 @@ OnPlayerConnect()
|
||||
if ( player IsTestClient() )
|
||||
{
|
||||
// we don't want to track bots
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
player thread SetPersistentData();
|
||||
player thread WaitForClientEvents();
|
||||
}
|
||||
|
@ -49,11 +49,14 @@ Setup()
|
||||
level.eventTypes.urlRequested = "UrlRequested";
|
||||
level.eventTypes.urlRequestCompleted = "UrlRequestCompleted";
|
||||
level.eventTypes.registerCommandRequested = "RegisterCommandRequested";
|
||||
level.eventTypes.getCommandsRequested = "GetCommandsRequested";
|
||||
|
||||
level.eventCallbacks[level.eventTypes.urlRequestCompleted] = ::OnUrlRequestCompletedCallback;
|
||||
level.eventCallbacks[level.eventTypes.getCommandsRequested] = ::OnCommandsRequestedCallback;
|
||||
|
||||
level.iw4madminIntegrationDefaultPerformance = 200;
|
||||
level.notifyEntities = [];
|
||||
level.customCommands = [];
|
||||
|
||||
level notify( level.notifyTypes.sharedFunctionsInitialized );
|
||||
level waittill( level.notifyTypes.gameFunctionsInitialized );
|
||||
@ -194,6 +197,32 @@ SaveTrackingMetrics()
|
||||
|
||||
// #region register script command
|
||||
|
||||
OnCommandsRequestedCallback( event )
|
||||
{
|
||||
scripts\_integration_base::LogDebug( "Get commands requested" );
|
||||
thread SendCommands( event.data["name"] );
|
||||
}
|
||||
|
||||
SendCommands( commandName )
|
||||
{
|
||||
level endon( level.eventTypes.gameEnd );
|
||||
|
||||
for ( i = 0; i < level.customCommands.size; i++ )
|
||||
{
|
||||
data = level.customCommands[i];
|
||||
|
||||
if ( IsDefined( commandName ) && commandName != data["name"] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
scripts\_integration_base::LogDebug( "Sending custom command " + ( i + 1 ) + "/" + level.customCommands.size + ": " + data["name"] );
|
||||
commandRegisterRequest = scripts\_integration_base::BuildEventRequest( false, level.eventTypes.registerCommandRequested, "", undefined, data );
|
||||
// not threading here as there might be a lot of commands to register
|
||||
scripts\_integration_base::QueueEvent( commandRegisterRequest, level.eventTypes.registerCommandRequested, undefined );
|
||||
}
|
||||
}
|
||||
|
||||
RegisterScriptCommandObject( command )
|
||||
{
|
||||
RegisterScriptCommand( command.eventKey, command.name, command.alias, command.description, command.minPermission, command.supportedGames, command.requiresTarget, command.handler );
|
||||
@ -258,8 +287,7 @@ RegisterScriptCommand( eventKey, name, alias, description, minPermission, suppor
|
||||
scripts\_integration_base::LogWarning( "handler not defined for script command " + name );
|
||||
}
|
||||
|
||||
commandRegisterRequest = scripts\_integration_base::BuildEventRequest( false, level.eventTypes.registerCommandRequested, "", undefined, data );
|
||||
thread scripts\_integration_base::QueueEvent( commandRegisterRequest, level.eventTypes.registerCommandRequested, undefined );
|
||||
level.customCommands[level.customCommands.size] = data;
|
||||
}
|
||||
|
||||
// #end region
|
||||
@ -391,7 +419,6 @@ GetNextNotifyEntity()
|
||||
return max;
|
||||
}
|
||||
|
||||
|
||||
// #end region
|
||||
|
||||
// #region team balance
|
||||
|
85
GameFiles/GameInterface/example_module.gsc
Normal file
85
GameFiles/GameInterface/example_module.gsc
Normal file
@ -0,0 +1,85 @@
|
||||
Init()
|
||||
{
|
||||
// this gives the game interface time to setup
|
||||
waittillframeend;
|
||||
thread ModuleSetup();
|
||||
}
|
||||
|
||||
ModuleSetup()
|
||||
{
|
||||
// waiting until the game specific functions are ready
|
||||
level waittill( level.notifyTypes.gameFunctionsInitialized );
|
||||
|
||||
RegisterCustomCommands();
|
||||
}
|
||||
|
||||
RegisterCustomCommands()
|
||||
{
|
||||
command = SpawnStruct();
|
||||
|
||||
// unique key for each command (how iw4madmin identifies the command)
|
||||
command.eventKey = "PrintLineCommand";
|
||||
|
||||
// name of the command (cannot conflict with existing command names)
|
||||
command.name = "println";
|
||||
|
||||
// short version of the command (cannot conflcit with existing command aliases)
|
||||
command.alias = "pl";
|
||||
|
||||
// description of what the command does
|
||||
command.description = "prints line to game";
|
||||
|
||||
// minimum permision required to execute
|
||||
// valid values: User, Trusted, Moderator, Administrator, SeniorAdmin, Owner
|
||||
command.minPermission = "Trusted";
|
||||
|
||||
// games the command is supported on
|
||||
// separate with comma or don't define for all
|
||||
// valid values: IW3, IW4, IW5, IW6, T4, T5, T6, T7, SHG1, CSGO, H1
|
||||
command.supportedGames = "IW4,IW5,T5,T6";
|
||||
|
||||
// indicates if a target player must be provided to execvute on
|
||||
command.requiresTarget = false;
|
||||
|
||||
// code to run when the command is executed
|
||||
command.handler = ::PrintLnCommandCallback;
|
||||
|
||||
// register the command with integration to be send to iw4madmin
|
||||
scripts\_integration_shared::RegisterScriptCommandObject( command );
|
||||
|
||||
// you can also register via parameters
|
||||
scripts\_integration_shared::RegisterScriptCommand( "AffirmationCommand", "affirm", "af", "provide affirmations", "User", undefined, false, ::AffirmationCommandCallback );
|
||||
}
|
||||
|
||||
PrintLnCommandCallback( event )
|
||||
{
|
||||
if ( IsDefined( event.data["args"] ) )
|
||||
{
|
||||
IPrintLnBold( event.data["args"] );
|
||||
return;
|
||||
}
|
||||
|
||||
scripts\_integration_base::LogDebug( "No data was provided for PrintLnCallback" );
|
||||
}
|
||||
|
||||
AffirmationCommandCallback( event, _ )
|
||||
{
|
||||
level endon( level.eventTypes.gameEnd );
|
||||
|
||||
request = SpawnStruct();
|
||||
request.url = "https://www.affirmations.dev";
|
||||
request.method = "GET";
|
||||
|
||||
// If making a post request you can also provide more data
|
||||
// request.body = "Body of the post message";
|
||||
// request.headers = [];
|
||||
// request.headers["Authorization"] = "api-key";
|
||||
|
||||
scripts\_integration_shared::RequestUrlObject( request );
|
||||
request waittill( level.eventTypes.urlRequestCompleted, response );
|
||||
|
||||
// horrible json parsing.. but it's just an example
|
||||
parsedResponse = strtok( response, "\"" );
|
||||
|
||||
self IPrintLnBold ( "^5" + parsedResponse[parsedResponse.size - 2] );
|
||||
}
|
Reference in New Issue
Block a user