Skip to content

Commit

Permalink
Merge branch 'main' into fix/support-outfit-crashs
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel authored May 30, 2024
2 parents e4078b5 + 6fed176 commit f3c5d26
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 156 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/mysql-schema-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
name: MySQL Schema Check
on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "schema.sql"
merge_group:
push:
paths:
- "schema.sql"
branches:
- main

jobs:
mysql-schema-check:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: canary
MYSQL_USER: canary
MYSQL_PASSWORD: canary
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
name: Check
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: 📌 MySQL Start & init & show db
run: |
sudo /etc/init.d/mysql start
mysql -e 'CREATE DATABASE canary;' -uroot -proot
mysql -e "SHOW DATABASES" -uroot -proot
- name: Import Canary Schema
run: |
mysql -uroot -proot canary < schema.sql
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
# VCPKG
# cmake -DCMAKE_TOOLCHAIN_FILE=/opt/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake ..
# Needed libs is in file vcpkg.json
# Windows required libs: .\vcpkg install --triplet x64-windows asio pugixml spdlog curl protobuf parallel-hashmap magic-enum mio luajit libmariadb mpir abseil
# Windows required libs: .\vcpkg install --triplet x64-windows asio pugixml spdlog curl protobuf parallel-hashmap magic-enum mio luajit libmariadb mpir abseil bshoshany-thread-pool
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
Expand Down Expand Up @@ -124,4 +124,4 @@ add_subdirectory(src)

if(BUILD_TESTS)
add_subdirectory(tests)
endif()
endif()
10 changes: 5 additions & 5 deletions data-otservbr-global/migrations/45.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function onUpdateDatabase()

