LoGD Standardrelease steht hier zum Download zur Verfügung!

Zeige Source: /zerbaes/neu/common.php

Hier klicken für den Source, ODER
Weitere Dateien, von denen du den Quelltext sehen kannst:
(Das Lesen des Source, um sich spielerische Vorteile zu verschaffen, ist nicht erlaubt. Solltest du Schwachstellen oder Fehler entdecken, bist du als Spieler verpflichtet, diese zu melden.)

Source von: /zerbaes/neu/common.php

<?php

// 12092004

require_once "dbwrapper.php";
require_once 
"anticheat.php"

$pagestarttime getmicrotime();

$nestedtags=array();
$output="";

function 
useronline(){ //Wer ist hier online? V.1.0 by Devilzimti
global $session,$SCRIPT_NAME;

$useronline "<br>
<table border='0' cellpadding='0' cellspacing='0' class='vitalinfo'>
<tr><td class='charhead' colspan='2'><b>`&&nbsp;Hier anwesend:`0</b></tr></td> "
;
$sql "SELECT name,login FROM accounts
                WHERE (accounts.restorepage LIKE '"
.$SCRIPT_NAME."%"."' OR accounts.acctid=".$session[user][acctid].")
                AND loggedin = 1
                AND locked = 0
                AND laston>'"
.date("Y-m-d H:i:s",strtotime("-".getsetting("LOGINTIMEOUT",900)." seconds"))."'
                ORDER BY dragonkills,level;
                "
;

$query =db_query($sql);

while(
$row db_fetch_assoc($query)){
    
$useronline.= "<tr><td>&nbsp;<a href='mail.php?op=write&to=".rawurlencode($row['login'])."' target='_blank' onClick=\"".popup("mail.php?op=write&to=".rawurlencode($row['login'])).";return false;\"><img src='images/newscroll.GIF' width='16' height='16' alt='Mail schreiben' border='0'></a>&nbsp;";
/*if ($session[user][loggedin] && $row[rpbulb]==0) $useronline.="<img src=\"images/stern2.gif\">&nbsp;&nbsp;";
if ($session[user][loggedin] && $row[rpbulb]==1) $useronline.="<img src=\"images/stern1.gif\">&nbsp;&nbsp;";*/
   //if (getsetting("fest",0)==0)
   
$useronline.= "`0$row[name]</td></tr>";}
 
//  if (getsetting("fest",0)==1)  $useronline.= "`0$row[festname]</td></tr>";
}
$useronline.= "</td></tr></table>";

$useronline appoencode($useronline,true);
return 
$useronline;
}

function 
pvpwarning($dokill=false) {
    global 
$session;
    
$days getsetting("pvpimmunity"5);
    
$exp getsetting("pvpminexp"1500);
    if (
$session['user']['age'] <= $days &&
        
$session['user']['dragonkills'] == &&
        
$session['user']['user']['pk'] == &&
        
$session['user']['experience'] <= $exp) {
        if (
$dokill) {
            
output("`\$Warnung!`^ Da du selbst noch vor PvP geschützt warst, aber jetzt einen anderen Spieler angreifst, hast du deine Immunität verloren!!`n`n");
            
$session['user']['pk'] = 1;
        } else {
            
output("`\$Warnung!`^ Innerhalb der ersten $days  Tage in dieser Welt, oder bis sie $exp Erfahrungspunkte gesammelt haben, sind alle Spieler vor PvP-Angriffen geschützt. Wenn du einen anderen Spieler angreifst, verfällt diese Immunität für dich!`n`n");
        }
    }
}

function 
rawoutput($indata) {
    global 
$output;
    
$output .= $indata "\n";
}

function 
output($indata,$priv=false){
    global 
$nestedtags,$output;
    
$data translate($indata);
// Aprilscherz deaktiviert ;)
//    if (date("m-d")=="04-01"){
//        $out = appoencode($data,$priv);
//        if ($priv==false) $out = borkalize($out);
//        $output.=$out;
//    }else{
      
$output.=appoencode($data,$priv);
//    }
    
$output.="\n";
    return 
0;
}

