/
init.sqf
213 lines (178 loc) · 8.32 KB
/
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "script_macros.hpp"
/*
File: init.sqf
Author: Bryan "Tonic" Boardwine
Edit: Nanou for HeadlessClient optimization.
Please read support for more informations.
Description:
Initialize the server and required systems.
*/
private ["_dome","_rsb","_timeStamp"];
DB_Async_Active = false;
DB_Async_ExtraLock = false;
life_server_isReady = false;
life_server_extDB_notLoaded = "";
serv_sv_use = [];
publicVariable "life_server_isReady";
life_save_civilian_position = if (LIFE_SETTINGS(getNumber,"save_civilian_position") isEqualTo 0) then {false} else {true};
fn_whoDoneIt = compile preprocessFileLineNumbers "\life_server\Functions\Systems\fn_whoDoneIt.sqf";
/*
Prepare the headless client.
*/
life_HC_isActive = false;
publicVariable "life_HC_isActive";
HC_Life = false;
publicVariable "HC_Life";
if (EXTDB_SETTING(getNumber,"HeadlessSupport") isEqualTo 1) then {
[] execVM "\life_server\initHC.sqf";
};
/*
Prepare extDB before starting the initialization process
for the server.
*/
if (isNil {uiNamespace getVariable "life_sql_id"}) then {
life_sql_id = round(random(9999));
CONSTVAR(life_sql_id);
uiNamespace setVariable ["life_sql_id",life_sql_id];
try {
_result = EXTDB format ["9:ADD_DATABASE:%1",EXTDB_SETTING(getText,"DatabaseName")];
if (!(_result isEqualTo "[1]")) then {throw "extDB2: Error with Database Connection"};
_result = EXTDB format ["9:ADD_DATABASE_PROTOCOL:%2:SQL_RAW_V2:%1:ADD_QUOTES",FETCH_CONST(life_sql_id),EXTDB_SETTING(getText,"DatabaseName")];
if (!(_result isEqualTo "[1]")) then {throw "extDB2: Error with Database Connection"};
} catch {
diag_log _exception;
life_server_extDB_notLoaded = [true, _exception];
};
publicVariable "life_server_extDB_notLoaded";
if (life_server_extDB_notLoaded isEqualType []) exitWith {};
EXTDB "9:LOCK";
diag_log "extDB2: Connected to Database";
} else {
life_sql_id = uiNamespace getVariable "life_sql_id";
CONSTVAR(life_sql_id);
diag_log "extDB2: Still Connected to Database";
};
if (life_server_extDB_notLoaded isEqualType []) exitWith {};
/* Run stored procedures for SQL side cleanup */
["CALL resetLifeVehicles",1] call DB_fnc_asyncCall;
["CALL deleteDeadVehicles",1] call DB_fnc_asyncCall;
["CALL deleteOldHouses",1] call DB_fnc_asyncCall;
["CALL deleteOldGangs",1] call DB_fnc_asyncCall;
_timeStamp = diag_tickTime;
diag_log "----------------------------------------------------------------------------------------------------";
diag_log "---------------------------------- Starting Altis Life Server Init ---------------------------------";
diag_log "------------------------------------------ Version 4.5 -------------------------------------------";
diag_log "----------------------------------------------------------------------------------------------------";
if (LIFE_SETTINGS(getNumber,"save_civilian_position_restart") isEqualTo 1) then {
[] spawn {
_query = "UPDATE players SET civ_alive = '0' WHERE civ_alive = '1'";
[_query,1] call DB_fnc_asyncCall;
};
};
/* Map-based server side initialization. */
master_group attachTo[bank_obj,[0,0,0]];
{
_hs = createVehicle ["Land_Hospital_main_F", [0,0,0], [], 0, "NONE"];
_hs setDir (markerDir _x);
_hs setPosATL (getMarkerPos _x);
_var = createVehicle ["Land_Hospital_side1_F", [0,0,0], [], 0, "NONE"];
_var attachTo [_hs, [4.69775,32.6045,-0.1125]];
detach _var;
_var = createVehicle ["Land_Hospital_side2_F", [0,0,0], [], 0, "NONE"];
_var attachTo [_hs, [-28.0336,-10.0317,0.0889387]];
detach _var;
if (worldName isEqualTo "Tanoa") then {
if (_forEachIndex isEqualTo 0) then {
atm_hospital_2 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
vendor_hospital_2 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
"medic_spawn_3" setMarkerPos (_var modelToWorld [8.01172,-5.47852,-8.20022]);
"med_car_2" setMarkerPos (_var modelToWorld [8.01172,-5.47852,-8.20022]);
hospital_assis_2 setPos (_hs modelToWorld [0.0175781,0.0234375,-0.231956]);
} else {
atm_hospital_3 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
vendor_hospital_3 setPos (_var modelToWorld [4.48633,0.438477,-8.25683]);
"medic_spawn_1" setMarkerPos (_var modelToWorld [-1.85181,-6.07715,-8.24944]);
"med_car_1" setMarkerPos (_var modelToWorld [5.9624,11.8799,-8.28493]);
hospital_assis_2 setPos (_hs modelToWorld [0.0175781,0.0234375,-0.231956]);
};
};
} forEach ["hospital_2","hospital_3"];
{
if (!isPlayer _x) then {
_npc = _x;
{
if (_x != "") then {
_npc removeWeapon _x;
};
} forEach [primaryWeapon _npc,secondaryWeapon _npc,handgunWeapon _npc];
};
} forEach allUnits;
[8,true,12] execFSM "\life_server\FSM\timeModule.fsm";
life_adminLevel = 0;
life_medicLevel = 0;
life_copLevel = 0;
CONST(JxMxE_PublishVehicle,"false");
/* Setup radio channels for west/independent/civilian */
life_radio_west = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
life_radio_civ = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
life_radio_indep = radioChannelCreate [[0, 0.95, 1, 0.8], "Side Channel", "%UNIT_NAME", []];
/* Set the amount of gold in the federal reserve at mission start */
fed_bank setVariable ["safe",count playableUnits,true];
[] spawn TON_fnc_federalUpdate;
/* Event handler for disconnecting players */
addMissionEventHandler ["HandleDisconnect",{_this call TON_fnc_clientDisconnect; false;}];
[] call compile preprocessFileLineNumbers "\life_server\functions.sqf";
/* Set OwnerID players for Headless Client */
TON_fnc_requestClientID =
{
(_this select 1) setVariable ["life_clientID", owner (_this select 1), true];
};
"life_fnc_RequestClientId" addPublicVariableEventHandler TON_fnc_requestClientID;
/* Event handler for logs */
"money_log" addPublicVariableEventHandler {diag_log (_this select 1)};
"advanced_log" addPublicVariableEventHandler {diag_log (_this select 1)};
/* Miscellaneous mission-required stuff */
life_wanted_list = [];
cleanupFSM = [] execFSM "\life_server\FSM\cleanup.fsm";
[] spawn {
for "_i" from 0 to 1 step 0 do {
uiSleep (30 * 60);
{
_x setVariable ["sellers",[],true];
} forEach [Dealer_1,Dealer_2,Dealer_3];
};
};
[] spawn TON_fnc_initHouses;
cleanup = [] spawn TON_fnc_cleanup;
TON_fnc_playtime_values = [];
TON_fnc_playtime_values_request = [];
//Just incase the Headless Client connects before anyone else
publicVariable "TON_fnc_playtime_values";
publicVariable "TON_fnc_playtime_values_request";
/* Setup the federal reserve building(s) */
private _vaultHouse = [[["Altis", "Land_Research_house_V1_F"], ["Tanoa", "Land_Medevac_house_V1_F"]]] call life_fnc_terrainSort;
private _altisArray = [16019.5,16952.9,0];
private _tanoaArray = [11074.2,11501.5,0.00137329];
private _pos = [[["Altis", _altisArray], ["Tanoa", _tanoaArray]]] call life_fnc_terrainSort;
_dome = nearestObject [_pos,"Land_Dome_Big_F"];
_rsb = nearestObject [_pos,_vaultHouse];
for "_i" from 1 to 3 do {_dome setVariable [format ["bis_disabled_Door_%1",_i],1,true]; _dome animate [format ["Door_%1_rot",_i],0];};
_dome setVariable ["locked",true,true];
_rsb setVariable ["locked",true,true];
_rsb setVariable ["bis_disabled_Door_1",1,true];
_dome allowDamage false;
_rsb allowDamage false;
/* Tell clients that the server is ready and is accepting queries */
life_server_isReady = true;
publicVariable "life_server_isReady";
/* Initialize hunting zone(s) */
aiSpawn = ["hunting_zone",30] spawn TON_fnc_huntingZone;
// We create the attachment point to be used for objects to attachTo load virtually in vehicles.
life_attachment_point = "Land_HelipadEmpty_F" createVehicle [0,0,0];
life_attachment_point setPosASL [0,0,0];
life_attachment_point setVectorDirAndUp [[0,1,0], [0,0,1]];
// Sharing the point of attachment with all players.
publicVariable "life_attachment_point";
diag_log "----------------------------------------------------------------------------------------------------";
diag_log format [" End of Altis Life Server Init :: Total Execution Time %1 seconds ",(diag_tickTime) - _timeStamp];
diag_log "----------------------------------------------------------------------------------------------------";