forked from Relicta-Team/ReSDK_A3.vr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverRpc_init.sqf
170 lines (129 loc) · 4.24 KB
/
serverRpc_init.sqf
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// ======================================================
// Copyright (c) 2017-2024 the ReSDK_A3 project
// sdk.relicta.ru
// ======================================================
#include <..\engine.hpp>
#define log_server_rpc
#ifndef ENABLE_RPCLOG_CONSOLE_SERVER
#undef log_server_rpc
#endif
#ifdef RELEASE
#undef log_server_rpc
#endif
#define DISABLED_RPC_LOG ["onupdch","onupdob"]
#define canlog(eventname,code) if !((toLower eventname) in DISABLED_RPC_LOG) then {code}
#define debugprint_type "debug_console" callExtension
#ifdef __VM_VALIDATE
#define debugprint_type diag_log
#endif
#ifdef log_server_rpc
#define rpc_log(event,owner,args) canlog(event,debugprint_type format['[NET::LOG::SERVER]: <%1> send %4 bytes to (%2) with %3' arg event arg owner arg args arg args call oop_getTypeSizeFull]; ["<%1> send %4 bytes to (%2) with %3" arg event arg owner arg args arg args call oop_getTypeSizeFull] call logInfo)
#define rpc_simple(data) debugprint_type format['[NET::LOG]: %1' arg data]; ["<RPC::Simple> %1" arg data] call logInfo
#else
#define rpc_log(event,owner,args)
#define rpc_simple(data)
#endif
#define EMULATE_SERVERINDEBUG
server_addEvent = {
params ["_eventName","_eventCode"];
rpc_simple("Added RPC - " + _eventName);
["server_" + _eventName,_eventCode] call cba_fnc_addEventHandler
};
server_removeEvent = {
params ["_eventName","_eventId"];
["server_" + _eventName,_eventId] call CBA_fnc_removeeventhandler
};
rpc_removeEventGlobal = {
params ["_eventName","_eventId"];
[_eventName,_eventId] call CBA_fnc_removeeventhandler
};
server_callEvent = {
params ["_eventName","_args"];
["server_" + _eventName,_args] call CBA_fnc_localEvent
};
server_sendtoclient = {
params ["_clientId","_eventName","_args"];
#ifdef ENABLE_LAG_NETWORK
private _c = {
params ["_clientId","_eventName","_args"];
#endif
rpc_log(_eventName,_clientId,_args);
["client_" + _eventName,_args,_clientId] call CBA_fnc_ownerEvent;
#ifdef ENABLE_LAG_NETWORK
}; invokeAfterDelayParams(_c,__LAG_NETWORK_GET_LAG__,_this);
#endif
};
server_sendtoclientobject = {
params ["_clientobj","_eventName","_args"];
// fix isplayer
if (owner _clientobj <= 3 && isMultiplayer) exitWith {
traceformat("skip sending packets. Rpc: %1; args %2",_eventName arg _args)
};
if equals(_clientobj,objNull) exitWith {
errorformat("Server::rpcSendToObject() - client object is null reference. Rpc name - %1; data %2",_eventName arg _args);
};
#ifdef ENABLE_LAG_NETWORK
private _c = {
params ["_clientobj","_eventName","_args"];
#endif
rpc_log(_eventName,_clientobj,_args);
if (isMultiplayer) then {
#ifdef ENABLE_LAG_NETWORK
private _c = {
params ["_clientobj","_eventName","_args"];
["client_" + _eventName,_args,_clientobj] call CBA_fnc_targetEvent
}; invokeAfterDelayParams(_c,__LAG_NETWORK_GET_LAG__,_this);
#else
["client_" + _eventName,_args,_clientobj] call CBA_fnc_targetEvent
#endif
} else {
#ifdef EMULATE_SERVERINDEBUG
if (_clientobj isEqualTo player) then {
["client_" + _eventName,_args,_clientobj] call CBA_fnc_targetEvent;
};
#else
["client_" + _eventName,_args,_clientobj] call CBA_fnc_targetEvent;
#endif
};
#ifdef ENABLE_LAG_NETWORK
}; invokeAfterDelayParams(_c,__LAG_NETWORK_GET_LAG__,_this);
#endif
};
server_sendtoallclients = {
params ["_eventName","_args"];
#ifdef ENABLE_LAG_NETWORK
private _c = {
params ["_eventName","_args"];
#endif
rpc_log(_eventName,'ALL CLIENTS',_args);
["client_" + _eventName,_args] call CBA_fnc_globalEvent;
#ifdef ENABLE_LAG_NETWORK
}; invokeAfterDelayParams(_c,__LAG_NETWORK_GET_LAG__,_this);
#endif
};
rpc_sendGlobal = {
params ["_eventName","_args"];
#ifdef ENABLE_LAG_NETWORK
private _c = {
params ["_eventName","_args"];
#endif
rpc_log(_eventName,'GLOBAL',_args);
if (isMultiplayer) then {
[_eventName,_args] call CBA_fnc_globalEvent
} else {
[_eventName,_args] call CBA_fnc_localEvent
};
#ifdef ENABLE_LAG_NETWORK
}; invokeAfterDelayParams(_c,__LAG_NETWORK_GET_LAG__,_this);
#endif
};
#ifdef DEBUG
rpc_getClientEvent = {
params ["_name"];
cba_events_eventNamespace getVariable ["client_" + _name,[]];
};
rpc_getServerEvent = {
params ["_name"];
cba_events_eventNamespace getVariable ["server_" + _name,[]];
};
#endif