Skip to content

Commit

Permalink
Merge pull request #89 from xtjoeytx/feature/new-serveroptions
Browse files Browse the repository at this point in the history
Implemented unstickmetime and protectedweapons. (#25)
  • Loading branch information
LoneBoco authored Feb 21, 2023
2 parents 1b8b60d + 257644c commit 6ae3852
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions bin/servers/default/config/serveroptions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
unstickmelevel = onlinestartlocal.nw
unstickmex = 30
unstickmey = 30.5
unstickmetime = 30

# Players in these levels can''t warp out nor can they PM other players.
jaillevels = police2.graal,police4.graal
Expand Down Expand Up @@ -111,6 +112,9 @@ clientsidepushpull = true
# If false, it will prevent the player from obtaining items like bomb, bow, superbomb, etc.
defaultweapons = true

# List of weapon names (comma separated) that will be given to the player each time they connect.
protectedweapons =

# List of bigmap.txt type maps used by the server. It lets the server know the level layout
# so you can see players move and talk in adjacent levels.
maps =
Expand Down Expand Up @@ -199,3 +203,4 @@ language = English

# Scripting
gs2default = false
nickname =
5 changes: 3 additions & 2 deletions server/src/TPlayer/TPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,8 @@ bool TPlayer::processChat(CString pChat)
for (std::vector<CString>::iterator i = jailList.begin(); i != jailList.end(); ++i)
if (i->trim() == levelName) return false;

if ((int)difftime(time(0), lastMovement) >= 30)
int unstickTime = server->getSettings().getInt("unstickmetime", 30);
if ((int)difftime(time(0), lastMovement) >= unstickTime)
{
lastMovement = time(0);
CString unstickLevel = server->getSettings().getStr("unstickmelevel", "onlinestartlocal.nw");
Expand All @@ -1304,7 +1305,7 @@ bool TPlayer::processChat(CString pChat)
setChat("Warped!");
}
else
setChat(CString() << "Don't move for 30 seconds before doing '" << pChat << "'!");
setChat(CString() << "Don't move for " << CString(unstickTime) << " seconds before doing '" << pChat << "'!");
}
}
else if (pChat == "update level" && hasRight(PLPERM_UPDATELEVEL))
Expand Down
11 changes: 8 additions & 3 deletions server/src/TPlayer/TPlayerLogin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,10 @@ bool TPlayer::sendLoginClient()
for (auto& weaponName : weaponList)
{
auto weapon = server->getWeapon(weaponName.toString());
if (weapon == 0)
if (weapon == nullptr)
{
// Let's check to see if it is a default weapon. If so, we can add it to the server now.
LevelItemType itemType = TLevelItem::getItemId(weaponName.toString());
if (itemType != LevelItemType::INVALID)
if (auto itemType = TLevelItem::getItemId(weaponName.toString()); itemType != LevelItemType::INVALID)
{
CString defWeapPacket = CString() >> (char)PLI_WEAPONADD >> (char)0 >> (char)TLevelItem::getItemTypeId(itemType);
defWeapPacket.readGChar();
Expand All @@ -320,6 +319,12 @@ bool TPlayer::sendLoginClient()
sendPacket(weapon->getWeaponPacket(versionID));
}

// Send any protected weapons we do not have.
auto protectedWeapons = server->getSettings().getStr("protectedweapons").gCommaStrTokens();
std::erase_if(protectedWeapons, [this](CString &val) { return std::find(weaponList.begin(), weaponList.end(), val) != weaponList.end(); });
for (auto& weaponName : protectedWeapons)
this->addWeapon(weaponName.toString());

if (versionID >= CLVER_4_0211)
{
// Send the player's weapons.
Expand Down

0 comments on commit 6ae3852

Please sign in to comment.