<?php
/*
* This file is part of 'Crown of Evanion'.
*
* 'Crown of Evanion' is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 'Crown of Evanion' is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 'Crown of Evanion'; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
ob_start(); //Start output buffer, just in case I need it.
# CyberPetsHQ Include file, written by Nicholas Evans In fact, nearly every line of code has been written by Nicolas Evans.
# TheRedA contributed a few lines of code to this file, and the egg/dragon image.
# Now, hows about we get started? First off, we might like to establish a connection to the database.
# Those things are damn right handy.
$connect = @mysql_connect("localhost", "owlmanat_penisbi", "x15yabvxj23980") or die("Error: Could Not Establish Connection To Database");
@mysql_select_db("owlmanat_cyberpets",$connect) or die("Error: Could Not Find Database!");
# We will now establish some times/dates.
$timeofu = (date("U")); //epotch
$date = (date("l, F dS, Y")); //Day, Month, Date, year
$time = (date("h:i:s A")); //Time
/* Functions */
# Cut string function
function cutstring($strVal,$limit){
if(strlen($strVal)>$limit){
return substr($strVal,0,$limit) . "...";
}else{
return $strVal;
}
}
# The emoicon/codes function
/* To use it, you need to set two variables in it - $string and $html.
$string is what you want to pass through the filter, while $html should be set to 0 or 1.
1 would disable HTML, 0 would enable it. For example
$someforummessage = filter($database[message], 1);
would remove all HTML from the post. However,
$someforummessage = filter($database[message], 0);
would let HTML through.
*/
function filter($string, $html) {
$select = mysql_query("SELECT * FROM code");
if($html) {
$string = strip_tags($string);
}
while ($codes = mysql_fetch_array($select)) {
$string = str_replace("$codes[user]","$codes[new]",$string);
}
$string = str_replace("\n","<br />",$string);
return $string;
}
function forumkill($text) {
echo $text;
include("footer.php");
die;
}
function logincheck($user) {
if(!$user) {
header("location: login.php");
die;
}
}
# IP Ban
$select = mysql_query("SELECT ip FROM ban");
while ($banish = mysql_fetch_array($select)) {
if ($banish[ip] == $REMOTE_ADDR) {
die("You have been banned. Go fuck a cactus, shitface!");
}
}
# Not so hard, eh? Well, it gets better. Lets check and see if the user is logged in.
if($HTTP_COOKIE_VARS[CPH_Usr] != "" || $HTTP_COOKIE_VARS[CPH_Psw] != ""){ //Logged in
$select = mysql_query("SELECT * FROM users WHERE username = '$HTTP_COOKIE_VARS[CPH_Usr]'") or die("Error");
$user_data = mysql_fetch_array($select);
# These are some nice variables holding user data, which will be quite handy.
$Username = $user_data[username];
$Password = $user_data[password];
$Money = $user_data[money];
$Status = $user_data[status];
$Banned = $user_data[ban];
$Stren = $user_data[strength];
$Tough = $user_data[tough];
$Intel = $user_data[intelligence];
$UserID = $user_data[id];
$Quill = $user_data[quill];
$Mana = $user_data[mana];
$MaxMana = $user_data[maxmana];
$select = mysql_query("SELECT * FROM dragons WHERE owner = '$Username'");
$dragon_data = mysql_fetch_array($select);
# Variables with dragon data
$Dragon = $dragon_data[name];
$HP = $dragon_data[health];
$MaxHP = $dragon_data[maxhealth];
$Hatched = $dragon_data[egg];
$Hatch = $dragon_data[hatch];
$Hatched = $dragon_data[hatched];
$Birth = $dragon_data[life];
$Created = $dragon_data[created];
$Hatchtime = $Created + $Hatched;
$Hatchsecsleft = $Hatchtime - $timeofu;
$Hatchsecspassed = $Hatched - $Hatchsecsleft;
$Secssincehatched = $timeofu - $Hatchtime;
$stage = $dragon_data[phase];
$DragStren = $dragon_data[strength];
$DragTough = $dragon_data[tough];
$DragCol = $dragon_data[color];
$DragGen = $dragon_data[gender];
$DragArmor = $dragon_data[armor];
$hunger = $dragon_data[hunger];
$fun = $dragon_data[fun];
# Add some nice color to the gender
if($DragGen == "male") { $DragGen = "<span style=\"color: blue;\">Male</span>"; }
if($DragGen == "female") { $DragGen = "<span style=\"color: pink;\">Female</span>"; }
$select = mysql_query("SELECT * FROM color WHERE id = '$DragCol'");
$coldata = mysql_fetch_array($select);
$DragCol = $coldata[color];
$DragColNum = $coldata[id];
# This will make sure the health does not go too high
if($HP > $MaxHP) {
mysql_query("UPDATE dragons SET health = maxhealth WHERE name = '$Dragon'");
}
# This will make sure the health does not go too low
if($HP < 0) {
mysql_query("UPDATE dragons SET health = '0' WHERE name = '$Dragon'");
}
# Maturity level, the word.
$DragLevel = array(
'1' => "Egg",
'2' => "Hatchling",
'3' => "Young",
'4' => "Fully Grown",
'5' => "Aging",
);
if(!$DragLevel) {
$DragLevel = "Aging";
}
# Hunger level, the word.
$DragHung = array(
'1' => "Dieing",
'2' => "Starving",
'3' => "Famished",
'4' => "Famished",
'5' => "Extreamly Hungry",
'6' => "Very Hungry",
'7' => "Hungry",
'8' => "Hungry",
'9' => "Full",
'10' => "Very Full",
);
# Fun level, the word.
$DragFun = array(
'1' => "Suffering",
'2' => "Extreamly Unhappy",
'3' => "Very Unhappy",
'4' => "Unhappy",
'5' => "Extreamly Sad",
'6' => "Very Sad",
'7' => "Meh",
'8' => "Happy",
'9' => "Very Happy",
'10' => "Extatic",
);
# Hunger / Fun level matanince
if(!$hunger) {
mysql_query("UPDATE dragons SET hunger = '1' WHERE name = '$Dragon'");
}
if(!$fun) {
mysql_query("UPDATE dragons SET fun = '1' WHERE name = '$Dragon'");
}
# Some framework for notifications
$selec = mysql_query("SELECT * FROM event WHERE foruser = '$UserID'");
$number = mysql_num_rows($selec);
if($number != 0) {
$event = mysql_fetch_array($selec);
mysql_query("DELETE FROM event WHERE id = '$event[id]'");
$event = "<p class=\"event\">$event[text]</p>";
}
# Will only display health if egg is hatched
if($dragon_data[egg] == 0) {
$thing = "Not Hatched";
$link = "<li><a href=\"myegg.php\">My Egg</a></li>";
$DragImage = "images/egg.swf?c=".$DragColNum."&l=".round(($Hatchsecspassed/($Hatch+1))/.2)."";
} else {
$Dayssincehatched = round($Secssincehatched/86400);
if($Dayssincehatched > 7) {
$Dayssincehatched = 7;
}
$DragImage = "images/hatchling.swf?c=".$DragColNum."&l=".$Dayssincehatched;
$thing = "<strong>Health:</strong> $HP / $MaxHP";
$link = "<li><a href=\"mydragon.php\">My Dragon</a></li>";
}
# This is to make sure no one pulls a fast one and chages their username in the cookie.
if($HTTP_COOKIE_VARS[CPH_Psw] != $Password) {
$Username = "";
setcookie ("CPH_Usr", $Username, time()-7776000);
setcookie ("CPH_Psw", $Password, time()-7776000);
} else { # Here we have the stuff to display username, points, etc.
$layinf = "<strong>Username:</strong> $Username | <strong>Moneys:</strong> $Money
<p><strong>Dragon:</strong> $Dragon | $thing</p>
<a href=editprof.php>Edit Profile</a> | <a href=login.php?page=logout>Logout</a>";
}
# First stage, which means in egg - Scratch
if($stage == 1) {
if($timeofu >= $Hatchtime) {
mysql_query("UPDATE dragons SET egg = '1' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET hatch = '604800' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET phase = '2' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET life = '$timeofu' WHERE owner = '$Username'");
mysql_query("INSERT INTO event (foruser,text) VALUES ('$UserID','Your egg has hatched!')");
}
}
# Second stage, hatchling - Bite
if($stage == 2) {
if($timeofu >= $Hatchtime) {
mysql_query("UPDATE dragons SET hatch = '604800' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET phase = '3' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET life = '$timeofu' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET strength = strength+2 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET tough = tough+3 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET maxhealth = maxhealth+25 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET health = health+25 WHERE owner = '$Username'");
mysql_query("INSERT INTO event (foruser,text) VALUES ('$UserID','Your dragon has grown!')");
}
}
# Stage three is a maturing dragon - Spines, tail mace.
if($stage == 3) {
if($timeofu >= $Hatchtime) {
mysql_query("UPDATE dragons SET hatch = '604800' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET phase = '4' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET life = '$timeofu' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET strength = strength+8 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET tough = tough+9 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET maxhealth = maxhealth+20 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET health = health+20 WHERE owner = '$Username'");
mysql_query("INSERT INTO event (foruser,text) VALUES ('$UserID','Your dragon has grown!')");
}
}
# Fully Matured, fire breathing, able to carry human.
if($stage == 4) {
if($timeofu >= $Hatchtime) {
mysql_query("UPDATE dragons SET hatch = '1209600' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET phase = '5' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET life = '$timeofu' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET strength = strength+4 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET tough = tough+3 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET maxhealth = maxhealth+40 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET health = health+40 WHERE owner = '$Username'");
mysql_query("INSERT INTO event (foruser,text) VALUES ('$UserID','Your dragon has grown!')");
}
}
if($stage >= 5) {
if($timeofu >= $Hatchtime) {
mysql_query("UPDATE dragons SET phase = phase+1 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET phase = phase+1 WHERE owner = '$Username'");mysql_query("UPDATE dragons SET hatch = '1209600' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET life = '$timeofu' WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET strength = strength+2 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET tough = tough+2 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET maxhealth = maxhealth+10 WHERE owner = '$Username'");
mysql_query("UPDATE dragons SET health = health+10 WHERE owner = '$Username'");
mysql_query("INSERT INTO event (foruser,text) VALUES ('$UserID','Your dragon has become stronger!')");
}
}
if($Status >= 3) {
$admin = "<li><a href=\"admin.php\">Admin</a></li>";
}
# Random bits to lower happiness/hunger while the user is online.
$start = rand(1,1000);
if($start == 5) {
$hunorfun = rand(1,2);
$decre = rand(1,4);
if($hunorfun == 1) {
mysql_query("UPDATE dragons SET fun = fun-$decre WHERE name = '$Dragon'");
}
else if($hunorfun == 2) {
mysql_query("UPDATE dragons SET hunger = hunger-$decre WHERE name = '$Dragon'");
}
}
} else { //Not logged in
$layinf = "<p>Not <a href=login.php>logged in.</a></p>
<p><a href=register.php>Register?</a></p>"; # Again, displays where points and such should be.
$Username = ""; # Makes sure that Username is undefined
setcookie ("CPH_Usr", $Username, time()-7776000);
setcookie ("CPH_Psw", $Password, time()-7776000);
$link = "<li><a href=\"mydragon.php\">My Dragon</a></li>";
}
# If they are frozen, it logs their ass out.
if($Banned == 2) {
setcookie ("CPH_Usr", $Username, time()-7776000);
setcookie ("CPH_Psw", $Password, time()-7776000);
header("location: index.php");
}
# This is for restocking the shops
$select = mysql_query("SELECT * FROM crons WHERE type = 'shops'");
$cron = mysql_fetch_array($select);
if($timeofu > $cron[time]) {
mysql_query("DELETE FROM stocks");
$select = mysql_query("SELECT * FROM items WHERE stocknum > '0' AND rare = '3'");
$trala = rand(1,5);
if($trala == 3) {
while ($iteminfo = mysql_fetch_array($select)) {
mysql_query("INSERT INTO stocks (shop,itemid,quan) VALUES ('$iteminfo[stockshop]','$iteminfo[id]','$iteminfo[stocknum]')");
}
}
$select = mysql_query("SELECT * FROM items WHERE stocknum > '0' AND rare < '3'");
while ($iteminfo = mysql_fetch_array($select)) {
mysql_query("INSERT INTO stocks (shop,itemid,quan) VALUES ('$iteminfo[stockshop]','$iteminfo[id]','$iteminfo[stocknum]')");
}
$next = $timeofu+1200;
mysql_query("UPDATE crons SET time = '$next' WHERE type = 'shops'");
}
# Jolly good, eh? Now, let's start the layout up. We can put it in a variable, because I like that.
$layoutT = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
<html lang=\"en-US\">
<head>
<title>Crown of Evanion | $title</title>
<link rel=\"stylesheet\" type=\"text/css\" media=\"screen,projection\" href=\"style.css\">
</head>
<body>
<div id=\"header\">
<h1 id=\"title\">Crown of Evanion</h1>
<div id=\"userinfo\">
<p class=\"first last\">$layinf</p>
</div>
<ul id=\"nav\">
<li class=\"first\"><a href=\"index.php\">Home</a></li>
<li><a href=\"news.php\">News</a></li>
$link
<li><a href=\"village.php\">Village</a></li>
<li><a href=\"char.php\">Character</a></li>
<li><a href=\"forums.php\">Forum</a></li>
<li><a href=\"post.php\">Owl Post</a></li>
$admin
</ul>
</div>
<div id=\"content\">";
# And now, the world shall see Leif's wonderful layout!
echo $layoutT;
echo $event;
$startprofileingthingamajiggy = microtime();
?>