Working on stuck behavior handler, fix for world crash when you can't connect to a login server.

This commit is contained in:
KimLS 2018-11-09 18:30:05 -08:00
parent 8f0051db8d
commit 81b409a2e4
4 changed files with 80 additions and 17 deletions

View File

@ -306,6 +306,20 @@ void LoginServer::SendStatus() {
delete pack;
}
void LoginServer::SendPacket(ServerPacket *pack)
{
if (IsLegacy) {
if (legacy_client) {
legacy_client->SendPacket(pack);
}
}
else {
if (client) {
client->SendPacket(pack);
}
}
}
void LoginServer::SendAccountUpdate(ServerPacket* pack) {
ServerLSAccountUpdate_Struct* s = (ServerLSAccountUpdate_Struct *)pack->pBuffer;
if (CanUpdate()) {
@ -315,3 +329,19 @@ void LoginServer::SendAccountUpdate(ServerPacket* pack) {
SendPacket(pack);
}
}
bool LoginServer::Connected()
{
if (IsLegacy) {
if (legacy_client) {
return legacy_client->Connected();
}
}
else {
if (client) {
return client->Connected();
}
}
return false;
}

View File

@ -40,9 +40,9 @@ public:
void SendNewInfo();
void SendStatus();
void SendPacket(ServerPacket* pack) { if (IsLegacy) legacy_client->SendPacket(pack); else client->SendPacket(pack); }
void SendPacket(ServerPacket* pack);
void SendAccountUpdate(ServerPacket* pack);
bool Connected() { return IsLegacy ? legacy_client->Connected() : client->Connected(); }
bool Connected();
bool MiniLogin() { return minilogin; }
bool CanUpdate() { return CanAccountUpdate; }

View File

@ -735,7 +735,7 @@ void MobMovementManager::UpdatePathGround(Mob * who, float x, float y, float z,
auto &ent = (*eiter);
if (route.size() == 0) {
//handle stuck behavior
HandleStuckBehavior(who, x, y, z, mode);
return;
}
@ -782,13 +782,23 @@ void MobMovementManager::UpdatePathGround(Mob * who, float x, float y, float z,
}
}
PushStopMoving(ent.second);
if (stuck) {
//handle stuck
HandleStuckBehavior(who, x, y, z, mode);
}
}
void MobMovementManager::UpdatePathUnderwater(Mob * who, float x, float y, float z, MobMovementMode mode)
void MobMovementManager::UpdatePathUnderwater(Mob *who, float x, float y, float z, MobMovementMode mode)
{
auto eiter = _impl->Entries.find(who);
auto &ent = (*eiter);
if (zone->watermap->InLiquid(who->GetPosition()) && zone->watermap->InLiquid(glm::vec3(x, y, z)) && zone->zonemap->CheckLoS(who->GetPosition(), glm::vec3(x, y, z))) {
PushSwimTo(ent.second, x, y, z, mode);
PushStopMoving(ent.second);
return;
}
auto partial = false;
auto stuck = false;
auto route = zone->pathing->FindRoute(
@ -796,13 +806,10 @@ void MobMovementManager::UpdatePathUnderwater(Mob * who, float x, float y, float
glm::vec3(x, y, z),
partial,
stuck,
PathingWater | PathingLava | PathingVWater | PathingPortal | PathingPrefer);
auto eiter = _impl->Entries.find(who);
auto &ent = (*eiter);
PathingNotDisabled ^ PathingZoneLine);
if (route.size() == 0) {
//handle stuck behavior
HandleStuckBehavior(who, x, y, z, mode);
return;
}
@ -812,6 +819,30 @@ void MobMovementManager::UpdatePathUnderwater(Mob * who, float x, float y, float
glm::vec3 previous_pos(who->GetX(), who->GetY(), who->GetZ());
bool first_node = true;
while (iter != route.end()) {
auto &current_node = (*iter);
if (!zone->watermap->InLiquid(current_node.pos)) {
stuck = true;
while (iter != route.end()) {
iter = route.erase(iter);
}
break;
}
else {
iter++;
}
}
if (route.size() == 0) {
HandleStuckBehavior(who, x, y, z, mode);
return;
}
iter = route.begin();
while (iter != route.end()) {
auto &current_node = (*iter);
@ -840,17 +871,14 @@ void MobMovementManager::UpdatePathUnderwater(Mob * who, float x, float y, float
CalculateHeadingAngleBetweenPositions(current_node.pos.x, current_node.pos.y, next_node.pos.x, next_node.pos.y));
}
else {
if (zone->watermap->InLiquid(previous_pos)) {
PushSwimTo(ent.second, next_node.pos.x, next_node.pos.y, next_node.pos.z, mode);
}
else {
PushMoveTo(ent.second, next_node.pos.x, next_node.pos.y, next_node.pos.z, mode);
}
PushSwimTo(ent.second, next_node.pos.x, next_node.pos.y, next_node.pos.z, mode);
}
}
PushStopMoving(ent.second);
if (stuck) {
//handle stuck
HandleStuckBehavior(who, x, y, z, mode);
}
}
@ -904,3 +932,7 @@ void MobMovementManager::PushStopMoving(MobMovementEntry &ent)
{
ent.Commands.push_back(std::unique_ptr<IMovementCommand>(new StopMovingCommand()));
}
void MobMovementManager::HandleStuckBehavior(Mob * who, float x, float y, float z, MobMovementMode mode)
{
}

View File

@ -66,6 +66,7 @@ private:
void PushSwimTo(MobMovementEntry &ent, float x, float y, float z, MobMovementMode mode);
void PushRotateTo(MobMovementEntry &ent, Mob *who, float to, MobMovementMode mode);
void PushStopMoving(MobMovementEntry &ent);
void HandleStuckBehavior(Mob *who, float x, float y, float z, MobMovementMode mode);
struct Implementation;
std::unique_ptr<Implementation> _impl;