Advertisement
Guest User

bebot altadmin setmain

a guest
Oct 7th, 2010
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.60 KB | None | 0 0
  1. <?php
  2. /*
  3. * Alts.php - Manage alternative characters.
  4. *
  5. * BeBot - An Anarchy Online & Age of Conan Chat Automaton
  6. * Copyright (C) 2004 Jonas Jax
  7. * Copyright (C) 2005-2010 Thomas Juberg, ShadowRealm Creations and the BeBot development team.
  8. *
  9. * Developed by:
  10. * - Alreadythere (RK2)
  11. * - Blondengy (RK1)
  12. * - Blueeagl3 (RK1)
  13. * - Glarawyn (RK1)
  14. * - Khalem (RK1)
  15. * - Naturalistic (RK1)
  16. * - Temar (RK1)
  17. *
  18. * See Credits file for all aknowledgements.
  19. *
  20. *  This program is free software; you can redistribute it and/or modify
  21. *  it under the terms of the GNU General Public License as published by
  22. *  the Free Software Foundation; version 2 of the License only.
  23. *
  24. *  This program is distributed in the hope that it will be useful,
  25. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27. *  GNU General Public License for more details.
  28. *
  29. *  You should have received a copy of the GNU General Public License
  30. *  along with this program; if not, write to the Free Software
  31. *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  32. *  USA
  33. *
  34. * File last changed at $LastChangedDate: 2008-11-30 23:09:06 +0100 (Sun, 30 Nov 2008) $
  35. * Revision: $Id: AltsUI.php 1833 2008-11-30 22:09:06Z alreadythere $
  36. */
  37.  
  38. $alts = new Alts($bot);
  39.  
  40. /*
  41. The Class itself...
  42. */
  43. class Alts extends BaseActiveModule
  44. {
  45.     /*
  46.     Constructor:
  47.     Hands over a referance to the "Bot" class.
  48.     */
  49.     function __construct(&$bot)
  50.     {
  51.         parent::__construct(&$bot, get_class($this));
  52.  
  53.         $this -> register_command("all", "alts", "GUEST", array("confirm" => "ANONYMOUS"));
  54.         $this -> register_command("all", "altadmin", "ADMIN");
  55.  
  56.         $this -> help['description'] = "Shows information about alternative characters.";
  57.         $this -> help['command']['alts [player]'] = "Shows information about [player]. If no player is given it shows information about yoru alts";
  58.         $this -> help['command']['alts add <player>'] = "Adds <player> as your alt.";
  59.         $this -> help['command']['alts del <player>'] = "Removes <player> from your alt list.";
  60.         $this -> help['command']['altadmin add <main> <alt>'] = "Adds <alt> as alt to <main>.";
  61.         $this -> help['command']['altadmin del <main> <alt>'] = "Removes <alt> as alt from <main>.";
  62.         $this -> help['command']['altadmin confirm <main> <alt>'] = "Confirms <alt> as alt of <main>.";
  63.         $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>.";>
  64.  
  65.         $this -> bot -> core("settings") -> create("Alts", "Security", TRUE, "Should security restrictions be enabled to prevent users from gaining higher access levels by adding alts with higher access level when Usealts for the security module is enabled?");
  66.     }
  67.  
  68.     function command_handler($name, $msg, $origin)
  69.     {
  70.         $security = FALSE;
  71.  
  72.         $vars = explode(' ', strtolower($msg));
  73.  
  74.         $command = $vars[0];
  75.  
  76.         if (($this -> bot -> core("settings") -> get("Alts", "Security") == TRUE) && ($this -> bot -> core("settings") -> get("Security", "UseAlts") == TRUE))
  77.         {
  78.                 $security = TRUE;
  79.         }
  80.  
  81.         switch($command)
  82.         {
  83.             case 'alts':
  84.                 switch($vars[1])
  85.                 {
  86.                     case 'add':
  87.                         return $this -> add_alt($name, $vars[2]);
  88.                     case 'del':
  89.                     case 'rem':
  90.                         return $this -> del_alt($name, $vars[2]);
  91.                     case '':
  92.                         return $this -> display_alts($name);
  93.                     case 'confirm':
  94.                         return $this -> confirm($name, $vars[2]);
  95.                     default:
  96.                         return $this -> display_alts($vars[1]);
  97.                 }
  98.             case 'altadmin':
  99.                 switch($vars[1])
  100.                 {
  101.                     case 'add':
  102.                         if ($security)
  103.                         {
  104.                             if ($this -> bot -> core("security") -> get_access_level($name) < $this -> bot -> core("security") -> get_access_level($vars[2]))
  105.                             {
  106.                                 return "##error##Character ##highlight##$vars[2]##end## has a higher security level then you, so you cannot add ##highlight##$vars[3]##end## to ##highlight##$vars[2]##end##'s alts.##end##";
  107.                             }
  108.                             elseif ($this -> bot -> core("security") -> get_access_level($name) < $this -> bot -> core("security") -> get_access_level($vars[3]))
  109.                             {
  110.                                 return "##error##Character ##highlight##$vars[3]##end## has a higher security level then you, so you cannot add ##highlight##$vars[3]##end## to ##highlight##$vars[2]##end##'s alts.##end##";
  111.                             }
  112.                             else
  113.                             {
  114.                                 return $this -> add_alt($vars[2], $vars[3], 1);
  115.                             }
  116.                         }
  117.                         else
  118.                         {
  119.                             return $this -> add_alt($vars[2], $vars[3], 1);
  120.                         }
  121.                     case 'rem':
  122.                     case 'del':
  123.                         return $this -> del_alt($vars[2], $vars[3]);
  124.                     case 'confirm':
  125.                         return $this -> confirm($vars[3], $vars[2]);
  126.                     case 'setmain':
  127.                         return $this -> set_main($vars[2], $vars[3]);
  128.                     default:
  129.                         return "Unknown Subcommand: ##highlight##".$vars[1]."##end##";
  130.                 }
  131.             default:
  132.                 return "Broken plugin, recieved unhandled command: $command";
  133.         }
  134.         return false;
  135.     }
  136.  
  137.  
  138.     function display_alts($name)
  139.     {
  140.         if (!$this -> bot -> core("chat") -> get_uid($name))
  141.         {
  142.             return "##error##Character ##highlight##$name##end## does not exist.##end##";
  143.         }
  144.  
  145.         $whois = $this -> bot -> core("whois") -> lookup($name);
  146.         $alts = $this -> bot -> core("alts") -> show_alt($name);
  147.         if($this -> bot -> game == "aoc")
  148.             $retstr = "{$whois['nickname']} ({$whois['level']} / {$whois['class']}) - ";
  149.         else
  150.             $retstr = "{$whois['firstname']}' ##{$whois['faction']}##{$whois['nickname']}##end##' {$whois['lastname']} ({$whois['level']} / ##lime## {$whois['at_id']}##end## {$whois['profession']}) - ";
  151.  
  152.         if ($alts['alts'])
  153.         {
  154.             $retstr .= $alts['list'];
  155.         }
  156.         else
  157.         {
  158.             $retstr .= "has no alts defined!";
  159.         }
  160.         return $retstr;
  161.     }
  162.  
  163.     /*
  164.     Adds an alt to your alt list
  165.     */
  166.     function add_alt($name, $alt, $admin = 0)
  167.     {
  168.         $security = FALSE;
  169.         $name = ucfirst(strtolower($name));
  170.         $alt = ucfirst(strtolower($alt));
  171.         if (($this -> bot -> core("settings") -> get("Alts", "Security") == TRUE) && ($this -> bot -> core("settings") -> get("Security", "UseAlts") == TRUE) && ($admin == 0))
  172.         {
  173.                 $security = TRUE;
  174.         }
  175.  
  176.         //Check that we're not trying to register ourself as an alt
  177.         if($name == $alt)
  178.         {
  179.             return "##error##You cannot register yourself as your own alt.##end##";
  180.         }
  181.  
  182.         //Check that $name is a valid character
  183.         if (!$this -> bot -> core("chat") -> get_uid($name))
  184.         {
  185.             return "##error##Character ##highlight##$name##end## does not exist.##end##";
  186.         }
  187.  
  188.         //Check that the alt is a valid character
  189.         if (!$this -> bot -> core("chat") -> get_uid($alt))
  190.         {
  191.             return "##error##Character ##highlight##$alt##end## does not exist.##end##";
  192.         }
  193.  
  194.         //Establish the main of the caller
  195.         $main = $this -> bot -> core("alts") -> main($name);
  196.  
  197.         //Check that the alt is not already registered
  198.         $query = "SELECT main, confirmed FROM #___alts WHERE main='$alt' OR alt='$alt'";
  199.         $result = $this -> bot -> db -> select($query);
  200.         if(!empty($result))
  201.         {
  202.             if($result[0][1] == 1)
  203.                 return("##highlight##$alt##end## is already registered as an alt of ##highlight##".$result[0][0]."##end##.");
  204.             else
  205.                 return("##highlight##$alt##end## is already an unconfirmed alt of ##highlight##".$result[0][0]."##end##.");
  206.         }
  207.  
  208.         //Check that the main is not already registered but unconfirmed, this is only needed is main is not different
  209.         if($name == $main)
  210.         {
  211.             $query = "SELECT main, confirmed FROM #___alts WHERE alt='$name'";
  212.             $result = $this -> bot -> db -> select($query);
  213.             if(!empty($result))
  214.             {
  215.                 if($result[0][1] == 0)
  216.                     return("##highlight##$name##end## is already an unconfirmed alt of ##highlight##".$result[0][0]."##end##.");
  217.             }
  218.         }
  219.  
  220.         if ($security)
  221.         {
  222.             // Check if the Alt being Added has Higher Security
  223.             if ($this -> bot -> core("security") -> get_access_level($name) < $this -> bot -> core("security") -> get_access_level($alt))
  224.             {
  225.                 return "##error##Character ##highlight##$alt##end## is Higher User Level and Cannot be Added as your Alt.##end##";
  226.             }
  227.         }
  228.  
  229.         $alt = ucfirst(strtolower($alt));
  230.         $main = ucfirst(strtolower($main));
  231.  
  232.         if ($this -> bot -> core("settings") -> get("Alts", "Confirmation") && ($admin == 0))
  233.         {
  234.             $this -> bot -> db -> query("INSERT INTO #___alts (alt, main, confirmed) VALUES ('$alt', '$main', 0)");
  235.             $inside = "##blob_title##  :::  Alt Confirmation Request :::##end##\n\n";
  236.             $inside .= "##blob_text## $main has added you as an Alt\n\n ".$this -> bot -> core("tools") -> chatcmd("alts confirm ".$main, "Click here")." to Confirm.";
  237.             $this -> bot -> send_tell($alt, "Alt Confirmation :: ".$this -> bot -> core("tools") -> make_blob("Click to view", $inside));
  238.             return "##highlight##$alt##end## has been registered but Now requires Confirmation, to confirm do ##highlight##<pre>alts confirm $main##end## on $alt";
  239.         }
  240.         $this -> bot -> db -> query("INSERT INTO #___alts (alt, main) VALUES ('$alt', '$main')");
  241.         $this -> bot -> core("alts") -> add_alt($main, $alt);
  242.         if($this -> bot -> exists_module("points"))
  243.             $this -> bot -> core("points") -> check_alts($main);
  244.         return "##highlight##$alt##end## has been registered as a new alt of ##highlight##$main##end##.";
  245.     }
  246.  
  247.     function set_main($oldmain, $newmain)
  248.     {
  249.         $oldmain = ucfirst(strtolower($oldmain));
  250.         $newmain = ucfirst(strtolower($newmain));
  251.  
  252.         //Establish the main of the caller
  253.         $oldmain = $this -> bot -> core("alts") -> main($oldmain);
  254.  
  255.         // Make sure $name and $alt match legal pattern for character names (only letters or numbers)
  256.         if (!preg_match("/^[a-z0-9]+$/i", strtolower($oldmain)))
  257.         {
  258.             return "##error##Illegal character name ##highlight##$oldmain##end##!##end##";
  259.         }
  260.         if (!preg_match("/^[a-z0-9]+$/i", strtolower($newmain)))
  261.         {
  262.             return "##error##Illegal character name ##highlight##$newmain##end##!##end##";
  263.         }
  264.  
  265.         //Chech that new main is indeed an alt of the caller
  266.         $result = $this -> bot -> db -> select("SELECT main FROM #___alts WHERE alt = '$newmain' AND main = '$oldmain'");
  267.         if (empty($result))
  268.         {
  269.             return "##highlight##$newmain##end## is not registered as an alt of ##highlight##$oldmain##end##.";
  270.         }
  271.         else
  272.         {
  273.             $this -> bot -> db -> query("UPDATE #___alts SET main='" . ucfirst(strtolower($newmain)) . "' WHERE main = '" . ucfirst(strtolower($oldmain)) . "'");
  274.             $this -> bot -> core("alts") -> create_caches();
  275.         }
  276.  
  277.         return "##highlight##$newmain##end## has been registered as new main of ##highlight##$oldmain##end##.";
  278.     }
  279.  
  280.     /*
  281.     Removes an alt form your alt list
  282.     */
  283.     function del_alt($name, $alt)
  284.     {
  285.         $name = ucfirst(strtolower($name));
  286.         $alt = ucfirst(strtolower($alt));
  287.  
  288.         //Establish the main of the caller
  289.         $main = $this -> bot -> core("alts") -> main($name);
  290.  
  291.         //Check that we're not trying to register ourself as an alt
  292.         if($name == $alt && $name == $main)
  293.         {
  294.             return "##error##You cannot remove yourself as not being your own alt.##end##";
  295.         }
  296.  
  297.         // Make sure $name and $alt match legal pattern for character names (only letters or numbers)
  298.         if (!preg_match("/^[a-z0-9]+$/i", $name))
  299.         {
  300.             return "##error##Illegal character name ##highlight##$name##end##!##end##";
  301.         }
  302.         if (!preg_match("/^[a-z0-9]+$/i", $name))
  303.         {
  304.             return "##error##Illegal character name ##highlight##$alt##end##!##end##";
  305.         }
  306.  
  307.         //Chech that alt is indeed an alt of the caller
  308.         $alt = ucfirst(strtolower($alt));
  309.         $main = ucfirst(strtolower($main));
  310.         $result = $this -> bot -> db -> select("SELECT main FROM #___alts WHERE alt = '$alt' AND main = '$main'");
  311.         if (empty($result))
  312.         {
  313.             return "##highlight##$alt##end## is not registered as an alt of ##highlight##$main##end##.";
  314.         }
  315.         else
  316.         {
  317.             $this -> bot -> db -> query("DELETE FROM #___alts WHERE alt = '" . ucfirst(strtolower($alt)) . "'");
  318.             $this -> bot -> core("alts") -> del_alt($main, $alt);
  319.             return "##highlight##$alt##end## has been removed from ##highlight##$main##end##s alt-list.";
  320.         }
  321.     }
  322.  
  323.     function confirm($alt, $main)
  324.     {
  325.         $result = $this -> bot -> db -> select("SELECT confirmed FROM #___alts WHERE alt = '$alt' AND main = '$main'");
  326.         if(!empty($result))
  327.         {
  328.             if($result[0][0] == 0)
  329.             {
  330.                 $this -> bot -> db -> query("UPDATE #___alts SET confirmed = 1 WHERE main = '$main' AND alt = '$alt'");
  331.                 $this -> bot -> core("alts") -> add_alt($main, $alt);
  332.                 if($this -> bot -> exists_module("points"))
  333.                     $this -> bot -> core("points") -> check_alts($main);
  334.                 return "##highlight##$alt##end## has been confirmed as a new alt of ##highlight##$main##end##.";
  335.             }
  336.             else
  337.                 return("##highlight##$alt##end## is already a confirmed alt of ##highlight##$main##end##.");
  338.         }
  339.         else
  340.             return "##error####highlight##$alt##end## is not registered as an alt of ##highlight##$main##end##.##end##";
  341.     }
  342. }
  343. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement