Posts

My RPG Game

As you probably know already, the motivation for using SignalR was a MMO Facebook game I am working on.  The progress is slow as I am working on it only in my free time. Recently I finally had some time to compile a 'playable' version and publish it to my home server.  So in case you are curious whats that all about and how SignalR works in a real game you can check it here:  https://apps.facebook.com/titanium-mykingdom You will need to login with a Facebook account though. As this is my home server expect more downtime than uptime. There is also a SSL problem for I am using a self signed certificate. Your browser will probably notice that and dump a warning that the certificate authority is not known. Depending on the browser you use just click on 'Show content' or (for Chrome) copy the URL and open it another tab and click on 'Proceed'. One more note; don't expect much, the game has maybe 30% of features so its not even nearly finished. I was 

SignalR: send messages to single client

One of the problems I came across while using SignalR was to send messages to a single client. In the following example (taken from my game prototype) the static DispatchMessage() is used to send a message to a specific client. Note that the connection id's are generated via the ConnectionFactory explained in my last post (connectionId equals player.Id). public class ServerHub : Hub { private static readonly IHubContext ctx = GlobalHost.DependencyResolver.Resolve ().GetHubContext (); public static void DispatchMessage( int playerId, RpgMessage msg ) { var client = ctx.Clients[playerId.ToString()]; client.serverMessage( msg ); } // other instance method omitted ... } Here we cache the hub context in a static member. The context exposes a collection of all known clients that we use to get the desired client. Also note that the client.serverMessage() function is implemented on the client side and you should invoke it

SignalR: Wire-up the ConnectionId with a user instance

While working on a RPG game prototype based on ASP.NET I started experimenting with SignalR. This library was a perfect fit as it allows pushing data from server to clients in a very easy way (read: with just a few lines of code) and of course server method invocations from clients through JavaScript. Unfortunately SignalR is not providing a direct and intuitive way of gluing together application specific (server side) objects with the SignalR internal connections. This means that at any time you know how many clients are connected but you have absolutely no idea who they are. A client is basically a connection. A connection has a unique connectionId so you can distinguish clients but that's about it. Even worse, each time a client reconnects it gets a new connection id. In real world applications you have a bunch high level objects like: users, accounts, players etc. that are required to be in sync with client connections. So the problem is how to wire up a particular client w

Manipulating connection strings

Every once in a while I see devs struggling with connection strings.  As a rule they seem inclined to use string concatenation, string.Replace or even string.SubString In case you didn't know here is the correct way to do it:  SqlConnectionStringBuilder