342 lines
10 KiB
C++
342 lines
10 KiB
C++
#include "LogonScene.h"
|
|
#include "MainScene.h"
|
|
#include "PopScene.h"
|
|
#include "LoadingScene.h"
|
|
#include "UserInfo.h"
|
|
#include "JniFun.h"
|
|
#include "GlobalJosn.h"
|
|
#include "YvVoiceManager.hpp"
|
|
#include "13S_GameLogic.h"
|
|
|
|
LogonScene::LogonScene()
|
|
{
|
|
m_kLoginMission.setUrl(GlobalJosn::getInstance()->m_strLogonIp.c_str(), GlobalJosn::getInstance()->m_iPort);
|
|
|
|
MissionWeiXin::Instance().setMissionSink(this);
|
|
m_kLoginMission.setMissionSink(this);
|
|
}
|
|
LogonScene::~LogonScene()
|
|
{
|
|
|
|
}
|
|
bool LogonScene::init()
|
|
{
|
|
if (!Scene::init())
|
|
{
|
|
return false;
|
|
};
|
|
|
|
this->setTag(SCENE_TAG_LOGON);
|
|
|
|
auto rootPanel = CSLoader::createNode("Platform/LogonScene.csb");
|
|
CC_ASSERT(rootPanel != nullptr);
|
|
this->addChild(rootPanel);
|
|
|
|
auto txtVersion = (Text*)rootPanel->getChildByName("txtVersion");
|
|
CC_ASSERT(txtVersion != nullptr);
|
|
|
|
std::string strVersion = StringUtils::format("版本: v%s", JniFun::getVersionName().c_str());//JniFun::getVersionName();
|
|
txtVersion->setString(utility::a_u8(strVersion));
|
|
|
|
auto btnWeiXinLogon = (Button*)rootPanel->getChildByName("btnWeiXinLogon");
|
|
CC_ASSERT(btnWeiXinLogon != nullptr);
|
|
|
|
btnWeiXinLogon->addClickEventListener(CC_CALLBACK_1(LogonScene::onWeiXinLogon, this));
|
|
|
|
//对手机返回键的监听
|
|
auto keyListener = EventListenerKeyboard::create();
|
|
//和回调函数绑定
|
|
keyListener->onKeyReleased = CC_CALLBACK_2(LogonScene::onKeyReleased, this);
|
|
//添加到事件分发器中
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this);
|
|
|
|
return true;
|
|
}
|
|
|
|
//按键处理
|
|
void LogonScene::onKeyReleased(EventKeyboard::KeyCode keyCode, Event * pEvent)
|
|
{
|
|
//返回值处理
|
|
if (keyCode == EventKeyboard::KeyCode::KEY_ESCAPE)
|
|
{
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
|
|
auto callback = []{
|
|
Director::getInstance()->end();
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
exit(0);
|
|
#endif
|
|
};
|
|
|
|
PopScene::Instance().show(utility::a_u8("您确定要退出游戏吗?"), callback, nullptr);
|
|
}
|
|
}
|
|
|
|
void LogonScene::onEnter()
|
|
{
|
|
Scene::onEnter();
|
|
}
|
|
|
|
void LogonScene::onEnterTransitionDidFinish()
|
|
{
|
|
Scene::onEnterTransitionDidFinish();
|
|
|
|
LoadingScene::Instance().show(this);
|
|
|
|
JniFun::startLocation();
|
|
|
|
checkVersion();
|
|
}
|
|
|
|
void LogonScene::onExit()
|
|
{
|
|
Scene::onExit();
|
|
|
|
LoadingScene::Instance().hide();
|
|
}
|
|
|
|
void LogonScene::RegisterAccount()
|
|
{
|
|
CCAssert(m_kWeiXinUserInfo.openid != "","");
|
|
if (m_kWeiXinUserInfo.openid == "")
|
|
{
|
|
return;
|
|
}
|
|
std::string kAccounts = "WeiXin"+m_kWeiXinUserInfo.openid;
|
|
m_kPssword = "WeiXinPassword";
|
|
|
|
CMD_GP_RegisterAccounts kRegister;
|
|
zeromemory(&kRegister,sizeof(kRegister));
|
|
|
|
kRegister.dwPlazaVersion = Helps::Instance()->GetPlazaVersion();
|
|
kRegister.cbValidateFlags = MB_VALIDATE_FLAGS | LOW_VER_VALIDATE_FLAGS;
|
|
kRegister.cbGender = m_kWeiXinUserInfo.sex;
|
|
kRegister.wFaceID = 0;
|
|
|
|
strncpy(kRegister.szOpenId, m_kWeiXinUserInfo.openid.c_str(), LEN_OPENID - 1);
|
|
strncpy(kRegister.szUnionid, m_kWeiXinUserInfo.unionid.c_str(), LEN_UNIONID - 1);
|
|
strncpy(kRegister.szAccounts, kAccounts.c_str(), LEN_ACCOUNTS-1);
|
|
strncpy(kRegister.szLogonPass, m_kPssword.c_str(), LEN_MD5-1);
|
|
|
|
std::string kNickName = utility::u8_a(m_kWeiXinUserInfo.nickname);
|
|
strncpy(kRegister.szNickName, kNickName.c_str(), LEN_NICKNAME-1);
|
|
|
|
m_kLoginMission.registerServer(kRegister);
|
|
}
|
|
|
|
void LogonScene::onGPLoginSuccess()
|
|
{
|
|
cocos2d::log("kuili:-----LogonScene::onGPLoginSuccess call---------");
|
|
CGlobalUserInfo * pGlobalUserInfo=CGlobalUserInfo::GetInstance();
|
|
tagGlobalUserData * pGlobalUserData=pGlobalUserInfo->GetGlobalUserData();
|
|
|
|
//UserDefault::getInstance()->setStringForKey("Accounts",pGlobalUserData->szAccounts);
|
|
//UserDefault::getInstance()->setStringForKey("Password",m_kPssword);
|
|
|
|
if (pGlobalUserData != nullptr)
|
|
{
|
|
UserDefault::getInstance()->setStringForKey("Accounts", pGlobalUserData->szAccounts);
|
|
UserDefault::getInstance()->setStringForKey("Password", m_kPssword);
|
|
|
|
// 更新微信最新信息;
|
|
pGlobalUserData->cbGender = m_kWeiXinUserInfo.sex;
|
|
strncpy(pGlobalUserData->szNickName, m_kWeiXinUserInfo.nickname.c_str(), LEN_NICKNAME - 1);
|
|
strncpy(pGlobalUserData->szHeadHttp, m_kWeiXinUserInfo.headimgurl.c_str(), LEN_HEAD_HTTP - 1);
|
|
|
|
#if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32
|
|
UserInfo::Instance().modifyWeiXinInfo(m_kWeiXinUserInfo.sex, m_kWeiXinUserInfo.nickname, m_kWeiXinUserInfo.headimgurl);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
void LogonScene::onGPLoginComplete()
|
|
{
|
|
// 标识登陆完成
|
|
UserInfo::Instance().m_IsLogin = true;
|
|
|
|
Director::getInstance()->replaceScene(TransitionFade::create(0.3f, MainScene::create()));
|
|
}
|
|
|
|
void LogonScene::onGPLoginFailure(unsigned int iErrorCode,const char* szDescription)
|
|
{
|
|
if (iErrorCode == 3 || iErrorCode == 1)
|
|
{
|
|
RegisterAccount();
|
|
}
|
|
else
|
|
{
|
|
LoadingScene::Instance().hide();
|
|
PopScene::Instance().show(utility::a_u8(szDescription));
|
|
}
|
|
}
|
|
|
|
void LogonScene::onGPError(int err)
|
|
{
|
|
LoadingScene::Instance().hide();
|
|
//NoticeMsg::Instance().ShowTopMsg(utility::a_u8("网络错误。"));
|
|
PopScene::Instance().show(utility::a_u8("网络错误。"));
|
|
}
|
|
|
|
void LogonScene::onWxLoginSuccess(WxUserInfo kWxUserInfo )
|
|
{
|
|
m_kWeiXinUserInfo = kWxUserInfo;
|
|
|
|
std::string kAccounts = "WeiXin"+m_kWeiXinUserInfo.openid;
|
|
m_kPssword = "WeiXinPassword";
|
|
CMD_GP_LogonAccounts loginAccount;
|
|
zeromemory(&loginAccount, sizeof(loginAccount));
|
|
loginAccount.dwPlazaVersion = Helps::Instance()->GetPlazaVersion();
|
|
loginAccount.cbValidateFlags = MB_VALIDATE_FLAGS | LOW_VER_VALIDATE_FLAGS;
|
|
strcpy(loginAccount.szAccounts, kAccounts.c_str());
|
|
strcpy(loginAccount.szPassword, m_kPssword.c_str());
|
|
strcpy(loginAccount.szOpenId, m_kWeiXinUserInfo.openid.c_str());
|
|
strcpy(loginAccount.szUnionid, m_kWeiXinUserInfo.unionid.c_str());
|
|
|
|
YvVoiceManager::GetInstance()->CpLogin(kAccounts, kAccounts);
|
|
|
|
cocos2d::log("LogonScene::onWxLoginSuccess account = %s loginAccount.szPassword = %s", loginAccount.szAccounts, loginAccount.szPassword);
|
|
m_kLoginMission.loginAccount(loginAccount);
|
|
}
|
|
void LogonScene::onWxLoginFail(std::string kError)
|
|
{
|
|
LoadingScene::Instance().hide();
|
|
}
|
|
|
|
void LogonScene::onWeiXinLogon(Ref*)
|
|
{
|
|
YSAudioEngine::Instance().playBtnClickEffect();
|
|
|
|
LoadingScene::Instance().show(this);
|
|
|
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
|
std::string kNickName = GlobalJosn::getInstance()->m_strNickName;
|
|
|
|
if (kNickName.empty())
|
|
{
|
|
kNickName = "test4";
|
|
}
|
|
m_kWeiXinUserInfo.sex = 2;
|
|
m_kWeiXinUserInfo.unionid = kNickName;// "oU-m7t0ctHRsg1WaO0QtKOWYQswA";
|
|
m_kWeiXinUserInfo.openid = kNickName;
|
|
m_kWeiXinUserInfo.nickname = kNickName;
|
|
m_kWeiXinUserInfo.headimgurl = "http://wx.qlogo.cn/mmopen/B7yJAogVrU082WG0kG1JZp58rw9f4yuypJxCzLYAnB5rYQ1B7uY0GA4urZYaiaIs1CVxt4ia8fBYQjH3EAzUR1a39xN9ENrlkU/0";
|
|
|
|
onWxLoginSuccess(m_kWeiXinUserInfo);
|
|
#else
|
|
cocos2d::log("kuili:-----LogonScene::Button_WeiXinLogon call---------");
|
|
//MissionWeiXin::Instance().logonWeiXin();
|
|
this->scheduleOnce([=](float dt){
|
|
MissionWeiXin::Instance().logonWeiXin();
|
|
}, 0.1f, "logonWeiXin");
|
|
#endif
|
|
}
|
|
|
|
// 检测版本
|
|
void LogonScene::checkVersion()
|
|
{
|
|
#if (CC_TARGET_PLATFORM!=CC_PLATFORM_WIN32)
|
|
std::string strUrl = StringUtils::format("%s/interface/wnmj.aspx", WEB_SERVER_ADDRESS);
|
|
CWebReq::getInstance().sendRequestDocumentUrl(strUrl, CC_CALLBACK_1(LogonScene::ResponseResult, this), nullptr);
|
|
#else
|
|
LoadingScene::Instance().hide();
|
|
#endif
|
|
}
|
|
|
|
//请求版本信息结果
|
|
void LogonScene::ResponseResult(rapidjson::Document* pDoc)
|
|
{
|
|
LoadingScene::Instance().hide();
|
|
|
|
if (pDoc == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
std::string strLocalVer = JniFun::getVersionName();
|
|
std::string strprovince =CWebReq::getDataValueStr(pDoc, "province");
|
|
std::string strcity = CWebReq::getDataValueStr(pDoc, "city");
|
|
|
|
std::string strRealIpAndPort = CWebReq::getDataValueStr(pDoc, "version"); // 真实的IP和PORT
|
|
if (strRealIpAndPort.size() > 0)
|
|
{
|
|
GlobalJosn::getInstance()->SetLoginIpAndPort(strRealIpAndPort);
|
|
m_kLoginMission.setUrl(GlobalJosn::getInstance()->m_strLogonIp.c_str(), GlobalJosn::getInstance()->m_iPort);
|
|
}
|
|
cocos2d::log("LogonIp = %s, port = %d", GlobalJosn::getInstance()->m_strLogonIp.c_str(), GlobalJosn::getInstance()->m_iPort);
|
|
|
|
std::string strPayUrl = CWebReq::getDataValueStr(pDoc, "PayUrl"); // 充值地址;
|
|
if (strPayUrl.size() > 0)
|
|
{
|
|
GlobalJosn::getInstance()->m_strPayUrl = strPayUrl;
|
|
}
|
|
|
|
std::string strDuiHuanUrl = CWebReq::getDataValueStr(pDoc, "DuiHuanUrl"); // 兑换地址;
|
|
if (strDuiHuanUrl.size() > 0)
|
|
{
|
|
GlobalJosn::getInstance()->m_strDuiHuanUrl = strDuiHuanUrl;
|
|
}
|
|
|
|
std::string strGongHuiUrl = CWebReq::getDataValueStr(pDoc, "GongHuiUrl"); // 公会地址;
|
|
if (strGongHuiUrl.size() > 0)
|
|
{
|
|
GlobalJosn::getInstance()->m_strGongHuiUrl = strGongHuiUrl;
|
|
}
|
|
|
|
std::string strShareUrl = CWebReq::getDataValueStr(pDoc, "shareUrl"); // 分享地址;
|
|
if (strShareUrl.size() > 0)
|
|
{
|
|
GlobalJosn::getInstance()->m_strShareUrl = strShareUrl;
|
|
}
|
|
|
|
int isNotice = CWebReq::getDataValueInt(pDoc, "IsNotice");
|
|
int IsOpenNN = CWebReq::getDataValueInt(pDoc, "IsOpenNN");
|
|
int IsOpenZJH = CWebReq::getDataValueInt(pDoc, "IsOpenZJH");
|
|
int IsOpenSSZ = CWebReq::getDataValueInt(pDoc, "IsOpenSSZ");
|
|
|
|
std::string strNoticeUrl = CWebReq::getDataValueStr(pDoc, "NoticeUrl");
|
|
|
|
// 开启公告;
|
|
GlobalJosn::getInstance()->m_IsNotice = (isNotice == 1) ? true : false;
|
|
GlobalJosn::getInstance()->m_IsOpenNN = (IsOpenNN == 1) ? true : false;
|
|
GlobalJosn::getInstance()->m_IsOpenZJH = (IsOpenZJH == 1) ? true : false;
|
|
GlobalJosn::getInstance()->m_IsOpenSSZ = (IsOpenSSZ == 1) ? true : false;
|
|
|
|
GlobalJosn::getInstance()->m_NoticeUrl = strNoticeUrl;
|
|
|
|
UserInfo::Instance().setAddress(StringUtils::format("%s%s", strprovince.c_str(), strcity.c_str()));
|
|
|
|
int nRefreshTime = CWebReq::getDataValueInt(pDoc, "RefreshTime");
|
|
if (nRefreshTime <= 0)
|
|
{
|
|
GlobalJosn::getInstance()->m_RefreshTime = 30;
|
|
}
|
|
else
|
|
{
|
|
GlobalJosn::getInstance()->m_RefreshTime = nRefreshTime;
|
|
}
|
|
|
|
#if (CC_TARGET_PLATFORM==CC_PLATFORM_IOS)
|
|
std::string strLastIosVer = CWebReq::getDataValueStr(pDoc, "LastIosVersion");
|
|
|
|
if (strLocalVer.compare(strLastIosVer) != 0)
|
|
{
|
|
std::string strIPAUrl = CWebReq::getDataValueStr(pDoc, "IPAUrl");
|
|
auto callback = [=]{
|
|
JniFun::openURL(strIPAUrl);
|
|
};
|
|
|
|
PopScene::Instance().show(utility::a_u8("发现新版本,请前往官网下载并重新安装!"), callback);
|
|
}
|
|
#else
|
|
|
|
std::string strLastAndroidVer = CWebReq::getDataValueStr(pDoc, "LastAndroidVersion");
|
|
std::string strUrl = CWebReq::getDataValueStr(pDoc, "DownUrl");
|
|
std::string strDesc = CWebReq::getDataValueStr(pDoc, "Desc");
|
|
|
|
if (strLocalVer.compare(strLastAndroidVer) != 0)
|
|
{
|
|
JniFun::versionUpdate(strUrl.c_str(), strDesc.c_str(), 0, 1);
|
|
}
|
|
#endif
|
|
|
|
} |