vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 2.x Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=4)
-   -   Users in IRC Channel(s) (https://vborg.vbsupport.ru/showthread.php?t=46173)

FASherman 11-27-2002 10:00 PM

Users in IRC Channel(s)
 
Okay, I'm not sure if this qualifies as a "true" hack or not. Feel free to move this to an appropriate area, if not.

At any rate, I have 18 IRC channels supporting a range of topics. What I needed was something to keep track of how many users where in each channel.

1. Create a tables named ircstat in your vbulletin database. The table consists of two fields, channelname (type = text) and channelusers (type = int, length = 3, Not Null, Default = 0).

2. Insert a row for each IRC channel you want to monitor:
INSERT INTO ircstat(channelname,channelusers) VALUES ('#channel','0')

Case IS important. It must match your IRC channel name EXACTLY.

3. Create a perl script called ircstat.pl. Cut and paste below into it and change the values that need changing:

---START CUT&PASTE NEXT LINE
#!/usr/bin/perl
$server = "change.irc.server";
$port = 6667;
$nick = "PickANick";
$realname = "Just passing through...";
use IO::Socket;
use DBI;
$dbname = "yourdbname";
$dbhost = "yourhost";
$dbuser = "yourdbuser";
$dbpasswd = "yourdbpassword";
$vbdb=DBI->connect("dbi:mysql:".$dbname.":".$dbhost,$dbuser, $dbpasswd);
@channels = ('#channel1','#channel2','#channel3');
$irc=IO::Socket::INET->new( PeerAddr=>$server, PeerPort=>$port, Proto=>'tcp')or die "$server: $@\n";
print $irc "USER $nick $nick $nick :$realname\n";
print $irc "NICK $nick\n";
while(@channels) {
$channel = shift @channels;
print $irc "LIST $channel\n";
while(defined($in=<$irc>)){
chop($in);
if($in=~/PING :(.*)/){
print $irc "PONG $1\n";
}
@field = split(/ /,$in);
if ($channel eq $field[3]) {
$sql = $vbdb->prepare("UPDATE ircstat SET channelusers=$field[4] WHERE channelname=\"$field[3]\"");
$sql->execute;
last;
}
if ($field[1] eq "263") {
print $irc "LIST $channel\n";
}
}
}
close($irc);
-----END CUT&PASTE PREVIOUS LINE----

4. Run this script out of cron. Every 5 minutes if you have 1 or 2 channels, every 10 minutes if you have more than 2 channels.

Remember, all this does is keeps the database updated. with the number of users in your channels. You'll have to decide where you want to display this information and make the appropriate php/template hacks.

KelteN 11-28-2002 04:31 AM

Cool, if I ever setup a IRC channel for my forum. Ill be sure to use this hack/mod ;)

Thx :D

JulianD 11-28-2002 05:46 AM

OK thanks for the script :) All the script to get users in IRC made with PHP doesn't work on my host... I hope this one works :)

futureal 11-28-2002 07:50 AM

Wow, this is something I have been looking for, for a long time. Thanks!

Any idea what the server load might be like? It seems negligible, which is great. Hopefully the IRC servers my forums use will allow it to connect. :)

FASherman 11-28-2002 12:28 PM

Quote:

Originally posted by futureal
Wow, this is something I have been looking for, for a long time. Thanks!

Any idea what the server load might be like? It seems negligible, which is great. Hopefully the IRC servers my forums use will allow it to connect. :)

They will. They see it as just another client. Server load is practically nothing. Most of the load is on the IRC server, hence the check for "263" messages, which means the server responded that load is too high, please try again.

With 18 channels on a heavily used IRC server, it still completes in just under 3 minutes.

Velocd 11-28-2002 02:42 PM

Some questions:

#1. Does this bog down the server if you are NOT using a dedicated server? This was an issue with the egg-drop method.

#2. How might you store the nick as well for each person in the database? You could probably modify the table to be:
Code:

create table ircstat
(  channelname text not null primary key,
  channelusers smallint(5) not null default'0',
  usernicks text not null
);

But within your perl script, how might with the following query:
Code:

