Update: I'm sorry if maybe my question isn't clear enough. I've read about the command pattern, but unfortunately have not used it myself. I'm trying to figure out how I could use it (or some other pattern) to make game events abstract enough that the server can process them using a single Process() method. My main hang up here is making sure the game events receive enough information to actually DO what they need to do (e.g., log in a user and add them to the active user list, send map data, move a player, etc.). A relevant example would be very much appreciated.
I'm pretty new to game development but have decided to start working on a (relatively) simple, 2D MMORPG in my spare time. I would consider myself to be a very capable programmer and I have a good foundation of skills, but I'm still grappling with some of the design related to a client-server game. Specifically, I'm having a hard time thinking of an extensible way to process commands. Let me provide a functional example:
Log In Request
From a client-server architecture perspective, here's what I'm doing right now:
[Client]
My example identifies three key events that occur:
Process Log In
Validate the information the user provided, download the player information from the database (HP, MP, last location, etc.), and associate the player with a map and a connection.
Get Player Info
Send back information about the player's stats, equipment, experience, current map ID, and anything else that needs to be displayed on the UI.
Get Map Info
Send information to the player about all the tiles within a 50 tile radius...this should include tile information for a three-layer map and the locations and names of NPCs/monsters/players; when the player moves, more map information will be requested/updated.
You can see that each of these processes is different and requires different information. On the server-side, how can I do something like:
while (ServerIsRunning)
{
foreach (Client c in clients)
{
eventQueue.AddList(c.ReceiveAll());
}
foreach(GameEvent event in eventQueue)
{
event.Process();
}
int[] keys = messageQueue.Keys;
foreach (int key in keys)
{
Client c = clients.Get(key);
foreach(NetworkMessage message in messageQueue[key])
{
c.Send(message);
}
}
}
When I read what you're asking, you seem to be asking for "an extensible way of implementing command processing".
From the way you phrase it, your request obviously points to the Command Pattern.
I'm not a C# person, so sadly I can't do much of a job evaluating the plethora of suggestions Google provides. Here's one to get you started. http://www.c-sharpcorner.com/UploadFile/cupadhyay/CommandPatternsInCS11142005021734AM/CommandPatternsInCS.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With