├── Hive ├── .gitignore ├── Source │ ├── .gitignore │ ├── HiveLib │ │ ├── .gitignore │ │ ├── Version.cpp.template │ │ ├── HiveLib.vcxproj.user │ │ ├── version_gen.sh │ │ ├── Version.h │ │ ├── DataSource │ │ │ ├── DataSource.h │ │ │ ├── SqlDataSource.h │ │ │ ├── CharDataSource.h │ │ │ ├── ObjDataSource.h │ │ │ ├── SqlCharDataSource.h │ │ │ ├── SqlObjDataSource.h │ │ │ └── CharDataSource.cpp │ │ ├── ExtStartup.h │ │ ├── Sqf.h │ │ ├── HiveLib.vcxproj.filters │ │ ├── HiveExtApp.h │ │ └── ExtStartup.cpp │ ├── HiveExt │ │ ├── Resource.rc │ │ ├── resource.h │ │ ├── HiveExt.vcxproj.filters │ │ ├── HiveExt.vcxproj.user │ │ ├── DirectHiveApp.h │ │ ├── DirectHiveApp.cpp │ │ └── Main.cpp │ ├── Database │ │ ├── Implementation │ │ │ ├── DatabaseMySql │ │ │ │ ├── Resource.rc │ │ │ │ ├── resource.h │ │ │ │ ├── DatabaseMySql.vcxproj.filters │ │ │ │ ├── Manifest.cpp │ │ │ │ ├── QueryResultMySql.h │ │ │ │ ├── QueryResultMySql.cpp │ │ │ │ ├── DatabaseMySql.h │ │ │ │ └── DatabaseMySql.vcxproj │ │ │ ├── DatabasePostgre │ │ │ │ ├── Resource.rc │ │ │ │ ├── postgre.h │ │ │ │ ├── resource.h │ │ │ │ ├── DatabasePostgre.vcxproj.filters │ │ │ │ ├── Manifest.cpp │ │ │ │ ├── QueryResultPostgre.h │ │ │ │ ├── DatabasePostgre.h │ │ │ │ └── DatabasePostgre.vcxproj │ │ │ ├── QueryResultImpl.h │ │ │ ├── SqlDelayThread.h │ │ │ ├── SqlStatementImpl.cpp │ │ │ ├── SqlDelayThread.cpp │ │ │ ├── SqlStatementImpl.h │ │ │ ├── RetrySqlOp.h │ │ │ ├── SqlPreparedStatement.h │ │ │ ├── SqlOperations.h │ │ │ ├── SqlConnection.h │ │ │ ├── SqlPreparedStatement.cpp │ │ │ ├── SqlOperations.cpp │ │ │ └── SqlConnection.cpp │ │ ├── Database.vcxproj.user │ │ ├── Callback.h │ │ ├── Database.vcxproj.filters │ │ ├── Field.h │ │ ├── QueryResult.h │ │ └── Database.h │ ├── Shared │ │ ├── Shared.vcxproj.user │ │ ├── Common │ │ │ ├── Singleton.h │ │ │ ├── SingletonImpl.h │ │ │ ├── Pimpl.h │ │ │ ├── Timer.h │ │ │ ├── PimplImpl.h │ │ │ ├── Types.h │ │ │ ├── Timer.cpp │ │ │ └── Exception.h │ │ ├── Server │ │ │ ├── Log │ │ │ │ ├── ArmaConsoleChannel.h │ │ │ │ ├── HiveConsoleChannel.h │ │ │ │ ├── CustomLevelChannel.h │ │ │ │ └── HiveConsoleChannel.cpp │ │ │ ├── AppServer.h │ │ │ └── AppServer.cpp │ │ ├── Library │ │ │ ├── SharedLibraryLoader.h │ │ │ └── Database │ │ │ │ ├── DatabaseLoader.h │ │ │ │ └── DatabaseLoader.cpp │ │ ├── Policy │ │ │ └── Allocator.cpp │ │ ├── Shared.vcxproj.filters │ │ └── Shared.vcxproj │ ├── Restarter │ │ ├── Restarter.vcxproj.filters │ │ ├── Restarter.vcxproj.user │ │ └── Restarter.vcxproj │ ├── StaticLib.Debug.props │ ├── ConsoleApp.Debug.props │ ├── Executable.Debug.props │ ├── Executable.Release.props │ ├── StaticLib.Release.props │ ├── ConsoleApp.Release.props │ ├── ConsoleApp.Generic.props │ ├── StaticLib.Common.props │ ├── DynamicLib.Common.props │ ├── Generic.Debug.props │ ├── Generic.Release.props │ ├── DynamicLib.Debug.props │ ├── DynamicLib.Release.props │ ├── Executable.Common.props │ ├── Generic.Common.props │ └── Hive.sln ├── Binaries │ ├── .gitignore │ ├── Restarter.ini │ ├── README.txt │ └── HiveExt.ini └── SQL │ ├── obj_tables.sql │ └── char_tables.sql ├── .gitignore └── Dependencies ├── TBB.props ├── MySQL.props ├── Poco.props ├── Detours.props └── PostgreSQL.props /Hive/.gitignore: -------------------------------------------------------------------------------- 1 | Build 2 | Out -------------------------------------------------------------------------------- /Hive/Source/.gitignore: -------------------------------------------------------------------------------- 1 | ipch -------------------------------------------------------------------------------- /Hive/Source/HiveLib/.gitignore: -------------------------------------------------------------------------------- 1 | Version.cpp 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.suo 2 | *.sdf 3 | *.opensdf 4 | *.aps 5 | -------------------------------------------------------------------------------- /Hive/Binaries/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.log.* 3 | *.exe 4 | *.dll 5 | *.pdb -------------------------------------------------------------------------------- /Hive/Source/HiveExt/Resource.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajkosto/hive/HEAD/Hive/Source/HiveExt/Resource.rc -------------------------------------------------------------------------------- /Hive/Source/HiveLib/Version.cpp.template: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Version.h" 3 | 4 | const std::string GIT_VERSION = "%GIT_VERSION%"; -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabaseMySql/Resource.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajkosto/hive/HEAD/Hive/Source/Database/Implementation/DatabaseMySql/Resource.rc -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabasePostgre/Resource.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajkosto/hive/HEAD/Hive/Source/Database/Implementation/DatabasePostgre/Resource.rc -------------------------------------------------------------------------------- /Hive/Source/Database/Database.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Hive/Source/HiveLib/HiveLib.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Hive/Source/Shared/Shared.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Hive/Source/HiveLib/version_gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | gitVer=`git rev-list HEAD | head -n 1` 4 | sedCommand="s/%GIT_VERSION%/${gitVer}/g" 5 | echo "Generating Git version file" 6 | sed "$sedCommand" $1 > $2 -------------------------------------------------------------------------------- /Hive/Source/Restarter/Restarter.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Dependencies/TBB.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Dependencies/MySQL.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Dependencies/Poco.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Dependencies/Detours.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabasePostgre/postgre.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef WIN32 4 | #ifdef FD_SETSIZE 5 | #undef FD_SETSIZE 6 | #endif 7 | #define FD_SETSIZE 1024 8 | #include 9 | #include 10 | #else 11 | #include 12 | #endif -------------------------------------------------------------------------------- /Dependencies/PostgreSQL.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Hive/Source/StaticLib.Debug.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Hive/Source/ConsoleApp.Debug.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Hive/Source/Executable.Debug.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Hive/Source/Executable.Release.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Hive/Source/StaticLib.Release.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Hive/Source/ConsoleApp.Release.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Hive/Source/HiveExt/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Resource.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /Hive/Source/ConsoleApp.Generic.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | _CONSOLE;%(PreprocessorDefinitions) 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabaseMySql/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Resource.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabasePostgre/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Resource.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /Hive/Source/StaticLib.Common.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | _LIB;%(PreprocessorDefinitions) 9 | $(TargetDir)$(TargetName).pdb 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Hive/Source/DynamicLib.Common.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | _USRDLL;%(PreprocessorDefinitions) 9 | 10 | 11 | $(TargetDir)$(TargetName).lib 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Hive/Source/Generic.Debug.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $(ProjectName)d 9 | 10 | 11 | 12 | _DEBUG;_SECURE_SCL=0;%(PreprocessorDefinitions) 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Hive/Source/Generic.Release.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $(ProjectName) 9 | 10 | 11 | 12 | NDEBUG;%(PreprocessorDefinitions) 13 | true 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Hive/Source/DynamicLib.Debug.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | $(ProjectName)d 10 | .dll 11 | 12 | 13 | 14 | _USRDLL;%(PreprocessorDefinitions) 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Hive/Source/DynamicLib.Release.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | $(ProjectName) 10 | .dll 11 | 12 | 13 | 14 | _USRDLL;%(PreprocessorDefinitions) 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Hive/Source/HiveExt/HiveExt.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Resource 11 | 12 | 13 | 14 | 15 | {5effb2b5-ada7-4b17-a444-3ad3c6cdccd2} 16 | 17 | 18 | 19 | 20 | Resource 21 | 22 | 23 | -------------------------------------------------------------------------------- /Hive/Source/Restarter/Restarter.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(BinariesDir)$(TargetFileName) 5 | WindowsLocalDebugger 6 | $(BinariesDir) 7 | 8 | 9 | $(BinariesDir)$(TargetFileName) 10 | WindowsLocalDebugger 11 | $(BinariesDir) 12 | 13 | -------------------------------------------------------------------------------- /Hive/Source/HiveLib/Version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | #include 21 | 22 | extern const std::string GIT_VERSION; -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabaseMySql/DatabaseMySql.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Resource 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | {c245e7ad-2011-4774-9609-3d51523ede87} 18 | 19 | 20 | 21 | 22 | Resource 23 | 24 | 25 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabasePostgre/DatabasePostgre.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Resource 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | {A2A36450-1171-4A55-9502-6978E46BB5FC} 18 | 19 | 20 | 21 | 22 | Resource 23 | 24 | 25 | -------------------------------------------------------------------------------- /Hive/SQL/obj_tables.sql: -------------------------------------------------------------------------------- 1 | SET FOREIGN_KEY_CHECKS=0; 2 | 3 | -- ---------------------------- 4 | -- Table structure for `Object_DATA` 5 | -- ---------------------------- 6 | CREATE TABLE `Object_DATA` ( 7 | `ObjectID` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, 8 | `ObjectUID` bigint(20) NOT NULL DEFAULT '0', 9 | `Instance` int(11) NOT NULL, 10 | `Classname` varchar(64) DEFAULT NULL, 11 | `Datestamp` datetime NOT NULL, 12 | `CharacterID` int(11) UNSIGNED NOT NULL DEFAULT '0', 13 | `Worldspace` varchar(128) NOT NULL DEFAULT '[]', 14 | `Inventory` text, 15 | `Hitpoints` varchar(512) NOT NULL DEFAULT '[]', 16 | `Fuel` double(13,5) NOT NULL DEFAULT '1.00000', 17 | `Damage` double(13,5) NOT NULL DEFAULT '0.00000', 18 | `last_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 19 | PRIMARY KEY (`ObjectID`), 20 | KEY `ObjectUID` (`ObjectUID`), 21 | KEY `Instance` (`Instance`) 22 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; 23 | -------------------------------------------------------------------------------- /Hive/Source/HiveExt/HiveExt.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(BinariesDir)$(TargetFileName) 5 | 6 | 7 | 8 | 9 | WindowsLocalDebugger 10 | $(BinariesDir) 11 | 12 | 13 | $(BinariesDir)$(TargetFileName) 14 | WindowsLocalDebugger 15 | $(BinariesDir) 16 | 17 | -------------------------------------------------------------------------------- /Hive/Source/Shared/Common/Singleton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | template 22 | class Singleton 23 | { 24 | protected: 25 | Singleton() {}; 26 | public: 27 | static RealType& instance(); 28 | }; -------------------------------------------------------------------------------- /Hive/Source/Executable.Common.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | $(SolutionDir)..\Binaries\ 6 | 7 | 8 | 9 | 10 | $(OutDir);%(AdditionalLibraryDirectories) 11 | $(IntDir)$(TargetName).lib 12 | Version.lib;%(AdditionalDependencies) 13 | 14 | 15 | copy /Y "$(TargetPath)" "$(BinariesDir)" 16 | 17 | 18 | Copy Binary Artifact 19 | 20 | 21 | 22 | 23 | $(BinariesDir) 24 | 25 | 26 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabaseMySql/Manifest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include 20 | #include "Database/Database.h" 21 | 22 | #include "DatabaseMySql.h" 23 | 24 | POCO_BEGIN_MANIFEST(Database) 25 | POCO_EXPORT_CLASS(DatabaseMySql) 26 | POCO_END_MANIFEST -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabasePostgre/Manifest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include 20 | #include "Database/Database.h" 21 | 22 | #include "DatabasePostgre.h" 23 | 24 | POCO_BEGIN_MANIFEST(Database) 25 | POCO_EXPORT_CLASS(DatabasePostgre) 26 | POCO_END_MANIFEST -------------------------------------------------------------------------------- /Hive/Source/Shared/Common/SingletonImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "Singleton.h" 20 | #include 21 | 22 | #define DEFINE_SINGLETON(SingletonType) namespace { Poco::SingletonHolder sh; }; \ 23 | SingletonType& Singleton::instance() { return *sh.get(); } 24 | -------------------------------------------------------------------------------- /Hive/Source/HiveLib/DataSource/DataSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "../Sqf.h" 22 | 23 | namespace Poco { class Logger; }; 24 | class DataSource 25 | { 26 | public: 27 | DataSource(Poco::Logger& logger) : _logger(logger) {} 28 | virtual ~DataSource() {} 29 | protected: 30 | Poco::Logger& _logger; 31 | }; -------------------------------------------------------------------------------- /Hive/Source/HiveExt/DirectHiveApp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include "HiveLib/HiveExtApp.h" 23 | 24 | class Database; 25 | class DirectHiveApp: public HiveExtApp 26 | { 27 | public: 28 | DirectHiveApp(string suffixDir); 29 | protected: 30 | bool initialiseService() override; 31 | private: 32 | shared_ptr _charDb, _objDb; 33 | }; -------------------------------------------------------------------------------- /Hive/Source/Shared/Server/Log/ArmaConsoleChannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "CustomLevelChannel.h" 22 | #include "Poco/UnWindows.h" 23 | 24 | class ArmaConsoleChannel: public CustomLevelChannel 25 | { 26 | public: 27 | ArmaConsoleChannel(); 28 | void log(const Poco::Message& msg); 29 | protected: 30 | ~ArmaConsoleChannel(); 31 | private: 32 | HWND _wndRich; 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /Hive/Source/Generic.Common.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $(SolutionDir)..\Out\$(Platform)\$(PlatformToolset)\ 7 | 8 | 9 | $(SolutionDir)..\Build\$(ProjectName)\$(Platform)\$(PlatformToolset)\$(Configuration)\ 10 | 11 | 12 | $(IntDir)\$(MSBuildProjectName).log 13 | 14 | 15 | 16 | WIN32;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 17 | $(SolutionDir);%(AdditionalIncludeDirectories) 18 | $(OutDir)$(TargetName).pdb 19 | 20 | 21 | true 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Hive/Source/HiveLib/DataSource/SqlDataSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "DataSource.h" 22 | 23 | class Database; 24 | class SqlDataSource : public DataSource 25 | { 26 | public: 27 | SqlDataSource(Poco::Logger& logger, shared_ptr db) : DataSource(logger), _db(db) {} 28 | ~SqlDataSource() {} 29 | protected: 30 | Database* getDB() const { return _db.get(); } 31 | private: 32 | shared_ptr _db; 33 | }; -------------------------------------------------------------------------------- /Hive/Source/Shared/Server/Log/HiveConsoleChannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "CustomLevelChannel.h" 22 | #include "Poco/UnWindows.h" 23 | 24 | class HiveConsoleChannel: public CustomLevelChannel 25 | { 26 | public: 27 | HiveConsoleChannel(std::string windowTitle = ""); 28 | 29 | void log(const Poco::Message& msg); 30 | protected: 31 | ~HiveConsoleChannel(); 32 | private: 33 | bool _consoleCreated; 34 | HANDLE _hConsole; 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /Hive/Source/HiveLib/ExtStartup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "HiveExtApp.h" 22 | #include 23 | 24 | namespace ExtStartup 25 | { 26 | typedef boost::function MakeAppFunction; 27 | 28 | void InitModule(MakeAppFunction makeAppFunc); 29 | void ProcessShutdown(); 30 | }; 31 | 32 | #define WIN32_LEAN_AND_MEAN 33 | #include 34 | #include 35 | 36 | extern "C" 37 | { 38 | __declspec(dllexport) void CALLBACK RVExtension(char* output, int outputSize, const char* function); 39 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabaseMySql/QueryResultMySql.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include "../QueryResultImpl.h" 23 | #include "DatabaseMySql.h" 24 | 25 | class QueryResultMySql : public QueryResultImpl 26 | { 27 | public: 28 | QueryResultMySql(MySQLConnection* theConn, const char* sql); 29 | ~QueryResultMySql(); 30 | 31 | bool fetchRow() override; 32 | QueryFieldNames fetchFieldNames() const override; 33 | 34 | bool nextResult() override; 35 | private: 36 | vector _results; 37 | int _currRes; 38 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabasePostgre/QueryResultPostgre.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "../QueryResultImpl.h" 22 | #include "DatabasePostgre.h" 23 | 24 | class QueryResultPostgre : public QueryResultImpl 25 | { 26 | public: 27 | QueryResultPostgre(PostgreSQLConnection* theConn, const char* sql); 28 | ~QueryResultPostgre(); 29 | 30 | bool fetchRow() override; 31 | QueryFieldNames fetchFieldNames() const override; 32 | 33 | bool nextResult() override; 34 | private: 35 | vector _results; 36 | int _currRes; 37 | size_t _tblIdx; 38 | }; 39 | -------------------------------------------------------------------------------- /Hive/Source/Shared/Common/Pimpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | 23 | template 24 | class Pimpl 25 | { 26 | private: 27 | std::unique_ptr m; 28 | public: 29 | Pimpl(); 30 | template 31 | Pimpl( Arg1&& arg1 ); 32 | 33 | template 34 | Pimpl( Arg1&& arg1, Arg2&& arg2 ); 35 | 36 | template 37 | Pimpl( Arg1&& arg1, Arg2&& arg2, Arg3&& arg3 ); 38 | 39 | ~Pimpl(); 40 | 41 | T* operator->(); 42 | T* operator->() const; 43 | T& operator*(); 44 | T& operator*() const; 45 | }; -------------------------------------------------------------------------------- /Hive/Source/Shared/Server/AppServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include 23 | 24 | class AppServer: public Poco::Util::ServerApplication 25 | { 26 | public: 27 | AppServer(std::string appName = "", std::string suffixDir = "") : appName(appName), appDir(suffixDir) {} 28 | std::string getAppDir() { return appDir; } 29 | void enableAsyncLogging(); 30 | protected: 31 | void initialize(Application& self) override; 32 | void uninitialize() override; 33 | private: 34 | void initConfig(); 35 | void initLogger(); 36 | std::string appName; 37 | std::string appDir; 38 | }; 39 | -------------------------------------------------------------------------------- /Hive/Binaries/Restarter.ini: -------------------------------------------------------------------------------- 1 | [Global] 2 | ;if not specified, will look in currently working directory for beta, then normal, if running as service, cwd = dir exe is in 3 | exePath = d:\Program Files\Steam\steamapps\common\arma 2 operation arrowhead\Expansion\beta\arma2oaserver.exe 4 | 5 | [EUDAYZPRIV] 6 | ;maxMem = 2047 7 | ;if not specified, uses your physical cpu count from windows 8 | ;cpuCount = 4 9 | exThreads = 1 10 | ;if not specified, uses the section name 11 | ;name = EUDAYZPRIV 12 | ;if not specified, uses the server name (either section, or name=) as a subfolder 13 | ;profiles = EUDAYZPRIV 14 | ;if not specified, tries profiles/[arma2.cfg,basic.cfg,arma2oa.cfg] 15 | ;cfg = EUDAYZPRIV\arma2.cfg 16 | ;if not specified, tries profiles/server.cfg 17 | config = EUDAYZPRIV\server_666.cfg 18 | ;must be specified if you run mods 19 | mod = @dayz;@hive 20 | ;world = Chernarus 21 | ;ip = 0.0.0.0 22 | port = 3000 23 | 24 | [EUDAYZPRIV2] 25 | maxMem = 2047 26 | ;if not specified, uses your physical cpu count from windows 27 | cpuCount = 3 28 | exThreads = 1 29 | ;if not specified, uses the section name 30 | ;name = EUDAYZPRIV 31 | ;if not specified, uses the server name (either section, or name=) as a subfolder 32 | ;profiles = EUDAYZPRIV 33 | ;if not specified, tries profiles/[arma2.cfg,basic.cfg,arma2oa.cfg] 34 | ;cfg = EUDAYZPRIV\arma2.cfg 35 | ;if not specified, tries profiles/server.cfg 36 | config = EUDAYZPRIV2\server_666.cfg 37 | ;must be specified if you run mods 38 | mod = @dayz;@hive 39 | world = Chernarus 40 | ;ip = 0.0.0.0 41 | port = 4000 -------------------------------------------------------------------------------- /Hive/Source/Shared/Server/Log/CustomLevelChannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Poco/Foundation.h" 22 | #include "Poco/Channel.h" 23 | #include "Poco/Mutex.h" 24 | 25 | #include 26 | 27 | class CustomLevelChannel: public Poco::Channel 28 | { 29 | public: 30 | CustomLevelChannel() {}; 31 | 32 | void overrideLevel(int newLevel) { _level = newLevel; } 33 | void removeLevelOverride() { _level.reset(); } 34 | protected: 35 | bool shouldLog(int theLevel) const 36 | { 37 | if (!_level.is_initialized()) 38 | return true; 39 | 40 | if (theLevel <= _level.get()) 41 | return true; 42 | 43 | return false; 44 | } 45 | 46 | ~CustomLevelChannel() {}; 47 | private: 48 | boost::optional _level; 49 | }; 50 | 51 | -------------------------------------------------------------------------------- /Hive/Source/Database/Callback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include 23 | 24 | class QueryResult; 25 | struct QueryCallback 26 | { 27 | typedef unique_ptr& ResType; 28 | typedef boost::function FuncType; 29 | 30 | QueryCallback() : res(nullptr) {} 31 | QueryCallback(FuncType fun, QueryResult* res = nullptr) : fun(fun), res(res) {} 32 | 33 | void invoke() 34 | { 35 | unique_ptr pRes(res); 36 | res = nullptr; 37 | 38 | //transfer ownership to callback function so that it can stash it or use it later 39 | if (!fun.empty()) 40 | fun(pRes); 41 | } 42 | void setResult(QueryResult* res) { this->res = res; } 43 | protected: 44 | FuncType fun; 45 | QueryResult* res; 46 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/QueryResultImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Database/QueryResult.h" 22 | 23 | class QueryResultImpl : public QueryResult 24 | { 25 | public: 26 | QueryResultImpl() {} 27 | QueryResultImpl(UInt64 rowCount, size_t fieldCount) : _row(fieldCount), _numFields(fieldCount), _numRows(rowCount) {} 28 | ~QueryResultImpl() {} 29 | 30 | const vector& fields() const override { return _row; } 31 | 32 | size_t numFields() const override { return _numFields; } 33 | UInt64 numRows() const override { return _numRows; } 34 | 35 | protected: 36 | void setNumFields(size_t numFields) { _numFields = numFields; } 37 | void setNumRows(UInt64 numRows) { _numRows = numRows; } 38 | 39 | vector _row; 40 | private: 41 | size_t _numFields; 42 | UInt64 _numRows; 43 | }; -------------------------------------------------------------------------------- /Hive/Source/HiveLib/DataSource/CharDataSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "DataSource.h" 22 | 23 | class CharDataSource 24 | { 25 | public: 26 | virtual ~CharDataSource() {} 27 | 28 | virtual Sqf::Value fetchCharacterInitial( string playerId, int serverId, const string& playerName ) = 0; 29 | virtual Sqf::Value fetchCharacterDetails( int characterId ) = 0; 30 | typedef map FieldsType; 31 | virtual bool updateCharacter( int characterId, const FieldsType& fields ) = 0; 32 | virtual bool initCharacter( int characterId, const Sqf::Value& inventory, const Sqf::Value& backpack ) = 0; 33 | virtual bool killCharacter( int characterId, int duration ) = 0; 34 | virtual bool recordLogin( string playerId, int characterId, int action ) = 0; 35 | protected: 36 | static int SanitiseInv(Sqf::Parameters& origInv); 37 | }; -------------------------------------------------------------------------------- /Hive/Source/Shared/Common/Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | 23 | #ifdef min 24 | #undef min 25 | #endif 26 | #ifdef max 27 | #undef max 28 | #endif 29 | 30 | class GlobalTimer 31 | { 32 | public: 33 | //get current server time 34 | static UInt64 getMSTime64(); 35 | static UInt32 getMSTime(); 36 | 37 | //get time difference between two timestamps 38 | static inline UInt32 getMSTimeDiff(UInt32 oldMSTime, UInt32 newMSTime) 39 | { 40 | if (oldMSTime > newMSTime) 41 | { 42 | const UInt32 diff_1 = (UInt32(0xFFFFFFFF) - oldMSTime) + newMSTime; 43 | const UInt32 diff_2 = oldMSTime - newMSTime; 44 | 45 | return std::min(diff_1, diff_2); 46 | } 47 | 48 | return newMSTime - oldMSTime; 49 | } 50 | 51 | //get unix time 52 | static Int32 getTime(); 53 | private: 54 | GlobalTimer(); 55 | GlobalTimer(const GlobalTimer& ); 56 | }; -------------------------------------------------------------------------------- /Hive/Binaries/README.txt: -------------------------------------------------------------------------------- 1 | HiveExt persistence layer for DayzMod 2 | 3 | Contents: 4 | @hive 5 | - HiveExt.dll HiveExt ArmA2 native extension 6 | cfgdayz 7 | - HiveExt.ini Sample ini file with explanations 8 | DatabaseMySql.dll Required module for proper HiveExt operation 9 | DatabasePostgre.dll Optional module for proper HiveExt operation 10 | tbb.dll Required module for proper HiveExt operation 11 | tbbmalloc.dll Required module for proper HiveExt operation 12 | 13 | README.txt This file 14 | 15 | The contents are displayed as relative to the archive root, and should be extracted as such into the OA game folder 16 | (the folder where the non-beta-patch ArmA2OA.exe resides, as well as other files like _runA2CO.cmd if you have CO) 17 | 18 | Microsoft Visual C++ 2010 SP1 x86 redistributable is required for HiveExt to start 19 | If you do not already have it, get it from http://www.microsoft.com/en-us/download/details.aspx?id=8328 20 | 21 | If you want to specify any options other than the defaults in the .ini file, you must place it into your PROFILES folder 22 | (this is the folder which you specify using the -profiles command line option to arma2oaserver.exe, the same one where the .rpt will go) 23 | It is highly advised to have this folder OUTSIDE of the Arma2OA root, otherwise hackers running modified scripts MIGHT be able to read it 24 | (the same recommendation should be followed for the folders that house your server.cfg and BEServer.cfg files) 25 | 26 | HiveExt.ini file changelog 27 | 0.9.6.13 - Changed [Time] section, when running a private server, you can now specify a static date as well as hour 28 | 0.9.6.10 - Added [Logger] section with explanations and defaults, added explanation for Hostname = . named-pipe option in [Database] -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/SqlDelayThread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | class Database; 25 | class SqlOperation; 26 | class SqlConnection; 27 | 28 | class SqlDelayThread : public Poco::Runnable 29 | { 30 | protected: 31 | typedef tbb::concurrent_queue SqlQueue; 32 | 33 | SqlQueue _sqlQueue; //Queue of SQL statements 34 | Database& _dbEngine; //Pointer to used Database engine 35 | SqlConnection& _dbConn; //Pointer to DB connection 36 | volatile bool _isRunning; 37 | 38 | //process all enqueued requests 39 | virtual void processRequests(); 40 | public: 41 | SqlDelayThread(Database& db, SqlConnection& conn); 42 | virtual ~SqlDelayThread(); 43 | 44 | //Put sql statement to delay queue 45 | bool queueOperation(SqlOperation* sql) 46 | { 47 | _sqlQueue.push(sql); 48 | return true; 49 | } 50 | 51 | //Send stop event 52 | virtual void stop(); 53 | //Main Thread loop 54 | void run() override; 55 | }; -------------------------------------------------------------------------------- /Hive/Source/HiveLib/DataSource/ObjDataSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "DataSource.h" 22 | 23 | class ObjDataSource 24 | { 25 | public: 26 | virtual ~ObjDataSource() {} 27 | 28 | typedef std::queue ServerObjectsQueue; 29 | virtual void populateObjects( int serverId, ServerObjectsQueue& queue ) = 0; 30 | 31 | virtual bool updateObjectInventory( int serverId, Int64 objectIdent, bool byUID, const Sqf::Value& inventory ) = 0; 32 | virtual bool deleteObject( int serverId, Int64 objectIdent, bool byUID ) = 0; 33 | virtual bool updateVehicleMovement( int serverId, Int64 objectIdent, const Sqf::Value& worldspace, double fuel ) = 0; 34 | virtual bool updateVehicleStatus( int serverId, Int64 objectIdent, const Sqf::Value& hitPoints, double damage ) = 0; 35 | virtual bool createObject( int serverId, const string& className, double damage, int characterId, 36 | const Sqf::Value& worldSpace, const Sqf::Value& inventory, const Sqf::Value& hitPoints, double fuel, Int64 uniqueId ) = 0; 37 | }; -------------------------------------------------------------------------------- /Hive/Source/HiveLib/Sqf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include 23 | 24 | namespace Sqf 25 | { 26 | typedef boost::make_recursive_variant< double, int, Int64, bool, string, void*, vector >::type Value; 27 | typedef vector Parameters; 28 | 29 | bool IsNull(const Value& val); 30 | bool IsAny(const Value& val); 31 | double GetDouble(const Value& val); 32 | int GetIntAny(const Value& val); 33 | Int64 GetBigInt(const Value& val); 34 | string GetStringAny(const Value& val); 35 | bool GetBoolAny(const Value& val); 36 | 37 | void runTest(); 38 | } 39 | 40 | namespace boost 41 | { 42 | std::istream& operator >> (std::istream& src, Sqf::Value& out); 43 | std::ostream& operator << (std::ostream& out, const Sqf::Value& val); 44 | }; 45 | 46 | namespace std 47 | { 48 | std::istream& operator >> (std::istream& src, Sqf::Parameters& out); 49 | std::ostream& operator << (std::ostream& out, const Sqf::Parameters& params); 50 | }; -------------------------------------------------------------------------------- /Hive/Source/Shared/Library/SharedLibraryLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | 23 | #include 24 | #include 25 | 26 | template 27 | class SharedLibraryLoader 28 | { 29 | public: 30 | void loadLibrary(const string& libName) 31 | { 32 | string fileName = libName + Poco::SharedLibrary::suffix(); 33 | _loader.loadLibrary(fileName); 34 | } 35 | 36 | Base* create(const std::string& className) const { return _loader.create(className); } 37 | Base& instance(const std::string& className) const { return _loader.instance(className); } 38 | bool canCreate(const std::string& className) const { return _loader.canCreate(className); } 39 | void destroy(const std::string& className, Base* pObject) const { _loader.destroy(className,pObject); } 40 | bool isAutoDelete(const std::string& className, Base* pObject) const { return _loader.isAutoDelete(className, pObject); } 41 | private: 42 | typedef Poco::ClassLoader LibraryLoader; 43 | LibraryLoader _loader; 44 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/SqlStatementImpl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "SqlStatementImpl.h" 20 | #include "ConcreteDatabase.h" 21 | 22 | #include 23 | 24 | ////////////////////////////////////////////////////////////////////////// 25 | 26 | void SqlStatementImpl::verifyNumBoundParams( const SqlStmtParameters& args ) 27 | { 28 | //verify amount of bound parameters 29 | if(args.boundParams() != this->numArgs()) 30 | { 31 | string errMsg = Poco::format("SQL ERROR: wrong amount of parameters (%d instead of %d) in statement %s", 32 | args.boundParams(),this->numArgs(),_dbEngine->getStmtString(this->getId())); 33 | poco_bugcheck_msg(errMsg.c_str()); 34 | } 35 | } 36 | 37 | bool SqlStatementImpl::execute() 38 | { 39 | SqlStmtParameters args = detach(); 40 | verifyNumBoundParams(args); 41 | return _dbEngine->executeStmt(_stmtId, args); 42 | } 43 | 44 | bool SqlStatementImpl::directExecute() 45 | { 46 | SqlStmtParameters args = detach(); 47 | verifyNumBoundParams(args); 48 | return _dbEngine->directExecuteStmt(_stmtId, args); 49 | } -------------------------------------------------------------------------------- /Hive/Source/Shared/Library/Database/DatabaseLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include "Database/Database.h" 23 | #include 24 | 25 | static const UInt32 REQUIRED_DB_VERSION_NUM[4] = {0,9,14,0}; 26 | 27 | class DatabaseLoader 28 | { 29 | public: 30 | static string GetDbTypeFromConfig(Poco::Util::AbstractConfiguration* dbConfig); 31 | static string GetDbModuleName(string dbType, bool physicalName = false); 32 | 33 | static bool GetVersionOfModule(const string& moduleName, UInt32& outMajor, UInt32& outMinor, UInt32& outRev, UInt32& outBld); 34 | static bool IsVersionCompatible(const UInt32* wantedVer, const UInt32* gotVer); 35 | 36 | static shared_ptr Create(const string& dbType); 37 | static shared_ptr Create(Poco::Util::AbstractConfiguration* dbConfig); 38 | 39 | static Database::KeyValueColl MakeConnParams(Poco::Util::AbstractConfiguration* dbConfig); 40 | 41 | POCO_DEFINE_EXCEPTION(,CreationError,Poco::LogicException,"Cannot create database"); 42 | }; -------------------------------------------------------------------------------- /Hive/Source/Shared/Common/PimplImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "Pimpl.h" 20 | 21 | #include 22 | 23 | template 24 | Pimpl::Pimpl() : m(new T()) { } 25 | 26 | template 27 | template 28 | Pimpl::Pimpl( Arg1&& arg1 ) 29 | : m( new T( std::forward(arg1) ) ) { } 30 | 31 | template 32 | template 33 | Pimpl::Pimpl( Arg1&& arg1, Arg2&& arg2 ) 34 | : m( new T( std::forward(arg1), std::forward(arg2) ) ) { } 35 | 36 | template 37 | template 38 | Pimpl::Pimpl( Arg1&& arg1, Arg2&& arg2, Arg3&& arg3 ) 39 | : m( new T( std::forward(arg1), std::forward(arg2), std::forward(arg3) ) ) { } 40 | 41 | template 42 | Pimpl::~Pimpl() { } 43 | 44 | template 45 | T* Pimpl::operator->() { return m.get(); } 46 | 47 | template 48 | T* Pimpl::operator->() const { return m.get(); } 49 | 50 | template 51 | T& Pimpl::operator*() { return *m.get(); } 52 | 53 | template 54 | T& Pimpl::operator*() const { return *m.get(); } -------------------------------------------------------------------------------- /Hive/Source/Shared/Common/Types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #define NOMINMAX 22 | 23 | #include 24 | 25 | using Poco::Int8; 26 | using Poco::Int16; 27 | using Poco::Int32; 28 | using Poco::Int64; 29 | using Poco::UInt8; 30 | using Poco::UInt16; 31 | using Poco::UInt32; 32 | using Poco::UInt64; 33 | using Poco::IntPtr; 34 | using Poco::UIntPtr; 35 | 36 | #include 37 | using std::unique_ptr; 38 | #include 39 | using boost::shared_ptr; 40 | #include 41 | using boost::weak_ptr; 42 | #include 43 | using boost::make_shared; 44 | #include 45 | using boost::scoped_ptr; 46 | 47 | #include 48 | using std::string; 49 | #include 50 | using std::vector; 51 | typedef std::vector ByteVector; 52 | #include 53 | using std::map; 54 | #include 55 | using boost::unordered_map; 56 | #include 57 | using std::deque; 58 | #include 59 | using std::queue; 60 | #include 61 | using std::list; 62 | 63 | using std::begin; 64 | using std::end; 65 | using std::for_each; 66 | 67 | #include 68 | using boost::array; -------------------------------------------------------------------------------- /Hive/Source/HiveLib/HiveLib.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {1cb43970-0f83-4a32-8927-28e02fdcbc94} 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | DataSource 15 | 16 | 17 | DataSource 18 | 19 | 20 | DataSource 21 | 22 | 23 | DataSource 24 | 25 | 26 | 27 | 28 | DataSource 29 | 30 | 31 | DataSource 32 | 33 | 34 | 35 | 36 | 37 | 38 | DataSource 39 | 40 | 41 | DataSource 42 | 43 | 44 | DataSource 45 | 46 | 47 | DataSource 48 | 49 | 50 | DataSource 51 | 52 | 53 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/SqlDelayThread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "SqlDelayThread.h" 20 | #include "Database/Database.h" 21 | #include "SqlOperations.h" 22 | 23 | #include 24 | 25 | SqlDelayThread::SqlDelayThread(Database& db, SqlConnection& conn) : _dbEngine(db), _dbConn(conn), _isRunning(true) 26 | { 27 | } 28 | 29 | SqlDelayThread::~SqlDelayThread() 30 | { 31 | //make sure we are stopped 32 | stop(); 33 | //process all requests which might have been queued while thread was stopping 34 | processRequests(); 35 | } 36 | 37 | void SqlDelayThread::run() 38 | { 39 | _dbEngine.threadEnter(); 40 | 41 | const size_t loopSleepMS = 10; 42 | 43 | while (_isRunning) 44 | { 45 | //if the running state gets turned off while sleeping 46 | //empty the queue before exiting 47 | Poco::Thread::sleep(loopSleepMS); 48 | 49 | processRequests(); 50 | } 51 | 52 | _dbEngine.threadExit(); 53 | } 54 | 55 | void SqlDelayThread::stop() 56 | { 57 | _isRunning = false; 58 | } 59 | 60 | void SqlDelayThread::processRequests() 61 | { 62 | SqlOperation* s = nullptr; 63 | while (_sqlQueue.try_pop(s)) 64 | { 65 | s->execute(_dbConn); 66 | s->onRemove(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Hive/Source/Shared/Common/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "Timer.h" 20 | #include 21 | 22 | using Poco::Timestamp; 23 | namespace 24 | { 25 | Timestamp globalProgramStartTime = Timestamp(); 26 | } 27 | 28 | UInt64 GlobalTimer::getMSTime64() 29 | { 30 | //get current time 31 | const Timestamp currTime = Timestamp(); 32 | //calculate time diff between two world ticks 33 | //special case: curr_time < old_time - we suppose that our time has not ticked at all 34 | //this should be constant value otherwise it is possible that our time can start ticking backwards until next world tick!!! 35 | Timestamp::TimeVal elapsed = globalProgramStartTime.elapsed(); 36 | //possible that globalProgramStartTime not initialized yet, return 0 in that case 37 | if (elapsed < 0) 38 | elapsed = 0; 39 | else //convert to milliseconds 40 | elapsed /= 1000; 41 | 42 | UInt64 diff = static_cast(elapsed); //always positive now 43 | return diff; 44 | } 45 | 46 | UInt32 GlobalTimer::getMSTime() 47 | { 48 | UInt64 diff = getMSTime64(); 49 | //clamp it 50 | UInt32 iRes = UInt32(diff % UInt64(0x00000000FFFFFFFF)); 51 | return iRes; 52 | } 53 | 54 | Int32 GlobalTimer::getTime() 55 | { 56 | return static_cast(Timestamp().epochTime()); 57 | } 58 | -------------------------------------------------------------------------------- /Hive/Source/HiveLib/DataSource/SqlCharDataSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "SqlDataSource.h" 22 | #include "CharDataSource.h" 23 | #include "Database/SqlStatement.h" 24 | 25 | class SqlCharDataSource : public SqlDataSource, public CharDataSource 26 | { 27 | public: 28 | SqlCharDataSource(Poco::Logger& logger, shared_ptr db, const string& idFieldName, const string& wsFieldName); 29 | ~SqlCharDataSource(); 30 | 31 | Sqf::Value fetchCharacterInitial( string playerId, int serverId, const string& playerName ) override; 32 | Sqf::Value fetchCharacterDetails( int characterId ) override; 33 | bool updateCharacter( int characterId, const FieldsType& fields ) override; 34 | bool initCharacter( int characterId, const Sqf::Value& inventory, const Sqf::Value& backpack ) override; 35 | bool killCharacter( int characterId, int duration ) override; 36 | bool recordLogin( string playerId, int characterId, int action ) override; 37 | 38 | private: 39 | string _idFieldName; 40 | string _wsFieldName; 41 | 42 | //statement ids 43 | SqlStatementID _stmtChangePlayerName; 44 | SqlStatementID _stmtInsertPlayer; 45 | SqlStatementID _stmtUpdateCharacterLastLogin; 46 | SqlStatementID _stmtInsertNewCharacter; 47 | SqlStatementID _stmtInitCharacter; 48 | SqlStatementID _stmtKillCharacter; 49 | SqlStatementID _stmtRecordLogin; 50 | }; -------------------------------------------------------------------------------- /Hive/SQL/char_tables.sql: -------------------------------------------------------------------------------- 1 | SET FOREIGN_KEY_CHECKS=0; 2 | 3 | -- ---------------------------- 4 | -- Table structure for `Player_DATA` 5 | -- ---------------------------- 6 | CREATE TABLE `Player_DATA` ( 7 | `PlayerUID` varchar(32) NOT NULL, 8 | `PlayerName` varchar(128) CHARACTER SET utf8 NOT NULL, 9 | `PlayerMorality` int(11) NOT NULL DEFAULT '0', 10 | `PlayerSex` tinyint(3) UNSIGNED NOT NULL DEFAULT '0', 11 | PRIMARY KEY (`PlayerUID`) 12 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 13 | 14 | -- ---------------------------- 15 | -- Table structure for `Character_DATA` 16 | -- ---------------------------- 17 | CREATE TABLE `Character_DATA` ( 18 | `CharacterID` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, 19 | `PlayerUID` varchar(32) NOT NULL, 20 | `InstanceID` int(11) NOT NULL, 21 | `Datestamp` datetime DEFAULT NULL, 22 | `LastLogin` datetime NOT NULL, 23 | `Inventory` text, 24 | `Backpack` text, 25 | `Worldspace` varchar(128) NOT NULL DEFAULT '[]', 26 | `Medical` varchar(256) NOT NULL DEFAULT '[]', 27 | `Alive` tinyint(3) UNSIGNED NOT NULL DEFAULT '1', 28 | `Generation` int(11) UNSIGNED NOT NULL DEFAULT '1', 29 | `LastAte` datetime NOT NULL, 30 | `LastDrank` datetime NOT NULL, 31 | `KillsZ` int(11) UNSIGNED NOT NULL DEFAULT '0', 32 | `HeadshotsZ` int(11) UNSIGNED NOT NULL DEFAULT '0', 33 | `DistanceFoot` int(11) NOT NULL DEFAULT '0', 34 | `Duration` int(11) UNSIGNED NOT NULL DEFAULT '0', 35 | `CurrentState` varchar(128) NOT NULL DEFAULT '[]', 36 | `KillsH` int(11) UNSIGNED NOT NULL DEFAULT '0', 37 | `Model` varchar(64) NOT NULL DEFAULT '"Survivor2_DZ"', 38 | `KillsB` int(11) UNSIGNED NOT NULL DEFAULT '0', 39 | `Humanity` int(11) NOT NULL DEFAULT '2500', 40 | PRIMARY KEY (`CharacterID`), 41 | KEY `CharFetch` (`PlayerUID`,`Alive`) USING BTREE 42 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; 43 | 44 | -- ---------------------------- 45 | -- Table structure for `Player_LOGIN` 46 | -- ---------------------------- 47 | CREATE TABLE `Player_LOGIN` ( 48 | `LoginID` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, 49 | `PlayerUID` varchar(32) NOT NULL, 50 | `CharacterID` int(11) UNSIGNED NOT NULL, 51 | `Datestamp` datetime NOT NULL, 52 | `Action` tinyint(3) NOT NULL, 53 | PRIMARY KEY (`LoginID`) 54 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; 55 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/SqlStatementImpl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Database/SqlStatement.h" 22 | 23 | class ConcreteDatabase; 24 | 25 | class SqlStatementImpl : public SqlStatement 26 | { 27 | public: 28 | SqlStatementImpl(const SqlStatementImpl& index) 29 | { 30 | _stmtId = index._stmtId; 31 | _dbEngine = index._dbEngine; 32 | 33 | if(index._params.boundParams() > 0) 34 | _params = index._params; 35 | else 36 | _params.reset(_stmtId.numArgs()); 37 | } 38 | virtual ~SqlStatementImpl() 39 | { 40 | } 41 | 42 | SqlStatementImpl& operator=( const SqlStatementImpl& index ) 43 | { 44 | if(this != &index) 45 | { 46 | _stmtId = index._stmtId; 47 | _dbEngine = index._dbEngine; 48 | 49 | if(index._params.boundParams() > 0) 50 | _params = index._params; 51 | else 52 | _params.reset(_stmtId.numArgs()); 53 | } 54 | 55 | return *this; 56 | } 57 | bool execute(); 58 | bool directExecute(); 59 | protected: 60 | //don't allow anyone except Database class to create static SqlStatement objects 61 | friend class ConcreteDatabase; 62 | SqlStatementImpl(const SqlStatementID& index, ConcreteDatabase& db) 63 | { 64 | _stmtId = index; 65 | _dbEngine = &db; 66 | _params.reset(_stmtId.numArgs()); 67 | } 68 | private: 69 | inline SqlStmtParameters detach() 70 | { 71 | SqlStmtParameters retVal; 72 | _params.swap(retVal); 73 | return retVal; 74 | } 75 | void verifyNumBoundParams(const SqlStmtParameters& args); 76 | 77 | ConcreteDatabase* _dbEngine; 78 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/Database.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Implementation 11 | 12 | 13 | Implementation 14 | 15 | 16 | Implementation 17 | 18 | 19 | Implementation 20 | 21 | 22 | Implementation 23 | 24 | 25 | Implementation 26 | 27 | 28 | Implementation 29 | 30 | 31 | Implementation 32 | 33 | 34 | 35 | 36 | {571aebda-42b7-4cf1-b958-523c0ec413a0} 37 | 38 | 39 | 40 | 41 | Implementation 42 | 43 | 44 | Implementation 45 | 46 | 47 | Implementation 48 | 49 | 50 | Implementation 51 | 52 | 53 | Implementation 54 | 55 | 56 | Implementation 57 | 58 | 59 | -------------------------------------------------------------------------------- /Hive/Source/Shared/Policy/Allocator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef USE_STANDARD_MALLOC 20 | 21 | #include 22 | 23 | #pragma warning( disable : 4290 ) 24 | 25 | // No retry loop because we assume that scalable_malloc does 26 | // all it takes to allocate the memory, so calling it repeatedly 27 | // will not improve the situation at all 28 | // 29 | // No use of std::new_handler because it cannot be done in portable 30 | // and thread-safe way (see sidebar) 31 | // 32 | // We throw std::bad_alloc() when scalable_malloc returns NULL 33 | //(we return NULL if it is a no-throw implementation) 34 | void* operator new (size_t size) throw (std::bad_alloc) 35 | { 36 | if (size == 0) size = 1; 37 | if (void* ptr = scalable_malloc (size)) 38 | return ptr; 39 | throw std::bad_alloc (); 40 | } 41 | void* operator new[] (size_t size) throw (std::bad_alloc) 42 | { 43 | return operator new (size); 44 | } 45 | void* operator new (size_t size, const std::nothrow_t&) throw () 46 | { 47 | if (size == 0) size = 1; 48 | if (void* ptr = scalable_malloc (size)) 49 | return ptr; 50 | return NULL; 51 | } 52 | 53 | void* operator new[] (size_t size, const std::nothrow_t&) throw () 54 | { 55 | return operator new (size, std::nothrow); 56 | } 57 | void operator delete (void* ptr) throw () 58 | { 59 | if (ptr != 0) scalable_free (ptr); 60 | } 61 | void operator delete[] (void* ptr) throw () 62 | { 63 | operator delete (ptr); 64 | } 65 | void operator delete (void* ptr, const std::nothrow_t&) throw () 66 | { 67 | if (ptr != 0) scalable_free (ptr); 68 | } 69 | void operator delete[] (void* ptr, const std::nothrow_t&) throw () 70 | { 71 | operator delete (ptr, std::nothrow); 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /Hive/Source/HiveLib/DataSource/SqlObjDataSource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "SqlDataSource.h" 22 | #include "ObjDataSource.h" 23 | #include "Database/SqlStatement.h" 24 | 25 | namespace Poco { namespace Util { class AbstractConfiguration; }; }; 26 | class SqlObjDataSource : public SqlDataSource, public ObjDataSource 27 | { 28 | public: 29 | SqlObjDataSource(Poco::Logger& logger, shared_ptr db, const Poco::Util::AbstractConfiguration* conf); 30 | ~SqlObjDataSource() {} 31 | 32 | void populateObjects( int serverId, ServerObjectsQueue& queue ) override; 33 | bool updateObjectInventory( int serverId, Int64 objectIdent, bool byUID, const Sqf::Value& inventory ) override; 34 | bool deleteObject( int serverId, Int64 objectIdent, bool byUID ) override; 35 | bool updateVehicleMovement( int serverId, Int64 objectIdent, const Sqf::Value& worldspace, double fuel ) override; 36 | bool updateVehicleStatus( int serverId, Int64 objectIdent, const Sqf::Value& hitPoints, double damage ) override; 37 | bool createObject( int serverId, const string& className, double damage, int characterId, 38 | const Sqf::Value& worldSpace, const Sqf::Value& inventory, const Sqf::Value& hitPoints, double fuel, Int64 uniqueId ) override; 39 | private: 40 | string _objTableName; 41 | int _cleanupPlacedDays; 42 | bool _vehicleOOBReset; 43 | 44 | //statement ids 45 | SqlStatementID _stmtDeleteOldObject; 46 | SqlStatementID _stmtUpdateObjectbyUID; 47 | SqlStatementID _stmtUpdateObjectByID; 48 | SqlStatementID _stmtDeleteObjectByUID; 49 | SqlStatementID _stmtDeleteObjectByID; 50 | SqlStatementID _stmtUpdateVehicleMovement; 51 | SqlStatementID _stmtUpdateVehicleStatus; 52 | SqlStatementID _stmtCreateObject; 53 | }; -------------------------------------------------------------------------------- /Hive/Source/HiveLib/DataSource/CharDataSource.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "CharDataSource.h" 20 | 21 | #include 22 | 23 | namespace 24 | { 25 | enum MeleeAmmoType 26 | { 27 | MELEE_HATCHET, 28 | MELEE_CROWBAR, 29 | MELEE_COUNT 30 | }; 31 | 32 | class MeleeAmmoVisitor : public boost::static_visitor 33 | { 34 | public: 35 | MeleeAmmoType operator()(const string& itemClass) const 36 | { 37 | if (boost::iequals(itemClass,"Hatchet_Swing")) 38 | return MELEE_HATCHET; 39 | else if (boost::iequals(itemClass,"crowbar_swing")) 40 | return MELEE_CROWBAR; 41 | else 42 | return MELEE_COUNT; 43 | } 44 | template MeleeAmmoType operator()(const T& other) const { return MELEE_COUNT; } 45 | }; 46 | } 47 | 48 | int CharDataSource::SanitiseInv( Sqf::Parameters& origInv ) 49 | { 50 | if (origInv.size() != 2) //empty inv or not conforming to [weapons, magazines] layout 51 | return 0; 52 | 53 | map numAmmo; 54 | numAmmo[MELEE_HATCHET] = 0; 55 | numAmmo[MELEE_CROWBAR] = 0; 56 | 57 | try 58 | { 59 | int numErased = 0; 60 | 61 | Sqf::Parameters& magazines = boost::get(origInv.at(1)); 62 | for (auto it=magazines.begin();it!=magazines.end();) 63 | { 64 | MeleeAmmoType ammoType = boost::apply_visitor(MeleeAmmoVisitor(),*it); 65 | if (ammoType != MELEE_COUNT) 66 | { 67 | ++numAmmo[ammoType]; 68 | 69 | if (numAmmo[ammoType] > 1) //erase all but 1st 70 | { 71 | it = magazines.erase(it); 72 | numErased++; 73 | } 74 | else 75 | ++it; 76 | } 77 | else 78 | ++it; 79 | } 80 | 81 | return numErased; 82 | } 83 | catch (const boost::bad_get&) { return 0; } //magazines not an array? 84 | } -------------------------------------------------------------------------------- /Hive/Source/Shared/Common/Exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | template 26 | class GenericException : public ExceptType 27 | { 28 | public: 29 | GenericException(const char* staticName) : ExceptType(staticName) {} 30 | virtual ~GenericException() throw() {} 31 | 32 | virtual std::string toString() const = 0; 33 | const char* what() const throw() { _str = this->toString(); return _str.c_str(); } 34 | void print(Poco::Logger& logger) const { logger.error(this->toString()); } 35 | void print(std::ostream& out) const { out << this->toString() << std::endl; } 36 | private: 37 | mutable std::string _str; 38 | }; 39 | 40 | #include 41 | 42 | #define POCO_DEFINE_EXCEPTION_CODE(API, CLS, BASE, CODE, NAME) \ 43 | class API CLS: public BASE \ 44 | { \ 45 | public: \ 46 | CLS(int code = CODE): BASE(code) {} \ 47 | CLS(const std::string& msg, int code = CODE): BASE(msg, code) {} \ 48 | CLS(const std::string& msg, const std::string& arg, int code = CODE): BASE(msg, arg, code) {} \ 49 | CLS(const std::string& msg, const Poco::Exception& exc, int code = CODE): BASE(msg, exc, code) {} \ 50 | CLS(const CLS& exc): BASE(exc) {} \ 51 | ~CLS() throw() {} \ 52 | CLS& operator = (const CLS& exc) \ 53 | { \ 54 | BASE::operator = (exc); \ 55 | return *this; \ 56 | } \ 57 | const char* name() const throw() {return NAME;} \ 58 | const char* className() const throw() {return typeid(*this).name();} \ 59 | Poco::Exception* clone() const {return new CLS(*this);} \ 60 | void rethrow() const {throw *this;} \ 61 | }; 62 | 63 | #define POCO_DEFINE_EXCEPTION(API, CLS, BASE, NAME) \ 64 | POCO_DEFINE_EXCEPTION_CODE(API, CLS, BASE, 0, NAME) 65 | 66 | -------------------------------------------------------------------------------- /Hive/Source/Database/Field.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include 23 | 24 | class Field 25 | { 26 | public: 27 | enum DataTypes 28 | { 29 | DB_TYPE_UNKNOWN = 0x00, 30 | DB_TYPE_STRING = 0x01, 31 | DB_TYPE_INTEGER = 0x02, 32 | DB_TYPE_FLOAT = 0x03, 33 | DB_TYPE_BOOL = 0x04 34 | }; 35 | 36 | Field() : _value(nullptr), _type(DB_TYPE_UNKNOWN) {} 37 | Field(const char* value, enum DataTypes type) : _value(value), _type(type) {} 38 | ~Field() {} 39 | 40 | DataTypes getType() const { return _type; } 41 | bool isNull() const { return _value == nullptr; } 42 | 43 | const char* getCStr() const { return _value; } 44 | std::string getString() const 45 | { 46 | //std::string s = 0 has undefined result 47 | return _value ? _value : ""; 48 | } 49 | double getDouble() const { return _value ? static_cast(atof(_value)) : 0.0; } 50 | float getFloat() const { return static_cast(getDouble()); } 51 | bool getBool() const { return _value ? atoi(_value) > 0 : false; } 52 | Int32 getInt32() const { return _value ? static_cast(atol(_value)) : Int32(0); } 53 | Int8 getInt8() const { return _value ? static_cast(atol(_value)) : Int8(0); } 54 | UInt8 getUInt8() const { return _value ? static_cast(atol(_value)) : UInt8(0); } 55 | UInt16 getUInt16() const { return _value ? static_cast(atol(_value)) : UInt16(0); } 56 | Int16 getInt16() const { return _value ? static_cast(atol(_value)) : Int16(0); } 57 | UInt32 getUInt32() const { return _value ? static_cast(atol(_value)) : UInt32(0); } 58 | UInt64 getUInt64() const 59 | { 60 | if (!_value) 61 | return 0; 62 | 63 | UInt64 parsedVal; 64 | if (!Poco::NumberParser::tryParseUnsigned64(_value,parsedVal)) 65 | return 0; 66 | 67 | return parsedVal; 68 | } 69 | 70 | void setType(DataTypes type) { _type = type; } 71 | //no need for memory allocations to store resultset field strings 72 | //all we need is to cache pointers returned by different DBMS APIs 73 | void setValue(const char* value) { _value = value; }; 74 | private: 75 | const char* _value; 76 | enum DataTypes _type; 77 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/RetrySqlOp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "SqlConnection.h" 22 | #include "Shared/Common/Timer.h" 23 | #include 24 | #include 25 | 26 | namespace Retry 27 | { 28 | template 29 | struct SqlOp 30 | { 31 | typedef boost::function FuncType; 32 | typedef boost::function SqlStrType; 33 | 34 | SqlOp(Poco::Logger& log_, FuncType runMe_, bool throwExc_ = false) : runMe(runMe_), loggerInst(log_), throwExc(throwExc_) {} 35 | RetVal operator () (SqlConnection& theConn,const char* logStr="",SqlStrType sqlLogFunc = [](){ return ""; }) 36 | { 37 | for (;;) 38 | { 39 | try 40 | { 41 | UInt32 startTime; 42 | if (loggerInst.trace()) 43 | startTime = GlobalTimer::getMSTime(); 44 | RetVal returnMe = runMe(theConn); 45 | if (loggerInst.trace()) 46 | { 47 | std::string sqlStr = sqlLogFunc(); 48 | if (strlen(logStr) < 1 && sqlStr.length() > 0) 49 | logStr = "Operation"; 50 | 51 | if (strlen(logStr) > 0) 52 | { 53 | UInt32 execTime = GlobalTimer::getMSTimeDiff(startTime,GlobalTimer::getMSTime()); 54 | std::string formatStr = string(logStr) + " [%u ms]"; 55 | if (sqlStr.length() > 0) 56 | formatStr += " SQL: '" + sqlStr + "'"; 57 | 58 | loggerInst.trace(Poco::format(formatStr,execTime)); 59 | } 60 | } 61 | return returnMe; 62 | } 63 | catch(const SqlConnection::SqlException& opExc) 64 | { 65 | opExc.toLog(loggerInst); 66 | if (opExc.isConnLost()) 67 | { 68 | try { theConn.connect(); } 69 | catch (const SqlConnection::SqlException& connExc) 70 | { 71 | connExc.toLog(loggerInst); 72 | if (throwExc) 73 | throw connExc; 74 | else 75 | return 0; 76 | } 77 | } 78 | if (throwExc) 79 | throw opExc; 80 | else if (opExc.isRepeatable()) 81 | continue; 82 | else 83 | return 0; 84 | } 85 | } 86 | } 87 | private: 88 | FuncType runMe; 89 | Poco::Logger& loggerInst; 90 | bool throwExc; 91 | }; 92 | }; -------------------------------------------------------------------------------- /Hive/Source/HiveExt/DirectHiveApp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "DirectHiveApp.h" 20 | 21 | DirectHiveApp::DirectHiveApp(string suffixDir) : HiveExtApp(suffixDir) {} 22 | 23 | #include "Shared/Library/Database/DatabaseLoader.h" 24 | #include "HiveLib/DataSource/SqlCharDataSource.h" 25 | #include "HiveLib/DataSource/SqlObjDataSource.h" 26 | 27 | bool DirectHiveApp::initialiseService() 28 | { 29 | //Load up databases 30 | { 31 | Poco::AutoPtr globalDBConf(config().createView("Database")); 32 | Poco::AutoPtr objDBConf(config().createView("ObjectDB")); 33 | 34 | try 35 | { 36 | Poco::Logger& dbLogger = Poco::Logger::get("Database"); 37 | _charDb = DatabaseLoader::Create(globalDBConf); 38 | if (!_charDb->initialise(dbLogger,DatabaseLoader::MakeConnParams(globalDBConf))) 39 | return false; 40 | 41 | _objDb = _charDb; 42 | if (objDBConf->getBool("Use",false)) 43 | { 44 | Poco::Logger& objDBLogger = Poco::Logger::get("ObjectDB"); 45 | _objDb = DatabaseLoader::Create(objDBConf); 46 | if (!_objDb->initialise(objDBLogger,DatabaseLoader::MakeConnParams(objDBConf))) 47 | return false; 48 | } 49 | } 50 | catch (const DatabaseLoader::CreationError& e) 51 | { 52 | logger().critical(e.displayText()); 53 | return false; 54 | } 55 | } 56 | 57 | //Create character datasource 58 | { 59 | static const string defaultID = "PlayerUID"; 60 | static const string defaultWS = "Worldspace"; 61 | 62 | Poco::AutoPtr charDBConf(config().createView("Characters")); 63 | _charData.reset(new SqlCharDataSource(logger(),_charDb,charDBConf->getString("IDField",defaultID),charDBConf->getString("WSField",defaultWS))); 64 | } 65 | 66 | //Create object datasource 67 | { 68 | Poco::AutoPtr objConf(config().createView("Objects")); 69 | _objData.reset(new SqlObjDataSource(logger(),_objDb,objConf.get())); 70 | } 71 | 72 | //Create custom datasource 73 | _customData.reset(new CustomDataSource(logger(),_charDb,_objDb)); 74 | 75 | _charDb->allowAsyncOperations(); 76 | if (_objDb != _charDb) 77 | _objDb->allowAsyncOperations(); 78 | 79 | return true; 80 | } 81 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/SqlPreparedStatement.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | 23 | class SqlConnection; 24 | class SqlStmtField; 25 | class SqlStmtParameters; 26 | 27 | //base prepared statement class 28 | class SqlPreparedStatement 29 | { 30 | public: 31 | virtual ~SqlPreparedStatement() {} 32 | 33 | bool isPrepared() const { return _prepared; } 34 | bool isQuery() const { return _isQuery; } 35 | 36 | size_t numParams() const { return _numParams; } 37 | size_t numColumns() const { return isQuery()?_numColumns:0; } 38 | 39 | //initialize internal structures of prepared statement 40 | //upon success _prepared should be true 41 | virtual void prepare() = 0; 42 | //bind parameters for prepared statement from parameter placeholder 43 | virtual void bind(const SqlStmtParameters& holder) = 0; 44 | 45 | //execute statement w/o result set 46 | virtual bool execute() = 0; 47 | 48 | virtual int lastError() const { return 0; } 49 | virtual std::string lastErrorDescr() const { return ""; } 50 | 51 | virtual std::string getSqlString(bool withValues=false) const 52 | { 53 | if (_stmtLen > 0) 54 | return std::string(_stmtSql,_stmtLen); 55 | 56 | return ""; 57 | } 58 | protected: 59 | SqlPreparedStatement(const char* sqlText, SqlConnection& conn); 60 | 61 | size_t _numParams; 62 | size_t _numColumns; 63 | 64 | bool _isQuery; 65 | bool _prepared; 66 | 67 | const char* _stmtSql; 68 | size_t _stmtLen; 69 | 70 | SqlConnection& _conn; 71 | }; 72 | 73 | //prepared statements via plain SQL string requests 74 | class SqlPlainPreparedStatement : public SqlPreparedStatement 75 | { 76 | public: 77 | SqlPlainPreparedStatement(const char* sqlText, SqlConnection& conn); 78 | ~SqlPlainPreparedStatement() {} 79 | 80 | //nothing to do, we already have the query string 81 | void prepare() override; 82 | 83 | //we should replace all '?' symbols with substrings with proper format 84 | void bind(const SqlStmtParameters& holder) override; 85 | 86 | bool execute() override; 87 | 88 | std::string getSqlString(bool withValues=false) const override; 89 | protected: 90 | void dataToString(const SqlStmtField& data, std::ostringstream& fmt) const; 91 | 92 | std::string _preparedSql; 93 | }; -------------------------------------------------------------------------------- /Hive/Source/Shared/Shared.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {d3432b9a-e190-4157-997f-0e22a0830c33} 6 | 7 | 8 | {af42941c-bc37-493a-910c-41b3aa27b2a2} 9 | 10 | 11 | {de37bd18-611c-4ce6-a94f-cd8ee3e1caa8} 12 | 13 | 14 | {ea9da682-83b1-45d1-bc8f-ea6cd344aded} 15 | 16 | 17 | {8cb2e685-e396-4ed8-add3-2d37c626b6ef} 18 | 19 | 20 | {1894bce0-0f3a-4fae-8120-1b5a065b79d1} 21 | 22 | 23 | 24 | 25 | Common 26 | 27 | 28 | Common 29 | 30 | 31 | Common 32 | 33 | 34 | Library 35 | 36 | 37 | Library\Database 38 | 39 | 40 | Server 41 | 42 | 43 | Common 44 | 45 | 46 | Common 47 | 48 | 49 | Common 50 | 51 | 52 | Common 53 | 54 | 55 | Server\Log 56 | 57 | 58 | Server\Log 59 | 60 | 61 | Server\Log 62 | 63 | 64 | 65 | 66 | Policy 67 | 68 | 69 | Common 70 | 71 | 72 | Library\Database 73 | 74 | 75 | Server 76 | 77 | 78 | Server\Log 79 | 80 | 81 | Server\Log 82 | 83 | 84 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabasePostgre/DatabasePostgre.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "../ConcreteDatabase.h" 22 | #include "../SqlConnection.h" 23 | #include 24 | 25 | #include "postgre.h" 26 | 27 | class PostgreSQLConnection : public SqlConnection 28 | { 29 | public: 30 | //Initialize PostgreSQL library and store credentials 31 | //connParams should contain host,[port],username,password,database 32 | PostgreSQLConnection(ConcreteDatabase& db, const Database::KeyValueColl& connParams); 33 | virtual ~PostgreSQLConnection(); 34 | 35 | //Connect or reconnect using stored credentials 36 | void connect() override; 37 | 38 | unique_ptr query(const char* sql) override; 39 | bool execute(const char* sql) override; 40 | 41 | size_t escapeString(char* to, const char* from, size_t length) const override; 42 | 43 | bool transactionStart() override; 44 | bool transactionCommit() override; 45 | bool transactionRollback() override; 46 | 47 | struct ResultInfo 48 | { 49 | void clear() 50 | { 51 | if (pgRes != nullptr) 52 | { 53 | PQclear(pgRes); 54 | pgRes = nullptr; 55 | } 56 | numRows = 0; 57 | numFields = 0; 58 | } 59 | 60 | ResultInfo() : pgRes(nullptr) { clear(); } 61 | ~ResultInfo() { clear(); } 62 | 63 | ResultInfo(ResultInfo&& rhs) : pgRes(nullptr) 64 | { 65 | clear(); 66 | 67 | using std::swap; 68 | swap(this->pgRes,rhs.pgRes); 69 | swap(this->numFields,rhs.numFields); 70 | swap(this->numRows,rhs.numRows); 71 | } 72 | 73 | PGresult* pgRes; 74 | int numFields; 75 | int numRows; 76 | private: 77 | //only move construction 78 | ResultInfo(const ResultInfo& rhs); 79 | }; 80 | //Returns whether or not result fetching was successfull (false means no more results) 81 | bool _PostgreStoreResult(const char* sql, ResultInfo* outResInfo = nullptr); 82 | private: 83 | bool _ConnectionLost() const; 84 | bool _Query(const char* sql); 85 | 86 | std::string lastErrorDescr(PGresult* maybeRes = nullptr) const; 87 | 88 | std::string _host, _port, _user, _password, _database; 89 | PGconn* _pgConn; 90 | }; 91 | 92 | class DatabasePostgre : public ConcreteDatabase 93 | { 94 | public: 95 | DatabasePostgre(); 96 | ~DatabasePostgre(); 97 | 98 | //Query creation helpers 99 | std::string sqlLike() const override; 100 | std::string sqlTableSim(const std::string& tableName) const override; 101 | std::string sqlConcat(const std::string& a, const std::string& b, const std::string& c) const override; 102 | std::string sqlOffset() const override; 103 | protected: 104 | unique_ptr createConnection(const KeyValueColl& connParams) override; 105 | private: 106 | static size_t db_count; 107 | }; 108 | -------------------------------------------------------------------------------- /Hive/Source/Shared/Server/Log/HiveConsoleChannel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "HiveConsoleChannel.h" 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | namespace 27 | { 28 | bool RedirectIOToConsole() 29 | { 30 | //allocate a console for this app 31 | if (!AllocConsole()) 32 | return false; 33 | 34 | //set the screen buffer to be big enough to let us scroll text 35 | { 36 | //maximum mumber of lines the output console should have 37 | static const WORD MAX_CONSOLE_LINES = 500; 38 | 39 | CONSOLE_SCREEN_BUFFER_INFO coninfo; 40 | GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&coninfo); 41 | coninfo.dwSize.Y = MAX_CONSOLE_LINES; 42 | SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),coninfo.dwSize); 43 | } 44 | 45 | //redirect unbuffered STDOUT to the console 46 | { 47 | intptr_t stdHandle = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE); 48 | int fHandle = _open_osfhandle(stdHandle,_O_TEXT); 49 | FILE* fp = _fdopen(fHandle,"w"); 50 | *stdout = *fp; 51 | setvbuf(stdout,nullptr,_IONBF,0); 52 | } 53 | 54 | //redirect unbuffered STDIN to the console 55 | { 56 | intptr_t stdHandle = (intptr_t)GetStdHandle(STD_INPUT_HANDLE); 57 | int fHandle = _open_osfhandle(stdHandle,_O_TEXT); 58 | FILE* fp = _fdopen(fHandle,"r"); 59 | *stdin = *fp; 60 | setvbuf(stdin,nullptr,_IONBF,0); 61 | } 62 | 63 | //redirect unbuffered STDERR to the console 64 | { 65 | intptr_t stdHandle = (intptr_t)GetStdHandle(STD_ERROR_HANDLE); 66 | int fHandle = _open_osfhandle(stdHandle,_O_TEXT); 67 | FILE* fp = _fdopen(fHandle,"w"); 68 | *stderr = *fp; 69 | setvbuf(stderr,nullptr,_IONBF,0); 70 | } 71 | 72 | //make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well 73 | std::ios::sync_with_stdio(); 74 | 75 | return true; 76 | } 77 | }; 78 | 79 | HiveConsoleChannel::HiveConsoleChannel(std::string windowTitle) : _consoleCreated(false) 80 | { 81 | _consoleCreated = RedirectIOToConsole(); 82 | if (windowTitle.length() > 0) 83 | { 84 | std::wstring wideTitle; 85 | Poco::UnicodeConverter::toUTF16(windowTitle,wideTitle); 86 | SetConsoleTitleW(wideTitle.c_str()); 87 | } 88 | 89 | _hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 90 | } 91 | 92 | HiveConsoleChannel::~HiveConsoleChannel() 93 | { 94 | if (_consoleCreated) 95 | { 96 | FreeConsole(); 97 | _consoleCreated = false; 98 | } 99 | } 100 | 101 | void HiveConsoleChannel::log(const Poco::Message& msg) 102 | { 103 | if (!shouldLog(msg.getPriority())) 104 | return; 105 | 106 | std::string text = msg.getText() + "\r\n"; 107 | { 108 | std::wstring utext; 109 | Poco::UnicodeConverter::toUTF16(text,utext); 110 | DWORD written; 111 | WriteConsoleW(_hConsole,utext.data(),static_cast(utext.size()),&written,nullptr); 112 | } 113 | } -------------------------------------------------------------------------------- /Hive/Source/HiveLib/HiveExtApp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include "Shared/Server/AppServer.h" 23 | 24 | #include "Sqf.h" 25 | #include "DataSource/CharDataSource.h" 26 | #include "DataSource/ObjDataSource.h" 27 | #include "DataSource/CustomDataSource.h" 28 | 29 | #include 30 | #include 31 | 32 | class Database; 33 | class HiveExtApp: public AppServer 34 | { 35 | public: 36 | HiveExtApp(string suffixDir); 37 | virtual ~HiveExtApp() {}; 38 | 39 | struct ServerShutdownException : public std::exception 40 | { 41 | ServerShutdownException(string theKey, Sqf::Value theVal = false) 42 | : _theKey(std::move(theKey)), _theVal(std::move(theVal)) {} 43 | bool keyMatches(const string& otherKey) const 44 | { 45 | return ((_theKey.length() > 0) && (_theKey == otherKey)); 46 | 47 | } 48 | const Sqf::Value& getReturnValue() const { return _theVal; } 49 | private: 50 | string _theKey; 51 | Sqf::Value _theVal; 52 | }; 53 | void callExtension(const char* function, char* output, size_t outputSize); 54 | protected: 55 | int main(const std::vector& args); 56 | 57 | virtual bool initialiseService() = 0; 58 | protected: 59 | void setServerId(int newId) { _serverId = newId; } 60 | int getServerId() const { return _serverId; } 61 | 62 | unique_ptr _charData; 63 | unique_ptr _objData; 64 | unique_ptr _customData; 65 | 66 | string _initKey; 67 | private: 68 | int _serverId; 69 | boost::posix_time::time_duration _timeOffset; 70 | void setupClock(); 71 | 72 | typedef boost::function HandlerFunc; 73 | map handlers; 74 | 75 | Sqf::Value getDateTime(Sqf::Parameters params); 76 | 77 | ObjDataSource::ServerObjectsQueue _srvObjects; 78 | Sqf::Value streamObjects(Sqf::Parameters params); 79 | 80 | Sqf::Value objectPublish(Sqf::Parameters params); 81 | Sqf::Value objectInventory(Sqf::Parameters params, bool byUID = false); 82 | Sqf::Value objectDelete(Sqf::Parameters params, bool byUID = false); 83 | 84 | Sqf::Value vehicleMoved(Sqf::Parameters params); 85 | Sqf::Value vehicleDamaged(Sqf::Parameters params); 86 | 87 | Sqf::Value loadPlayer(Sqf::Parameters params); 88 | Sqf::Value loadCharacterDetails(Sqf::Parameters params); 89 | Sqf::Value recordCharacterLogin(Sqf::Parameters params); 90 | 91 | Sqf::Value playerUpdate(Sqf::Parameters params); 92 | Sqf::Value playerInit(Sqf::Parameters params); 93 | Sqf::Value playerDeath(Sqf::Parameters params); 94 | 95 | Sqf::Value dataRequest(Sqf::Parameters params, bool async = false); 96 | Sqf::Value dataStatus(Sqf::Parameters params); 97 | Sqf::Value dataFetchRow(Sqf::Parameters params); 98 | Sqf::Value dataClose(Sqf::Parameters params); 99 | 100 | Sqf::Value changeTableAccess(Sqf::Parameters params); 101 | Sqf::Value serverShutdown(Sqf::Parameters params); 102 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/QueryResult.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include "Shared/Common/Exception.h" 23 | #include 24 | 25 | #include "Field.h" 26 | typedef std::vector QueryFieldNames; 27 | 28 | class QueryResult : public boost::noncopyable 29 | { 30 | public: 31 | virtual ~QueryResult() {} 32 | 33 | //call before accessing, to populate the row. 34 | //false return value means that there's no more rows 35 | virtual bool fetchRow() = 0; 36 | 37 | virtual const vector& fields() const = 0; 38 | 39 | const Field& at(size_t idx) const 40 | { 41 | if (idx < fields().size()) 42 | return fields()[idx]; 43 | else 44 | return _dummyField; 45 | } 46 | const Field& operator [] (size_t idx) const { return at(idx); } 47 | 48 | virtual size_t numFields() const = 0; 49 | //this will also return number of affected rows for non-SELECT statements 50 | virtual UInt64 numRows() const = 0; 51 | 52 | //gets the field names using vendor-specific calls 53 | virtual QueryFieldNames fetchFieldNames() const = 0; 54 | 55 | //call after getting all the rows to switch to the next result 56 | //false return value means that there's no more results 57 | //after this returns false, all the result information is invalid 58 | virtual bool nextResult() = 0; 59 | protected: 60 | Field _dummyField; 61 | }; 62 | 63 | class QueryNamedResult : public QueryResult 64 | { 65 | public: 66 | QueryNamedResult(unique_ptr query) : _actualRes(std::move(query)) 67 | { 68 | _fieldNames = _actualRes->fetchFieldNames(); 69 | } 70 | ~QueryNamedResult() {} 71 | 72 | bool fetchRow() override { return _actualRes->fetchRow(); } 73 | const vector& fields() const override { return _actualRes->fields(); } 74 | 75 | size_t numFields() const override { return _actualRes->numFields(); } 76 | UInt64 numRows() const override { return _actualRes->numRows(); } 77 | 78 | //get field names by copy 79 | QueryFieldNames fetchFieldNames() const override { return fieldNames(); }; 80 | 81 | //named access 82 | const Field& operator[] (const std::string& name) const { return (*_actualRes)[fieldIdx(name)]; } 83 | //get field names by reference 84 | const QueryFieldNames& fieldNames() const { return _fieldNames; } 85 | 86 | size_t fieldIdx(const std::string& name) const 87 | { 88 | for(size_t idx=0; idx<_fieldNames.size(); idx++) 89 | { 90 | if(_fieldNames[idx] == name) 91 | return idx; 92 | } 93 | poco_bugcheck_msg("unknown field name"); 94 | return size_t(-1); 95 | } 96 | 97 | //also refreshes the field names 98 | bool nextResult() override 99 | { 100 | bool resultValid = _actualRes->nextResult(); 101 | if (resultValid) 102 | _fieldNames = _actualRes->fetchFieldNames(); 103 | else 104 | _fieldNames.clear(); 105 | 106 | return resultValid; 107 | }; 108 | 109 | protected: 110 | unique_ptr _actualRes; 111 | QueryFieldNames _fieldNames; 112 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/Database.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | 23 | #include "QueryResult.h" 24 | #include "SqlStatement.h" 25 | #include "Callback.h" 26 | 27 | namespace Poco { class Logger; }; 28 | 29 | class Database : public boost::noncopyable 30 | { 31 | public: 32 | virtual ~Database() {}; 33 | 34 | typedef std::map KeyValueColl; 35 | virtual bool initialise(Poco::Logger& dbLogger, const KeyValueColl& connParams, bool logSql = false, const std::string& logDir = "", size_t nConns = 1) = 0; 36 | 37 | //start worker thread for async DB request execution 38 | virtual void initDelayThread() = 0; 39 | //stop worker thread 40 | virtual void haltDelayThread() = 0; 41 | 42 | //Synchronous DB queries 43 | virtual unique_ptr query(const char* sql) = 0; 44 | virtual unique_ptr namedQuery(const char* sql) = 0; 45 | 46 | virtual unique_ptr queryParams(const char* format,...) = 0; 47 | virtual unique_ptr namedQueryParams(const char* format,...) = 0; 48 | 49 | virtual bool directExecute(const char* sql) = 0; 50 | virtual bool directExecuteParams(const char* format,...) = 0; 51 | 52 | //Query creation helpers 53 | virtual std::string sqlLike() const = 0; 54 | virtual std::string sqlTableSim(const std::string& tableName) const = 0; 55 | virtual std::string sqlConcat(const std::string& a, const std::string& b, const std::string& c) const = 0; 56 | virtual std::string sqlOffset() const = 0; 57 | 58 | //Async queries and query holders 59 | virtual bool asyncQuery(QueryCallback::FuncType func, const char* sql) = 0; 60 | virtual bool asyncQueryParams(QueryCallback::FuncType func, const char* format, ...) = 0; 61 | 62 | virtual bool execute(const char* sql) = 0; 63 | virtual bool executeParams(const char* format,...) = 0; 64 | 65 | //Writes SQL commands to a LOG file 66 | virtual bool executeParamsLog(const char* format,...) = 0; 67 | 68 | virtual bool transactionStart() = 0; 69 | virtual bool transactionCommit() = 0; 70 | virtual bool transactionRollback() = 0; 71 | //for sync transaction execution 72 | virtual bool transactionCommitDirect() = 0; 73 | 74 | //PREPARED STATEMENT API 75 | 76 | //allocate index for prepared statement with SQL request string 77 | virtual unique_ptr makeStatement(SqlStatementID& index, std::string sqlText) = 0; 78 | 79 | //Is DB ready for requests 80 | virtual operator bool () const = 0; 81 | 82 | //Escape string generation 83 | virtual std::string escape(const std::string& str) const = 0; 84 | 85 | //Call before first query in a thread 86 | virtual void threadEnter() = 0; 87 | //Must be called before the thread that called ThreadStart exits 88 | virtual void threadExit() = 0; 89 | 90 | //Invoke callbacks for finished async queries 91 | virtual void invokeCallbacks() = 0; 92 | 93 | //Check if connection to DB is alive and well 94 | virtual bool checkConnections() = 0; 95 | 96 | //Call this once you're out of global constructor code/DLLMain 97 | virtual void allowAsyncOperations() = 0; 98 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/SqlOperations.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include "Database/Callback.h" 23 | #include "Database/SqlStatement.h" 24 | 25 | #include 26 | #include 27 | 28 | // ---- BASE --- 29 | 30 | class Database; 31 | class SqlConnection; 32 | class SqlDelayThread; 33 | class SqlStmtParameters; 34 | 35 | class SqlOperation 36 | { 37 | public: 38 | virtual void onRemove() { delete this; } 39 | bool execute(SqlConnection& sqlConn); 40 | virtual ~SqlOperation() {} 41 | protected: 42 | friend class SqlTransaction; 43 | //execute as a single thing 44 | virtual bool rawExecute(SqlConnection& sqlConn, bool throwExc = false) = 0; 45 | //execute as part of a transaction (no retries) 46 | typedef boost::function SuccessCallback; 47 | virtual void transExecute(SqlConnection& sqlConn, SuccessCallback& transSuccess) 48 | { 49 | //execute normally, but throw exc on error so we dont retry 50 | this->rawExecute(sqlConn,true); 51 | } 52 | }; 53 | 54 | // ---- ASYNC STATEMENTS / TRANSACTIONS ---- 55 | 56 | class SqlPlainRequest : public SqlOperation 57 | { 58 | public: 59 | SqlPlainRequest(std::string sql) : _sql(std::move(sql)) {}; 60 | ~SqlPlainRequest() {}; 61 | protected: 62 | bool rawExecute(SqlConnection& sqlConn, bool throwExc) override; 63 | private: 64 | std::string _sql; 65 | }; 66 | 67 | class SqlTransaction : public SqlOperation 68 | { 69 | public: 70 | SqlTransaction() {} 71 | ~SqlTransaction() {}; 72 | 73 | void queueOperation(SqlOperation* sql) { _queue.push_back(sql); } 74 | protected: 75 | bool rawExecute(SqlConnection& sqlConn, bool throwExc) override; 76 | private: 77 | boost::ptr_vector _queue; 78 | }; 79 | 80 | class SqlPreparedRequest : public SqlOperation 81 | { 82 | public: 83 | SqlPreparedRequest(const SqlStatementID& stId, SqlStmtParameters& arg) : _id(stId) { _params.swap(arg); } 84 | ~SqlPreparedRequest() {} 85 | protected: 86 | bool rawExecute(SqlConnection& sqlConn, bool throwExc) override; 87 | private: 88 | SqlStatementID _id; 89 | SqlStmtParameters _params; 90 | }; 91 | 92 | // ---- ASYNC QUERIES ---- 93 | 94 | class SqlQuery; //contains a single async query 95 | class QueryResult; //the result of one 96 | class SqlResultQueue; //queue for thread sync 97 | 98 | class SqlResultQueue : public tbb::concurrent_queue 99 | { 100 | public: 101 | SqlResultQueue() {} 102 | void processCallbacks(); 103 | }; 104 | 105 | class SqlQuery : public SqlOperation 106 | { 107 | public: 108 | SqlQuery(std::string sql, QueryCallback callback, SqlResultQueue& queue) : _sql(std::move(sql)), _callback(callback), _queue(&queue) {}; 109 | ~SqlQuery() {}; 110 | protected: 111 | bool rawExecute(SqlConnection& sqlConn, bool throwExc) override; 112 | void transExecute(SqlConnection& sqlConn, SuccessCallback& transSuccess) override; 113 | private: 114 | std::string _sql; 115 | QueryCallback _callback; 116 | SqlResultQueue* _queue; 117 | }; 118 | -------------------------------------------------------------------------------- /Hive/Source/HiveLib/ExtStartup.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "ExtStartup.h" 20 | 21 | #ifdef UNICODE 22 | #include 23 | #endif 24 | 25 | namespace 26 | { 27 | #ifdef UNICODE 28 | #define GetCommandLineWut GetCommandLineW 29 | #define CommandLineToArgv CommandLineToArgvW 30 | #else 31 | #define GetCommandLineWut GetCommandLineA 32 | #define CommandLineToArgv CommandLineToArgvA 33 | #endif 34 | 35 | vector GetCmdLineParams(LPTSTR** argv=NULL, int* argc=NULL) 36 | { 37 | LPTSTR cmdLine = GetCommandLineWut(); 38 | int numCmdLineArgs = 0; 39 | LPTSTR* cmdLineArgs = CommandLineToArgv(cmdLine, &numCmdLineArgs); 40 | if (argv) 41 | *argv = cmdLineArgs; 42 | if (argc) 43 | *argc = numCmdLineArgs; 44 | 45 | vector result; 46 | result.reserve(numCmdLineArgs); 47 | for (int i=0;i 66 | #include 67 | 68 | namespace 69 | { 70 | ExtStartup::MakeAppFunction gMakeAppFunc; 71 | 72 | unique_ptr CreateApp() 73 | { 74 | LPTSTR* argv; 75 | int argc; 76 | auto cmdLine = GetCmdLineParams(&argv,&argc); 77 | 78 | string serverFolder = "@hive"; 79 | for (auto it=cmdLine.begin();it!=cmdLine.end();++it) 80 | { 81 | string starter = "-profiles="; 82 | if (it->length() < starter.length()) 83 | continue; 84 | string compareMe = it->substr(0,starter.length()); 85 | if (!boost::iequals(compareMe,starter)) 86 | continue; 87 | 88 | string rest = it->substr(compareMe.length()); 89 | boost::trim(rest); 90 | 91 | serverFolder = rest; 92 | } 93 | 94 | unique_ptr theApp(gMakeAppFunc(serverFolder)); 95 | { 96 | int appRes = theApp->run(argc, argv); 97 | LocalFree(argv); 98 | 99 | if (appRes == Poco::Util::Application::EXIT_IOERR) 100 | MessageBox(NULL,TEXT("Error connecting to the service"),TEXT("Hive error"),MB_ICONERROR|MB_OK); 101 | else if (appRes == Poco::Util::Application::EXIT_DATAERR) 102 | MessageBox(NULL,TEXT("Error loading required resources"),TEXT("Hive error"),MB_ICONERROR|MB_OK); 103 | else if (appRes != Poco::Util::Application::EXIT_OK) 104 | MessageBox(NULL,TEXT("Unknown internal error"),TEXT("Hive error"),MB_ICONERROR|MB_OK); 105 | 106 | if (appRes != Poco::Util::Application::EXIT_OK) 107 | return nullptr; 108 | else 109 | theApp->enableAsyncLogging(); 110 | } 111 | 112 | return std::move(theApp); 113 | } 114 | }; 115 | 116 | namespace 117 | { 118 | unique_ptr gApp; 119 | }; 120 | 121 | void ExtStartup::InitModule( MakeAppFunction makeAppFunc ) 122 | { 123 | gMakeAppFunc = std::move(makeAppFunc); 124 | } 125 | 126 | void ExtStartup::ProcessShutdown() 127 | { 128 | gApp.reset(); 129 | } 130 | 131 | void CALLBACK RVExtension(char *output, int outputSize, const char* function) 132 | { 133 | if (!gApp) 134 | { 135 | gApp = CreateApp(); 136 | if (!gApp) //error during creation 137 | ExitProcess(1); 138 | } 139 | 140 | try 141 | { 142 | gApp->callExtension(function, output, outputSize); 143 | } 144 | catch(const HiveExtApp::ServerShutdownException&) 145 | { 146 | ExtStartup::ProcessShutdown(); 147 | } 148 | } -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabaseMySql/QueryResultMySql.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "QueryResultMySql.h" 20 | #include "DatabaseMySql.h" 21 | 22 | QueryResultMySql::QueryResultMySql(MySQLConnection* theConn, const char* sql) : _currRes(-1) 23 | { 24 | bool hasAnotherResult = false; 25 | MySQLConnection::ResultInfo resInfo; 26 | do 27 | { 28 | hasAnotherResult = theConn->_MySQLStoreResult(sql,&resInfo); 29 | _results.push_back(std::move(resInfo)); 30 | } 31 | while (hasAnotherResult); 32 | 33 | //gotta have at least one result 34 | poco_assert(nextResult() == true); 35 | } 36 | 37 | QueryResultMySql::~QueryResultMySql() {} 38 | 39 | bool QueryResultMySql::fetchRow() 40 | { 41 | //if we're outta results, there's also no more rows 42 | if (_currRes < 0 || _currRes >= _results.size()) 43 | return false; 44 | 45 | //current result set is in range 46 | const auto& theRes = _results[_currRes]; 47 | 48 | MYSQL_ROW myRow = mysql_fetch_row(theRes.myRes); 49 | if (!myRow) //no more rows in this result set 50 | return false; 51 | 52 | //we got a row, point the pointers 53 | for (size_t i=0; i<_row.size(); i++) 54 | _row[i].setValue(myRow[i]); 55 | 56 | return true; 57 | } 58 | 59 | namespace 60 | { 61 | Field::DataTypes MySQLTypeToFieldType(enum_field_types mysqlType) 62 | { 63 | switch (mysqlType) 64 | { 65 | case FIELD_TYPE_TIMESTAMP: 66 | case FIELD_TYPE_DATE: 67 | case FIELD_TYPE_TIME: 68 | case FIELD_TYPE_DATETIME: 69 | case FIELD_TYPE_YEAR: 70 | case FIELD_TYPE_STRING: 71 | case FIELD_TYPE_VAR_STRING: 72 | case FIELD_TYPE_BLOB: 73 | case FIELD_TYPE_SET: 74 | case FIELD_TYPE_NULL: 75 | return Field::DB_TYPE_STRING; 76 | case FIELD_TYPE_TINY: 77 | case FIELD_TYPE_SHORT: 78 | case FIELD_TYPE_LONG: 79 | case FIELD_TYPE_INT24: 80 | case FIELD_TYPE_LONGLONG: 81 | case FIELD_TYPE_ENUM: 82 | return Field::DB_TYPE_INTEGER; 83 | case FIELD_TYPE_DECIMAL: 84 | case FIELD_TYPE_FLOAT: 85 | case FIELD_TYPE_DOUBLE: 86 | return Field::DB_TYPE_FLOAT; 87 | default: 88 | return Field::DB_TYPE_UNKNOWN; 89 | } 90 | } 91 | } 92 | 93 | bool QueryResultMySql::nextResult() 94 | { 95 | //is the currently selected result in bounds ? if so, free it 96 | if (_currRes >= 0 && _currRes < _results.size()) 97 | _results[_currRes].clear(); 98 | //select next result 99 | _currRes++; 100 | 101 | if (_currRes < _results.size()) 102 | { 103 | const auto& theRes = _results[_currRes]; 104 | setNumFields(theRes.numFields); 105 | setNumRows(theRes.numRows); 106 | 107 | _row.resize(theRes.numFields); 108 | if (_row.size() > 0) 109 | { 110 | poco_assert(theRes.myRes != nullptr); 111 | MYSQL_FIELD* fields = mysql_fetch_fields(theRes.myRes); 112 | for (size_t i=0; i<_row.size(); i++) 113 | { 114 | _row[i].setValue(nullptr); 115 | _row[i].setType(MySQLTypeToFieldType(fields[i].type)); 116 | } 117 | } 118 | 119 | return true; 120 | } 121 | else 122 | { 123 | _results.clear(); 124 | _currRes = -1; 125 | 126 | setNumFields(0); 127 | setNumRows(0); 128 | _row.clear(); 129 | 130 | return false; 131 | } 132 | } 133 | 134 | QueryFieldNames QueryResultMySql::fetchFieldNames() const 135 | { 136 | //if we got no result, can't fetch field names 137 | if (_currRes < 0 || _currRes >= _results.size()) 138 | return QueryFieldNames(); 139 | 140 | const auto& theRes = _results[_currRes]; 141 | QueryFieldNames fieldNames(theRes.numFields); 142 | if (fieldNames.size() > 0) 143 | { 144 | poco_assert(theRes.myRes != nullptr); 145 | MYSQL_FIELD* fields = mysql_fetch_fields(theRes.myRes); 146 | for (size_t i=0; i 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "Shared/Common/Types.h" 22 | #include "Shared/Common/Exception.h" 23 | 24 | #include 25 | #include 26 | 27 | #include "SqlPreparedStatement.h" 28 | 29 | class Database; 30 | class ConcreteDatabase; 31 | class QueryResult; 32 | class QueryNamedResult; 33 | class SqlStatementID; 34 | class SqlStmtParameters; 35 | 36 | class SqlConnection : public boost::noncopyable 37 | { 38 | public: 39 | class SqlException : public Poco::Exception 40 | { 41 | public: 42 | SqlException(int code, const std::string& descr, const char* func, bool connLost = false, bool repeatable = false, std::string query = "") 43 | : Poco::Exception(descr,code), _query(std::move(query)), _function(func), _connLost(connLost), _repeatable(repeatable) {} 44 | 45 | int getCode() const { return this->code(); } 46 | const std::string getDescr() const { return this->message(); } 47 | const char* getFunction() const { return _function; } 48 | const std::string& getQuery() const { return _query; } 49 | 50 | bool isConnLost() const { return _connLost; } 51 | bool isRepeatable() const { return _repeatable; } 52 | 53 | void toStream(std::ostream& ostr) const; 54 | std::string toString() const; 55 | void toLog(Poco::Logger& logger) const; 56 | private: 57 | std::string _query; 58 | const char* _function; 59 | bool _connLost; 60 | bool _repeatable; 61 | }; 62 | 63 | virtual ~SqlConnection() {} 64 | 65 | //called to make sure we are connected (after it breaks, etc) 66 | virtual void connect() = 0; 67 | 68 | //public methods for making queries 69 | virtual unique_ptr query(const char* sql) = 0; 70 | virtual unique_ptr namedQuery(const char* sql); 71 | 72 | //public methods for making requests 73 | virtual bool execute(const char* sql) = 0; 74 | 75 | //escape string generation 76 | virtual size_t escapeString(char* to, const char* from, size_t length) const; 77 | 78 | //nothing do if DB doesn't support transactions 79 | virtual bool transactionStart(); 80 | virtual bool transactionCommit(); 81 | //can't rollback without transaction support 82 | virtual bool transactionRollback(); 83 | 84 | //methods to work with prepared statements 85 | bool executeStmt(const SqlStatementID& stId, const SqlStmtParameters& id); 86 | 87 | //SqlConnection object lock 88 | class Lock 89 | { 90 | public: 91 | Lock(SqlConnection& conn) : _lockedConn(conn) { _lockedConn._connLock.lock(); } 92 | ~Lock() { _lockedConn._connLock.unlock(); } 93 | 94 | SqlConnection* operator->() const { return &_lockedConn; } 95 | private: 96 | SqlConnection& _lockedConn; 97 | }; 98 | 99 | ConcreteDatabase& getDB() { return *_dbEngine; } 100 | //allocate and return prepared statement object 101 | SqlPreparedStatement* getStmt(const SqlStatementID& stId); 102 | protected: 103 | SqlConnection(ConcreteDatabase& db) : _dbEngine(&db) {} 104 | ConcreteDatabase* _dbEngine; 105 | 106 | //make connection-specific prepared statement obj 107 | virtual SqlPreparedStatement* createPreparedStatement(const char* sqlText); 108 | //clear any state (because of reconnects, etc) 109 | virtual void clear(); 110 | 111 | private: 112 | typedef Poco::FastMutex ConnLockType; 113 | ConnLockType _connLock; 114 | 115 | class StmtHolder 116 | { 117 | public: 118 | StmtHolder() {} 119 | ~StmtHolder() { clear(); } 120 | 121 | //remove all statements 122 | void clear(); 123 | 124 | SqlPreparedStatement* getPrepStmtObj(UInt32 stmtId) const; 125 | void insertPrepStmtObj(UInt32 stmtId, SqlPreparedStatement* stmtObj); 126 | unique_ptr releasePrepStmtObj(UInt32 stmtId); 127 | private: 128 | typedef std::vector< unique_ptr > StatementObjVect; 129 | StatementObjVect _storage; 130 | } _stmtHolder; 131 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/SqlPreparedStatement.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "SqlPreparedStatement.h" 20 | #include "Database/Database.h" 21 | #include "SqlConnection.h" 22 | 23 | #include 24 | 25 | SqlPreparedStatement::SqlPreparedStatement( const char* sqlText, SqlConnection& conn ) : 26 | _numParams(0), _numColumns(0), _isQuery(false), _prepared(false), 27 | _stmtSql(sqlText), _stmtLen(strlen(sqlText)), _conn(conn) { } 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | SqlPlainPreparedStatement::SqlPlainPreparedStatement( const char* sqlText, SqlConnection& conn ) : 31 | SqlPreparedStatement(sqlText, conn) {} 32 | 33 | void SqlPlainPreparedStatement::prepare() 34 | { 35 | _numParams = std::count(_stmtSql, _stmtSql+_stmtLen, '?'); 36 | _isQuery = !strnicmp("select",_stmtSql,6); 37 | _prepared = true; 38 | } 39 | 40 | void SqlPlainPreparedStatement::bind( const SqlStmtParameters& holder ) 41 | { 42 | poco_assert(isPrepared()); 43 | 44 | //verify if we bound all needed input parameters 45 | if (_numParams != holder.boundParams()) 46 | { 47 | poco_bugcheck_msg("Not all parameters bound in SqlPlainPreparedStatement"); 48 | return; 49 | } 50 | 51 | //reset resulting plain SQL request 52 | _preparedSql = _stmtSql; 53 | size_t nLastPos = 0; 54 | 55 | const SqlStmtParameters::ParameterContainer& holderArgs = holder.params(); 56 | for (auto it=holderArgs.cbegin(); it!=holderArgs.cend(); ++it) 57 | { 58 | const SqlStmtField& data = (*it); 59 | 60 | nLastPos = _preparedSql.find('?', nLastPos); 61 | if(nLastPos != std::string::npos) 62 | { 63 | //bind parameter 64 | std::ostringstream fmt; 65 | dataToString(data, fmt); 66 | 67 | std::string tmp = fmt.str(); 68 | _preparedSql.replace(nLastPos, 1, tmp); 69 | nLastPos += tmp.length(); 70 | } 71 | } 72 | } 73 | 74 | bool SqlPlainPreparedStatement::execute() 75 | { 76 | poco_assert(isPrepared()); 77 | 78 | if (_preparedSql.empty()) 79 | return false; 80 | 81 | return _conn.execute(_preparedSql.c_str()); 82 | } 83 | 84 | std::string SqlPlainPreparedStatement::getSqlString( bool withValues/*=false*/ ) const 85 | { 86 | if (withValues) 87 | return _preparedSql; 88 | 89 | return SqlPlainPreparedStatement::getSqlString(withValues); 90 | } 91 | 92 | #include 93 | #include "ConcreteDatabase.h" 94 | 95 | void SqlPlainPreparedStatement::dataToString( const SqlStmtField& data, std::ostringstream& fmt ) const 96 | { 97 | switch (data.type()) 98 | { 99 | case SqlStmtField::FIELD_BOOL: fmt << "'" << UInt32(data.toBool()) << "'"; break; 100 | case SqlStmtField::FIELD_UI8: fmt << "'" << UInt32(data.toUint8()) << "'"; break; 101 | case SqlStmtField::FIELD_UI16: fmt << "'" << UInt32(data.toUint16()) << "'"; break; 102 | case SqlStmtField::FIELD_UI32: fmt << "'" << data.toUint32() << "'"; break; 103 | case SqlStmtField::FIELD_UI64: fmt << "'" << data.toUint64() << "'"; break; 104 | case SqlStmtField::FIELD_I8: fmt << "'" << Int32(data.toInt8()) << "'"; break; 105 | case SqlStmtField::FIELD_I16: fmt << "'" << Int32(data.toInt16()) << "'"; break; 106 | case SqlStmtField::FIELD_I32: fmt << "'" << data.toInt32() << "'"; break; 107 | case SqlStmtField::FIELD_I64: fmt << "'" << data.toInt64() << "'"; break; 108 | case SqlStmtField::FIELD_FLOAT: fmt << "'" << data.toFloat() << "'"; break; 109 | case SqlStmtField::FIELD_DOUBLE: fmt << "'" << data.toDouble() << "'"; break; 110 | case SqlStmtField::FIELD_STRING: 111 | { 112 | std::string tmp = _conn.getDB().escape(data.toString()); 113 | fmt << "'" << tmp << "'"; 114 | } 115 | break; 116 | case SqlStmtField::FIELD_BINARY: 117 | { 118 | std::ostringstream ss; 119 | Poco::HexBinaryEncoder(ss).write((char*)data.buff(),data.size()); 120 | ss.flush(); 121 | fmt << "UNHEX('" << ss.str() << "')"; 122 | } 123 | break; 124 | } 125 | } -------------------------------------------------------------------------------- /Hive/Source/Hive.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Shared", "Shared\Shared.vcxproj", "{92C57338-E848-422B-8E81-6F6D11671750}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Database", "Database\Database.vcxproj", "{E0E04F80-0DB4-4946-B956-4BCA754DAB71}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HiveExt", "HiveExt\HiveExt.vcxproj", "{2F502C7B-F168-46C0-B239-F9635237959B}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {92C57338-E848-422B-8E81-6F6D11671750} = {92C57338-E848-422B-8E81-6F6D11671750} 11 | {591D3468-3D70-4D83-B522-BDBD22DC7ADC} = {591D3468-3D70-4D83-B522-BDBD22DC7ADC} 12 | {E0E04F80-0DB4-4946-B956-4BCA754DAB71} = {E0E04F80-0DB4-4946-B956-4BCA754DAB71} 13 | EndProjectSection 14 | EndProject 15 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Restarter", "Restarter\Restarter.vcxproj", "{11AFA4C2-C32F-467D-A7C5-D4B629068E2B}" 16 | EndProject 17 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HiveLib", "HiveLib\HiveLib.vcxproj", "{591D3468-3D70-4D83-B522-BDBD22DC7ADC}" 18 | EndProject 19 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DB", "DB", "{64A7A09C-C971-4934-9B73-D6FD1741CE70}" 20 | EndProject 21 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DatabaseMySql", "Database\Implementation\DatabaseMySql\DatabaseMySql.vcxproj", "{E6BA8EFD-342A-409B-9273-6463009E5DCA}" 22 | EndProject 23 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DatabasePostgre", "Database\Implementation\DatabasePostgre\DatabasePostgre.vcxproj", "{3A94A40D-418F-4890-829D-7CD16EA1AB6C}" 24 | EndProject 25 | Global 26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 27 | Debug|Win32 = Debug|Win32 28 | Release|Win32 = Release|Win32 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {92C57338-E848-422B-8E81-6F6D11671750}.Debug|Win32.ActiveCfg = Debug|Win32 32 | {92C57338-E848-422B-8E81-6F6D11671750}.Debug|Win32.Build.0 = Debug|Win32 33 | {92C57338-E848-422B-8E81-6F6D11671750}.Release|Win32.ActiveCfg = Release|Win32 34 | {92C57338-E848-422B-8E81-6F6D11671750}.Release|Win32.Build.0 = Release|Win32 35 | {E0E04F80-0DB4-4946-B956-4BCA754DAB71}.Debug|Win32.ActiveCfg = Debug|Win32 36 | {E0E04F80-0DB4-4946-B956-4BCA754DAB71}.Debug|Win32.Build.0 = Debug|Win32 37 | {E0E04F80-0DB4-4946-B956-4BCA754DAB71}.Release|Win32.ActiveCfg = Release|Win32 38 | {E0E04F80-0DB4-4946-B956-4BCA754DAB71}.Release|Win32.Build.0 = Release|Win32 39 | {2F502C7B-F168-46C0-B239-F9635237959B}.Debug|Win32.ActiveCfg = Debug|Win32 40 | {2F502C7B-F168-46C0-B239-F9635237959B}.Debug|Win32.Build.0 = Debug|Win32 41 | {2F502C7B-F168-46C0-B239-F9635237959B}.Release|Win32.ActiveCfg = Release|Win32 42 | {2F502C7B-F168-46C0-B239-F9635237959B}.Release|Win32.Build.0 = Release|Win32 43 | {11AFA4C2-C32F-467D-A7C5-D4B629068E2B}.Debug|Win32.ActiveCfg = Debug|Win32 44 | {11AFA4C2-C32F-467D-A7C5-D4B629068E2B}.Debug|Win32.Build.0 = Debug|Win32 45 | {11AFA4C2-C32F-467D-A7C5-D4B629068E2B}.Release|Win32.ActiveCfg = Release|Win32 46 | {11AFA4C2-C32F-467D-A7C5-D4B629068E2B}.Release|Win32.Build.0 = Release|Win32 47 | {591D3468-3D70-4D83-B522-BDBD22DC7ADC}.Debug|Win32.ActiveCfg = Debug|Win32 48 | {591D3468-3D70-4D83-B522-BDBD22DC7ADC}.Debug|Win32.Build.0 = Debug|Win32 49 | {591D3468-3D70-4D83-B522-BDBD22DC7ADC}.Release|Win32.ActiveCfg = Release|Win32 50 | {591D3468-3D70-4D83-B522-BDBD22DC7ADC}.Release|Win32.Build.0 = Release|Win32 51 | {E6BA8EFD-342A-409B-9273-6463009E5DCA}.Debug|Win32.ActiveCfg = Debug|Win32 52 | {E6BA8EFD-342A-409B-9273-6463009E5DCA}.Debug|Win32.Build.0 = Debug|Win32 53 | {E6BA8EFD-342A-409B-9273-6463009E5DCA}.Debug|Win32.Deploy.0 = Debug|Win32 54 | {E6BA8EFD-342A-409B-9273-6463009E5DCA}.Release|Win32.ActiveCfg = Release|Win32 55 | {E6BA8EFD-342A-409B-9273-6463009E5DCA}.Release|Win32.Build.0 = Release|Win32 56 | {E6BA8EFD-342A-409B-9273-6463009E5DCA}.Release|Win32.Deploy.0 = Release|Win32 57 | {3A94A40D-418F-4890-829D-7CD16EA1AB6C}.Debug|Win32.ActiveCfg = Debug|Win32 58 | {3A94A40D-418F-4890-829D-7CD16EA1AB6C}.Debug|Win32.Build.0 = Debug|Win32 59 | {3A94A40D-418F-4890-829D-7CD16EA1AB6C}.Debug|Win32.Deploy.0 = Debug|Win32 60 | {3A94A40D-418F-4890-829D-7CD16EA1AB6C}.Release|Win32.ActiveCfg = Release|Win32 61 | {3A94A40D-418F-4890-829D-7CD16EA1AB6C}.Release|Win32.Build.0 = Release|Win32 62 | {3A94A40D-418F-4890-829D-7CD16EA1AB6C}.Release|Win32.Deploy.0 = Release|Win32 63 | EndGlobalSection 64 | GlobalSection(SolutionProperties) = preSolution 65 | HideSolutionNode = FALSE 66 | EndGlobalSection 67 | GlobalSection(NestedProjects) = preSolution 68 | {E0E04F80-0DB4-4946-B956-4BCA754DAB71} = {64A7A09C-C971-4934-9B73-D6FD1741CE70} 69 | {E6BA8EFD-342A-409B-9273-6463009E5DCA} = {64A7A09C-C971-4934-9B73-D6FD1741CE70} 70 | {3A94A40D-418F-4890-829D-7CD16EA1AB6C} = {64A7A09C-C971-4934-9B73-D6FD1741CE70} 71 | EndGlobalSection 72 | EndGlobal 73 | -------------------------------------------------------------------------------- /Hive/Binaries/HiveExt.ini: -------------------------------------------------------------------------------- 1 | ;This is a comment 2 | ;Comments above a certain setting will provide it's description 3 | 4 | ;The format for a setting is 5 | ;Variable = Value 6 | 7 | ;If you see a commented line of that form, it means that the setting is optional, and the Value shows the default 8 | ;To change from the default, simply uncomment the line and change the Value 9 | 10 | ;This configuration file should be placed inside your server instance's configuration directory (like cfgdayz) 11 | 12 | [Time] 13 | ;Possible values: Local, Custom, Static 14 | ;You cannot use Static on OFFICIAL Hive, it will just revert to Local 15 | ;Type = Local 16 | ;If using Custom type, offset from UTC in hours (can be negative as well) 17 | ;Offset = 0 18 | ;These 2 settings only apply if using Static type (Custom date/time on every server start) 19 | ;The value (0-24) to set the Hour to, if commented or empty then the hour won't be changed 20 | ;Hour = 8 21 | ;The value (DD/MM/YYYY) to set the Date to, if commented or empty then the date won't be changed 22 | ;Date = 4.1.2013 23 | 24 | [Logger] 25 | ;Possible values: trace, debug, information, notice, warning, error, critical, fatal, none 26 | ;They are sorted by importance (low to high), with trace being the most verbose, and none would turn off logging 27 | ;This controls both the file output level, and the console output level 28 | ;Level = information 29 | 30 | ;Uncomment this option to override the logging level for the console only 31 | ;The specified level can only be higher than the global one, setting lower values will have no effect 32 | ;So for example, if you want to have information-level logs in your file, but only warning-level and higher in your console 33 | ;You would uncomment this option and set it to warning 34 | ;Leaving it commented out means there's no special level for the console, so it will just use the global one 35 | ;ConsoleLevel = information 36 | 37 | ;By default, the HiveExt console log output will go to the Arma2 server window, with colour highlighing by importance 38 | ;If you want to use the old style, separate windows console window for the HiveExt log output, set this option to true 39 | ;SeparateConsole = false 40 | 41 | [Database] 42 | ;Hostname or IP of the server to connect to 43 | ;You can use the value "." (without quotes) to indicate named-pipe localhost connection 44 | ;If you leave this line commented or blank, HiveExt will connect to the OFFICIAL Hive, which requires registration 45 | ;See support.dayzmod.com for more information on what OFFICIAL Hive means, what are the rules, etc. 46 | ;If using OFFICIAL hive, the rest of the settings in this section have no effect 47 | ;Host = localhost 48 | 49 | ;The default is MySql, which is better supported than Postgre (completely untested) 50 | ;Type = MySql 51 | 52 | ;Port to connect to. The default is the default listening port of a server of the selected Type 53 | ;Instead of specifying Port, you can specify Socket and set Value to the socket name 54 | ;Port = 3306 55 | 56 | ;Database name to connect to (you must supply this if private). 57 | ;Database = 58 | 59 | ;Username to connect with 60 | ;Username = root 61 | ;Password to authenticate with (default is blank) 62 | ;Password = 63 | 64 | ;If using OFFICIAL hive, the settings in this section have no effect, appropriate layout will be used 65 | [Characters] 66 | ;The field name that Player's IDs are stored in (unique per game license) 67 | ;Some table layouts have this as PlayerID, and some as PlayerUID, that's why this is configurable 68 | ;IDField = PlayerUID 69 | ;The field name that Player's World Position and rotation is stored in 70 | ;Enables you to run multiple different maps (different instances) off the same character table 71 | ;WSField = Worldspace 72 | 73 | ;If using OFFICIAL hive, the settings in this section have no effect, as it will clean up by itself 74 | [Objects] 75 | ;Which table should the objects be stored and fetched from ? 76 | ;Table = Object_DATA 77 | 78 | ;Negative values will disable this feature 79 | ;0 means that ALL empty placed items will be deleted every server restart 80 | ;A positive number is how old (in days) a placed empty item must be, in order for it to be deleted 81 | ;CleanupPlacedAfterDays = 6 82 | 83 | ;Flag indicating whether hiveext should detect vehicles out of map boundaries (X < 0, or Y > 15360) and reset their position to [] 84 | ;Note: YOU MUST have a proper dayz_server.pbo that supports this feature, otherwise you will get script errors 85 | ;You can find that file under the SQF directory for your server version 86 | ;ResetOOBVehicles = false 87 | 88 | ;If using OFFICIAL hive, the settings in this section have no effect, it will manage objects on its own 89 | [ObjectDB] 90 | ;Setting this to true separates the Object fetches from the Character fetches 91 | ;That means that the Object Table must be on this other database 92 | ;Use = false 93 | 94 | ;The settings here have the same meaning as in [Database], and are only used if the setting above is set to true 95 | ;Type = MySql 96 | ;Host = localhost 97 | ;Port = 3306 98 | ;Database = 99 | ;Username = root 100 | ;Password = -------------------------------------------------------------------------------- /Hive/Source/Restarter/Restarter.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | {11AFA4C2-C32F-467D-A7C5-D4B629068E2B} 18 | Win32Proj 19 | Restarter 20 | 21 | 22 | 23 | Application 24 | true 25 | Unicode 26 | v110 27 | 28 | 29 | Application 30 | false 31 | true 32 | Unicode 33 | v110 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | true 51 | 52 | 53 | false 54 | 55 | 56 | 57 | 58 | 59 | Level3 60 | Disabled 61 | %(PreprocessorDefinitions) 62 | MultiThreadedDebugDLL 63 | %(AdditionalIncludeDirectories) 64 | 65 | 66 | Console 67 | true 68 | %(AdditionalLibraryDirectories) 69 | Version.lib;%(AdditionalDependencies) 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | Level3 78 | 79 | 80 | MaxSpeed 81 | true 82 | true 83 | %(PreprocessorDefinitions) 84 | MultiThreadedDLL 85 | %(AdditionalIncludeDirectories) 86 | 87 | 88 | Console 89 | true 90 | true 91 | true 92 | %(AdditionalLibraryDirectories) 93 | Version.lib;%(AdditionalDependencies) 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabaseMySql/DatabaseMySql.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "../ConcreteDatabase.h" 22 | #include "../SqlConnection.h" 23 | #include "../SqlPreparedStatement.h" 24 | 25 | #ifdef WIN32 26 | #include 27 | #include 28 | #else 29 | #include 30 | #endif 31 | 32 | class MySQLConnection; 33 | //MySQL prepared statement class 34 | class MySqlPreparedStatement : public SqlPreparedStatement 35 | { 36 | public: 37 | MySqlPreparedStatement(const char* sqlText, MySQLConnection& conn); 38 | ~MySqlPreparedStatement(); 39 | 40 | //prepare statement 41 | void prepare() override; 42 | 43 | //bind input parameters 44 | void bind(const SqlStmtParameters& holder) override; 45 | 46 | //execute DML statement 47 | bool execute() override; 48 | 49 | int lastError() const override; 50 | std::string lastErrorDescr() const override; 51 | 52 | std::string getSqlString(bool withValues=false) const override 53 | { 54 | std::string retStr = SqlPreparedStatement::getSqlString(); 55 | if (withValues) 56 | retStr += bindParamsToStr(); 57 | 58 | return retStr; 59 | } 60 | protected: 61 | //bind parameters 62 | void addParam(size_t nIndex, const SqlStmtField& data); 63 | private: 64 | void unprepare(); 65 | std::string bindParamsToStr() const; 66 | 67 | class MySQLConnection& _mySqlConn; 68 | MYSQL_STMT* _myStmt; 69 | std::vector _myArgs; 70 | std::vector _myRes; 71 | MYSQL_RES* _myResMeta; 72 | }; 73 | 74 | class MySQLConnection : public SqlConnection 75 | { 76 | public: 77 | //Initialize MySQL library and store credentials 78 | //connParams should contain host,[port],username,password,database 79 | MySQLConnection(ConcreteDatabase& db, const Database::KeyValueColl& connParams); 80 | ~MySQLConnection(); 81 | 82 | //Connect or reconnect using stored credentials 83 | void connect() override; 84 | 85 | unique_ptr query(const char* sql) override; 86 | bool execute(const char* sql); 87 | 88 | size_t escapeString(char* to, const char* from, size_t length) const override; 89 | 90 | bool transactionStart() override; 91 | bool transactionCommit() override; 92 | bool transactionRollback() override; 93 | 94 | struct ResultInfo 95 | { 96 | void clear() 97 | { 98 | if (myRes != nullptr) 99 | { 100 | mysql_free_result(myRes); 101 | myRes = nullptr; 102 | } 103 | numRows = 0; 104 | numFields = 0; 105 | } 106 | 107 | ResultInfo() : myRes(nullptr) { clear(); } 108 | ~ResultInfo() { clear(); } 109 | 110 | ResultInfo(ResultInfo&& rhs) : myRes(nullptr) 111 | { 112 | clear(); 113 | 114 | using std::swap; 115 | swap(this->myRes,rhs.myRes); 116 | swap(this->numFields,rhs.numFields); 117 | swap(this->numRows,rhs.numRows); 118 | } 119 | 120 | MYSQL_RES* myRes; 121 | size_t numFields; 122 | UInt64 numRows; 123 | 124 | private: 125 | //only move construction 126 | ResultInfo(const ResultInfo& rhs); 127 | }; 128 | //Returns whether or not there are more results to be fetched (by again calling this method) 129 | bool _MySQLStoreResult(const char* sql, ResultInfo* outResInfo = nullptr); 130 | 131 | MYSQL_STMT* _MySQLStmtInit(); 132 | void _MySQLStmtPrepare(const SqlPreparedStatement& who, MYSQL_STMT* stmt, const char* sqlText, size_t textLen); 133 | void _MySQLStmtExecute(const SqlPreparedStatement& who, MYSQL_STMT* stmt); 134 | protected: 135 | SqlPreparedStatement* createPreparedStatement(const char* sqlText) override; 136 | private: 137 | bool _Query(const char* sql); 138 | 139 | std::string _host, _user, _password, _database; 140 | int _port; 141 | std::string _unixSocket; 142 | 143 | MYSQL* _myHandle; 144 | MYSQL* _myConn; 145 | }; 146 | 147 | class DatabaseMySql : public ConcreteDatabase 148 | { 149 | public: 150 | DatabaseMySql(); 151 | ~DatabaseMySql(); 152 | 153 | // must be call before first query in thread 154 | void threadEnter() override; 155 | // must be call before the thread has finished running 156 | void threadExit() override; 157 | 158 | //Query creation helpers 159 | std::string sqlLike() const override; 160 | std::string sqlTableSim(const std::string& tableName) const override; 161 | std::string sqlConcat(const std::string& a, const std::string& b, const std::string& c) const override; 162 | std::string sqlOffset() const override; 163 | 164 | protected: 165 | unique_ptr createConnection(const KeyValueColl& connParams) override; 166 | 167 | private: 168 | static size_t db_count; 169 | }; -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/SqlOperations.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "SqlOperations.h" 20 | #include "Database/QueryResult.h" 21 | #include "SqlDelayThread.h" 22 | #include "SqlConnection.h" 23 | #include "SqlPreparedStatement.h" 24 | 25 | #include 26 | #include 27 | 28 | #include "ConcreteDatabase.h" 29 | #include "RetrySqlOp.h" 30 | 31 | 32 | // ---- ASYNC STATEMENTS / TRANSACTIONS ---- 33 | bool SqlOperation::execute( SqlConnection& sqlConn ) 34 | { 35 | SqlConnection::Lock guard(sqlConn); 36 | return rawExecute(sqlConn); 37 | } 38 | 39 | bool SqlPlainRequest::rawExecute(SqlConnection& sqlConn, bool throwExc) 40 | { 41 | //just do it 42 | return Retry::SqlOp(sqlConn.getDB().getLogger(),[&](SqlConnection& c){ return c.execute(_sql.c_str()); }, throwExc) 43 | (sqlConn,"PlainRequest",[&](){ return _sql; }); 44 | } 45 | 46 | bool SqlTransaction::rawExecute(SqlConnection& sqlConn, bool throwExc) 47 | { 48 | if(_queue.empty()) 49 | return true; 50 | 51 | for (;;) 52 | { 53 | try 54 | { 55 | //the only time this returns false is when transactions aren't supported, so bail out 56 | //all other errors will throw a SqlException 57 | if (!sqlConn.transactionStart()) 58 | return false; 59 | 60 | vector callUsWhenDone; 61 | for (auto it=_queue.begin(); it!=_queue.end(); ++it) 62 | { 63 | SuccessCallback callMeOnDone; 64 | it->transExecute(sqlConn,callMeOnDone); 65 | 66 | if (!callMeOnDone.empty()) 67 | callUsWhenDone.push_back(std::move(callMeOnDone)); 68 | } 69 | 70 | poco_assert(sqlConn.transactionCommit() == true); 71 | 72 | //whole transaction came through, which means all the callbacks have good data 73 | for (size_t i=0; i(sqlConn.getDB().getLogger(),[&](SqlConnection& c){ return c.executeStmt(_id, _params); }, throwExc) 117 | (sqlConn,"PreparedRequest",[&](){ return sqlConn.getStmt(_id)->getSqlString(true); }); 118 | } 119 | 120 | // ---- ASYNC QUERIES ---- 121 | bool SqlQuery::rawExecute(SqlConnection& sqlConn, bool throwExc) 122 | { 123 | if(!_queue) 124 | return false; 125 | 126 | //execute the query and store the result in the callback 127 | { 128 | auto res = Retry::SqlOp>(sqlConn.getDB().getLogger(),[&](SqlConnection& c){ return c.query(_sql.c_str()); }, throwExc) 129 | (sqlConn,"AsyncQuery",[&](){ return _sql; }); 130 | _callback.setResult(res.release()); 131 | } 132 | 133 | //this is set only if we're part of a transaction 134 | //we can only process the calback immediately if we aren't 135 | if (!throwExc) 136 | { 137 | //add the callback to the sql result queue of the thread it originated from 138 | _queue->push(_callback); 139 | } 140 | 141 | return true; 142 | } 143 | 144 | void SqlQuery::transExecute( SqlConnection& sqlConn, SuccessCallback& transSuccess ) 145 | { 146 | SqlOperation::transExecute(sqlConn,transSuccess); 147 | //the callback should now be primed with the result (or lack of) 148 | //on complete transaction success, we will push it to the queue 149 | transSuccess = [&]() { _queue->push(_callback); }; 150 | } 151 | 152 | void SqlResultQueue::processCallbacks() 153 | { 154 | //execute the callbacks waiting in the synchronization queue 155 | QueryCallback callMe; 156 | while (this->try_pop(callMe)) 157 | callMe.invoke(); 158 | } 159 | -------------------------------------------------------------------------------- /Hive/Source/Shared/Server/AppServer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "AppServer.h" 20 | #include "Log/ArmaConsoleChannel.h" 21 | #include "Log/HiveConsoleChannel.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | void AppServer::initialize( Application& self ) 33 | { 34 | ServerApplication::initialize(self); 35 | 36 | if (appDir.length() < 1) 37 | appDir = config().getString("application.dir"); 38 | else 39 | { 40 | auto cwd = Poco::Path(Poco::Path::current()); 41 | cwd.resolve(Poco::Path(appDir)); 42 | appDir = cwd.toString(); 43 | if (appDir[appDir.length()-1] != Poco::Path::separator()) 44 | appDir += Poco::Path::separator(); 45 | } 46 | 47 | if (appName.length() < 1) 48 | appName = config().getString("application.baseName"); 49 | 50 | initConfig(); 51 | initLogger(); 52 | } 53 | 54 | void AppServer::uninitialize() 55 | { 56 | ServerApplication::uninitialize(); 57 | } 58 | 59 | #include 60 | 61 | void AppServer::initConfig() 62 | { 63 | try 64 | { 65 | loadConfiguration(appDir+appName+std::string(".ini")); 66 | } 67 | catch(const Poco::IOException& e) 68 | { 69 | std::cout << "Unable to load configuration: " << e.displayText() << std::endl; 70 | } 71 | } 72 | 73 | void AppServer::initLogger() 74 | { 75 | using Poco::AutoPtr; 76 | using Poco::ConsoleChannel; 77 | using Poco::FileChannel; 78 | using Poco::SplitterChannel; 79 | using Poco::FormattingChannel; 80 | using Poco::PatternFormatter; 81 | using Poco::Util::AbstractConfiguration; 82 | using Poco::Logger; 83 | 84 | AutoPtr logConf(config().createView("Logger")); 85 | AutoPtr splitChan(new SplitterChannel); 86 | 87 | //Set up the file channel 88 | { 89 | AutoPtr fileChan(new FileChannel); 90 | fileChan->setProperty("path", appDir+logConf->getString("Filename",appName+std::string(".log")) ); 91 | fileChan->setProperty("rotation", logConf->getString("Rotation","never") ); 92 | fileChan->setProperty("archive", "timestamp"); 93 | fileChan->setProperty("times", "local"); 94 | 95 | AutoPtr fileFormatter(new PatternFormatter); 96 | fileFormatter->setProperty("pattern", logConf->getString("FilePattern","%Y-%m-%d %H:%M:%S %s: [%p] %t")); 97 | fileFormatter->setProperty("times", "local"); 98 | 99 | AutoPtr fileFormatChan(new FormattingChannel(fileFormatter, fileChan)); 100 | splitChan->addChannel(fileFormatChan); 101 | } 102 | //Set up the console channel 103 | { 104 | bool useRealConsole = true; 105 | #ifndef _DEBUG 106 | useRealConsole = logConf->getBool("SeparateConsole",false); 107 | #endif 108 | AutoPtr consoleChan; 109 | if (useRealConsole) 110 | { 111 | string title = appName; 112 | if (appDir.length() > 1) 113 | { 114 | Poco::Path dirPath(appDir); 115 | if (dirPath.depth() > 0) 116 | title += " - " + dirPath[dirPath.depth()-1]; 117 | } 118 | 119 | consoleChan = new HiveConsoleChannel(std::move(title)); 120 | } 121 | else 122 | consoleChan = new ArmaConsoleChannel; 123 | 124 | if (logConf->hasProperty("ConsoleLevel")) 125 | consoleChan->overrideLevel(Poco::Logger::parseLevel(logConf->getString("ConsoleLevel"))); 126 | 127 | AutoPtr consoleFormatter(new PatternFormatter); 128 | consoleFormatter->setProperty("pattern", logConf->getString("ConsolePattern","%H:%M:%S %s(%I): [%p] %t") ); 129 | consoleFormatter->setProperty("times", "local"); 130 | 131 | AutoPtr consFormatChan(new FormattingChannel(consoleFormatter, consoleChan)); 132 | splitChan->addChannel(consFormatChan); 133 | } 134 | Logger::root().setChannel(splitChan); 135 | 136 | std::string loggingLevel = Poco::toLower(logConf->getString("Level","information")); 137 | Logger::root().setLevel(loggingLevel); 138 | 139 | this->setLogger(Logger::get(appName)); 140 | } 141 | 142 | void AppServer::enableAsyncLogging() 143 | { 144 | using Poco::Logger; 145 | using Poco::AutoPtr; 146 | using Poco::SplitterChannel; 147 | using Poco::AsyncChannel; 148 | 149 | SplitterChannel* splitChan = dynamic_cast(Logger::root().getChannel()); 150 | if (splitChan != nullptr) //only if its not async already 151 | { 152 | //make it async 153 | AutoPtr asyncChan(new AsyncChannel(splitChan)); 154 | Logger::setChannel("",asyncChan); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /Hive/Source/HiveExt/Main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "HiveLib/ExtStartup.h" 20 | #include "DirectHiveApp.h" 21 | 22 | BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 23 | { 24 | switch (ul_reason_for_call) 25 | { 26 | case DLL_PROCESS_ATTACH: 27 | ExtStartup::InitModule([](string profileFolder){ return new DirectHiveApp(profileFolder); }); 28 | break; 29 | case DLL_THREAD_ATTACH: 30 | break; 31 | case DLL_THREAD_DETACH: 32 | break; 33 | case DLL_PROCESS_DETACH: 34 | ExtStartup::ProcessShutdown(); 35 | break; 36 | } 37 | return TRUE; 38 | } 39 | 40 | int main() 41 | { 42 | Sqf::runTest(); 43 | 44 | //#define DEBUG_SPLIT_TESTS 45 | #ifdef DEBUG_SPLIT_TESTS 46 | using boost::lexical_cast; 47 | 48 | DllMain(NULL,DLL_PROCESS_ATTACH,NULL); 49 | char testOutBuf[4096]; 50 | RVExtension(testOutBuf,sizeof(testOutBuf),"CHILD:307:"); 51 | #define CUSTOMDATA_TESTS 52 | #ifdef CUSTOMDATA_TESTS 53 | RVExtension(testOutBuf,sizeof(testOutBuf),"CHILD:302:1337:"); 54 | Sqf::Parameters objStreamStart = boost::get(lexical_cast(string(testOutBuf))); 55 | poco_assert(boost::get(objStreamStart.at(0)) == "ObjectStreamStart"); 56 | string magicKey = boost::get(objStreamStart.at(2)); 57 | for (size_t i=0; i(objStreamStart.at(1)); i++) 58 | { 59 | RVExtension(testOutBuf,sizeof(testOutBuf),"CHILD:302:1337:"); 60 | Sqf::Parameters objInfo = boost::get(lexical_cast(string(testOutBuf))); 61 | string objDump = lexical_cast(Sqf::Value(objInfo)); 62 | } 63 | RVExtension(testOutBuf,sizeof(testOutBuf),string("CHILD:500:"+magicKey+":Character.characters:").c_str()); 64 | 65 | vector dbTests; 66 | dbTests.push_back("CHILD:502:Character.characters:[\"charId\",\"status\",\"handle\"]:[\"( (\",[\"charId\",\"!=\",\"7\"],\"))\"]:[0,10]:"); 67 | dbTests.push_back("CHILD:501:Character.characters:[\"charId\",\"status\",\"handle\"]:[]:"); 68 | dbTests.push_back("CHILD:503:"); 69 | dbTests.push_back("CHILD:504:353253:"); 70 | dbTests.push_back("CHILD:505:sdmf:"); 71 | dbTests.push_back("CHILD:503:132:"); 72 | dbTests.push_back("CHILD:504:aaaaaaaa:"); 73 | dbTests.push_back("CHILD:505:353253:"); 74 | for (auto it=dbTests.begin(); it!=dbTests.end(); ++it) 75 | { 76 | RVExtension(testOutBuf,sizeof(testOutBuf),it->c_str()); 77 | string token; 78 | { 79 | auto firstResponse = boost::get(lexical_cast(string(testOutBuf))); 80 | string firstMsg = boost::get(firstResponse.at(0)); 81 | if (firstMsg == "PASS") 82 | token = boost::get(firstResponse.at(1)); 83 | else 84 | continue; 85 | } 86 | 87 | int numRows = 0; 88 | for (;;) 89 | { 90 | string reqStr = "CHILD:503:" + token + ":"; 91 | RVExtension(testOutBuf,sizeof(testOutBuf),reqStr.c_str()); 92 | auto detailsResp = boost::get(lexical_cast(string(testOutBuf))); 93 | string detailsMsg = boost::get(detailsResp.at(0)); 94 | 95 | if (detailsMsg == "WAIT") 96 | { 97 | Sleep(10); 98 | continue; 99 | } 100 | 101 | if (detailsMsg != "PASS") 102 | break; 103 | else 104 | { 105 | numRows = Sqf::GetIntAny(detailsResp.at(1)); 106 | break; 107 | } 108 | } 109 | 110 | for (int i=0; i< numRows+2; i++) 111 | { 112 | string reqStr = "CHILD:504:" + token + ":"; 113 | RVExtension(testOutBuf,sizeof(testOutBuf),reqStr.c_str()); 114 | 115 | auto rowResp = boost::get(lexical_cast(string(testOutBuf))); 116 | string rowMsg = boost::get(rowResp.at(0)); 117 | 118 | if (rowMsg != "PASS") 119 | { 120 | if (rowMsg != "NOMORE") 121 | break; 122 | } 123 | } 124 | 125 | string reqStr = "CHILD:505:" + token + ":"; 126 | RVExtension(testOutBuf,sizeof(testOutBuf),reqStr.c_str()); 127 | auto closeResp = boost::get(lexical_cast(string(testOutBuf))); 128 | string closeMsg = boost::get(closeResp.at(0)); 129 | 130 | if (closeMsg != "PASS") 131 | continue; 132 | } 133 | 134 | #else 135 | RVExtension(testOutBuf,sizeof(testOutBuf),"CHILD:302:1337:"); 136 | RVExtension(testOutBuf,sizeof(testOutBuf),"CHILD:201:12662:[]:[]:[]:[false,false,false,false,false,false,true,10130.1,any,[0.837194,0],0,[0,0]]:false:false:0:0:0:0:[]:0:0:Survivor3_DZ:0:"); 137 | RVExtension(testOutBuf,sizeof(testOutBuf),"CHILD:201:5700692:[80,[2588.59,10073.7,0.001]]:"); 138 | RVExtension(testOutBuf,sizeof(testOutBuf),"CHILD:308:1311:Wire_cat1:0:6255222:[329.449,[10554.4,3054.12,0]]:[]:[]:0:1.055e14:"); 139 | RVExtension(testOutBuf,sizeof(testOutBuf),"CHILD:101:23572678:1311:Audris:"); 140 | #endif 141 | 142 | DllMain(NULL,DLL_PROCESS_DETACH,NULL); 143 | #endif 144 | 145 | return 0; 146 | } -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/SqlConnection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2012 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "SqlConnection.h" 20 | #include "ConcreteDatabase.h" 21 | #include "SqlPreparedStatement.h" 22 | 23 | #include 24 | 25 | void SqlConnection::SqlException::toStream( std::ostream& ostr ) const 26 | { 27 | if (isConnLost()) 28 | ostr << "Connection lost (" << getDescr() << ") during "; 29 | else 30 | ostr << "Error " << getCode() << " (" << getDescr() << ") in "; 31 | 32 | ostr << getFunction(); 33 | 34 | if (getQuery().length() > 0) 35 | ostr << " SQL: '" << getQuery() << "'"; 36 | if (isRepeatable()) 37 | ostr << " , retrying..."; 38 | } 39 | 40 | std::string SqlConnection::SqlException::toString() const 41 | { 42 | std::ostringstream str; 43 | toStream(str); 44 | return str.str(); 45 | } 46 | 47 | void SqlConnection::SqlException::toLog( Poco::Logger& logger ) const 48 | { 49 | if (isRepeatable()) 50 | logger.warning(this->toString()); 51 | else 52 | logger.error(this->toString()); 53 | } 54 | 55 | ////////////////////////////////////////////////////////////////////////// 56 | SqlPreparedStatement* SqlConnection::createPreparedStatement( const char* sqlText ) 57 | { 58 | return new SqlPlainPreparedStatement(sqlText, *this); 59 | } 60 | 61 | void SqlConnection::clear() 62 | { 63 | SqlConnection::Lock guard(*this); 64 | _stmtHolder.clear(); 65 | } 66 | 67 | SqlPreparedStatement* SqlConnection::getStmt( const SqlStatementID& stId ) 68 | { 69 | if(!stId.isInitialized()) 70 | return nullptr; 71 | 72 | UInt32 stmtId = stId.getId(); 73 | SqlPreparedStatement* pStmt = _stmtHolder.getPrepStmtObj(stmtId); 74 | 75 | //create stmt obj if needed 76 | if(pStmt == nullptr) 77 | { 78 | //obtain SQL request string 79 | const char* sqlText = _dbEngine->getStmtString(stmtId); 80 | if (!sqlText || !sqlText[0]) 81 | poco_bugcheck_msg("Blank sql statment string!"); 82 | 83 | //allocate SqlPreparedStatement object 84 | pStmt = createPreparedStatement(sqlText); 85 | //prepare statement 86 | pStmt->prepare(); 87 | 88 | //save statement in internal registry 89 | _stmtHolder.insertPrepStmtObj(stmtId,pStmt); 90 | } 91 | 92 | return pStmt; 93 | } 94 | 95 | bool SqlConnection::executeStmt( const SqlStatementID& stId, const SqlStmtParameters& params ) 96 | { 97 | if(!stId.isInitialized()) 98 | return false; 99 | 100 | //get prepared statement object 101 | SqlPreparedStatement* pStmt = getStmt(stId); 102 | //bind parameters 103 | pStmt->bind(params); 104 | //execute statement 105 | try { return pStmt->execute(); } 106 | catch(const SqlException& e) 107 | { 108 | if (e.isConnLost() || e.isRepeatable()) 109 | { 110 | //destroy prepared statement since there was an error in its execution 111 | _stmtHolder.releasePrepStmtObj(stId.getId()); 112 | } 113 | 114 | //retry or log error as usual 115 | throw e; 116 | } 117 | } 118 | 119 | unique_ptr SqlConnection::namedQuery( const char* sql ) 120 | { 121 | unique_ptr realRes = this->query(sql); 122 | if (!realRes) 123 | return nullptr; 124 | 125 | //fetches the field names in it's constructor, and wraps nextResult to keep them updated 126 | return unique_ptr(new QueryNamedResult(std::move(realRes))); 127 | } 128 | 129 | size_t SqlConnection::escapeString( char* to, const char* from, size_t length ) const 130 | { 131 | strncpy(to,from,length); 132 | return length; 133 | } 134 | 135 | bool SqlConnection::transactionStart() 136 | { 137 | return false; 138 | } 139 | 140 | bool SqlConnection::transactionCommit() 141 | { 142 | return false; 143 | } 144 | 145 | bool SqlConnection::transactionRollback() 146 | { 147 | return false; 148 | } 149 | 150 | void SqlConnection::StmtHolder::clear() 151 | { 152 | _storage.clear(); 153 | } 154 | 155 | SqlPreparedStatement* SqlConnection::StmtHolder::getPrepStmtObj( UInt32 stmtId ) const 156 | { 157 | if (stmtId < 1) 158 | return nullptr; 159 | 160 | size_t idx = stmtId-1; 161 | 162 | if (idx < _storage.size()) 163 | return _storage[idx].get(); 164 | else 165 | return nullptr; 166 | } 167 | 168 | void SqlConnection::StmtHolder::insertPrepStmtObj( UInt32 stmtId, SqlPreparedStatement* stmtObj ) 169 | { 170 | if (stmtId < 1) 171 | poco_bugcheck_msg("Trying to insert uninitialized stmt into conn"); 172 | 173 | size_t idx = stmtId-1; 174 | if (idx >= _storage.size()) 175 | _storage.resize(idx+1); 176 | 177 | if (_storage[idx]) 178 | poco_bugcheck_msg("Inserting conn stmt into already occupied slot"); 179 | 180 | _storage[idx].reset(stmtObj); 181 | } 182 | 183 | unique_ptr SqlConnection::StmtHolder::releasePrepStmtObj( UInt32 stmtId ) 184 | { 185 | if (stmtId < 1) 186 | return nullptr; 187 | 188 | size_t idx = stmtId-1; 189 | if (idx >= _storage.size()) 190 | return nullptr; 191 | 192 | return std::move(_storage[idx]); 193 | } 194 | -------------------------------------------------------------------------------- /Hive/Source/Shared/Shared.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | {92C57338-E848-422B-8E81-6F6D11671750} 38 | Win32Proj 39 | Shared 40 | 41 | 42 | 43 | StaticLibrary 44 | true 45 | Unicode 46 | v110 47 | 48 | 49 | StaticLibrary 50 | false 51 | true 52 | Unicode 53 | v110 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | Level3 81 | Disabled 82 | %(PreprocessorDefinitions) 83 | %(AdditionalIncludeDirectories) 84 | MultiThreadedDebugDLL 85 | 86 | 87 | Windows 88 | true 89 | 90 | 91 | 92 | 93 | 94 | 95 | Level3 96 | 97 | 98 | MaxSpeed 99 | true 100 | true 101 | %(PreprocessorDefinitions) 102 | %(AdditionalIncludeDirectories) 103 | MultiThreadedDLL 104 | 105 | 106 | Windows 107 | true 108 | true 109 | true 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /Hive/Source/Shared/Library/Database/DatabaseLoader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2013 Rajko Stojadinovic 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #include "DatabaseLoader.h" 20 | #include 21 | 22 | #include "Shared/Library/SharedLibraryLoader.h" 23 | #include 24 | #include 25 | 26 | namespace 27 | { 28 | typedef SharedLibraryLoader LibraryType; 29 | static Poco::SingletonHolder holder; 30 | } 31 | 32 | string DatabaseLoader::GetDbTypeFromConfig( Poco::Util::AbstractConfiguration* dbConfig ) 33 | { 34 | string dbTypeStr; 35 | 36 | if (dbConfig->has("Type")) 37 | dbTypeStr = dbConfig->getString("Type"); 38 | else if (dbConfig->has("Provider")) 39 | dbTypeStr = dbConfig->getString("Provider"); 40 | else if (dbConfig->has("Engine")) 41 | dbTypeStr = dbConfig->getString("Engine"); 42 | else 43 | dbTypeStr = "MySql"; 44 | 45 | Poco::trimInPlace(dbTypeStr); 46 | 47 | if (dbTypeStr.length() < 1) 48 | throw DatabaseLoader::CreationError(string("Unspecified DB type")); 49 | 50 | return dbTypeStr; 51 | } 52 | 53 | #include 54 | 55 | string DatabaseLoader::GetDbModuleName( string dbType, bool physicalName ) 56 | { 57 | if (boost::icontains(dbType,"mysql")) 58 | dbType = "MySql"; 59 | else if (boost::icontains(dbType,"postgre")) 60 | dbType = "Postgre"; 61 | 62 | string modName = "Database"+dbType; 63 | if (physicalName) 64 | modName += Poco::SharedLibrary::suffix(); 65 | 66 | return modName; 67 | } 68 | 69 | bool DatabaseLoader::GetVersionOfModule( const string& moduleName, UInt32& outMajor, UInt32& outMinor, UInt32& outRev, UInt32& outBld ) 70 | { 71 | std::wstring fileName; 72 | { 73 | WCHAR fullPath[MAX_PATH]; 74 | HMODULE ourModule = GetModuleHandleA(moduleName.c_str()); 75 | if (ourModule == NULL) 76 | return false; 77 | 78 | GetModuleFileNameW(ourModule,fullPath,MAX_PATH); 79 | fileName = fullPath; 80 | } 81 | 82 | size_t verSize = GetFileVersionInfoSizeW(fileName.c_str(),NULL); 83 | if (verSize < 1) 84 | return false; 85 | 86 | vector fileVerBuf(verSize); 87 | if (!GetFileVersionInfoW(fileName.c_str(),0,fileVerBuf.size(),&fileVerBuf[0])) 88 | return false; 89 | 90 | VS_FIXEDFILEINFO* fileInfo = NULL; 91 | size_t infoLen = 0; 92 | if (!VerQueryValue(&fileVerBuf[0],L"\\",(LPVOID*)&fileInfo,&infoLen)) 93 | return false; 94 | if (!fileInfo || infoLen < 1) 95 | return false; 96 | 97 | outMajor = HIWORD(fileInfo->dwFileVersionMS); 98 | outMinor = LOWORD(fileInfo->dwFileVersionMS); 99 | outRev = HIWORD(fileInfo->dwFileVersionLS); 100 | outBld = LOWORD(fileInfo->dwFileVersionLS); 101 | 102 | return true; 103 | } 104 | 105 | bool DatabaseLoader::IsVersionCompatible( const UInt32* wantedVer, const UInt32* gotVer ) 106 | { 107 | if (gotVer[0] != wantedVer[0]) 108 | return false; 109 | if (gotVer[1] != wantedVer[1]) 110 | return false; 111 | if (gotVer[2] != wantedVer[2]) 112 | return false; 113 | if (gotVer[3] < wantedVer[3]) 114 | return false; 115 | 116 | return true; 117 | } 118 | 119 | shared_ptr DatabaseLoader::Create(const string& dbType) 120 | { 121 | const string moduleName = GetDbModuleName(dbType); 122 | try 123 | { 124 | return shared_ptr(holder.get()->create(moduleName)); 125 | } 126 | catch (const Poco::NotFoundException&) 127 | { 128 | try 129 | { 130 | holder.get()->loadLibrary(moduleName); 131 | 132 | UInt32 dbVerNum[4]; 133 | const string fullLibName = GetDbModuleName(dbType,true); 134 | if (!GetVersionOfModule(fullLibName,dbVerNum[0],dbVerNum[1],dbVerNum[2],dbVerNum[3])) 135 | throw CreationError("Unable to get "+moduleName+" module version info"); 136 | 137 | string wantedDbVerStr = Poco::format("%u.%u.%u.%u or higher, but lower than ", 138 | REQUIRED_DB_VERSION_NUM[0],REQUIRED_DB_VERSION_NUM[1],REQUIRED_DB_VERSION_NUM[2],REQUIRED_DB_VERSION_NUM[3]); 139 | wantedDbVerStr += Poco::format("%u.%u.%u.0",REQUIRED_DB_VERSION_NUM[0],REQUIRED_DB_VERSION_NUM[1],REQUIRED_DB_VERSION_NUM[2]+1); 140 | 141 | if (!IsVersionCompatible(REQUIRED_DB_VERSION_NUM,dbVerNum)) 142 | { 143 | throw CreationError(Poco::format(moduleName+" module is incompatible (%u.%u.%u.%u). Replace it with a compatible version (%s)", 144 | dbVerNum[0],dbVerNum[1],dbVerNum[2],dbVerNum[3],wantedDbVerStr)); 145 | } 146 | 147 | return shared_ptr(holder.get()->create(moduleName)); 148 | } 149 | catch (const Poco::LibraryLoadException&) { throw CreationError("Error loading database module: "+moduleName); } 150 | catch (const Poco::NotFoundException&) { throw CreationError("Unimplemented database type: "+dbType); } 151 | } 152 | } 153 | 154 | shared_ptr DatabaseLoader::Create( Poco::Util::AbstractConfiguration* dbConfig ) 155 | { 156 | return Create(GetDbTypeFromConfig(dbConfig)); 157 | } 158 | 159 | Database::KeyValueColl DatabaseLoader::MakeConnParams(Poco::Util::AbstractConfiguration* dbConfig) 160 | { 161 | Database::KeyValueColl keyVals; 162 | { 163 | vector keys; 164 | dbConfig->keys(keys); 165 | 166 | for (auto it=keys.begin(); it!=keys.end(); ++it) 167 | { 168 | string value = dbConfig->getString(*it); 169 | Poco::trimInPlace(value); 170 | string keyStr = std::move(*it); 171 | Poco::toLowerInPlace(keyStr); 172 | keyVals.insert(std::make_pair(std::move(keyStr),std::move(value))); 173 | } 174 | } 175 | 176 | return keyVals; 177 | } 178 | 179 | 180 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabaseMySql/DatabaseMySql.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | {e0e04f80-0db4-4946-b956-4bca754dab71} 29 | 30 | 31 | 32 | {E6BA8EFD-342A-409B-9273-6463009E5DCA} 33 | Win32Proj 34 | DatabaseMySql 35 | 36 | 37 | 38 | DynamicLibrary 39 | true 40 | Unicode 41 | v110 42 | 43 | 44 | DynamicLibrary 45 | false 46 | true 47 | Unicode 48 | v110 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | true 70 | 71 | 72 | false 73 | 74 | 75 | 76 | 77 | 78 | Level3 79 | Disabled 80 | DATABASEMYSQL_EXPORTS;%(PreprocessorDefinitions) 81 | MultiThreadedDebugDLL 82 | %(AdditionalIncludeDirectories) 83 | 84 | 85 | Windows 86 | true 87 | %(AdditionalLibraryDirectories) 88 | %(AdditionalDependencies) 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | Level3 98 | 99 | 100 | MaxSpeed 101 | true 102 | true 103 | DATABASEMYSQL_EXPORTS;%(PreprocessorDefinitions) 104 | MultiThreadedDLL 105 | %(AdditionalIncludeDirectories) 106 | 107 | 108 | Windows 109 | true 110 | true 111 | true 112 | %(AdditionalLibraryDirectories) 113 | %(AdditionalDependencies) 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /Hive/Source/Database/Implementation/DatabasePostgre/DatabasePostgre.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | {e0e04f80-0db4-4946-b956-4bca754dab71} 29 | 30 | 31 | 32 | {3A94A40D-418F-4890-829D-7CD16EA1AB6C} 33 | Win32Proj 34 | DatabasePostgre 35 | 36 | 37 | 38 | DynamicLibrary 39 | true 40 | Unicode 41 | v110 42 | 43 | 44 | DynamicLibrary 45 | false 46 | true 47 | Unicode 48 | v110 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | true 70 | 71 | 72 | false 73 | 74 | 75 | 76 | 77 | 78 | Level3 79 | Disabled 80 | DATABASEPOSTGRE_EXPORTS;%(PreprocessorDefinitions) 81 | MultiThreadedDebugDLL 82 | %(AdditionalIncludeDirectories) 83 | 84 | 85 | Windows 86 | true 87 | %(AdditionalLibraryDirectories) 88 | %(AdditionalDependencies) 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | Level3 98 | 99 | 100 | MaxSpeed 101 | true 102 | true 103 | DATABASEPOSTGRE_EXPORTS;%(PreprocessorDefinitions) 104 | MultiThreadedDLL 105 | %(AdditionalIncludeDirectories) 106 | 107 | 108 | Windows 109 | true 110 | true 111 | true 112 | %(AdditionalLibraryDirectories) 113 | %(AdditionalDependencies) 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | --------------------------------------------------------------------------------