From 9ae5949e6a168fccbc802970a37c1a03469afb17 Mon Sep 17 00:00:00 2001 From: andy koch Date: Mon, 1 Jun 2015 23:32:38 -0700 Subject: [PATCH] initial commit --- ...nds for SimCity Online Region Exchange.doc | Bin 0 -> 20480 bytes background.png | Bin 0 -> 3591 bytes config.gif | Bin 0 -> 169 bytes config.png | Bin 0 -> 205 bytes daepngfix.js | 34 + download.png | Bin 0 -> 1475 bytes empty.gif | Bin 0 -> 43 bytes html_inc/admin_inc.php | 216 +++++ html_inc/footer.php | 2 + html_inc/header.php | 15 + html_inc/iframe_inc.php | 63 ++ html_inc/login_inc.php | 61 ++ html_inc/main_inc.php | 49 ++ html_inc/popup_inc.php | 21 + html_inc/region_inc.php | 63 ++ html_inc/register_inc.php | 45 ++ html_inc/settings_inc.php | 96 +++ iframebackground.png | Bin 0 -> 628 bytes index.php | 120 +++ junkyard.php | 285 +++++++ notes.txt | 119 +++ php_inc/admin_inc.php | 462 +++++++++++ php_inc/classes_inc.php | 741 ++++++++++++++++++ php_inc/database_inc.php | 68 ++ php_inc/iframe_inc.php | 55 ++ php_inc/login_inc.php | 36 + php_inc/main_inc.php | 315 ++++++++ php_inc/popup_inc.php | 25 + php_inc/regionFileDecode_inc.php | 115 +++ php_inc/region_inc.php | 738 +++++++++++++++++ php_inc/register_inc.php | 138 ++++ php_inc/sc4_extractor.php | 43 + php_inc/score_inc.php | 533 +++++++++++++ php_inc/settings_inc.php | 1 + php_inc/zip_inc.php | 186 +++++ score.css | 234 ++++++ score.js | 54 ++ score.php | 124 +++ score.sql | 136 ++++ terrain.png | Bin 0 -> 1324 bytes 40 files changed, 5193 insertions(+) create mode 100755 Docs/SCORE Stands for SimCity Online Region Exchange.doc create mode 100755 background.png create mode 100755 config.gif create mode 100755 config.png create mode 100755 daepngfix.js create mode 100755 download.png create mode 100755 empty.gif create mode 100755 html_inc/admin_inc.php create mode 100755 html_inc/footer.php create mode 100755 html_inc/header.php create mode 100755 html_inc/iframe_inc.php create mode 100755 html_inc/login_inc.php create mode 100755 html_inc/main_inc.php create mode 100755 html_inc/popup_inc.php create mode 100755 html_inc/region_inc.php create mode 100755 html_inc/register_inc.php create mode 100755 html_inc/settings_inc.php create mode 100755 iframebackground.png create mode 100755 index.php create mode 100755 junkyard.php create mode 100755 notes.txt create mode 100755 php_inc/admin_inc.php create mode 100755 php_inc/classes_inc.php create mode 100755 php_inc/database_inc.php create mode 100755 php_inc/iframe_inc.php create mode 100755 php_inc/login_inc.php create mode 100755 php_inc/main_inc.php create mode 100755 php_inc/popup_inc.php create mode 100755 php_inc/regionFileDecode_inc.php create mode 100755 php_inc/region_inc.php create mode 100755 php_inc/register_inc.php create mode 100755 php_inc/sc4_extractor.php create mode 100755 php_inc/score_inc.php create mode 100755 php_inc/settings_inc.php create mode 100755 php_inc/zip_inc.php create mode 100755 score.css create mode 100755 score.js create mode 100755 score.php create mode 100755 score.sql create mode 100755 terrain.png diff --git a/Docs/SCORE Stands for SimCity Online Region Exchange.doc b/Docs/SCORE Stands for SimCity Online Region Exchange.doc new file mode 100755 index 0000000000000000000000000000000000000000..32f4674f786dc1f470a1121d2e73403403d530c8 GIT binary patch literal 20480 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 N002ovPDHLkV1icw+8F=< literal 0 HcmV?d00001 diff --git a/config.gif b/config.gif new file mode 100755 index 0000000000000000000000000000000000000000..501cde1a9f220bb643ece3c250baf7ce79e1b76e GIT binary patch literal 169 zcmZ?wbhEHblxL7ilmW@oWPA=AV**@Ru(~Eyg=h"; +} + +function correctPNG() { + var r = new RegExp(".png$", "i"); + for(var i=0; i;x#y4<= zp&j_fAbs_4V~7BqW3YpHfv-RdwdfnOnCyozA+g z+jhPC!8hkFI17&1IlWOQ6Cna`)Ef)(?dKc~Zym45J94O|`f5u{3q?`2wY8EYX`|CL zy|lD6IXO8oIsNK^?EKfISgNtDt*&pNhvQ5k+rjq^^!(QDj3s|Qel%(S{(X1;xVyNx zXfm0+UhmAzj35Xa=&~&HJkKzU)oK~{Oo^iL`>S8ReZv0Wq04AA0$ELB@cj?F-#Kx# zrsjg*PxbXZfL@Em0y%X1{eEq9)wJj+qt%+wKk(>{%U^kymY;}tM0}>h&Zd9MKdH$`-{E#Y z#tI%1$az7c7=omqn7U>)DXME_Dc~R0z_JGXY`)n`Qu1MB@ zFnWW5W)0#KgP(0#8tAgDP>g)!oGf*?cA z3W8_k?|3vHNnUTC;d#Hw6m$0Mho?`M4f%wSyyFMmc`b-T$LzAQlF)10&hrAY{=JjM z+qc<%zjJ$H!UG{mkczBR2!d2&NCdD1UeI$~a`INIB{AgHH9Zp`l4N)7+55_Nn|gqz zXf!W;NGgDh!0>|Lc8_|!3ubfd*3?wh_6P+Uo>4b}v04+aT)EQR)I>7@LgVB()C(Kv z@{)woFD@?Ly?bv&xvXJ(xChJ1$_fh$H*MO4Qmm}3Y;SK5-;C<7sHg}xE5h{}wuhS# z6%|!bP_Sjo7W7q*#}k2$NiaM-4Bf;k8L!c2R@!Wk(2qt(M`veeHB-Xvb`K2=VN|U) zo1Q}V`FwCL%d+Uyp?hH5#KpydkB^UkCUT3zg5yp~| z5)3dHg{UHEupLhh=!S4?Y;0j+K?)Ma1(H&|90HJ=n|t{1VN57wQE--Ny~S`C`T>dn zV8y6}Pv8N-AwzJRi3v;+5ne`|)6&wClatM6GmcD8Ph%`^+_*6*DG8>m`qG;Z63l@D zfFgR>jg){Sd~8C<1__M%6oARlq-MeM-jUc1lu+)gtC|&9)#0gDfLfwz?m|s?<`6IR d4g8+~0{}2w^8AD#IyV3S002ovPDHLkV1gb#(JcS~ literal 0 HcmV?d00001 diff --git a/empty.gif b/empty.gif new file mode 100755 index 0000000000000000000000000000000000000000..5bfd67a2d6f72ac3a55cbfcea5866e841d22f5d9 GIT binary patch literal 43 mcmZ?wbhEHbWMp7uXkdT>#h)yUAf^t80Ld^gF}W}@SOWlZ0R#L1 literal 0 HcmV?d00001 diff --git a/html_inc/admin_inc.php b/html_inc/admin_inc.php new file mode 100755 index 0000000..134cf2b --- /dev/null +++ b/html_inc/admin_inc.php @@ -0,0 +1,216 @@ +
+ Main + + data['privileges'] > 50 ) + { + echo " + > Admin"; + } + ?> + +
O
+ Functions: + Settings +  |  + Logout data['login'] ?> +
+ + + + + + +
+ +
Region Settings
+ +
+ + + + + + +
+ + + +
+ + +
General SCORE Options/Settings:
+
+ +
+ + + +
+ SCORE Variables +

+

+ Public Registration +
+
+ + > +
+ + +
+ Admin Name +
+
+ +
+ + +
+ Admin Email +
+
+ +
+ + +
+ SMTP Settings (Optional) +

+ + SCORE will use php's built in mail() + function which uses sendmail on linux, + and an external, non authenticating SMTP + server on windows (specified in php.ini). +

+ If you need authenitcating SMTP or just wish + to use an external SMTP, specify the server and + optionally any login/pass needed to authenticate. + Leave blank if no authentication is not needed. + + +

+ External SMTP Host +
+
+ +
+ + +
+ SMTP Login +
+
+ +
+ +
+ SMTP Password +
+
+ +
+ +
+ + Expiration of Stale Accounts +

+ +

+ Warn on accounts Idle for X days old +
+
+ +
+ +
+ Remove account X days later after warn +
+
+ +
+ + +
+ + Path Settings +

+ + Note: Changing these values once regions are in progress is a very bad idea. Existing regions should be deleted and added back. +

+

+ +
+ Use Zip () +
+
+ + > +
+ +
+ Images Path +
+
+ +
+ +
+ Region Path +
+
+ +
+ +
+ Region Image Width (pixels or percent) +
+
+ +
+ +
+ + + + + Server Environment (php.ini) +

+ +

+ max_execution_time (in seconds) +
+
+   +
+ +
+ post_max_size (10 - 20MB recommended) +
+
+   +
+ +
+ upload_max_filesize (match to post_max_size) +
+
+   +
+ +
+ memory_limit (post_max_size + 10%) +
+
+   +
+ +
+
+ + + +
+ + +
\ No newline at end of file diff --git a/html_inc/footer.php b/html_inc/footer.php new file mode 100755 index 0000000..b353eb4 --- /dev/null +++ b/html_inc/footer.php @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/html_inc/header.php b/html_inc/header.php new file mode 100755 index 0000000..a6e45b1 --- /dev/null +++ b/html_inc/header.php @@ -0,0 +1,15 @@ + + + + SimCity Online Region Exchange + + + + + + + + + diff --git a/html_inc/iframe_inc.php b/html_inc/iframe_inc.php new file mode 100755 index 0000000..6b27bcb --- /dev/null +++ b/html_inc/iframe_inc.php @@ -0,0 +1,63 @@ + + + + SimCity Online Region Exchange + + + + + + + + + + + \ No newline at end of file diff --git a/html_inc/login_inc.php b/html_inc/login_inc.php new file mode 100755 index 0000000..b745d02 --- /dev/null +++ b/html_inc/login_inc.php @@ -0,0 +1,61 @@ + + + + + + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + Note! IE does not fully support PNG transparency. + +
+ + Get Firefox + +
+
+ +
\ No newline at end of file diff --git a/html_inc/main_inc.php b/html_inc/main_inc.php new file mode 100755 index 0000000..05e2482 --- /dev/null +++ b/html_inc/main_inc.php @@ -0,0 +1,49 @@ + +
+ Main +
O
+ Functions: + Settings +  |  + Logout data['login'] ?> + + +
+ + + + + + + + + + \ No newline at end of file diff --git a/html_inc/popup_inc.php b/html_inc/popup_inc.php new file mode 100755 index 0000000..a2aa06f --- /dev/null +++ b/html_inc/popup_inc.php @@ -0,0 +1,21 @@ + + + + + + SimCity Online Region Exchange + + + + + + +
+ +
+ + + \ No newline at end of file diff --git a/html_inc/region_inc.php b/html_inc/region_inc.php new file mode 100755 index 0000000..25278ce --- /dev/null +++ b/html_inc/region_inc.php @@ -0,0 +1,63 @@ + +
+ Main > + data['name'] ?> +
O
+ Functions: + Settings +  |  + Logout data['login']?> + + +
+ + + +
+ Region Detail & City Listing +
+ + +
+
+ All Regions / Games +
+ +
+ +
+
+ +
+ Your Cities in Play +
+
+ +
+ + +
+ Your Messages +
+
+ +
+ + + + +
+ + + +
+ + + + + + + + + + + +
+ + If you just uploaded your city and you don't see the changes on the full map or in the city view - its likely because of your browser cacheing the image. +
+
+ + + +
+ + + + \ No newline at end of file diff --git a/html_inc/register_inc.php b/html_inc/register_inc.php new file mode 100755 index 0000000..0e509e0 --- /dev/null +++ b/html_inc/register_inc.php @@ -0,0 +1,45 @@ + + + +
+
+
+ SCORE Registration Policy & User Agreement +
+ +
+ Here are the rules for using this SCORE system:

+ + - Don't be a bad-ass. +

+ If you agree to these terms and rules please continue with + the registration. + +

+ Thank You. +

+
+ +
+
+ +
+ SimCity Online Region Exchange: New User Registration Form +
+ + + +
+
+ + + +
+ +
+
+
\ No newline at end of file diff --git a/html_inc/settings_inc.php b/html_inc/settings_inc.php new file mode 100755 index 0000000..21241c2 --- /dev/null +++ b/html_inc/settings_inc.php @@ -0,0 +1,96 @@ +
+ Main + + data['privileges'] > 50 ) + { + echo " + > Settings"; + } + ?> + +
O
+ Functions: + Logout data['login'] ?> +
+ + + + + + + + + +
+
+
Player Settings
+ +
+ + Personal Info +

+

+ Email Address +
+
+ +
+
+ At this time - please contact the Admin to change your email address. + +
+ Change Password +

+ +

+ Current Password +
+
+ +
+ +
+ New Password +
+
+ +
+ +
+ New Password x2 +
+
+ +
+ +
+ + Game Options +

+

+ Email game messages? +
(still not really implemented yet - sorry, just ignore) +
+
+ + data['email_messages']) ?>> +
+
+ With this option ON you will be sent an email with each new SCORE message. + +
+ +
+ +
+ +
+
+
+
Let us know what should go here
+ +
+ +
+
\ No newline at end of file diff --git a/iframebackground.png b/iframebackground.png new file mode 100755 index 0000000000000000000000000000000000000000..6cb6225650f4ed728b239fd8c55282a953701e4f GIT binary patch literal 628 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1SEZ8zRdwroCO|{#S9GWDj>}09x+3cfq_ZQ z)5S5QV$R#S8?z2O2(X4b9b#L_r}jkq(|`GtORXY(I(Kuq!l(T{!}!auo03FZS5 z496G@-Z9*`FU#K?~_1elB%JYD@<);T3K F0RXT$3y}Z- literal 0 HcmV?d00001 diff --git a/index.php b/index.php new file mode 100755 index 0000000..aaef848 --- /dev/null +++ b/index.php @@ -0,0 +1,120 @@ +data['id']) || isset($_SESSION['score_guest']) ) + { + + // sometimes (like for the region view iFrame or for headers) + // we want to load score with out spewing content + if (! isset($_REQUEST['noheader'])) + include('html_inc/header.php'); + /* + ** Lib & Call handle what section of the site we're at and what functions to call + */ + + lib_request(); func_request(); + + // includes this library's html file + if (@is_numeric($_SESSION['score_user']->data['id']) || isset($_SESSION['score_guest'])) // still an existing session - checking again because func_request could have logged the user out + include("html_inc/{$_SESSION['score_lib']}_inc.php"); + + // sometimes (like for the region view iFrame or for headers) + // we want to load score with out spewing content + if (! isset($_REQUEST['noheader'])) + include('html_inc/footer.php'); + } + + +/* +decho ("
+
 
SESSION"); +if (isset($_SESSION)) + print_array($_SESSION); + +decho ("GET"); +if (isset($_GET)) + print_array($_GET); + +decho ("POST"); +if (isset($_POST)) + print_array($_POST); + +decho ("GLOBAL"); +if (isset($GLOBALS['SCORE'])) + print_array($GLOBALS['SCORE']); +decho("
") +*/ +?> \ No newline at end of file diff --git a/junkyard.php b/junkyard.php new file mode 100755 index 0000000..cd292d4 --- /dev/null +++ b/junkyard.php @@ -0,0 +1,285 @@ + data['id']}"; + $city_data = dbq($sql); + + echo " +
+ {$GLOBALS['SCORE']['scRegion']->data['name']} +
+ - Created: NA +  |  + Last Updated: NA +

+ - TotalPop: {$GLOBALS['SCORE']['scRegion']->data['total_pop']} +
+    + R: {$GLOBALS['SCORE']['scRegion']->data['total_R']} +  |  + C: {$GLOBALS['SCORE']['scRegion']->data['total_C']} +  |  + I: {$GLOBALS['SCORE']['scRegion']->data['total_I']} +

+ +
+ City Upload: +
+ + +
+
+
+ "; + + // output city listing + if (is_array($city_data)) + { + echo " + + "; + foreach($city_data as $key=>$city) + //print_array ($city); + { + echo " + + + + "; + } + echo "
+ + data['name'])."/".rawurlencode($city['name']).".sc4\" title=\"Click to Download\">{$city['name']} +
+ - Created: NA
+ - Updated: NA +

