SHOW:
|
|
- or go back to the newest paste.
1 | fileName = "server" | |
2 | if(fs.exists(fileName) == true)then | |
3 | print("Installing BlueBank Server System") | |
4 | shell.run("rename "..fileName.." startup") | |
5 | sleep(5) | |
6 | os.reboot() | |
7 | end | |
8 | --[ Welcome to BlueBank made by TrumpetMiner v3.5 | |
9 | - | side = "top" -- Rednet Modem sidem (End of Setup) |
9 | + | |
10 | --[ To Setup Your Server, Edit The Following | |
11 | -- Authorization Code | |
12 | authSet = 3 | |
13 | function authF() | |
14 | authSet = authSet * 2 + 7 | |
15 | - | print "BlueBank Server 3.0 Status: Online" |
15 | + | |
16 | ||
17 | ||
18 | ||
19 | server = nil -- Admin ID# | |
20 | function getserver() | |
21 | local fname = "ServerID" | |
22 | if fs.exists(fname) then | |
23 | file = fs.open(fname, "r") | |
24 | server = tonumber(file.readAll()) | |
25 | file.close() | |
26 | print("Server ID: "..server) | |
27 | else | |
28 | print("No server configured") | |
29 | print("This ID is: ".. os.getComputerID()) | |
30 | term.write("Server ID: ") | |
31 | server = io.read() | |
32 | file = fs.open(fname, "w") | |
33 | file.write(server) | |
34 | file.close() | |
35 | server = tonumber(server) | |
36 | end | |
37 | end | |
38 | getserver() | |
39 | ||
40 | -- Determine where the modem is. | |
41 | print("Looking for modem,") | |
42 | if peripheral.isPresent("left") and peripheral.getType("left")=="modem" then | |
43 | side = "left" | |
44 | elseif peripheral.isPresent("right") and peripheral.getType("right")=="modem" then | |
45 | side = "right" | |
46 | elseif peripheral.isPresent("top") and peripheral.getType("top")=="modem" then | |
47 | side = "top" | |
48 | elseif peripheral.isPresent("back") and peripheral.getType("back")=="modem" then | |
49 | side = "back" | |
50 | elseif peripheral.isPresent("bottom") and peripheral.getType("bottom")=="modem" then | |
51 | side = "bottom" | |
52 | else | |
53 | print("No Modem Found") | |
54 | side = false | |
55 | end | |
56 | while side == false do | |
57 | ||
58 | sleep(5) | |
59 | shell.run("startup") | |
60 | ||
61 | end | |
62 | print("Modem found on "..side) | |
63 | rednet.open(side) | |
64 | -- Functions | |
65 | function drawStart() | |
66 | term.clear() | |
67 | cur(1,1) | |
68 | print ("BlueBank Server 3.0 Status: Online Server ID: " .. tonumber(server)) | |
69 | print "--------------------------------------" | |
70 | cur(3,4) | |
71 | print("Current Auth Code > "..authSet) | |
72 | id, message = rednet.receive() | |
73 | if type(message) == "string" then | |
74 | if message == "Login" then | |
75 | login() | |
76 | elseif message == "Balance" then | |
77 | balance() | |
78 | elseif message == "Transfer" then | |
79 | transfer() | |
80 | elseif message == "Create" then | |
81 | create() | |
82 | elseif message == "Delete" then | |
83 | delete() | |
84 | elseif message == "Rename" then | |
85 | rename() | |
86 | elseif message == "Passcode" then | |
87 | passcode() | |
88 | elseif message == "Add" then | |
89 | add() | |
90 | elseif message == "Auth" then | |
91 | auth() | |
92 | else | |
93 | rednet.send(id,"Command Not Found") | |
94 | drawStart() | |
95 | end | |
96 | else | |
97 | rednet.send(id,"Data is Not String") | |
98 | end | |
99 | end | |
100 | function login() | |
101 | id, user = rednet.receive() | |
102 | id, pass = rednet.receive() | |
103 | if type(pass) == "string" then | |
104 | if type(user) == "string" then | |
105 | if fs.exists("user/"..user) == true then | |
106 | h = fs.open("user/"..user, "r") | |
107 | passReal = h.readAll() | |
108 | h.close() | |
109 | if pass == passReal then | |
110 | rednet.send(id,"Login Successful") | |
111 | drawStart() | |
112 | else | |
113 | rednet.send(id,"Password Incorrect") | |
114 | drawStart() | |
115 | end | |
116 | else | |
117 | rednet.send(id,"Unknown User") | |
118 | drawStart() | |
119 | end | |
120 | else | |
121 | rednet.send(id,"User Is Not String") | |
122 | end | |
123 | else | |
124 | rednet.send(id,"Password Is Not String") | |
125 | end | |
126 | end | |
127 | function balance() | |
128 | id, user = rednet.receive() | |
129 | if type(user) == "string" then | |
130 | h = fs.open("$/"..user, "r") | |
131 | bal = h.readAll() | |
132 | h.close() | |
133 | rednet.send(id,bal) | |
134 | drawStart() | |
135 | else | |
136 | rednet.send(id,"User is Not String") | |
137 | end | |
138 | end | |
139 | function transfer() | |
140 | id, user1 = rednet.receive() | |
141 | id, user2 = rednet.receive() | |
142 | id, am = rednet.receive() | |
143 | if type(user1) == "string" and type(user2) == "string" and type(am) == "string" then | |
144 | if fs.exists("user/"..user1) and fs.exists("user/"..user2)then | |
145 | h = fs.open("$/"..user1, "r") | |
146 | bal1 = h.readAll() | |
147 | h.close() | |
148 | if tonumber(bal1) >= tonumber(am) then | |
149 | h = fs.open("$/"..user2, "r") | |
150 | bal2 = h.readAll() | |
151 | h.close() | |
152 | bal1 = bal1 - am | |
153 | bal2 = bal2 + am | |
154 | h = fs.open("$/"..user1, "w") | |
155 | h.write(bal1) | |
156 | h.close() | |
157 | h = fs.open("$/"..user2, "w") | |
158 | h.write(bal2) | |
159 | h.close() | |
160 | rednet.send(id,"Funds Transfered") | |
161 | drawStart() | |
162 | elseif bal1 <= am then | |
163 | rednet.send(id,"Not Enough Funds") | |
164 | --term.setCursorPos(1,3) | |
165 | --print(user1) | |
166 | --print(user2) | |
167 | --print(bal1) | |
168 | --print(bal2) | |
169 | --print(am) | |
170 | drawStart() | |
171 | else | |
172 | rednet.send(id,"An Error Occurred") | |
173 | drawStart() | |
174 | end | |
175 | else | |
176 | rednet.send(id," User(s) Not Found") | |
177 | drawStart() | |
178 | end | |
179 | else | |
180 | rednet.send(id,"Data Is Not String") | |
181 | end | |
182 | end | |
183 | function create() | |
184 | id, user = rednet.receive() | |
185 | id, pass = rednet.receive() | |
186 | if type(user) == "string" and type(pass) then | |
187 | if fs.exists("user/"..user) then | |
188 | rednet.send(id,"User Exists") | |
189 | else | |
190 | h = fs.open("user/"..user,"w") | |
191 | h.write(pass) | |
192 | h.close() | |
193 | h = fs.open("$/"..user,"w") | |
194 | h.write("0") | |
195 | h.close() | |
196 | rednet.send(id,"Account Created") | |
197 | drawStart() | |
198 | end | |
199 | else | |
200 | rednet.send(id,"Data Is Not String") | |
201 | end | |
202 | drawStart() | |
203 | end | |
204 | function delete() | |
205 | end | |
206 | function rename() | |
207 | end | |
208 | function passcode() | |
209 | end | |
210 | function add() | |
211 | id, user = rednet.receive() | |
212 | id, amt = rednet.receive() | |
213 | id, auth1 = rednet.receive() | |
214 | if type(user) == "string" and type(amt) == "string" and type(auth1) == "string" then | |
215 | if tonumber(auth1) == authSet then | |
216 | if fs.exists("user/"..user) then | |
217 | h = fs.open("$/"..user, "r") | |
218 | bal = h.readAll() | |
219 | h.close() | |
220 | balNew = bal + amt | |
221 | h = fs.open("$/"..user, "w") | |
222 | h.write(balNew) | |
223 | h.close() | |
224 | rednet.send(id,"$"..amt.." Added to "..user) | |
225 | drawStart() | |
226 | else | |
227 | rednet.send(id,"No Such User") | |
228 | drawStart() | |
229 | end | |
230 | else | |
231 | rednet.send(id,"Authorization Code Not Accepted") | |
232 | drawStart() | |
233 | end | |
234 | else | |
235 | rednet.send(id,"Data Is Not String") | |
236 | end | |
237 | end | |
238 | function auth() | |
239 | authF() | |
240 | rednet.send(id,"New Auth Code Found") | |
241 | drawStart() | |
242 | end | |
243 | function cur(cX,cY) | |
244 | term.setCursorPos(cX,cY) | |
245 | end | |
246 | -- Program | |
247 | drawStart() |