1+ //connect->fast_loop->spawn_dl->cvar_save:http_tmp
12function http2_init()
23{
3- // disconnecting/reconnecting
4+ // connecting/ disconnecting/reconnecting
45 sp_sc_func_exec spf_sc_list_onchange_add_func _sp_cl_info_state http2_state_change
5- // connecting to server
6- sp_sc_func_exec spf_sc_list_onchange_add_func _sp_cl_on_connect http2_on_connect
6+
77 // udp downloads begin
88 sp_sc_func_exec spf_sc_list_onchange_add_func cl_download_filename http2_dl_filename
99
10- zero _http2_mapname
11- set _http2_mapname_prev_conn ""
1210 set _http2_timer 0
1311 set _http2_not_exist_local 0
1412 set _http2_thread_ids 0
13+ set _http2_out_in 1
1514
1615 sp_sc_timer 250 "sp_sc_func_exec http2_init_print"
1716}
1817
1918function http2_init_print()
2019{
21- echo "[HTTP] Version v1.4 Loaded"
20+ echo "[HTTP] Version v1.5 Loaded"
2221}
2322
23+ //2 -> 4 -> 7 -> 8
2424// 1-Not connected
2525// 2-Attempting to connect to a server
2626// 4-(Re)connecting to a server
@@ -30,45 +30,66 @@ function http2_init_print()
3030// we entered the game, stop the thread loop
3131function http2_state_change(*)
3232{
33- sp_sc_cvar_copy ~val #~1
34- sp_sc_flow_if text cvar ~val == val 4
33+ sp_sc_cvar_copy ~state #~1
34+ //echo state is $~state
35+ // fully disconnected
36+ sp_sc_flow_if text cvar ~state == val 1
37+ {
38+ sp_sc_func_exec http2_fast_loop $_http2_thread_ids "stop"
39+ set _http2_out_in 1
40+ }
41+ // Attempting Connect...
42+ sp_sc_flow_if text cvar ~state == val 2
43+ {
44+ //echo "state 2"
45+ sp_cl_info_map
46+ //echo HMM: $_sp_cl_info_map
47+ }
48+ // Reconnecting..
49+ sp_sc_flow_if text cvar ~state == val 4
50+ {
51+ //echo "state 4"
52+ sp_cl_info_map
53+ //echo HMM: $_sp_cl_info_map
54+ sp_sc_flow_if text cvar _http2_out_in == val 0
55+ {
56+ // This resets _sp_cl_info_map to ""
57+ set _http2_out_in 1
58+ disconnect
59+ reconnect
60+ }
61+ }
62+ // Connecting..
63+ sp_sc_flow_if text cvar ~state == val 7
3564 {
36- //reconnect from which state, matters.
37- set _http2_timer 0
65+ //echo "State 7"
66+
3867 sp_sc_func_exec http2_on_connect
3968 }
4069
4170 // fully connected
42- sp_sc_flow_if text cvar ~val == val 8
71+ sp_sc_flow_if text cvar ~state == val 8
4372 {
4473 sp_sc_flow_if text cvar _http2_not_exist_local == val 1
4574 {
4675 // It doesn't request .bsp file thus download succeeded.
47- sp_sc_cvar_sset ~text "[HTTP] " #_http2_mapname ".zip was downloaded."
76+ sp_sc_cvar_sset ~text "[HTTP] " #_sp_cl_info_map ".zip was downloaded."
4877 echo #~text
49- set _http2_not_exist_local 0
5078 }
5179 sp_sc_func_exec http2_fast_loop $_http2_thread_ids "stop"
5280 }
53- else
54- {
55- // fully disconnected
56- sp_sc_flow_if text cvar ~val == val 1
57- {
58- sp_sc_func_exec http2_fast_loop $_http2_thread_ids "stop"
59- }
60- }
6181}
62-
82+ // State == 7
6383function http2_on_connect()
6484{
65-
85+ //echo ON CONNECT
86+ set _http2_out_in 0
6687 set _http2_timer 0
6788 set _http2_not_exist_local 0
6889
69- //Only bounce between 1 and 3
90+ //Only bounce between 1 and 5
7091 add _http2_thread_ids 1
71- sp_sc_flow_if number cvar _http2_thread_ids > val 3
92+ sp_sc_flow_if number cvar _http2_thread_ids > val 5
7293 {
7394 set _http2_thread_ids 1
7495 }
@@ -89,64 +110,45 @@ function http2_fast_loop(~thread_id, ~mode)
89110 sp_sc_flow_if text cvar ~mode == val "stop"
90111 {
91112 //echo STOP
92- sp_sc_flow_if text cvar $~thread == val 1
93- {
94- set $~thread 0
95- }
113+ set $~thread 0
96114 }
97115 sp_sc_flow_if text cvar ~mode == val "cont"
98116 {
99117 //echo CONT
100118 // Thread guaranteed to die.
101119 sp_sc_flow_if text cvar $~thread == val 1
102120 {
103- // returns the value from previous map until a special moment.
121+
122+ // is empty for a few frames before. perfect.
104123 sp_cl_info_map
105-
106- sp_sc_flow_if text cvar _sp_cl_info_map != cvar _http2_mapname_prev_conn
107- {
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- }
113- }
114- else
124+ //echo MAP : $_sp_cl_info_map
125+ sp_sc_flow_if text cvar _sp_cl_info_map != val ""
115126 {
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- }
127+ //echo Map variable appears at : $_http2_timer
128+ //echo Map is $_sp_cl_info_map
129+ sp_sc_func_exec http2_spawn_dl $~thread_id
124130 }
125-
126131 add _http2_timer 100
127132 sset ~cmd sp_sc_func_exec http2_fast_loop $~thread_id "cont"
128133 sp_sc_timer 100 #~cmd
129134 }
130135 }
131136}
132-
137+ // Called by fast_loop if mapname seemed to change.
133138function http2_spawn_dl(~thread_id)
134139{
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
138140 // Stop this thread, we have got the mapname we needed. Only a new connect creates new thread.
139141 sp_sc_func_exec http2_fast_loop $~thread_id "stop"
140142
141143 // Begin download.
142- sp_sc_cvar_append ~full_path #_http2_mapname ".bsp"
144+ sp_sc_cvar_append ~full_path #_sp_cl_info_map ".bsp"
143145
144146 sp_sc_file_find ~found maps/$~full_path file
145147 sp_sc_flow_if text cvar ~found_0 == val "0"
146148 {
147149 // We have duration of configstrings to download map ( should freeze here possibly )
148150 set _http2_not_exist_local 1
149- sp_sc_cvar_sset ~text "[HTTP] Checking repo for " #_http2_mapname ".zip"
151+ sp_sc_cvar_sset ~text "[HTTP] Checking repo for " #_sp_cl_info_map ".zip"
150152 echo #~text
151153 sp_sc_cvar_save http_tmp ~full_path
152154 }
@@ -165,15 +167,15 @@ function http2_dl_filename(*)
165167 {
166168 // Bsp is always downloaded first, so indicates map wasn't in repo. (ignores .sp and extras)
167169 // 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"
170+ sp_sc_cvar_sset ~text "[HTTP] Map " #_sp_cl_info_map ".zip _probably_ not in repo"
169171 echo #~text
170172 }
171173 else
172174 {
173175 sp_sc_flow_if text cvar _http2_not_exist_local == val 1
174176 {
175177 // It doesn't request .bsp file thus download succeeded.
176- sp_sc_cvar_sset ~text "[HTTP] " #_http2_mapname ".zip was downloaded."
178+ sp_sc_cvar_sset ~text "[HTTP] " #_sp_cl_info_map ".zip was downloaded."
177179 echo #~text
178180 set _http2_not_exist_local 0
179181 }
0 commit comments