Monday, 21 April 2014

Using a Raspberry Pi as a headless media store on a Sonos network

This is to build a headless media centre and is also being built that way - that is, I'm not going to plug a screen or keyboard/mouse directly into the Pi. This means that I can install the version of Debian without the window manager which makes it far lighter on the processor.

It's not difficult, but I've compiled my notes and written some English to link them together as someone may find them useful. I'm going to assume some basic Linux and home networking knowledge.

You will need

Sourced from Amazon, total cost (at time of writing, without hunting around) is: £47.60

You'll also need some USB hard drives. The Pi (model B here) only has USB 2.0 ports so you can use older drives if you're not planning on plugging them in anywhere else. Also, the Pi runs on very low power so you really want powered drives or a powered USB hub to sit between them. If you want to back up your data, you're going to need two drives. If you don't, you can ignore all the stuff about rsync that comes up later.

Let's go

Up and running

  1. download Raspbian
    Sadly, the NOOBS install method requires the use of a screen so wont work for us.
  2. install Raspbian onto the SD card
    These are the instructions for prepping the card on a Windows machine.
  3. put the Pi in the case, plug in the ethernet cable and put in the SD card
  4. finally plug in the power cable and we're off

Connect and update

Find the IP address of your Pi, shell to it and log in (default username / password is pi / raspberry). You need to run:
sudo raspi-config
and select the option to expand the root filesystem to fill the SD card. It's important you do this before any of the other steps or you will be starting again.

Next update the operating system via:
sudo apt-get update
sudo apt-get upgrade
This will likely take a while.

Connect the drives

Plugging the drives in will auto-mount them, however if we are using one drive as a backup to the other we need to ensure they are always mounting the same way round on restart. To do this we will identify the drives via their UUID in /etc/fstab:
UUID=0AC4D607C4D5F543 /mount/location ntfs rw,defaults 0 0
To find the UUID of the drives:
blkid /dev/sda1
blkid /dev/sdb1
Remember that if you format a drive, the UUID will change.

Install the software

Time to install some useful software.

Samba shares specified parts of your filesystem on the network. It will allow you to mount the drive on another computer which will let you put files on your media server when it's ready. It is also the shared area that Sonos will be able to search for music files.

Minidlna shares an area of your filesystem via DLNA. This means a DLNA-ready device can locate the share and request any files in it. I use this for watching video on my iPad (my viewing program of choice being 8player).
# install samba
sudo apt-get install samba samba-common-bin

# install minidlna
sudo apt-get install minidlna
I also installed some extra tools to make other tasks easier. You don't need them for this build.
sudo apt-get install tree locate chkconfig

Configure samba

To configure samba you need to edit /etc/samba/smb.conf. You'll want something like this:
[global]
    netbios name = NETBIOS_NAME
    workgroup = WORKGROUP
    security = user
    encrypt passwords = yes
    smb passwd file = /etc/samba/smbpasswd

[media]
    comment = My media
    path = /PATH/TO/SHARE
    writeable = yes
    create mask = 0770
    force create mode = 0770
    locking = yes
Mixed to taste, of course.

Then add the user to the samba password file:
sudo smbpasswd -L -a USERNAME
Restart samba and you should then be able to mount the drive on other machines on the network.

Configure minidlna

The minidlna config file is found at /etc/minidlna.conf

Docs on configuring minidlna are available on the minidlna site. The important bits are:
media_dir=A,/home/user/Music      # Music directory
media_dir=P,/home/user/Pictures   # Pictures directory
media_dir=V,/home/user/Videos     # Video directory
friendly_name=Laptop              # Name of the share
db_dir=/var/cache/minidlna        # Index files (make sure location is writeable)
log_dir=/var/log                  # Log files (make sure location is writeable)
inotify=yes                       # Index new files as they are added
It's important to make sure the minidlna user can read and write to the index and log directories and read the media files. Alternately, if you're lazy like me you can make minidlna run as the main user by editing /etc/init.d/minidlna (around line 68). Obviously this is not recommended for any significant install of anything, but I'm assuming we're at home on a very limited access network.

