Merge remote-tracking branch 'upstream/master' into registered-user-only-server
Conflicts: common/server.cpp common/server_protocolhandler.cpp servatrice/src/servatrice.cpp
This commit is contained in:
commit
021f0911c4
95 changed files with 4557 additions and 3906 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ tags
|
|||
build*
|
||||
*.qm
|
||||
.directory
|
||||
mysql.cnf
|
||||
|
|
|
@ -7,13 +7,21 @@
|
|||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
set(PROJECT_NAME "Cockatrice")
|
||||
set(PROJECT_VERSION_MAJOR 0)
|
||||
set(PROJECT_VERSION_MINOR 0)
|
||||
set(PROJECT_VERSION_PATCH 1)
|
||||
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} )
|
||||
if(POLICY CMP0020)
|
||||
cmake_policy(SET CMP0020 OLD)
|
||||
endif()
|
||||
|
||||
# Defualt to "Release" build type
|
||||
if(POLICY CMP0043)
|
||||
cmake_policy(SET CMP0043 OLD)
|
||||
endif()
|
||||
|
||||
if(POLICY CMP0048)
|
||||
cmake_policy(SET CMP0048 OLD)
|
||||
endif()
|
||||
|
||||
set(PROJECT_NAME "Cockatrice")
|
||||
|
||||
# Default to "Release" build type
|
||||
# User-provided value for CMAKE_BUILD_TYPE must be checked before the PROJECT() call
|
||||
IF(DEFINED CMAKE_BUILD_TYPE)
|
||||
SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Type of build")
|
||||
|
@ -24,9 +32,19 @@ ENDIF()
|
|||
# A project name is needed for CPack
|
||||
PROJECT("${PROJECT_NAME}")
|
||||
|
||||
|
||||
# Set conventional loops
|
||||
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
|
||||
|
||||
# Search path for cmake modules
|
||||
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||
|
||||
# Retrieve git version hash
|
||||
include(getversion)
|
||||
|
||||
# Create a header and a cpp file containing the version hash
|
||||
include(createversionfile)
|
||||
|
||||
# Define a proper install path
|
||||
if(UNIX)
|
||||
if(APPLE)
|
||||
|
@ -71,8 +89,33 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
|||
ADD_DEFINITIONS("-DSFMT_MEXP=19937")
|
||||
ENDIF()
|
||||
|
||||
#Find Qt4 and enable the needed features
|
||||
FIND_PACKAGE(Qt4 REQUIRED)
|
||||
# Find Qt and enable the needed features
|
||||
# Default is Qt5 unless WITH_QT4 option is enabled
|
||||
option(WITH_QT4 "Force thr use of Qt4 libraries" OFF)
|
||||
|
||||
IF(NOT WITH_QT4)
|
||||
FIND_PACKAGE(Qt5Widgets)
|
||||
ENDIF()
|
||||
|
||||
IF(Qt5Widgets_FOUND)
|
||||
MESSAGE(STATUS "Found Qt ${Qt5Widgets_VERSION_STRING}")
|
||||
|
||||
if(UNIX AND NOT APPLE AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
|
||||
# FIX: Qt was built with -reduce-relocations
|
||||
add_definitions(-fPIC)
|
||||
endif()
|
||||
ELSE()
|
||||
FIND_PACKAGE(Qt4 4.8.0 REQUIRED)
|
||||
IF(QT4_FOUND)
|
||||
# Old FindQt4.cmake modules used the same flag with different case
|
||||
SET(Qt4_FOUND TRUE)
|
||||
ENDIF()
|
||||
IF(Qt4_FOUND)
|
||||
MESSAGE(STATUS "Found Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}")
|
||||
ELSE()
|
||||
MESSAGE(FATAL_ERROR "No Qt4 or Qt5 found!")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
set(CMAKE_AUTOMOC TRUE)
|
||||
|
||||
|
@ -83,8 +126,8 @@ FIND_PACKAGE(Protobuf REQUIRED)
|
|||
set(CPACK_PACKAGE_CONTACT "Daenyth+github@gmail.com")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PROJECT_NAME})
|
||||
set(CPACK_PACKAGE_VENDOR "Cockatrice Development Team")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.md")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
|
||||
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
|
||||
|
@ -96,7 +139,7 @@ if(UNIX)
|
|||
set(CPACK_DMG_FORMAT "UDBZ")
|
||||
set(CPACK_DMG_VOLUME_NAME "${PROJECT_NAME}")
|
||||
set(CPACK_SYSTEM_NAME "OSX")
|
||||
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
|
||||
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-osx_git-${PROJECT_VERSION}")
|
||||
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/cockatrice/resources/appicon.icns")
|
||||
else()
|
||||
# linux
|
||||
|
@ -107,13 +150,13 @@ if(UNIX)
|
|||
endif()
|
||||
elseif(WIN32)
|
||||
set(CPACK_GENERATOR NSIS ${CPACK_GENERATOR})
|
||||
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}\\\\${PROJECT_VERSION}")
|
||||
set(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\${PROJECT_NAME}.exe")
|
||||
set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
|
||||
set(CPACK_NSIS_HELP_LINK "https://github.com/Daenyth/Cockatrice")
|
||||
set(CPACK_NSIS_URL_INFO_ABOUT "https://github.com/Daenyth/Cockatrice")
|
||||
set(CPACK_NSIS_CONTACT "Daenyth+github@gmail.com")
|
||||
set(CPACK_NSIS_MODIFY_PATH ON)
|
||||
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}_win32_git-${PROJECT_VERSION}")
|
||||
|
||||
# Configure file with custom definitions for NSIS.
|
||||
configure_file(
|
||||
${CMAKE_MODULE_PATH}/NSIS.definitions.nsh.in
|
||||
${PROJECT_BINARY_DIR}/NSIS.definitions.nsh
|
||||
)
|
||||
endif()
|
||||
|
||||
include(CPack)
|
||||
|
|
|
@ -33,8 +33,9 @@ To compile:
|
|||
|
||||
The following flags can be passed to `cmake`:
|
||||
|
||||
- `-DWITH_SERVER=1` build the server
|
||||
- `-DWITHOUT_CLIENT=1` do not build the client
|
||||
- `-DWITH_SERVER=1` Build the server
|
||||
- `-DWITHOUT_CLIENT=1` Do not build the client
|
||||
- `-DWITH_QT4=1` Force compilation to use Qt4 instead of Qt5.
|
||||
|
||||
# Running
|
||||
|
||||
|
|
1
cmake/NSIS.definitions.nsh.in
Normal file
1
cmake/NSIS.definitions.nsh.in
Normal file
|
@ -0,0 +1 @@
|
|||
!define NSIS_SOURCE_PATH "@PROJECT_SOURCE_DIR@"
|
|
@ -1,30 +1,26 @@
|
|||
!include ..\..\..\NSIS.definitions.nsh
|
||||
!include "MUI2.nsh"
|
||||
!include "FileFunc.nsh"
|
||||
|
||||
!define /date TIMESTAMP "%Y%m%d"
|
||||
!searchparse /file ../build/cockatrice/version_string.cpp '= "' VERSION '";'
|
||||
|
||||
Name "Cockatrice"
|
||||
OutFile "cockatrice_win32_${TIMESTAMP}_git-${VERSION}.exe"
|
||||
Name "@CPACK_PACKAGE_NAME@"
|
||||
OutFile "@CPACK_TOPLEVEL_DIRECTORY@/@CPACK_OUTPUT_FILE_NAME@"
|
||||
SetCompressor /SOLID lzma
|
||||
InstallDir "$PROGRAMFILES\Cockatrice"
|
||||
|
||||
; set the Qt install dir here (and make sure you use the latest 4.8 version for packaging)
|
||||
!define QTDIR "C:\Qt\4.8.6"
|
||||
!define INST_DIR "@CPACK_TEMPORARY_DIRECTORY@"
|
||||
|
||||
!define MUI_ABORTWARNING
|
||||
!define MUI_WELCOMEFINISHPAGE_BITMAP "leftimage.bmp"
|
||||
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "leftimage.bmp"
|
||||
!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSIS_SOURCE_PATH}\cmake\leftimage.bmp"
|
||||
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "${NSIS_SOURCE_PATH}\cmake\leftimage.bmp"
|
||||
!define MUI_HEADERIMAGE
|
||||
!define MUI_HEADERIMAGE_BITMAP "headerimage.bmp"
|
||||
!define MUI_HEADERIMAGE_UNBITMAP "headerimage.bmp"
|
||||
!define MUI_HEADERIMAGE_BITMAP "${NSIS_SOURCE_PATH}\cmake\headerimage.bmp"
|
||||
!define MUI_HEADERIMAGE_UNBITMAP "${NSIS_SOURCE_PATH}\cmake\headerimage.bmp"
|
||||
!define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of Cockatrice.$\r$\n$\r$\nClick Next to continue."
|
||||
!define MUI_FINISHPAGE_RUN "$INSTDIR/oracle.exe"
|
||||
!define MUI_FINISHPAGE_RUN_TEXT "Run card database downloader now"
|
||||
!define MUI_FINISHPAGE_RUN_PARAMETERS "-dlsets"
|
||||
|
||||
!insertmacro MUI_PAGE_WELCOME
|
||||
!insertmacro MUI_PAGE_LICENSE "..\COPYING"
|
||||
!insertmacro MUI_PAGE_LICENSE "${NSIS_SOURCE_PATH}\COPYING"
|
||||
!insertmacro MUI_PAGE_COMPONENTS
|
||||
!insertmacro MUI_PAGE_DIRECTORY
|
||||
!insertmacro MUI_PAGE_INSTFILES
|
||||
|
@ -39,37 +35,9 @@ InstallDir "$PROGRAMFILES\Cockatrice"
|
|||
Section "Application" SecApplication
|
||||
SetShellVarContext all
|
||||
SetOutPath "$INSTDIR"
|
||||
File ..\build\cockatrice\Release\cockatrice.exe
|
||||
File ..\build\oracle\Release\oracle.exe
|
||||
File ..\doc\usermanual\Usermanual.pdf
|
||||
File ..\build\protobuf-2.5.0\protobuf-2.5.0\vsprojects\Release\libprotobuf.lib
|
||||
File "${QTDIR}\bin\QtCore4.dll"
|
||||
File "${QTDIR}\bin\QtGui4.dll"
|
||||
File "${QTDIR}\bin\QtNetwork4.dll"
|
||||
File "${QTDIR}\bin\QtSvg4.dll"
|
||||
File "${QTDIR}\bin\QtXml4.dll"
|
||||
File "${QTDIR}\bin\QtMultimedia4.dll"
|
||||
|
||||
SetOutPath "$INSTDIR\zonebg"
|
||||
File /r ..\zonebg\*.*
|
||||
|
||||
SetOutPath "$INSTDIR\plugins"
|
||||
SetOutPath "$INSTDIR\plugins\codecs"
|
||||
File "${QTDIR}\plugins\codecs\qcncodecs4.dll"
|
||||
File "${QTDIR}\plugins\codecs\qjpcodecs4.dll"
|
||||
File "${QTDIR}\plugins\codecs\qkrcodecs4.dll"
|
||||
File "${QTDIR}\plugins\codecs\qtwcodecs4.dll"
|
||||
SetOutPath "$INSTDIR\plugins\iconengines"
|
||||
File "${QTDIR}\plugins\iconengines\qsvgicon4.dll"
|
||||
SetOutPath "$INSTDIR\plugins\imageformats"
|
||||
File "${QTDIR}\plugins\imageformats\qjpeg4.dll"
|
||||
File "${QTDIR}\plugins\imageformats\qsvg4.dll"
|
||||
|
||||
SetOutPath "$INSTDIR\sounds"
|
||||
File /r ..\sounds\*.*
|
||||
|
||||
SetOutPath "$INSTDIR\translations"
|
||||
File /r ..\build\cockatrice\*.qm
|
||||
@CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS@
|
||||
@CPACK_NSIS_FULL_INSTALL@
|
||||
|
||||
WriteUninstaller "$INSTDIR\uninstall.exe"
|
||||
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
|
||||
|
@ -107,12 +75,10 @@ SetShellVarContext all
|
|||
Delete "$INSTDIR\oracle.exe"
|
||||
Delete "$INSTDIR\Usermanual.pdf"
|
||||
Delete "$INSTDIR\libprotobuf.lib"
|
||||
Delete "$INSTDIR\QtCore4.dll"
|
||||
Delete "$INSTDIR\QtGui4.dll"
|
||||
Delete "$INSTDIR\QtNetwork4.dll"
|
||||
Delete "$INSTDIR\QtSvg4.dll"
|
||||
Delete "$INSTDIR\QtXml4.dll"
|
||||
Delete "$INSTDIR\QtMultimedia4.dll"
|
||||
Delete "$INSTDIR\Qt*.dll"
|
||||
Delete "$INSTDIR\icu*.dll"
|
||||
Delete "$INSTDIR\qt.conf"
|
||||
Delete "$INSTDIR\qdebug.txt"
|
||||
RMDir "$INSTDIR"
|
||||
|
||||
RMDir "$SMPROGRAMS\Cockatrice"
|
17
cmake/createversionfile.cmake
Normal file
17
cmake/createversionfile.cmake
Normal file
|
@ -0,0 +1,17 @@
|
|||
set(VERSION_STRING_CPP "${PROJECT_BINARY_DIR}/version_string.cpp")
|
||||
set(VERSION_STRING_H "${PROJECT_BINARY_DIR}/version_string.h")
|
||||
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
|
||||
|
||||
set( hstring "extern const char *VERSION_STRING\;\n" )
|
||||
set( cppstring "const char * VERSION_STRING = \"${PROJECT_VERSION}\"\;\n")
|
||||
|
||||
file(WRITE ${PROJECT_BINARY_DIR}/version_string.cpp.txt ${cppstring} )
|
||||
file(WRITE ${PROJECT_BINARY_DIR}/version_string.h.txt ${hstring} )
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_BINARY_DIR}/version_string.h.txt ${VERSION_STRING_H}
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PROJECT_BINARY_DIR}/version_string.cpp.txt ${VERSION_STRING_CPP}
|
||||
)
|
||||
|
|
@ -2,6 +2,7 @@ find_package(Git)
|
|||
if(GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} describe --long --always
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
RESULT_VARIABLE res_var
|
||||
OUTPUT_VARIABLE GIT_COM_ID
|
||||
)
|
||||
|
@ -15,15 +16,5 @@ else()
|
|||
message( WARNING "Git not found. Build will not contain git revision info." )
|
||||
endif()
|
||||
|
||||
set( hstring "extern const char *VERSION_STRING\;\n" )
|
||||
set( cppstring "const char * VERSION_STRING = \"${GIT_COMMIT_ID}\"\;\n")
|
||||
|
||||
file(WRITE version_string.cpp.txt ${cppstring} )
|
||||
file(WRITE version_string.h.txt ${hstring} )
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different version_string.h.txt ${CMAKE_CURRENT_BINARY_DIR}/version_string.h
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different version_string.cpp.txt ${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp
|
||||
)
|
||||
set(PROJECT_VERSION_MAJOR ${GIT_COMMIT_ID})
|
||||
set(PROJECT_VERSION ${GIT_COMMIT_ID} )
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 201 KiB After Width: | Height: | Size: 201 KiB |
|
@ -90,7 +90,7 @@ SET(cockatrice_SOURCES
|
|||
src/qt-json/json.cpp
|
||||
src/soundengine.cpp
|
||||
src/pending_command.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp
|
||||
${VERSION_STRING_CPP}
|
||||
)
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
|
@ -125,41 +125,119 @@ if(APPLE)
|
|||
set(cockatrice_SOURCES ${cockatrice_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/resources/appicon.icns)
|
||||
ENDIF(APPLE)
|
||||
|
||||
if (NOT QT_QTMULTIMEDIA_FOUND)
|
||||
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
FIND_PACKAGE(QtMobility REQUIRED)
|
||||
endif (NOT QT_QTMULTIMEDIA_FOUND)
|
||||
set(COCKATRICE_LIBS)
|
||||
|
||||
SET(QT_USE_QTNETWORK TRUE)
|
||||
SET(QT_USE_QTMULTIMEDIA TRUE)
|
||||
SET(QT_USE_QTXML TRUE)
|
||||
SET(QT_USE_QTSVG TRUE)
|
||||
# Qt4 stuff
|
||||
if(Qt4_FOUND)
|
||||
if (NOT QT_QTMULTIMEDIA_FOUND)
|
||||
FIND_PACKAGE(QtMobility REQUIRED)
|
||||
endif()
|
||||
|
||||
SET(QT_USE_QTNETWORK TRUE)
|
||||
SET(QT_USE_QTMULTIMEDIA TRUE)
|
||||
SET(QT_USE_QTXML TRUE)
|
||||
SET(QT_USE_QTSVG TRUE)
|
||||
|
||||
# Include directories
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
INCLUDE_DIRECTORIES(${QT_INCLUDES})
|
||||
INCLUDE_DIRECTORIES(${QT_MOBILITY_INCLUDE_DIR})
|
||||
INCLUDE_DIRECTORIES(${QT_MOBILITY_MULTIMEDIAKIT_INCLUDE_DIR})
|
||||
LIST(APPEND COCKATRICE_LIBS ${QT_LIBRARIES})
|
||||
LIST(APPEND COCKATRICE_LIBS ${QT_QTMAIN_LIBRARY})
|
||||
LIST(APPEND COCKATRICE_LIBS ${QT_MOBILITY_MULTIMEDIAKIT_LIBRARY})
|
||||
|
||||
# Let cmake chew Qt4's translations and resource files
|
||||
# Note: header files are MOC-ed automatically by cmake
|
||||
QT4_ADD_TRANSLATION(cockatrice_QM ${cockatrice_TS})
|
||||
QT4_ADD_RESOURCES(cockatrice_RESOURCES_RCC ${cockatrice_RESOURCES})
|
||||
endif()
|
||||
|
||||
# qt5 stuff
|
||||
if(Qt5Widgets_FOUND)
|
||||
include_directories(${Qt5Widgets_INCLUDE_DIRS})
|
||||
list(APPEND COCKATRICE_LIBS Widgets)
|
||||
|
||||
# QtNetwork
|
||||
find_package(Qt5Network)
|
||||
if(Qt5Network_FOUND)
|
||||
include_directories(${Qt5Network_INCLUDE_DIRS})
|
||||
list(APPEND COCKATRICE_LIBS Network)
|
||||
endif()
|
||||
|
||||
# QtMultimedia
|
||||
find_package(Qt5Multimedia)
|
||||
if(Qt5Multimedia_FOUND)
|
||||
include_directories(${Qt5Multimedia_INCLUDE_DIRS})
|
||||
list(APPEND COCKATRICE_LIBS Multimedia)
|
||||
endif()
|
||||
|
||||
# QtPrinter
|
||||
find_package(Qt5PrintSupport)
|
||||
if(Qt5PrintSupport_FOUND)
|
||||
include_directories(${Qt5PrintSupport_INCLUDE_DIRS})
|
||||
list(APPEND COCKATRICE_LIBS PrintSupport)
|
||||
endif()
|
||||
|
||||
# QtXml
|
||||
find_package(Qt5Xml)
|
||||
if(Qt5Xml_FOUND)
|
||||
include_directories(${Qt5Xml_INCLUDE_DIRS})
|
||||
list(APPEND COCKATRICE_LIBS Xml)
|
||||
endif()
|
||||
|
||||
# QtSvg
|
||||
find_package(Qt5Svg)
|
||||
if(Qt5Svg_FOUND)
|
||||
include_directories(${Qt5Svg_INCLUDE_DIRS})
|
||||
list(APPEND COCKATRICE_LIBS Svg)
|
||||
endif()
|
||||
|
||||
# Qt5LinguistTools
|
||||
find_package(Qt5LinguistTools)
|
||||
if(Qt5LinguistTools_FOUND)
|
||||
include_directories(${Qt5LinguistTools_INCLUDE_DIRS})
|
||||
list(APPEND COCKATRICE_LIBS LinguistTools)
|
||||
endif()
|
||||
|
||||
# Let cmake chew Qt5's translations and resource files
|
||||
# Note: header files are MOC-ed automatically by cmake
|
||||
QT5_ADD_TRANSLATION(cockatrice_QM ${cockatrice_TS})
|
||||
QT5_ADD_RESOURCES(cockatrice_RESOURCES_RCC ${cockatrice_RESOURCES})
|
||||
|
||||
# guess plugins and libraries directory
|
||||
set(QT_PLUGINS_DIR "${Qt5Widgets_DIR}/../../../plugins")
|
||||
get_target_property(QT_LIBRARY_DIR Qt5::Core LOCATION)
|
||||
get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH)
|
||||
endif()
|
||||
|
||||
# Declare path variables
|
||||
set(ICONDIR share/icons CACHE STRING "icon dir")
|
||||
set(DESKTOPDIR share/applications CACHE STRING "desktop file destination")
|
||||
|
||||
# Let cmake chew Qt4's translations and resource files
|
||||
# Note: header files are MOC-ed automatically by cmake
|
||||
QT4_ADD_TRANSLATION(cockatrice_QM ${cockatrice_TS})
|
||||
QT4_ADD_RESOURCES(cockatrice_RESOURCES_RCC ${cockatrice_RESOURCES})
|
||||
|
||||
# Include directories
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
INCLUDE_DIRECTORIES(../common)
|
||||
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
|
||||
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/common)
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
|
||||
INCLUDE_DIRECTORIES(${QT_MOBILITY_INCLUDE_DIR})
|
||||
INCLUDE_DIRECTORIES(${QT_MOBILITY_MULTIMEDIAKIT_INCLUDE_DIR})
|
||||
|
||||
# Build cockatrice binary and link it
|
||||
ADD_EXECUTABLE(cockatrice WIN32 MACOSX_BUNDLE ${cockatrice_SOURCES} ${cockatrice_QM} ${cockatrice_RESOURCES_RCC} ${cockatrice_MOC_SRCS})
|
||||
TARGET_LINK_LIBRARIES(cockatrice cockatrice_common ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES} ${QT_MOBILITY_MULTIMEDIAKIT_LIBRARY})
|
||||
|
||||
if(MSVC)
|
||||
set_target_properties(cockatrice PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
|
||||
endif(MSVC)
|
||||
if(Qt4_FOUND)
|
||||
if(MSVC)
|
||||
set(QT_USE_QTMAIN true)
|
||||
endif()
|
||||
TARGET_LINK_LIBRARIES(cockatrice cockatrice_common ${COCKATRICE_LIBS})
|
||||
endif()
|
||||
if(Qt5Widgets_FOUND)
|
||||
if(MSVC)
|
||||
TARGET_LINK_LIBRARIES(cockatrice cockatrice_common Qt5::WinMain)
|
||||
else()
|
||||
TARGET_LINK_LIBRARIES(cockatrice cockatrice_common)
|
||||
endif()
|
||||
qt5_use_modules(cockatrice ${COCKATRICE_LIBS})
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
if(APPLE)
|
||||
|
@ -178,11 +256,6 @@ elseif(WIN32)
|
|||
INSTALL(FILES ${cockatrice_QM} DESTINATION ./translations)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp ${CMAKE_CURRENT_BINARY_DIR}/version_string.h
|
||||
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/../common/getversion.cmake
|
||||
)
|
||||
|
||||
if(APPLE)
|
||||
# these needs to be relative to CMAKE_INSTALL_PREFIX
|
||||
set(plugin_dest_dir cockatrice.app/Contents/Plugins)
|
||||
|
@ -215,3 +288,36 @@ Data = Resources\")
|
|||
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/cockatrice.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
|
||||
" COMPONENT Runtime)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# these needs to be relative to CMAKE_INSTALL_PREFIX
|
||||
set(plugin_dest_dir Plugins)
|
||||
set(qtconf_dest_dir .)
|
||||
|
||||
# note: no codecs in qt5
|
||||
# note: phonon_backend => mediaservice
|
||||
# note: needs platform on osx
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
|
||||
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*d\\.dll")
|
||||
else()
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
|
||||
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*[^d]\\.dll")
|
||||
endif()
|
||||
|
||||
install(CODE "
|
||||
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
|
||||
Plugins = Plugins
|
||||
Translations = Resources/translations
|
||||
Data = Resources\")
|
||||
" COMPONENT Runtime)
|
||||
|
||||
install(CODE "
|
||||
file(GLOB_RECURSE QTPLUGINS
|
||||
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dll\")
|
||||
set(BU_CHMOD_BUNDLE_ITEMS ON)
|
||||
include(BundleUtilities)
|
||||
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/cockatrice.exe\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
|
||||
" COMPONENT Runtime)
|
||||
endif()
|
|
@ -11,8 +11,12 @@
|
|||
AbstractCounter::AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value), hovered(false), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea)
|
||||
{
|
||||
#if QT_VERSION < 0x050000
|
||||
setAcceptsHoverEvents(true);
|
||||
|
||||
#else
|
||||
setAcceptHoverEvents(true);
|
||||
#endif
|
||||
|
||||
if (player->getLocal()) {
|
||||
menu = new QMenu(name);
|
||||
aSet = new QAction(this);
|
||||
|
@ -129,7 +133,13 @@ void AbstractCounter::setCounter()
|
|||
{
|
||||
bool ok;
|
||||
dialogSemaphore = true;
|
||||
int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, -2000000000, 2000000000, 1, &ok);
|
||||
int newValue =
|
||||
#if QT_VERSION < 0x050000
|
||||
QInputDialog::getInteger(
|
||||
#else
|
||||
QInputDialog::getInt(
|
||||
#endif
|
||||
0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, -2000000000, 2000000000, 1, &ok);
|
||||
if (deleteAfterDialog) {
|
||||
deleteLater();
|
||||
return;
|
||||
|
|
|
@ -68,6 +68,8 @@ QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation,
|
|||
|
||||
void CardDatabaseModel::updateCardList()
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
for (int i = 0; i < cardList.size(); ++i)
|
||||
disconnect(cardList[i], 0, this, 0);
|
||||
|
||||
|
@ -75,7 +77,7 @@ void CardDatabaseModel::updateCardList()
|
|||
for (int i = 0; i < cardList.size(); ++i)
|
||||
connect(cardList[i], SIGNAL(cardInfoChanged(CardInfo *)), this, SLOT(cardInfoChanged(CardInfo *)));
|
||||
|
||||
reset();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void CardDatabaseModel::cardInfoChanged(CardInfo *card)
|
||||
|
|
|
@ -233,7 +233,8 @@ CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPoin
|
|||
|
||||
void CardItem::deleteDragItem()
|
||||
{
|
||||
dragItem->deleteLater();
|
||||
if(dragItem)
|
||||
dragItem->deleteLater();
|
||||
dragItem = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ DeckListModel::~DeckListModel()
|
|||
|
||||
void DeckListModel::rebuildTree()
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
root->clearTree();
|
||||
InnerDecklistNode *listRoot = deckList->getRoot();
|
||||
for (int i = 0; i < listRoot->size(); i++) {
|
||||
|
@ -55,7 +57,7 @@ void DeckListModel::rebuildTree()
|
|||
}
|
||||
}
|
||||
|
||||
reset();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int DeckListModel::rowCount(const QModelIndex &parent) const
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#include <QMessageBox>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
#include <QUrlQuery>
|
||||
#endif
|
||||
|
||||
DeckStatsInterface::DeckStatsInterface(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
@ -39,12 +43,29 @@ void DeckStatsInterface::queryFinished(QNetworkReply *reply)
|
|||
deleteLater();
|
||||
}
|
||||
|
||||
void DeckStatsInterface::analyzeDeck(DeckList *deck)
|
||||
#if QT_VERSION < 0x050000
|
||||
void DeckStatsInterface::getAnalyzeRequestData(DeckList *deck, QByteArray *data)
|
||||
{
|
||||
QUrl params;
|
||||
params.addQueryItem("deck", deck->writeToString_Plain());
|
||||
data->append(params.encodedQuery());
|
||||
}
|
||||
#else
|
||||
void DeckStatsInterface::getAnalyzeRequestData(DeckList *deck, QByteArray *data)
|
||||
{
|
||||
QUrl params;
|
||||
QUrlQuery urlQuery;
|
||||
urlQuery.addQueryItem("deck", deck->writeToString_Plain());
|
||||
params.setQuery(urlQuery);
|
||||
data->append(params.query(QUrl::EncodeReserved));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void DeckStatsInterface::analyzeDeck(DeckList *deck)
|
||||
{
|
||||
QByteArray data;
|
||||
data.append(params.encodedQuery());
|
||||
getAnalyzeRequestData(deck, &data);
|
||||
|
||||
QNetworkRequest request(QUrl("http://deckstats.net/index.php"));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
class QByteArray;
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
class DeckList;
|
||||
|
@ -13,6 +14,7 @@ private:
|
|||
QNetworkAccessManager *manager;
|
||||
private slots:
|
||||
void queryFinished(QNetworkReply *reply);
|
||||
void getAnalyzeRequestData(DeckList *deck, QByteArray *data);
|
||||
public:
|
||||
DeckStatsInterface(QObject *parent = 0);
|
||||
void analyzeDeck(DeckList *deck);
|
||||
|
|
|
@ -64,7 +64,11 @@ void DeckViewCardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
DeckViewCard::DeckViewCard(const QString &_name, const QString &_originZone, QGraphicsItem *parent)
|
||||
: AbstractCardItem(_name, 0, -1, parent), originZone(_originZone), dragItem(0)
|
||||
{
|
||||
#if QT_VERSION < 0x050000
|
||||
setAcceptsHoverEvents(true);
|
||||
#else
|
||||
setAcceptHoverEvents(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
DeckViewCard::~DeckViewCard()
|
||||
|
|
|
@ -79,8 +79,13 @@ DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *pa
|
|||
chooseTokenView->header()->setStretchLastSection(false);
|
||||
chooseTokenView->header()->hideSection(1);
|
||||
chooseTokenView->header()->hideSection(2);
|
||||
#if QT_VERSION < 0x050000
|
||||
chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
|
||||
chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
|
||||
#else
|
||||
chooseTokenView->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||
chooseTokenView->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
|
||||
|
||||
if (predefinedTokens.isEmpty())
|
||||
|
|
|
@ -73,8 +73,13 @@ DlgEditTokens::DlgEditTokens(CardDatabaseModel *_cardDatabaseModel, QWidget *par
|
|||
chooseTokenView->header()->setStretchLastSection(false);
|
||||
chooseTokenView->header()->hideSection(1);
|
||||
chooseTokenView->header()->hideSection(2);
|
||||
#if QT_VERSION < 0x050000
|
||||
chooseTokenView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
|
||||
chooseTokenView->header()->setResizeMode(4, QHeaderView::ResizeToContents);
|
||||
#else
|
||||
chooseTokenView->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||
chooseTokenView->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
connect(chooseTokenView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, SLOT(tokenSelectionChanged(QModelIndex, QModelIndex)));
|
||||
|
||||
QAction *aAddToken = new QAction(tr("Add token"), this);
|
||||
|
|
|
@ -9,26 +9,53 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QSettings>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
DlgFilterGames::DlgFilterGames(const QMap<int, QString> &_allGameTypes, QWidget *parent)
|
||||
: QDialog(parent),
|
||||
allGameTypes(_allGameTypes)
|
||||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup("filter_games");
|
||||
|
||||
unavailableGamesVisibleCheckBox = new QCheckBox(tr("Show &unavailable games"));
|
||||
unavailableGamesVisibleCheckBox->setChecked(
|
||||
settings.value("unavailable_games_visible", false).toBool()
|
||||
);
|
||||
|
||||
passwordProtectedGamesVisibleCheckBox = new QCheckBox(tr("Show &password protected games"));
|
||||
passwordProtectedGamesVisibleCheckBox->setChecked(
|
||||
settings.value("password_protected_games_visible", false).toBool()
|
||||
);
|
||||
|
||||
QLabel *gameNameFilterLabel = new QLabel(tr("Game &description:"));
|
||||
gameNameFilterEdit = new QLineEdit;
|
||||
gameNameFilterEdit->setText(
|
||||
settings.value("game_name_filter", "").toString()
|
||||
);
|
||||
QLabel *gameNameFilterLabel = new QLabel(tr("Game &description:"));
|
||||
gameNameFilterLabel->setBuddy(gameNameFilterEdit);
|
||||
|
||||
QLabel *creatorNameFilterLabel = new QLabel(tr("&Creator name:"));
|
||||
creatorNameFilterEdit = new QLineEdit;
|
||||
creatorNameFilterEdit->setText(
|
||||
settings.value("creator_name_filter", "").toString()
|
||||
);
|
||||
QLabel *creatorNameFilterLabel = new QLabel(tr("&Creator name:"));
|
||||
creatorNameFilterLabel->setBuddy(creatorNameFilterEdit);
|
||||
|
||||
QVBoxLayout *gameTypeFilterLayout = new QVBoxLayout;
|
||||
QMapIterator<int, QString> gameTypesIterator(allGameTypes);
|
||||
while (gameTypesIterator.hasNext()) {
|
||||
gameTypesIterator.next();
|
||||
|
||||
QCheckBox *temp = new QCheckBox(gameTypesIterator.value());
|
||||
temp->setChecked(
|
||||
settings.value(
|
||||
"game_type/" + hashGameType(gameTypesIterator.value()),
|
||||
false
|
||||
).toBool()
|
||||
);
|
||||
|
||||
gameTypeFilterCheckBoxes.insert(gameTypesIterator.key(), temp);
|
||||
gameTypeFilterLayout->addWidget(temp);
|
||||
}
|
||||
|
@ -43,14 +70,18 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
|
|||
maxPlayersFilterMinSpinBox = new QSpinBox;
|
||||
maxPlayersFilterMinSpinBox->setMinimum(1);
|
||||
maxPlayersFilterMinSpinBox->setMaximum(99);
|
||||
maxPlayersFilterMinSpinBox->setValue(1);
|
||||
maxPlayersFilterMinSpinBox->setValue(
|
||||
settings.value("min_players", 1).toInt()
|
||||
);
|
||||
maxPlayersFilterMinLabel->setBuddy(maxPlayersFilterMinSpinBox);
|
||||
|
||||
QLabel *maxPlayersFilterMaxLabel = new QLabel(tr("at &most:"));
|
||||
maxPlayersFilterMaxSpinBox = new QSpinBox;
|
||||
maxPlayersFilterMaxSpinBox->setMinimum(1);
|
||||
maxPlayersFilterMaxSpinBox->setMaximum(99);
|
||||
maxPlayersFilterMaxSpinBox->setValue(99);
|
||||
maxPlayersFilterMaxSpinBox->setValue(
|
||||
settings.value("max_players", 99).toInt()
|
||||
);
|
||||
maxPlayersFilterMaxLabel->setBuddy(maxPlayersFilterMaxSpinBox);
|
||||
|
||||
QGridLayout *maxPlayersFilterLayout = new QGridLayout;
|
||||
|
@ -83,7 +114,7 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
|
|||
hbox->addLayout(rightColumn);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
|
@ -94,6 +125,42 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
|
|||
setWindowTitle(tr("Filter games"));
|
||||
}
|
||||
|
||||
void DlgFilterGames::actOk() {
|
||||
QSettings settings;
|
||||
settings.beginGroup("filter_games");
|
||||
settings.setValue(
|
||||
"unavailable_games_visible",
|
||||
unavailableGamesVisibleCheckBox->isChecked()
|
||||
);
|
||||
settings.setValue(
|
||||
"password_protected_games_visible",
|
||||
passwordProtectedGamesVisibleCheckBox->isChecked()
|
||||
);
|
||||
settings.setValue("game_name_filter", gameNameFilterEdit->text());
|
||||
settings.setValue("creator_name_filter", creatorNameFilterEdit->text());
|
||||
|
||||
QMapIterator<int, QString> gameTypeIterator(allGameTypes);
|
||||
QMapIterator<int, QCheckBox *> checkboxIterator(gameTypeFilterCheckBoxes);
|
||||
while (gameTypeIterator.hasNext()) {
|
||||
gameTypeIterator.next();
|
||||
checkboxIterator.next();
|
||||
|
||||
settings.setValue(
|
||||
"game_type/" + hashGameType(gameTypeIterator.value()),
|
||||
checkboxIterator.value()->isChecked()
|
||||
);
|
||||
}
|
||||
|
||||
settings.setValue("min_players", maxPlayersFilterMinSpinBox->value());
|
||||
settings.setValue("max_players", maxPlayersFilterMaxSpinBox->value());
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
QString DlgFilterGames::hashGameType(const QString &gameType) const {
|
||||
return QCryptographicHash::hash(gameType.toUtf8(), QCryptographicHash::Md5).toHex();
|
||||
}
|
||||
|
||||
bool DlgFilterGames::getUnavailableGamesVisible() const
|
||||
{
|
||||
return unavailableGamesVisibleCheckBox->isChecked();
|
||||
|
|
|
@ -19,6 +19,16 @@ private:
|
|||
QMap<int, QCheckBox *> gameTypeFilterCheckBoxes;
|
||||
QSpinBox *maxPlayersFilterMinSpinBox;
|
||||
QSpinBox *maxPlayersFilterMaxSpinBox;
|
||||
|
||||
const QMap<int, QString> &allGameTypes;
|
||||
|
||||
/*
|
||||
* The game type might contain special characters, so to use it in
|
||||
* QSettings we just hash it.
|
||||
*/
|
||||
QString hashGameType(const QString &gameType) const;
|
||||
private slots:
|
||||
void actOk();
|
||||
public:
|
||||
DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *parent = 0);
|
||||
|
||||
|
|
|
@ -33,8 +33,11 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
|
|||
gameListView->header()->hideSection(1);
|
||||
else
|
||||
gameListProxyModel->setUnavailableGamesVisible(true);
|
||||
#if QT_VERSION < 0x050000
|
||||
gameListView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
|
||||
|
||||
#else
|
||||
gameListView->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
filterButton = new QPushButton;
|
||||
filterButton->setIcon(QIcon(":/resources/icon_search.svg"));
|
||||
connect(filterButton, SIGNAL(clicked()), this, SLOT(actSetFilter()));
|
||||
|
@ -81,12 +84,6 @@ void GameSelector::actSetFilter()
|
|||
if (room)
|
||||
gameTypeMap = gameListModel->getGameTypes().value(room->getRoomId());
|
||||
DlgFilterGames dlg(gameTypeMap, this);
|
||||
dlg.setUnavailableGamesVisible(gameListProxyModel->getUnavailableGamesVisible());
|
||||
dlg.setPasswordProtectedGamesVisible(gameListProxyModel->getPasswordProtectedGamesVisible());
|
||||
dlg.setGameNameFilter(gameListProxyModel->getGameNameFilter());
|
||||
dlg.setCreatorNameFilter(gameListProxyModel->getCreatorNameFilter());
|
||||
dlg.setGameTypeFilter(gameListProxyModel->getGameTypeFilter());
|
||||
dlg.setMaxPlayersFilter(gameListProxyModel->getMaxPlayersFilterMin(), gameListProxyModel->getMaxPlayersFilterMax());
|
||||
|
||||
if (!dlg.exec())
|
||||
return;
|
||||
|
|
|
@ -55,6 +55,7 @@ QString translationPath = TRANSLATION_PATH;
|
|||
QString translationPath = QString();
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
static void myMessageOutput(QtMsgType /*type*/, const char *msg)
|
||||
{
|
||||
QFile file("qdebug.txt");
|
||||
|
@ -63,6 +64,16 @@ static void myMessageOutput(QtMsgType /*type*/, const char *msg)
|
|||
out << msg << endl;
|
||||
file.close();
|
||||
}
|
||||
#else
|
||||
static void myMessageOutput(QtMsgType /*type*/, const QMessageLogContext &, const QString &msg)
|
||||
{
|
||||
QFile file("qdebug.txt");
|
||||
file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||
QTextStream out(&file);
|
||||
out << msg << endl;
|
||||
file.close();
|
||||
}
|
||||
#endif
|
||||
|
||||
void installNewTranslator()
|
||||
{
|
||||
|
@ -87,11 +98,21 @@ int main(int argc, char *argv[])
|
|||
QApplication app(argc, argv);
|
||||
|
||||
if (app.arguments().contains("--debug-output"))
|
||||
{
|
||||
#if QT_VERSION < 0x050000
|
||||
qInstallMsgHandler(myMessageOutput);
|
||||
#else
|
||||
qInstallMessageHandler(myMessageOutput);
|
||||
#endif
|
||||
}
|
||||
#ifdef Q_OS_WIN
|
||||
app.addLibraryPath(app.applicationDirPath() + "/plugins");
|
||||
#endif
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
// gone in Qt5, all source files _MUST_ be utf8-encoded
|
||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||
#endif
|
||||
|
||||
QCoreApplication::setOrganizationName("Cockatrice");
|
||||
QCoreApplication::setOrganizationDomain("cockatrice.de");
|
||||
|
@ -114,8 +135,13 @@ int main(int argc, char *argv[])
|
|||
installNewTranslator();
|
||||
|
||||
qsrand(QDateTime::currentDateTime().toTime_t());
|
||||
|
||||
|
||||
bool startMainProgram = true;
|
||||
#if QT_VERSION < 0x050000
|
||||
const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||
#else
|
||||
const QString dataDir = QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
|
||||
#endif
|
||||
if (!db->getLoadSuccess())
|
||||
if (db->loadCardDatabase(dataDir + "/cards.xml"))
|
||||
settingsCache->setCardDatabasePath(dataDir + "/cards.xml");
|
||||
|
|
|
@ -13,7 +13,11 @@ PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _c
|
|||
: CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent)
|
||||
{
|
||||
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
||||
#if QT_VERSION < 0x050000
|
||||
setAcceptsHoverEvents(true);
|
||||
#else
|
||||
setAcceptHoverEvents(true);
|
||||
#endif
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
|
||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||
|
|
|
@ -774,7 +774,13 @@ void Player::actViewLibrary()
|
|||
void Player::actViewTopCards()
|
||||
{
|
||||
bool ok;
|
||||
int number = QInputDialog::getInteger(0, tr("View top cards of library"), tr("Number of cards:"), defaultNumberTopCards, 1, 2000000000, 1, &ok);
|
||||
int number =
|
||||
#if QT_VERSION < 0x050000
|
||||
QInputDialog::getInteger(
|
||||
#else
|
||||
QInputDialog::getInt(
|
||||
#endif
|
||||
0, tr("View top cards of library"), tr("Number of cards:"), defaultNumberTopCards, 1, 2000000000, 1, &ok);
|
||||
if (ok) {
|
||||
defaultNumberTopCards = number;
|
||||
static_cast<GameScene *>(scene())->toggleZoneView(this, "deck", number);
|
||||
|
@ -829,7 +835,13 @@ void Player::actMulligan()
|
|||
|
||||
void Player::actDrawCards()
|
||||
{
|
||||
int number = QInputDialog::getInteger(0, tr("Draw cards"), tr("Number:"));
|
||||
int number =
|
||||
#if QT_VERSION < 0x050000
|
||||
QInputDialog::getInteger(
|
||||
#else
|
||||
QInputDialog::getInt(
|
||||
#endif
|
||||
0, tr("Draw cards"), tr("Number:"));
|
||||
if (number) {
|
||||
Command_DrawCards cmd;
|
||||
cmd.set_number(number);
|
||||
|
@ -844,8 +856,14 @@ void Player::actUndoDraw()
|
|||
|
||||
void Player::actMoveTopCardsToGrave()
|
||||
{
|
||||
int number = QInputDialog::getInteger(0, tr("Move top cards to grave"), tr("Number:"));
|
||||
if (!number)
|
||||
int number =
|
||||
#if QT_VERSION < 0x050000
|
||||
QInputDialog::getInteger(
|
||||
#else
|
||||
QInputDialog::getInt(
|
||||
#endif
|
||||
0, tr("Move top cards to grave"), tr("Number:"));
|
||||
if (!number)
|
||||
return;
|
||||
|
||||
const int maxCards = zones.value("deck")->getCards().size();
|
||||
|
@ -867,8 +885,14 @@ void Player::actMoveTopCardsToGrave()
|
|||
|
||||
void Player::actMoveTopCardsToExile()
|
||||
{
|
||||
int number = QInputDialog::getInteger(0, tr("Move top cards to exile"), tr("Number:"));
|
||||
if (!number)
|
||||
int number =
|
||||
#if QT_VERSION < 0x050000
|
||||
QInputDialog::getInteger(
|
||||
#else
|
||||
QInputDialog::getInt(
|
||||
#endif
|
||||
0, tr("Move top cards to exile"), tr("Number:"));
|
||||
if (!number)
|
||||
return;
|
||||
|
||||
const int maxCards = zones.value("deck")->getCards().size();
|
||||
|
@ -914,7 +938,13 @@ void Player::actUntapAll()
|
|||
void Player::actRollDie()
|
||||
{
|
||||
bool ok;
|
||||
int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
|
||||
int sides =
|
||||
#if QT_VERSION < 0x050000
|
||||
QInputDialog::getInteger(
|
||||
#else
|
||||
QInputDialog::getInt(
|
||||
#endif
|
||||
0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
|
||||
if (ok) {
|
||||
Command_RollDie cmd;
|
||||
cmd.set_sides(sides);
|
||||
|
@ -2022,7 +2052,13 @@ void Player::actCardCounterTrigger()
|
|||
case 11: {
|
||||
bool ok;
|
||||
dialogSemaphore = true;
|
||||
int number = QInputDialog::getInteger(0, tr("Set counters"), tr("Number:"), 0, 0, MAX_COUNTERS_ON_CARD, 1, &ok);
|
||||
int number =
|
||||
#if QT_VERSION < 0x050000
|
||||
QInputDialog::getInteger(
|
||||
#else
|
||||
QInputDialog::getInt(
|
||||
#endif
|
||||
0, tr("Set counters"), tr("Number:"), 0, 0, MAX_COUNTERS_ON_CARD, 1, &ok);
|
||||
dialogSemaphore = false;
|
||||
if (clearCardsToDelete())
|
||||
return;
|
||||
|
|
|
@ -72,7 +72,11 @@ PlayerListWidget::PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient
|
|||
setColumnCount(6);
|
||||
setHeaderHidden(true);
|
||||
setRootIsDecorated(false);
|
||||
#if QT_VERSION < 0x050000
|
||||
header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
|
|
|
@ -553,7 +553,7 @@ int Json::nextToken(const QString &json, int &index)
|
|||
|
||||
QChar c = json[index];
|
||||
index++;
|
||||
switch(c.toAscii())
|
||||
switch(c.toLatin1())
|
||||
{
|
||||
case '{': return JsonTokenCurlyOpen;
|
||||
case '}': return JsonTokenCurlyClose;
|
||||
|
|
|
@ -15,7 +15,7 @@ RemoteClient::RemoteClient(QObject *parent)
|
|||
: AbstractClient(parent), timeRunning(0), lastDataReceived(0), messageInProgress(false), handshakeStarted(false), messageLength(0)
|
||||
{
|
||||
timer = new QTimer(this);
|
||||
timer->setInterval(9000);
|
||||
timer->setInterval(1000);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(ping()));
|
||||
|
||||
socket = new QTcpSocket(this);
|
||||
|
|
|
@ -258,8 +258,11 @@ void RemoteDeckList_TreeModel::deckListFinished(const Response &r)
|
|||
{
|
||||
const Response_DeckList &resp = r.GetExtension(Response_DeckList::ext);
|
||||
|
||||
beginResetModel();
|
||||
|
||||
root->clearTree();
|
||||
reset();
|
||||
|
||||
endResetModel();
|
||||
|
||||
ServerInfo_DeckStorage_TreeItem tempRoot;
|
||||
tempRoot.set_id(0);
|
||||
|
@ -280,7 +283,11 @@ RemoteDeckList_TreeWidget::RemoteDeckList_TreeWidget(AbstractClient *_client, QW
|
|||
setModel(proxyModel);
|
||||
connect(treeModel, SIGNAL(treeRefreshed()), this, SLOT(expandAll()));
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
setUniformRowHeights(true);
|
||||
setSortingEnabled(true);
|
||||
proxyModel->sort(0, Qt::AscendingOrder);
|
||||
|
|
|
@ -278,7 +278,11 @@ RemoteReplayList_TreeWidget::RemoteReplayList_TreeWidget(AbstractClient *_client
|
|||
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
setModel(proxyModel);
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
header()->setStretchLastSection(false);
|
||||
setUniformRowHeights(true);
|
||||
setSortingEnabled(true);
|
||||
|
|
|
@ -33,8 +33,13 @@ void SoundEngine::soundEnabledChanged()
|
|||
if (settingsCache->getSoundEnabled()) {
|
||||
qDebug("SoundEngine: enabling sound");
|
||||
QAudioFormat format;
|
||||
#if QT_VERSION < 0x050000
|
||||
format.setFrequency(44100);
|
||||
format.setChannels(1);
|
||||
#else
|
||||
format.setSampleRate(44100);
|
||||
format.setChannelCount(1);
|
||||
#endif
|
||||
format.setSampleSize(16);
|
||||
format.setCodec("audio/pcm");
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
virtual QString getTabText() const = 0;
|
||||
virtual void retranslateUi() = 0;
|
||||
virtual void closeRequest() { }
|
||||
virtual void tabActivated() { }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -134,7 +134,11 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
|||
deckView->setUniformRowHeights(true);
|
||||
deckView->setSortingEnabled(true);
|
||||
deckView->sortByColumn(1, Qt::AscendingOrder);
|
||||
#if QT_VERSION < 0x050000
|
||||
deckView->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
deckView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
deckView->installEventFilter(&deckViewKeySignals);
|
||||
connect(deckView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoRight(const QModelIndex &, const QModelIndex &)));
|
||||
connect(&deckViewKeySignals, SIGNAL(onEnter()), this, SLOT(actIncrement()));
|
||||
|
|
|
@ -38,7 +38,11 @@ TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_c
|
|||
localDirView->setColumnHidden(1, true);
|
||||
localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0));
|
||||
localDirView->setSortingEnabled(true);
|
||||
#if QT_VERSION < 0x050000
|
||||
localDirView->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
localDirView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
localDirView->header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||
|
||||
leftToolBar = new QToolBar;
|
||||
|
|
|
@ -49,6 +49,12 @@ void TabMessage::retranslateUi()
|
|||
aLeave->setText(tr("&Leave"));
|
||||
}
|
||||
|
||||
void TabMessage::tabActivated()
|
||||
{
|
||||
if(!sayEdit->hasFocus())
|
||||
sayEdit->setFocus();
|
||||
}
|
||||
|
||||
QString TabMessage::getUserName() const
|
||||
{
|
||||
return QString::fromStdString(otherUserInfo->name());
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
~TabMessage();
|
||||
void retranslateUi();
|
||||
void closeRequest();
|
||||
void tabActivated();
|
||||
QString getUserName() const;
|
||||
QString getTabText() const;
|
||||
|
||||
|
|
|
@ -36,7 +36,11 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client)
|
|||
localDirView->setColumnHidden(1, true);
|
||||
localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0));
|
||||
localDirView->setSortingEnabled(true);
|
||||
#if QT_VERSION < 0x050000
|
||||
localDirView->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
localDirView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
localDirView->header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||
|
||||
leftToolBar = new QToolBar;
|
||||
|
|
|
@ -121,6 +121,12 @@ void TabRoom::closeRequest()
|
|||
actLeaveRoom();
|
||||
}
|
||||
|
||||
void TabRoom::tabActivated()
|
||||
{
|
||||
if(!sayEdit->hasFocus())
|
||||
sayEdit->setFocus();
|
||||
}
|
||||
|
||||
QString TabRoom::sanitizeHtml(QString dirty) const
|
||||
{
|
||||
return dirty
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
~TabRoom();
|
||||
void retranslateUi();
|
||||
void closeRequest();
|
||||
void tabActivated();
|
||||
void processRoomEvent(const RoomEvent &event);
|
||||
int getRoomId() const { return roomId; }
|
||||
const QMap<int, QString> &getGameTypes() const { return gameTypes; }
|
||||
|
|
|
@ -28,11 +28,17 @@ RoomSelector::RoomSelector(AbstractClient *_client, QWidget *parent)
|
|||
roomList->setRootIsDecorated(false);
|
||||
roomList->setColumnCount(4);
|
||||
roomList->header()->setStretchLastSection(false);
|
||||
#if QT_VERSION < 0x050000
|
||||
roomList->header()->setResizeMode(0, QHeaderView::ResizeToContents);
|
||||
roomList->header()->setResizeMode(1, QHeaderView::Stretch);
|
||||
roomList->header()->setResizeMode(2, QHeaderView::ResizeToContents);
|
||||
roomList->header()->setResizeMode(3, QHeaderView::ResizeToContents);
|
||||
|
||||
#else
|
||||
roomList->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
roomList->header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
roomList->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
||||
roomList->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
joinButton = new QPushButton;
|
||||
connect(joinButton, SIGNAL(clicked()), this, SLOT(joinClicked()));
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
|
|
|
@ -479,6 +479,7 @@ void TabSupervisor::updateCurrent(int index)
|
|||
tab->setContentsChanged(false);
|
||||
}
|
||||
emit setMenu(static_cast<Tab *>(widget(index))->getTabMenus());
|
||||
tab->tabActivated();
|
||||
} else
|
||||
emit setMenu();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,11 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
|||
currentMinimumWidth = minWidth;
|
||||
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
#if QT_VERSION < 0x050000
|
||||
setAcceptsHoverEvents(true);
|
||||
#else
|
||||
setAcceptHoverEvents(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TableZone::updateBgPixmap()
|
||||
|
|
|
@ -216,7 +216,11 @@ UserList::UserList(TabSupervisor *_tabSupervisor, AbstractClient *_client, UserL
|
|||
|
||||
userTree = new QTreeWidget;
|
||||
userTree->setColumnCount(3);
|
||||
#if QT_VERSION < 0x050000
|
||||
userTree->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
userTree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
userTree->setHeaderHidden(true);
|
||||
userTree->setRootIsDecorated(false);
|
||||
userTree->setIconSize(QSize(20, 12));
|
||||
|
|
|
@ -28,7 +28,20 @@ SET(common_SOURCES
|
|||
sfmt/SFMT.c
|
||||
)
|
||||
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
set(ORACLE_LIBS)
|
||||
|
||||
# Qt4 stuff
|
||||
if(Qt4_FOUND)
|
||||
# Include directories
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
include_directories(${QT_INCLUDES})
|
||||
endif()
|
||||
|
||||
# qt5 stuff
|
||||
if(Qt5Widgets_FOUND)
|
||||
include_directories(${Qt5Widgets_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
INCLUDE_DIRECTORIES(pb)
|
||||
INCLUDE_DIRECTORIES(sfmt)
|
||||
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
|
||||
|
|
|
@ -10,26 +10,26 @@
|
|||
#ifdef QT_GUI_LIB
|
||||
inline QColor convertColorToQColor(const color &c)
|
||||
{
|
||||
return QColor(c.r(), c.g(), c.b());
|
||||
return QColor(c.r(), c.g(), c.b());
|
||||
}
|
||||
|
||||
inline color convertQColorToColor(const QColor &c)
|
||||
{
|
||||
color result;
|
||||
result.set_r(c.red());
|
||||
result.set_g(c.green());
|
||||
result.set_b(c.blue());
|
||||
return result;
|
||||
color result;
|
||||
result.set_r(c.red());
|
||||
result.set_g(c.green());
|
||||
result.set_b(c.blue());
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline color makeColor(int r, int g, int b)
|
||||
{
|
||||
color result;
|
||||
result.set_r(r);
|
||||
result.set_g(g);
|
||||
result.set_b(b);
|
||||
return result;
|
||||
color result;
|
||||
result.set_r(r);
|
||||
result.set_g(g);
|
||||
result.set_b(b);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -23,152 +23,152 @@ class InnerDecklistNode;
|
|||
|
||||
class SideboardPlan {
|
||||
private:
|
||||
QString name;
|
||||
QList<MoveCard_ToZone> moveList;
|
||||
QString name;
|
||||
QList<MoveCard_ToZone> moveList;
|
||||
public:
|
||||
SideboardPlan(const QString &_name = QString(), const QList<MoveCard_ToZone> &_moveList = QList<MoveCard_ToZone>());
|
||||
bool readElement(QXmlStreamReader *xml);
|
||||
void write(QXmlStreamWriter *xml);
|
||||
SideboardPlan(const QString &_name = QString(), const QList<MoveCard_ToZone> &_moveList = QList<MoveCard_ToZone>());
|
||||
bool readElement(QXmlStreamReader *xml);
|
||||
void write(QXmlStreamWriter *xml);
|
||||
|
||||
QString getName() const { return name; }
|
||||
const QList<MoveCard_ToZone> &getMoveList() const { return moveList; }
|
||||
void setMoveList(const QList<MoveCard_ToZone> &_moveList);
|
||||
QString getName() const { return name; }
|
||||
const QList<MoveCard_ToZone> &getMoveList() const { return moveList; }
|
||||
void setMoveList(const QList<MoveCard_ToZone> &_moveList);
|
||||
};
|
||||
|
||||
enum DeckSortMethod { ByNumber, ByName, ByPrice };
|
||||
|
||||
class AbstractDecklistNode {
|
||||
protected:
|
||||
InnerDecklistNode *parent;
|
||||
DeckSortMethod sortMethod;
|
||||
InnerDecklistNode *parent;
|
||||
DeckSortMethod sortMethod;
|
||||
public:
|
||||
AbstractDecklistNode(InnerDecklistNode *_parent = 0);
|
||||
virtual ~AbstractDecklistNode() { }
|
||||
virtual void setSortMethod(DeckSortMethod method) { sortMethod = method; }
|
||||
virtual QString getName() const = 0;
|
||||
InnerDecklistNode *getParent() const { return parent; }
|
||||
int depth() const;
|
||||
virtual int height() const = 0;
|
||||
virtual bool compare(AbstractDecklistNode *other) const = 0;
|
||||
AbstractDecklistNode(InnerDecklistNode *_parent = 0);
|
||||
virtual ~AbstractDecklistNode() { }
|
||||
virtual void setSortMethod(DeckSortMethod method) { sortMethod = method; }
|
||||
virtual QString getName() const = 0;
|
||||
InnerDecklistNode *getParent() const { return parent; }
|
||||
int depth() const;
|
||||
virtual int height() const = 0;
|
||||
virtual bool compare(AbstractDecklistNode *other) const = 0;
|
||||
|
||||
virtual bool readElement(QXmlStreamReader *xml) = 0;
|
||||
virtual void writeElement(QXmlStreamWriter *xml) = 0;
|
||||
virtual bool readElement(QXmlStreamReader *xml) = 0;
|
||||
virtual void writeElement(QXmlStreamWriter *xml) = 0;
|
||||
};
|
||||
|
||||
class InnerDecklistNode : public AbstractDecklistNode, public QList<AbstractDecklistNode *> {
|
||||
private:
|
||||
QString name;
|
||||
class compareFunctor;
|
||||
QString name;
|
||||
class compareFunctor;
|
||||
public:
|
||||
InnerDecklistNode(const QString &_name = QString(), InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent), name(_name) { }
|
||||
InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent = 0);
|
||||
virtual ~InnerDecklistNode();
|
||||
void setSortMethod(DeckSortMethod method);
|
||||
QString getName() const { return name; }
|
||||
void setName(const QString &_name) { name = _name; }
|
||||
static QString visibleNameFromName(const QString &_name);
|
||||
virtual QString getVisibleName() const;
|
||||
void clearTree();
|
||||
AbstractDecklistNode *findChild(const QString &name);
|
||||
int height() const;
|
||||
int recursiveCount(bool countTotalCards = false) const;
|
||||
InnerDecklistNode(const QString &_name = QString(), InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent), name(_name) { }
|
||||
InnerDecklistNode(InnerDecklistNode *other, InnerDecklistNode *_parent = 0);
|
||||
virtual ~InnerDecklistNode();
|
||||
void setSortMethod(DeckSortMethod method);
|
||||
QString getName() const { return name; }
|
||||
void setName(const QString &_name) { name = _name; }
|
||||
static QString visibleNameFromName(const QString &_name);
|
||||
virtual QString getVisibleName() const;
|
||||
void clearTree();
|
||||
AbstractDecklistNode *findChild(const QString &name);
|
||||
int height() const;
|
||||
int recursiveCount(bool countTotalCards = false) const;
|
||||
float recursivePrice(bool countTotalCards = false) const;
|
||||
bool compare(AbstractDecklistNode *other) const;
|
||||
bool compareNumber(AbstractDecklistNode *other) const;
|
||||
bool compareName(AbstractDecklistNode *other) const;
|
||||
bool comparePrice(AbstractDecklistNode *other) const;
|
||||
QVector<QPair<int, int> > sort(Qt::SortOrder order = Qt::AscendingOrder);
|
||||
bool compare(AbstractDecklistNode *other) const;
|
||||
bool compareNumber(AbstractDecklistNode *other) const;
|
||||
bool compareName(AbstractDecklistNode *other) const;
|
||||
bool comparePrice(AbstractDecklistNode *other) const;
|
||||
QVector<QPair<int, int> > sort(Qt::SortOrder order = Qt::AscendingOrder);
|
||||
|
||||
bool readElement(QXmlStreamReader *xml);
|
||||
void writeElement(QXmlStreamWriter *xml);
|
||||
bool readElement(QXmlStreamReader *xml);
|
||||
void writeElement(QXmlStreamWriter *xml);
|
||||
};
|
||||
|
||||
class AbstractDecklistCardNode : public AbstractDecklistNode {
|
||||
public:
|
||||
AbstractDecklistCardNode(InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent) { }
|
||||
virtual int getNumber() const = 0;
|
||||
virtual void setNumber(int _number) = 0;
|
||||
virtual QString getName() const = 0;
|
||||
virtual void setName(const QString &_name) = 0;
|
||||
AbstractDecklistCardNode(InnerDecklistNode *_parent = 0) : AbstractDecklistNode(_parent) { }
|
||||
virtual int getNumber() const = 0;
|
||||
virtual void setNumber(int _number) = 0;
|
||||
virtual QString getName() const = 0;
|
||||
virtual void setName(const QString &_name) = 0;
|
||||
virtual float getPrice() const = 0;
|
||||
virtual void setPrice(const float _price) = 0;
|
||||
float getTotalPrice() const { return getNumber() * getPrice(); }
|
||||
int height() const { return 0; }
|
||||
bool compare(AbstractDecklistNode *other) const;
|
||||
bool compareNumber(AbstractDecklistNode *other) const;
|
||||
bool compareName(AbstractDecklistNode *other) const;
|
||||
bool compareTotalPrice(AbstractDecklistNode *other) const;
|
||||
int height() const { return 0; }
|
||||
bool compare(AbstractDecklistNode *other) const;
|
||||
bool compareNumber(AbstractDecklistNode *other) const;
|
||||
bool compareName(AbstractDecklistNode *other) const;
|
||||
bool compareTotalPrice(AbstractDecklistNode *other) const;
|
||||
|
||||
bool readElement(QXmlStreamReader *xml);
|
||||
void writeElement(QXmlStreamWriter *xml);
|
||||
bool readElement(QXmlStreamReader *xml);
|
||||
void writeElement(QXmlStreamWriter *xml);
|
||||
};
|
||||
|
||||
class DecklistCardNode : public AbstractDecklistCardNode {
|
||||
private:
|
||||
QString name;
|
||||
int number;
|
||||
QString name;
|
||||
int number;
|
||||
float price;
|
||||
public:
|
||||
DecklistCardNode(const QString &_name = QString(), int _number = 1, float _price = 0, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number), price(_price) { }
|
||||
DecklistCardNode(const QString &_name = QString(), int _number = 1, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number), price(0) { }
|
||||
DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent);
|
||||
int getNumber() const { return number; }
|
||||
void setNumber(int _number) { number = _number; }
|
||||
QString getName() const { return name; }
|
||||
void setName(const QString &_name) { name = _name; }
|
||||
DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent);
|
||||
int getNumber() const { return number; }
|
||||
void setNumber(int _number) { number = _number; }
|
||||
QString getName() const { return name; }
|
||||
void setName(const QString &_name) { name = _name; }
|
||||
float getPrice() const { return price; }
|
||||
void setPrice(const float _price) { price = _price; }
|
||||
};
|
||||
|
||||
class DeckList : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString name, comments;
|
||||
QString deckHash;
|
||||
QMap<QString, SideboardPlan *> sideboardPlans;
|
||||
InnerDecklistNode *root;
|
||||
void getCardListHelper(InnerDecklistNode *node, QSet<QString> &result) const;
|
||||
QString name, comments;
|
||||
QString deckHash;
|
||||
QMap<QString, SideboardPlan *> sideboardPlans;
|
||||
InnerDecklistNode *root;
|
||||
void getCardListHelper(InnerDecklistNode *node, QSet<QString> &result) const;
|
||||
signals:
|
||||
void deckHashChanged();
|
||||
void deckHashChanged();
|
||||
public slots:
|
||||
void setName(const QString &_name = QString()) { name = _name; }
|
||||
void setComments(const QString &_comments = QString()) { comments = _comments; }
|
||||
void setName(const QString &_name = QString()) { name = _name; }
|
||||
void setComments(const QString &_comments = QString()) { comments = _comments; }
|
||||
public:
|
||||
DeckList();
|
||||
DeckList(const DeckList &other);
|
||||
DeckList(const QString &nativeString);
|
||||
~DeckList();
|
||||
QString getName() const { return name; }
|
||||
QString getComments() const { return comments; }
|
||||
QList<MoveCard_ToZone> getCurrentSideboardPlan();
|
||||
void setCurrentSideboardPlan(const QList<MoveCard_ToZone> &plan);
|
||||
const QMap<QString, SideboardPlan *> &getSideboardPlans() const { return sideboardPlans; }
|
||||
DeckList();
|
||||
DeckList(const DeckList &other);
|
||||
DeckList(const QString &nativeString);
|
||||
~DeckList();
|
||||
QString getName() const { return name; }
|
||||
QString getComments() const { return comments; }
|
||||
QList<MoveCard_ToZone> getCurrentSideboardPlan();
|
||||
void setCurrentSideboardPlan(const QList<MoveCard_ToZone> &plan);
|
||||
const QMap<QString, SideboardPlan *> &getSideboardPlans() const { return sideboardPlans; }
|
||||
|
||||
bool readElement(QXmlStreamReader *xml);
|
||||
void write(QXmlStreamWriter *xml);
|
||||
bool loadFromXml(QXmlStreamReader *xml);
|
||||
bool loadFromString_Native(const QString &nativeString);
|
||||
QString writeToString_Native();
|
||||
bool loadFromFile_Native(QIODevice *device);
|
||||
bool saveToFile_Native(QIODevice *device);
|
||||
bool loadFromStream_Plain(QTextStream &stream);
|
||||
bool loadFromFile_Plain(QIODevice *device);
|
||||
bool saveToStream_Plain(QTextStream &stream);
|
||||
bool saveToFile_Plain(QIODevice *device);
|
||||
QString writeToString_Plain();
|
||||
bool readElement(QXmlStreamReader *xml);
|
||||
void write(QXmlStreamWriter *xml);
|
||||
bool loadFromXml(QXmlStreamReader *xml);
|
||||
bool loadFromString_Native(const QString &nativeString);
|
||||
QString writeToString_Native();
|
||||
bool loadFromFile_Native(QIODevice *device);
|
||||
bool saveToFile_Native(QIODevice *device);
|
||||
bool loadFromStream_Plain(QTextStream &stream);
|
||||
bool loadFromFile_Plain(QIODevice *device);
|
||||
bool saveToStream_Plain(QTextStream &stream);
|
||||
bool saveToFile_Plain(QIODevice *device);
|
||||
QString writeToString_Plain();
|
||||
|
||||
void cleanList();
|
||||
bool isEmpty() const { return root->isEmpty() && name.isEmpty() && comments.isEmpty() && sideboardPlans.isEmpty(); }
|
||||
QStringList getCardList() const;
|
||||
void cleanList();
|
||||
bool isEmpty() const { return root->isEmpty() && name.isEmpty() && comments.isEmpty() && sideboardPlans.isEmpty(); }
|
||||
QStringList getCardList() const;
|
||||
|
||||
int getSideboardSize() const;
|
||||
|
||||
QString getDeckHash() const { return deckHash; }
|
||||
void updateDeckHash();
|
||||
QString getDeckHash() const { return deckHash; }
|
||||
void updateDeckHash();
|
||||
|
||||
InnerDecklistNode *getRoot() const { return root; }
|
||||
DecklistCardNode *addCard(const QString &cardName, const QString &zoneName);
|
||||
bool deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNode = 0);
|
||||
InnerDecklistNode *getRoot() const { return root; }
|
||||
DecklistCardNode *addCard(const QString &cardName, const QString &zoneName);
|
||||
bool deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNode = 0);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
int getPbExtension(const ::google::protobuf::Message &message)
|
||||
{
|
||||
std::vector< const ::google::protobuf::FieldDescriptor * > fieldList;
|
||||
message.GetReflection()->ListFields(message, &fieldList);
|
||||
for (unsigned int j = 0; j < fieldList.size(); ++j)
|
||||
if (fieldList[j]->is_extension())
|
||||
return fieldList[j]->number();
|
||||
return -1;
|
||||
std::vector< const ::google::protobuf::FieldDescriptor * > fieldList;
|
||||
message.GetReflection()->ListFields(message, &fieldList);
|
||||
for (unsigned int j = 0; j < fieldList.size(); ++j)
|
||||
if (fieldList[j]->is_extension())
|
||||
return fieldList[j]->number();
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#define GET_PB_EXTENSION_H
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
class Message;
|
||||
}
|
||||
namespace protobuf {
|
||||
class Message;
|
||||
}
|
||||
}
|
||||
|
||||
int getPbExtension(const ::google::protobuf::Message &message);
|
||||
|
|
|
@ -4,27 +4,27 @@
|
|||
|
||||
QVector<int> RNG_Abstract::makeNumbersVector(int n, int min, int max)
|
||||
{
|
||||
const int bins = max - min + 1;
|
||||
QVector<int> result(bins);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
int number = rand(min, max);
|
||||
if ((number < min) || (number > max))
|
||||
qDebug() << "rand(" << min << "," << max << ") returned " << number;
|
||||
else
|
||||
result[number - min]++;
|
||||
}
|
||||
return result;
|
||||
const int bins = max - min + 1;
|
||||
QVector<int> result(bins);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
int number = rand(min, max);
|
||||
if ((number < min) || (number > max))
|
||||
qDebug() << "rand(" << min << "," << max << ") returned " << number;
|
||||
else
|
||||
result[number - min]++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
double RNG_Abstract::testRandom(const QVector<int> &numbers) const
|
||||
{
|
||||
int n = 0;
|
||||
for (int i = 0; i < numbers.size(); ++i)
|
||||
n += numbers[i];
|
||||
double expected = (double) n / (double) numbers.size();
|
||||
double chisq = 0;
|
||||
for (int i = 0; i < numbers.size(); ++i)
|
||||
chisq += ((double) numbers[i] - expected) * ((double) numbers[i] - expected) / expected;
|
||||
|
||||
return chisq;
|
||||
int n = 0;
|
||||
for (int i = 0; i < numbers.size(); ++i)
|
||||
n += numbers[i];
|
||||
double expected = (double) n / (double) numbers.size();
|
||||
double chisq = 0;
|
||||
for (int i = 0; i < numbers.size(); ++i)
|
||||
chisq += ((double) numbers[i] - expected) * ((double) numbers[i] - expected) / expected;
|
||||
|
||||
return chisq;
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
#include <QVector>
|
||||
|
||||
class RNG_Abstract : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
RNG_Abstract(QObject *parent = 0) : QObject(parent) { }
|
||||
virtual unsigned int rand(int min, int max) = 0;
|
||||
QVector<int> makeNumbersVector(int n, int min, int max);
|
||||
double testRandom(const QVector<int> &numbers) const;
|
||||
RNG_Abstract(QObject *parent = 0) : QObject(parent) { }
|
||||
virtual unsigned int rand(int min, int max) = 0;
|
||||
QVector<int> makeNumbersVector(int n, int min, int max);
|
||||
double testRandom(const QVector<int> &numbers) const;
|
||||
};
|
||||
|
||||
extern RNG_Abstract *rng;
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
#endif
|
||||
|
||||
RNG_SFMT::RNG_SFMT(QObject *parent)
|
||||
: RNG_Abstract(parent)
|
||||
: RNG_Abstract(parent)
|
||||
{
|
||||
// initialize the random number generator with a 32bit integer seed (timestamp)
|
||||
sfmt_init_gen_rand(&sfmt, QDateTime::currentDateTime().toTime_t());
|
||||
// initialize the random number generator with a 32bit integer seed (timestamp)
|
||||
sfmt_init_gen_rand(&sfmt, QDateTime::currentDateTime().toTime_t());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,11 +32,11 @@ unsigned int RNG_SFMT::rand(int min, int max) {
|
|||
* There has been no use for negative random numbers with rand() though, so it's treated as error.
|
||||
*/
|
||||
if(min < 0) {
|
||||
throw std::invalid_argument(
|
||||
QString("Invalid bounds for RNG: Got min " +
|
||||
QString::number(min) + " < 0!\n").toStdString());
|
||||
// at this point, the method exits. No return value is needed, because
|
||||
// basically the exception itself is returned.
|
||||
throw std::invalid_argument(
|
||||
QString("Invalid bounds for RNG: Got min " +
|
||||
QString::number(min) + " < 0!\n").toStdString());
|
||||
// at this point, the method exits. No return value is needed, because
|
||||
// basically the exception itself is returned.
|
||||
}
|
||||
|
||||
// For complete fairness and equal timing, this should be a roll, but let's skip it anyway
|
||||
|
@ -99,38 +99,38 @@ unsigned int RNG_SFMT::rand(int min, int max) {
|
|||
*/
|
||||
unsigned int RNG_SFMT::cdf(unsigned int min, unsigned int max)
|
||||
{
|
||||
// This all makes no sense if min > max, which should never happen.
|
||||
if(min > max) {
|
||||
throw std::invalid_argument(
|
||||
QString("Invalid bounds for RNG: min > max! Values were: min = " +
|
||||
QString::number(min) + ", max = " +
|
||||
QString::number(max)).toStdString());
|
||||
// at this point, the method exits. No return value is needed, because
|
||||
// basically the exception itself is returned.
|
||||
}
|
||||
// This all makes no sense if min > max, which should never happen.
|
||||
if(min > max) {
|
||||
throw std::invalid_argument(
|
||||
QString("Invalid bounds for RNG: min > max! Values were: min = " +
|
||||
QString::number(min) + ", max = " +
|
||||
QString::number(max)).toStdString());
|
||||
// at this point, the method exits. No return value is needed, because
|
||||
// basically the exception itself is returned.
|
||||
}
|
||||
|
||||
// First compute the diameter (aka size, length) of the [min, max] interval
|
||||
const unsigned int diameter = max - min + 1;
|
||||
// First compute the diameter (aka size, length) of the [min, max] interval
|
||||
const unsigned int diameter = max - min + 1;
|
||||
|
||||
// Compute how many buckets (each in size of the diameter) will fit into the
|
||||
// universe.
|
||||
// If the division has a remainder, the result is floored automatically.
|
||||
const uint64_t buckets = UINT64_MAX / diameter;
|
||||
// Compute how many buckets (each in size of the diameter) will fit into the
|
||||
// universe.
|
||||
// If the division has a remainder, the result is floored automatically.
|
||||
const uint64_t buckets = UINT64_MAX / diameter;
|
||||
|
||||
// Compute the last valid random number. All numbers beyond have to be ignored.
|
||||
// If there was no remainder in the previous step, limit is equal to UINT64_MAX.
|
||||
const uint64_t limit = diameter * buckets;
|
||||
// Compute the last valid random number. All numbers beyond have to be ignored.
|
||||
// If there was no remainder in the previous step, limit is equal to UINT64_MAX.
|
||||
const uint64_t limit = diameter * buckets;
|
||||
|
||||
uint64_t rand;
|
||||
// To make the random number generation thread-safe, a mutex is created around
|
||||
// the generation. Outside of the loop of course, to avoid lock/unlock overhead.
|
||||
mutex.lock();
|
||||
do {
|
||||
rand = sfmt_genrand_uint64(&sfmt);
|
||||
} while (rand >= limit);
|
||||
mutex.unlock();
|
||||
uint64_t rand;
|
||||
// To make the random number generation thread-safe, a mutex is created around
|
||||
// the generation. Outside of the loop of course, to avoid lock/unlock overhead.
|
||||
mutex.lock();
|
||||
do {
|
||||
rand = sfmt_genrand_uint64(&sfmt);
|
||||
} while (rand >= limit);
|
||||
mutex.unlock();
|
||||
|
||||
// Now determine the bucket containing the SFMT() random number and after adding
|
||||
// the lower bound, a random number from [min, max] can be returned.
|
||||
return (unsigned int) (rand / buckets + min);
|
||||
// Now determine the bucket containing the SFMT() random number and after adding
|
||||
// the lower bound, a random number from [min, max] can be returned.
|
||||
return (unsigned int) (rand / buckets + min);
|
||||
}
|
||||
|
|
|
@ -26,15 +26,15 @@
|
|||
*/
|
||||
|
||||
class RNG_SFMT : public RNG_Abstract {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
QMutex mutex;
|
||||
sfmt_t sfmt;
|
||||
// The discrete cumulative distribution function for the RNG
|
||||
unsigned int cdf(unsigned int min, unsigned int max);
|
||||
QMutex mutex;
|
||||
sfmt_t sfmt;
|
||||
// The discrete cumulative distribution function for the RNG
|
||||
unsigned int cdf(unsigned int min, unsigned int max);
|
||||
public:
|
||||
RNG_SFMT(QObject *parent = 0);
|
||||
unsigned int rand(int min, int max);
|
||||
RNG_SFMT(QObject *parent = 0);
|
||||
unsigned int rand(int min, int max);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -139,7 +139,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||
databaseInterface->unlockSessionTables();
|
||||
return RegistrationRequired;
|
||||
}
|
||||
|
||||
|
||||
QString tempName = name;
|
||||
int i = 0;
|
||||
while (users.contains(tempName) || databaseInterface->userExists(tempName) || databaseInterface->userSessionExists(tempName))
|
||||
|
|
152
common/server.h
152
common/server.h
|
@ -31,87 +31,87 @@ enum AuthenticationResult { NotLoggedIn = 0, PasswordRight = 1, UnknownUser = 2,
|
|||
|
||||
class Server : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void pingClockTimeout();
|
||||
void sigSendIslMessage(const IslMessage &message, int serverId);
|
||||
void endSession(qint64 sessionId);
|
||||
void pingClockTimeout();
|
||||
void sigSendIslMessage(const IslMessage &message, int serverId);
|
||||
void endSession(qint64 sessionId);
|
||||
private slots:
|
||||
void broadcastRoomUpdate(const ServerInfo_Room &roomInfo, bool sendToIsl = false);
|
||||
void broadcastRoomUpdate(const ServerInfo_Room &roomInfo, bool sendToIsl = false);
|
||||
public:
|
||||
mutable QReadWriteLock clientsLock, roomsLock; // locking order: roomsLock before clientsLock
|
||||
Server(bool _threaded, QObject *parent = 0);
|
||||
~Server();
|
||||
void setThreaded(bool _threaded) { threaded = _threaded; }
|
||||
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reason, int &secondsLeft);
|
||||
const QMap<int, Server_Room *> &getRooms() { return rooms; }
|
||||
|
||||
Server_AbstractUserInterface *findUser(const QString &userName) const;
|
||||
const QMap<QString, Server_ProtocolHandler *> &getUsers() const { return users; }
|
||||
const QMap<qint64, Server_ProtocolHandler *> &getUsersBySessionId() const { return usersBySessionId; }
|
||||
void addClient(Server_ProtocolHandler *player);
|
||||
void removeClient(Server_ProtocolHandler *player);
|
||||
virtual QString getLoginMessage() const { return QString(); }
|
||||
|
||||
virtual bool getGameShouldPing() const { return false; }
|
||||
virtual int getMaxGameInactivityTime() const { return 9999999; }
|
||||
virtual int getMaxPlayerInactivityTime() const { return 9999999; }
|
||||
virtual int getMessageCountingInterval() const { return 0; }
|
||||
virtual int getMaxMessageCountPerInterval() const { return 0; }
|
||||
virtual int getMaxMessageSizePerInterval() const { return 0; }
|
||||
virtual int getMaxGamesPerUser() const { return 0; }
|
||||
virtual bool getThreaded() const { return false; }
|
||||
|
||||
Server_DatabaseInterface *getDatabaseInterface() const;
|
||||
int getNextLocalGameId() { QMutexLocker locker(&nextLocalGameIdMutex); return ++nextLocalGameId; }
|
||||
|
||||
void sendIsl_Response(const Response &item, int serverId = -1, qint64 sessionId = -1);
|
||||
void sendIsl_SessionEvent(const SessionEvent &item, int serverId = -1, qint64 sessionId = -1);
|
||||
void sendIsl_GameEventContainer(const GameEventContainer &item, int serverId = -1, qint64 sessionId = -1);
|
||||
void sendIsl_RoomEvent(const RoomEvent &item, int serverId = -1, qint64 sessionId = -1);
|
||||
void sendIsl_GameCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId, int playerId);
|
||||
void sendIsl_RoomCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId);
|
||||
|
||||
void addExternalUser(const ServerInfo_User &userInfo);
|
||||
void removeExternalUser(const QString &userName);
|
||||
const QMap<QString, Server_AbstractUserInterface *> &getExternalUsers() const { return externalUsers; }
|
||||
|
||||
void addPersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
|
||||
void removePersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
|
||||
QList<PlayerReference> getPersistentPlayerReferences(const QString &userName) const;
|
||||
mutable QReadWriteLock clientsLock, roomsLock; // locking order: roomsLock before clientsLock
|
||||
Server(bool _threaded, QObject *parent = 0);
|
||||
~Server();
|
||||
void setThreaded(bool _threaded) { threaded = _threaded; }
|
||||
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reason, int &secondsLeft);
|
||||
const QMap<int, Server_Room *> &getRooms() { return rooms; }
|
||||
|
||||
Server_AbstractUserInterface *findUser(const QString &userName) const;
|
||||
const QMap<QString, Server_ProtocolHandler *> &getUsers() const { return users; }
|
||||
const QMap<qint64, Server_ProtocolHandler *> &getUsersBySessionId() const { return usersBySessionId; }
|
||||
void addClient(Server_ProtocolHandler *player);
|
||||
void removeClient(Server_ProtocolHandler *player);
|
||||
virtual QString getLoginMessage() const { return QString(); }
|
||||
|
||||
virtual bool getGameShouldPing() const { return false; }
|
||||
virtual int getMaxGameInactivityTime() const { return 9999999; }
|
||||
virtual int getMaxPlayerInactivityTime() const { return 9999999; }
|
||||
virtual int getMessageCountingInterval() const { return 0; }
|
||||
virtual int getMaxMessageCountPerInterval() const { return 0; }
|
||||
virtual int getMaxMessageSizePerInterval() const { return 0; }
|
||||
virtual int getMaxGamesPerUser() const { return 0; }
|
||||
virtual bool getThreaded() const { return false; }
|
||||
|
||||
Server_DatabaseInterface *getDatabaseInterface() const;
|
||||
int getNextLocalGameId() { QMutexLocker locker(&nextLocalGameIdMutex); return ++nextLocalGameId; }
|
||||
|
||||
void sendIsl_Response(const Response &item, int serverId = -1, qint64 sessionId = -1);
|
||||
void sendIsl_SessionEvent(const SessionEvent &item, int serverId = -1, qint64 sessionId = -1);
|
||||
void sendIsl_GameEventContainer(const GameEventContainer &item, int serverId = -1, qint64 sessionId = -1);
|
||||
void sendIsl_RoomEvent(const RoomEvent &item, int serverId = -1, qint64 sessionId = -1);
|
||||
void sendIsl_GameCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId, int playerId);
|
||||
void sendIsl_RoomCommand(const CommandContainer &item, int serverId, qint64 sessionId, int roomId);
|
||||
|
||||
void addExternalUser(const ServerInfo_User &userInfo);
|
||||
void removeExternalUser(const QString &userName);
|
||||
const QMap<QString, Server_AbstractUserInterface *> &getExternalUsers() const { return externalUsers; }
|
||||
|
||||
void addPersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
|
||||
void removePersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
|
||||
QList<PlayerReference> getPersistentPlayerReferences(const QString &userName) const;
|
||||
private:
|
||||
bool threaded;
|
||||
QMultiMap<QString, PlayerReference> persistentPlayers;
|
||||
mutable QReadWriteLock persistentPlayersLock;
|
||||
int nextLocalGameId;
|
||||
QMutex nextLocalGameIdMutex;
|
||||
protected slots:
|
||||
void externalUserJoined(const ServerInfo_User &userInfo);
|
||||
void externalUserLeft(const QString &userName);
|
||||
void externalRoomUserJoined(int roomId, const ServerInfo_User &userInfo);
|
||||
void externalRoomUserLeft(int roomId, const QString &userName);
|
||||
void externalRoomSay(int roomId, const QString &userName, const QString &message);
|
||||
void externalRoomGameListChanged(int roomId, const ServerInfo_Game &gameInfo);
|
||||
void externalJoinGameCommandReceived(const Command_JoinGame &cmd, int cmdId, int roomId, int serverId, qint64 sessionId);
|
||||
void externalGameCommandContainerReceived(const CommandContainer &cont, int playerId, int serverId, qint64 sessionId);
|
||||
void externalGameEventContainerReceived(const GameEventContainer &cont, qint64 sessionId);
|
||||
void externalResponseReceived(const Response &resp, qint64 sessionId);
|
||||
|
||||
virtual void doSendIslMessage(const IslMessage &msg, int serverId) { }
|
||||
bool threaded;
|
||||
QMultiMap<QString, PlayerReference> persistentPlayers;
|
||||
mutable QReadWriteLock persistentPlayersLock;
|
||||
int nextLocalGameId;
|
||||
QMutex nextLocalGameIdMutex;
|
||||
protected slots:
|
||||
void externalUserJoined(const ServerInfo_User &userInfo);
|
||||
void externalUserLeft(const QString &userName);
|
||||
void externalRoomUserJoined(int roomId, const ServerInfo_User &userInfo);
|
||||
void externalRoomUserLeft(int roomId, const QString &userName);
|
||||
void externalRoomSay(int roomId, const QString &userName, const QString &message);
|
||||
void externalRoomGameListChanged(int roomId, const ServerInfo_Game &gameInfo);
|
||||
void externalJoinGameCommandReceived(const Command_JoinGame &cmd, int cmdId, int roomId, int serverId, qint64 sessionId);
|
||||
void externalGameCommandContainerReceived(const CommandContainer &cont, int playerId, int serverId, qint64 sessionId);
|
||||
void externalGameEventContainerReceived(const GameEventContainer &cont, qint64 sessionId);
|
||||
void externalResponseReceived(const Response &resp, qint64 sessionId);
|
||||
|
||||
virtual void doSendIslMessage(const IslMessage &msg, int serverId) { }
|
||||
protected:
|
||||
void prepareDestroy();
|
||||
void setDatabaseInterface(Server_DatabaseInterface *_databaseInterface);
|
||||
QList<Server_ProtocolHandler *> clients;
|
||||
QMap<qint64, Server_ProtocolHandler *> usersBySessionId;
|
||||
QMap<QString, Server_ProtocolHandler *> users;
|
||||
QMap<qint64, Server_AbstractUserInterface *> externalUsersBySessionId;
|
||||
QMap<QString, Server_AbstractUserInterface *> externalUsers;
|
||||
QMap<int, Server_Room *> rooms;
|
||||
QMap<QThread *, Server_DatabaseInterface *> databaseInterfaces;
|
||||
|
||||
int getUsersCount() const;
|
||||
int getGamesCount() const;
|
||||
void addRoom(Server_Room *newRoom);
|
||||
void prepareDestroy();
|
||||
void setDatabaseInterface(Server_DatabaseInterface *_databaseInterface);
|
||||
QList<Server_ProtocolHandler *> clients;
|
||||
QMap<qint64, Server_ProtocolHandler *> usersBySessionId;
|
||||
QMap<QString, Server_ProtocolHandler *> users;
|
||||
QMap<qint64, Server_AbstractUserInterface *> externalUsersBySessionId;
|
||||
QMap<QString, Server_AbstractUserInterface *> externalUsers;
|
||||
QMap<int, Server_Room *> rooms;
|
||||
QMap<QThread *, Server_DatabaseInterface *> databaseInterfaces;
|
||||
|
||||
int getUsersCount() const;
|
||||
int getGamesCount() const;
|
||||
void addRoom(Server_Room *newRoom);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,82 +15,82 @@
|
|||
|
||||
void Server_AbstractUserInterface::sendProtocolItemByType(ServerMessage::MessageType type, const ::google::protobuf::Message &item)
|
||||
{
|
||||
switch (type) {
|
||||
case ServerMessage::RESPONSE: sendProtocolItem(static_cast<const Response &>(item)); break;
|
||||
case ServerMessage::SESSION_EVENT: sendProtocolItem(static_cast<const SessionEvent &>(item)); break;
|
||||
case ServerMessage::GAME_EVENT_CONTAINER: sendProtocolItem(static_cast<const GameEventContainer &>(item)); break;
|
||||
case ServerMessage::ROOM_EVENT: sendProtocolItem(static_cast<const RoomEvent &>(item)); break;
|
||||
}
|
||||
switch (type) {
|
||||
case ServerMessage::RESPONSE: sendProtocolItem(static_cast<const Response &>(item)); break;
|
||||
case ServerMessage::SESSION_EVENT: sendProtocolItem(static_cast<const SessionEvent &>(item)); break;
|
||||
case ServerMessage::GAME_EVENT_CONTAINER: sendProtocolItem(static_cast<const GameEventContainer &>(item)); break;
|
||||
case ServerMessage::ROOM_EVENT: sendProtocolItem(static_cast<const RoomEvent &>(item)); break;
|
||||
}
|
||||
}
|
||||
|
||||
SessionEvent *Server_AbstractUserInterface::prepareSessionEvent(const ::google::protobuf::Message &sessionEvent)
|
||||
{
|
||||
SessionEvent *event = new SessionEvent;
|
||||
event->GetReflection()->MutableMessage(event, sessionEvent.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(sessionEvent);
|
||||
return event;
|
||||
SessionEvent *event = new SessionEvent;
|
||||
event->GetReflection()->MutableMessage(event, sessionEvent.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(sessionEvent);
|
||||
return event;
|
||||
}
|
||||
|
||||
void Server_AbstractUserInterface::sendResponseContainer(const ResponseContainer &responseContainer, Response::ResponseCode responseCode)
|
||||
{
|
||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &preResponseQueue = responseContainer.getPreResponseQueue();
|
||||
for (int i = 0; i < preResponseQueue.size(); ++i)
|
||||
sendProtocolItemByType(preResponseQueue[i].first, *preResponseQueue[i].second);
|
||||
|
||||
if (responseCode != Response::RespNothing) {
|
||||
Response response;
|
||||
response.set_cmd_id(responseContainer.getCmdId());
|
||||
response.set_response_code(responseCode);
|
||||
::google::protobuf::Message *responseExtension = responseContainer.getResponseExtension();
|
||||
if (responseExtension)
|
||||
response.GetReflection()->MutableMessage(&response, responseExtension->GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(*responseExtension);
|
||||
sendProtocolItem(response);
|
||||
}
|
||||
|
||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &postResponseQueue = responseContainer.getPostResponseQueue();
|
||||
for (int i = 0; i < postResponseQueue.size(); ++i)
|
||||
sendProtocolItemByType(postResponseQueue[i].first, *postResponseQueue[i].second);
|
||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &preResponseQueue = responseContainer.getPreResponseQueue();
|
||||
for (int i = 0; i < preResponseQueue.size(); ++i)
|
||||
sendProtocolItemByType(preResponseQueue[i].first, *preResponseQueue[i].second);
|
||||
|
||||
if (responseCode != Response::RespNothing) {
|
||||
Response response;
|
||||
response.set_cmd_id(responseContainer.getCmdId());
|
||||
response.set_response_code(responseCode);
|
||||
::google::protobuf::Message *responseExtension = responseContainer.getResponseExtension();
|
||||
if (responseExtension)
|
||||
response.GetReflection()->MutableMessage(&response, responseExtension->GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(*responseExtension);
|
||||
sendProtocolItem(response);
|
||||
}
|
||||
|
||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &postResponseQueue = responseContainer.getPostResponseQueue();
|
||||
for (int i = 0; i < postResponseQueue.size(); ++i)
|
||||
sendProtocolItemByType(postResponseQueue[i].first, *postResponseQueue[i].second);
|
||||
}
|
||||
|
||||
void Server_AbstractUserInterface::playerRemovedFromGame(Server_Game *game)
|
||||
{
|
||||
qDebug() << "Server_AbstractUserInterface::playerRemovedFromGame(): gameId =" << game->getGameId();
|
||||
|
||||
QMutexLocker locker(&gameListMutex);
|
||||
games.remove(game->getGameId());
|
||||
qDebug() << "Server_AbstractUserInterface::playerRemovedFromGame(): gameId =" << game->getGameId();
|
||||
|
||||
QMutexLocker locker(&gameListMutex);
|
||||
games.remove(game->getGameId());
|
||||
}
|
||||
|
||||
void Server_AbstractUserInterface::playerAddedToGame(int gameId, int roomId, int playerId)
|
||||
{
|
||||
qDebug() << "Server_AbstractUserInterface::playerAddedToGame(): gameId =" << gameId;
|
||||
|
||||
QMutexLocker locker(&gameListMutex);
|
||||
games.insert(gameId, QPair<int, int>(roomId, playerId));
|
||||
qDebug() << "Server_AbstractUserInterface::playerAddedToGame(): gameId =" << gameId;
|
||||
|
||||
QMutexLocker locker(&gameListMutex);
|
||||
games.insert(gameId, QPair<int, int>(roomId, playerId));
|
||||
}
|
||||
|
||||
void Server_AbstractUserInterface::joinPersistentGames(ResponseContainer &rc)
|
||||
{
|
||||
QList<PlayerReference> gamesToJoin = server->getPersistentPlayerReferences(QString::fromStdString(userInfo->name()));
|
||||
|
||||
server->roomsLock.lockForRead();
|
||||
for (int i = 0; i < gamesToJoin.size(); ++i) {
|
||||
const PlayerReference &pr = gamesToJoin.at(i);
|
||||
|
||||
Server_Room *room = server->getRooms().value(pr.getRoomId());
|
||||
if (!room)
|
||||
continue;
|
||||
QReadLocker roomGamesLocker(&room->gamesLock);
|
||||
|
||||
Server_Game *game = room->getGames().value(pr.getGameId());
|
||||
if (!game)
|
||||
continue;
|
||||
QMutexLocker gameLocker(&game->gameMutex);
|
||||
|
||||
Server_Player *player = game->getPlayers().value(pr.getPlayerId());
|
||||
|
||||
player->setUserInterface(this);
|
||||
playerAddedToGame(game->getGameId(), room->getId(), player->getPlayerId());
|
||||
|
||||
game->createGameJoinedEvent(player, rc, true);
|
||||
}
|
||||
server->roomsLock.unlock();
|
||||
QList<PlayerReference> gamesToJoin = server->getPersistentPlayerReferences(QString::fromStdString(userInfo->name()));
|
||||
|
||||
server->roomsLock.lockForRead();
|
||||
for (int i = 0; i < gamesToJoin.size(); ++i) {
|
||||
const PlayerReference &pr = gamesToJoin.at(i);
|
||||
|
||||
Server_Room *room = server->getRooms().value(pr.getRoomId());
|
||||
if (!room)
|
||||
continue;
|
||||
QReadLocker roomGamesLocker(&room->gamesLock);
|
||||
|
||||
Server_Game *game = room->getGames().value(pr.getGameId());
|
||||
if (!game)
|
||||
continue;
|
||||
QMutexLocker gameLocker(&game->gameMutex);
|
||||
|
||||
Server_Player *player = game->getPlayers().value(pr.getPlayerId());
|
||||
|
||||
player->setUserInterface(this);
|
||||
playerAddedToGame(game->getGameId(), room->getId(), player->getPlayerId());
|
||||
|
||||
game->createGameJoinedEvent(player, rc, true);
|
||||
}
|
||||
server->roomsLock.unlock();
|
||||
}
|
||||
|
|
|
@ -18,31 +18,31 @@ class Server_Game;
|
|||
|
||||
class Server_AbstractUserInterface : public ServerInfo_User_Container {
|
||||
private:
|
||||
mutable QMutex gameListMutex;
|
||||
QMap<int, QPair<int, int> > games; // gameId -> (roomId, playerId)
|
||||
mutable QMutex gameListMutex;
|
||||
QMap<int, QPair<int, int> > games; // gameId -> (roomId, playerId)
|
||||
protected:
|
||||
Server *server;
|
||||
Server *server;
|
||||
public:
|
||||
Server_AbstractUserInterface(Server *_server) : server(_server) { }
|
||||
Server_AbstractUserInterface(Server *_server, const ServerInfo_User_Container &other) : ServerInfo_User_Container(other), server(_server) { }
|
||||
virtual ~Server_AbstractUserInterface() { }
|
||||
|
||||
virtual int getLastCommandTime() const = 0;
|
||||
|
||||
void playerRemovedFromGame(Server_Game *game);
|
||||
void playerAddedToGame(int gameId, int roomId, int playerId);
|
||||
void joinPersistentGames(ResponseContainer &rc);
|
||||
|
||||
QMap<int, QPair<int, int> > getGames() const { QMutexLocker locker(&gameListMutex); return games; }
|
||||
|
||||
virtual void sendProtocolItem(const Response &item) = 0;
|
||||
virtual void sendProtocolItem(const SessionEvent &item) = 0;
|
||||
virtual void sendProtocolItem(const GameEventContainer &item) = 0;
|
||||
virtual void sendProtocolItem(const RoomEvent &item) = 0;
|
||||
void sendProtocolItemByType(ServerMessage::MessageType type, const ::google::protobuf::Message &item);
|
||||
|
||||
static SessionEvent *prepareSessionEvent(const ::google::protobuf::Message &sessionEvent);
|
||||
void sendResponseContainer(const ResponseContainer &responseContainer, Response::ResponseCode responseCode);
|
||||
Server_AbstractUserInterface(Server *_server) : server(_server) { }
|
||||
Server_AbstractUserInterface(Server *_server, const ServerInfo_User_Container &other) : ServerInfo_User_Container(other), server(_server) { }
|
||||
virtual ~Server_AbstractUserInterface() { }
|
||||
|
||||
virtual int getLastCommandTime() const = 0;
|
||||
|
||||
void playerRemovedFromGame(Server_Game *game);
|
||||
void playerAddedToGame(int gameId, int roomId, int playerId);
|
||||
void joinPersistentGames(ResponseContainer &rc);
|
||||
|
||||
QMap<int, QPair<int, int> > getGames() const { QMutexLocker locker(&gameListMutex); return games; }
|
||||
|
||||
virtual void sendProtocolItem(const Response &item) = 0;
|
||||
virtual void sendProtocolItem(const SessionEvent &item) = 0;
|
||||
virtual void sendProtocolItem(const GameEventContainer &item) = 0;
|
||||
virtual void sendProtocolItem(const RoomEvent &item) = 0;
|
||||
void sendProtocolItemByType(ServerMessage::MessageType type, const ::google::protobuf::Message &item);
|
||||
|
||||
static SessionEvent *prepareSessionEvent(const ::google::protobuf::Message &sessionEvent);
|
||||
void sendResponseContainer(const ResponseContainer &responseContainer, Response::ResponseCode responseCode);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,17 +14,17 @@ Server_Arrow::Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget
|
|||
|
||||
void Server_Arrow::getInfo(ServerInfo_Arrow *info)
|
||||
{
|
||||
info->set_id(id);
|
||||
info->set_start_player_id(startCard->getZone()->getPlayer()->getPlayerId());
|
||||
info->set_start_zone(startCard->getZone()->getName().toStdString());
|
||||
info->set_start_card_id(startCard->getId());
|
||||
info->mutable_arrow_color()->CopyFrom(arrowColor);
|
||||
info->set_id(id);
|
||||
info->set_start_player_id(startCard->getZone()->getPlayer()->getPlayerId());
|
||||
info->set_start_zone(startCard->getZone()->getName().toStdString());
|
||||
info->set_start_card_id(startCard->getId());
|
||||
info->mutable_arrow_color()->CopyFrom(arrowColor);
|
||||
|
||||
Server_Card *targetCard = qobject_cast<Server_Card *>(targetItem);
|
||||
if (targetCard) {
|
||||
info->set_target_player_id(targetCard->getZone()->getPlayer()->getPlayerId());
|
||||
info->set_target_zone(targetCard->getZone()->getName().toStdString());
|
||||
info->set_target_card_id(targetCard->getId());
|
||||
} else
|
||||
info->set_target_player_id(static_cast<Server_Player *>(targetItem)->getPlayerId());
|
||||
Server_Card *targetCard = qobject_cast<Server_Card *>(targetItem);
|
||||
if (targetCard) {
|
||||
info->set_target_player_id(targetCard->getZone()->getPlayer()->getPlayerId());
|
||||
info->set_target_zone(targetCard->getZone()->getName().toStdString());
|
||||
info->set_target_card_id(targetCard->getId());
|
||||
} else
|
||||
info->set_target_player_id(static_cast<Server_Player *>(targetItem)->getPlayerId());
|
||||
}
|
||||
|
|
|
@ -9,18 +9,18 @@ class ServerInfo_Arrow;
|
|||
|
||||
class Server_Arrow {
|
||||
private:
|
||||
int id;
|
||||
Server_Card *startCard;
|
||||
Server_ArrowTarget *targetItem;
|
||||
color arrowColor;
|
||||
int id;
|
||||
Server_Card *startCard;
|
||||
Server_ArrowTarget *targetItem;
|
||||
color arrowColor;
|
||||
public:
|
||||
Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor);
|
||||
int getId() const { return id; }
|
||||
Server_Card *getStartCard() const { return startCard; }
|
||||
Server_ArrowTarget *getTargetItem() const { return targetItem; }
|
||||
const color &getColor() const { return arrowColor; }
|
||||
|
||||
void getInfo(ServerInfo_Arrow *info);
|
||||
Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor);
|
||||
int getId() const { return id; }
|
||||
Server_Card *getStartCard() const { return startCard; }
|
||||
Server_ArrowTarget *getTargetItem() const { return targetItem; }
|
||||
const color &getColor() const { return arrowColor; }
|
||||
|
||||
void getInfo(ServerInfo_Arrow *info);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
|
||||
#include "server_arrowtarget.h"
|
||||
#include "server_arrowtarget.h"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QObject>
|
||||
|
||||
class Server_ArrowTarget : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,138 +23,138 @@
|
|||
#include "pb/serverinfo_card.pb.h"
|
||||
|
||||
Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone)
|
||||
: zone(_zone), id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), facedown(false), color(QString()), power(-1), toughness(-1), annotation(QString()), destroyOnZoneChange(false), doesntUntap(false), parentCard(0)
|
||||
: zone(_zone), id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), facedown(false), color(QString()), power(-1), toughness(-1), annotation(QString()), destroyOnZoneChange(false), doesntUntap(false), parentCard(0)
|
||||
{
|
||||
}
|
||||
|
||||
Server_Card::~Server_Card()
|
||||
{
|
||||
// setParentCard(0) leads to the item being removed from our list, so we can't iterate properly
|
||||
while (!attachedCards.isEmpty())
|
||||
attachedCards.first()->setParentCard(0);
|
||||
|
||||
if (parentCard)
|
||||
parentCard->removeAttachedCard(this);
|
||||
// setParentCard(0) leads to the item being removed from our list, so we can't iterate properly
|
||||
while (!attachedCards.isEmpty())
|
||||
attachedCards.first()->setParentCard(0);
|
||||
|
||||
if (parentCard)
|
||||
parentCard->removeAttachedCard(this);
|
||||
}
|
||||
|
||||
void Server_Card::resetState()
|
||||
{
|
||||
counters.clear();
|
||||
setTapped(false);
|
||||
setAttacking(false);
|
||||
power = -1;
|
||||
toughness = -1;
|
||||
setAnnotation(QString());
|
||||
setDoesntUntap(false);
|
||||
counters.clear();
|
||||
setTapped(false);
|
||||
setAttacking(false);
|
||||
power = -1;
|
||||
toughness = -1;
|
||||
setAnnotation(QString());
|
||||
setDoesntUntap(false);
|
||||
}
|
||||
|
||||
QString Server_Card::setAttribute(CardAttribute attribute, const QString &avalue, bool allCards)
|
||||
{
|
||||
switch (attribute) {
|
||||
case AttrTapped: {
|
||||
bool value = avalue == "1";
|
||||
if (!(!value && allCards && doesntUntap))
|
||||
setTapped(value);
|
||||
break;
|
||||
}
|
||||
case AttrAttacking: setAttacking(avalue == "1"); break;
|
||||
case AttrFaceDown: setFaceDown(avalue == "1"); break;
|
||||
case AttrColor: setColor(avalue); break;
|
||||
case AttrPT: setPT(avalue); return getPT();
|
||||
case AttrAnnotation: setAnnotation(avalue); break;
|
||||
case AttrDoesntUntap: setDoesntUntap(avalue == "1"); break;
|
||||
}
|
||||
return avalue;
|
||||
switch (attribute) {
|
||||
case AttrTapped: {
|
||||
bool value = avalue == "1";
|
||||
if (!(!value && allCards && doesntUntap))
|
||||
setTapped(value);
|
||||
break;
|
||||
}
|
||||
case AttrAttacking: setAttacking(avalue == "1"); break;
|
||||
case AttrFaceDown: setFaceDown(avalue == "1"); break;
|
||||
case AttrColor: setColor(avalue); break;
|
||||
case AttrPT: setPT(avalue); return getPT();
|
||||
case AttrAnnotation: setAnnotation(avalue); break;
|
||||
case AttrDoesntUntap: setDoesntUntap(avalue == "1"); break;
|
||||
}
|
||||
return avalue;
|
||||
}
|
||||
|
||||
void Server_Card::setCounter(int id, int value)
|
||||
{
|
||||
if (value)
|
||||
counters.insert(id, value);
|
||||
else
|
||||
counters.remove(id);
|
||||
if (value)
|
||||
counters.insert(id, value);
|
||||
else
|
||||
counters.remove(id);
|
||||
}
|
||||
|
||||
void Server_Card::setPT(const QString &_pt)
|
||||
{
|
||||
if (_pt.isEmpty()) {
|
||||
power = 0;
|
||||
toughness = -1;
|
||||
} else {
|
||||
int sep = _pt.indexOf('/');
|
||||
QString p1 = _pt.left(sep);
|
||||
QString p2 = _pt.mid(sep + 1);
|
||||
if (p1.isEmpty() || p2.isEmpty())
|
||||
return;
|
||||
if ((p1[0] == '+') || (p2[0] == '+')) {
|
||||
if (power < 0)
|
||||
power = 0;
|
||||
if (toughness < 0)
|
||||
toughness = 0;
|
||||
}
|
||||
if (p1[0] == '+')
|
||||
power += p1.mid(1).toInt();
|
||||
else
|
||||
power = p1.toInt();
|
||||
if (p2[0] == '+')
|
||||
toughness += p2.mid(1).toInt();
|
||||
else
|
||||
toughness = p2.toInt();
|
||||
}
|
||||
if (_pt.isEmpty()) {
|
||||
power = 0;
|
||||
toughness = -1;
|
||||
} else {
|
||||
int sep = _pt.indexOf('/');
|
||||
QString p1 = _pt.left(sep);
|
||||
QString p2 = _pt.mid(sep + 1);
|
||||
if (p1.isEmpty() || p2.isEmpty())
|
||||
return;
|
||||
if ((p1[0] == '+') || (p2[0] == '+')) {
|
||||
if (power < 0)
|
||||
power = 0;
|
||||
if (toughness < 0)
|
||||
toughness = 0;
|
||||
}
|
||||
if (p1[0] == '+')
|
||||
power += p1.mid(1).toInt();
|
||||
else
|
||||
power = p1.toInt();
|
||||
if (p2[0] == '+')
|
||||
toughness += p2.mid(1).toInt();
|
||||
else
|
||||
toughness = p2.toInt();
|
||||
}
|
||||
}
|
||||
|
||||
QString Server_Card::getPT() const
|
||||
{
|
||||
if (toughness < 0)
|
||||
return QString("");
|
||||
return QString::number(power) + "/" + QString::number(toughness);
|
||||
if (toughness < 0)
|
||||
return QString("");
|
||||
return QString::number(power) + "/" + QString::number(toughness);
|
||||
}
|
||||
|
||||
void Server_Card::setParentCard(Server_Card *_parentCard)
|
||||
{
|
||||
if (parentCard)
|
||||
parentCard->removeAttachedCard(this);
|
||||
parentCard = _parentCard;
|
||||
if (parentCard)
|
||||
parentCard->addAttachedCard(this);
|
||||
if (parentCard)
|
||||
parentCard->removeAttachedCard(this);
|
||||
parentCard = _parentCard;
|
||||
if (parentCard)
|
||||
parentCard->addAttachedCard(this);
|
||||
}
|
||||
|
||||
void Server_Card::getInfo(ServerInfo_Card *info)
|
||||
{
|
||||
QString displayedName = facedown ? QString() : name;
|
||||
|
||||
info->set_id(id);
|
||||
info->set_name(displayedName.toStdString());
|
||||
info->set_x(coord_x);
|
||||
info->set_y(coord_y);
|
||||
if (facedown)
|
||||
info->set_face_down(true);
|
||||
info->set_tapped(tapped);
|
||||
if (attacking)
|
||||
info->set_attacking(true);
|
||||
if (!color.isEmpty())
|
||||
info->set_color(color.toStdString());
|
||||
const QString ptStr = getPT();
|
||||
if (!ptStr.isEmpty())
|
||||
info->set_pt(ptStr.toStdString());
|
||||
if (!annotation.isEmpty())
|
||||
info->set_annotation(annotation.toStdString());
|
||||
if (destroyOnZoneChange)
|
||||
info->set_destroy_on_zone_change(true);
|
||||
if (doesntUntap)
|
||||
info->set_doesnt_untap(true);
|
||||
|
||||
QMapIterator<int, int> cardCounterIterator(counters);
|
||||
while (cardCounterIterator.hasNext()) {
|
||||
cardCounterIterator.next();
|
||||
ServerInfo_CardCounter *counterInfo = info->add_counter_list();
|
||||
counterInfo->set_id(cardCounterIterator.key());
|
||||
counterInfo->set_value(cardCounterIterator.value());
|
||||
}
|
||||
QString displayedName = facedown ? QString() : name;
|
||||
|
||||
info->set_id(id);
|
||||
info->set_name(displayedName.toStdString());
|
||||
info->set_x(coord_x);
|
||||
info->set_y(coord_y);
|
||||
if (facedown)
|
||||
info->set_face_down(true);
|
||||
info->set_tapped(tapped);
|
||||
if (attacking)
|
||||
info->set_attacking(true);
|
||||
if (!color.isEmpty())
|
||||
info->set_color(color.toStdString());
|
||||
const QString ptStr = getPT();
|
||||
if (!ptStr.isEmpty())
|
||||
info->set_pt(ptStr.toStdString());
|
||||
if (!annotation.isEmpty())
|
||||
info->set_annotation(annotation.toStdString());
|
||||
if (destroyOnZoneChange)
|
||||
info->set_destroy_on_zone_change(true);
|
||||
if (doesntUntap)
|
||||
info->set_doesnt_untap(true);
|
||||
|
||||
QMapIterator<int, int> cardCounterIterator(counters);
|
||||
while (cardCounterIterator.hasNext()) {
|
||||
cardCounterIterator.next();
|
||||
ServerInfo_CardCounter *counterInfo = info->add_counter_list();
|
||||
counterInfo->set_id(cardCounterIterator.key());
|
||||
counterInfo->set_value(cardCounterIterator.value());
|
||||
}
|
||||
|
||||
if (parentCard) {
|
||||
info->set_attach_player_id(parentCard->getZone()->getPlayer()->getPlayerId());
|
||||
info->set_attach_zone(parentCard->getZone()->getName().toStdString());
|
||||
info->set_attach_card_id(parentCard->getId());
|
||||
}
|
||||
if (parentCard) {
|
||||
info->set_attach_player_id(parentCard->getZone()->getPlayer()->getPlayerId());
|
||||
info->set_attach_zone(parentCard->getZone()->getName().toStdString());
|
||||
info->set_attach_card_id(parentCard->getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,68 +29,68 @@ class Server_CardZone;
|
|||
class ServerInfo_Card;
|
||||
|
||||
class Server_Card : public Server_ArrowTarget {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
Server_CardZone *zone;
|
||||
int id;
|
||||
int coord_x, coord_y;
|
||||
QString name;
|
||||
QMap<int, int> counters;
|
||||
bool tapped;
|
||||
bool attacking;
|
||||
bool facedown;
|
||||
QString color;
|
||||
int power, toughness;
|
||||
QString annotation;
|
||||
bool destroyOnZoneChange;
|
||||
bool doesntUntap;
|
||||
|
||||
Server_Card *parentCard;
|
||||
QList<Server_Card *> attachedCards;
|
||||
Server_CardZone *zone;
|
||||
int id;
|
||||
int coord_x, coord_y;
|
||||
QString name;
|
||||
QMap<int, int> counters;
|
||||
bool tapped;
|
||||
bool attacking;
|
||||
bool facedown;
|
||||
QString color;
|
||||
int power, toughness;
|
||||
QString annotation;
|
||||
bool destroyOnZoneChange;
|
||||
bool doesntUntap;
|
||||
|
||||
Server_Card *parentCard;
|
||||
QList<Server_Card *> attachedCards;
|
||||
public:
|
||||
Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone = 0);
|
||||
~Server_Card();
|
||||
|
||||
Server_CardZone *getZone() const { return zone; }
|
||||
void setZone(Server_CardZone *_zone) { zone = _zone; }
|
||||
|
||||
int getId() const { return id; }
|
||||
int getX() const { return coord_x; }
|
||||
int getY() const { return coord_y; }
|
||||
QString getName() const { return name; }
|
||||
const QMap<int, int> &getCounters() const { return counters; }
|
||||
int getCounter(int id) const { return counters.value(id, 0); }
|
||||
bool getTapped() const { return tapped; }
|
||||
bool getAttacking() const { return attacking; }
|
||||
bool getFaceDown() const { return facedown; }
|
||||
QString getColor() const { return color; }
|
||||
QString getPT() const;
|
||||
QString getAnnotation() const { return annotation; }
|
||||
bool getDoesntUntap() const { return doesntUntap; }
|
||||
bool getDestroyOnZoneChange() const { return destroyOnZoneChange; }
|
||||
Server_Card *getParentCard() const { return parentCard; }
|
||||
const QList<Server_Card *> &getAttachedCards() const { return attachedCards; }
|
||||
Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone = 0);
|
||||
~Server_Card();
|
||||
|
||||
Server_CardZone *getZone() const { return zone; }
|
||||
void setZone(Server_CardZone *_zone) { zone = _zone; }
|
||||
|
||||
int getId() const { return id; }
|
||||
int getX() const { return coord_x; }
|
||||
int getY() const { return coord_y; }
|
||||
QString getName() const { return name; }
|
||||
const QMap<int, int> &getCounters() const { return counters; }
|
||||
int getCounter(int id) const { return counters.value(id, 0); }
|
||||
bool getTapped() const { return tapped; }
|
||||
bool getAttacking() const { return attacking; }
|
||||
bool getFaceDown() const { return facedown; }
|
||||
QString getColor() const { return color; }
|
||||
QString getPT() const;
|
||||
QString getAnnotation() const { return annotation; }
|
||||
bool getDoesntUntap() const { return doesntUntap; }
|
||||
bool getDestroyOnZoneChange() const { return destroyOnZoneChange; }
|
||||
Server_Card *getParentCard() const { return parentCard; }
|
||||
const QList<Server_Card *> &getAttachedCards() const { return attachedCards; }
|
||||
|
||||
void setId(int _id) { id = _id; }
|
||||
void setCoords(int x, int y) { coord_x = x; coord_y = y; }
|
||||
void setName(const QString &_name) { name = _name; }
|
||||
void setCounter(int id, int value);
|
||||
void setTapped(bool _tapped) { tapped = _tapped; }
|
||||
void setAttacking(bool _attacking) { attacking = _attacking; }
|
||||
void setFaceDown(bool _facedown) { facedown = _facedown; }
|
||||
void setColor(const QString &_color) { color = _color; }
|
||||
void setPT(const QString &_pt);
|
||||
void setAnnotation(const QString &_annotation) { annotation = _annotation; }
|
||||
void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; }
|
||||
void setDoesntUntap(bool _doesntUntap) { doesntUntap = _doesntUntap; }
|
||||
void setParentCard(Server_Card *_parentCard);
|
||||
void addAttachedCard(Server_Card *card) { attachedCards.append(card); }
|
||||
void removeAttachedCard(Server_Card *card) { attachedCards.removeAt(attachedCards.indexOf(card)); }
|
||||
|
||||
void resetState();
|
||||
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
|
||||
|
||||
void getInfo(ServerInfo_Card *info);
|
||||
void setId(int _id) { id = _id; }
|
||||
void setCoords(int x, int y) { coord_x = x; coord_y = y; }
|
||||
void setName(const QString &_name) { name = _name; }
|
||||
void setCounter(int id, int value);
|
||||
void setTapped(bool _tapped) { tapped = _tapped; }
|
||||
void setAttacking(bool _attacking) { attacking = _attacking; }
|
||||
void setFaceDown(bool _facedown) { facedown = _facedown; }
|
||||
void setColor(const QString &_color) { color = _color; }
|
||||
void setPT(const QString &_pt);
|
||||
void setAnnotation(const QString &_annotation) { annotation = _annotation; }
|
||||
void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; }
|
||||
void setDoesntUntap(bool _doesntUntap) { doesntUntap = _doesntUntap; }
|
||||
void setParentCard(Server_Card *_parentCard);
|
||||
void addAttachedCard(Server_Card *card) { attachedCards.append(card); }
|
||||
void removeAttachedCard(Server_Card *card) { attachedCards.removeAt(attachedCards.indexOf(card)); }
|
||||
|
||||
void resetState();
|
||||
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
|
||||
|
||||
void getInfo(ServerInfo_Card *info);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -33,48 +33,48 @@ class GameEventStorage;
|
|||
|
||||
class Server_CardZone {
|
||||
private:
|
||||
Server_Player *player;
|
||||
QString name;
|
||||
bool has_coords;
|
||||
ServerInfo_Zone::ZoneType type;
|
||||
int cardsBeingLookedAt;
|
||||
QSet<int> playersWithWritePermission;
|
||||
bool alwaysRevealTopCard;
|
||||
QList<Server_Card *> cards;
|
||||
QMap<int, QMap<int, Server_Card *> > coordinateMap; // y -> (x -> card)
|
||||
QMap<int, QMultiMap<QString, int> > freePilesMap; // y -> (cardName -> x)
|
||||
QMap<int, int> freeSpaceMap; // y -> x
|
||||
void removeCardFromCoordMap(Server_Card *card, int oldX, int oldY);
|
||||
void insertCardIntoCoordMap(Server_Card *card, int x, int y);
|
||||
Server_Player *player;
|
||||
QString name;
|
||||
bool has_coords;
|
||||
ServerInfo_Zone::ZoneType type;
|
||||
int cardsBeingLookedAt;
|
||||
QSet<int> playersWithWritePermission;
|
||||
bool alwaysRevealTopCard;
|
||||
QList<Server_Card *> cards;
|
||||
QMap<int, QMap<int, Server_Card *> > coordinateMap; // y -> (x -> card)
|
||||
QMap<int, QMultiMap<QString, int> > freePilesMap; // y -> (cardName -> x)
|
||||
QMap<int, int> freeSpaceMap; // y -> x
|
||||
void removeCardFromCoordMap(Server_Card *card, int oldX, int oldY);
|
||||
void insertCardIntoCoordMap(Server_Card *card, int x, int y);
|
||||
public:
|
||||
Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ServerInfo_Zone::ZoneType _type);
|
||||
~Server_CardZone();
|
||||
|
||||
const QList<Server_Card *> &getCards() const { return cards; }
|
||||
int removeCard(Server_Card *card);
|
||||
Server_Card *getCard(int id, int *position = NULL, bool remove = false);
|
||||
Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ServerInfo_Zone::ZoneType _type);
|
||||
~Server_CardZone();
|
||||
|
||||
const QList<Server_Card *> &getCards() const { return cards; }
|
||||
int removeCard(Server_Card *card);
|
||||
Server_Card *getCard(int id, int *position = NULL, bool remove = false);
|
||||
|
||||
int getCardsBeingLookedAt() const { return cardsBeingLookedAt; }
|
||||
void setCardsBeingLookedAt(int _cardsBeingLookedAt) { cardsBeingLookedAt = _cardsBeingLookedAt; }
|
||||
bool hasCoords() const { return has_coords; }
|
||||
ServerInfo_Zone::ZoneType getType() const { return type; }
|
||||
QString getName() const { return name; }
|
||||
Server_Player *getPlayer() const { return player; }
|
||||
void getInfo(ServerInfo_Zone *info, Server_Player *playerWhosAsking, bool omniscient);
|
||||
|
||||
int getFreeGridColumn(int x, int y, const QString &cardName) const;
|
||||
bool isColumnEmpty(int x, int y) const;
|
||||
bool isColumnStacked(int x, int y) const;
|
||||
void fixFreeSpaces(GameEventStorage &ges);
|
||||
void moveCardInRow(GameEventStorage &ges, Server_Card *card, int x, int y);
|
||||
void insertCard(Server_Card *card, int x, int y);
|
||||
void updateCardCoordinates(Server_Card *card, int oldX, int oldY);
|
||||
void shuffle();
|
||||
void clear();
|
||||
void addWritePermission(int playerId);
|
||||
const QSet<int> &getPlayersWithWritePermission() const { return playersWithWritePermission; }
|
||||
bool getAlwaysRevealTopCard() const { return alwaysRevealTopCard; }
|
||||
void setAlwaysRevealTopCard(bool _alwaysRevealTopCard) { alwaysRevealTopCard = _alwaysRevealTopCard; }
|
||||
int getCardsBeingLookedAt() const { return cardsBeingLookedAt; }
|
||||
void setCardsBeingLookedAt(int _cardsBeingLookedAt) { cardsBeingLookedAt = _cardsBeingLookedAt; }
|
||||
bool hasCoords() const { return has_coords; }
|
||||
ServerInfo_Zone::ZoneType getType() const { return type; }
|
||||
QString getName() const { return name; }
|
||||
Server_Player *getPlayer() const { return player; }
|
||||
void getInfo(ServerInfo_Zone *info, Server_Player *playerWhosAsking, bool omniscient);
|
||||
|
||||
int getFreeGridColumn(int x, int y, const QString &cardName) const;
|
||||
bool isColumnEmpty(int x, int y) const;
|
||||
bool isColumnStacked(int x, int y) const;
|
||||
void fixFreeSpaces(GameEventStorage &ges);
|
||||
void moveCardInRow(GameEventStorage &ges, Server_Card *card, int x, int y);
|
||||
void insertCard(Server_Card *card, int x, int y);
|
||||
void updateCardCoordinates(Server_Card *card, int oldX, int oldY);
|
||||
void shuffle();
|
||||
void clear();
|
||||
void addWritePermission(int playerId);
|
||||
const QSet<int> &getPlayersWithWritePermission() const { return playersWithWritePermission; }
|
||||
bool getAlwaysRevealTopCard() const { return alwaysRevealTopCard; }
|
||||
void setAlwaysRevealTopCard(bool _alwaysRevealTopCard) { alwaysRevealTopCard = _alwaysRevealTopCard; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -12,9 +12,9 @@ Server_Counter::Server_Counter(int _id, const QString &_name, const color &_coun
|
|||
|
||||
void Server_Counter::getInfo(ServerInfo_Counter *info)
|
||||
{
|
||||
info->set_id(id);
|
||||
info->set_name(name.toStdString());
|
||||
info->mutable_counter_color()->CopyFrom(counterColor);
|
||||
info->set_radius(radius);
|
||||
info->set_count(count);
|
||||
info->set_id(id);
|
||||
info->set_name(name.toStdString());
|
||||
info->mutable_counter_color()->CopyFrom(counterColor);
|
||||
info->set_radius(radius);
|
||||
info->set_count(count);
|
||||
}
|
||||
|
|
|
@ -27,22 +27,22 @@ class ServerInfo_Counter;
|
|||
|
||||
class Server_Counter {
|
||||
protected:
|
||||
int id;
|
||||
QString name;
|
||||
color counterColor;
|
||||
int radius;
|
||||
int count;
|
||||
int id;
|
||||
QString name;
|
||||
color counterColor;
|
||||
int radius;
|
||||
int count;
|
||||
public:
|
||||
Server_Counter(int _id, const QString &_name, const color &_counterColor, int _radius, int _count = 0);
|
||||
~Server_Counter() { }
|
||||
int getId() const { return id; }
|
||||
QString getName() const { return name; }
|
||||
const color &getColor() const { return counterColor; }
|
||||
int getRadius() const { return radius; }
|
||||
int getCount() const { return count; }
|
||||
void setCount(int _count) { count = _count; }
|
||||
|
||||
void getInfo(ServerInfo_Counter *info);
|
||||
Server_Counter(int _id, const QString &_name, const color &_counterColor, int _radius, int _count = 0);
|
||||
~Server_Counter() { }
|
||||
int getId() const { return id; }
|
||||
QString getName() const { return name; }
|
||||
const color &getColor() const { return counterColor; }
|
||||
int getRadius() const { return radius; }
|
||||
int getCount() const { return count; }
|
||||
void setCount(int _count) { count = _count; }
|
||||
|
||||
void getInfo(ServerInfo_Counter *info);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,32 +6,32 @@
|
|||
#include "server.h"
|
||||
|
||||
class Server_DatabaseInterface : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
Server_DatabaseInterface(QObject *parent = 0)
|
||||
: QObject(parent) { }
|
||||
|
||||
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft) = 0;
|
||||
virtual bool userExists(const QString &user) { return false; }
|
||||
virtual QMap<QString, ServerInfo_User> getBuddyList(const QString &name) { return QMap<QString, ServerInfo_User>(); }
|
||||
virtual QMap<QString, ServerInfo_User> getIgnoreList(const QString &name) { return QMap<QString, ServerInfo_User>(); }
|
||||
virtual bool isInBuddyList(const QString &whoseList, const QString &who) { return false; }
|
||||
virtual bool isInIgnoreList(const QString &whoseList, const QString &who) { return false; }
|
||||
virtual ServerInfo_User getUserData(const QString &name, bool withId = false) = 0;
|
||||
virtual void storeGameInformation(const QString &roomName, const QStringList &roomGameTypes, const ServerInfo_Game &gameInfo, const QSet<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const QList<GameReplay *> &replayList) { }
|
||||
virtual DeckList *getDeckFromDatabase(int deckId, int userId) { return 0; }
|
||||
|
||||
virtual qint64 startSession(const QString &userName, const QString &address) { return 0; }
|
||||
Server_DatabaseInterface(QObject *parent = 0)
|
||||
: QObject(parent) { }
|
||||
|
||||
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft) = 0;
|
||||
virtual bool userExists(const QString &user) { return false; }
|
||||
virtual QMap<QString, ServerInfo_User> getBuddyList(const QString &name) { return QMap<QString, ServerInfo_User>(); }
|
||||
virtual QMap<QString, ServerInfo_User> getIgnoreList(const QString &name) { return QMap<QString, ServerInfo_User>(); }
|
||||
virtual bool isInBuddyList(const QString &whoseList, const QString &who) { return false; }
|
||||
virtual bool isInIgnoreList(const QString &whoseList, const QString &who) { return false; }
|
||||
virtual ServerInfo_User getUserData(const QString &name, bool withId = false) = 0;
|
||||
virtual void storeGameInformation(const QString &roomName, const QStringList &roomGameTypes, const ServerInfo_Game &gameInfo, const QSet<QString> &allPlayersEver, const QSet<QString> &allSpectatorsEver, const QList<GameReplay *> &replayList) { }
|
||||
virtual DeckList *getDeckFromDatabase(int deckId, int userId) { return 0; }
|
||||
|
||||
virtual qint64 startSession(const QString &userName, const QString &address) { return 0; }
|
||||
public slots:
|
||||
virtual void endSession(qint64 sessionId) { }
|
||||
virtual void endSession(qint64 sessionId) { }
|
||||
public:
|
||||
virtual int getNextGameId() = 0;
|
||||
virtual int getNextReplayId() = 0;
|
||||
|
||||
virtual void clearSessionTables() { }
|
||||
virtual void lockSessionTables() { }
|
||||
virtual void unlockSessionTables() { }
|
||||
virtual bool userSessionExists(const QString &userName) { return false; }
|
||||
virtual int getNextGameId() = 0;
|
||||
virtual int getNextReplayId() = 0;
|
||||
|
||||
virtual void clearSessionTables() { }
|
||||
virtual void lockSessionTables() { }
|
||||
virtual void unlockSessionTables() { }
|
||||
virtual bool userSessionExists(const QString &userName) { return false; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -42,86 +42,86 @@ class Server_AbstractUserInterface;
|
|||
class Event_GameStateChanged;
|
||||
|
||||
class Server_Game : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
Server_Room *room;
|
||||
int nextPlayerId;
|
||||
int hostId;
|
||||
ServerInfo_User *creatorInfo;
|
||||
QMap<int, Server_Player *> players;
|
||||
QSet<QString> allPlayersEver, allSpectatorsEver;
|
||||
bool gameStarted;
|
||||
bool gameClosed;
|
||||
int gameId;
|
||||
QString description;
|
||||
QString password;
|
||||
int maxPlayers;
|
||||
QList<int> gameTypes;
|
||||
int activePlayer, activePhase;
|
||||
bool onlyBuddies, onlyRegistered;
|
||||
bool spectatorsAllowed;
|
||||
bool spectatorsNeedPassword;
|
||||
bool spectatorsCanTalk;
|
||||
bool spectatorsSeeEverything;
|
||||
int inactivityCounter;
|
||||
int startTimeOfThisGame, secondsElapsed;
|
||||
bool firstGameStarted;
|
||||
QDateTime startTime;
|
||||
QTimer *pingClock;
|
||||
QList<GameReplay *> replayList;
|
||||
GameReplay *currentReplay;
|
||||
|
||||
void createGameStateChangedEvent(Event_GameStateChanged *event, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo);
|
||||
void sendGameStateToPlayers();
|
||||
void storeGameInformation();
|
||||
Server_Room *room;
|
||||
int nextPlayerId;
|
||||
int hostId;
|
||||
ServerInfo_User *creatorInfo;
|
||||
QMap<int, Server_Player *> players;
|
||||
QSet<QString> allPlayersEver, allSpectatorsEver;
|
||||
bool gameStarted;
|
||||
bool gameClosed;
|
||||
int gameId;
|
||||
QString description;
|
||||
QString password;
|
||||
int maxPlayers;
|
||||
QList<int> gameTypes;
|
||||
int activePlayer, activePhase;
|
||||
bool onlyBuddies, onlyRegistered;
|
||||
bool spectatorsAllowed;
|
||||
bool spectatorsNeedPassword;
|
||||
bool spectatorsCanTalk;
|
||||
bool spectatorsSeeEverything;
|
||||
int inactivityCounter;
|
||||
int startTimeOfThisGame, secondsElapsed;
|
||||
bool firstGameStarted;
|
||||
QDateTime startTime;
|
||||
QTimer *pingClock;
|
||||
QList<GameReplay *> replayList;
|
||||
GameReplay *currentReplay;
|
||||
|
||||
void createGameStateChangedEvent(Event_GameStateChanged *event, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo);
|
||||
void sendGameStateToPlayers();
|
||||
void storeGameInformation();
|
||||
signals:
|
||||
void sigStartGameIfReady();
|
||||
void gameInfoChanged(ServerInfo_Game gameInfo);
|
||||
void sigStartGameIfReady();
|
||||
void gameInfoChanged(ServerInfo_Game gameInfo);
|
||||
private slots:
|
||||
void pingClockTimeout();
|
||||
void doStartGameIfReady();
|
||||
void pingClockTimeout();
|
||||
void doStartGameIfReady();
|
||||
public:
|
||||
mutable QMutex gameMutex;
|
||||
Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
|
||||
~Server_Game();
|
||||
Server_Room *getRoom() const { return room; }
|
||||
void getInfo(ServerInfo_Game &result) const;
|
||||
int getHostId() const { return hostId; }
|
||||
ServerInfo_User *getCreatorInfo() const { return creatorInfo; }
|
||||
bool getGameStarted() const { return gameStarted; }
|
||||
int getPlayerCount() const;
|
||||
int getSpectatorCount() const;
|
||||
const QMap<int, Server_Player *> &getPlayers() const { return players; }
|
||||
int getGameId() const { return gameId; }
|
||||
QString getDescription() const { return description; }
|
||||
QString getPassword() const { return password; }
|
||||
int getMaxPlayers() const { return maxPlayers; }
|
||||
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
||||
bool getSpectatorsNeedPassword() const { return spectatorsNeedPassword; }
|
||||
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
|
||||
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
|
||||
Response::ResponseCode checkJoin(ServerInfo_User *user, const QString &_password, bool spectator, bool overrideRestrictions);
|
||||
bool containsUser(const QString &userName) const;
|
||||
void addPlayer(Server_AbstractUserInterface *userInterface, ResponseContainer &rc, bool spectator, bool broadcastUpdate = true);
|
||||
void removePlayer(Server_Player *player);
|
||||
void removeArrowsRelatedToPlayer(GameEventStorage &ges, Server_Player *player);
|
||||
void unattachCards(GameEventStorage &ges, Server_Player *player);
|
||||
bool kickPlayer(int playerId);
|
||||
void startGameIfReady();
|
||||
void stopGameIfFinished();
|
||||
int getActivePlayer() const { return activePlayer; }
|
||||
int getActivePhase() const { return activePhase; }
|
||||
void setActivePlayer(int _activePlayer);
|
||||
void setActivePhase(int _activePhase);
|
||||
void nextTurn();
|
||||
int getSecondsElapsed() const { return secondsElapsed; }
|
||||
mutable QMutex gameMutex;
|
||||
Server_Game(const ServerInfo_User &_creatorInfo, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, const QList<int> &_gameTypes, bool _onlyBuddies, bool _onlyRegistered, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent);
|
||||
~Server_Game();
|
||||
Server_Room *getRoom() const { return room; }
|
||||
void getInfo(ServerInfo_Game &result) const;
|
||||
int getHostId() const { return hostId; }
|
||||
ServerInfo_User *getCreatorInfo() const { return creatorInfo; }
|
||||
bool getGameStarted() const { return gameStarted; }
|
||||
int getPlayerCount() const;
|
||||
int getSpectatorCount() const;
|
||||
const QMap<int, Server_Player *> &getPlayers() const { return players; }
|
||||
int getGameId() const { return gameId; }
|
||||
QString getDescription() const { return description; }
|
||||
QString getPassword() const { return password; }
|
||||
int getMaxPlayers() const { return maxPlayers; }
|
||||
bool getSpectatorsAllowed() const { return spectatorsAllowed; }
|
||||
bool getSpectatorsNeedPassword() const { return spectatorsNeedPassword; }
|
||||
bool getSpectatorsCanTalk() const { return spectatorsCanTalk; }
|
||||
bool getSpectatorsSeeEverything() const { return spectatorsSeeEverything; }
|
||||
Response::ResponseCode checkJoin(ServerInfo_User *user, const QString &_password, bool spectator, bool overrideRestrictions);
|
||||
bool containsUser(const QString &userName) const;
|
||||
void addPlayer(Server_AbstractUserInterface *userInterface, ResponseContainer &rc, bool spectator, bool broadcastUpdate = true);
|
||||
void removePlayer(Server_Player *player);
|
||||
void removeArrowsRelatedToPlayer(GameEventStorage &ges, Server_Player *player);
|
||||
void unattachCards(GameEventStorage &ges, Server_Player *player);
|
||||
bool kickPlayer(int playerId);
|
||||
void startGameIfReady();
|
||||
void stopGameIfFinished();
|
||||
int getActivePlayer() const { return activePlayer; }
|
||||
int getActivePhase() const { return activePhase; }
|
||||
void setActivePlayer(int _activePlayer);
|
||||
void setActivePhase(int _activePhase);
|
||||
void nextTurn();
|
||||
int getSecondsElapsed() const { return secondsElapsed; }
|
||||
|
||||
void createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming);
|
||||
|
||||
GameEventContainer *prepareGameEvent(const ::google::protobuf::Message &gameEvent, int playerId, GameEventContext *context = 0);
|
||||
GameEventContext prepareGameEventContext(const ::google::protobuf::Message &gameEventContext);
|
||||
|
||||
void sendGameEventContainer(GameEventContainer *cont, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int privatePlayerId = -1);
|
||||
void createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming);
|
||||
|
||||
GameEventContainer *prepareGameEvent(const ::google::protobuf::Message &gameEvent, int playerId, GameEventContext *context = 0);
|
||||
GameEventContext prepareGameEventContext(const ::google::protobuf::Message &gameEventContext);
|
||||
|
||||
void sendGameEventContainer(GameEventContainer *cont, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int privatePlayerId = -1);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -62,104 +62,104 @@ class Command_SetSideboardLock;
|
|||
class Command_ChangeZoneProperties;
|
||||
|
||||
class Server_Player : public Server_ArrowTarget, public ServerInfo_User_Container {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
class MoveCardCompareFunctor;
|
||||
Server_Game *game;
|
||||
Server_AbstractUserInterface *userInterface;
|
||||
DeckList *deck;
|
||||
QMap<QString, Server_CardZone *> zones;
|
||||
QMap<int, Server_Counter *> counters;
|
||||
QMap<int, Server_Arrow *> arrows;
|
||||
QList<int> lastDrawList;
|
||||
int pingTime;
|
||||
int playerId;
|
||||
bool spectator;
|
||||
int initialCards;
|
||||
int nextCardId;
|
||||
bool readyStart;
|
||||
bool conceded;
|
||||
bool sideboardLocked;
|
||||
class MoveCardCompareFunctor;
|
||||
Server_Game *game;
|
||||
Server_AbstractUserInterface *userInterface;
|
||||
DeckList *deck;
|
||||
QMap<QString, Server_CardZone *> zones;
|
||||
QMap<int, Server_Counter *> counters;
|
||||
QMap<int, Server_Arrow *> arrows;
|
||||
QList<int> lastDrawList;
|
||||
int pingTime;
|
||||
int playerId;
|
||||
bool spectator;
|
||||
int initialCards;
|
||||
int nextCardId;
|
||||
bool readyStart;
|
||||
bool conceded;
|
||||
bool sideboardLocked;
|
||||
public:
|
||||
mutable QMutex playerMutex;
|
||||
Server_Player(Server_Game *_game, int _playerId, const ServerInfo_User &_userInfo, bool _spectator, Server_AbstractUserInterface *_handler);
|
||||
~Server_Player();
|
||||
void prepareDestroy();
|
||||
Server_AbstractUserInterface *getUserInterface() const { return userInterface; }
|
||||
void setUserInterface(Server_AbstractUserInterface *_userInterface);
|
||||
void disconnectClient();
|
||||
|
||||
void setPlayerId(int _id) { playerId = _id; }
|
||||
bool getReadyStart() const { return readyStart; }
|
||||
void setReadyStart(bool _readyStart) { readyStart = _readyStart; }
|
||||
int getPlayerId() const { return playerId; }
|
||||
bool getSpectator() const { return spectator; }
|
||||
bool getConceded() const { return conceded; }
|
||||
void setConceded(bool _conceded) { conceded = _conceded; }
|
||||
DeckList *getDeck() const { return deck; }
|
||||
Server_Game *getGame() const { return game; }
|
||||
const QMap<QString, Server_CardZone *> &getZones() const { return zones; }
|
||||
const QMap<int, Server_Counter *> &getCounters() const { return counters; }
|
||||
const QMap<int, Server_Arrow *> &getArrows() const { return arrows; }
|
||||
|
||||
int getPingTime() const { return pingTime; }
|
||||
void setPingTime(int _pingTime) { pingTime = _pingTime; }
|
||||
void getProperties(ServerInfo_PlayerProperties &result, bool withUserInfo);
|
||||
|
||||
int newCardId();
|
||||
int newCounterId() const;
|
||||
int newArrowId() const;
|
||||
|
||||
void addZone(Server_CardZone *zone);
|
||||
void addArrow(Server_Arrow *arrow);
|
||||
bool deleteArrow(int arrowId);
|
||||
void addCounter(Server_Counter *counter);
|
||||
|
||||
void clearZones();
|
||||
void setupZones();
|
||||
mutable QMutex playerMutex;
|
||||
Server_Player(Server_Game *_game, int _playerId, const ServerInfo_User &_userInfo, bool _spectator, Server_AbstractUserInterface *_handler);
|
||||
~Server_Player();
|
||||
void prepareDestroy();
|
||||
Server_AbstractUserInterface *getUserInterface() const { return userInterface; }
|
||||
void setUserInterface(Server_AbstractUserInterface *_userInterface);
|
||||
void disconnectClient();
|
||||
|
||||
void setPlayerId(int _id) { playerId = _id; }
|
||||
bool getReadyStart() const { return readyStart; }
|
||||
void setReadyStart(bool _readyStart) { readyStart = _readyStart; }
|
||||
int getPlayerId() const { return playerId; }
|
||||
bool getSpectator() const { return spectator; }
|
||||
bool getConceded() const { return conceded; }
|
||||
void setConceded(bool _conceded) { conceded = _conceded; }
|
||||
DeckList *getDeck() const { return deck; }
|
||||
Server_Game *getGame() const { return game; }
|
||||
const QMap<QString, Server_CardZone *> &getZones() const { return zones; }
|
||||
const QMap<int, Server_Counter *> &getCounters() const { return counters; }
|
||||
const QMap<int, Server_Arrow *> &getArrows() const { return arrows; }
|
||||
|
||||
int getPingTime() const { return pingTime; }
|
||||
void setPingTime(int _pingTime) { pingTime = _pingTime; }
|
||||
void getProperties(ServerInfo_PlayerProperties &result, bool withUserInfo);
|
||||
|
||||
int newCardId();
|
||||
int newCounterId() const;
|
||||
int newArrowId() const;
|
||||
|
||||
void addZone(Server_CardZone *zone);
|
||||
void addArrow(Server_Arrow *arrow);
|
||||
bool deleteArrow(int arrowId);
|
||||
void addCounter(Server_Counter *counter);
|
||||
|
||||
void clearZones();
|
||||
void setupZones();
|
||||
|
||||
Response::ResponseCode drawCards(GameEventStorage &ges, int number);
|
||||
Response::ResponseCode moveCard(GameEventStorage &ges, Server_CardZone *startzone, const QList<const CardToMove *> &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces = true, bool undoingDraw = false);
|
||||
void unattachCard(GameEventStorage &ges, Server_Card *card);
|
||||
Response::ResponseCode setCardAttrHelper(GameEventStorage &ges, const QString &zone, int cardId, CardAttribute attribute, const QString &attrValue);
|
||||
Response::ResponseCode drawCards(GameEventStorage &ges, int number);
|
||||
Response::ResponseCode moveCard(GameEventStorage &ges, Server_CardZone *startzone, const QList<const CardToMove *> &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces = true, bool undoingDraw = false);
|
||||
void unattachCard(GameEventStorage &ges, Server_Card *card);
|
||||
Response::ResponseCode setCardAttrHelper(GameEventStorage &ges, const QString &zone, int cardId, CardAttribute attribute, const QString &attrValue);
|
||||
|
||||
Response::ResponseCode cmdLeaveGame(const Command_LeaveGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdKickFromGame(const Command_KickFromGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdConcede(const Command_Concede &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdReadyStart(const Command_ReadyStart &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetSideboardLock(const Command_SetSideboardLock &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdGameSay(const Command_GameSay &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdShuffle(const Command_Shuffle &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdMulligan(const Command_Mulligan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdFlipCard(const Command_FlipCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdDeleteArrow(const Command_DeleteArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetCardAttr(const Command_SetCardAttr &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetCardCounter(const Command_SetCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdIncCardCounter(const Command_IncCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdIncCounter(const Command_IncCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdCreateCounter(const Command_CreateCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetCounter(const Command_SetCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdNextTurn(const Command_NextTurn &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetActivePhase(const Command_SetActivePhase &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdDumpZone(const Command_DumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdStopDumpZone(const Command_StopDumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
|
||||
Response::ResponseCode processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges);
|
||||
void sendGameEvent(const GameEventContainer &event);
|
||||
|
||||
void getInfo(ServerInfo_Player *info, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo);
|
||||
Response::ResponseCode cmdLeaveGame(const Command_LeaveGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdKickFromGame(const Command_KickFromGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdConcede(const Command_Concede &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdReadyStart(const Command_ReadyStart &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetSideboardLock(const Command_SetSideboardLock &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdGameSay(const Command_GameSay &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdShuffle(const Command_Shuffle &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdMulligan(const Command_Mulligan &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdFlipCard(const Command_FlipCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdDeleteArrow(const Command_DeleteArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetCardAttr(const Command_SetCardAttr &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetCardCounter(const Command_SetCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdIncCardCounter(const Command_IncCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdIncCounter(const Command_IncCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdCreateCounter(const Command_CreateCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetCounter(const Command_SetCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdNextTurn(const Command_NextTurn &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdSetActivePhase(const Command_SetActivePhase &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdDumpZone(const Command_DumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdStopDumpZone(const Command_StopDumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
Response::ResponseCode cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd, ResponseContainer &rc, GameEventStorage &ges);
|
||||
|
||||
Response::ResponseCode processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges);
|
||||
void sendGameEvent(const GameEventContainer &event);
|
||||
|
||||
void getInfo(ServerInfo_Player *info, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
|
||||
class PlayerReference {
|
||||
private:
|
||||
int roomId;
|
||||
int gameId;
|
||||
int playerId;
|
||||
int roomId;
|
||||
int gameId;
|
||||
int playerId;
|
||||
public:
|
||||
PlayerReference(int _roomId, int _gameId, int _playerId) : roomId(_roomId), gameId(_gameId), playerId(_playerId) { }
|
||||
int getRoomId() const { return roomId; }
|
||||
int getGameId() const { return gameId; }
|
||||
int getPlayerId() const { return playerId; }
|
||||
bool operator==(const PlayerReference &other) { return ((roomId == other.roomId) && (gameId == other.gameId) && (playerId == other.playerId)); }
|
||||
PlayerReference(int _roomId, int _gameId, int _playerId) : roomId(_roomId), gameId(_gameId), playerId(_playerId) { }
|
||||
int getRoomId() const { return roomId; }
|
||||
int getGameId() const { return gameId; }
|
||||
int getPlayerId() const { return playerId; }
|
||||
bool operator==(const PlayerReference &other) { return ((roomId == other.roomId) && (gameId == other.gameId) && (playerId == other.playerId)); }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,64 +40,64 @@ class Command_CreateGame;
|
|||
class Command_JoinGame;
|
||||
|
||||
class Server_ProtocolHandler : public QObject, public Server_AbstractUserInterface {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
protected:
|
||||
QMap<int, Server_Room *> rooms;
|
||||
|
||||
bool deleted;
|
||||
Server_DatabaseInterface *databaseInterface;
|
||||
AuthenticationResult authState;
|
||||
bool acceptsUserListChanges;
|
||||
bool acceptsRoomListChanges;
|
||||
virtual void logDebugMessage(const QString &message) { }
|
||||
QMap<int, Server_Room *> rooms;
|
||||
|
||||
bool deleted;
|
||||
Server_DatabaseInterface *databaseInterface;
|
||||
AuthenticationResult authState;
|
||||
bool acceptsUserListChanges;
|
||||
bool acceptsRoomListChanges;
|
||||
virtual void logDebugMessage(const QString &message) { }
|
||||
private:
|
||||
QList<int> messageSizeOverTime, messageCountOverTime;
|
||||
int timeRunning, lastDataReceived;
|
||||
QTimer *pingClock;
|
||||
QList<int> messageSizeOverTime, messageCountOverTime;
|
||||
int timeRunning, lastDataReceived;
|
||||
QTimer *pingClock;
|
||||
|
||||
virtual void transmitProtocolItem(const ServerMessage &item) = 0;
|
||||
|
||||
Response::ResponseCode cmdPing(const Command_Ping &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdLogin(const Command_Login &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdMessage(const Command_Message &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdGetUserInfo(const Command_GetUserInfo &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdListRooms(const Command_ListRooms &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdJoinRoom(const Command_JoinRoom &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdListUsers(const Command_ListUsers &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdLeaveRoom(const Command_LeaveRoom &cmd, Server_Room *room, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdRoomSay(const Command_RoomSay &cmd, Server_Room *room, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdCreateGame(const Command_CreateGame &cmd, Server_Room *room, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdJoinGame(const Command_JoinGame &cmd, Server_Room *room, ResponseContainer &rc);
|
||||
|
||||
Response::ResponseCode processSessionCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
virtual Response::ResponseCode processExtendedSessionCommand(int cmdType, const SessionCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
||||
Response::ResponseCode processRoomCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
Response::ResponseCode processGameCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
Response::ResponseCode processModeratorCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
virtual Response::ResponseCode processExtendedModeratorCommand(int cmdType, const ModeratorCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
||||
Response::ResponseCode processAdminCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
virtual Response::ResponseCode processExtendedAdminCommand(int cmdType, const AdminCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
||||
virtual void transmitProtocolItem(const ServerMessage &item) = 0;
|
||||
|
||||
Response::ResponseCode cmdPing(const Command_Ping &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdLogin(const Command_Login &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdMessage(const Command_Message &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdGetUserInfo(const Command_GetUserInfo &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdListRooms(const Command_ListRooms &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdJoinRoom(const Command_JoinRoom &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdListUsers(const Command_ListUsers &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdLeaveRoom(const Command_LeaveRoom &cmd, Server_Room *room, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdRoomSay(const Command_RoomSay &cmd, Server_Room *room, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdCreateGame(const Command_CreateGame &cmd, Server_Room *room, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdJoinGame(const Command_JoinGame &cmd, Server_Room *room, ResponseContainer &rc);
|
||||
|
||||
Response::ResponseCode processSessionCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
virtual Response::ResponseCode processExtendedSessionCommand(int cmdType, const SessionCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
||||
Response::ResponseCode processRoomCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
Response::ResponseCode processGameCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
Response::ResponseCode processModeratorCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
virtual Response::ResponseCode processExtendedModeratorCommand(int cmdType, const ModeratorCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
||||
Response::ResponseCode processAdminCommandContainer(const CommandContainer &cont, ResponseContainer &rc);
|
||||
virtual Response::ResponseCode processExtendedAdminCommand(int cmdType, const AdminCommand &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
|
||||
private slots:
|
||||
void pingClockTimeout();
|
||||
void pingClockTimeout();
|
||||
public slots:
|
||||
void prepareDestroy();
|
||||
void prepareDestroy();
|
||||
public:
|
||||
Server_ProtocolHandler(Server *_server, Server_DatabaseInterface *_databaseInterface, QObject *parent = 0);
|
||||
~Server_ProtocolHandler();
|
||||
|
||||
bool getAcceptsUserListChanges() const { return acceptsUserListChanges; }
|
||||
bool getAcceptsRoomListChanges() const { return acceptsRoomListChanges; }
|
||||
virtual QString getAddress() const = 0;
|
||||
Server_DatabaseInterface *getDatabaseInterface() const { return databaseInterface; }
|
||||
Server_ProtocolHandler(Server *_server, Server_DatabaseInterface *_databaseInterface, QObject *parent = 0);
|
||||
~Server_ProtocolHandler();
|
||||
|
||||
bool getAcceptsUserListChanges() const { return acceptsUserListChanges; }
|
||||
bool getAcceptsRoomListChanges() const { return acceptsRoomListChanges; }
|
||||
virtual QString getAddress() const = 0;
|
||||
Server_DatabaseInterface *getDatabaseInterface() const { return databaseInterface; }
|
||||
|
||||
int getLastCommandTime() const { return timeRunning - lastDataReceived; }
|
||||
void processCommandContainer(const CommandContainer &cont);
|
||||
|
||||
void sendProtocolItem(const Response &item);
|
||||
void sendProtocolItem(const SessionEvent &item);
|
||||
void sendProtocolItem(const GameEventContainer &item);
|
||||
void sendProtocolItem(const RoomEvent &item);
|
||||
int getLastCommandTime() const { return timeRunning - lastDataReceived; }
|
||||
void processCommandContainer(const CommandContainer &cont);
|
||||
|
||||
void sendProtocolItem(const Response &item);
|
||||
void sendProtocolItem(const SessionEvent &item);
|
||||
void sendProtocolItem(const GameEventContainer &item);
|
||||
void sendProtocolItem(const RoomEvent &item);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,20 +4,20 @@
|
|||
|
||||
void Server_RemoteUserInterface::sendProtocolItem(const Response &item)
|
||||
{
|
||||
server->sendIsl_Response(item, userInfo->server_id(), userInfo->session_id());
|
||||
server->sendIsl_Response(item, userInfo->server_id(), userInfo->session_id());
|
||||
}
|
||||
|
||||
void Server_RemoteUserInterface::sendProtocolItem(const SessionEvent &item)
|
||||
{
|
||||
server->sendIsl_SessionEvent(item, userInfo->server_id(), userInfo->session_id());
|
||||
server->sendIsl_SessionEvent(item, userInfo->server_id(), userInfo->session_id());
|
||||
}
|
||||
|
||||
void Server_RemoteUserInterface::sendProtocolItem(const GameEventContainer &item)
|
||||
{
|
||||
server->sendIsl_GameEventContainer(item, userInfo->server_id(), userInfo->session_id());
|
||||
server->sendIsl_GameEventContainer(item, userInfo->server_id(), userInfo->session_id());
|
||||
}
|
||||
|
||||
void Server_RemoteUserInterface::sendProtocolItem(const RoomEvent &item)
|
||||
{
|
||||
server->sendIsl_RoomEvent(item, userInfo->server_id(), userInfo->session_id());
|
||||
server->sendIsl_RoomEvent(item, userInfo->server_id(), userInfo->session_id());
|
||||
}
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
|
||||
class Server_RemoteUserInterface : public Server_AbstractUserInterface {
|
||||
public:
|
||||
Server_RemoteUserInterface(Server *_server, const ServerInfo_User_Container &_userInfoContainer) : Server_AbstractUserInterface(_server, _userInfoContainer) { }
|
||||
|
||||
int getLastCommandTime() const { return 0; }
|
||||
|
||||
void sendProtocolItem(const Response &item);
|
||||
void sendProtocolItem(const SessionEvent &item);
|
||||
void sendProtocolItem(const GameEventContainer &item);
|
||||
void sendProtocolItem(const RoomEvent &item);
|
||||
Server_RemoteUserInterface(Server *_server, const ServerInfo_User_Container &_userInfoContainer) : Server_AbstractUserInterface(_server, _userInfoContainer) { }
|
||||
|
||||
int getLastCommandTime() const { return 0; }
|
||||
|
||||
void sendProtocolItem(const Response &item);
|
||||
void sendProtocolItem(const SessionEvent &item);
|
||||
void sendProtocolItem(const GameEventContainer &item);
|
||||
void sendProtocolItem(const RoomEvent &item);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,64 +3,64 @@
|
|||
#include "server_game.h"
|
||||
|
||||
GameEventStorageItem::GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients)
|
||||
: event(new GameEvent), recipients(_recipients)
|
||||
: event(new GameEvent), recipients(_recipients)
|
||||
{
|
||||
event->GetReflection()->MutableMessage(event, _event.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_event);
|
||||
event->set_player_id(_playerId);
|
||||
event->GetReflection()->MutableMessage(event, _event.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_event);
|
||||
event->set_player_id(_playerId);
|
||||
}
|
||||
|
||||
GameEventStorageItem::~GameEventStorageItem()
|
||||
{
|
||||
delete event;
|
||||
delete event;
|
||||
}
|
||||
|
||||
GameEventStorage::GameEventStorage()
|
||||
: gameEventContext(0)
|
||||
: gameEventContext(0)
|
||||
{
|
||||
}
|
||||
|
||||
GameEventStorage::~GameEventStorage()
|
||||
{
|
||||
delete gameEventContext;
|
||||
for (int i = 0; i < gameEventList.size(); ++i)
|
||||
delete gameEventList[i];
|
||||
delete gameEventContext;
|
||||
for (int i = 0; i < gameEventList.size(); ++i)
|
||||
delete gameEventList[i];
|
||||
}
|
||||
|
||||
void GameEventStorage::setGameEventContext(const ::google::protobuf::Message &_gameEventContext)
|
||||
{
|
||||
delete gameEventContext;
|
||||
gameEventContext = new GameEventContext;
|
||||
gameEventContext->GetReflection()->MutableMessage(gameEventContext, _gameEventContext.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_gameEventContext);
|
||||
delete gameEventContext;
|
||||
gameEventContext = new GameEventContext;
|
||||
gameEventContext->GetReflection()->MutableMessage(gameEventContext, _gameEventContext.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(_gameEventContext);
|
||||
}
|
||||
|
||||
void GameEventStorage::enqueueGameEvent(const ::google::protobuf::Message &event, int playerId, GameEventStorageItem::EventRecipients recipients, int _privatePlayerId)
|
||||
{
|
||||
gameEventList.append(new GameEventStorageItem(event, playerId, recipients));
|
||||
if (_privatePlayerId != -1)
|
||||
privatePlayerId = _privatePlayerId;
|
||||
gameEventList.append(new GameEventStorageItem(event, playerId, recipients));
|
||||
if (_privatePlayerId != -1)
|
||||
privatePlayerId = _privatePlayerId;
|
||||
}
|
||||
|
||||
void GameEventStorage::sendToGame(Server_Game *game)
|
||||
{
|
||||
if (gameEventList.isEmpty())
|
||||
return;
|
||||
|
||||
GameEventContainer *contPrivate = new GameEventContainer;
|
||||
GameEventContainer *contOthers = new GameEventContainer;
|
||||
for (int i = 0; i < gameEventList.size(); ++i) {
|
||||
const GameEvent &event = gameEventList[i]->getGameEvent();
|
||||
const GameEventStorageItem::EventRecipients recipients = gameEventList[i]->getRecipients();
|
||||
if (recipients.testFlag(GameEventStorageItem::SendToPrivate))
|
||||
contPrivate->add_event_list()->CopyFrom(event);
|
||||
if (recipients.testFlag(GameEventStorageItem::SendToOthers))
|
||||
contOthers->add_event_list()->CopyFrom(event);
|
||||
}
|
||||
if (gameEventContext) {
|
||||
contPrivate->mutable_context()->CopyFrom(*gameEventContext);
|
||||
contOthers->mutable_context()->CopyFrom(*gameEventContext);
|
||||
}
|
||||
game->sendGameEventContainer(contPrivate, GameEventStorageItem::SendToPrivate, privatePlayerId);
|
||||
game->sendGameEventContainer(contOthers, GameEventStorageItem::SendToOthers, privatePlayerId);
|
||||
if (gameEventList.isEmpty())
|
||||
return;
|
||||
|
||||
GameEventContainer *contPrivate = new GameEventContainer;
|
||||
GameEventContainer *contOthers = new GameEventContainer;
|
||||
for (int i = 0; i < gameEventList.size(); ++i) {
|
||||
const GameEvent &event = gameEventList[i]->getGameEvent();
|
||||
const GameEventStorageItem::EventRecipients recipients = gameEventList[i]->getRecipients();
|
||||
if (recipients.testFlag(GameEventStorageItem::SendToPrivate))
|
||||
contPrivate->add_event_list()->CopyFrom(event);
|
||||
if (recipients.testFlag(GameEventStorageItem::SendToOthers))
|
||||
contOthers->add_event_list()->CopyFrom(event);
|
||||
}
|
||||
if (gameEventContext) {
|
||||
contPrivate->mutable_context()->CopyFrom(*gameEventContext);
|
||||
contOthers->mutable_context()->CopyFrom(*gameEventContext);
|
||||
}
|
||||
game->sendGameEventContainer(contPrivate, GameEventStorageItem::SendToPrivate, privatePlayerId);
|
||||
game->sendGameEventContainer(contOthers, GameEventStorageItem::SendToOthers, privatePlayerId);
|
||||
}
|
||||
|
||||
ResponseContainer::ResponseContainer(int _cmdId)
|
||||
|
@ -70,9 +70,9 @@ ResponseContainer::ResponseContainer(int _cmdId)
|
|||
|
||||
ResponseContainer::~ResponseContainer()
|
||||
{
|
||||
delete responseExtension;
|
||||
for (int i = 0; i < preResponseQueue.size(); ++i)
|
||||
delete preResponseQueue[i].second;
|
||||
for (int i = 0; i < postResponseQueue.size(); ++i)
|
||||
delete postResponseQueue[i].second;
|
||||
delete responseExtension;
|
||||
for (int i = 0; i < preResponseQueue.size(); ++i)
|
||||
delete preResponseQueue[i].second;
|
||||
for (int i = 0; i < postResponseQueue.size(); ++i)
|
||||
delete postResponseQueue[i].second;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define SERVER_RESPONSE_CONTAINERS_H
|
||||
|
||||
#include <QPair>
|
||||
#include <QList>
|
||||
#include "pb/server_message.pb.h"
|
||||
|
||||
namespace google { namespace protobuf { class Message; } }
|
||||
|
@ -9,54 +10,54 @@ class Server_Game;
|
|||
|
||||
class GameEventStorageItem {
|
||||
public:
|
||||
enum EventRecipient { SendToPrivate = 0x01, SendToOthers = 0x02};
|
||||
Q_DECLARE_FLAGS(EventRecipients, EventRecipient)
|
||||
enum EventRecipient { SendToPrivate = 0x01, SendToOthers = 0x02};
|
||||
Q_DECLARE_FLAGS(EventRecipients, EventRecipient)
|
||||
private:
|
||||
GameEvent *event;
|
||||
EventRecipients recipients;
|
||||
GameEvent *event;
|
||||
EventRecipients recipients;
|
||||
public:
|
||||
GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients);
|
||||
~GameEventStorageItem();
|
||||
|
||||
const GameEvent &getGameEvent() const { return *event; }
|
||||
EventRecipients getRecipients() const { return recipients; }
|
||||
GameEventStorageItem(const ::google::protobuf::Message &_event, int _playerId, EventRecipients _recipients);
|
||||
~GameEventStorageItem();
|
||||
|
||||
const GameEvent &getGameEvent() const { return *event; }
|
||||
EventRecipients getRecipients() const { return recipients; }
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(GameEventStorageItem::EventRecipients)
|
||||
|
||||
class GameEventStorage {
|
||||
private:
|
||||
::google::protobuf::Message *gameEventContext;
|
||||
QList<GameEventStorageItem *> gameEventList;
|
||||
int privatePlayerId;
|
||||
::google::protobuf::Message *gameEventContext;
|
||||
QList<GameEventStorageItem *> gameEventList;
|
||||
int privatePlayerId;
|
||||
public:
|
||||
GameEventStorage();
|
||||
~GameEventStorage();
|
||||
|
||||
void setGameEventContext(const ::google::protobuf::Message &_gameEventContext);
|
||||
::google::protobuf::Message *getGameEventContext() const { return gameEventContext; }
|
||||
const QList<GameEventStorageItem *> &getGameEventList() const { return gameEventList; }
|
||||
int getPrivatePlayerId() const { return privatePlayerId; }
|
||||
|
||||
void enqueueGameEvent(const ::google::protobuf::Message &event, int playerId, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int _privatePlayerId = -1);
|
||||
void sendToGame(Server_Game *game);
|
||||
GameEventStorage();
|
||||
~GameEventStorage();
|
||||
|
||||
void setGameEventContext(const ::google::protobuf::Message &_gameEventContext);
|
||||
::google::protobuf::Message *getGameEventContext() const { return gameEventContext; }
|
||||
const QList<GameEventStorageItem *> &getGameEventList() const { return gameEventList; }
|
||||
int getPrivatePlayerId() const { return privatePlayerId; }
|
||||
|
||||
void enqueueGameEvent(const ::google::protobuf::Message &event, int playerId, GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate | GameEventStorageItem::SendToOthers, int _privatePlayerId = -1);
|
||||
void sendToGame(Server_Game *game);
|
||||
};
|
||||
|
||||
class ResponseContainer {
|
||||
private:
|
||||
int cmdId;
|
||||
::google::protobuf::Message *responseExtension;
|
||||
QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > preResponseQueue, postResponseQueue;
|
||||
int cmdId;
|
||||
::google::protobuf::Message *responseExtension;
|
||||
QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > preResponseQueue, postResponseQueue;
|
||||
public:
|
||||
ResponseContainer(int _cmdId);
|
||||
~ResponseContainer();
|
||||
|
||||
int getCmdId() const { return cmdId; }
|
||||
void setResponseExtension(::google::protobuf::Message *_responseExtension) { responseExtension = _responseExtension; }
|
||||
::google::protobuf::Message *getResponseExtension() const { return responseExtension; }
|
||||
void enqueuePreResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item) { preResponseQueue.append(qMakePair(type, item)); }
|
||||
void enqueuePostResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item) { postResponseQueue.append(qMakePair(type, item)); }
|
||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &getPreResponseQueue() const { return preResponseQueue; }
|
||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &getPostResponseQueue() const { return postResponseQueue; }
|
||||
ResponseContainer(int _cmdId);
|
||||
~ResponseContainer();
|
||||
|
||||
int getCmdId() const { return cmdId; }
|
||||
void setResponseExtension(::google::protobuf::Message *_responseExtension) { responseExtension = _responseExtension; }
|
||||
::google::protobuf::Message *getResponseExtension() const { return responseExtension; }
|
||||
void enqueuePreResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item) { preResponseQueue.append(qMakePair(type, item)); }
|
||||
void enqueuePostResponseItem(ServerMessage::MessageType type, ::google::protobuf::Message *item) { postResponseQueue.append(qMakePair(type, item)); }
|
||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &getPreResponseQueue() const { return preResponseQueue; }
|
||||
const QList<QPair<ServerMessage::MessageType, ::google::protobuf::Message *> > &getPostResponseQueue() const { return postResponseQueue; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,326 +13,326 @@
|
|||
#include <google/protobuf/descriptor.h>
|
||||
|
||||
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
|
||||
: QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes), gamesLock(QReadWriteLock::Recursive)
|
||||
: QObject(parent), id(_id), name(_name), description(_description), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes), gamesLock(QReadWriteLock::Recursive)
|
||||
{
|
||||
connect(this, SIGNAL(gameListChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(gameListChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)), Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
Server_Room::~Server_Room()
|
||||
{
|
||||
qDebug("Server_Room destructor");
|
||||
|
||||
gamesLock.lockForWrite();
|
||||
const QList<Server_Game *> gameList = games.values();
|
||||
for (int i = 0; i < gameList.size(); ++i)
|
||||
delete gameList[i];
|
||||
games.clear();
|
||||
gamesLock.unlock();
|
||||
|
||||
usersLock.lockForWrite();
|
||||
users.clear();
|
||||
usersLock.unlock();
|
||||
qDebug("Server_Room destructor");
|
||||
|
||||
gamesLock.lockForWrite();
|
||||
const QList<Server_Game *> gameList = games.values();
|
||||
for (int i = 0; i < gameList.size(); ++i)
|
||||
delete gameList[i];
|
||||
games.clear();
|
||||
gamesLock.unlock();
|
||||
|
||||
usersLock.lockForWrite();
|
||||
users.clear();
|
||||
usersLock.unlock();
|
||||
}
|
||||
|
||||
Server *Server_Room::getServer() const
|
||||
{
|
||||
return static_cast<Server *>(parent());
|
||||
return static_cast<Server *>(parent());
|
||||
}
|
||||
|
||||
const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes, bool includeExternalData) const
|
||||
{
|
||||
result.set_room_id(id);
|
||||
|
||||
result.set_name(name.toStdString());
|
||||
result.set_description(description.toStdString());
|
||||
result.set_auto_join(autoJoin);
|
||||
|
||||
gamesLock.lockForRead();
|
||||
result.set_game_count(games.size() + externalGames.size());
|
||||
if (complete) {
|
||||
QMapIterator<int, Server_Game *> gameIterator(games);
|
||||
while (gameIterator.hasNext())
|
||||
gameIterator.next().value()->getInfo(*result.add_game_list());
|
||||
if (includeExternalData) {
|
||||
QMapIterator<int, ServerInfo_Game> externalGameIterator(externalGames);
|
||||
while (externalGameIterator.hasNext())
|
||||
result.add_game_list()->CopyFrom(externalGameIterator.next().value());
|
||||
}
|
||||
}
|
||||
gamesLock.unlock();
|
||||
|
||||
usersLock.lockForRead();
|
||||
result.set_player_count(users.size() + externalUsers.size());
|
||||
if (complete) {
|
||||
QMapIterator<QString, Server_ProtocolHandler *> userIterator(users);
|
||||
while (userIterator.hasNext())
|
||||
result.add_user_list()->CopyFrom(userIterator.next().value()->copyUserInfo(false));
|
||||
if (includeExternalData) {
|
||||
QMapIterator<QString, ServerInfo_User_Container> externalUserIterator(externalUsers);
|
||||
while (externalUserIterator.hasNext())
|
||||
result.add_user_list()->CopyFrom(externalUserIterator.next().value().copyUserInfo(false));
|
||||
}
|
||||
}
|
||||
usersLock.unlock();
|
||||
|
||||
if (complete || showGameTypes)
|
||||
for (int i = 0; i < gameTypes.size(); ++i) {
|
||||
ServerInfo_GameType *gameTypeInfo = result.add_gametype_list();
|
||||
gameTypeInfo->set_game_type_id(i);
|
||||
gameTypeInfo->set_description(gameTypes[i].toStdString());
|
||||
}
|
||||
|
||||
return result;
|
||||
result.set_room_id(id);
|
||||
|
||||
result.set_name(name.toStdString());
|
||||
result.set_description(description.toStdString());
|
||||
result.set_auto_join(autoJoin);
|
||||
|
||||
gamesLock.lockForRead();
|
||||
result.set_game_count(games.size() + externalGames.size());
|
||||
if (complete) {
|
||||
QMapIterator<int, Server_Game *> gameIterator(games);
|
||||
while (gameIterator.hasNext())
|
||||
gameIterator.next().value()->getInfo(*result.add_game_list());
|
||||
if (includeExternalData) {
|
||||
QMapIterator<int, ServerInfo_Game> externalGameIterator(externalGames);
|
||||
while (externalGameIterator.hasNext())
|
||||
result.add_game_list()->CopyFrom(externalGameIterator.next().value());
|
||||
}
|
||||
}
|
||||
gamesLock.unlock();
|
||||
|
||||
usersLock.lockForRead();
|
||||
result.set_player_count(users.size() + externalUsers.size());
|
||||
if (complete) {
|
||||
QMapIterator<QString, Server_ProtocolHandler *> userIterator(users);
|
||||
while (userIterator.hasNext())
|
||||
result.add_user_list()->CopyFrom(userIterator.next().value()->copyUserInfo(false));
|
||||
if (includeExternalData) {
|
||||
QMapIterator<QString, ServerInfo_User_Container> externalUserIterator(externalUsers);
|
||||
while (externalUserIterator.hasNext())
|
||||
result.add_user_list()->CopyFrom(externalUserIterator.next().value().copyUserInfo(false));
|
||||
}
|
||||
}
|
||||
usersLock.unlock();
|
||||
|
||||
if (complete || showGameTypes)
|
||||
for (int i = 0; i < gameTypes.size(); ++i) {
|
||||
ServerInfo_GameType *gameTypeInfo = result.add_gametype_list();
|
||||
gameTypeInfo->set_game_type_id(i);
|
||||
gameTypeInfo->set_description(gameTypes[i].toStdString());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
RoomEvent *Server_Room::prepareRoomEvent(const ::google::protobuf::Message &roomEvent)
|
||||
{
|
||||
RoomEvent *event = new RoomEvent;
|
||||
event->set_room_id(id);
|
||||
event->GetReflection()->MutableMessage(event, roomEvent.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(roomEvent);
|
||||
return event;
|
||||
RoomEvent *event = new RoomEvent;
|
||||
event->set_room_id(id);
|
||||
event->GetReflection()->MutableMessage(event, roomEvent.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(roomEvent);
|
||||
return event;
|
||||
}
|
||||
|
||||
void Server_Room::addClient(Server_ProtocolHandler *client)
|
||||
{
|
||||
Event_JoinRoom event;
|
||||
event.mutable_user_info()->CopyFrom(client->copyUserInfo(false));
|
||||
sendRoomEvent(prepareRoomEvent(event));
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
usersLock.lockForWrite();
|
||||
users.insert(QString::fromStdString(client->getUserInfo()->name()), client);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
gamesLock.lockForRead();
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
gamesLock.unlock();
|
||||
// -----------
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
Event_JoinRoom event;
|
||||
event.mutable_user_info()->CopyFrom(client->copyUserInfo(false));
|
||||
sendRoomEvent(prepareRoomEvent(event));
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
usersLock.lockForWrite();
|
||||
users.insert(QString::fromStdString(client->getUserInfo()->name()), client);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
gamesLock.lockForRead();
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
gamesLock.unlock();
|
||||
// -----------
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
void Server_Room::removeClient(Server_ProtocolHandler *client)
|
||||
{
|
||||
usersLock.lockForWrite();
|
||||
users.remove(QString::fromStdString(client->getUserInfo()->name()));
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
Event_LeaveRoom event;
|
||||
event.set_name(client->getUserInfo()->name());
|
||||
sendRoomEvent(prepareRoomEvent(event));
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
gamesLock.lockForRead();
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
gamesLock.unlock();
|
||||
// -----------
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
usersLock.lockForWrite();
|
||||
users.remove(QString::fromStdString(client->getUserInfo()->name()));
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
Event_LeaveRoom event;
|
||||
event.set_name(client->getUserInfo()->name());
|
||||
sendRoomEvent(prepareRoomEvent(event));
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
gamesLock.lockForRead();
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
gamesLock.unlock();
|
||||
// -----------
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
void Server_Room::addExternalUser(const ServerInfo_User &userInfo)
|
||||
{
|
||||
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||
ServerInfo_User_Container userInfoContainer(userInfo);
|
||||
Event_JoinRoom event;
|
||||
event.mutable_user_info()->CopyFrom(userInfoContainer.copyUserInfo(false));
|
||||
sendRoomEvent(prepareRoomEvent(event), false);
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||
ServerInfo_User_Container userInfoContainer(userInfo);
|
||||
Event_JoinRoom event;
|
||||
event.mutable_user_info()->CopyFrom(userInfoContainer.copyUserInfo(false));
|
||||
sendRoomEvent(prepareRoomEvent(event), false);
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
usersLock.lockForWrite();
|
||||
externalUsers.insert(QString::fromStdString(userInfo.name()), userInfoContainer);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
usersLock.lockForWrite();
|
||||
externalUsers.insert(QString::fromStdString(userInfo.name()), userInfoContainer);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
void Server_Room::removeExternalUser(const QString &name)
|
||||
{
|
||||
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
usersLock.lockForWrite();
|
||||
if (externalUsers.contains(name))
|
||||
externalUsers.remove(name);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
Event_LeaveRoom event;
|
||||
event.set_name(name.toStdString());
|
||||
sendRoomEvent(prepareRoomEvent(event), false);
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
usersLock.lockForWrite();
|
||||
if (externalUsers.contains(name))
|
||||
externalUsers.remove(name);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
Event_LeaveRoom event;
|
||||
event.set_name(name.toStdString());
|
||||
sendRoomEvent(prepareRoomEvent(event), false);
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
void Server_Room::updateExternalGameList(const ServerInfo_Game &gameInfo)
|
||||
{
|
||||
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
gamesLock.lockForWrite();
|
||||
if (!gameInfo.has_player_count() && externalGames.contains(gameInfo.game_id()))
|
||||
externalGames.remove(gameInfo.game_id());
|
||||
else
|
||||
externalGames.insert(gameInfo.game_id(), gameInfo);
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
gamesLock.unlock();
|
||||
|
||||
broadcastGameListUpdate(gameInfo, false);
|
||||
emit roomInfoChanged(roomInfo);
|
||||
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
gamesLock.lockForWrite();
|
||||
if (!gameInfo.has_player_count() && externalGames.contains(gameInfo.game_id()))
|
||||
externalGames.remove(gameInfo.game_id());
|
||||
else
|
||||
externalGames.insert(gameInfo.game_id(), gameInfo);
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
gamesLock.unlock();
|
||||
|
||||
broadcastGameListUpdate(gameInfo, false);
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
Response::ResponseCode Server_Room::processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface)
|
||||
{
|
||||
// This function is called from the Server thread and from the S_PH thread.
|
||||
// server->roomsMutex is always locked.
|
||||
|
||||
QReadLocker roomGamesLocker(&gamesLock);
|
||||
Server_Game *g = games.value(cmd.game_id());
|
||||
if (!g) {
|
||||
if (externalGames.contains(cmd.game_id())) {
|
||||
CommandContainer cont;
|
||||
cont.set_cmd_id(rc.getCmdId());
|
||||
RoomCommand *roomCommand = cont.add_room_command();
|
||||
roomCommand->GetReflection()->MutableMessage(roomCommand, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
|
||||
getServer()->sendIsl_RoomCommand(cont, externalGames.value(cmd.game_id()).server_id(), userInterface->getUserInfo()->session_id(), id);
|
||||
|
||||
return Response::RespNothing;
|
||||
} else
|
||||
return Response::RespNameNotFound;
|
||||
}
|
||||
|
||||
QMutexLocker gameLocker(&g->gameMutex);
|
||||
|
||||
Response::ResponseCode result = g->checkJoin(userInterface->getUserInfo(), QString::fromStdString(cmd.password()), cmd.spectator(), cmd.override_restrictions());
|
||||
if (result == Response::RespOk)
|
||||
g->addPlayer(userInterface, rc, cmd.spectator());
|
||||
|
||||
return result;
|
||||
// This function is called from the Server thread and from the S_PH thread.
|
||||
// server->roomsMutex is always locked.
|
||||
|
||||
QReadLocker roomGamesLocker(&gamesLock);
|
||||
Server_Game *g = games.value(cmd.game_id());
|
||||
if (!g) {
|
||||
if (externalGames.contains(cmd.game_id())) {
|
||||
CommandContainer cont;
|
||||
cont.set_cmd_id(rc.getCmdId());
|
||||
RoomCommand *roomCommand = cont.add_room_command();
|
||||
roomCommand->GetReflection()->MutableMessage(roomCommand, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
|
||||
getServer()->sendIsl_RoomCommand(cont, externalGames.value(cmd.game_id()).server_id(), userInterface->getUserInfo()->session_id(), id);
|
||||
|
||||
return Response::RespNothing;
|
||||
} else
|
||||
return Response::RespNameNotFound;
|
||||
}
|
||||
|
||||
QMutexLocker gameLocker(&g->gameMutex);
|
||||
|
||||
Response::ResponseCode result = g->checkJoin(userInterface->getUserInfo(), QString::fromStdString(cmd.password()), cmd.spectator(), cmd.override_restrictions());
|
||||
if (result == Response::RespOk)
|
||||
g->addPlayer(userInterface, rc, cmd.spectator());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Server_Room::say(const QString &userName, const QString &s, bool sendToIsl)
|
||||
{
|
||||
Event_RoomSay event;
|
||||
event.set_name(userName.toStdString());
|
||||
event.set_message(s.toStdString());
|
||||
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
||||
Event_RoomSay event;
|
||||
event.set_name(userName.toStdString());
|
||||
event.set_message(s.toStdString());
|
||||
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
||||
}
|
||||
|
||||
void Server_Room::sendRoomEvent(RoomEvent *event, bool sendToIsl)
|
||||
{
|
||||
usersLock.lockForRead();
|
||||
{
|
||||
QMapIterator<QString, Server_ProtocolHandler *> userIterator(users);
|
||||
while (userIterator.hasNext())
|
||||
userIterator.next().value()->sendProtocolItem(*event);
|
||||
}
|
||||
usersLock.unlock();
|
||||
|
||||
if (sendToIsl)
|
||||
static_cast<Server *>(parent())->sendIsl_RoomEvent(*event);
|
||||
|
||||
delete event;
|
||||
usersLock.lockForRead();
|
||||
{
|
||||
QMapIterator<QString, Server_ProtocolHandler *> userIterator(users);
|
||||
while (userIterator.hasNext())
|
||||
userIterator.next().value()->sendProtocolItem(*event);
|
||||
}
|
||||
usersLock.unlock();
|
||||
|
||||
if (sendToIsl)
|
||||
static_cast<Server *>(parent())->sendIsl_RoomEvent(*event);
|
||||
|
||||
delete event;
|
||||
}
|
||||
|
||||
void Server_Room::broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl)
|
||||
{
|
||||
Event_ListGames event;
|
||||
event.add_game_list()->CopyFrom(gameInfo);
|
||||
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
||||
Event_ListGames event;
|
||||
event.add_game_list()->CopyFrom(gameInfo);
|
||||
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
||||
}
|
||||
|
||||
void Server_Room::addGame(Server_Game *game)
|
||||
{
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
gamesLock.lockForWrite();
|
||||
connect(game, SIGNAL(gameInfoChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)));
|
||||
|
||||
game->gameMutex.lock();
|
||||
games.insert(game->getGameId(), game);
|
||||
ServerInfo_Game gameInfo;
|
||||
game->getInfo(gameInfo);
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
game->gameMutex.unlock();
|
||||
gamesLock.unlock();
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
usersLock.lockForRead();
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
// -----------
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
gamesLock.lockForWrite();
|
||||
connect(game, SIGNAL(gameInfoChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)));
|
||||
|
||||
game->gameMutex.lock();
|
||||
games.insert(game->getGameId(), game);
|
||||
ServerInfo_Game gameInfo;
|
||||
game->getInfo(gameInfo);
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
game->gameMutex.unlock();
|
||||
gamesLock.unlock();
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
usersLock.lockForRead();
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
// -----------
|
||||
|
||||
emit gameListChanged(gameInfo);
|
||||
emit roomInfoChanged(roomInfo);
|
||||
emit gameListChanged(gameInfo);
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
void Server_Room::removeGame(Server_Game *game)
|
||||
{
|
||||
// No need to lock gamesLock or gameMutex. This method is only
|
||||
// called from ~Server_Game, which locks both mutexes anyway beforehand.
|
||||
|
||||
disconnect(game, 0, this, 0);
|
||||
|
||||
ServerInfo_Game gameInfo;
|
||||
game->getInfo(gameInfo);
|
||||
emit gameListChanged(gameInfo);
|
||||
|
||||
games.remove(game->getGameId());
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
usersLock.lockForRead();
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
// -----------
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
// No need to lock gamesLock or gameMutex. This method is only
|
||||
// called from ~Server_Game, which locks both mutexes anyway beforehand.
|
||||
|
||||
disconnect(game, 0, this, 0);
|
||||
|
||||
ServerInfo_Game gameInfo;
|
||||
game->getInfo(gameInfo);
|
||||
emit gameListChanged(gameInfo);
|
||||
|
||||
games.remove(game->getGameId());
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
usersLock.lockForRead();
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
// -----------
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
int Server_Room::getGamesCreatedByUser(const QString &userName) const
|
||||
{
|
||||
QReadLocker locker(&gamesLock);
|
||||
|
||||
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||
int result = 0;
|
||||
while (gamesIterator.hasNext())
|
||||
if (gamesIterator.next().value()->getCreatorInfo()->name() == userName.toStdString())
|
||||
++result;
|
||||
return result;
|
||||
QReadLocker locker(&gamesLock);
|
||||
|
||||
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||
int result = 0;
|
||||
while (gamesIterator.hasNext())
|
||||
if (gamesIterator.next().value()->getCreatorInfo()->name() == userName.toStdString())
|
||||
++result;
|
||||
return result;
|
||||
}
|
||||
|
||||
QList<ServerInfo_Game> Server_Room::getGamesOfUser(const QString &userName) const
|
||||
{
|
||||
QReadLocker locker(&gamesLock);
|
||||
|
||||
QList<ServerInfo_Game> result;
|
||||
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||
while (gamesIterator.hasNext()) {
|
||||
Server_Game *game = gamesIterator.next().value();
|
||||
if (game->containsUser(userName)) {
|
||||
ServerInfo_Game gameInfo;
|
||||
game->getInfo(gameInfo);
|
||||
result.append(gameInfo);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
QReadLocker locker(&gamesLock);
|
||||
|
||||
QList<ServerInfo_Game> result;
|
||||
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||
while (gamesIterator.hasNext()) {
|
||||
Server_Game *game = gamesIterator.next().value();
|
||||
if (game->containsUser(userName)) {
|
||||
ServerInfo_Game gameInfo;
|
||||
game->getInfo(gameInfo);
|
||||
result.append(gameInfo);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -24,58 +24,58 @@ class ResponseContainer;
|
|||
class Server_AbstractUserInterface;
|
||||
|
||||
class Server_Room : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void roomInfoChanged(const ServerInfo_Room &roomInfo);
|
||||
void gameListChanged(const ServerInfo_Game &gameInfo);
|
||||
void roomInfoChanged(const ServerInfo_Room &roomInfo);
|
||||
void gameListChanged(const ServerInfo_Game &gameInfo);
|
||||
private:
|
||||
int id;
|
||||
QString name;
|
||||
QString description;
|
||||
bool autoJoin;
|
||||
QString joinMessage;
|
||||
QStringList gameTypes;
|
||||
QMap<int, Server_Game *> games;
|
||||
QMap<int, ServerInfo_Game> externalGames;
|
||||
QMap<QString, Server_ProtocolHandler *> users;
|
||||
QMap<QString, ServerInfo_User_Container> externalUsers;
|
||||
int id;
|
||||
QString name;
|
||||
QString description;
|
||||
bool autoJoin;
|
||||
QString joinMessage;
|
||||
QStringList gameTypes;
|
||||
QMap<int, Server_Game *> games;
|
||||
QMap<int, ServerInfo_Game> externalGames;
|
||||
QMap<QString, Server_ProtocolHandler *> users;
|
||||
QMap<QString, ServerInfo_User_Container> externalUsers;
|
||||
private slots:
|
||||
void broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl = true);
|
||||
void broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl = true);
|
||||
public:
|
||||
mutable QReadWriteLock usersLock;
|
||||
mutable QReadWriteLock gamesLock;
|
||||
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
|
||||
~Server_Room();
|
||||
int getId() const { return id; }
|
||||
QString getName() const { return name; }
|
||||
QString getDescription() const { return description; }
|
||||
bool getAutoJoin() const { return autoJoin; }
|
||||
QString getJoinMessage() const { return joinMessage; }
|
||||
const QStringList &getGameTypes() const { return gameTypes; }
|
||||
const QMap<int, Server_Game *> &getGames() const { return games; }
|
||||
const QMap<int, ServerInfo_Game> &getExternalGames() const { return externalGames; }
|
||||
Server *getServer() const;
|
||||
const ServerInfo_Room &getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes = false, bool includeExternalData = true) const;
|
||||
int getGamesCreatedByUser(const QString &name) const;
|
||||
QList<ServerInfo_Game> getGamesOfUser(const QString &name) const;
|
||||
|
||||
void addClient(Server_ProtocolHandler *client);
|
||||
void removeClient(Server_ProtocolHandler *client);
|
||||
|
||||
void addExternalUser(const ServerInfo_User &userInfo);
|
||||
void removeExternalUser(const QString &name);
|
||||
const QMap<QString, ServerInfo_User_Container> &getExternalUsers() const { return externalUsers; }
|
||||
void updateExternalGameList(const ServerInfo_Game &gameInfo);
|
||||
|
||||
Response::ResponseCode processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface);
|
||||
|
||||
void say(const QString &userName, const QString &s, bool sendToIsl = true);
|
||||
|
||||
void addGame(Server_Game *game);
|
||||
void removeGame(Server_Game *game);
|
||||
|
||||
void sendRoomEvent(RoomEvent *event, bool sendToIsl = true);
|
||||
RoomEvent *prepareRoomEvent(const ::google::protobuf::Message &roomEvent);
|
||||
mutable QReadWriteLock usersLock;
|
||||
mutable QReadWriteLock gamesLock;
|
||||
Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent);
|
||||
~Server_Room();
|
||||
int getId() const { return id; }
|
||||
QString getName() const { return name; }
|
||||
QString getDescription() const { return description; }
|
||||
bool getAutoJoin() const { return autoJoin; }
|
||||
QString getJoinMessage() const { return joinMessage; }
|
||||
const QStringList &getGameTypes() const { return gameTypes; }
|
||||
const QMap<int, Server_Game *> &getGames() const { return games; }
|
||||
const QMap<int, ServerInfo_Game> &getExternalGames() const { return externalGames; }
|
||||
Server *getServer() const;
|
||||
const ServerInfo_Room &getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes = false, bool includeExternalData = true) const;
|
||||
int getGamesCreatedByUser(const QString &name) const;
|
||||
QList<ServerInfo_Game> getGamesOfUser(const QString &name) const;
|
||||
|
||||
void addClient(Server_ProtocolHandler *client);
|
||||
void removeClient(Server_ProtocolHandler *client);
|
||||
|
||||
void addExternalUser(const ServerInfo_User &userInfo);
|
||||
void removeExternalUser(const QString &name);
|
||||
const QMap<QString, ServerInfo_User_Container> &getExternalUsers() const { return externalUsers; }
|
||||
void updateExternalGameList(const ServerInfo_Game &gameInfo);
|
||||
|
||||
Response::ResponseCode processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface);
|
||||
|
||||
void say(const QString &userName, const QString &s, bool sendToIsl = true);
|
||||
|
||||
void addGame(Server_Game *game);
|
||||
void removeGame(Server_Game *game);
|
||||
|
||||
void sendRoomEvent(RoomEvent *event, bool sendToIsl = true);
|
||||
RoomEvent *prepareRoomEvent(const ::google::protobuf::Message &roomEvent);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,46 +7,46 @@ ServerInfo_User_Container::ServerInfo_User_Container(ServerInfo_User *_userInfo)
|
|||
}
|
||||
|
||||
ServerInfo_User_Container::ServerInfo_User_Container(const ServerInfo_User &_userInfo)
|
||||
: userInfo(new ServerInfo_User(_userInfo))
|
||||
: userInfo(new ServerInfo_User(_userInfo))
|
||||
{
|
||||
}
|
||||
|
||||
ServerInfo_User_Container::ServerInfo_User_Container(const ServerInfo_User_Container &other)
|
||||
{
|
||||
if (other.userInfo)
|
||||
userInfo = new ServerInfo_User(*other.userInfo);
|
||||
else
|
||||
userInfo = 0;
|
||||
if (other.userInfo)
|
||||
userInfo = new ServerInfo_User(*other.userInfo);
|
||||
else
|
||||
userInfo = 0;
|
||||
}
|
||||
|
||||
ServerInfo_User_Container::~ServerInfo_User_Container()
|
||||
{
|
||||
delete userInfo;
|
||||
delete userInfo;
|
||||
}
|
||||
|
||||
void ServerInfo_User_Container::setUserInfo(const ServerInfo_User &_userInfo)
|
||||
{
|
||||
userInfo = new ServerInfo_User(_userInfo);
|
||||
userInfo = new ServerInfo_User(_userInfo);
|
||||
}
|
||||
|
||||
ServerInfo_User &ServerInfo_User_Container::copyUserInfo(ServerInfo_User &result, bool complete, bool internalInfo, bool sessionInfo) const
|
||||
{
|
||||
if (userInfo) {
|
||||
result.CopyFrom(*userInfo);
|
||||
if (!sessionInfo) {
|
||||
result.clear_session_id();
|
||||
result.clear_address();
|
||||
}
|
||||
if (!internalInfo)
|
||||
result.clear_id();
|
||||
if (!complete)
|
||||
result.clear_avatar_bmp();
|
||||
}
|
||||
return result;
|
||||
if (userInfo) {
|
||||
result.CopyFrom(*userInfo);
|
||||
if (!sessionInfo) {
|
||||
result.clear_session_id();
|
||||
result.clear_address();
|
||||
}
|
||||
if (!internalInfo)
|
||||
result.clear_id();
|
||||
if (!complete)
|
||||
result.clear_avatar_bmp();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ServerInfo_User ServerInfo_User_Container::copyUserInfo(bool complete, bool internalInfo, bool sessionInfo) const
|
||||
{
|
||||
ServerInfo_User result;
|
||||
return copyUserInfo(result, complete, internalInfo, sessionInfo);
|
||||
ServerInfo_User result;
|
||||
return copyUserInfo(result, complete, internalInfo, sessionInfo);
|
||||
}
|
||||
|
|
|
@ -5,16 +5,16 @@ class ServerInfo_User;
|
|||
|
||||
class ServerInfo_User_Container {
|
||||
protected:
|
||||
ServerInfo_User *userInfo;
|
||||
ServerInfo_User *userInfo;
|
||||
public:
|
||||
ServerInfo_User_Container(ServerInfo_User *_userInfo = 0);
|
||||
ServerInfo_User_Container(const ServerInfo_User &_userInfo);
|
||||
ServerInfo_User_Container(const ServerInfo_User_Container &other);
|
||||
virtual ~ServerInfo_User_Container();
|
||||
ServerInfo_User *getUserInfo() const { return userInfo; }
|
||||
void setUserInfo(const ServerInfo_User &_userInfo);
|
||||
ServerInfo_User ©UserInfo(ServerInfo_User &result, bool complete, bool internalInfo = false, bool sessionInfo = false) const;
|
||||
ServerInfo_User copyUserInfo(bool complete, bool internalInfo = false, bool sessionInfo = false) const;
|
||||
ServerInfo_User_Container(ServerInfo_User *_userInfo = 0);
|
||||
ServerInfo_User_Container(const ServerInfo_User &_userInfo);
|
||||
ServerInfo_User_Container(const ServerInfo_User_Container &other);
|
||||
virtual ~ServerInfo_User_Container();
|
||||
ServerInfo_User *getUserInfo() const { return userInfo; }
|
||||
void setUserInfo(const ServerInfo_User &_userInfo);
|
||||
ServerInfo_User ©UserInfo(ServerInfo_User &result, bool complete, bool internalInfo = false, bool sessionInfo = false) const;
|
||||
ServerInfo_User copyUserInfo(bool complete, bool internalInfo = false, bool sessionInfo = false) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,21 +16,77 @@ SET(oracle_SOURCES
|
|||
../cockatrice/src/qt-json/json.cpp
|
||||
)
|
||||
|
||||
SET(QT_USE_QTNETWORK TRUE)
|
||||
SET(QT_USE_QTXML TRUE)
|
||||
SET(QT_USE_QTSVG TRUE)
|
||||
set(ORACLE_LIBS)
|
||||
|
||||
# Qt4 stuff
|
||||
if(Qt4_FOUND)
|
||||
SET(QT_USE_QTNETWORK TRUE)
|
||||
SET(QT_USE_QTXML TRUE)
|
||||
SET(QT_USE_QTSVG TRUE)
|
||||
|
||||
# Include directories
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
include_directories(${QT_INCLUDES})
|
||||
LIST(APPEND ORACLE_LIBS ${QT_QTMAIN_LIBRARY})
|
||||
LIST(APPEND ORACLE_LIBS ${QT_LIBRARIES})
|
||||
endif()
|
||||
|
||||
# qt5 stuff
|
||||
if(Qt5Widgets_FOUND)
|
||||
include_directories(${Qt5Widgets_INCLUDE_DIRS})
|
||||
list(APPEND ORACLE_LIBS Widgets)
|
||||
|
||||
# QtConcurrent
|
||||
find_package(Qt5Concurrent)
|
||||
if(Qt5Concurrent_FOUND)
|
||||
include_directories(${Qt5Concurrent_INCLUDE_DIRS})
|
||||
list(APPEND ORACLE_LIBS Concurrent)
|
||||
endif()
|
||||
|
||||
# QtNetwork
|
||||
find_package(Qt5Network)
|
||||
if(Qt5Network_FOUND)
|
||||
include_directories(${Qt5Network_INCLUDE_DIRS})
|
||||
list(APPEND ORACLE_LIBS Network)
|
||||
endif()
|
||||
|
||||
# QtXml
|
||||
find_package(Qt5Xml)
|
||||
if(Qt5Xml_FOUND)
|
||||
include_directories(${Qt5Xml_INCLUDE_DIRS})
|
||||
list(APPEND ORACLE_LIBS Xml)
|
||||
endif()
|
||||
|
||||
# QtSvg
|
||||
find_package(Qt5Svg)
|
||||
if(Qt5Svg_FOUND)
|
||||
include_directories(${Qt5Svg_INCLUDE_DIRS})
|
||||
list(APPEND ORACLE_LIBS Svg)
|
||||
endif()
|
||||
|
||||
# guess plugins and libraries directory
|
||||
set(QT_PLUGINS_DIR "${Qt5Widgets_DIR}/../../../plugins")
|
||||
get_target_property(QT_LIBRARY_DIR Qt5::Core LOCATION)
|
||||
get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH)
|
||||
endif()
|
||||
|
||||
# Include directories
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
INCLUDE_DIRECTORIES(../cockatrice/src)
|
||||
|
||||
# Build oracle binary and link it
|
||||
ADD_EXECUTABLE(oracle WIN32 MACOSX_BUNDLE ${oracle_SOURCES} ${oracle_MOC_SRCS})
|
||||
TARGET_LINK_LIBRARIES(oracle ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES})
|
||||
|
||||
if(MSVC)
|
||||
set_target_properties(oracle PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
|
||||
endif(MSVC)
|
||||
if(Qt4_FOUND)
|
||||
if(MSVC)
|
||||
set(QT_USE_QTMAIN true)
|
||||
endif()
|
||||
TARGET_LINK_LIBRARIES(oracle ${ORACLE_LIBS})
|
||||
endif()
|
||||
if(Qt5Widgets_FOUND)
|
||||
if(MSVC)
|
||||
TARGET_LINK_LIBRARIES(oracle Qt5::WinMain)
|
||||
endif()
|
||||
qt5_use_modules(oracle ${ORACLE_LIBS})
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
if(APPLE)
|
||||
|
@ -78,3 +134,35 @@ Translations = Resources/translations\")
|
|||
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/oracle.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
|
||||
" COMPONENT Runtime)
|
||||
endif()
|
||||
|
||||
IF(WIN32)
|
||||
# these needs to be relative to CMAKE_INSTALL_PREFIX
|
||||
set(plugin_dest_dir Plugins)
|
||||
set(qtconf_dest_dir .)
|
||||
|
||||
# note: no codecs in qt5
|
||||
# note: phonon_backend => mediaservice
|
||||
# note: needs platform on osx
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
|
||||
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*d\\.dll")
|
||||
else()
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
|
||||
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*[^d]\\.dll")
|
||||
endif()
|
||||
|
||||
install(CODE "
|
||||
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
|
||||
Plugins = Plugins
|
||||
Translations = Resources/translations\")
|
||||
" COMPONENT Runtime)
|
||||
|
||||
install(CODE "
|
||||
file(GLOB_RECURSE QTPLUGINS
|
||||
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dll\")
|
||||
set(BU_CHMOD_BUNDLE_ITEMS ON)
|
||||
include(BundleUtilities)
|
||||
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/oracle.exe\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
|
||||
" COMPONENT Runtime)
|
||||
endif()
|
|
@ -8,9 +8,12 @@ SettingsCache *settingsCache;
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
// gone in Qt5, all source files _MUST_ be utf8-encoded
|
||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||
|
||||
#endif
|
||||
|
||||
QCoreApplication::setOrganizationName("Cockatrice");
|
||||
QCoreApplication::setOrganizationDomain("cockatrice");
|
||||
// this can't be changed, as it influences the default savepath for cards.xml
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#include "oracleimporter.h"
|
||||
#include <QtGui>
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <QtGui>
|
||||
#else
|
||||
#include <QtWidgets>
|
||||
#endif
|
||||
#include <QDebug>
|
||||
|
||||
#include "qt-json/json.h"
|
||||
|
|
|
@ -1,8 +1,25 @@
|
|||
#include <QtGui>
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <QDesktopServices>
|
||||
#else
|
||||
#include <QStandardPaths>
|
||||
#include <QtConcurrent>
|
||||
#endif
|
||||
#include <QAbstractButton>
|
||||
#include <QCheckBox>
|
||||
#include <QFileDialog>
|
||||
#include <QGridLayout>
|
||||
#include <QDesktopServices>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QProgressBar>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QScrollArea>
|
||||
#include <QScrollBar>
|
||||
#include <QTextEdit>
|
||||
|
||||
#include "oraclewizard.h"
|
||||
#include "oracleimporter.h"
|
||||
|
@ -13,7 +30,14 @@ OracleWizard::OracleWizard(QWidget *parent)
|
|||
: QWizard(parent)
|
||||
{
|
||||
settings = new QSettings(this);
|
||||
importer = new OracleImporter(QDesktopServices::storageLocation(QDesktopServices::DataLocation), this);
|
||||
|
||||
importer = new OracleImporter(
|
||||
#if QT_VERSION < 0x050000
|
||||
QDesktopServices::storageLocation(QDesktopServices::DataLocation)
|
||||
#else
|
||||
QStandardPaths::standardLocations(QStandardPaths::DataLocation).first()
|
||||
#endif
|
||||
, this);
|
||||
|
||||
addPage(new IntroPage);
|
||||
addPage(new LoadSetsPage);
|
||||
|
@ -372,7 +396,12 @@ void SaveSetsPage::updateTotalProgress(int cardsImported, int setIndex, const QS
|
|||
bool SaveSetsPage::validatePage()
|
||||
{
|
||||
bool ok = false;
|
||||
const QString dataDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||
const QString dataDir =
|
||||
#if QT_VERSION < 0x050000
|
||||
QDesktopServices::storageLocation(QDesktopServices::DataLocation);
|
||||
#else
|
||||
QStandardPaths::standardLocations(QStandardPaths::DataLocation).first();
|
||||
#endif
|
||||
QDir dir(dataDir);
|
||||
if (!dir.exists())
|
||||
dir.mkpath(dataDir);
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
PROJECT(servatrice)
|
||||
|
||||
# cmake module for libgcrypt is included in current directory
|
||||
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
FIND_PACKAGE(Libgcrypt REQUIRED)
|
||||
|
||||
SET(servatrice_SOURCES
|
||||
|
@ -17,15 +15,50 @@ SET(servatrice_SOURCES
|
|||
src/server_logger.cpp
|
||||
src/serversocketinterface.cpp
|
||||
src/isl_interface.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp
|
||||
${VERSION_STRING_CPP}
|
||||
)
|
||||
|
||||
SET(QT_DONTUSE_QTGUI)
|
||||
SET(QT_USE_QTNETWORK TRUE)
|
||||
SET(QT_USE_QTSQL TRUE)
|
||||
set(SERVATRICE_LIBS)
|
||||
|
||||
# Qt4 stuff
|
||||
if(Qt4_FOUND)
|
||||
SET(QT_USE_QTNETWORK TRUE)
|
||||
SET(QT_USE_QTSQL TRUE)
|
||||
|
||||
# Include directories
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
include_directories(${QT_INCLUDES})
|
||||
LIST(APPEND SERVATRICE_LIBS ${QT_LIBRARIES})
|
||||
endif()
|
||||
|
||||
# qt5 stuff
|
||||
if(Qt5Widgets_FOUND)
|
||||
include_directories(${Qt5Widgets_INCLUDE_DIRS})
|
||||
list(APPEND SERVATRICE_LIBS Widgets)
|
||||
|
||||
# QtNetwork
|
||||
find_package(Qt5Network)
|
||||
if(Qt5Network_FOUND)
|
||||
include_directories(${Qt5Network_INCLUDE_DIRS})
|
||||
list(APPEND SERVATRICE_LIBS Network)
|
||||
endif()
|
||||
|
||||
# QtSql
|
||||
find_package(Qt5Sql)
|
||||
if(Qt5Sql_FOUND)
|
||||
include_directories(${Qt5Sql_INCLUDE_DIRS})
|
||||
list(APPEND SERVATRICE_LIBS Sql)
|
||||
endif()
|
||||
|
||||
# guess plugins and libraries directory
|
||||
set(QT_PLUGINS_DIR "${Qt5Widgets_DIR}/../../../plugins")
|
||||
get_target_property(QT_LIBRARY_DIR Qt5::Core LOCATION)
|
||||
get_filename_component(QT_LIBRARY_DIR ${QT_LIBRARY_DIR} PATH)
|
||||
endif()
|
||||
|
||||
SET(QT_DONT_USE_QTGUI TRUE)
|
||||
|
||||
# Include directories
|
||||
INCLUDE(${QT_USE_FILE})
|
||||
INCLUDE_DIRECTORIES(../common)
|
||||
INCLUDE_DIRECTORIES(${LIBGCRYPT_INCLUDE_DIR})
|
||||
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
|
||||
|
@ -34,13 +67,21 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
|
|||
|
||||
# Build servatrice binary and link it
|
||||
ADD_EXECUTABLE(servatrice MACOSX_BUNDLE ${servatrice_SOURCES} ${servatrice_MOC_SRCS})
|
||||
TARGET_LINK_LIBRARIES(servatrice cockatrice_common ${QT_LIBRARIES} ${LIBGCRYPT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
#add_custom_target(versionheader ALL DEPENDS version_header)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version_string.h ${CMAKE_CURRENT_BINARY_DIR}/version_string.cpp
|
||||
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/../common/getversion.cmake
|
||||
)
|
||||
if(Qt4_FOUND)
|
||||
if(MSVC)
|
||||
set(QT_USE_QTMAIN true)
|
||||
endif()
|
||||
TARGET_LINK_LIBRARIES(servatrice cockatrice_common ${SERVATRICE_LIBS} ${LIBGCRYPT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
if(Qt5Widgets_FOUND)
|
||||
if(MSVC)
|
||||
TARGET_LINK_LIBRARIES(servatrice cockatrice_common ${LIBGCRYPT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} Qt5::WinMain)
|
||||
else()
|
||||
TARGET_LINK_LIBRARIES(servatrice cockatrice_common ${LIBGCRYPT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
qt5_use_modules(servatrice ${SERVATRICE_LIBS})
|
||||
endif()
|
||||
|
||||
# install rules
|
||||
if(UNIX)
|
||||
|
@ -85,3 +126,35 @@ Translations = Resources/translations\")
|
|||
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/servatrice.app\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
|
||||
" COMPONENT Runtime)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
# these needs to be relative to CMAKE_INSTALL_PREFIX
|
||||
set(plugin_dest_dir Plugins)
|
||||
set(qtconf_dest_dir .)
|
||||
|
||||
# note: no codecs in qt5
|
||||
# note: phonon_backend => mediaservice
|
||||
# note: needs platform on osx
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
|
||||
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*d\\.dll")
|
||||
else()
|
||||
install(DIRECTORY "${QT_PLUGINS_DIR}/" DESTINATION ${plugin_dest_dir} COMPONENT Runtime
|
||||
FILES_MATCHING REGEX "(codecs|iconengines|imageformats|mediaservice|phonon_backend|platforms)/.*[^d]\\.dll")
|
||||
endif()
|
||||
|
||||
install(CODE "
|
||||
file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${qtconf_dest_dir}/qt.conf\" \"[Paths]
|
||||
Plugins = Plugins
|
||||
Translations = Resources/translations\")
|
||||
" COMPONENT Runtime)
|
||||
|
||||
install(CODE "
|
||||
file(GLOB_RECURSE QTPLUGINS
|
||||
\"\${CMAKE_INSTALL_PREFIX}/${plugin_dest_dir}/*.dll\")
|
||||
set(BU_CHMOD_BUNDLE_ITEMS ON)
|
||||
include(BundleUtilities)
|
||||
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/servatrice.exe\" \"\${QTPLUGINS}\" \"${QT_LIBRARY_DIR}\")
|
||||
" COMPONENT Runtime)
|
||||
endif()
|
3
servatrice/scripts/maint_replays
Normal file
3
servatrice/scripts/maint_replays
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
# SCHEDULE WITH CRONTAB BASED ON TIME PERIOD REPLAYS SHOULD BE SAVED UNTIL (EX: SCHEDULE ONCE A WEEK TO KEEP A WEEKS WORTH OF REPLAYS IN THE DB)
|
||||
mysql --defaults-file=./mysql.cnf -h localhost -e 'truncate table servatrice.cockatrice_replays;truncate table servatrice.cockatrice_replays_access'
|
3
servatrice/scripts/maint_sessions
Normal file
3
servatrice/scripts/maint_sessions
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
# SCHEDULE WITH CRONTAB TO RUN ONCE A MONTH
|
||||
mysql --defaults-file=./mysql.cnf -h localhost -e "delete from servatrice.cockatrice_sessions where start_time < DATE_SUB(now(), INTERVAL 1 MONTH)"
|
3
servatrice/scripts/mysql.cnf.example
Normal file
3
servatrice/scripts/mysql.cnf.example
Normal file
|
@ -0,0 +1,3 @@
|
|||
[client]
|
||||
user={db_username}
|
||||
password={db_password}
|
|
@ -82,6 +82,7 @@ void testHash()
|
|||
std::cerr << startTime.secsTo(endTime) << "secs" << std::endl;
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
void myMessageOutput(QtMsgType /*type*/, const char *msg)
|
||||
{
|
||||
logger->logMessage(msg);
|
||||
|
@ -92,6 +93,18 @@ void myMessageOutput2(QtMsgType /*type*/, const char *msg)
|
|||
logger->logMessage(msg);
|
||||
std::cerr << msg << std::endl;
|
||||
}
|
||||
#else
|
||||
void myMessageOutput(QtMsgType /*type*/, const QMessageLogContext &, const QString &msg)
|
||||
{
|
||||
logger->logMessage(msg);
|
||||
}
|
||||
|
||||
void myMessageOutput2(QtMsgType /*type*/, const QMessageLogContext &, const QString &msg)
|
||||
{
|
||||
logger->logMessage(msg);
|
||||
std::cerr << msg.toStdString() << std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
void sigSegvHandler(int sig)
|
||||
|
@ -121,9 +134,12 @@ int main(int argc, char *argv[])
|
|||
bool logToConsole = args.contains("--log-to-console");
|
||||
|
||||
qRegisterMetaType<QList<int> >("QList<int>");
|
||||
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
// gone in Qt5, all source files _MUST_ be utf8-encoded
|
||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||
|
||||
#endif
|
||||
|
||||
QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat);
|
||||
|
||||
loggerThread = new QThread;
|
||||
|
@ -133,11 +149,19 @@ int main(int argc, char *argv[])
|
|||
|
||||
loggerThread->start();
|
||||
QMetaObject::invokeMethod(logger, "startLog", Qt::BlockingQueuedConnection, Q_ARG(QString, settings->value("server/logfile").toString()));
|
||||
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
if (logToConsole)
|
||||
qInstallMsgHandler(myMessageOutput);
|
||||
else
|
||||
qInstallMsgHandler(myMessageOutput2);
|
||||
#else
|
||||
if (logToConsole)
|
||||
qInstallMessageHandler(myMessageOutput);
|
||||
else
|
||||
qInstallMessageHandler(myMessageOutput2);
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
struct sigaction hup;
|
||||
hup.sa_handler = ServerLogger::hupSignalHandler;
|
||||
|
@ -173,8 +197,12 @@ int main(int argc, char *argv[])
|
|||
if (server->initServer()) {
|
||||
std::cerr << "-------------------------" << std::endl;
|
||||
std::cerr << "Server initialized." << std::endl;
|
||||
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
qInstallMsgHandler(myMessageOutput);
|
||||
#else
|
||||
qInstallMessageHandler(myMessageOutput);
|
||||
#endif
|
||||
retval = app.exec();
|
||||
|
||||
std::cerr << "Server quit." << std::endl;
|
||||
|
|
|
@ -16,7 +16,7 @@ QString PasswordHasher::computeHash(const QString &password, const QString &salt
|
|||
const int algo = GCRY_MD_SHA512;
|
||||
const int rounds = 1000;
|
||||
|
||||
QByteArray passwordBuffer = (salt + password).toAscii();
|
||||
QByteArray passwordBuffer = (salt + password).toUtf8();
|
||||
int hashLen = gcry_md_get_algo_dlen(algo);
|
||||
char hash[hashLen], tmp[hashLen];
|
||||
gcry_md_hash_buffer(algo, hash, passwordBuffer.data(), passwordBuffer.size());
|
||||
|
|
|
@ -78,7 +78,11 @@ Servatrice_GameServer::~Servatrice_GameServer()
|
|||
}
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
void Servatrice_GameServer::incomingConnection(int socketDescriptor)
|
||||
#else
|
||||
void Servatrice_GameServer::incomingConnection(qintptr socketDescriptor)
|
||||
#endif
|
||||
{
|
||||
// Determine connection pool with smallest client count
|
||||
int minClientCount = -1;
|
||||
|
@ -231,82 +235,90 @@ bool Servatrice::initServer()
|
|||
maxMessageSizePerInterval = settings->value("security/max_message_size_per_interval").toInt();
|
||||
maxGamesPerUser = settings->value("security/max_games_per_user").toInt();
|
||||
|
||||
try { if (settings->value("servernetwork/active", 0).toInt()) {
|
||||
qDebug() << "Connecting to ISL network.";
|
||||
const QString certFileName = settings->value("servernetwork/ssl_cert").toString();
|
||||
const QString keyFileName = settings->value("servernetwork/ssl_key").toString();
|
||||
qDebug() << "Loading certificate...";
|
||||
QFile certFile(certFileName);
|
||||
if (!certFile.open(QIODevice::ReadOnly))
|
||||
throw QString("Error opening certificate file: %1").arg(certFileName);
|
||||
QSslCertificate cert(&certFile);
|
||||
if (!cert.isValid())
|
||||
throw(QString("Invalid certificate."));
|
||||
qDebug() << "Loading private key...";
|
||||
QFile keyFile(keyFileName);
|
||||
if (!keyFile.open(QIODevice::ReadOnly))
|
||||
throw QString("Error opening private key file: %1").arg(keyFileName);
|
||||
QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
|
||||
if (key.isNull())
|
||||
throw QString("Invalid private key.");
|
||||
|
||||
QMutableListIterator<ServerProperties> serverIterator(serverList);
|
||||
while (serverIterator.hasNext()) {
|
||||
const ServerProperties &prop = serverIterator.next();
|
||||
if (prop.cert == cert) {
|
||||
serverIterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
QThread *thread = new QThread;
|
||||
thread->setObjectName("isl_" + QString::number(prop.id));
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
|
||||
IslInterface *interface = new IslInterface(prop.id, prop.hostname, prop.address.toString(), prop.controlPort, prop.cert, cert, key, this);
|
||||
interface->moveToThread(thread);
|
||||
connect(interface, SIGNAL(destroyed()), thread, SLOT(quit()));
|
||||
|
||||
thread->start();
|
||||
QMetaObject::invokeMethod(interface, "initClient", Qt::BlockingQueuedConnection);
|
||||
}
|
||||
|
||||
const int networkPort = settings->value("servernetwork/port", 14747).toInt();
|
||||
qDebug() << "Starting ISL server on port" << networkPort;
|
||||
|
||||
islServer = new Servatrice_IslServer(this, cert, key, this);
|
||||
if (islServer->listen(QHostAddress::Any, networkPort))
|
||||
qDebug() << "ISL server listening.";
|
||||
else
|
||||
throw QString("islServer->listen()");
|
||||
} } catch (QString error) {
|
||||
qDebug() << "ERROR --" << error;
|
||||
return false;
|
||||
}
|
||||
|
||||
pingClock = new QTimer(this);
|
||||
connect(pingClock, SIGNAL(timeout()), this, SIGNAL(pingClockTimeout()));
|
||||
pingClock->start(1000);
|
||||
|
||||
int statusUpdateTime = settings->value("server/statusupdate").toInt();
|
||||
statusUpdateClock = new QTimer(this);
|
||||
connect(statusUpdateClock, SIGNAL(timeout()), this, SLOT(statusUpdate()));
|
||||
if (statusUpdateTime != 0) {
|
||||
qDebug() << "Starting status update clock, interval " << statusUpdateTime << " ms";
|
||||
statusUpdateClock->start(statusUpdateTime);
|
||||
}
|
||||
|
||||
const int numberPools = settings->value("server/number_pools", 1).toInt();
|
||||
gameServer = new Servatrice_GameServer(this, numberPools, servatriceDatabaseInterface->getDatabase(), this);
|
||||
gameServer->setMaxPendingConnections(1000);
|
||||
const int gamePort = settings->value("server/port", 4747).toInt();
|
||||
qDebug() << "Starting server on port" << gamePort;
|
||||
if (gameServer->listen(QHostAddress::Any, gamePort))
|
||||
qDebug() << "Server listening.";
|
||||
else {
|
||||
qDebug() << "gameServer->listen(): Error.";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
try { if (settings->value("servernetwork/active", 0).toInt()) {
|
||||
qDebug() << "Connecting to ISL network.";
|
||||
const QString certFileName = settings->value("servernetwork/ssl_cert").toString();
|
||||
const QString keyFileName = settings->value("servernetwork/ssl_key").toString();
|
||||
qDebug() << "Loading certificate...";
|
||||
QFile certFile(certFileName);
|
||||
if (!certFile.open(QIODevice::ReadOnly))
|
||||
throw QString("Error opening certificate file: %1").arg(certFileName);
|
||||
QSslCertificate cert(&certFile);
|
||||
#if QT_VERSION < 0x050000
|
||||
if (!cert.isValid())
|
||||
throw(QString("Invalid certificate."));
|
||||
#else
|
||||
const QDateTime currentTime = QDateTime::currentDateTime();
|
||||
if(currentTime < cert.effectiveDate() ||
|
||||
currentTime > cert.expiryDate() ||
|
||||
cert.isBlacklisted())
|
||||
throw(QString("Invalid certificate."));
|
||||
#endif
|
||||
qDebug() << "Loading private key...";
|
||||
QFile keyFile(keyFileName);
|
||||
if (!keyFile.open(QIODevice::ReadOnly))
|
||||
throw QString("Error opening private key file: %1").arg(keyFileName);
|
||||
QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
|
||||
if (key.isNull())
|
||||
throw QString("Invalid private key.");
|
||||
|
||||
QMutableListIterator<ServerProperties> serverIterator(serverList);
|
||||
while (serverIterator.hasNext()) {
|
||||
const ServerProperties &prop = serverIterator.next();
|
||||
if (prop.cert == cert) {
|
||||
serverIterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
QThread *thread = new QThread;
|
||||
thread->setObjectName("isl_" + QString::number(prop.id));
|
||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||
|
||||
IslInterface *interface = new IslInterface(prop.id, prop.hostname, prop.address.toString(), prop.controlPort, prop.cert, cert, key, this);
|
||||
interface->moveToThread(thread);
|
||||
connect(interface, SIGNAL(destroyed()), thread, SLOT(quit()));
|
||||
|
||||
thread->start();
|
||||
QMetaObject::invokeMethod(interface, "initClient", Qt::BlockingQueuedConnection);
|
||||
}
|
||||
|
||||
const int networkPort = settings->value("servernetwork/port", 14747).toInt();
|
||||
qDebug() << "Starting ISL server on port" << networkPort;
|
||||
|
||||
islServer = new Servatrice_IslServer(this, cert, key, this);
|
||||
if (islServer->listen(QHostAddress::Any, networkPort))
|
||||
qDebug() << "ISL server listening.";
|
||||
else
|
||||
throw QString("islServer->listen()");
|
||||
} } catch (QString error) {
|
||||
qDebug() << "ERROR --" << error;
|
||||
return false;
|
||||
}
|
||||
|
||||
pingClock = new QTimer(this);
|
||||
connect(pingClock, SIGNAL(timeout()), this, SIGNAL(pingClockTimeout()));
|
||||
pingClock->start(1000);
|
||||
|
||||
int statusUpdateTime = settings->value("server/statusupdate").toInt();
|
||||
statusUpdateClock = new QTimer(this);
|
||||
connect(statusUpdateClock, SIGNAL(timeout()), this, SLOT(statusUpdate()));
|
||||
if (statusUpdateTime != 0) {
|
||||
qDebug() << "Starting status update clock, interval " << statusUpdateTime << " ms";
|
||||
statusUpdateClock->start(statusUpdateTime);
|
||||
}
|
||||
|
||||
const int numberPools = settings->value("server/number_pools", 1).toInt();
|
||||
gameServer = new Servatrice_GameServer(this, numberPools, servatriceDatabaseInterface->getDatabase(), this);
|
||||
gameServer->setMaxPendingConnections(1000);
|
||||
const int gamePort = settings->value("server/port", 4747).toInt();
|
||||
qDebug() << "Starting server on port" << gamePort;
|
||||
if (gameServer->listen(QHostAddress::Any, gamePort))
|
||||
qDebug() << "Server listening.";
|
||||
else {
|
||||
qDebug() << "gameServer->listen(): Error.";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Servatrice::addDatabaseInterface(QThread *thread, Servatrice_DatabaseInterface *databaseInterface)
|
||||
|
@ -316,21 +328,21 @@ void Servatrice::addDatabaseInterface(QThread *thread, Servatrice_DatabaseInterf
|
|||
|
||||
void Servatrice::updateServerList()
|
||||
{
|
||||
qDebug() << "Updating server list...";
|
||||
|
||||
serverListMutex.lock();
|
||||
serverList.clear();
|
||||
|
||||
QSqlQuery query(servatriceDatabaseInterface->getDatabase());
|
||||
query.prepare("select id, ssl_cert, hostname, address, game_port, control_port from " + dbPrefix + "_servers order by id asc");
|
||||
servatriceDatabaseInterface->execSqlQuery(query);
|
||||
while (query.next()) {
|
||||
ServerProperties prop(query.value(0).toInt(), QSslCertificate(query.value(1).toString().toAscii()), query.value(2).toString(), QHostAddress(query.value(3).toString()), query.value(4).toInt(), query.value(5).toInt());
|
||||
serverList.append(prop);
|
||||
qDebug() << QString("#%1 CERT=%2 NAME=%3 IP=%4:%5 CPORT=%6").arg(prop.id).arg(QString(prop.cert.digest().toHex())).arg(prop.hostname).arg(prop.address.toString()).arg(prop.gamePort).arg(prop.controlPort);
|
||||
}
|
||||
|
||||
serverListMutex.unlock();
|
||||
qDebug() << "Updating server list...";
|
||||
|
||||
serverListMutex.lock();
|
||||
serverList.clear();
|
||||
|
||||
QSqlQuery query(servatriceDatabaseInterface->getDatabase());
|
||||
query.prepare("select id, ssl_cert, hostname, address, game_port, control_port from " + dbPrefix + "_servers order by id asc");
|
||||
servatriceDatabaseInterface->execSqlQuery(query);
|
||||
while (query.next()) {
|
||||
ServerProperties prop(query.value(0).toInt(), QSslCertificate(query.value(1).toString().toUtf8()), query.value(2).toString(), QHostAddress(query.value(3).toString()), query.value(4).toInt(), query.value(5).toInt());
|
||||
serverList.append(prop);
|
||||
qDebug() << QString("#%1 CERT=%2 NAME=%3 IP=%4:%5 CPORT=%6").arg(prop.id).arg(QString(prop.cert.digest().toHex())).arg(prop.hostname).arg(prop.address.toString()).arg(prop.gamePort).arg(prop.controlPort);
|
||||
}
|
||||
|
||||
serverListMutex.unlock();
|
||||
}
|
||||
|
||||
QList<ServerProperties> Servatrice::getServerList() const
|
||||
|
|
|
@ -52,7 +52,11 @@ public:
|
|||
Servatrice_GameServer(Servatrice *_server, int _numberPools, const QSqlDatabase &_sqlDatabase, QObject *parent = 0);
|
||||
~Servatrice_GameServer();
|
||||
protected:
|
||||
#if QT_VERSION < 0x050000
|
||||
void incomingConnection(int socketDescriptor);
|
||||
#else
|
||||
void incomingConnection(qintptr socketDescriptor);
|
||||
#endif
|
||||
};
|
||||
|
||||
class Servatrice_IslServer : public QTcpServer {
|
||||
|
|
Loading…
Reference in a new issue