Пример #1
0
void GameInterchange::operProCancelChange(TCPConnection::Pointer conn,interchangeOperPro*  oper)
{

    Server* srv = Server::GetInstance();
    SessionMgr::SessionPointer sp = SessionMgr::Instance()->GetSession();
    boost::shared_ptr<Interchange> interchange = (*sp)[conn].m_interchage;
    TCPConnection::Pointer partnerConn = interchange->partnerConn;

    SessionMgr::SessionMap::iterator iter = sp->find(partnerConn);

    if(iter == sp->end())    //对方离线
    {
        interchange->clear();           //清除交易状态
        srv->free(oper);
        return;
    }

    //对方在线
    boost::shared_ptr<Interchange> pInterchange = (*sp)[partnerConn].m_interchage;
    partnerConn->Write_all((char*)oper, sizeof(interchangeOperPro));   //转发取消交易的包

    for(std::vector<STR_Goods>::iterator iter = interchange->changes.begin(); iter != interchange->changes.end(); ++iter)    //背包位置信息恢复原来标志
    {
        (*sp)[conn].m_goodsPosition[iter->Position] = POS_NONEMPTY;
    }
    for(std::vector<STR_Goods>::iterator iter = pInterchange->changes.begin(); iter != pInterchange->changes.end(); ++iter)
    {
        (*sp)[partnerConn].m_goodsPosition[iter->Position] = POS_NONEMPTY;
    }
    interchange->clear();           //清除交易状态
    pInterchange->clear();             //对方清除交易状态
    srv->free(oper);
}
Пример #2
0
void GameInterchange::operProLock(TCPConnection::Pointer conn,  interchangeOperPro*  oper)
{
    Server* srv = Server::GetInstance();
    SessionMgr::SessionPointer sp = SessionMgr::Instance()->GetSession();
    boost::shared_ptr<Interchange> interchange = (*sp)[conn].m_interchage;
    TCPConnection::Pointer partnerConn = interchange->partnerConn;

    interchange->lock();                  //进入锁定状态

    SessionMgr::SessionMap::iterator iter = sp->find(partnerConn);
    if(iter == sp->end())                        //对方离线 则由服务器发取消交易的包返回
    {
        interchangeOperPro resp;
        resp.operType = Operation_CancelChange;
        conn->Write_all((char*)&resp, sizeof(interchangeOperPro));
        for(std::vector<STR_Goods>::iterator iterIn = interchange->changes.begin(); iterIn != interchange->changes.end();++iterIn)
        {
              (*sp)[conn].m_goodsPosition[iterIn->Position] = POS_NONEMPTY;       //恢复物品原来标志
        }
        interchange->clear();           //清除交易状态  对方离线所以不用处理其状态信息

        srv->free(oper);
        return;
    }

    partnerConn->Write_all((char*)oper, sizeof(interchangeOperPro));
    srv->free(oper);
}
Пример #3
0
void StoreServer::handle_read(TcpConnection::Pointer conn, std::size_t bytes_transfered) {
    ConnData& data = conns_[conn];
    std::string& buf = data.buf;
    //没有获得完整命令,就返回
    buf.append(std::string(conn->buf().data(), bytes_transfered));
    if (buf.length() < 3) {
        return;
    }
    std::size_t len = static_cast<std::size_t>(total_len(buf));
    if (buf.length() < len) {
        return;
    }
    std::string cmd = buf.substr(0, len);
    buf.erase(0, len);
    std::string retmsg("");
    //将命令分发到对应的处理函数中,返回结果
    int err = dispath_cmd(cmd, conn, retmsg);
    //发送response
    std::string response("");
    if (err < 0) {
        response = get_response(retmsg, RESP_TYPE_ERR);
    } else {
        response = get_response(retmsg, RESP_TYPE_OK);
        persistence_.record(cmd,  data.db);
    }
    conn->send(response);
    //尾递归,处理没有处理完的命令
    handle_read(conn, 0);
}
Пример #4
0
//查找此任务是否为任务进度里收集物品,如果是,更新任务进度
void GameTask::UpdateCollectGoodsTaskProcess(TCPConnection::Pointer conn, STR_PickGoods* t_pickGoods, hf_uint32 goodsCount)
{
    SessionMgr::SessionMap* smap = SessionMgr::Instance()->GetSession().get();
    umap_taskProcess umap_playerAcceptTask = ((*smap)[conn]).m_playerAcceptTask;
    for(_umap_taskProcess::iterator t_task = umap_playerAcceptTask->begin(); t_task != umap_playerAcceptTask->end(); t_task++)
    {
        if(t_task->second.AimID == t_pickGoods->LootGoodsID && t_task->second.ExeModeID == EXE_collect_items && t_task->second.AimCount < t_task->second.AimAmount)
        {
            if(t_task->second.AimCount == t_task->second.AimAmount)
            {
                return;
            }
            else if(t_task->second.AimCount + goodsCount > t_task->second.AimAmount)
            {
                t_task->second.AimCount = t_task->second.AimAmount;
            }
            else
            {
                t_task->second.AimCount = t_task->second.AimCount + goodsCount;
            }


            (*umap_playerAcceptTask)[t_task->second.TaskID] = t_task->second;

            STR_PackHead t_packHead;
            t_packHead.Len = sizeof(STR_TaskProcess);
            t_packHead.Flag = FLAG_TaskProcess;

            conn->Write_all(&(t_packHead), sizeof(STR_PackHead));
            conn->Write_all(&(t_task->second), sizeof(STR_TaskProcess));
        }
    }
}
Пример #5
0
void GameInterchange::operProCancelRequest(TCPConnection::Pointer conn,interchangeOperPro*  oper)
{

    Server* srv = Server::GetInstance();
    SessionMgr::SessionPointer sp = SessionMgr::Instance()->GetSession();
    boost::shared_ptr<Interchange> interchange = (*sp)[conn].m_interchage;
    TCPConnection::Pointer partnerConn = interchange->partnerConn;

    SessionMgr::SessionMap::iterator iter = sp->find(partnerConn);

    if(iter == sp->end())    //对方离线
    {
        interchange->clear();           //清除交易状态
        srv->free(oper);
        return;
    }

    //对方在线
    boost::shared_ptr<Interchange> pInterchange = (*sp)[partnerConn].m_interchage;
    partnerConn->Write_all((char*)oper, sizeof(interchangeOperPro));   //转发取消交易的包

    interchange->clear();           //清除交易状态
    pInterchange->clear();             //对方清除交易状态
    srv->free(oper);
}
Пример #6
0
//请求任务
void GameTask::AskTask(TCPConnection::Pointer conn, hf_uint32 taskid)
{
    //判断任务条件,暂时只判断等级
    SessionMgr::SessionMap* smap = SessionMgr::Instance()->GetSession().get();
    STR_RoleBasicInfo* t_RoleBaseInfo = &(*smap)[conn].m_RoleBaseInfo;

    umap_taskProcess umap_playerAcceptTask = (*smap)[conn].m_playerAcceptTask;

    _umap_taskProcess::iterator it = umap_playerAcceptTask->find(taskid);
    if(it != umap_playerAcceptTask->end()) //已经接取当前任务
    {
        return;
    }

    //得到该任务的任务要求
    umap_taskPremise::iterator task_it = m_taskPremise->find(taskid);
    if(task_it == m_taskPremise->end()) //发送的任务编号错误
    {
        return;
    }
    STR_PackAskResult t_askResult;
    t_askResult.TaskID = taskid;
    if(t_RoleBaseInfo->Level < task_it->second.Level)  //等级不符合
    {
        t_askResult.Result = RESULT_LEVEL;
        conn->Write_all(&t_askResult, sizeof(STR_PackAskResult));
        return;
    }

    t_askResult.Result = RESULT_SUCCESS;   //请求任务成功
    conn->Write_all(&t_askResult, sizeof(STR_PackAskResult));

    //将任务添加到该角色的任务列表里,退出时将未完成的任务写进数据库。
    STR_TaskProcess t_taskProcess;
    umap_taskAim::iterator iter= m_taskAim->find(taskid);
    if(iter != m_taskAim->end())
    {
     t_taskProcess.TaskID = taskid;
     t_taskProcess.AimID = iter->second.AimID;
     t_taskProcess.AimCount = 0;  //此处要查找背包
     t_taskProcess.AimAmount = iter->second.Amount;
     t_taskProcess.ExeModeID = iter->second.ExeModeID;
     (*umap_playerAcceptTask)[taskid] = t_taskProcess;

     Server::GetInstance()->GetOperationPostgres()->PushUpdateTask((*smap)[conn].m_roleid, &t_taskProcess, PostInsert); //将新任务添加到list
     STR_PackTaskProcess process;
     memcpy(&process.TaskProcess, &t_taskProcess, sizeof(STR_TaskProcess));
     conn->Write_all(&process, sizeof(STR_PackTaskProcess));
    }
}
Пример #7
0
//发送玩家可视范围内的任务
void GameTask::SendPlayerViewTask(TCPConnection::Pointer conn)
{
    //根据任务条件和玩家信息判断玩家可接取的任务
    SessionMgr::SessionMap* smap = SessionMgr::Instance()->GetSession().get();
    STR_RoleBasicInfo* t_RoleBaseInfo = &(*smap)[conn].m_RoleBaseInfo; //得到玩家信息
    umap_taskProcess umap_playerAcceptTask = ((*smap)[conn]).m_playerAcceptTask;

    hf_int32 size = 0;
    Server* srv = Server::GetInstance();
    hf_char* buff = (hf_char*)srv->malloc();
    STR_PackHead t_packHead;

    //发送玩家所在地图上的任务
    for(_umap_taskProfile::iterator it = m_taskProfile->begin(); it != m_taskProfile->end(); it++)
    {
        _umap_taskProcess::iterator iter = umap_playerAcceptTask->find(it->first);
        if(iter == umap_playerAcceptTask->end()) //是否已接取
        {
            STR_TaskPremise t_taskpremise = (*m_taskPremise)[it->first];
            if(t_RoleBaseInfo->Level >= t_taskpremise.Level)  //等级符合
            {
                it->second.Status = 1;
                memcpy(buff + sizeof(STR_PackHead) + size*sizeof(STR_TaskProfile), &(*m_taskProfile)[it->first], sizeof(STR_TaskProfile));
                size++;
            }
        }
        if(size == (CHUNK_SIZE - sizeof(STR_PackHead))/sizeof(STR_TaskProfile))
        {
            t_packHead.Flag = FLAG_TaskProfile;
            t_packHead.Len = sizeof(STR_TaskProfile) * size;

            memcpy(buff, (hf_char*)&t_packHead, sizeof(STR_PackHead));
            //发送可接取的任务
            conn->Write_all(buff, sizeof(STR_PackHead) + t_packHead.Len);
            size = 0;
        }
    }

    if(size != (CHUNK_SIZE - sizeof(STR_PackHead))/sizeof(STR_TaskProfile) && size != 0)
    {
        t_packHead.Flag = FLAG_TaskProfile;
        t_packHead.Len = sizeof(STR_TaskProfile) * size;

        memcpy(buff, (hf_char*)&t_packHead, sizeof(STR_PackHead));
        //发送可接取的任务
        conn->Write_all(buff, sizeof(STR_PackHead) + t_packHead.Len);
    }
    srv->free(buff);
}
Пример #8
0
 //请求任务奖励
