1#!/usr/bin/env perl
2# $Id: qq,v 1.1 2007/01/02 21:11:32 tans Exp $
3
4# Copyright (c) 2002 - 2006 Shufeng Tan.  All rights reserved.
5#
6# This program is free software and is provided "as is" without express
7# or implied warranty.  It may be used, redistributed and/or modified
8# under the terms of the Perl Artistic License (see
9# http://www.perl.com/perl/misc/Artistic.html)
10
11use strict;
12use Getopt::Long;
13use Net::OICQ::TextConsole;
14
15print "Crypt::OICQ version $Crypt::OICQ::VERSION, Net::OICQ version $Net::OICQ::VERSION\n";
16
17my $usage = <<EOF;
18Usage:
19If you use Borne shell, bash or ksh, type:
20OICQ_PW='xxxxxxx' $0 [-hiu] [-d#] [-p<plugin>] id
21
22If you use csh or tcsh, type:
23setenv OICQ_PW 'xxxxxxx'
24$0 [-hi] [-d#] [-p<plugin>] id
25
26Options:
27    -h  print this help message
28    -i  invisible mode
29    -u  UDP protocol (TCP is default)
30    -d  debug mode
31    -p<plugin>  specify plugin
32EOF
33
34my $invisible= 0;
35my $udp      = 0;
36my $debug    = 0;
37my $plugin   = "";
38my $help     = 0;
39
40GetOptions("debug=i"   => \$debug,
41	   "invisible" => \$invisible,
42	   "udp"       => \$udp,
43           "plugin=s"  => \$plugin,
44	   "help"      => \$help);
45
46die $usage if $help;
47
48my $mode   = $invisible ? 'Invisible' : 'Normal';
49
50my $proto  = $udp ? 'udp' : 'tcp';
51
52my $uid = shift;
53
54$| = 1;
55my $ui = new Net::OICQ::TextConsole;
56
57unless ($uid) {
58	$uid = $ENV{OICQ_ID};
59	die "Login Id not given\n" unless $uid;
60	$ui->info("QQ id: $uid\n");
61}
62
63my $pw  = $ENV{OICQ_PW};
64if ($pw) {
65	print "OICQ_PW found in env.\n";
66} else {
67	$pw = $ui->ask_passwd("Enter password for $uid: ");
68	$pw or die "Password not entered.\n";
69}
70
71our $oicq = $ui->{OICQ};
72$oicq->{EventQueueSize} = 100;
73$oicq->{FontSize}  = '10';  # This can be random
74$oicq->{FontColor} = 'random';
75$oicq->{Debug} = $debug;
76
77$oicq->login($uid, $pw, $mode, $proto) or die "Failed to login.\n";
78$ui->{LastKbInput} = time;
79$oicq->get_friends_list;
80$oicq->get_online_friends;
81$oicq->get_user_info($uid);
82if ($plugin) {
83    if (-f $plugin) {
84        $ui->load_plugin($plugin);
85    } else {
86        $ui->warn("Plugin $plugin does not exist.\n");
87    }
88}
89$ui->loop;
90
91END { defined $oicq && defined $oicq->{Socket} && $oicq->logout }
92