Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the GServer #96

Closed
wants to merge 14 commits into from
38 changes: 24 additions & 14 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: 0
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignEscapedNewlines: Left
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
Expand All @@ -11,40 +12,49 @@ AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
Cpp11BracedListStyle: false
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 4
IndentAccessModifiers: false
IndentCaseLabels: true
IndentPPDirectives: None
IndentPPDirectives: BeforeHash
IndentWidth: 4
InsertNewlineAtEOF: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
PointerAlignment: Left
ReflowComments: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
Expand All @@ -56,7 +66,7 @@ SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ dependencies/v8*
lib/
out/
packages/
vcpkg_installed/
CMakeSettings.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "cmake/nuget"]
path = cmake/nuget
url = https://github.com/katusk/CMakeNuGetTools
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
#

cmake_minimum_required(VERSION 3.0.0)

# Make it easier for Windows users to get the required packages.
# This needs to go before the project() call.
if(WIN32)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
if(V8NPCSERVER)
set(VCPKG_MANIFEST_FEATURES "npcserver")
endif()
endif()

project(GS2Emu VERSION 3.0.9 DESCRIPTION "Graal Online v1.411 to v6.037 compatible server" LANGUAGES C CXX)

set(CMAKE_DEBUG_POSTFIX _d)
Expand Down Expand Up @@ -182,7 +193,8 @@ elseif(WIN32)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("/std:c++latest" _cpp_latest_flag_supported)
if (_cpp_latest_flag_supported)
add_compile_options("/std:c++latest")
set(CMAKE_CXX_STANDARD 23)
#add_compile_options("/std:c++latest")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE")
endif()

Expand All @@ -205,7 +217,7 @@ elseif(WIN32)
cmake_policy(SET CMP0043 NEW)

# hack to fix clion + msvc together
if (CLIONHAX)
#if (CLIONHAX)
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
Expand All @@ -217,7 +229,7 @@ elseif(WIN32)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif()
#endif()
endif()

if( MINGW )
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#define CATCH_CONFIG_MAIN
#include "catch2/catch_all.hpp"
#include <TPlayer.h>
#include <TServer.h>
#include <Player.h>
#include <Server.h>

SCENARIO( "TPlayer", "[object]" ) {
SCENARIO( "Player", "[object]" ) {

GIVEN( "TPlayer" ) {
GIVEN( "Player" ) {
int id = 123;
auto* server = new TServer("test");
auto* server = new Server("test");
auto* socket = new CSocket();
auto* player = new TPlayer(server, (CSocket*)socket, id);
auto* player = new Player(server, (CSocket*)socket, id);

WHEN( "getting player id" ) {
THEN( "id should be " << id ) {
Expand Down
2 changes: 1 addition & 1 deletion cmake/AddTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(add_test_og TARGET_NAME TARGET_PATH)
target_include_directories(${TARGET_NAME} PUBLIC ${GS2COMPILER_INCLUDE_DIRECTORY})

target_include_directories(${TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/server/include)
target_include_directories(${TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/server/include/TLevel)
target_include_directories(${TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/server/include/Level)
target_include_directories(${TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/server/include/Scripting)
target_include_directories(${TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/server/include/Scripting/v8)
target_include_directories(${TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/server/include/Scripting/interface)
Expand Down
4 changes: 2 additions & 2 deletions cmake/FindV8.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ if(NOT V8_LIBRARY OR NOT V8_INCLUDE_DIR)
message("Mingw package search failed, looking for nuget package")

if (NOT V8_LIBRARY AND NOT V8_INCLUDE_DIR AND MSVC)
file(DOWNLOAD https://dist.nuget.org/win-x86-commandline/latest/nuget.exe ${CMAKE_BINARY_DIR}/nuget.exe)
set(NUGET_COMMAND ${CMAKE_BINARY_DIR}/nuget.exe)
file(DOWNLOAD https://dist.nuget.org/win-x86-commandline/latest/nuget.exe "${CMAKE_BINARY_DIR}/nuget.exe")
set(NUGET_COMMAND "${CMAKE_BINARY_DIR}/nuget.exe")
include("${CMAKE_SOURCE_DIR}/cmake/nuget/cmake/NuGetTools.cmake")
# Call this once before any other nuget_* calls.
nuget_initialize()
Expand Down
6 changes: 3 additions & 3 deletions docs/tobedone.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Send PM
case NCI_SENDPM:
{
TPlayer *player = server->getPlayer(pPacket.readGUShort());
TPlayer *player = m_server->getPlayer(pPacket.readGUShort());
if (player != 0)
player->sendPacket(CString() >> (char)PLO_PRIVATEMESSAGE >> (short)id << pPacket.readString(""));
break;
Expand All @@ -11,7 +11,7 @@
// Send RPG Message
case NCI_SENDRPGMESSAGE:
{
TPlayer *player = server->getPlayer(pPacket.readGUShort());
TPlayer *player = m_server->getPlayer(pPacket.readGUShort());
if (player != 0 && player->isClient() && player->getVersion() >= CLVER_2_1)
player->sendPacket(CString() >> (char)PLO_RPGWINDOW << "\"" << pPacket.readString("") << "\"");
break;
Expand All @@ -20,7 +20,7 @@
// NPCServer -> Player --> Sign Message
case NCI_SAY2SIGN:
{
TPlayer* pl = server->getPlayer(pPacket.readGUShort());
TPlayer* pl = m_server->getPlayer(pPacket.readGUShort());
if (pl != 0)
pl->sendPacket(CString() >> (char)PLO_SAY2 << pPacket.readString("").replaceAll("\n", "#b"));
break;
Expand Down
73 changes: 37 additions & 36 deletions server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ include(CheckSymbolExists)

set(
SOURCES
src/CFileSystem.cpp
src/main.cpp
src/TAccount.cpp
src/TMap.cpp
src/TNPC.cpp
src/TScriptClass.cpp
src/TServer.cpp
src/TServerList.cpp
src/TUpdatePackage.cpp
src/TWeapon.cpp
src/Scripting/GS2ScriptManager.cpp
src/TriggerCommandHandlers.cpp
${PROJECT_SOURCE_DIR}/bin/servers/default/bootstrap.js
"src/FileSystem.cpp"
"src/main.cpp"
"src/Account.cpp"
"src/Map.cpp"
"src/NPC.cpp"
"src/ScriptClass.cpp"
"src/Server.cpp"
"src/ServerList.cpp"
"src/UpdatePackage.cpp"
"src/Weapon.cpp"
"src/Scripting/GS2ScriptManager.cpp"
"src/TriggerCommandHandlers.cpp"
"${PROJECT_SOURCE_DIR}/bin/servers/default/bootstrap.js"
)

file(GLOB TPLAYER_SOURCES src/TPlayer/**.cpp)
list(APPEND SOURCES ${TPLAYER_SOURCES})
file(GLOB PLAYER_SOURCES src/Player/**.cpp)
list(APPEND SOURCES ${PLAYER_SOURCES})

file(GLOB TLEVEL_SOURCES src/TLevel/**.cpp)
list(APPEND SOURCES ${TLEVEL_SOURCES})
file(GLOB LEVEL_SOURCES src/Level/**.cpp)
list(APPEND SOURCES ${LEVEL_SOURCES})

file(GLOB MISC_SOURCES src/Misc/**.cpp)
list(APPEND SOURCES ${MISC_SOURCES})
Expand All @@ -59,24 +59,25 @@ include(bin2h)
set(EXE_HEADERS "")
set(
HEADERS
${PROJECT_BINARY_DIR}/server/include/IConfig.h
include/CFileSystem.h
include/main.h
include/TAccount.h
include/TMap.h
include/TNPC.h
include/TPlayer.h
include/TScriptClass.h
include/TServer.h
include/TServerList.h
include/TUpdatePackage.h
include/TWeapon.h
include/Scripting/GS2ScriptManager.h
include/Scripting/ScriptOrigin.h
include/Scripting/SourceCode.h)

file(GLOB TLEVEL_HEADERS include/TLevel/**.h)
list(APPEND HEADERS ${TLEVEL_HEADERS})
"${PROJECT_BINARY_DIR}/server/include/IConfig.h"
"include/FileSystem.h"
"include/main.h"
"include/Account.h"
"include/Map.h"
"include/NPC.h"
"include/Player.h"
"include/ScriptClass.h"
"include/Server.h"
"include/ServerList.h"
"include/UpdatePackage.h"
"include/Weapon.h"
"include/Scripting/GS2ScriptManager.h"
"include/Scripting/ScriptOrigin.h"
"include/Scripting/SourceCode.h"
)

file(GLOB LEVEL_HEADERS include/Level/**.h)
list(APPEND HEADERS ${LEVEL_HEADERS})

file(GLOB MISC_HEADERS include/Misc/**.h)
list(APPEND HEADERS ${MISC_HEADERS})
Expand Down Expand Up @@ -139,7 +140,7 @@ include_directories(
${PROJECT_BINARY_DIR}/server/include
${PROJECT_SOURCE_DIR}/server/include
${PROJECT_SOURCE_DIR}/server/include/Misc
${PROJECT_SOURCE_DIR}/server/include/TLevel
${PROJECT_SOURCE_DIR}/server/include/Level
${PROJECT_SOURCE_DIR}/server/include/utilities
${PROJECT_SOURCE_DIR}/server/include/Scripting
${PROJECT_SOURCE_DIR}/server/include/Scripting/interface
Expand Down
Loading