+ - TotalPop: {$city['pop']}
+    + R: {$city['R']} +
+    + C: {$city['C']} +
+    + I: {$city['I']} +

+

+ data['name'])."/".rawurlencode($city['name'])."_thumb.png\" align=\"right\"> +
"; + } + } + + + + function showEntireRegion() + { + + $sql = "SELECT name,sizeX,sizeY,locX,locY FROM cities WHERE region_id = {$_SESSION['score_region_id']} ORDER BY locY,locX"; + $array = dbq($sql); + + drawEntireRegion($array, $GLOBALS['SCORE']['scRegion']->data); + } + + + + + function drawEntireRegion($array, $region) + { + + $configBMP = configBMP($array); + $f=0; + while(sizeof($array)) + { + foreach($array as $key => $item) + { + if ( tileCheck($item['locX'], $item['locY'], $item['sizeX'], $item['sizeX'], $configBMP) ) + { + $drawlist[] = $item; + unset($array[$key]); + } else { + $f++; + if ($f > 1000) + exit; + } + } + } + + $so[1]['X']=0; + $so[1]['Y']=0; + + $so[2]['X']=-35; + $so[2]['Y']=20; + + $so[4]['X']= -110; + $so[4]['Y']= 60; + + foreach($drawlist as $tile) + { + $Isize = getimagesize ( "{$GLOBALS['SCORE']['SC4IMG_PATH']}/{$GLOBALS['SCORE']['scRegion']->data['name']}/{$tile['name']}.png" ); + + $YOffset = ($Isize[1]) - (45 * $tile['sizeY']); + $ImageX = (-37 * $tile['locY'] + 1) + ($tile['locX'] * 90) + $so[$tile['sizeX']]['X'] + 250; + $ImageY = (45 * $tile['locY'] + 1) + ($tile['locX'] * 18) - $YOffset + $so[$tile['sizeY']]['Y'] + 75; + echo + " + data['name']}/{$tile['name']}.png\" style=\"position:absolute; top: {$ImageY}; left: {$ImageX}\"> + "; + } + } + + +function rebuildSCORE () { + + // setting some variables + $t_start = array_sum(explode(' ', microtime())); // to monitor processing time + $ccount = 0; // city count + $rcount = 0; // region count + + echo ("."); + // clear existing data + $sql = "TRUNCATE TABLE regions"; + dbsql($sql); + $sql = "TRUNCATE TABLE cities"; + dbsql($sql); + + echo ("."); + // delete image data + remove_dir($GLOBALS['SCORE']['SC4IMG_PATH']); + mkdir($GLOBALS['SCORE']['SC4IMG_PATH']); + + echo ("."); + // prepare our objects + $Rdirs = new scDir(); + $Cfiles = new scDir(); + $scFile = new scSaveGameFile(); + $scImg = new scImg(); + + echo ("."); + // Read in the Regions dir. Loop through each region gathering city names, and other data + $Rdirs->Load($GLOBALS['SCORE']['SC4PATH']); + + if( ! sizeof($Rdirs->getDirContents())) + return false; + + foreach($Rdirs->getDirContents() as $key=>$dir) + { + echo ("."); + $rcount++; + $total_region['R'] = $total_region['C'] = $total_region['I'] = 0; + $path = $GLOBALS['SCORE']['SC4PATH'] . '/' . $dir . '/'; + $img_path = $GLOBALS['SCORE']['SC4IMG_PATH']. '/' . $dir . '/'; + + echo ("."); + // add the region the table + $sql = "INSERT INTO `regions` ( `id` , `name` , `total_pop` , `total_R` , `total_C` , `total_I` , `vrestrict`, `created`, `modified`) VALUES ('', '{$dir}', NULL , NULL , NULL , NULL , '0', now(), now())"; + dbsql($sql); + + echo ("."); + mkdir($GLOBALS['SCORE']['SC4IMG_PATH']. '/' . $dir); + + echo ("."); + $Rid = mysql_insert_id($GLOBALS['score_dbconn']); + + echo ("."); + // process the city files for this region + $Cfiles->Load($GLOBALS['SCORE']['SC4PATH'] . '/' . $dir); + + if( ! sizeof($Cfiles->getFileContents())) + return false; + + echo ("."); + foreach($Cfiles->getFileContents() as $key=>$file) + { + flush(); + if( substr($file, -4) === '.sc4' ) + { + $ccount++; + + echo ("."); + // load and parse the city file + $scFile->Load($path . $file); + $scFile->fullParse(); + + echo ("."); + // load fullsize and process to new size(s) + $scImg->Load($scFile->contents['mainImg']); + $scImg->Resize('66%','66%'); + $scImg->setAlphaTrans($scImg->current, false, true, 0,0,0); + $scImg->setAlphaTrans($scImg->original, false, true, 0,0,0); + + echo ("."); + $scImg->writeImg($img_path . substr($file, 0, -4) . '.png', 'original'); + $scImg->writeImg($img_path . substr($file, 0, -4) . '_thumb.png'); + + echo ("."); + // add city info to table + $sql = "INSERT INTO `cities` ( `id`, + `region_id`, + `R`, + `C`, + `I`, + `pop`, + `name`, + `locX`, + `locY`, + `sizeX`, + `sizeY`, + `created`, + `modified` + ) + VALUES + ( + '', + '{$Rid}', + '{$scFile->contents['R']}', + '{$scFile->contents['C']}', + '{$scFile->contents['I']}', + '".($scFile->contents['R']+$scFile->contents['C']+$scFile->contents['I'])."', + '" . substr($file, 0, -4) . "', + '{$scFile->contents['locX']}', + '{$scFile->contents['locY']}', + '{$scFile->contents['sizeX']}', + '{$scFile->contents['sizeY']}', + now(), + now() + + )"; + dbsql($sql); + $total_region['R'] += $scFile->contents['R']; + $total_region['C'] += $scFile->contents['C']; + $total_region['I'] += $scFile->contents['I']; + + + } + } + + // update the region info to include RCI & pop + echo ("."); + $sql = " UPDATE `regions` SET + + `total_pop` = '".($total_region['R']+$total_region['C']+$total_region['I'])."', + `total_R` = '{$total_region['R']}', + `total_C` = '{$total_region['C']}', + `total_I` = '{$total_region['I']}' + + WHERE `id` = '$Rid' + "; + dbsql($sql); + + // generate the region images + $region['name'] = $dir; + $region['id'] = $Rid; + + gen_region_images($region, true); + } + + decho("Processed $ccount cities in $rcount regions in " . (array_sum(explode(' ', microtime())) - $t_start) . " seconds"); + } + + ?> \ No newline at end of file diff --git a/notes.txt b/notes.txt new file mode 100755 index 0000000..7d02725 --- /dev/null +++ b/notes.txt @@ -0,0 +1,119 @@ +Key: [-] todo; [o] done + +Todo General: +============= + +o add default admin user to setup sql +o first user inserted will have id 0 - which may cause problems +o registration page +- may be able to use date/time stamp as unique id on city file - for such uses and varifying uploaded city file is the original +- use transit images +- consider going to jpg since it will work better in IE (won't it?) +- some sort of region image feedback mechanism so people know which city they're highlighting +- better borders around cities on region map so users know where to click +o Zipping of uploads/downloads - complete region download +- support for zipped uploads +- Need to go to templating of any HTML being done in php now +o Login had html being outputted then does a redirect +o deal with expiring registrations which aren't confirmed with a login +o make login form data secure (sc_REQUEST) +o make registration form data secure (sc_REQUEST) +- make all GET/POST id's use sc_REQUEST +- make admin form use sc_REQUEST +o Improve admin region import to compare against the database not the Images dir +- make email contain url to populate the login form for convenience +- show file size beside download links (time estimate?) +o possible option for players to turn off zipped files +- add confirmation popup to resign +o tab order with register link on login page +o going directly to region url somehow bypasses check on valid user session +o regions zip download not working +o ie image tile js not working when in conjunction with the dom js + + + +**- credits page + + +Todo Game Features: +=================== +o city checkout by request only +o fixed time limited checkouts +- inactivity based checkouts +- game limited by simcity version +- add showing of game options to main view +- option to disallow resign of cities? + + +Admin Todos: +============ + System Wide + o public registrations + o use zip? + o Image path + o Region path + + + Region/Game Settings + o full region downloads + o city/point limit option + o city checkout by request only + o time limited checkouts on/off + o time limited checkout time limit + o game limited by simcity version + + - assign a city to a user + - resign a user from a city + o list showing pending city term requests w/deny & accept + + + +Setup Notes: +============ +- increase post_max_size to at least 10MB - 20 recommended +- increase upload_max_filesize to at least 10MB - 20 recommended (set same as post_max_size) +- increase max memory to 20mb +- need to set (and possibly uncomment) SMTP = your ips's mail server and sendmail_from = your account with your provider + + +To Test: +======== +- entering invalid values for all forms +o does SCORE handle regions with empty spots in the bitmap file + + + +Idea for Browser Input Validator: +================================= +- you have basic data types: + - FILE + - TEXT + - ID + +- all forms use array's for name="" which specify type. + for example: + +- then in score.php a generic class looks in $_REQUEST for a + score_form ($_REQUEST['sf']) and loads it, then validates each set of value + types accordingly + +- ids are checked for being numeric; text fields have addslashes called, file names have basename() called + +You can still reference the original values in $_REQUEST['sf'] if you need unvalidated, raw values. +And you can opt not to use the SCORE forms validator by simply not naming your html form data: sf[type] + + + +Permisisions Ideas: +====== +- permissions 0-200. each 'function' is assigned a min permission value + anyone over that value can access that function. + + + +FAQ: +==== + +Q:How do I edit the end-user agreement on the registration page? + +A:open the file html_inc/register_inc.php and edit as you desire. \ No newline at end of file diff --git a/php_inc/admin_inc.php b/php_inc/admin_inc.php new file mode 100755 index 0000000..a127f66 --- /dev/null +++ b/php_inc/admin_inc.php @@ -0,0 +1,462 @@ + $region) + { + $update = ''; + foreach($region as $field => $value) + $update .= "$field='".addslashes($value)."',"; + $update = substr($update,0,-1); + $sql = "UPDATE regions SET $update WHERE id='$region_id'"; + dbsql ($sql); + } +} + + +function UpdateSCORESettings() +{ + if(! isset($_REQUEST['score_option'])) + return false; + + $element_array[] = 'PUBLIC_REG'; + $element_array[] = 'USE_ZIP'; + $element_array[] = 'SC4IMG_PATH'; + $element_array[] = 'SC4PATH'; + $element_array[] = 'SC4REGION_IMG_WIDTH'; + $element_array[] = 'ADMIN_NAME'; + $element_array[] = 'ADMIN_EMAIL'; + $element_array[] = 'idle_account_limit_warn'; + $element_array[] = 'idle_account_limit'; + + $element_array[] = 'SMTP_HOST'; + $element_array[] = 'SMTP_USER'; + $element_array[] = 'SMTP_PASS'; + + $update = ''; + foreach ($element_array as $el) + { + $update .= "$el='{$_REQUEST['score_option'][$el]}',"; + } + + $update = substr($update,0,-1); + $sql = "UPDATE score_sys SET $update WHERE name_id='score_sys'"; + dbsql ($sql); + + set_score_prefs(); +} + + +function html_get_admin_region_list() +{ + $sql="SELECT id,name,complete_region_dl,checkout_req_auth,checkout_user_limit,checkout_timelimit,vrestrict,description,cityloc_check FROM regions"; + $r = dbq($sql); + + if(! sizeof($r)) + return false; + + echo " +
"; + + $basename = $_SERVER['PHP_SELF']; + + foreach($r as $region) + { + // setup variables + + $vrestrict_options = ''; + foreach($GLOBALS['SCORE']['SC4VERSIONS'] as $string => $val) + { + if ($region['vrestrict'] == $val) + $selected = 'SELECTED'; else $selected = ''; + $vrestrict_options .= "\n"; + } + + if($region['complete_region_dl'] == 'on') + $checked['complete_region_dl'] = ' CHECKED'; else $checked['complete_region_dl'] =''; + + if($region['checkout_req_auth'] == 'on') + $checked['checkout_req_auth'] = ' CHECKED'; else $checked['checkout_req_auth'] =''; + + if($region['cityloc_check'] == 'on') + $checked['cityloc_check'] = ' CHECKED'; else $checked['cityloc_check'] =''; + + echo " +
+ {$region['name']} - + (Delete) + +
+
+ Full Region Downloads +
+
+ + +
+ +
+ City Checkout Authorization +
+
+ + +
+ +
+ City Location Validation on Updates
+
+
+ + +
+ +
+ User Checkout City Limit (Zero Unlimited) +
+
+ +
+ +
+ Time Limited Checkouts (in Days; Zero Unlimited) +
+
+ +
+ +
+ General Description +
+
+ +
+ + + +
+ "; + } + + echo "
+
+ +
+
+ "; +} + + +function deleteRegion () + { + if(! isset($_REQUEST['id']) || ! is_numeric($_REQUEST['id']) ) + return false; + + $region = new scRegion($_REQUEST['id']); + if( ! $region->status ) + { + decho("status is bad:".$region->status); + return false; + } + + // delete region folder from SC4IMG_PATH + remove_dir("{$GLOBALS['SCORE']['SC4IMG_PATH']}/{$region->data['name']}"); + + // confirm the delete worked + if ( is_dir("{$GLOBALS['SCORE']['SC4IMG_PATH']}/{$region->data['name']}")) + { + $GLOBALS['SCORE']['errors'][] = "{$region->data['name']} directory failed to delete. Permissions problem?"; + return false; + } + + // delete cities from database + $sql = "DELETE FROM cities WHERE region_id='{$region->data['id']}'"; + dbq($sql); + + // delete region from database + $sql = "DELETE FROM regions WHERE id='{$region->data['id']}'"; + dbq($sql); + + unset($region); + } + +function html_show_perms_state() + { + $gword = 'Yes'; + $bword = 'No'; + + $gcolor = "{$gword}"; + $bcolor = "{$bword}"; + + $sc4path['r'] = (is_readable($GLOBALS['SCORE']['SC4PATH'])) ? $gcolor : $bcolor; + $sc4path['w'] = (is_writable($GLOBALS['SCORE']['SC4PATH'])) ? $gcolor : $bcolor; + + $sc4img_path['r'] = (is_readable($GLOBALS['SCORE']['SC4IMG_PATH'])) ? $gcolor : $bcolor; + $sc4img_path['w'] = (is_writable($GLOBALS['SCORE']['SC4IMG_PATH'])) ? $gcolor : $bcolor; + + $gd_lib = (extension_loaded('gd')) ? $gcolor : $bcolor; + $gdpng = (function_exists('imagecreatefrompng')) ? $gcolor : $bcolor; + + $pearMail = (@include('Mail.php')) ? $gcolor : $bcolor; + $pearMailAuth = (@include('Auth/SASL.php')) ? $gcolor : $bcolor; + + echo " +
+ Permissions Status +
+ {$GLOBALS['SCORE']['SC4PATH']} is Readable {$sc4path['r']} / Writable {$sc4path['w']} +
+ {$GLOBALS['SCORE']['SC4IMG_PATH']} is Readable {$sc4img_path['r']} / Writable {$sc4img_path['w']} +

+ + Requirements +
+ GD Extensions available? {$gd_lib} +
+ GD-PNG Extensions available? {$gdpng} +
+ PEAR Mail Class available? {$pearMail} +

+ + Optional +
+ PEAR SMTP Authentication available? {$pearMailAuth} +

+ "; + } + + +function html_import_regions() + { + // is specified folders for regions/images useable by score (read/write) + if ( ! is_writable($GLOBALS['SCORE']['SC4PATH']) || ! is_writable($GLOBALS['SCORE']['SC4IMG_PATH']) ) + { + echo "Region and Images dir do not have correct permission or do not exist - please ensure that php can read and write to theses directories and their contents"; + return false; + } + + echo " +
+

+ Import New Region + + +

+ "; + } + + +function html_options_importableRegions () + { + $dir = new scDir(); + + // get region folder names from SC4PATH + $dir->Load($GLOBALS['SCORE']['SC4PATH']); + $all_regions = $dir->getDirContents(); + + // get list of already imported regions + $imported_regions = dbq("SELECT name FROM regions"); + + foreach($imported_regions as $region) + $ir[] = $region['name']; + + echo " + "; + + foreach($all_regions as $region) + { + if ( is_readable("{$GLOBALS['SCORE']['SC4PATH']}/{$region}") && ! in_array($region, $ir) ) + { + echo " + "; + } elseif ( ! is_readable("{$GLOBALS['SCORE']['SC4PATH']}/{$region}") && ! in_array($region, $ir) ) { + echo " + "; + } + } + + unset($dir); + } + + + +function ImportRegion() + { + if ( ! isset($_REQUEST['importRegion']) ) + return false; + + if ( $_REQUEST['importRegion'] == 'NOREAD' ) + { + $GLOBALS['SCORE']['errors'][] = "You can not import this region until you fix the read permissions. See the 'setup' documentation for more information."; + return false; + } + + if ( ! extension_loaded('gd') || ! function_exists('imagecreatefrompng') ) + { + $GLOBALS['SCORE']['errors'][] = "The version of PHP you are using doesn't have GD Extensions with PNG support. See the 'setup' documentation for more information."; + return false; + } + + $import_region = basename($_REQUEST['importRegion']); + + if ( ! is_dir("{$GLOBALS['SCORE']['SC4PATH']}/$import_region") ) + return false; + + if ( is_dir("{$GLOBALS['SCORE']['SC4IMG_PATH']}/$import_region") ) + return false; + + importSCRegion($import_region); + } + + +function importSCRegion($importRegion) + { + // class handles rolling back any changes on any error + //$sc_importErrorHandler = new sc_importErrorHandler($importRegion); + + // set up variables + $total_region['R'] = $total_region['C'] = $total_region['I'] = $total_region['money'] = 0; + $path = $GLOBALS['SCORE']['SC4PATH'] . '/' . $importRegion . '/'; + $img_path = $GLOBALS['SCORE']['SC4IMG_PATH']. '/' . $importRegion . '/'; + + // set up objects + $Cfiles = new scDir(); + $scFile = new scSaveGameFile(); + $scImg = new scImg(); + + //make the region dir in Images dir + mkdir($GLOBALS['SCORE']['SC4IMG_PATH']. '/' . $importRegion); + + // process the city files for this region + $Cfiles->Load($GLOBALS['SCORE']['SC4PATH'] . '/' . $importRegion); + + // add the region the table + $sql = "INSERT INTO `regions` ( `id` , `name` , `total_pop` , `total_R` , `total_C` , `total_I` , `vrestrict`, `created`, `modified`) VALUES ('', '{$importRegion}', NULL , NULL , NULL , NULL , '0', now(), now())"; + dbsql($sql); + $Rid = mysql_insert_id($GLOBALS['score_dbconn']); + + // this ensures the error handler can clean up our database tables + //$sc_importErrorHandler->setRegionID($Rid); + + if( ! sizeof($Cfiles->getFileContents())) + return false; + + foreach($Cfiles->getFileContents() as $key=>$file) + { + if( substr($file, -4) === '.sc4' && is_readable($path.$file) ) + { + + // load and parse the city file (if readable) + $scFile->Load($path . $file); + $scFile->fullParse(); + + // load fullsize and process to new size(s) + $scImg->Load($scFile->contents['mainImg']); + $scImg->Resize('66%','66%'); + + $scImg->setAlphaTrans($scImg->current, false, false, 0,0,0); + $scImg->setAlphaTrans($scImg->original, false, true, 0,0,0); + + $scImg->writeImg($img_path . substr($file, 0, -4) . '.png', 'original'); + $scImg->writeImg($img_path . substr($file, 0, -4) . '_thumb.png'); + + // add city info to table + $sql = "INSERT INTO `cities` ( `id`, + `region_id`, + `R`, + `C`, + `I`, + `pop`, + `name`, + `locX`, + `locY`, + `sizeX`, + `sizeY`, + `created`, + `modified`, + `money` + ) + VALUES + ( + '', + '{$Rid}', + '{$scFile->contents['R']}', + '{$scFile->contents['C']}', + '{$scFile->contents['I']}', + '".($scFile->contents['R']+$scFile->contents['C']+$scFile->contents['I'])."', + '" . addslashes(substr($file, 0, -4)) . "', + '{$scFile->contents['locX']}', + '{$scFile->contents['locY']}', + '{$scFile->contents['sizeX']}', + '{$scFile->contents['sizeY']}', + now(), + now(), + '{$scFile->contents['money']}' + + )"; + dbsql($sql); + $total_region['R'] += $scFile->contents['R']; + $total_region['C'] += $scFile->contents['C']; + $total_region['I'] += $scFile->contents['I']; + $total_region['money'] += $scFile->contents['money']; + + } + } + + // update the region info to include RCI & pop + $sql = " UPDATE `regions` SET + + `total_pop` = '".($total_region['R']+$total_region['C']+$total_region['I'])."', + `total_R` = '{$total_region['R']}', + `total_C` = '{$total_region['C']}', + `total_I` = '{$total_region['I']}', + `total_money` = '{$total_region['money']}' + WHERE `id` = '{$Rid}' + "; + dbsql($sql); + + + + + // generate the region image + $region['name'] = $importRegion; + $region['id'] = $Rid; + gen_region_images($region, true); + } + +?> \ No newline at end of file diff --git a/php_inc/classes_inc.php b/php_inc/classes_inc.php new file mode 100755 index 0000000..0e6fcd3 --- /dev/null +++ b/php_inc/classes_inc.php @@ -0,0 +1,741 @@ +data = $data; + } + } + + + class scMayor extends scUser + { + var $data; + + function scMayor($id) + { + $sql = "SELECT * FROM users WHERE id = '{$id}'"; + $r = dbq($sql); + + if( sizeof($r) != 1) + return false; + + $this->data = $r[0]; + } + } + + + class scRegion + { + var $data; + var $status; + + function scRegion($id) + { + $sql = "SELECT * FROM regions WHERE id = '{$id}'"; + $tmp = dbq($sql); + + if( ! sizeof($tmp) == 1 ) + { + $this->status = false; + $GLOBALS['SCORE']['errors'][] = "Error Loading Region Object"; + return $this->status; + } + + $this->data = $tmp[0]; + $this->data['imagemap'] = unserialize($this->data['imagemap']); + + $this->status = true; + return $this->status; + + } + + + function getCityList() + { + $sql = "SELECT * FROM cities WHERE region_id = '{$this->data['id']}'"; + $tmp = dbq($sql); + + foreach($tmp as $city) + $this->data['Cities'][$city['id']] = $city; + } + + // gets the number of city-points used in this region + function usedCityPoints ($force=false) + { + if( ! isset($this->data['Cities']) ) + $this->getCityList(); + + $total=0; + + foreach($this->data['Cities'] as $id => $city) + if ( $_SESSION['score_user']->data['id'] == $city['mayor_id']) + $total += $city['sizeX']; + + return $total; + } + + } + + + class scImg extends scBaseClass + { + var $original; // img resource + var $currrent; // current image + + + function Load($data) + { + $this->original = imagecreatefromstring ( $data ); + } + + + // handles converting percents to pix and calculating proportionate X or Y + function normalizeSize(&$toX, $cX, &$toY, $cY) + { + // pixelize $toX if percent + if ( substr($toX,-1) == '%' ) // if number provided in percent + { + $toX = $cX * (substr($toX,0,-1) / ( 100 ) ); + } + + // pixelize $toY if percent + if ( substr($toY,-1) == '%' ) // if number provided in percent + { + $toY = $cY * (substr($toY,0,-1) / ( 100 ) ); + } + + // determine if we need to calculate aspect ratio resize + // based on if only one dimension size was provided + if ($toX == '' && $toY > 0) + $toX = $cX * ($toY/$cY); + + if ($toY == '' && $toX > 0) + $toY = $cY * ($toX/$cX); + + } + + function setAlphaTrans(&$Image, $ImgAlphaBlend, $ImgSaveAlpha, $R,$G,$B) + { + imagealphablending ( $Image, $ImgAlphaBlend); + imagesavealpha ( $Image, $ImgSaveAlpha ); + $trans = imagecolortransparent ( $Image, imagecolorallocate ( $Image, $R, $G, $B ) ); + } + + + function Resize($toX, $toY) + { + $cX = imagesx($this->original); + $cY = imagesy($this->original); + + $this->normalizeSize($toX, $cX, $toY, $cY); + + // skip it if there would be no size change + if ($toX == $cX && $toY == $cY) + { + $this->current = $this->original; + return true; + } + + $this->current = imagecreatetruecolor ( $toX, $toY ); + $return = imagecopyresampled ( $this->current, + $this->original, + 0, + 0, + 0, + 0, + $toX, + $toY, + $cX, + $cY); + } + + + function writeImg($path, $which='current') + { + if ($which == 'current') + { + imagepng($this->current, $path); + } + else + { + imagepng($this->original, $path); + } + } + + + function writeImgToBrowser() + { + header ("Content-type: image/png"); + imagepng ($this->current); + } + + + function loadCurrent() + { + $this->original = $this->current; + $this->current = false; + } + } + + + + class scRegionImg extends scImg + { + var $tilearray; // string containing html Image Map coords + var $Imap; // holds image map coordinates if needed + + function drawEntireRegion($region, $doImap=false) + { + $this->status = true; + $this->tilearray = array(); + + $sql = "SELECT id,name,sizeX,sizeY,locX,locY FROM cities WHERE region_id = {$region['id']}"; + $array = dbq($sql); + + $configBMP = configBMP($array); + + while(sizeof($array)) + { + foreach($array as $key => $item) + { + if ( tileCheck($item['locX'], $item['locY'], $item['sizeX'], $item['sizeX'], $configBMP) ) + { + $this->tilearray[] = $item; + unset($array[$key]); + $f=true; + } + } + + // check to make sure the loop placed at least 1 tile + // otherwise "we may have a problem Houston". + if ($f !== true) + return false; + else + $f = false; + } + + if( ! sizeof($this->tilearray) ) + { + $GLOBALS['SCORE']['errors'][] = "It appears there are no cities in this region. This is likely due to permissions - unreadable city files."; + $this->status = false; + return $this->status; + } + + unset($array); + + $maxX = 0; + $maxY = 0; + foreach($this->tilearray as $A) + { + ( ($A['locX'] + $A['sizeX']) > $maxX) ? ($maxX = ($A['locX'] + $A['sizeX'] ) ) : false ; + ( ($A['locY'] + $A['sizeY']) > $maxY) ? ($maxY = ($A['locY'] + $A['sizeY'] ) ) : false ; + + } + + $so[1]['X']=0; + $so[1]['Y']=0; + + $so[2]['X']=-35; + $so[2]['Y']=20; + + $so[4]['X']= -111; + $so[4]['Y']= 58; + + $this->current = imagecreatetruecolor( ($maxX*127)+(($maxX*127)*.01),($maxY*68)+(($maxY*68)*.01) ); + + foreach($this->tilearray as $key => $tile) + { + $this->Load(file_get_contents("{$GLOBALS['SCORE']['SC4IMG_PATH']}/{$region['name']}/{$tile['name']}.png")); + $Isize['X'] = imagesx($this->original); + $Isize['Y'] = imagesy($this->original); + + $YOffset = ($Isize['Y']) - (45 * $tile['sizeY']); + $ImageX = (-37 * $tile['locY'] + 1) + ($tile['locX'] * 90) + $so[$tile['sizeX']]['X'] + $maxX*127*0.27; + $ImageY = (45 * $tile['locY'] + 1) + ($tile['locX'] * 18) - $YOffset + $so[$tile['sizeY']]['Y']+50; + + /* + ** now that we've determined where this tile goes - copy it to our scratch (current) image + */ + if($doImap) + { + $this->Imap[$tile['id']] = array( + 'x1' => $ImageX + (0.29*$Isize['X'])+5, 'y1' => $ImageY, // top left + 'x2' => $ImageX +5, 'y2' => $ImageY+(0.744*($Isize['Y']-40)), // bottom left + 'x3' => $ImageX + (0.71*$Isize['X'])-5, 'y3' => ($ImageY+$Isize['Y']-30), // bottom right + 'x4' => ($ImageX + $Isize['X'])-5, 'y4' => $ImageY+(0.248*$Isize['Y']), // top right + 'x5' => $ImageX+ (0.29*$Isize['X']), 'y5' => $ImageY // top left (again) + ); + } + + + imagecopy ( $this->current, $this->original, $ImageX, $ImageY, 0, 0, $Isize['X'], $Isize['Y'] ); + } + } + } + + + function &configBMP ($array) + { + $maxX = $maxY = 0; + foreach($array as $A) + { + ( ($A['locX'] + $A['sizeX']) > $maxX) ? ($maxX = ($A['locX'] + $A['sizeX'] - 1 ) ) : false ; + ( ($A['locY'] + $A['sizeY']) > $maxY) ? ($maxY = ($A['locY'] + $A['sizeY'] - 1 ) ) : false ; + + } + + $img = imagecreatetruecolor($maxX+1, $maxY+1); + $white = imagecolorallocate($img, 255,255,255); + $c[1] = imagecolorallocate($img, 255,0,0); + $c[2] = imagecolorallocate($img, 0,255,0); + $c[4] = imagecolorallocate($img, 0,0,255); + + foreach($array as $tile) + { + foreach($array as $tile) + for($x=$tile['locX']; $x <= (($tile['locX']) + ($tile['sizeX']-1)); $x++ ) + for($y=$tile['locY']; $y <= (($tile['locY']) + ($tile['sizeY']-1)); $y++ ) + imagesetpixel ( $img, $x, $y, $c[$tile['sizeY']] ); + } + + + return $img; + } + + + function tileCheck($x,$y,$xSize,$ySize,&$configBMP) + { + $imageX = imagesx($configBMP); + $imageY = imagesy($configBMP); + + $blk= imagecolorallocate ( $configBMP, 0, 0, 0 ); + + if ($y > 0) + for($n=0; $n < $xSize; $n++) + if ( imagecolorat($configBMP, $x+$n, $y-1 ) != $blk ) + return false; + + + if ($x > 0) + for($n=0; $n < $ySize; $n++) + if ( imagecolorat($configBMP, $x-1, $y+$n) != $blk ) + return false; + + + for ($imgX=$x; $imgX < ($x + $xSize); $imgX++) + for ($imgY=$y; $imgY < ($y + $ySize); $imgY++) + imagesetpixel($configBMP, $imgX, $imgY, $blk); + + return true; + } + + + + class scFile extends scBaseClass + { + + + var $data; // file resource + var $length = 0; // file_data length + + function Load($file) + { + if (file_exists($file) && is_readable($file) ){ + $this->data = file_get_contents($file); + $this->length = strlen($this->data); + $this->status = true; + } else { + $this->status = false; + return $this->status; + } + } + + + function getContents() + { + //print_Array($this->dir_content); + return $this->file_data; + } + + + function unLoad() + { + $this->data = ''; + } + } + + + class scSaveGameFile extends scFile + { + + var $indexes = array(); // stores the parsed indexes from file + var $contents = array(); // anything extracted frm file goes in this array + + function scSaveGameFile () + { + require('php_inc/regionFileDecode_inc.php'); + } + + + function isSane() + { + // file big enough? + if(! strlen($this->data) > 11) + { + $this->status=false; + return false; + } + + $this->contents['major_version'] = unpack1(substr($this->data,4,4),'V'); + $this->contents['minor_version'] = unpack1(substr($this->data,8,4),'V'); + + // return valid version #? + if ($this->contents['major_version'] == '1' && $this->contents['minor_version'] == '0') + { + return '1.0'; + } else { + false; + } + } + + function locateIndex($TGI) + { + + if(! is_array($this->indexes) ) + return false; + + foreach($this->indexes as $key=>$index) + { + $dat = unpack('V*',substr($index,0,20)); + //decho( strtolower(dechex($dat[1])) .'=='. strtolower($TGI[0]) .'&&'. strtolower(dechex($dat[2])) .'=='. strtolower($TGI[1]) .'&&'. strtolower(dechex($dat[3])) .'=='. strtolower($TGI[2]) ); + if( strtolower(dechex($dat[1])) == strtolower($TGI[0]) && strtolower(dechex($dat[2])) == strtolower($TGI[1]) && strtolower(dechex($dat[3])) == strtolower($TGI[2])) + return $dat; + } + + return false; + } + + + function parseRegionFileData($Cname='unknown') + { + + $TGI = array('ca027edb', 'ca027ee1', '00'); + $index = $this->locateIndex($TGI); + + if(!$index) + return false; + + //decho ("grabbing region file at {$dat[4]} thru {$dat[5]} bytes"); + $RF = substr($this->data, $index[4], $index[5]); + unset($dat); + + $RF = fileDecode($RF, $Cname); + + $RFstring = implode($RF,''); + unset($RF); + + $this->contents['rvmj'] = unpack1(substr($RFstring,0,2),'v'); + $this->contents['rvmi'] =unpack1(substr($RFstring,2,4),'v'); + + $this->contents['locX'] = unpack1(substr($RFstring,4,4)); + $this->contents['locY'] = unpack1(substr($RFstring,8,4)); + + $this->contents['sizeX'] = unpack1(substr($RFstring,12,4)); + $this->contents['sizeY'] = unpack1(substr($RFstring,16,4)); + + $this->contents['R'] = unpack1(substr($RFstring,20,4)); + $this->contents['C'] = unpack1(substr($RFstring,24,4)); + $this->contents['I'] = unpack1(substr($RFstring,28,4)); + + return true; + } + + + function parseDates() + { + if(! strlen($this->data) > 31) + { + $this->status=false; + return false; + } + + $this->contents['dateC'] = date('Y-m-d',unpack1(substr($this->data,24,4),'V')); + $this->contents['dateM'] = date('Y-m-d',unpack1(substr($this->data,28,4),'V')); + + return true; + } + + + function parseIndexes() { + if(! strlen($this->data) > 43) + { + $this->status = false; + return false; + } + + $num_indexes = unpack1(substr($this->data, 36, 4)); + $loc_indexes = unpack1(substr($this->data, 40, 4)); + + //decho("num_indexes: $num_indexes | loc_indexes: $loc_indexes"); + $tloc_indexes=$loc_indexes; + + for($i=0; $i < $num_indexes; $i++) + { + $this->indexes[$i] = substr($this->data, $tloc_indexes, 20); + $tloc_indexes+=20; + } + } + + + function parseMainImg() + { + $index = $this->locateIndex(array('8a2482b9', '4a2482bb', '00')); + if(!$index) + return false; + $this->contents['mainImg'] = substr( $this->data, $index[4] , $index[5] ); + } + + + function fullParse($Cname='unknown') + { // to handle doing all parse* methods in one go + if(! ($this->isSane() && $this->parseDates())) + { + $GLOBALS['SCORE']['errors'][] = 'File was found to be unsane.'; + return false; + } + + + $this->parseIndexes(); + $this->parseRegionFileData($Cname); + $this->parsemainImg(); + $this->parseMoney(); + } + + function parseMoney() + { + $TGI = array('e990BE01','299B2D1B','00000'); + $index = $this->locateIndex($TGI); + if ( ! $index ) + return false; + + $file = substr($this->data, $index[4], $index[5]); + unset($dat); + + $file = fileDecode($file, 'moneyFile'); + + $file = implode($file,''); + + // the money value is in the file at: + // long long long short quad-money-value + // 4 + 4 + 4 + 2 = 14 + $this->contents['money'] = unpack1(substr($file,14,4),'V'); + } + } + + + + class scDir extends scBaseClass + { + var $dir_content = array(); // contents of dir + + + // get $dir's contents + function Load($dir) + { + $this->dir_content = array(); + if (is_dir($dir)) { + if ($dh = opendir($dir)) { + while (($file = readdir($dh)) !== false) { + if($file != '.' && $file != '..') + $this->dir_content[@is_dir($dir .'/'. $file)][] = $file; // silence errors due to file not being readable + } + closedir($dh); + $this->status = true; + return; + } else { + $this->status = false; + return $this->status; + } + } else { + $this->status = false; + return $this->status; + } + } + + + function getDirContents() + { + if(isset($this->dir_content[1])) + return $this->dir_content[1]; + else + return false; + } + + function getFileContents() + { + if(isset($this->dir_content[0])) + return $this->dir_content[0]; + else + return false; + } + + function getAllContents() + { + if ( is_array($this->dir_content[0]) && is_array($this->dir_content[1]) ) + return array_merge($this->dir_content[0], $this->dir_content[1]); + elseif ( is_array($this->dir_content[0]) && !is_array($this->dir_content[1]) ) + return $this->dir_content[0]; + elseif ( !is_array($this->dir_content[0]) && is_array($this->dir_content[1]) ) + $this->dir_content[1]; + else + return false; + } + } + + + class scBaseClass + { + var $status; // last action's return + + function getStatus() + { + return $this->status; + } + + } + + + // class will be loaded with any values in $_REQUEST['sf'] + // at each load of score.php - these values have general validation + // performed on them such as confirming integers and basenaming file + // names, escaping text strings + class sc_REQUEST extends scBaseClass + { + var $values; // contains $_REQUEST values + var $types; // contains the data types we validate + + function sc_REQUEST() + { + // set the default state of class vars + $this->values = array(); + $this->types = array('TEXT','ID','FILE'); + + + // check if we have anything for us + if ( ! isset($_REQUEST['sf']) || ! is_array($_REQUEST['sf']) ) + return false; + + $this->values = $_REQUEST['sf']; + + // now call out validator functions + foreach($this->types as $type) + $this->validate($type); + + } + + + // these functions have to handle + // if instead of a single value + // its any number of sub arrays + // - so recursive behaviour. + function validate($type) + { + if ( ! isset($this->values[$type]) || ! is_array($this->values[$type]) ) + return false; + + // dynamic method call --- oooh beholds it's wonder and slendor + $this->{'validate'.$type}($this->values[$type]); + } + + + function validateTEXT(&$array) + { + foreach($array as $key => $val) + if ( is_array($val) ) + $this->validateTEXT($array[$key]); + else + $array[$key] = addslashes($val); + } + + function validateID(&$array) + { + // check for valid integer, unset if not + foreach( $array as $key => $val ) + if ( is_array($val) ) + $this->validateID($array[$key]); + else + if ( ! $this->isInt($val) ) + unset($array[$key]); + } + + function validateFILE(&$array) + { + // basename these values + foreach($array as $key => $val) + if ( is_array($val) ) + $this->validateFILE($array[$key]); + else + $array = basename($val); + + } + + function isInt($var) + { + // Determines if a variable's value is an integer regardless of type + // meant to be an analogy to PHP's is_numeric() + if (is_int($var)) return TRUE; + if (is_string($var) && $var === (string)(int) $var) return TRUE; + //if (is_float($var) and $var === (float)(int) $var) return TRUE; + else return FALSE; + } + + } + + + class sc_importErrorHandler + { + var $region_id; + var $region_name; + + function sc_importErrorHandler($rname, $rid=false) + { + $this->region_id = $rid; + $this->region_name = $rname; + set_error_handler(array(&$this, 'errorHandler')); + } + + function setRegionID($rid) + { + $this->region_id = $rid; + set_error_handler(array(&$this, 'errorHandler')); + } + + function errorHandler($errno, $errmsg, $filename, $linenum, $var) + { + $errortypes = array(2 => 'Warning', 8 => 'Notice'); + $GLOBALS['SCORE']['errors'][] = "There has been an error during the import: {$errortypes[$errno]} $errmsg in $filename on line $linenum."; + + // clean up regions and cities database + if(is_numeric($this->region_id)) + { + decho ("cleaning tables"); + dbq("DELETE FROM cities WHERE region_id='{$this->region_id}'"); + dbq("DELETE FROM regions WHERE id='{$this->region_id}'"); + } + + // clean up images directory + remove_dir("{$GLOBALS['SCORE']['SC4IMG_PATH']}/{$this->region_name}"); + } + } +?> \ No newline at end of file diff --git a/php_inc/database_inc.php b/php_inc/database_inc.php new file mode 100755 index 0000000..51813fe --- /dev/null +++ b/php_inc/database_inc.php @@ -0,0 +1,68 @@ + 0 ) { + while( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) + $array_result[] = $row; + + mysql_free_result($result); + return $array_result; + } else { + return array(); + } + } + + return $result; + } + +?> \ No newline at end of file diff --git a/php_inc/iframe_inc.php b/php_inc/iframe_inc.php new file mode 100755 index 0000000..23a85fb --- /dev/null +++ b/php_inc/iframe_inc.php @@ -0,0 +1,55 @@ +data['Cities']) ) + $scRegion->getCityList(); + + echo " + "; + foreach($scRegion->data['Cities'] as $city) + { + echo " + " . html_generate_Imap($city,$scRegion->data['imagemap'][$city['id']]); + } + echo " + "; + $rand = rand(); + echo " + data['name']}/{$GLOBALS['SCORE']['scRegion']->data['name']}.png?nocache={$rand}\" usemap=\"#citymap\" border=\"none\">"; + + + $_SESSION['score_lib'] = 'region'; + } + + function html_generate_Imap($city,$Imap) + { + $html_Imap = " + "; + + return $html_Imap; + } + +?> \ No newline at end of file diff --git a/php_inc/login_inc.php b/php_inc/login_inc.php new file mode 100755 index 0000000..a6815e5 --- /dev/null +++ b/php_inc/login_inc.php @@ -0,0 +1,36 @@ +values['TEXT']['score_login']) && isset($sc_REQUEST->values['TEXT']['score_pass']) ) + { + $login_result = dbq("SELECT * FROM users WHERE login='{$sc_REQUEST->values['TEXT']['score_login']}' AND pass='{$sc_REQUEST->values['TEXT']['score_pass']}'"); + // valid login? + + if ( $login_result && sizeof($login_result) === 1 && $login_result[0]['login'] == $_POST['sf']['TEXT']['score_login'] && $login_result[0]['pass'] == $_POST['sf']['TEXT']['score_pass']) + { + // login looks good + // - setup general session info regarding user in question + $_SESSION['score_user'] = new scUser($login_result[0]); + $_SESSION['score_lib'] = 'main'; + unset($_SESSION['score_guest']); + dbq("UPDATE users SET lastlastlogin=users.lastlogin, lastlogin=now(), flagged_idle=NULL WHERE id={$_SESSION['score_user']->data['id']}"); + } + } + + // either way we'll redirect them + header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/".basename($_SERVER['PHP_SELF'])); + } + + + function show_public_register() + { + if(strtolower($GLOBALS['SCORE']['PUBLIC_REG']) === 'on' ) + echo "(Register)"; + else + echo ' '; + } +?> \ No newline at end of file diff --git a/php_inc/main_inc.php b/php_inc/main_inc.php new file mode 100755 index 0000000..c1aedb4 --- /dev/null +++ b/php_inc/main_inc.php @@ -0,0 +1,315 @@ +"; + foreach($regions as $key=>$region) + { + echo " +
+ + + + + + + + {$region['name']} + +
+ - Created: {$region['created']} +
+ - Updated: {$region['modified']} +

+ - TotalPop: ".number_format($region['total_pop'])." +
+    + R: ".number_format($region['total_R'])." +
+    + C: ".number_format($region['total_C'])." +
+    + I: ".number_format($region['total_I'])." +

+ - Total Funds: $".number_format($region['total_money'])." +

+ + +

+ ".nl2br($region['description'])." +
+ + + "; + + // are we making available zip archives of each region? + echo "
"; + if (strtolower($GLOBALS['SCORE']['USE_ZIP']) == 'on' && strtolower($region['complete_region_dl']) == 'on') + echo " + "; + + // do we have config.bmp and terrain maps for this region? + if (is_file("{$GLOBALS['SCORE']['SC4PATH']}/{$region['name']}/config.bmp")) + echo " + "; + + if(is_file("{$GLOBALS['SCORE']['SC4PATH']}/{$region['name']}/terrain.jpg")) + echo " + "; + + if(is_file("{$GLOBALS['SCORE']['SC4PATH']}/{$region['name']}/terrain.png")) + echo " + "; + + if(is_file("{$GLOBALS['SCORE']['SC4PATH']}/{$region['name']}/terrain.bmp")) + echo " + "; + + // close out the div + echo " +
+
+
+ "; + } + } + + + function clearUserMessages() + { + if( ! is_numeric($_SESSION['score_user']->data['id']) ) + return false; + + dbq("DELETE FROM messages WHERE type='user' AND relation_id='{$_SESSION['score_user']->data['id']}'"); + } + + + function html_show_your_messages() + { + if ( ! is_numeric($_SESSION['score_user']->data['id']) ) + return false; + + $messages = dbq("SELECT * FROM messages WHERE type='user' AND relation_id='{$_SESSION['score_user']->data['id']}' ORDER BY created"); + + if(sizeof($messages) < 1) + { + echo "

You have no messages.

"; + return false; + } + + foreach($messages as $m) + { + echo + "

+ - {$m['text']} -- {$m['created']} +
+ "; + } + + echo + " +

+

+ + "; + } + + + + function html_show_your_cities () + { + $sql = "SELECT r.id rid,r.checkout_timelimit, r.name rname, c.id cid, c.name cname, c.pop, c.R, c.C, c.I, c.created, c.modified, c.mayor_id, c.requested_mayor_id, c.checkout FROM cities c, regions r WHERE (c.mayor_id='{$_SESSION['score_user']->data['id']}' OR c.requested_mayor_id='{$_SESSION['score_user']->data['id']}') AND c.region_id=r.id ORDER BY r.name"; + $myCities = dbq($sql); + + if(sizeof($myCities) < 1) + { + echo "

You are not currently playing a city.

"; + return false; + } + + + + // prep vars for html + $php_self = basename($_SERVER['PHP_SELF']); + + + foreach($myCities as $city) + { + if ( $city['mayor_id'] ) + { + $checkout = strtotime($city['checkout']); + $now = time(); + $days_as_mayor = ceil(($now - $checkout)/60/60/24); + + // show optional time remaining for regions with checkout timelimits + if ($city['checkout_timelimit'] > 0) + { + $remainder = ($city['checkout_timelimit'] - $days_as_mayor); + $checkout_limit_html = " You have $remainder days left."; + } else { + $checkout_limit_html = ''; + } + + echo " + {$city['cname']} of {$city['rname']} +
+ - You've been mayor for {$days_as_mayor} days. $checkout_limit_html +

+ "; + + } elseif ($city['requested_mayor_id']) { + echo " + {$city['cname']} of {$city['rname']} +
+ - You have requested a term as mayor of this city. +

+ "; + } + } + } + + + function downloadRegionZip() + { + if( ! strtolower($GLOBALS['SCORE']['USE_ZIP']) == 'on' ) + return false; + + if( ! isset($_REQUEST['id']) || ! is_numeric($_REQUEST['id'])) + return false; + + $region = new scRegion($_REQUEST['id']); + if ( ! $region->status) + { + return false; + } + + if (! strtolower($region->data['complete_region_dl']) == 'on') + return false; + + require('php_inc/zip_inc.php'); + + $rDir = new scDir(); + $rDir->Load("{$GLOBALS['SCORE']['SC4PATH']}/{$region->data['name']}"); + + if(! $rDir->status) + return false; + + $regionZip = new zipfile(); + + foreach($rDir->getFileContents() as $file) + { + $regionZip->addFile(file_get_contents("{$GLOBALS['SCORE']['SC4PATH']}/{$region->data['name']}/$file"), "{$region->data['name']}/{$file}"); + } + + header("Content-type: application/zip"); + header("Content-Disposition: attachment; filename=".str_replace(' ', '_', $region->data['name']).".zip"); + header("Content-Length: ".strlen($regionZip->file())); + echo($regionZip->file()); + } + + + + function html_show_admins_cityrequests() + { + if(! $_SESSION['score_user']->data['privileges'] > 100) + return false; + + $city_requests = dbq("SELECT c.id cityid, c.name cityname, r.id regionid, r.name regionname, u.id userid, u.login FROM cities c, regions r, users u WHERE c.requested_mayor_id IS NOT NULL AND c.region_id=r.id AND c.requested_mayor_id=u.id"); + + if (empty($city_requests)) + return false; + + + echo" +

+
+ Pending City Requests +
+
+
+ +
+   +
+
+ Yes | No +
+ "; + + foreach($city_requests as $r) + { + echo + " +
+ {$r['login']} requests {$r['cityname']} in {$r['regionname']}. +
+
+ + +
+
+ "; + } + + echo" +
+ +
+ +
+
+
+ "; + } + + function AnswerRequests() + { + if(! $_SESSION['score_user']->data['privileges'] > 100) + return false; + + $SC =& $GLOBALS['SCORE']['sc_REQUEST']; + + if( ! isset($SC->values['TEXT']['auth_city']) || ! is_array($SC->values['TEXT']['auth_city']) ) + return false; + + foreach( $SC->values['TEXT']['auth_city'] as $cityid => $response) + handleRequestResponse($cityid, $response); + + } + + + function handleRequestResponse($cityid, $response) + { + // lookup this info from the database + $dbdata = dbq("SELECT c.id cityid, c.name cityname, c.requested_mayor_id, r.id regionid, r.name regionname FROM cities c, regions r WHERE c.region_id=r.id AND c.id='$cityid'"); + + if(empty($dbdata)) + return false; + + // set request flag to null on city, set mayor id to new mayor id if 'yes' given + // send user a message informing them of if they were approved or denied + if($response == 'yes') + { + dbq("UPDATE cities SET requested_mayor_id=NULL, mayor_id='{$dbdata[0]['requested_mayor_id']}',checkout=now() WHERE id='{$cityid}' LIMIT 1"); + add_message('user', $dbdata[0]['requested_mayor_id'], "Your request for term as mayor of {$dbdata[0]['cityname']} in {$dbdata[0]['regionname']} has been granted."); + } elseif($response == 'no') { + dbq("UPDATE cities SET requested_mayor_id=NULL WHERE id='{$cityid}' LIMIT 1"); + add_message('user', $dbdata[0]['requested_mayor_id'], "Your request for term as mayor of {$dbdata[0]['cityname']} in {$dbdata[0]['regionname']} has been denied."); + } + } +?> \ No newline at end of file diff --git a/php_inc/popup_inc.php b/php_inc/popup_inc.php new file mode 100755 index 0000000..a69e0b2 --- /dev/null +++ b/php_inc/popup_inc.php @@ -0,0 +1,25 @@ +'; + + + if ( ! isset($GLOBALS['SCORE']['sc_REQUEST']->values['ID']['cityid']) ) + return false; + + $history = dbq("SELECT text,created FROM city_log WHERE city_id='{$GLOBALS['SCORE']['sc_REQUEST']->values['ID']['cityid']}' ORDER BY created"); + + if ( sizeof($history) ) + foreach ($history as $entry) + $GLOBALS['SCORE']['popup_output'] .= " +
-{$entry['created']} -- {$entry['text']}
+ "; + else + $GLOBALS['SCORE']['popup_output'] .= 'No history yet.'; + + $GLOBALS['SCORE']['popup_output'] .= '

'; + + } + +?> \ No newline at end of file diff --git a/php_inc/regionFileDecode_inc.php b/php_inc/regionFileDecode_inc.php new file mode 100755 index 0000000..810b3bb --- /dev/null +++ b/php_inc/regionFileDecode_inc.php @@ -0,0 +1,115 @@ +>2)+3; + $offset=(($packcode>>5)<<8)+$a+1; + mmemcpy($outbuf,$outpos,$outbuf,$outpos-$offset,$lenb); + $outpos+=$lenb; + //decho ("Code $packcode len plain: $lena len: $lenb offset: $offset outpos: $outpos"); + } + else if (!($packcode&0x40)) { + //decho('match 0x40'); + $lena=($a>>6)&3; + mmemcpy($outbuf,$outpos,$inbuf,$inpos+3,$lena); + $inpos+=$lena+3; + $outpos+=$lena; + $lenb=($packcode&0x3f)+4; + $offset=($a&0x3f)*256+$b+1; + mmemcpy($outbuf,$outpos,$outbuf,$outpos-$offset,$lenb); + $outpos+=$lenb; + //decho ("Code $packcode len plain: $lena len: $lenb offset: $offset outpos: $outpos"); + } + else if (!($packcode&0x20)) { + //decho('match 0x20'); + $c=unpack1($inbuf[$inpos+3],'C'); + $lena=$packcode&3; + mmemcpy($outbuf,$outpos,$inbuf,$inpos+4,$lena); + $inpos+=$lena+4; + $outpos+=$lena; + $lenb=(($packcode>>2)&3)*256+$c+5; + $offset=(($packcode&0x10)<<12)+256*$a+$b+1; + mmemcpy($outbuf,$outpos,$outbuf,$outpos-$offset,$lenb); + $outpos+=$lenb; + //decho ("Code $packcode len plain: $lena len: $lenb offset: $offset outpos: $outpos"); + } + else { + //decho('match 0x1f'); + $len=($packcode&0x1f)*4+4; + mmemcpy($outbuf,$outpos,$inbuf,$inpos+1,$len); + $inpos+=$len+1; + $outpos+=$len; + //decho ("Code $packcode Plain Chars: $len outpos: $outpos"); //Code 224 Plain Chars: 4 outpos: 0 + } + } + + /* trailing bytes + if (($inpos<$inlen)&&($outpos<$outlen)) { + mmemcpy($outbuf,$outpos,$inbuf,$inpos+1,unpack1($inbuf[$inpos],'C')&3); + $outpos+=unpack1($inbuf[$inpos],'C')&3; + } + */ + + /* + if ($outpos!=$outlen) + decho("Warning: bad length ? {$outpos} instead of {$outlen} with {$Cname}"); + */ + $buflen=$outlen; + return $outbuf; + } + + + + function mmemcpy(&$dest, $destpos, &$src, $srcpos, $len) + { + while ($len--) + { + //decho ("destpos: $destpos | srcpos: {$src[$srcpos]}"); + $dest[$destpos] = $src[$srcpos]; + + $destpos++; + $srcpos++; + } + } + + + function unpack1($bytes, $type=false) + { + if($type) + { + $dat = unpack("{$type}int",$bytes); + return $dat['int']; + } else { + $dat = unpack('Vint',$bytes); + return $dat['int']; + } + } +?> \ No newline at end of file diff --git a/php_inc/region_inc.php b/php_inc/region_inc.php new file mode 100755 index 0000000..8e8cab2 --- /dev/null +++ b/php_inc/region_inc.php @@ -0,0 +1,738 @@ +data['Cities']) ) + $scRegion->getCityList(); + + echo " + "; + foreach($scRegion->data['Cities'] as $city) + { + echo " + " . html_generate_Imap($city,$scRegion->data['imagemap'][$city['id']]); + } + echo " + "; + echo " + data['name']}/{$GLOBALS['SCORE']['scRegion']->data['name']}.png\" usemap=\"#citymap\" border=\"none\">"; + } + + + + function Upload () + { + + set_time_limit ( 120 ); + + $scRegion =& $GLOBALS['SCORE']['scRegion']; + if( ! isset($scRegion->data['Cities']) ) + $scRegion->getCityList(); + + // valid cityid who user is mayor of? + if(! isset($_REQUEST['cityid']) || ! isset($scRegion->data['Cities'][$_REQUEST['cityid']]) ) + { + $GLOBALS['SCORE']['errors'][] = "Could not load file \"{$_FILES['score_file']['name']}\" due to invalid cityid."; + unlink("temp/{$_FILES['score_file']['name']}"); + return false; + } + + // confirm this user is in fact the mayor of this city + if($scRegion->data['Cities'][$_REQUEST['cityid']]['mayor_id'] !== $_SESSION['score_user']->data['id']) + { + $GLOBALS['SCORE']['errors'][] = "Could not load file \"{$_FILES['score_file']['name']}\". You don't appear to be the mayor."; + unlink("temp/{$_FILES['score_file']['name']}"); + return false; + } + + + // did they upload any1pxg? + if ( ! is_array($_FILES['score_file']) ) + { + $GLOBALS['SCORE']['errors'][] = "The uploaded file exceeds the upload_max_filesize directive in php.ini."; + return false; + } + + if ( $_FILES['score_file']['error'] == 1 ) + { + $GLOBALS['SCORE']['errors'][] = "No file uploaded."; + return false; + } + + if ( $_FILES['score_file']['error'] == 3 ) + { + $GLOBALS['SCORE']['errors'][] = "The uploaded file was only partially uploaded."; + return false; + } + + if ( $_FILES['score_file']['error'] == 6 ) + { + $GLOBALS['SCORE']['errors'][] = "Missing a temporary folder."; + return false; + } + + if ( $_FILES['score_file']['error'] == 4 || $_FILES['score_file']['size'] < 1 ) + { + $GLOBALS['SCORE']['errors'][] = "No file uploaded."; + return false; + } + + // ensure no monkeybusiness with specifying filename with ../../../blah.sc4 + $_FILES['score_file']['name'] = basename($_FILES['score_file']['name']); + + // didn't seem to be able to read the file in it's temp location - so here is a new temp location + move_uploaded_file( $_FILES['score_file']['tmp_name'], "temp/{$_FILES['score_file']['name']}" ); + + // handle if its a zip file and zip is turned on + if ( substr($_FILES['score_file']['name'],-4) == '.zip') + { + if ( strtolower($GLOBALS['SCORE']['USE_ZIP']) != 'on') + { + $GLOBALS['SCORE']['errors'][] = "File \"{$_FILES['score_file']['name']}\" is zip format but currently Zip support is off - please upload the city file unzipped."; + unlink("temp/{$_FILES['score_file']['name']}"); + return false; + } + + decho("temp/{$_FILES['score_file']['name']}"); + $zip = zip_open("temp/{$_FILES['score_file']['name']}"); + if( ! $zip ) + { + $GLOBALS['SCORE']['errors'][] = "Could not open Zip file."; + //unlink("temp/{$_FILES['score_file']['name']}"); + return false; + } + + while($e = zip_read($zip)) + $zip_entries[] = $e; + + print_array($zip_entries); + + zip_close($zip); + unlink("temp/{$_FILES['score_file']['name']}"); + exit; + } + + + + // process data from file + $scFile = new scSaveGameFile(); + $scFile->Load("temp/{$_FILES['score_file']['name']}"); + + // check for proper Region dir + if( ! $scFile->status) + { + $GLOBALS['SCORE']['errors'][] = "Could not load file \"{$_FILES['score_file']['name']}\" into scFile Object."; + unlink("temp/{$_FILES['score_file']['name']}"); + return false; + } + + $scFile->fullParse($_FILES['score_file']['name']); + if( ! $scFile->status) + { + $GLOBALS['SCORE']['errors'][] = "Problem parsing file \"{$_FILES['score_file']['name']}\"."; + unlink("temp/{$_FILES['score_file']['name']}"); + return false; + } + + // check that this new file's location and size match the existing one - to ensure they're a match + if( + $scFile->contents['sizeX'] != $scRegion->data['Cities'][$_REQUEST['cityid']]['sizeX'] + || + $scFile->contents['sizeY'] != $scRegion->data['Cities'][$_REQUEST['cityid']]['sizeY'] + ) + { + $GLOBALS['SCORE']['errors'][] = "The city \"{$_FILES['score_file']['name']}\" doesn't appear to match the City your attempting to update"; + unlink("temp/{$_FILES['score_file']['name']}"); + return false; + } + + // checks city for valid last played location within a region + if($scRegion->data['cityloc_check'] == 'on') + { + if( + $scFile->contents['locX'] != $scRegion->data['Cities'][$_REQUEST['cityid']]['locX'] + || + $scFile->contents['locY'] != $scRegion->data['Cities'][$_REQUEST['cityid']]['locY'] + ) + { + $GLOBALS['SCORE']['errors'][] = "The city \"{$_FILES['score_file']['name']}\" doesn't appear to match the City your attempting to update"; + unlink("temp/{$_FILES['score_file']['name']}"); + return false; + } + } + + // process images + $scImage= new scImg(); + $scImage->Load($scFile->contents['mainImg']); + $scImage->Resize('66%', '66%'); + + $scImage->setAlphaTrans($scImage->current, false, false, 0,0,0); + $scImage->setAlphaTrans($scImage->original, false, true, 0,0,0); + + $scImage->writeImg("{$GLOBALS['SCORE']['SC4IMG_PATH']}/{$GLOBALS['SCORE']['scRegion']->data['name']}/" . substr($_FILES['score_file']['name'],0,-4) . "_thumb.png"); + $scImage->writeImg("{$GLOBALS['SCORE']['SC4IMG_PATH']}/{$GLOBALS['SCORE']['scRegion']->data['name']}/" . substr($_FILES['score_file']['name'],0,-4) . ".png", 'original'); + + // check for proper Region dir + if( ! is_dir("{$GLOBALS['SCORE']['SC4PATH']}/{$GLOBALS['SCORE']['scRegion']->data['name']}")) + { + $GLOBALS['SCORE']['errors'][] = "No directory to upload file \"{$_FILES['score_file']['name']}\" to region \"{$GLOBALS['SCORE']['scRegion']->data['name']}\"."; + unlink("temp/{$_FILES['score_file']['name']}"); + return false; + } + + // delete the existing city file + if( ! @unlink("{$GLOBALS['SCORE']['SC4PATH']}/{$GLOBALS['SCORE']['scRegion']->data['name']}/{$scRegion->data['Cities'][$_REQUEST['cityid']]['name']}.sc4")) + { + $GLOBALS['SCORE']['errors'][] = "The city \"{$_FILES['score_file']['name']}\" in \"{$GLOBALS['SCORE']['scRegion']->data['name']}\" region wouldn't delete. Permissions problem?"; + unlink("temp/{$_FILES['score_file']['name']}"); + return false; + } + + // copy the new one over + rename( "temp/{$_FILES['score_file']['name']}", "{$GLOBALS['SCORE']['SC4PATH']}/{$GLOBALS['SCORE']['scRegion']->data['name']}/{$_FILES['score_file']['name']}" ); + + // update the database + $sql = "UPDATE `regions` SET modified = now() WHERE id='{$GLOBALS['SCORE']['scRegion']->data['id']}'"; + dbsql($sql); + + updateRegionTotals($GLOBALS['SCORE']['scRegion']->data['id']); + + $tpop = $scFile->contents['R'] + $scFile->contents['C'] + $scFile->contents['I']; + $sql = "UPDATE `cities` SET modified = now(), R='{$scFile->contents['R']}',C='{$scFile->contents['C']}',I='{$scFile->contents['I']}', pop=R+C+I, money='{$scFile->contents['money']}', name='" . substr($_FILES['score_file']['name'],0,-4) . "' WHERE id='{$_REQUEST['cityid']}'"; + dbsql($sql); + + // regenerate the region image + gen_region_images($GLOBALS['SCORE']['scRegion']->data); + + // give user some feedback + $GLOBALS['SCORE']['errors'][] = "The city \"{$_FILES['score_file']['name']}\" was updated in \"{$GLOBALS['SCORE']['scRegion']->data['name']}\". Thank you for updating."; + + // update city history + add_city_log($_REQUEST['cityid'], "City update was uploaded."); + + } + + + function updateRegionTotals($rid) + { + $totals = dbq("SELECT SUM(R) R, + SUM(C) C, + SUM(I) I, + SUM(pop) pop, + SUM(money) money + FROM cities WHERE region_id=$rid"); + + dbq("UPDATE regions SET total_R={$totals[0]['R']}, + total_C={$totals[0]['C']}, + total_I={$totals[0]['I']}, + total_pop={$totals[0]['pop']}, + total_money={$totals[0]['money']} + WHERE id=$rid + "); + } + + + function checkoutCity() + { + $scRegion =& $GLOBALS['SCORE']['scRegion']; + + if( ! isset($scRegion->data['Cities']) ) + $scRegion->getCityList(); + + if ( ! isset($_REQUEST['cityid']) || ! is_numeric( $_REQUEST['cityid']) ) + return false; + + // ensure not already checked out + $city = &$scRegion->data['Cities'][$_REQUEST['cityid']]; + + if ( is_int($city['mayor_id']) ) + return false; + + // was this player the previous mayor of this city + if ( $_SESSION['score_user']->data['id'] == $city['last_mayor_id'] && $scRegion->data['checkout_timelimit'] > 0) + { + $GLOBALS['SCORE']['errors'][] = 'You can not take control of this city because you just played it.'; + return false; + } + + // check if city points are turned on for this city, and if the user has enough available. + if ( $scRegion->data['checkout_user_limit'] != '0' ) + { + $uCP = $scRegion->usedCityPoints(); + if ( ($uCP+$city['sizeX']) > $scRegion->data['checkout_user_limit']) + { + $GLOBALS['SCORE']['errors'][] = 'Becoming Mayor of this city would exceed your City-Points quota.'; + return false; + } + } + + $scRegion =& $GLOBALS['SCORE']['scRegion']; + $sql = "UPDATE cities SET mayor_id = {$_SESSION['score_user']->data['id']}, checkout=now() WHERE id='{$_REQUEST['cityid']}'"; + dbsql($sql); + + // update scRegion Cities list to reflect our new mayor + $scRegion->data['Cities'][$_REQUEST['cityid']]['mayor_id'] = $_SESSION['score_user']->data['id']; + + // nice feedback + $GLOBALS['SCORE']['errors'][] = "You are now mayor for this city. Thank you for playing"; + + add_city_log($_REQUEST['cityid'], "Mayor {$_SESSION['score_user']->data['login']} began a term."); + } + + + + function resignCity() + { + if( ! isset($_REQUEST['cityid']) || ! is_numeric($_REQUEST['cityid']) ) + return false; + + $scRegion =& $GLOBALS['SCORE']['scRegion']; + + if( ! isset($scRegion->data['Cities']) ) + $scRegion->getCityList(); + + // confirm this user is in fact the mayor of this city + if($scRegion->data['Cities'][$_REQUEST['cityid']]['mayor_id'] !== $_SESSION['score_user']->data['id']) + return false; + + $sql = "UPDATE cities SET mayor_id=NULL, last_mayor_id='{$_SESSION['score_user']->data['id']}', checkout=NULL WHERE id='{$_REQUEST['cityid']}'"; + dbsql($sql); + + // update the Cities array so html_ functions display current info + $scRegion->data['Cities'][$_REQUEST['cityid']]['mayor_id'] = ''; + + $GLOBALS['SCORE']['errors'][] = "You are no longer mayor for this city. Thank you for playing."; + + add_city_log($_REQUEST['cityid'], "Mayor {$_SESSION['score_user']->data['login']} resigned."); + } + + + + function downloadCityZip() + { + $scRegion =& $GLOBALS['SCORE']['scRegion']; + if( ! isset($scRegion) ) + return false; + + if( ! strtolower($GLOBALS['SCORE']['USE_ZIP']) == 'on' ) + return false; + + if( ! isset($_REQUEST['id']) || ! is_numeric($_REQUEST['id']) ) + return false; + + $city = dbq("SELECT name, id FROM cities WHERE id = '{$_REQUEST['id']}'"); + if ( ! sizeof($city) === 1) + return false; + $city = $city[0]; + + $file = "{$GLOBALS['SCORE']['SC4PATH']}/{$scRegion->data['name']}/{$city['name']}.sc4"; + if(! is_file($file) || ! is_readable ( $file ) ) + { + $GLOBALS['SCORE']['errors'][] = 'Could not read/locate city file - contact the admin.'; + } + + $Cdat = file_get_contents($file); + if ( ! strlen($Cdat) ) + { + $GLOBALS['SCORE']['errors'][] = 'Zero length file. Could not read-in city file - contact the admin.?'; + } + + require('php_inc/zip_inc.php'); + $cityZip = new zipfile(); + $cityZip->addFile($Cdat, "{$city['name']}.sc4" ); + + ob_clean(); + header("Content-type: application/zip"); + header("Content-Disposition: attachment; filename=".str_replace(' ', '', $city['name']).".zip"); + header("Content-Length: ".strlen($cityZip->file())); + header("Accept-Ranges: bytes"); + echo($cityZip->file()); + } + + + function requestCity() + { + if ( ! isset($GLOBALS['SCORE']['sc_REQUEST']->values['ID']['cityid']) ) + return false; + + $cityid = $GLOBALS['SCORE']['sc_REQUEST']->values['ID']['cityid']; + + $scRegion =& $GLOBALS['SCORE']['scRegion']; + if( ! isset($scRegion->data['Cities']) ) + $scRegion->getCityList(); + + $city = &$scRegion->data['Cities'][$cityid]; + + + // check if city points are turned on for this city, and if the user has enough available. + if ( $scRegion->data['checkout_user_limit'] != '0' ) + { + $uCP = $scRegion->usedCityPoints(); + if ( ($uCP+$city['sizeX']) > $scRegion->data['checkout_user_limit']) + { + $GLOBALS['SCORE']['errors'][] = 'Becoming Mayor of this city would exceed your City-Points quota.'; + return false; + } + } + + + // ensure this city isn't already requested + if ( $city['requested_mayor_id'] || $city['mayor_id'] ) + { + $GLOBALS['SCORE']['errors'][] = 'This city has already been requested by someone else.'; + return false; + } + + + // request this city + dbq("UPDATE cities SET requested_mayor_id='{$_SESSION['score_user']->data['id']}' WHERE id='{$cityid}'"); + + // update the array so html_ functions display current info + $city['requested_mayor_id'] = $_SESSION['score_user']->data['id']; + + // nice user feedback + $GLOBALS['SCORE']['errors'][] = 'You have now placed a request for a term as mayor of this city.'; + } + + + function cancelCityRequest() + { + if ( ! isset($GLOBALS['SCORE']['sc_REQUEST']->values['ID']['cityid']) ) + return false; + + $cityid = &$GLOBALS['SCORE']['sc_REQUEST']->values['ID']['cityid']; + + $scRegion =& $GLOBALS['SCORE']['scRegion']; + if( ! isset($scRegion->data['Cities']) ) + $scRegion->getCityList(); + + $city = &$scRegion->data['Cities'][$cityid]; + + // ensure people aren't cancelling requests for other people + if ( $city['requested_mayor_id'] != $_SESSION['score_user']->data['id'] ) + return false; + + // request this city + dbq("UPDATE cities SET requested_mayor_id=NULL WHERE id='{$cityid}'"); + + // update the array so html_ functions display current info + $city['requested_mayor_id'] = ''; + } + + + function html_show_user_stats() + { + $scRegion =& $GLOBALS['SCORE']['scRegion']; + + if( ! isset($scRegion->data['Cities']) ) + $scRegion->getCityList(); + + $php_self = basename($_SERVER['PHP_SELF']); + + echo " +

+
Mayor Info
+
+ "; + + // show player's cities + echo "Your Cities:
"; + + if ( sizeof($scRegion->data['Cities']) ) + { + $list = ''; + foreach($scRegion->data['Cities'] as $city) + { + if($city['mayor_id'] == $_SESSION['score_user']->data['id']) + { + $list .= " +  {$city['name']}
"; + } elseif ($city['requested_mayor_id'] == $_SESSION['score_user']->data['id']) { + $list .= " +  {$city['name']} (requested)
"; + } + } + echo $list; + } else { + echo " None
"; + } + + + // show city-points + if( $scRegion->data['checkout_user_limit'] != '0' ) + { + $uCP = $scRegion->usedCityPoints(); + $uCP = $scRegion->data['checkout_user_limit'] - $uCP; + echo "City-Points: {$uCP}/{$scRegion->data['checkout_user_limit']}"; + } + + echo " +
+
"; + } + + + + function html_show_city_data() + { + $scRegion =& $GLOBALS['SCORE']['scRegion']; + if( ! isset($scRegion->data['Cities']) ) + $scRegion->getCityList(); + + echo "
+
+
City Info
+
+ Click the image to the right to select a city. +
+
+ "; + + $citySizes = array(1 => 'Small', 2 => 'Medium', 4=>'Large'); + + // for each city spit out the html we need + foreach($scRegion->data['Cities'] as $city) + { + + + + // show link to sign on as mayor or resign as mayor + if($city['mayor_id']) + { + $scMayor = new scMayor($city['mayor_id']); + $mayor_html = " + data['email']}\">{$scMayor->data['login']}"; + if($city['mayor_id'] == $_SESSION['score_user']->data['id']) + $mayor_html .= " + (Resign)"; + } + elseif ($city['requested_mayor_id']) + { + $request_mayor = dbq("SELECT * FROM users WHERE id='{$city['requested_mayor_id']}'"); + $mayor_html = " + Requested by {$request_mayor[0]['login']}"; + if($city['requested_mayor_id'] == $_SESSION['score_user']->data['id']) + $mayor_html .= " + (Cancel)"; + } + else + { + // not currently owned by a user if user has enough + // city-points or city-points limit isn't in effect + // determine if checkout is by authorization or not + + // tally up city-points for this person mayor + $uCP = $scRegion->usedCityPoints(); + + + if ( $scRegion->data['checkout_user_limit'] != '0' && ($uCP+$city['sizeX']) > $scRegion->data['checkout_user_limit'] ) + { + $mayor_html = "None"; + + } else { + if ( $scRegion->data['checkout_req_auth'] == 'on') + { + $mayor_html = " + Request Term"; + } else { + $mayor_html = " + Begin Term"; + } + } + } + + + + // are we making available zip download? + + + if (strtolower($GLOBALS['SCORE']['USE_ZIP']) == 'on' ) + $zipahref = " + (Zipped)"; + else + $zipahref = ''; + + $ahref= " + data['name']}/{$city['name']}.sc4\" title=\"Download this city\">{$city['name']}"; + + + // need an upload form? + if($city['mayor_id'] == $_SESSION['score_user']->data['id']) + { + $form = " +

+ City Upload: + (.sc4 files only please) + +

+ + + +
+ "; + } else { + $form =''; + } + + + if ($scRegion->data['checkout_user_limit'] != 0) + $city_point_cost="(City-Point Cost: {$city['sizeX']})"; + else + $city_point_cost=''; + + // output the stats + echo " +
+
City Info
+
+ $ahref + (City History) +
+ {$zipahref} +
+ Current Mayor: {$mayor_html} +

+ + data['name']}/{$city['name']}.png', 'FullSize', 'menubar=no,toolbar=no,resizable,height=300,width=530'), FullSize.focus()\" title=\"View Full Size\"> + data['name']}/{$city['name']}_thumb.png\" border=\"none\" id=\"city_image_{$city['id']}\"> + + + +

+ - Size: {$citySizes[$city['sizeX']]} $city_point_cost +
+ - Created: {$city['created']} +
+ - Updated: {$city['modified']} +
+ - TotalPop: ".number_format($city['pop'])." +
+    + R: ".number_format($city['R'])." +
+    + C: ".number_format($city['C'])." +
+    + I: ".number_format($city['I'])." +
+ - Total Funds: $".number_format($city['money'])." + $form +

+
+ "; + + } //end for loop + echo "
"; //end id=cib div + } // end function + + + + function html_show_whois_playing_which_cities() + { + $scRegion =& $GLOBALS['SCORE']['scRegion']; + $inPlay = dbq("SELECT u.login, c.id, c.name FROM cities c, users u WHERE c.region_id={$scRegion->data['id']} AND c.mayor_id=u.id AND mayor_id IS NOT NULL ORDER BY c.mayor_id"); + + if(sizeof($inPlay)) + { + echo " +
+
Who's Playing?
+
+ "; + $i=0; $output = ''; + foreach($inPlay as $city) + { + // if mayor has more than one city? + if(!isset($inPlay[$i-1]['login']) || $city['login'] != $inPlay[$i-1]['login']) + { + $output .= " + {$city['login']} is playing: + + + {$city['name']}"; + + // append break? + if( ! isset($inPlay[$i+1]['login']) || $city['login'] != $inPlay[$i+1]['login']) + $output .= "
"; + + } elseif ($city['login'] == $inPlay[$i-1]['login']) { + $output .= ", {$city['name']}"; + + // append break? + if( !isset($inPlay[$i+1]['login']) || $city['login'] != $inPlay[$i+1]['login']) + $output .= "
"; + } + + $i++; + } + + echo $output; + + echo " +
+
+ "; + } + //print_array($dbq); + } + + + function html_show_updated_cities() + { + if(! $_SESSION['score_user']->data['lastlastlogin'] ) + return false; + + $scRegion =& $GLOBALS['SCORE']['scRegion']; + if( ! isset($scRegion->data['Cities']) ) + $scRegion->getCityList(); + + $output = ''; + $count = 0; + + $output .= " +
+
Cities Updated Since Your Last Login
+
+ "; + foreach($scRegion->data['Cities'] as $id => $city) + { + // if the city isn't owned by the current user + // + if( $city['mayor_id'] != $_SESSION['score_user']->data['id'] && strtotime($city['modified']) > strtotime($_SESSION['score_user']->data['lastlastlogin']) ) + { + $count++; + $output .= " + {$city['name']}, "; + } + } + + + if($count) + { + $output = substr($output, 0, -2); + $output .= " +
+
"; + echo $output; + } + + } +?> \ No newline at end of file diff --git a/php_inc/register_inc.php b/php_inc/register_inc.php new file mode 100755 index 0000000..29ec253 --- /dev/null +++ b/php_inc/register_inc.php @@ -0,0 +1,138 @@ +values['TEXT']['score_register']['login']}'"; + $r = dbq($sql); + + if( sizeof($r) ) + { + $GLOBALS['SCORE']['errors'][] = 'This login is taken already, try another.'; + return false; + } + + + // check database that this email doesn't already exist in the database + $sql = "SELECT email FROM users WHERE email='{$srv->values['TEXT']['score_register']['email']}'"; + $r = dbq($sql); + + if( sizeof($r) ) + { + $GLOBALS['SCORE']['errors'][] = 'This email is taken already, try another.'; + return false; + } + + + // generate temporary password + // 48-57,65-90,97-122 + + //generate char array + $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; + $chars_length = strlen($chars); + $pass = ''; + for( $i=0; $i < 10; $i++ ) + $pass .= $chars[rand(0, $chars_length-1)]; + + + $body = " +Your SCORE Registration has been accepted. + +Your login is: +{$sr['login']} + +Your temporary password is: +{$pass} + +Please login here: +http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']} + +Thank-you for participating. +"; + + $headers = array('From' => $GLOBALS['SCORE']['ADMIN_EMAIL'],'Subject' => 'SCORE Registration Complete'); + + + if ( score_mail($sr['email'], $body, $headers) ) + { + $sql = "INSERT INTO users (login, pass, email, created) VALUES ('{$srv->values['TEXT']['score_register']['login']}','{$pass}', '{$srv->values['TEXT']['score_register']['email']}', now())"; + dbsql($sql); + $GLOBALS['register_ok'] = true; + } + + + } + + + + +function html_register_form() +{ + if( ! isset($GLOBALS['register_ok']) ) + { + echo " + +
+ Login +
+
+ +
+ +
+ Email +
+
+ +
+
+
+ (return to login) + + +
+ + "; + } else { + echo " +

+ Thank-you for Registering. An Email has been sent to the address you provided containing your temporary login password. +

+

+ "; + } +} + +?> \ No newline at end of file diff --git a/php_inc/sc4_extractor.php b/php_inc/sc4_extractor.php new file mode 100755 index 0000000..02b82c2 --- /dev/null +++ b/php_inc/sc4_extractor.php @@ -0,0 +1,43 @@ +"; + } + + class sc4 { + var $d=array(); //command line options + var $data=false; //buffer to store the file contents while operated upon. + var $png=array(); //image holder. + var $version='0.1Beta'; + + function sc4_extract_pngs() { + if(!$this->data) return false; + status_update('Extracting png images....'); + $s=$e=0; + while(($s=strpos($this->data,chr(hexdec(89)).'PNG',$s))!==false) { + $this->png[$i=sizeof($this->png)]=substr($this->data,$s,($e=strpos($this->data,'IEND',$s))-$s+4); + status_update('Processing image '.($i+1).' [ '.strlen($this->png[$i]).' bytes ] ....'); + $fp=fopen($this->d['f'].$i.'.png',"wb"); + fwrite($fp,$this->png[$i]); + fclose($fp); + $s=$e; + } + status_update('Processed '.sizeof($this->png).' images.'); + } + + function sc4() { + echo "\nsc4 extractor v{$this->version}\n"; + $this->d=getopt('f:'); + if ($this->d['f'] && file_exists($this->d['f'])) { + status_update('Opening file '.$this->d['f']); + $this->data=file_get_contents($this->d['f']); + status_update('Done [ '.strlen($this->data).' bytes ]'); + $this->sc4_extract_pngs(); + } else { + status_update('Could not open "'.$this->d['f'].'" for processing.'); + } + echo "done!\n"; + } + } + +?> \ No newline at end of file diff --git a/php_inc/score_inc.php b/php_inc/score_inc.php new file mode 100755 index 0000000..77f7aa2 --- /dev/null +++ b/php_inc/score_inc.php @@ -0,0 +1,533 @@ +data['privileges'] >= 100 ) + { + $GLOBALS['SCORE']['call_functions']['admin'][] = 'UpdateRegionSettings'; + $GLOBALS['SCORE']['call_functions']['admin'][] = 'UpdateSCORESettings'; + $GLOBALS['SCORE']['call_functions']['admin'][] = 'deleteRegion'; + $GLOBALS['SCORE']['call_functions']['admin'][] = 'ImportRegion'; + } + + /* + ** DEBUG FUNCTIONS + */ + + function decho($text) + { + echo $text . "\n
"; + } + + function print_array($array) + { + echo "
";
+		print_r($array);
+		echo "
"; + } + + + + /* + ** LIB/CALL Handling Functions + */ + + function func_request () { + + // valid function names have to be prefixed by lib used in lib_request + if(isset($_REQUEST['score_call'])) + { + // strip out spaces from form Submit buttons + $_REQUEST['score_call'] = str_replace(' ','',$_REQUEST['score_call']); + + if ( @in_array($_REQUEST['score_call'], $GLOBALS['SCORE']['call_functions'][$_SESSION['score_lib']]) + || + @in_array($_REQUEST['score_call'], $GLOBALS['SCORE']['call_functions']['score']) + ) + { + return $_REQUEST['score_call'](); + + } else { + + $GLOBALS['SCORE']['errors'][] = "Sorry, that function does not seem to exist."; + return false; + + } + + } else { + + return false; + + } + } + + + + function lib_request () { + // in future we'll make a preference file storing names of valid libs + if ( isset($_REQUEST['score_lib']) ) + { + $score_lib = basename($_REQUEST['score_lib']); + if ( isset($score_lib) && array_key_exists($score_lib, $GLOBALS['SCORE']['call_functions']) && file_exists("php_inc/{$score_lib}_inc.php") ) + { + $_SESSION['score_lib'] = $score_lib; + } else { + logout(); + return false; + } + } + + if (isset($_SESSION['score_lib'])) + { + include("php_inc/" . $_SESSION['score_lib'] . "_inc.php"); + } + + } + + + + /* + ** Score End-User Functions + */ + + function logout () { + // Unset all of the session variables. + session_unset(); + // Finally, destroy the session. + session_destroy(); + + echo " +
Logged Out - Session Over
+
+ (return to login) + "; + } + + + + /* + ** Purpose: generates the region images form the city tile images + ** + ** Called When: + ** - a city file update occurs + ** - region rebuild + */ + + function gen_region_images(&$region, $doImap=false) + { + // generate the region image + $scRegionImg = new scRegionImg(); + + $scRegionImg->drawEntireRegion($region, true); + if ($scRegionImg->status === false) + { + $GLOBALS['SCORE']['errors'][] = 'Could not generate Region Image'; + } + + $scRegionImg->loadCurrent(); + + // resize according to our settings in score_sys (y is proportionate) + $scRegionImg->Resize($GLOBALS['SCORE']['SC4REGION_IMG_WIDTH'],''); + + // determine scale for calculating the image map vectors + if ( substr($GLOBALS['SCORE']['SC4REGION_IMG_WIDTH'],-1) == '%' ) // if its in percent + $scale = substr($GLOBALS['SCORE']['SC4REGION_IMG_WIDTH'],0,-1) / (100); + else + $scale = (imagesx($scRegionImg->current)/$sizeX); + + + if($doImap) + { + if(isset($scale)) + $scRegionImg->Imap = scale_Imap($scRegionImg->Imap, $scale); + + $sql = "UPDATE regions SET imagemap='".mysql_real_escape_string(serialize($scRegionImg->Imap))."' WHERE id = {$region['id']}"; + dbsql($sql); + } + + $scRegionImg->setAlphaTrans($scRegionImg->current, false, false, 0,0,0); + $scRegionImg->writeImg("{$GLOBALS['SCORE']['SC4IMG_PATH']}/{$region['name']}/{$region['name']}.png"); + + /// generate thumbnail for region image + $scRegionImg->loadCurrent(); + $scRegionImg->Resize('258','149'); + $scRegionImg->setAlphaTrans($scRegionImg->current, false, false, 0,0,0); + $scRegionImg->writeImg("{$GLOBALS['SCORE']['SC4IMG_PATH']}/{$region['name']}/{$region['name']}_thumb.png"); + } + + + + /* + ** Purpose: provided with a valid Imap array (by the scRegionImg Class) + ** and a numeric to scale by, scale_Imap will adjust the Imap array by $scale. + ** For example, you resze the original region image smaller by 20% - so you + ** want to call scale_Imap to adjust the Imap vectors use $scale of 0.2 + ** + ** Called When: gen_region_images() is called with $doImap set to True + */ + function scale_Imap($Imap, $scale) + { + foreach($Imap as $key => $tile) + { + $Imap[$key]['x1'] = ceil($tile['x1'] * $scale); + $Imap[$key]['y1'] = ceil($tile['y1'] * $scale); + + $Imap[$key]['x2'] = ceil($tile['x2'] * $scale); + $Imap[$key]['y2'] = floor($tile['y2'] * $scale); + + $Imap[$key]['x3'] = floor($tile['x3'] * $scale); + $Imap[$key]['y3'] = floor($tile['y3'] * $scale); + + $Imap[$key]['x4'] = floor($tile['x4'] * $scale); + $Imap[$key]['y4'] = ceil($tile['y4'] * $scale); + + $Imap[$key]['x5'] = ceil($tile['x5'] * $scale); + $Imap[$key]['y5'] = ceil($tile['y5'] * $scale); + } + return $Imap; + } + + + + /* + ** Internal use functions + */ + + function write_file ($path, &$data) + { + if($fp=fopen($path,"wb")) + { + fwrite($fp, $data); + fclose($fp); + return true; + } else { + return false; + } + } + + + // part of a simple system for score to provider users + // with feedback/errors to their actions. Append your + // functions feedback to the $GLOBALS['SCORE']['errors'] + // array. The feedback will be displayed to the user + // automaticly. + function scoreErrorsOut() + { + if(! sizeof($GLOBALS['SCORE']['errors']) ) + return false; + + echo " +
+ "; + + foreach($GLOBALS['SCORE']['errors'] as $error) + { + echo $error; + } + + echo " +
+ "; + + } + + + // recursively removes specified dir and subcontents + function remove_dir($dir) + { + + if (file_exists($dir)) { + + $d=dir($dir); + while (false !== ($entry = $d->read()) ) { + if( $entry != "." && $entry != ".." ) { + if ( is_dir($dir."/".$entry) ){ + $dirs[] = $entry; + } else { + $files[] = $entry; + } + } + } + + $d->close(); + + if(isset($files)) + { + for($i=0; $i < sizeof($files); $i++){ + $fileresult=unlink($dir."/".$files[$i]); + } + } + + if(isset($dirs)) + { + for($i=0; $i < sizeof($dirs); $i++){ + remove_dir($dir."/".$dirs[$i]); + } + } + + $dirresult=rmdir($dir); + } + } + + + function isChecked($var_to_check) + { + if(strtolower($var_to_check) == 'on') + echo ' CHECKED'; + } + + function inputValue($var) + { + if (isset($var)) + echo $var; + } + + + function set_score_prefs() + { + if(! isset($GLOBALS['SCORE']) ) + $GLOBALS['SCORE'] = array(); + + $r = dbq('SELECT * FROM score_sys'); + $GLOBALS['SCORE'] = array_merge($GLOBALS['SCORE'],$r['0']); + $GLOBALS['SCORE']['SC4VERSIONS'] = unserialize($GLOBALS['SCORE']['SC4VERSIONS']); + } + + + function score_maintenance() + { + + // determine if time interval since last maintenance exceeds maintenance limit + if ( (time() - strtotime($GLOBALS['SCORE']['last_maintenance'])) > 14400) // 4 hours + { + // expires stale accounts that have never + // logged in after registering + sm_expire_stale_unregistered(); + + // do system wide maintenance + if ( $GLOBALS['SCORE']['idle_account_limit'] > 0 ) + sm_expire_stale_accounts(); + + // do region specific maintenance + $Regions = dbq("SELECT name, id, checkout_timelimit FROM regions"); + foreach($Regions as $region) + { + $Cities = dbq("SELECT m.login as mayor_name, m.id as mayor_id, c.name, c.id, c.modified, c.mayor_id, c.checkout FROM cities c, users m WHERE c.region_id='{$region['id']}' AND c.checkout IS NOT NULL AND c.mayor_id=m.id"); + + if ( $region['checkout_timelimit'] > 0 ) + sm_expire_cities($region, $Cities); + + /* abandoned due to time constraints + if ( $region['idle_city_limit'] > 0 ) + sm_expire_idle_cities($region, $Cities); + */ + } + + // update 'last_maintenance' + //dbq('UPDATE score_sys SET last_maintenance=now()'); + } + } + + +/* abandoned due to time constraints + // looks for cities that have been checked out + // but not updated for more than X days; send + // email notifications/messages and unasigns. + function sm_expire_idle_cities(&$region, &$Cities) + { + $day = 86400; + + // look for idle flagged cities + + foreach($Cities as $city) + { + // if last modified in seconds is < now + idle_city_limit_warn + $modified = strtotime($city['modified']); + $now = time(); + $limit = $region['idle_city_limit_warn'] * $day; + + if ( ($modified + $limit) < $now ) + decho("idle city limit warning: ".($modified + $limit)." < $now "); + } + } +*/ + + + // looks for cities past their checkout + // time-limit and resigns them. + function sm_expire_cities(&$region, &$Cities) + { + $day = 86400; + foreach($Cities as $city) + { + if ( ( strtotime($city['checkout']) + ($region['checkout_timelimit']*$day)) < time() ) + { + // resign this mayor + dbq("UPDATE cities SET mayor_id=NULL WHERE id='{$city['id']}'"); + add_message('user', $city['mayor_id'], "Your term as mayor of {$city['name']} in {$region['name']} has expired."); + add_city_log($city['id'], "Mayor {$city['mayor_name']} Resigns. (term expired)"); + } + } + } + + + // looks for accounts which haven't been + // used in X months and expires them + function sm_expire_stale_accounts() + { + // we'll be using this often + $day = 86400; + + // look for flagged stale accounts + $idleusers = dbq("SELECT id, flagged_idle FROM users WHERE flagged_idle IS NOT NULL AND `privileges` =0"); + + + foreach($idleusers as $user) + { + // if time since flagged_idle and now exceeds idle_account_limit_warn + $flagged_idle = strtotime($user['flagged_idle']); + $limit = $day*$GLOBALS['SCORE']['idle_account_limit']; + + if ( time() > ($flagged_idle+$limit) ) + { + // disasociate user from cities, messages & requests + dbq("UPDATE cities SET mayor_id=NULL WHERE mayor_id='{$user['id']}'"); + dbq("UPDATE cities SET requested_mayor_id=NULL WHERE requested_mayor_id='{$user['id']}'"); + dbq("DELETE FROM messages WHERE relation_id='{$user['id']}'"); + + // remove user + dbq("DELETE FROM users WHERE id='{$user['id']}'"); + } + } + + // flag any acitvated accounts as 'newly-stale' - as they say + // user's last login was more than idle_account_limit_warn (days) ago + $when = ( time() - ($day*$GLOBALS['SCORE']['idle_account_limit_warn']) ); + $when = date('Y-m-d', $when); //0000-00-00 00:00:00 + + // we'll need the email addresses of these users to notify them that their accounts will expire soon + $notify_users = dbq("SELECT email FROM users WHERE `lastlogin` < '{$when}' AND `flagged_idle` IS NULL AND `privileges` =0"); + + $headers = array('From' => $GLOBALS['SCORE']['ADMIN_EMAIL'],'Subject' => 'SCORE: Account Expiration'); + + foreach($notify_users as $user) + { + $body =" +This email is an automatic reminder that you have an active SCORE account at: +http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']} + +However the account will expire in {$GLOBALS['SCORE']['idle_account_limit']} days if you do not show renewed activity. + +Thank you. +"; + + $r = score_mail($user['email'], $body, $headers); + } + + $sql = "UPDATE users SET `flagged_idle`=now() WHERE `lastlogin` < '{$when}' AND `flagged_idle` IS NULL AND `privileges` =0"; + dbq($sql); + } + + // remove any stale accounts not activated - hard coded to 10 days + function sm_expire_stale_unregistered() + { + $day = 86400; + $when = ( time() - ($day*10) ); + $when = date('Y-m-d', $when); //0000-00-00 00:00:00 + dbq("DELETE FROM users WHERE created < '{$when}' AND lastlogin IS NULL AND `privileges` =0"); + } + + + function html_adminLink() + { + if ( $_SESSION['score_user']->data['privileges'] > 50 ) + { + echo " + | + Admin"; + } + } + + + + function add_message($type, $relation_id, $text) + { + dbq("INSERT INTO messages (type, relation_id, text, created) VALUES ('$type', '$relation_id', '$text', now());"); + } + + function add_city_log($city_id, $text) + { + dbq("INSERT INTO city_log (city_id, text, created) VALUES ('$city_id','$text', now())"); + } + + + /* handles all mail sending */ + function score_mail( $to, $body, $head) + { + if (! @require_once('Mail.php')) + { + $GLOBALS['SCORE']['errors'][] = "Could not include PEAR::Mail.php - Pear installed? Pear's Mail Class installed?"; + return false; + } + + if ( strlen(trim($GLOBALS['SCORE']['SMTP_HOST'])) ) // we got a specified smtp host + { + $auth_flag = (strlen(trim($GLOBALS['SCORE']['SMTP_USER']))) ? true : false; + $mailer_obj =& Mail::factory('smtp', array('host' => $GLOBALS['SCORE']['SMTP_HOST'], 'port' => '25', 'auth' => $auth_flag, 'username' => $GLOBALS['SCORE']['SMTP_USER'], 'password' => $GLOBALS['SCORE']['SMTP_PASS'])); + } else { + $mailer_obj =& Mail::factory('mail', "-f{$GLOBALS['SCORE']['ADMIN_EMAIL']}"); + } + + $r = $mailer_obj->send($to, $head, $body); + + if (PEAR::isError($r)) + { + decho("problem sending the email - result:" . print_array($r) ); + $GLOBALS['SCORE']['errors'][] = 'There was a problem sending mail: ' . $r->getMessage(); + return false; + } + + return true; + } + ?> \ No newline at end of file diff --git a/php_inc/settings_inc.php b/php_inc/settings_inc.php new file mode 100755 index 0000000..deeb287 --- /dev/null +++ b/php_inc/settings_inc.php @@ -0,0 +1 @@ +values['TEXT'][$el]}',"; } // update database values $update = substr($update,0,-1); $sql = "UPDATE users SET $update WHERE id='{$_SESSION['score_user']->data['id']}'"; // update session values if(dbsql ($sql)) foreach ($element_array as $el) $_SESSION['score_user']->data[$el] = $sfv->values['TEXT'][$el]; } function update_user_pass() { // just make this variable a little more convenient to use $sf =& $_REQUEST['sf']; $sfv =& $GLOBALS['SCORE']['sc_REQUEST']; // validated form data // doesn't entered password match users real current password? if ( $sf['TEXT']['current_password'] !== $_SESSION['score_user']->data['pass'] ) { $GLOBALS['SCORE']['errors'][] = "Password you entered does not match your current password."; return false; } // do both password1 and password2 match if ( $sf['TEXT']['new_password1'] !== $sf['TEXT']['new_password2'] ) { $GLOBALS['SCORE']['errors'][] = "Your new passwords didn't match"; return false; } // we can't have null passwords if ( strlen($sf['TEXT']['new_password1']) < 3) { $GLOBALS['SCORE']['errors'][] = "Your password is too short. It must be at least 3 characters."; return false; } // ok, then we can update dbq("UPDATE `users` SET pass='{$sfv->values['TEXT']['new_password1']}' WHERE id='{$_SESSION['score_user']->data['id']}' LIMIT 1"); $_SESSION['score_user']->data['pass'] = $sf['TEXT']['new_password1']; $GLOBALS['SCORE']['errors'][] = "Your password has been updated."; return true; } ?> \ No newline at end of file diff --git a/php_inc/zip_inc.php b/php_inc/zip_inc.php new file mode 100755 index 0000000..0e29076 --- /dev/null +++ b/php_inc/zip_inc.php @@ -0,0 +1,186 @@ + + * + * http://www.zend.com/codex.php?id=470&single=1 + * by Denis125 + * + * a patch from Peter Listiak for last modified + * date and time of the compressed file + * + * Official ZIP file format: http://www.pkware.com/appnote.txt + * + * @access public + */ +class zipfile +{ + /** + * Array to store compressed data + * + * @var array $datasec + */ + var $datasec = array(); + + /** + * Central directory + * + * @var array $ctrl_dir + */ + var $ctrl_dir = array(); + + /** + * End of central directory record + * + * @var string $eof_ctrl_dir + */ + var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; + + /** + * Last offset position + * + * @var integer $old_offset + */ + var $old_offset = 0; + + + /** + * Converts an Unix timestamp to a four byte DOS date and time format (date + * in high two bytes, time in low two bytes allowing magnitude comparison). + * + * @param integer the current Unix timestamp + * + * @return integer the current date in a four byte DOS format + * + * @access private + */ + function unix2DosTime($unixtime = 0) { + $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime); + + if ($timearray['year'] < 1980) { + $timearray['year'] = 1980; + $timearray['mon'] = 1; + $timearray['mday'] = 1; + $timearray['hours'] = 0; + $timearray['minutes'] = 0; + $timearray['seconds'] = 0; + } // end if + + return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | + ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); + } // end of the 'unix2DosTime()' method + + + /** + * Adds "file" to archive + * + * @param string file contents + * @param string name of the file in the archive (may contains the path) + * @param integer the current timestamp + * + * @access public + */ + function addFile($data, $name, $time = 0) + { + $name = str_replace('\\', '/', $name); + + $dtime = dechex($this->unix2DosTime($time)); + $hexdtime = '\x' . $dtime[6] . $dtime[7] + . '\x' . $dtime[4] . $dtime[5] + . '\x' . $dtime[2] . $dtime[3] + . '\x' . $dtime[0] . $dtime[1]; + eval('$hexdtime = "' . $hexdtime . '";'); + + $fr = "\x50\x4b\x03\x04"; + $fr .= "\x14\x00"; // ver needed to extract + $fr .= "\x00\x00"; // gen purpose bit flag + $fr .= "\x08\x00"; // compression method + $fr .= $hexdtime; // last mod time and date + + // "local file header" segment + $unc_len = strlen($data); + $crc = crc32($data); + $zdata = gzcompress($data); + $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug + $c_len = strlen($zdata); + $fr .= pack('V', $crc); // crc32 + $fr .= pack('V', $c_len); // compressed filesize + $fr .= pack('V', $unc_len); // uncompressed filesize + $fr .= pack('v', strlen($name)); // length of filename + $fr .= pack('v', 0); // extra field length + $fr .= $name; + + // "file data" segment + $fr .= $zdata; + + // "data descriptor" segment (optional but necessary if archive is not + // served as file) + $fr .= pack('V', $crc); // crc32 + $fr .= pack('V', $c_len); // compressed filesize + $fr .= pack('V', $unc_len); // uncompressed filesize + + // add this entry to array + $this -> datasec[] = $fr; + + // now add to central directory record + $cdrec = "\x50\x4b\x01\x02"; + $cdrec .= "\x00\x00"; // version made by + $cdrec .= "\x14\x00"; // version needed to extract + $cdrec .= "\x00\x00"; // gen purpose bit flag + $cdrec .= "\x08\x00"; // compression method + $cdrec .= $hexdtime; // last mod time & date + $cdrec .= pack('V', $crc); // crc32 + $cdrec .= pack('V', $c_len); // compressed filesize + $cdrec .= pack('V', $unc_len); // uncompressed filesize + $cdrec .= pack('v', strlen($name) ); // length of filename + $cdrec .= pack('v', 0 ); // extra field length + $cdrec .= pack('v', 0 ); // file comment length + $cdrec .= pack('v', 0 ); // disk number start + $cdrec .= pack('v', 0 ); // internal file attributes + $cdrec .= pack('V', 32 ); // external file attributes - 'archive' bit set + + $cdrec .= pack('V', $this -> old_offset ); // relative offset of local header + $this -> old_offset += strlen($fr); + + $cdrec .= $name; + + // optional extra field, file comment goes here + // save to central directory + $this -> ctrl_dir[] = $cdrec; + } // end of the 'addFile()' method + + + /** + * Dumps out file + * + * @return string the zipped file + * + * @access public + */ + function file() + { + $data = implode('', $this -> datasec); + $ctrldir = implode('', $this -> ctrl_dir); + + return + $data . + $ctrldir . + $this -> eof_ctrl_dir . + pack('v', sizeof($this -> ctrl_dir)) . // total # of entries "on this disk" + pack('v', sizeof($this -> ctrl_dir)) . // total # of entries overall + pack('V', strlen($ctrldir)) . // size of central dir + pack('V', strlen($data)) . // offset to start of central dir + "\x00\x00"; // .zip file comment length + } // end of the 'file()' method + +} // end of the 'zipfile' class +?> \ No newline at end of file diff --git a/score.css b/score.css new file mode 100755 index 0000000..a8876e2 --- /dev/null +++ b/score.css @@ -0,0 +1,234 @@ + /* + SimCity Online Region Exchange CSS + + COLORS + #4B572D + #A68A68 + #4A5D8D light blue + #4F5835 dark olive green + */ + + + + a { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 10px; + color: #4F5835; + text-decoration: none; + } + + a:hover { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 10px; + color: #4A5D8D; + text-decoration: underline; + } + + + .dark_bg-link + { + color: #FFFFFF; + } + + .dark_bg-link:hover + { + color: #FFFFFF; + text-decoration: underline; + } + + body { + font-family: Verdana, Arial, Helvetica, sans-serif; + margin: 1%; + padding: 0px; + font-size: 10px; + text-align: center; + vertical-align: middle; + border: 1px solid gray; + height: auto; + background-color: white; + } + + img { + border: none; + } + + iframe + { + margin: 5px 5px 5px 0px; + border: 1px solid black; + } + + + input, textarea, select, table td { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 10px; + } + + + .login_form + { + font-family: sans-serif; font-size: 10px; + border-bottom: thin solid grey; + border-right: thin solid grey; + width: 300px; + background-image: url("background.png"); + } + + #function_header + { + text-align: left; + height: 15px; + padding-left: 5px; + } + + + .background_color1 + { + background-color: #4F5835; + color: #EEEEEE; + } + + .background_color2 + { + background-color: #4A5D8D; + color: #EEEEEE; + } + + .background_image + { + background-image: url("background.png"); + } + + .title_text /* commonly used on region name */ + { + font-size: 11px; + font-weight: bold; + } + + + .title_text a { + font-family: Verdana, Arial, Helvetica, sans-serif; + color: #4F5835; + text-decoration: none; + font-size: 11px; + font-weight: bold; + } + + .title_text a:hover { + font-family: Verdana, Arial, Helvetica, sans-serif; + color: #4A5D8D; + text-decoration: underline; + font-size: 11px; + font-weight: bold; + } + + + .warn_text /* errors and user-function feedback */ + { + color: maroon; + text-align: left; + font-size: 12px; + font-weight: bold; + } + + /* + ** Column headers + */ + .column_header + { + /*margin: 0px 2px 0px 2px;*/ + text-align: center; + padding: 1px; + } + + .column_content + { + margin: 0px 2px 0px 2px; + text-align: left; + padding: 2px; + } + + + /* + ** generic style for making two column layouts + */ + .ldiv {float: left;} + .rdiv {text-align: right;} + + /* + ** main page layout + */ + .main_table + { + width:100%; + border: none; + padding: 0px; + margin: 0px; + height: 100%; + } + + .main_left_column + { + height: 100%; + border-right: 1px solid gray; + vertical-align: top; + width: 60%; + text-align: left; + } + + .main_right_column + { + height: 100%; + vertical-align: top; + width: 40%; + text-align: left; + } + + + + /* user stats (such as City-Points)*/ + .user_statusbar + { + border: 1px solid black; + background-color: white; + width: 345px; + text-align: left; + margin: 5px; + } + + .whos_playing + { + border: 1px solid black; + background-color: white; + width: 345px; + text-align: left; + margin: 5px; + } + + #updated_cities + { + border: 1px solid black; + background-color: white; + width: 345px; + text-align: left; + margin: 5px; + } + + /* + ** City View Div's + */ + + .city_info_box + { + border: 1px solid black; + text-align: center; + background-color: white; + width: 345px; + text-align: left; + margin: 5px; + } + + #main{ + width:100%; + height:100%; + } \ No newline at end of file diff --git a/score.js b/score.js new file mode 100755 index 0000000..45e5e42 --- /dev/null +++ b/score.js @@ -0,0 +1,54 @@ + +function toggle_node(x, untoggle_elements) { + + if(untoggle_elements) + { + node = document.getElementById(untoggle_elements) + cnodes = node.childNodes + + for(i=0; i < cnodes.length; i++) + { + node = cnodes.item(i) + if(node.nodeType == 1) + node.style.display = 'none' + } + } + + var node = document.getElementById('city_info_' + x) + var img = document.getElementById('city_image_' + x) + + // now that we know what the file name is + /* + if(img.getAttribute("loaded") == "false") + { + */ + LoadImage = new Image() + LoadImage.src = img.getAttribute("url") + img.src = LoadImage.src + '?nocache=' + Number.random + + // img.setAttribute("loaded", 'true') + //} + + +if (node.style.display == '') { + node.style.display = 'none' + } else { + node.style.display = '' + } +} + +function js_confirm($message) { + return (confirm($message)); +} + + +function refresh_city_img(id) +{ + +} + + +function refresh_region_img() +{ + +} \ No newline at end of file diff --git a/score.php b/score.php new file mode 100755 index 0000000..7d901c0 --- /dev/null +++ b/score.php @@ -0,0 +1,124 @@ +data['id']) || isset($_SESSION['score_guest']) ) + { + + // sometimes (like for the region view iFrame or for headers) + // we want to load score with out spewing content + if (! isset($_REQUEST['noheader'])) + include('html_inc/header.php'); + /* + ** Lib & Call handle what section of the site we're at and what functions to call + */ + + lib_request(); func_request(); + + // includes this library's html file + if (@is_numeric($_SESSION['score_user']->data['id']) || isset($_SESSION['score_guest'])) // still an existing session - checking again because func_request could have logged the user out + include("html_inc/{$_SESSION['score_lib']}_inc.php"); + + // sometimes (like for the region view iFrame or for headers) + // we want to load score with out spewing content + if (! isset($_REQUEST['noheader'])) + include('html_inc/footer.php'); + } + +/* DEBUG NONSENSE +decho ("
+
 
