Skip to content

Commit

Permalink
multiworld system: refactoring of world data. changed and improved ch…
Browse files Browse the repository at this point in the history
…ecks of world type. refactored config.lua.
  • Loading branch information
elsongabriel committed Aug 30, 2024
1 parent 91e075f commit 11994ab
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 99 deletions.
18 changes: 10 additions & 8 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ toggleMaintainMode = false
maintainModeMessage = ""

-- Combat settings
-- NOTE: World id is 1 as default, new worlds must have different ids always greater than 1
-- NOTE: valid values for worldType are: "pvp", "no-pvp" and "pvp-enforced"
-- NOTE: removeBeginningWeaponAmmunition: spears, arrows, bolt have endless ammo (allows training for paladins)
-- NOTE: refundManaOnBeginningWeapons: wand of vortex and snakebite refund mana used (allows training for mages)
worldId = 1
worldType = "pvp"
hotkeyAimbotEnabled = true
protectionLevel = 7
pzLocked = 60 * 1000
Expand All @@ -54,7 +50,8 @@ cleanProtectionZones = false
-- Connection Config
-- NOTE: allowOldProtocol can allow login on 10x protocol. (11.00)
-- NOTE: maxPlayers set to 0 means no limit
-- NOTE: MaxPacketsPerSeconds if you change you will be subject to bugs by WPE, keep the default value of 25,
-- NOTE: serverName it's different than world name
-- NOTE: MaxPacketsPerSeconds if you change you will be subject to bugs by WPE, keep the default value of 25,
-- It's recommended to use a range like min 50 in this function, otherwise you will be disconnected after equipping two-handed distance weapons.
ip = "127.0.0.1"
allowOldProtocol = false
Expand All @@ -73,6 +70,14 @@ maxContainer = 100
maxPlayersOnlinePerAccount = 1
maxPlayersOutsidePZPerAccount = 1

-- World settings (This information will be loaded from the 'worlds' database table as well)
-- NOTE: World id is 1 as default, new worlds must have different ids always greater than 1
-- NOTE: valid values for worldType are: "pvp", "no-pvp", "pvp-enforced", "retro-pvp" and "retro-pvp-enforced"
-- NOTE: valid values for worldLocation are: "Europe", "North America", "South America" and "Oceania"
worldId = 1
worldType = "pvp"
worldLocation = "South America"

-- Packet Compression
-- Minimize network bandwith and reduce ping
-- Levels: 0 = disabled, 1 = best speed, 9 = best compression
Expand Down Expand Up @@ -246,7 +251,6 @@ onlyPremiumAccount = false
-- NOTE: autoBank = true, the dropped coins from monsters will be automatically deposited to your bank account.
-- NOTE: toggleGoldPouchAllowAnything will allow players to move items or gold to gold pouch
-- NOTE: toggleGoldPouchQuickLootOnly will ONLY allow quickloot to move items to gold pouch
-- NOTE: toggleServerIsRetroPVP will make this server as retro, setting PARTY_PROTECTION and ADVANCED_SECURE_MODE to 0
-- NOTE: toggleTravelsFree will make all travels from boat free
-- NOTE: buyAolCommandFee will add fee when player buy aol by command (!aol), active changing value more than 0 (fee value. ex: 1 = 1gp aol will be 50001)
-- NOTE: buyBlessCommandFee will add fee when player buy bless by command (!bless), active changing value between 1 and 100 (fee percent. ex: 3 = 3%, 30 = 30%)
Expand All @@ -265,7 +269,6 @@ autoLoot = false
autoBank = false
toggleGoldPouchAllowAnything = false
toggleGoldPouchQuickLootOnly = false
toggleServerIsRetroPVP = false
toggleTravelsFree = false
buyAolCommandFee = 0
buyBlessCommandFee = 0
Expand Down Expand Up @@ -541,7 +544,6 @@ startupDatabaseOptimization = true
ownerName = "OpenTibiaBR"
ownerEmail = "[email protected]"
url = "http://docs.opentibiabr.com/"
location = "South America"

