View difference between Paste ID: grETVPLk and D66cBKMg
SHOW: | | - or go back to the newest paste.
1
rednet.open("back");
2
3
local connected = 0;
4
local serverName = nil;
5
local serverID = 0;
6
7
8
function repaint()
9
	term.setCursorPos(1, 1);
10
11
	term.setBackgroundColor(colors.white);
12
	for i = 1, 20 do
13
		for j = 1, 26 do
14
			write(" ");
15
		end
16
		print();
17
	end
18
	
19
	if (connected == 0) then
20
		term.setBackgroundColor(colors.red);
21
	else
22
		term.setBackgroundColor(colors.green);
23
	end
24
	
25
	term.setTextColor(colors.white);
26
		
27
	term.setCursorPos(1, 1);
28
	write("                          ");
29
	
30
	term.setCursorPos(1, 20);
31
	write("                          ");
32
	
33
	
34
	term.setCursorPos(1, 1);
35
	write(serverName);
36
	
37
	
38
end
39
40
function connectToServer()
41
	rednet.broadcast("$INFO");
42
	id, msg = rednet.receive(5);
43
	
44
	if (msg == nil) then
45
		showErrorMessage("No Carrier");
46
		sleep(3);
47
		os.reboot();
48
	else
49
		serverName = msg;
50
		serverID = id;
51
		connected = 1;
52
	end
53
end
54
55
56
function showErrorMessage(message)
57
	term.setBackgroundColor(colors.red);
58
	term.setTextColor(colors.white);
59
	
60
	for i = 8, 13 do
61
		term.setCursorPos(2, i);
62
		for j = 1, 24 do
63
			write(" ");
64
		end 
65
		print();
66
	end
67
	
68
	term.setCursorPos(11, 9);
69
	write("Error");
70
	
71
	
72
	term.setCursorPos(4, 11);
73
	write(message);
74
end
75
76
function showInformationMessage(line1, line2)
77
	term.setBackgroundColor(colors.lightBlue);
78
	term.setTextColor(colors.white);
79
	
80
	for i = 8, 13 do
81
		term.setCursorPos(2, i);
82
		for j = 1, 24 do
83
			write(" ");
84
		end 
85
		print();
86
	end
87
	
88
	term.setCursorPos(11, 9);
89
	write("Message");
90
	
91
	
92
	term.setCursorPos(4, 11);
93
	write(line1);
94
	term.setCursorPos(4, 12);
95
	write(line2);
96
end
97
98
function showInputDialog(message)
99
	term.setBackgroundColor(colors.lightBlue);
100
	term.setTextColor(colors.brown);
101
	
102
	for i = 4, 17 do
103
		term.setCursorPos(2, i);
104
		for j = 1, 24 do
105
			write(" ");
106
		end
107
	end
108
	
109
	term.setCursorPos(4, 6);
110
	write(message);
111
	
112
	term.setCursorPos(5, 14);
113
	input = read();
114
	
115
	return input;
116
end
117
118
119
function showOSInformation()
120
	term.setBackgroundColor(colors.white);
121
	term.setTextColor(colors.lightGray);
122
	
123
	term.setCursorPos(4, 5);
124
	write("PDATerm v0.1");
125
	term.setCursorPos(4, 7);
126
	write("A Free Mobile Terminal");
127
	term.setCursorPos(4, 8);
128
	write("for ComputerCraft");
129
end
130
131
function lock()
132
	term.setCursorPos(1, 1);
133
	term.setBackgroundColor(colors.black);
134
	term.setTextColor(colors.white);
135
	
136
	for i = 1, 20 do
137
		for j = 1, 26 do
138
			if (i == 1 or i == 20 or j == 1 or j == 26) then
139
				term.setBackgroundColor(colors.red);
140
			end
141
			write(" ");
142
			term.setBackgroundColor(colors.black);
143
		end
144
		if (i ~= 20) then
145
			print();
146
		end
147
	end
148
	
149
	term.setCursorPos(5, 3);
150
	write("--Enter Passcode--");
151
	
152
	cpass = "1234";
153
	pass = "";
154
	
155
	term.setTextColor(colors.white);
156
	
157
	while(pass ~= cpass) do
158
	
159
		pass = "";
160
		
161
		term.setCursorPos(5, 15);
162
		write("   -  -  -  -   ");
163
		
164
		for i = 1, 4 do
165
			term.setCursorPos(5 + i * 3, 15);
166
			local event, key = os.pullEvent("char");
167
			pass = pass .. key;
168
			write("*");
169
		end
170
	end
171
	
172
	
173
end
174
175
176
177
function rednetControl()
178
	term.setCursorPos(1, 1);
179
	term.setBackgroundColor(colors.lightGray);
180
	term.setTextColor(colors.white);
181
	
182
	for i = 1, 20 do
183
		for j = 1, 26 do
184
			if (i == 1 or i == 20 or j == 1 or j == 26) then
185-
				term.setBackgroundColor(colors.blue);
185+
				term.setBackgroundColor(colors.gray);
186
			end
187
			write(" ");
188-
			term.setBackgroundColor(colors.lightBlue);
188+
			term.setBackgroundColor(colors.lightGray);
189
		end
190
		if (i ~= 20) then
191
			print();
192
		end
193
	end
194
	
195-
	term.setCursorPos(4, 3);
195+
	term.setCursorPos(3, 3);
196
	write("Advanced Rednet Console");
197
	
198-
	term.setBackgroundColor(colors.orange);
198+
	term.setBackgroundColor(colors.blue);
199
	term.setCursorPos(3, 6);
200
	write("    OPEN Rednet       ");
201
	term.setCursorPos(3, 8);
202
	write("    CLOSE Rednet      ");
203
	term.setCursorPos(3, 10);
204
	write("  Rednet Broadcast    ");
205
	term.setCursorPos(3, 12);
206
	write("    Send Message      ");
207
	term.setCursorPos(3, 14);
208
	write("     Get Message      ");
209
	term.setCursorPos(3, 16);
210
	write("    Computer ID       ");
211
	term.setCursorPos(3, 18);
212
	write("        Exit          ");
213
	
214
	local event, button, x, y = os.pullEvent("mouse_click");
215
	
216
	if (button == 1) then
217
		if (y == 6) then
218
			rednet.open("back");
219
			showInformationMessage("Rednet Turned On");
220
			sleep(2);
221
		end
222
		if (y == 8) then
223
			rednet.close("back");
224
			showInformationMessage("Rednet Turned Off");
225
			sleep(2);
226
		end
227
		if (y == 10) then
228
			message = showInputDialog("Broadcast Message");
229
			showInformationMessage("Broadcasting...", "");
230
			rednet.broadcast(message);
231
			sleep(2);
232
		end
233
		if (y == 12) then
234
			id = tonumber(showInputDialog("Target ID"));
235
			message = showInputDialog("Enter Message");
236
			showInformationMessage("Sending Message...", "");
237
			rednet.send(id, message);
238
			sleep(2);
239
		end
240
		if (y == 14) then
241
			timeout = tonumber(showInputDialog("Enter Timeout"));
242
			showInformationMessage("Waiting for", "message");
243
			id, msg = rednet.receive(timeout);
244
			if (msg == nil) then
245
				showErrorMessage("Receive Timeout.");
246
				sleep(2);
247
			else
248
				showInformationMessage(id, msg);
249
				sleep(5);
250
			end
251
		end
252
		if (y == 16) then
253
			showInformationMessage("Computer ID", os.getComputerID());
254
			sleep(5);
255
		end
256
		
257
		if (y == 18) then
258
			return;
259
		end
260
		rednetControl();
261
	end
262
end
263
264
function displayMainMenu()
265
	term.setBackgroundColor(colors.yellow);
266
	term.setTextColor(colors.red);
267
268
	term.setCursorPos(2, 5);
269
	write("  Current GPS Position  ");
270
	
271
	term.setCursorPos(2, 7);
272
	write("       Mail System      ");
273
	
274
	term.setCursorPos(2, 9);
275
	write("       Enter Chat       ");
276
	
277
	term.setCursorPos(2, 11);
278
	write("    Rednet Console      ");
279
	
280
	term.setCursorPos(2, 13);
281
	write("      Reconnect         ");
282
	
283
	term.setCursorPos(2, 15);
284
	write("       Shutdown         ");
285
	
286
	local event, button, x, y = os.pullEvent("mouse_click");
287
288
	if (button == 1) then
289
		if (y == 5) then
290
			showInformationMessage("Getting Location", "");
291
			if (gps.locate(5) == nil) then
292
				showErrorMessage("No GPS Signal.");
293
				sleep(2);
294
			else
295
				x, y, z = gps.locate();
296
				showInformationMessage("Your Location: ", x .. ", " .. y .. ", " .. z);
297
				sleep(5);
298
			end
299
		end
300
		
301
		if (y == 7) then
302
		end
303
		
304
		if (y == 9) then
305
			name = showInputDialog("Server Hostname");
306
			usrname = showInputDialog("Username");
307
			shell.run("chat", "join", name, usrname);
308
		end
309
		
310
		if (y == 11) then
311
			showInformationMessage("Please Wait...", "");
312
			sleep(2);
313
			rednetControl();
314
		end
315
		
316
		if (y == 13) then
317
			showInformationMessage("Connecting...", "");
318
			connected = 0;
319
			connectToServer();
320
			
321
		end
322
		
323
		if (y == 15) then
324
			showInformationMessage("Shutting Down...", "");
325
			sleep(2);
326
			os.shutdown();
327
		end
328
		
329
	end
330
	
331
	repaint();
332
	displayMainMenu();
333
334
end
335
336
337
338
339
lock();
340
341
connectToServer();
342
repaint();
343
showOSInformation();
344
345
if (connected == 0) then
346
	showErrorMessage("No Carrier");
347
	sleep(5);
348
	os.reboot();
349
else
350
	showInformationMessage("Connected to", serverName);
351
	sleep(3);
352
end
353
354
355
repaint();
356
displayMainMenu();