SHOW:
|
|
- or go back to the newest paste.
1 | rednet.open("top") | |
2 | ||
3 | while true do | |
4 | id, message, info = rednet.receive() | |
5 | if message == "register" then | |
6 | local user = info[1] | |
7 | local pass = info[2] | |
8 | if fs.exists(user) then | |
9 | rednet.send(id, "userexists") | |
10 | else | |
11 | fs.makeDir(user) | |
12 | --local dir = user.."/" | |
13 | local dir = user | |
14 | file = fs.open(fs.combine(dir, "password"), "w") | |
15 | file.write(pass) | |
16 | file.close() | |
17 | rednet.send(id, "sucessful") | |
18 | end | |
19 | elseif message == "login" then | |
20 | local user = info[1] | |
21 | local pass = info[2] | |
22 | if fs.exists(user) == false then | |
23 | rednet.send(id, "usernoexist") | |
24 | else | |
25 | tmp = fs.open(fs.combine(user, "password"), "r") | |
26 | local spass = tmp.readAll() | |
27 | tmp.close() | |
28 | if spass == pass then | |
29 | rednet.send(id, "sucessful") | |
30 | else | |
31 | rednet.send(id, "passwrong") | |
32 | end | |
33 | end | |
34 | elseif message == "download" then | |
35 | local user = info[1] | |
36 | local pass = info[2] | |
37 | -- Adding Authentication just in case someone | |
38 | -- tries to trick the login system on the | |
39 | -- client | |
40 | if fs.exists(user) == false then | |
41 | rednet.send(id, "invaildauth") | |
42 | else | |
43 | tmp = fs.open(fs.combine(user, "password"), "r") | |
44 | local spass = tmp.readAll() | |
45 | tmp.close() | |
46 | if pass == spass then | |
47 | -- Send files one by one | |
48 | local files = fs.list("/"..user.."/") | |
49 | for k,v in pairs(files) do | |
50 | if v == "password" then | |
51 | -- Do nothing | |
52 | else | |
53 | file = fs.open(fs.combine(user, v), "r") | |
54 | local content = file.readAll() | |
55 | file.close() | |
56 | info = {v, content} | |
57 | rednet.send(id, "recieve", info) | |
58 | end | |
59 | end | |
60 | rednet.send(id, "stop") | |
61 | else | |
62 | -- Invaild Session | |
63 | rednet.send(id, "invaildauth") | |
64 | end | |
65 | end | |
66 | elseif message == "send-start" then | |
67 | -- Basic Auth | |
68 | local user = info[1] | |
69 | local pass = info[2] | |
70 | if fs.exists(user) == false then | |
71 | rednet.send(id, "invaildauth") | |
72 | else | |
73 | while true do | |
74 | id, message, info = rednet.receive() | |
75 | if message == "send" then | |
76 | if fs.exists(fs.combine(user, info[1])) then | |
77 | fs.delete(fs.combine(user, info[1])) | |
78 | end | |
79 | f = fs.open(fs.combine(user, info[1]), "w") | |
80 | f.write(info[2]) | |
81 | f.close() | |
82 | elseif message == "send-stop" then | |
83 | break | |
84 | end | |
85 | end | |
86 | end | |
87 | end | |
88 | end |