lcpclist.cpp
来自「天之炼狱1服务器端源文件游戏服务端不完整」· C++ 代码 · 共 209 行
CPP
209 行
//----------------------------------------------------------------------// // Filename : LCPCList.cpp // Written By : Reiot// Description :// //----------------------------------------------------------------------// include files#include "LCPCList.h"#include "PCSlayerInfo.h"#include "PCVampireInfo.h"#include "PCOustersInfo.h"//----------------------------------------------------------------------// constructor//----------------------------------------------------------------------LCPCList::LCPCList () throw (){ for ( uint i = 0 ; i < SLOT_MAX ; i ++ ) m_pPCInfos[i] = NULL;}//----------------------------------------------------------------------// destructor//----------------------------------------------------------------------LCPCList::~LCPCList () throw (){ // heap 俊 积己等 PC Type 函荐甸阑 昏力秦具 茄促. for ( uint i = 0 ; i < SLOT_MAX ; i ++ ) { SAFE_DELETE(m_pPCInfos[i]); }}//----------------------------------------------------------------------// 涝仿胶飘覆(滚欺)栏肺何磐 单捞鸥甫 佬绢辑 菩哦阑 檬扁拳茄促.//----------------------------------------------------------------------void LCPCList::read ( SocketInputStream & iStream ) throw ( ProtocolException , Error ){ __BEGIN_TRY //-------------------------------------------------- // PC 鸥涝 沥焊甫 罐酒柯促. // // *OPTMIZATION* // // 唱吝俊绰 捞 沥焊甫 1 官捞飘俊 持绢辑 厚飘 楷魂阑 窍档废 茄促. // //-------------------------------------------------- char pcTypes[SLOT_MAX]; for ( uint i = 0 ; i < SLOT_MAX ; i ++ ) iStream.read(pcTypes[i]); //-------------------------------------------------- // PC 沥焊 夯眉甫 佬绰促. //-------------------------------------------------- for ( uint j = 0 ; j < SLOT_MAX ; j ++ ) { switch ( pcTypes[j] ) { case 'S' : { PCSlayerInfo * pPCSlayerInfo = new PCSlayerInfo(); pPCSlayerInfo->read( iStream ); m_pPCInfos[ pPCSlayerInfo->getSlot() ] = pPCSlayerInfo; } break; case 'V' : { PCVampireInfo * pPCVampireInfo = new PCVampireInfo(); pPCVampireInfo->read( iStream ); m_pPCInfos[ pPCVampireInfo->getSlot() ] = pPCVampireInfo; } break; case 'O' : { PCOustersInfo * pPCOustersInfo = new PCOustersInfo(); pPCOustersInfo->read( iStream ); m_pPCInfos[ pPCOustersInfo->getSlot() ] = pPCOustersInfo; } break; case '0' : break; default : throw InvalidProtocolException("invalid pc type"); } } __END_CATCH} //////////////////////////////////////////////////////////////////////// 免仿胶飘覆(滚欺)栏肺 菩哦狼 官捞呈府 捞固瘤甫 焊辰促.//////////////////////////////////////////////////////////////////////void LCPCList::write ( SocketOutputStream & oStream ) const throw ( ProtocolException , Error ){ __BEGIN_TRY //-------------------------------------------------- // 老窜 PC 鸥涝阑 敬促. // // 唱吝俊绰 捞 沥焊甫 1 官捞飘俊 持绢辑 厚飘 楷魂阑 窍档废 茄促. // // ex> // S0V : Slayer-EMPTY-VAMPIRE // 00S : EMPTY-EMPTY-SLAYER // //-------------------------------------------------- for ( uint i = 0 ; i < SLOT_MAX ; i ++ ) { if ( m_pPCInfos[i] ) { // m_pPCInfos[i] != NULL if ( m_pPCInfos[i]->getPCType() == PC_SLAYER ) { oStream.write( 'S' ); } else if ( m_pPCInfos[i]->getPCType() == PC_VAMPIRE ) { // case of PC_VAMPIRE oStream.write( 'V' ); } else { oStream.write( 'O' ); } } else { // m_pPCInfos[i] == NULL oStream.write( '0' ); } } //-------------------------------------------------- // 弊促澜 PCType 按眉 夯眉甫 敬促. //-------------------------------------------------- for ( uint j = 0 ; j < SLOT_MAX ; j ++ ) { if ( m_pPCInfos[j] != NULL ) { m_pPCInfos[j]->write( oStream ); } } __END_CATCH}//////////////////////////////////////////////////////////////////////// execute packet's handler//////////////////////////////////////////////////////////////////////void LCPCList::execute ( Player * pPlayer ) throw ( ProtocolException , Error ){ __BEGIN_TRY LCPCListHandler::execute( this , pPlayer ); __END_CATCH}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////PacketSize_t LCPCList::getPacketSize () const throw (){ PacketSize_t packetSize = 0; for ( uint i = 0 ; i < SLOT_MAX ; i ++ ) { if ( m_pPCInfos[i] ) { // m_pPCInfos[i] != NULL packetSize += m_pPCInfos[i]->getSize(); } } return packetSize;}////////////////////////////////////////////////////////////////////////// get packet's debug string////////////////////////////////////////////////////////////////////////string LCPCList::toString () const throw (){ __BEGIN_TRY StringStream msg; msg << "LCPCList(\n"; for ( uint i = 0 ; i < SLOT_MAX ; i ++ ) if ( m_pPCInfos[i] != NULL ) msg << m_pPCInfos[i]->toString() << "\n"; else msg << "EMPTY SLOT\n"; msg << ")"; return msg.toString(); __END_CATCH}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?