collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18366
  • stats Total Topics: 2501
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Trouble with modified module  (Read 3760 times)

0 Members and 1 Guest are viewing this topic.

Offline Zarkingu

  • Contributor
  • *******
  • Posts: 34
  • Karma: +0/-0
Trouble with modified module
« on: June 02, 2005, 02:37:25 pm »
I've been modifying some of the modules to limit who got access to the different commands. I got 3 different groups at the moment (Superadmin, Admin, Raidleader).

All of a sudden my loot module decided to kick everyone that do not have access to the commands from privategroup. I've been checking the module over and over again, but can't find whats wrong.
Here is what it looks like


<?
/*
* Loot Module for BE Bot <http://bebot.fieses.net>
* Module coded by Craized <http://www.craized.net>

/*
Add a "_" at the beginning of the file (_Loot.php) if you do not want it to be loaded.
*/

$loot = new Rolls($bot);


$commands["tell"]["rem"] = &$loot;
$commands["tell"]["add"] = &$loot;
$commands["pgmsg"]["loot"] = &$loot;
$commands["pgmsg"]["add"] = &$loot;
$commands["pgmsg"]["rem"] = &$loot;
$commands["pgmsg"]["result"] = &$loot;
$commands["pgmsg"]["mode"] = &$loot;
$commands["pgmsg"]["list"] = &$loot;
$commands["pgmsg"]["clear"] = &$loot;

/*
The Class itself...
*/
class Rolls {
    var $bot;

    /*
    Constructor:
    Hands over a referance to the "Bot" class.
    */
    function Rolls (&$bot) {
        $this -> bot = &$bot;
        $this -> mode = "multi";
        if(!$this -> bot -> highlight_color) {
            $this -> highlight = "<font color=#CB11C9>";
            } else {

            $this -> highlight = "<font color=" . $this -> bot -> highlight_color . ">";
        }
    }

    /*
    This gets called on a tell with the command
    */
    function tell($name, $msg) {
        $highlight = $this -> highlight;
        if(preg_match("/^" . $this -> bot -> commpre . "rem ([0-9]+)/i", $msg, $info)) {
            unset($this -> loot[$info[1]][$name]);
            $this -> bot -> send_pgroup($highlight . $name . "</font> removed from rolls in slot$highlight #" . $info[1]);
            $this -> bot -> send_tell($name, $highlight . $name . " </font>removed from rolls in slot$highlight #" . $info[1]);
        }
        if(preg_match("/^" . $this -> bot -> commpre . "add ([0-9]+)/i", $msg, $info)) {
            $this -> add($name, $info[1]);
            $this -> bot -> send_tell($name, $this -> addmsg);
        }
    }

    /*
    This gets called on a msg in the privgroup with the command
    */
    function pgmsg($name, $msg) {
    if ( ($this -> bot -> admin -> in_group($name, "superadmin")) or ($this -> bot -> admin -> in_group($name, "admin")) or ($this -> bot -> admin -> in_group($name, "raidleader")) ) {
        $highlight = $this -> highlight;
        if(preg_match("/^" . $this -> bot -> commpre . "loot (.*)/i", $msg, $info)) {
            $this -> loot($info[1], $name);
        }
        }

        if(preg_match("/^" . $this -> bot -> commpre . "add ([0-9]+)/i", $msg, $info)) {
            $this -> add($name, $info[1]);
        }
        if ( ($this -> bot -> admin -> in_group($name, "superadmin")) or ($this -> bot -> admin -> in_group($name, "admin")) or  ($this -> bot -> raidleader -> in_group($name, "raidleader")) ) {
        if(preg_match("/^" . $this -> bot -> commpre . "list/i", $msg)) {
            $this -> rlist();
        }
        }

   if ( ($this -> bot -> admin -> in_group($name, "superadmin")) or ($this -> bot -> admin -> in_group($name, "admin")) or ($this -> bot -> admin -> in_group($name, "raidleader")) ) {
        if(preg_match("/^" . $this -> bot -> commpre . "mode ?(.*)/i", $msg, $info)) {
            if(!$info[1]) {
                $this -> bot -> send_pgroup("Loot mode currently set to$highlight " . $this -> mode . "</font>.");
            }
            if(!$this -> lead || $this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> admin -> in_group($name, "raidleader") || $this -> bot -> admin -> in_group($name, "admin")) {
                if(!$this -> lead) {
                    if($info[1] == single) {
                        $this -> mode = "single";
                        $this -> bot -> send_pgroup("Roll mode changed to$highlight single loot</font>.");
                    } else if($info[1] == multi) {
                        $this -> mode = "multi";
                        $this -> bot -> send_pgroup("Roll mode changed to$highlight multiple loot</font>.");
                    }
                    } else {
                    $this -> bot -> send_pgroup("You cannot change the loot mode while rolling is in progress.");
                }
            }
        }
        }

        if(preg_match("/^" . $this -> bot -> commpre . "rem ([0-9]+)/i", $msg, $info)) {
            unset($this -> loot[$info[1]][$name]);
            $this -> bot -> send_pgroup($highlight . $name . "</font> removed from rolls in slot$highlight #" . $info[1]);
        }

        if ( ($this -> bot -> admin -> in_group($name, "superadmin")) or ($this -> bot -> admin -> in_group($name, "admin")) or ($this -> bot -> admin -> in_group($name, "raidleader")) ) {
        if(preg_match("/^" . $this -> bot -> commpre . "result/i", $msg)) {
            if($this -> lead == $name || !$this -> lead || $this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> admin -> in_group($name, "raidleader") || $this -> bot -> admin -> in_group($name, "admin")) {
                $this -> roll($name);
            }
        }
        }

        if ( ($this -> bot -> admin -> in_group($name, "superadmin")) or ($this -> bot -> admin -> in_group($name, "admin")) or ($this -> bot -> admin -> in_group($name, "raidleader")) ) {
        if(preg_match("/^" . $this -> bot -> commpre . "clear/i", $msg)) {
            if($this -> lead == $name || !$this -> lead || $this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> admin -> in_group($name, "raidleader") || $this -> bot -> admin -> in_group($name, "admin")) {
                unset($this -> loot);
                unset($this -> lead);
                $this -> bot -> send_pgroup($highlight . $name . "</font><font color=#FF0000> cancelled the loot rolls in progress");
            }
        }
        }

      else
         {
      // Error message if a non admin tries to use loot commands.
      $this -> bot -> send_pgroup("</font><font color=#DB9C15>You must be an admin to do this</font>");
      }

    }

