PtokaX forum

PtokaX => FAQ section => Topic started by: sphynxsoft on 13 November, 2005, 00:50:10

Title: About checking nicknames
Post by: sphynxsoft on 13 November, 2005, 00:50:10
Hi there!
I just melted my brains trying to figure out how to check the users' nicknames. The situaation is I want a nick to look like [Cx]Nickname, where x may be 1, 6, 7, 8 or 17. That's all. Nothing less, nothing more. Can you help? I owe you big!
Title:
Post by: bastya_elvtars on 13 November, 2005, 01:04:07
Are you using the PtokaX way or a script?
Title:
Post by: sphynxsoft on 13 November, 2005, 01:15:58
No, just PtokaX.
Title:
Post by: sphynxsoft on 13 November, 2005, 01:58:07
Thanks a lot, Mutor... All my gratitude!
Title:
Post by: bastya_elvtars on 13 November, 2005, 02:24:34
This is my paranoid version.

-- created by bastya_elvtars
--[[    NICK CHECKING STUFF
   =====================
   
BETTER NOT CHANGE THE BADNICK TABLE IF YOU DON'T KNOW WHAT YOU ARE DOING!!!
]]

-- The nick rule redirect address MUST be set in PtokaX.
-- Note that bad characters always get checked in every nick!!!
BadChars = { " ", ";", ",", "+", "<++", "^", "~",}

userlevels={ [-1] = 1, [0] = 5, [1] = 4, [2] = 3, [3] = 2 }

-- Define what prefixes can be used.
-- Can be anything between ( and { and [ and ] and } and ] , these can also be mixed.
-- note that check is case sensitive, so [hun] is not equal to [HUN]
PrefixesNeeded =
  {
    "[HUN]",
    "[EU]",
    "(HUN)",
  }

--[[
Now something new. With these prefixes, one can not enter the hub.
This one works even if prefix check is off.
Obviously these only affect unreg users, and should only contain the most necessary elements.
(Only unregs can have bad prefix, because a user using a bad prefix cannot be registered IMHO. :P)
]]
BadPrefixes=
 {
   "[OP]",
   "[VIP]",
   "[SU]",
 }

-- Values: 1 to disconnect, 2 to redirect
BadPrefixToDo=1

Level=3

ExclusionList= -- case of lettters does not matter
{
  "{hublistpinger}","pinger","test-nick"
}

function Main()
  Prefixes={Needed={},Bad={}}
  for k,v in pairs(BadPrefixes) do
    Prefixes.Bad[v]=1
  end
  Prefixes.List="\r\n====================\r\n"
  table.sort(PrefixesNeeded)
  for k,v in pairs(PrefixesNeeded) do
    Prefixes.Needed[v]=1
    Prefixes.List=Prefixes.List..v.."\r\n"
  end
  Prefixes.List=Prefixes.List.."====================\r\n\r\nNote that the check is case sensitive, a.k.a. [prefix] and [PREFIX] are different."
  Immune={}
  for i,v in ipairs(ExclusionList) do
    Immune[string.lower(v)]=1
  end
end

function MyINFOArrival(user,data)
  if Immune[string.lower(user.sName)] then return end
  if not user.bConnected then
    for i,v in ipairs(BadChars) do
if string.find(user.sName,v,1,true) then
 local bdchr=v
 user:SendData("NickNameCheck","Your nick contains the following invalid character (if nothing shows, it's a space): "..v)
 user:SendData("NickNameCheck","Please correct it and reconnect! Try using only numbers, letters, brackets, underscores and hyphens.")
 user:SendData("NickNameCheck","Disconnects...")
 user:Disconnect()
 return
end
    end
    local _,_,prefix = string.find(user.sName, "^([%[%{%(]%S+[%)%}%]])%S+")
    if prefix and Prefixes.Bad[prefix] and not user.bRegistered then
user:SendData("NickNameCheck", prefix.." - This prefix is not allowed for you to use.")
user:Disconnect()
    end
    if userlevels[user.iProfile] < Level then
if prefix then
 if not Prefixes.Needed[prefix] then
   user:SendData("NickNameCheck", "\r\nBad prefix, use one of these:"..Prefixes.List)
   if BadPrefixToDo==1 then
user:Disconnect()
   else
user:Redirect(frmHub:GetNickRuleRedirAddr())
   end
   return
 end
else
 user:SendData("NickNameCheck", "\r\nNo prefix specified, use one of these:"..Prefixes.List)
 if BadPrefixToDo==1 then
   user:Disconnect()
 else
   user:Redirect(frmHub:GetNickRuleRedirAddr())
 end
end
    end
  end
end
Title:
Post by: sphynxsoft on 13 November, 2005, 02:28:30
LOL! Thank you a lot for the script! I'll try both! Keep up te good job!