262 lines
5.9 KiB
C++
262 lines
5.9 KiB
C++
|
|
#include "GlobalJosn.h"
|
|||
|
|
#include "cocos2d.h"
|
|||
|
|
#include "json/document.h"
|
|||
|
|
#include "Utility.h"
|
|||
|
|
#include "Platform.h"
|
|||
|
|
#include "cryptHeader.h"
|
|||
|
|
|
|||
|
|
USING_NS_CC;
|
|||
|
|
|
|||
|
|
GlobalJosn* GlobalJosn::s_configInstance = nullptr;
|
|||
|
|
|
|||
|
|
void GlobalJosn::init()
|
|||
|
|
{
|
|||
|
|
std::vector<tagGameConfig>().swap(m_vecGameConfig);
|
|||
|
|
m_vecGameConfig.reserve(10);
|
|||
|
|
|
|||
|
|
m_strLogonIp = LOGON_SERVER_ADDRESS;
|
|||
|
|
m_iPort = LOGON_SERVER_PORT;
|
|||
|
|
m_strAgentTip = "";
|
|||
|
|
m_strShareTip = "";
|
|||
|
|
|
|||
|
|
m_IsNotice = false;
|
|||
|
|
m_NoticeUrl = "";
|
|||
|
|
|
|||
|
|
m_strPayUrl = PAY_TO_PLAYER_HTTP_ADDRESS;
|
|||
|
|
m_strDuiHuanUrl = DUI_HUAN_HTTP_ADDRESS;
|
|||
|
|
m_strGongHuiUrl = GONG_HUI_HTTP_ADDRESS;
|
|||
|
|
m_RefreshTime = DEFINE_REFRESH_TIME;
|
|||
|
|
m_strShareUrl = SHARE_HTTP_ADDRESS;
|
|||
|
|
|
|||
|
|
#if (CC_TARGET_PLATFORM==CC_PLATFORM_WIN32)
|
|||
|
|
m_IsOpenNN = true;
|
|||
|
|
m_IsOpenZJH = true;
|
|||
|
|
m_IsOpenSSZ = true;
|
|||
|
|
#else
|
|||
|
|
m_IsOpenNN = false;
|
|||
|
|
m_IsOpenZJH = false;
|
|||
|
|
m_IsOpenSSZ = false;
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void GlobalJosn::clear()
|
|||
|
|
{
|
|||
|
|
std::vector<tagGameConfig>().swap(m_vecGameConfig);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void GlobalJosn::loadConfig()
|
|||
|
|
{
|
|||
|
|
//loadServerList();
|
|||
|
|
|
|||
|
|
loadShareList();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void GlobalJosn::loadServerList()
|
|||
|
|
{
|
|||
|
|
std::vector<tagGameConfig>().swap(m_vecGameConfig);
|
|||
|
|
|
|||
|
|
auto str = cocos2d::FileUtils::getInstance()->getStringFromFile("Platform/gamelist/GameConfig.json");
|
|||
|
|
rapidjson::Document doc;
|
|||
|
|
doc.Parse<0>(str.c_str());
|
|||
|
|
|
|||
|
|
if (doc.HasParseError() || !doc.IsArray())
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
|
for (rapidjson::SizeType i = 0; i < doc.Size(); ++i)
|
|||
|
|
{
|
|||
|
|
const rapidjson::Value &gameObject = doc[i];
|
|||
|
|
tagGameConfig config = tagGameConfig();
|
|||
|
|
|
|||
|
|
//<2F><>Ϸ<EFBFBD><CFB7>
|
|||
|
|
if (gameObject.HasMember("name") && gameObject["name"].IsString())
|
|||
|
|
{
|
|||
|
|
config.strGamename = gameObject["name"].GetString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//kind id
|
|||
|
|
if (gameObject.HasMember("kind") && gameObject["kind"].IsInt())
|
|||
|
|
{
|
|||
|
|
config.nGameKindId = gameObject["kind"].GetInt();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F>Ƿ<C7B7>
|
|||
|
|
if (gameObject.HasMember("active") && gameObject["active"].IsBool())
|
|||
|
|
{
|
|||
|
|
config.bGameActive = gameObject["active"].GetBool();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>Ϸ<EFBFBD>б<EFBFBD>
|
|||
|
|
if (gameObject.HasMember("addtolist") && gameObject["addtolist"].IsBool())
|
|||
|
|
{
|
|||
|
|
config.bAddToList = gameObject["addtolist"].GetBool();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
|
|||
|
|
if (gameObject.HasMember("GameRule") && gameObject["GameRule"].IsString())
|
|||
|
|
{
|
|||
|
|
config.strGameRule = gameObject["GameRule"].GetString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//ע<><D7A2>
|
|||
|
|
if (gameObject.HasMember("comment") && gameObject["comment"].IsString())
|
|||
|
|
{
|
|||
|
|
config.strComment = gameObject["comment"].GetString();
|
|||
|
|
cocos2d::log("game name:%s, kind:%d, comment:%s", config.strGamename.c_str(), config.nGameKindId, config.strGamename.c_str());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_vecGameConfig.push_back(config);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
std::string strCout = StringUtils::format("<EFBFBD><EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %d", (int)m_vecGameConfig.size());
|
|||
|
|
cocos2d::log("%s", utility::a_u8(strCout).c_str());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void GlobalJosn::loadShareList()
|
|||
|
|
{
|
|||
|
|
std::vector<tagShareInfo>().swap(m_vecShareList);
|
|||
|
|
|
|||
|
|
auto str = cocos2d::FileUtils::getInstance()->getStringFromFile("Platform/gamelist/notice.json");
|
|||
|
|
rapidjson::Document doc;
|
|||
|
|
doc.Parse<0>(str.c_str());
|
|||
|
|
|
|||
|
|
if (doc.HasParseError() || !doc.IsArray())
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
CC_ASSERT(!doc.HasParseError() && doc.IsArray());
|
|||
|
|
|
|||
|
|
for (rapidjson::SizeType i = 0; i < doc.Size(); i++)
|
|||
|
|
{
|
|||
|
|
const rapidjson::Value &gameObject = doc[i];
|
|||
|
|
tagShareInfo config = tagShareInfo();
|
|||
|
|
|
|||
|
|
//kind id
|
|||
|
|
if (gameObject.HasMember("kind") && gameObject["kind"].IsInt())
|
|||
|
|
{
|
|||
|
|
config.nKindID = gameObject["kind"].GetInt();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>
|
|||
|
|
if (gameObject.HasMember("comment") && gameObject["comment"].IsString())
|
|||
|
|
{
|
|||
|
|
config.strComment = gameObject["comment"].GetString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_vecShareList.push_back(config);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int GlobalJosn::getGameCount()
|
|||
|
|
{
|
|||
|
|
return (int)m_vecGameConfig.size();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
tagGameConfig GlobalJosn::getGameConfigByIdx(const int &nIdx, bool &bHave)
|
|||
|
|
{
|
|||
|
|
bHave = false;
|
|||
|
|
if (nIdx >= 0 && nIdx < (int)m_vecGameConfig.size())
|
|||
|
|
{
|
|||
|
|
bHave = true;
|
|||
|
|
return m_vecGameConfig[nIdx];
|
|||
|
|
}
|
|||
|
|
return tagGameConfig();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
tagGameConfig GlobalJosn::getGameConfigByKind(const int &nKind, bool &bHave)
|
|||
|
|
{
|
|||
|
|
bHave = false;
|
|||
|
|
for (int i = 0; i < (int)m_vecGameConfig.size(); ++i)
|
|||
|
|
{
|
|||
|
|
if (m_vecGameConfig[i].nGameKindId == nKind)
|
|||
|
|
{
|
|||
|
|
bHave = true;
|
|||
|
|
return m_vecGameConfig[i];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return tagGameConfig();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool GlobalJosn::isGameActive(const int &nKind)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < (int)m_vecGameConfig.size(); ++i)
|
|||
|
|
{
|
|||
|
|
if (m_vecGameConfig[i].nGameKindId == nKind)
|
|||
|
|
{
|
|||
|
|
return m_vecGameConfig[i].bGameActive;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool GlobalJosn::isGameInList(const int &nKind)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < (int)m_vecGameConfig.size(); ++i)
|
|||
|
|
{
|
|||
|
|
if (m_vecGameConfig[i].nGameKindId == nKind)
|
|||
|
|
{
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20>ı<EFBFBD><C4B1><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UTF-8<><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת
|
|||
|
|
std::string GlobalJosn::getShareInfoByKind(const int nKindID)
|
|||
|
|
{
|
|||
|
|
if (nKindID == SH_KIND_FRIEND_RUL || nKindID == SH_KIND_WEIXIN_URL)
|
|||
|
|
{
|
|||
|
|
return m_strShareUrl;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
for (int i = 0; i < (int)m_vecShareList.size(); ++i)
|
|||
|
|
{
|
|||
|
|
if (m_vecShareList[i].nKindID == nKindID)
|
|||
|
|
{
|
|||
|
|
return m_vecShareList[i].strComment;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>IP<49><50>PORT(<28><>ʽ:192.168.1.123,10086)
|
|||
|
|
void GlobalJosn::SetLoginIpAndPort(std::string strIpAndPortEncrypt)
|
|||
|
|
{
|
|||
|
|
if (strIpAndPortEncrypt.empty()) return;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD>KEY
|
|||
|
|
m_strAesKey = "45404b08fbfa98823c6f3dbb5ffd8259";
|
|||
|
|
coAesSetKey(m_strAesKey.c_str());
|
|||
|
|
//cocos2d::log("AesKey = %s", m_strAesKey.c_str());
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
std::string strBase64Decode = ""; // base64<36><34><EFBFBD><EFBFBD>
|
|||
|
|
std::string strAesDecode = ""; // aes<65><73><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
// BASE64<36><34><EFBFBD><EFBFBD>
|
|||
|
|
coBase64Decode(strBase64Decode, strIpAndPortEncrypt);
|
|||
|
|
//cocos2d::log("Base64Decode = %s", strBase64Decode.c_str());
|
|||
|
|
|
|||
|
|
// AES<45><53><EFBFBD><EFBFBD>
|
|||
|
|
coAesDecript(strBase64Decode, strAesDecode);
|
|||
|
|
//cocos2d::log("AesDecode = %s", strAesDecode.c_str());
|
|||
|
|
|
|||
|
|
// <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
|
|||
|
|
int __size = strAesDecode.length();
|
|||
|
|
int __ind = strAesDecode.find(',');
|
|||
|
|
if (std::string::npos == __ind) return;
|
|||
|
|
|
|||
|
|
std::string strPort = "";
|
|||
|
|
m_strLogonIp = strAesDecode.substr(0, __ind);
|
|||
|
|
strPort = strAesDecode.substr(__ind + 1);
|
|||
|
|
//cocos2d::log("m_strLogonIp = %s, strPort = %s", m_strLogonIp.c_str(), strPort.c_str());
|
|||
|
|
|
|||
|
|
// <20>˿<EFBFBD>ת<EFBFBD><D7AA>
|
|||
|
|
char* lpStrEnd = NULL;
|
|||
|
|
int iPort = (int)strtol(strPort.c_str(), &lpStrEnd, 10);
|
|||
|
|
GlobalJosn::getInstance()->m_iPort = iPort;
|
|||
|
|
}
|