Today I’m writing an entry for the the developers, an opportunity for me to introduce the new architecture for XNova:Legacies and explain its differences with what may have existed so far on the project. It is worth remembering that the biggest evolutions of the upcoming version comes from a brand new source code written in PHP 5.2, this version becomes though a dependency to make XNova:Legacies work on your system, but don’t worry, this PHP verison exists since 2006 and is therefore widely deployed on PHP hosting providers since a long time.

To return to what we are all here, everything has been redesigned to facilitate simple and rapid modification of the functionnalities of the game without the need of applying neither 1 line of the original source code. Everything is built upon the configuration, if a functionality in the base source code does not work like you wanted : replace it! it is as simple as that.

Accessing to data from the database has never been as simple and safe : get an ID, and load your model, woithout any risk of possible SQL injection. But how do we update, create or delete a database record? Just a line! For the preview 2010-alpha0, the user module will be the first module launched. It is relatively simple and will therefore serve both standard and benchmark for what will follow: 90% of this new source will be shared by an overwhelming majority of functionality or future refactoring.

But all that makes many words and few examples, so here are some previews (may be subject to modification in the final version):

Loading and modifying data of a player from the database:

To load data from a player which, for example, have the ID 8 in the database, the following is enough:
$user = Nova::getModel('user/user')->load(8);

And next? take your newly created variable (here, $user) and use it as like an array, just like you did until now… almost. Yes, because now it is no longer an array, it’s an object. Whath’s the difference? well is that my $ user has now gained virtual accessors and mutators and it even knows how to directly save its data by itself in the database!

$user
->setEmail('player@example.com'); // Updating the field 'email'
->setUsername('Player') // Updating the field 'username'
->save();

Yes, It’s all well and good, but I like it like it was before!

No panic! our $user keeps up appearances and can still be used just like we did before:
echo $user['username'];

But it does not stop with a simple syntax change!

Yes, rather than having functions everywhere, and asking where a particular feature would be, why not combine everything in one place? Well, we do it now! For example: to manage the connection of a player, why not create an automated mechanism?

$user = Nova::getModel('user/user');
if ($user->login($_POST['username'], $_POST['password'])) {
// Our user has submitted the good password, he is now logged in
} else {
// A problem hapened, maybe a passord error?
}

Oh, but how could we retrieve the current user from anywhere now? Simple! Easy! The sessions comes to help us and have also been improved:

$user = Nova::getSingleton('user/session')->getUser();

We now got back our $user, which have logged in in the previous example.

And it goes even further!

Develop and debug your old mods or develop modules for Legacies by enabling debug mode and Deprecation mode and use the source code profiler, simple tools and methods to optimize your code.

In your .htaccess, add the following to enable the two methods mentioned above:

SetEnv DEBUG On
SetEnv DEPRECATION On

The source code profiler is used to count the time taken by a particular treatment, it will return the number of times that it was executed, and various statistics of execution time. It is used with both static methods Nova::profilerStart() and Nova::profilerStop(), respectively, to start a counter and stop t. It both take a single argument that identifies the time counter:

Nova::profilerStart('NOVA.EXAMPLE');
// The treatment to analyze starts from here
for ($i = 0; $i < 200000; $i++) {
echo 'Hello world';
}
// and ends here
Nova::profilerStop('NOVA.EXAMPLE');

Note that the profiler results will only appear in debug mode.