/
ntdownloader.dm
205 lines (180 loc) · 7.75 KB
/
ntdownloader.dm
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
/datum/computer_file/program/ntnetdownload
filename = "ntndownloader"
filedesc = "NTNet Software Download Tool"
program_icon_state = "generic"
program_key_state = "generic_key"
program_menu_icon = "arrowthickstop-1-s"
extended_desc = "This program allows downloads of software from official software repositories"
unsendable = TRUE
undeletable = TRUE
size = 4
processing_size = 0.5
requires_ntnet = TRUE
requires_ntnet_feature = NTNET_SOFTWAREDOWNLOAD
available_on_ntnet = FALSE
nanomodule_path = /datum/nano_module/program/computer_ntnetdownload
ui_header = "downloader_finished.gif"
var/datum/computer_file/program/downloaded_file = null
var/hacked_download = FALSE
/// GQ of downloaded data.
var/download_completion = 0
var/download_netspeed = 0
var/downloaderror = ""
var/list/downloads_queue[0]
/// For logging, can be faked by antags.
var/file_info
var/server
usage_flags = PROGRAM_ALL
category = PROG_UTIL
/datum/computer_file/program/ntnetdownload/on_shutdown()
..()
downloaded_file = null
download_completion = 0
download_netspeed = 0
downloaderror = ""
ui_header = "downloader_finished.gif"
/datum/computer_file/program/ntnetdownload/proc/begin_file_download(filename, skill)
if(downloaded_file)
return FALSE
var/datum/computer_file/program/PRG = ntnet_global.find_ntnet_file_by_name(filename)
if(!check_file_download(filename))
return FALSE
ui_header = "downloader_running.gif"
hacked_download = (PRG in ntnet_global.available_antag_software)
file_info = hide_file_info(PRG)
generate_network_log("Began downloading file [file_info] from [server].")
downloaded_file = PRG.clone()
/datum/computer_file/program/ntnetdownload/proc/check_file_download(filename)
//returns 1 if file can be downloaded, returns 0 if download prohibited
var/datum/computer_file/program/PRG = ntnet_global.find_ntnet_file_by_name(filename)
if(!PRG || !istype(PRG))
return FALSE
// Attempting to download antag only program, but without having emagged computer. No.
if(PRG.available_on_syndinet && !computer.emagged())
return FALSE
if(!computer || !computer.try_create_file(PRG))
return FALSE
return TRUE
/datum/computer_file/program/ntnetdownload/proc/hide_file_info(datum/computer_file/file, skill)
server = (file in ntnet_global.available_station_software) ? "NTNet Software Repository" : "unspecified server"
if(!hacked_download)
return "[file.filename].[file.filetype]"
var/stealth_chance = max(skill - SKILL_BASIC, 0) * 30
if(!prob(stealth_chance))
return "**ENCRYPTED**.[file.filetype]"
var/datum/computer_file/fake_file = pick(ntnet_global.available_station_software)
server = "NTNet Software Repository"
return "[fake_file.filename].[fake_file.filetype]"
/datum/computer_file/program/ntnetdownload/proc/abort_file_download()
if(!downloaded_file)
return
generate_network_log("Aborted download of file [file_info].")
downloaded_file = null
download_completion = 0
ui_header = "downloader_finished.gif"
/datum/computer_file/program/ntnetdownload/proc/complete_file_download()
if(!downloaded_file)
return
generate_network_log("Completed download of file [file_info].")
if(!computer || !computer.create_file(downloaded_file))
// The download failed
downloaderror = "I/O ERROR - Unable to save file. Check whether you have enough free space on your hard drive and whether your hard drive is properly connected. If the issue persists contact your system administrator for assistance."
downloaded_file = null
download_completion = 0
ui_header = "downloader_finished.gif"
/datum/computer_file/program/ntnetdownload/process_tick()
if(!downloaded_file)
return
if(download_completion >= downloaded_file.size)
complete_file_download()
if(length(downloads_queue) > 0)
begin_file_download(downloads_queue[1], downloads_queue[downloads_queue[1]])
downloads_queue.Remove(downloads_queue[1])
// Download speed according to connectivity state. NTNet server is assumed to be on unlimited speed so we're limited by our local connectivity
download_netspeed = computer.get_ntnet_speed(computer.get_ntnet_status())
download_completion += download_netspeed
/datum/computer_file/program/ntnetdownload/Topic(href, href_list)
if(..())
return TOPIC_HANDLED
if(href_list["PRG_downloadfile"])
if(!downloaded_file)
begin_file_download(href_list["PRG_downloadfile"], usr.get_skill_value(SKILL_COMPUTER))
else if(check_file_download(href_list["PRG_downloadfile"]) && !downloads_queue.Find(href_list["PRG_downloadfile"]) && downloaded_file.filename != href_list["PRG_downloadfile"])
downloads_queue[href_list["PRG_downloadfile"]] = usr.get_skill_value(SKILL_COMPUTER)
return TOPIC_HANDLED
if(href_list["PRG_removequeued"])
downloads_queue.Remove(href_list["PRG_removequeued"])
return TOPIC_HANDLED
if(href_list["PRG_reseterror"])
if(downloaderror)
download_completion = 0
download_netspeed = 0
downloaded_file = null
downloaderror = ""
return TOPIC_HANDLED
return TOPIC_NOACTION
/datum/nano_module/program/computer_ntnetdownload
name = "Network Downloader"
/datum/nano_module/program/computer_ntnetdownload/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null, force_open = 1, datum/topic_state/state = GLOB.default_state)
var/list/data = list()
var/datum/computer_file/program/ntnetdownload/prog = program
// For now limited to execution by the downloader program
if(!prog || !istype(prog))
return
if(program)
data = program.get_header_data()
// This IF cuts on data transferred to client, so i guess it's worth it.
if(prog.downloaderror) // Download errored. Wait until user resets the program.
data["error"] = prog.downloaderror
if(prog.downloaded_file) // Download running. Wait please..
data["downloadname"] = prog.downloaded_file.filename
data["downloaddesc"] = prog.downloaded_file.filedesc
data["downloadsize"] = prog.downloaded_file.size
data["downloadspeed"] = prog.download_netspeed
data["downloadcompletion"] = round(prog.download_completion, 0.1)
data["disk_size"] = program.computer.max_disk_capacity()
data["disk_used"] = program.computer.used_disk_capacity()
var/list/all_entries[0]
for(var/category in ntnet_global.available_software_by_category)
var/list/category_list[0]
for(var/datum/computer_file/program/P in ntnet_global.available_software_by_category[category])
// Only those programs our user can run will show in the list
if(!P.can_run(user) && P.requires_access_to_download)
continue
if(!P.is_supported_by_hardware(program.computer.get_hardware_flag()))
continue
category_list.Add(list(list(
"filename" = P.filename,
"filedesc" = P.filedesc,
"fileinfo" = P.extended_desc,
"size" = P.size,
"icon" = P.program_menu_icon
)))
if(length(category_list))
all_entries.Add(list(list("category"=category, "programs"=category_list)))
data["hackedavailable"] = FALSE
if(prog.computer.emagged()) // If we are running on emagged computer we have access to some "bonus" software
var/list/hacked_programs[0]
for(var/datum/computer_file/program/P in ntnet_global.available_antag_software)
data["hackedavailable"] = TRUE
hacked_programs.Add(list(list(
"filename" = P.filename,
"filedesc" = P.filedesc,
"fileinfo" = P.extended_desc,
"size" = P.size,
"icon" = P.program_menu_icon
)))
data["hacked_programs"] = hacked_programs
data["downloadable_programs"] = all_entries
if(length(prog.downloads_queue) > 0)
var/list/queue = list() // Nanoui can't iterate through assotiative lists, so we have to do this
for(var/item in prog.downloads_queue)
queue += item
data["downloads_queue"] = queue
ui = SSnano.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "ntnet_downloader.tmpl", "NTNet Download Program", 575, 700, state = state)
ui.auto_update_layout = 1
ui.set_initial_data(data)
ui.open()
ui.set_auto_update(1)