X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ND%2FInclude.pm;fp=ND%2FInclude.pm;h=0000000000000000000000000000000000000000;hb=90b8d5d5169a7e029c393f1f82a927f6e780f1bc;hp=9a42d97b092f062599c628e7e72e7257bbde2de3;hpb=a074bd17f5e8ba341a22bbfca1da7093b8351774;p=ndwebbie.git diff --git a/ND/Include.pm b/ND/Include.pm deleted file mode 100644 index 9a42d97..0000000 --- a/ND/Include.pm +++ /dev/null @@ -1,103 +0,0 @@ -#************************************************************************** -# Copyright (C) 2006 by Michael Andreen * -# * -# This program is free software; you can redistribute it and/or modify * -# it under the terms of the GNU General Public License as published by * -# the Free Software Foundation; either version 2 of the License, or * -# (at your option) any later version. * -# * -# This program is distributed in the hope that it will be useful, * -# but WITHOUT ANY WARRANTY; without even the implied warranty of * -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -# GNU General Public License for more details. * -# * -# You should have received a copy of the GNU General Public License * -# along with this program; if not, write to the * -# Free Software Foundation, Inc., * -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -#**************************************************************************/ - -package ND::Include; -use strict; -use warnings; -use CGI qw{:standard}; -require Exporter; - -our @ISA = qw/Exporter/; - -our @EXPORT = qw/min max parseValue prettyValue log_message intel_log unread_query pa_xp/; - -sub min { - my ($x,$y) = @_; - return ($x > $y ? $y : $x); -} - -sub max { - my ($x,$y) = @_; - return ($x < $y ? $y : $x); -} - - -sub parseValue { - if (defined $_[0] && $_[0] =~ /^(-?\d+(?:\.\d+)?)([khMG])?$/){ - return $1 unless defined $2; - return $1*100 if $2 eq 'h'; - return $1*1000 if $2 eq 'k'; - return $1*1000000 if $2 eq 'M'; - return $1*1000000000 if $2 eq 'G'; - } - return $_[0]; -} - -sub prettyValue { - my ($value,$decimals) = @_; - return sprintf('%.3e',$value) if $value > 1000000000000000; - my $unit = ''; - my @units = ('k','M','G','T'); - for (my $i = 0; $value >= 1000 && $i < 4;$i++){ - $value /= 1000; - $unit = $units[$i]; - } - unless (defined $decimals){ - $decimals = '.0'; - $decimals = '.1' if $value < 100 && $unit; - $decimals = '.2' if $value < 10 && $unit; - } - - return sprintf('%'.$decimals.'f%s', $value,$unit); -} - - -sub log_message { - my ($uid, $message) = @_; - my $log = $ND::DBH->prepare_cached(q{INSERT INTO forum_posts (ftid,uid,message) VALUES( - (SELECT ftid FROM users WHERE uid = $1),$1,$2)}); - $log->execute($uid,$message) or $ND::ERROR .= p($ND::DBH->errstr); -} - -sub intel_log { - my ($uid,$planet, $message) = @_; - my $log = $ND::DBH->prepare_cached(q{INSERT INTO forum_posts (ftid,uid,message) VALUES( - (SELECT ftid FROM planets WHERE id = $3),$1,$2)}); - $log->execute($uid,$message,$planet) or $ND::ERROR .= p($ND::DBH->errstr); -} - -sub pa_xp { - my ($roids,$ascore,$avalue,$tscore,$tvalue) = @_; - my $bravery = (max(0,min(2,$tscore/$ascore)-0.6)) * (min(2,$tvalue/$avalue)-0.4); - return int(max($roids * 10 * $bravery,0)) - -} - -sub unread_query { - return $ND::DBH->prepare_cached(q{ - SELECT count(*) AS unread, count(NULLIF(fp.time > $2,FALSE)) AS new -FROM forum_boards fb NATURAL JOIN forum_threads ft - JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN - (SELECT * FROM forum_thread_visits WHERE uid = $1) ftv ON ftv.ftid = ft.ftid -WHERE (ftv.time IS NULL OR fp.time > ftv.time) AND fbid > 0 AND - fbid IN (SELECT fbid FROM forum_access WHERE gid IN (SELECT groups($1))) - }); -} - -1;