11function http2_init()
22{
3- //spf_sc_list_add_cmd( ~par_cvar_name, ~par_item );
4- //spf_sc_list_add_func( ~par_cvar_name, ~par_item ),
5-
3+ // disconnecting/reconnecting
64 sp_sc_func_exec spf_sc_list_onchange_add_func _sp_cl_info_state http2_state_change
7-
8- // sp_sc_func_exec spf_sc_list_onchange_add_func cl_downloading http2_dl_active
9-
5+ // connecting to server
6+ sp_sc_func_exec spf_sc_list_onchange_add_func _sp_cl_on_connect http2_on_connect
7+ // udp downloads begin
108 sp_sc_func_exec spf_sc_list_onchange_add_func cl_download_filename http2_dl_filename
119
12- //sp_sc_func_exec spf_sc_list_onchange_add_func cl_download_percent http2_dl_percent
13-
14-
15- sp_sc_func_exec spf_sc_list_add_func _sp_cl_on_connect http2_on_connect
16-
17- //sp_sc_func_exec spf_sc_list_onchange_add_func _sp_cl_print_data http2_on_status
18-
1910 zero _http2_mapname
20- set _http2_thread_running 0
2111 set _http2_mapname_prev_conn ""
2212 set _http2_timer 0
13+ set _http2_not_exist_local 0
14+ set _http2_thread_ids 0
2315
2416 sp_sc_timer 250 "sp_sc_func_exec http2_init_print"
2517}
2618
2719function http2_init_print()
2820{
29- echo "HTTP Downloader v1.3 Loaded"
30- }
31-
32- function http2_spawn_dl()
33- {
34- sp_sc_cvar_copy _http2_mapname _sp_cl_info_map
35-
36- //echo "MAP CHANGE == " $_http2_mapname
37-
38- // It always returns stale values, so compare it to this stale value from prev connection.
39- // ISSUE: When lastConnection has same Map, it won't download. Because it thinks its early value.
40- // When it might not be early value.
41- sp_sc_cvar_copy _http2_mapname_prev_conn _sp_cl_info_map
42- // Stop this thread, we have got the mapname we needed. Only a new connect creates new thread.
43- set _http2_thread_running 0
44-
45- // Begin download.
46-
47- sp_sc_cvar_append ~full_path #_http2_mapname ".bsp"
48- //echo " FULL MAPNAME " #~full_path
49- sp_sc_file_find ~found maps/$~full_path file
50-
51- sp_sc_flow_if text cvar ~found_0 == val "1"
52- {
53- //echo " MAP ALREADY DOWNLOADED"
54- }
55- else
56- {
57- // We have duration of configstrings to download map ( should freeze here possibly )
58- sp_sc_cvar_sset ~text "[HTTP] Checking repo for " #_http2_mapname ".zip"
59- echo #~text
60- sp_sc_cvar_save http_tmp ~full_path
61- }
62- }
63- // Pros: Works even on linux server because doesn't depend on serverstatus
64- // A loop to get the mapname spamming sp_cl_info_map
65- function http2_fast_loop()
66- {
67- sp_cl_info_map
68- // it seems its only empty when the game is first opened.
69- // it will always return the last/current map.
70- // difficult to tell when its fresh data.
71- // load our own map to give a comparison from.
72-
73- // Careful because it can be "", ignore empty case.
74- sp_sc_flow_if text cvar _sp_cl_info_map != cvar _http2_mapname_prev_conn
75- {
76- sp_sc_flow_if text cvar _sp_cl_info_map != val ""
77- {
78- sp_sc_func_exec http2_spawn_dl
79- }
80- }
81- else
82- {
83- // Assume its the same map after all if X time has passed.
84- sp_sc_flow_if number cvar _http2_timer > val 5000
85- {
86- sp_sc_flow_if text cvar _sp_cl_info_map != val ""
87- {
88- //echo "Timeout assume same mapname"
89- sp_sc_func_exec http2_spawn_dl
90- }
91- }
92- }
93-
94- // Keep running this until we are spawned.
95- sp_sc_flow_if text cvar _http2_thread_running == val 1
96- {
97- add _http2_timer 100
98- sp_sc_timer 100 "sp_sc_func_exec http2_fast_loop"
99- }
100- }
101-
102-
103- function http2_on_connect()
104- {
105- // Never start a thread that is already running.
106- // to stop the thread : _http2_thread_running 0
107- sp_sc_flow_if text cvar _http2_thread_running == val 0
108- {
109- set _http2_timer 0
110- //echo " START CONNECT GETTING MAP NAME"
111- set _http2_thread_running 1
112- sp_sc_func_exec http2_fast_loop
113- }
114-
115- }
116- // used for realizing we out of time
117- function http2_dl_filename(*)
118- {
119- // Time is up! The server is ready for slow downloads
120- sp_sc_cvar_copy ~val #~1
121- //echo "DL FILENAME == " #~val
122- sp_sc_cvar_sset ~text "[HTTP] Map " #_http2_mapname ".zip not in repo"
123- echo #~text
21+ echo "[HTTP] Version v1.4 Loaded"
12422}
12523
12624// 1-Not connected
@@ -143,79 +41,142 @@ function http2_state_change(*)
14341 // fully connected
14442 sp_sc_flow_if text cvar ~val == val 8
14543 {
146- set _http2_thread_running 0
44+ sp_sc_flow_if text cvar _http2_not_exist_local == val 1
45+ {
46+ // It doesn't request .bsp file thus download succeeded.
47+ sp_sc_cvar_sset ~text "[HTTP] " #_http2_mapname ".zip was downloaded."
48+ echo #~text
49+ set _http2_not_exist_local 0
50+ }
51+ sp_sc_func_exec http2_fast_loop $_http2_thread_ids "stop"
14752 }
14853 else
14954 {
15055 // fully disconnected
15156 sp_sc_flow_if text cvar ~val == val 1
15257 {
153- set _http2_thread_running 0
58+ sp_sc_func_exec http2_fast_loop $_http2_thread_ids "stop"
15459 }
15560 }
156-
157- //echo "CONNECTED STATE == " $~val
158- }
159- //not used
160- function http2_dl_active(*)
161- {
162- sp_sc_cvar_copy ~val #~1
163- //echo "DL ACTIVE == " #~val
164- }
165- //not used
166- function http2_dl_percent(*)
167- {
168- sp_sc_cvar_copy ~val #~1
169- //echo "DL PERCENT == " #~val
17061}
17162
172- function http2_on_connect_deprecated()
173- {
174- //echo " START CONNECT " #~1 #~2 #~3
175- // enable hidden parsing
176- set _sp_cl_print 3
177- sp_sc_cvar_append ~cmd "serverstatus " #_sp_cl_info_server
178- sp_sc_timer 1 #~cmd
179- }
180-
181- // on unconnected packet response
182- // This method is deprecated. But viable. SoF Linux does not return mapname in status response.
183- // To make this method work, serverstatus has to be triggered by reconnect (state==4), not on_connect_event.
184- // If cl_download_filename contains informaiton, you've ran out of time. should reconnect
185- function http2_on_status(*)
63+ function http2_on_connect()
18664{
187- // disable parsing
188- set _sp_cl_print 0
18965
190- //echo " DATA1 " #_sp_cl_print_data
66+ set _http2_timer 0
67+ set _http2_not_exist_local 0
19168
192- sp_sc_cvar_split ~split "\" _sp_cl_print_data
69+ //Only bounce between 1 and 3
70+ add _http2_thread_ids 1
71+ sp_sc_flow_if number cvar _http2_thread_ids > val 3
72+ {
73+ set _http2_thread_ids 1
74+ }
75+ sp_sc_func_exec http2_fast_loop $_http2_thread_ids "start"
76+ }
19377
194- sp_sc_flow_while number cvar ~i < val #~split_0
78+ // Pros: Works even on linux server because doesn't depend on serverstatus
79+ // A loop to get the mapname spamming sp_cl_info_map
80+ function http2_fast_loop(~thread_id, ~mode)
81+ {
82+ set ~thread _http2_thread_ids_$~thread_id
83+ sp_sc_flow_if text cvar ~mode == val "start"
19584 {
196- sp_sc_flow_if text cvar ~split_$~i == val "mapname"
85+ //echo START
86+ set $~thread 1
87+ set ~mode "cont"
88+ }
89+ sp_sc_flow_if text cvar ~mode == val "stop"
90+ {
91+ //echo STOP
92+ sp_sc_flow_if text cvar $~thread == val 1
19793 {
198- add ~i 1
199- sp_sc_flow_if text cvar _http2_mapname == val ""
94+ set $~thread 0
95+ }
96+ }
97+ sp_sc_flow_if text cvar ~mode == val "cont"
98+ {
99+ //echo CONT
100+ // Thread guaranteed to die.
101+ sp_sc_flow_if text cvar $~thread == val 1
102+ {
103+ // returns the value from previous map until a special moment.
104+ sp_cl_info_map
105+
106+ sp_sc_flow_if text cvar _sp_cl_info_map != cvar _http2_mapname_prev_conn
200107 {
201- sp_sc_cvar_copy _http2_mapname ~split_$~i
108+ sp_sc_flow_if text cvar _sp_cl_info_map != val ""
109+ {
110+ //echo Map variable appears at : $_http2_timer
111+ sp_sc_func_exec http2_spawn_dl $~thread_id
112+ }
202113 }
203-
114+ else
115+ {
116+ // Assume its the same map after all if X [1500-2100] time has passed.
117+ sp_sc_flow_if number cvar _http2_timer > val 3500
118+ {
119+ sp_sc_flow_if text cvar _sp_cl_info_map != val ""
120+ {
121+ sp_sc_func_exec http2_spawn_dl $~thread_id
122+ }
123+ }
124+ }
125+
126+ add _http2_timer 100
127+ sset ~cmd sp_sc_func_exec http2_fast_loop $~thread_id "cont"
128+ sp_sc_timer 100 #~cmd
204129 }
205- add ~i 1
206130 }
131+ }
132+
133+ function http2_spawn_dl(~thread_id)
134+ {
135+ sp_sc_cvar_copy _http2_mapname _sp_cl_info_map
136+
137+ sp_sc_cvar_copy _http2_mapname_prev_conn _sp_cl_info_map
138+ // Stop this thread, we have got the mapname we needed. Only a new connect creates new thread.
139+ sp_sc_func_exec http2_fast_loop $~thread_id "stop"
140+
141+ // Begin download.
207142 sp_sc_cvar_append ~full_path #_http2_mapname ".bsp"
208- //echo " FULL MAPNAME " #~full_path
209- sp_sc_file_find ~found #~full_path file
210143
211- sp_sc_flow_if text cvar ~found_0 == val "1"
144+ sp_sc_file_find ~found maps/$~full_path file
145+ sp_sc_flow_if text cvar ~found_0 == val "0"
146+ {
147+ // We have duration of configstrings to download map ( should freeze here possibly )
148+ set _http2_not_exist_local 1
149+ sp_sc_cvar_sset ~text "[HTTP] Checking repo for " #_http2_mapname ".zip"
150+ echo #~text
151+ sp_sc_cvar_save http_tmp ~full_path
152+ }
153+ }
154+
155+ // udp downloads begin
156+ // assumption: 1 bsp file per connect
157+ function http2_dl_filename(*)
158+ {
159+ // Time is up! The server is ready for slow downloads
160+ sp_sc_cvar_copy ~filename #~1
161+ sp_sc_cvar_split ~split "." ~filename
162+ //last item
163+ sp_sc_cvar_copy ~ext ~split_$~split_0
164+ sp_sc_flow_if text cvar ~ext == val "bsp"
212165 {
213- //echo " MAP ALREADY DOWNLOADED"
166+ // Bsp is always downloaded first, so indicates map wasn't in repo. (ignores .sp and extras)
167+ // Or the time it took to http download was too long. ( rare case. )
168+ sp_sc_cvar_sset ~text "[HTTP] Map " #_http2_mapname ".zip _probably_ not in repo"
169+ echo #~text
214170 }
215171 else
216172 {
217- // We have duration of configstrings to download map ( should freeze here possibly )
218- //echo " DOWNLOADING MAP!"
173+ sp_sc_flow_if text cvar _http2_not_exist_local == val 1
174+ {
175+ // It doesn't request .bsp file thus download succeeded.
176+ sp_sc_cvar_sset ~text "[HTTP] " #_http2_mapname ".zip was downloaded."
177+ echo #~text
178+ set _http2_not_exist_local 0
179+ }
180+
219181 }
220-
221182}
0 commit comments