User Control Panel
Advertisements

HELP US, HELP YOU!

Double trouble

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Review
View unanswered posts
Author Message
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Sun Jan 23, 2005 2:50 am    Post subject: Reply with quote

Right...Heres the situation

Before i starting working on it, it was working fine and dandy...
But now i've started to try and impliment Mirrors,
By using code like :
Code:
$bot->{msn} = {<br />  'bot@hotmail.co.uk' => new MSN (<br />     Handle => 'bot@hotmail.co.uk',<br />     Password => '********',<br />  ),<br />  'evozbot@gmail.com' => new MSN (<br />     Handle => 'evozbot@gmail.com',<br />     Password => '*********',<br />  ),<br />};


Theres my MSN objects....Everything else seems fine...

But when the code below is used, it is multigames in which it has to deliever messages to a room periodically to tell them that time is running out ect...
But on some messages it sends the twice!
I've searched long and hard for an explanation..
But havent got a clue....

Notice i only have 2 mirrors, is this a link? should i try with 3 to see if it sends it 3 times...

From what i can see it seems the gameover messages and new round messages are sent once but ones that describe time is running down appear twice...

Here is my WHOLE timeres sub....thank you for any help

Code:
<br />sub addTimers{<br />    my $self = shift;<br />    <br />    #Too keep convo's open.<br />   $timer->addforever(code => sub {<br />                                    my($timer,$msn) = @_;<br />                                    foreach my $handle (keys %{$bot->{msn}}) { <br />                                        foreach my $convo (values %{$bot->{msn}->{$handle}->getConvoList()}){<br />                                            $convo->sendtyping();<br />                                        }<br />                                    }<br />                                }, data => $bot->{msn}, interval => 120);<br />    #Snap timer                            <br />    $timer->addforever(code => sub {<br />                                    my($timer,$msn) = @_;<br />                                    my $snapon;<br />                                    foreach my $handle (keys %{$bot->{msn}}) { <br />                                        foreach my $convo (values %{$bot->{msn}->{$handle}->getConvoList()}){<br />                                            if(defined $convo->{in} && $convo->{in} eq "snap"){<br />                                                $snapon = "on";<br />                                            }<br />                                        }<br />                                    }<br />                                    if(!defined $snapon){<br />                                        $snapon = "off";<br />                                    }<br />                                    if($snapon eq "on"){<br />                                        &snap($self);<br />                                    }   <br />                                    else{<br />                                        return;<br />                                    }<br />                                }, data => $bot->{msn}, interval => 1);<br />   <br />   #The scramble's Timer<br />   $timer->addforever(code => sub {<br />                                    my($timer,$msn) = @_;<br />  <br />                                    my $time = time;<br />                                    $bot->{store}->{general}->{chatrooms}->{scramble}->{time} = time - 38 if(!defined $bot->{store}->{general}->{chatrooms}->{scramble}->{time});<br />                                    my $gone = $time - $bot->{store}->{general}->{chatrooms}->{scramble}->{time};<br />                                    my $chatroom  = "scramble";<br /><br />                                    if($gone == 20){<br />                                        my $message = "20 Seconds left! - Unscramble $bot->{store}->{general}->{chatrooms}->{scramble}->{scrambled} to win 5 points!!";   <br />                                        my $color = "009900";<br />                                        &chatAnnounce($message,$chatroom,$color);<br />                                        $bot->{store}->{general}->{chatrooms}->{scramble}->{worth} = 5;<br />                                    }<br />                                    elsif($gone == 30){<br />                                        my $word = $bot->{store}->{general}->{chatrooms}->{scramble}->{word};<br />                                        my @blanks;<br />                                        my @chars = split(//, $word);<br />                                        my $first = shift (@chars);<br />                                        my $last = pop (@chars);<br />                                        foreach my $item (@chars) {<br />                                            push (@blanks, "_");<br />                                        }<br />                                        unshift (@blanks, $first);<br />                                        push (@blanks, $last);<br /><br />                                        my $hint = join (" ", @blanks);<br />                                        my $message = "10 Seconds Left! - Unscramble : $bot->{store}->{general}->{chatrooms}->{scramble}->{scrambled} to win 2 points!\nHint : $hint";<br />                                        my $color = "0099ff";<br />                                        &chatAnnounce($message,$chatroom,$color);<br />                                        $bot->{store}->{general}->{chatrooms}->{scramble}->{worth} = 2;<br />                                    }<br />                                    elsif($gone >= 40){<br />                                        my $message = "Gameover - Starting a  new round.";<br />                                        &chatAnnounce($message,$chatroom);<br />                                        my ($unscram,$scram) = &get_random_word;<br />                                        $bot->{store}->{general}->{chatrooms}->{scramble}->{word} = $unscram;<br />                                        $bot->{store}->{general}->{chatrooms}->{scramble}->{scrambled} = $scram;<br />                                        $bot->{store}->{general}->{chatrooms}->{scramble}->{time} = time; <br />                                        $bot->{store}->{general}->{chatrooms}->{scramble}->{worth} = 10;<br />                                        $message = "New round : The scrambled word is : $scram - Unscramble it for 10 points!";<br />                                        &chatAnnounce($message,$chatroom);<br />                                    }   <br />                                }, data => $bot->{store}, interval => 1);<br /><br />    #Trivia                                <br />    $timer->addforever(code => sub {<br />                                    my($timer,$msn) = @_;<br />                                    if(!defined $bot->{store}->{general}->{chatrooms}->{trivia}->{answer}){ &startTrivia;}<br />                                    my $time = time;<br />                                    $bot->{store}->{general}->{chatrooms}->{trivia}->{time} = time - 38 if(!defined $bot->{store}->{general}->{chatrooms}->{trivia}->{time});<br />                                    my $gone = $time - $bot->{store}->{general}->{chatrooms}->{trivia}->{time};<br />                                    my $chatroom  = "trivia";<br /><br />                                    if($gone == 20){<br />                                        my $message = "40 Seconds left! - Question :  $bot->{store}->{general}->{chatrooms}->{trivia}->{question} to win 10 points!!" if(defined $bot->{store}->{general}->{chatrooms}->{trivia}->{question});   <br />                                        my $color = "009900";<br />                                        &chatAnnounce($message,$chatroom);<br />                                        $bot->{store}->{general}->{chatrooms}->{trivia}->{worth} = 10;<br />                                    }<br />                                    elsif($gone == 40){<br />                                        my $word = $bot->{store}->{general}->{chatrooms}->{trivia}->{answer};<br />                                        my @blanks;<br />                                        my @chars = split(//, $word);<br />                                        my $first = shift (@chars);<br />                                        my $last = pop (@chars);<br />                                        foreach my $item (@chars) {<br />                                            push (@blanks, "_") unless ($item eq " ");<br />                                            push (@blanks, " ") if($item eq " ");<br />                                        }<br />                                        unshift (@blanks, $first);<br />                                        push (@blanks, $last);<br /><br />                                        my $hint = join (" ", @blanks);<br />                                        my $messager = "20 Seconds Left! - Question : $bot->{store}->{general}->{chatrooms}->{trivia}->{question} to win 5 points!\nHint : $hint";<br />     <br />                                        &chatAnnounce($messager,$chatroom);<br />                                        $bot->{store}->{general}->{chatrooms}->{trivia}->{worth} = 5;<br />                                    }<br />                                    elsif($gone >= 60){<br />                                        my $message = "Gameover - Starting a  new round.";<br />                                        &chatAnnounce($message,$chatroom);<br />                                        &startTrivia;<br />                                    }<br />                                }, data => $bot->{store}, interval => 1);<br /><br />    #Timed blocks                                    <br />    $timer->addforever(code => sub {<br />                                    my($timer,$msn) = @_;<br />                                    foreach my $blocked (keys %{$bot->{store}->{blocks}}){<br />                                        if(defined $bot->{store}->{blocks}->{$blocked} && $bot->{store}->{blocks}->{$blocked} < time){<br />                                            delete $bot->{store}->{blocks}->{$blocked};<br />                                            $msn->call($blocked,"[!] OK, Youre block has expired.\nBut remember you will be blocked again if caught flooding!");<br />                                        }<br />                                    }   <br />                                    }, data => $bot->{msn}, interval => 5);<br />}


This problem occures in snapz, trivia, scramble,
So if you can notice one im sure it is reflected in the others...

Have i missed anything?
Back to top
Dazzy
Agent
Agent


Joined: 09 Jan 2004
Posts: 1731

Reputation: 72.3

PostPosted: Sun Jan 23, 2005 4:19 am    Post subject: Reply with quote

I figured it out!

I knew it had a link with the number or mirrors!!

Anyway,
i had the sub being called in sub connected, and i then relised this wasnt being called just the once! Therefore the timers were being added twice.....

Very Happy
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Review All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group