BeBot - An Anarchy Online and Age Of Conan chat automaton

Development => Coding and development discussion => Topic started by: heljeere on October 07, 2010, 01:45:08 pm

Title: altadmin setmain <old main> <new main>
Post by: heljeere on October 07, 2010, 01:45:08 pm
I have no idea where to post this. None of the forums really fit.

Anyway, I've had to change people's mains a number of times and it's a tedious job (if they have many alts that is). Instead of doing it manually for the Nth time i decided to change the altadmin command to do it for me.

With these changes you can "altadmin setmain <old main> <new main>" to change someone's main. The name specified in <new main> must be registered as an alt of <old main>.

Add help:

Code: [Select]
$this -> help['command']['altadmin setmain <old main> <new main>'] = "Sets <new main> as main for <old main>. <new main> must be a registered alt of <old main>.";>( Add this after the other help commands in __construct(&$bot) )

Add command processing:
Code: [Select]
case 'setmain':
return $this -> set_main($vars[2], $vars[3]);
( Add this right above the default case in command_handler($name, $msg, $origin) )

Add the actual function:
Code: [Select]
function set_main($oldmain, $newmain)
{
$oldmain = ucfirst(strtolower($oldmain));
$newmain = ucfirst(strtolower($newmain));

//Establish the main of the caller
$oldmain = $this -> bot -> core("alts") -> main($oldmain);

// Make sure $name and $alt match legal pattern for character names (only letters or numbers)
if (!preg_match("/^[a-z0-9]+$/i", strtolower($oldmain)))
{
return "##error##Illegal character name ##highlight##$oldmain##end##!##end##";
}
if (!preg_match("/^[a-z0-9]+$/i", strtolower($newmain)))
{
return "##error##Illegal character name ##highlight##$newmain##end##!##end##";
}

//Chech that new main is indeed an alt of the caller
$result = $this -> bot -> db -> select("SELECT main FROM #___alts WHERE alt = '$newmain' AND main = '$oldmain'");
if (empty($result))
{
return "##highlight##$newmain##end## is not registered as an alt of ##highlight##$oldmain##end##.";
}
else
{
$this -> bot -> db -> query("UPDATE #___alts SET main='" . ucfirst(strtolower($newmain)) . "' WHERE main = '" . ucfirst(strtolower($oldmain)) . "'");
$this -> bot -> db -> query("UPDATE #___alts SET main='" . ucfirst(strtolower($newmain)) . "', alt='" . ucfirst(strtolower($oldmain)) . "' WHERE alt = '" . ucfirst(strtolower($newmain)) . "'");
$this -> bot -> core("alts") -> create_caches();
}

return "##highlight##$newmain##end## has been registered as new main of ##highlight##$oldmain##end##.";
}
Title: Re: altadmin setmain <old main> <new main>
Post by: heljeere on October 07, 2010, 01:49:14 pm
Added the complete code to pastebin too for easier reading.

http://pastebin.com/GpSKMMXL
Title: Re: altadmin setmain <old main> <new main>
Post by: heljeere on October 07, 2010, 10:54:48 pm
There was a slight bug that made you lose the old main in the alt list after doing setmain. I've edited the code in the original post and added:

Code: [Select]
$this -> bot -> db -> query("UPDATE #___alts SET main='" . ucfirst(strtolower($newmain)) . "', alt='" . ucfirst(strtolower($oldmain)) . "' WHERE alt = '" . ucfirst(strtolower($newmain)) . "'");
It now properly swaps your new and old mains so you don't lose and toons :)
Title: Re: altadmin setmain <old main> <new main>
Post by: Runemy on October 08, 2010, 03:11:01 am
Thanks for this one mate! :)
Title: Re: altadmin setmain <old main> <new main>
Post by: Glarawyn on October 13, 2010, 04:40:00 pm
At one point we were I was looking at restructuring the database a bit for the next BeBot release and this was one of the things addressed in the new design. Instead of the concept of mains and alts characters are just characters. The new design has every character tied to an account ID that is unique to BeBot. So a player simply registers their characters. By default the first character would be the display name (main) for the BeBot account. I designed security so that the display name could be changed to any character registered to the account by the player. I also had the option of setting a custom display name if that feature was enabled by the bot's administrator.

Unfortunately I only got the design work done before real life got insanely busy. :)
Title: Re: altadmin setmain <old main> <new main>
Post by: Odinochka on October 18, 2010, 07:11:38 am
At one point we were I was looking at restructuring the database a bit for the next BeBot release and this was one of the things addressed in the new design. Instead of the concept of mains and alts characters are just characters. The new design has every character tied to an account ID that is unique to BeBot. So a player simply registers their characters. By default the first character would be the display name (main) for the BeBot account. I designed security so that the display name could be changed to any character registered to the account by the player. I also had the option of setting a custom display name if that feature was enabled by the bot's administrator.

Unfortunately I only got the design work done before real life got insanely busy. :)

I have it working, completely overhauled the alts module etc. For version 5.4(i think :P) tho, contact me on msn([email protected]) if you need the code and the database sample.
PS.
Napoleon had no horse cause he was too short to ride it. On the painting it's white but it was done only for his ego.
Title: Re: altadmin setmain <old main> <new main>
Post by: Tsamoonia on December 06, 2010, 10:42:58 pm
im getting an error i_d something or another for line 73
Title: Re: altadmin setmain <old main> <new main>
Post by: Tsamoonia on December 06, 2010, 10:43:42 pm
im getting an error i_d something or another for line 73
SimplePortal 2.3.7 © 2008-2024, SimplePortal