okay i must be retarded... i cant get the function to work... :-( any hints robin?? or anyone??? i hate not being able to figure this kind of stuff out..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#begin#
# Create an array %usersList, fill it on sub new_user_connected
sub new_user_connected() {
my($user) = @_;
$usersList{$user} = {$user};
}
# when typing in the chat : !getnick 'ip'
if($data =~ /!getnick/)
{
#extract the ip.
$poz1 = rindex($data, "!getnick")+9;
my($tmpdata) = substr($data, $poz1, -1);
#loop in the userList
my(@uservalues) = values %usersList;
while (@uservalues) {
my($userval) = pop(@uservalues);
my($userIp) = odch::get_ip($userval);
# then compare ip
if($tmpdata eq $userIp){
odch::data_to_user($user,"\$To: $nick From: $botname \$ $userIp belong to $userval.|");
}
}
}
#end#
There's one important difference with the good coding of rob1n. You have to restart the hub to log all users in the list, if you reload the script whitout restarting the hub, only new user after reload will be in the list.
Zo.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thx to the both of ya.. i got the script that zoto is runnig to work.. but have had little luck with rob1ns script... i will keep pluging away at it as i am still working on the bots
cheers
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#begin#
# Create an array %usersList, fill it on sub new_user_connected
sub new_user_connected() {
my($user) = @_;
$usersList{$user} = {$user};
}
# when typing in the chat : !getnick 'ip'
if($data =~ /!getnick/)
{
#extract the ip.
$poz1 = rindex($data, "!getnick")+9;
my($tmpdata) = substr($data, $poz1, -1);
#loop in the userList
my(@uservalues) = values %usersList;
while (@uservalues) {
my($userval) = pop(@uservalues);
my($userIp) = odch::get_ip($userval);
# then compare ip
if($tmpdata eq $userIp){
odch::data_to_user($user,"\$To: $nick From: $botname \$ $userIp belong to $userval.|");
}
}
}
#end#
There's one important difference with the good coding of rob1n. You have to restart the hub to log all users in the list, if you reload the script whitout restarting the hub, only new user after reload will be in the list.
Zo.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Re, i don't want to flood that thread, i hope jhoon won't kick me ;)
I've forgot the line sub data_arrival()in this sample script and removed the "!" before getnick 'ip', because it does'nt work on the main chat if using by admin.
#begin#
# Create an array %usersList, fill it on sub new_user_connected
sub new_user_connected() {
my($user) = @_;
$usersList{$user} = {$user};
}
sub data_arrival() {
# when typing in the chat : getnick 'ip'
if($data =~ /getnick/)
{
#extract the ip.
$poz1 = rindex($data, "getnick")+8;
my($tmpdata) = substr($data, $poz1, -1);
#loop in the userList
my(@uservalues) = values %usersList;
while (@uservalues) {
my($userval) = pop(@uservalues);
my($userIp) = odch::get_ip($userval);
# then compare ip
if($tmpdata eq $userIp){
odch::data_to_user($user,"\$To: $nick From: $botname \$userIp belong to $userval.|");
}
}
}
#and obviously removed the user from the list when he/she leave the hub.
sub user_disconnect(){
my($user) = @_;
if(exists $usersList{$user}) {
delete $usersList{$user};
}
}
#end#
You have to restart the hub to log all users in the list, if you reload the script whitout restarting the hub, only new user after reload will be in the list.
Zo.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
is there a way to get the username from the ip?
this is the last part of my script lol... and its totally messing my head up :-(
The way I've done this is:
- Get a list of all users in the hub (by reading in ~/tmp/odchlist)
- For each user, get the IP address and compare.
It would probably be faily simple to add a function to do this in the hub (it'd be using exactly the same process though).
okay i must be retarded... i cant get the function to work... :-( any hints robin?? or anyone??? i hate not being able to figure this kind of stuff out..
Here's the two functions I use (since the list of all users is useful elsewhere):
sub user_ListAll {
my @users = ();
my $users_file = ((getpwuid($<))[7]) . "/tmp/odchlist";
if (-e $users_file) {
open INFILE, "$users_file";
my $old_eol = $/;
undef $/;
my $users_list = <INFILE>;
close(INFILE);
$/ = $old_eol;
foreach (split(/\n/, $users_list)) {
push(@users, (split(/ /, $_))[0]);
}
}
return @users;
}
sub user_NameByIp {
my ($sIP) = @_;
foreach (user_ListAll()) {
if (odch::get_ip($_) eq $sIP) {
return $_;
}
}
return "";
}
Hi,
I use davidator script array to do that :
#begin#
# Create an array %usersList, fill it on sub new_user_connected
sub new_user_connected() {
my($user) = @_;
$usersList{$user} = {$user};
}
# when typing in the chat : !getnick 'ip'
if($data =~ /!getnick/)
{
#extract the ip.
$poz1 = rindex($data, "!getnick")+9;
my($tmpdata) = substr($data, $poz1, -1);
#loop in the userList
my(@uservalues) = values %usersList;
while (@uservalues) {
my($userval) = pop(@uservalues);
my($userIp) = odch::get_ip($userval);
# then compare ip
if($tmpdata eq $userIp){
odch::data_to_user($user,"\$To: $nick From: $botname \$ $userIp belong to $userval.|");
}
}
}
#end#
There's one important difference with the good coding of rob1n. You have to restart the hub to log all users in the list, if you reload the script whitout restarting the hub, only new user after reload will be in the list.
Zo.
I use in sub data_arrival:
if($data =~/\+getuser/) {
my $theuser = &quad2int((split(/\ /, $data))[2]);
my $sth = $dbh->prepare("SELECT * FROM users WHERE longip=$theuser");
$sth->execute();
while(my $ref = $sth->fetchrow_hashref()) {
odch::data_to_all("<$botname> \nName: $ref->{'user'}\nIP: $ref->{'ip'}\nLONGIP: $ref->{'longip'}\nOnline: $ref->{'online'}|");
}
}
thx to the both of ya.. i got the script that zoto is runnig to work.. but have had little luck with rob1ns script... i will keep pluging away at it as i am still working on the bots
cheers
Hi,
I use davidator script array to do that :
#begin#
# Create an array %usersList, fill it on sub new_user_connected
sub new_user_connected() {
my($user) = @_;
$usersList{$user} = {$user};
}
# when typing in the chat : !getnick 'ip'
if($data =~ /!getnick/)
{
#extract the ip.
$poz1 = rindex($data, "!getnick")+9;
my($tmpdata) = substr($data, $poz1, -1);
#loop in the userList
my(@uservalues) = values %usersList;
while (@uservalues) {
my($userval) = pop(@uservalues);
my($userIp) = odch::get_ip($userval);
# then compare ip
if($tmpdata eq $userIp){
odch::data_to_user($user,"\$To: $nick From: $botname \$ $userIp belong to $userval.|");
}
}
}
#end#
There's one important difference with the good coding of rob1n. You have to restart the hub to log all users in the list, if you reload the script whitout restarting the hub, only new user after reload will be in the list.
Zo.
Re, i don't want to flood that thread, i hope jhoon won't kick me ;)
I've forgot the line sub data_arrival()in this sample script and removed the "!" before getnick 'ip', because it does'nt work on the main chat if using by admin.
#begin#
# Create an array %usersList, fill it on sub new_user_connected
sub new_user_connected() {
my($user) = @_;
$usersList{$user} = {$user};
}
sub data_arrival() {
# when typing in the chat : getnick 'ip'
if($data =~ /getnick/)
{
#extract the ip.
$poz1 = rindex($data, "getnick")+8;
my($tmpdata) = substr($data, $poz1, -1);
#loop in the userList
my(@uservalues) = values %usersList;
while (@uservalues) {
my($userval) = pop(@uservalues);
my($userIp) = odch::get_ip($userval);
# then compare ip
if($tmpdata eq $userIp){
odch::data_to_user($user,"\$To: $nick From: $botname \$userIp belong to $userval.|");
}
}
}
#and obviously removed the user from the list when he/she leave the hub.
sub user_disconnect(){
my($user) = @_;
if(exists $usersList{$user}) {
delete $usersList{$user};
}
}
#end#
You have to restart the hub to log all users in the list, if you reload the script whitout restarting the hub, only new user after reload will be in the list.
Zo.