SHOW:
|
|
- or go back to the newest paste.
1 | - | --Made by CWC |
1 | + | --Made by Sapphire |
2 | - | x,y=term.getSize() |
2 | + | --Please do not edit! |
3 | - | version = "Alpha 4.0" |
3 | + | version = "Alpha 7.2" |
4 | - | local function drawMainPage() |
4 | + | local modem = false |
5 | - | local page = "home" |
5 | + | local code_404 = "term.setBackgroundColor(colors.white) term.clear() term.setCursorPos(1,1) term.setTextColor(colors.lightGray) print('Uh oh, captin, we are lost!') print('Sorry, the page was not found on the server!')" |
6 | local sides = { | |
7 | "top", | |
8 | "bottom", | |
9 | - | local size = { term.getSize() } |
9 | + | "back", |
10 | "left", | |
11 | "right" | |
12 | } | |
13 | local size = { term.getSize() } | |
14 | if not fs.exists("domain_name") then | |
15 | term.setBackgroundColor(colors.white) | |
16 | term.clear() | |
17 | paintutils.drawFilledBox(1,1,size[1],4,colors.gray) | |
18 | term.setCursorPos(1,1) | |
19 | term.setTextColor(colors.lightGray) | |
20 | term.setBackgroundColor(colors.gray) | |
21 | print("Setup server domain name") | |
22 | term.setBackgroundColor(colors.white) | |
23 | term.setCursorPos(1,6) | |
24 | print("(adds .cc) Enter domain name: ") | |
25 | local dmn = read() | |
26 | local dmn = (dmn..".cc") | |
27 | local domainf = fs.open("domain_name","w") | |
28 | domainf.write(dmn) | |
29 | - | sleep(60) |
29 | + | domainf.close() |
30 | term.clear() | |
31 | - | drawMainPage() |
31 | + | |
32 | term.setCursorPos(1,1) | |
33 | print("Setup server owner") | |
34 | term.setCursorPos(1,6) | |
35 | term.setBackgroundColor(colors.white) | |
36 | write("Enter server owner: ") | |
37 | local owner = read() | |
38 | local own = fs.open("server_owner","w") | |
39 | own.write(owner) | |
40 | end | |
41 | if not fs.exists("index") then | |
42 | term.setBackgroundColor(colors.white) | |
43 | term.clear() | |
44 | paintutils.drawFilledBox(1,1,size[1],4,colors.gray) | |
45 | term.setCursorPos(1,1) | |
46 | term.setTextColor(colors.lightGray) | |
47 | print("Uh oh,") | |
48 | term.setBackgroundColor(colors.white) | |
49 | term.setCursorPos(1,5) | |
50 | print("The main file, index is missing! Please create it then restart the server!") | |
51 | term.setTextColor(colors.cyan) | |
52 | term.setCursorPos(1,8) | |
53 | print("Click anywhere to shutdown") | |
54 | os.pullEvent("mouse_click") | |
55 | os.shutdown() | |
56 | else | |
57 | for i = 1, #sides do | |
58 | if peripheral.isPresent(sides[i]) then | |
59 | if peripheral.getType(sides[i]) == "modem" then | |
60 | local modem = peripheral.find("modem") | |
61 | if modem.isWireless() then | |
62 | rednet.open(sides[i]) | |
63 | local modem = true | |
64 | end | |
65 | end | |
66 | end | |
67 | end | |
68 | local domainf = fs.open("domain_name","r") | |
69 | local domain = domainf.readAll() | |
70 | domainf.close() | |
71 | if modem then | |
72 | local function reqLoop() | |
73 | while true do | |
74 | local evnt = { rednet.receive() } | |
75 | if evnt[3] == domain then | |
76 | if fs.exists(evnt[2]) then | |
77 | local codef = fs.open(evnt[2]) | |
78 | local code = codef.readAll() | |
79 | codef.close() | |
80 | rednet.send(evnt[1],code) | |
81 | else | |
82 | rednet.send(evnt[1],code_404) | |
83 | end | |
84 | end | |
85 | end | |
86 | end | |
87 | local main_loop = coroutine.create(reqLoop) | |
88 | coroutine.resume(main_loop) | |
89 | local function sep(sSep) | |
90 | local sub = {} | |
91 | for i = 1,#sSep do | |
92 | local toAdd = string.sub(sSep,1,i) | |
93 | table.insert(sub,toAdd) | |
94 | end | |
95 | return sub | |
96 | end | |
97 | local function drawMainPage() | |
98 | term.setBackgroundColor(colors.white) | |
99 | term.clear() | |
100 | term.setTextColor(colors.lightGray) | |
101 | paintutils.drawFilledBox(1,1,size[1],4,colors.gray) | |
102 | term.setCursorPos(1,1) | |
103 | print("System Version "..version) | |
104 | paintutils.drawFilledBox(1,6,21,9,colors.cyan) | |
105 | term.setCursorPos(3,7) | |
106 | term.setTextColor(colors.white) | |
107 | print("Edit Domain Name") | |
108 | paintutils.drawFilledBox(31,6,51,9,colors.yellow) | |
109 | term.setCursorPos(36,7) | |
110 | print("View Details") | |
111 | paintutils.drawFilledBox(1,11,21,14,colors.lime) | |
112 | term.setCursorPos(9,12) | |
113 | print("Quit") | |
114 | paintutils.drawFilledBox(31,11,51,14,colors.orange) | |
115 | term.setCursorPos(38,12) | |
116 | print("Restart") | |
117 | paintutils.drawFilledBox(1,16,size[1],19,colors.red) | |
118 | term.setCursorPos(22,17) | |
119 | print("Shutdown") | |
120 | end | |
121 | local function drawEditDmnPage() | |
122 | term.setBackgroundColor(colors.white) | |
123 | term.clear() | |
124 | paintutils.drawFilledBox(1,1,size[1],4,colors.gray) | |
125 | term.setCursorPos(1,1) | |
126 | term.setTextColor(colors.lightGray) | |
127 | print("Domain name editor") | |
128 | term.setCursorPos(1,6) | |
129 | term.setBackgroundColor(colors.white) | |
130 | write("Enter new domain name: ") | |
131 | local new_name = read() | |
132 | local dmn = fs.open("domain_name","w") | |
133 | local new_name =(new_name..".cc") | |
134 | dmn.write(new_name) | |
135 | dmn.close() | |
136 | drawMainPage() | |
137 | end | |
138 | local function drawDetailsPage() | |
139 | term.setBackgroundColor(colors.white) | |
140 | term.clear() | |
141 | paintutils.drawFilledBox(1,1,size[1],4,colors.gray) | |
142 | term.setCursorPos(1,1) | |
143 | term.setTextColor(colors.lightGray) | |
144 | local dmnf = fs.open("domain_name","r") | |
145 | local dmn = dmnf.readAll() | |
146 | dmnf.close() | |
147 | local ownf = fs.open("server_owner","r") | |
148 | local own = ownf.readAll() | |
149 | ownf.close() | |
150 | print("System details") | |
151 | term.setCursorPos(1,6) | |
152 | term.setBackgroundColor(colors.white) | |
153 | print("Domain name: "..dmn) | |
154 | term.setCursorPos(1,8) | |
155 | print("Owner: "..own) | |
156 | term.setCursorPos(1,10) | |
157 | print("ID: "..os.getComputerID()) | |
158 | term.setTextColor(colors.cyan) | |
159 | term.setCursorPos(1,14) | |
160 | print("Press anywhere to exit") | |
161 | os.pullEvent("mouse_click") | |
162 | drawMainPage() | |
163 | end | |
164 | os.pullEvent = os.pullEventRaw | |
165 | drawMainPage() | |
166 | while true do | |
167 | local evnt,btn,xPos,yPos = os.pullEvent("mouse_click") | |
168 | if xPos >= 1 and xPos <= 21 and yPos >= 6 and yPos <= 9 then | |
169 | drawEditDmnPage() | |
170 | elseif xPos >= 31 and xPos <= 51 and yPos >= 6 and yPos <= 9 then | |
171 | drawDetailsPage() | |
172 | elseif xPos >= 1 and xPos <= 21 and yPos >= 11 and yPos <= 14 then | |
173 | coroutine.yield(main_loop) | |
174 | break | |
175 | elseif xPos >= 31 and xPos <= 51 and yPos >= 11 and yPos <= 14 then | |
176 | term.setBackgroundColor(colors.white) | |
177 | term.clear() | |
178 | term.setTextColor(colors.cyan) | |
179 | term.setCursorPos(1,1) | |
180 | print("Restarting...") | |
181 | sleep(1) | |
182 | os.reboot() | |
183 | elseif xPos >= 1 and xPos <= size[1] and yPos >= 16 and yPos <= 19 then | |
184 | term.setBackgroundColor(colors.white) | |
185 | term.clear() | |
186 | term.setTextColor(colors.cyan) | |
187 | term.setCursorPos(1,1) | |
188 | print("Shutting down...") | |
189 | sleep(1) | |
190 | os.shutdown() | |
191 | end | |
192 | end | |
193 | end | |
194 | end |