Skip to content

Commit 102120f

Browse files
committed
up
1 parent 104ae20 commit 102120f

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

kbe/src/server/cellapp/cellapp.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,8 @@ void Cellapp::reqTeleportOtherAck(Mercury::Channel* pChannel, MemoryStream& s)
14951495
//-------------------------------------------------------------------------------------
14961496
void Cellapp::reqTeleportOther(Mercury::Channel* pChannel, MemoryStream& s)
14971497
{
1498+
size_t rpos = s.rpos();
1499+
14981500
ENTITY_ID nearbyMBRefID = 0, teleportEntityID = 0;
14991501
Position3D pos;
15001502
Direction3D dir;
@@ -1505,10 +1507,22 @@ void Cellapp::reqTeleportOther(Mercury::Channel* pChannel, MemoryStream& s)
15051507
s >> entityType;
15061508
s >> pos.x >> pos.y >> pos.z;
15071509
s >> dir.dir.x >> dir.dir.y >> dir.dir.z;
1510+
1511+
bool success = false;
15081512

15091513
Space* space = Spaces::findSpace(spaceID);
15101514
if(space == NULL)
15111515
{
1516+
s.rpos(rpos);
1517+
1518+
Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
1519+
(*pBundle).newMessage(CellappInterface::reqTeleportOtherCB);
1520+
(*pBundle) << teleportEntityID;
1521+
(*pBundle) << success;
1522+
(*pBundle).append(&s);
1523+
pBundle->send(this->getNetworkInterface(), pChannel);
1524+
Mercury::Bundle::ObjPool().reclaimObject(pBundle);
1525+
15121526
ERROR_MSG(boost::format("Cellapp::reqTeleportOther: not found space(%1%), reqTeleportEntity(%2%)!\n") % spaceID % teleportEntityID);
15131527
s.opfini();
15141528
return;
@@ -1518,6 +1532,16 @@ void Cellapp::reqTeleportOther(Mercury::Channel* pChannel, MemoryStream& s)
15181532
Entity* e = createEntityCommon(EntityDef::findScriptModule(entityType)->getName(), NULL, false, teleportEntityID, false);
15191533
if(e == NULL)
15201534
{
1535+
s.rpos(rpos);
1536+
1537+
Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
1538+
(*pBundle).newMessage(CellappInterface::reqTeleportOtherCB);
1539+
(*pBundle) << teleportEntityID;
1540+
(*pBundle) << success;
1541+
(*pBundle).append(&s);
1542+
pBundle->send(this->getNetworkInterface(), pChannel);
1543+
Mercury::Bundle::ObjPool().reclaimObject(pBundle);
1544+
15211545
ERROR_MSG(boost::format("Cellapp::reqTeleportOther: create reqTeleportEntity(%1%) is error!\n") % teleportEntityID);
15221546
s.opfini();
15231547
return;
@@ -1536,6 +1560,61 @@ void Cellapp::reqTeleportOther(Mercury::Channel* pChannel, MemoryStream& s)
15361560

15371561
Entity* nearbyMBRef = Cellapp::getSingleton().findEntity(nearbyMBRefID);
15381562
e->onTeleportSuccess(nearbyMBRef, lastSpaceID);
1563+
1564+
success = true;
1565+
1566+
{
1567+
Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
1568+
(*pBundle).newMessage(CellappInterface::reqTeleportOtherCB);
1569+
(*pBundle) << teleportEntityID;
1570+
(*pBundle) << success;
1571+
pBundle->send(this->getNetworkInterface(), pChannel);
1572+
Mercury::Bundle::ObjPool().reclaimObject(pBundle);
1573+
}
1574+
}
1575+
1576+
//-------------------------------------------------------------------------------------
1577+
void Cellapp::reqTeleportOtherCB(Mercury::Channel* pChannel, MemoryStream& s)
1578+
{
1579+
ENTITY_ID nearbyMBRefID = 0, teleportEntityID = 0;
1580+
bool success;
1581+
1582+
s >> teleportEntityID >> success;
1583+
1584+
Entity* entity = Cellapp::getSingleton().findEntity(teleportEntityID);
1585+
1586+
if(entity == NULL)
1587+
{
1588+
if(!success)
1589+
{
1590+
ERROR_MSG(boost::format("Cellapp::reqTeleportOtherCB: not found reqTeleportEntity(%1%), lose entity!\n") % teleportEntityID);
1591+
s.opfini();
1592+
return;
1593+
}
1594+
1595+
s.opfini();
1596+
}
1597+
1598+
// 传送成功, 我们销毁这个entity。
1599+
if(success)
1600+
{
1601+
destroyEntity(teleportEntityID, false);
1602+
return;
1603+
}
1604+
1605+
// 传送失败了, 我们需要重恢复entity
1606+
Position3D pos;
1607+
Direction3D dir;
1608+
ENTITY_SCRIPT_UID entityType;
1609+
SPACE_ID spaceID = 0, lastSpaceID = 0;
1610+
1611+
s >> teleportEntityID >> nearbyMBRefID >> lastSpaceID >> spaceID;
1612+
s >> entityType;
1613+
s >> pos.x >> pos.y >> pos.z;
1614+
s >> dir.dir.x >> dir.dir.y >> dir.dir.z;
1615+
1616+
entity->changeToReal(0, s);
1617+
entity->onTeleportFailure();
15391618
}
15401619

15411620
//-------------------------------------------------------------------------------------

kbe/src/server/cellapp/cellapp.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ class Cellapp: public EntityApp<Entity>,
231231
void reqTeleportOtherValidation(Mercury::Channel* pChannel, MemoryStream& s);
232232
void reqTeleportOtherAck(Mercury::Channel* pChannel, MemoryStream& s);
233233
void reqTeleportOther(Mercury::Channel* pChannel, MemoryStream& s);
234+
void reqTeleportOtherCB(Mercury::Channel* pChannel, MemoryStream& s);
234235

235236
/**
236237
获取和设置ghost管理器

kbe/src/server/cellapp/cellapp_interface.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ NETWORK_INTERFACE_DECLARE_BEGIN(CellappInterface)
160160
// 请求teleport到当前cellapp上
161161
CELLAPP_MESSAGE_DECLARE_STREAM(reqTeleportOther, MERCURY_VARIABLE_MESSAGE)
162162

163+
// entity传送到目的cellapp上的space之后, 返回给之前cellapp的回调
164+
CELLAPP_MESSAGE_DECLARE_STREAM(reqTeleportOtherCB, MERCURY_VARIABLE_MESSAGE)
165+
163166
// real请求更新属性到ghost
164167
CELLAPP_MESSAGE_DECLARE_STREAM(onUpdateGhostPropertys, MERCURY_VARIABLE_MESSAGE)
165168

kbe/src/server/cellapp/entity.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,8 +2491,10 @@ void Entity::onReqTeleportOtherAck(Mercury::Channel* pChannel, ENTITY_ID nearbyM
24912491
pBundle->send(Cellapp::getSingleton().getNetworkInterface(), pChannel);
24922492
Mercury::Bundle::ObjPool().reclaimObject(pBundle);
24932493

2494-
// 销毁这个entity
2495-
Cellapp::getSingleton().destroyEntity(getID(), false);
2494+
// 暂时不销毁这个entity, 等那边成功创建之后再回来销毁
2495+
// 此期间的消息可以通过ghost转发给real
2496+
// 如果未能正确传输过去则可以从当前cell继续恢复entity.
2497+
// Cellapp::getSingleton().destroyEntity(getID(), false);
24962498
}
24972499

24982500
//-------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)