db.query([[
CREATE TABLE IF NOT EXISTS `account_vipgroups` (
`id` tinyint(3) UNSIGNED NOT NULL,
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose vip group entry it is',
`name` varchar(128) NOT NULL,
`customizable` BOOLEAN NOT NULL DEFAULT '1',
Expand All @@ -13,17 +13,17 @@ function onUpdateDatabase()

db.query([[
CREATE TRIGGER `oncreate_accounts` AFTER INSERT ON `accounts` FOR EACH ROW BEGIN
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (1, NEW.`id`, 'Enemies', 0);
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (2, NEW.`id`, 'Friends', 0);
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (3, NEW.`id`, 'Trading Partner', 0);
INSERT INTO `account_vipgroups` (`account_id`, `name`, `customizable`) VALUES (NEW.`id`, 'Enemies', 0);
INSERT INTO `account_vipgroups` (`account_id`, `name`, `customizable`) VALUES (NEW.`id`, 'Friends', 0);
INSERT INTO `account_vipgroups` (`account_id`, `name`, `customizable`) VALUES (NEW.`id`, 'Trading Partner', 0);
END;
]])

db.query([[
CREATE TABLE IF NOT EXISTS `account_vipgrouplist` (
`account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose viplist entry it is',
`player_id` int(11) NOT NULL COMMENT 'id of target player of viplist entry',
`vipgroup_id` tinyint(3) UNSIGNED NOT NULL COMMENT 'id of vip group that player belongs',
`vipgroup_id` int(11) UNSIGNED NOT NULL COMMENT 'id of vip group that player belongs',
INDEX `account_id` (`account_id`),
INDEX `player_id` (`player_id`),
INDEX `vipgroup_id` (`vipgroup_id`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ local config = {
from = Position(33705, 31463, 14),
to = Position(33719, 31477, 14),
},
exit = Position(33609, 31499, 10),
exit = Position(33609, 31495, 10),
}

local lever = BossLever(config)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local config = {
monsterName = "Preceptor Lazare",
bossPosition = Position(33374, 31338, 3),
range = 5,
range = 50,
}

local preceptorLazare = GlobalEvent("PreceptorLazareRespawn")
Expand Down
62 changes: 30 additions & 32 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ CREATE TABLE IF NOT EXISTS `account_viplist` (

-- Table structure `account_vipgroup`
CREATE TABLE IF NOT EXISTS `account_vipgroups` (
`id` tinyint(3) UNSIGNED NOT NULL,
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose vip group entry it is',
`name` varchar(128) NOT NULL,
`customizable` BOOLEAN NOT NULL DEFAULT '1',
Expand All @@ -229,9 +229,9 @@ CREATE TABLE IF NOT EXISTS `account_vipgroups` (
--
DELIMITER //
CREATE TRIGGER `oncreate_accounts` AFTER INSERT ON `accounts` FOR EACH ROW BEGIN
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (1, NEW.`id`, 'Enemies', 0);
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (2, NEW.`id`, 'Friends', 0);
INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (3, NEW.`id`, 'Trading Partner', 0);
INSERT INTO `account_vipgroups` (`account_id`, `name`, `customizable`) VALUES (NEW.`id`, 'Enemies', 0);
INSERT INTO `account_vipgroups` (`account_id`, `name`, `customizable`) VALUES (NEW.`id`, 'Friends', 0);
INSERT INTO `account_vipgroups` (`account_id`, `name`, `customizable`) VALUES (NEW.`id`, 'Trading Partner', 0);
END
//
DELIMITER ;
Expand All @@ -240,7 +240,7 @@ DELIMITER ;
CREATE TABLE IF NOT EXISTS `account_vipgrouplist` (
`account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose viplist entry it is',
`player_id` int(11) NOT NULL COMMENT 'id of target player of viplist entry',
`vipgroup_id` tinyint(3) UNSIGNED NOT NULL COMMENT 'id of vip group that player belongs',
`vipgroup_id` int(11) UNSIGNED NOT NULL COMMENT 'id of vip group that player belongs',
INDEX `account_id` (`account_id`),
INDEX `player_id` (`player_id`),
INDEX `vipgroup_id` (`vipgroup_id`),
Expand All @@ -258,35 +258,36 @@ CREATE TABLE IF NOT EXISTS `boosted_boss` (
`boostname` TEXT,
`date` varchar(250) NOT NULL DEFAULT '',
`raceid` varchar(250) NOT NULL DEFAULT '',
`looktypeEx` int(11) NOT NULL DEFAULT "0",
`looktype` int(11) NOT NULL DEFAULT "136",
`lookfeet` int(11) NOT NULL DEFAULT "0",
`looklegs` int(11) NOT NULL DEFAULT "0",
`lookhead` int(11) NOT NULL DEFAULT "0",
`lookbody` int(11) NOT NULL DEFAULT "0",
`lookaddons` int(11) NOT NULL DEFAULT "0",
`lookmount` int(11) DEFAULT "0",
`looktypeEx` int(11) NOT NULL DEFAULT 0,
`looktype` int(11) NOT NULL DEFAULT 136,
`lookfeet` int(11) NOT NULL DEFAULT 0,
`looklegs` int(11) NOT NULL DEFAULT 0,
`lookhead` int(11) NOT NULL DEFAULT 0,
`lookbody` int(11) NOT NULL DEFAULT 0,
`lookaddons` int(11) NOT NULL DEFAULT 0,
`lookmount` int(11) DEFAULT 0,
PRIMARY KEY (`date`)
) AS SELECT 0 AS date, "default" AS boostname, 0 AS raceid;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `boosted_boss` (`boostname`, `date`, `raceid`) VALUES ('default', 0, 0);

-- Table structure `boosted_creature`
CREATE TABLE IF NOT EXISTS `boosted_creature` (
`boostname` TEXT,
`date` varchar(250) NOT NULL DEFAULT '',
`raceid` varchar(250) NOT NULL DEFAULT '',
`looktype` int(11) NOT NULL DEFAULT "136",
`lookfeet` int(11) NOT NULL DEFAULT "0",
`looklegs` int(11) NOT NULL DEFAULT "0",
`lookhead` int(11) NOT NULL DEFAULT "0",
`lookbody` int(11) NOT NULL DEFAULT "0",
`lookaddons` int(11) NOT NULL DEFAULT "0",
`lookmount` int(11) DEFAULT "0",
`looktype` int(11) NOT NULL DEFAULT 136,
`lookfeet` int(11) NOT NULL DEFAULT 0,
`looklegs` int(11) NOT NULL DEFAULT 0,
`lookhead` int(11) NOT NULL DEFAULT 0,
`lookbody` int(11) NOT NULL DEFAULT 0,
`lookaddons` int(11) NOT NULL DEFAULT 0,
`lookmount` int(11) DEFAULT 0,
PRIMARY KEY (`date`)
) AS SELECT 0 AS date, "default" AS boostname, 0 AS raceid;
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------
INSERT INTO `boosted_creature` (`boostname`, `date`, `raceid`) VALUES ('default', 0, 0);

--
-- Tabble Structure `daily_reward_history`
CREATE TABLE IF NOT EXISTS `daily_reward_history` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand Down Expand Up @@ -473,7 +474,6 @@ END
DELIMITER ;

-- Table structure `house_lists`

CREATE TABLE IF NOT EXISTS `house_lists` (
`house_id` int NOT NULL,
`listid` int NOT NULL,
Expand All @@ -485,7 +485,6 @@ CREATE TABLE IF NOT EXISTS `house_lists` (
CONSTRAINT `houses_list_house_fk` FOREIGN KEY (`house_id`) REFERENCES `houses` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;


-- Table structure `ip_bans`
CREATE TABLE IF NOT EXISTS `ip_bans` (
`ip` int(11) NOT NULL,
Expand Down Expand Up @@ -540,7 +539,6 @@ CREATE TABLE IF NOT EXISTS `market_offers` (
ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- Table structure `players_online`
CREATE TABLE IF NOT EXISTS `players_online` (
`player_id` int(11) NOT NULL,
Expand Down Expand Up @@ -671,7 +669,6 @@ CREATE TABLE IF NOT EXISTS `player_wheeldata` (
PRIMARY KEY (`player_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- Table structure `player_kills`
CREATE TABLE IF NOT EXISTS `player_kills` (
`player_id` int(11) NOT NULL,
Expand Down Expand Up @@ -830,6 +827,7 @@ CREATE TABLE IF NOT EXISTS `account_sessions` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Table structure `kv_store`
CREATE TABLE IF NOT EXISTS `kv_store` (
`key_name` varchar(191) NOT NULL,
`timestamp` bigint NOT NULL,
Expand All @@ -854,7 +852,7 @@ INSERT INTO `players`
(6, 'GOD', 6, 1, 2, 0, 155, 155, 100, 113, 115, 95, 39, 75, 0, 60, 60, 0, 8, '', 410, 1, 10, 0, 10, 0, 10, 0, 10, 0);

-- Create vip groups for GOD account
INSERT INTO `account_vipgroups` (`id`, `name`, `account_id`, `customizable`) VALUES
(1, 'Friends', 1, 0),
(2, 'Enemies', 1, 0),
(3, 'Trading Partners', 1, 0);
INSERT INTO `account_vipgroups` (`name`, `account_id`, `customizable`) VALUES
('Friends', 1, 0),
('Enemies', 1, 0),
('Trading Partners', 1, 0);
4 changes: 2 additions & 2 deletions src/database/databasetasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ DatabaseTasks &DatabaseTasks::getInstance() {
}

void DatabaseTasks::execute(const std::string &query, std::function<void(DBResult_ptr, bool)> callback /* nullptr */) {
threadPool.addLoad([this, query, callback]() {
threadPool.detach_task([this, query, callback]() {
bool success = db.executeQuery(query);
if (callback != nullptr) {
g_dispatcher().addEvent([callback, success]() { callback(nullptr, success); }, "DatabaseTasks::execute");
Expand All @@ -32,7 +32,7 @@ void DatabaseTasks::execute(const std::string &query, std::function<void(DBResul
}

void DatabaseTasks::store(const std::string &query, std::function<void(DBResult_ptr, bool)> callback /* nullptr */) {
threadPool.addLoad([this, query, callback]() {
threadPool.detach_task([this, query, callback]() {
DBResult_ptr result = db.storeQuery(query);
if (callback != nullptr) {
g_dispatcher().addEvent([callback, result]() { callback(result, true); }, "DatabaseTasks::store");
Expand Down
6 changes: 3 additions & 3 deletions src/game/scheduling/dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Dispatcher &Dispatcher::getInstance() {
void Dispatcher::init() {
UPDATE_OTSYS_TIME();

threadPool.addLoad([this] {
threadPool.detach_task([this] {
std::unique_lock asyncLock(dummyMutex);

while (!threadPool.getIoContext().stopped()) {
while (!threadPool.isStopped()) {
UPDATE_OTSYS_TIME();

executeEvents();
Expand Down Expand Up @@ -60,7 +60,7 @@ void Dispatcher::executeParallelEvents(std::vector<Task> &tasks, const uint8_t g
std::atomic_bool isTasksCompleted = false;

for (const auto &task : tasks) {
threadPool.addLoad([groupId, &task, &isTasksCompleted, &totalTaskSize] {
threadPool.detach_task([groupId, &task, &isTasksCompleted, &totalTaskSize] {
dispacherContext.type = DispatcherType::AsyncEvent;
dispacherContext.group = static_cast<TaskGroup>(groupId);
dispacherContext.taskName = task.getContext();
Expand Down
2 changes: 1 addition & 1 deletion src/game/scheduling/dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Dispatcher {
public:
explicit Dispatcher(ThreadPool &threadPool) :
threadPool(threadPool) {
threads.reserve(threadPool.getNumberOfThreads() + 1);
threads.reserve(threadPool.get_thread_count() + 1);
for (uint_fast16_t i = 0; i < threads.capacity(); ++i) {
threads.emplace_back(std::make_unique<ThreadTask>());
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/scheduling/save_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void SaveManager::scheduleAll() {
return;
}

threadPool.addLoad([this, scheduledAt]() {
threadPool.detach_task([this, scheduledAt]() {
if (m_scheduledAt.load() != scheduledAt) {
logger.warn("Skipping save for server because another save has been scheduled.");
return;
Expand Down Expand Up @@ -69,7 +69,7 @@ void SaveManager::schedulePlayer(std::weak_ptr<Player> playerPtr) {
logger.debug("Scheduling player {} for saving.", playerToSave->getName());
auto scheduledAt = std::chrono::steady_clock::now();
m_playerMap[playerToSave->getGUID()] = scheduledAt;
threadPool.addLoad([this, playerPtr, scheduledAt]() {
threadPool.detach_task([this, playerPtr, scheduledAt]() {
auto player = playerPtr.lock();
if (!player) {
logger.debug("Skipping save for player because player is no longer online.");
Expand Down
2 changes: 1 addition & 1 deletion src/lib/thread/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main() {
ThreadPool &pool = inject<ThreadPool>(); // preferrably uses constructor injection or setter injection.

// Post a task to the thread pool
pool.addLoad([]() {
pool.detach_task([]() {
std::cout << "Hello from thread " << std::this_thread::get_id() << std::endl;
});
}
Expand Down
Loading

0 comments on commit f3c5d26

Please sign in to comment.