I learned enums when I learned C and from time to time I keep myself reminding about it and most of the time by re-reading from some source,it occurred to me that this is d
I started a personal project in, and I wanted to identify my packet ID, it looks like this:
enum{
//Client to server
//Connection
ID_KEEP_ALIVE = 0x00,
ID_LOGIN_REQUEST = 0x01,
ID_CONNECTING = 0x02,
ID_DISCONNECT = 0x03,
//Player actions
ID_PLAYER_INFO = 0x04,
ID_PLAYER_MOVE = 0x05,
ID_PLAYER_ATTACK = 0x06,
//Inventory
ID_LOOT_ITEM = 0x10,
ID_DESTROY_ITEM = 0x12,
ID_USE_ITEM = 0x13,
ID_EQUIP_ITEM = 0x15,
ID_UNEQUIP_ITEM = 0x16,
ID_DROP_ITEM = 0x17,
};
and then, when I receive a packet, I've got a huge switch that looks like this to process the packets and send them:
switch(packet.packetID){
case ID_KEEP_ALIVE:
//...
break;
case ID_LOGIN_REQUEST:
//...
break;
case ID_CONNECTING:
//...
break;
case ID_DISCONNECT:
//...
break;
//..
}
it's my best example, enjoy :)