User Control Panel
Advertisements

HELP US, HELP YOU!

Status Check
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Bot Depot Forum Index -> AIM Protocol & questions
View unanswered posts
Author Message
Tony_shu
God Like
God Like


Joined: 12 Nov 2003
Posts: 624

Reputation: 42.9Reputation: 42.9Reputation: 42.9Reputation: 42.9

PostPosted: Mon Jan 26, 2004 7:40 pm    Post subject: Reply with quote

I think I understood what you were suggesting Keenie. in any case, I went ahead and altered the code some more...and now it works.

Code:
<br />sub status {<br /><br /> my $who = shift;<br /> my ($toprint,$status);<br /><br /> #Buddy has signed on<br /> if (exists $users_online{$who}) {<br />  $status = "on";<br />  $toprint .= "User $who is online.\n\n";<br /> }<br /> #Buddy has signed offline<br /> if (!exists $users_online{$who}) {<br />  $status = "off";<br />  $toprint .= "User $who is offline.\n\n";<br /> }<br /> #Buddy is away<br /> if (exists $buddies_away{$who}) {<br />  $status = "away";<br />  $toprint .= "User $who is away.\n\n";<br /> }<br /> #Buddy is idle<br /> if (exists $buddies_idle{$who}) {<br />  $status = "idle";<br />  $toprint .= "User $who is idle.\n\n";<br /> }<br /><br /> &print($toprint);<br /> return $status;<br /><br />}<br />1;
..just ignore all the $toprint stuff....that's another function I have

Just change
Code:
$toprint .=
to
Code:
print

_________________
Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
Back to top
Keenie
Almost An Agent
Almost An Agent


Joined: 31 Oct 2003
Posts: 1071

Reputation: 52.4

PostPosted: Mon Jan 26, 2004 8:11 pm    Post subject: Reply with quote

yeah thats what I ment, checking the user against the hash before you sent it, instead of trying to use the $evt args

I don't think I worded my post right, but at least you knew what I ment
Back to top
Tony_shu
God Like
God Like


Joined: 12 Nov 2003
Posts: 624

Reputation: 42.9Reputation: 42.9Reputation: 42.9Reputation: 42.9

PostPosted: Mon Jan 26, 2004 9:34 pm    Post subject: Reply with quote

It worked for like 10 minutes...and now it doesn't work anymore...lol oye
_________________
Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
Back to top
Tony_shu
God Like
God Like


Joined: 12 Nov 2003
Posts: 624

Reputation: 42.9Reputation: 42.9Reputation: 42.9Reputation: 42.9

PostPosted: Tue Jan 27, 2004 12:58 am    Post subject: Reply with quote

This darn thing keeps giving me issues...it was working and now nothing works :wacko:

This is the on_update_buddy()
Code:
#Variables for holding online, away, and idle users<br />my %users_online;<br />my %buddies_away;<br />my %buddies_idle;<br /><br />sub on_update_buddy {<br /><br />my ($self,$evt,$from,$to) = @_;<br />my ($bud,$online,$evil,$signon_time,$idle_amount,$user_class) = @{$evt->args()};<br />my $toprint;<br /><br />$scn = lc($bud);<br />$scn =~ s/ //g;<br /><br />#Buddy has signed on<br />if ($online eq "T" && !exists $users_online{$scn}) {<br /> $user_online{$scn} = time;<br /> $time = localtime();<br /> $toprint .= "<$time> User $bud has just signed on.\n\n";<br />}<br />#Buddy has signed offline<br />if ($online eq "F") {<br /> if (exists $buddies_away{$scn}) {<br />  delete $buddies_away{$scn};<br /> }<br /> if (exists $buddies_idle{$scn}) {<br />  delete $buddies_idle{$scn};<br /> }<br /> delete $users_online{$scn};<br /> $time = localtime();<br /> $toprint .= "<$time> User $bud has signed off.\n\n";<br />}<br />#Buddy is away<br />if ($online eq "T" && !exists $buddies_away{$scn} && length $user_class==3) {<br /> $buddies_away{$scn} = time;<br /> $time = localtime();<br /> $toprint .= "<$time> User $bud is away.\n\n";<br />}<br />#Buddy is idle<br />if ($online eq "T" && !exists $buddies_idle{$scn} && $idle_amount>0) {<br /> $buddies_idle{$scn} = time;<br /> $time = localtime();<br /> $toprint .= "<$time> User $bud is idle.\n\n";<br />}<br />#Buddy returns from away status<br />if ($online eq "T" && exists $buddies_away{SN} && length $user_class != 3) {<br /> delete $buddies_away{$scn};<br /> $time = localtime();<br /> $toprint .= "<$time> User $bud has returned from away status.\n\n";<br />}<br />#Buddy is no longer idle<br />if ($online eq "T" && exists $buddies_idle{$scn} && $idle_amount == 0) {<br /> delete $buddies_idle{$scn};<br /> $time = localtime();<br /> $toprint .= "<$time> User $bud is no longer idle.\n\n"<br />}<br />#Buddy is not away OR idle<br />if ($online eq "T" && (exists $buddies_away{$scn} || exists $buddies_idle{$scn}) && $idle_amount == 0 && length $user_class != 3) {<br /> if (exists $buddies_away{$scn}) {<br />  delete $buddies_away{$scn};<br /> }<br /> if (exists $buddies_idle{$scn}) {<br />  delete $buddies_idle{$scn};<br /> }<br /> $time = localtime();<br /> $toprint .= "<$time> $bud is not away or idle.\n\n";<br />}<br /><br /> &print($toprint);<br /><br />}<br />1;
This used to print every few seconds someone signing on & off...now it doesn't print anything.

I edited the above code, and created another function, which it also no longer works...this is called status()
Code:
sub status {<br /><br /> my $who = shift;<br />print "Who: $who\n";<br /> my $toprint;<br /> my $status;<br /><br /> #Buddy has signed on<br /> if (exists $users_online{$who}) {<br />  $status = "on";<br />  $toprint .= "User $who is online.\n\n";<br /> }<br /> #Buddy has signed offline<br /> if (!exists $users_online{$who}) {<br />  $status = "off";<br />  $toprint .= "User $who is offline.\n\n";<br /> }<br /> #Buddy is away<br /> if (exists $buddies_away{$who}) {<br />  $status = "away";<br />  $toprint .= "User $who is away.\n\n";<br /> }<br /> #Buddy is idle<br /> if (exists $buddies_idle{$who}) {<br />  $status = "idle";<br />  $toprint .= "User $who is idle.\n\n";<br /> }<br /><br /> &print($toprint);<br /> return $status;<br /><br />}<br />1;
...This works by getting called from a command, such as !sendim. The related portion of sendim() is posted here:
Code:
  $status = &status($scrn);<br />  if ($status eq "on") {<br />   $aim->send_im($scrn, "$what");<br />   $toprint .= "$sn: (to $scrn) $what\n\n";<br />   sleep(2);<br />   $reply = "Message sent!";<br />  } elsif ($status eq "off") {<br />   $reply = "Sorry, but $scrn is not online to receive your message";<br />  } elsif ($status = "away") {<br />   $reply = "Sorry, but $scrn is not available for messaging";<br />  } elsif ($status = "idle") {<br />   $aim->send_im($scrn, "$what");<br />   $toprint .= "$sn: (to $scrn) $what\n\n";<br />   sleep(2);<br />   $reply = "Individual was idle, however message was sent.";<br />  }<br />
...I know that status() function is being called, and that the $who is being defined, because I have it print what $who is, after it is defined. However, it always returns that the individual is not online. This is rather not surprising, since the on_update_buddy() is not functioning.

Also, when I sign on to the bot's screenname through AIM (not perl), the buddy list has a group named Buddies, which lists all the buddies. However, there is also a new group called "unkown" that continually adds itself.

_________________
Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
Back to top
Tony_shu
God Like
God Like


Joined: 12 Nov 2003
Posts: 624

Reputation: 42.9Reputation: 42.9Reputation: 42.9Reputation: 42.9

PostPosted: Tue Jan 27, 2004 5:15 pm    Post subject: Reply with quote

I tried to play around with the code, and it started to "work" a little.

When I placed this...
Code:
#Variables for holding online, away, and idle users<br />my %users_online;<br />my %buddies_away;<br />my %buddies_idle;
...within the sub on_update_buddy(), it started to work, and actually started to print in my command prompt all the sign on/off/idle/away/etc.

However, by looking at the code, the hashes end up being for only the on_update_buddy() sub. The code does seem to work if I take off all the "my" codes in the above section.

As for the status() sub, it doesn't seem to work right. It doesn't seem to be able to find the hashes.

_________________
Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
Back to top
Nate
God Like
God Like


Joined: 12 Nov 2003
Posts: 553

Reputation: 41.3Reputation: 41.3Reputation: 41.3Reputation: 41.3

PostPosted: Tue Jan 27, 2004 7:52 pm    Post subject: Reply with quote

When you declare the hashes for the first time, DO NOT use the word "my"

And it's better to declare them outside of the sub...

Code:
%users_online;<br />%buddies_away;<br />%buddies_idle;<br /><br />sub on_update_buddy {
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Tue Jan 27, 2004 7:54 pm    Post subject: Reply with quote

Better would be a relative term. To make global hashes thats how you do it. Just remember they will only be global to their file so if you do that in a different file than bot.pl (the main .pl) then only that file will see it.
_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Nate
God Like
God Like


Joined: 12 Nov 2003
Posts: 553

Reputation: 41.3Reputation: 41.3Reputation: 41.3Reputation: 41.3

PostPosted: Tue Jan 27, 2004 7:55 pm    Post subject: Reply with quote

Oh...

I thought that the Perl like loads the sources of all the files and then like compiles it as if it was one file.
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Tue Jan 27, 2004 8:21 pm    Post subject: Reply with quote

Actually, my makes a variable local to the currrent scope. Scope is generally anything inside a pair of functional braces {} or a package. This is how you can have variables of the same name inside different scopes. When a variable goes out of scope, it is deleted. Using my promotes cleaner, more readable and less buggy code.

Since this was a command that Tony made, it will be loaded into the scope of the bot, making it pretty much global to the bot. So he SHOULD use my and the variables will be availabe to his command.

Nate, you shouldn't tell people not to do something just because you think it's better. This is how people get into poor programming habits and it results in badly written code and unseen bugs.

Perl is a language for the lazy, I admit, and sometimes shortcuts are fine, but from a general programming standpoint, it's important to understand and use good syntax and use of my everywhere you can is a good idea. Of course, I come from a C++ background where you don't have a choice. Using scoped variables is always a good habit to have. Very Happy
Back to top
Nate
God Like
God Like


Joined: 12 Nov 2003
Posts: 553

Reputation: 41.3Reputation: 41.3Reputation: 41.3Reputation: 41.3

PostPosted: Tue Jan 27, 2004 8:35 pm    Post subject: Reply with quote

Okay, 1. I think you're just out to get me, you lower my rep for every little thing. <_<

And 2. This is what I discovered...

Inside bot.pl
Code:
my %bot;<br /><br />$bot{azulianbot}->{password} = "xxx";<br />$bot{azulianbot}->{profile} = "./profile.htm";<br />$bot{azulianbot}->{client} = "AIM";<br /><br /># And so-on, this %bot variable was declared<br /># in the main bot.pl outside of any subs. It<br /># "should" be global.


Inside aim_signon_done.pl
Code:
open (INFO, $bot{$screenname}->{profile}) or die;


The $bot would & should still be global but it's not.

You remove the "MY" from it and it works.

Inside config.pl
Code:
%config;<br /><br />sub get_config {<br />  open (CONFIG, "./config.cfg");<br />  my @config = <CONFIG>;<br />  close (CONFIG);<br /><br />  chomp @config;<br /><br />  foreach $line (@config) {<br />    ($what,$is) = split(/=/, $line, 2);<br />    $config{$what} = $is;<br />  }<br />}


I declared %config inside a subfile, outside of a sub. And what do you know... IT WORKS in other subs as a global variable.

Isn't that odd? My way works just fine.

So anyway, stop with the negative rep points, what did I ever do to you?
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Tue Jan 27, 2004 9:42 pm    Post subject: Reply with quote

OK, apparently requireing files changes the scope, something I was unaware of - I don't use require. I think we're all learning something here.

The point I was trying to make is that using variables without my is a bad programming habit and will only lead to trouble. Declaring global variables inside a sub is a particularly bad thing to do.

By not using my when declaring a variable, you are only inviting bugs that result from overwriting an existing variable with that same name.

Tony, it is ALWAYS a good idea to scope your variables with my and use strict; while you're at it to catch places you didn't.

Nate, I'm not out to get you, but ever since you posted backdoor-enabled bots and posted a dangerous use of the eval function, I've been very suspect of your code and suggestions to other posters. That said, I'll back off on the whole lowering rep thing.
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Tue Jan 27, 2004 10:42 pm    Post subject: Reply with quote

To be very clear I think that globals are evil. Thats not based on reading anything, or being told by anyone, thats just based on experience. If you want to have something available then it should be passed around in a friendly manner that makes it obvious where it comes from. This also allows for object oriented projects where you might want more than one version of a global floating around.

That said here is a little research project.

main.pl
Code:
<br />my $mainMy = "My Works";<br />my $dang = "test";<br />$mainNoMy = "No My Works";<br /><br />require "subpart.pl";<br /><br /><br />print "In main.pl\n";<br />print "Main: $mainMy, $mainNoMy\n";<br />print "Required: $subMy, $subNoMy\n";<br />print "\n";<br /><br /><br />test();<br />


subpart.pl
Code:
<br />my $subMy = "My Works";<br />$subNoMy = "No My Works";<br /><br />sub test {<br />    print "In required file:\n";<br />    print "Main: $mainMy, $mainNoMy\n";<br />    print "Required: $subMy, $subNoMy\n";<br />    print "\n";<br />}<br />


and the output when main.pl is run
Code:
<br />C:\test>perl main.pl<br />In main.pl<br />Main: My Works, No My Works<br />Required: , No My Works<br /><br />In required file:<br />Main: , No My Works<br />Required: My Works, No My Works<br />



You can see from that, anything with my in front of it is available only in its own file. Now you might think, so the only way to do this is to make it global! Well if that is the case then I recommend putting them all in the main.pl file so you know what you expect your global variables names to be. Of course once you have them all in main.pl it is then also easier to put my in front of all of them and then pass them to the subs that need them.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Tony_shu
God Like
God Like


Joined: 12 Nov 2003
Posts: 624

Reputation: 42.9Reputation: 42.9Reputation: 42.9Reputation: 42.9

PostPosted: Wed Jan 28, 2004 7:17 am    Post subject: Reply with quote

Thanks guys (sorry you had to argue over it) I couldn't get the bot to even "think" of working any other way...but this is how I will leave the code to work Very Happy...

1. I placed both subs: on_update_buddy() and status() in the same file (on_update_buddy.pl).

2. I tried to use the hashes (with my)...and it didn't work outside of sub on_update_buddy()

3. When I place the hashes within the sub on_update_buddy()...with or without the "my", no other subs could use the hashes, unless I forwarded the hashes to that specific sub.
For example, at the bottom of on_update_buddy() I placed this:
Code:
&status(%users_online,%buddies_away,%buddies_idle);
...Which my status() sub has to call on them:
Code:
(%users_online,%buddies_away,%buddies_idle) = (shift,shift,shift);

But if I do it that way, when I call on the status() sub through my !sendim command, the screenname I send is "shift"-ed into the hash.

...However, the status() sub works...and thats what's important...more so than having on_update_buddy() printing everytime someone's status changes (it doesn't print it...nor does it change it <_< ).

EDITED: on_update_buddy() doesn't seem to be updating its hashes

_________________
Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Wed Jan 28, 2004 4:20 pm    Post subject: Reply with quote

If you are passing $self to your commands then you could store stuff in $self like its a hash. Its kinda bastardized way of doing it, but it might be a good solution for you. Just use $self->{users_online} as the hash. then anywhere you have $self you have your online hash. Be very carefull though because the $self hash is acutaly the aim object, so don't use any names it might already use as keys to the hash.
_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Tony_shu
God Like
God Like


Joined: 12 Nov 2003
Posts: 624

Reputation: 42.9Reputation: 42.9Reputation: 42.9Reputation: 42.9

PostPosted: Thu Jan 29, 2004 2:39 am    Post subject: Reply with quote

My OCD won't let me quit...so I'm reposting my issues.

EDITED:No matter what I do...most of the functions will not work. So for now I'm giving up on the project. I've reverted my bot to the original form, and just have it send the message, and if the user is not online, they just won't get it.

Sorry you guys had to argue over it...lol (felt like home Very Happy)

I'll try to play around with the functions when I have more time.

Thanks again.

_________________
Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> AIM Protocol & questions All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 



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