+ SESSION"); +if (isset($_SESSION)) + print_array($_SESSION); + +decho ("GET"); +if (isset($_GET)) + print_array($_GET); + +decho ("COOKIE"); +if (isset($_COOKIE)) + print_array($_COOKIE); + +decho ("POST"); +if (isset($_POST)) + print_array($_POST); + +decho ("GLOBAL"); +if (isset($GLOBALS['SCORE'])) + print_array($GLOBALS['SCORE']); +decho("
") +*/ +?> \ No newline at end of file diff --git a/score.sql b/score.sql new file mode 100755 index 0000000..743f504 --- /dev/null +++ b/score.sql @@ -0,0 +1,136 @@ +# +# Table structure for table `cities` +# + +CREATE TABLE `cities` ( + `id` mediumint(9) unsigned NOT NULL auto_increment, + `region_id` smallint(6) unsigned NOT NULL default '0', + `R` mediumint(9) unsigned default NULL, + `C` mediumint(9) unsigned default NULL, + `I` mediumint(9) unsigned default NULL, + `pop` mediumint(9) unsigned default NULL, + `name` varchar(255) NOT NULL default '', + `locX` tinyint(4) unsigned NOT NULL default '0', + `locY` tinyint(4) unsigned NOT NULL default '0', + `sizeX` tinyint(4) unsigned NOT NULL default '0', + `sizeY` tinyint(4) unsigned NOT NULL default '0', + `created` datetime NOT NULL default '0000-00-00 00:00:00', + `modified` datetime NOT NULL default '0000-00-00 00:00:00', + `mayor_id` mediumint(9) unsigned default NULL, + `checkout` datetime default NULL, + `money` int(11) default NULL, + `last_mayor_id` mediumint(9) default NULL, + `requested_mayor_id` mediumint(8) unsigned default NULL, + `file_size` mediumint(8) unsigned default NULL, + PRIMARY KEY (`id`) +) TYPE=MyISAM; + +# -------------------------------------------------------- + +# +# Table structure for table `city_log` +# + +CREATE TABLE `city_log` ( + `id` mediumint(8) unsigned NOT NULL auto_increment, + `city_id` mediumint(8) unsigned NOT NULL default '0', + `text` text, + `created` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`id`) +) TYPE=MyISAM; + +# -------------------------------------------------------- + +# +# Table structure for table `messages` +# + +CREATE TABLE `messages` ( + `id` mediumint(8) unsigned NOT NULL auto_increment, + `type` varchar(32) NOT NULL default '', + `relation_id` mediumint(8) unsigned NOT NULL default '0', + `text` text, + `created` datetime NOT NULL default '0000-00-00 00:00:00', + PRIMARY KEY (`id`) +) TYPE=MyISAM; + +# -------------------------------------------------------- + +# +# Table structure for table `regions` +# + +CREATE TABLE `regions` ( + `id` smallint(6) unsigned NOT NULL auto_increment, + `name` varchar(255) NOT NULL default '', + `total_pop` mediumint(9) unsigned default NULL, + `total_R` mediumint(9) unsigned default NULL, + `total_C` mediumint(9) unsigned default NULL, + `total_I` mediumint(9) unsigned default NULL, + `vrestrict` varchar(5) NOT NULL default '0', + `created` datetime NOT NULL default '0000-00-00 00:00:00', + `modified` datetime NOT NULL default '0000-00-00 00:00:00', + `imagemap` text, + `complete_region_dl` varchar(4) NOT NULL default 'on', + `checkout_req_auth` varchar(4) NOT NULL default 'off', + `checkout_user_limit` tinyint(3) unsigned NOT NULL default '0', + `checkout_timelimit` tinyint(3) unsigned NOT NULL default '0', + `total_money` int(11) default NULL, + `description` text, + `cityloc_check` varchar(4) NOT NULL default 'on', + PRIMARY KEY (`id`) +) TYPE=MyISAM; + +# -------------------------------------------------------- + +# +# Table structure for table `score_sys` +# + +CREATE TABLE `score_sys` ( + `name_id` varchar(16) NOT NULL default 'score_sy', + `PUBLIC_REG` varchar(4) NOT NULL default 'on', + `USE_ZIP` varchar(4) NOT NULL default 'on', + `SC4PATH` varchar(255) NOT NULL default 'Regions', + `SC4IMG_PATH` varchar(255) NOT NULL default 'Images', + `SC4REGION_IMG_WIDTH` varchar(6) NOT NULL default '800', + `SC4VERSIONS` varchar(255) NOT NULL default 'a:3:{s:16:"Rush/Hour Deluxe";s:4:"1.13";s:16:"SimCity Original";s:3:"1.9";s:11:"Any Version";s:1:"0";}', + `ADMIN_EMAIL` varchar(255) NOT NULL default '', + `ADMIN_NAME` varchar(255) NOT NULL default '', + `last_maintenance` datetime NOT NULL default '0000-00-00 00:00:00', + `idle_account_limit` tinyint(3) unsigned NOT NULL default '0', + `idle_account_limit_warn` tinyint(3) unsigned NOT NULL default '0', + `SMTP_HOST` varchar(255) default NULL, + `SMTP_PASS` varchar(255) default NULL, + `SMTP_USER` varchar(255) default NULL, + PRIMARY KEY (`name_id`) +) TYPE=MyISAM; + +# -------------------------------------------------------- + +# +# Table structure for table `users` +# + +CREATE TABLE `users` ( + `id` mediumint(11) unsigned NOT NULL auto_increment, + `login` varchar(255) NOT NULL default '', + `pass` varchar(255) NOT NULL default '', + `email` varchar(255) NOT NULL default '', + `privileges` tinyint(9) unsigned NOT NULL default '0', + `flagged_idle` datetime default NULL, + `lastlogin` datetime default NULL, + `lastlastlogin` datetime default NULL, + `created` datetime NOT NULL default '0000-00-00 00:00:00', + `email_messages` varchar(4) NOT NULL default 'on', + PRIMARY KEY (`id`) +) TYPE=MyISAM; + + + + +# +# Setup Data +# +INSERT INTO `score_sys` (`name_id`, `PUBLIC_REG`, `USE_ZIP`, `SC4PATH`, `SC4IMG_PATH`, `SC4REGION_IMG_WIDTH`, `SC4VERSIONS`, `ADMIN_EMAIL`, `ADMIN_NAME`, `last_maintenance`, `idle_account_limit`, `idle_account_limit_warn`, `SMTP_HOST`, `SMTP_PASS`, `SMTP_USER`) VALUES ('score_sys', 'on', 'on', 'Regions', 'Images', '99%', 'a:3:{s:16:"Rush/Hour Deluxe";s:4:"1.13";s:16:"SimCity Original";s:3:"1.9";s:11:"Any Version";s:1:"0";}', 'admin@localhost', 'admin', now(), 1, 5, '', NULL, NULL); +INSERT INTO `users` (`id`, `login`, `pass`, `email`, `privileges`, `flagged_idle`, `lastlogin`, `created`, `email_messages`) VALUES (1, 'admin', 'admin', 'admin@localhost', 150, NULL, NULL, now(), 'on'); \ No newline at end of file diff --git a/terrain.png b/terrain.png new file mode 100755 index 0000000000000000000000000000000000000000..9fcda400134d696491519a3db44cd4ea6d90b4bc GIT binary patch literal 1324 zcmV+{1=IS8P)B&d$zmZf=^Jn^AtRS4&Ha-|P`{^vkOLSvASd&d%4b zUpE?!i;IgweDUJNt5>gV*uK8LK0iM{Jw0`Vt(b}J>hA82BY$UrA_lNhL^wnu?d|P@ zgM;Vw!ZR~7guXM{1~FDs+if_-1J51@9*#K?nXa3 zIUy2!zJ2@l?%lf&A3pT<_EPxe%NK^J5=vuwdRi>_SoR;YWyRjn(Ggvcp?z*{j+ULB z9a8v@kB zl&YnrC0I!V&U*s|3US0onJDc;JClkMH#e!X(RYZ$!^6}O0SL$Cd9Pjo+~41)#Ay{b z#ps`mAZR2n_E>GNmk7AYYY^jn|NcFqWJmz$5p@7dK~+%&72+*vKV{AZ@u~!Yzj^bf zBp@{g98NLMHexD-A^~xWJyyX|fGy=-`Jt2mkHn5oU4b~+#>Y)x6nT~a3{mZin2sfW zk49CgqDH++OI4+KkZ^FnwO-U6)hlHhMTwG0pv%X76*d~Af{9}u|YMHD8f}~fyf3#8FTR$)T5)L^pJYU!Ck%b&zFoUs(C86v?M-?IL?*i zj3qoc<)92f$>W56RA59N#xV-A)RU0RtSqwJVee1V>OHipgGX z{U*JsH~ZY3DSz7SjU)WVDnFbu{4nf@aTY5M8ytuM!BNI?Dlg2~gezyFS1@U2aRhJ< zCD5N<67==5_O&}i77Y7-H(Ns*_DAG+s{9|;sPj%_4M=*<0h+l zf5dQH5pK};P4hq2^V5y?q?tTStTYr)Q@)vT@i&E_(DR}xwebAYu{