Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent=os.pullEventRaw
- local users={{name="Sylvyrfysh",pin=1324},{name="tester",pin=1111}};
- local typedOptions={{key="1",funct=(function() buy(); end)},{key="2",funct=(function() term.clear(); term.setCursorPos(1,1); end)},{key="3",funct=(function() print(cell.getEnergyStored("RF")*100/cell.getMaxEnergyStored("RF").."%"); end)}};
- local args={...};
- local tempuser;
- local modem=peripheral.wrap("bottom");
- local cmodem=peripheral.wrap("back");
- cell=peripheral.wrap("cofh_thermalexpansion_energycell_1");
- term.clear()
- term.setCursorPos(1,1);
- local function main()
- write("\nSylvyrfysh Inc Power Plant and Sales. Press 1 to buy, 2 to clear screen, and 3 to see how much power is currently available.");
- end
- local function auth()
- while true do
- term.clear();
- term.setCursorPos(1,1);
- write("Username: ");
- unm=read();
- term.write('\n');
- write("PIN: ");
- pss=read("*")
- for t,y in pairs(users) do
- if y.name==unm and y.pin==pss then
- term.clear();
- tempuser=unm;
- return true;
- end
- end
- term.clear();
- term.setCursorPos(1,1);
- write("Auth failed. Retry? y/n");
- key=os.pullEvent("char")[2];
- if not key=="y" or key=="Y" then
- return false;
- end
- end
- end
- function sendf(channel,rChannel,message,mID)
- modem.transmit(channel,rChannel,textutils.serialize({content=message,senderID=os.getComputerID(),chan=channel,rChan=rChannel,messageID=mID or "revolutOS:wirelessAPI"}));
- return true;
- end
- function send(us1,us2,amount)
- if not sendf(21450,21450,{paying=us1,payed=us2,price=amount},"fevAPI") then return false; end
- mess=waitForMessage(21500);
- return mess.content.auth;
- end
- function waitForMessage(channel)
- if not modem.isOpen(channel) then modem.open(channel); end
- while true do
- e={os.pullEvent("modem_message")};
- if e[3]==channel then
- e[5]=textutils.unserialize(e[5]);
- return e[5];
- end
- end
- end
- function buy()
- if not auth() then return; end
- am={50000,100000,200000,400000,1000000,2000000,5000000,10000000};
- fv={200,390,765,1500,3675,7250,21000,40000};
- while true do
- write("Please input the amout of enrgy you would like to buy: (amount in RF)\n");
- print("1: 50k");
- print("2: 100k");
- print("3: 200k");
- print("4: 400k");
- print("5: 1m");
- print("6: 2m");
- print("7: 5m");
- print("8: 10m");
- print("9: Cancel");
- e=os.pullEvent("char")[2];
- if tonumber(e) then
- if tonumber(e)==9 then return; end
- write(am[tonumber(e)].." selected. Price is "..fv[tonumber(e)]..". Is this OK? (y/n): ");
- e=os.pullEvent("char")[2];
- if e=="y" or e=="Y" then
- if send(tempuser,"Sylvyrfysh",fv[tonumber(e)]) then
- ticks=am[tonumber(e)]/400;
- cmodem.transmit(3,3,"on");
- write("Dispensing for "..(ticks*20).." seconds. ("..am[tonumber(e)].."RF");
- sleep(ticks*20);
- cmodem.transmit(3,3,"off");
- else
- print("Fev authorization failed or funds were low.");
- end
- end
- else
- print("Number not received.");
- sleep(5);
- end
- write("Logout? (y/n): ");
- e=os.pullEvent("char")[2];
- if e=="y" or e=="Y" then
- tempuser="";
- end
- end
- tempuser="";
- end
- term.setCursorPos(1,1);
- while true do
- main()
- e={os.pullEvent()};
- if e[1]=="char" then
- for r,y in pairs(typedOptions) do
- if y.key==e[2] then
- y.funct();
- end
- end
- end
- tempuser="";
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement