In this post I will be explaining some of the changes in CraftBian 2, codewise. These changes has mainly happened because i now utilize Laravel, so this is both notes to my self but might also be useful to others
Laravel
Laravel uses the MVC design pattern, which CraftBian v1.x did not. In CraftBian v1.x i used my “own” design pattern, with a ViewHandler that generated HTML so somewhat still separated from the View, but not completely. Laravel changes all that so that its now more distinctly separated hence the MVC: Model, View, Controller. Now in the view a templating engine called Blade is used, which gets its variables passed from the Controller. This structures the code much better, and most importantly – makes the code much easy to maintain. Furthermore Laravel provides loads of helper features which makes it easier to do Logging, Localization and even showing messages to the user. All features which CraftBian v1.x was missing very much
Localization
In CraftBian v1.x i simply didn’t do localization, which meant that all strings was typed in directly where needed. Laravel uses localization files like the below one
// This file is located in resources\lang\en\minecraft.php and is therefore the
// ..English translation file
return [
'motd' => 'MOTD',
'gametype' => 'Gametype',
'version' => 'Version',
'players' => 'Players',
'world' => 'World',
'type' => 'Type',
'server_not_started' => 'Server not started',
'server_in_starting_stage_msg' => 'The server is currently in starting stage.
Error Messages is normal! If it hasnt started after 15 mins, try rebooting the Raspberry Pi',
'current_output' => 'Current output',
'waiting_for_server_output' => 'Waiting for server output...',
]
And when needing a specific translation, you call it out via the __() helper function, which takes the filename as input followed by the key needed like so
// In a Controller (PHP)
$translatedString = __('minecraft.gametype'); // <- Would be: Gametype
// In the blade templating engine (View)
{{ __('minecraft.current_output') }} // <- Would be: Current Output
Logging
Logging is also a feature which i would have appreciated back in CraftBian v1.x, mainly because it would be much easier to debug when CraftBians users were having trouble with something, which i needed to assist on. Laravel makes this very easy. An example below of logging a simple information is shown:
public function reboot()
{
Log::info('Reboot has been called', ["user" => Auth::user()]);
// ...
// Doing the actual reboot stuff
// ...
Log::error('Rebooting unit failed!', ["returned" => $errorMessage]);
}
As you can see its as simple as calling the static method info inside the Log class. This methods first argument would be a simple titile describing what has happened, and the next parameter is an array containing contextual and relevant info, but it is optional. There are other methods besides info or error, which you can find more info about here .
The log file containing all this is stored in storage/logs/laravel.log
Messages to the user (Flash messages)
CraftBian v1.x missed a lot of feedback to the user, when they did something inside the interface, being everything from saving a server.properties file for a Minecraft server, or setting up a backup schedule. In Laravel this is so easy to do with Flash messages:
// Below method is called when the user clicks a save button
public function saveSettings(Request $request)
{
// .. the changed settings are inside the $request parameter
// .. and is then updated, and finally:
$request->session()->flash('success', 'Settings saved!');
// The above line stores a message, which is the shown when the view
// .. is returned below:
return view('settings');
}
This is mostly notes to my self, but others might find it useful / interesting . It also gives you a slight insight in the development of CraftBian 2
I have more things i would like to cover, like the Model structure and how Object relational mapping works in Laravel, which i also get to utilize in CraftBian 2, because it now uses SQLite to store its settings instead of JSON as in CraftBian v1.x.
Instead of Minibian as is used now, i want to use Ubuntu at it is updated more frequently and still based on Debian. Also wider support across multiple platforms.
I hope to make a CraftBian installer, so that you can install the interface on whatever platform you might want to use. Everything from a Raspberry Pi, to a full fledged Server PC. However i still want to provide a full image like you are used to on the current CraftBian release.
I’ve already begun the early testing phase on this, to test the compatibility of the current functionality in CraftBian
Simply because it is better supported
Smaller, yet important changes:
One of the things that i don’t quite like about CraftBian v1.x is that if my remote server is down, CraftBian will be very slow or/and maybe even not work properly. This is something i do not want.
When updating CraftBian currently, the software behind it, in Linux, is not updated. This means that if some major change happened on this side, the user would be forced to completely reflash the image with a newer version. Something i do not want.
Something i had always intended but never got around to.
Another thing i had always wanted, but never got around to, as it would be easier for me to help and debug users having trouble.
This blog is intended for a detailed explanation on the progress of the development of CraftBian 2 and it will include some rather techy terms along with some programming. I also intend to use it for my self, as notes i need to remember along the way.