#include <string>
#include <map>
#include <vector>
#include "LobbyPlayer.h"
#include "LobbyServer.h"
using namespace std;
typedef bool(*NetMsgProcProtoType)(LobbyPlayer* pPlayer, vector<int> &args);
struct NetMsgFunction
{
NetMsgFunction()
{
proc = 0;
MsgID = 0;
FucName = "";
}
NetMsgProcProtoType proc;
string FucName;
int MsgID;
};
class GmMgr
{
public:
GmMgr();
~GmMgr();
static GmMgr* getInstance() { static GmMgr gInstance; return &gInstance; };
virtual void RegMsgFun(string FucName, NetMsgProcProtoType fun)
{
NetMsgFunction ele;
ele.proc = fun;
ele.FucName = FucName;
g_FuncMap[FucName] = ele;
}
virtual bool CallHandleFunc(string FucName, LobbyPlayer* pPlayer, vector<int> &args);
void RegMsg();
bool CallGM(LobbyPlayer* pPlayer, const char* content);
public:
//加俱乐部资金
static bool AddGuildMoney(LobbyPlayer* pPlayer, vector<int> &args);
//加金币
static bool AddCoin(LobbyPlayer* pPlayer, vector<int> &args);
private:
map<string, NetMsgFunction> g_FuncMap;
};
#include "GM.h"
#include "Common/Common.h"
#include "Common/Text.h"
#include "GameClubManage.h"
GmMgr::GmMgr()
{
RegMsg();
}
GmMgr::~GmMgr()
{
}
void GmMgr::RegMsg()
{
RegMsgFun("@addguildmoney", GmMgr::AddGuildMoney);
RegMsgFun("@addcoin", GmMgr::AddCoin);
}
bool GmMgr::CallHandleFunc(string FucName, LobbyPlayer* pPlayer, vector<int> &args)
{
map<string, NetMsgFunction>::iterator it = g_FuncMap.find(FucName);
if (it == g_FuncMap.end())
{
return false;
}
return it->second.proc(pPlayer, args);
}
bool GmMgr::CallGM(LobbyPlayer* pPlayer, const char* content)
{
__log(_ERROR, __FUNCTION__, "%s", content);
vector<string> names;
char split[32] = "|";
Extralib::Text::split(content, split, names);
if (names.size() < 1)
return false;
vector<int> args;
for (int i=1;i < names.size();i++)
{
args.push_back(atoi(names[i].c_str()));
}
CallHandleFunc(names[0], pPlayer, args);
}
bool GmMgr::AddGuildMoney(LobbyPlayer* pPlayer, vector<int> &args)
{
if (args.size() < 2)
return false;
__log(_ERROR, __FUNCTION__, "%d", pPlayer->m_iUserID);
GameClubManage::getInstance()->OnChangeGuildCoin(args[0], pPlayer->m_iUserID, args[1], CONTROL_LOG);
return true;
}
bool GmMgr::AddCoin(LobbyPlayer* pPlayer, vector<int> &args)
{
__log(_ERROR, __FUNCTION__, "%d", pPlayer->m_iUserID);
if (args.size() < 1)
return false;
pPlayer->m_lpLobbyServer->OnChangeMoney(pPlayer->m_iUserID, (long long)args[0]);
return true;
}