Пример #1
0
Status
loginServerOtpStatus(const Login &login, bool &on, long &timeout)
{
    const auto url = ABC_SERVER_ROOT "/v1/otp/status";
    ServerRequestJson json;
    ABC_CHECK(json.setup(login));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    struct ResultJson:
        public JsonObject
    {
        ABC_JSON_CONSTRUCTORS(ResultJson, JsonObject)
        ABC_JSON_BOOLEAN(on, "on", false)
        ABC_JSON_INTEGER(timeout, "otp_timeout", 0)
    } resultJson(replyJson.results());

    on = resultJson.on();
    if (on)
    {
        ABC_CHECK(resultJson.timeoutOk());
        timeout = resultJson.timeout();
    }
    return Status();
}
Пример #2
0
Status
loginServerGetPinPackage(DataSlice DID, DataSlice LPIN1, std::string &result,
                         AuthError &authError)
{
    const auto url = ABC_SERVER_ROOT "/v1/account/pinpackage/get";
    ServerRequestJson json;
    ABC_CHECK(json.set(ABC_SERVER_JSON_DID_FIELD, base64Encode(DID)));
    ABC_CHECK(json.set(ABC_SERVER_JSON_LPIN1_FIELD, base64Encode(LPIN1)));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply, &authError));

    struct ResultJson:
        public JsonObject
    {
        ABC_JSON_CONSTRUCTORS(ResultJson, JsonObject)
        ABC_JSON_STRING(package, "pin_package", nullptr)
    } resultJson(replyJson.results());

    ABC_CHECK(resultJson.packageOk());
    result = resultJson.package();
    return Status();
}
Пример #3
0
Status
loginServerGetLoginPackage(const Lobby &lobby,
                           DataSlice LP1, DataSlice LRA1, LoginPackage &result, JsonPtr &rootKeyBox)
{
    const auto url = ABC_SERVER_ROOT "/account/loginpackage/get";
    ServerRequestJson json;
    ABC_CHECK(json.setup(lobby));
    if (LP1.size())
        ABC_CHECK(json.authKeySet(base64Encode(LP1)));
    if (LRA1.size())
        ABC_CHECK(json.recoveryAuthKeySet(base64Encode(LRA1)));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply.body));
    ABC_CHECK(replyJson.ok());

    struct ResultJson:
        public JsonObject
    {
        ABC_JSON_CONSTRUCTORS(ResultJson, JsonObject)
        ABC_JSON_STRING(package, "login_package", nullptr)
        ABC_JSON_VALUE(rootKeyBox, "rootKeyBox", JsonPtr)
    } resultJson(replyJson.results());

    ABC_CHECK(resultJson.packageOk());
    ABC_CHECK(result.decode(resultJson.package()));
    if (json_is_object(resultJson.rootKeyBox().get()))
        rootKeyBox = resultJson.rootKeyBox();
    return Status();
}
Пример #4
0
Status
loginServerGetCarePackage(const Lobby &lobby, CarePackage &result)
{
    const auto url = ABC_SERVER_ROOT "/account/carepackage/get";
    ServerRequestJson json;
    ABC_CHECK(json.setup(lobby));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply.body));
    ABC_CHECK(replyJson.ok());

    struct ResultJson:
        public JsonObject
    {
        ABC_JSON_CONSTRUCTORS(ResultJson, JsonObject)
        ABC_JSON_STRING(package, "care_package", nullptr)
    } resultJson(replyJson.results());

    ABC_CHECK(resultJson.packageOk());
    ABC_CHECK(result.decode(resultJson.package()));
    return Status();
}
Пример #5
0
//http://www.tuicool.com/articles/YNZ7Jj
void* ResPonseThread::threadFunc(void *arg)
{
	ResPonseThread* thred=(ResPonseThread*)arg;	
	ODSocket csocket = SocketThread::GetInstance()->getSocket();
	if(SocketThread::GetInstance()->state==0)
	{
		while (true)
		{
			//have message come
			if (csocket.Select() == -2)
			{
				//deduct 2 head_length, 
				unsigned char recvLen[2]; //must less 65535 bytes
				memset(recvLen, 0, sizeof(recvLen));
				int actualRecvLen = csocket.Recv((char*)recvLen, sizeof(recvLen), 0);
				//log("actualRecvLen = %d", actualRecvLen);
				if (HEAD_LEN == actualRecvLen)
				{
					//the rest data
					int tLen = ((int)recvLen[0] << 8) + recvLen[1];
					char* recvBuf = new char[tLen];
					memset(recvBuf, 0, tLen);
					int recvResult = csocket.Recv(recvBuf, tLen, 0);
					std::string resultJson(recvBuf, tLen);
					log(" recveBuf =======>  %s ", recvBuf);
					delete[] recvBuf;
					recvBuf = nullptr;

					//json parse
					do
					{
						rapidjson::Document *_doc = new rapidjson::Document;
						_doc->Parse<0>(resultJson.c_str());
						CC_BREAK_IF(_doc->HasParseError());
						if (!_doc->IsObject())
							break;
						if (_doc->HasMember("Type"))
						{
							//to do 
							const rapidjson::Value &pType = _doc->operator[]("Type");
							std::string type = pType.GetString();
							Director::getInstance()->getScheduler()->performFunctionInCocosThread([=]() {
								Director::getInstance()->getEventDispatcher()->setEnabled(true);
								if (type == "LoginResult")
								{
									Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(FIND_DEVICE_MSG, (void *)_doc);
								}
								else if (type == "Joystick")
								{
									Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(CONTROLLER_JOYSTICK_MSG, (void *)_doc);
								}
								else if (type == "Shock")
								{
									Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(CONTROLLER_SHOCK_MSG, (void *)_doc);
								}
								else if (type == "SwapPositionResult")
								{
									Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(CUSTOM_SWAP_POSITION_MSG, (void *)_doc);
								}
								else if (type == "ResponseJoystickStatus")
								{
									Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(REPORT_JOYSTICK_STATUS_MSG, (void *)_doc);
								}
								delete _doc;
							});
						}
						else
						{
							delete _doc;
						}
					} while (0);
				}
				else
				{
					//log("ResPonseThread::threadFunc(void *arg) : exit !!! 2");
					////disconnect
					//break;
				}


			}//if (csocket.Select() == -2)

			//close socket -> exit thread !
			if (thred->isExit())
			{
				log("ResPonseThread::threadFunc(void *arg) : thred->isExit()");
				break;
			}
					
		}//while (true)
	}//if(SocketThread::GetInstance()->state==0)
	return NULL;
}