void GameTask::TaskReward(TCPConnection::Pointer conn, hf_uint32 taskid)
{
    Server* srv = Server::GetInstance();
    hf_char* buff = (hf_char*)srv->malloc();
    STR_PackHead        t_packHead;
    t_packHead.Flag = FLAG_TaskReward;
    umap_taskReward::iterator it = (*m_taskReward).find(taskid);  //其他奖励
    if(it != (*m_taskReward).end())
    {
        memcpy(buff + sizeof(STR_PackHead), &(*m_taskReward)[taskid], sizeof(STR_PackTaskReward));
    }

    umap_goodsReward::iterator iter = (*m_goodsReward).find(taskid);  //奖励物品
    hf_uint8 i = 0;
    if(iter != (*m_goodsReward).end())
    {
        for(vector<STR_PackGoodsReward>::iterator itt = iter->second.begin(); itt != iter->second.end(); itt++)
        {
            memcpy(buff + sizeof(STR_PackHead) + sizeof(STR_PackTaskReward) + i*sizeof(STR_PackGoodsReward), &itt->GoodsID, sizeof(STR_PackGoodsReward));
            i++;
        }
    }
    t_packHead.Len = sizeof(STR_PackTaskReward) + i*sizeof(STR_PackGoodsReward);
    memcpy(buff, &t_packHead, sizeof(STR_PackHead));
    conn->Write_all(buff, sizeof(STR_PackHead) + t_packHead.Len);
    srv->free(buff);
}
Пример #9
0
 //发送已接取的任务进度,和任务概述
