MOD- names, prevent users from taking the suffix name

Blasteh

big tits
Apr 3, 2013
1,156
521
Hey lads,
So basically I'm trying to figure out something, let's say there is a Moderator named "MOD-Example", how can I prevent users from registering/flagging/taking the username "Example", I know a simple, but annoying way is to just create a new account named "Example", but that's also creating unnecessary data in the database and there has to be a simpler way.
 

Platinum

Hello!
Sep 2, 2012
295
282
Although I don’t have any idea how you would go about doing this as it’s just an idea but rather than having to rename someone from “Example” to “MOD-Example” and then somehow not let anyone register with “Example”, is it not possible to make it so if users rank = 5 (or whatever the MOD rank is) in the EMU the prefix at the beginning of anyone who’s rank 5 will have “MOD-“

Don’t know if that makes sense or not.
 

Blasteh

big tits
Apr 3, 2013
1,156
521
Although I don’t have any idea how you would go about doing this as it’s just an idea but rather than having to rename someone from “Example” to “MOD-Example” and then somehow not let anyone register with “Example”, is it not possible to make it so if users rank = 5 (or whatever the MOD rank is) in the EMU the prefix at the beginning of anyone who’s rank 5 will have “MOD-“

Don’t know if that makes sense or not.
Yeah, that's what I was thinking, but that may screw up some things - I'm not sure.

Because that'd be just in-game, I'd like it fully like that, for the site and client.
 

Platinum

Hello!
Sep 2, 2012
295
282
Yeah, that's what I was thinking, but that may screw up some things - I'm not sure.

Because that'd be just in-game, I'd like it fully like that, for the site and client.

If it’s a plausible option then I don’t see why you shouldn’t attempt it, yes perhaps something might screw up but through failure comes success :p just make sure to back everything up if you do end up deciding to make edits and whatnot!

For the site couldn’t you write code near {username} if user is rank 5, MOD-{username} will appear?
 

Hayd3n

peace.wtf
Jun 14, 2013
76
29
Yeah, that's what I was thinking, but that may screw up some things - I'm not sure.

Because that'd be just in-game, I'd like it fully like that, for the site and client.
You could do it that way, shouldn't break anything since it's just checking if their a moderator and placing a prefix before the username.
You could also just do a reserved username function in your cms (register) and emu (flagme command)
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
I have a register script that prevent users registering with names in the database. I'll share the code later (it's 3am)

Personally I would write a script on the login. If rank == 5 and name does not start with MOD- add it
If rank < 5 and name starts with MOD- remove it.

Otherwise it will become sloppy code, and be too complicated
 

Muff

Member
Aug 5, 2015
252
129
Although I don’t have any idea how you would go about doing this as it’s just an idea but rather than having to rename someone from “Example” to “MOD-Example” and then somehow not let anyone register with “Example”, is it not possible to make it so if users rank = 5 (or whatever the MOD rank is) in the EMU the prefix at the beginning of anyone who’s rank 5 will have “MOD-“

Don’t know if that makes sense or not.
Yeah it's pretty possible @Damien made a Function in Project alias (Plus Emulator edit) for when any person with the rank of (2)
is given the prefix MOD- tag at the beginning there name it's pretty cool :)
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
Yeah it's pretty possible @Damien made a Function in Project alias (Plus Emulator edit) for when any person with the rank of (2)
is given the prefix MOD- tag at the beginning there name it's pretty cool :)
I forgot to attach my code * -

But he wants their username to change on the CMS, Not just the emulator.
-----------------------------------------------------------------------------------------------------------
Alrighty So to answer this 2 part question:

First I'll supply the code for part 2 which is the blocking certain names for registering:

First Create The Table "registerblock" with the provided SQL.
Code:
CREATE TABLE `registerblock` (
  `word` varchar(80) NOT NULL,
  `EntireName` enum('0','1') NOT NULL DEFAULT '0',
  PRIMARY KEY (`word`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"Word" will be the character sequence you would like to block
"EntireName" is so you can say if the username is equal to, or if the username contains
Equal To = 1
Contains = 0

Example of how this works is if you put the value for word as "MOD-" and set "EntireName" equal to 1 , their username would need to be "MOD-" if you set "EntireName" equal to 0, their username could be "MOD-Name" or "RealMod-" and it will get blocked.

Now to add the code that actual blocks the name, Inside your app -> class.users.php file add a new function:

Code:
final public function allowedUsername($username){
        $registerBlocks = mysql_query("SELECT * FROM registerblock");
        while($word = mysql_fetch_assoc($registerBlocks)){
            if($word['EntireName'] == 1){
                if($username == $word['word']){
                    return false;
                }
            }else{
                if(strpos($username, $word['word']) !== false){
                    return false;
                }
            }
        }
        return true;
    }

Finally, in your Register() function add a new check below the validName to call to our new function allowedUsername

Example Code:

Code:
if($this->validName($template->form->reg_username)){
    if($this>allowedUsername($template>form>reg_username)){
        .....
    }
   }else{
     $template->form->error = 'Username Not Allowed';
        return;
     }
} else {
$template->form->error = 'Username is invalid';
return;
}
-----------------------------------------------------------------------------------------------------------
How to add MOD- to your username Solution 1 UNTESTED!!!!!!

In your Login function you have this:
Code:
$this->turnOn($template->form->reg_username);
That is what will send your username of who is logging in... Add this method:

Simple Explanation: If user logs in, and rank is equal to 5 , and their username does not start with MOD- it will update their username before assigning the session (See below). If they are not rank 5, and their username starts with "MOD-" (Maybe because they were deranked?) it will automatic revert it back to normal.

No reason to tell the user their username is changed because it will show it when they login (and if they don't pay attention they are dumb).
Code:
final public function staffUsername($username){
        $returnUsername = $username;
            $findUserInfo = mysql_fetch_assoc(mysql_query("SELECT `rank` FROM `users` WHERE `username` = '".$username."' LIMIT 1"));
            if($findUserInfo['rank'] == '5'){ //Put Your Moderator Rank Here
                if(substr( $username, 0, 4 ) != "MOD-"){
                    mysql_query("UPDATE `users` SET `username` = 'MOD-".$username."' WHERE `username` = '".$username."' LIMIT 1");
                    $returnUsername = "MOD-".$username;
                }
            }else{
                if(substr( $username, 0, 4 ) === "MOD-"){
                    mysql_query("UPDATE `users` SET `username` = '".substr($username, 4)."' WHERE `username` = '".$username."' LIMIT 1");
                    $returnUsername = substr($username, 4);
                }
            }
        return $returnUsername;
    }

So everywhere you see this:
Code:
$this->turnOn($template->form->reg_username);

Replace with this:
Code:
$this->turnOn(staffUsername($template->form->reg_username));

And Done!
 

Users who are viewing this thread

Top