Sign in to follow this  
  • entries
    32
  • comments
    30
  • views
    10732

Realization is a funny thing.

Sign in to follow this  
Lacutis

79 views

Ok, so realization set in last night as I got the server part running.

I need to come up with a protocol to allow the server and client to communicate. For one, text is exremely inefficient, and for another, why would I do it with text which would be required to be parsed? So today I have been sketching out a simple protocol that I will use to allow the client and server to communicate.

Basically it is going to work like this. I have a base command class that looks like this:


class CCommand
{
public:
CCommand() { Type = COM_NONE; }
eComType Type;
}




For now, eComType is unimportant, it's an enumeration which will have each message type in it.

Now, using the magic of inheritance I can do this:

class CComDisplay : public CCommand
{
public:
CComDisplay() { Type = COM_DISPLAY; }

char m_Message[128];
}




And when I pop that through the network, I can do something like this:


switch((CCommand)TempCmd->Type)
{
case COM_NONE:
break;
case COM_DISPLAY:
DisplayMsg(TempCmd);
break;
}




Since every inherited command is a command, and contains the Type variable as the first variable in the class I can downcast it to the base type to check what it is. That will also allow me to know if the entire command is recieved from the network, as I only need to know the sizeof CCommand in order to check the type, then I know the size of the type to verify the size.

I'm fairly sure this will work and be expandable in the future. If anyone noticed something that I'm missing let me know.

After I get the command system coded, I'll need to import the entity system from my mud, with a few tweaks.

Then I have to work on the client :x

Or maybe I'll do some Lua scripting, who knows.

Edit (a couple hours later):
Ok, well that didn't take long, I've got the command passing and buffering code finished it looks like. I think I'll work on the entities.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now