zoukankan      html  css  js  c++  java
  • [手游项目4]GM系统,消息映射

    
    #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;
    }
  • 相关阅读:
    MYSQL判断某个表是否已经存在
    百度、雅虎、谷歌搜索引擎接口调用注意事项
    Codeigniter整合Tank Auth权限类库的教程
    短链接的生成算法
    自定义String
    运算符和结合性
    字符串类封装
    运算符重载
    数组类封装
    友元
  • 原文地址:https://www.cnblogs.com/byfei/p/14104104.html
Copyright © 2011-2022 走看看