blob: a51e528f6a90844a5ea02d0d0b3155b3d5e31f96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
|