function 
compress_out ($input) {
    
//Based on old YaBBSE code (c)
    //Open-Source Project by Zef Hemel (zef@zefnet.com <mailto:zef@zefnet.com>)
    //Copyright (c) 2001-2002 The YaBB Development Team
    
if((function_exists("gzcompress")) && (function_exists("crc32"))){
       if(
strpos(" " $_SERVER['HTTP_ACCEPT_ENCODING'], "x-gzip")){
          
$encode "x-gzip";
       }
       elseif(
strpos(" " $_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")){
          
$encode "gzip";
       }
    if (isset(
$encode)){
        
header("Content-Encoding: $encode");
        
$encode_size strlen($input);
        
$encode_crc crc32($input);
        
$out "\x1f\x8b\x08\x00\x00\x00\x00\x00";
        
$out .= substr(gzcompress($input1), 0, -4);
        
$out .= pack("V"$encode_crc);
        
$out .= pack("V"$encode_size);
    }
    else{
        
$out $input;
    }
}
else{
    
$out $input;
}
return (
$out);



function 
safeescape($input){
    return 
preg_replace('/([^\\\\])(["\'])/s',"\\1\\\\\\2",$input);

}

//by Chaosmaker
function petitionmail($subject,$body,$petition,$from,$seen=0,$to=0,$messageid=0) {
    
$subject safeescape($subject);
    
$subject=str_replace("\n","",$subject);
    
$subject=str_replace("`n","",$subject);
    
$body safeescape($body);
    
    
$sql "INSERT INTO petitionmail (petitionid,messageid,msgfrom,msgto,subject,body,sent,seen) VALUES ('".(int)$petition."','".(int)$messageid."','".(int)$from."','".(int)$to."','$subject','$body',now(),'$seen')";
    
db_query($sql);
    
$sql 'UPDATE petitions SET lastact=NOW() WHERE petitionid="'.(int)$petition.'"';
    
db_query($sql);
}
//end petitionmail 
function systemmail($to,$subject,$body,$from=0,$noemail=false){
    
$subject safeescape($subject);
    
$subject=str_replace("\n","",$subject);
    
$subject=str_replace("`n","",$subject);
    
$body safeescape($body);
    
//echo $subject."<br>".$body;
    
$sql "SELECT prefs,emailaddress FROM accounts WHERE acctid='$to'";
    
$result db_query($sql);
    
$row db_fetch_assoc($result);
    
db_free_result($result);
    
$prefs unserialize($row['prefs']);
    
    if (
$prefs['dirtyemail']){
        
//output("Not cleaning: $prefs[dirtyemail]");
    
}else{
        
//output("Cleaning: $prefs[dirtyemail]");
        
$subject=soap($subject);
        
$body=soap($body);
    }

    
$sql "INSERT INTO mail (msgfrom,msgto,subject,body,sent) VALUES ('".(int)$from."','".(int)$to."','$subject','$body',now())";
    
db_query($sql);
    
$email=false;
    if (
$prefs['emailonmail'] && $from>0){
        
$email=true;
    }elseif(
$prefs[emailonmail] && $from==&& $prefs[systemmail]){
        
$email=true;
    }
    if (!
is_email($row['emailaddress'])) $email=false;
    if (
$email && !$noemail){
        
$sql "SELECT name FROM accounts WHERE acctid='$from'";
        
$result db_query($sql);
        
$row1=db_fetch_assoc($result);
        
db_free_result($result);
        if (
$row1['name']!=""$fromline="From: ".preg_replace("'[`].'","",$row1[name])."\n";
        
// We've inserted it into the database, so.. strip out any formatting
        // codes from the actual email we send out... they make things
        // unreadable
        
$body preg_replace("'[`]n'""\n"$body);
        
$body preg_replace("'[`].'"""$body);
        
mail($row['emailaddress'],"Neue LoGD Mail","Du hast eine neue Nachricht von LoGD @ http://".$_SERVER[HTTP_HOST].dirname($_SERVER[SCRIPT_NAME])." empfangen.\n\n$fromline"
            
."Betreff: ".preg_replace("'[`].'","",stripslashes($subject))."\n"
            
."Body: ".stripslashes($body)."\n"
            
."\nDu kannst diese Meldungen in deinen Einstellungen abschalten.",
            
"From: ".getsetting("gameadminemail","postmaster@localhost")
        );
    }
}

function 
isnewday($level){
    global 
$session;
    if (
$session['user']['superuser']<$level) {
        
clearnav();
        
$session['output']="";
        
page_header("FREVEL!");
        
$session['bufflist']['angrygods']=array(
            
"name"=>"`^Die Götter sind wütend!",
            
"rounds"=>10,
            
"wearoff"=>"`^Es ist den Göttern langweilig geworden, dich zu quälen.",
            
"minioncount"=>$session['user']['level'],
            
"maxgoodguydamage"=> 2,
            
"effectmsg"=>"`7Die Götter verfluchen dich und machen dir `^{damage}`7 Schaden!",
            
"effectnodmgmsg"=>"`7Die Götter haben beschlossen, dich erstmal nicht zu quälen.",
            
"activate"=>"roundstart",
            
"survivenewday"=>1,
            
"newdaymessage"=>"`6Die Götter sind dir immer noch böse!"
        
);
        
output("Für den Versuch, die Götter zu betrügen, wurdest du niedergeschmettert!`n`n");
        
output("`\$Ramius, der Gott der Toten`) erscheint dir in einer Vision. Dafür, dass du versucht hast, deinen Geist mit seinem zu messen, sagt er dir wortlos, dass du keinen Gefallen mehr bei ihm hast.`n`n");
        
addnews("`&Für den Versuch, die Götter zu besudeln, wurde ".$session['user']['name']." zu Tode gequält! (Hackversuch gescheitert).");
        
$session['user']['hitpoints']=0;
        
$session['user']['alive']=0;
        
$session['user']['soulpoints']=0;
        
$session['user']['gravefights']=0;
        
$session['user']['deathpower']=0;
        
$session['user']['experience']*=0.75;
        
addnav("Tägliche News","news.php");
        
page_footer();
        
$sql "SELECT acctid FROM accounts WHERE superuser>=3";
        
$result db_query($sql);
        while (
$row db_fetch_assoc($result)) {
            
systemmail($row['acctid'],"`#{$session['user']['name']}`# hat versucht, Superuser-Seiten zu hacken!","Böse(r), böse(r), böse(r) {$session['user']['name']}, du bist ein Hacker!");
        }
        exit();
    }
}

function 
forest($noshowmessage=false) {
    global 
$session,$playermount;
  
$conf unserialize($session['user']['donationconfig']);
  if (
$conf['healer'] || $session['user']['acctid']==getsetting("hasegg",0)) {
      
addnav("H?Golindas Hütte","healer.php");
  } else {
      
addnav("H?Hütte des Heilers","healer.php");
  }
  
addnav("B?Etwas zum Bekämpfen suchen","forest.php?op=search");
  if (
$session['user']['level']>1)
      
addnav("H?Herumziehen","forest.php?op=search&type=slum");
  
addnav("N?Nervenkitzel suchen","forest.php?op=search&type=thrill");
  
//if ($session[user][hashorse]>=2) addnav("D?Dark Horse Tavern","forest.php?op=darkhorse");
  
if ($playermount['tavern']>0addnav("D?Nimm {$playermount['mountname']} zur Dark Horse Taverne","forest.php?op=darkhorse");
  if (
$playermount['tavern']>&& $conf['castle']) addnav("B?Nimm {$playermount['mountname']} zur Burg","forest.php?op=castle");
  if (
$conf['goldmine']>0addnav("Goldmine (".$conf[goldmine]."x)","paths.php?ziel=goldmine&pass=conf");
  
addnav("Z?Zurück zum Dorf","village.php");
  
addnav("","forest.php");
    if (
$session['user']['level']>=15  && $session['user']['seendragon']==0){
        
addnav("G?`@Den Grünen Drachen suchen","forest.php?op=dragon");
    }
    
addnav("Sonstiges");
    
addnav("P?Plumpsklo","outhouse.php");
    if (
$session['user']['turns']<=addnav("Hexenhaus","hexe.php");
    if (
$noshowmessage!=true){
        
output("`c`7`bDer Wald`b`0`c");
        
output("Der Wald, Heimat von bösartigen Kreaturen und üblen Übeltätern aller Art.`n`n");
        
output("Die dichten Blätter des Waldes erlauben an den meisten Stellen nur wenige Meter Sicht.  ");
        
output("Die Wege würden dir verborgen bleiben, hättest du nicht ein so gut geschultes Auge. Du bewegst dich so leise wie ");
        
output("eine milde Brise über den dicken Humus, der den Boden bedeckt. Dabei versuchst du es zu vermeiden ");
        
output("auf dünne Zweige oder irgendwelche der ausgebleichten Knochenstücke zu treten, welche den Waldboden spicken. ");
        
output("Du verbirgst deine Gegenwart vor den abscheulichen Monstern, die den Wald durchwandern.");
        if (
$session['user']['turns']<=1output(" In der Nähe siehst du wieder den Rauch aus dem Kamin eines windschiefen Hexenhäuschens aufsteigen, von dem du schwören könntest, es war eben noch nicht da. ");
    }
    if (
$session['user']['superuser']>1){
        
output("`n`nSUPERUSER Specials:`n");
        
$d dir("special");
        while (
false !== ($entry $d->read())){
            
// Skip non php files (including directories)
            
if(strpos($entry".php") === false) continue;
            
// Skip any hidden files
            
if (substr($entry,0,1)==".") continue;
              
output("<a href='forest.php?specialinc=$entry'>$entry</a>`n"true);
            
addnav("","forest.php?specialinc=$entry");
        }
    }
}

function 
borkalize($in){
    
$out $in;
    
$out str_replace(". ",". Bork bork. ",$out);
    
$out str_replace(", ",", bork, ",$out);
    
$out str_replace(" h"," hoor",$out);
    
$out str_replace(" v"," veer",$out);
    
$out str_replace("g ","gen ",$out);
    
$out str_replace(" p"," pere",$out);
    
$out str_replace(" qu"," quee",$out);
    
$out str_replace("n ","nen ",$out);
    
$out str_replace("e ","eer ",$out);
    
$out str_replace("s ","ses ",$out);
    return 
$out;
}

function 
getmicrotime(){ 
    list(
$usec$sec) = explode(" ",microtime()); 
    return ((float)
$usec + (float)$sec); 
    } 
function 
make_seed() {
    list(
$usec$sec) = explode(' 'microtime());
    return (float) 
$sec + ((float) $usec 100000);
}
mt_srand(make_seed());

function 
e_rand($min=false,$max=false){
    if (
$min===false) return mt_rand();
    
$min*=1000;
    if (
$max===false) return round(mt_rand($min)/1000,0);
    
$max*=1000;
    if (
$min==$max) return round($min/1000,0);
    
// if ($min==0 && $max==0) return 0; //do NOT as me why this line can be executed, it makes no sense, but it *does* get executed.
    
if ($min<$max){
        return 
round(@mt_rand($min,$max)/1000,0);
    }else if(
$min>$max){
        return 
round(@mt_rand($max,$min)/1000,0);
    }
}

function 
is_email($email){
    return 
preg_match("/[[:alnum:]_.-]+[@][[:alnum:]_.-]{2,}.[[:alnum:]_.-]{2,}/",$email);
}

function 
checkban($login=false){
    global 
$session;
    if (
$session['banoverride']) return false;
    if (
$login===false){
        
$ip=$_SERVER[REMOTE_ADDR];
        
$id=$_COOKIE[lgi];
        
//echo "<br>Orig output: $ip, $id<br>";
    
}else{
        
$sql "SELECT lastip,uniqueid,banoverride FROM accounts WHERE login='$login'";
        
$result db_query($sql) or die(db_error(LINK));
        
$row db_fetch_assoc($result);
        if (
$row['banoverride']){
            
$session['banoverride']=true;
            
//echo "`nYou are absolved of your bans, son.";
            
return false;
        }else{
            
//echo "`nNo absolution here, son.";
        
}
        
db_free_result($result);
        
$ip=$row['lastip'];
        
$id=$row['uniqueid'];
        
//echo "<br>Secondary output: $ip, $id<br>";
    
}
    
$sql "select * from bans where ((substring('$ip',1,length(ipfilter))=ipfilter AND ipfilter<>'') OR (uniqueid='$id' AND uniqueid<>'')) AND (banexpire='0000-00-00' OR banexpire>'".date("Y-m-d")."')";
    
//echo $sql;
    
$result db_query($sql) or die(db_error(LINK));
    if (
db_num_rows($result)>0){
        
// $msg.=$session['message'];
        
$session=array();
        
//$session['message'] = $msg;
        //echo "Session Abandonment";
        
$session[message].="`n`4Du bist einer Verbannung zum Opfer gefallen:`n";
        for (
$i=0;$i<db_num_rows($result);$i++){
            
$row db_fetch_assoc($result);
            
$session[message].=$row[banreason];
            if (
$row[banexpire]=="0000-00-00"$session[message].="  `\$Die Verbannung ist permanent!`0";
            if (
$row[banexpire]!="0000-00-00"$session[message].="  `^Der Bann wird am ".date("M d, Y",strtotime($row[banexpire]))." aufgehoben `0";
            
$session[message].="`n";
        }
        
$session[message].="`4Wenn du willst, kannst du mit einer Anfrage nach dem Grund fragen.";
        
header("Location: index.php");
        exit();
    }
    
db_free_result($result);
}

function 
increment_specialty(){
  global 
$session;
        if (
$session[user][specialty]>0){
            
$skillnames = array(1=>"Dunkle Künste","Mystische Kräfte","Diebeskunst");
            
$skills = array(1=>"darkarts","magic","thievery");
            
$skillpoints = array(1=>"darkartuses","magicuses","thieveryuses");
            
$session[user][$skills[$session[user][specialty]]]++;
            
output("`nDu steigst in `&".$skillnames[$session[user][specialty]]."`# ein Level auf ".$session[user][$skills[$session[user][specialty]]]." auf. ");
            
$x = ($session[user][$skills[$session[user][specialty]]]) % 3;
            if (
$x == 0){
                
output("Du bekommst eine zusätzliche Anwendung!`n");
                
$session[user][$skillpoints[$session[user][specialty]]]++;
            }else{
                
output("Nur noch ".(3-$x)." weitere Stufen, bis du eine zusätzliche Anwendung erhältst!`n");
            }
        }else{
            
output("`7Du wanderst ziel- und planlos durchs Leben. Du solltest eine Rast machen und einige wichtige Entscheidungen für dein weiteres Leben treffen.`n");
        }
}

function 
fightnav($allowspecial=true$allowflee=true){
  global 
$PHP_SELF,$session;
    
//$script = str_replace("/","",$PHP_SELF);
    
$script substr($PHP_SELF,strrpos($PHP_SELF,"/")+1);
    
addnav("Kämpfen","$script?op=fight");
    if (
$allowflee) {
        
addnav("Wegrennen","$script?op=run");
    }
    if (
getsetting("autofight",0)){
        
addnav("AutoFight");
        
addnav("5 Runden kämpfen","$script?op=fight&auto=five");
        
addnav("Bis zum bitteren Ende","$script?op=fight&auto=full");
    }
    if (
$allowspecial) {
        
addnav("`bBesondere Fähigkeiten`b");
        if (
$session[user][darkartuses]>0) {
            
addnav("`\$Dunkle Künste`0""");
            
addnav("`\$&#149; Skelette herbeirufen`7 (1/".$session[user][darkartuses].")`0","$script?op=fight&skill=DA&l=1",true);
        }
        if (
$session[user][darkartuses]>1)
            
addnav("`\$&#149; Voodoo`7 (2/".$session[user][darkartuses].")`0","$script?op=fight&skill=DA&l=2",true);
        if (
$session[user][darkartuses]>2)
            
addnav("`\$&#149; Geist verfluchen`7 (3/".$session[user][darkartuses].")`0","$script?op=fight&skill=DA&l=3",true);
        if (
$session[user][darkartuses]>4)
            
addnav("`\$&#149; Seele verdorren`7 (5/".$session[user][darkartuses].")`0","$script?op=fight&skill=DA&l=5",true);
    
        if (
$session[user][thieveryuses]>0) {
            
addnav("`^Diebeskünste`0","");
            
addnav("`^&#149; Beleidigen`7 (1/".$session[user][thieveryuses].")`0","$script?op=fight&skill=TS&l=1",true);
        }
        if (
$session[user][thieveryuses]>1)
            
addnav("`^&#149; Waffe vergiften`7 (2/".$session[user][thieveryuses].")`0","$script?op=fight&skill=TS&l=2",true);
        if (
$session[user][thieveryuses]>2)
            
addnav("`^&#149; Versteckter Angriff`7 (3/".$session[user][thieveryuses].")`0","$script?op=fight&skill=TS&l=3",true);
        if (
$session[user][thieveryuses]>4)
            
addnav("`^&#149; Angriff von hinten`7 (5/".$session[user][thieveryuses].")`0","$script?op=fight&skill=TS&l=5",true);
    
        if (
$session[user][magicuses]>0) {
            
addnav("`%Mystische Kräfte`0","");
            
//disagree with making this 'n', players shouldn't have their behavior dictated by convenience of god mode, hehe
            
addnav("g?`%&#149; Regeneration`7 (1/".$session[user][magicuses].")`0","$script?op=fight&skill=MP&l=1",true);
        }
        if (
$session[user][magicuses]>1)
            
addnav("`%&#149; Erdenfaust`7 (2/".$session[user][magicuses].")`0","$script?op=fight&skill=MP&l=2",true);
        if (
$session[user][magicuses]>2)
            
addnav("L?`%&#149; Leben absaugen`7 (3/".$session[user][magicuses].")`0","$script?op=fight&skill=MP&l=3",true);
        if (
$session[user][magicuses]>4)
            
addnav("A?`%&#149; Blitz Aura`7 (5/".$session[user][magicuses].")`0","$script?op=fight&skill=MP&l=5",true);
        if (
$session[user][superuser]>=3) {
            
addnav("`&Superuser`0","");
            
addnav("!?`&&#149; __GOD MODE","$script?op=fight&skill=godmode",true);
        }
// spells by anpera
        
$sql="SELECT * FROM items WHERE class='Zauber' AND owner=".$session[user][acctid]." AND value1>0 ORDER BY name ASC";
        
$result=db_query($sql) or die(db_error(LINK));
        if (
db_num_rows($result)>0addnav("Zauber");
        for (
$i=0;$i<db_num_rows($result);$i++){
              
$row db_fetch_assoc($result);
            
$spellbuff=unserialize($row[buff]);
            
addnav("`v$spellbuff[name] `0(".$row[value1]."x)","$script?op=fight&skill=zauber&itemid=$row[id]");
        }
// end spells
    
}
}

function 
appoencode($data,$priv=false)
{
   global 
$nestedtags,$session,$appoencode;
   
/* Überarbeitet und verkleinert von Eliwood =D */
   
$output "";
   while( !((
$x=strpos($data,"`")) === false) )
    {
        
$tag=substr($data,$x+1,1);
        
$append=substr($data,0,$x);
        
$output.=($priv?$append:HTMLSpecialChars($append));
        
$data=substr($data,$x+2);
        if(
$tag == "0")
      {
        if (
$nestedtags['color']) $output.="</span>";
          unset(
$nestedtags['color']);
      }
      elseif(
$tag == "`")
      {
        
$output.="`";
      }
      elseif(
$tag == "z")
      {
            
// Zufällige Farbe - by Devilzimti
            
$appoencode_s $appoencode;
            
shuffle($appoencode_s);
        
$rand e_rand(0,count($appoencode_s));
        if (
$nestedtags['color']) $output.="</span>"; else $nestedtags['color']=true;
        
$output.="<span style='color: #".$appoencode_s[$rand]['color'].";'>";
      }
      else
        {
          if(isset(
$appoencode[$tag]))
        {
            
$tagrow $appoencode[$tag];
            if(empty(
$tagrow['color']))
          {
            if(
$nestedtags[$tagrow['tag']] && strchr($tagrow['tag']," /")==false)
            {
              
$output.="</".$tagrow['tag'].">";
              unset(
$nestedtags[$tagrow['tag']]);
            }
            elseif(
strchr($tagrow['tag']," /")==true$output.="<".$tagrow['tag'].">\n";
            else
            {
              
$output.="<".$tagrow['tag']." ".$tagrow['style'].">";
              
$nestedtags[$tagrow['tag']] = true;
            }
          }
          else
          {
            if (
$nestedtags['color']) $output.="</span>"; else $nestedtags['color']=true;
            
$output.="<span style='color: #".$tagrow['color'].";'>";
          }
        }
        else 
$output.=$tag;
        }
    }
    if (
$priv)
        
$output.=$data;
     else
        
$output.=HTMLSpecialChars($data);
    return 
$output;
}





function 
Load_Tags()
{
  global 
$db,$link;
  
/* (c) 2005 by Eliwood & Serra */
  
$result DB_Query("SELECT * FROM appoencode",LINK);
  
$tags = array();
  while(
$row DB_Fetch_Assoc($result))
  {
    
$tags[$row['code']] = $row;
  }
  return 
$tags;
}

function 
Get_Allowed_Tags()
{
  global 
$appoencode;
  
/* (c) 2005 by Eliwood & Serra */
  
while(list($key,$val) = each($appoencode))
  {
    if(
$val['allowed'] == true$list.=$val['code'];
  }
  return 
preg_quote($list);
}
function 
closetags($string$tags) {
    
$tags explode('`',$tags);
    foreach (
$tags as $siht) {
        
$siht trim($siht);
        if (
$siht=='') continue;
        if (
substr_count($string,'`'.$siht)%2$string .= '`'.$siht;
    }    
    return 
$string;
}

function 
templatereplace($itemname,$vals=false){
    global 
$template;
    @
reset($vals);
    if (!isset(
$template[$itemname])) output("`bWarnung:`b Das `i$itemname`i Template wurde nicht gefunden!`n");
    
$out $template[$itemname];
    
//output($template[$itemname]."`n");
    
while (list($key,$val)=@each($vals)){
        if (
strpos($out,"{".$key."}")===falseoutput("`bWarnung:`b Das `i$key`i Teil wurde im `i$itemname`i Template nicht gefunden! (".$out.")`n");
        
$out str_replace("{"."$key"."}",$val,$out);
    }
    return 
$out;
}

function 
charstats(){
    global 
$session;
    
$u =& $session[user];
    if (
$session[loggedin]){
        
$u['hitpoints']=round($u['hitpoints'],0);
        
$u['experience']=round($u['experience'],0);
        
$u['maxhitpoints']=round($u['maxhitpoints'],0);
        
$spirits=array("-6"=>"Wiedererweckt","-2"=>"Sehr schlecht","-1"=>"Schlecht","0"=>"Normal","1"=>"Gut","2"=>"Sehr gut");
        if (
$u[alive]){ }else{ $spirits[$u[spirits]] = "TOT"; }
        
reset($session[bufflist]);
        
$atk=$u[attack];
        
$def=$u[defence];
        while (list(
$key,$val)=each($session[bufflist])){
            
$buffs.=appoencode("`#$val[name] `7($val[rounds] Runden übrig)`n",true);
            if (isset(
$val[atkmod])) $atk *= $val[atkmod];
            if (isset(
$val[defmod])) $def *= $val[defmod];
        }
        
$atk round($atk2);
        
$def round($def2);
        
$atk = ($atk == $u[attack] ? "`^" : ($atk $u[attack] ? "`@" "`$")) . "`b$atk`b`0";
        
$def = ($def == $u[defence] ? "`^" : ($def $u[defence] ? "`@" "`$")) . "`b$def`b`0";

        if (
count($session[bufflist])==0){
            
$buffs.=appoencode("`^Keine`0",true);
        }
$wetter="`O$coloredtime".getgametime()." ".$daytide." `n $thisweather ";
 
$stats $u['gold']."`n".$u['gems']."`n".$u['charm'];
        
$charstat=appoencode(templatereplace("statstart")
        .
templatereplace("stathead",array("title"=>"Vital Info"))
        .
templatereplace("statrow",array("title"=>"Name","value"=>appoencode($u[name],false)))
        ,
true);
        if (
$session['user']['alive']){

            
$charstat.=appoencode(
            
templatereplace("statrow",array("title"=>"Lebenspunkte","value"=>"$u[hitpoints]`0/$u[maxhitpoints]".grafbar($u[maxhitpoints],$u[hitpoints])))
            .
templatereplace("statrow",array("title"=>"Runden","value"=>$u['turns']))
            ,
true);
        }else{
            
$charstat.=appoencode(
             
templatereplace("statrow",array("title"=>"Seelenpunkte","value"=>"$u[soulpoints]".grafbar((5*$u[level]+50),$u[soulpoints])))
            .
templatereplace("statrow",array("title"=>"Foltern","value"=>$u['gravefights']))
            ,
true);
        }
        
$charstat.=appoencode(
        
templatereplace("statrow",array("title"=>"Stimmung","value"=>"`b".$spirits[(string)$u['spirits']]."`b"))
        .
templatereplace("statrow",array("title"=>"Level","value"=>"`b".$u['level']."`b"))
        .(
$session['user']['alive']?
             
templatereplace("statrow",array("title"=>"Angriff","value"=>$atk))
            .
templatereplace("statrow",array("title"=>"Verteidigung","value"=>$def))
            :
             
templatereplace("statrow",array("title"=>"Psyche","value"=>10 round(($u['level']-1)*1.5)))
            .
templatereplace("statrow",array("title"=>"Geist","value"=>10 round(($u['level']-1)*1.5)))
            )
        .
templatereplace("statrow",array("title"=>"Edelsteine","value"=>$u['gems']))
        .
templatereplace("stathead",array("title"=>"Weitere Infos"))
        .
templatereplace("statrow",array("title"=>"Gold","value"=>$u['gold']))
        .
templatereplace("statrow",array("title"=>"Erfahrung","value"=>expbar()))
        .
templatereplace("statrow",array("title"=>"Waffe","value"=>$u['weapon']))
        .
templatereplace("statrow",array("title"=>"Rüstung","value"=>$u['armor']))
        ,
true);
        if (
getsetting("dispnextday",0)){
            
$time gametime(); 
            
$tomorrow strtotime(date("Y-m-d H:i:s",$time)." + 1 day"); 
            
$tomorrow strtotime(date("Y-m-d 00:00:00",$tomorrow)); 
            
$secstotomorrow $tomorrow-$time
            
$realsecstotomorrow round($secstotomorrow / (int)getsetting("daysperday",4));
            
$charstat.=appoencode(templatereplace("statrow",array("title"=>"Nächster Tag","value"=>date("G\\h, i\\m, s\\s \\",strtotime("1980-01-01 00:00:00 + $realsecstotomorrow seconds")))),true);
        }
        if (!
is_array($session[bufflist])) $session[bufflist]=array();
        
$charstat.=appoencode(templatereplace("statbuff",array("title"=>"Aktionen","value"=>$buffs)),true);
        
$charstat.=appoencode(templatereplace("statend"),true);
        return 
$charstat;
    }else{
        
//return "Your character info will appear here after you've logged in.";
        //$sql = "SELECT name,alive,location,sex,level,laston,loggedin,lastip,uniqueid FROM accounts WHERE locked=0 AND loggedin=1 ORDER BY level DESC";
        
$sql="SELECT name,alive,location,sex,level,laston,loggedin,lastip,uniqueid FROM accounts WHERE locked=0 AND loggedin=1 AND laston>'".date("Y-m-d H:i:s",strtotime(date("r")."-".getsetting("LOGINTIMEOUT",900)." seconds"))."' ORDER BY level DESC";
        
$result db_query($sql) or die(sql_error($sql));
        
$count db_num_rows($result); 
        
$ret.=appoencode("`b$count Spieler Online:`b`n");
        for (
$i=0;$i<db_num_rows($result);$i++){
            
$row db_fetch_assoc($result);
            
$ret.=appoencode("`^$row[name]`n");
            
$onlinecount++;
        }
        
db_free_result($result);
        if (
$onlinecount==0$ret.=appoencode("`iNiemand`i");
        
$ret.=(getsetting("maxonline",10)>0?grafbar(getsetting("maxonline",10),(getsetting("maxonline",10)-$onlinecount),180):"");
        return 
$ret;
    }
}

$accesskeys=array();
$quickkeys=array();
function 
addnav($text,$link=false,$priv=false,$pop=false,$newwin=false){
    global 
$nav,$session,$accesskeys,$REQUEST_URI,$quickkeys;
    
$text translate($text);
    
/*
    if (date("m-d")=="04-01"){
        $text = borkalize($text);
    }
    */
    
if ($link===false){
        
$nav.=templatereplace("navhead",array("title"=>appoencode($text,$priv)));
    }elseif (
$link === "") {
        
$nav.=templatereplace("navhelp",array("text"=>appoencode($text,$priv)));
    }else{
        if (
$text!=""){
            
$extra="";
            if (
$newwin===false) {
                if (
strpos($link,"?")){
                    
$extra="&c=$session[counter]";
                }else{
                    
$extra="?c=$session[counter]";
                }
            }

            if (
$newwin===false$extra.="-".date("His");
            
//$link = str_replace(" ","%20",$link);
            //hotkey for the link.
            
$key="";
            if (
substr($text,1,1)=="?") {
                
// check to see if a key was specified up front.
                
if ($accesskeys[strtolower(substr($text01))]==1){
                    
// output ("key ".substr($text,0,1)." already taken`n");
                    
$text substr($text,2);
                }else{
                    
$key substr($text,0,1);
                    
$text substr($text,2);
                    
//output("key set to $key`n");
                    
$found=false;
                    for (
$i=0;$i<strlen($text); $i++){
                        
$char substr($text,$i,1);
                        if (
$ignoreuntil == $char){
                            
$ignoreuntil="";
                        }else{
                            if (
$ignoreuntil<>""){
                                if (
$char=="<"$ignoreuntil=">";
                                if (
$char=="&"$ignoreuntil=";";
                                if (
$char=="`"$ignoreuntil=substr($text,$i+1,1);
                            }else{
                                if (
$char==$key) {
                                    
$found=true;
                                    break;
                                }
                            }
                        }
                    }
                    if (
$found==false) {
                        if (
strpos($text"__") !== false)
                            
$text=str_replace("__""(".$key.") "$text);
                        else
                            
$text="(".strtoupper($key).") ".$text;
                        
$i=strpos($text$key);
                        
// output("Not found`n");
                    
}
                }
                
//
            
}
            if (
$key==""){
                for (
$i=0;$i<strlen($text); $i++){
                    
$char substr($text,$i,1);
                    if (
$ignoreuntil == $char) {
                        
$ignoreuntil="";
                    }else{
                        if ((
$accesskeys[strtolower($char)]==1) || (strpos("abcdefghijklmnopqrstuvwxyz0123456789"strtolower($char)) === false) || $ignoreuntil<>"") {
                            if (
$char=="<"$ignoreuntil=">";
                            if (
$char=="&"$ignoreuntil=";";
                            if (
$char=="`"$ignoreuntil=substr($text,$i+1,1);
                        }else{
                            break;
                        }
                    }
                }
            }
            if (
$i<strlen($text)){
                
$key=substr($text,$i,1);
                
$accesskeys[strtolower($key)]=1;
                
$keyrep=" accesskey=\"$key\" ";
            }else{
                
$key="";
                
$keyrep="";
            }
            
//output("Key is $key for $text`n");
            
            
if ($key==""){
                
//$nav.="<a href=\"".HTMLSpecialChars($link.$extra)."\" class='nav'>".appoencode($text,$priv)."<br></a>";
                //$key==""; // This is useless
            
}else{
                
$text=substr($text,0,strpos($text,$key))."`H".$key."`H".substr($text,strpos($text,$key)+1);
                if (
$pop){
                    
$quickkeys[$key]=popup($link.$extra);
                }else{
                    
$quickkeys[$key]="window.location='$link$extra';";
                }
            }
            
$nav.=templatereplace("navitem",array(
                
"text"=>appoencode($text,$priv), 
                
"link"=>HTMLSpecialChars($link.$extra),
                
"accesskey"=>$keyrep,
                
"popup"=>($pop==true "target='_blank' onClick=\"".popup($link.$extra)."; return false;\"" : ($newwin==true?"target='_blank'":""))
                ));
            
//$nav.="<a href=\"".HTMLSpecialChars($link.$extra)."\" $keyrep class='nav'>".appoencode($text,$priv)."<br></a>";
        
}
        
$session[allowednavs][$link.$extra]=true;
        
$session[allowednavs][str_replace(" ""%20"$link).$extra]=true;
        
$session[allowednavs][str_replace(" ""+"$link).$extra]=true;
    }
}

function 
savesetting($settingname,$value){
    global 
$settings;
    
loadsettings();
    if (
$value>""){
        if (!isset(
$settings[$settingname])){
            
$sql "INSERT INTO settings (setting,value) VALUES (\"".addslashes($settingname)."\",\"".addslashes($value)."\")";
        }else{
            
$sql "UPDATE settings SET value=\"".addslashes($value)."\" WHERE setting=\"".addslashes($settingname)."\"";
        }
        
db_query($sql) or die(db_error(LINK));
        
$settings[$settingname]=$value;
        if (
db_affected_rows()>0) return true; else return false;
    }
    return 
false;
}

function 
loadsettings(){
    global 
$settings;
    
//as this seems to be a common complaint, examine the execution path of this function,
    //it will only load the settings once per page hit, in subsequent calls to this function,
    //$settings will be an array, thus this function will do nothing.
    
if (!is_array($settings)){
        
$settings=array();
        
$sql "SELECT * FROM settings";
        
$result db_query($sql) or die(db_error(LINK));
        for (
$i=0;$i<db_num_rows($result);$i++){
            
$row db_fetch_assoc($result);
            
$settings[$row[setting]] = $row[value];
        }
        
db_free_result($result);
        
$ch=0;
        if (
$ch=&& strpos($_SERVER['SCRIPT_NAME'],"login.php")){
            
//@file("http://www.mightye.org/logdserver?".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
        
}
    }
}

function 
getsetting($settingname,$default){
    global 
$settings;
    
loadsettings();
    if (!isset(
$settings[$settingname])){
        
savesetting($settingname,$default);
        return 
$default;
    }else{
        if (
trim($settings[$settingname])==""$settings[$settingname]=$default;
        return 
$settings[$settingname];
    }
}

function 
showform($layout,$row,$nosave=false){
    global 
$output;
    
output("<table>",true);
    while(list(
$key,$val)=each($layout)){
        
$info split(",",$val);
        if (
$info[1]=="title"){
            
output("<tr><td colspan='2' bgcolor='#666666'>",true);
            
output("`b`^$info[0]`0`b");
            
output("</td></tr>",true);
        }else{
            
output("<tr><td nowrap valign='top'>",true);
            
output("$info[0]");
            
output("</td><td>",true);
        }
        switch (
$info[1]){
        case 
"title":
            
            break;
        case 
"enum":
            
reset($info);
            list(
$k,$v)=each($info);
            list(
$k,$v)=each($info);
            
$output.="<select name='$key'>";
            while (list(
$k,$v)=each($info)){
                
$optval $v;
                list(
$k,$v)=each($info);
                
$optdis $v;
                
$output.="<option value='$optval'".($row[$key]==$optval?" selected":"").">".HTMLSpecialChars("$optval : $optdis")."</option>";
            }
            
$output.="</select>";
            break;
        case 
"password":
            
$output.="<input type='password' name='$key' value='".HTMLSpecialChars($row[$key])."'>";
            break;
        case 
"bool":
            
$output.="<select name='$key'>";
            
$output.="<option value='0'".($row[$key]==0?" selected":"").">Nein</option>";
            
$output.="<option value='1'".($row[$key]==1?" selected":"").">Ja</option>";
            
$output.="</select>";
            break;
        case 
"hidden":
            
$output.="<input type='hidden' name='$key' value=\"".HTMLSpecialChars($row[$key])."\">".HTMLSpecialChars($row[$key]);
            break;
        case 
"viewonly":
            
output(dump_item($row[$key]), true);
//            output(str_replace("{","<blockquote>{",str_replace("}","}</blockquote>",HTMLSpecialChars(preg_replace("'(b:[[:digit:]]+;)'","\\1`n",$row[$key])))),true);
            
break;
    case 
"int":
            
$output.="<input name='$key' value=\"".HTMLSpecialChars($row[$key])."\" size='5'>";
            break;
        case 
"textarea":
            
$output.="<textarea name='$key' class='input' cols='40' rows='9'>".HTMLSpecialChars($row[$key])."</textarea>";
            break;
// Changed by Dasher - guilds/clans code
                
case "veryhidden":
                
// We want form fields that have no display at all
                        
$output.="<input type='hidden' name='$key' value=\"".HTMLSpecialChars($row[$key])."\">";
                        break;
                case 
"array":
                
// Allows array's to be passed and edited
                        
if (is_array($row[$key])) {
                            
$SubArray=array();
                            
$SubArray[]=$key.",title";
                            while (list(
$arrayKey$arrayVal)=each($row[$key])) {
                                
$SubArray[$arrayKey]=$arrayKey;
                            }
                            if (isset(
$info[2])) {
                                
$NoSaveDisplay=($info[2]=="save")?false:true;
                            } else {
                                
$NoSaveDisplay=true;
                            }
                            
showform($SubArray,$row[$key],$NoSaveDisplay);
                        }
                        break;
        default:
            
$output.=("<input size='50' name='$key' value=\"".HTMLSpecialChars($row[$key])."\">");
            
//output("`n$val");
        
}
        
output("</td></tr>",true);
    }
    
output("</table>",true);
    if (
$nosave) {} else output("<input type='submit' class='button' value='Speichern'>",true);

}

function 
clearnav(){
    
$session[allowednavs]=array();
}

function 
redirect($location,$reason=false){
    global 
$session,$REQUEST_URI;
    if (
$location!="badnav.php"){
        
$session[allowednavs]=array();
        
addnav("",$location);
    }
    if (
strpos($location,"badnav.php")===false$session[output]="<a href=\"".HTMLSpecialChars($location)."\">Hier klicken</a>";
    
$session['debug'].="Redirected to $location from $REQUEST_URI.  $reason\n";
    
saveuser();
    
header("Location: $location");
    echo 
$location;
    echo 
$session['debug'];
    exit();
}

function 
loadtemplate($templatename){
    if (!
file_exists("templates/$templatename") || $templatename==""$templatename="bloodred.html";
    
$fulltemplate join("",file("templates/$templatename"));
    
$fulltemplate split("<!--!",$fulltemplate);
    while (list(
$key,$val)=each($fulltemplate)){
        
$fieldname=substr($val,0,strpos($val,"-->"));
        if (
$fieldname!=""){
            
$template[$fieldname]=substr($val,strpos($val,"-->")+3);
        }
    }
    return 
$template;
}

function 
maillink(){
    global 
$session;
    
$sql "SELECT sum(if(seen=1,1,0)) AS seencount, sum(if(seen=0,1,0)) AS notseen FROM mail WHERE msgto=\"".$session[user][acctid]."\"";
    
$result db_query($sql) or die(mysql_error(LINK));
    
$row db_fetch_assoc($result);
    
db_free_result($result);
    
$row[seencount]=(int)$row[seencount];
    
$row[notseen]=(int)$row[notseen];
    if (
$row[notseen]>0){
        return 
"<a href='mail.php' target='_blank' onClick=\"".popup("mail.php").";return false;\" class='hotmotd'>Ye Olde Mail: $row[notseen] neu, $row[seencount] alt</a>";
    }else{
        return 
"<a href='mail.php' target='_blank' onClick=\"".popup("mail.php").";return false;\" class='motd'>Ye Olde Mail: $row[notseen] neu, $row[seencount] alt</a>";
    }
}

function 
motdlink(){
    
// missing $session caused unread motd's to never highlight the link
    
global $session;
    if (
$session[needtoviewmotd]){
        return 
"<a href='motd.php' target='_blank' onClick=\"".popup("motd.php").";return false;\" class='hotmotd'><b>MoTD</b></a>";
    }else{
        return 
"<a href='motd.php' target='_blank' onClick=\"".popup("motd.php").";return false;\" class='motd'><b>MoTD</b></a>";
    }
}

function 
page_header($title="Ephyra"){
    global 
$header,$SCRIPT_NAME,$session,$template;
    
$nopopups["login.php"]=1;
    
$nopopups["motd.php"]=1;
    
$nopopups["rpnews.php"]=1;
        
$nopopups["watchsu.php"]=1;
    
$nopopups["index.php"]=1;
    
$nopopups["create.php"]=1;
    
$nopopups["about.php"]=1;
    
$nopopups["mail.php"]=1;
$nopopups["wegweiser.php"]=1;
    
$nopopups["bio.php"]=1;
    
$nopopups["chat.php"]=1;
    
$nopopups["farbenvor.php"]=1;
    
$nopopups["status.php"]=1;
    
    
$header $template['header'];
    
$sql "SELECT motddate FROM motd ORDER BY motditem DESC LIMIT 1";
    
$result db_query($sql);
    
$row db_fetch_assoc($result);
    
db_free_result($result);
    if ((
$row[motddate]>$session[user][lastmotd]) && $nopopups[$SCRIPT_NAME]!=&& $session[user][loggedin]){
        
$header=str_replace("{headscript}","<script language=\"JavaScript\" type=\"text/javascript\">".popup("motd.php")."</script>",$header);
        
$session[needtoviewmotd]=true;
    }else{
        
$header=str_replace("{headscript}","",$header);
        
$session[needtoviewmotd]=false;
    }
    
$header=str_replace("{title}",$title,$header);
        
$session[user][ort] = $title;
}

function 
popup($page){
  return 
"window.open('$page','".preg_replace("([^[:alnum:]])","",$page)."','scrollbars=yes,resizable=yes,width=550,height=300')";
}

function 
page_footer(){
    
$forumlink=getsetting("forum","http://lotgd.net/forum");
    
//$forumlink="http://www.anpera.net/forum/index.php?c=12#";
    
global $output,$nestedtags,$header,$nav,$session,$REMOTE_ADDR,$REQUEST_URI,$pagestarttime,$dbtimethishit,$dbqueriesthishit,$quickkeys,$template,$logd_version;
    
    while (list(
$key,$val)=each($nestedtags)){
        
$output.="</$key>";

        unset(
$nestedtags[$key]);
    }
    
$script.="<script language=\"JavaScript\" type=\"text/javascript\">
    <!--
    document.onkeypress=keyevent;
    function keyevent(e){
        var c;
        var target;
        var altKey;
        var ctrlKey;
        if (window.event != null) {
            c=String.fromCharCode(window.event.keyCode).toUpperCase(); 
            altKey=window.event.altKey;
            ctrlKey=window.event.ctrlKey;
        }else{
            c=String.fromCharCode(e.charCode).toUpperCase();
            altKey=e.altKey;
            ctrlKey=e.ctrlKey;
        }
        if (window.event != null)
            target=window.event.srcElement;
        else
            target=e.originalTarget;
        if (target.nodeName.toUpperCase()=='INPUT' || target.nodeName.toUpperCase()=='TEXTAREA' || altKey || ctrlKey){
        }else{"
;
    
reset($quickkeys);
    while (list(
$key,$val)=each($quickkeys)){
        
$script.="\n            if (c == '".strtoupper($key)."') { $val; return false; }";
    }
    
$script.="
        }
    }
    //-->
    </script>"
;
    
 

// chat preview mod by Chaosmaker Modified for Ellis Colortags by Devilzimti)- start
$appoencode Load_Tags();
$cases" ";
while(list(
$key,$val) = each($appoencode)) {
if(
$val['allowed'] == true) {
    
$cases .= "
    case \""
.$val['code']."\":\n
        if (openspan) output= output+\"</span>\"; else openspan = true;\n
        output= output+\"<span style='color: #"
.$val['color'].";'>\";\n
    break;\n    "
;
}else{
    
$cases .= "\n//".$val['code']." darf hier nicht benutzt werden!\n ";
}
}
$script .= <<<JS
      <script type="text/javascript">
      <!--
         function appoencode(data) {
            var Fundstelle = -1;
            var tag = '';
            var append = '';
            var output = '<br />Vorschau: ';
            var openspan = false;
            while ((Fundstelle = data.search(/`/)) != -1) {
               tag = data.substr(Fundstelle+1, 1);
               append = data.substr(0,Fundstelle);
               append = append.replace(/</,'&lt;');
               append = append.replace(/>/,'&gt;');
               output = output+ append;
               if (data.length >= Fundstelle+2) data = data.substring(Fundstelle+2,data.length);
               else data = '';
               switch (tag) {
                  case "0":
                  if (openspan) output= output+"</span>";
                  openspan = false;
                    break;
                  
{$cases}
                  default:
                  output= output+"`"+tag;
               }
            }
            output += data;
            if (openspan) output += '</span>';
            return output;
         }
      //-->
      </script>
JS;
// chat preview mod by Chaosmaker (Modified for Ellis Colortags by Devilzimti) - end  insercommentary[]
 
$script .= <<<JS
 <script type="text/javascript">

<!--
function insert_code(aTag, eTag,section) {
var ins="insertcommentary[";
var klo="]";
var element= "insertcommentary[village]" ;
var element2=ins+section+klo;
  var input = document.forms['formular'].elements[element2];
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}
//-->
</script>
JS;
    
$footer $template['footer'];
    if (
strpos($footer,"{paypal}") || strpos($header,"{paypal}")){ $palreplace="{paypal}"; }else{ $palreplace="{stats}"; }
    
    
//NOTICE
    //NOTICE Although I will not deny you the ability to remove the below paypal link, I do request, as the author of this software
    //NOTICE that you leave it in.
    //NOTICE
    
$paypalstr '<table align="center"><tr><td>';
    
$paypalstr .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="nahdude81@hotmail.com">
<input type="hidden" name="item_name" value="Legend of the Green Dragon Author Donation from '
.preg_replace("/[`]./","",$session['user']['name']).'">
<input type="hidden" name="item_number" value="'
.HTMLSpecialChars($session['user']['login']).":".$_SERVER['HTTP_HOST']."/".$_SERVER['REQUEST_URI'].'">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="cn" value="Your Character Name">
<input type="hidden" name="cs" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">
<input type="image" src="images/paypal1.gif" border="0" name="submit" alt="Donate!">
</form>'
;
    
$paysite getsetting("paypalemail""");
    if (
$paysite != "") {
        
$paypalstr .= '</td><td>';
        
$paypalstr .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
        <input type="hidden" name="cmd" value="_xclick">
        <input type="hidden" name="business" value="'
.$paysite.'">
<input type="hidden" name="item_name" value="Legend of the Green Dragon Site Donation from '
.preg_replace("/[`]./","",$session['user']['name']).'">
<input type="hidden" name="item_number" value="'
.HTMLSpecialChars($session['user']['login']).":".$_SERVER['HTTP_HOST']."/".$_SERVER['REQUEST_URI'].'">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="cn" value="Your Character Name">
<input type="hidden" name="cs" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">
<input type="image" src="images/paypal2.gif" border="0" name="submit" alt="Donate!">
</form>'
;
    }
$paypalstr .= '</td></tr></table>';
//   $paypalstr .= '</td></tr><tr><td span="2" align="right" valign="top"><a href="http://www.anpera.net" target="_blank"><img src="images/anpnet-klein.gif" alt="Sponsor" border="0"></a></td></tr></table>';
    
$footer=str_replace($palreplace,(strpos($palreplace,"paypal")?"":"{stats}").$paypalstr,$footer);
    
$header=str_replace($palreplace,(strpos($palreplace,"paypal")?"":"{stats}").$paypalstr,$header);
    
//NOTICE
    //NOTICE Although I will not deny you the ability to remove the above paypal link, I do request, as the author of this software
    //NOTICE that you leave it in.
    //NOTICE
    
$header=str_replace("{nav}",$nav,$header);
    
$footer=str_replace("{nav}",$nav,$footer);

    
$header str_replace("{motd}"motdlink(), $header);
    
$footer str_replace("{motd}"motdlink(), $footer);
    
$header str_replace("{forum}""<a href='$forumlink' target='_blank' class='motd'>Forum</a>"$header);
    
$footer str_replace("{forum}""<a href='$forumlink' target='_blank' class='motd'>Forum</a>"$footer);

    if (
$session[user][acctid]>0) {
        
$header=str_replace("{mail}",maillink(),$header);
        
$footer=str_replace("{mail}",maillink(),$footer);
            
$header=str_replace("{useronline}",useronline(),$header);
    
$footer=str_replace("{useronline}",useronline(),$footer);
        
$header=str_replace("{chat}","<a href='chat.php' target='_blank' class='motd' onClick=\"".popup("chat.php").";return false;\">Chat</a>",$header);
        
$footer=str_replace("{chat}","<a href='chat.php' target='_blank' class='motd' onClick=\"".popup("chat.php").";return false;\">Chat</a>",$footer);
    }else{
        
$header=str_replace("{mail}","",$header);
        
$footer=str_replace("{mail}","",$footer);
        
$header=str_replace("{useronline}","",$header);
        
$footer=str_replace("{useronline}","",$footer);
        
$header=str_replace("{chat}","",$header);
        
$footer=str_replace("{chat}","",$footer);
    }
    
$header=str_replace("{petition}","<a href='petition.php' onClick=\"".popup("petition.php").";return false;\" target='_blank' align='right' class='motd'>Hilfe anfordern</a>",$header);
    
$footer=str_replace("{petition}","<a href='petition.php' onClick=\"".popup("petition.php").";return false;\" target='_blank' align='right' class='motd'>Hilfe anfordern</a>",$footer);
    if (
$session['user']['superuser']>1){
        
// $sql = "SELECT count(petitionid) AS c,status FROM petitions GROUP BY status";
        
$sql "SELECT max(lastact) AS lastact, count(petitionid) AS c,status FROM petitions GROUP BY status";
        
$result db_query($sql);
        
$petitions=array(0=>0,1=>0,2=>0);
        
$petitions['unread'] = false;
        for (
$i=0;$i<db_num_rows($result);$i++){
            
$row db_fetch_assoc($result);
            
$petitions[(int)$row['status']] = $row['c'];
            if (
$row['lastact']>$session['lastlogoff']) $petitions['unread'] = true;
        }
        
db_free_result($result);
        
// Neue Petitionen; schauen, ob Sternchen nötig ist
        
$petitions['star'] = '';
        if (
$petitions['unread']) {
            
$sql 'SELECT petitionid, lastact FROM petitions WHERE lastact > "'.$session['lastlogoff'].'"';
            
$result db_query($sql);
            while (
$row db_fetch_assoc($result)) {
                if (!
$session['petitions'][$row['petitionid']]) {
                    
$petitions['star'] = '<span class="colDkRed">*</span>';
                }
        }
        
db_free_result($result);
    }
        
$footer "<table border='0' cellpadding='5' cellspacing='0' align='right'><tr><td><b><a href='viewpetition.php'>Anfragen</a>$petitions[star]:</b> $petitions[0] Ungelesen, $petitions[1] Gelesen, $petitions[2] Geschlossen.</td></tr></table>".$footer;
//        $footer = "<table border='0' cellpadding='5' cellspacing='0' align='right'><tr><td><b>Anfragen:</b> $petitions[0] Ungelesen, $petitions[1] Gelesen, $petitions[2] Geschlossen.</td></tr></table>".$footer;
        
addnav('','viewpetition.php');
    }
    
$footer=str_replace("{stats}",charstats(),$footer);
    
$header=str_replace("{stats}",charstats(),$header);
    
$header=str_replace("{script}",$script,$header);
    if (
$session[user][loggedin]){
        
$footer=str_replace("{source}","<a href='source.php?url=".preg_replace("/[?].*/","",($_SERVER['REQUEST_URI']))."' target='_blank'>Source</a>",$footer);
        
$header=str_replace("{source}","<a href='source.php?url=".preg_replace("/[?].*/","",($_SERVER['REQUEST_URI']))."' target='_blank'>Source</a>",$header);
    }else{
        
$footer=str_replace("{source}","<a href='source.php' target='_blank'>Source</a>",$footer);
        
$header=str_replace("{source}","<a href='source.php' target='_blank'>Source</a>",$header);
    }
    
$footer=str_replace("{copyright}","Copyright 2002-2003, Game: Eric Stevens",$footer);
    
$footer=str_replace("{version}""Version: $logd_version"$footer);
    
$gentime getmicrotime()-$pagestarttime;
    
$session[user][gentime]+=$gentime;
    
$session[user][gentimecount]++;
    
$dbtimethishit=round($dbtimethishit,2); 
    
// $footer=str_replace("{pagegen}","Seitengenerierung: ".round($gentime,2)."s, Schnitt: ".round($session[user][gentime]/$session[user][gentimecount],2)."s - ".round($session[user][gentime],2)."/".round($session[user][gentimecount],2)."".($session[user][superuser]>1?"; DB: $dbqueriesthishit in $dbtimethishit s":"")."",$footer);
    
$footer=str_replace("{pagegen}","Seitengenerierung: ".round($gentime,2)."s, Schnitt: ".round($session[user][gentime]/$session[user][gentimecount],2)."s".($session[user][superuser]>1?"; DB: $dbqueriesthishit in ".$dbtimethishit."s":"")."",$footer);
    if (
strpos($_SERVER['HTTP_HOST'],"lotgd.net")!==false){
        
$footer=str_replace(
            
"</html>",
            
'<script language="JavaScript" type="text/JavaScript" src="http://www.reinvigorate.net/archive/app.bin/jsinclude.php?5193"></script></html>',
            
$footer
            
);
    }

    
$output=$header.$output.$footer;
    
$session['user']['gensize']+=strlen($output);
    
$session[output]=$output;
    
saveuser();

    
session_write_close();
    
//`mpg123 -g 100 -q hit.mp3 2>&1 > /dev/null`;
//    echo compress_out($output);
    
echo $output;
    exit();
}

function 
popup_header($title="Legend of the Green Dragon"){
  global 
$header;
    
$header.="<html><head><title>$title</title>";
    
$header.="<link href=\"newstyle.css\" rel=\"stylesheet\" type=\"text/css\">";
    
$header.="</head><body bgcolor='#000000' text='#CCCCCC'><table cellpadding=5 cellspacing=0 width='100%'>";
    
$header.="<tr><td class='popupheader'><b>$title</b></td></tr>";
    
$header.="<tr><td valign='top' width='100%'>";
}

function 
popup_footer(){
  global 
$output,$nestedtags,$header,$nav,$session;
    while (list(
$key,$val)=each($nestedtags)){
        
$output.="</$key>";
        unset(
$nestedtags[$key]);
    }
    
$output.="</td></tr><tr><td bgcolor='#330000' align='center'>Copyright 2002, Eric Stevens</td></tr></table></body></html>";
    
$output=$header.$output;
    
//$session[output]=$output;
    
    
saveuser();
    echo 
$output;
    exit();
}

function 
clearoutput(){
  global 
$output,$nestedtags,$header,$nav,$session;
    
$session[allowednavs]="";
    
$output="";
  unset(
$nestedtags);
    
$header="";
    
$nav="";
}

function 
soap($input){
    if (
getsetting("soap",1)){
        
$sql "SELECT * FROM nastywords";
        
$result db_query($sql);
        
$row db_fetch_assoc($result);
        
$search $row['words'];
        
$search str_replace("a",'[a4@]',$search);
        
$search str_replace("l",'[l1!]',$search);
        
$search str_replace("i",'[li1!]',$search);
        
$search str_replace("e",'[e3]',$search);
        
$search str_replace("t",'[t7+]',$search);
        
$search str_replace("o",'[o0]',$search);
        
$search str_replace("s",'[sz$]',$search);
        
$search str_replace("k",'c',$search);
        
$search str_replace("c",'[c(k]',$search);
        
$start "'(\s|\A)";
        
$end "(\s|\Z)'iU";
        
$search str_replace("*","([[:alnum:]]*)",$search);
        
$search str_replace(" ","$end $start"$search);
        
$search "$start".$search."$end";
        
//echo $search;
        
$search split(" ",$search);
        
//$input = " $input ";
    
        
return preg_replace($search,"\\1`i$@#%`i\\2",$input);
    }else{
        return 
$input;
    }
}

function 
saveuser(){
    global 
$session,$dbqueriesthishit;
//    $cmd = date("Y-m-d H:i:s")." $dbqueriesthishit ".$_SERVER['REQUEST_URI'];
//    @exec("echo $cmd >> /home/groups/l/lo/lotgd/sessiondata/data/queryusage-".$session['user']['login'].".txt");
    
if ($session[loggedin] && $session[user][acctid]!=""){
      
$session[user][output]=$session[output];
      
$session[user][allowednavs]=serialize($session[allowednavs]);
        
$session[user][bufflist]=serialize($session[bufflist]);
        if (
is_array($session[user][prefs])) $session[user][prefs]=serialize($session[user][prefs]);
        if (
is_array($session[user][dragonpoints])) $session[user][dragonpoints]=serialize($session[user][dragonpoints]);
        
//$session[user][laston] = date("Y-m-d H:i:s");
      
$sql="UPDATE accounts SET ";
      
reset($session[user]);
      while(list(
$key,$val)=each($session[user])){
          if (
is_array($val)){
                
$sql.="$key='".addslashes(serialize($val))."', ";
            }else{
                
$sql.="$key='".addslashes($val)."', ";
            }
      }
      
$sql substr($sql,0,strlen($sql)-2);
      
$sql.=" WHERE acctid = ".$session[user][acctid];
      
db_query($sql);
  }
}

function 
createstring($array){
  if (
is_array($array)){
    
reset($array);
    while (list(
$key,$val)=each($array)){
      
$output.=rawurlencoderawurlencode($key)."\"".rawurlencode($val) )."\"";
    }
    
$output=substr($output,0,strlen($output)-1);
  }
  return 
$output;
}

function 
createarray($string){
  
$arr1 split("\"",$string);
  
$output = array();
  while (list(
$key,$val)=each($arr1)){
    
$arr2=split("\"",rawurldecode($val));
    
$output[rawurldecode($arr2[0])] = rawurldecode($arr2[1]);
  }
  return 
$output;
}

function 
output_array($array,$prefix=""){
  while (list(
$key,$val)=@each($array)){
    
$output.=$prefix."[$key] = ";
    if (
is_array($val)){
      
$output.="array{\n".output_array($val,$prefix."[$key]")."\n}\n";
    }else{
      
$output.=$val."\n";
    }
  }
  return 
$output;
}

function 
dump_item($item){
    
$output "";
    if (
is_array($item)) $temp $item;
    else 
$temp unserialize($item);
    if (
is_array($temp)) {
        
$output .= "array(" count($temp) . ") {<blockquote>";
        while(list(
$key$val) = @each($temp)) {
            
$output .= "'$key' = '" dump_item($val) . "'`n";
        }
        
$output .= "</blockquote>}";
    } else {
        
$output .= $item;
    }
    return 
$output;
}

function 
addnews($news){
    global 
$session;
    
$sql "INSERT INTO news(newstext,newsdate,accountid) VALUES ('".addslashes($news)."',NOW(),".$session[user][acctid].")";
    return 
db_query($sql) or die(db_error($link));
}

function 
checkday() {
    global 
$session,$revertsession,$REQUEST_URI;
  
//output("`#`iChecking to see if you're due for a new day: ".$session[user][laston].", ".date("Y-m-d H:i:s")."`i`n`0");
    
if ($session['user']['loggedin']){
        
output("<!--CheckNewDay()-->",true);
        if(
is_new_day()){
            
$session=$revertsession;
            
$session[user][restorepage]=$REQUEST_URI;
            
$session[allowednavs]=array();
            
addnav("","newday.php");
            
redirect("newday.php");
        }
    }
}

function 
is_new_day(){
    global 
$session;
    
$t1 gametime(); 
    
$t2 convertgametime(strtotime($session[user][lasthit]));
    
$d1 date("Y-m-d",$t1);
    
$d2 date("Y-m-d",$t2);
    if (
$d1!=$d2){
        return 
true;
    }else{
        return 
false;
    }
}

function 
getgametime(){
//    return date("g:i a",gametime());
    
return date(getsetting('gametimeformat','g:i a'),gametime());    
}

// Gamedate-Mod by Chaosmaker
function getgamedate() {
    
$date explode('-',getsetting('gamedate','0005-01-01'));
    
$find = array('%Y','%y','%m','%n','%d','%j');
    
$replace = array($date[0],sprintf('%02d',$date[0]%100),sprintf('%02d',$date[1]),(int)$date[1],sprintf('%02d',$date[2]),(int)$date[2]);
    return 
str_replace($find,$replace,getsetting('gamedateformat','%Y-%m-%d'));
}

function 
gametime(){
    
$time convertgametime(strtotime(date("r")));
    return 
$time;
}

function 
convertgametime($intime){
    
// Hehe, einen hamwa noch, einen hamwa noch: by JT & anpera
    
$multi getsetting("daysperday",4);
    
$offset getsetting("gameoffsetseconds",0);
    
$fixtime mktime(0,0,0-$offset,date("m")-$multi,date("d"),date("Y"));
    
$time=$multi*(strtotime(date("Y-m-d H:i:s",$intime))-$fixtime);
    
$time=strtotime(date("Y-m-d H:i:s",$time)."+".($multi*date("I",$intime))." hour"); 
    
$time=strtotime(date("Y-m-d H:i:s",$time)."-".date("I",$time). " hour"); 
    
$time=strtotime(date("Y-m-d H:i:s",$time)."+".(23-$multi)." hour"); 
    return 
$time;
}
function 
timetotomorrow($what="array"){
    
$time gametime();
    
$tomorrow mktime(0,0,0,date('m',$time),date('d',$time)+1,date('Y',$time));
    
$secstotomorrow $tomorrow-$time;
    
$realsecstotomorrow round($secstotomorrow / (int)getsetting("daysperday",4));
    
$hours=(int)($realsecstotomorrow/60/60);
    
$minutes=(int)($realsecstotomorrow/60)-$hours*60;
    
$seconds=$realsecstotomorrow-($hours*3600+$minutes*60);
    if (
$what=="hours"){
        return(
$hours);
    }elseif (
$what=="minutes"){
        return(
$minutes);
    }elseif (
$what=="seconds"){
        return(
$seconds);
    }elseif (
$what=="realsecs"){
        return(
$realsecstotomorrow);
    }else{
        return(array(
                    
"hours"=>$hours,
                    
"minutes"=>$minutes,
                    
"seconds"=>$seconds,
                    
"realsecs"=>$realsecstotomorrow
                    
));
    }
}
function 
sql_error($sql){
    global 
$session;
    return 
output_array($session)."SQL = <pre>$sql</pre>".db_error(LINK);
}

function 
ordinal($val){
  
$exceptions = array(1=>"ten",2=>"ten",3=>"ten",11=>"ten",12=>"ten",13=>"ten");
    
$x = ($val 100);
    if (isset(
$exceptions[$x])){
      return 
$val.$exceptions[$x];
    }else{
      
$x = ($val 10);
        if (isset(
$exceptions[$x])){
          return 
$val.$exceptions[$x];
        }else{
          return 
$val."ten";
        }
    }
}

function 
addcommentary() {
    global 
$HTTP_POST_VARS,$session,$REQUEST_URI,$HTTP_GET_VARS,$doublepost;
    
$doublepost=0;

    
$section=$HTTP_POST_VARS['section'];
    
$talkline=$HTTP_POST_VARS['talkline'];
    if (
$HTTP_POST_VARS[insertcommentary][$section]!==NULL &&
        
trim($HTTP_POST_VARS[insertcommentary][$section])!="") {
        
$commentary str_replace("`n","",soap($HTTP_POST_VARS[insertcommentary][$section]));
        
$y strlen($commentary);
        for (
$x=0;$x<$y;$x++){
            if (
substr($commentary,$x,1)=="`"){
                
$colorcount++;
                if (
$colorcount>=getsetting("maxcolors",10)){
                    
$commentary substr($commentary,0,$x).preg_replace("'[`].'","",substr($commentary,$x));
                    
$x=$y;
                }
                
$x++;
            }
        }
        if (
substr($commentary,0,1)!=":" &&
            
substr($commentary,0,2)!="::" &&
            
substr($commentary,0,3)!="/me" &&
            
$session['user']['drunkenness']>0) {
            
//drunk people shouldn't talk very straight.
            
$straight $commentary;
            
$replacements=0;
            while (
$replacements/strlen($straight) < ($session['user']['drunkenness'])/500 ){
                
$slurs = array("a"=>"aa","e"=>"ee","f"=>"ff","h"=>"hh","i"=>"ij","l"=>"ll","m"=>"mm","n"=>"nn","o"=>"oo","r"=>"rr","s"=>"sh","u"=>"uu","v"=>"vv","w"=>"ww","y"=>"yy","z"=>"zz");
                if (
e_rand(0,9)) {
                    
srand(e_rand());
                    
$letter array_rand($slurs);
                    
$x strpos(strtolower($commentary),$letter);
                    if (
$x!==false &&
                        
substr($comentary,$x,5)!="*hic*" &&
                        
substr($commentary,max($x-1,0),5)!="*hic*" &&
                        
substr($commentary,max($x-2,0),5)!="*hic*" &&
                        
substr($commentary,max($x-3,0),5)!="*hic*" &&
                        
substr($commentary,max($x-4,0),5)!="*hic*"
                        
){
                        if (
substr($commentary,$x,1)<>strtolower($letter)) $slurs[$letter] = strtoupper($slurs[$letter]); else $slurs[$letter] = strtolower($slurs[$letter]);
                            
$commentary substr($commentary,0,$x).$slurs[$letter].substr($commentary,$x+1);
                        
$replacements++;
                    }
                }else{
                    
$x e_rand(0,strlen($commentary));
                    if (
substr($commentary,$x,5)=="*hic*") {$x+=5; } //output("moved 5 to $x "); 
                    
if (substr($commentary,max($x-1,0),5)=="*hic*") {$x+=4; } //output("moved 4 to $x ");
                    
if (substr($commentary,max($x-2,0),5)=="*hic*") {$x+=3; } //output("moved 3 to $x "); 
                    
if (substr($commentary,max($x-3,0),5)=="*hic*") {$x+=2; } //output("moved 2 to $x ");
                    
if (substr($commentary,max($x-4,0),5)=="*hic*") {$x+=1; } //output("moved 1 to $x "); 
                    
$commentary substr($commentary,0,$x)."*hic*".substr($commentary,$x);
                    
//output($commentary."`n");
                    
$replacements++;
                }
//end if
            
}//end while
            //output("$replacements replacements (".($replacements/strlen($straight)).")`n");
            
while (strpos($commentary,"*hic**hic*"))
                
$commentary str_replace("*hic**hic*","*hic*hic*",$commentary);
        }
//end if


        
if((substr($commentary,0,6)=='/rpcmd')){
                  
//Begin Command Mod by Hadriel v1.6
                  /*           HISTORY:           *\
                  |  v1.0 -> release               |
                  |  v1.1 -> added 'settings'      |
                  |  v1.2 -> bugfixes              |
                  |  v1.3 -> bugfixes              |
if(strpos($row[comment],"/X ")==strlen($talkline)+10)
            {
                $row[comment]=str_replace("&amp;","&",HTMLSpecialChars(substr($row[comment],'8'+strlen($talkline))));
                $row[comment]=substr($row[comment],'0',strlen($row[comment])-8);
            }              |       -> added this history    |
                  |       -> added 'addnews'       |
                  |  v1.5 -> bugfixes              |
                  |  v1.6 -> bugfixes              |
                  |  v1.7 -> added something o__Ô  |
                  \*______________________________*/
                  // Commands seen at silienta-logd.de | Idea by DoM
                  
if($session['user']['superuser']>=3){
                  
$intro explode(' ',$commentary,2);
                  
$parts explode(';',$intro[1]);

                  switch(
$parts[0]){
                    case 
"userb":
                    
/*
                    case 1: /rpcmd userb;[userlogin];fullife
                          -> user [userlogin] gets full life

                    case 2: /rpcmd userb;[userlogin];onehp
                          -> user has only 1 hp left

                    case 3: /rpcmd userb;[userlogin];gold;[pieces]
                          -> user gets [pieces] gold. can be -[pieces].

                    case 4: /rpcmd userb;[userlogin];gems;[pieces]
                          -> user gets [pieces] gems. can be -[pieces].

                    */
                      
if(!empty($parts[1])){
                        switch(
$parts[2]){
                         case 
"fullife":
                          
$frm "hitpoints = maxhitpoints";
                         break;
                         case 
"onehp":
                          
$frm "hitpoints = 1";
                         break;
                         case 
"gold":
                          
$frm "gold = gold + (".$parts[3].")";
                         break;
                         case 
"gems":
                          
$frm "gems = gems + (".$parts[3].")";
                         break;
                        }
                        
mysql_query("UPDATE accounts SET ".$frm." WHERE login = '".$parts[1]."';");
                      }
                      return 
false;
                    break;
                    case 
"addnews":
                     
/*
                     case 1: /rpcmd addnews;[news]
                             -> adds a news '[News]'

                     case 2: /rpcmd addnews;Ich heisse %user% und trage %wep% und %arm%.
                             -> adds a news 'Ich heisse [username] und trage [userweapon] und [userarmor]

                     */
                      
if(!empty($parts[1])){
                        
$parts[1] = str_replace('%user%',$session['user']['name'],$parts[1]);

                        
addnews($parts[1]);
                        return 
false;
                      }else{
                        return 
false;
                      }
                    break;
                    case 
"weather":
                    
/*
                    case 1: /rpcmd weather;Sonnig und Warm
                            -> Change Weather to 'Sonnig und Warm'

                    case 2: /rpcmd weather;Sonnig und Warm;[Loginname_of_a_user]
                            -> Change Weather to 'Sonnig und Warm - Extra für [Name_of_[Loginname_of_a_user]]'
                    */
                     
if(!empty($parts[2])){
                       
$sql "SELECT name FROM accounts WHERE login = '".$parts[2]."';";
                       
$res mysql_query($sql);
                       if(
mysql_num_rows($res)>0){
                         
$row mysql_fetch_assoc($res);
                         
$extra '`0 - Extra für '.$row['name'];
                       }
                     }
                     
output('Weather called '.$parts[1].$extra);
                     
savesetting('weather',$parts[1].$extra);
                     
$commentary '/me ändert das Wetter per göttlicher Macht auf '.$parts[1].$extra;

                    break;
                    case 
"fran"  :
                         
/*
                    case 1: /rpcmd die;[Loginname_of_a_user]
                            -> [Loginname_of_a_user] will be dead (works only at the same place!)

                    */
                    
$currentpage=$session['user']['restorepage'];
                      if (
strstr($currentpage"?comscroll=") !=""){
                    
$position=strrpos($currentpage,"?comscroll=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                                if (
strstr($currentpage"&comscroll=") !=""){
                    
$position=strrpos($currentpage,"&comscroll=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                                if (
strstr($currentpage"&c=") !=""){
                    
$position=strrpos($currentpage,"&c=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                if (
strstr($currentpage"?c=") !=""){
                    
$position=strrpos($currentpage,"?c=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                      
output($currentpage);
                     if(!empty(
$parts[1]) && $parts[1]!=$session['user']['login']){
                      
$sql "SELECT name FROM accounts WHERE login = '".$parts[1]."' AND loggedin=1;";
                       
$res mysql_query($sql);
                       if(
mysql_num_rows($res)>0){
                         
$row mysql_fetch_assoc($res);
                         
$commentary '/me reißt '.$row["name"].'`& seine Seele aus dem Leib und opfert diese `~† Cœ`i`fpr`;iç`4e F`µrancisc`4o  `4O`;mb`fra`i`~ge. '.$row["name"].'`0 stirbt.';
                         
mysql_query("UPDATE accounts SET alive = 0, hitpoints=0 WHERE login = '".$parts[1]."';");
                         
output('Die called '.$parts[1]);
                       }else{
                       return 
false;
                       }
                     }else{
                       
output('Die called '.$parts[1].' - ERROR!');
                       return 
false;
                     }
                    break;
                     case 
"liw"  :
                         
/*
                    case 1: /rpcmd die;[Loginname_of_a_user]
                            -> [Loginname_of_a_user] will be dead (works only at the same place!)

                    */
                    
$currentpage=$session['user']['restorepage'];
                      if (
strstr($currentpage"?comscroll=") !=""){
                    
$position=strrpos($currentpage,"?comscroll=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                                if (
strstr($currentpage"&comscroll=") !=""){
                    
$position=strrpos($currentpage,"&comscroll=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                                if (
strstr($currentpage"&c=") !=""){
                    
$position=strrpos($currentpage,"&c=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                if (
strstr($currentpage"?c=") !=""){
                    
$position=strrpos($currentpage,"?c=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                      
output($currentpage);
                     if(!empty(
$parts[1]) && $parts[1]!=$session['user']['login']){
                      
$sql "SELECT name FROM accounts WHERE login = '".$parts[1]."' AND loggedin=1;";
                       
$res mysql_query($sql);
                       if(
mysql_num_rows($res)>0){
                         
$row mysql_fetch_assoc($res);
                         
$commentary '/me `averteilt `j~ `jC`9o`-l`Xo`ac`va`hs`&ia L`hi`vw`aa`-n`ja`Ss`a speziellen, komprimierten Hustensaft an '.$row["name"].'`a. Leider waren die Hustenbonbons wohl giftig. '.$row["name"].'`0 stirbt.';
                         
mysql_query("UPDATE accounts SET alive = 0, hitpoints=0 WHERE login = '".$parts[1]."';");
                         
output('Die called '.$parts[1]);
                       }else{
                       return 
false;
                       }
                     }else{
                       
output('Die called '.$parts[1].' - ERROR!');
                       return 
false;
                     }
                    break;


                    case 
"rebirth":
                    
/*
                    case 1: /rpcmd rebirth;[Loginname_of_a_user]
                            -> [Loginname_of_a_user] will be alive

                    */
                     
if(!empty($parts[1]) && $parts[1]!=$session['user']['login']){
                       
$sql "SELECT name FROM accounts WHERE login = '".$parts[1]."' ;";
                       
$res mysql_query($sql);
                       if(
mysql_num_rows($res)>0){
                         
$row mysql_fetch_assoc($res);
                         
$commentary '/me schenkt '.$row["name"].'`0 neues Leben.';
                         
mysql_query("UPDATE accounts SET alive = 1, hitpoints = maxhitpoints WHERE login = '".$parts[1]."' ;");
                         
output('Rebirth called '.$parts[1]);
                       }else{
                       return 
false;
                       }
                     }else{
                     
output('Rebirth called '.$parts[1].' - ERROR!');
                     return 
false;
                     }
                    break;

                    case 
"die":
                    
/*
                    case 1: /rpcmd die;[Loginname_of_a_user]
                            -> [Loginname_of_a_user] will be dead (works only at the same place!)

                    */
                    
$currentpage=$session['user']['restorepage'];
                      if (
strstr($currentpage"?comscroll=") !=""){
                    
$position=strrpos($currentpage,"?comscroll=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                                if (
strstr($currentpage"&comscroll=") !=""){
                    
$position=strrpos($currentpage,"&comscroll=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                                if (
strstr($currentpage"&c=") !=""){
                    
$position=strrpos($currentpage,"&c=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                if (
strstr($currentpage"?c=") !=""){
                    
$position=strrpos($currentpage,"?c=");
                    
$currentpage=substr($currentpage,0,$position);
                }
                      
output($currentpage);
                     if(!empty(
$parts[1]) && $parts[1]!=$session['user']['login']){
                      
$sql "SELECT name FROM accounts WHERE login = '".$parts[1]."' AND alive=1 AND loggedin=1;";
                       
$res mysql_query($sql);
                       if(
mysql_num_rows($res)>0){
                         
$row mysql_fetch_assoc($res);
                         
$commentary '/me lässt einen Blitz in '.$row["name"].'`0 hineinfahren. '.$row["name"].'`0 stirbt.';
                         
mysql_query("UPDATE accounts SET alive = 0, hitpoints=0 WHERE login = '".$parts[1]."' AND alive=1;");
                         
output('Die called '.$parts[1]);
                       }else{
                       return 
false;
                       }
                     }else{
                       
output('Die called '.$parts[1].' - ERROR!');
                       return 
false;
                     }
                    break;
                    case 
"setting":
                    
/*
                    case 1: /rpcmd setting;[setting_name];[setting_value]
                            -> Setting [setting_name]'s value will be [setting_value]

                    */

                      
if(!empty($parts[1])){
                        if(!empty(
$parts[2])){
                          
output("Changed setting ".$parts[1]." (original value ".($settings[$parts[1]]?$settings[$parts[1]]:"`iUNSET`i").") to ".$parts[2]."`n");
                          
savesetting($parts[1],$parts[2]);
                        }
                      }
                      return 
false;

                    break;
                    default:
                      return 
false;
                    break;
                  }
                  }else{
                  return 
false;
                  }
                 
//End Command mod by hadriel
                

        
$commentary preg_replace("'([^[:space:]]{45,45})([^[:space:]])'","\\1 \\2",$commentary);
        if (
$session['user']['drunkenness']>50$talkline "lallt";
        
$talkline translate($talkline);
         if (
substr($commentary,0,1)==':' || substr($commentary,0,3)=='/me') {
if (
substr($commentary,0,3)=='/me'$strpos 3;
elseif (
substr($commentary,0,2)=='::'$strpos 2;
else 
$strpos 1;
if (
$session['user']['prefs']['commentemotecolor']) $commentary substr($commentary,0,$strpos).$session['user']['prefs']['commentemotecolor'].substr($commentary,$strpos);
}
else {
if (
$session['user']['prefs']['commenttalkcolor']) $commentary $session['user']['prefs']['commenttalkcolor'].$commentary;
}
            
$commentary ereg_replace("%name;",$session['user']['name'],$commentary);
            
$commentary ereg_replace("%me;",$session['user']['prefs']['commentemotecolor'],$commentary);
            
$commentary ereg_replace("%sagt;",$session['user']['prefs']['commenttalkcolor'],$commentary);
            
$commentary ereg_replace("%sc1;",$session['user']['sc1'],$commentary);
        if (
$talkline!="sagt" // do an emote if the area has a custom talkline and the user isn't trying to emote already.
        
&& substr($commentary,0,1)!=":" 
        
&& substr($commentary,0,2)!="::"
                
&& substr($commentary,0,2)!="/X"
        
&& substr($commentary,0,3)!="/me"
            
$commentary ":`3$talkline: \\\"`#$commentary`3\\\"";
        
$sql "SELECT commentary.comment,commentary.author FROM commentary WHERE section='$section' ORDER BY commentid DESC LIMIT 1";
        
$result db_query($sql) or die(db_error(LINK));
        
$row db_fetch_assoc($result);
        
db_free_result($result);
        if (
$row[comment]!=stripslashes($commentary) || $row[author]!=$session[user][acctid]){
        
// if ($row[comment]!=$commentary || $row[author]!=$session[user][acctid]){
          
$sql "INSERT INTO commentary (postdate,section,author,comment) VALUES (now(),'$section',".$session[user][acctid].",\"$commentary\")";
            
db_query($sql) or die(db_error(LINK));
//RP-Sys


if ($section!=OFFTOPIC){
 if (
$session['user']['beta1'] == 1  && count(explode(' ',$commentary)) >=30) {
    
$postdp floor((strlen($row['comment']))/25);
    
$session['user']['donation']+=$postdp;

}

 if (
$session['user']['beta1'] >= 0  && count(explode(' ',$commentary)) >=30) {

       
$postgold floor(strlen($row['comment']));
    
$session['user']['gold']+=$postgold;


}


}
//Rp-Sys Ende
            
return true;
        } else {
            
$doublepost 1;
        }
        }
    return 
false;
}

function 
viewcommentary($section,$message="Kommentar hinzufügen?",$limit=10,$talkline="sagt") {
    global 
$HTTP_POST_VARS,$session,$REQUEST_URI,$HTTP_GET_VARS$doublepost,$appoencode_str;
    
$nobios = array("motd.php"=>true);
    if (
$nobios[basename($_SERVER['SCRIPT_NAME'])]) $linkbios=false; else $linkbios=true;
    
//output("`b".basename($_SERVER['SCRIPT_NAME'])."`b`n");
    
if ($doublepostoutput("`\$`bDoppelpost?`b`0`n");
    
$message translate($message);

    
$com=(int)$HTTP_GET_VARS[comscroll];
  
$sql "SELECT commentary.*, 
                   accounts.name,
                   accounts.login,
                   accounts.prefs,
        accounts.loggedin,
        accounts.location,
        accounts.laston
              FROM commentary
             INNER JOIN accounts
                ON accounts.acctid = commentary.author
             WHERE section = '$section'
               AND accounts.locked=0 
             ORDER BY commentid DESC
             LIMIT "
.($com*$limit).",$limit";

    
$result db_query($sql) or die(db_error(LINK));
    
$counttoday=0;
    for (
$i=0;$i db_num_rows($result);$i++){
      
$row db_fetch_assoc($result);
        
$row[comment]=preg_replace("'[`][^".$appoencode_str."`]'","",$row[comment]);
        
$commentids[$i] = $row[commentid];
/* limit posts
        if (date("Y-m-d",strtotime($row[postdate]))==date("Y-m-d")){
//            if ($row[name]==$session[user][name] && substr($section,0,5)!="house") $counttoday++;
        }
*/
        
$timest="";
            if (
$session['user']['prefs']['timestamps']) $timest="`0[".date("H:i",strtotime($row['postdate']))."] ";


// /X-Posts an allen Orten       hack by Linus in 2007
        
if($talkline!="sagt")
        {
            if(
strpos($row[comment],"/X ")==strlen($talkline)+10)
            {
                
$row[comment]=str_replace("&amp;","&",HTMLSpecialChars(substr($row[comment],'8'+strlen($talkline))));
                
$row[comment]=substr($row[comment],'0',strlen($row[comment])-8);
            }
        }

        
$x=0;
        
$ft="";
        
$timest="";
if (
$session['user']['prefs']['timestamps']) $timest="`0[".date("H:i",strtotime($row['postdate']))."] ";
        for (
$x=0;strlen($ft)<&& $x<strlen($row[comment]);$x++){
            if (
substr($row[comment],$x,1)=="`" && strlen($ft)==0) {
                
$x++;
            }else{
                
$ft.=substr($row[comment],$x,1);
            }
        }
        
$link "bio.php?char=".rawurlencode($row[login]);
        if (
substr($ft,0,2)=="::"$ft substr($ft,0,2);
        else

if (
substr($ft,0,2)=="/X"$ft substr($ft,0,2);
   else
            if (
substr($ft,0,1)==":"$ft substr($ft,0,1);
        
/*
        Landschafts-Emote by Eliwood
        */
                
if ($ft=="/X")
                    {
                        
$x strpos($row[comment],$ft);
                        if (
$x!==false)
                            {
                                if (
$linkbios)
                                    
$op[$i] =$timest.str_replace("&amp;","&",HTMLSpecialChars(substr($row['comment'],0,$x)))
                                    .
"`0\n`& "
                                    
.str_replace("&amp;","&",HTMLSpecialChars(substr($row[comment],$x+strlen($ft))))
                                        .
"`0`n";
                                else
                                    
$op[$i] =$timest.str_replace("&amp;","&",HTMLSpecialChars(substr($row['comment'],0,$x)))
                                    .
"`0\n`& "
                                    
.str_replace("&amp;","&",HTMLSpecialChars(substr($row[comment],$x+strlen($ft))))
                                        .
"`0`n";
                            }
                    }
        
/*Landschaft-Emote Ende*/


        
if ($ft=="::" || $ft=="/me" || $ft==":"){
            
$x strpos($row[comment],$ft);
            if (
$x!==false){
                if (
$linkbios)
                    
$op[$i] = str_replace("&amp;","&",HTMLSpecialChars(substr($row[comment],0,$x)))
                    .
"`0<a href='$link'  target='window_popup' onClick=\"".popup($link)."; return false;\">\n`&$row[name]`0</a>\n`& "
                    
.str_replace("&amp;","&",HTMLSpecialChars(substr($row[comment],$x+strlen($ft))))
                        .
"`0`n";
                else
                    
$op[$i] = str_replace("&amp;","&",HTMLSpecialChars(substr($row[comment],0,$x)))
                    .
"`0\n`&$row[name]`0\n`& "
                    
.str_replace("&amp;","&",HTMLSpecialChars(substr($row[comment],$x+strlen($ft))))
                        .
"`0`n";
            }
        }
        if (
$op[$i]==""
            if (
$linkbios)
                
$op[$i] = "`0<a href='$link'  target='window_popup' onClick=\"".popup($link)."; return false;\">\n`&$row[name]`0</a>\n`&`3 sagt: \"`#"
                    
.str_replace("&amp;","&",HTMLSpecialChars($row[comment]))."`3\"`0`n";
            else
                
$op[$i] = "`0`&$row[name]`0`3 sagt: \"`#"
                    
.str_replace("&amp;","&",HTMLSpecialChars($row[comment]))."`3\"`0`n";
        if (
$message=="X"$op[$i]="`0($row[section]) ".$op[$i];
        
$loggedin=(date("U") - strtotime($row[laston]) < getsetting("LOGINTIMEOUT",900) && $row[loggedin] && $row[location]==0);
        if (
$row['postdate']>=$session['user']['recentcomments']) $op[$i]=($loggedin?"<img src='images/new-online.gif' alt='&gt;' width='3' height='5' align='absmiddle'> ":"<img src='images/new.gif' alt='&gt;' width='3' height='5' align='absmiddle'> ").$op[$i];
        
addnav("",$link);
    }
    
$i--;
    
$outputcomments=array();
    
$sect="x";
    for (;
$i>=0;$i--){
        
$out="";
    if (
$session['user']['superuser']>=|| ($session['user']['superuser']>=&& $message=="X")){
                if (
$session['user']['prefs']['xmote'])     $out.="`0[ <a href='superuser.php?op=commentdelete&commentid=$commentids[$i]&return=".URLEncode($_SERVER['REQUEST_URI'])."'>Löschen</a>  ]".$authors[$i].":&nbsp;";
                else            
$out.="`0[ <a href='superuser.php?op=commentdelete&commentid=$commentids[$i]&return=".URLEncode($_SERVER['REQUEST_URI'])."'>Löschen</a> ]&nbsp;";
            
addnav("","superuser.php?op=commentdelete&commentid=$commentids[$i]&return=".URLEncode($_SERVER['REQUEST_URI']));
                if(
$message=="X")
                {
            
$matches=array();
            
preg_match("/[(][^)]*[)]/",$op[$i],$matches);
            
$sect=$matches[0];
        }
            }
        
//output($op[$i],true);
        
$out.=$op[$i];
        if (!
is_array($outputcomments[$sect])) $outputcomments[$sect]=array();
        
array_push($outputcomments[$sect],$out);
    }
    
ksort($outputcomments);
    
reset($outputcomments);
    while (list(
$sec,$v)=each($outputcomments)){
        if (
$sec!="x"output("`n`b$sec`b`n");
        
output(implode('',$v),true);
    }

    if (
$session[user][loggedin]) {
        
//if ($counttoday<($limit/2) || $session['user']['superuser']>=2){
            
if ($message!="X"){
                if (
$talkline!="sagt"$tll strlen($talkline)+11; else $tll=0;
                                 
// chat preview mod by Chaosmaker  
            
            
output("<form name=\"formular\" action=\"$REQUEST_URI\" method='POST'>`@$message`n<textarea cols='50' rows='4' class='input' name='insertcommentary[$section]' size='40' maxlength='".(5000-$tll)."' onkeyup=\"document.getElementById('chatpreview').innerHTML = appoencode(this.value);\"></textarea><input type='hidden' name='talkline' value='$talkline'><input type='hidden' name='section' value='$section'><input type='submit' class='button' value='Hinzufügen'><span id='chatpreview'></span>`n".(round($limit/2,0)-$counttoday<3?"`)(Du hast noch ".(round($limit/2,0)-$counttoday)." Beiträge für heute übrig)":"")."`0`n",true);
                
addnav("",$REQUEST_URI);
            }

//        }else{
//            output("`@$message`nSorry, du hast deine Beiträge in dieser Region für heute aufgebraucht.`0`n");
//        }
    
}
    if (
db_num_rows($result)>=$limit){
        
$req preg_replace("'[&]?c(omscroll)?=([[:digit:]-])*'","",$REQUEST_URI)."&comscroll=".($com+1);
            
//$req = substr($REQUEST_URI,0,strpos($REQUEST_URI,"c="))."&c=$HTTP_GET_VARS[c]"."&comscroll=".($com+1);
            
$req str_replace("?&","?",$req);
            if (!
strpos($req,"?")) $req str_replace("&","?",$req);
            
output("<a href=\"$req\">&lt;&lt; Vorherige</a>",true);
            
addnav("",$req);
        }
    
$req preg_replace("'[&]?c(omscroll)?=([[:digit:]]|-)*'","",$REQUEST_URI)."&comscroll=0";
        
//$req = substr($REQUEST_URI,0,strpos($REQUEST_URI,"c="))."&c=$HTTP_GET_VARS[c]"."&comscroll=".($com-1);
        
$req str_replace("?&","?",$req);
        if (!
strpos($req,"?")) $req str_replace("&","?",$req);
        
output("&nbsp;<a href=\"$req\">Aktualisieren</a>&nbsp;",true);
        
addnav("",$req);
        
addnav("+?Aktualisieren",$req);
        if (
$com>0){
        
$req preg_replace("'[&]?c(omscroll)?=([[:digit:]]|-)*'","",$REQUEST_URI)."&comscroll=".($com-1);
            
//$req = substr($REQUEST_URI,0,strpos($REQUEST_URI,"c="))."&c=$HTTP_GET_VARS[c]"."&comscroll=".($com-1);
            
$req str_replace("?&","?",$req);
            if (!
strpos($req,"?")) $req str_replace("&","?",$req);
            
output(" <a href=\"$req\">Nächste &gt;&gt;</a>",true);
            
addnav("",$req);
        }
        
//Delete/Edit Funktion Anfang

output('<br><br> <a href="chatdelete.php?op=delete&section='.$section.'&restore='.$REQUEST_URI.'" onClick="return confirm(\'Willst du diesen Eintrag wirklich löschen?\');">`$&lt;&lt;Löschen&gt;&gt;`0</a>',true);
addnav("","chatdelete.php?op=delete&section=".$section."&restore=$REQUEST_URI");
output("<a href=\"chatdelete.php?op=edit&section=".$section."&restore=$REQUEST_URI\">`\$&lt;&lt;Editieren&gt;&gt;`0</a>",true);
addnav("","chatdelete.php?op=edit&section=".$section."&restore=$REQUEST_URI");

//Delete/Edit Funktion Ende
    
db_free_result($result);
    
output("`n`n`n`n`7Farbcodes:`n`n`0`0`0");

rawoutput("<table boder=0 cellspacing=20><td width=100%>");
$result db_query("SELECT allowed, code FROM appoencode WHERE allowed='1'");
while (
$row db_fetch_assoc($result)){

output("`0<a  target='formular'; onClick=\"insert_code('``$row[code]', '', '$section')\"; return false; \">`$row[code]$row[code], `0</a>",true);
}
output("</table><input type=\"button\" value=\"Einfügen\" onClick=\"insert_code('".$session[user][sc1]."', '', '$section')\";>",true);
output(" </form>",true);
}

function 
dhms($secs,$dec=false){
    if (
$dec===false$secs=round($secs,0);
    return (int)(
$secs/86400)."d".(int)($secs/3600%24)."h".(int)($secs/60%60)."m".($secs%60).($dec?substr($secs-(int)$secs,1):"")."s";
}

function 
getmount($horse=0) {
    
$sql "SELECT * FROM mounts WHERE mountid='$horse'";
    
$result db_query($sql);
    if (
db_num_rows($result)>0){
        return 
db_fetch_assoc($result);
    }else{
        return array();
    }
}

function 
debuglog($message,$target=0){
    global 
$session;
    
$sql "DELETE from debuglog WHERE date <'".date("Y-m-d H:i:s",strtotime(date("r")."-".(getsetting("expirecontent",180)/10)." days"))."'";
    
db_query($sql);
    
$sql "INSERT INTO debuglog VALUES(0,now(),{$session['user']['acctid']},$target,'".addslashes($message)."')";
    
db_query($sql);
}
// exp bar mod coded by: dvd871 with modifications by: anpera

function expbar() {
    global 
$session;
    
$exparray=array(1=>100,400,1002,1912,3140,4707,6641,8985,11795,15143,19121,23840,29437,36071,43930,55000);
    while (list(
$key,$val)=each($exparray)){
        
$exparray[$key]= round($val + ($session['user']['dragonkills']/4) * $key 100,0);
    }
    
$exp $session[user][experience]-$exparray[$session[user][level]-1];
    
$req=$exparray[$session[user][level]]-$exparray[$session[user][level]-1];
    
$u="<font face=\"verdana\" size=1>".$session[user][experience]."<br>".grafbar($req,$exp)."</font>";
    return(
$u);
}

// end exp bar mod

function grafbar($full,$left,$width=70,$height=5) {
    
$col2="#000000";
    if (
$left<=0){
        
$col="#000000";
    }else if (
$left<$full/4){
        
$col="#FF0000";
    }else if (
$left<$full/2){
        
$col="yellow";
    }else if (
$left>=$full){
        
$col="#00AA00";
        
$col2="#00AA00";
    }else{
        
$col="#00FF00";
    }
    if (
$full==0$full=1;
    
$u "<table cellspacing=\"0\" style=\"border: solid 1px #000000\" width=\"$width\" height=\"$height\"><tr><td width=\"" . ($left $full 100) . "%\" bgcolor=\"$col\"></td><td width=\"".(100-($left $full 100)) ."%\" bgcolor=\"$col2\"></td></tr></table>";
    return(
$u);
}


if (
file_exists("dbconnect.php")){
    require_once 
"dbconnect.php";
}else{
    echo 
"Du must die benötigten Informationen in die Datei \"dbconnect.php.dist\" eintragen und sie unter dem Namen \"dbconnect.php\" speichern.".
    exit();
}

$link db_pconnect($DB_HOST$DB_USER$DB_PASS) or die (db_error($link));
db_select_db ($DB_NAME) or die (db_error($link));
define("LINK",$link);
$appoencode Load_Tags();
$appoencode_str Get_Allowed_Tags();
require_once 
"translator.php";


session_register("session");
function 
register_global(&$var){
    @
reset($var);
    while (list(
$key,$val)=@each($var)){
        global $
$key;
        $
$key $val;
    }
    @
reset($var);
}
$session =& $_SESSION['session'];
//echo nl2br(HTMLSpecialChars(output_array($session)));
//register_global($_SESSION);
register_global($_SERVER);

if (
strtotime(date("r")."-".getsetting("LOGINTIMEOUT",900)." seconds") > $session['lasthit'] && $session['lasthit']>&& $session[loggedin]){
    
//force the abandoning of the session when the user should have been sent to the fields.
    //echo "Session abandon:".(strtotime("now")-$session[lasthit]);
    
    
$session=array();
    
$session['message'].="`nDeine Session ist abgelaufen!`n";
}
$session[lasthit]=strtotime(date("r"));

$revertsession=$session;

if (
$PATH_INFO != "") {
    
$SCRIPT_NAME=$PATH_INFO;
    
$REQUEST_URI="";
}
if (
$REQUEST_URI==""){
    
//necessary for some IIS installations (CGI in particular)
    
if (is_array($_GET) && count($_GET)>0){
        
$REQUEST_URI=$SCRIPT_NAME."?";
        
reset($_GET);
        
$i=0;
        while (list(
$key,$val)=each($_GET)){
            if (
$i>0$REQUEST_URI.="&";
            
$REQUEST_URI.="$key=".URLEncode($val);
            
$i++;
        }
    }else{
        
$REQUEST_URI=$SCRIPT_NAME;
    }
    
$_SERVER['REQUEST_URI'] = $REQUEST_URI;
}
$SCRIPT_NAME=substr($SCRIPT_NAME,strrpos($SCRIPT_NAME,"/")+1);
if (
strpos($REQUEST_URI,"?")){
    
$REQUEST_URI=$SCRIPT_NAME.substr($REQUEST_URI,strpos($REQUEST_URI,"?"));
}else{
    
$REQUEST_URI=$SCRIPT_NAME;
}

$allowanonymous=array("index.php"=>true,"login.php"=>true,"create.php"=>true,"about.php"=>true,"list.php"=>true,"petition.php"=>true,"connector.php"=>true,"logdnet.php"=>true,"referral.php"=>true,"news.php"=>true,"motd.php"=>true,"topwebvote.php"=>true,"source.php"=>true);
$allownonnav = array("badnav.php"=>true,"motd.php"=>true,"petition.php"=>true,"bio.php"=>true,"mail.php"=>true,"topwebvote.php"=>true,"chat.php"=>true,"source.php"=>true);
if (
$session[loggedin]){
    
$sql "SELECT * FROM accounts WHERE acctid = '".$session[user][acctid]."'";
    
$result db_query($sql);
    if (
db_num_rows($result)==1){
        
$session[user]=db_fetch_assoc($result);
        
$session[output]=$session[user][output];
        
$session[user][dragonpoints]=unserialize($session[user][dragonpoints]);
        
$session[user][prefs]=unserialize($session[user][prefs]);
        if (!
is_array($session[user][dragonpoints])) $session[user][dragonpoints]=array();
        if (
is_array(unserialize($session[user][allowednavs]))){
            
$session[allowednavs]=unserialize($session[user][allowednavs]);
        }else{
            
//depreciated, left only for legacy support.
            
$session[allowednavs]=createarray($session[user][allowednavs]);
        }
        if (!
$session[user][loggedin] || (&& (date("U") - strtotime($session[user][laston])) > getsetting("LOGINTIMEOUT",900)) ){
            
$session=array();
            
redirect("index.php?op=timeout","Account ist nicht eingeloggt, aber die Session denkt, er ist es.");
        }
    }else{
        
$session=array();
        
$session[message]="`4Fehler! Dein Login war falsch.`0";
        
redirect("index.php","Account verschwunden!");
    }
    
db_free_result($result);
    if (
$session[allowednavs][$REQUEST_URI] && !$allownonnav[$SCRIPT_NAME]){
        
$session[allowednavs]=array();
    }else{
        if (!
$allownonnav[$SCRIPT_NAME]){
            
redirect("badnav.php","Navigation auf $REQUEST_URI nicht erlaubt");
        }
    }
}else{
    
//if ($SCRIPT_NAME!="index.php" && $SCRIPT_NAME!="login.php" && $SCRIPT_NAME!="create.php" && $SCRIPT_NAME!="about.php"){
    
if (!$allowanonymous[$SCRIPT_NAME]){
        
$session['message']="Du bist nicht eingeloggt. Wahrscheinlich ist deine Sessionzeit abgelaufen.";
        
redirect("index.php?op=timeout","Not logged in: $REQUEST_URI");
    }
}
//if ($session[user][loggedin]!=true && $SCRIPT_NAME!="index.php" && $SCRIPT_NAME!="login.php" && $SCRIPT_NAME!="create.php" && $SCRIPT_NAME!="about.php"){
if ($session[user][loggedin]!=true && !$allowanonymous[$SCRIPT_NAME]){
    
redirect("login.php?op=logout");
}

$session[counter]++;
$nokeeprestore=array("newday.php"=>1,"badnav.php"=>1,"motd.php"=>1,"mail.php"=>1,"bio.php"=>1,"petition.php"=>1,"chat.php"=>1);
if (!
$nokeeprestore[$SCRIPT_NAME]) { //strpos($REQUEST_URI,"newday.php")===false && strpos($REQUEST_URI,"badnav.php")===false && strpos($REQUEST_URI,"motd.php")===false && strpos($REQUEST_URI,"mail.php")===false
  
$session[user][restorepage]=$REQUEST_URI;
}else{

}

if (
$session['user']['hitpoints']>0){
    
$session['user']['alive']=true;
}else{
    
$session['user']['alive']=false;
}

$session[bufflist]=unserialize($session[user][bufflist]);
if (!
is_array($session[bufflist])) $session[bufflist]=array();
$session[user][lastip]=$REMOTE_ADDR;
if (
strlen($_COOKIE[lgi])<32){
    if (
strlen($session[user][uniqueid])<32){
        
$u=md5(microtime());
        
setcookie("lgi",$u,strtotime(date("r")."+365 days"));
        
$_COOKIE['lgi']=$u;
        
$session[user][uniqueid]=$u;
    }else{
        
setcookie("lgi",$session[user][uniqueid],strtotime(date("r")."+365 days"));
    }
}else{
    
$session[user][uniqueid]=$_COOKIE[lgi];
}
$url "http://".$_SERVER['SERVER_NAME'].dirname($_SERVER['REQUEST_URI']);
$url substr($url,0,strlen($url)-1);

if (
substr($_SERVER['HTTP_REFERER'],0,strlen($url))==$url || $_SERVER['HTTP_REFERER']==""){

}else{
    
$sql "SELECT * FROM referers WHERE uri='{$_SERVER['HTTP_REFERER']}'";
    
$result db_query($sql);
    
$row db_fetch_assoc($result);
    
db_free_result($result);
    
$site str_replace("http://","",$_SERVER['HTTP_REFERER']);
    if (
strpos($site,"/")) 
        
$site substr($site,0,strpos($site,"/"));
    if (
$row['refererid']>""){
        
$sql "UPDATE referers SET count=count+1,last=now(),site='".addslashes($site)."' WHERE refererid='{$row['refererid']}'";
    }else{
        
$sql "INSERT INTO referers (uri,count,last,site) VALUES ('{$_SERVER['HTTP_REFERER']}',1,now(),'".addslashes($site)."')";
    }
    
db_query($sql);
}
if (
$_COOKIE['template']!=""$templatename=$_COOKIE['template'];
if (
$templatename=="" || !file_exists("templates/$templatename")) $templatename="bloodred.html";
$template loadtemplate($templatename);
//tags that must appear in the header
$templatetags=array("title","headscript","script");
foreach (
$templatetags AS $val) {
    if (
strpos($template['header'],"{".$val."}")===false$templatemessage.="You do not have {".$val."} defined in your header\n";
}
//tags that must appear in the footer
$templatetags=array();
foreach (
$templatetags AS $val) {
    if (
strpos($template['footer'],"{".$val."}")===false$templatemessage.="You do not have {".$val."} defined in your footer\n";
}
//tags that may appear anywhere but must appear
//touch the copyright and we will force your server to be shut down
$templatetags=array("nav","stats","petition","motd","mail","paypal","copyright","source");
foreach (
$templatetags AS $val) {
    if (
strpos($template['header'],"{".$val."}")===false && strpos($template['footer'],"{".$val."}")===false$templatemessage.="You do not have {".$val."} defined in either your header or footer\n";
}

if (
$templatemessage!=""){
    echo 
"<b>Du hast einen oder mehrere Fehler in deinem Template!</b><br>".nl2br($templatemessage);
    
$template=loadtemplate("bloodred.html");
}

$races=array(1=>"Troll",2=>"Elf",3=>"Mensch",4=>"Zwerg",5=>"Echse",0=>"Unbekannt",50=>"Hoverschaf");
$colraces=array(1=>"`2Troll`0",2=>"`^Elf`0",3=>"`0Mensch",4=>"`#Zwerg`0",5=>"`5Echse`0",0=>"`)Unbekannt`0",50=>"Hoverschaf");

$logd_version "0.9.7+jt ext (GER)";
$session['user']['laston']=date("Y-m-d H:i:s");

$playermount getmount($session['user']['hashorse']);

$titles = array(
    
0=>array("Bauernjunge","Bauernmädchen"),
    
1=>array("Knecht""Magd"),
    
2=>array("Bauer""Bäuerin"),
    
3=>array("Grossbauer""Grossbäuerin"),
    
4=>array("Spurenleser","Spurenleserin"),
        
5=>array("Jäger","Jägerin"),
    
6=>array("Gutshofverwalter","Gutshofverwalterin"),
    
7=>array("Gutsherr","Gutsherrin"),
    
8=>array("Bürger","Bürgerin"),
    
9=>array("Gladiator","Gladiatorin"),
    
10=>array("Legionär","Legionärin"),
    
11=>array("Centurio","Centurioness"),
    
12=>array("Meister","Meisterin"),
    
13=>array("Ratsherr""Ratsfrau"),
    
14=>array("Verwalter","Verwalterin"),
    
15=>array("Bürgermeister""Bürgermeisterin"),
    
16=>array("Major""Major"),
    
17=>array("General""General"),
    
18=>array("Edler""Edle"),
    
19=>array("Ritter""Ritterin"),
    
20=>array("Junker""Junkerin"),
    
21=>array("Freiherr""Freifrau"),
    
22=>array("Baron""Baronin"),
    
23=>array("Fürst""Fürstin"),
    
24=>array("Grossfürst""Grossfürstin"),
    
25=>array("Herzog""Herzogin"),
    
26=>array("Graf""Gräfin"),
    
27=>array("Prinz""Prinzessin"),
    
28=>array("Kronprinz""Kronprinzessin"),
    
29=>array("König""Königin"),
    
30=>array("Kaiser""Kaiserin"),
    
31=>array("Drachentöter","Drachentöterin"),
    
32=>array("Bischof","Bischöfin"),
    
33=>array("Papst""Päpstin"),
    
34=>array("Seele""Seele"),
    
35=>array("Seliger""Selige"),
    
36=>array("Heiliger""Heilige"),
    
37=>array("Engel""Engel"),
    
38=>array("Erzengel""Erzengel"),
    
39=>array("Kraft""Kraft"),
    
40=>array("Macht""Macht"),
    
41=>array("Herrschaft""Herrschaft"),
    
42=>array("Thron""Thron"),
    
43=>array("Seraphim""Seraphim"),
    
44=>array("Cherubim""Cherubim"),
    
45=>array("Titan","Titanin"),
    
46=>array("Erztitan","Erztitanin"),
    
47=>array("Halbgott""Halbgöttin"),
    
48=>array("Untergott","Untergöttin")
);

$beta = (getsetting("beta",0) == || $session['user']['beta']==1);
?>