Check A File For Specific Text?
Started by popdog15, Aug 22 2013 09:15 PM
15 replies to this topic
#1
Posted 22 August 2013 - 09:15 PM
I'm making a security system, and I have a file with the 'admins' of it. I need a way for the program to check the admin file if the person using the player detector is indeed an admin. I've heard I can use string.sub() to do this, but I'm unaware of the syntax and really how it works.
#2
Posted 22 August 2013 - 10:05 PM
if you have a file like this for example:
rank=line:match(".*"..user..":([^\n]+).")
basically it looks to see if there is something after user..":"
(.+) will output anything, as long as the user exists
more info on patterns here
Mk352:banned Cloudy:admin PixelToast:awesomeyou could use this to get the user's rank:
rank=line:match(".*"..user..":([^\n]+).")
basically it looks to see if there is something after user..":"
(.+) will output anything, as long as the user exists
more info on patterns here
#3
Posted 22 August 2013 - 10:18 PM
PixelToast, on 22 August 2013 - 10:05 PM, said:
if you have a file like this for example:
rank=line:match("."..user.."
[^\n]+).")
basically it looks to see if there is something after user..":"
(.+) will output anything, as long as the user exists
more info on patterns here
Mk352:banned Cloudy:admin PixelToast:awesomeyou could use this to get the user's rank:
rank=line:match("."..user.."
basically it looks to see if there is something after user..":"
(.+) will output anything, as long as the user exists
more info on patterns here
#4
Posted 22 August 2013 - 10:25 PM
isAdmin=line:match(".*"..user.." :([^\n]+).")=="admin"
or if you just have a normal list with just names
isAdmin=line:match(".*("..user..")\n*")~=nil
or if you just have a normal list with just names
isAdmin=line:match(".*("..user..")\n*")~=nil
#5
Posted 22 August 2013 - 11:34 PM
PixelToast, on 22 August 2013 - 10:25 PM, said:
isAdmin=line:match(".*"..user.."
[^\n]+).")=="admin"
or if you just have a normal list with just names
isAdmin=line:match(".*("..user..")\n*")~=nil
or if you just have a normal list with just names
isAdmin=line:match(".*("..user..")\n*")~=nil
#6
Posted 23 August 2013 - 12:28 AM
local file=fs.open("admins","r")
local admins=file.readAll()
file.close()
while true do
e,p=os.pullEvent("player")
if admins:match(".*("..p..")\n*") then
-- do stuff
end
end
EDIT: fixed, sorry it was 2 AM
#7
Posted 23 August 2013 - 12:31 AM
EDIT: *got ninja'ed by PixelToast*
#8
Posted 23 August 2013 - 01:47 AM
uhhh pixel don't you need to specify a mode eg.("r","w","a") so I believe it should be
fs.open("admins", "r")
#11
#13
Posted 23 August 2013 - 12:24 PM
Freack100, on 23 August 2013 - 12:12 PM, said:
okay, (I've checked the APIs) It's a feature of the IO API, the FS API don't provides this feature... right?
local h = io.open("test")
for k,v in pairs(h) do
print(k," = ",v)
end
h:close()
it will work... this won't work...local h = fs.open("test")
for k,v in pairs(h) do
print(k," = ",v)
end
h.close()
#14
Posted 23 August 2013 - 01:27 PM
Why not use have a table which has textutils.serialize applied to it and saved in a file?
#16
Posted 23 August 2013 - 02:14 PM
I'd highly recommend the Lua User's Wiki rather than the lua documentation. It reads much easier in my opinion.
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users