void GameTask::SendPlayerTaskProcess(TCPConnection::Pointer conn)
{
    Server* srv = Server::GetInstance();
     //根据任务条件和玩家信息判断玩家可接取的任务
    SessionMgr::SessionMap* smap = SessionMgr::Instance()->GetSession().get();
    umap_taskProcess umap_playerAcceptTask = ((*smap)[conn]).m_playerAcceptTask;
    //查询任务进度
    StringBuilder builder;
    builder << "select * from t_playertaskprocess where roleid = " << (*smap)[conn].m_roleid << ";";
    Logger::GetLogger()->Debug(builder.str());
    if ( srv->getDiskDB()->GetPlayerTaskProcess(umap_playerAcceptTask, (const hf_char*)builder.str()) < 0 )
    {
        Logger::GetLogger()->Error("Query playerAcceptTask error");
        return;
    }

    //发送已接取的任务进度
    if(umap_playerAcceptTask->size() > 0)
    {
        hf_char* buff = (hf_char*)srv->malloc();
        hf_char* probuff = (hf_char*)srv->malloc();
        hf_uint32 i = 0;
        for(_umap_taskProcess::iterator it = umap_playerAcceptTask->begin();it != umap_playerAcceptTask->end(); it++)
        {
            (*m_taskProfile)[it->first].Status = 2;
            memcpy(probuff + sizeof(STR_PackHead) + i*sizeof(STR_TaskProfile), &(*m_taskProfile)[it->first], sizeof(STR_TaskProfile));

            memcpy(buff + sizeof(STR_PackHead) + i*sizeof(STR_TaskProcess), &((*umap_playerAcceptTask)[it->first]), sizeof(STR_TaskProcess));
            i++;
        }

        STR_PackHead t_packHead;
        //发送玩家已经接取的任务的任务概述
        t_packHead.Flag = FLAG_TaskProfile;
        t_packHead.Len = sizeof(STR_TaskProfile) * i;
        memcpy(probuff, &t_packHead, sizeof(STR_PackHead));
        conn->Write_all(probuff, sizeof(STR_PackHead) + t_packHead.Len);

        t_packHead.Flag = FLAG_TaskProcess;
        t_packHead.Len = sizeof(STR_TaskProcess) * i;
        memcpy(buff, &t_packHead, sizeof(STR_PackHead));
        conn->Write_all(buff, sizeof(STR_PackHead) + t_packHead.Len);

        srv->free(buff);
        srv->free(probuff);
    } 
}
Пример #10
0
void GameInterchange::operRequest(TCPConnection::Pointer conn, operationRequest*  operReq)
{
    Server* srv = Server::GetInstance();
    SessionMgr::SessionPointer sp = SessionMgr::Instance()->GetSession();

    if((*sp)[conn].m_interchage->isInchange)         //已经在交易状态,不能再发请求交易的数据包
    {
        srv->free(operReq);
        return;
    }

    umap_roleSock rsock =  SessionMgr::Instance()->GetRoleSock();
    _umap_roleSock::iterator iter = rsock->find(operReq->RoleID);
    if(iter == rsock->end())           //对方不在线 由服务器发拒绝的包返回
    {
        operationRequestResult resp;
        resp.operType = operReq->operType;
        resp.operResult = Result_Reject;
        conn->Write_all((char*)&resp, sizeof(operationRequestResult));
        srv->free(operReq);
        return;
    }

    TCPConnection::Pointer partnerConn = (*rsock)[operReq->RoleID];
    if((*sp)[partnerConn].m_interchage->inChange())             //对方正在交易中 由服务器发拒绝的包返回
    {
        operationRequestResult resp;
        resp.operType = operReq->operType;
        resp.operResult = Result_Reject;
        conn->Write_all((char*)&resp, sizeof(operationRequestResult));
        srv->free(operReq);
        return;
    }

    (*sp)[conn].m_interchage->goInChange();          //进入交易状态
    (*sp)[partnerConn].m_interchage->goInChange();          //服务器设定对方也进入交易状态 ,避免竞争
    (*sp)[conn].m_interchage->roleId = (*sp)[conn].m_roleid;  //保存自己的角色id
    (*sp)[partnerConn].m_interchage->roleId = (*sp)[partnerConn].m_roleid;  //对方保存自己的角色id
    (*sp)[conn].m_interchage->partnerConn = partnerConn; //互相保存对方的连接
    (*sp)[partnerConn].m_interchage->partnerConn = conn;  //互相保存对方的连接

    operReq->RoleID =  (*sp)[conn].m_roleid;                        // 向对方转发请求
    partnerConn->Write_all((char*)operReq, sizeof(operationRequest));
    srv->free(operReq);

}
Пример #11
0
 //用户登陆成功后推送用户的位置
 static void Position_push( TCPConnection::Pointer conn, hf_uint32 roleid)
 {
     STR_PackPlayerPosition pos = GetUserPos( roleid );
     char buf[512] = {0};
     memcpy(buf,&pos,sizeof(pos));
     conn->Write_all(buf,sizeof(pos));
     //保存玩家位置
     SessionMgr::Instance()->SaveSession(conn, &pos);        
 }
Пример #12
0
 //请求任务目标
void GameTask::TaskAim(TCPConnection::Pointer conn, hf_uint32 taskid)
{
    umap_taskAim::iterator it = (*m_taskAim).find(taskid);
    if(it != (*m_taskAim).end())
    {
        STR_PackTaskAim t_aim = (*m_taskAim)[taskid];
        conn->Write_all(&t_aim, sizeof(STR_PackTaskAim));
    }
}
Пример #13
0
 //请求任务描述
void GameTask::TaskDescription(TCPConnection::Pointer conn, hf_uint32 taskid)
{
    umap_taskDescription::iterator it = (*m_taskDesc).find(taskid);
    if(it != (*m_taskDesc).end())
    {
        STR_PackTaskDescription t_desc= (*m_taskDesc)[taskid];
        conn->Write_all(&t_desc, sizeof(STR_PackTaskDescription));
    }
}
Пример #14
0
    void clear()                                           //恢复到原来未交易状态
    {
        isInchange = false;
        isLocked =false;
        isChangeChecked = false;
        partnerConn.reset();
        changes.clear();
        money.MoneyCount = 0;

    }
Пример #15
0
void EMServer::handle_accept(
	TcpConnection::Pointer new_connection,
        const boost::system::error_code &err)
{
	if (!err)
		new_connection->start();
	else
		warn() << "handle_accept: error\n";
	start_accept();
}
Пример #16
0
void GameInterchange::operMoneyChanges(TCPConnection::Pointer conn, interchangeMoney*  oper) //交易金钱变动
{

    Server* srv = Server::GetInstance();
    SessionMgr::SessionPointer sp = SessionMgr::Instance()->GetSession();
    boost::shared_ptr<Interchange> interchange = (*sp)[conn].m_interchage;
    TCPConnection::Pointer partnerConn = interchange->partnerConn;

    SessionMgr::SessionMap::iterator iter = sp->find(partnerConn);
    if(iter == sp->end())                        //对方离线 则发取消交易的包返回
    {
        interchangeOperPro resp;
        resp.operType = Operation_CancelChange;
        conn->Write_all((char*)&resp, sizeof(interchangeOperPro));
        for(std::vector<STR_Goods>::iterator iter = interchange->changes.begin(); iter != interchange->changes.end(); ++iter)    //背包位置信息恢复原来标志
        {
            (*sp)[conn].m_goodsPosition[iter->Position] = POS_NONEMPTY;
        }
        interchange->clear();           //清除交易状态
        srv->free(oper);
        return;
    }

    _umap_roleMoney::iterator iterMoney = (*sp)[conn].m_playerMoney->find(oper->MoneyType);
    if(iterMoney == (*sp)[conn].m_playerMoney->end()                                           //没有这样类型的金币
            || (*((*sp)[conn].m_playerMoney))[oper->MoneyType].Count < oper->MoneyCount)  //或者没有这样数量的金币
    {
        interchangeOperPro resp;
        resp.operType = Operation_MoneyNotEnough;         //由服务器发金币不足的包
        conn->Write_all((char*)&resp, sizeof(interchangeOperPro));
        srv->free(oper);
        return;
    }

    conn->Write_all((char*)oper, sizeof(interchangeMoney));
    oper->roleId = (*sp)[conn].m_roleid;
    partnerConn->Write_all((char*)oper, sizeof(interchangeMoney));

    interchange->money.MoneyCount = oper->MoneyCount;                      //缓存要交易的金币数量
    interchange->money.MoneyType = oper->MoneyType;

    srv->free(oper);
}
Пример #17
0
void GameInterchange::operProUnlock(TCPConnection::Pointer conn, interchangeOperPro*  oper)
{

    Server* srv = Server::GetInstance();
    SessionMgr::SessionPointer sp = SessionMgr::Instance()->GetSession();
    boost::shared_ptr<Interchange> interchange = (*sp)[conn].m_interchage;
    TCPConnection::Pointer partnerConn = interchange->partnerConn;

    SessionMgr::SessionMap::iterator iter = sp->find(partnerConn);
    if(iter == sp->end())    //对方离线 则由服务器发取消交易的包返回
    {
        interchangeOperPro resp;
        resp.operType = Operation_CancelChange;
        conn->Write_all((char*)&resp, sizeof(interchangeOperPro));

        for(std::vector<STR_Goods>::iterator iterIn = interchange->changes.begin(); iterIn != interchange->changes.end();++iterIn)
        {
              (*sp)[conn].m_goodsPosition[iterIn->Position] = POS_NONEMPTY;       //恢复物品原来标志
        }

        interchange->clear();           //清除交易状态  对方离线所以不用处理其状态信息

        srv->free(oper);
        return;
    }
    else                //对方在线
    {
        if((*sp)[partnerConn].m_interchage->isChangeChecked)  //对方已经点击确认交易时,如果解除锁定,则对方也退回到解除锁定状态
        {
            interchange->unlock();           //解除锁定状态
            (*sp)[partnerConn].m_interchage->unlock();        //对方解除锁定状态
            oper->operType = Operation_BothUnLock;  //对方已经点击确认交易时,如果解除锁定,则对方也退回到解除锁定状态
            conn->Write_all((char*)oper, sizeof(interchangeOperPro));  //这个包要向双方都发
            partnerConn->Write_all((char*)oper, sizeof(interchangeOperPro)); //这个包要向双方都发
        }
        else   //对方没有点击交易时,则向其转发取消锁定的包
        {
            oper->operType = Operation_UnLock;
            partnerConn->Write_all((char*)oper, sizeof(interchangeOperPro));
        }
        srv->free(oper);
    }
}
Пример #18
0
void GameInterchange::operResponse(TCPConnection::Pointer conn,  operationRequestResult*  operReq)
{
    Server* srv = Server::GetInstance();
    SessionMgr::SessionPointer sp = SessionMgr::Instance()->GetSession();
    umap_roleSock rsock =  (SessionMgr::Instance()->GetRoleSock());
    _umap_roleSock::iterator iter = rsock->find(operReq->RoleID);
    if(iter == rsock->end())                    //对方掉线 由服务器发取消交易的包返回
    {
        if(operReq->operResult == Result_Accept)
        {
            interchangeOperPro resp;
            resp.operType = Operation_CancelChange;
            conn->Write_all((char*)&resp, sizeof(interchangeOperPro));
        }
        (*sp)[conn].m_interchage->clear();
        srv->free(operReq);
        return;
    }

    TCPConnection::Pointer partnerConn = (*rsock)[operReq->RoleID];
    operReq->RoleID =  (*sp)[conn].m_roleid;
    partnerConn->Write_all((char*)operReq, sizeof(operationRequestResult));       //转发答复的包

    if(operReq->operResult == Result_Accept)                                                                                   //如果答复同意交易,则设置交易标志
    {
//        (*sp)[conn].m_interchage->roleId = (*sp)[conn].m_roleid;  //保存自己的角色id
//        (*sp)[partnerConn].m_interchage->roleId = (*sp)[partnerConn].m_roleid;  //对方保存自己的角色id
//        (*sp)[conn].m_interchage->partnerConn = partnerConn; //互相保存对方的连接
//        (*sp)[partnerConn].m_interchage->partnerConn = conn;  //互相保存对方的连接
    }
    else if(operReq->operResult == Result_Reject || operReq->operResult == Result_RejectTimeOut)                           //拒绝
    {
        (*sp)[conn].m_interchage->clear();
        (*sp)[partnerConn].m_interchage->clear();
    }

   srv->free(operReq);
}
Пример #19
0
void TCPServer::CallBack_Accept(TCPConnection::Pointer conn, const boost::system::error_code &ec)
{
    if ( ! ec)
    {
        Logger::GetLogger()->Debug("Client Connected");

        //set nodelay option
        boost::asio::ip::tcp::no_delay  nodelay(true);
        conn->socket().set_option(nodelay);

        Server::GetInstance()->RunTask(boost::bind(&TCPConnection::Start,conn));
    }
    StartListen();
}
Пример #20
0
void TCPServer::CallBack_Accept(TCPConnection::Pointer conn, const boost::system::error_code &ec)
{
    if ( ! ec)
    {
        Logger::GetLogger()->Debug("Client Connected");
        boost::asio::ip::tcp::no_delay  nodelay(true);
        boost::asio::socket_base::non_blocking_io none_block(true);
        conn->socket().io_control(none_block);
        if ( conn->socket().non_blocking() ){
            Logger::GetLogger()->Debug("None_Block");
        }else{
            Logger::GetLogger()->Debug("Block Socket");
        }
        conn->socket().set_option(nodelay);

        conn->Start();
//        Server::GetInstance()->RunTask(boost::bind(&TCPConnection::Start,conn));
    }
    else
    {
        Logger::GetLogger()->Error("error:%d",ec.value());
    }
    StartListen();
}
Пример #21
0
//请求任务结束对话
void GameTask::FinishTaskDlg(TCPConnection::Pointer conn, hf_uint32 taskid)
{
    umap_dialogue::iterator it = (*m_dialogue).find(taskid);
    if(it != (*m_dialogue).end())
    {
        hf_char* buff = (hf_char*)Server::GetInstance()->malloc();
        STR_PackTaskDlg t_dlg= (*m_dialogue)[taskid];
        STR_PackHead t_packHead;
        t_packHead.Len = t_dlg.FinishLen + sizeof(t_dlg.TaskID) ;
        t_packHead.Flag = FLAG_FinishTaskDlg;
        memcpy(buff, &t_packHead, sizeof(STR_PackHead));
        memcpy(buff + sizeof(STR_PackHead), &t_dlg.TaskID, sizeof(t_dlg.TaskID));
        memcpy(buff + sizeof(STR_PackHead) + sizeof(t_dlg.TaskID), t_dlg.FinishDialogue, t_dlg.FinishLen);

        conn->Write_all(buff, sizeof(STR_PackHead) + t_packHead.Len);
        Server::GetInstance()->free(buff);
    }
}
Пример #22
0
//玩家上线,发送离线的添加好友请求
 void TeamFriend::SendAskAddFriend(TCPConnection::Pointer conn)
 {
     SessionMgr::SessionPointer smap = SessionMgr::Instance()->GetSession();
     hf_uint32 roleid = (*smap)[conn].m_roleid;
     StringBuilder sbd;
     sbd << "select requestroleid,requestnick from t_addFriend where addroleid = " << roleid << ";";
     Logger::GetLogger()->Debug(sbd.str());

     Server* srv = Server::GetInstance();
     vector<STR_AddFriend> addFriend;
     hf_int32 t_row = srv->getDiskDB()->GetAskAddFriend(addFriend, sbd.str());
     if(t_row > 0)
     {
         hf_char* buff = (hf_char*)srv->malloc();
         STR_PackHead t_packHead;
         t_packHead.Flag = FLAG_AddFriend;
         t_packHead.Len = t_row*sizeof(STR_AddFriend);
         hf_int32 i = 0;
         for(vector<STR_AddFriend>::iterator it = addFriend.begin(); it != addFriend.end(); it++)
         {
             memcpy(buff + sizeof(STR_PackHead) + i*sizeof(STR_AddFriend),&(*it), sizeof(STR_AddFriend));
             i++;
         }
         memcpy(buff, &t_packHead, sizeof(STR_PackHead));
         conn->Write_all(buff,t_packHead.Len + sizeof(STR_PackHead));

         srv->free(buff);

         //删除保存的离线添加请求
         sbd.Clear();
         sbd << "delete from t_addFriend where addroleid = " << roleid << ";";
         Logger::GetLogger()->Debug(sbd.str());
         t_row = srv->getDiskDB()->Set(sbd.str());
         if(t_row == 1)
         {
             Logger::GetLogger()->Debug("delete asd addfriend success");
         }
     }
 }
