Page MenuHomeCode

No OneTemporary

This document is not UTF8. It was detected as ISO-8859-1 (Latin 1) and converted to UTF8 for display.
diff --git a/dev/schema-mysql.sql b/dev/schema-mysql.sql
--- a/dev/schema-mysql.sql
+++ b/dev/schema-mysql.sql
@@ -1,641 +1,625 @@
-- phpMyAdmin SQL Dump
-- version 3.3.3
-- http://www.phpmyadmin.net
--
-- Serveur: localhost
-- Généré le : Sam 17 Juillet 2010 à 19:37
-- Version du serveur: 5.5.4
-- Version de PHP: 5.3.2
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Base de données: `zed`
--
-- --------------------------------------------------------
--
-- Structure de la table `api_keys`
--
CREATE TABLE IF NOT EXISTS `api_keys` (
`key_guid` varchar(36) NOT NULL,
`key_active` tinyint(1) unsigned NOT NULL DEFAULT '1',
`key_description` tinytext,
`key_hits` bigint(20) NOT NULL DEFAULT '0',
`key_lastcall` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`key_guid`),
KEY `key_active` (`key_active`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Contenu de la table `api_keys`
--
-- --------------------------------------------------------
--
-- Doublure de structure pour la vue `content`
--
CREATE TABLE IF NOT EXISTS `content` (
`content_id` mediumint(8) unsigned
,`location_global` varchar(9)
,`location_local` varchar(255)
,`location_k` smallint(5) unsigned
,`content_path` varchar(255)
,`user_id` smallint(5)
,`perso_id` smallint(5)
,`content_title` varchar(255)
);
-- --------------------------------------------------------
--
-- Structure de la table `content_files`
--
CREATE TABLE IF NOT EXISTS `content_files` (
`content_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`content_path` varchar(255) NOT NULL,
`user_id` smallint(5) NOT NULL,
`perso_id` smallint(5) NOT NULL,
`content_title` varchar(255) NOT NULL,
PRIMARY KEY (`content_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
--
-- Contenu de la table `content_files`
--
-- --------------------------------------------------------
--
-- Structure de la table `content_locations`
--
CREATE TABLE IF NOT EXISTS `content_locations` (
`location_global` varchar(9) NOT NULL,
`location_local` varchar(255) NOT NULL,
`location_k` smallint(5) unsigned NOT NULL,
`content_id` mediumint(8) unsigned NOT NULL,
PRIMARY KEY (`location_global`,`location_local`,`location_k`),
KEY `content_id` (`content_id`),
KEY `location_global` (`location_global`,`location_local`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Contenu de la table `content_locations`
--
-- --------------------------------------------------------
--
-- Structure de la table `geo_bodies`
--
CREATE TABLE IF NOT EXISTS `geo_bodies` (
`body_code` mediumint(5) unsigned zerofill NOT NULL AUTO_INCREMENT,
`body_name` varchar(31) NOT NULL,
`body_status` set('hypership','asteroid','moon','planet','star','orbital','hidden') DEFAULT NULL,
`body_location` varchar(15) DEFAULT NULL,
`body_description` text,
PRIMARY KEY (`body_code`),
KEY `body_status` (`body_status`),
FULLTEXT KEY `text` (`body_name`,`body_description`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
--
-- Contenu de la table `geo_bodies`
--
INSERT INTO `geo_bodies` (`body_code`, `body_name`, `body_status`, `body_location`, `body_description`) VALUES
(00001, 'Hypership', 'hypership', NULL, NULL),
(00002, 'Xen', 'asteroid', NULL, NULL),
(00003, 'Kaos', 'asteroid', NULL, NULL);
-- --------------------------------------------------------
--
-- Doublure de structure pour la vue `geo_locations`
--
CREATE TABLE IF NOT EXISTS `geo_locations` (
`location_code` varchar(9)
,`location_name` varchar(255)
);
-- --------------------------------------------------------
--
-- Structure de la table `geo_places`
--
CREATE TABLE IF NOT EXISTS `geo_places` (
`place_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`body_code` mediumint(5) unsigned zerofill NOT NULL,
`place_code` smallint(3) unsigned zerofill NOT NULL,
`place_name` varchar(255) NOT NULL,
`place_description` longtext NOT NULL,
+ `location_local_format` varchar(63) DEFAULT NULL,
`place_status` set('start','hidden') DEFAULT NULL,
PRIMARY KEY (`place_id`),
UNIQUE KEY `body_id` (`body_code`,`place_code`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Contenu de la table `geo_places`
--
-INSERT INTO `geo_places` (`place_id`, `body_code`, `place_code`, `place_name`, `place_description`, `place_status`) VALUES
-(1, 00001, 001, 'Tour', 'Tour circulaire, surplombant l''hypership, offrant une vue circulaire sur l''espace (ou l''ultraespace, ou l''hyperespace) et une rotonde aux derniers étages.\r\n\r\n== Toponymie numérique ==\r\nChaque niveau (correspondant à un secteur, identifié par la lettre T suivi du niveau, en partant du haut) est divisé en 6 couloirs d''approximativement 60°.', NULL),
-(2, 00001, 002, 'Core', 'Le c.ur de l''hypership, son centre de gravité et les 8 cubes l''entourant.\r\n\r\n== Toponymie numérique ==\r\nLe core est divisé en 9 secteurs : C0 pour le centre de gravité, C1 à C4 pour les cubes de la couche inférieure, C5 à C8 pour les cubes de la couche supérieure.', NULL),
-(3, 00002, 001, 'Algir', '', NULL),
-(4, 00003, 001, 'Zeta', '', 'start'),
-(5, 00001, 003, 'Bays', 'Baies permettant d''accueillir divers vaisseaux au sein de l''hypership.', NULL);
+INSERT INTO `geo_places` (`place_id`, `body_code`, `place_code`, `place_name`, `place_description`, `location_local_format`, `place_status`) VALUES
+(1, 00001, 001, 'Tour', 'Tour circulaire, surplombant l''hypership, offrant une vue circulaire sur l''espace (ou l''ultraespace, ou l''hyperespace) et une rotonde aux derniers étages.\r\n\r\n== Toponymie numérique ==\r\nChaque niveau (correspondant à un secteur, identifié par la lettre T suivi du niveau, en partant du haut) est divisé en 6 couloirs d''approximativement 60°.', '/^(T[1-9][0-9]*C[1-6])$/', NULL),
+(2, 00001, 002, 'Core', 'Le coeur de l''hypership, son centre de gravité et les 8 cubes l''entourant.\r\n\r\n== Toponymie numérique ==\r\nLe core est divisé en 9 secteurs : C0 pour le centre de gravité, C1 à C4 pour les cubes de la couche inférieure, C5 à C8 pour les cubes de la couche supérieure.', NULL, NULL),
+(3, 00002, 001, 'Algir', '', NULL, NULL),
+(4, 00003, 001, 'Zeta', '', NULL, 'start'),
+(5, 00001, 003, 'Bays', 'Baies permettant d''accueillir divers vaisseaux au sein de l''hypership.', NULL, NULL);
-- --------------------------------------------------------
--
-- Structure de la table `log_smartline`
--
CREATE TABLE IF NOT EXISTS `log_smartline` (
`command_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`perso_id` smallint(5) unsigned DEFAULT NULL,
`command_time` int(10) DEFAULT NULL,
`command_text` varchar(255) DEFAULT NULL,
`isError` tinyint(1) DEFAULT '0',
PRIMARY KEY (`command_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Contenu de la table `log_smartline`
--
-- --------------------------------------------------------
--
-- Structure de la table `messages`
--
CREATE TABLE IF NOT EXISTS `messages` (
`message_id` mediumint(9) NOT NULL AUTO_INCREMENT,
`message_date` int(11) NOT NULL DEFAULT '0',
`message_from` varchar(4) NOT NULL DEFAULT '0',
`message_to` varchar(4) NOT NULL DEFAULT '0',
`message_text` longtext NOT NULL,
`message_flag` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`message_id`),
KEY `message_to` (`message_to`),
KEY `message_flag` (`message_flag`),
KEY `message_date` (`message_date`),
KEY `inbox` (`message_to`,`message_flag`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Contenu de la table `messages`
--
-- --------------------------------------------------------
--
-- Structure de la table `motd`
--
CREATE TABLE IF NOT EXISTS `motd` (
`motd_id` int(11) NOT NULL AUTO_INCREMENT,
`perso_id` int(11) NOT NULL,
`motd_text` varchar(255) NOT NULL,
`motd_date` int(10) NOT NULL,
PRIMARY KEY (`motd_id`),
KEY `perso_id` (`perso_id`),
KEY `motd_date` (`motd_date`),
FULLTEXT KEY `motd_text` (`motd_text`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=25 ;
--
-- Contenu de la table `motd`
--
INSERT INTO `motd` (`motd_id`, `perso_id`, `motd_text`, `motd_date`) VALUES
(24, 4960, 'You''re on the *DEVELOPMENT AND TESTING server (database zed, using the repo hg)*', 1279161701);
-- --------------------------------------------------------
--
-- Structure de la table `pages`
--
CREATE TABLE IF NOT EXISTS `pages` (
`page_id` int(11) NOT NULL AUTO_INCREMENT,
`page_code` varchar(31) NOT NULL,
`page_title` varchar(255) NOT NULL,
`page_content` longtext NOT NULL,
PRIMARY KEY (`page_id`),
UNIQUE KEY `page_code` (`page_code`),
FULLTEXT KEY `page_text` (`page_code`,`page_title`,`page_content`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
--
-- Contenu de la table `pages`
--
INSERT INTO `pages` (`page_id`, `page_code`, `page_title`, `page_content`) VALUES
(3, 'ArtworkCredits', 'Artwork credits', '<h2>Login screen</h2>\r\n<p>Wires and blocks use following tutorials:</p>\r\n<ul>\r\n <li><a href="http://www.tutorio.com/tutorial/futuristic-decay-interface">Futuristic Decay Interface</a></li>\r\n <li><a href="http://www.tutorio.com/tutorial/photoshop-wire-tutorial">Photoshop Wire Tutorial</a></li>\r\n</ul>\r\n<h2>Hypership</h2>\r\n<h3>Gallery tower</h3>\r\n<p>Technical schemas Dereckson. In the future, some could contain technical shapes Photoshop brushes, by <a href="http://scully7491.deviantart.com/">scully7491</a>.</p>\r\n<p>Portholes structure (c) Richard Carpenter, Six Revisions.<br />\r\nA <a href="http://sixrevisions.com/tutorials/photoshop-tutorials/how-to-design-a-space-futuristic-gallery-layout-in-photoshop/">tutorial is available here</a>.</p>\r\n<p>When the hypership is in hyperspace mode, portholes prints a colored background by <a href="http://www.sxc.hu/profile/ilco">ilco</a>.<br />\r\nWhen reaching a system, it prints a scene excerpt.</p>\r\n<h3>Core cancelled sector</h3>\r\n<p>Photographies: J&eacute;r&ocirc;me<br />\r\nEditing: Dereckson</p>\r\n<h2>Scenes</h2>\r\n<h3>Xen and Kaos</h3>\r\n<p>Scene composed from 2 wallpapers from Interfacelift, n&deg; 587 and 781.</p>\r\n<h2>Future sources</h2>\r\n<h3>Fasticon</h3>\r\n<p>It''s possible in the future some http://www.fasticon.com/ icons are added.</p>\r\n<h4>Comic Tiger</h4>\r\n<p>(c) <a href="mailto:dirceu@fasticon.com">Dirceu Veiga</a> - FastIcon Studio.<br />\r\n<strong>License:</strong> All Icons on the Fast Icon &quot;Download&quot; page are are FREEWARE, but to use our Icons in your software, web site, in a theme or other project, <a href="mailto:contact@fasticon.com">you need our permission first</a>. You don''t need permission for personal use our Icons on your computer.</p>');
-- --------------------------------------------------------
--
-- Structure de la table `pages_edits`
--
CREATE TABLE IF NOT EXISTS `pages_edits` (
`page_edit_id` int(11) NOT NULL AUTO_INCREMENT,
`page_code` varchar(255) DEFAULT NULL,
`page_version` smallint(6) NOT NULL DEFAULT '0',
`page_title` varchar(255) NOT NULL DEFAULT '',
`page_content` longtext,
`page_edit_reason` varchar(255) DEFAULT NULL,
`page_edit_user_id` smallint(4) unsigned DEFAULT NULL,
`page_edit_time` int(10) DEFAULT NULL,
PRIMARY KEY (`page_edit_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
--
-- Contenu de la table `pages_edits`
--
-- --------------------------------------------------------
--
-- Structure de la table `persos`
--
CREATE TABLE IF NOT EXISTS `persos` (
`user_id` smallint(4) DEFAULT NULL,
`perso_id` smallint(4) NOT NULL DEFAULT '0',
`perso_name` varchar(255) NOT NULL DEFAULT '',
`perso_nickname` varchar(31) NOT NULL DEFAULT '',
`perso_race` varchar(31) NOT NULL DEFAULT '',
`perso_sex` enum('M','F','N','2') NOT NULL DEFAULT 'M',
`perso_avatar` varchar(255) DEFAULT NULL,
`location_global` varchar(9) DEFAULT 'B00001001',
`location_local` varchar(255) DEFAULT NULL,
PRIMARY KEY (`perso_id`),
UNIQUE KEY `nickname` (`perso_nickname`),
KEY `race` (`perso_race`),
KEY `user_id` (`user_id`),
KEY `location_global` (`location_global`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Contenu de la table `persos`
--
INSERT INTO `persos` (`user_id`, `perso_id`, `perso_name`, `perso_nickname`, `perso_race`, `perso_sex`, `perso_avatar`, `location_global`, `location_local`) VALUES
(2600, 4960, 'Lorem Ipsum', 'demo', 'humanoid', 'M', '', 'B00003001', '1');
-- --------------------------------------------------------
--
-- Structure de la table `persos_flags`
--
CREATE TABLE IF NOT EXISTS `persos_flags` (
`flag_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`perso_id` smallint(6) NOT NULL DEFAULT '0',
`flag_key` varchar(255) NOT NULL,
`flag_value` varchar(512) NOT NULL,
PRIMARY KEY (`flag_id`),
UNIQUE KEY `persoflag` (`perso_id`,`flag_key`),
KEY `perso_id` (`perso_id`),
KEY `flag_key` (`flag_key`),
KEY `flag` (`flag_key`(127),`flag_value`(199))
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=459 ;
-- --------------------------------------------------------
--
-- Structure de la table `persos_notes`
--
CREATE TABLE IF NOT EXISTS `persos_notes` (
`perso_id` smallint(4) NOT NULL,
`note_code` varchar(63) NOT NULL,
`note_text` longtext NOT NULL,
PRIMARY KEY (`perso_id`,`note_code`),
KEY `perso_id` (`perso_id`),
KEY `note_code` (`note_code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Contenu de la table `persos_notes`
--
-- --------------------------------------------------------
--
-- Structure de la table `ports`
--
CREATE TABLE IF NOT EXISTS `ports` (
`port_id` smallint(6) NOT NULL AUTO_INCREMENT,
`location_global` char(9) NOT NULL,
`location_local` varchar(255) NOT NULL,
`port_name` varchar(63) NOT NULL,
`port_status` set('hidden','requiresPTA') NOT NULL,
PRIMARY KEY (`port_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Contenu de la table `ports`
--
INSERT INTO `ports` (`port_id`, `location_global`, `location_local`, `port_name`, `port_status`) VALUES
(1, 'B00003001', '3', 'Le Dôme de Thétys', ''),
(2, 'B00001003', '', 'Hypership''s general bays', '');
-- --------------------------------------------------------
--
-- Structure de la table `profiles`
--
CREATE TABLE IF NOT EXISTS `profiles` (
`perso_id` int(11) NOT NULL,
`profile_text` longtext NOT NULL,
`profile_updated` int(10) NOT NULL,
`profile_fixedwidth` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`perso_id`),
KEY `profile_fixedwidth` (`profile_fixedwidth`),
KEY `profile_updated` (`profile_updated`),
FULLTEXT KEY `profile` (`profile_text`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Contenu de la table `profiles`
--
-- --------------------------------------------------------
--
-- Structure de la table `profiles_comments`
--
CREATE TABLE IF NOT EXISTS `profiles_comments` (
`comment_id` mediumint(9) NOT NULL AUTO_INCREMENT,
`perso_id` smallint(5) unsigned NOT NULL,
`comment_author` smallint(5) unsigned NOT NULL,
`comment_date` int(10) NOT NULL,
`comment_text` text NOT NULL,
PRIMARY KEY (`comment_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
--
-- Contenu de la table `profiles_comments`
--
-- --------------------------------------------------------
--
-- Structure de la table `profiles_photos`
--
CREATE TABLE IF NOT EXISTS `profiles_photos` (
`photo_id` int(11) NOT NULL AUTO_INCREMENT,
`perso_id` smallint(6) NOT NULL,
`photo_name` varchar(63) NOT NULL,
`photo_description` varchar(63) NOT NULL,
`photo_avatar` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`photo_id`),
UNIQUE KEY `photo_name` (`photo_name`),
KEY `user_id` (`perso_id`),
KEY `photo_avatar` (`photo_avatar`),
KEY `user_avatar` (`perso_id`,`photo_avatar`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
--
-- Contenu de la table `profiles_photos`
--
-- --------------------------------------------------------
--
-- Structure de la table `profiles_tags`
--
CREATE TABLE IF NOT EXISTS `profiles_tags` (
`perso_id` int(11) NOT NULL,
`tag_code` varchar(31) NOT NULL,
`tag_class` varchar(15) NOT NULL DEFAULT 'music',
PRIMARY KEY (`perso_id`,`tag_code`),
KEY `tag_code` (`tag_code`),
KEY `tag_class` (`tag_class`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Contenu de la table `profiles_tags`
--
-- --------------------------------------------------------
--
-- Structure de la table `registry`
--
CREATE TABLE IF NOT EXISTS `registry` (
`registry_key` varchar(63) NOT NULL,
`registry_value` longtext NOT NULL,
`registry_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`registry_key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Contenu de la table `registry`
--
INSERT INTO `registry` (`registry_key`, `registry_value`, `registry_updated`) VALUES
('api.ship.session.S00001.Demios0001', '1148', '2010-07-04 15:18:04');
-- --------------------------------------------------------
--
-- Structure de la table `sessions`
--
CREATE TABLE IF NOT EXISTS `sessions` (
`session_id` varchar(32) NOT NULL DEFAULT '',
`Where` tinyint(4) NOT NULL DEFAULT '1',
`IP` varchar(8) NOT NULL DEFAULT '',
`user_id` smallint(5) NOT NULL DEFAULT '-1',
`perso_id` smallint(6) DEFAULT NULL,
`Skin` varchar(31) NOT NULL DEFAULT 'zed',
`Skin_accent` varchar(31) NOT NULL DEFAULT '',
`online` tinyint(4) NOT NULL DEFAULT '1',
`HeureLimite` varchar(15) NOT NULL DEFAULT '',
`SessionLimite` varchar(15) NOT NULL DEFAULT '',
PRIMARY KEY (`session_id`),
KEY `Where` (`Where`),
KEY `HeureLimite` (`HeureLimite`)
) ENGINE=MEMORY DEFAULT CHARSET=latin1 COMMENT='Sessions @ Pluton';
---
--- Contenu de la table `sessions`
---
-
-INSERT INTO `sessions` (`session_id`, `Where`, `IP`, `user_id`, `perso_id`, `Skin`, `Skin_accent`, `online`, `HeureLimite`, `SessionLimite`) VALUES
-('11o5p5fpacnoutbc2pgvh03ih1', 21, '0a000004', -1, NULL, 'zed', '', 1, '1279392190', '1279399090'),
-('74ue7g6k02e6k7bfirqudmhgi7', 21, '0a000004', -1, NULL, 'zed', '', 1, '1279392191', '1279399091'),
-('tu8otohbqlhknmt0atiuk850r6', 21, '0a000004', 2600, 4960, 'zed', '', 1, '1279392446', '1279399346'),
-('395f7o7pme0dkt32df8h8reo66', 21, '0a000004', -1, NULL, 'zed', '', 1, '1279392191', '1279399091'),
-('klss5iti1bf6vja6a6ibd48j02', 21, '0a000004', -1, NULL, 'zed', '', 1, '1279392193', '1279399093'),
-('ai71qqkde5hbbjc14sh4dj87o1', 21, '0a000004', -1, NULL, 'zed', '', 1, '1279392194', '1279399094');
-
-- --------------------------------------------------------
--
-- Structure de la table `ships`
--
CREATE TABLE IF NOT EXISTS `ships` (
`ship_id` mediumint(5) unsigned zerofill NOT NULL AUTO_INCREMENT,
`ship_name` varchar(63) NOT NULL,
`location_global` char(9) DEFAULT NULL,
`location_local` varchar(255) NOT NULL,
`api_key` varchar(36) NOT NULL,
`ship_description` text NOT NULL,
PRIMARY KEY (`ship_id`),
UNIQUE KEY `ship_name` (`ship_name`),
KEY `location` (`location_global`),
KEY `api_key` (`api_key`),
FULLTEXT KEY `ship_name_2` (`ship_name`,`ship_description`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
-
---
--- Contenu de la table `ships`
---
-
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
-- Doublure de structure pour la vue `ships_sessions`
--
CREATE TABLE IF NOT EXISTS `ships_sessions` (
`ship_id` varchar(5)
,`session_id` varchar(165)
,`perso_id` longtext
,`session_updated` bigint(10)
);
-- --------------------------------------------------------
--
-- Structure de la table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`user_id` smallint(4) NOT NULL DEFAULT '0',
`username` varchar(11) NOT NULL DEFAULT '',
`user_password` varchar(32) NOT NULL DEFAULT '',
`user_active` tinyint(1) NOT NULL DEFAULT '0',
`user_actkey` varchar(11) DEFAULT NULL,
`user_email` varchar(63) NOT NULL DEFAULT '',
`user_regdate` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Contenu de la table `users`
--
-- Adds a default account with demo/demo as login/password
--
INSERT INTO `users` (`user_id`, `username`, `user_password`, `user_active`, `user_actkey`, `user_email`, `user_regdate`) VALUES
(2600, 'demo', 'fe01ce2a7fbac8fafaed7c982a04e229', 1, NULL, 'lorem@ipsum.dol', 1279161321);
-- --------------------------------------------------------
--
-- Structure de la table `users_invites`
--
CREATE TABLE IF NOT EXISTS `users_invites` (
`invite_code` char(6) NOT NULL,
`invite_date` int(10) NOT NULL,
`invite_from_user_id` smallint(5) NOT NULL,
`invite_from_perso_id` smallint(5) NOT NULL,
`invite_to_user_id` smallint(5) DEFAULT NULL,
PRIMARY KEY (`invite_code`),
KEY `invite_to_user_id` (`invite_to_user_id`),
KEY `invite_from_user_id` (`invite_from_user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Contenu de la table `users_invites`
--
-- --------------------------------------------------------
--
-- Structure de la table `users_openid`
--
CREATE TABLE IF NOT EXISTS `users_openid` (
`openid_id` mediumint(9) NOT NULL AUTO_INCREMENT,
`openid_url` varchar(255) NOT NULL,
`user_id` mediumint(9) NOT NULL,
PRIMARY KEY (`openid_id`),
UNIQUE KEY `openid_url` (`openid_url`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
--
-- Contenu de la table `users_openid`
--
-- --------------------------------------------------------
--
-- Structure de la vue `content`
--
DROP TABLE IF EXISTS `content`;
CREATE VIEW `content` AS select `cl`.`content_id` AS `content_id`,`cl`.`location_global` AS `location_global`,`cl`.`location_local` AS `location_local`,`cl`.`location_k` AS `location_k`,`cf`.`content_path` AS `content_path`,`cf`.`user_id` AS `user_id`,`cf`.`perso_id` AS `perso_id`,`cf`.`content_title` AS `content_title` from (`content_locations` `cl` join `content_files` `cf`) where (`cf`.`content_id` = `cl`.`content_id`);
-- --------------------------------------------------------
--
-- Structure de la vue `geo_locations`
--
DROP TABLE IF EXISTS `geo_locations`;
CREATE VIEW `geo_locations` AS select concat(_utf8'B',convert(`geo_bodies`.`body_code` using utf8)) AS `location_code`,`geo_bodies`.`body_name` AS `location_name` from `geo_bodies` union select concat(_utf8'B',convert(`geo_places`.`body_code` using utf8),convert(`geo_places`.`place_code` using utf8)) AS `code`,`geo_places`.`place_name` AS `NAME` from `geo_places` union select concat(_utf8'S',convert(`ships`.`ship_id` using utf8)) AS `location_code`,`ships`.`ship_name` AS `location_name` from `ships`;
-- --------------------------------------------------------
--
-- Structure de la vue `ships_sessions`
--
DROP TABLE IF EXISTS `ships_sessions`;
CREATE VIEW `ships_sessions` AS select substr(`registry`.`registry_key`,19,5) AS `ship_id`,substr(`registry`.`registry_key`,25) AS `session_id`,`registry`.`registry_value` AS `perso_id`,unix_timestamp(`registry`.`registry_updated`) AS `session_updated` from `registry` where (left(`registry`.`registry_key`,17) = _utf8'api.ship.session.');
-- --------------------------------------------------------
--
-- Structure de la vue `geo_coordinates`
--
CREATE VIEW geo_coordinates AS (SELECT body_name as object_name, body_status as object_type, body_location as object_location FROM geo_bodies)
UNION
(SELECT ship_name as object_name, 'ship' as object_type, location_global as object_location FROM ships WHERE LEFT(location_global, 3) = 'xyz') ORDER BY object_name
\ No newline at end of file
diff --git a/includes/SmartLine/ZedCommands.php b/includes/SmartLine/ZedCommands.php
--- a/includes/SmartLine/ZedCommands.php
+++ b/includes/SmartLine/ZedCommands.php
@@ -1,463 +1,472 @@
<?php
/**
* Zed SmartLine commands.
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* This is the SmartLine subcontroller.
*
* The SmartLine is a widget allowing to add some basic CLI capability.
*
* It executes any command given in GET or POST request (parameter C).
*
* This files also provides SmartLine history helper: a method log_C to log
* a SmartLine command and some procedural code assigning a SmartLineHistory.
*
* This code is inspired from Viper, a corporate PHP intranet I wrote in 2004.
* There, the SmartLine allowed to change color theme or to find quickly user,
* account, order or server information in a CRM context.
*
* @package Zed
* @subpackage SmartLine
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*
* @todo SettingsSmartLineCommand - understand why dojo floating pane isn't rendered if we est $controller instead to redirect
*/
///
/// Register commands
///
$smartLine->register_object('goto', 'GotoSmartLineCommand');
$smartLine->register_object('guid', 'GUIDSmartLineCommand');
$smartLine->register_object('invite', 'InviteSmartLineCommand');
$smartLine->register_object('invites', 'InviteSmartLineCommand');
$smartLine->register_object('list', 'ListSmartLineCommand');
$smartLine->register_object('requests', 'RequestsSmartLineCommand');
$smartLine->register_object('settings', 'SettingsSmartLineCommand');
$smartLine->register_object('unixtime', 'UnixTimeSmartLineCommand');
$smartLine->register_object('version', 'VersionSmartLineCommand');
$smartLine->register_object('whereami', 'WhereAmISmartLineCommand');
///
/// Help (todo: move $lang array in lang folder)
///
$lang['Help']['goto'] = "Go to a location";
$lang['Help']['guid'] = "Generate a GUID";
$lang['Help']['invite'] = "Generate an invite. To see the generated invites, invite list.";
$lang['Help']['list'] = "Lists specified objects (bodies, locations or places)";
$lang['Help']['requests'] = "Checks if there are waiting requests";
$lang['Help']['settings'] = 'Go to settings page';
$lang['Help']['unixtime'] = "Prints current unixtime (seconds elapsed since 1970-01-01 00:00, UTC) or the specified unixtime date.";
$lang['Help']['version'] = "Gets Zed's software version info (Mercurial repository version, node id and if you're on the dev or prod site)";
$lang['Help']['whereami'] = "Where am I?";
/**
* The goto command
*
* Moves to the current perso to the specified location.
*/
class GotoSmartLineCommand extends SmartLineCommand {
/**
* Runs the command
*
* @param array $argv an array of string, each item a command argument
* @param int $argc the number of arguments
+ *
+ * @todo allow .goto global local (e.g. .goto B0001001 T2C3)
+ * @todo determine if we allow rewrite rules to bypass can_travel rules
*/
public function run ($argv, $argc) {
global $CurrentPerso;
if ($argc == 1) {
$this->SmartLine->puts("Where do you want to go?", STDERR);
return;
}
+ if ($argc > 2) {
+ $ignored_string = implode(" ", array_slice($argv, 2));
+ $this->SmartLine->puts("Warning: ignoring $ignored_string", STDERR);
+ }
+
require_once("includes/geo/location.php");
-
+ require_once("includes/travel/travel.php");
+
$here = new GeoLocation($CurrentPerso->location_global, $CurrentPerso->location_local);
+ $travel = Travel::load(); //maps content/travel.xml
- try {
- $place = new GeoLocation($argv[1]);
-
- if ($place->equals($CurrentPerso->location_global)) {
- $this->SmartLine->puts("You're already there.");
- return;
- }
- } catch (Exception $ex) {
- //Global location failed, trying local location
+ //Parses the expression, by order of priority, as :
+ // - a rewrite rule
+ // - a new global location
+ // - a new local location (inside the current global location)
+ if (!$travel->try_parse_rewrite_rule($argv[1], $here, $place)) {
try {
- $place = new GeoLocation($CurrentPerso->location_global, $argv[1]);
+ $place = new GeoLocation($argv[1]);
+
+ if ($place->equals($CurrentPerso->location_global)) {
+ $this->SmartLine->puts("You're already there.");
+ return;
+ }
} catch (Exception $ex) {
- $this->SmartLine->puts($ex->getMessage(), STDERR);
- return;
- }
-
- if ($place->equals($here)) {
- $this->SmartLine->puts("You're already there.");
- return;
- }
- }
-
- //Determines if the place exists
- //if (!$place->exists()) {
- // $this->SmartLine->puts("This place doesn't seem to exist.");
- // return;
- //}
+ //Global location failed, trying local location
+ try {
+ $place = new GeoLocation($CurrentPerso->location_global, $argv[1]);
+ } catch (Exception $ex) {
+ $this->SmartLine->puts($ex->getMessage(), STDERR);
+ return;
+ }
+
+ if ($place->equals($here)) {
+ $this->SmartLine->puts("You're already there.");
+ return;
+ }
+ }
+ }
//Could we really go there?
- require_once("includes/travel/travel.php");
- $travel = Travel::load();
if (!$travel->can_travel($here, $place)) {
$this->SmartLine->puts("You can't reach that location.");
return;
}
+ //Moves
$CurrentPerso->move_to($place->global, $place->local);
$this->SmartLine->puts("You travel to that location.");
return;
- }
+ }
}
/**
* The GUID command
*
* Prints a new GUID.
*
* guid 8 will print 8 guid
*/
class GUIDSmartLineCommand extends SmartLineCommand {
/**
* Runs the command
*
* @param array $argv an array of string, each item a command argument
* @param int $argc the number of arguments
*/
public function run ($argv, $argc) {
if ($argc > 1 && is_numeric($argv[1])) {
for ($i = 0 ; $i < $argv[1] ; $i++) {
$this->SmartLine->puts(new_guid());
}
return;
}
$this->SmartLine->puts(new_guid());
}
}
/**
* The invite command
*
* Manages invites.
*
* invite [add]
* creates a new invite code
*
* invite del <invite code>
* deletes the specified invite
*
* invite list
* prints current invite codes
*/
class InviteSmartLineCommand extends SmartLineCommand {
/**
* Runs the command
*
* @param array $argv an array of string, each item a command argument
* @param int $argc the number of arguments
*/
public function run ($argv, $argc) {
require_once('includes/objects/invite.php');
global $CurrentUser, $CurrentPerso;
$command = ($argc > 1) ? strtolower($argv[1]) : '';
switch ($command) {
case 'list':
$codes = Invite::get_invites_from($CurrentPerso->id);
if (!count($codes)) {
$this->SmartLine->puts("No invite code.");
} else {
foreach ($codes as $code) {
$this->SmartLine->puts($code);
}
}
break;
case 'add':
case '':
$code = Invite::create($CurrentUser->id, $CurrentPerso->id);
$url = get_server_url() . get_url('invite', $code);
$this->SmartLine->puts("New invite code created: $code<br />Invite URL: $url");
break;
case 'del':
$code = $argv[2];
if (!preg_match("/^([A-Z]){3}([0-9]){3}$/i", $code)) {
$this->SmartLine->puts("Invalid code format. Use invite list to get all your invite codes.", STDERR);
} else {
$invite = new Invite($code);
if ($CurrentPerso->id == $invite->from_perso_id) {
$invite->delete();
$this->SmartLine->puts("Deleted");
} else {
$this->SmartLine->puts("Invalid code. Use invite list to get all your invite codes.", STDERR);
}
}
break;
default:
$this->SmartLine->puts("Usage: invite [add|list|del <code>]", STDERR);
break;
}
}
}
/**
* The list command
*
* Prints a list of bodies, locations or places.
*
* This can easily be extended to output any list from any table.
*/
class ListSmartLineCommand extends SmartLineCommand {
/**
* Runs the command
*
* @param array $argv an array of string, each item a command argument
* @param int $argc the number of arguments
*/
public function run ($argv, $argc) {
if ($argc == 1) {
$this->SmartLine->puts("Available lists: bodies, locations, places");
return;
}
switch ($objects = $argv[1]) {
case 'bodies':
$list = $this->get_list(TABLE_BODIES, "CONCAT('B', body_code)", "body_name");
$this->SmartLine->puts($list);
break;
case 'locations':
$list = $this->get_list(TABLE_LOCATIONS, "location_code", "location_name");
$this->SmartLine->puts($list);
break;
case 'places':
if ($argv[2] == "-a" || $argv[2] == "--all") {
//Global bodies places list
$list = $this->get_list(TABLE_PLACES, "CONCAT('B', body_code, place_code)", "place_name");
} else {
//Local places (or equivalent) list
global $CurrentPerso;
switch ($CurrentPerso->location_global[0]) {
case 'B':
$body_code = substr($CurrentPerso->location_global, 1, 5);
$list = $this->get_list(TABLE_PLACES, "CONCAT('B', body_code, place_code)", "place_name", "body_code = $body_code");
break;
case 'S':
$this->SmartLine->puts("I don't have a map of the spaceship.", STDERR);
return;
default:
$this->SmartLine->puts("Unknown location type. Can only handle B or S.", STDERR);
return;
}
}
$this->SmartLine->puts($list);
break;
default:
$this->SmartLine->puts("Unknown objects to list: $objects", STDERR);
}
}
/**
* Gets a custom list from the specified table and fields.
*
* The list will ascendingly ordered by the specified key.
*
* @param $table the table to query from the database
* @param $key the first field to fetch, as key
* @param $value the second field to fetch, as value
* @param $where the WHERE clause, without the WHERE keyword (optionnal)
*/
public function get_list ($table, $key, $value, $where = null) {
global $db;
$sql = "SELECT $key as `key`, $value as value FROM $table ";
if ($where) $sql .= "WHERE $where ";
$sql .= "ORDER BY `key` ASC";
if (!$result = $db->sql_query($sql)) {
message_die(SQL_ERROR, "Unable to fetch list", '', __LINE__, __FILE__, $sql);
}
while ($row = $db->sql_fetchrow($result)) {
$rows .= "<tr><td>$row[key]</td><td>$row[value]</td></tr>";
}
$this->SmartLine->truncate(STDERR); //kludge
return "<table cellspacing=\"8\"><thead style=\"color: white\" scope=\"row\"><tr><th>Key</th><th>Value</th></thead><tbody>$rows</tbody></table>";
}
}
/**
* The requests command
*
* Redirects user the the requests page.
*
* By default only redirect if a flag indicates there's a new request.
*
* To forcefully goes to the request page, requests --force
*/
class RequestsSmartLineCommand extends SmartLineCommand {
/**
* Runs the command
*
* @param array $argv an array of string, each item a command argument
* @param int $argc the number of arguments
*/
public function run ($argv, $argc) {
global $CurrentPerso;
$force = ($argc > 1) && ($argv[1] == "-f" || $argv[1] == "--force");
if ($force || (array_key_exists('site.requests', $CurrentPerso->flags) && $CurrentPerso->flags['site.requests'])) {
global $controller;
$controller = 'controllers/persorequest.php';
} else {
$this->SmartLine->puts("No request waiting.");
}
}
}
/**
* The settings command
*
* Redirects user the the settings page.
*/
class SettingsSmartLineCommand extends SmartLineCommand {
/**
* Runs the command
*
* @param array $argv an array of string, each item a command argument
* @param int $argc the number of arguments
*/
public function run ($argv, $argc) {
if (headers_sent()) {
global $controller;
$controller = 'controllers/settings.php';
} else {
header('location: ' . get_url('settings'));
}
}
}
/**
* The unixtime command
*
* Prints current unixtime (seconds elapsed since 1970-01-01 00:00, UTC)
* or if an unixtime is specified as argument, the matching date.
*/
class UnixTimeSmartLineCommand extends SmartLineCommand {
/**
* Runs the command
*
* @param array $argv an array of string, each item a command argument
* @param int $argc the number of arguments
*/
public function run ($argv, $argc) {
date_default_timezone_set('UTC');
if ($argc == 1) {
$this->SmartLine->puts(time());
} elseif ($argc == 2 && is_numeric($argv[1])) {
$this->SmartLine->puts(strftime("%Y-%m-%d %X", $argv[1]));
$this->SmartLine->puts(get_hypership_time($argv[1]));
} else {
array_shift($argv);
$date = implode(' ', $argv);
if ($time = strtotime($date) !== false) {
$this->SmartLine->puts("Unixtime from $date: <span class=\"highlight\">$time</span>");
} else {
$this->SmartLine->puts("$date isn't a unixtime nor a valid date strtotime is able to parse.", STDERR);
}
}
}
}
/**
* The version command
*
* Prints current hg revision, if we're in prod or dev environement and
* the current revision's hash.
*
* The version and env information is extracted from
* .hg/tags.cache (indicating we're in a Mercurial repo and so in a dev environment), or from
* version.txt file (indicating we've deployed code in a production environement)
*
* e.g. r130 (development environment)
* Hash: 057bf394741706fd2136541e3bb07c9e60b4963d
*/
class VersionSmartLineCommand extends SmartLineCommand {
/**
* Runs the command
*
* @param array $argv an array of string, each item a command argument
* @param int $argc the number of arguments
*/
public function run ($argv, $argc) {
//Gets .hg revision
if (file_exists('.hg/tags.cache')) {
$content = file_get_contents('.hg/tags.cache');
$info = explode(' ', $content, 2);
$info[] = "development environment";
$this->SmartLine->puts("r$info[0] ($info[2])");
$this->SmartLine->puts("Hash: $info[1]");
} else if (file_exists('version.txt')) {
$content = file('version.txt');
foreach ($content as $line) {
$this->SmartLine->puts($line);
}
} else {
$this->SmartLine->puts("No version information available.", STDERR);
return false;
}
return true;
}
}
/**
* The whereami (Where am I?) command
*
* Prints current position, e.g. B00001001 - Tour, Hypership
*/
class WhereAmISmartLineCommand extends SmartLineCommand {
/**
* Runs the command
*
* @param array $argv an array of string, each item a command argument
* @param int $argc the number of arguments
*/
public function run ($argv, $argc) {
global $CurrentPerso;
require_once("includes/geo/location.php");
$place = new GeoLocation($CurrentPerso->location_global);
$this->SmartLine->puts($CurrentPerso->location_global . ' - ' . $place);
}
}
?>
diff --git a/includes/geo/place.php b/includes/geo/place.php
--- a/includes/geo/place.php
+++ b/includes/geo/place.php
@@ -1,216 +1,216 @@
<?php
/**
* Geo place class.
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* 0.1 2010-01-28 01:48 Autogenerated by Pluton Scaffolding
*
* @package Zed
* @subpackage Geo
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*/
/**
* Default local location format
*
* The local_location format is a PCRE regular expression
*
* By default, local_location format is an (x, y, z) expression
*/
define('LOCATION_LOCAL_DEFAULT_FORMAT', '/^\([0-9]+( )*,( )*[0-9]+( )*,( )*[0-9]+\)$/');
/**
* Geo place
*
* A place is a city or a hypership district.
*
* It's identified by a 9 chars geocode like B0001001.
* The 5 first chars indicates the body (class GeoBody) where the place is and
* the 3 last digits is the place number.
*
* This class maps the geo_places table.
*/
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
*
* @return string the status field value (e.g. "requiresPTA,default")
*/
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 looks valid
*
* @param string $local_location the local location
- * @return boolean true if the specified local location looks valid ; otherwise, false.r
+ * @return boolean true if the specified local location looks valid ; otherwise, false.
*/
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) > 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
*
* @return string The global location code of 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
diff --git a/includes/travel/place.php b/includes/travel/place.php
--- a/includes/travel/place.php
+++ b/includes/travel/place.php
@@ -1,122 +1,152 @@
<?php
/**
* TravelPlace class
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* 0.1 2010-07-19 22:10 DcK
*
* @package Zed
* @subpackage Travel
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*/
/**
* TravelPlace class
*
* The TravelPlace class is a set of rules determining which moves are valid
* in a specific place.
*
* @see GeoPlace
*
*/
class TravelPlace {
/**
* The place code
*
* @var string
*/
public $code;
/**
* Determines if any local location move is valid
*
* @var bool
*/
public $freeLocalMove = false;
/**
* Array of strings, each item another place reachable
*
* This matches GlobalTravelTo XML tags.
*
* @var Array
*/
public $globalTravelTo = array();
/**
* Aray of array, containing [location, alias, name] entries
*
* This matches LocalMove XML tags.
*
* @var Array
*/
public $localMoves = array();
/**
+ * Aray of array, containing [expression, global_location, local_location] entries
+ *
+ * This matches RewriteRule XML tags.
+ *
+ * @var Array
+ */
+ public $rewriteRules = array();
+
+ /**
* Initializes a new TravelPlace instance, from the specified XML fragment
*
* @param string $xml the XML fragment to parse
* @return TravelPlace the TravelPlace instance maching the specified XML fragment
*/
static function from_xml ($xml) {
$travelPlace = new TravelPlace();
//Reads attributes: <TravelPlace code="B00001001" freeLocalMove="true">
foreach ($xml->attributes() as $key => $value) {
switch ($key) {
case 'code':
$travelPlace->code = (string)$value;
break;
case 'freeLocalMove':
$travelPlace->freeLocalMove = (boolean)$value;
break;
}
}
//<GlobalTravelTo code="B00001002" />
foreach ($xml->GlobalTravelTo as $globalTravelToXml) {
foreach ($globalTravelToXml->attributes() as $key => $value) {
if ($key == "code") {
$travelPlace->globalTravelTo[] = (string)$value;
}
}
}
//<LocalMove local_location="(0, 0, 0)" alias="C0" name="Core" />
foreach ($xml->LocalMove as $localMoveXml) {
$localMove = array(null, null, null);
foreach ($localMoveXml->attributes() as $key => $value) {
switch ($key) {
case 'local_location':
$localMove[0] = (string)$value;
break;
case 'alias':
$localMove[1] = (string)$value;
break;
case 'name':
$localMove[2] = (string)$value;
break;
}
}
$travelPlace->localMoves[] = $localMove;
}
+ //<RewriteRule expression="/^T([1-9][0-9]*)$/" global_location="B00001001" local_location="T$1C1" />
+ foreach ($xml->RewriteRule as $rewriteRuleXml) {
+ $rewriteRule = array(null, null, null);
+ foreach ($rewriteRuleXml->attributes() as $key => $value) {
+ switch ($key) {
+ case 'expression':
+ $rewriteRule[0] = (string)$value;
+ break;
+
+ case 'global_location':
+ $rewriteRule[1] = (string)$value;
+ break;
+
+ case 'local_location':
+ $rewriteRule[2] = (string)$value;
+ break;
+ }
+ }
+ $travelPlace->rewriteRules[] = $rewriteRule;
+ }
+
return $travelPlace;
}
}
?>
\ No newline at end of file
diff --git a/includes/travel/travel.php b/includes/travel/travel.php
--- a/includes/travel/travel.php
+++ b/includes/travel/travel.php
@@ -1,139 +1,172 @@
<?php
/**
* Travel helper class
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* 0.1 2010-07-18 22:05 DcK
*
* @package Zed
* @subpackage Travel
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*/
require_once('place.php');
/**
* Travel helper class
*
* The Travel class reads content/travel.xml to get travel special rules
*
* It so be able to provide methods determining if a move is or not valid.
*
* This class implements a singleton pattern.
*/
class Travel {
/**
* Array of TravelPlace, each one a custom travel rule
*
* This array is indexed by TravelPlace code.
*
* @var Array
*/
public $globalTravelTo;
/**
* Constructor
*/
function __construct () {
//Initializes array
$this->globalTravelTo = array();
}
/**
* Gets and initializes if needed the Travel instance
*
* @return Travel the Travel instance
*/
static function load () {
require_once('includes/cache/cache.php');
$cache = Cache::load();
if (!$travel = $cache->get('zed_travel')) {
//Initializes resource and caches it
$travel = new Travel();
$travel->load_xml("content/travel.xml");
$cache->set('zed_travel', serialize($travel));
return $travel;
}
return unserialize($travel);
}
/**
* Loads a travel configuration XML file
*
* @param string the path to the travel XML file
*/
function load_xml ($file) {
$xml = simplexml_load_file($file);
foreach ($xml->TravelPlace as $travelPlaceXml) {
$travelPlace = TravelPlace::from_xml($travelPlaceXml);
$this->globalTravelTo[$travelPlace->code] = $travelPlace;
}
}
/**
+ * Tries to parse the specified expression, according the rewrite rules
+ * (for example defined by the <RewriteRule> xml tags)
+ *
+ * @param string $expression the expression to parse
+ * @param GeoLocation the location where the perso is
+ * @param GeoLocation the location where the perso wants to go
+ *
+ * @return boolean true if the expression have been parsed ; otherwise, false.
+ */
+ function try_parse_rewrite_rule ($expression, $from, &$to) {
+ //Relevant write rules depends from the location the perso is ($from)
+ $travelPlace = $this->globalTravelTo[$from->global];
+ foreach ($travelPlace->rewriteRules as $rule) {
+ //$rule is an array [expression, global_location, local_location]
+ $subpatterns = array();
+ $result = preg_match($rule[0], $expression, $subpatterns);
+ if ($result > 0) {
+ //$subpatterns is an array with:
+ // - at indice 0, the full matched regexp
+ // - from 1 to n, the (groups) inside the regexp
+ //We need so to replace $1 by $subpatterns[1] and so on.
+ for ($i = count($subpatterns) - 1 ; $i > 0 ; $i--) {
+ $rule[1] = str_replace('$' . $i, $subpatterns[$i], $rule[1]);
+ $rule[2] = str_replace('$' . $i, $subpatterns[$i], $rule[2]);
+ }
+ $to = new GeoLocation($rule[1], $rule[2]);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Determines if a perso can travel from $from to $to
*
* If an alias have been used for $to local location, set correct location.
*
* @param GeoLocation the location where the perso is
* @param GeoLocation the location where the perso wants to go
- * @return boolean if the travel move is valid ; otherwise, false.
+ * @return boolean true if the travel move is valid ; otherwise, false.
*
* @todo From B00001002, goto C1 doesn't work. Alias seems ignored.
*/
- function can_travel ($from, &$to) {
+ function can_travel ($from, &$to) {
if ($from->global != $to->global) {
//Checks if we can locally from $from to $to place
if (!array_key_exists($from->global, $this->globalTravelTo)) {
return false;
}
$travelPlace = $this->globalTravelTo[$from->global];
if (!in_array($to->global, $travelPlace->globalTravelTo)) {
return false;
}
}
if ($to->containsLocalLocation) {
//Determines if we've custom rules about local moves in $to
if (!array_key_exists($to->global, $this->globalTravelTo)) {
return false;
}
$travelPlace = $this->globalTravelTo[$to->global];
//Is it's an especially allowed movement?
foreach ($travelPlace->localMoves as $move) {
//move is a [location, alias, name] array
//If any of those 3 parameters matches $to->local, it's okay
if (in_array($to->local, $move)) {
$to->local = $move[0];
return true;
}
}
if ($travelPlace->freeLocalMove) {
//We can move freely, perfect
return true;
}
//Local move not allowed
return false;
}
return true;
}
}
?>

File Metadata

Mime Type
text/x-diff
Expires
Sun, Nov 24, 17:07 (6 h, 33 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21165
Default Alt Text
(59 KB)

Event Timeline