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.

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
    }

BlogEngine.NET

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.