Development > Coding and development discussion

altadmin setmain <old main> <new main>

(1/2) > >>

heljeere:
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: ---$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>.";>
--- End code ---
( Add this after the other help commands in __construct(&$bot) )

Add command processing:

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

Add the actual function:

--- Code: --- 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##.";
}
--- End code ---

heljeere:
Added the complete code to pastebin too for easier reading.

http://pastebin.com/GpSKMMXL

heljeere:
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: ---$this -> bot -> db -> query("UPDATE #___alts SET main='" . ucfirst(strtolower($newmain)) . "', alt='" . ucfirst(strtolower($oldmain)) . "' WHERE alt = '" . ucfirst(strtolower($newmain)) . "'");
--- End code ---

It now properly swaps your new and old mains so you don't lose and toons :)

Runemy:
Thanks for this one mate! :)

Glarawyn:
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. :)

Navigation

[0] Message Index

[#] Next page

Go to full version