When starting minidlna you may get an error message claiming to be exceeding the watch limit. To increase this limit, add to /etc/sysctl.d/90-inotify.conf
fs.inotify.max_user_watches = 100000
and restart.

Note that there is a new version of minidlna on the way called ReadyMedia possibly rendering this completely obsolete.

Back up the drives

I wanted to keep a backup of my media on the second drive. I could have used RAID 1 but reading around suggested that the amount of read/write information going across the USB bus would cause a bottleneck and therefore problems serving the files. To get around this, I use rsync to copy everything across on a nightly basis.

Something like this in the crontab will sync the drives each night at 3am:
0 3 * * * rsync /mountpoint/maindrive /mountpoint/backupdrive >> ~/rsync_log.txt 2>&1
And with this, the setup is complete.

Getting the media files in order

Sonos will read the ID3 tags on the music files so they need to correct. Due to the fun of an iTunes crash some time in the past mine are a mess so it's time for some scripting. More on this in a future post.

Saturday, 19 April 2014

On a list

Recent statistics from Steam say that approximately a third of owned games remain unplayed. I'm as bad as anyone with this - between sales, Humble Bundles and people sending me keys from THEIR bundles I've got a long list of the things I'm sure I'll get around to playing one day. Obviously, when someone says "Hey, Splinter Cell: Blacklist is on sale - why don't we pick it up?" there is only one response: why not?

I've got a splinter

I'm not a long-term fan of the Splinter Cell series. Slightly odd national-paranoia storyline and slow slide into mediocre FPS territory aside, I've never really gotten into the gameplay. This is probably my own fault as typically I've played the games around five years after release and they really haven't stood up to the ravages of time. It's not that I dislike the games - it's more that each time I've sat down to play one I've found better things to do with my time. This time, though, there was something different. Blacklist has co-op.

Just the two of us

Things are better with a friend and gaming is (usually) no exception. Assuming you have a friend to play with, co-op can be seen as a magic bullet that can improve any game. Of course if you have to find someone via a matchmaking system it can be the most irritating thing in the world.

Personally, I like to be able to play whatever the game has as a single player campaign in co-op mode. Blacklist goes down the cheap and annoying route of having a single player campaign with some bonus missions in which you can bring a friend. Normally this leaves co-op as a bolt-on to be enjoyed for half an hour before you move on to the inevitable multiplayer. Blacklist manages to avoid short-changing you by making the bonus missions roughly 75% of the game content and this means many happy hours yelling at your buddy for tripping alarms and forcing a restart of the entire mission. It really is a lot of fun and substantial - which is good, because it was the main reason I bought the game in the first place.

I'm told the side missions are divided into four types which will be recognisable to fans of the older games. I can't comment on how good these missions are at evoking the spirit of the older games, but I can say that they all play differently and are a good way of keeping the game fresh and interesting. There are the "normal" missions, with normal defined as being similar in playstyle to the single player game. Then there are the full-stealth missions where the whole thing is failed if anyone catches sight of you. These are great as the tension ramps up towards the end and you risk losing the last hour of game time to a mistimed run from cover to cover. Next up there are the violent missions in which your job is to murder everyone in an area - ideally without being seen - which are a pleasant change in pace to the uber-stealth missions. Finally there are the survival missions, in which you need to hold an area using guns and gadgets until you've worked through the waves of attackers then either bail or stick around for more mayhem.

I've not seen co-op implemented quite like this before. It's a fantastic idea, giving me the co-op experience I like while leaving the main campaign alone so the writers can tell the story they want to tell without being hamstrung by the constant requirement of a second protagonist.

All by myself

So yes, there's also a solo campaign. It seems to do a good job of continuing the existing story while not alienating newcomers to the series like me. I found it easy enough to get a feel for the established characters - not the most challenging thing, but they are more rounded than most of hardened military or espionage types you typically find in settings like this.

