-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
427 lines (414 loc) · 16.1 KB
/
main.lua
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
local splashes = {[[
__ _ ,
/ -, , ,- - ,
|| ) || _||_ ||
~||---) _-_ =||= ' || /'\\ ,._-_ =||= ,._-_ _-_ _-_, _-_,
~||---, || \\ || || || || || || || || \\ ||_. ||_.
~|| / ||/ || |, || || || || || ||/ ~ || ~ ||
|, / \\,/ \\, _-/ \\,/ \\, \\, \\, \\,/ ,-_- ,-_-
-_- --~
]],
[[
'||\ ||` || '||''''| ||
||\\ || || || . ||
|| \\ ||.|''|''||'' ||''.|''|'||''''||'''||''.|''|('''(''''
|| \\||||..|| || || || |||| || || ||..||`'')`'')
.|| \||`|... `|...||. `|..|.||. `|...||. `|...`...`...'
]],
[[
______ __ _______ __
| _ \.-----| |_| _ .-----.----| |_.----.-----.-----.-----.
|. | | -__| _|. 1___| _ | _| _| _| -__|__ --|__ --|
|. | |_____|____|. __) |_____|__| |____|__| |_____|_____|_____|
|: | | |: |
|::.| | |::.|
`--- ---' `---'
]],
[[
# # #######
## # ###### ##### # #### ##### ##### ##### ###### #### ####
# # # # # # # # # # # # # # # #
# # # ##### # ##### # # # # # # # ##### #### ####
# # # # # # # # ##### # ##### # # #
# ## # # # # # # # # # # # # # # #
# # ###### # # #### # # # # # ###### #### ####
]],
[[
88b 88 888888 888888 888888 dP"Yb 88""Yb 888888 88""Yb 888888 .dP"Y8 .dP"Y8
88Yb88 88__ 88 88__ dP Yb 88__dP 88 88__dP 88__ `Ybo." `Ybo."
88 Y88 88"" 88 88"" Yb dP 88"Yb 88 88"Yb 88"" o.`Y8b o.`Y8b
88 Y8 888888 88 88 YbodP 88 Yb 88 88 Yb 888888 8bodP' 8bodP'
]],
[[
8"""8 8""""
8 8 eeee eeeee 8 eeeee eeeee eeeee eeeee eeee eeeee eeeee
8e 8 8 8 8eeee 8 88 8 8 8 8 8 8 8 " 8 "
88 8 8eee 8e 88 8 8 8eee8e 8e 8eee8e 8eee 8eeee 8eeee
88 8 88 88 88 8 8 88 8 88 88 8 88 88 88
88 8 88ee 88 88 8eee8 88 8 88 88 8 88ee 8ee88 8ee88
]],
[[
+-+-+-+-+-+-+-+-+-+-+-+
|N|e|t|F|o|r|t|r|e|s|s|
+-+-+-+-+-+-+-+-+-+-+-+
]],
[[
'||\ ||` || '||''''| ||
||\\ || || || . ||
|| \\ ||.|''|''||'' ||''.|''|'||''''||'''||''.|''|('''(''''
|| \\||||..|| || || || |||| || || ||..||`'')`'')
.|| \||`|... `|...||. `|..|.||. `|...||. `|...`...`...'
]],
[[
___
/| | / / /
( | | ___ (___ (___ ___ ___ (___ ___ ___ ___ ___
| | )|___)| | | )| )| | )|___)|___ |___
| |/ |__ |__ | |__/ | |__ | |__ __/ __/
]],
[[
__ __________________ _____________ ______ __
||\ ||| | || || // \\|| \| || || \|| (( (( \
||\\|||== || ||=(( )||_// || ||_/||== \\ \\
|| \|||___ || || \\_//|| \\ || || \||__\_)\_))
]],
[[
) (
( /( ))\ ) )
)\()) ( ( /(()/( ( ( /(( (
((_)\ ))\ )\()/(_))( )( )\())( ))\( (
_((_)/((_(_))(_))_|)\(()\(_))(()\ /((_)\ )\
| \| (_)) | |_| |_ ((_)((_| |_ ((_(_))((_((_)
| .` / -_)| _| __/ _ | '_| _| '_/ -_(_-(_-
|_|\_\___| \__|_| \___|_| \__|_| \___/__/__/
]],
[[
_ _ _ _____ _
| \ | | ___| |_| ______ _ __| |_ _ __ ___ ___ ___
| \| |/ _ | __| |_ / _ \| '__| __| '__/ _ / __/ __|
| |\ | __| |_| _| (_) | | | |_| | | __\__ \__ \
|_| \_|\___|\__|_| \___/|_| \__|_| \___|___|___/
]],
[[
NetFortress NetFortress NetFortress
NetFortress NetFortress NetFortress
NetFortress NetFortress NetFortress
NetFortress NetFortress NetFortress
NetFortress NetFortress NetFortress
]],
}
function requireDirectory( dir )
dir = dir or ""
local entities = love.filesystem.getDirectoryItems(dir)
for k, ents in ipairs(entities) do
trim = string.gsub( ents, ".lua", "")
require(dir .. "/" .. trim)
end
end
font = love.graphics.newFont(32)
function love.draw()
local w, h = love.window.getMode();
love.graphics.rectangle("fill", 0, 0, w, h)
love.graphics.printf("NetFortress", font, w / 2 - font:getWidth("NetFortress") / 2, h / 2, w);
love.graphics.printf("See the console to get started", font, w / 2 - font:getWidth("See the console to get started") / 2, h / 2, w);
end
print( splashes[love.math.random(#splashes)] )
local disclaimer = [[
READ THIS OR SUFFER A TERRIBLE FATE
NetFortress makes frequent use of audiovisual effects.
These effects are usually meant to represent statuses without text or other intrusive elements.
However, they can be straining to the eyes of some users.
In worse cases, they could be harmful to people with epilepsy.
Giving players seizures is not within the scope of NetFortress.
I do my best to make toggles and switches for these, but they are all turned on by default.
Please browse the Switches menu to turn them off or back on.
]]
print(disclaimer)
love.filesystem.setIdentity( "netfortress" )
local http = require("socket.http")
local manifest = http.request("http://sabbath.vineyard.haus/netfortress/manifest.txt")
local sha = require("sha")
local tobool = require("toboolean")
local inspect = require("inspect")
function string.explode(str, div)
assert(type(str) == "string" and type(div) == "string", "invalid arguments")
local o = {}
while true do
local pos1,pos2 = str:find(div)
if not pos1 then
o[#o+1] = str
break
end
o[#o+1],str = str:sub(1,pos1-1),str:sub(pos2+1)
end
return o
end
while( true ) do
local sploded = string.explode( manifest, "\n" );
local data = love.filesystem.read( "clidata.txt" )
local serverinfo = love.filesystem.read( "serverinfo.txt" )
local kbfile = love.filesystem.read( "keybinds.txt" )
local avfile = love.filesystem.read( "audiovisual.txt" )
local opts = {
"Play NetFortress!",
"Update NetFortress",
"Edit server connection or login credentials",
"Switches for audiovisual phenomena",
"Change keybindings/controls",
"Donate to NetFortress's developer",
"Join the NetFortress Discord server (full server access is manually authorized)"
}
if( not serverinfo ) then
opts[1] = "Play NetFortress! (NO SERVER INFO -- SEE OPTION 3 FIRST)"
end
if( not data ) then
print("Client data not found. Update NetFortress\n")
opts[4] = "Switches for audiovisual phenomena (update NetFortress first)"
opts[5] = "Change keybindings/controls (update NetFortress first)"
elseif( data ~= sploded[1] ) then
print("Your copy of NetFortress is outdated\n");
end
for k, v in pairs( opts ) do
print( k .. ". " .. v )
end
print("Please select an option and press ENTER");
local sel = io.read("*n")
sel = string.gsub(sel, "%s+", "")
sel = tonumber( sel )
if( sel == 1 ) then
if( not serverinfo or not data or not kbfile or not avfile ) then
print("You should read before you press buttons!")
else
require("client");
break;
end
elseif( sel == 2 ) then
local clearedbinds = false
local clearedav = false
for k, v in pairs( sploded ) do
if( k > 1 ) then
local path = string.gsub(string.gsub(v, "%s+", ""), "\\", "/")
local info = love.filesystem.getInfo( path );
local skip = false
if( path:match("^.+/(.+)$") ) then
if( info ) then
local b, r, h = http.request( { url = "http://sabbath.vineyard.haus/netfortress/" .. path, method = "HEAD" } )
local fsize = tonumber(h["content-length"])
if( fsize == info.size ) then
print("Download progress: " .. math.floor( ((k - 1) / (#sploded - 1)) * 100 ) .. "% (" .. k - 1 .. "/" .. #sploded - 1 .. ") SKIPPED " .. v)
skip = true
end
end
if( not skip ) then
local file = http.request( "http://sabbath.vineyard.haus/netfortress/" .. path )
if( file ) then
local dont = false
if( path == "keybinds.txt" and kbfile ) then
local opts = string.explode( file, "\n" )
if( #string.explode( kbfile, "\n" ) == #opts ) then
dont = true
print("Download progress: " .. math.floor( ((k - 1) / (#sploded - 1)) * 100 ) .. "% (" .. k - 1 .. "/" .. #sploded - 1 .. ") SKIPPED " .. v)
else
clearedbinds = true
end
end
if( path == "audiovisual.txt" and avfile ) then
local opts = string.explode( file, "\n" )
if( #string.explode( avfile, "\n" ) == #opts ) then
dont = true
print("Download progress: " .. math.floor( ((k - 1) / (#sploded - 1)) * 100 ) .. "% (" .. k - 1 .. "/" .. #sploded - 1 .. ") SKIPPED " .. v)
else
clearedav = true
end
end
if( not dont ) then
local direxp = string.explode( path, "/" );
if( #direxp > 1 ) then
local dir = "";
for i=1, #direxp - 1 do
local diridx = direxp[i];
dir = dir .. diridx .. "/";
end
dir = string.sub( dir, 1, -2 );
love.filesystem.createDirectory( dir );
end
love.filesystem.write(path, file)
if( path == "keybinds.txt" ) then
kbfile = love.filesystem.read("keybinds.txt")
end
if( path == "audiovisual.txt" ) then
avfile = love.filesystem.read("audiovisual.txt")
end
print("Download progress: " .. math.floor( ((k - 1) / (#sploded - 1)) * 100 ) .. "% (" .. k - 1 .. "/" .. #sploded - 1 .. ") " .. v)
end
end
end
end
end
end
love.filesystem.write("clidata.txt", sploded[1])
if( clearedbinds ) then
for i=1, 3 do
print("YOUR KEYBINDS WERE CLEARED BECAUSE OF AN ADDITION OR REMOVAL OF A CONTROL OR MULTIPLE, PLEASE SET THEM AGAIN")
end
end
if( clearedav ) then
for i=1, 3 do
print("YOUR AUDIOVISUAL SWITCHES WERE CLEARED BECAUSE OF AN ADDITION OR REMOVAL OF ONE OR MULTIPLE, PLEASE SET THEM AGAIN")
end
end
print()
elseif( sel == 3 ) then
if( not serverinfo ) then
print("Generating a blank server info file");
local line = "deathcult.today\n6666\nEMPTY\nEMPTY";
love.filesystem.write("serverinfo.txt", line);
end
local serverdatatable = string.explode( love.filesystem.read("serverinfo.txt"), "\n" );
print("Your password should be generated by the owner of the server FOR you, and should never under any circumstances be a password you choose or use anywhere else")
print("Contact the owner of the server if you are lacking an account or need to reset your credentials")
local broken = false
while( not broken ) do
print("1. Server IP: " .. serverdatatable[1])
print("2. Server port: " .. serverdatatable[2])
print("3. Your username for this server: " .. serverdatatable[3])
print("4. Your password for this server is hidden")
print("Please enter the number of your selection or 0 to go back to the main menu")
sel = io.read("*n")
if( sel == 0 ) then
broken = true
elseif( sel == 1 ) then
print("Please input the server address")
repeat address = io.read() until address:match("%S")
print("You have entered: " .. address)
serverdatatable[1] = address
elseif( sel == 2 ) then
print("Please input the server port")
port = io.read("*n")
print("You have entered: " .. port)
serverdatatable[2] = port
elseif( sel == 3 ) then
print("Please input your username for this server")
repeat user = io.read() until user:match("%S")
print("You have entered: " .. user)
serverdatatable[3] = user
elseif( sel == 4 ) then
print("Please input your password for your username for this server")
repeat password = io.read() until password:match("%S")
print("You have entered your password, which has been encrypted")
serverdatatable[4] = sha.sha256(password)
end
local line = ""
for i=1, 4 do
line = line .. serverdatatable[i] .. "\n"
end
love.filesystem.write("serverinfo.txt", line)
sel = nil
print()
end
elseif( sel == 4 ) then
if( not avfile ) then
print("You should read before you press buttons!")
else
local switches = {}
for k, v in pairs( string.explode( avfile, "\n" ) ) do
local kb = string.explode( v, "|" )
if( string.find( kb[3], "\r" ) ) then
kb[3] = string.gsub(kb[3], "\r", "")
end
kb[2] = tobool(kb[2])
table.insert( switches, kb )
end
local broken = false
while( not broken ) do
local idx = 0
for k, v in pairs( switches ) do
if( #v == 3 ) then
idx = idx + 1
print( idx .. ". " .. v[1] .. " [" .. v[3] .. "]: " .. tostring(v[2]) )
end
end
print( "Enter the number of whatever control you want to toggle, 0 to go back and confirm your edits" )
sel = io.read("*n")
if( sel == 0 ) then
broken = true
elseif( sel > idx ) then
print( "Invalid selection, try again" )
else
switches[sel][2] = not switches[sel][2]
print( "Audiovisual switch " .. switches[sel][1] .. " set to " .. tostring(switches[sel][2]) )
end
end
local line = ""
for k, v in pairs( switches ) do
if( #v == 3 ) then
line = line .. v[1] .. "|" .. tostring(v[2]) .. "|" .. v[3] .. "\n"
end
end
love.filesystem.write("audiovisual.txt", string.sub(line, 1, -2))
print("Your audiovisual settings have been saved")
end
elseif( sel == 5 ) then
if( not kbfile ) then
print("You should read before you press buttons!")
else
local keybinds = {}
local keycodes = require("keycodes")
for k, v in pairs( string.explode( kbfile, "\n" ) ) do
local kb = string.explode( v, "|" )
if( string.find( kb[2], "\r" ) ) then
kb[2] = string.gsub(kb[2], "\r", "")
end
table.insert( keybinds, kb )
end
local broken = false
while( not broken ) do
local idx = 0
for k, v in pairs( keybinds ) do
if( #v == 2 ) then
idx = idx + 1
print( idx .. ". " .. v[1] .. " [" .. v[2] .. "]" )
end
end
print( "Enter the number of whatever control you want to change, 0 to go back and confirm your edits, or -1 to open the list of keycodes" )
print( "Special characters (as in, you have to hold shift to access them) will not work" )
sel = io.read("*n")
if( sel == -1 ) then
love.system.openURL("https://love2d.org/wiki/KeyConstant")
elseif( sel == 0 ) then
broken = true
elseif( sel > idx ) then
print( "Invalid selection, try again" )
else
print( "What would you like the new keycode for " .. keybinds[sel][1] .. " to be?" )
repeat nb = io.read() until nb:match("%S")
local found = false
for k, v in pairs( keycodes ) do
if( nb == v ) then
found = true
end
end
if( found ) then
keybinds[sel][2] = nb
print( "Your new keycode for " .. keybinds[sel][1] .. " is " .. keybinds[sel][2] )
else
print( "That is not a valid keycode" )
love.system.openURL("https://love2d.org/wiki/KeyConstant")
end
end
end
local line = ""
for k, v in pairs( keybinds ) do
if( #v == 2 ) then
line = line .. v[1] .. "|" .. v[2] .. "\n"
end
end
love.filesystem.write("keybinds.txt", string.sub(line, 1, -2))
print("Your keybinds have been saved")
end
elseif( sel == 6 ) then
love.system.openURL( "www.patreon.com/deathculttoday" );
elseif( sel == 7 ) then
love.system.openURL( "https://discord.gg/vNZgTffqHa" );
end
end