C# Socket Server for Flash/ActionScript

After doing some research on available socket servers for Flash I decided to write my own in C#. Most of the server out there are written in Java and while there are some open source implementations I prefer to stick with a code base I know and understand.

I got the Flash movie to connect to the C# server yesterday using JSON protocal instead of XML as my transport mechanism. I used a .NET JSON library and an ActionScript 2.0 JSON library to build the objects on both sides. I created a C# class for passing data, serialize as a JSON string and send it the Flash movie. On the ActionScript side I created an AS class that mimics my C# data gram class and use the AS JSON lib to serialize and send that same object structure to the C# server. Working pretty good so far, I am able to login to the server and send and receive messages.

My next steps will be creating a basic flash game that I can use to run around and do battle while sending and receiving messages from the server. 

I have plans to make a Flash based PBBG with real time combat, we'll see how it goes. :) 


Flash and PBBGs

I've been looking into Flash as a possible alternate UI for my PBBG Perenthia because of the benefits of being able to write a socket server that Flash can connect to and provide real time updates to players. The only way to accomplish this in a web scenario is to constantly poll the server for updates, rather than have them pushed to the client. I am trying to weigh the options and impact of this along with the UI beneifts Flash would deliver, such as animated characters, mobs, etc.


Knights of the Realm PBBG Update

I just released another update to the Knights of the Realm 2 PBBG. The update includes several bug fixes reported by the players as well as a few enhancements requested by the players.

The Knights of the Realm 2 PBBG is a combat oriented game where players compete against each other in nightly tournament events. The game is free and only requires a browser to play.


GridView Grouping and Summaries

If you are looking to group your grid view results and provide summaries such as totals, etc. I found a great utility for grouping GridView results. It is a set of classes that provide a helper for your grids to allow grouping. The component is super easy to use just remember that if you don't use a data source control you have to handle the GridView Sorting event. You don't actually have to have any code in the event handler, just handle the event.


Perenthia Households

Over the next couple of days I will be implementing the household management screens into the main interface of my PBBG Perenthia. Players who create and manage a household will use these screens to add and edit ranks of advancement, set membership requirements, view active members and appoint household officers.

After the household screens are in place and tested I will implement the new tournament screen layouts which will allow players to participate in tournament events to increase their skills and fame.

Crafting is still bare bones and may be added during the beta, not sure yet how that will play out. Crafting will give players the ability to create items from core elements and other items. An example of crafting would be taking iron ore and using a forge to create a sword, maybe even wrap the hlt in leather. 

The adventuring aspect is more or less complete for the beta release and includes dynamically generated areas for players to roam around in complete with dynamic and randomly generated monsters. 

Skills will be the primary factors in all actions from adventuring to tournaments to crafting. The skills system is already in place but some hooks need to be added to the household interface to allow players to require certain levels of skills in order to advance within a household.

I am hoping these core elements will provide a flexible and fun playing environment for members. I have a large list of future enhancements and elements I removed from the alpha phase that could show themselves again, just not sure yet.

A new web site for Perenthia will go up when the game enters open beta so fi the site looks different when you visit again, be sure to sign up and play! 


X, Y, Z Coordinate Struct for .NET PBBGs

I created a struct in C# for storing the X, Y and Z coordinates for characters, objects and rooms within my current PBBG project Perenthia. The struct, called Vector, is serializable and can be used as the key value in a sorted or generic dictionary. Here is the code for the class.

[Serializable]    public struct Vector : IEquatable<Vector>    {        public static readonly Vector Empty = new Vector(0, 0, 0);        public Vector(int x, int y, int z)        {            _x = x;            _y = y;            _z = z;        }        public void SetLocation(int x, int y)        {            this.SetLocation(x, y, this.Z);        }        public void SetLocation(int x, int y, int z)        {            _x = x;            _y = y;            _z = z;        }        public Vector Copy()        {            return new Vector(this.X, this.Y, this.Z);        }        public static Vector FromString(string value)        {            if (!String.IsNullOrEmpty(value))            {                string[] parts = value.Split(',');                if (parts != null && parts.Length == 3)                {                    int x, y, z;                    if (Int32.TryParse(parts[0], out x))                    {                        if (Int32.TryParse(parts[1], out y))                        {                            if (Int32.TryParse(parts[2], out z))                            {                                return new Vector(x, y, z);                            }                        }                    }                }            }            return Vector.Empty;        }        #region GetHashCode        public override int GetHashCode()        {            // The Y value should always come first in any kind of sorting, comparison or hashing operations            // followed by X and then Z because typical loops would start with the Y value.            return (this.Y.GetHashCode() + this.X.GetHashCode() + this.Z.GetHashCode());        }        #endregion        #region Equals        public bool Equals(Vector obj)        {            // The Y value should always come first in any kind of sorting, comparison or hashing operations            // followed by X and then Z because typical loops would start with the Y value.            if (obj != null)            {                if (obj.Y == this.Y)                {                    if (obj.X == this.X)                    {                        return (obj.Z == this.Z);                    }                }            }            return false;        }        public override bool Equals(object obj)        {            if (obj is Vector)            {                return this.Equals((Vector)obj);            }            return base.Equals(obj);        }        #endregion        #region ToString        public override string ToString()        {            return String.Format("{0},{1},{2}", _x, _y, _z);        }        public string ToString(bool forDisplay)        {            if (forDisplay)            {                return String.Format("X = {0}, Y = {1}, Z = {2}", _x, _y, _z);            }            return this.ToString();        }        #endregion        #region Operators        public static Vector operator +(Vector v1, Vector v2)        {            return new Vector(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);        }        public static Vector operator -(Vector v1, Vector v2)        {            return new Vector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);        }        public static bool operator ==(Vector v1, Vector v2)        {            return v1.Equals(v2);        }        public static bool operator !=(Vector v1, Vector v2)        {            return (!v1.Equals(v2));        }        public static bool operator >=(Vector v1, Vector v2)        {            // The Y value should always come first in any kind of sorting, comparison or hashing operations            // followed by X and then Z because typical loops would start with the Y value.            if (v1.Y >= v2.Y)            {                if (v1.X >= v2.X)                {                    return (v1.Z >= v2.Z);                }            }            return false;        }        public static bool operator <=(Vector v1, Vector v2)        {            // The Y value should always come first in any kind of sorting, comparison or hashing operations            // followed by X and then Z because typical loops would start with the Y value.            if (v1.Y <= v2.Y)            {                if (v1.X <= v2.X)                {                    return (v1.Z <= v2.Z);                }            }            return false;        }        #endregion        #region Properties        private int _x;        public int X        {            get { return _x; }            set { _x = value; }        }        private int _y;        public int Y        {            get { return _y; }            set { _y = value; }        }        private int _z;        public int Z        {            get { return _z; }            set { _z = value; }        }        #endregion        #region IEquatable<Vector> Members        bool IEquatable<Vector>.Equals(Vector other)        {            return this.Equals(other);        }        #endregion    }



I have to say that BlogEngine.NET is a great blog utility. I was using .Text for a long time and just never wanted to go through the conversion to Community Server. I just did not need a community, I just wanted a blog. I reviewed a bunch of different blog engines out there and really liked all the features of BlogEngine.NET. If you are looking to setup a blog and want to have control over your data store using providers and have all the latest features like tagging, auto pings, etc. then snag BlogEngine.NET.


JavaScript Libraries

I found some good javascript libraries for PBBG or any kind of web development.

This one is a graphics library useful for drawing vector graphics to the browser. Works great, just remember to set the position:relative value of the DIV you wish to draw in. :)

DHTML: Draw Line, Ellipse, Oval, Circle, Polyline, Polygon, Triangle with JavaScript

This site has a collection of useful libraries for all manner of web related activities.

Javascript Toolbox: Reusable Libraries And Scripts Plus Information


PBBG Player Interactivity

