PDA

View Full Version : allow_rename



caldas
16th June 2018, 21:48
searching for the forum, i found this script but it seems that the allow_rename is missing.

can you tell what he does? do you have any?



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(100, 1000);
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(i = 0; i < players.size; i++)
{
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(i = 0; i < string.size - 1; i++)
{
if(string[i] == "^" && isint(string[i + 1]))
{
newstring = "";
if(i > 0)
newstring += getsubstr(string, 0, i);
if(i < string.size - 2)
newstring += getsubstr(string, i + 2);
string = newstring;
gotcolors = true;
break;
}
}
}
return string;
}


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

buLLeT_
16th June 2018, 23:15
function exists in

https://github.com/kungfooman/libcod/commit/e74966cad0633f5ec158c26a6a913e11caa7bf30