227 lines
5.5 KiB
C++
227 lines
5.5 KiB
C++
|
|
#include "GlobalUserInfo.h"
|
|||
|
|
|
|||
|
|
#include "external/json/document.h"
|
|||
|
|
#include "JniFun.h"
|
|||
|
|
#include "Utility.h"
|
|||
|
|
|
|||
|
|
CGlobalUserInfo __gGlobalUserInfo; //<2F>û<EFBFBD><C3BB><EFBFBD>Ϣ
|
|||
|
|
|
|||
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|||
|
|
|
|||
|
|
//<2F><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
|||
|
|
CGlobalUserInfo * CGlobalUserInfo::m_pGlobalUserInfo=0; //<2F>û<EFBFBD><C3BB><EFBFBD>Ϣ
|
|||
|
|
GlobalUserInfoSink * CGlobalUserInfo::m_pUserInfoSink=0; //<2F>û<EFBFBD><C3BB><EFBFBD>Ϣ
|
|||
|
|
|
|||
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>캯<EFBFBD><ECBAAF>
|
|||
|
|
CGlobalUserInfo::CGlobalUserInfo()
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD>
|
|||
|
|
ASSERT(m_pGlobalUserInfo==0);
|
|||
|
|
if (m_pGlobalUserInfo==0) m_pGlobalUserInfo=this;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
|
|||
|
|
zeromemory(&m_GlobalUserData,sizeof(m_GlobalUserData));
|
|||
|
|
zeromemory(&m_IndividualUserData,sizeof(m_IndividualUserData));
|
|||
|
|
|
|||
|
|
m_IsShowLottery = true;
|
|||
|
|
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
CGlobalUserInfo::~CGlobalUserInfo()
|
|||
|
|
{
|
|||
|
|
//<2F>ͷŶ<CDB7><C5B6><EFBFBD>
|
|||
|
|
ASSERT(m_pGlobalUserInfo==this);
|
|||
|
|
if (m_pGlobalUserInfo==this) m_pGlobalUserInfo=0;
|
|||
|
|
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void CGlobalUserInfo::ResetUserInfoData()
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
|
|||
|
|
zeromemory(&m_GlobalUserData,sizeof(m_GlobalUserData));
|
|||
|
|
zeromemory(&m_IndividualUserData,sizeof(m_IndividualUserData));
|
|||
|
|
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
void CGlobalUserInfo::setUserScore(SCORE lScore)
|
|||
|
|
{
|
|||
|
|
m_pGlobalUserInfo->GetGlobalUserData()->lUserScore = lScore;
|
|||
|
|
upPlayerInfo();
|
|||
|
|
}
|
|||
|
|
void CGlobalUserInfo::setNickName(std::string kName)
|
|||
|
|
{
|
|||
|
|
strncpy(m_pGlobalUserInfo->GetGlobalUserData()->szNickName,
|
|||
|
|
(kName.c_str()), countarray(m_pGlobalUserInfo->GetGlobalUserData()->szNickName));
|
|||
|
|
upPlayerInfo();
|
|||
|
|
}
|
|||
|
|
void CGlobalUserInfo::setAccounts(std::string kAccounts)
|
|||
|
|
{
|
|||
|
|
strncpy(m_pGlobalUserInfo->GetGlobalUserData()->szAccounts,
|
|||
|
|
(kAccounts.c_str()), countarray(m_pGlobalUserInfo->GetGlobalUserData()->szAccounts));
|
|||
|
|
upPlayerInfo();
|
|||
|
|
}
|
|||
|
|
void CGlobalUserInfo::setUserInsure(SCORE lScore)
|
|||
|
|
{
|
|||
|
|
m_pGlobalUserInfo->GetGlobalUserData()->lUserInsure = lScore;
|
|||
|
|
upPlayerInfo();
|
|||
|
|
}
|
|||
|
|
uint32 CGlobalUserInfo::getUserID()
|
|||
|
|
{
|
|||
|
|
return m_pGlobalUserInfo->GetGlobalUserData()->dwUserID;
|
|||
|
|
}
|
|||
|
|
uint32 CGlobalUserInfo::getGameID()
|
|||
|
|
{
|
|||
|
|
return m_pGlobalUserInfo->GetGlobalUserData()->dwGameID;
|
|||
|
|
}
|
|||
|
|
char* CGlobalUserInfo::getPassword()
|
|||
|
|
{
|
|||
|
|
return m_pGlobalUserInfo->GetGlobalUserData()->szPassword;
|
|||
|
|
}
|
|||
|
|
uint8 CGlobalUserInfo::getGender()
|
|||
|
|
{
|
|||
|
|
return m_pGlobalUserInfo->GetGlobalUserData()->cbGender;
|
|||
|
|
}
|
|||
|
|
std::string CGlobalUserInfo::getNickName()
|
|||
|
|
{
|
|||
|
|
return m_pGlobalUserInfo->GetGlobalUserData()->szNickName;
|
|||
|
|
}
|
|||
|
|
std::string CGlobalUserInfo::getHeadHttp()
|
|||
|
|
{
|
|||
|
|
return m_pGlobalUserInfo->GetGlobalUserData()->szHeadHttp;
|
|||
|
|
}
|
|||
|
|
std::string CGlobalUserInfo::getUserChannel()
|
|||
|
|
{
|
|||
|
|
return m_pGlobalUserInfo->GetGlobalUserData()->szUserChannel;
|
|||
|
|
}
|
|||
|
|
std::string CGlobalUserInfo::getAccounts()
|
|||
|
|
{
|
|||
|
|
return m_pGlobalUserInfo->GetGlobalUserData()->szAccounts;
|
|||
|
|
}
|
|||
|
|
SCORE CGlobalUserInfo::getUserScore()
|
|||
|
|
{
|
|||
|
|
return m_pGlobalUserInfo->GetGlobalUserData()->lUserScore;
|
|||
|
|
}
|
|||
|
|
SCORE CGlobalUserInfo::getUserInsure()
|
|||
|
|
{
|
|||
|
|
return m_pGlobalUserInfo->GetGlobalUserData()->lUserInsure;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CGlobalUserInfo::setSink(GlobalUserInfoSink* pSink)
|
|||
|
|
{
|
|||
|
|
m_pUserInfoSink = pSink;
|
|||
|
|
}
|
|||
|
|
void CGlobalUserInfo::upPlayerInfo()
|
|||
|
|
{
|
|||
|
|
if (m_pUserInfoSink)
|
|||
|
|
{
|
|||
|
|
m_pUserInfoSink->upPlayerInfo();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
void CGlobalUserInfo::LoginSucess()
|
|||
|
|
{
|
|||
|
|
if (m_pUserInfoSink)
|
|||
|
|
{
|
|||
|
|
m_pUserInfoSink->LoginSucess();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
std::string CGlobalUserInfo::getPhoneNumber()
|
|||
|
|
{
|
|||
|
|
return m_IndividualUserData.szMobilePhone;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void CGlobalUserInfo::onLocationChanaged(std::string strJson)
|
|||
|
|
{
|
|||
|
|
rapidjson::Document doc;
|
|||
|
|
doc.Parse<0>(strJson.c_str());
|
|||
|
|
if (doc.GetParseError())
|
|||
|
|
{
|
|||
|
|
cocos2d::log("%s", strJson.c_str());
|
|||
|
|
cocos2d::log("------------------------------");
|
|||
|
|
return ;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (doc.HasMember("ret") && doc["ret"].IsBool())
|
|||
|
|
{
|
|||
|
|
bool bRet = doc["ret"].GetBool();
|
|||
|
|
if ( bRet )
|
|||
|
|
{
|
|||
|
|
m_UserAddr.isInit = true;
|
|||
|
|
if (doc.HasMember("latitude") && doc["latitude"].IsDouble())
|
|||
|
|
{
|
|||
|
|
m_UserAddr.latitude = doc["latitude"].GetDouble();
|
|||
|
|
}
|
|||
|
|
if (doc.HasMember("longitude") && doc["longitude"].IsDouble())
|
|||
|
|
{
|
|||
|
|
m_UserAddr.longitude = doc["longitude"].GetDouble();
|
|||
|
|
}
|
|||
|
|
if (doc.HasMember("accuracy") && doc["accuracy"].IsDouble())
|
|||
|
|
{
|
|||
|
|
m_UserAddr.accuracy = doc["accuracy"].GetDouble();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (doc.HasMember("provider") && doc["provider"].IsString())
|
|||
|
|
{
|
|||
|
|
m_UserAddr.strProvider = doc["provider"].GetString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (doc.HasMember("address") && doc["address"].IsString())
|
|||
|
|
{
|
|||
|
|
m_UserAddr.strAddress = doc["address"].GetString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
std::string strInfo = cocos2d::StringUtils::format("%f, %f, %f, %s, %s", m_UserAddr.latitude, m_UserAddr.longitude,
|
|||
|
|
m_UserAddr.accuracy, m_UserAddr.strAddress.c_str(), m_UserAddr.strProvider.c_str());
|
|||
|
|
cocos2d::log("%s", strInfo.c_str());
|
|||
|
|
|
|||
|
|
//JniFun::stopLocation();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>;
|
|||
|
|
tagUserAddr* CGlobalUserInfo::GetUserAddr()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
|||
|
|
|
|||
|
|
m_UserAddr.isInit = true;
|
|||
|
|
|
|||
|
|
m_UserAddr.accuracy = 150.0f;
|
|||
|
|
m_UserAddr.latitude = 39.915129f;
|
|||
|
|
m_UserAddr.longitude = 116.4039945f;
|
|||
|
|
m_UserAddr.strAddress = utility::a_u8("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>찲<EFBFBD><EFBFBD>");
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
return &m_UserAddr;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC>ľ<EFBFBD><C4BE><EFBFBD>;
|
|||
|
|
double CGlobalUserInfo::GetDistance(double latitude, double longitude)
|
|||
|
|
{
|
|||
|
|
double radLat1 = radian(m_UserAddr.latitude);
|
|||
|
|
double radLat2 = radian(latitude);
|
|||
|
|
|
|||
|
|
double a = radLat1 - radLat2;
|
|||
|
|
double b = radian(m_UserAddr.longitude) - radian(longitude);
|
|||
|
|
|
|||
|
|
double dst = 2 * asin((sqrt(pow(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2))));
|
|||
|
|
dst = dst * EARTH_RADIUS;
|
|||
|
|
dst = round(dst * 10000) / 10000;
|
|||
|
|
|
|||
|
|
return dst;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><EFBFBD>;
|
|||
|
|
double CGlobalUserInfo::radian(double d)
|
|||
|
|
{
|
|||
|
|
return d * PI / 180.0f; //<2F>Ƕ<EFBFBD>1? = <20><> / 180
|
|||
|
|
}
|
|||
|
|
//////////////////////////////////////////////////////////////////////////////////
|