Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: renaming

  1. #1
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts

    renaming

    Hey all
    Found a way to rename players without touching the "name" cvar (thus no setclientcvar needed)

    Also: blocking renaming of certain players
    Also: blocking renaming of certain players + renaming those players from script anyway without touching the name cvar.

    Coming soon to a libcod installation near you
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  2. The Following 5 Users Say Thank You to IzNoGoD For This Useful Post:

    kung foo man (13th January 2015),Mitch (13th January 2015),Ni3ls (13th January 2015),voron00 (13th January 2015),YuriJurek (13th January 2015)

  3. #2
    Corporal voron00's Avatar
    Join Date
    Nov 2014
    Posts
    248
    Thanks
    64
    Thanked 216 Times in 116 Posts
    That's great, thanks. I wish it would be also possible to rename the server itself, i mean the "console" thing in chat.

  4. #3
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by voron00 View Post
    That's great, thanks. I wish it would be also possible to rename the server itself, i mean the "console" thing in chat.
    You can already sent custom messages with sendGameServerCommand. But i think renaming "console:" to "...." is possible.

  5. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Quote Originally Posted by Mitch View Post
    You can already sent custom messages with sendGameServerCommand. But i think renaming "console:" to "...." is possible.
    But as it is already possible with sendgameservercommand, there is no real need to find this. Just tunnel your b3 into a cvar instead of the rcon say thingy and sendgameservercommand from there.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  6. #5
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Ok, the functions have some (initially) unintended side-effects:

    The "name" cvar can be read as an input after which the script can decide to 1) rename the player to that name 2) not rename the player at all 3) rename the player to a different name.
    Basically these new functions allow for a "rename" event.

    https://github.com/kungfooman/libcod...913e11caa7bf30
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  7. #6
    Corporal voron00's Avatar
    Join Date
    Nov 2014
    Posts
    248
    Thanks
    64
    Thanked 216 Times in 116 Posts
    Hmm it seems now on SD names are changing instantly, without having to wait till the next round, even without calling these functions, but i like it, actually.
    Last edited by voron00; 16th January 2015 at 03:27.

  8. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    PHP Code:
    playerinit()
    {
        
    self.izno = []; //initialize player-info array
        
    self checkinitialname(); //fix initial "Unknown Soldier" names
        
    self.izno["userinfoname"] = self get_userinfo("name"); //keep track of the name as per the user's userinfo
        
    self thread monitor_namechange();
        
    self allow_rename(false);
    }

    checkinitialname()
    {
        
    name self get_userinfo("name");
        
    self.izno["realname"] = name;
        
    result checkname(name); //checkname returns true if the name is not allowed or a duplicate
        
    if(result)
        {
            
    //as i disallow duplicate names, this while() loop tries to find an open JumpersHeavenFan#NUMBER for the player to use
            
    while(result)
            {
                
    self.izno["realname"] = "JumpersHeavenFan#" randomintrange(1001000);
                
    result self checkname(self.izno["realname"]);
            }
            
    //now, to keep the userinfo the same to not excessively trigger a clientuserinfochanged event, store the user's name before renaming him
            
    userinfoname self get_userinfo("name");

            
    //this will allow clientuserinfochanged to rename the player
            
    self allow_rename(true);

            
    //change the name in the userinfo, then call the clientuserinfochanged function to do the actual renaming
            
    self set_userinfo("name"self.izno["realname"]);
            
    self clientuserinfochanged();

            
    //disallow any future user-started rename events
            
    self allow_rename(false);

            
    //restore the original userinfo
            
    self set_userinfo("name"userinfoname);
        }
        
    }

    monitor_namechange()
    {
        
    self endon("disconnect");
        while(
    true)
        {
            
    name self get_userinfo("name");

            
    //if the name in userinfo is different than the one stored serverside, the user changed his /name
            
    if(name != self.izno["userinfoname"])
            {
                
    //namechange event
                //check if user is allowed to change his name and what his real name should be
                
    self.izno["realname"] = self namechanged(name);

                
    //next few lines to the same as the renaming in checkinitialname()
                
    self set_userinfo("name"self.izno["realname"]);
                
    self allow_rename(true);
                
    self clientuserinfochanged();
                
    self allow_rename(false);
                
    self.izno["userinfoname"] = name;
                
    self set_userinfo("name"name);
            }
            
    wait 0.05;
        }
    }

    namechanged(newname)
    {
        
    in_use checkname(newname); //if the name is currently in use, try keeping your old name. If that's in use too, generate a new random name
        
    if(in_use)
        {
            
    old_in_use checkname(self.izno["realname"]);
            
    self iprintlnbold("No duplicate names allowed");
            if(!
    old_in_use)
                return 
    self.izno["realname"]; //user renaming DENIED
            
    else
            {
                
    //find a new name for this user as his old name is in use
                
    while(old_in_use)
                {
                    
    newname "JumpersHeavenFan#" randomintrange(1001000);
                    
    result self checkname(newname);
                }
                return 
    newname;
            }
        }
        else
            return 
    newname//renaming allowed
    }

    checkname(name)
    {
        
    name tolower(stripcolors(name)); //strip colors, remove capitals
        
    switch(name)
        {
            
    //you can add more names to this banned-names list.
            
    case "Unknown Soldier"
            case 
    "UnnamedPlayer":
                return 
    true;
        }
        
    players getentarray("player""classname");
        for(
    0players.sizei++)
        {
            if(
    players[i] == self)
                continue;
            if(
    tolower(stripcolors(players[i].name)) == name//another player has the same name after stripping colors
                
    return true;
        }
        return 
    false;
    }

    stripcolors(string)
    {
        
    gotcolors true;
        while(
    gotcolors)
        {
            
    gotcolors false;
            for(
    0string.size 1i++)
            {
                if(
    string[i] == "^" && isint(string[1]))
                {
                    
    newstring "";
                    if(
    0)
                        
    newstring += getsubstr(string0i);
                    if(
    string.size 2)
                        
    newstring += getsubstr(string2);
                    
    string newstring;
                    
    gotcolors true;
                    break;
                }
            }
        }
        return 
    string;
    }

    isint(char)
    {
        
    asc getAscii(char);
        return 
    asc <= 57 && asc >= 48;

    This code will work very well with the change. It prevents duplicate names and the rename notification of players when they rename to a duplicate name and back to their old name.
    Can easily be extended to prevent players from renaming on an individual basis.
    Last edited by Mitch; 22nd January 2015 at 17:08. Reason: added "); to iprintlnbold
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  9. #8
    Corporal voron00's Avatar
    Join Date
    Nov 2014
    Posts
    248
    Thanks
    64
    Thanked 216 Times in 116 Posts
    Quote Originally Posted by IzNoGoD View Post
    PHP Code:
    playerinit()
    {
        
    self.izno = []; //initialize player-info array
        
    self checkinitialname(); //fix initial "Unknown Soldier" names
        
    self.izno["userinfoname"] = self get_userinfo("name"); //keep track of the name as per the user's userinfo
        
    self thread monitor_namechange();
        
    self allow_rename(false);
    }

    checkinitialname()
    {
        
    name self get_userinfo("name");
        
    self.izno["realname"] = name;
        
    result checkname(name); //checkname returns true if the name is not allowed or a duplicate
        
    if(result)
        {
            
    //as i disallow duplicate names, this while() loop tries to find an open JumpersHeavenFan#NUMBER for the player to use
            
    while(result)
            {
                
    self.izno["realname"] = "JumpersHeavenFan#" randomintrange(1001000);
                
    result self checkname(self.izno["realname"]);
            }
            
    //now, to keep the userinfo the same to not excessively trigger a clientuserinfochanged event, store the user's name before renaming him
            
    userinfoname self get_userinfo("name");

            
    //this will allow clientuserinfochanged to rename the player
            
    self allow_rename(true);

            
    //change the name in the userinfo, then call the clientuserinfochanged function to do the actual renaming
            
    self set_userinfo("name"self.izno["realname"]);
            
    self clientuserinfochanged();

            
    //disallow any future user-started rename events
            
    self allow_rename(false);

            
    //restore the original userinfo
            
    self set_userinfo("name"userinfoname);
        }
        
    }

    monitor_namechange()
    {
        
    self endon("disconnect");
        while(
    true)
        {
            
    name self get_userinfo("name");

            
    //if the name in userinfo is different than the one stored serverside, the user changed his /name
            
    if(name != self.izno["userinfoname"])
            {
                
    //namechange event
                //check if user is allowed to change his name and what his real name should be
                
    self.izno["realname"] = self namechanged(name);

                
    //next few lines to the same as the renaming in checkinitialname()
                
    self set_userinfo("name"self.izno["realname"]);
                
    self allow_rename(true);
                
    self clientuserinfochanged();
                
    self allow_rename(false);
                
    self.izno["userinfoname"] = name;
                
    self set_userinfo("name"name);
            }
            
    wait 0.05;
        }
    }

    namechanged(newname)
    {
        
    in_use checkname(newname); //if the name is currently in use, try keeping your old name. If that's in use too, generate a new random name
        
    if(in_use)
        {
            
    old_in_use checkname(self.izno["realname"]);
            
    self iprintlnbold("No duplicate names allowed
            if(!old_in_use)
                return self.izno["
    realname"]; //user renaming DENIED
            else
            {
                //find a new name for this user as his old name is in use
                while(old_in_use)
                {
                    newname = "
    JumpersHeavenFan#" + randomintrange(100, 1000);
                    
    result self checkname(newname);
                }
                return 
    newname;
            }
        }
        else
            return 
    newname//renaming allowed
    }

    checkname(name)
    {
        
    name tolower(stripcolors(name)); //strip colors, remove capitals
        
    switch(name)
        {
            
    //you can add more names to this banned-names list.
            
    case "Unknown Soldier"
            case 
    "UnnamedPlayer":
                return 
    true;
        }
        
    players getentarray("player""classname");
        for(
    0players.sizei++)
        {
            if(
    players[i] == self)
                continue;
            if(
    tolower(stripcolors(players[i].name)) == name//another player has the same name after stripping colors
                
    return true;
        }
        return 
    false;
    }

    stripcolors(string)
    {
        
    gotcolors true;
        while(
    gotcolors)
        {
            
    gotcolors false;
            for(
    0string.size 1i++)
            {
                if(
    string[i] == "^" && isint(string[1]))
                {
                    
    newstring "";
                    if(
    0)
                        
    newstring += getsubstr(string0i);
                    if(
    string.size 2)
                        
    newstring += getsubstr(string2);
                    
    string newstring;
                    
    gotcolors true;
                    break;
                }
            }
        }
        return 
    string;
    }

    isint(char)
    {
        
    asc getAscii(char);
        return 
    asc <= 57 && asc >= 48;

    This code will work very well with the change. It prevents duplicate names and the rename notification of players when they rename to a duplicate name and back to their old name.
    Can easily be extended to prevent players from renaming on an individual basis.
    Thanks for this, but there is an error in self iprintlnbold("No duplicate names allowed, also i tried this code but im getting segmentation fault on server after 30 seconds, wtf.

  10. #9
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by voron00 View Post
    Hmm it seems now on SD names are changing instantly, without having to wait till the next round, even without calling these functions, but i like it, actually.
    That was already possible
    Code:
    setClientNameMode("auto_change");

  11. #10
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by voron00 View Post
    Thanks for this, but there is an error in self iprintlnbold("No duplicate names allowed, also i tried this code but im getting segmentation fault on server after 30 seconds, wtf.
    The segmentation fault is probably due to the address in gsc_player_clientuserinfochanged. (which is for 1.3 or 1.2)
    I fixed the iprintlnbold error in the original code post. Now it is easier to look at the code and see what it does.

    Edit: i modified the rename script to an event function like player messages. (CodeCallback_PlayerCommand)

    https://github.com/M-itch/libcod/com...d949182ab52720 (+ 2 commits to fix some issues)

    PHP Code:
    CodeCallback_UserInfoChanged(clientNum)
    {
        
    oldname self.name;
        
    newname self get_userinfo("name");
        
        if(
    oldname != newname)
        {
            
    self iprintlnbold("Your old name is " oldname);
            
    self iprintlnbold("Your new name is " newname);
        }
        
        
    self clientuserinfochanged();

    I updated my libcod builds for cod2 1.0 - 1.3 on http://znation.nl/libcod/ubuntu/.
    Last edited by Mitch; 22nd January 2015 at 20:37.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •