I spent a little time yesterday searching for good examples of a basic asynchronous TCP socket class in C#. We’ll need one eventually at work, and I wanted to use it to throw together a simple MUD. Basically, I want to be able to instantiate the object (SocketServer server = new SocketServer()), set a few properties (server.Port = 4444, etc), and have it start listening for connections and data. When a connection is made or lost, I want it to raise events. When data is sent/received, I want it to raise events. Is that so hard? I could research it and code one myself, but I thought surely there was one already out there. Nope.
While I was researching that, I had a brainstorm (I often get them in the middle of doing something else). I’ve already got a small application that acts as an AIM bot using the AIM SDK. I was planning on one day creating a MUD with IM capabilities to go along with MUD Ideas #3. The thought was that the MUD would send you IMs about stuff like when another player knocks on your home’s door, the town crier has an announcement, or when an administrator was about to run a new quest. That would be simple enough. When a player knocks on the door to a player-owned house, check to see if the owner’s character logged out while in the house. If so, get the AIM ScreenName for that player and send him an IM saying, “Someone is knocking on your door.” If the player logged out in a city, send the town crier’s announcements, etc.
Then, I started thinking, “Well, what if I forego the socket layer and just use AIM as the connection method?” A player could send an IM to the MUD’s AIM ScreenName and the MUD would parse it just like it would from a telnet or MUD client. Well, I gave it a shot last night, threw together a quick and dirty MUD using AIM. It’s got 5 rooms (laid out in a plus [+]). You can navigate using standard N, S, E, W directions. You can view the room’s title, description, exits, and occupants (other players) using the LOOK command. The SAY command is next, which will be very simple, too. In order to do anything, you first send it an IM saying “LOGIN”. After that, you’re MUDding via IM.
I’m sure AIM has very strict spam levels that would keep such a mechanism from being a viable connection layer for a true MUD, but as a proof of concept, it sure works. Plus, I can start coding the objects for use when I have the socket layer done and use the IM interface for testing. You may be asking yourself, “Why code a MUD in C#?” Well, because I love that language. It’s easy to code, the IDE is powerful, and I already know it. With most MUD codebases out there, you need to use a Linux box (or Cygwin) to compile. Plus, I wanted to start one from scratch using OOP. I think I want to do the data side of things with XML files (for possible portability using Mono), but it would be much easier to do it with SQL Server, since I’m already familiar with it and have a data layer that can already do it. Using XML would help me learn, though, which is one of the main reasons I wanted to do this in the first place.
Ultimately, this will be a socket-based MUD with IM notifications, a web interface for some features (player-owned shops, auctions, world building, etc), RSS feeds for in-game news and events, and web services for data retrieval with widgets, etc.
Any suggestions or comments?

