Started by PaullyBeenis, Mar 05, 2021, 12:13 am
Quote from: Lupus590 on Mar 05, 2021, 10:19 amYou have a security problem, rednet IDs depend on the computer IDs and computer IDs can be faked. You will want to look into secure signing systems of real-life instead, which will include some public-key encryption. You might want to look at real-life SSL and key exchange.For having multiple client sessions at the same time, the way that real-life web servers do it is to have the server have a very short term memory and every request to be a new thread.A basic rundown with how real-life web servers do this, they get a request and start up a thread to resolve it. Once the thread has resolved the request it sends a response and then terminates itself, the server now has no memory of the request unless that request interacted with the permanent data store.For CC, you can ignore the thread part as the event queue will be able to take care of this for you.
-- Client side:-- User confirms identity of server from a rednet 3 way handshake type method to confirm its not being spoofed.-- User sends rednet msg: authenticate(PaullyBeenis,1234)-- Server side:-- 2 files running at once, one that listens for messages and adds requests to the event queue, and another file that will pull the events and then run them???lua file 1:while true do local id,msg,dist=rednet.receive(port) if msg.find(str, "authenticate") then os.queueEvent("authenticate", username, password) endendlua file 2:while true do local event, username, password = os.pullEvent() if event == "authenticate" then if accounts[username]:authenticate(password) then -- Add session to sessions list with UNIX time of when it was started and a number token to refer to it. -- provide number token to the client to use during banking commands ex: getBalance(token). -- Have a 3rd looping lua file running that checks session list every 60 seconds to see if sessions are expired and removes them if they are. else print("Event: " .. event) endend
Quote from: PaullyBeenis on Mar 06, 2021, 01:57 am-- 2 files running at once, one that listens for messages and adds requests to the event queue, and another file that will pull the events and then run them???
Quote from: Lupus590 on Mar 06, 2021, 08:44 amQuote from: PaullyBeenis on Mar 06, 2021, 01:57 am-- 2 files running at once, one that listens for messages and adds requests to the event queue, and another file that will pull the events and then run them???You don't need two separate files or even a duplicate event loop (maybe, the handshake stuff might disrupt that) Also, it sounds like you are not aware of the parallel API which will be useful in this situation.rednet.recive doesn't have a port argument, see: https://tweaked.cc/module/rednet.html#v:receivesending table data will be better than using string.find (mentioning which, you should double-check how you are using string.find as you have done it wrong in the example that you've given.