Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top");
- local services = fs.open("/services", "r");
- local userFile = fs.open("/users", "r");
- local mailFile = fs.open("/mails", "r");
- local userID = {};
- local mailDatabase = {};
- local userCount = tonumber(userFile.readLine());
- local serviceCount = tonumber(services.readLine());
- local serviceName = {};
- local serviceAddress = {};
- local serverName = "JimNet Central Server";
- for i = 0, serviceCount - 1 do
- serviceName[i] = services.readLine();
- serviceAddress[i] = services.readLine();
- print ("Loaded Service. NAME:" .. serviceName[i] .. ", ADDR:" .. serviceAddress[i]);
- end
- for i = 0, userCount - 1 do
- userID = userFile.readLine();
- mailDatabase[i] = {};
- mailCount = tonumber(mailFile.readLine());
- for j = 0, mailCount - 1 do
- mailDatabase[i][j] = mailFile.readLine();
- end
- print ("Loaded Mail. ID:" .. userID .. ", MAILCOUNT: " .. mailCount);
- end
- sleep(1);
- term.clear();
- term.setCursorPos(1, 1);
- term.setTextColor(colors.red);
- print (" Phone Carrier Server\n");
- term.setTextColor(colors.white);
- while true do
- print ("\n\nListening for Requests...");
- id, msg = rednet.receive();
- print ("Incoming Message. ID:" .. id .. ", MSG:" .. msg);
- if (msg == "$REGISTER") then
- for i = 0, userCount-1 do
- if (userID[i] == id) then
- rednet.send(id, "$FAILED");
- print ("Terminal #" .. id .. " registration failed.");
- else
- userID[userCount] = id;
- userCount = count + 1;
- print ("Terminal #" .. id .. " joined the network.");
- term.setTextColor(colors.red);
- print ("Updating Databases...");
- end
- end
- end
- if (msg == "$SERVICES") then
- rednet.send(id, tostring(serviceCount));
- for i = 0, serviceCount - 1 do
- rednet.send(id, serviceName[i]);
- rednet.send(id, serviceAddress[i]);
- end
- end
- if (msg == "$INFO") then
- rednet.send(id, serverName);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment