Archive
LightSwitch for Games Part 4: OData Access from C++ Client Code with the C++ REST SDK
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…
LightSwitch for Games Part 3: Creating a Web Interface for your Users
NOTE: Although this series is aimed at small game developers, it is equally applicable to anyone wishing to learn how to use LightSwitch.
In this article, I present a fast crash course in a raft of commonly used LightSwitch techniques. You will learn:
- how to make your web site base URL re-direct to your LightSwitch application
- how to enable remote error viewing in a LightSwitch HTML client application
- how to create new LightSwitch screens (web pages and dialog boxes)
- the difference between Browse, View Detail and Add/Edit Detail screens
- how to add buttons that allow the user to navigate between screens
- how to associate queries to LightSwitch tables and use them as the basis for new screens
- how LightSwitch categorizes data sets into All, Set and Single types, and how each data set type can be used
- how to create local properties (client-side variables that are associated with a single screen)
- how to make table rows and local properties on one screen input parameters to another screen
- how to create a button which executes custom code when clicked
- how to access table rows and local properties from client-side JavaScript
- how to perform custom client-side validation in JavaScript
- what the new LightSwitch ServerApplicationContext API is and how to use it
- how to make generic handlers (.ashx scripts) which can be used from client-side JavaScript to query and change data on the server from a LightSwitch HTML screen
- how to use jQuery to send data (with HTTP POST) and retrieve the response from a web page (in this case, .ashx scripts)
- how to use promises in LightSwitch to store a future result that is currently unknown (generally, the result of a request to the server) and make asynchronous (non-blocking) requests to the server
- how to create a custom control in JavaScript to represent a masked text box (a text box where the contents are replaced with asterisks or dots, like a password entry box)
- how to access the name of the currently logged in user with client-side JavaScript (for rendering purposes)
- how to change the default theme of a LightSwitch HTML application
- how to customize the default images in your LightSwitch HTML client application
- how to customize the LightSwitch HTML client login screen to match the rest of your web site
This article assumes some familiarity with:
- HTTP GET and POST methods
- HTML and CSS
- JSON
- a basic understanding of JavaScript (no jQuery knowledge is needed)
- a basic understanding of C#
Project Goals
In part 2 of this series we looked at how to securely allow anonymous users to create full user accounts for themselves, and how to expose this as a service via OData over HTTP to our future game clients. We looked at the basics of OData, WCF RIA Services, how to assign permissions and roles and how to limit a user to only accessing their own data. In this part, we’ll look at how to create a web-based user interface to allow gamers to edit/update their accounts. Our goals:
- allow the user to log in to a web site using their LightSwitch account
- allow the user to view and edit their profile (except their username)
- provide a change password dialog which requires the old and new passwords, and the new password to be typed twice
- customize the appearance of the site to your own company style
NOTE: You need Visual Studio Professional 2012 Update 2 or Update 3, or Visual Studio 2013 (Preview) to complete the tutorials in this article. Note that in Visual Studio 2013 (Preview), the organization of items in Solution Explorer has changed so some items may be in different places to those indicated below. Read more…
LightSwitch for Games Part 1: Introduction to Building your Game Data Network with LightSwitch
NOTE: Although this series is aimed at small game developers, it is equally applicable to anyone wishing to learn how to use LightSwitch.
Most modern video games have an online component nowadays. For games with online leaderboards, stats tracking, world-viewable awards and achievements, online virtual currency and distributed non-real-time turn-based games (for a very simple example, play-by-mail chess), a server is required with a database to store the information, and some way of retrieving and updating the data in a secure manner.
A typical and traditional way to achieve this is by using PHP and MySQL: you merely create tables in the MySQL database for the information required, and provide a series of PHP scripts or endpoints which can be passed data via HTTP GET queries (standard browser URLs with no additional data except that in the query string), and return the results – typically either the requested data, or a flag indicating whether the data was updated successfully or not. Your game code calls these endpoints as required to query and update the server-side data. Read more…
How to enable right-clicking with a buttonless touchpad in Ubuntu 12.04
The buttonless touchpad, also known as the ClickPad – designed to allow greater flexibility in touchpads by treating the entire surface as one button with programmable click regions – is possibly one of the worst touchpad designs ever conceived. Unfortunately, it would seem that it’s here to stay. The last few versions of Ubuntu haven’t played nice with ClickPads, and one of the great touted features of Ubuntu 12.04 (Precise Pangolin) is vastly improved ClickPad support. Imagine my surprise, then, when I upgraded from 11.10 only to find that right-clicking and two-finger drag no longer worked. Read more…
Tutorial: How to make WSUS 3.0 Selfupdate work with Apache
The problem: You want to run Apache or another web server besides IIS on port 80 on a machine which is also running Windows Server Update Services (WSUS). When you disable IIS’s Default Web Site running on port 80, WSUS stops working normally and the following error is reported in the Event Log:
Event ID: 13042 Type: Error Self-update is not working. For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
The cause: While client machines use an IIS web site on port 8530 by default to interact with WSUS, some files are required to be accessible on port 80 as well.
The solution: Make the needed files available via Apache or the other web server you want to run on port 80. Read more…
How to fix being unable to login to Windows XP after you image it
You just copied your Windows XP partition from one drive to another. When you reboot into the new partition, you reach the login screen, but when you try to login, it logs you straight out again with no error. Read more…