$savecounterfile.$currentDay") || &errormesg ("Error - counterfile3new: $!
Please notify webmaster\@storymania.com");
eval 'flock(FCOUNTSV,2)'; # LOCK file
print FCOUNTSV @hitcount;
eval 'flock(FCOUNTB,8)'; # UN-LOCK file
close (FCOUNTSV);
chmod (0666, "$savecounterfile.$currentDay");
# Do self-correction!
@hitcount = @bkhitcount;
}
close (FCOUNTB);
} else {
open (FCOUNTB, ">$bkcounterfile.$currentDay") || &errormesg ("Error - counterfile3new: $!
Please notify webmaster\@storymania.com");
eval 'flock(FCOUNTB,2)'; # LOCK file
print FCOUNTB @hitcount;
eval 'flock(FCOUNTB,8)'; # UN-LOCK file
close (FCOUNTB);
}
chmod (0666, "$bkcounterfile.$currentDay");
# Does an entry exist
$entryFound = "N";
$baseID = $titlesdir . $INPUT{'file'};
if ($INPUT{'action'} eq "display") {
$baseID =~ s/.*\/(.*).htm/$1/;
} else {
$baseID =~ s/.*\/(.*).exe/$1/;
}
# Look for entry and increment counter if IP address is different
@new_count = ();
# Determine count
foreach $co (@hitcount) {
chomp($co);
if ($co eq "") { next; }
($authorTitleID, $ipAddr, $count) = split (/$SEP2/, $co);
if (($ipAddr eq "") || ($count eq "")) { next; }
if ($authorTitleID eq $baseID) {
$entryFound = "Y";
if ($cur_remote_ip ne $ipAddr) { $count++; }
push (@new_count, "$authorTitleID$SEP$cur_remote_ip$SEP$count\n");
next;
}
push (@new_count, $co, "\n");
}
if ($entryFound eq "N") {
push (@new_count, "$baseID$SEP$cur_remote_ip$SEP$defaultCount\n");
}
# Fix file lock, July 2001
open (FCOUNT, "+<$counterfile") || &errormesg ("Error - counterfile2: $!
Please notify webmaster\@storymania.com");
eval 'flock(FCOUNT,2)'|| &errormesg ("Error - lockcounterfile2: $!
Please notify webmaster\@storymania.com");
seek (FCOUNT, 0, 0);
truncate (FCOUNT, 0) || &errormesg ("Error - counterfile2trun: $!
Please notify webmaster\@storymania.com");
# open (FCOUNT, ">$counterfile") || &errormesg ("Error - counterfile2cr: $!
Please notify webmaster\@storymania.com");
print FCOUNT @new_count; # Overwrites file!
eval 'flock(FCOUNT,8)'|| &errormesg ("Error - unlockcounterfile2: $!
Please notify webmaster\@storymania.com");
close (FCOUNT);
## End of main routine!
# Put out error message and exit
sub errormesg {
my ($reason) = @_;
print ("Content-type: text/html\n\n");
print("\nStorymania\n\n");
print("
\n");
print ("$reason\n");
print("
Please use the back button of your browser to continue.\n");
print("
[ Storymania Home Page ]
\n");
print ("\n");
exit;
}