$sql = $vbdb->prepare("UPDATE ircstat SET channelusers=$field[4] WHERE channelname=\"$field[3]\"");
I could insert as well the nick each person (seperated by commas, maybe using variable $nick or $username?) It would be great if the nick corresponded with the persons actual username on the forum, but that would be much more difficult to achieve.

Anyway, if this is possible I'll defiantly consider installing the hack. ;)

FASherman 11-28-2002 05:00 PM

You do NOT want to gather the nicks of everyone in a channel. Trust me. To do that, you would have to have the script (really a lightweight bot) JOIN each channel, run NAMES in each channel, parse the results, update the database and exit.

Imagine how disruptive it would be for this bot to bounce in and out every 5 minutes or so...

As for the server load, its minimal. The real load is on the IRC server.

FASherman 11-29-2002 04:10 PM

To get it to do what you request, change the script to this:

---START CUT&PASTE NEXT LINE
#!/usr/bin/perl
$server = "change.irc.server";
$port = 6667;
$nick = "PickANick";
$realname = "Just passing through...";
use IO::Socket;
use DBI;
$dbname = "yourdbname";
$dbhost = "yourhost";
$dbuser = "yourdbuser";
$dbpasswd = "yourdbpassword";
$vbdb=DBI->connect("dbi:mysql:".$dbname.":".$dbhost,$dbuser, $dbpasswd);
@channels = ('#Newsdesk','#Education','#Politics-&-Govt','#Military-&-Vets','#DallasMavericks','#TexasRangers','#Houston Texans','#YouthSports','#bits-&-bytes','#Daily-Web.Info','#technology','#religion-&-faith','#business-&-finance','#health','#SportsPage','#DallasStars','# DallasCowboys','#entertainment');
$irc=IO::Socket::INET->new( PeerAddr=>$server, PeerPort=>$port, Proto=>'tcp')or die "$server: $@\n";
print $irc "USER $nick $nick $nick :$realname\n";
print $irc "NICK $nick\n";
while(@channels) {
$channel = shift @channels;
print $irc "JOIN $channel\n";
while(defined($in=<$irc>)){
chop($in);
if($in=~/PING :(.*)/){
print $irc "PONG $1\n";
}
@field = split(/ /,$in);
if ($field[1] eq "353") {
@users = split(/:/,$in);
$users[2] =~ s/@//g;
$users[2] =~ s/\+//g;
$users[2] =~ s/ PutNickHere//; # <----Don't forget!
@nicks = split(/ +/,$users[2]);
$sql = $vbdb->prepare("UPDATE ircstat SET channelusers=$#nicks, channelnicks=\"$users[2]\" WHERE channelname=\"$field[4]\"");

$sql->execute;
print $irc "PART $channel\n";
last;
}
}
}
close($irc);
-----END CUT&PASTE PREVIOUS LINE----

This runs considerably faster, 20 seconds for 18 channels instead of 3 minutes, but it does have drawbacks.

First, is whatever time interval you set the script to run via cron, thats how often this user is going to join/leave the channel. The more often you do it, the more annoying it is. The less often you do it, the more stale your data becomes.

If you have channel bots, make sure they do not do an on_join greet to this nick. It just increases the annoyance factor. Also make sure this nick is exempy from excessive join/part bans.

This script is an example of the axiom, "Be careful what you wish for, you may get it".

GoTTi 11-29-2002 06:08 PM

im confused as hell...ive never used cron jobs, but this would be of some good for me...

can you put the instructions in simpl form with more detailed instructions...it is kinda throwing me off...

example:
4. Run this script out of cron. Every 5 minutes if you have 1 or 2 channels, every 10 minutes if you have more than 2 channels.

I dont know how to use cron, so what would be the commands that I would use?

Velocd 11-29-2002 06:55 PM

@da_gotti: http://www.aota.net/Script_Installat.../cronhelp.php4

@FASherman: thanks for the script, I'll try it out and see how much of an annoyance it might be ;)


All times are GMT. The time now is 12:35 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01086 seconds
  • Memory Usage 1,750KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete