Archive for April, 2014

LightSwitch for Games Part 4: OData Access from C++ Client Code with the C++ REST SDK

April 2, 2014 7 comments

NOTE: Although this series is aimed at small game developers, it is equally applicable to anyone wishing to learn how to use LightSwitch.

In Part 2 of this series we built a user account and profile database on our LightSwitch server, and in part 3 we showed how to make a web interface to allow users to edit their account details. In this part, we will look at how to enable new users to register and existing users to log in direct from your C++ game (or application) code. If you’ve ever played a console game which requires log in to EA’s Origin servers or something similar, you will be familiar with this workflow and why it is useful to have in your game; that is, it saves users from having to go to a web site to make an account before they can play.

You don’t need to have completed part 3 in order to follow along with the tutorial below, but your LightSwitch project and database need to be in a state that matches at least the end of part 2. The web interface from part 3 is a fully distinct code path from what we will do below so it is not required for this code to work.

This article assumes some familiarity with:

  • HTTP requests and responses, methods and headers
  • JSON
  • OData transactions (covered in part 2)
  • a moderate understanding of C++ (including C++11 lambda functions)
  • a basic understanding of threading
  • setting up include and library directories for a project in Visual Studio

You will learn:

  • How to interact with LightSwitch OData endpoints using the C++ REST SDK (codename ‘Casablanca’)
  • How to use PPL(X) tasks and continuations
  • How to use OData to create new users (write table rows) and fetch user profiles (read table rows) from our server’s database programmatically in C++
  • How to update and delete rows with HTTP/OData directly or from within C++ programmatically
  • How to make the code error-resistant (for example if the user is disconnected from the internet)
  • How to separate the client-side logic (interacting with the server) from the user interface
  • How to access the server asynchronously (that is, using multiple threads so that the rest of your game or application does not stall or block while waiting for the server to respond)
  • How to create a basic framework of C++ classes to make your code easily re-usable and extensible

Project Goals

We need a client-side framework for communicating with the LightSwitch server before we start adding game-specific features and plugging the code into an actual game, so for this part our goal will be to create a simple console test application which allows us to create new users and fetch their profiles.

NOTE: The code presented below makes heavy use of C++11 features. You need Visual Studio 2013 Preview¬†or later to complete the tutorials in this article. You can re-write portions of the code without these features if you need to compile it with Visual Studio 2012. Read more…

How to statically link the C++ REST SDK (Casablanca)

April 1, 2014 12 comments

You are trying to use the C++ REST SDK (Casablanca) in your Windows application. You have one of the following problems:

  • you need Windows XP support
  • when your code executes you receive a debug assertion: _pFirstBlock == pHead
  • you get unpredictable behaviour or random crashing
  • you need to build an application which links against static libraries

You have 30 minutes to solve the problem. Here is how:

The issue is that the C++ REST SDK only supports dynamic linking. The solution is to re-build the SDK with static linking. Read more…

%d bloggers like this: