コード例 #1
0
ファイル: Obj_PlayerOther.cpp プロジェクト: brock7/TianLong
//发出请求更详细信息的请求
VOID CObject_PlayerOther::SendEuipRequest(VOID)
{
	if(GetServerID() == -1) return;

	CGCharAskEquipment msg;
	msg.setObjID((ObjID_t)GetServerID());

	CNetManager::GetMe()->SendPacket(&msg);
}
コード例 #2
0
ファイル: Obj_PlayerOther.cpp プロジェクト: brock7/TianLong
// 左键指令的分析
BOOL CObject_PlayerOther::FillMouseCommand_Left( SCommand_Mouse *pOutCmd, tActionItem* pActiveSkill )
{
	pOutCmd->m_typeMouse = SCommand_Mouse::MCT_NULL;

	//是物品
	if(pActiveSkill && pActiveSkill->GetType() == AOT_ITEM)
	{
		//鼠标上挂的是一个物品
		return CObject_PlayerNPC::FillMouseCommand_Left(pOutCmd, pActiveSkill);
	}
	else
	{
		ENUM_RELATION eCampType = CGameProcedure::s_pGameInterface->GetCampType( CObjectManager::GetMe()->GetMySelf(), this );
		switch ( eCampType )
		{
		case RELATION_FRIEND:
			{
				if ( pActiveSkill != NULL
					&& pActiveSkill->GetType() == AOT_MOUSECMD_ADDFRIEND )
				{
					pOutCmd->m_typeMouse  = SCommand_Mouse::MCT_UI_USE_ADDFRIEND;
					pOutCmd->m_adwParam[0] = GetServerID();
				}
				else 
				if ( pActiveSkill != NULL
					&& pActiveSkill->GetType() == AOT_MOUSECMD_EXCHANGE )
				{
					pOutCmd->m_typeMouse  = SCommand_Mouse::MCT_UI_USE_EXCHANGE;
					pOutCmd->m_adwParam[0] = GetServerID();
				}
				break;
			}
		case RELATION_ENEMY:
		default:
			{
				if ( pActiveSkill != NULL
					&& pActiveSkill->GetType() == AOT_SKILL )
				{
					const SCLIENT_SKILL* pSkillImpl = (const SCLIENT_SKILL*)pActiveSkill->GetImpl();
					if(pSkillImpl != NULL
						&& pSkillImpl->m_pDefine->m_nSelectType == SELECT_TYPE_CHARACTER)
					{
						pOutCmd->m_typeMouse = SCommand_Mouse::MCT_SKILL_OBJ;
						pOutCmd->m_apParam[0] = (VOID*)pActiveSkill;
						pOutCmd->m_adwParam[1] = GetServerID();
					}
				}
			}
			break;
		}
	}
	return TRUE;
}
コード例 #3
0
bool ConnectionManagerToAccess::start() {
    //packet_streamer
    packet_streamer_.setPacketFactory(&packet_factory_);
    transport_for_access_.start();

    //依赖接入服务
    std::vector<const char*> access_specs=
        TBSYS_CONFIG.getStringList("access_server", "access_spec");
    if (access_specs.size() <= 0) {
        TBSYS_LOG(ERROR,"server_type_num == 0");
        return false;
    }

    tbnet::Connection* conn;
    uint64_t server_id;
    for (int i=0;i<access_specs.size();i++) {
        conn=transport_for_access_.connect(access_specs[i],
            &packet_streamer_,true);
        if (NULL==conn) {
            TBSYS_LOG(ERROR,"connect to access-%s fail", access_specs[i]);
            return false;
        }
        conn->setDefaultPacketHandler(this);
        conn->setQueueLimit(_queueLimit);
        conn->setQueueTimeout(_queueTimeout);

        server_id=GetServerID(access_specs[i]);
        assert(server_id==conn->getServerId());
        conn_map_[conn->getServerId()]=conn;
    }

    return true;
}
コード例 #4
0
ファイル: User.cpp プロジェクト: gangzi4494/web-pap
// 给该玩家发送某好友下线的信息
VOID USER::SendRelationOfflineMsg(USER* pUser)
{
__ENTER_FUNCTION

    Assert( pUser );

    if( UserStatus() != US_NORMAL )
    {
        return;
    }

    ServerPlayer* pServerPlayer = g_pServerManager->GetServerPlayer( GetServerID() );
    if( pServerPlayer == NULL )
    {
        Assert( pServerPlayer );
        return;
    }

    WGRelation Msg;

    WG_RELATION* pRelation = Msg.GetRelation();

    pRelation->SetPlayerID( GetPlayerID() );
    pRelation->m_Type = RET_RELATIONOFFLINE;
    pRelation->m_RelationGUID.SetTargetGUID( pUser->GetGUID() );

    pServerPlayer->SendPacket( &Msg );

__LEAVE_FUNCTION
}
コード例 #5
0
ファイル: Obj_Bus.cpp プロジェクト: gitrider/wxsj2
VOID CObject_Bus::UpdateMemberRenderInterfaceByIndex(INT nIndex)
{
	if(m_anPassengerIDs[nIndex] == INVALID_ID)
		return;

	if(m_abPassengerAttacheds[nIndex])
		return;

	if(m_pRenderInterface != NULL && m_pBusData != NULL && strlen(m_pBusData->m_aSeatInfo[nIndex].m_pszLocator) > 0)
	{
		CObject *pObj = (CObject*)(CObjectManager::GetMe()->FindServerObject(m_anPassengerIDs[nIndex]));
		if(pObj != NULL && pObj->GetRenderInterface() != NULL)
		{
			m_pRenderInterface->Attach_Object(pObj->GetRenderInterface(), m_pBusData->m_aSeatInfo[nIndex].m_pszLocator);
			if(g_theKernel.IsKindOf(pObj->GetClass(), GETCLASS(CObject_Character)))
			{
				CObject_Character *pCharMember = (CObject_Character*)(pObj);
				pCharMember->GetCharacterData()->Set_BusObjID(GetServerID());
				pCharMember->Bus_UpdateCharActionSetFile();
			}
			m_abPassengerAttacheds[nIndex] = TRUE;

			UpdateAnimation();
			SetPosition(GetPosition());
		}
	}
}
コード例 #6
0
// You usually wouldn't want to use this, since if the transaction failed, the opening number
// is already burned and gone. But there might be cases where it's not, and you want to retrieve it.
// So I added this function.
//
void OTAgreement::HarvestOpeningNumber(OTPseudonym & theNym)
{
    // since we overrode the parent, we give it a chance to harvest also.
    // IF theNym is the original sender, the opening number will be harvested
    // inside this call.
    //
    OTCronItem::HarvestOpeningNumber(theNym);

    // The Nym is the original recipient. (If Compares true).
    // IN CASES where GetTransactionNum() isn't already burned, we can harvest it here.
    //
    if (theNym.CompareID(GetRecipientUserID()))
    {
        // This function will only "add it back" if it was really there in the first place.
        // (Verifies it is on issued list first, before adding to available list.)
        //
        theNym.ClawbackTransactionNumber(GetServerID(), GetRecipientOpeningNum(), true); //bSave=true
    }
    
    // NOTE: if the message failed (transaction never actually ran) then the sender AND recipient
    // can both reclaim their opening numbers. But if the message SUCCEEDED and the transaction FAILED,
    // then only the recipient can claim his opening number -- the sender's is already burned. So then,
    // what if you mistakenly call this function and pass the sender, when that number is already burned?
    // There's nothing this function can do, because we have no way of telling, from inside here,
    // whether the message succeeded or not, and whether the transaction succeeded or not. Therefore,
    // ==> we MUST rely on the CALLER to know this, and to avoid calling this function in the first place, 
    // if he's sitting on a sender with a failed transaction.
}
コード例 #7
0
bool ConnectionManagerToServer::start() {

    const char * str_config_value = TBSYS_CONFIG.getString(
        "server","config_server_spec",NULL);
    if (NULL == str_config_value) {
        TBSYS_LOG(ERROR,"%s",
            "config error,config_server url error");
        return false;
    }
    memset(config_server_spec_,0,
        sizeof(config_server_spec_));
    strcat(config_server_spec_,str_config_value);

    self_server_type_=TBSYS_CONFIG.getInt(
        "server","self_server_type",
        SERVER_TYPE_ACCESS_SERVER);
    str_config_value=TBSYS_CONFIG.getString(
        "server","self_server_spec","");
    if (0==strlen(str_config_value)) {
        TBSYS_LOG(ERROR,"%s",
            "config error,self_server_spec error");
        return false;
    }
    memset(self_server_spec_,0,
        sizeof(self_server_spec_));
    strcat(self_server_spec_,str_config_value);

    self_server_id_=GetServerID(self_server_spec_);
    if (0==self_server_id_) {
        TBSYS_LOG(ERROR,"%s",
            "config error,self_server_spec error"
            ",self_server_id error");
        return false;
    }

    depend_server_type_=TBSYS_CONFIG.getIntList(
        "server","depend_server_type");

    conn_to_config_server_=transport_->connect(
        config_server_spec_,packet_streamer_,true);
    if (NULL==conn_to_config_server_) {
        TBSYS_LOG(ERROR,"%s",
            "connect to config_server error");
        return false;
    }
    conn_to_config_server_->setDefaultPacketHandler(this);

    packet_handler_to_server_=new 
        PacketHandlerToServer(this, business_packet_handler_);
    if (NULL==packet_handler_to_server_) {
        TBSYS_LOG(ERROR,"%s",
            "packet_handler_to_server_ init error");
        return false;
    }

    packet_handler_to_server_->start();
    timer_thread_.start(this,NULL);
    return true;
}
コード例 #8
0
ファイル: ConnectClient.cpp プロジェクト: ELMERzark/PSS
int CConnectClient::handle_close(ACE_HANDLE h, ACE_Reactor_Mask mask)
{
    if (h == ACE_INVALID_HANDLE)
    {
        OUR_DEBUG((LM_DEBUG, "[CConnectClient::handle_close] h is NULL mask=%d.\n", GetServerID(), (int)mask));
    }

    Close();
    return 0;
}
コード例 #9
0
ファイル: Obj_PlayerOther.cpp プロジェクト: brock7/TianLong
// 右键指令的分析
BOOL CObject_PlayerOther::FillMouseCommand_Right( SCommand_Mouse *pOutCmd, tActionItem* pActiveSkill )
{
	pOutCmd->m_typeMouse = SCommand_Mouse::MCT_NULL;
	ENUM_RELATION eCampType = CGameProcedure::s_pGameInterface->GetCampType( CObjectManager::GetMe()->GetMySelf(), this );
	switch ( eCampType )
	{
	case RELATION_FRIEND:
		{
			pOutCmd->m_typeMouse	= SCommand_Mouse::MCT_CONTEXMENU;
			pOutCmd->m_adwParam[0]	= GetServerID();
		}
		break;
	case RELATION_ENEMY:
	default:
		{
			pOutCmd->m_typeMouse	= SCommand_Mouse::MCT_PLAYER_SELECT;
			pOutCmd->m_adwParam[0]	= GetServerID();
		}
		break;
	}
	return TRUE;
}
コード例 #10
0
ファイル: ServiceBase.cpp プロジェクト: sguphil/GameProject
BOOL ServiceBase::StartService()
{
    CLog::GetInstancePtr()->AddLog("*******服务器信息***********");
    CLog::GetInstancePtr()->AddLog("服务器地址:%s 监听端口:%d", CGlobalConfig::GetInstancePtr()->m_strIpAddr.c_str(), CGlobalConfig::GetInstancePtr()->m_sPort);
    CLog::GetInstancePtr()->AddLog("服务器类型:%d 服务器ID:%d", GetServerType(), GetServerID());
    CLog::GetInstancePtr()->AddLog("********服务器信息***********");
    CLog::GetInstancePtr()->AddLog("");
    CLog::GetInstancePtr()->AddLog("");

    if(!CNetManager::GetInstancePtr()->Start(this))
    {
        CLog::GetInstancePtr()->AddLog("启动网络层失败");
        return FALSE;
    }

    CLog::GetInstancePtr()->AddLog("服务器启动成功!");

    return TRUE;
}
コード例 #11
0
// Used for adding transaction numbers back to a Nym, after deciding not to use this agreement
// or failing in trying to use it. Client side.
//
void OTAgreement::HarvestClosingNumbers(OTPseudonym & theNym)
{
    // Since we overrode the parent, we give it a chance to harvest also.
    // If theNym is the sender, then his closing numbers will be harvested
    // inside here. But what if the transaction was a success? The numbers
    // will still be harvested, since they are still on the sender's issued
    // list, but they should not have been harvested, regardless, since the
    // transaction was a success and the server therefore has them marked as
    // "used." So clearly you cannot just blindly call this function unless
    // you know beforehand whether the message and transaction were a success.
    //
    OTCronItem::HarvestClosingNumbers(theNym);

    // The Nym is the original recipient. (If Compares true).
	// FYI, if Nym is the original sender, then the above call will handle him.
	//
    // GetTransactionNum() is burned, but we can harvest the closing
    // numbers from the "Closing" list, which is only for the sender's numbers.
    // Subclasses will have to override this function for recipients, etc.
    //
    if (theNym.CompareID(GetRecipientUserID()))
    {
        for (int i = 0; i < GetRecipientCountClosingNumbers(); i++)
        {
            // This function will only "add it back" if it was really there in the first place.
            // (Verifies it is on issued list first, before adding to available list.)
            //
            const bool bClawedBack = 
                theNym.ClawbackTransactionNumber(GetServerID(), 
                                                 GetRecipientClosingTransactionNoAt(i), 
                                                 (i == (GetRecipientCountClosingNumbers()-1) ? true : false)); // bSave=true only on the last iteration.
			if (!bClawedBack)
            {
//				OTLog::vError("OTAgreement::HarvestClosingNumbers: Number (%ld) failed as issued. (Thus didn't bother 'adding it back'.)\n",
//							  GetRecipientClosingTransactionNoAt(i));
            }
        }
    }
}
コード例 #12
0
bool OTAgreement::Compare(const OTAgreement & rhs) const
{
    // Compare OTAgreement specific info here.
    
    if ( 
        (   m_strConsideration.Compare(rhs.m_strConsideration) ) &&
        (   GetRecipientAcctID() == rhs.GetRecipientAcctID()   ) &&
        (   GetRecipientUserID() == rhs.GetRecipientUserID()   ) &&
//        (   m_dequeClosingNumbers == rhs.m_dequeClosingNumbers ) && // The merchant wouldn't know the customer's trans#s.
                                                                        // (Thus wouldn't expect them to be set in BOTH versions...)
        (   m_dequeRecipientClosingNumbers == rhs.m_dequeRecipientClosingNumbers   ) &&
//      (   GetTransactionNum()  == rhs.GetTransactionNum()   ) && // (commented out for same reason as above.)
//      (   GetSenderAcctID()    == rhs.GetSenderAcctID()     ) && // Same here -- we should let the merchant leave these blank,
//      (   GetSenderUserID()    == rhs.GetSenderUserID()     ) && // and then allow the customer to add them in his version, 
        (   GetAssetID()         == rhs.GetAssetID()          ) && // (and this Compare function still still verify it.)
        (   GetServerID()        == rhs.GetServerID()         ) &&
        (   GetValidFrom()       == rhs.GetValidFrom()        ) &&
        (   GetValidTo()         == rhs.GetValidTo()          )
       )
        return true;
    
    return false;
}
コード例 #13
0
ファイル: ConnectClient.cpp プロジェクト: ELMERzark/PSS
bool CConnectClient::SendData(ACE_Message_Block* pmblk)
{
    //如果是DEBUG状态,记录当前接受包的二进制数据
    if (App_MainConfig::instance()->GetDebug() == DEBUG_ON)
    {
        char szDebugData[MAX_BUFF_1024] = {'\0'};
        char szLog[10]  = {'\0'};
        int  nDebugSize = 0;
        bool blblMore   = false;

        if (pmblk->length() >= MAX_BUFF_200)
        {
            nDebugSize = MAX_BUFF_200;
            blblMore   = true;
        }
        else
        {
            nDebugSize = (int)pmblk->length();
        }

        char* pData = pmblk->rd_ptr();

        for (int i = 0; i < nDebugSize; i++)
        {
            sprintf_safe(szLog, 10, "0x%02X ", (unsigned char)pData[i]);
            sprintf_safe(szDebugData + 5 * i, MAX_BUFF_1024 - 5 * i, "%s", szLog);
        }

        if (blblMore == true)
        {
            AppLogManager::instance()->WriteLog(LOG_SYSTEM_DEBUG_CLIENTRECV, "[%s:%d]%s.(数据包过长只记录前200字节)", m_addrRemote.get_host_addr(), m_addrRemote.get_port_number(), szDebugData);
        }
        else
        {
            AppLogManager::instance()->WriteLog(LOG_SYSTEM_DEBUG_CLIENTRECV, "[%s:%d]%s.", m_addrRemote.get_host_addr(), m_addrRemote.get_port_number(), szDebugData);
        }
    }

    ACE_Time_Value     nowait(MAX_MSG_PACKETTIMEOUT);

    if (NULL == pmblk)
    {
        OUR_DEBUG((LM_ERROR, "[CConnectClient::SendData] ConnectID = %d, get_handle() == ACE_INVALID_HANDLE.\n", GetServerID()));
        return false;
    }

    if (get_handle() == ACE_INVALID_HANDLE)
    {
        OUR_DEBUG((LM_ERROR, "[CConnectClient::SendData] ConnectID = %d, get_handle() == ACE_INVALID_HANDLE.\n", GetServerID()));
        sprintf_safe(m_szError, MAX_BUFF_500, "[CConnectClient::SendData] ConnectID = %d, get_handle() == ACE_INVALID_HANDLE.\n", GetServerID());
        pmblk->release();
        return false;
    }

    char* pData = pmblk->rd_ptr();

    if (NULL == pData)
    {
        OUR_DEBUG((LM_ERROR, "[CConnectClient::SendData] ConnectID = %d, pData is NULL.\n", GetServerID()));
        pmblk->release();
        return false;
    }

    int nSendLen = (int)pmblk->length();   //发送数据的总长度
    int nIsSendSize = 0;

    //循环发送,直到数据发送完成。
    while (true)
    {
        if (nSendLen <= 0)
        {
            OUR_DEBUG((LM_ERROR, "[CConnectClient::SendData] ConnectID = %d, nCurrSendSize error is %d.\n", GetServerID(), nSendLen));
            pmblk->release();
            return false;
        }

        int nDataLen = this->peer().send(pmblk->rd_ptr(), nSendLen - nIsSendSize, &nowait);
        int nErr = ACE_OS::last_error();

        if (nDataLen <= 0)
        {
            if (nErr == EWOULDBLOCK)
            {
                //如果发送堵塞,则等10毫秒后再发送。
                ACE_Time_Value tvSleep(0, 10 * MAX_BUFF_1000);
                ACE_OS::sleep(tvSleep);
                continue;
            }

			_ClientIPInfo objServerIPInfo;
			sprintf_safe(objServerIPInfo.m_szClientIP, MAX_BUFF_20, "%s", m_addrRemote.get_host_addr());
			objServerIPInfo.m_nPort = m_addrRemote.get_port_number();
			m_pClientMessage->ConnectError((int)ACE_OS::last_error(), objServerIPInfo);

            OUR_DEBUG((LM_ERROR, "[CConnectClient::SendData] ConnectID = %d, error = %d.\n", GetServerID(), errno));
            pmblk->release();
            return false;
        }
        else if (nDataLen + nIsSendSize >= nSendLen)  //当数据包全部发送完毕,清空。
        {
            //OUR_DEBUG((LM_ERROR, "[CConnectHandler::handle_output] ConnectID = %d, send (%d) OK.\n", GetConnectID(), msg_queue()->is_empty()));
            pmblk->release();
            m_u4SendSize += (uint32)nSendLen;
            m_u4SendCount++;
            return true;
        }
        else
        {
            pmblk->rd_ptr(nDataLen);
            nIsSendSize      += nDataLen;
            continue;
        }
    }

    return true;
}
コード例 #14
0
// THIS FUNCTION IS CALLED BY THE CUSTOMER
//
// (Transaction number and closing number are retrieved from Nym at this time.)
bool OTAgreement::Confirm(OTPseudonym & MERCHANT_NYM, OTPseudonym & PAYER_NYM)
{
    // ----------------------------------------------------------------------------
    OTIdentifier id_MERCHANT_NYM, id_PAYER_NYM;
    MERCHANT_NYM.GetIdentifier(id_MERCHANT_NYM);
    PAYER_NYM.GetIdentifier(id_PAYER_NYM);
    
    if (GetRecipientUserID() == GetSenderUserID())
    {
        OTLog::Output(0, "OTAgreement::Confirm: Error: Sender and recipient have the same Nym ID (not allowed.)\n");
        return false;        
    }
    else if (GetRecipientUserID() != id_MERCHANT_NYM)
    {
        OTLog::Output(0, "OTAgreement::Confirm: Merchant has wrong NymID (should be same as RecipientUserID.)\n");
        return false;        
    }
    else if (GetSenderUserID() != id_PAYER_NYM)
    {
        OTLog::Output(0, "OTAgreement::Confirm: Payer has wrong NymID (should be same as SenderUserID.)\n");
        return false;        
    }
    else if (PAYER_NYM.GetTransactionNumCount(GetServerID()) < 2) // Need opening and closing numbers (that's 2)... 
    {
        OTLog::Output(0, "OTAgreement::Confirm: Failure. You need at least 2 transaction numbers available to do this.\n");
		return false;
    }
    else if (GetRecipientCountClosingNumbers() < 2)
    {
        OTLog::Output(0, "OTAgreement::Confirm: Failure. (The merchant was supposed to attach 2 transaction numbers.)\n");
		return false;
    }
    // ----------------------------------------------------------------------------
    // This is the single reason why MERCHANT_NYM was even passed in here!
    // Supposedly merchant has already signed.  Let's verify this!!
    //
    if (false == this->VerifySignature(MERCHANT_NYM))
    {
        OTLog::Output(0, "OTAgreement::Confirm: Merchant's signature failed to verify.\n");
        return false;
    }
    // ----------------------------------------------------------------------------
    
    // Now that we KNOW the merchant signed it... SAVE MERCHANT's COPY.
    // Let's save a copy of the one the merchant signed, before changing it and re-signing it,
    // (to add my own transaction numbers...)
    //
    OTString strTemp;
    this->SaveContractRaw(strTemp);
    this->SetMerchantSignedCopy(strTemp);

    // *******************************************************************
    
    // The payer has to submit TWO transaction numbers in order to activate this agreement...
    //
    OTString strServerID(GetServerID());
	long lTransactionNumber=0, lClosingTransactionNo=0;
	
	if (false == PAYER_NYM.GetNextTransactionNum(PAYER_NYM, strServerID, lTransactionNumber))
	{
		OTLog::Error("OTAgreement::Confirm: Error: Strangely unable to get a transaction number.\n");
		return false;
	}
	else if (false == PAYER_NYM.GetNextTransactionNum(PAYER_NYM, strServerID, lClosingTransactionNo))
	{
 		OTLog::Error("OTAgreement::Confirm: Error: Strangely unable to get a closing transaction number.\n");
        PAYER_NYM.AddTransactionNum(PAYER_NYM, strServerID, lTransactionNumber, true); // bSave=true
        // (Since the first one was successful, we just put it back before returning.)
		return false;
	}
    
    // At this point we now HAVE 2 transaction numbers (for payer / sender)...
    // We can't return without USING THEM or PUTTING THEM BACK.
    //
    // ---------------------------------------------------------
 
     
	this->SetTransactionNum(lTransactionNumber); // Set the Transaction Number
    this->AddClosingTransactionNo(lClosingTransactionNo); // and the Closing Number (both for sender)...

	// ------------------------------------------- 
	
    // CREATION DATE was set in the Merchant's proposal, and it's RESET here in the Confirm.
    // This way, (since we still have the original proposal) we can see BOTH times.
    //
	time_t CURRENT_TIME = time(NULL);
	// Set the Creation Date.
	SetCreationDate(CURRENT_TIME);
    
	// ------------------------------------------- 
    
	OTLog::Output(4, "OTAgreement::Confirm(): Success!\n");
    
	return true;
}
コード例 #15
0
// THIS FUNCTION IS CALLED BY THE MERCHANT
//
// (lMerchantTransactionNumber, lMerchantClosingNumber are set internally in this call, from MERCHANT_NYM.)
bool OTAgreement::SetProposal(OTPseudonym & MERCHANT_NYM,       const OTString & strConsideration,
                              const time_t VALID_FROM/*=0*/,  const time_t VALID_TO/*=0*/)
{
    // ----------------------------------------------------------------------------
    OTIdentifier id_MERCHANT_NYM;
    MERCHANT_NYM.GetIdentifier(id_MERCHANT_NYM);
    
    if (GetRecipientUserID() != id_MERCHANT_NYM)
    {
        OTLog::Output(0, "OTAgreement::SetProposal: Merchant has wrong NymID (should be same as RecipientUserID.)\n");
        return false;        
    }
    else if (GetRecipientUserID() == GetSenderUserID())
    {
        OTLog::Output(0, "OTAgreement::SetProposal: Error: Sender and recipient have the same Nym ID (not allowed.)\n");
        return false;        
    }
    else if (MERCHANT_NYM.GetTransactionNumCount(GetServerID()) < 2) // Need opening and closing numbers (that's 2)... 
    {
        OTLog::Output(0, "OTAgreement::SetProposal: Failure. You need at least 2 transaction numbers available to do this.\n");
		return false;
    }

    // ------------------------------------------- 
	// Set the CREATION DATE
    //
	const time_t CURRENT_TIME = time(NULL);
	
	// Set the Creation Date.
	SetCreationDate(CURRENT_TIME);

    // -----------------------------------------
    // Putting this above here so I don't have to put the transaction numbers back if this fails:
    // ------------------------------------------- 
    // VALID_FROM
    //
	// The default "valid from" time is NOW.
	if (0 >= VALID_FROM) // if it's 0 or less, set to current time.
		SetValidFrom(CURRENT_TIME);
	else // Otherwise use whatever was passed in.
		SetValidFrom(VALID_FROM);
    // ------------------------------------------- 
    // VALID_TO
    //
	// The default "valid to" time is 0 (which means no expiration date / cancel anytime.)
	if (0 == VALID_TO) // VALID_TO is 0
	{
		SetValidTo(VALID_TO); // Keep it at zero then, so it won't expire.
	}
	else if (0 < VALID_TO) // VALID_TO is ABOVE zero...
	{
		if (VALID_TO < VALID_FROM) // If Valid-To date is EARLIER than Valid-From date...
		{
			long lValidTo = VALID_TO, lValidFrom = VALID_FROM;
			OTLog::vError("OTAgreement::SetProposal: VALID_TO (%ld) is earlier than VALID_FROM (%ld)\n", 
                          lValidTo, lValidFrom);
			return false;
		}
		
		SetValidTo(VALID_TO); // Set it to whatever it is, since it is now validated as higher than Valid-From.
	}
	else // VALID_TO is a NEGATIVE number... Error.
	{
		long lValidTo = VALID_TO;
		OTLog::vError("Negative value for valid_to in SetAgreement: %ld\n", lValidTo);
        
		return false;
	}

    // ----------------------------------------------------------------------------
    // Since we'll be needing 2 transaction numbers to do this, let's grab 'em...
    //
    OTString strServerID(GetServerID());
    
	long lTransactionNumber=0, lClosingTransactionNo=0;
	
    if (MERCHANT_NYM.GetTransactionNumCount(GetServerID()) < 2) // Need opening and closing numbers (that's 2)... 
    {
        OTLog::Output(0, "OTAgreement::SetProposal: Failure. You need at least 2 transaction numbers available to do this.\n");
		return false;
    }
	else if (false == MERCHANT_NYM.GetNextTransactionNum(MERCHANT_NYM, strServerID, lTransactionNumber))
	{
		OTLog::Error("OTAgreement::SetProposal: Error: Strangely unable to get a transaction number.\n");
		return false;
	}
	else if (false == MERCHANT_NYM.GetNextTransactionNum(MERCHANT_NYM, strServerID, lClosingTransactionNo))
	{
 		OTLog::Error("OTAgreement::SetProposal: Error: Strangely unable to get a closing transaction number.\n");
        MERCHANT_NYM.AddTransactionNum(MERCHANT_NYM, strServerID, lTransactionNumber, true); // bSave=true
        // (Since the first one was successful, we just put it back before returning.)
		return false;
	}

    // At this point we now have 2 transaction numbers...
    // We can't return without either USING THEM, or PUTTING THEM BACK.
    //
    // ---------------------------------------------------------
    
	// Set the Transaction Number and the Closing transaction number... (for merchant / recipient.)
    //
    this->AddRecipientClosingTransactionNo(lTransactionNumber);
    this->AddRecipientClosingTransactionNo(lClosingTransactionNo);
    // (They just both go onto this same list.)
    
	// ------------------------------------------- 

	// Set the Consideration memo...
	m_strConsideration.Set(strConsideration);
            
	// ------------------------------------------- 
    
	OTLog::Output(4, "Successfully performed OTPaymentPlan::SetProposal()\n");
	
	return true;
}
コード例 #16
0
bool ManagerServer::start() {

    const char * str_config_value;

    self_server_type_=TBSYS_CONFIG.getInt(
        "server","self_server_type",
        SERVER_TYPE_ACCESS_SERVER);

    str_config_value=TBSYS_CONFIG.getString(
        "server","self_server_spec","");
    if (0==strlen(str_config_value)) {
        TBSYS_LOG(ERROR,"%s",
            "config error,self_server_spec error");
        return false;
    }
    memset(self_server_spec_,0,
        sizeof(self_server_spec_));
    strcat(self_server_spec_,str_config_value);

    self_server_id_=GetServerID(self_server_spec_);
    if (0==self_server_id_) {
        TBSYS_LOG(ERROR,"%s",
            "config error,self_server_spec error"
            ",self_server_id error");
        return false;
    }
/*
    int thread_count = TBSYS_CONFIG.getInt(
        "server","work_thread_count_for_server",4);
    task_queue_thread_.setThreadParameter(thread_count,this,NULL);
    
    task_queue_thread_.start();
*/   
    //timer_thread_.start(this,NULL);
    packet_streamer_.setPacketFactory(&packet_factory_);
    transport_for_server_.start();

/*
    //依赖后端业务服务
    std::vector<int> server_types=
        TBSYS_CONFIG.getIntList("depend_server", "server_type");
    if (server_types.size() <= 0) {
        TBSYS_LOG(ERROR,"server_type_num == 0");
        return false;
    }

    for (int i=0;i<server_types.size();i++) {
        LoadConnection* lc=new LoadConnection(server_types[i], 
            &transport_for_server_, &packet_streamer_, this);
        if (!lc->Connect()) {
            lc->DisConnect();
            delete lc;
            lc=NULL;
            TBSYS_LOG(ERROR,"exit start");
            return false;
        }
        conn_map_[server_types[i]]=lc;
    }
*/
    return true;
}
コード例 #17
0
ファイル: ConnectClient.cpp プロジェクト: ELMERzark/PSS
int CConnectClient::RecvData_et()
{
    int nCurrCount = (uint32)m_pCurrMessage->size();

    if (nCurrCount < 0)
    {
        //如果剩余字节为负,说明程序出了问题
        OUR_DEBUG((LM_ERROR, "[CConnectClient::handle_input][%d] nCurrCount < 0 m_u4CurrSize = %d.\n", GetServerID(), m_u4CurrSize));
        m_u4CurrSize = 0;

        if (NULL != m_pClientMessage)
        {
			_ClientIPInfo objServerIPInfo;
			sprintf_safe(objServerIPInfo.m_szClientIP, MAX_BUFF_20, "%s", m_addrRemote.get_host_addr());
			objServerIPInfo.m_nPort = m_addrRemote.get_port_number();

			if(S2S_NEED_CALLBACK == m_ems2s)
			{
				m_pClientMessage->ConnectError((int)ACE_OS::last_error(), objServerIPInfo);
			}
        }

        return -1;
    }

		while(true)
		{
	    int nDataLen = this->peer().recv(m_pCurrMessage->wr_ptr(), nCurrCount, MSG_NOSIGNAL);
	
	    if (nDataLen <= 0)
	    {
	        m_u4CurrSize = 0;
	        uint32 u4Error = (uint32)errno;
	        
			if(nDataLen == -1 && u4Error == EAGAIN)
			{
					break;
			}	        
	        
	        OUR_DEBUG((LM_ERROR, "[CConnectClient::handle_input] ConnectID = %d, recv data is error nDataLen = [%d] errno = [%d].\n", GetServerID(), nDataLen, u4Error));
	        sprintf_safe(m_szError, MAX_BUFF_500, "[CConnectClient::handle_input] ConnectID = %d, recv data is error[%d].\n", GetServerID(), nDataLen);
	
	        if (NULL != m_pClientMessage)
	        {
				_ClientIPInfo objServerIPInfo;
				sprintf_safe(objServerIPInfo.m_szClientIP, MAX_BUFF_20, "%s", m_addrRemote.get_host_addr());
				objServerIPInfo.m_nPort = m_addrRemote.get_port_number();

				if(S2S_NEED_CALLBACK == m_ems2s)
				{
					m_pClientMessage->ConnectError((int)ACE_OS::last_error(), objServerIPInfo);
				}
	        }
	
	        return -1;
	    }
	
	    //如果是DEBUG状态,记录当前接受包的二进制数据
	    if (App_MainConfig::instance()->GetDebug() == DEBUG_ON)
	    {
	        char szDebugData[MAX_BUFF_1024] = {'\0'};
	        char szLog[10]  = {'\0'};
	        int  nDebugSize = 0;
	        bool blblMore   = false;
	
	        if (nDataLen >= MAX_BUFF_200)
	        {
	            nDebugSize = MAX_BUFF_200;
	            blblMore   = true;
	        }
	        else
	        {
	            nDebugSize = nDataLen;
	        }
	
	        char* pData = m_pCurrMessage->wr_ptr();
	
	        for (int i = 0; i < nDebugSize; i++)
	        {
	            sprintf_safe(szLog, 10, "0x%02X ", (unsigned char)pData[i]);
	            sprintf_safe(szDebugData + 5 * i, MAX_BUFF_1024 - 5 * i, "%s", szLog);
	        }
	
	        if (blblMore == true)
	        {
	            AppLogManager::instance()->WriteLog(LOG_SYSTEM_DEBUG_SERVERRECV, "[%s:%d]%s.(数据包过长只记录前200字节)", m_addrRemote.get_host_addr(), m_addrRemote.get_port_number(), szDebugData);
	        }
	        else
	        {
	            AppLogManager::instance()->WriteLog(LOG_SYSTEM_DEBUG_SERVERRECV, "[%s:%d]%s.", m_addrRemote.get_host_addr(), m_addrRemote.get_port_number(), szDebugData);
	        }
	    }
	
	    m_pCurrMessage->wr_ptr(nDataLen);
	
	    if (NULL != m_pClientMessage)
	    {
	        //接收数据,返回给逻辑层,自己不处理整包完整性判定
			_ClientIPInfo objServerIPInfo;
			sprintf_safe(objServerIPInfo.m_szClientIP, MAX_BUFF_20, "%s", m_addrRemote.get_host_addr());
			objServerIPInfo.m_nPort = m_addrRemote.get_port_number();
	        m_pClientMessage->RecvData(m_pCurrMessage, objServerIPInfo);
	    }
	
	    m_pCurrMessage->reset();
  	}
    
    return 0;		
}