Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local JSON=require "libraries/json";
- local args={...}
- if (#args<1) then error("please provide a token") end
- local token=args[1]
- local dataDir="nms"
- local id=nil
- if (fs.exists(dataDir.."/nmsId")) then
- local f=fs.open(dataDir.."/nmsId")
- id=tonumber(f.read())
- f.close()
- end
- local ws, err = http.websocket("wss://nmserver.ddns.net/websocket/")
- if ws then
- print("performing login...")
- if (id==nil) then
- ws.send("{\"login\":\""..token.."\"}")
- else
- ws.send("{\"login\":\""..token.."\",id:"..id+"}")
- end
- local answer = JSON.parse(ws.receive());
- print(answer)
- if (answer["status"]~="accepted")then
- print("token rejected")
- return
- end
- print("token accepted: "..answer["id"])
- ws.close()
- else print(err)
- end
Add Comment
Please, Sign In to add comment