Пример #23
0
//请求完成任务
void GameTask::AskFinishTask(TCPConnection::Pointer conn, STR_FinishTask* finishTask)
{
    SessionMgr::SessionMap* smap = SessionMgr::Instance()->GetSession().get();
    umap_taskProcess umap_playerAcceptTask = (*smap)[conn].m_playerAcceptTask;

    _umap_taskProcess::iterator it = umap_playerAcceptTask->find(finishTask->TaskID);
    if(it == umap_playerAcceptTask->end()) //没接取当前任务
    {
        return;
    }
    umap_taskAim::iterator iter= m_taskAim->find(finishTask->TaskID);
    if(iter != m_taskAim->end())
    {
        if(it->second.AimAmount == iter->second.Amount)
        {
             Server::GetInstance()->GetOperationPostgres()->PushUpdateTask((*smap)[conn].m_roleid, &(it->second), PostDelete); //将任务从list中删除
             umap_playerAcceptTask->erase(it);
             STR_PackFinishTaskResult t_taskResult;
             t_taskResult.TaskID = finishTask->TaskID;
             conn->Write_all(&t_taskResult, sizeof(STR_PackFinishTaskResult));
        }
    }
}
Пример #24
0
//查找此任务是否为任务进度里打怪任务,如果是,更新任务进度
void GameTask::UpdateAttackMonsterTaskProcess(TCPConnection::Pointer conn, STR_MonsterBasicInfo* monster)
{
    SessionMgr::SessionPointer smap =  SessionMgr::Instance()->GetSession();

    umap_taskProcess umap_playerAcceptTask = ((*smap)[conn]).m_playerAcceptTask;
    for(_umap_taskProcess::iterator t_task = umap_playerAcceptTask->begin(); t_task != umap_playerAcceptTask->end(); t_task++)
    {
        if(t_task->second.AimID == monster->MonsterTypeID && t_task->second.ExeModeID == EXE_attack_blame && t_task->second.AimCount < t_task->second.AimAmount)
        {
            if(t_task->second.AimCount == t_task->second.AimAmount)
            {
                return;
            }
            t_task->second.AimCount = t_task->second.AimCount + 1;

            (*umap_playerAcceptTask)[t_task->second.TaskID] = t_task->second;

            STR_PackTaskProcess t_taskProcess;
            memcpy(&t_taskProcess.TaskProcess, &t_task->second, sizeof(STR_TaskProcess));
            conn->Write_all(&t_taskProcess, sizeof(STR_PackTaskProcess));
        }
    }
}
Пример #25
0
    //
    //向当前玩家推送其他玩家的位置(可见的)
    //
    static void PushOtherUserPosition( TCPConnection::Pointer sk, STR_PackPlayerPosition *pos)
    {
        SessionMgr::SessionPointer ssmap = SessionMgr::Instance()->GetSession();
        SessionMgr::SessionMap::iterator it = ssmap->begin();
        while ( it != ssmap->end() )
        {
                TCPConnection::Pointer first = it->first;
                STR_PackPlayerPosition *spos = &( it->second.m_position);

                //不要推给自己
                if ( first == sk)
                    continue;
                hf_float dx = spos->Pos_x - pos->Pos_x,
                                dy = spos->Pos_y - pos->Pos_y,
                                dz = spos->Pos_z - pos->Pos_z,
                        dis = sqrt( dx*dx + dy * dy + dz * dz );

                //不要推视野范围外的玩家
                if ( dis > PlayerView )
                    continue;
                //Transfer::write_n(sk,(char*)pos,sizeof(STR_PackPlayerPosition));
                sk->Write_all(pos,sizeof(STR_PackPlayerPosition));
        }
    }
Пример #26
0
    //用户位置移动
    static void PlayerPositionMove(TCPConnection::Pointer conn, STR_PackPlayerMove* Move)
    {
        SessionMgr::SessionPointer smap =  SessionMgr::Instance()->GetSession();

        STR_PackPlayerPosition* pos = &((*smap)[conn].m_position);
        pos->Direct = Move->Direct;
        pos->ActID = Move->ActID;
        hf_uint16 move_speed = (*smap)[conn].m_roleInfo.Move_Speed;
        switch(Move->Opt)
        {
        case 0:
        {
            conn->Write_all(pos, sizeof(STR_PackPlayerPosition));
            //给可视范围内的玩家发送位置
            BroadCastUserPosition(conn, pos);
            Server::GetInstance()->free(Move);
            return;
        }
        case 1:   //向前移动
        {
            pos->Pos_x = pos->Pos_x + PlayerMoveDistance * move_speed/100 * cos(pos->Direct);
            pos->Pos_z = pos->Pos_z + PlayerMoveDistance * move_speed/100 * sin(pos->Direct);
            break;
        }
        case 2: //向后移动
        {
            pos->Pos_x = pos->Pos_x + PlayerMoveDistance * move_speed/100 * cos(pos->Direct + PI);
            pos->Pos_z = pos->Pos_z + PlayerMoveDistance * move_speed/100 * sin(pos->Direct + PI);
            break;
        }
        case 3://向左移动
        {
            pos->Pos_x = pos->Pos_x + PlayerMoveDistance * move_speed/100 * cos(pos->Direct + PI/2);
            pos->Pos_z = pos->Pos_z + PlayerMoveDistance * move_speed/100 * sin(pos->Direct + PI/2);
            break;
        }
        case 4://向右移动
        {
            pos->Pos_x = pos->Pos_x + PlayerMoveDistance * move_speed/100 * cos(pos->Direct + PI*3/2);
            pos->Pos_z = pos->Pos_z + PlayerMoveDistance * move_speed/100 * sin(pos->Direct + PI*3/2);
            break;
        }
        default:
            Logger::GetLogger()->Info("Unkown derect pack");
            Server::GetInstance()->free(Move);
            return;
        }

//        conn->Write_all(pos, sizeof(STR_PackPlayerPosition));
        //给可视范围内的玩家发送位置       
        BroadCastUserPosition(conn, pos);

        STR_PlayerStartPos* startPos = &(*smap)[conn].m_StartPos;
        hf_float dx = startPos->Pos_x - pos->Pos_x,
                 dy = startPos->Pos_y - pos->Pos_y,
                 dz = startPos->Pos_z - pos->Pos_z;
        if(dx*dx + dy*dy + dz*dz >= RefreshDistance*RefreshDistance)
        {
            startPos->Pos_x = pos->Pos_x;
            startPos->Pos_x = pos->Pos_x;
            startPos->Pos_x = pos->Pos_x;
            //刷新新看到的怪和离开可视范围的怪
            Server::GetInstance()->GetMonster()->PushViewMonsters(conn);
            //刷新新看到的玩家和离开可视范围的的玩家
            Server::GetInstance()->GetPlayerLogin()->SendViewRole(conn);
        }
        Server::GetInstance()->free(Move);
    }
