Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpcodeMgr class, will be used to register opcode handlers
- Loading branch information
Showing
7 changed files
with
77 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "OpcodeMgr.h" | ||
#include <boost/function.hpp> | ||
#include <boost/bind.hpp> | ||
#include "Defines.h" | ||
#include "Log.h" | ||
#include "Packet.h" | ||
|
||
void OpcodeMgr::AddHandler(uint16 opcode, OpcHandler handler) | ||
{ | ||
#ifdef _DEBUG | ||
std::map<uint16, OpcHandler>::iterator itr = _handlers.find(opcode); | ||
if (itr != _handlers.end()) | ||
LeLog.WriteP(LOG_APP, "Handler for opcode %u already registered.", opcode); | ||
#endif | ||
|
||
_handlers[opcode] = handler; | ||
} | ||
|
||
void OpcodeMgr::BindAndCall(Packet* packet) | ||
{ | ||
OpcHandler* handler = GetHandler(packet->GetOpcode()); | ||
if (!handler) | ||
{ | ||
LeLog.WriteP(LOG_APP, "Handler for opcode %u not found.", packet->GetOpcode()); | ||
return; | ||
} | ||
|
||
boost::bind(*handler, packet)(); | ||
} | ||
|
||
OpcHandler* OpcodeMgr::GetHandler(uint16 opcode) | ||
{ | ||
std::map<uint16, OpcHandler>::iterator itr = _handlers.find(opcode); | ||
if (itr == _handlers.end()) | ||
return NULL; | ||
|
||
return &_handlers[opcode]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef OPCODEMGR_H | ||
#define OPCODEMGR_H | ||
|
||
#include <map> | ||
#include <boost/function.hpp> | ||
#include "Defines.h" | ||
|
||
class Packet; | ||
|
||
enum Direction | ||
{ | ||
ClientToServer = 0, // CMSG | ||
ServerToClient = 1, // SMSG | ||
}; | ||
|
||
typedef boost::function<void (Packet* packet)> OpcHandler; | ||
|
||
class OpcodeMgr | ||
{ | ||
public: | ||
void AddHandler(uint16 opcode, OpcHandler handler); | ||
|
||
void BindAndCall(Packet* packet); | ||
|
||
private: | ||
std::map<uint16, OpcHandler> _handlers; | ||
OpcHandler* GetHandler(uint16 opcode); | ||
}; | ||
|
||
#endif // OPCODEMGR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters