diff --git a/Irpg/Event.pm b/Irpg/Event.pm index d57821c3da00afd1a326e7225fdc1bc1612a9782..e1e40f354b47d6461f003de4ceda10ff0cede5ba 100644 --- a/Irpg/Event.pm +++ b/Irpg/Event.pm @@ -36,7 +36,7 @@ sub find_item { # find item for argument player if ($rps->{$u}{level} >= 25 && rand(40) < 1) { $ulevel = 50+int(rand(25)); if ($ulevel >= $level && $ulevel > int($rps->{$u}{item}{helm})) { - notice("The light of the gods shines down upon you! You have ". + Irpg::Irc::notice("The light of the gods shines down upon you! You have ". "found the level $ulevel Mattt's Omniscience Grand Crown! ". "Your enemies fall before you as you anticipate their ". "every move.",$rps->{$u}{nick}); @@ -47,7 +47,7 @@ sub find_item { # find item for argument player elsif ($rps->{$u}{level} >= 25 && rand(40) < 1) { $ulevel = 50+int(rand(25)); if ($ulevel >= $level && $ulevel > int($rps->{$u}{item}{ring})) { - notice("The light of the gods shines down upon you! You have ". + Irpg::Irc::notice("The light of the gods shines down upon you! You have ". "found the level $ulevel Juliet's Glorious Ring of ". "Sparkliness! You enemies are blinded by both its glory ". "and their greed as you bring desolation upon them.", @@ -59,7 +59,7 @@ sub find_item { # find item for argument player elsif ($rps->{$u}{level} >= 30 && rand(40) < 1) { $ulevel = 75+int(rand(25)); if ($ulevel >= $level && $ulevel > int($rps->{$u}{item}{tunic})) { - notice("The light of the gods shines down upon you! You have ". + Irpg::Irc::notice("The light of the gods shines down upon you! You have ". "found the level $ulevel Res0's Protectorate Plate Mail! ". "Your enemies cower in fear as their attacks have no ". "effect on you.",$rps->{$u}{nick}); @@ -70,7 +70,7 @@ sub find_item { # find item for argument player elsif ($rps->{$u}{level} >= 35 && rand(40) < 1) { $ulevel = 100+int(rand(25)); if ($ulevel >= $level && $ulevel > int($rps->{$u}{item}{amulet})) { - notice("The light of the gods shines down upon you! You have ". + Irpg::Irc::notice("The light of the gods shines down upon you! You have ". "found the level $ulevel Dwyn's Storm Magic Amulet! Your ". "enemies are swept away by an elemental fury before the ". "war has even begun",$rps->{$u}{nick}); @@ -81,7 +81,7 @@ sub find_item { # find item for argument player elsif ($rps->{$u}{level} >= 40 && rand(40) < 1) { $ulevel = 150+int(rand(25)); if ($ulevel >= $level && $ulevel > int($rps->{$u}{item}{weapon})) { - notice("The light of the gods shines down upon you! You have ". + Irpg::Irc::notice("The light of the gods shines down upon you! You have ". "found the level $ulevel Jotun's Fury Colossal Sword! Your ". "enemies' hatred is brought to a quick end as you arc your ". "wrist, dealing the crushing blow.",$rps->{$u}{nick}); @@ -92,7 +92,7 @@ sub find_item { # find item for argument player elsif ($rps->{$u}{level} >= 45 && rand(40) < 1) { $ulevel = 175+int(rand(26)); if ($ulevel >= $level && $ulevel > int($rps->{$u}{item}{weapon})) { - notice("The light of the gods shines down upon you! You have ". + Irpg::Irc::notice("The light of the gods shines down upon you! You have ". "found the level $ulevel Drdink's Cane of Blind Rage! Your ". "enemies are tossed aside as you blindly swing your arm ". "around hitting stuff.",$rps->{$u}{nick}); @@ -104,7 +104,7 @@ sub find_item { # find item for argument player $ulevel = 250+int(rand(51)); if ($ulevel >= $level && $ulevel > int($rps->{$u}{item}{"pair of boots"})) { - notice("The light of the gods shines down upon you! You have ". + Irpg::Irc::notice("The light of the gods shines down upon you! You have ". "found the level $ulevel Mrquick's Magical Boots of ". "Swiftness! Your enemies are left choking on your dust as ". "you run from them very, very quickly.",$rps->{$u}{nick}); @@ -115,7 +115,7 @@ sub find_item { # find item for argument player elsif ($rps->{$u}{level} >= 52 && rand(40) < 1) { $ulevel = 300+int(rand(51)); if ($ulevel >= $level && $ulevel > int($rps->{$u}{item}{weapon})) { - notice("The light of the gods shines down upon you! You have ". + Irpg::Irc::notice("The light of the gods shines down upon you! You have ". "found the level $ulevel Jeff's Cluehammer of Doom! Your ". "enemies are left with a sudden and intense clarity of ". "mind... even as you relieve them of it.",$rps->{$u}{nick}); @@ -124,13 +124,13 @@ sub find_item { # find item for argument player } } if ($level > int($rps->{$u}{item}{$type})) { - notice("You found a level $level $type! Your current $type is only ". + Irpg::Irc::notice("You found a level $level $type! Your current $type is only ". "level ".int($rps->{$u}{item}{$type}).", so it seems Luck is ". "with you!",$rps->{$u}{nick}); $rps->{$u}{item}{$type} = $level; } else { - notice("You found a level $level $type. Your current $type is level ". + Irpg::Irc::notice("You found a level $level $type. Your current $type is level ". int($rps->{$u}{item}{$type}).", so it seems Luck is against you. ". "You toss the $type.",$rps->{$u}{nick}); } @@ -143,20 +143,22 @@ sub hog { # summon the hand of god my $win = int(rand(5)); my $time = int(((5 + int(rand(71)))/100) * $rps->{$player}{next}); if ($win) { - chanmsg(clog("Verily I say unto thee, the Heavens have burst forth, ". - "and the blessed hand of God carried $player ". - duration($time)." toward level ".($rps->{$player}{level}+1). - ".")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "Verily I say unto thee, the Heavens have burst forth, ". + "and the blessed hand of God carried $player ". + duration($time)." toward level ".($rps->{$player}{level}+1). + ".")); $rps->{$player}{next} -= $time; } else { - chanmsg(clog("Thereupon He stretched out His little finger among them ". - "and consumed $player with fire, slowing the heathen ". - duration($time)." from level ".($rps->{$player}{level}+1). - ".")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "Thereupon He stretched out His little finger among them ". + "and consumed $player with fire, slowing the heathen ". + duration($time)." from level ".($rps->{$player}{level}+1). + ".")); $rps->{$player}{next} += $time; } - chanmsg("$player reaches next level in ".duration($rps->{$player}{next})."."); + Irpg::Irc::chanmsg("$player reaches next level in ".duration($rps->{$player}{next})."."); } sub calamity { # suffer a little one @@ -168,32 +170,38 @@ sub calamity { # suffer a little one "shield"); my $type = $items[rand(@items)]; if ($type eq "amulet") { - chanmsg(clog("$player fell, chipping the stone in his amulet! ". - "$player\'s $type loses 10% of its effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player fell, chipping the stone in his amulet! ". + "$player\'s $type loses 10% of its effectiveness.")); } elsif ($type eq "charm") { - chanmsg(clog("$player slipped and dropped his charm in a dirty ". - "bog! $player\'s $type loses 10% of its ". - "effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player slipped and dropped his charm in a dirty ". + "bog! $player\'s $type loses 10% of its ". + "effectiveness.")); } elsif ($type eq "weapon") { - chanmsg(clog("$player left his weapon out in the rain to rust! ". - "$player\'s $type loses 10% of its effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player left his weapon out in the rain to rust! ". + "$player\'s $type loses 10% of its effectiveness.")); } elsif ($type eq "tunic") { - chanmsg(clog("$player spilled a level 7 shrinking potion on his ". - "tunic! $player\'s $type loses 10% of its ". - "effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player spilled a level 7 shrinking potion on his ". + "tunic! $player\'s $type loses 10% of its ". + "effectiveness.")); } elsif ($type eq "shield") { - chanmsg(clog("$player\'s shield was damaged by a dragon's fiery ". - "breath! $player\'s $type loses 10% of its ". - "effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player\'s shield was damaged by a dragon's fiery ". + "breath! $player\'s $type loses 10% of its ". + "effectiveness.")); } else { - chanmsg(clog("$player burned a hole through his leggings while ". - "ironing them! $player\'s $type loses 10% of its ". - "effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player burned a hole through his leggings while ". + "ironing them! $player\'s $type loses 10% of its ". + "effectiveness.")); } my $suffix=""; if ($rps->{$player}{item}{$type} =~ /(\D)$/) { $suffix=$1; } @@ -203,7 +211,7 @@ sub calamity { # suffer a little one else { my $time = int(int(5 + rand(8)) / 100 * $rps->{$player}{next}); if (!open(Q,$opts->{eventsfile})) { - return chanmsg("ERROR: Failed to open $opts->{eventsfile}: $!"); + return Irpg::Irc::chanmsg("ERROR: Failed to open $opts->{eventsfile}: $!"); } my($i,$actioned); while (my $line = <Q>) { @@ -214,11 +222,12 @@ sub calamity { # suffer a little one my $pron_poss = pronoun(2, $rps->{$player}{gender}); $actioned =~ s/<p_obj>/$pron_obj/g; $actioned =~ s/<p_poss>/$pron_poss/g; - chanmsg(clog("$player $actioned. This terrible calamity has slowed ". - $pron_obj." ".duration($time)." from level ". - ($rps->{$player}{level}+1).".")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player $actioned. This terrible calamity has slowed ". + $pron_obj." ".duration($time)." from level ". + ($rps->{$player}{level}+1).".")); $rps->{$player}{next} += $time; - chanmsg("$player reaches next level in ".duration($rps->{$player}{next}). + Irpg::Irc::chanmsg("$player reaches next level in ".duration($rps->{$player}{next}). "."); } } @@ -232,29 +241,35 @@ sub godsend { # bless the unworthy "shield"); my $type = $items[rand(@items)]; if ($type eq "amulet") { - chanmsg(clog("$player\'s amulet was blessed by a passing cleric! ". - "$player\'s $type gains 10% effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player\'s amulet was blessed by a passing cleric! ". + "$player\'s $type gains 10% effectiveness.")); } elsif ($type eq "charm") { - chanmsg(clog("$player\'s charm ate a bolt of lightning! ". - "$player\'s $type gains 10% effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player\'s charm ate a bolt of lightning! ". + "$player\'s $type gains 10% effectiveness.")); } elsif ($type eq "weapon") { - chanmsg(clog("$player sharpened the edge of his weapon! ". - "$player\'s $type gains 10% effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player sharpened the edge of his weapon! ". + "$player\'s $type gains 10% effectiveness.")); } elsif ($type eq "tunic") { - chanmsg(clog("A magician cast a spell of Rigidity on $player\'s ". - "tunic! $player\'s $type gains 10% effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "A magician cast a spell of Rigidity on $player\'s ". + "tunic! $player\'s $type gains 10% effectiveness.")); } elsif ($type eq "shield") { - chanmsg(clog("$player reinforced his shield with a dragon's ". - "scales! $player\'s $type gains 10% effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player reinforced his shield with a dragon's ". + "scales! $player\'s $type gains 10% effectiveness.")); } else { - chanmsg(clog("The local wizard imbued $player\'s pants with a ". - "Spirit of Fortitude! $player\'s $type gains 10% ". - "effectiveness.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "The local wizard imbued $player\'s pants with a ". + "Spirit of Fortitude! $player\'s $type gains 10% ". + "effectiveness.")); } my $suffix=""; if ($rps->{$player}{item}{$type} =~ /(\D)$/) { $suffix=$1; } @@ -264,7 +279,7 @@ sub godsend { # bless the unworthy else { my $time = int(int(5 + rand(8)) / 100 * $rps->{$player}{next}); if (!open(Q,$opts->{eventsfile})) { - return chanmsg("ERROR: Failed to open $opts->{eventsfile}: $!"); + return Irpg::Irc::chanmsg("ERROR: Failed to open $opts->{eventsfile}: $!"); } my($i,$actioned); while (my $line = <Q>) { @@ -275,11 +290,12 @@ sub godsend { # bless the unworthy my $pron_poss = pronoun(2, $rps->{$player}{gender}); $actioned =~ s/<p_obj>/$pron_obj/g; $actioned =~ s/<g_poss>/$pron_poss/g; - chanmsg(clog("$player $actioned! This wondrous godsend has ". - "accelerated ".$pron_obj." ".duration($time). - " towards level ".($rps->{$player}{level}+1).".")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$player $actioned! This wondrous godsend has ". + "accelerated ".$pron_obj." ".duration($time). + " towards level ".($rps->{$player}{level}+1).".")); $rps->{$player}{next} -= $time; - chanmsg("$player reaches next level in ".duration($rps->{$player}{next}). + Irpg::Irc::chanmsg("$player reaches next level in ".duration($rps->{$player}{next}). "."); } } @@ -302,28 +318,30 @@ sub evilness { my $tempitem = $rps->{$me}{item}{$type}; $rps->{$me}{item}{$type} = $rps->{$target}{item}{$type}; $rps->{$target}{item}{$type} = $tempitem; - chanmsg(clog("$me stole $target\'s level ". - int($rps->{$me}{item}{$type})." $type while ". - pronoun(1, $rps->{$target}{gender}). - ($rps->{$target}{gender} eq 'n' ? " were " : " was "). - "sleeping! $me leaves ". - pronoun(2, $rps->{$me}{gender})." old level ". - int($rps->{$target}{item}{$type})." $type behind, ". - "which $target then takes.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$me stole $target\'s level ". + int($rps->{$me}{item}{$type})." $type while ". + pronoun(1, $rps->{$target}{gender}). + ($rps->{$target}{gender} eq 'n' ? " were " : " was "). + "sleeping! $me leaves ". + pronoun(2, $rps->{$me}{gender})." old level ". + int($rps->{$target}{item}{$type})." $type behind, ". + "which $target then takes.")); } else { - notice("You made to steal $target\'s $type, but realized it was ". + Irpg::Irc::notice("You made to steal $target\'s $type, but realized it was ". "lower level than your own. You creep back into the ". "shadows.",$rps->{$me}{nick}); } } else { # being evil only pays about half of the time... my $gain = 1 + int(rand(5)); - chanmsg(clog("$me is forsaken by his evil god. ". - duration(int($rps->{$me}{next} * ($gain/100)))." is added ". - "to his clock.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$me is forsaken by his evil god. ". + duration(int($rps->{$me}{next} * ($gain/100)))." is added ". + "to his clock.")); $rps->{$me}{next} = int($rps->{$me}{next} * (1 + ($gain/100))); - chanmsg("$me reaches next level in ".duration($rps->{$me}{next})."."); + Irpg::Irc::chanmsg("$me reaches next level in ".duration($rps->{$me}{next})."."); } } @@ -333,15 +351,16 @@ sub goodness { return unless @players > 1; splice(@players,int(rand(@players)),1) while @players > 2; my $gain = 5 + int(rand(8)); - chanmsg(clog("$players[0] and $players[1] have not let the iniquities of ". - "evil men poison them. Together have they prayed to their ". - "god, and it is his light that now shines upon them. $gain\% ". - "of their time is removed from their clocks.")); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$players[0] and $players[1] have not let the iniquities of ". + "evil men poison them. Together have they prayed to their ". + "god, and it is his light that now shines upon them. $gain\% ". + "of their time is removed from their clocks.")); $rps->{$players[0]}{next} = int($rps->{$players[0]}{next}*(1 - ($gain/100))); $rps->{$players[1]}{next} = int($rps->{$players[1]}{next}*(1 - ($gain/100))); - chanmsg("$players[0] reaches next level in ". + Irpg::Irc::chanmsg("$players[0] reaches next level in ". duration($rps->{$players[0]}{next})."."); - chanmsg("$players[1] reaches next level in ". + Irpg::Irc::chanmsg("$players[1] reaches next level in ". duration($rps->{$players[1]}{next})."."); } diff --git a/Irpg/Fight.pm b/Irpg/Fight.pm index da978a6d36ab6fc072e4566d19d4e74b4b34f329..2b77b464e023d6a0471aa7d5fce5bfd158c18e48 100644 --- a/Irpg/Fight.pm +++ b/Irpg/Fight.pm @@ -69,20 +69,22 @@ sub challenge_opp { # pit argument player against random player my $gain = ($opp eq $$primnick_ref)?20:int($rps->{$opp}{level}/4); $gain = 7 if $gain < 7; $gain = int(($gain/100)*$rps->{$u}{next}); - chanmsg(clog("$u [$myroll/$mysum] has challenged $opp [$opproll/". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$u [$myroll/$mysum] has challenged $opp [$opproll/". "$oppsum] in combat and won! ".duration($gain)." is ". "removed from $u\'s clock.")); $rps->{$u}{next} -= $gain; - chanmsg("$u reaches next level in ".duration($rps->{$u}{next})."."); + Irpg::Irc::chanmsg("$u reaches next level in ".duration($rps->{$u}{next})."."); my $csfactor = $rps->{$u}{alignment} eq "g" ? 50 : $rps->{$u}{alignment} eq "e" ? 20 : 35; if (rand($csfactor) < 1 && $opp ne $$primnick_ref) { $gain = int(((5 + int(rand(20)))/100) * $rps->{$opp}{next}); - chanmsg(clog("$u has dealt $opp a Critical Strike! ". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$u has dealt $opp a Critical Strike! ". duration($gain)." is added to $opp\'s clock.")); $rps->{$opp}{next} += $gain; - chanmsg("$opp reaches next level in ".duration($rps->{$opp}{next}). + Irpg::Irc::chanmsg("$opp reaches next level in ".duration($rps->{$opp}{next}). "."); } elsif (rand(25) < 1 && $opp ne $$primnick_ref && $rps->{$u}{level} > 19) { @@ -91,7 +93,8 @@ sub challenge_opp { # pit argument player against random player "pair of boots"); my $type = $items[rand(@items)]; if (int($rps->{$opp}{item}{$type}) > int($rps->{$u}{item}{$type})) { - chanmsg(clog("In the fierce battle, $opp dropped his level ". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "In the fierce battle, $opp dropped his level ". int($rps->{$opp}{item}{$type})." $type! $u picks ". "it up, tossing his old level ". int($rps->{$u}{item}{$type})." $type to $opp.")); @@ -105,11 +108,12 @@ sub challenge_opp { # pit argument player against random player my $gain = ($opp eq $$primnick_ref)?10:int($rps->{$opp}{level}/7); $gain = 7 if $gain < 7; $gain = int(($gain/100)*$rps->{$u}{next}); - chanmsg(clog("$u [$myroll/$mysum] has challenged $opp [$opproll/". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$u [$myroll/$mysum] has challenged $opp [$opproll/". "$oppsum] in combat and lost! ".duration($gain)." is ". "added to $u\'s clock.")); $rps->{$u}{next} += $gain; - chanmsg("$u reaches next level in ".duration($rps->{$u}{next})."."); + Irpg::Irc::chanmsg("$u reaches next level in ".duration($rps->{$u}{next})."."); } } @@ -124,17 +128,19 @@ sub collision_fight { my $gain = int($rps->{$opp}{level}/4); $gain = 7 if $gain < 7; $gain = int(($gain/100)*$rps->{$u}{next}); - chanmsg(clog("$u [$myroll/$mysum] has come upon $opp [$opproll/$oppsum". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$u [$myroll/$mysum] has come upon $opp [$opproll/$oppsum". "] and taken ".pronoun(3, $rps->{$opp}{gender})." in combat! ".duration($gain)." is ". "removed from $u\'s clock.")); $rps->{$u}{next} -= $gain; - chanmsg("$u reaches next level in ".duration($rps->{$u}{next})."."); + Irpg::Irc::chanmsg("$u reaches next level in ".duration($rps->{$u}{next})."."); if (rand(35) < 1 && $opp ne $$primnick_ref) { $gain = int(((5 + int(rand(20)))/100) * $rps->{$opp}{next}); - chanmsg(clog("$u has dealt $opp a Critical Strike! ". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$u has dealt $opp a Critical Strike! ". duration($gain)." is added to $opp\'s clock.")); $rps->{$opp}{next} += $gain; - chanmsg("$opp reaches next level in ".duration($rps->{$opp}{next}). + Irpg::Irc::chanmsg("$opp reaches next level in ".duration($rps->{$opp}{next}). "."); } elsif (rand(25) < 1 && $opp ne $$primnick_ref && $rps->{$u}{level} > 19) { @@ -143,7 +149,7 @@ sub collision_fight { "pair of boots"); my $type = $items[rand(@items)]; if (int($rps->{$opp}{item}{$type}) > int($rps->{$u}{item}{$type})) { - chanmsg("In the fierce battle, $opp dropped his level ". + Irpg::Irc::chanmsg("In the fierce battle, $opp dropped his level ". int($rps->{$opp}{item}{$type})." $type! $u picks it up, ". "tossing his old level ".int($rps->{$u}{item}{$type}). " $type to $opp."); @@ -157,11 +163,12 @@ sub collision_fight { my $gain = ($opp eq $$primnick_ref)?10:int($rps->{$opp}{level}/7); $gain = 7 if $gain < 7; $gain = int(($gain/100)*$rps->{$u}{next}); - chanmsg(clog("$u [$myroll/$mysum] has come upon $opp [$opproll/$oppsum". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$u [$myroll/$mysum] has come upon $opp [$opproll/$oppsum". "] and been defeated in combat! ".duration($gain)." is ". "added to $u\'s clock.")); $rps->{$u}{next} += $gain; - chanmsg("$u reaches next level in ".duration($rps->{$u}{next})."."); + Irpg::Irc::chanmsg("$u reaches next level in ".duration($rps->{$u}{next})."."); } } @@ -180,7 +187,8 @@ sub team_battle { # pit three players against three other players my $myroll = int(rand($mysum)); my $opproll = int(rand($oppsum)); if ($myroll >= $opproll) { - chanmsg(clog("$opp[0], $opp[1], and $opp[2] [$myroll/$mysum] have ". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$opp[0], $opp[1], and $opp[2] [$myroll/$mysum] have ". "team battled $opp[3], $opp[4], and $opp[5] [$opproll/". "$oppsum] and won! ".duration($gain)." is removed from ". "their clocks.")); @@ -189,7 +197,8 @@ sub team_battle { # pit three players against three other players $rps->{$opp[2]}{next} -= $gain; } else { - chanmsg(clog("$opp[0], $opp[1], and $opp[2] [$myroll/$mysum] have ". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$opp[0], $opp[1], and $opp[2] [$myroll/$mysum] have ". "team battled $opp[3], $opp[4], and $opp[5] [$opproll/". "$oppsum] and lost! ".duration($gain)." is added to ". "their clocks.")); diff --git a/Irpg/Irc.pm b/Irpg/Irc.pm index 2eaba5cea43db53be238ee9f9c795546c408ffa9..45b83c1c3e19b3ccde8707b08e28fd43e57babb8 100644 --- a/Irpg/Irc.pm +++ b/Irpg/Irc.pm @@ -25,13 +25,15 @@ our @EXPORT = qw($sock); our @EXPORT_OK = qw($sock @queue &irc_connect &irc_clean &checkmsg &fq &sts - &privmsg &chanmsg ¬ice $inbytes); + &privmsg &chanmsg ¬ice $inbytes $outbytes); our %EXPORT_TAGS = (connection=>[qw($sock &irc_connect &irc_clean &checkmsg)], interaction=>[qw(fq sts privmsg chanmsg notice)]); my $outbytes = 0; # sent bytes my $inbytes = 0; # received bytes +my $out_ref = \$outbytes; +my $in_ref = \$inbytes; my @queue; # outgoing message queue diff --git a/Irpg/Quest.pm b/Irpg/Quest.pm index 2ccd7c704d5d54a6e7b77935e451766b1efd0ebe..8032a6295e3e6cea333e67313fe4cf7952306409 100644 --- a/Irpg/Quest.pm +++ b/Irpg/Quest.pm @@ -35,7 +35,7 @@ sub init_pkg { ($opts, $rps) = @_; } sub writequestfile { return unless $opts->{writequestfile}; open(QF,">$opts->{questfilename}") or do { - chanmsg("Error: Cannot open $opts->{questfilename}: $!"); + Irpg::Irc::chanmsg("Error: Cannot open $opts->{questfilename}: $!"); return; }; # if no active quest, just empty questfile. otherwise, write it @@ -79,7 +79,7 @@ sub quest { splice(@{$quest{questers}},int(rand(@{$quest{questers}})),1); } if (!open(Q,$opts->{eventsfile})) { - return chanmsg("ERROR: Failed to open $opts->{eventsfile}: $!"); + return Irpg::Irc::chanmsg("ERROR: Failed to open $opts->{eventsfile}: $!"); } my $i; while (my $line = <Q>) { @@ -101,13 +101,13 @@ sub quest { } close(Q); if ($quest{type} == 1) { - chanmsg(join(", ",(@{$quest{questers}})[0..2]).", and ". + Irpg::Irc::chanmsg(join(", ",(@{$quest{questers}})[0..2]).", and ". "$quest{questers}->[3] have been chosen by the gods to ". "$quest{text}. Quest to end in ".duration($quest{qtime}-time()). "."); } elsif ($quest{type} == 2) { - chanmsg(join(", ",(@{$quest{questers}})[0..2]).", and ". + Irpg::Irc::chanmsg(join(", ",(@{$quest{questers}})[0..2]).", and ". "$quest{questers}->[3] have been chosen by the gods to ". "$quest{text}. Participants must first reach [$quest{p1}->[0],". "$quest{p1}->[1]], then [$quest{p2}->[0],$quest{p2}->[1]].". @@ -126,7 +126,8 @@ sub questpencheck { my ($quester,$player); for $quester (@{$quest{questers}}) { if ($quester eq $k) { - chanmsg(clog("$k\'s prudence and self-regard has brought the ". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$k\'s prudence and self-regard has brought the ". "wrath of the gods upon the realm. All your great ". "wickedness makes you as it were heavy with lead, ". "and to tend downwards with great weight and ". @@ -164,7 +165,8 @@ sub movequesters { } if ($quest{stage}==1 && $allgo) { # all participants have reached point 1, now point 2 - chanmsg(clog(join(", ",(@{$quest{questers}})[0..2]).", ". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + join(", ",(@{$quest{questers}})[0..2]).", ". "and $quest{questers}->[3] have reached ". "the first step of their long quest. May the ". "Gods keep on smiling upon them.")); @@ -173,7 +175,8 @@ sub movequesters { } elsif ($quest{stage} == 2 && $allgo) { # all participants have reached point 2, time for reward \o/ - chanmsg(clog(join(", ",(@{$quest{questers}})[0..2]).", ". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + join(", ",(@{$quest{questers}})[0..2]).", ". "and $quest{questers}->[3] have completed their ". "journey! 25% of their burden is eliminated. ". "The peple can rejoice, the realm is sure a safer ". @@ -227,7 +230,8 @@ sub rpcheck { if (!@{$quest{questers}}) { quest(); } elsif ($quest{type} == 1) { # Time-based quest (type 1) reward - chanmsg(clog(join(", ",(@{$quest{questers}})[0..2]).", and ". + Irpg::Irc::chanmsg(Irpg::Utils::clog( + join(", ",(@{$quest{questers}})[0..2]).", and ". "$quest{questers}->[3] have blessed the realm by ". "completing their quest! 25% of their burden is ". "eliminated.")); @@ -246,16 +250,16 @@ sub rpcheck { sub quest_info { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!@{$quest{questers}}) { - privmsg("There is no active quest.",$source); + Irpg::Irc::privmsg("There is no active quest.",$source); } elsif ($quest{type} == 1) { - privmsg(join(", ",(@{$quest{questers}})[0..2]).", and ". + Irpg::Irc::privmsg(join(", ",(@{$quest{questers}})[0..2]).", and ". "$quest{questers}->[3] are on a quest to ". "$quest{text}. Quest to complete in ". duration($quest{qtime}-time()).".",$source); } elsif ($quest{type} == 2) { - privmsg(join(", ",(@{$quest{questers}})[0..2]).", and ". + Irpg::Irc::privmsg(join(", ",(@{$quest{questers}})[0..2]).", and ". "$quest{questers}->[3] are on a quest to ". "$quest{text}. Participants must first reach ". "[$quest{p1}->[0],$quest{p1}->[1]], then ". diff --git a/Irpg/Users.pm b/Irpg/Users.pm index dd3d71507b3a6e78188ea59fc7e3532f1ab26725..9251ed2f5441278634ae44a39c8a265ef598b012 100644 --- a/Irpg/Users.pm +++ b/Irpg/Users.pm @@ -206,10 +206,6 @@ sub logout { sub status { return unless ($opts->{statuscmd}); my ($userhost, $usernick, $username, $source, @arg) = @_; - #if (!defined($username)) { - # Irpg::Irc::privmsg("You are not logged in.", $usernick); - #} - # argument is optional my $asked = $arg[0]; $asked = $username unless ($asked); my $asked_found = Irpg::Main::finduser($asked) unless (exists($rps->{$asked})); @@ -219,7 +215,7 @@ sub status { if (!$asked) { Irpg::Irc::privmsg("No matching user found.",$source); } - else { # no argument, look up this user + else { Irpg::Irc::privmsg("$asked: Level $rps->{$asked}{level} ". "$rps->{$asked}{class}; Status: O". ($rps->{$asked}{online}?"n":"ff")."line; ". @@ -234,20 +230,20 @@ sub status { sub whoami { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!defined($username)) { - Irpg::Irc::privmsg("You are not logged in.", $usernick); + Irpg::Irc::notice("You are not logged in.", $usernick); } else { Irpg::Irc::privmsg("You are $username, the level ". $rps->{$username}{level}." $rps->{$username}{class}. ". "Next level in ".duration($rps->{$username}{next}), - $usernick); + $source); } } sub newpass { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!defined($username)) { - Irpg::Irc::privmsg("You are not logged in.", $usernick) + Irpg::Irc::notice("You are not logged in.", $usernick) } elsif (!defined($arg[0])) { Irpg::Irc::privmsg("Try: NEWPASS <new password>", $usernick); @@ -261,42 +257,42 @@ sub newpass { sub align { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!defined($username)) { - Irpg::Irc::privmsg("You are not logged in.", $usernick) + Irpg::Irc::notice("You are not logged in.", $usernick) } elsif (!defined($arg[0]) || (lc($arg[0]) ne "good" && lc($arg[0]) ne "neutral" && lc($arg[0]) ne "evil")) { - Irpg::Irc::privmsg("Try: ALIGN <good|neutral|evil>", $usernick); + Irpg::Irc::notice("Try: ALIGN <good|neutral|evil>", $usernick); } else { $rps->{$username}{alignment} = substr(lc($arg[0]),0,1); Irpg::Irc::chanmsg("$username has changed alignment to: ".lc($arg[0]). "."); Irpg::Irc::privmsg("Your alignment was changed to ".lc($arg[0]).".", - $usernick); + $source); } } sub gender { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!defined($username)) { - Irpg::Irc::privmsg("You are not logged in.", $usernick) + Irpg::Irc::notice("You are not logged in.", $usernick) } elsif (!defined($arg[0]) || $arg[0] =~ /[^MFN]/) { - Irpg::Irc::privmsg("Try: GENDER <M|F|N>",$usernick); + Irpg::Irc::notice("Try: GENDER <M|F|N>",$usernick); } else { $rps->{$username}{gender} = substr(lc($arg[0]),0,1); Irpg::Irc::chanmsg("$username has changed gender to: ".lc($arg[0]). "."); Irpg::Irc::privmsg("Your gender was changed to ".lc($arg[0]).".", - $usernick); + $source); } } sub rmplayer { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!defined($username)) { - Irpg::Irc::privmsg("You are not logged in.", $usernick) + Irpg::Irc::notice("You are not logged in.", $usernick) } else { Irpg::Irc::privmsg("Account $username removed.",$usernick); @@ -308,7 +304,7 @@ sub rmplayer { sub help { my ($userhost, $usernick, $username, $source, @arg) = @_; - if ($source !~ /^#/ || !Irpg::Main::ha($usernick)) { + if ($source =~ /^#/ || !Irpg::Main::ha($usernick)) { Irpg::Irc::privmsg("For information on IRPG bot commands, see ". $opts->{helpurl}, $source); } @@ -340,8 +336,8 @@ sub info { "online of %d total users. PAUSE_MODE is %d, ". "SILENT_MODE is %d. Outgoing queue is %d bytes ". "in %d items. On via: %s. Admins online: %s.", - $Irpg::Irc::outbytes/1024, - $Irpg::Irc::inbytes/1024, + $$Irpg::Irc::out_ref/1024, + $$Irpg::Irc::in_ref/1024, duration(time()-$^T), scalar(grep { $rps->{$_}{online} } keys(%$rps)), scalar(keys(%$rps)), @@ -359,15 +355,15 @@ sub info { our $commands = { register => {ref => \®ister, adm => 0, prv => 1, pub => 0}, - chclass => {ref => \&chclass, adm => 0, prv => 1, pub => 0}, + removeme => {ref => \&rmplayer, adm => 0, prv => 1, pub => 1}, login => {ref => \&login, adm => 0, prv => 1, pub => 0}, logout => {ref => \&logout, adm => 0, prv => 1, pub => 0}, - status => {ref => \&status, adm => 0, prv => 1, pub => 1}, - whoami => {ref => \&whoami, adm => 0, prv => 1, pub => 1}, newpass => {ref => \&newpass, adm => 0, prv => 1, pub => 0}, + chclass => {ref => \&chclass, adm => 0, prv => 1, pub => 0}, align => {ref => \&align, adm => 0, prv => 1, pub => 1}, gender => {ref => \&gender, adm => 0, prv => 1, pub => 1}, - removeme => {ref => \&rmplayer, adm => 0, prv => 1, pub => 1}, + status => {ref => \&status, adm => 0, prv => 1, pub => 1}, + whoami => {ref => \&whoami, adm => 0, prv => 1, pub => 1}, help => {ref => \&help, adm => 0, prv => 1, pub => 1}, info => {ref => \&info, adm => 0, prv => 1, pub => 0} }; diff --git a/Irpg/Utils.pm b/Irpg/Utils.pm index d60e529e7861afd59e77aaa385a64c0af10da5ae..cb4d53f183bf1498e61efcca9747814c2861bb4b 100644 --- a/Irpg/Utils.pm +++ b/Irpg/Utils.pm @@ -29,20 +29,10 @@ our %EXPORT_TAGS = (text=>[qw(&duration &pronoun &mksalt)], data=>[qw(&readconfig &createdb &loaddb &backup &writedb)]); -my $debug; -my $verbose; -my $debugfile; - my $_configfile = '.irpg.conf'; -=head1 FUNCTION set_debug_status - This function sets the variables used by the debug function. -=over -=item SCALAR (bool) - whether the debug is active or not -=item SCALAR (bool) - whether the verbose mode is active or not -=item SCALAR (string) - name of the debug file -=cut -sub set_debug_status { ($debug, $verbose, $debugfile) = @_; } +my $opts; +my $rps; =head1 FUNCTION ts This function returns a random salt for passwds @@ -108,8 +98,8 @@ sub ts { # timestamp sub debug { (my $text = shift) =~ s/[\r\n]//g; my $die = shift; - if ($debug || $verbose) { - open(DBG,">>$debugfile") or do { + if ($opts->{debug} || $opts->{verbose}) { + open(DBG,">>$opts->{debugfile}") or do { Irpg::Irc::chanmsg("Error: Cannot open debug file: $!"); return; }; @@ -130,7 +120,6 @@ sub debug { =cut sub clog { my $mesg = shift; - my $opts = shift; open(B,">>$opts->{modsfile}") or do { debug("Error: Cannot open $opts->{modsfile}: $!"); Irpg::Irc::chanmsg("Error: Cannot open $opts->{modsfile}: $!"); @@ -144,12 +133,8 @@ sub clog { =head1 FUNCTION daemonize This function daemonizes the process. -=over -=item SCALAR (ref) - reference to the options hash -=back =cut sub daemonize { - my $opts = shift; # win32 doesn't daemonize (this way?) if ($^O eq "MSWin32") { print debug("Nevermind, this is Win32, no I'm not.")."\n"; @@ -183,7 +168,7 @@ sub readconfig { my %opts; if (! -e $_configfile) { debug("Error: Cannot find $_configfile. Copy it to this directory, ". - "please.",\%opts,1); + "please.",1); } else { open(CONF,"<$_configfile") or do { @@ -210,7 +195,8 @@ sub readconfig { else { $opts{$key} = $val; } } close(CONF); - return %opts; + $opts = \%opts; + return $opts; } } @@ -237,13 +223,10 @@ sub backup { and returns a reference to this hash =over =item SCALAR - socket (from irc connection) -=item SCALAR (ref) - reference to the options hash -=item SCALAR (ref) - reference to the hash of online players =back =cut sub loaddb { # load the players database my $sock = shift; - my $opts = shift; backup($opts); my $l; my %rps = (); @@ -302,20 +285,15 @@ sub loaddb { # load the players database close(RPS); debug("loaddb(): loaded ".scalar(keys(%rps))." accounts, ". scalar(keys(%prev_online))." previously online."); - return (\%rps, \%prev_online); + $rps = \%rps; + return ($rps, \%prev_online); } =head1 FUNCTION writedb This function write the content of the hash of players into the database -=over -=item SCALAR (ref) - reference to the options hash -=item SCALAR (ref) - reference to the hash of players -=back =cut sub writedb { - my $opts = shift; - my $rps = shift; open(RPS,">$opts->{dbfile}") or do { Irpg::Irc::chanmsg("ERROR: Cannot write $opts->{dbfile}: $!"); return 0; @@ -450,9 +428,10 @@ sub createdb { "pen_logout","pen_logout","pen_class") { $rps{$uname}{$pen} = 0; } - writedb($opts, \%rps); + writedb(); print "OK, wrote you into $opts->{dbfile}.\n"; - return \%rps; + $rps = \%rps; + return $rps; } =head1 FUNCTION checksplits @@ -464,7 +443,7 @@ sub createdb { =back =cut sub checksplits { # removed expired split hosts from the hash - my ($opts, $rps, $split) = @_; + my $split = shift; my $host; while ($host = each(%$split)) { if (time()-$split->{$host}{time} > $opts->{splitwait}) { diff --git a/irpg_bot.pl b/irpg_bot.pl index 50d40d29aef09dd37e1b2e22f8dcb9b97cf04482..d5ea7074d2f67cfd6ad3f9ef7e9460c43a3a0703 100644 --- a/irpg_bot.pl +++ b/irpg_bot.pl @@ -34,8 +34,8 @@ use Irpg::Irc qw(:connection &privmsg); use Irpg::Utils qw(:DEFAULT &daemonize &set_debug_status :data); use Irpg::Main; -my %opts = readconfig(); -set_debug_status($opts{debug}, $opts{verbose}, $opts{debugfile}); +my $opts = readconfig(); +#Irpg::Utils::init_pkg(\%opts); my $version = "3.2.0"; @@ -73,7 +73,7 @@ usage: $prog [OPTIONS] } # command line overrides .irpg.conf -GetOptions(\%opts, +GetOptions($opts, "help|h", "verbose|v", "debug", @@ -129,31 +129,30 @@ GetOptions(\%opts, "rppenstep=f", "dbfile|irpgdb|db|d=s", ) or debug("Error: Could not parse command line. Try $0 --help\n",1); -set_debug_status($opts{debug}, $opts{verbose}, $opts{debugfile}); -$opts{help} and do { help(); exit 0; }; +$opts->{help} and do { help(); exit 0; }; -debug("Config: read $_: ".Dumper($opts{$_})) for keys(%opts); +debug("Config: read $_: ".Dumper($opts->{$_})) for keys(%$opts); my $rps = {}; # role-players my $prev_online = {}; # user@hosts online on restart, die my $auto_login = {}; # users to automatically log back on my $lasttime = 1; # last time that rpcheck() was run -$rps = createdb(\%opts) unless -e $opts{dbfile}; +$rps = createdb($opts) unless -e $opts->{dbfile}; -print "\n".debug("Becoming a daemon...")."\n"; -daemonize(\%opts); +#print "\n".debug("Becoming a daemon...")."\n"; +#daemonize(); $SIG{HUP} = "readconfig"; # sighup = reread config file CONNECT: -($rps, $prev_online) = loaddb($sock, \%opts); +($rps, $prev_online) = loaddb($sock); -irc_connect(\%opts); +irc_connect($opts); -Irpg::Main::init_pkg(\%opts, $rps, \$lasttime, $prev_online, $auto_login); +Irpg::Main::init_pkg($opts, $rps, \$lasttime, $prev_online, $auto_login); #-----------------# # MAIN LOOP # @@ -169,12 +168,12 @@ while (1) { # users' online flags to 1, rewrite db, and attempt to reconnect # (if that's wanted of us) $rps->{$_}{online}=1 for keys(%$auto_login); - writedb(\%opts, $rps); - if ($opts{reconnect}) { - irc_clean(\%opts); + writedb(); + if ($opts->{reconnect}) { + irc_clean($opts); goto CONNECT; } else { debug("Socket closed; disconnected.",1); } } - if ((time()-$lasttime) >= $opts{self_clock}) { rpcheck(); } + if ((time()-$lasttime) >= $opts->{self_clock}) { rpcheck(); } }