Author Topic: Name Checker/Kick  (Read 8967 times)

0 Members and 3 Guests are viewing this topic.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Name Checker/Kick
« on: October 07, 2013, 09:06:49 AM »
Hello everyone.
I'm developing a script that is sort of advanced, and I have a base idea of it. I need some help with something, and it would be great if you could point me in the right direction.
I'm part of a family friendly server environment, where we don't allow swearing/cursing, this includes bad words in names. What I'm trying to do is to create a script to check the name and find words from a list, and if it find a word from that list in your name, you'll get kicked.

It seems to be quite hard, if not impossible to even pull off. I've been thinking about using string.sub together with the PlayerInitialSpawn hook, but other than that I'm pretty ignorant of what else I need to do to pull this off (if it's even possible).

Any help is appreciated. I'm still pretty newbie in Lua, but I'm starting to understand more and more of it. So if I don't get what you mean the first time, please be patient.

Thanks in advance!
~Decicus/Alex
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Name Checker/Kick
« Reply #1 on: October 07, 2013, 11:46:06 AM »
I hope you don't mind I just did this for you. :D

I am sitting on 24 hour CQ and am terribly bored. Not to mention this is a very simple script.

http://pastebin.com/wykH1YHB

Granted.. this isn't tested but it should work. Just replace and add the strings in the table at the top with the strings you wish to kick for. Make sure you take into account possible workarounds. For example (while remaining family-friendly myself):
ask and @$k and @sk and a$k are all different strings and would each need to be added to the table.

Also be careful because you could be unintentionally kicking for legitimate strings. Someone with the name assignment would be kicked for having the word (insert first three letters of that word here) as a part of their name.

Trying to write a script that would detect strings while also finding legitimate uses of those strings would indeed be a fairly difficult task. Choose your strings carefully.

There are some strings that would never be legitimate. For example the F word, the C word, the S word. You get my gist.

Code: [Select]
local kickstrings = { "test", "these", "strings" } --Make sure these are ALL lowercase

function NameKicker( ply )

local pname = string.lower( ply:Nick() )

for k, v in pairs( kickstrings ) do

if string.find( pname, v ) then

ULib.kick( ply, "Auto-Kicked for having the string " .. v .. " in your name. Please change your name and rejoin" )

end

end

end
hook.Add( "PlayerInitialSpawn", "NameKicker", NameKicker )

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Name Checker/Kick
« Reply #2 on: October 07, 2013, 11:56:37 AM »
I have fallen in love with you, MrPresident. Thanks a lot!

And yes, I actually kept in mind that some words include other words. So I was only going to use the strongest words that you basically said yourself.
Thank you, MrP. I appreciate this greatly!
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Name Checker/Kick
« Reply #3 on: October 07, 2013, 12:35:54 PM »
Place a return after the kick line.


Otherwise, the loop might continue after it kicks a player and cause an error.

Code: [Select]
local kickstrings = { "test", "these", "strings" } --Make sure these are ALL lowercase

function NameKicker( ply )

local pname = string.lower( ply:Nick() )

for k, v in pairs( kickstrings ) do

if string.find( pname, v ) then

ULib.kick( ply, "Auto-Kicked for having the string " .. v .. " in your name. Please change your name and rejoin" )
return

end

end

end
hook.Add( "PlayerInitialSpawn", "NameKicker", NameKicker )

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Name Checker/Kick
« Reply #4 on: October 07, 2013, 12:50:04 PM »
Thanks. I did that.
How would I do it basically print a message for the admins? I'm not sure how I'm gonna add IsAdmin()/IsSuperAdmin() into that.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Name Checker/Kick
« Reply #5 on: October 07, 2013, 04:15:29 PM »
Just posting again to verify that it did in fact work. I added a part of my name to that list to test, and it kicked me.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Name Checker/Kick
« Reply #6 on: October 07, 2013, 04:49:25 PM »
Don't forget our NameChanged hook. :)
Experiencing God's grace one day at a time.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Name Checker/Kick
« Reply #7 on: October 07, 2013, 05:14:31 PM »
Don't forget our NameChanged hook. :)
Useful. I think I'll add that to the script. Thanks!
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Name Checker/Kick
« Reply #8 on: October 07, 2013, 06:57:35 PM »
Some fun learn as you go ideas;
Instead of kicking, you could maybe run a name change on the client side. (I forget what Garry's blocked allowing run on clients.)
If that works, change name once to something like IhadANaughtyName<some_random_number>.
Store the player in a table. If they change their name back to something naughty in it, as detected by the name change hook, then they get kicked.
If they change to something without setting off the alert kick, code exits gracefully.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Name Checker/Kick
« Reply #9 on: October 07, 2013, 07:03:43 PM »
I like the idea, JamminR, but I'm pretty sure you can't change anyone's names in-game anymore. I know a few years back that some Source games allowed you to have a different name than your Steam nickname. Now every game (including Garry's Mod) takes the nickname from Steam and uses that instead.

So I'm pretty sure (although not 100% sure), that it won't really work.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Name Checker/Kick
« Reply #10 on: October 07, 2013, 07:36:27 PM »
He's right. You're not allowed to change a client's name anymore.

As for printing a message to admins, why don't you just use ULX's built in asay? It would automatically send the message to all admins.

I just installed windows on this laptop so I don't have my copies of ULib/ULX on here yet to reference. I believe it's ulx.asay but I don't remember the arguements off the top of my head.

you can find it in chat.lua in your ULX directory.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Name Checker/Kick
« Reply #11 on: October 08, 2013, 04:46:04 AM »
I'll take a look at it, MrPresident. Thanks for the tip.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: Name Checker/Kick
« Reply #12 on: October 08, 2013, 07:16:38 AM »
Mr President, this is exactly what I need!! But I am not too good at lua. Do I just create a lua file and copy what is in your pastebin or do I put it in with another existing lua file? Thanks!

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Name Checker/Kick
« Reply #13 on: October 08, 2013, 08:01:08 AM »
Hey Storm. I have a download for this, here: https://www.dropbox.com/s/sr91sp1nx8jhhs5/bnk.lua
Just add the Lua file into <GMod server directory>\lua\autorun\server\
Edit: Now also includes the function to kick if someone changes their name to something else that includes one of the words inside "kickstrings".

Add words in the "kickstrings" table. Be careful if you're adding new words though. Let's say you add the word "low" (even though that word is not bad itself, just an example) to the list of "kickstrings". Then players with the names "slow", "slower", "lower" and so on will also be kicked.
« Last Edit: October 08, 2013, 08:30:44 AM by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Storm

  • Full Member
  • ***
  • Posts: 220
  • Karma: 4
Re: Name Checker/Kick
« Reply #14 on: October 08, 2013, 08:57:10 AM »
Wow thanks so much! It works perfectly. You should make this an official addon!
« Last Edit: October 08, 2013, 10:25:34 AM by Storm »