本文整理汇总了C++中Packet::GetBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ Packet::GetBuffer方法的具体用法?C++ Packet::GetBuffer怎么用?C++ Packet::GetBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet::GetBuffer方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SOCK_SendPacket
int SOCK_SendPacket(SOCKET socket, Packet& packet, unsigned long protover, bool extended)
{
if(!extended)
{
if(!packet.GetLength()) return 0;
uint8_t* data = new uint8_t[packet.GetLength()];
uint32_t size = packet.GetLength();
std::vector<uint8_t> tbuf = packet.GetBuffer();
for(uint32_t i = 0; i < size; i++)
data[i] = tbuf[i];
int ret_code = send_msg(socket, protover, data, size, 1);
delete[] data;
if(ret_code == -2) return SERR_TIMEOUT;
if(ret_code == -1) return SERR_CONNECTION_LOST;
return 0;
}
else
{
uint8_t* data = new uint8_t[packet.GetLength()+8];
*(uint32_t*)(data) = packet.GetLength();
*(uint32_t*)(data+4) = 0x80100000;
std::vector<uint8_t> tbuf = packet.GetBuffer();
for(uint32_t i = 0; i < packet.GetLength(); i++)
data[i+8] = tbuf[i];
int ret_code = send(socket, (const char*)data, packet.GetLength()+8, 0);
delete[] data;
if(ret_code == -1) return SERR_CONNECTION_LOST;
return 0;
}
}
示例2: OnProcessPacket
void MapSvc::OnProcessPacket(Session& session,Packet& packet)
{
DEBUG_PRINTF1( "C_S req pkg-------MsgType[%d] \n", packet.MsgType );
DEBUG_SHOWHEX( packet.GetBuffer()->GetReadPtr()-PACKET_HEADER_LENGTH, packet.GetBuffer()->GetDataSize()+PACKET_HEADER_LENGTH, 0, __FILE__, __LINE__ );
switch(packet.MsgType)
{
case 201:
ProcessEnterMap(session,packet);
break;
case 202:
ProcessMapMove(session,packet);
break;
case 203:
ProcessTeleportByRune(session,packet);
break;
default:
ClientErrorAck(session,packet,ERR_SYSTEM_PARAM);
LOG(LOG_ERROR,__FILE__,__LINE__,"MsgType[%d] not found",packet.MsgType);
break;
}
}
示例3: SSRequest
//S_S 请求及应答
int SSClient::SSRequest( Packet &packet)
{
int iRet = 0;
//连接
iRet = Connect();
if(iRet<0)
goto EndOfProcess;
DEBUG_PRINTF( "SSRequest: req pkg------- \n" );
DEBUG_SHOWHEX( packet.GetBuffer()->GetReadPtr(), packet.GetBuffer()->GetDataSize(), 0, __FILE__, __LINE__ );
//发送消息
iRet = SendMsg(packet);
if(iRet<0)
goto EndOfProcess;
//缓存清空
packet.GetBuffer()->Reset();
//接收应答
iRet = RecvMsg(packet);
if(iRet<0)
goto EndOfProcess;
DEBUG_PRINTF( "SSRequest: ack pkg------- \n" );
DEBUG_SHOWHEX( packet.GetBuffer()->GetReadPtr()-PACKET_HEADER_LENGTH, packet.GetBuffer()->GetDataSize()+PACKET_HEADER_LENGTH , 0, __FILE__, __LINE__ );
EndOfProcess:
Close();
return iRet;
}
示例4: ProcessMapMove
//@brief [MsgType:0202]移动
void MapSvc::ProcessMapMove(Session& session,Packet& packet)
{
UInt32 RetCode = 0;
DataBuffer serbuffer(1024);
int iRet = 0;
UInt32 RoleID = packet.RoleID;
ArchvRoute art;
//序列化类
Serializer s(packet.GetBuffer());
s>>art;
if( s.GetErrorCode()!= 0 )
{
LOG(LOG_ERROR,__FILE__,__LINE__,"serial error" );
return;
}
DEBUG_PRINTF1( " ProcessMapMove roleID[%d]\n", RoleID );
//业务处理
iRet = _mainSvc->GetCoreData()->ProcessRoleMove( RoleID, art);
if(iRet)
{
LOG(LOG_ERROR,__FILE__,__LINE__,"ProcessRoleMove error" );
return;
}
return;
}
示例5: RecvMsg
int SSClient::RecvMsg( Packet & packet)
{
DataBuffer * buff = packet.GetBuffer();
//消息头接收
int iRecv = SockRecv( buff->GetWritePtr(), PACKET_HEADER_LENGTH);
if( iRecv < 0 || iRecv != PACKET_HEADER_LENGTH )
return -1;
//移动 写指针
buff->MoveWritePtr(iRecv);
//解包头
packet.UnpackHeader();
//包体长度
int iLeft = packet.Length- PACKET_HEADER_LENGTH;
if( 0 == iLeft )
return 0;
//消息体接收
iRecv = SockRecv( buff->GetWritePtr(), iLeft );
if( iRecv != iLeft )
return -1;
//移动 写指针
buff->MoveWritePtr(iRecv);
return 0;
}
示例6: OnProcessPacket
void PKSvc::OnProcessPacket(Session& session,Packet& packet)
{
DEBUG_PRINTF1( "C_S req pkg-------MsgType[%d] \n", packet.MsgType );
DEBUG_SHOWHEX( packet.GetBuffer()->GetReadPtr()-PACKET_HEADER_LENGTH, packet.GetBuffer()->GetDataSize()+PACKET_HEADER_LENGTH, 0, __FILE__, __LINE__ );
switch(packet.MsgType)
{
case 401: //请求PK
ProcessPKReq(session,packet);
break;
default:
ClientErrorAck(session,packet,ERR_SYSTEM_PARAM);
LOG(LOG_ERROR,__FILE__,__LINE__,"MsgType[%d] not found",packet.MsgType);
break;
}
}
示例7: SendMsg
int SSClient::SendMsg( Packet & packet )
{
DataBuffer * buff = packet.GetBuffer();
int iRet = SockSend( buff->GetReadPtr(), buff->GetDataSize());
if(iRet < 0)
return -1;
return 0;
}
示例8: OnProcessPacket
//数据包信息
void OffLineUpdateSvc::OnProcessPacket(Session& session,Packet& packet)
{
DEBUG_PRINTF1( "C_S req pkg-------MsgType[%d] \n", packet.MsgType );
DEBUG_SHOWHEX( packet.GetBuffer()->GetReadPtr()-PACKET_HEADER_LENGTH, packet.GetBuffer()->GetDataSize()+PACKET_HEADER_LENGTH, 0, __FILE__, __LINE__ );
switch(packet.MsgType)
{
case 1601: //[MsgType:1601]升级数据查询
ProcessUpdateDataQuery(session, packet);
break;
case 1602: //[MsgType:1602]开始修炼升级
ProcessBeginUpdate(session, packet);
break;
case 1603: //[MsgType:1603]金币加速挂机
ProcessSpeedupUpdate(session, packet);
break;
case 1604: //[MsgType:1604]停止修炼升级
ProcessStopUpdate(session, packet);
break;
case 1605: //[MsgType:1605] 剩余挂机的时间
ProcessLeftUpdateHour(session, packet);
break;
case 1699: //[MsgType:1699]前台触发扣费
ProcessLostBilling(session, packet);
break;
default:
ClientErrorAck(session,packet,ERR_SYSTEM_PARAM);
LOG(LOG_ERROR,__FILE__,__LINE__,"MsgType[%d] not found",packet.MsgType);
break;
}
}
示例9: UserLogout
void LoginClientConn::UserLogout(const string &user_id) {
proto::IMServerUserLogoutRequest logout_req;
logout_req.set_user_id(user_id);
Packet packet;
PacketSetPBMsg(&packet, &logout_req);
packet.SetVersion(IM_PROTO_VERSION);
packet.SetServiceId(proto::SID_SERVER);
packet.SetCommandId(proto::CID_SERVER_REQ_USERLOGOUT);
// TODO seq num
packet.SetSeqNum(0);
// TODO can add to wait for logout ack list
Send(packet.GetBuffer(), packet.GetLength());
}
示例10: ProcessselectShopItem
void ShopSvc::ProcessselectShopItem(Session& session,Packet& packet)
{
//查询背包物品函数
UInt32 RetCode = 0;
DataBuffer serbuffer(1024);
char szSql[1024];
Connection con,conSub;
DBOperate dbo,dboSub;
Int16 iRet = 0;
UInt32 roleID = packet.RoleID;
List<ArchvShopItem> shopItem;
ArchvShopItem item1;
//序列化类
Serializer s(packet.GetBuffer());
if( s.GetErrorCode()!= 0 )
{
RetCode = ERR_SYSTEM_SERERROR;
LOG(LOG_ERROR,__FILE__,__LINE__,"serial error" );
goto EndOf_Process;
}
//获取DB连接
con = _cp->GetConnection();
dbo.SetHandle(con.GetHandle());
conSub=_cp->GetConnection();
dboSub.SetHandle(conSub.GetHandle());
DEBUG_PRINTF( "C_S ProcessShopItem sucess!!!!!!!!\n" );
//查询全部的
sprintf( szSql, "select ItemID,Category,NowPrice from ShopItem;");
iRet=dbo.QuerySQL(szSql);
if(iRet==0)
{
while(dbo.HasRowData())
{
item1.ItemID=dbo.GetIntField(0);
item1.Category=dbo.GetIntField(1);
item1.NowPrice=dbo.GetIntField(2);
if(item1.Category==7)
{
sprintf( szSql, "select leftNum from specialItem where ItemID=%d;",item1.ItemID);
iRet=dboSub.QuerySQL(szSql);
if(iRet==0)
{
item1.Num=dboSub.GetIntField(0);
}
}
shopItem.push_back(item1);
dbo.NextRow();
}
}
else
{
RetCode = ERR_SYSTEM_DBNORECORD;
LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL error[%s],szSql[%s] ", mysql_error(con.GetHandle()), szSql);
goto EndOf_Process;
}
//LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL data what to get not found,szSql[%d %d] " , PackNum,GetRoleCellNum(roleID));
EndOf_Process:
//组应答数据
Packet p(&serbuffer);
s.SetDataBuffer(&serbuffer);
serbuffer.Reset();
p.CopyHeader(packet);
p.Direction = DIRECT_C_S_RESP;
p.PackHeader();
s<<RetCode;
if( 0 == RetCode )
{//RetCode 为0 才会返回包体剩下内容
s<<shopItem;
}
p.UpdatePacketLength();
//发送应答数据
if( session.Send(&serbuffer) )
{
LOG(LOG_ERROR,__FILE__,__LINE__,"session.Send error ");
}
DEBUG_PRINTF( "ack pkg=======, \n" );
DEBUG_SHOWHEX( serbuffer.GetReadPtr(), serbuffer.GetDataSize(), 0, __FILE__, __LINE__ );
return;
}
示例11: ProcessBuyItem
void ShopSvc::ProcessBuyItem(Session& session,Packet& packet)
{
UInt32 RetCode = 0;
DataBuffer serbuffer(1024);
char szSql[1024];
Connection con;
DBOperate dbo;
Int16 iRet = 0;
UInt16 num=0;
UInt16 cellType=0;
UInt16 itemType=0;
UInt16 IsStack=0;
UInt16 Bind=0;
UInt32 Dur=0;
UInt32 price=0;
UInt32 EntityID=0;
UInt32 CellIndex=0;
UInt32 leftnum=0;
List<UInt16> cell;
List<ItemCell> lic;
ItemCell lic1;
List<UInt16>::iterator itor;
UInt32 roleID = packet.RoleID;
UInt32 itemID=0;
UInt16 count=0;
UInt32 numcell=1;
UInt16 Rarity=0;
UInt32 BuyType=0;
Byte type=0;
Byte flag=0;
//序列化类
Serializer s(packet.GetBuffer());
s>>type>>itemID>>num;
LOG(LOG_ERROR,__FILE__,__LINE__,"type[%d]--itemid[%d]--num[%d]",type,itemID,num);
//得到物品ID和数量
if( s.GetErrorCode()!= 0 )
{
RetCode = ERR_SYSTEM_SERERROR;
LOG(LOG_ERROR,__FILE__,__LINE__,"serial error" );
goto EndOf_Process;
}
//获取DB连接
con = _cp->GetConnection();
dbo.SetHandle(con.GetHandle());
//验证价格
sprintf( szSql, "select NowPrice from ShopItem where ItemID=%d and Category=%d;",itemID,type );
iRet = dbo.QuerySQL(szSql);
if(iRet==0)
{
price=dbo.GetIntField(0);
}
else
{
RetCode = ERR_SYSTEM_DBNORECORD;
LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL data not found or erro,szSql[%s] " , szSql);
goto EndOf_Process;
}
if(type==6)
{
//表示礼券购买
iRet=DropGift(roleID,price*num);
if(iRet==1)
{
//没有这么多数量的礼券
RetCode = NO_MUCH_GIFT;
LOG(LOG_ERROR,__FILE__,__LINE__,"Not so many Gift!! ");
goto EndOf_Process;
}
else if(iRet==-1)
{
//错误
RetCode = ERR_APP_DATA;
LOG(LOG_ERROR,__FILE__,__LINE__,"there are some erro!! ");
goto EndOf_Process;
}
}
else if(type==7)
{
//表示限量抢购
sprintf( szSql, "select ItemID,leftNum from specialItem where ItemID=%d;",itemID);
iRet = dbo.QuerySQL(szSql);
if(iRet!=0)
{
RetCode = ERR_SYSTEM_DBNORECORD;
LOG(LOG_ERROR,__FILE__,__LINE__,"QuerySQL data not found ,szSql[%s] " , szSql);
goto EndOf_Process;
}
else
{
leftnum=dbo.GetIntField(1);
//.........这里部分代码省略.........
示例12: ProcessPKReq
void PKSvc::ProcessPKReq(Session& session,Packet& packet)
{
UInt32 RetCode = 0;
DataBuffer serbuffer(1024);
char szSql[1024];
Connection con;
DBOperate dbo;
int iRet = 0;
PKBriefList pkList;
UInt32 roleID = packet.RoleID;
Byte creatureFlag;
UInt32 creatureID;
ArchvRolePKInfo pkInfo;
List<ArchvRolePKInfo> lrpki;
UInt32 pkID = 0;
ArchvCreatureStatus cs;
List<ArchvCreatureStatus> lcs;
list<TeamRole> roleIDitor;
list<TeamRole>::iterator itor;
list<UInt32> roleID1,roleID2;
list<UInt32>::iterator it;
Team team;
ArchvPosition posMid;
ArchvPosition posPKOrigin;
int iTmp = 0;
list<SenceMonster> monsterrs;
list<SenceMonster>::iterator itor1;
Byte Status=0;
RolePtr srcRole = _mainSvc->GetCoreData()->ProcessGetRolePtr(roleID);
RolePtr desRole;
Monster desMonster;
ArchvPosition pos1;
ArchvPosition pos2;
int pp=-1;
int j=1;
//序列化类
Serializer s(packet.GetBuffer());
s>>creatureFlag>>creatureID;
if( s.GetErrorCode()!= 0 )
{
RetCode = ERR_SYSTEM_SERERROR;
LOG(LOG_ERROR,__FILE__,__LINE__,"serial error" );
goto EndOf_Process;
}
//获取DB连接
/* con = _cp->GetConnection();
dbo.SetHandle(con.GetHandle());
*/
LOG(LOG_ERROR,__FILE__,__LINE__,"creatureFlag[%d],creatureID[%d] ", creatureFlag, creatureID );
//生物标志校验
if( creatureFlag <=0 || creatureFlag > 4 )
{
RetCode = ERR_APP_DATA;
LOG(LOG_ERROR,__FILE__,__LINE__,"creatureFlag error!! creatureFlag[%d] ", creatureFlag );
goto EndOf_Process;
}
//会发生角色无法PK得状态,可以使用定时放开PK限制
pkID=_mainSvc->GetCoreData()->IfRoleInPK(roleID);
if(pkID!=0)
{
LOG(LOG_DEBUG,__FILE__,__LINE__,"111111111111 pkID=%d roleID=%d", pkID, roleID );
RetCode = 2011;//角色的上场战斗没有结束
LOG(LOG_ERROR,__FILE__,__LINE__,"role status error!! role is in the pk RoleId=%d", roleID );
goto EndOf_Process;
}
if( 0 == srcRole->ID() )
{
RetCode = ERR_APP_ROLENOTEXISTS;
LOG(LOG_ERROR,__FILE__,__LINE__,"ProcessGetRole error,roleID[%d]", roleID );
goto EndOf_Process;
}
if(srcRole->TeamFlag()==0)
{
//单独作战,跳过
}
else
{
if(srcRole->TeamFlag()!=2)
{
//失败,不是队长
RetCode = ERR_APP_ROLENOTEXISTS;
LOG(LOG_ERROR,__FILE__,__LINE__,"ProcessGetRole error,roleID[%d]", roleID );
goto EndOf_Process;
}
//.........这里部分代码省略.........
示例13: ProcessTeleportByRune
//@brief [MsgType:0203] (使用飞行符文)瞬移
void MapSvc::ProcessTeleportByRune(Session& session,Packet& packet)
{
UInt32 RetCode = 0;
DataBuffer serbuffer(1024);
Connection con;
DBOperate dbo;
int iRet = 0;
UInt32 roleID = packet.RoleID;
UInt32 mapID = 0;
UInt16 x;
UInt16 y;
ArchvRoute art;
ArchvPosition pos;
int isToCurrMap = 0; //是否本地图内瞬移 0否 1 是
//序列化类
Serializer s(packet.GetBuffer());
s>>mapID>>x>>y;
if( s.GetErrorCode()!= 0 )
{
LOG(LOG_ERROR,__FILE__,__LINE__,"serial error" );
return;
}
DEBUG_PRINTF1( " ProcessTeleportByRune roleID[%d]\n", roleID );
//获取角色信息
RolePtr pRole = _mainSvc->GetCoreData()->ProcessGetRolePtr(roleID);
if(pRole->ID()==0)
{
RetCode = ERR_APP_DATA;
LOG(LOG_ERROR,__FILE__,__LINE__,"data error!! role not found,roleID[%d]", roleID);
goto EndOf_Process;
}
//组队状态,不能瞬移
if(pRole->TeamFlag())
{
RetCode = ERR_APP_DATA;
LOG(LOG_ERROR,__FILE__,__LINE__,"status error!! role in team, roleID[%d]", roleID);
goto EndOf_Process;
}
//是否在本地图瞬移
if( pRole->MapID() == mapID )
{//本地图内瞬移
isToCurrMap = 1;
//移动
pos.X = x;
pos.Y = y;
art.listPos.push_back(pos);
iRet = _mainSvc->GetCoreData()->ProcessRoleMove( roleID, art);
if(iRet)
{
RetCode = ERR_APP_OP;
LOG(LOG_ERROR,__FILE__,__LINE__,"ProcessRoleMove error" );
goto EndOf_Process;
}
}
else
{//跨地图瞬移
pRole->MapID(mapID);
isToCurrMap = 0;
//业务处理
iRet = _mainSvc->GetCoreData()->ProcessRoleEnterMap( roleID, mapID, x, y);
if( iRet == -1)
{
RetCode = ERR_APP_OP;
LOG(LOG_ERROR,__FILE__,__LINE__,"GetCoreData()->ProcessRoleEnterMap error");
goto EndOf_Process;
}
if(iRet == 1)
{
RetCode = ERR_APP_ALREADYINMAP;
LOG(LOG_ERROR,__FILE__,__LINE__,"GetCoreData()->ProcessRoleEnterMap error");
goto EndOf_Process;
}
}
EndOf_Process:
//组应答数据
Packet p(&serbuffer);
s.SetDataBuffer(&serbuffer);
serbuffer.Reset();
p.CopyHeader(packet);
p.Direction = DIRECT_C_S_RESP;
p.PackHeader();
s<<RetCode;
if( 0 == RetCode )
{//RetCode 为0 才会返回包体剩下内容
// s<<Time;
}
//.........这里部分代码省略.........
示例14: ProcessEnterMap
//@brief [MsgType:0201]进入场景
void MapSvc::ProcessEnterMap(Session& session,Packet& packet)
{
UInt32 RetCode = 0;
DataBuffer serbuffer(1024);
char szSql[1024];
Connection con;
DBOperate dbo;
int iRet = 0;
UInt32 roleID = packet.RoleID;
UInt32 mapID = 0;
UInt16 x;
UInt16 y;
UInt32 Time = 0;
//序列化类
Serializer s(packet.GetBuffer());
s>>mapID>>x>>y;
if( s.GetErrorCode()!= 0 )
{
RetCode = ERR_SYSTEM_SERERROR;
LOG(LOG_ERROR,__FILE__,__LINE__,"serial error" );
goto EndOf_Process;
}
//DEBUG_PRINTF4( " ProcessEnterMap--roleID[%d],MapID[%d],.X[%d],.Y[%d] \n", roleID, mapID, x, y );
//业务处理
iRet = _mainSvc->GetCoreData()->ProcessRoleEnterMap( roleID, mapID, x, y);
if( iRet == -1)
{
RetCode = ERR_APP_OP;
LOG(LOG_ERROR,__FILE__,__LINE__,"GetCoreData()->ProcessRoleEnterMap error");
goto EndOf_Process;
}
if(iRet == 1)
{
RetCode = ERR_APP_ALREADYINMAP;
LOG(LOG_ERROR,__FILE__,__LINE__,"GetCoreData()->ProcessRoleEnterMap error");
goto EndOf_Process;
}
EndOf_Process:
//应答包时间字段
Time = time(NULL);
//组应答数据
Packet p(&serbuffer);
s.SetDataBuffer(&serbuffer);
serbuffer.Reset();
p.CopyHeader(packet);
p.Direction = DIRECT_C_S_RESP;
p.PackHeader();
s<<RetCode;
if( 0 == RetCode )
{//RetCode 为0 才会返回包体剩下内容
s<<Time;
}
p.UpdatePacketLength();
//发送应答数据
if( session.Send(&serbuffer) )
{
LOG(LOG_ERROR, __FILE__, __LINE__, "session->Send() error,errno[%d],strerror[%s]", errno, strerror(errno) );
}
//DEBUG_PRINTF1( "C_S ack pkg ----- MsgType[%d] \n", packet.MsgType );
// DEBUG_SHOWHEX( serbuffer.GetReadPtr(), serbuffer.GetDataSize(), 0, __FILE__, __LINE__ );
if(RetCode==0)
{
RolePtr pRole=_mainSvc->GetCoreData()->ProcessGetRolePtr(roleID);
//[MsgType:0202](单播)进入场景,场景所有其他角色的列表
_mainSvc->GetCoreData()->NotifyAllRoleInfo(roleID);
//s-c205进入地图
//NotifyEnterMap(roleID,mapID,x,y);
if(pRole->TeamFlag()==1)
{
NotifyTeamLeader(roleID,pRole->LeaderRoleID());
}
LOG(LOG_DEBUG,__FILE__,__LINE__,"ProcessEnterMap OK!!roleID[%d],mapID[%d], EnterMapNum[%d]", pRole->ID(), mapID, pRole->EnterMapNum());
//角色登陆进地图的未完成的挂机数据
_mainSvc->GetOffLineUpdateSvc()->OnRoleLoginNotify(roleID);
if(pRole->EnterMapNum() == 1)
{
//角色登录的符文使用数据
List<RoleRune> lic;
pRole->PopulateRoleRuneList(lic);
if(lic.size()>0){
NotifyActRuneListOnLogin(roleID, lic);
}
}
//.........这里部分代码省略.........