Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local configFile = fs.open("client.cfg", "r")
- local config = textutils.unserialise(configFile.readAll())
- configFile.close()
- rednet.open(config.modemLocation)
- local Orientation = {
- NORTH = 0,
- SOUTH = 1,
- WEST = 2,
- EAST = 3
- }
- local startingOrientation = config.orientation
- local serverID = config.serverID
- local map = {}
- local function connectToServer()
- rednet.send(config.serverID, {
- type = "connect"
- })
- local id,msg = rednet.receive(5)
- if msg == nil or msg.type ~= "accepted" then
- printError("Connection refused.")
- return false
- else
- print("Connected to server (" .. id .. ")")
- serverID = id
- return true
- end
- end
- local function clientLoop(eventData)
- local e, p1, p2, p3, p4, p5 = unpack(eventData)
- if e == "rednet_message" then
- local id, tbl = p1, p2
- if id == serverID then
- if tbl.type == "keepalive" then
- rednet.send(id, { type = "keepalive" })
- elseif tbl.type == "disconnect" then
- print("Disconnected: " .. tbl.reason)
- return false
- elseif tbl.type == "map" then
- print("Received map from server")
- map = tbl.data
- end
- else
- print("Message from unknown sender " .. id)
- rednet.send(config.serverID, {
- type = "suspicious_computer",
- id = id
- })
- end
- elseif e == "terminate" then
- rednet.send(serverID, { type = "disconnect" })
- return false
- end
- return true
- end
- local ok = connectToServer(config.serverID)
- if not ok then return end
- rednet.send(config.serverID, { type = "map" })
- while true do
- local eventData = { os.pullEventRaw() }
- if not clientLoop(eventData) then break end
- end
Advertisement
Add Comment
Please, Sign In to add comment