-- Sends Discord webhook notifications on startup, raids and shutdown.
-- The URL layout is https://discord.com/api/webhooks/:id/:token
Expand Down
7 changes: 5 additions & 2 deletions data-otservbr-global/migrations/46.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ function onUpdateDatabase()
db.query([[
CREATE TABLE IF NOT EXISTS `worlds` (
`id` int(3) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`type` varchar(12) NOT NULL,
`name` varchar(80) NOT NULL,
`type` enum('no-pvp','pvp','retro-pvp','pvp-enforced','retro-pvp-enforced') NOT NULL,
`motd` varchar(255) NOT NULL DEFAULT '',
`location` enum('Europe','North America','South America','Oceania') NOT NULL,
`ip` varchar(15) NOT NULL,
`port` int(5) UNSIGNED NOT NULL,
`creation` int(11) NOT NULL DEFAULT unix_timestamp(),
CONSTRAINT `worlds_pk` PRIMARY KEY (`id`),
CONSTRAINT `worlds_unique` UNIQUE (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Expand Down
22 changes: 12 additions & 10 deletions data/XML/events.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<events>
<event name="Otservbr example 1" startdate="11/03/2020" enddate="12/30/2023" script="example.lua" >
<ingame exprate="100" lootrate="100" bosslootrate="100" spawnrate="100" skillrate="100" />
<description description="Otserver br example 1 description double exp and a half, double loot !chance!, regular spawn and double skill" />
<colors colordark="#235c00" colorlight="#2d7400" />
<details displaypriority="6" isseasonal="0" specialevent="0" />
<event name="Otservbr example 1" startdate="01/01/2024" enddate="12/31/2024">
<ingame exprate="100" lootrate="100" bosslootrate="100" spawnrate="100" skillrate="100"/>
<description
description="Otserver br example 1 description double exp and a half, double loot !chance!, regular spawn and double skill"/>
<colors colordark="#235c00" colorlight="#2d7400"/>
<details displaypriority="6" isseasonal="0" specialevent="0"/>
</event>
<event name="Otservbr example 2" startdate="2/2/2022" enddate="12/31/2023" script="" >
<ingame exprate="100" lootrate="100" bosslootrate="100" spawnrate="100" skillrate="100" />
<description description="Otserver br example 2 description 50% less exp, triple loot !chance!, 50% faster spawn and regular skill" />
<colors colordark="#735D10" colorlight="#8B6D05" />
<details displaypriority="6" isseasonal="0" specialevent="0" />
<event name="Otservbr example 2" startdate="01/01/2024" enddate="12/31/2024" script="">
<ingame exprate="100" lootrate="100" bosslootrate="100" spawnrate="100" skillrate="100"/>
<description
description="Otserver br example 2 description 50% less exp, triple loot !chance!, 50% faster spawn and regular skill"/>
<colors colordark="#735D10" colorlight="#8B6D05"/>
<details displaypriority="6" isseasonal="0" specialevent="0"/>
</event>
</events>
4 changes: 2 additions & 2 deletions data/events/scripts/creature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Creature:onTargetCombat(target)
return RETURNVALUE_YOUMAYNOTATTACKTHISCREATURE
end

if not IsRetroPVP() or PARTY_PROTECTION ~= 0 then
if not IsRetroPVP() then
if self:isPlayer() and target:isPlayer() then
local party = self:getParty()
if party then
Expand All @@ -71,7 +71,7 @@ function Creature:onTargetCombat(target)
end
end

if not IsRetroPVP() or ADVANCED_SECURE_MODE ~= 0 then
if not IsRetroPVP() then
if self:isPlayer() and target:isPlayer() then
if self:hasSecureMode() then
return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
Expand Down
23 changes: 18 additions & 5 deletions data/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,31 @@ function IsRunningGlobalDatapack()
end
end

function getWorldTypeName()
local worldType = Game.getWorldType()
if worldType == WORLD_TYPE_PVP then
return "Open PvP"
elseif worldType == WORLD_TYPE_NO_PVP then
return "Optional PvP"
elseif worldType == WORLD_TYPE_PVP_ENFORCED then
return "Hardcore PvP"
elseif worldType == WORLD_TYPE_RETRO_PVP then
return "Retro Open PvP"
elseif worldType == WORLD_TYPE_RETRO_PVP_ENFORCED then
return "Retro Hardcore PvP"
else
return "Unknown"
end
end

function IsRetroPVP()
return configManager.getBoolean(configKeys.TOGGLE_SERVER_IS_RETRO)
return table.contains({ WORLD_TYPE_RETRO_PVP, WORLD_TYPE_RETRO_PVP_ENFORCED }, Game.getWorldType())
end

function IsTravelFree()
return configManager.getBoolean(configKeys.TOGGLE_TRAVELS_FREE)
end

-- NOTE: 0 is disabled.
PARTY_PROTECTION = (IsRetroPVP() and 0) or 1
ADVANCED_SECURE_MODE = (IsRetroPVP() and 0) or 1

NORTH = DIRECTION_NORTH
EAST = DIRECTION_EAST
SOUTH = DIRECTION_SOUTH
Expand Down
2 changes: 0 additions & 2 deletions data/libs/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1461,8 +1461,6 @@ function setGlobalStorageValue(key, value)
return true
end

getWorldType = Game.getWorldType

numberToVariant = Variant
stringToVariant = Variant
positionToVariant = Variant
Expand Down
2 changes: 1 addition & 1 deletion data/modules/scripts/blessings/blessings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Blessings.Credits = {

Blessings.Config = {
AdventurerBlessingLevel = configManager.getNumber(configKeys.ADVENTURERSBLESSING_LEVEL), -- Free full bless until level
HasToF = not configManager.getBoolean(configKeys.TOGGLE_SERVER_IS_RETRO), -- Enables/disables twist of fate
HasToF = not IsRetroPVP(), -- Enables/disables twist of fate
InquisitonBlessPriceMultiplier = 1.1, -- Bless price multiplied by henricus
SkulledDeathLoseStoreItem = configManager.getBoolean(configKeys.SKULLED_DEATH_LOSE_STORE_ITEM), -- Destroy all items on store when dying with red/blackskull
InventoryGlowOnFiveBless = configManager.getBoolean(configKeys.INVENTORY_GLOW), -- Glow in yellow inventory items when the player has 5 or more bless,
Expand Down
7 changes: 1 addition & 6 deletions data/scripts/runes/magic_wall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ function onCreateMagicWall(creature, position)
if tile and tile:getTopCreature() and not tile:getTopCreature():isPlayer() then
return false
end
local magicWall
if Game.getWorldType() == WORLD_TYPE_NO_PVP then
magicWall = ITEM_MAGICWALL_SAFE
else
magicWall = ITEM_MAGICWALL
end
local magicWall = Game.getWorldType() == WORLD_TYPE_NO_PVP and ITEM_MAGICWALL_SAFE or ITEM_MAGICWALL
local item = Game.createItem(magicWall, 1, position)
item:setDuration(16, 24)
end
Expand Down
7 changes: 1 addition & 6 deletions data/scripts/runes/wild_growth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ function onCreateWildGrowth(creature, position)
if tile and tile:getTopCreature() and not tile:getTopCreature():isPlayer() then
return false
end
local wildGrowth
if Game.getWorldType() == WORLD_TYPE_NO_PVP then
wildGrowth = ITEM_WILDGROWTH_SAFE
else
wildGrowth = ITEM_WILDGROWTH
end
local wildGrowth = Game.getWorldType() == WORLD_TYPE_NO_PVP and ITEM_WILDGROWTH_SAFE or ITEM_WILDGROWTH
local item = Game.createItem(wildGrowth, 1, position)
item:setDuration(30, 60)
end
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/talkactions/player/server_info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function serverInfo.onSay(player, words, param)
.. "\nProtection level: "
.. configManager.getNumber(configKeys.PROTECTION_LEVEL)
.. "\nWorldType: "
.. configManager.getString(configKeys.WORLD_TYPE)
.. getWorldTypeName()
.. "\nKills/day to red skull: "
.. configManager.getNumber(configKeys.DAY_KILLS_TO_RED)
.. "\nKills/week to red skull: "
Expand Down
10 changes: 7 additions & 3 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
-- Table structure `worlds`
CREATE TABLE IF NOT EXISTS `worlds` (
`id` int(3) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`type` varchar(12) NOT NULL,
`name` varchar(80) NOT NULL,
`type` enum('no-pvp','pvp','retro-pvp','pvp-enforced','retro-pvp-enforced') NOT NULL,
`motd` varchar(255) NOT NULL DEFAULT '',
`location` enum('Europe','North America','South America','Oceania') NOT NULL,
`ip` varchar(15) NOT NULL,
`port` int(5) UNSIGNED NOT NULL,
`creation` int(11) NOT NULL DEFAULT unix_timestamp(),
CONSTRAINT `worlds_pk` PRIMARY KEY (`id`),
CONSTRAINT `worlds_unique` UNIQUE (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `worlds` (`name`, `type`, `ip`, `port`) VALUES ('OTServBR-Global', 'pvp', '127.0.0.1', 7172);
INSERT INTO `worlds` (`name`, `type`, `motd`, `location`, `ip`, `port`)
VALUES ('OTServBR-Global', 'pvp', 'Welcome to the OTServBR-Global!', 'South America', '127.0.0.1', 7172);

-- Table structure `server_config`
CREATE TABLE IF NOT EXISTS `server_config` (
Expand Down
24 changes: 18 additions & 6 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,36 @@ int CanaryServer::run() {

void CanaryServer::loadThisWorld() {
const auto worldTypeStr = g_configManager().getString(WORLD_TYPE, __FUNCTION__);
const auto worldType = Worlds::getTypeByString(worldTypeStr);
auto worldType = Worlds::getTypeByString(worldTypeStr);

if (worldType == WORLD_TYPE_NONE) {
throw FailedToInitializeCanary(
fmt::format(
"Unknown world type: {}, valid world types are: pvp, no-pvp and pvp-enforced",
g_configManager().getString(WORLD_TYPE, __FUNCTION__)
)
fmt::format("Unknown world type: {}, valid world types are: no-pvp, pvp, retro-pvp, pvp-enforced and retro-pvp-enforced", worldTypeStr)
);
}

const auto locationStr = g_configManager().getString(WORLD_LOCATION, __FUNCTION__);
const auto location = Worlds::getLocationCode(locationStr);
if (location == LOCATION_NONE) {
throw FailedToInitializeCanary(
fmt::format("Unknown world location: {}, valid world locations are: Europe, North America, South America and Oceania", locationStr)
);
}

if (g_configManager().getBoolean(TOGGLE_SERVER_IS_RETRO, __FUNCTION__)) {
g_logger().warn("[{}] - Config deprecated, you need to update your world type to 'retro-pvp' or 'retro-pvp-enforced'", __FUNCTION__);
worldType = worldType == WORLD_TYPE_PVP ? WORLD_TYPE_RETRO_PVP : WORLD_TYPE_RETRO_PVP_ENFORCED;
}

g_game().worlds()->setId(g_configManager().getNumber(WORLD_ID, __FUNCTION__));
g_game().worlds()->setName(g_configManager().getString(SERVER_NAME, __FUNCTION__));
g_game().worlds()->setType(worldType);
g_game().worlds()->setMotd(g_configManager().getString(SERVER_MOTD, __FUNCTION__));
g_game().worlds()->setLocation(location);
g_game().worlds()->setIp(g_configManager().getString(IP, __FUNCTION__));
g_game().worlds()->setPort(g_configManager().getNumber(GAME_PORT, __FUNCTION__));

logger.debug("World type set as {}", asUpperCaseString(worldTypeStr));
logger.debug("World type set as {} and location {}", asUpperCaseString(worldTypeStr), asUpperCaseString(locationStr));
}

void CanaryServer::loadMaps() const {
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ enum ConfigKey_t : uint16_t {
INVENTORY_GLOW,
IP,
KICK_AFTER_MINUTES,
LOCATION,
LOGIN_PORT,
LOGLEVEL,
LOOTPOUCH_MAXLIMIT,
Expand Down Expand Up @@ -324,6 +323,7 @@ enum ConfigKey_t : uint16_t {
WHEEL_POINTS_PER_LEVEL,
WHITE_SKULL_TIME,
WORLD_ID,
WORLD_LOCATION,
WORLD_TYPE,
XP_DISPLAY_MODE
};
2 changes: 1 addition & 1 deletion src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ bool ConfigManager::load() {
loadStringConfig(L, FORGE_FIENDISH_INTERVAL_TIME, "forgeFiendishIntervalTime", "1");
loadStringConfig(L, FORGE_FIENDISH_INTERVAL_TYPE, "forgeFiendishIntervalType", "hour");
loadStringConfig(L, GLOBAL_SERVER_SAVE_TIME, "globalServerSaveTime", "06:00");
loadStringConfig(L, LOCATION, "location", "");
loadStringConfig(L, M_CONST, "memoryConst", "1<<16");
loadStringConfig(L, METRICS_PROMETHEUS_ADDRESS, "metricsPrometheusAddress", "localhost:9464");
loadStringConfig(L, OWNER_EMAIL, "ownerEmail", "");
Expand All @@ -364,6 +363,7 @@ bool ConfigManager::load() {
loadStringConfig(L, STORE_IMAGES_URL, "coinImagesURL", "");
loadStringConfig(L, TIBIADROME_CONCOCTION_TICK_TYPE, "tibiadromeConcoctionTickType", "online");
loadStringConfig(L, URL, "url", "");
loadStringConfig(L, WORLD_LOCATION, "worldLocation", "South America");
loadStringConfig(L, WORLD_TYPE, "worldType", "pvp");

loaded = true;
Expand Down
1 change: 0 additions & 1 deletion src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ void Game::resetNpcs() const {

void Game::loadBoostedCreature() {
auto &db = Database::getInstance();
const auto worldId = worlds()->getId();

const std::string selectQuery = "SELECT * FROM `boosted_creature`";

Expand Down
18 changes: 14 additions & 4 deletions src/game/game_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ enum StackPosType_t {
STACKPOS_FIND_THING,
};

enum WorldType_t {
WORLD_TYPE_NONE = 0,
enum WorldType_t : int8_t {
WORLD_TYPE_NONE = -1,
WORLD_TYPE_PVP = 0,
WORLD_TYPE_NO_PVP = 1,
WORLD_TYPE_PVP = 2,
WORLD_TYPE_PVP_ENFORCED = 3,
WORLD_TYPE_PVP_ENFORCED = 2,
WORLD_TYPE_RETRO_PVP = 3,
WORLD_TYPE_RETRO_PVP_ENFORCED = 4,
};

enum Location_t {
LOCATION_NONE = 0,
LOCATION_EUROPE = 1,
LOCATION_NORTH_AMERICA = 2,
LOCATION_SOUTH_AMERICA = 3,
LOCATION_OCEANIA = 4,
};

enum GameState_t {
Expand Down
Loading

0 comments on commit 11994ab

Please sign in to comment.