Example #1
0
VOID CGetUserInfoHttpCMD::ProcessResult()
{
    DBG_INFO( _SDT( "[%s: %d]: Result(%s)" ), MSG_MARK, m_strResult.c_str() );

    Json::Value root;
    Json::Reader reader;
    if( !reader.parse( m_strResult, root ) )
    {
        SYS_CRITICAL( _SDT( "json parse error, result:%s" ), m_strResult.c_str() );
        //OnLoginExAck(	m_dwTransID, stLoginInfo.dwPlayerID, ERR_LOGIN::ID_LS_SERVER_NOT_STARTUP);
        return;
    }

    //检测数据个数,如果为零刚为出错,防止崩溃
    if (!root.isObject())
    {
        SYS_CRITICAL( _SDT( "json size error, result:%s" ), m_strResult.c_str() );
        //OnLoginExAck( m_dwTransID, stLoginInfo.dwPlayerID, ERR_LOGIN::ID_LS_SERVER_NOT_STARTUP);
        return;
    }

    //解析返回的状态码
    if (!root["errcode"].isInt())
    {
        SYS_CRITICAL( _SDT( "json parse error, result:%s" ), m_strResult.c_str() );
        return;
    }

    stAck.dwErrCode = root["errcode"].asInt();

    if (!root["datas"].isArray())
    {
        SYS_CRITICAL( _SDT( "json size error, result:%s" ), m_strResult.c_str() );
        return;
    }
    Json::Value datas = root["datas"];

    for (UINT32 idx = 0; idx < datas.size(); idx++)
    {
        Json::Value data = datas[idx];
        DT_USERINFO &stDT_USERINFO = stAck.astUserInfo[stAck.byNum];
        if (!data["type"].isInt())
        {
            continue;
        }
        stDT_USERINFO.byType = data["type"].asInt();
        if (!data["username"].isString())
        {
            continue;
        }
        SDStrncpy(stDT_USERINFO.aszUserName, data["username"].asCString(), USERNAME_LEN - 1);
        if (!data["nickname"].isString())
        {
            continue;
        }
        SDStrncpy(stDT_USERINFO.aszNickName, data["nickname"].asCString(), USERNAME_LEN - 1);
        stAck.byNum++;
    }
    ResponseMsg(CLIZS_GET_USERINFO_ACK, (CHAR*)(&stAck));
}
Example #2
0
VOID CUnBindDeviceHttpCMD::ProcessResult()
{
    DBG_INFO( _SDT( "[%s: %d]: Result(%s)" ), MSG_MARK, m_strResult.c_str() );

    Json::Value root;
    Json::Reader reader;
    if( !reader.parse( m_strResult, root ) )
    {
        SYS_CRITICAL( _SDT( "json parse error, result:%s" ), m_strResult.c_str() );
        //OnLoginExAck(	m_dwTransID, stLoginInfo.dwPlayerID, ERR_LOGIN::ID_LS_SERVER_NOT_STARTUP);
        return;
    }

    //检测数据个数,如果为零刚为出错,防止崩溃
    if (!root.isObject())
    {
        SYS_CRITICAL( _SDT( "json size error, result:%s" ), m_strResult.c_str() );
        //OnLoginExAck( m_dwTransID, stLoginInfo.dwPlayerID, ERR_LOGIN::ID_LS_SERVER_NOT_STARTUP);
        return;
    }

    //解析返回的状态码
    if (!root["errcode"].isInt())
    {
        SYS_CRITICAL( _SDT( "json parse error, result:%s" ), m_strResult.c_str() );
        return;
    }

    stAck.wErrCode = ERR_UNBIND_DEVICE::ID_SUCCESS;
    ResponseMsg(CLIZS_UN_BIND_DEVICE_ACK, (CHAR*)(&stAck));
}
Example #3
0
VOID CBindMobileCMD::OnExecuted()
{
    if (FALSE == m_bSuccess)
    {
		ResponseMsg(CLILS_BIND_MOBILE_ACK, (CHAR*)(&m_stAck));
		return;
	}
    if ( m_stAck.wErrCode != ERR_BIND_MOBILE::ID_SUCCESS)
    {
        ResponseMsg(CLILS_BIND_MOBILE_ACK, (CHAR*)(&m_stAck));
        return;
    }
    CBaseSmsCMD*	poBaseSmsCMD = CSmsMgr::Instance()->CreateCmd(ESMS_BINDMOBILE);
    if (NULL == poBaseSmsCMD)
    {
        SET_OTHER_ERR(m_stAck.wErrCode);
        ResponseMsg(CLILS_BIND_MOBILE_ACK, (CHAR*)(&m_stAck));
        return;
    }
    poBaseSmsCMD->SetUserData(m_pUserData, sizeof(PKT_CLILS_BIND_MOBILE_REQ), m_dwTransID);
    CSmsMgr::Instance()->AddCommand(poBaseSmsCMD);
}
Example #4
0
BOOL CGetUserInfoHttpCMD::OnExecuted()
{
    if (FALSE == m_bError)
    {
        stAck.dwErrCode = ERR_GET_USERINFO::ID_SUCCESS;
        ResponseMsg(CLIZS_GET_USERINFO_ACK, (CHAR*)(&stAck));
    }
    else
    {
        ProcessResult();
    }
    return TRUE;
}
Example #5
0
BOOL CUnBindDeviceHttpCMD::OnExecuted()
{
    if (FALSE == m_bError)
    {
        stAck.wErrCode = ERR_UNBIND_DEVICE::ID_SUCCESS;
        ResponseMsg(CLIZS_UN_BIND_DEVICE_ACK, (CHAR*)(&stAck));
    }
    else
    {
        ProcessResult();
    }
    return TRUE;
}
bool NFCHttpServerModule::OnReceiveNetPack(const NFHttpRequest& req)
{
	auto it = mMsgCBMap.GetElement(req.type);
	if (it)
	{
		auto itPath = it->find(req.path);
		if (it->end() != itPath)
		{
			HTTP_RECEIVE_FUNCTOR_PTR& pFunPtr = itPath->second;
			HTTP_RECEIVE_FUNCTOR* pFunc = pFunPtr.get();
			try
			{
				pFunc->operator()(req);
			}
			catch (const std::exception&)
			{
				ResponseMsg(req, "unknow error", NFWebStatus::WEB_INTER_ERROR);
			}
			return true;
		}
	}

	return ResponseMsg(req, "", NFWebStatus::WEB_ERROR);
}
Example #7
0
VOID CPlayBindCMD::OnExecuted()
{
    m_stAck.wErrCode = m_wErrCode;
    ResponseMsg(CLILS_BIND_ACK, (CHAR*)(&m_stAck));
}
Example #8
0
VOID CUnBindDeviceCMD::OnExecuted()
{
    ResponseMsg(CLIZS_UN_BIND_DEVICE_ACK, (CHAR*)(&m_stAck));
}
bool NFCHttpServer::ResponseFile(const NFHttpRequest& req, const std::string& strPath, const std::string& strFileName)
{
    //Add response type
    std::map<std::string, std::string> typeMap;
    typeMap["txt"] = "text/plain";
    typeMap["txt"] = "text/plain";
    typeMap["c"] = "text/plain";
    typeMap["h"] = "text/plain";
    typeMap["html"] = "text/html";
    typeMap["htm"] = "text/htm";
    typeMap["css"] = "text/css";
    typeMap["gif"] = "image/gif";
    typeMap["jpg"] = "image/jpeg";
    typeMap["jpeg"] = "image/jpeg";
    typeMap["png"] = "image/png";
    typeMap["pdf"] = "application/pdf";
    typeMap["ps"] = "application/postsript";

    std::string strFilePath = strPath;
    if (strFilePath.find_last_of("/") != strFilePath.size())
    {
        strFilePath += "/";
    }

    strFilePath = strFilePath + req.url;

    int fd = -1;
    struct stat st;
    if (stat(strFilePath.c_str(), &st) < 0)
    {
        std::string errMsg = strFilePath + strFileName;
        ResponseMsg(req, errMsg.c_str(), NFWebStatus::WEB_ERROR, errMsg.c_str());

        return false;
    }

    if (S_ISDIR(st.st_mode))
    {
        strFilePath += "/" + strFileName;
    }

    if (stat(strFilePath.c_str(), &st) < 0)
    {
        std::string errMsg = strFilePath + strFilePath;
        ResponseMsg(req, errMsg.c_str(), NFWebStatus::WEB_ERROR, errMsg.c_str());
        return false;
    }

#if NF_PLATFORM == NF_PLATFORM_WIN
    if ((fd = open(strFilePath.c_str(), O_RDONLY | O_BINARY)) < 0) {
#else
    if ((fd = open(strFilePath.c_str(), O_RDONLY)) < 0)
    {
#endif
        ResponseMsg(req, "error", NFWebStatus::WEB_ERROR, "error");
        return false;
    }

    if (fstat(fd, &st) < 0)
    {
        ResponseMsg(req, "error", NFWebStatus::WEB_ERROR, "error");
        return false;
    }

    const char* last_period = strrchr(strFilePath.c_str(), '.');
    std::string strType = last_period + 1;
    if (typeMap.find(strType) == typeMap.end())
    {
        strType = "application/misc";
    } else
    {
        strType = typeMap[strType];
    }
    ResponseFile(req, fd, st, strType);
    return false;
}

bool NFCHttpServer::ResponseFile(const NFHttpRequest& req, const int fd, struct stat st, const std::string& strType)
{
    evhttp_request* pHttpReq = (evhttp_request*) req.req;

    //create buffer
    struct evbuffer* eventBuffer = evbuffer_new();
    //send data
    evbuffer_add_file(eventBuffer, fd, 0, st.st_size);
    evhttp_add_header(evhttp_request_get_output_headers(pHttpReq), "Content-Type", strType.c_str());
    evhttp_send_reply(pHttpReq, 200, "OK", eventBuffer);

    //free
    evbuffer_free(eventBuffer);
    return true;
}
Example #10
0
VOID CGetUserInfoCMD::OnExecuted()
{
    ResponseMsg(CLIZS_GET_USERINFO_ACK, (CHAR*)(&m_stAck));
}