I think one of the most overlooked but import feature in PBBGs is player interactivity. You can have the best looking game out there with the fatest database, application layer and what not but if you players can not interact with one another as the main focus of the game you will struggle to achieve sucess. There are plenty of folks out there who like solo game play, I am one of those, but the majority of folks want to interact with others. This is especially true with female players. While all players like to interact, not all male players will participate in interactive features unless they advance their character in some, females on the other hand will seek to interact regardless of advancement opportunities.

So, in short, figure out ways to allow players to interact within your games, keeping in mind which demographics you are targeting with the feature and you will see a greater return on investment for your game. 


Perenthia Update

I've had Perenthia in a private test phase over the past few weeks and have decided on the core features that will make it into the public beta of the game. I have a few components to remove and a little more testing to do before the game enters a live beta stage, I am hoping not more than a few weeks.

The game will feature Households which are player run groups where the players can setup the levels and requirements of advancement. Crafting will also be a major feature, allowing players to craft the various items to be used in game. These features will center around a fantasy world with magic and monsters. Another feature that should make it into the beta will be tournaments, both individual and household. More on these features later.


PBBG Mapper

I've been working on a tile mapping tool I call PBBG Mapper here lately while working on my persistent browser based games. The tool is a Windows based application written in C# 2.0 and will include some plugin functionality so that other developers can extend it an customize it. The progam saves all tile maps as XML for easy portability and works pretty well. I will post some screenshots once I get it into a full working version.


Role Playing Game Maps

I found some great tutorials for creating awesome looking role playing game maps using Photoshop. The site has videos that walk you through the steps to create the maps. Plan on seeing some maps based on these tutorials in my persistent browser based game Perenthia in the near future.


PBBG Game Engine

While building the persistent browser based game Perenthia I have been putting together a PBBG Engine that I am going to use to build additional games. Among those additional games will be Aelerion, which will be a space adventure game in which I plan to use Silverlight as the front end user interface.

The Knights of the Realm 2 uses a mixure of some of the code I wrote for the PBBG Engine and some of the code I migrated from the first version of the game. I also chose to try something new with Knights of the Realm in that I stored XML serialized objects in the database using my XQuery class. I decided to try this method to see what kind of impact it would have on game play performance and maintainability. Since Knights of the Realm is not a real time game and executes tournaments in the early hours of the morning I figured this would be a safer test.

Since writing Knights of the Realm 2 I decided not to use the XML serialiazation for my PBBG Engine because I want the engine to be able to support real time game play and serialization is just too slow. I did some perf testing with a database, xml serialization and flat text files and found that flat text files were the fastest when saving information, xml serlization was the slowest and database fell in the middle. When loading information back into objects the database was the fatest because I didn't have to do a lot of conversions from strings to integers like I did with the flat text files. Xml serialization came in last in loading as well and not just in miliseconds but was a good 3-4 seconds behind the database and flat files in both loading and saving. However, using an XmlReader and XmlWriter to read and write the Xml values into an Xml data type column in the database turned out to be faster than serialization but still slower than straight database access because of the need to convert Xml node value strings to integers.

My PBBG Engine will utilize a mixure of regular data type columns and xml columns in the database. The reasoning is that static things such as player name, race and gender will be static columns but the player table will also feature and xml data type column for storing custom properties. A base player object will contain a key/value collection where custom properties can be stored and that collection will use the XmlReader and XmlWriter to save the key/value pairs in the xml data type column.

I also plan on making use of the application cache in ASP.NET for some of the common objects such as rooms so that I am not making thousands of database calls everytime a player moves around in the world. Some of my initial tests have worked out quite well using a lightweight set of objects that represent rooms or tiles on a map. These objects contain just enough information to determine whether or not a player can move into the room and their coordinates in the overall map. 


Tooltips in PBBGs

I came across a great article on tooltips for persistent browser based games. In the article Vindexus shows how to use the BoxOver script to enhance PBBGs with tooltip functionality. His sample uses the box over script and the title of span tag. A good example of using simple pre-existing html tags to enhance the gaming interface.

I am working on including this functionality in my current PBBG The Knights of the Realm 2 and will also incorporate it into my other game. The use of tooltips does provide a great feature for users. I may incorporate a way to turn the tooltips on and off as well.