    function add($name, $slot) {
        $highlight = $this -> highlight;
        unset($present);
        if($this -> loot[$slot]) {
            if($this -> mode == 'single') {
                $slots = array_keys($this -> loot);
                foreach($slots as $key=>$sslot) {
                    $list = array_keys($this -> loot[$sslot]);
                    foreach($list as $playerslot=>$player) {
                        if($player == $name) {
                            unset($this -> loot[$sslot][$player]);
                            $present = true;
                        }
                    }
                }
                if($present == true) {
                    $this -> addmsg = $highlight . "$name</font> changed to slot$highlight #$slot</font>";
                    } else {
                    $this -> addmsg = $highlight . "$name</font> assigned to slot$highlight #$slot</font>";
                }
                $this -> loot[$slot][$name] = true;
                } else {
                $this -> loot[$slot][$name] = true;
                $this -> addmsg = $highlight . "$name</font> assiged to slot$highlight #$slot</font>";
            }
            } else {
            $this -> addmsg = "There is currently no roll in slot $slot";
        }
        $this -> bot -> send_pgroup($this -> addmsg);
    }

    function loot($msg, $name) {
        $highlight = $this -> highlight;
        if($this -> lead == $name || !$this -> lead) {
            $this -> lead = $name;
            $count = count($this -> loot)+1;
            $this -> loot[$count][item] = $msg;
            $this -> bot -> send_pgroup($highlight . $msg . "</font> being rolled in slot$highlight #" . $count);
        }
    }

    function roll($name){
        $highlight = $this -> highlight;
        $num = 1;
        if($this -> bot -> commands[pgmsg][leader] -> raidleader == $name || $this -> bot -> admin -> in_group($name, "raidleader") || $this -> bot -> admin -> in_group($name, "admin") || $this -> lead == $name || !$this -> lead) {
            foreach($this -> loot as $slot) {
                unset($winner);
                $users = array();
                $item = $slot[item];
                unset($slot[item]);
                $list = $slot;
                $users = array_keys($slot);
                $rolling = $users;
                $count = count($slot)-1;
                for($i = 1; $i <= 10000; $i++) {
                    $list[$users[rand(0, $count)]] += 1;
                }
                natsort($list);
                foreach($list as $name => $points) {
                    $winner = $name;
                }
                if(!$winner) {
                    $winner = Nobody;
                }
                $this -> bot -> send_pgroup($highlight . $winner . " </font>won the roll for$highlight " . $item . " </font>in slot$highlight #" . $num . "!");
                unset($this -> loot[$num]);
                unset($this -> lead);
                $num++;
            }
        }
    }

    function rlist() {
        $highlight = $this -> highlight;
        $num = 0;
        foreach($this -> loot as $slot) {
            unset($msg);
            $num++;
            $msg .= "Rolling on item$highlight $slot[item]</font> in slot$highlight #$num</font>:";
            if(count($slot) == 1) {
                $msg .= $highlight . " Nobody included";
                } else {
                $list = array_keys($slot);
                foreach($list as $key=>$player) {
                    if($player != "item") {
                        $msg .= "$highlight [$player]</font>";
                    }
                }
            }
            $this -> bot -> send_pgroup($msg);
        }
    }
}
?>


I'm not all that good in PHP, so might be something obvious I'm missing. So please bare with me :)
Zarkingu 210 MP RK2

Offline Zacix

  • Contributor
  • *******
  • Posts: 73
  • Karma: +0/-0
Trouble with modified module
« Reply #1 on: June 02, 2005, 02:51:58 pm »
There's no need to check if the user is in "superadmin" group, that is automatically checked every time you do the admin->in_group(...). Also, I use || instead of 'or'...but don't really know what's allowed in PHP.
Zacix
Current projects:
RINGBot, BeBot branch
Neutnet, RK2 Neutral massmessage network

Offline Derroylo

  • Contributor
  • *******
  • Posts: 43
  • Karma: +0/-0
Trouble with modified module
« Reply #2 on: June 02, 2005, 03:02:15 pm »
Well i changed the loot module too cuz it spames me to much when you have 50ppls on a raid and doing !add $ in the bot. When you are interested you can test my loot system :)

Download
Derroylo 220/23 NT RK2

Offline Zarkingu

  • Contributor
  • *******
  • Posts: 34
  • Karma: +0/-0
Trouble with modified module
« Reply #3 on: June 02, 2005, 03:25:46 pm »
Seems like I found the problem.
Changed

($this -> bot -> raidleader -> in_group($name, "raidleader"))

to

($this -> bot -> admin -> in_group($name, "raidleader"))

I know that some programing languages use || instead of or. Or seems to work fins in PHP tho, atleast not getting any errors :D
Zarkingu 210 MP RK2

 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm ]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am ]

* Who's Online
  • Dot Guests: 435
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal