summaryrefslogtreecommitdiffstats
path: root/ksirc/test/tester.pl
blob: 2815a3a13cfa7cc42ec4de615847896ab51c6030 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
sub rndchr {
  my $string = "";
  for(my $i = 0; $i < 8; $i++){
    $string .= chr(int(rand(26)) + 97); # More or less the alpahbet
  }
  return $string;
}

srand(time());

&timer(1, "&next_one", 1);

$state = 0;
$max_win = 5;
$win_open = 0;
%wins = {};
$repeat = 1000;
$count = 0;


sub next_one {
  #
  # State 0 is open window
  #
  if($state == 0){
    $winnum = int(rand($max_win));
    $winname = "#" . rndchr();
    $wins{$winname} = 1;
    print("~$winname~*>* You have joined channel $winname\n");
    &docommand("/join $winname");
    $state = 1;
    $win_open ++;
  }
  #
  # State 1 is print stuff to channel
  #
  elsif($state == 1){
    while(($winname, $value) = each(%wins)){
      &msg("$winname", rndchr());
      &notice("$winname", rndchr());
    }
    $state = 2;
  }
  #
  # State 2 is close window
  #
  elsif($state == 2){
    if($win_open > $max_win){
      $times = int(rand($win_open-1));
      for($i = 0; $i<= $times; $i++){
	($winname, $value) = each(%wins);
      }
      print("~#test~ <boren> leaving $winname\n");
      delete($wins{$winname});
      print("~!all~*<* You have left channel $winname\n");
      &docommand("/part $winname");
      $win_open --;
    }
    $state = 0;
  }

  if($count++ < $repeat){
    &timer(5, "&next_one", 1);
  }
}