Blog

Latest news and updates from the PlayFab developers

by MarcoWilliams 2016-08-15

New PlayStream Feature and Updates to the PlayFab Game Server

[Update 2018/11/30: Edited to remove the notes on Event Subscription, in order to avoid confusion. We will shortly be releasing a new Publish/Subscribe feature ("PubSub"), which will provide the ability to subscribe to PlayStream events.]

In this blog I want to cover some of our recent updates to the PlayFab Custom Game Server.  This blog is mostly targeted towards developers using the Custom Game Server, as I think you’ll appreciate the new features we’ve added.  But those considering options for how to build your own game server for hosting in PlayFab, or who are just generally interested in learning more will also find this to be of interest.  

Here is a list of features and updates for this release

  • Updated structure of each “Context” module
    • Added notion of packages where each context module is now called a StrangePackage
    • Each context module now extends a new class & interface called StrangePackage
    • StrangePackage modules are auto-detected from the hierarchy
      • Need for Script Execution Order removed
      • Need for Bindings Factory removed
      • Bindings are defined in the StrangePackage “Manager”
    • All core StrangePackage modules are moved to  packages/defaultpackages folder
      • Each core package has been converted to a StrangePackage

There is a quite a bit to cover with the above features.  All the documentation for this has been updated in the repository’s README.md file.

So let’s dig in shall we?

Game Server Structure

Previously all of the context modules (which are now called Strange Packages) were bunched up in the /Contexts/ folder.  That folder has now been renamed to Packages and all of the core modules have been moved into /packages/DefaultPackages/.  Generally speaking, this shouldn’t affect anything.  The thing that does, is that  MainGameServerContext is now called GameServerContext and is at the root of the Game Server project.  However, you never need to modify it anymore!  Yay!  That was a clear pain point, and it wasn’t a clean solution to have developers modifying the Main Context.  Instead, we have converted this over to an auto-detected framework.  See the Upgrading section below for instructions on how to upgrade from the old server to the new one.

Another major thing is that Contexts no longer need a bindings factory and a context, as all the bindings from the factory are now moved into the PackageManager class in MapBindings, and that method is called for each StrangePackage found in the hierarchy of the project.  In addition, the other overridable methods are, in execution order, MapBindings, PostBindings, and Launch.  So any dependencies you need can be loaded PostBindings to ensure that they have been injected properly into the StrangeIoC framework before mapping those classes.  Finally, Launch is where you can do any startup logic specific to your module.

The good news is that none of your code should need to be re-written. f you have been using views and mediators those will work as is - you just need to put the mappings in the right place now.

Upgrading

Because the file structure has changed, I do not advise copying the files over into your existing project.  Rather, create a new project and follow the steps to migrate your existing code into the new project.  Once you do this, you will find that your code is now much more modular and easier to maintain.

  1. Create a new GameServer Project from the new PlayFab Game Server version.
  2. Next, Identify your views and mediators. You’ll need them for the following steps.  In the previous version of the game server we told you to create views and mediators in the MainGameContext, so you should find them there.  
  3. Create a new StrangePackage.
    1. Create a new folder in the /packages/ folder and name it.  It’s usually a good idea to give it a name relevant to its functionality.
    2. Create a new C# file in the root of that folder and name it  [ModuleName]Manager.cs.
    3. Make sure the class [ModuleName]Manager extends StrangePackage and implement the MapBindings Method.
  4. Set up your bindings
    1. Locate where you created your bindings in your previous project. Most likely this was in the Assets/Contexts/MainGameServerContext/MainGameServerContext.cs under a section commented with /* LOAD YOUR BINDINGS HERE */.
    2. Copy those bindings to your MapBindings method in your new package [ModuleName]Manager.

Please direct any questions about upgrading your Game Server to our forums at https://community.playfab.com. We’ll be more than happy to help you over any upgrade hurdles.