本文整理汇总了C++中tcpconnection::Pointer类的典型用法代码示例。如果您正苦于以下问题:C++ Pointer类的具体用法?C++ Pointer怎么用?C++ Pointer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pointer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operProCancelChange
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: operProLock
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: handle_read
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: UpdateCollectGoodsTaskProcess
//查找此任务是否为任务进度里收集物品,如果是,更新任务进度
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: operProCancelRequest
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: AskTask
//请求任务
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: SendPlayerViewTask
//发送玩家可视范围内的任务
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: TaskReward
//请求任务奖励
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: SendPlayerTaskProcess
//发送已接取的任务进度,和任务概述
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: operRequest
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: Position_push
//用户登陆成功后推送用户的位置
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: TaskAim
//请求任务目标
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: TaskDescription
//请求任务描述
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: handle_accept
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();
}
示例15: operMoneyChanges
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);
}