Page Menu
Home
Code
Search
Configure Global Search
Log In
Files
F209504
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
13 KB
Subscribers
None
View Options
diff --git a/README b/README
index 38e1b38..b9ed3d7 100644
--- a/README
+++ b/README
@@ -1,121 +1,126 @@
ZzzzzzZ zz
Z z z The spatial gallery / social network / lounge
z z (c) 2010, Dereckson, some rights reserved.
z zzzzz zzzzz
z z z z z 0.1 alpha technical preview
z zzzzzzz z z
z z z z Last update hypership time: 5.096
z Z z z z z
ZzzzzzZ zzzzz zzzzzz
===========
LOCATIONS
===========
* Global location is a 9 letters code
<B,S> <body or spaceship id> <place where you are in this body/spaceship>
zerofilled 5 digits zerofilled 3 digits
You can also find 6 digits expressions e.g. B00001 is the hypership
* Local location varies of the place.
- On hypership core (B00001002): Sector C<0-8> Level <z> Zone <x-y>
- 0 is the gravity center
- 1-8 the 8 cubes surrounding it: 1-4 below, 5-8 above
- On the ship tower (B00001001): Sector T<z> Couloir <1-6>
- z is the level
- couloir depends of your x, y position (polar coordinates could help)
=================
HYPERSHIP TIME?
=================
* the amount of days since hypership launch, January 25th 2010 00:00 UTC
* So the decimal part is like internet time, but in GMT and not CET/CEST
===============
SIDE PROJECTS
===============
* A pazaak game, to have something to play
* Will be an Arzakon client
=================
I WANT TO HELP!
=================
* You can create new SmartLine commands
* You can translate it in a new language
Start point: http://zed.dereckson.be/lang/en/core.conf
* You can code a bit of adventure, places description, stuff to do
as long you don't transform it in ogame clone (we're building a community
who want or don't want to play, but not a mechanic game)
and as long no money is involved (if you ask why, read Iain M. Banks novels)
in the hypership (in far asteroids, orbitals, planets you do what you want)
============
KNOWN BUGS
============
* Javascript get_hypership_time will returns 5.94 instead 5.094
Some %03d to add in /js/misc.js
* All URLs outside homepage will return Unknown URL
Well... only the home controller is coded.
* The floater rendering adds a black line under Opera
dojox.layout.floatingPane bug, need to check with last dojo version
* API /location query will break indent on location->body->location
beautify XML code to improve
=======================
API - General methods
=======================
* /api.php/time
Returns hypership time
Public access
* /api.php/perso/<perso_id>
Returns perso object
Created only to test extensively recursivity of api xml output
It's disabled since 10.811 on zed.dereckson.be, if you need an alternative,
open a bug report with the fields you need. Ship API should be able to manage
inventory if user is on. Ship API must also be able to get/set custom flags.
Requires a key
* /api.php/location/<location code or name>
Returns location object
Tip: to get the full name, use string eg /api.php/location/Zeta?format=string
Requires a key
* GET/POST API parameters
- key
API key, ask it at zed at dereckson be, object [DEV] api key request
- format
- preview print_r representation, so you've an idea of the object
- json json_encode() output
- php serialize() output
- wddx WDDX were an early universal serialization attempt
- xml XML document
- string output "as is" (or if it's an object, calls __toString())
============
API - Ship
=============
* /api.php/ship/authenticate/<perso nickname>
-
- Allows
\ No newline at end of file
+
+=================
+ ACKNOWLEDGEMENT
+=================
+
+Elfix, to have let me figure a regexp correction, instead to throw away regexp
+validation for places local location.
diff --git a/dev/tests/GeoPlaceTest.php b/dev/tests/GeoPlaceTest.php
new file mode 100644
index 0000000..a1a4c35
--- /dev/null
+++ b/dev/tests/GeoPlaceTest.php
@@ -0,0 +1,37 @@
+<?php
+require_once('PHPUnit/Framework.php');
+require_once('../../includes/geo/place.php');
+
+class GeoPlaceTest extends PHPUnit_Framework_TestCase {
+ public function testIsValidLocation () {
+ //Testing HyperShip Tower T2C3 format
+ $p0 = new GeoPlace();
+ $p0->location_local_format = '/T[1-9][0-9]*C[1-6]/';
+ $this->assertTrue($p0->is_valid_local_location("T1C1")); // 1
+ $this->assertTrue($p0->is_valid_local_location("T14C1")); // 2
+ $this->assertTrue($p0->is_valid_local_location("T14C6")); // 3
+ $this->assertTrue($p0->is_valid_local_location("T140C6")); // 4
+ $this->assertTrue($p0->is_valid_local_location("T14000C6")); // 5
+
+ $this->assertFalse($p0->is_valid_local_location("C1T6")); // 6
+ $this->assertFalse($p0->is_valid_local_location("T14000 C6")); // 7
+ $this->assertFalse($p0->is_valid_local_location("T4C7")); // 8
+ $this->assertFalse($p0->is_valid_local_location("T4C0")); // 9
+ $this->assertFalse($p0->is_valid_local_location("T0C0")); //10
+
+ //Unit testing is useful: this test led to fix the regexp
+ //from T[0-9]+C[1-6] to T[1-9][0-9]*C[1-6]
+ $this->assertFalse($p0->is_valid_local_location("T0C1")); //11
+
+ //Testing default format
+ $p1 = new GeoPlace();
+
+ $this->assertTrue($p1->is_valid_local_location("(4,62,35)")); //12
+ $this->assertTrue($p1->is_valid_local_location("(4, 62, 35)")); //13
+ $this->assertTrue($p1->is_valid_local_location("(4, 62,35)")); //14
+
+ $this->assertFalse($p1->is_valid_local_location("(4,62,-35)")); //15
+ $this->assertFalse($p1->is_valid_local_location("(4, 62)")); //16
+ }
+}
+?>
\ No newline at end of file
diff --git a/includes/geo/place.php b/includes/geo/place.php
index 6d963b5..2e2ecc1 100644
--- a/includes/geo/place.php
+++ b/includes/geo/place.php
@@ -1,181 +1,182 @@
<?php
/*
* place class
*
* 0.1 2010-01-28 01:48 Autogenerated by Pluton Scaffolding
*
* @package Zed
* @subpackage Geo
* @copyright Copyright (c) 2010, Dereckson
* @license Released under BSD license
* @version 0.1
*
*/
//By default, local_location format is an (x, y, z) expression
//The local_location format is a PCRE regular expression
-define('LOCATION_LOCAL_DEFAULT_FORMAT', '/([0-9]+( )*,( )*[0-9]+)( )*,( )*[0-9]+)/');
+define('LOCATION_LOCAL_DEFAULT_FORMAT', '/\([0-9]+( )*,( )*[0-9]+( )*,( )*[0-9]+\)/');
class GeoPlace {
public $id;
public $body_code;
public $code;
public $name;
public $description;
public $location_local_format;
public $start;
public $hidden;
/*
* Initializes a new instance
* @param int $id the primary key
*/
function __construct ($id = null) {
if ($id) {
$this->id = $id;
$this->load_from_database();
}
}
/*
* Loads the object place (ie fill the properties) from the $_POST array
*/
function load_from_form () {
if (array_key_exists('body_code', $_POST)) $this->body_code = $_POST['body_code'];
if (array_key_exists('code', $_POST)) $this->code = $_POST['code'];
if (array_key_exists('name', $_POST)) $this->name = $_POST['name'];
if (array_key_exists('description', $_POST)) $this->description = $_POST['description'];
if (array_key_exists('status', $_POST)) $this->status = $_POST['status'];
if (array_key_exists('location_local_format', $_POST)) $this->location_local_format = $_POST['location_local_format'];
}
/*
* Loads the object place (ie fill the properties) from the database
*/
function load_from_database () {
global $db;
$sql = "SELECT * FROM geo_places WHERE place_id = '" . $this->id . "'";
if ( !($result = $db->sql_query($sql)) ) message_die(SQL_ERROR, "Unable to query geo_places", '', __LINE__, __FILE__, $sql);
if (!$row = $db->sql_fetchrow($result)) {
$this->lastError = "place unkwown: " . $this->id;
return false;
}
$this->body_code = $row['body_code'];
$this->code = $row['place_code'];
$this->name = $row['place_name'];
$this->description = $row['place_description'];
$this->location_local_format = $row['location_local_format'];
//Explodes place_status SET field in boolean variables
if ($row['place_status']) {
$flags = explode(',', $row['place_status']);
foreach ($flags as $flag) {
$this->$flag = true;
}
}
return true;
}
/*
* Gets status field value
*/
function get_status () {
$flags = array('start', 'hidden');
foreach ($flags as $flag) {
if ($this->$flag == true) {
$status[] = $flag;
}
}
return implode(',', $status);
}
/*
* Saves to database
*/
function save_to_database () {
global $db;
$id = $this->id ? "'" . $db->sql_escape($this->id) . "'" : 'NULL';
$body_code = $db->sql_escape($this->body_code);
$code = $db->sql_escape($this->code);
$name = $db->sql_escape($this->name);
$description = $db->sql_escape($this->description);
$status = $this->get_status();
$location_local_format = $db->sql_escape($this->location_local_format);
//Updates or inserts
$sql = "REPLACE INTO geo_places (`place_id`, `body_code`, `place_code`, `place_name`, `place_description`, `place_status`, `location_local_format`) VALUES ($id, '$body_code', '$code', '$name', '$description', '$status', '$location_local_format')";
if (!$db->sql_query($sql)) {
message_die(SQL_ERROR, "Unable to save", '', __LINE__, __FILE__, $sql);
}
if (!$id) {
//Gets new record id value
$this->id = $db->sql_nextid();
}
}
/*
- * Determines if the specified local location is valid
+ * Determines if the specified local location looks valid
+ * @return boolean true if the specified local location looks valid ; otherwise, false.r
*/
function is_valid_local_location ($local_location) {
$format = $this->location_local_format ? $this->location_local_format : LOCATION_LOCAL_DEFAULT_FORMAT;
- return preg_match($format, $local_location);
+ return preg_match($format, $local_location) > 0;
}
/*
* Gets a string representation of the current place
* @return string A Bxxxxxyyy string like B00001001, which represents the current place.
*/
function __tostring () {
return 'B' . $this->body_code . $this->code;
}
/*
* Creates a Place instance, from the specified body/place code
* @param $code the place's code
* @return GeoPlace the place instance
*/
static function from_code ($code) {
global $db;
$sql = "SELECT * FROM geo_places WHERE CONCAT('B', body_code, place_code) LIKE '$code'";
if (!$result = $db->sql_query($sql)) message_die(SQL_ERROR, "Unable to query geo_places", '', __LINE__, __FILE__, $sql);
if (!$row = $db->sql_fetchrow($result)) {
return null;
}
$place = new GeoPlace();
$place->id = $row['place_id'];
$place->body_code = $row['body_code'];
$place->code = $row['place_code'];
$place->name = $row['place_name'];
$place->description = $row['place_description'];
$place->location_local_format = $row['location_local_format'];
//Explodes place_status SET field in boolean variables
if ($row['place_status']) {
$flags = explode(',', $row['place_status']);
foreach ($flags as $flag) {
$place->$flag = true;
}
}
return $place;
}
/*
* Gets a start location
* @TODO sql optimisation (query contains ORDER BY RAND())
*/
static function get_start_location () {
global $db;
$sql = "SELECT CONCAT('B', body_code, place_code) FROM geo_places WHERE FIND_IN_SET('start', place_status) > 0 ORDER BY rand() LIMIT 1";
return $db->sql_query_express($sql);
}
}
?>
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 4, 00:32 (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21054
Default Alt Text
(13 KB)
Attached To
rZED Zed
Event Timeline
Log In to Comment