Monday, July 6, 2009

Solar Vengeance 6 Lobby


I completed the multiplayer lobby interface for Solar Vengeance 6 in Silverlight. Click the link below to log into the new lobby. You can set your profile, including a Glyph image, and chat with other users in the lobby.

Implementing the lobby in the app was easy once my PrismServer components were ported to Silverlight. The PrismConnection component provides an easy way to connect a Silverlight app to a running PrismServer.

In SV6 I create the PrismConnection component in code, but you could also create it in your XAML since it descends from DependencyObject. You'd just need to be sure to place it within a ContentControl, because Silverlight panels can't take DependencyObjects directly. When defined in XAML, you can set the properties like Host, Port, and SubjectName in your XAML, as well as hook up event handlers.

In my custom application class I declare a private variable to hold the PrismConnection object, and a public property to provide access to it in other pages. In Application StartUp event, I create the instance:

_prism = new PrismConnection("1.2.3.4", 4502, false);
_prism.SubjectName = "SV6";

You'd replace "1.2.3.4" with the host name or IP address where your PrismServer is running.

To connect, call the Connect method, which will eventually fire either the ConnectSuccessful or ConnectFailed events.

In your ConnectSuccessful event handler you can call either Login (for existing users) or LoginNew (for new users). Login takes 2 parameters, a user name and a password. LoginNew takes 1 parameter, an instance of a PrismUser object that represents the user information for the new user.

These methods will eventually fire either the LoginOK or the LoginFailed events, which you can handle accordingly.

The PrismUser class has some helper methods that make it easy to store and retrieve Glyph images for users. The SV6 Lobby lets you select a local image file on your computer to represent you as your Glyph. PrismUser encodes this image into a Base64 string, and saves it in the PrismUser object, in one of the "Detail" fields. PrismUser GetDetail/SetDetail methods let you store arbitrary information with a PrismUser and have it saved on the server.

When a user logs back in, its encoded Glyph string is decoded and converted back into an ImageSource which is then displayed next to them in the Lobby.

I use the PrismUser GetDetail/SetDetail to store other game-specific information about a user, such as their rank and rating.

Handling chat in the Lobby is virtually effortless thanks to PrismConnection doing all of the dirty work. To send a line of chat to other users, simply call the SendChat method. A ChatRecieved event is triggered when an incoming chat message is received. The EventArgs class provides you the PrismUser who sent the chat as well as the line of text itself.

Now that the Lobby is completed I can move onto converting the actual game mechanics!

Solar Vengeance 6 Development Build - with Lobby!

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Looks great! Really smooth, this.

    Hmmm... just had a thought though, wanted to throw out there... with these games being hosted server-side, would it be possible to play 'long-turn' games? Where the individual ticks might take a good, long while? I don't even know if it would work at all (probably not), but the idea of playing a game over several days intrigues me...

    ReplyDelete
  3. There's no reason why this couldn't be achieved. To simulate a turn based game each "tick" could be made dynamic, so the turn executes when everyone has submitted their orders, or a timeout occurs. Game info can be saved on PrismServer and returned when the game is resumed.

    ReplyDelete