Skip to content

Commit

Permalink
Merge pull request #7 from DarkflameUniverse/main
Browse files Browse the repository at this point in the history
merge from upstream
  • Loading branch information
codeshaunted authored Dec 20, 2021
2 parents 712c4a7 + 3090890 commit 61d5186
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 22 deletions.
4 changes: 3 additions & 1 deletion dGame/dComponents/RacingControlComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ void RacingControlComponent::OnRequestDie(Entity *player) {
return;
}

racingPlayer.smashedTimes++;
if (!racingPlayer.noSmashOnReload) {
racingPlayer.smashedTimes++;
}

// Reset player to last checkpoint
GameMessages::SendRacingSetPlayerResetInfo(
Expand Down
33 changes: 25 additions & 8 deletions dMasterServer/InstanceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Instance * InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, L
maxPlayers = GetHardCap(mapID);
}

instance = new Instance(mExternalIP, ++m_LastPort, mapID, ++m_LastInstanceID, cloneID, softCap, maxPlayers);
uint32_t port = GetFreePort();
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, softCap, maxPlayers);

//Start the actual process:
#ifdef _WIN32
Expand All @@ -59,7 +60,7 @@ Instance * InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, L

cmd.append(std::to_string(mapID));
cmd.append(" -port ");
cmd.append(std::to_string(m_LastPort));
cmd.append(std::to_string(port));
cmd.append(" -instance ");
cmd.append(std::to_string(m_LastInstanceID));
cmd.append(" -maxclients ");
Expand All @@ -74,8 +75,6 @@ Instance * InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, L

system(cmd.c_str());

m_LastPort++; //Increment it again because the next port is for World<->Server comm.
m_LastPort++; //Increment it again because the next port is for World<->Chat comm.
m_Instances.push_back(instance);

if (instance) {
Expand All @@ -97,6 +96,25 @@ bool InstanceManager::IsPortInUse(uint32_t port) {
return false;
}

uint32_t InstanceManager::GetFreePort() {
uint32_t port = m_LastPort;
std::vector<uint32_t> usedPorts;
for (Instance* i : m_Instances) {
usedPorts.push_back(i->GetPort());
}

std::sort(usedPorts.begin(), usedPorts.end());

int portIdx = 0;
while (portIdx < usedPorts.size() && port == usedPorts[portIdx]) {
//increment by 3 since each instance uses 3 ports (instance, world-server, world-chat)
port += 3;
portIdx++;
}

return port;
}

void InstanceManager::AddPlayer(SystemAddress systemAddr, LWOMAPID mapID, LWOINSTANCEID instanceID) {
Instance* inst = FindInstance(mapID, instanceID);
if (inst) {
Expand Down Expand Up @@ -291,7 +309,8 @@ Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID clon

int maxPlayers = 999;

instance = new Instance(mExternalIP, ++m_LastPort, mapID, ++m_LastInstanceID, cloneID, maxPlayers, maxPlayers, true, password);
uint32_t port = GetFreePort();
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, maxPlayers, maxPlayers, true, password);

//Start the actual process:
std::string cmd = "start ./WorldServer.exe -zone ";
Expand All @@ -302,7 +321,7 @@ Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID clon

cmd.append(std::to_string(mapID));
cmd.append(" -port ");
cmd.append(std::to_string(m_LastPort));
cmd.append(std::to_string(port));
cmd.append(" -instance ");
cmd.append(std::to_string(m_LastInstanceID));
cmd.append(" -maxclients ");
Expand All @@ -317,8 +336,6 @@ Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID clon

system(cmd.c_str());

m_LastPort++; //Increment it again because the next port is for World<->Server comm.
m_LastPort++; //Increment it again because the next port is for World<->Chat comm.
m_Instances.push_back(instance);

if (instance) return instance;
Expand Down
1 change: 1 addition & 0 deletions dMasterServer/InstanceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class InstanceManager {

Instance* GetInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneID); //Creates an instance if none found
bool IsPortInUse(uint32_t port);
uint32_t GetFreePort();

void AddPlayer(SystemAddress systemAddr, LWOMAPID mapID, LWOINSTANCEID instanceID);
void RemovePlayer(SystemAddress systemAddr, LWOMAPID mapID, LWOINSTANCEID instanceID);
Expand Down
6 changes: 3 additions & 3 deletions dScripts/BaseRandomServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void BaseRandomServer::SetSpawnerNetwork(Entity* self, const std::string& spawne

if (spawnerName == "Named_Enemies")
{
//spawner->Reset();
spawner->SoftReset();
}

spawner->Activate();
Expand Down Expand Up @@ -173,12 +173,12 @@ void BaseRandomServer::NamedEnemyDeath(Entity* self, Spawner* spawner)

void BaseRandomServer::SpawnersUp(Entity* self)
{

}

void BaseRandomServer::SpawnersDown(Entity* self)
{

}

void BaseRandomServer::BaseOnTimerDone(Entity* self, const std::string& timerName)
Expand Down
2 changes: 1 addition & 1 deletion dScripts/BaseRandomServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BaseRandomServer
void SpawnersUp(Entity* self);
void SpawnersDown(Entity* self);
void BaseOnTimerDone(Entity* self, const std::string& timerName);

void NotifySpawnerOfDeath(Entity* self, Spawner* spawner);
void NamedEnemyDeath(Entity* self, Spawner* spawner);

Expand Down
11 changes: 3 additions & 8 deletions dScripts/BuccaneerValiantShip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
#include "dLogger.h"

void BuccaneerValiantShip::OnStartup(Entity* self) {
const auto skill = 982;
const auto behavior = 20577;
const auto skillCastTimer = 1.0F;

self->AddCallbackTimer(skillCastTimer, [&]() {
self->AddCallbackTimer(1.0F, [self]() {
auto* skillComponent = self->GetComponent<SkillComponent>();
auto* owner = self->GetOwner();

if (skillComponent != nullptr && owner != nullptr) {
skillComponent->CalculateBehavior(skill, behavior, LWOOBJID_EMPTY, true, false, owner->GetObjectID());
skillComponent->CalculateBehavior(982, 20577, LWOOBJID_EMPTY, true, false, owner->GetObjectID());

// Kill self if missed
const auto selfSmashTimer = 1.1F;
self->AddCallbackTimer(selfSmashTimer, [self]() {
self->AddCallbackTimer(1.1F, [self]() {
self->Kill();
});
}
Expand Down
1 change: 0 additions & 1 deletion utils
Submodule utils deleted from 74508f

0 comments on commit 61d5186

Please sign in to comment.