Пример #27
0
void GameInterchange::operChanges(TCPConnection::Pointer conn, interchangeOperGoods*  oper) //交易物品变动
{

    Server* srv = Server::GetInstance();

    SessionMgr::SessionPointer sp = SessionMgr::Instance()->GetSession();

    if(oper->goodsId>=min_EquipMentId && oper->goodsId <=max_EquipMentId)
    {
        _umap_roleEqu::iterator iterRoleGoods = (*sp)[conn].m_playerEqu->find(oper->goodsId);
        if(iterRoleGoods == (*sp)[conn].m_playerEqu->end())            //玩家选择的物品在服务器中不存在属于异常情况,忽略异常情况,服务器不做响应
        {
            return;
        }

        if(iterRoleGoods->second.goods.Position == oper->position&&iterRoleGoods->second.goods.Count == oper->goodsCount) //位置信息和数量同时对应,则是找到玩家选择的物品
        {
            (*sp)[conn].m_goodsPosition[oper->position] = POS_LOCKED;       //背包中找到该物品,则设定对该物品不能做其它操作
        }
        else
        {
            return;
        }
    }
    else
    {
        _umap_roleGoods::iterator iterRoleGoods = (*sp)[conn].m_playerGoods->find(oper->goodsId);
        if(iterRoleGoods == (*sp)[conn].m_playerGoods->end())            //玩家选择的物品在服务器中不存在属于异常情况,忽略异常情况,服务器不做响应
        {
            return;
        }
        vector<STR_Goods>::iterator iterGoods = iterRoleGoods->second.begin();
        for(; iterGoods != iterRoleGoods->second.end(); ++iterGoods)
        {
            if(iterGoods->Position == oper->position&&iterGoods->Count == oper->goodsCount) //位置信息和数量同时对应,则是找到玩家选择的物品
            {
                (*sp)[conn].m_goodsPosition[oper->position] = POS_LOCKED;       //背包中找到该物品,则设定对该物品不能做其它操作
                break;
            }
        }
        if(iterGoods == iterRoleGoods->second.end())                                    //背包中未找到该物品,属于异常情况,忽略异常情况
        {
            return;
        }
    }

    boost::shared_ptr<Interchange> interchange = (*sp)[conn].m_interchage;
    if(oper->operType == Goods_Add)                        //增加物品的操作
    {
        std::vector<STR_Goods>::iterator iter = interchange->changes.begin();
        for( ;iter != interchange->changes.end(); ++iter)
        {
            if(iter->Position == oper->position)
                break;
        }
        if(iter == interchange->changes.end())              //交易筐中还没添加该位置的物品
        {
            STR_Goods goods;
            goods.Count = oper->goodsCount;
            goods.Position = oper->position;
            goods.GoodsID = oper->goodsId;
            goods.TypeID = oper->goodsType;
            goods.Source = Source_Trade;
            interchange->changes.push_back(goods);
        }
        else
        {
            return;                //交易筐中已经添加该位置的物品,属于异常情况,则忽略该次请求
        }
    }
    else  if(oper->operType == Goods_Remove)                                                       //从交易篮中删除物品
    {
       int haveValue = 0;
       std::vector<STR_Goods>::iterator iter = interchange->changes.begin();
       for(;iter != interchange->changes.end();++iter)
       {
           if(iter->Count == oper->goodsCount&&iter->Position ==  oper->position&&iter->GoodsID == oper->goodsId)
           {
               haveValue = 1;
               iter = interchange->changes.erase(iter);
                (*sp)[conn].m_goodsPosition[oper->position] = POS_NONEMPTY;       //恢复物品原来标志
               break;
           }
       }
       if(iter == interchange->changes.end()&& haveValue == 0)
       {
           return;
       }
    }

    TCPConnection::Pointer partnerConn = interchange->partnerConn;
    SessionMgr::SessionMap::iterator iter = sp->find(partnerConn);
    if(iter == sp->end())                        //对方离线 则由服务器发取消交易的包返回
    {
        interchangeOperPro resp;
        resp.operType = Operation_CancelChange;
        conn->Write_all((char*)&resp, sizeof(interchangeOperPro));
        for(std::vector<STR_Goods>::iterator iter = interchange->changes.begin(); iter != interchange->changes.end(); ++iter)    //背包位置信息恢复原来标志
        {
            (*sp)[conn].m_goodsPosition[iter->Position] = POS_NONEMPTY;
        }
        interchange->clear();           //清除交易状态  对方离线所以不用处理其状态信息
        srv->free(oper);
        return;
    }

    conn->Write_all((char*)oper, sizeof(interchangeOperGoods));
    partnerConn->Write_all((char*)oper, sizeof(interchangeOperGoods));
    srv->free(oper);
}
Пример #28
0
void TeamFriend::addFriend(TCPConnection::Pointer conn, STR_PackAddFriend* addFriend)
{
    Server* srv = Server::GetInstance();

    STR_PackAddFriend t_addFriend;
    SessionMgr::SessionPointer smap = SessionMgr::Instance()->GetSession();
    t_addFriend.RoleID = (*smap)[conn].m_roleid;
    memcpy(t_addFriend.Nick, ((*smap)[conn].m_RoleBaseInfo.Nick), 32);

    if(addFriend->RoleID >= 100000000) //按roleID添加好友(优先)
    {
        umap_roleSock roleSock = SessionMgr::Instance()->GetRoleSock();
        _umap_roleSock::iterator it = roleSock->find(addFriend->RoleID);
        if(it != roleSock->end()) //要添加的好友在线
        {
            it->second->Write_all(&t_addFriend, sizeof(STR_PackAddFriend));
        }
        if(it == roleSock->end()) //玩家不在线
        {
            StringBuilder sbd;
            sbd << "insert into t_addFriend values(" << t_addFriend.RoleID << ",'" << t_addFriend.Nick << "'," << addFriend->RoleID << ");";
            Logger::GetLogger()->Debug(sbd.str());
            if(srv->getDiskDB()->Set(sbd.str()) == -1)
            {
                Logger::GetLogger()->Error("insert add role friend error");
            }
        }
    }
    else  //按昵称添加好友
    {
         SessionMgr::umap_nickSock nickSock = SessionMgr::Instance()->GetNickSock();
         SessionMgr::_umap_nickSock::iterator it = nickSock->find(addFriend->Nick);
         if(it != nickSock->end()) //在线
         {
             it->second->Write_all(&t_addFriend, sizeof(STR_PackAddFriend));
         }
         else //添加的好友不在线
         {
             hf_char nickbuff[40] = { 0 };
             memcpy(nickbuff, addFriend->Nick, sizeof(addFriend->Nick));
             //在数据库中查找昵称是否存在
             StringBuilder sbd;
             sbd << "select roleid from t_playerrolelist where nick = '" << nickbuff << "';";
             Logger::GetLogger()->Debug(sbd.str());
             hf_uint32 addroleid = 0;
             hf_int32 t_row = srv->getDiskDB()->GetNickRoleid(&addroleid, sbd.str());
             if(t_row == 1) //昵称存在,保存为离线请求
             {
                 hf_uint32 Requestroleid = (*smap)[conn].m_roleid;
                 hf_char   RequestNick[40] = { 0 };
                 memcpy(RequestNick, (*smap)[conn].m_RoleBaseInfo.Nick, 32);
                 sbd.Clear();
                 sbd << "insert into t_addFriend values(" << Requestroleid << ",'" << RequestNick << "'," << addroleid << ");";
                 Logger::GetLogger()->Debug(sbd.str());
                 t_row = srv->getDiskDB()->Set(sbd.str());
                 if( t_row == -1)
                 {
                     Logger::GetLogger()->Error("insert add friend error");
                 }
             }
             else if(t_row == 0) //昵称不存在
             {
                 STR_PackAddFriendReturn Raddfriend;

                 memcpy(Raddfriend.Nick, addFriend->Nick, 32);
                 Raddfriend.value = 3;
                 conn->Write_all(&Raddfriend, sizeof(STR_PackAddFriendReturn));
             }
         }
    }
    srv->free(addFriend);
}
Пример #29
0
void GameInterchange::operProCheckChange(TCPConnection::Pointer conn,  interchangeOperPro*  oper)  //确认交易
{

    Server* srv = Server::GetInstance();
    SessionMgr::SessionPointer sp = SessionMgr::Instance()->GetSession();
    boost::shared_ptr<Interchange> interchange = (*sp)[conn].m_interchage;
    TCPConnection::Pointer partnerConn =  interchange->partnerConn;

    SessionMgr::SessionMap::iterator iter = sp->find(partnerConn);
    if(iter == sp->end())    //对方离线 则由服务器发取消交易的包返回
    {
        interchangeOperPro resp;
        resp.operType = Operation_CancelChange;
        conn->Write_all((char*)&resp, sizeof(interchangeOperPro));

        for(std::vector<STR_Goods>::iterator iterIn = interchange->changes.begin(); iterIn != interchange->changes.end();++iterIn)
        {
              (*sp)[conn].m_goodsPosition[iterIn->Position] = POS_NONEMPTY;       //恢复物品原来标志
        }
        interchange->clear();           //清除交易状态  对方离线所以不用处理其状态信息
        srv->free(oper);
        return;
    }

    boost::shared_ptr<Interchange> pInterchange = (*sp)[partnerConn].m_interchage;

    if(!(interchange->isLocked&&pInterchange->isLocked)) //双方没有全都锁定过时候,确认交易请求无效
    {
        interchangeOperPro resp;
        resp.operType = Operation_NotLockedCheckChange;  //回复双方没有全都锁定的包
        conn->Write_all((char*)&resp, sizeof(interchangeOperPro));
        srv->free(oper);
        return;
    }

    interchange->isChangeChecked = true;      //双方都已经锁定过,则置确认交易的标志

    if(!pInterchange->isChangeChecked)   //对方没有确认交易,则只转发包返回
    {
        partnerConn->Write_all((char*)oper, sizeof(interchangeOperPro));
        srv->free(oper);
        return;
    }

    partnerConn->Write_all((char*)oper, sizeof(interchangeOperPro)); //对方也已经确认交易 转发包
    srv->free(oper);

    //计算双方背包空闲位置个数,判断是否满足交换需求
    int emptyPartnerconn = 0;
    int emptyconn = 0;
    for(int i = 1; i <=BAGCAPACITY-1;++i)                     //查找空闲位置 计算空闲位置个数
    {
        if((*sp)[conn].m_goodsPosition[i] == POS_EMPTY)
        {
           emptyconn++;
        }
    }
    for(int i = 1; i <=BAGCAPACITY-1;++i)                     //查找空闲位置 计算空闲位置个数
    {
        if((*sp)[partnerConn].m_goodsPosition[i] == POS_EMPTY)
        {
           emptyPartnerconn++;
        }
    }
    if(interchange->changes.size() + emptyconn < pInterchange->changes.size()
            || pInterchange->changes.size() + emptyPartnerconn < interchange->changes.size())        //如果空闲位置个数不满足交换需求,则取消交易
    {
        interchangeOperPro resp;
        resp.operType = Operation_CancelChange;
        conn->Write_all((char*)&resp, sizeof(interchangeOperPro));
        partnerConn->Write_all((char*)&resp, sizeof(interchangeOperPro));

        for(std::vector<STR_Goods>::iterator iter = interchange->changes.begin(); iter != interchange->changes.end();++iter)
        {
              (*sp)[conn].m_goodsPosition[iter->Position] = POS_NONEMPTY;       //恢复物品原来标志
        }
        for(std::vector<STR_Goods>::iterator iter = pInterchange->changes.begin(); iter != pInterchange->changes.end();++iter)
        {
              (*sp)[partnerConn].m_goodsPosition[iter->Position] = POS_NONEMPTY;       //恢复物品原来标志
        }
        interchange->clear();           //清除交易状态
        pInterchange->clear(); //对方清除交易状态
        return;
    }

    operDoChange(conn);//如果空闲位置个数满足交换需求,则交换两个玩家物品和金钱
    operReport(conn);    //交换完成发送交易报告

    interchangeOperPro resp;
    resp.operType = Operation_Done;
    conn->Write_all((char*)&resp, sizeof(interchangeOperPro));
    partnerConn->Write_all((char*)&resp, sizeof(interchangeOperPro));

    GameTask* t_task = srv->GetGameTask();
    for(std::vector<STR_Goods>::iterator iter = interchange->changes.begin(); iter != interchange->changes.end();++iter)
    {
          t_task->UpdateCollectGoodsTaskProcess(conn,iter->TypeID);
    }
    for(std::vector<STR_Goods>::iterator iter = pInterchange->changes.begin(); iter != pInterchange->changes.end();++iter)
    {
          t_task->UpdateCollectGoodsTaskProcess(conn,iter->TypeID);
    }

    interchange->clear();                          //交易完毕 恢复到原来状态
    pInterchange->clear();  //交易完毕 恢复到原来状态
}
Пример #30
0
void GameInterchange::operReport(TCPConnection::Pointer conn)   //交易报告 交换双方物品后向双方发送交易的物品变动
{

    Server* srv = Server::GetInstance();
    SessionMgr::SessionPointer sp = SessionMgr::Instance()->GetSession();
    boost::shared_ptr<Interchange> interchange = (*sp)[conn].m_interchage;
    TCPConnection::Pointer partnerConn =  interchange->partnerConn;
    boost::shared_ptr<Interchange> pInterchange = (*sp)[partnerConn].m_interchage;

    STR_PackHead        head;
    char bufToConn[1024]={0};
    char bufToPartner[1024]={0};
    memset(&head,0,sizeof(STR_PackHead));

    //向双方发送本方交易物品(包括装备)的变动
    head.Len = sizeof(STR_Goods)*interchange->changes.size();
    if(head.Len != 0)
    {
        head.Flag = FLAG_BagGoods;
        memcpy(bufToPartner,&head,sizeof(head));
        for(int i = 0; i < interchange->changes.size(); ++i)
        {
            memcpy(bufToPartner+sizeof(STR_PackHead)+sizeof(STR_Goods)*i,&(interchange->changes[i]),sizeof(STR_Goods));
        }
        partnerConn->Write_all(bufToPartner, sizeof(STR_PackHead)+head.Len);  //向对方发送本方已经交易的物品
    }

    //向对方发送本方交易中装备的属性

    head.Len = interchange->vecEqui.size()*sizeof(STR_EquipmentAttr);
    if(head.Len != 0)       //如果交易中有装备
    {
        head.Flag = FLAG_EquGoodsAttr;
        memset(bufToPartner,0,1024);
        memcpy(bufToPartner,&head,sizeof(head));

        for(int i = 0; i < interchange->vecEqui.size(); ++i)
        {
            memcpy(bufToPartner+sizeof(STR_PackHead)+sizeof(STR_EquipmentAttr)*i,&(interchange->vecEqui[i]),sizeof(STR_EquipmentAttr));
        }
        partnerConn->Write_all(bufToPartner, sizeof(STR_PackHead)+head.Len);   //本方交易的物品是装备,要向对方发送属性信息
    }

    //向双方发送对方交易物品的情况
    head.Len = sizeof(STR_Goods)*pInterchange->changes.size();
    if(head.Len != 0)
    {
        head.Flag = FLAG_BagGoods;
        memset(bufToConn,0,1024);
        memcpy(bufToConn,&head,sizeof(head));
        for(int i = 0; i < pInterchange->changes.size(); ++i)
        {
            memcpy(bufToConn+sizeof(STR_PackHead)+sizeof(STR_Goods)*i,&(pInterchange->changes[i]),sizeof(STR_Goods));
        }
        conn->Write_all(bufToConn, sizeof(STR_PackHead)+head.Len);  //向本方发送对方已经交易的物品
    }

    //向本方发送对方交易中装备的属性
    head.Len = pInterchange->vecEqui.size()*sizeof(STR_EquipmentAttr);
    cout<<"                   head.len2    "<<head.Len<<endl;
    if(head.Len != 0)      //如果交易中有装备
    {
        memset(bufToConn,0,1024);
        head.Flag = FLAG_EquGoodsAttr;
        memcpy(bufToConn,&head,sizeof(head));
        for(int i = 0; i < pInterchange->vecEqui.size(); ++i)
        {
            memcpy(bufToConn+sizeof(STR_PackHead)+sizeof(STR_EquipmentAttr)*i,&(pInterchange->vecEqui[i]),sizeof(STR_EquipmentAttr));
        }
        conn->Write_all(bufToConn, sizeof(STR_PackHead)+head.Len);  //对方交易的如果是装备,则向本方发送装备属性信息
    }

    //发送双方交易的金钱类型在交易后的现状
    if(pInterchange->money.MoneyCount != 0)
    {
        char buf[1024] = {0};
        memset(&head,0,sizeof(STR_PackHead));
        head.Flag = FLAG_PlayerMoney;
        head.Len = sizeof(STR_PlayerMoney);
        memcpy(buf,&head,sizeof(head));

        _umap_roleMoney::iterator iterMoney = (*sp)[partnerConn].m_playerMoney->find(pInterchange->money.MoneyType);
        if (iterMoney != (*sp)[partnerConn].m_playerMoney->end())
        {
            memcpy(buf+sizeof(STR_PackHead),&(iterMoney->second),sizeof(STR_PlayerMoney));
        }
        else        //如果金钱中未找到这种类型,说明已经为0,发送数量为0的包
        {
            STR_PlayerMoney money;
            money.TypeID = pInterchange->money.MoneyType;
            money.Count = 0;
            memcpy(buf+sizeof(STR_PackHead),&money,sizeof(STR_PlayerMoney));
        }
        partnerConn->Write_all(buf, sizeof(STR_PackHead)+head.Len);   //向对方发送对方现在这种类型的金钱
        iterMoney = (*sp)[conn].m_playerMoney->find(pInterchange->money.MoneyType);
        {
            if (iterMoney != (*sp)[conn].m_playerMoney->end())
            {
                memset(buf+sizeof(STR_PackHead),0,sizeof(STR_PlayerMoney));
                memcpy(buf+sizeof(STR_PackHead),&(iterMoney->second),sizeof(STR_PlayerMoney));
                conn->Write_all(buf, sizeof(STR_PackHead)+head.Len);   //向本方发送本方现在这种类型的金钱
            }
        }
    }

    //发送双方交易中金钱类型在交易后的现状
    if(interchange->money.MoneyCount != 0)
    {
        char buf[1024] = {0};
        memset(&head,0,sizeof(STR_PackHead));
        head.Flag = FLAG_PlayerMoney;
        head.Len = sizeof(STR_PlayerMoney);
        memcpy(buf,&head,sizeof(head));

        _umap_roleMoney::iterator iterMoney = (*sp)[conn].m_playerMoney->find(interchange->money.MoneyType);
        if (iterMoney != (*sp)[conn].m_playerMoney->end())
        {
            memcpy(buf+sizeof(STR_PackHead),&(iterMoney->second),sizeof(STR_PlayerMoney));
        }
        else
        {
            STR_PlayerMoney money;
            money.TypeID = interchange->money.MoneyType;
            money.Count = 0;
            memcpy(buf+sizeof(STR_PackHead),&money,sizeof(STR_PlayerMoney));
        }
        conn->Write_all(buf, sizeof(STR_PackHead)+head.Len);  //向本方发送本方现在这种类型的金钱
        iterMoney = (*sp)[partnerConn].m_playerMoney->find(interchange->money.MoneyType);
        if (iterMoney != (*sp)[partnerConn].m_playerMoney->end())
        {
            memset(buf+sizeof(STR_PackHead),0,sizeof(STR_PlayerMoney));
            memcpy(buf+sizeof(STR_PackHead),&(iterMoney->second),sizeof(STR_PlayerMoney));
            partnerConn->Write_all(buf, sizeof(STR_PackHead)+head.Len); //向对方发送对方现在这种类型的金钱
        }
    }
}