aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers
diff options
context:
space:
mode:
Diffstat (limited to 'Northstar.CustomServers')
-rw-r--r--Northstar.CustomServers/mod.json7
-rw-r--r--Northstar.CustomServers/mod/scripts/vscripts/sh_server_to_client_stringcommands.gnut52
2 files changed, 59 insertions, 0 deletions
diff --git a/Northstar.CustomServers/mod.json b/Northstar.CustomServers/mod.json
index 00dd06bc0..172bff117 100644
--- a/Northstar.CustomServers/mod.json
+++ b/Northstar.CustomServers/mod.json
@@ -92,6 +92,13 @@
"RunOn": "(CLIENT || SERVER) && MP"
},
{
+ "Path": "sh_server_to_client_stringcommands.gnut",
+ "RunOn": "CLIENT || SERVER",
+ "ClientCallback": {
+ "After": "ServerToClientStringCommands_Init"
+ }
+ },
+ {
"Path": "gamemodes/_gamemode_fra.nut",
"RunOn": "SERVER && MP",
"ServerCallback": {
diff --git a/Northstar.CustomServers/mod/scripts/vscripts/sh_server_to_client_stringcommands.gnut b/Northstar.CustomServers/mod/scripts/vscripts/sh_server_to_client_stringcommands.gnut
new file mode 100644
index 000000000..a51e528f6
--- /dev/null
+++ b/Northstar.CustomServers/mod/scripts/vscripts/sh_server_to_client_stringcommands.gnut
@@ -0,0 +1,52 @@
+#if CLIENT
+global function ServerToClientStringCommands_Init
+
+global function AddServerToClientStringCommandCallback
+global function NSClientCodeCallback_RecievedServerToClientStringCommand
+#endif
+
+#if SERVER
+global function ServerToClientStringCommand
+#endif
+
+#if CLIENT
+struct {
+ table< string, array< void functionref( array<string> args ) > > callbacks
+} file
+
+void function ServerToClientStringCommands_Init()
+{
+ getroottable().rawset( "NSClientCodeCallback_RecievedServerToClientStringCommand", NSClientCodeCallback_RecievedServerToClientStringCommand )
+}
+
+void function AddServerToClientStringCommandCallback( string command, void functionref( array<string> args ) callback )
+{
+ if ( !( command in file.callbacks ) )
+ file.callbacks[ command ] <- []
+
+ file.callbacks[ command ].append( callback )
+}
+
+void function NSClientCodeCallback_RecievedServerToClientStringCommand( string cmd )
+{
+ array<string> args = split( cmd, " " )
+ if ( args.len() == 0 )
+ return
+
+ string callbackName = args[ 0 ]
+ args.remove( 0 )
+
+ if ( callbackName in file.callbacks )
+ {
+ foreach ( void functionref( array<string> args ) callback in file.callbacks[ callbackName ] )
+ callback( args )
+ }
+}
+#endif
+
+#if SERVER
+void function ServerToClientStringCommand( entity player, string command )
+{
+ ClientCommand( player, "ns_script_servertoclientstringcommand " + command )
+}
+#endif \ No newline at end of file