The plot deals with a massive terrorist operation on US soil. It's heavy on the argh-foreigners paranoia, but interestingly you'll spend much of your time crossing swords with other US intelligence agencies and doing some pretty dubious stuff to get around them. It's a little odd to see a turf war breaking out while tens of thousands of civilians are at risk but it's credible and it makes for some interesting caveats on some of the missions. Nothing says "be careful" like the game failing you the moment you cut down an unsuspecting friendly trooper with a hail of silenced machine gun fire because you were too ham-fisted to sneak across a compound without them seeing you.

I also appreciate the game letting me do these things myself. It's depressingly common that a game's story is told through non-interactive cutscenes or via quick time events (note - a non-interactive cutscene does not become gameplay just because I have to lunge for a random button on my keyboard 3 minutes in) but in Blacklist the game does not feel in the way of the film the writers want you to watch. You get short cutscenes before and after missions and everything else is told in-mission. Like the extra work which has gone into making the co-op mission structure, this makes a big difference to the game.

Except...

Oh yes, except the end (bit of a spoiler warning for some of the game's ending here).

I assume there must be a QTE guy somewhere involved in this project. Maybe they sent him out for coffee every day so he couldn't interfere. Maybe he was on holiday. Either way, they managed to distract him for most of the game's production. Then at the last minute he was allowed back in and the FINALLY BOSS is defeated by a series of bloody quick time events - and not just ordinary events either. They are obnoxiously difficult and cause you to restart the entire boss fight (the rest of which is oddly mechanical and doesn't really flow properly but at least is gameplay) when you inevitably mess them up because after 20-odd hours of a proper game you really aren't expecting them.

ARGH.

I don't normally have a problem with QTEs (passing them, that is, not appreciating them) but the only way I could get through these was to learn the sequence and anticipate which button to hit. Thanks guys. It certainly doesn't ruin the game, but it does have a good go at ruining the ending.

Always a system

Back to something positive. The upgrade system is extensive but because of the variance in the game types in the extra content most of what is on offer is actually useful. The problem I had with something like Dishonored is that it gave you a big pile of toys with which you could cause mayhem then slapped your hands if you actually used them. In this you get everything from knockout gas to land mines and then the game lets you get on with it. Obviously you can't use hand grenades in the stealth-only missions, but you can go nuts in the survival modes. The guns aren't quite as generous as the gadgets - the silenced weapons are definitely more useful in all modes - but you can still find a use for the assault rifles if you try.

The only exceptions are the breaching charges (I carried these through SO MANY MISSIONS because they sound cool and didn't manage to use one once) and the final goggles (which appear to be the same as the second to last goggle but with a stylish chinstrap). Bonus points are awarded for not ruining the upgrade system with the DLC kit. Although it is very good there are still normal unlocks which are better so there is still something to work towards.

All the people

There's also a competitive multiplayer mode. It's another interesting Ubisoft game, with unbalanced teams fighting very different battles, and works very well. I haven't found it compelling enough to play for hours but what I did play was a lot of fun.

And so

I like Blacklist. I'm genuinely surprised to be writing that. In fact, I like it a lot and I'm sad that I've now played through all the content. I'd like a little more co-op, but frankly I'm always going to say that and despite completing it I can see myself going back to play more of the survival games. I hope the sequel is structured in the same way - if I can get another fix of sneaky co-op fun then you can finally me to the list of people who are excited by this series.

Saturday, 12 April 2014

When drives don't mount nicely

While rebuilding my media sharing Raspberry Pi I've come across a small problem with usb drives. If you don't unmount a drive from a Windows machine properly, the Pi will mount it read-only. A simple solution for this is:
  1. install the ntfs-3g package:
    sudo apt-get install ntfs-3g
  2. mount the drive using this utility:
    sudo ntfs-3g /dev/sda1 media
    (to mount drive at sda1 to directory media) which clears up all the locks for you
  3. then simply umount and mount and things are back to normal

Saturday, 1 February 2014

A city in Crysis

Oh look – I’ve got a blog. Seems I managed to forget that for most of last year. New Year’s resolution: write more. Let’s see how that turns out.

Games!

Back in the old days this was a blog about video games. I played through and wrote about Crysis and Crysis: Warhead and made certain criticisms of the design decisions. In my post about Crysis I praised the game but said the narrative was a bit wonky, lurching from shooting Koreans to shooting aliens and in the process utterly changing the way the game played – and not for the better. They fixed that in Crysis: Warhead. I also said that the nanosuit, while being interesting was overly complicated and that they’d be better off losing some of the power modes and having them always-on.

Which brings us nicely to Crysis 2.

Suit me up

We’re back in the nanosuit – now apparently only being worn by one person in the entire gameworld – but with some of the power modes removed and those functions always-on. Sounds familiar. The new interface is far slicker than the old one which makes the gameplay faster and more fluid. The missing modes (Speed and Strength) are still around, but accessed via context-sensitive prompts (Strength) and just running quickly (Speed) which makes a lot more sense, even if you’re sometimes killed by enemies because being shot has drained your energy leaving you unable to run away properly. Still – it’s your fault. Plan properly next time.

Me suit up 

But you can’t just remove the useless element from an interface - you have to add new and exciting buttons to push to justify the “2”ness of the experience. So we have nightvision, which I don’t remember in the original games and not really worth the bother now. It is only of any use in one (very brief) section where the lights fail and a couple of occasions when the playing area is randomly filled with smoke. It just feels tacked on, which is a shame.

Then there is TacVisorThing. I struggle with TacVisorThing. I like game worlds and generally I feel it helps immersion to build logical gadgets then incorporate them into the gameplay rather than adding something cool and hoping the setting can swallow it. In the gameworld, the TacVisor makes sense. Basically, you bring down the “spotter” sights and the nanosuit analyses the battlefield and overlays tactical options to help you out. Generally they are quite obvious (marking high ground as suitable for "sniping" or the bit at the side suitable for "flanking") but it can point out weapon and ammo caches which would otherwise be easily missed. The problem is that all this really does is put a series of button presses between you and continuing the action when you enter one of the more open areas. It’s just busywork and I can’t help feeling that an automatic overlay would have been a nicer solution (prediction for Crysis 3! Which has been out for nearly a year!).

Oh, and there is an upgrade system too. More on that later.

Up me suit

So, we’re suited up. Time to get going. The gameplay drops Crysis’s vaguely open world for a series of corridors spilling out into arenas. It keeps things focused, but does lose any real sense of planning. You’re going in at A and coming out at B. All you can really decide is how to progress between those points. Oh – you’ve chosen stealth. Well, that means you can just walk from A to B and ignore the guys hanging around waiting to kill you.

Damn.

Yes, the Stealth option basically lets you bypass most of the enemies and without ever engaging them. And there really isn’t much encouraging you to fight – sure the human opposition are portrayed as a bunch of thuggish tools, but you’ve got places to be and pretty soon they are all busy being eaten by aliens anyway. The aliens on the other hand are big walking robot things with tentacles coming out of their heads (gone are the flying squid-things from the first game) who … you can also walk straight past. Sigh.

Actually, this feels like a step backwards from Crysis 1 where the enemies would hunt you down once you’d shown yourself. Now re-cloaking utterly confuses them. They don’t try shooting where you might be, or throw things to make you appear. You can just scurry off and murder anew from a new angle. The AI in general seems universally dense – they follow very obvious paths and just don’t seem to react to what you’re doing beyond “turn and shoot” instincts.

In an effort to stop you bypassing all the enemies in stealth mode there is an upgrade system which is powered from the corpses of the alien troops. There is some pseudo-science explaining this, but suffice to say that it means you’ll 1. spend a lot of time running like an idiot through the middle of firefights because you don’t want to lose the XP, rather ruining game flow (why can’t the pick-ups drift to you?) and 2. become next to invulnerable horribly quickly. Pro tip when upgrading – get level 1 of all 4 sections, then save for level 3 stealth and armour in that order. Everything else is largely worthless.

There are also token collectables which do little other than say YOU’RE PLAYING A COMPUTER GAME (why am I picking up tourist models of famous buildings, exactly?). It’s important to not forget those.

Tell me a tale

The plot? Yeah, there's one of those too.

Come on

Eugh. Well, there is some evil-PMC nonsense, an alien invasion, a sinister businessman pulling the strings behind the scenes and some of the noblest marines you’ll ever meet. The characters are largely uninteresting and to a man unlikable and most of the time you’re glad you’re on your own. The marines do provide a particularly hilarious sequence though – you’re told that the normal humans basically have no chance against the aliens and you need to escort them back to base. However, these normal humans turn out to be invulnerable (presumably to stop the escort quest making you hate all of humanity which is what normally happens – definitely a good decision) which means you can cheerfully use them as shields or just cower in a corner while they PUNCH THE ALIEN MECHA-SUITS TO DEATH. Do NOT mess with the US Marine Corps.

You’re still typing

That’s about it. It all functions, but it feels rather uninspired. It’s as if Crytek have built a great engine, hired the best artists on the planet (even seven years on it looks amazing, but then you already knew that), thought about the nanosuit and basically free-styled the actual game part. Not to say that it isn’t fun – I had an enjoyable 10 or so hours blasting through it, aside from a horrible end of game fight against cloaked aliens who had to die to unlock a door for … reasons – but it feels like a missed opportunity. There was the potential to do an open-world game in a semi-ruined cityscape here which changed as the war evolved. Who knows – maybe some of your actions could have helped that evolution along different paths. In that world the nanosuit could have come into its own, allowing you to customise the game to your preferred play-style via your use of powers and upgrades. Instead, we have a corridor shooter with some knobs on. A good corridor shooter, with some very pretty knobs but still – corridors and knobs.

Saturday, 26 October 2013

Jekyll and Foundation with Guard

tl;dr - I've dropped the jekyll asset pipeline in favour of Guard in my pre-configured example project of Jekyll and Foundation.

A few weeks I wrote about my attempts to create a bootstrapped jekyll / foundation combination using the Jekyll asset pipeline to keep things building on the fly. I hit a snag, though. The asset pipeline was abandoned back in February and is locked to version 0.12 of Jekyll (current release being 1.2.1 at the time of writing). There are various forks of the project which bring things up to date but I'm worried about being left in the same position again and, frankly, I'm starting to question the methodology of using Jekyll to do everything instead of running the tools separately.

What I really want, I think, is some kind of meta-tool which lets me manage my build environment but by using the core tools - in my case Jekyll and Compass and probably a CoffeeScript processor eventually - so I (hopefully) have fewer maintenance problems down the line. Seems like Guard is pretty much what I want. I'm coupling it with guard-jekyll-plus and guard-compass to work with those tools. It isn't perfect, and doesn't assuage my dependency fears entirely but it feels a much more robust solution than the previous version.

My basic jekyll-foundation project has been changed to use this new tool chain and seems much more responsive than before (could be anecdotal) so I'm looking forward to making more use of it.


Monday, 30 September 2013

Jekyll and Foundation automatically recompiling changes

tl;dr - I've glued jekyll, jekyll pipeline and foundation into a pre-configured example project.

I look after a handful of small sites and I've been playing with different ways of maintaining them and keeping them vaguely modern. A CMS is the obvious way forward, but that has the learning curve problem and, frankly, after working away at this kind of thing all day I'd rather approach the problem a little differently.

What I really want is something which lets me write content in my markup language of choice, then generates some html for me and wraps it in a template. It should also handle some of the simpler optimization tasks (minifying, compressing, compiling any sass) and ideally allow some kind of on-the-fly regeneration of all these assets so I can work and hit refresh with it running in the background.

Jekyll seems like a good contender as a starting point. I love the fact it generates static HTML files for me (I'm getting tired of requiring the comparatively slow processing power of PHP for ultra-simple tasks) and it has a "watch" mode for recompiling the pages as I work. It uses the Liquid templating engine, which is sufficiently simple for my needs, and there is support for a variety of markup options.

Next, I need some sass support. This is easily done, but I want a simple workflow so it needs to recompile on the fly while jekyll watch is running. Step up the jekyll asset pipeline which lets me add whatever I like to the jekyll process with a minimum of fuss, including css compression and the sass compilation I wanted. I'm pretty sure I could add CoffeeScript support with it too, but I haven't tried that yet.

Right, I have the components I need. I'm going to work with Foundation 4 because it happens to be a framework I know relatively well. If only there was a vanilla project which pulled all this together ready so I could just fork it and start building a new site. Oh look.

In all seriousness, I've hammered these elements together into something that should be easy to just pick up and start using. I'm hoping it'll be useful to me and - this being the internet - chances are that means it'll be useful to someone else too. If that someone is you, enjoy this vanilla jekyll project with foundation sass built on the fly. Why not let me know?

Friday, 31 May 2013

An FPS but a bit more

I find the mechanics of Republic Commando interesting. On the face of it, it's a basic FPS which uses the Unreal 2 engine. You can carry 5 weapons plus melee attack and you fight waves of droids and flying bugs. Underneath that, however, it is something a bit different.

At the heart of what makes Commando different is the squad combat mechanic. Instead of the usual lone commando setup, you are one of four and you can order your AI buddies around to help everyone else around. So far, so unremarkable (although at the time perhaps not - I can't recall offhand when squad control started becoming a regular thing). The really nice part is the way the squad control mechanics are worked into the game.

Firstly, it is not a gimmick, rather it is a tool that is incredibly useful to progress. In a game such as Mass Effect 2, you can quite happily ignore your squad to do their own thing and blast your way through the encounters however attempting to do this in Commando this will likely result in a quick and painful death. On several occasions during my playthrough I blundered into a firefight and had my team slaughtered however on restarting the section, playing thoughtfully and actually using the options available to me the exact same encounter became a breeze. This isn't because your mates are victims of stupid and in dire need of micromanagement (the AI of your team is well above average in fact) but because there is a very tangible benefit to using the squad order system and instructing them to switch to sniper mode or hold a section of cover or whatever. Having said that, the order system does remain a tool. You are rarely forced to command your fellows and you can, if you're feeling light on your feet, play Commando as a more traditional shooter. Importantly, there are also some really bad command options presented so mechanically issuing orders doesn't work which avoids the danger of it becoming a simple "I win" option.

So the issuing of orders is a noticeably useful option given to the player. However it doesn't feel like a mechanic to be exploited because of the second great thing about its implementation - it is part of the game world. The obvious point there is that your character is the squad leader so you are expected to be telling everyone what to do. More subtly is the way the game encourages you to think carefully about your options. In any decent sized firefight there will be a dozen positions your squad can take up so you need to not only use the mechanic but think in real terms about the way this will benefit you. Most of the time it's fairly obvious stuff - but only if you're thinking about covering fire, line of sight and so on and then you're thinking about real world options rather than clicking buttons which helps with the immersion.

Something else important about the design of the squad is the commando skillset. Although each one of your team mates has a distinct personality, in terms of ability they are entirely interchangeable. While that may sound simplistic it helps avoid making everything too obvious. You don't drop your sniper in the sniper spot simply because he's a sniper, for example. You can have intersecting fields of sniper fire if you want - you aren't restricted to just one guy with a rifle. You also don't have the problem of needing to blow something up and your demo guy is the one who decided to get his face shot off - someone else can step up to the task.

Linked to this is the way you can define your own role in the team. You have the same skills as your team mates which means every time you order someone to set a bomb or hack a terminal, you can do it instead if you prefer. In the middle of a firefight, you can order one of your chaps to get on with hacking while you shoot the enemies off him, however if you prefer you can instead put yourself in danger and order your team to give you covering fire. It may not sound like much, but this really makes you feel like part of a team instead of above it which does wonders for the oh-so-important immersion.

There are other clever design ideas - regenerating shields but collectible health so you can limp along without being completely crippled but not getting shot has its benefits springs to mind - however the squad control system is what makes Commando interesting. It manages not only to avoid being a gimmick, but also demonstrate how a cleverly applied gameplay mechanic can enhance atmosphere and immersion.