forked from mirror/openmw-tes3mp
Compare commits
No commits in common. '0.7.0' and 'openmw-39' have entirely different histories.
@ -1,16 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*.cpp]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
|
||||
[*.hpp]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
|
||||
[*.glsl]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = false
|
@ -1,69 +0,0 @@
|
||||
stages:
|
||||
- build
|
||||
|
||||
Debian:
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
image: gcc
|
||||
cache:
|
||||
key: apt-cache
|
||||
paths:
|
||||
- apt-cache/
|
||||
before_script:
|
||||
- export APT_CACHE_DIR=`pwd`/apt-cache && mkdir -pv $APT_CACHE_DIR
|
||||
- apt-get update -yq
|
||||
- apt-get -o dir::cache::archives="$APT_CACHE_DIR" install -y cmake libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev libsdl2-dev libqt4-dev libopenal-dev libopenscenegraph-3.4-dev libunshield-dev libtinyxml-dev
|
||||
# - apt-get install -y libmygui-dev libbullet-dev # to be updated to latest below because stretch is too old
|
||||
- curl http://ftp.us.debian.org/debian/pool/main/b/bullet/libbullet-dev_2.87+dfsg-2_amd64.deb -o libbullet-dev_2.87+dfsg-2_amd64.deb
|
||||
- curl http://ftp.us.debian.org/debian/pool/main/b/bullet/libbullet2.87_2.87+dfsg-2_amd64.deb -o libbullet2.87_2.87+dfsg-2_amd64.deb
|
||||
- curl http://ftp.us.debian.org/debian/pool/main/m/mygui/libmygui.openglplatform0debian1v5_3.2.2+dfsg-1_amd64.deb -o libmygui.openglplatform0debian1v5_3.2.2+dfsg-1_amd64.deb
|
||||
- curl http://ftp.us.debian.org/debian/pool/main/m/mygui/libmyguiengine3debian1v5_3.2.2+dfsg-1_amd64.deb -o libmyguiengine3debian1v5_3.2.2+dfsg-1_amd64.deb
|
||||
- curl http://ftp.us.debian.org/debian/pool/main/m/mygui/libmygui-dev_3.2.2+dfsg-1_amd64.deb -o libmygui-dev_3.2.2+dfsg-1_amd64.deb
|
||||
- dpkg --ignore-depends=libmygui.ogreplatform0debian1v5 -i *.deb
|
||||
stage: build
|
||||
script:
|
||||
- cores_to_use=$((`nproc`-2)); if (( $cores_to_use < 1 )); then cores_to_use=1; fi
|
||||
- mkdir build; cd build; cmake -DCMAKE_BUILD_TYPE=MinSizeRel ../
|
||||
- make -j$cores_to_use
|
||||
- DESTDIR=artifacts make install
|
||||
artifacts:
|
||||
paths:
|
||||
- build/artifacts/
|
||||
MacOS:
|
||||
tags:
|
||||
- macos
|
||||
- xcode
|
||||
except:
|
||||
- branches # because our CI VMs are not public, MRs can't use them and timeout
|
||||
stage: build
|
||||
allow_failure: true
|
||||
script:
|
||||
- rm -fr build/* # remove anything in the build directory
|
||||
- CI/before_install.osx.sh
|
||||
- CI/before_script.osx.sh
|
||||
- cd build; make -j2 package
|
||||
artifacts:
|
||||
paths:
|
||||
- build/OpenMW-*.dmg
|
||||
|
||||
Windows:
|
||||
tags:
|
||||
- win10
|
||||
- msvc2017
|
||||
except:
|
||||
- branches # because our CI VMs are not public, MRs can't use them and timeout
|
||||
stage: build
|
||||
allow_failure: true
|
||||
script:
|
||||
# - env # turn on for debugging
|
||||
- sh %CI_PROJECT_DIR%/CI/before_script.msvc.sh -c Release -p x64 -v 2017 -V
|
||||
- SET msBuildLocation="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe"
|
||||
- call %msBuildLocation% MSVC2017_64\OpenMW.sln /t:Build /p:Configuration=Release /m:%NUMBER_OF_PROCESSORS%
|
||||
- 7z a OpenMW_MSVC2017_64_%CI_BUILD_REF_NAME%_%CI_BUILD_ID%.zip %CI_PROJECT_DIR%\MSVC2017_64\Release\
|
||||
cache:
|
||||
paths:
|
||||
- deps
|
||||
artifacts:
|
||||
paths:
|
||||
- "*.zip"
|
@ -1,3 +0,0 @@
|
||||
[submodule "extern/breakpad"]
|
||||
path = extern/breakpad
|
||||
url = https://chromium.googlesource.com/breakpad/breakpad
|
@ -1,92 +1,59 @@
|
||||
os:
|
||||
- linux
|
||||
# - osx
|
||||
osx_image: xcode9.4
|
||||
- osx
|
||||
osx_image: xcode7.2
|
||||
language: cpp
|
||||
sudo: required
|
||||
dist: xenial
|
||||
dist: trusty
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- coverity_scan
|
||||
- /openmw-.*$/
|
||||
- /^[0-9]+\.[0-9]+\.[0-9]+.*$/
|
||||
env:
|
||||
global:
|
||||
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
|
||||
# via the "travis encrypt" command using the project repo's public key
|
||||
- secure: 1QK0yVyoOB+gf2I7XzvhXu9w/5lq4stBXIwJbVCTjz4Q4XVHCosURaW1MAgKzMrPnbFEwjyn5uQ8BwsvvfkuN1AZD0YXITgc7gyI+J1wQ/p/ljxRxglakU6WEgsTs2J5z9UmGac4YTXg+quK7YP3rv+zuGim2I2rhzImejyzp0Ym3kRCnNcy+SGBsiRaevRJMe00Ch8zGAbEhduQGeSoS6W0rcu02DNlQKiq5NktWsXR+TWWWVfIeIlQR/lbPsCd0pdxMaMv2QCY0rVbwrYxWJwr/Qe45dAdWp+8/C3PbXpeMSGxlLa33nJNX4Lf/djxbjm8KWk6edaXPajrjR/0iwcpwq0jg2Jt6XfEdnJt35F1gpXlc04sxStjG45uloOKCFYT0wdhIO1Lq+hDP54wypQl+JInd5qC001O7pwhVxO36EgKWqo8HD+BqGDBwsNj2engy9Qcp3wO6G0rLBPB3CrZsk9wrHVv5cSiQSLMhId3Xviu3ZI2qEDA+kgTvxrKrsnMj4bILVCyG5Ka2Mj22wIDW9e8oIab9oTdujax3DTN1GkD6QuOAGzwDsNwGASsgfoeZ+FUhgM75RlBWGMilgkmnF7EJ0oAXLEpjtABnEr2d4qHv+y08kOuTDBLB9ExzCIj024dYYYNLZrqPKx0ncHuCMG2QNj2aJAJEZtj1rQ=
|
||||
|
||||
- secure: "jybGzAdUbqt9vWR/GEnRd96BgAi/7Zd1+2HK68j/i/8+/1YH2XxLOy4Jv/DUBhBlJIkxs/Xv8dRcUlFOclZDHX1d/9Qnsqd3oUVkD7k1y7cTOWy9TBQaE/v/kZo3LpzA3xPwwthrb0BvqIbOfIELi5fS5s8ba85WFRg3AX70wWE="
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'ppa:openmw/openmw'
|
||||
- sourceline: 'ppa:rakhimov/boost'
|
||||
- ubuntu-toolchain-r-test
|
||||
packages: [
|
||||
# Dev
|
||||
cmake, clang-6.0, libunshield-dev, libtinyxml-dev,
|
||||
g++-8,
|
||||
# Tests
|
||||
libgtest-dev, google-mock,
|
||||
# Boost
|
||||
libboost-filesystem1.61-dev, libboost-program-options1.61-dev, libboost-system1.61-dev,
|
||||
# FFmpeg
|
||||
libavcodec-dev, libavformat-dev, libavutil-dev, libswscale-dev,
|
||||
# Audio & Video
|
||||
libsdl2-dev, qtbase5-dev, libopenal-dev,
|
||||
# The other ones from OpenMW ppa
|
||||
libbullet-dev, libswresample-dev, libopenscenegraph-3.4-dev, libmygui-dev,
|
||||
# tes3mp stuff
|
||||
libboost1.61-dev, libqt5opengl5-dev, libluajit-5.1-dev
|
||||
]
|
||||
|
||||
coverity_scan:
|
||||
project:
|
||||
name: "TES3MP/openmw-tes3mp"
|
||||
name: "OpenMW/openmw"
|
||||
description: "<Your project description here>"
|
||||
notification_email: koncord@tes3mp.com
|
||||
build_command_prepend: "cmake . -DBUILD_UNITTESTS=FALSE -DBUILD_OPENCS=FALSE -DBUILD_BSATOOL=FALSE -DBUILD_ESMTOOL=FALSE -DBUILD_MWINIIMPORTER=FALSE -DBUILD_LAUNCHER=FALSE"
|
||||
build_command: "make -j3"
|
||||
notification_email: scrawl@baseoftrash.de
|
||||
build_command_prepend: "cmake . -DBUILD_UNITTESTS=FALSE"
|
||||
build_command: "make -j2"
|
||||
branch_pattern: coverity_scan
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
env:
|
||||
- ANALYZE="scan-build-6.0 --use-cc clang-6.0 --use-c++ clang++-6.0 "
|
||||
- MATRIX_CC="CC=clang-6.0 && CXX=clang++-6.0"
|
||||
ANALYZE="scan-build-3.6 --use-cc clang-3.6 --use-c++ clang++-3.6 "
|
||||
compiler: clang
|
||||
- os: linux
|
||||
env:
|
||||
- MATRIX_CC="CC=gcc-8 && CXX=g++-8"
|
||||
- os: linux
|
||||
env:
|
||||
- MATRIX_CC="CC=clang-6.0 && CXX=clang++-6.0"
|
||||
allow_failures:
|
||||
- env:
|
||||
- MATRIX_CC="CC=clang-6.0 && CXX=clang++-6.0"
|
||||
- env:
|
||||
- ANALYZE="scan-build-6.0 --use-cc clang-6.0 --use-c++ clang++-6.0 "
|
||||
- MATRIX_CC="CC=clang-6.0 && CXX=clang++-6.0"
|
||||
- env: ANALYZE="scan-build-3.6 --use-cc clang-3.6 --use-c++ clang++-3.6 "
|
||||
|
||||
before_install:
|
||||
- ./CI/before_install.${TRAVIS_OS_NAME}.sh
|
||||
before_script: ./CI/before_script.${TRAVIS_OS_NAME}.sh
|
||||
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then ./CI/before_install.linux.sh; fi
|
||||
- if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ./CI/before_install.osx.sh; fi
|
||||
before_script:
|
||||
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then ./CI/before_script.linux.sh; fi
|
||||
- if [ "${TRAVIS_OS_NAME}" = "osx" ]; then ./CI/before_script.osx.sh; fi
|
||||
script:
|
||||
- cd ./build
|
||||
- if [ "$COVERITY_SCAN_BRANCH" != 1 ]; then ${ANALYZE}make -j3; fi
|
||||
- if [ "$COVERITY_SCAN_BRANCH" != 1 ] && [ "${TRAVIS_OS_NAME}" = "osx" ]; then make package; fi
|
||||
- if [ "$COVERITY_SCAN_BRANCH" != 1 ] && [ "${TRAVIS_OS_NAME}" = "linux" ]; then ./openmw_test_suite; fi
|
||||
- if [ "$COVERITY_SCAN_BRANCH" != 1 ] && [ "${TRAVIS_OS_NAME}" = "linux" ]; then cd .. && ./CI/check_tabs.sh; fi
|
||||
#notifications:
|
||||
# email:
|
||||
# recipients:
|
||||
# - corrmage+travis-ci@gmail.com
|
||||
# on_success: change
|
||||
# on_failure: always
|
||||
# irc:
|
||||
# channels:
|
||||
# - "chat.freenode.net#openmw"
|
||||
# on_success: change
|
||||
# on_failure: always
|
||||
# use_notice: true
|
||||
notifications:
|
||||
recipients:
|
||||
- corrmage+travis-ci@gmail.com
|
||||
email:
|
||||
on_success: change
|
||||
on_failure: always
|
||||
irc:
|
||||
channels:
|
||||
- "chat.freenode.net#openmw"
|
||||
on_success: change
|
||||
on_failure: always
|
||||
use_notice: true
|
||||
|
@ -1,10 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
brew update
|
||||
brew rm cmake || true
|
||||
brew rm pkgconfig || true
|
||||
brew rm qt5 || true
|
||||
brew install cmake pkgconfig qt5
|
||||
|
||||
brew outdated cmake || brew upgrade cmake
|
||||
brew outdated pkgconfig || brew upgrade pkgconfig
|
||||
brew install qt
|
||||
|
||||
curl -fSL -R -J https://downloads.openmw.org/osx/dependencies/openmw-deps-100d2e0.zip -o ~/openmw-deps.zip
|
||||
unzip -o ~/openmw-deps.zip -d /private/tmp/openmw-deps > /dev/null
|
||||
curl http://downloads.openmw.org/osx/dependencies/openmw-deps-263d4a8.zip -o ~/openmw-deps.zip
|
||||
unzip ~/openmw-deps.zip -d /private/tmp/openmw-deps > /dev/null
|
||||
|
@ -1,11 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
cd build
|
||||
|
||||
DATE=`date +'%d%m%Y'`
|
||||
SHORT_COMMIT=`git rev-parse --short ${TRAVIS_COMMIT}`
|
||||
TARGET_FILENAME="OpenMW-${DATE}-${SHORT_COMMIT}.dmg"
|
||||
|
||||
if ! curl --ssl -u $OSX_FTP_USER:$OSX_FTP_PASSWORD "${OSX_FTP_URL}" --silent | grep $SHORT_COMMIT > /dev/null; then
|
||||
curl --ssl --ftp-create-dirs -T *.dmg -u $OSX_FTP_USER:$OSX_FTP_PASSWORD "${OSX_FTP_URL}${TARGET_FILENAME}"
|
||||
fi
|
@ -1,100 +0,0 @@
|
||||
|
||||
set (CMAKE_CXX_STANDARD 14)
|
||||
|
||||
set(BROWSER_UI
|
||||
${CMAKE_SOURCE_DIR}/files/tes3mp/ui/Main.ui
|
||||
${CMAKE_SOURCE_DIR}/files/tes3mp/ui/ServerInfo.ui
|
||||
)
|
||||
set(BROWSER
|
||||
main.cpp
|
||||
MainWindow.cpp
|
||||
ServerModel.cpp
|
||||
ServerInfoDialog.cpp
|
||||
MySortFilterProxyModel.cpp
|
||||
netutils/HTTPNetwork.cpp
|
||||
netutils/Utils.cpp
|
||||
netutils/QueryClient.cpp
|
||||
PingUpdater.cpp
|
||||
PingHelper.cpp
|
||||
QueryHelper.cpp
|
||||
${CMAKE_SOURCE_DIR}/files/tes3mp/browser.rc
|
||||
)
|
||||
|
||||
set(BROWSER_HEADER_MOC
|
||||
MainWindow.hpp
|
||||
ServerModel.hpp
|
||||
ServerInfoDialog.hpp
|
||||
MySortFilterProxyModel.hpp
|
||||
PingUpdater.hpp
|
||||
PingHelper.hpp
|
||||
QueryHelper.hpp
|
||||
)
|
||||
|
||||
set(BROWSER_HEADER
|
||||
${BROWSER_HEADER_MOC}
|
||||
netutils/HTTPNetwork.hpp
|
||||
netutils/Utils.hpp
|
||||
netutils/QueryClient.hpp
|
||||
Types.hpp
|
||||
)
|
||||
|
||||
source_group(browser FILES ${BROWSER} ${BROWSER_HEADER})
|
||||
|
||||
set(QT_USE_QTGUI 1)
|
||||
|
||||
# Set some platform specific settings
|
||||
if(WIN32)
|
||||
set(GUI_TYPE WIN32)
|
||||
set(QT_USE_QTMAIN TRUE)
|
||||
endif(WIN32)
|
||||
|
||||
if (DESIRED_QT_VERSION MATCHES 4)
|
||||
message(SEND_ERROR "QT4 is not supported.")
|
||||
#include(${QT_USE_FILE})
|
||||
#QT4_ADD_RESOURCES(RCC_SRCS ${CMAKE_SOURCE_DIR}/files/launcher/launcher.qrc)
|
||||
#QT4_WRAP_CPP(MOC_SRCS ${BROWSER_HEADER_MOC})
|
||||
#QT4_WRAP_UI(UI_HDRS ${BROWSER_UI})
|
||||
else()
|
||||
QT5_ADD_RESOURCES(RCC_SRCS ${CMAKE_SOURCE_DIR}/files/launcher/launcher.qrc)
|
||||
QT5_WRAP_CPP(MOC_SRCS ${BROWSER_HEADER_MOC})
|
||||
QT5_WRAP_UI(UI_HDRS ${BROWSER_UI})
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
if(NOT WIN32)
|
||||
include_directories(${LIBUNSHIELD_INCLUDE_DIR})
|
||||
endif(NOT WIN32)
|
||||
|
||||
# Main executable
|
||||
add_executable(tes3mp-browser
|
||||
${GUI_TYPE}
|
||||
${BROWSER}
|
||||
${BROWSER_HEADER}
|
||||
${RCC_SRCS}
|
||||
${MOC_SRCS}
|
||||
${UI_HDRS}
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
INSTALL(TARGETS tes3mp-browser RUNTIME DESTINATION ".")
|
||||
endif (WIN32)
|
||||
|
||||
target_link_libraries(tes3mp-browser
|
||||
${SDL2_LIBRARY_ONLY}
|
||||
${RakNet_LIBRARY}
|
||||
components
|
||||
)
|
||||
|
||||
if (DESIRED_QT_VERSION MATCHES 4)
|
||||
# target_link_libraries(tes3mp-browser ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
|
||||
# if(WIN32)
|
||||
# target_link_libraries(tes3mp-browser ${QT_QTMAIN_LIBRARY})
|
||||
# endif(WIN32)
|
||||
else()
|
||||
qt5_use_modules(tes3mp-browser Widgets Core)
|
||||
endif()
|
||||
|
||||
if (BUILD_WITH_CODE_COVERAGE)
|
||||
add_definitions (--coverage)
|
||||
target_link_libraries(tes3mp-browser gcov)
|
||||
endif()
|
@ -1,246 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 06.01.17.
|
||||
//
|
||||
|
||||
#include "MainWindow.hpp"
|
||||
#include "QueryHelper.hpp"
|
||||
#include "PingHelper.hpp"
|
||||
#include "ServerInfoDialog.hpp"
|
||||
#include "components/files/configurationmanager.hpp"
|
||||
#include <qdebug.h>
|
||||
#include <QInputDialog>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
|
||||
|
||||
using namespace Process;
|
||||
using namespace std;
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
mGameInvoker = new ProcessInvoker();
|
||||
|
||||
browser = new ServerModel;
|
||||
favorites = new ServerModel;
|
||||
proxyModel = new MySortFilterProxyModel(this);
|
||||
proxyModel->setSourceModel(browser);
|
||||
tblServerBrowser->setModel(proxyModel);
|
||||
tblFavorites->setModel(proxyModel);
|
||||
|
||||
// Remove Favorites tab while it remains broken
|
||||
tabWidget->removeTab(1);
|
||||
|
||||
tblServerBrowser->hideColumn(ServerData::ADDR);
|
||||
tblFavorites->hideColumn(ServerData::ADDR);
|
||||
|
||||
PingHelper::Get().SetModel((ServerModel*)proxyModel->sourceModel());
|
||||
queryHelper = new QueryHelper(proxyModel->sourceModel());
|
||||
connect(queryHelper, &QueryHelper::started, [this](){actionRefresh->setEnabled(false);});
|
||||
connect(queryHelper, &QueryHelper::finished, [this](){actionRefresh->setEnabled(true);});
|
||||
|
||||
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabSwitched(int)));
|
||||
connect(actionAdd, SIGNAL(triggered(bool)), this, SLOT(addServer()));
|
||||
connect(actionAdd_by_IP, SIGNAL(triggered(bool)), this, SLOT(addServerByIP()));
|
||||
connect(actionDelete, SIGNAL(triggered(bool)), this, SLOT(deleteServer()));
|
||||
connect(actionRefresh, SIGNAL(triggered(bool)), queryHelper, SLOT(refresh()));
|
||||
connect(actionPlay, SIGNAL(triggered(bool)), this, SLOT(play()));
|
||||
connect(tblServerBrowser, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected()));
|
||||
connect(tblFavorites, SIGNAL(clicked(QModelIndex)), this, SLOT(serverSelected()));
|
||||
connect(tblFavorites, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play()));
|
||||
connect(tblServerBrowser, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(play()));
|
||||
connect(cBoxNotFull, SIGNAL(toggled(bool)), this, SLOT(notFullSwitch(bool)));
|
||||
connect(cBoxWithPlayers, SIGNAL(toggled(bool)), this, SLOT(havePlayersSwitch(bool)));
|
||||
connect(cBBoxWOPass, SIGNAL(toggled(bool)), this, SLOT(noPasswordSwitch(bool)));
|
||||
connect(comboLatency, SIGNAL(currentIndexChanged(int)), this, SLOT(maxLatencyChanged(int)));
|
||||
connect(leGamemode, SIGNAL(textChanged(const QString &)), this, SLOT(gamemodeChanged(const QString &)));
|
||||
loadFavorites();
|
||||
queryHelper->refresh();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete mGameInvoker;
|
||||
}
|
||||
|
||||
void MainWindow::addServerAndUpdate(const QString &addr)
|
||||
{
|
||||
favorites->insertRow(0);
|
||||
QModelIndex mi = favorites->index(0, ServerData::ADDR);
|
||||
favorites->setData(mi, addr, Qt::EditRole);
|
||||
//NetController::get()->updateInfo(favorites, mi);
|
||||
//QueryClient::Update(RakNet::SystemAddress())
|
||||
/*auto data = QueryClient::Get().Query();
|
||||
if (data.empty())
|
||||
return;
|
||||
transform(data.begin(), data.end(), back_inserter());*/
|
||||
}
|
||||
|
||||
void MainWindow::addServer()
|
||||
{
|
||||
int id = tblServerBrowser->selectionModel()->currentIndex().row();
|
||||
|
||||
if (id >= 0)
|
||||
{
|
||||
int sourceId = proxyModel->mapToSource(proxyModel->index(id, ServerData::ADDR)).row();
|
||||
favorites->myData.push_back(browser->myData[sourceId]);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::addServerByIP()
|
||||
{
|
||||
bool ok;
|
||||
QString text = QInputDialog::getText(this, tr("Add Server by address"), tr("Address:"), QLineEdit::Normal, "", &ok);
|
||||
if (ok && !text.isEmpty())
|
||||
addServerAndUpdate(text);
|
||||
}
|
||||
|
||||
void MainWindow::deleteServer()
|
||||
{
|
||||
if (tabWidget->currentIndex() != 1)
|
||||
return;
|
||||
int id = tblFavorites->selectionModel()->currentIndex().row();
|
||||
if (id >= 0)
|
||||
{
|
||||
int sourceId = proxyModel->mapToSource(proxyModel->index(id, ServerData::ADDR)).row();
|
||||
favorites->removeRow(sourceId);
|
||||
if (favorites->myData.isEmpty())
|
||||
{
|
||||
actionPlay->setEnabled(false);
|
||||
actionDelete->setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::play()
|
||||
{
|
||||
QTableView *curTable = tabWidget->currentIndex() ? tblFavorites : tblServerBrowser;
|
||||
int id = curTable->selectionModel()->currentIndex().row();
|
||||
if (id < 0)
|
||||
return;
|
||||
|
||||
|
||||
ServerModel *sm = ((ServerModel*)proxyModel->sourceModel());
|
||||
|
||||
int sourceId = proxyModel->mapToSource(proxyModel->index(id, ServerData::ADDR)).row();
|
||||
ServerInfoDialog infoDialog(sm->myData[sourceId].addr, this);
|
||||
|
||||
if (!infoDialog.exec())
|
||||
return;
|
||||
|
||||
if (!infoDialog.isUpdated())
|
||||
return;
|
||||
|
||||
QStringList arguments;
|
||||
arguments.append(QLatin1String("--connect=") + sm->myData[sourceId].addr.toLatin1());
|
||||
|
||||
if (sm->myData[sourceId].GetPassword() == 1)
|
||||
{
|
||||
bool ok;
|
||||
QString passw = QInputDialog::getText(this, tr("Connecting to: ") + sm->myData[sourceId].addr, tr("Password: "),
|
||||
QLineEdit::Password, "", &ok);
|
||||
if (!ok)
|
||||
return;
|
||||
arguments.append(QLatin1String("--password=") + passw.toLatin1());
|
||||
}
|
||||
|
||||
if (mGameInvoker->startProcess(QLatin1String("tes3mp"), arguments, true))
|
||||
return qApp->quit();
|
||||
}
|
||||
|
||||
void MainWindow::tabSwitched(int index)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
proxyModel->setSourceModel(browser);
|
||||
actionDelete->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
proxyModel->setSourceModel(favorites);
|
||||
}
|
||||
actionPlay->setEnabled(false);
|
||||
actionAdd->setEnabled(false);
|
||||
}
|
||||
|
||||
void MainWindow::serverSelected()
|
||||
{
|
||||
actionPlay->setEnabled(true);
|
||||
if (tabWidget->currentIndex() == 0)
|
||||
actionAdd->setEnabled(true);
|
||||
if (tabWidget->currentIndex() == 1)
|
||||
actionDelete->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
Files::ConfigurationManager cfgMgr;
|
||||
QString cfgPath = QString::fromStdString((cfgMgr.getUserConfigPath() / "favorites.dat").string());
|
||||
|
||||
QJsonArray saveData;
|
||||
for (auto server : favorites->myData)
|
||||
saveData.push_back(server.addr);
|
||||
|
||||
QFile file(cfgPath);
|
||||
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
qDebug() << "Cannot save " << cfgPath;
|
||||
return;
|
||||
}
|
||||
|
||||
file.write(QJsonDocument(saveData).toJson());
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::loadFavorites()
|
||||
{
|
||||
Files::ConfigurationManager cfgMgr;
|
||||
QString cfgPath = QString::fromStdString((cfgMgr.getUserConfigPath() / "favorites.dat").string());
|
||||
|
||||
QFile file(cfgPath);
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
qDebug() << "Cannot open " << cfgPath;
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(file.readAll()));
|
||||
|
||||
for (auto server : jsonDoc.array())
|
||||
addServerAndUpdate(server.toString());
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void MainWindow::notFullSwitch(bool state)
|
||||
{
|
||||
proxyModel->filterFullServer(state);
|
||||
}
|
||||
|
||||
void MainWindow::havePlayersSwitch(bool state)
|
||||
{
|
||||
proxyModel->filterEmptyServers(state);
|
||||
}
|
||||
|
||||
void MainWindow::noPasswordSwitch(bool state)
|
||||
{
|
||||
proxyModel->filterPassworded(state);
|
||||
}
|
||||
|
||||
void MainWindow::maxLatencyChanged(int index)
|
||||
{
|
||||
int maxLatency = index * 50;
|
||||
proxyModel->pingLessThan(maxLatency);
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::gamemodeChanged(const QString &text)
|
||||
{
|
||||
proxyModel->setFilterFixedString(text);
|
||||
proxyModel->setFilterKeyColumn(ServerData::MODNAME);
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 06.01.17.
|
||||
//
|
||||
|
||||
#ifndef NEWLAUNCHER_MAIN_HPP
|
||||
#define NEWLAUNCHER_MAIN_HPP
|
||||
|
||||
|
||||
#include "ui_Main.h"
|
||||
#include "ServerModel.hpp"
|
||||
#include "MySortFilterProxyModel.hpp"
|
||||
#include <components/process/processinvoker.hpp>
|
||||
|
||||
class QueryHelper;
|
||||
|
||||
class MainWindow : public QMainWindow, private Ui::MainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
protected:
|
||||
void closeEvent(QCloseEvent * event) Q_DECL_OVERRIDE;
|
||||
void addServerAndUpdate(const QString &addr);
|
||||
protected slots:
|
||||
void tabSwitched(int index);
|
||||
void addServer();
|
||||
void addServerByIP();
|
||||
void deleteServer();
|
||||
void play();
|
||||
void serverSelected();
|
||||
void notFullSwitch(bool state);
|
||||
void havePlayersSwitch(bool state);
|
||||
void noPasswordSwitch(bool state);
|
||||
void maxLatencyChanged(int index);
|
||||
void gamemodeChanged(const QString &text);
|
||||
private:
|
||||
QueryHelper *queryHelper;
|
||||
Process::ProcessInvoker *mGameInvoker;
|
||||
ServerModel *browser, *favorites;
|
||||
MySortFilterProxyModel *proxyModel;
|
||||
void loadFavorites();
|
||||
};
|
||||
|
||||
|
||||
#endif //NEWLAUNCHER_MAIN_HPP
|
@ -1,84 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 30.01.17.
|
||||
//
|
||||
|
||||
#include "MySortFilterProxyModel.hpp"
|
||||
#include "ServerModel.hpp"
|
||||
|
||||
#include <qdebug.h>
|
||||
#include <apps/browser/netutils/Utils.hpp>
|
||||
|
||||
bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||
{
|
||||
|
||||
QModelIndex pingIndex = sourceModel()->index(sourceRow, ServerData::PING, sourceParent);
|
||||
QModelIndex plIndex = sourceModel()->index(sourceRow, ServerData::PLAYERS, sourceParent);
|
||||
QModelIndex maxPlIndex = sourceModel()->index(sourceRow, ServerData::MAX_PLAYERS, sourceParent);
|
||||
QModelIndex passwordIndex = sourceModel()->index(sourceRow, ServerData::PASSW, sourceParent);
|
||||
|
||||
bool pingOk;
|
||||
int ping = sourceModel()->data(pingIndex).toInt(&pingOk);
|
||||
int players = sourceModel()->data(plIndex).toInt();
|
||||
int maxPlayers = sourceModel()->data(maxPlIndex).toInt();
|
||||
|
||||
if (maxPing > 0 && (ping == -1 || ping > maxPing || !pingOk))
|
||||
return false;
|
||||
if (filterEmpty && players == 0)
|
||||
return false;
|
||||
if (filterFull && players >= maxPlayers)
|
||||
return false;
|
||||
if(filterPasswEnabled && sourceModel()->data(passwordIndex).toString() == "Yes")
|
||||
return false;
|
||||
|
||||
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
}
|
||||
|
||||
bool MySortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
||||
{
|
||||
if(sortColumn() == ServerData::PING)
|
||||
{
|
||||
bool valid;
|
||||
|
||||
int pingright = sourceModel()->data(source_right).toInt(&valid);
|
||||
pingright = valid ? pingright : PING_UNREACHABLE;
|
||||
|
||||
int pingleft = sourceModel()->data(source_left).toInt(&valid);
|
||||
pingleft = valid ? pingleft : PING_UNREACHABLE;
|
||||
return pingleft < pingright;
|
||||
}
|
||||
else
|
||||
return QSortFilterProxyModel::lessThan(source_left, source_right);
|
||||
}
|
||||
|
||||
MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent) : QSortFilterProxyModel(parent)
|
||||
{
|
||||
filterEmpty = false;
|
||||
filterFull = false;
|
||||
filterPasswEnabled = false;
|
||||
maxPing = 0;
|
||||
setSortCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
||||
}
|
||||
|
||||
void MySortFilterProxyModel::filterEmptyServers(bool state)
|
||||
{
|
||||
filterEmpty = state;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void MySortFilterProxyModel::filterFullServer(bool state)
|
||||
{
|
||||
filterFull = state;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void MySortFilterProxyModel::pingLessThan(int maxPing)
|
||||
{
|
||||
this->maxPing = maxPing;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void MySortFilterProxyModel::filterPassworded(bool state)
|
||||
{
|
||||
filterPasswEnabled = state;
|
||||
invalidateFilter();
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 30.01.17.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_MYSORTFILTERPROXYMODEL_HPP
|
||||
#define OPENMW_MYSORTFILTERPROXYMODEL_HPP
|
||||
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
class MySortFilterProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_FINAL;
|
||||
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const Q_DECL_FINAL;
|
||||
public:
|
||||
explicit MySortFilterProxyModel(QObject *parent);
|
||||
void filterFullServer(bool state);
|
||||
void filterEmptyServers(bool state);
|
||||
void filterPassworded(bool state);
|
||||
void pingLessThan(int maxPing);
|
||||
private:
|
||||
bool filterEmpty, filterFull, filterPasswEnabled;
|
||||
int maxPing;
|
||||
};
|
||||
|
||||
|
||||
#endif //OPENMW_MYSORTFILTERPROXYMODEL_HPP
|
@ -1,56 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 03.05.17.
|
||||
//
|
||||
|
||||
#include "PingHelper.hpp"
|
||||
#include "ServerModel.hpp"
|
||||
#include <QDebug>
|
||||
#include "PingUpdater.hpp"
|
||||
|
||||
void PingHelper::Add(int row, const AddrPair &addrPair)
|
||||
{
|
||||
pingUpdater->addServer(row, addrPair);
|
||||
if (!pingThread->isRunning())
|
||||
pingThread->start();
|
||||
}
|
||||
|
||||
void PingHelper::Reset()
|
||||
{
|
||||
//if (pingThread->isRunning())
|
||||
Stop();
|
||||
}
|
||||
|
||||
void PingHelper::Stop()
|
||||
{
|
||||
emit pingUpdater->stop();
|
||||
}
|
||||
|
||||
void PingHelper::SetModel(QAbstractTableModel *model)
|
||||
{
|
||||
this->model = model;
|
||||
}
|
||||
|
||||
void PingHelper::update(int row, unsigned ping)
|
||||
{
|
||||
model->setData(model->index(row, ServerData::PING), ping);
|
||||
}
|
||||
|
||||
PingHelper &PingHelper::Get()
|
||||
{
|
||||
static PingHelper helper;
|
||||
return helper;
|
||||
}
|
||||
|
||||
PingHelper::PingHelper() : QObject()
|
||||
{
|
||||
pingThread = new QThread;
|
||||
pingUpdater = new PingUpdater;
|
||||
pingUpdater->moveToThread(pingThread);
|
||||
|
||||
connect(pingThread, SIGNAL(started()), pingUpdater, SLOT(process()));
|
||||
connect(pingUpdater, SIGNAL(start()), pingThread, SLOT(start()));
|
||||
connect(pingUpdater, SIGNAL(finished()), pingThread, SLOT(quit()));
|
||||
connect(this, SIGNAL(stop()), pingUpdater, SLOT(stop()));
|
||||
//connect(pingUpdater, SIGNAL(finished()), pingUpdater, SLOT(deleteLater()));
|
||||
connect(pingUpdater, SIGNAL(updateModel(int, unsigned)), this, SLOT(update(int, unsigned)));
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 03.05.17.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_PINGHELPER_HPP
|
||||
#define OPENMW_PINGHELPER_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <QAbstractTableModel>
|
||||
#include <QThread>
|
||||
#include "Types.hpp"
|
||||
|
||||
class PingUpdater;
|
||||
|
||||
class PingHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
void Reset();
|
||||
void Add(int row, const AddrPair &addrPair);
|
||||
void Stop();
|
||||
void SetModel(QAbstractTableModel *model);
|
||||
//void UpdateImmedialy(PingUpdater::AddrPair addrPair);
|
||||
static PingHelper &Get();
|
||||
|
||||
PingHelper(const PingHelper&) = delete;
|
||||
PingHelper& operator=(const PingHelper&) = delete;
|
||||
private:
|
||||
PingHelper();
|
||||
signals:
|
||||
void stop();
|
||||
public slots:
|
||||
void update(int row, unsigned ping);
|
||||
private:
|
||||
QThread *pingThread;
|
||||
PingUpdater *pingUpdater;
|
||||
QAbstractTableModel *model;
|
||||
};
|
||||
|
||||
|
||||
#endif //OPENMW_PINGHELPER_HPP
|
@ -1,50 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 02.05.17.
|
||||
//
|
||||
|
||||
#include "PingUpdater.hpp"
|
||||
#include "netutils/Utils.hpp"
|
||||
#include <QDebug>
|
||||
#include <QModelIndex>
|
||||
#include <QThread>
|
||||
|
||||
void PingUpdater::stop()
|
||||
{
|
||||
servers.clear();
|
||||
run = false;
|
||||
}
|
||||
|
||||
void PingUpdater::addServer(int row, const AddrPair &addr)
|
||||
{
|
||||
servers.push_back({row, addr});
|
||||
run = true;
|
||||
emit start();
|
||||
}
|
||||
|
||||
void PingUpdater::process()
|
||||
{
|
||||
while (run)
|
||||
{
|
||||
if (servers.count() == 0)
|
||||
{
|
||||
QThread::msleep(1000);
|
||||
if (servers.count() == 0)
|
||||
{
|
||||
qDebug() << "PingUpdater stopped due to inactivity";
|
||||
run = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ServerRow server = servers.back();
|
||||
servers.pop_back();
|
||||
|
||||
unsigned ping = PingRakNetServer(server.second.first.toLatin1(), server.second.second);
|
||||
|
||||
qDebug() << "Pong from" << server.second.first + "|" + QString::number(server.second.second)
|
||||
<< ":" << ping << "ms" << "Sizeof servers: " << servers.size();
|
||||
|
||||
emit updateModel(server.first, ping);
|
||||
}
|
||||
emit finished();
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 02.05.17.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_PINGUPDATER_HPP
|
||||
#define OPENMW_PINGUPDATER_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
#include "Types.hpp"
|
||||
|
||||
class PingUpdater : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
void addServer(int row, const AddrPair &addrPair);
|
||||
public slots:
|
||||
void stop();
|
||||
void process();
|
||||
signals:
|
||||
void start();
|
||||
void updateModel(int row, unsigned ping);
|
||||
void finished();
|
||||
private:
|
||||
QVector<ServerRow> servers;
|
||||
bool run;
|
||||
};
|
||||
|
||||
|
||||
#endif //OPENMW_PINGUPDATER_HPP
|
@ -1,87 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 27.05.17.
|
||||
//
|
||||
|
||||
#include "netutils/QueryClient.hpp"
|
||||
#include "netutils/Utils.hpp"
|
||||
#include "QueryHelper.hpp"
|
||||
#include "PingHelper.hpp"
|
||||
|
||||
QueryUpdate *queryUpdate;
|
||||
|
||||
|
||||
QueryHelper::QueryHelper(QAbstractItemModel *model)
|
||||
{
|
||||
qRegisterMetaType<QueryData>("QueryData");
|
||||
queryThread = new QThread;
|
||||
queryUpdate = new QueryUpdate;
|
||||
_model = model;
|
||||
connect(queryThread, SIGNAL(started()), queryUpdate, SLOT(process()));
|
||||
connect(queryUpdate, SIGNAL(finished()), queryThread, SLOT(quit()));
|
||||
connect(queryUpdate, &QueryUpdate::finished, [this](){emit finished();});
|
||||
connect(queryUpdate, SIGNAL(updateModel(const QString&, unsigned short, const QueryData&)),
|
||||
this, SLOT(update(const QString&, unsigned short, const QueryData&)));
|
||||
queryUpdate->moveToThread(queryThread);
|
||||
}
|
||||
|
||||
void QueryHelper::refresh()
|
||||
{
|
||||
if (!queryThread->isRunning())
|
||||
{
|
||||
_model->removeRows(0, _model->rowCount());
|
||||
PingHelper::Get().Stop();
|
||||
queryThread->start();
|
||||
emit started();
|
||||
}
|
||||
}
|
||||
|
||||
void QueryHelper::terminate()
|
||||
{
|
||||
queryThread->terminate();
|
||||
}
|
||||
|
||||
void QueryHelper::update(const QString &addr, unsigned short port, const QueryData& data)
|
||||
{
|
||||
ServerModel *model = ((ServerModel*)_model);
|
||||
model->insertRow(model->rowCount());
|
||||
int row = model->rowCount() - 1;
|
||||
|
||||
QModelIndex mi = model->index(row, ServerData::ADDR);
|
||||
model->setData(mi, addr + ":" + QString::number(port));
|
||||
|
||||
mi = model->index(row, ServerData::PLAYERS);
|
||||
model->setData(mi, (int)data.players.size());
|
||||
|
||||
mi = model->index(row, ServerData::MAX_PLAYERS);
|
||||
model->setData(mi, data.GetMaxPlayers());
|
||||
|
||||
mi = model->index(row, ServerData::HOSTNAME);
|
||||
model->setData(mi, data.GetName());
|
||||
|
||||
mi = model->index(row, ServerData::MODNAME);
|
||||
model->setData(mi, data.GetGameMode());
|
||||
|
||||
mi = model->index(row, ServerData::VERSION);
|
||||
model->setData(mi, data.GetVersion());
|
||||
|
||||
mi = model->index(row, ServerData::PASSW);
|
||||
model->setData(mi, data.GetPassword() == 1);
|
||||
|
||||
mi = model->index(row, ServerData::PING);
|
||||
model->setData(mi, PING_UNREACHABLE);
|
||||
PingHelper::Get().Add(row, {addr, port});
|
||||
}
|
||||
|
||||
void QueryUpdate::process()
|
||||
{
|
||||
auto data = QueryClient::Get().Query();
|
||||
if (QueryClient::Get().Status() != ID_MASTER_QUERY)
|
||||
{
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &server : data)
|
||||
emit updateModel(server.first.ToString(false), server.first.GetPort(), server.second);
|
||||
emit finished();
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 27.05.17.
|
||||
//
|
||||
|
||||
|
||||
#ifndef OPENMW_QUERYHELPER_HPP
|
||||
#define OPENMW_QUERYHELPER_HPP
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#include <vector>
|
||||
#include <QAbstractItemModel>
|
||||
#include <components/openmw-mp/Master/MasterData.hpp>
|
||||
|
||||
Q_DECLARE_METATYPE(QueryData)
|
||||
|
||||
class QueryHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QueryHelper(QAbstractItemModel *model);
|
||||
public slots:
|
||||
void refresh();
|
||||
void terminate();
|
||||
private slots:
|
||||
void update(const QString &addr, unsigned short port, const QueryData& data);
|
||||
signals:
|
||||
void finished();
|
||||
void started();
|
||||
private:
|
||||
QThread *queryThread;
|
||||
QAbstractItemModel *_model;
|
||||
};
|
||||
|
||||
class QueryUpdate : public QObject
|
||||
{
|
||||
friend class QueryHelper;
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void finished();
|
||||
void updateModel(const QString &addr, unsigned short port, const QueryData& data);
|
||||
public slots:
|
||||
void process();
|
||||
};
|
||||
|
||||
#endif //OPENMW_QUERYHELPER_HPP
|
@ -1,107 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 07.01.17.
|
||||
//
|
||||
|
||||
#include <apps/browser/netutils/QueryClient.hpp>
|
||||
#include "qdebug.h"
|
||||
|
||||
#include "ServerInfoDialog.hpp"
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <QThread>
|
||||
|
||||
using namespace std;
|
||||
using namespace RakNet;
|
||||
|
||||
ThrWorker::ThrWorker(ServerInfoDialog *dialog, QString addr, unsigned short port): addr(std::move(addr)), port(port), stopped(false)
|
||||
{
|
||||
this->dialog = dialog;
|
||||
}
|
||||
|
||||
void ThrWorker::process()
|
||||
{
|
||||
stopped = false;
|
||||
auto newSD = QueryClient::Get().Update(SystemAddress(addr.toUtf8(), port));
|
||||
if (dialog != nullptr)
|
||||
dialog->setData(newSD);
|
||||
stopped = true;
|
||||
emit finished();
|
||||
}
|
||||
|
||||
ServerInfoDialog::ServerInfoDialog(const QString &addr, QWidget *parent): QDialog(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
refreshThread = new QThread;
|
||||
|
||||
QStringList list = addr.split(':');
|
||||
worker = new ThrWorker(this, list[0].toLatin1(), list[1].toUShort());
|
||||
worker->moveToThread(refreshThread);
|
||||
connect(refreshThread, SIGNAL(started()), worker, SLOT(process()));
|
||||
connect(worker, SIGNAL(finished()), refreshThread, SLOT(quit()));
|
||||
connect(refreshThread, SIGNAL(finished()), this, SLOT(refresh()));
|
||||
|
||||
connect(btnRefresh, &QPushButton::clicked, [this]{
|
||||
if (!refreshThread->isRunning())
|
||||
refreshThread->start();
|
||||
});
|
||||
}
|
||||
|
||||
ServerInfoDialog::~ServerInfoDialog()
|
||||
{
|
||||
worker->dialog = nullptr;
|
||||
if (!refreshThread->isRunning())
|
||||
refreshThread->terminate();
|
||||
}
|
||||
|
||||
bool ServerInfoDialog::isUpdated()
|
||||
{
|
||||
return sd.first != UNASSIGNED_SYSTEM_ADDRESS;
|
||||
}
|
||||
|
||||
void ServerInfoDialog::setData(std::pair<RakNet::SystemAddress, QueryData> &newSD)
|
||||
{
|
||||
sd = newSD;
|
||||
}
|
||||
|
||||
void ServerInfoDialog::refresh()
|
||||
{
|
||||
if (sd.first != UNASSIGNED_SYSTEM_ADDRESS)
|
||||
{
|
||||
leAddr->setText(sd.first.ToString(true, ':'));
|
||||
lblName->setText(sd.second.GetName());
|
||||
int ping = PingRakNetServer(sd.first.ToString(false), sd.first.GetPort());
|
||||
lblPing->setNum(ping);
|
||||
btnConnect->setDisabled(ping == PING_UNREACHABLE);
|
||||
|
||||
listPlayers->clear();
|
||||
for (const auto &player : sd.second.players)
|
||||
listPlayers->addItem(QString::fromStdString(player));
|
||||
|
||||
listPlugins->clear();
|
||||
for (const auto &plugin : sd.second.plugins)
|
||||
listPlugins->addItem(QString::fromStdString(plugin.name));
|
||||
|
||||
listRules->clear();
|
||||
const static vector<std::string> defaultRules {"gamemode", "maxPlayers", "name", "passw", "players", "version"};
|
||||
for (auto &rule : sd.second.rules)
|
||||
{
|
||||
if (::find(defaultRules.begin(), defaultRules.end(), rule.first) != defaultRules.end())
|
||||
continue;
|
||||
QString ruleStr = QString::fromStdString(rule.first) + " : ";
|
||||
if (rule.second.type == 's')
|
||||
ruleStr += QString::fromStdString(rule.second.str);
|
||||
else
|
||||
ruleStr += QString::number(rule.second.val);
|
||||
listRules->addItem(ruleStr);
|
||||
}
|
||||
|
||||
lblPlayers->setText(QString::number(sd.second.players.size()) + " / " + QString::number(sd.second.GetMaxPlayers()));
|
||||
}
|
||||
}
|
||||
|
||||
int ServerInfoDialog::exec()
|
||||
{
|
||||
if (!refreshThread->isRunning())
|
||||
refreshThread->start();
|
||||
return QDialog::exec();
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 07.01.17.
|
||||
//
|
||||
|
||||
#ifndef NEWLAUNCHER_SERVERINFODIALOG_HPP
|
||||
#define NEWLAUNCHER_SERVERINFODIALOG_HPP
|
||||
|
||||
#include "ui_ServerInfo.h"
|
||||
#include <apps/browser/netutils/Utils.hpp>
|
||||
#include <RakNetTypes.h>
|
||||
#include <components/openmw-mp/Master/MasterData.hpp>
|
||||
|
||||
class ThrWorker;
|
||||
|
||||
class ServerInfoDialog : public QDialog, public Ui::Dialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ServerInfoDialog(const QString &addr, QWidget *parent = nullptr);
|
||||
~ServerInfoDialog() override;
|
||||
bool isUpdated();
|
||||
void setData(std::pair<RakNet::SystemAddress, QueryData> &newSD);
|
||||
public slots:
|
||||
void refresh();
|
||||
int exec() Q_DECL_OVERRIDE;
|
||||
private:
|
||||
QThread *refreshThread;
|
||||
ThrWorker* worker;
|
||||
std::pair<RakNet::SystemAddress, QueryData> sd;
|
||||
};
|
||||
|
||||
class ThrWorker: public QObject
|
||||
{
|
||||
friend class ServerInfoDialog;
|
||||
Q_OBJECT
|
||||
public:
|
||||
ThrWorker(ServerInfoDialog *dialog, QString addr, unsigned short port);
|
||||
|
||||
public slots:
|
||||
void process();
|
||||
signals:
|
||||
void finished();
|
||||
private:
|
||||
QString addr;
|
||||
unsigned short port;
|
||||
bool stopped;
|
||||
ServerInfoDialog *dialog;
|
||||
};
|
||||
|
||||
|
||||
#endif //NEWLAUNCHER_SERVERINFODIALOG_HPP
|
@ -1,191 +0,0 @@
|
||||
#include <qmessagebox.h>
|
||||
#include "ServerModel.hpp"
|
||||
#include <qdebug.h>
|
||||
#include <apps/browser/netutils/Utils.hpp>
|
||||
|
||||
ServerModel::ServerModel(QObject *parent) : QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
/*QHash<int, QByteArray> ServerModel::roleNames() const
|
||||
{
|
||||
return roles;
|
||||
}*/
|
||||
|
||||
QVariant ServerModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
if (index.row() < 0 || index.row() > myData.size())
|
||||
return QVariant();
|
||||
|
||||
const ServerData &sd = myData.at(index.row());
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
QVariant var;
|
||||
switch (index.column())
|
||||
{
|
||||
case ServerData::ADDR:
|
||||
var = sd.addr;
|
||||
break;
|
||||
case ServerData::PASSW:
|
||||
var = (int)(sd.rules.at("passw").val) == 1 ? "Yes" : "No";
|
||||
break;
|
||||
case ServerData::VERSION:
|
||||
var = QString(sd.rules.at("version").str.c_str());
|
||||
break;
|
||||
case ServerData::PLAYERS:
|
||||
var = (int) sd.rules.at("players").val;
|
||||
break;
|
||||
case ServerData::MAX_PLAYERS:
|
||||
var = (int) sd.rules.at("maxPlayers").val;
|
||||
break;
|
||||
case ServerData::HOSTNAME:
|
||||
var = QString(sd.rules.at("name").str.c_str());
|
||||
break;
|
||||
case ServerData::PING:
|
||||
var = sd.ping == PING_UNREACHABLE ? QVariant("Unreachable") : sd.ping;
|
||||
break;
|
||||
case ServerData::MODNAME:
|
||||
if (sd.rules.at("gamemode").str == "")
|
||||
var = "default";
|
||||
else
|
||||
var = QString(sd.rules.at("gamemode").str.c_str());
|
||||
break;
|
||||
}
|
||||
return var;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant ServerModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
QVariant var;
|
||||
if (orientation == Qt::Horizontal)
|
||||
{
|
||||
if (role == Qt::SizeHintRole)
|
||||
{
|
||||
/*if (section == ServerData::HOSTNAME)
|
||||
var = QSize(200, 25);*/
|
||||
}
|
||||
else if (role == Qt::DisplayRole)
|
||||
{
|
||||
|
||||
switch (section)
|
||||
{
|
||||
case ServerData::ADDR:
|
||||
var = "Address";
|
||||
break;
|
||||
case ServerData::PASSW:
|
||||
var = "Password";
|
||||
break;
|
||||
case ServerData::VERSION:
|
||||
var = "Version";
|
||||
break;
|
||||
case ServerData::HOSTNAME:
|
||||
var = "Host name";
|
||||
break;
|
||||
case ServerData::PLAYERS:
|
||||
var = "Players";
|
||||
break;
|
||||
case ServerData::MAX_PLAYERS:
|
||||
var = "Max players";
|
||||
break;
|
||||
case ServerData::PING:
|
||||
var = "Ping";
|
||||
break;
|
||||
case ServerData::MODNAME:
|
||||
var = "Game mode";
|
||||
}
|
||||
}
|
||||
}
|
||||
return var;
|
||||
}
|
||||
|
||||
int ServerModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return myData.size();
|
||||
}
|
||||
|
||||
int ServerModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return ServerData::LAST;
|
||||
}
|
||||
|
||||
bool ServerModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (index.isValid() && role == Qt::EditRole)
|
||||
{
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
|
||||
ServerData &sd = myData[row];
|
||||
bool ok = true;
|
||||
switch(col)
|
||||
{
|
||||
case ServerData::ADDR:
|
||||
sd.addr = value.toString();
|
||||
ok = !sd.addr.isEmpty();
|
||||
break;
|
||||
case ServerData::PASSW:
|
||||
sd.SetPassword(value.toBool());
|
||||
break;
|
||||
case ServerData::VERSION:
|
||||
sd.SetVersion(value.toString().toUtf8());
|
||||
ok = !sd.addr.isEmpty();
|
||||
break;
|
||||
case ServerData::PLAYERS:
|
||||
sd.SetPlayers(value.toInt(&ok));
|
||||
break;
|
||||
case ServerData::MAX_PLAYERS:
|
||||
sd.SetMaxPlayers(value.toInt(&ok));
|
||||
break;
|
||||
case ServerData::HOSTNAME:
|
||||
sd.SetName(value.toString().toUtf8());
|
||||
ok = !sd.addr.isEmpty();
|
||||
break;
|
||||
case ServerData::PING:
|
||||
sd.ping = value.toInt(&ok);
|
||||
break;
|
||||
case ServerData::MODNAME:
|
||||
sd.SetGameMode(value.toString().toUtf8());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (ok)
|
||||
emit(dataChanged(index, index));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerModel::insertRows(int position, int count, const QModelIndex &index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
beginInsertRows(QModelIndex(), position, position + count - 1);
|
||||
|
||||
myData.insert(position, count, {});
|
||||
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ServerModel::removeRows(int position, int count, const QModelIndex &parent)
|
||||
{
|
||||
if (count == 0)
|
||||
return false;
|
||||
|
||||
beginRemoveRows(parent, position, position + count - 1);
|
||||
myData.erase(myData.begin()+position, myData.begin() + position + count);
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QModelIndex ServerModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
|
||||
QModelIndex index = QAbstractTableModel::index(row, column, parent);
|
||||
return index;
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
#ifndef SERVERMODEL_FONTMODEL_HPP
|
||||
#define SERVERMODEL_FONTMODEL_HPP
|
||||
|
||||
#include <QObject>
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
#include <QAbstractTableModel>
|
||||
#include <components/openmw-mp/Master/MasterData.hpp>
|
||||
|
||||
struct ServerData : public QueryData
|
||||
{
|
||||
QString addr;
|
||||
int ping;
|
||||
enum IDS
|
||||
{
|
||||
ADDR,
|
||||
HOSTNAME,
|
||||
PLAYERS,
|
||||
MAX_PLAYERS,
|
||||
PASSW,
|
||||
MODNAME,
|
||||
PING,
|
||||
VERSION,
|
||||
LAST
|
||||
};
|
||||
};
|
||||
|
||||
class ServerModel: public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ServerModel(QObject *parent = nullptr);
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_FINAL;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_FINAL;
|
||||
int columnCount(const QModelIndex &parent) const Q_DECL_FINAL;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) Q_DECL_FINAL;
|
||||
|
||||
bool insertRows(int row, int count, const QModelIndex &index = QModelIndex()) Q_DECL_FINAL;
|
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_FINAL;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_FINAL;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_FINAL;
|
||||
|
||||
|
||||
public:
|
||||
//QHash<int, QByteArray> roles;
|
||||
QVector<ServerData> myData;
|
||||
};
|
||||
|
||||
|
||||
#endif //SERVERMODEL_FONTMODEL_HPP
|
@ -1,15 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 07.05.17.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_TYPES_HPP
|
||||
#define OPENMW_TYPES_HPP
|
||||
|
||||
#include <QPair>
|
||||
#include <QString>
|
||||
|
||||
typedef QPair <QString, unsigned short> AddrPair;
|
||||
typedef QPair <int, AddrPair> ServerRow;
|
||||
|
||||
|
||||
#endif //OPENMW_TYPES_HPP
|
@ -1,53 +0,0 @@
|
||||
#include <QApplication>
|
||||
#include <components/settings/settings.hpp>
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#include <apps/browser/netutils/QueryClient.hpp>
|
||||
#include "MainWindow.hpp"
|
||||
|
||||
std::string loadSettings (Settings::Manager & settings)
|
||||
{
|
||||
Files::ConfigurationManager mCfgMgr;
|
||||
// Create the settings manager and load default settings file
|
||||
const std::string localdefault = (mCfgMgr.getLocalPath() / "tes3mp-client-default.cfg").string();
|
||||
const std::string globaldefault = (mCfgMgr.getGlobalPath() / "tes3mp-client-default.cfg").string();
|
||||
|
||||
// prefer local
|
||||
if (boost::filesystem::exists(localdefault))
|
||||
settings.loadDefault(localdefault);
|
||||
else if (boost::filesystem::exists(globaldefault))
|
||||
settings.loadDefault(globaldefault);
|
||||
else
|
||||
throw std::runtime_error ("No default settings file found! Make sure the file \"tes3mp-client-default.cfg\" was properly installed.");
|
||||
|
||||
// load user settings if they exist
|
||||
const std::string settingspath = (mCfgMgr.getUserConfigPath() / "tes3mp-client.cfg").string();
|
||||
if (boost::filesystem::exists(settingspath))
|
||||
settings.loadUser(settingspath);
|
||||
|
||||
return settingspath;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Settings::Manager mgr;
|
||||
|
||||
loadSettings(mgr);
|
||||
|
||||
std::string addr = mgr.getString("address", "Master");
|
||||
int port = mgr.getInt("port", "Master");
|
||||
|
||||
// Is this an attempt to connect to the official master server at the old port? If so,
|
||||
// redirect it to the correct port for the currently used fork of RakNet
|
||||
if (Misc::StringUtils::ciEqual(addr, "master.tes3mp.com") && port == 25560)
|
||||
port = 25561;
|
||||
|
||||
// initialize resources, if needed
|
||||
// Q_INIT_RESOURCE(resfile);
|
||||
|
||||
QueryClient::Get().SetServer(addr, port);
|
||||
QApplication app(argc, argv);
|
||||
MainWindow d;
|
||||
|
||||
d.show();
|
||||
return app.exec();
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 07.01.17.
|
||||
//
|
||||
|
||||
#include <RakPeer.h>
|
||||
#include <HTTPConnection2.h>
|
||||
#include <TCPInterface.h>
|
||||
#include <RakSleep.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "HTTPNetwork.hpp"
|
||||
|
||||
using namespace RakNet;
|
||||
|
||||
HTTPNetwork::HTTPNetwork(std::string addr, unsigned short port) : address(addr), port(port)
|
||||
{
|
||||
httpConnection = HTTPConnection2::GetInstance();
|
||||
tcpInterface = new TCPInterface;
|
||||
tcpInterface->Start(0, 64);
|
||||
tcpInterface->AttachPlugin(httpConnection);
|
||||
}
|
||||
|
||||
HTTPNetwork::~HTTPNetwork()
|
||||
{
|
||||
delete tcpInterface;
|
||||
}
|
||||
|
||||
std::string HTTPNetwork::answer()
|
||||
{
|
||||
RakNet::SystemAddress sa;
|
||||
RakNet::Packet *packet;
|
||||
RakNet::SystemAddress hostReceived;
|
||||
RakNet::RakString response;
|
||||
RakNet::RakString transmitted, hostTransmitted;
|
||||
int contentOffset = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
// This is kind of crappy, but for TCP plugins, always do HasCompletedConnectionAttempt,
|
||||
// then Receive(), then HasFailedConnectionAttempt(),HasLostConnection()
|
||||
sa = tcpInterface->HasCompletedConnectionAttempt();
|
||||
if (sa != RakNet::UNASSIGNED_SYSTEM_ADDRESS)
|
||||
printf("Connected to master server: %s\n", sa.ToString());
|
||||
|
||||
sa = tcpInterface->HasFailedConnectionAttempt();
|
||||
if (sa != RakNet::UNASSIGNED_SYSTEM_ADDRESS)
|
||||
{
|
||||
printf("Failed to connect to master server: %s\n", sa.ToString());
|
||||
return "FAIL_CONNECT";
|
||||
}
|
||||
sa = tcpInterface->HasLostConnection();
|
||||
if (sa != RakNet::UNASSIGNED_SYSTEM_ADDRESS)
|
||||
{
|
||||
printf("Lost connection to master server: %s\n", sa.ToString());
|
||||
return "LOST_CONNECTION";
|
||||
}
|
||||
|
||||
for (packet = tcpInterface->Receive(); packet; tcpInterface->DeallocatePacket(
|
||||
packet), packet = tcpInterface->Receive());
|
||||
|
||||
if (httpConnection->GetResponse(transmitted, hostTransmitted, response, hostReceived, contentOffset))
|
||||
{
|
||||
if (contentOffset < 0)
|
||||
return "NO_CONTENT"; // no content
|
||||
tcpInterface->CloseConnection(sa);
|
||||
|
||||
return (response.C_String() + contentOffset);
|
||||
}
|
||||
RakSleep(30);
|
||||
}
|
||||
}
|
||||
|
||||
std::string HTTPNetwork::getData(const char *uri)
|
||||
{
|
||||
RakNet::RakString createRequest = RakNet::RakString::FormatForGET(uri);
|
||||
|
||||
if (!httpConnection->TransmitRequest(createRequest, address.c_str(), port))
|
||||
return "UNKNOWN_ADDRESS";
|
||||
return answer();
|
||||
}
|
||||
|
||||
std::string HTTPNetwork::getDataPOST(const char *uri, const char* body, const char* contentType)
|
||||
{
|
||||
RakNet::RakString createRequest = RakNet::RakString::FormatForPOST(uri, contentType, body);
|
||||
|
||||
if (!httpConnection->TransmitRequest(createRequest, address.c_str(), port))
|
||||
return "UNKNOWN_ADDRESS";
|
||||
return answer();
|
||||
}
|
||||
|
||||
std::string HTTPNetwork::getDataPUT(const char *uri, const char* body, const char* contentType)
|
||||
{
|
||||
RakNet::RakString createRequest = RakNet::RakString::FormatForPUT(uri, contentType, body);
|
||||
|
||||
if (!httpConnection->TransmitRequest(createRequest, address.c_str(), port))
|
||||
return "UNKNOWN_ADDRESS";
|
||||
return answer();
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 07.01.17.
|
||||
//
|
||||
|
||||
#ifndef NEWLAUNCHER_HTTPNETWORK_HPP
|
||||
#define NEWLAUNCHER_HTTPNETWORK_HPP
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace RakNet
|
||||
{
|
||||
class TCPInterface;
|
||||
class HTTPConnection2;
|
||||
}
|
||||
|
||||
class HTTPNetwork
|
||||
{
|
||||
public:
|
||||
HTTPNetwork(std::string addr, unsigned short port);
|
||||
~HTTPNetwork();
|
||||
std::string getData(const char *uri);
|
||||
std::string getDataPOST(const char *uri, const char* body, const char* contentType = "application/json");
|
||||
std::string getDataPUT(const char *uri, const char* body, const char* contentType = "application/json");
|
||||
|
||||
protected:
|
||||
RakNet::TCPInterface *tcpInterface;
|
||||
RakNet::HTTPConnection2 *httpConnection;
|
||||
std::string address;
|
||||
unsigned short port;
|
||||
std::string answer();
|
||||
};
|
||||
|
||||
|
||||
#endif //NEWLAUNCHER_HTTPNETWORK_HPP
|
@ -1,212 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 24.04.17.
|
||||
//
|
||||
|
||||
#include "QueryClient.hpp"
|
||||
#include <RakSleep.h>
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
#include <iostream>
|
||||
#include <components/openmw-mp/Version.hpp>
|
||||
#include <qdebug.h>
|
||||
|
||||
using namespace RakNet;
|
||||
using namespace std;
|
||||
using namespace mwmp;
|
||||
|
||||
QueryClient::QueryClient()
|
||||
{
|
||||
peer = RakPeerInterface::GetInstance();
|
||||
pmq = new PacketMasterQuery(peer);
|
||||
pmu = new PacketMasterUpdate(peer);
|
||||
RakNet::SocketDescriptor sd;
|
||||
peer->Startup(8, &sd, 1);
|
||||
status = -1;
|
||||
}
|
||||
|
||||
QueryClient::~QueryClient()
|
||||
{
|
||||
delete pmq;
|
||||
delete pmu;
|
||||
RakPeerInterface::DestroyInstance(peer);
|
||||
}
|
||||
|
||||
void QueryClient::SetServer(const string &addr, unsigned short port)
|
||||
{
|
||||
masterAddr = SystemAddress(addr.c_str(), port);
|
||||
}
|
||||
|
||||
QueryClient &QueryClient::Get()
|
||||
{
|
||||
static QueryClient myInstance;
|
||||
return myInstance;
|
||||
}
|
||||
|
||||
map<SystemAddress, QueryData> QueryClient::Query()
|
||||
{
|
||||
map<SystemAddress, QueryData> query;
|
||||
BitStream bs;
|
||||
bs.Write((unsigned char) (ID_MASTER_QUERY));
|
||||
qDebug() << "Locking mutex in QueryClient::Query()";
|
||||
mxServers.lock();
|
||||
status = -1;
|
||||
int attempts = 3;
|
||||
do
|
||||
{
|
||||
if (Connect() == IS_NOT_CONNECTED)
|
||||
{
|
||||
qDebug() << "Unlocking mutex in QueryClient::Query()";
|
||||
mxServers.unlock();
|
||||
return query;
|
||||
}
|
||||
|
||||
int code = peer->Send(&bs, HIGH_PRIORITY, RELIABLE_ORDERED, CHANNEL_MASTER, masterAddr, false);
|
||||
|
||||
if (code == 0)
|
||||
{
|
||||
qDebug() << "Unlocking mutex in QueryClient::Query()";
|
||||
mxServers.unlock();
|
||||
return query;
|
||||
}
|
||||
|
||||
pmq->SetServers(&query);
|
||||
status = GetAnswer(ID_MASTER_QUERY);
|
||||
RakSleep(100);
|
||||
}
|
||||
while(status != ID_MASTER_QUERY && attempts-- > 0);
|
||||
if(status != ID_MASTER_QUERY)
|
||||
qDebug() << "Getting query was failed";
|
||||
qDebug() << "Unlocking mutex in QueryClient::Query()";
|
||||
peer->CloseConnection(masterAddr, true);
|
||||
mxServers.unlock();
|
||||
qDebug() <<"Answer" << (status == ID_MASTER_QUERY ? "ok." : "wrong.");
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
pair<SystemAddress, QueryData> QueryClient::Update(const RakNet::SystemAddress &addr)
|
||||
{
|
||||
qDebug() << "Locking mutex in QueryClient::Update(RakNet::SystemAddress addr)";
|
||||
pair<SystemAddress, QueryData> server;
|
||||
BitStream bs;
|
||||
bs.Write((unsigned char) (ID_MASTER_UPDATE));
|
||||
bs.Write(addr);
|
||||
|
||||
mxServers.lock();
|
||||
status = -1;
|
||||
int attempts = 3;
|
||||
pmu->SetServer(&server);
|
||||
do
|
||||
{
|
||||
if (Connect() == IS_NOT_CONNECTED)
|
||||
{
|
||||
qDebug() << IS_NOT_CONNECTED;
|
||||
qDebug() << "Unlocking mutex in QueryClient::Update(RakNet::SystemAddress addr)";
|
||||
mxServers.unlock();
|
||||
return server;
|
||||
}
|
||||
|
||||
peer->Send(&bs, HIGH_PRIORITY, RELIABLE_ORDERED, CHANNEL_MASTER, masterAddr, false);
|
||||
status = GetAnswer(ID_MASTER_UPDATE);
|
||||
RakSleep(100);
|
||||
}
|
||||
while(status != ID_MASTER_UPDATE && attempts-- > 0);
|
||||
if(status != ID_MASTER_UPDATE)
|
||||
qDebug() << "Getting update was failed";
|
||||
peer->CloseConnection(masterAddr, true);
|
||||
qDebug() << "Unlocking mutex in QueryClient::Update(RakNet::SystemAddress addr)";
|
||||
mxServers.unlock();
|
||||
return server;
|
||||
}
|
||||
|
||||
MASTER_PACKETS QueryClient::GetAnswer(MASTER_PACKETS waitingPacket)
|
||||
{
|
||||
RakNet::Packet *packet;
|
||||
bool update = true;
|
||||
unsigned char pid = 0;
|
||||
int id = -1;
|
||||
while (update)
|
||||
{
|
||||
for (packet = peer->Receive(); packet; peer->DeallocatePacket(packet), packet = peer->Receive())
|
||||
{
|
||||
BitStream data(packet->data, packet->length, false);
|
||||
pmq->SetReadStream(&data);
|
||||
pmu->SetReadStream(&data);
|
||||
data.Read(pid);
|
||||
switch(pid)
|
||||
{
|
||||
case ID_CONNECTION_LOST:
|
||||
qDebug() << "ID_CONNECTION_LOST";
|
||||
case ID_DISCONNECTION_NOTIFICATION:
|
||||
qDebug() << "Disconnected";
|
||||
update = false;
|
||||
break;
|
||||
case ID_MASTER_QUERY:
|
||||
qDebug() << "ID_MASTER_QUERY";
|
||||
if (waitingPacket == ID_MASTER_QUERY)
|
||||
pmq->Read();
|
||||
else
|
||||
qDebug() << "Got wrong packet";
|
||||
update = false;
|
||||
id = pid;
|
||||
break;
|
||||
case ID_MASTER_UPDATE:
|
||||
qDebug() << "ID_MASTER_UPDATE";
|
||||
if (waitingPacket == ID_MASTER_UPDATE)
|
||||
pmu->Read();
|
||||
else
|
||||
qDebug() << "Got wrong packet";
|
||||
update = false;
|
||||
id = pid;
|
||||
break;
|
||||
case ID_MASTER_ANNOUNCE:
|
||||
qDebug() << "ID_MASTER_ANNOUNCE";
|
||||
update = false;
|
||||
id = pid;
|
||||
break;
|
||||
case ID_CONNECTION_REQUEST_ACCEPTED:
|
||||
qDebug() << "ID_CONNECTION_REQUEST_ACCEPTED";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
RakSleep(500);
|
||||
}
|
||||
return (MASTER_PACKETS)(id);
|
||||
}
|
||||
|
||||
ConnectionState QueryClient::Connect()
|
||||
{
|
||||
|
||||
ConnectionAttemptResult car = peer->Connect(masterAddr.ToString(false), masterAddr.GetPort(), TES3MP_MASTERSERVER_PASSW,
|
||||
strlen(TES3MP_MASTERSERVER_PASSW), nullptr, 0, 5, 500);
|
||||
|
||||
while (true)
|
||||
{
|
||||
ConnectionState state = peer->GetConnectionState(masterAddr);
|
||||
switch (state)
|
||||
{
|
||||
case IS_CONNECTED:
|
||||
qDebug() << "Connected";
|
||||
return IS_CONNECTED;
|
||||
case IS_NOT_CONNECTED:
|
||||
case IS_DISCONNECTED:
|
||||
case IS_SILENTLY_DISCONNECTING:
|
||||
case IS_DISCONNECTING:
|
||||
{
|
||||
qDebug() << "Cannot connect to the master server. Code:"<< state;
|
||||
return IS_NOT_CONNECTED;
|
||||
}
|
||||
case IS_PENDING:
|
||||
case IS_CONNECTING:
|
||||
qDebug() << "Pending";
|
||||
break;
|
||||
}
|
||||
RakSleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
int QueryClient::Status()
|
||||
{
|
||||
return status;
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 24.04.17.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_QUERYCLIENT_HPP
|
||||
#define OPENMW_QUERYCLIENT_HPP
|
||||
|
||||
#include <string>
|
||||
#include <RakPeerInterface.h>
|
||||
#include <components/openmw-mp/Master/PacketMasterQuery.hpp>
|
||||
#include <components/openmw-mp/Master/PacketMasterUpdate.hpp>
|
||||
#include <apps/browser/ServerModel.hpp>
|
||||
#include <mutex>
|
||||
|
||||
class QueryClient
|
||||
{
|
||||
public:
|
||||
QueryClient(QueryClient const &) = delete;
|
||||
QueryClient(QueryClient &&) = delete;
|
||||
QueryClient &operator=(QueryClient const &) = delete;
|
||||
QueryClient &operator=(QueryClient &&) = delete;
|
||||
|
||||
static QueryClient &Get();
|
||||
void SetServer(const std::string &addr, unsigned short port);
|
||||
std::map<RakNet::SystemAddress, QueryData> Query();
|
||||
std::pair<RakNet::SystemAddress, QueryData> Update(const RakNet::SystemAddress &addr);
|
||||
int Status();
|
||||
private:
|
||||
RakNet::ConnectionState Connect();
|
||||
MASTER_PACKETS GetAnswer(MASTER_PACKETS packet);
|
||||
protected:
|
||||
QueryClient();
|
||||
~QueryClient();
|
||||
private:
|
||||
int status;
|
||||
RakNet::RakPeerInterface *peer;
|
||||
RakNet::SystemAddress masterAddr;
|
||||
mwmp::PacketMasterQuery *pmq;
|
||||
mwmp::PacketMasterUpdate *pmu;
|
||||
std::pair<RakNet::SystemAddress, ServerData> server;
|
||||
std::mutex mxServers;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //OPENMW_QUERYCLIENT_HPP
|
@ -1,167 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 07.01.17.
|
||||
//
|
||||
|
||||
#include <RakPeer.h>
|
||||
#include <MessageIdentifiers.h>
|
||||
#include <RakSleep.h>
|
||||
#include <GetTime.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <components/openmw-mp/Version.hpp>
|
||||
|
||||
#include "Utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
unsigned int PingRakNetServer(const char *addr, unsigned short port)
|
||||
{
|
||||
RakNet::Packet *packet;
|
||||
bool done = false;
|
||||
RakNet::TimeMS time = PING_UNREACHABLE;
|
||||
|
||||
RakNet::SocketDescriptor socketDescriptor{0, ""};
|
||||
RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
|
||||
peer->Startup(1, &socketDescriptor, 1);
|
||||
if (!peer->Ping(addr, port, false))
|
||||
return time;
|
||||
RakNet::TimeMS start = RakNet::GetTimeMS();
|
||||
while (!done)
|
||||
{
|
||||
RakNet::TimeMS now = RakNet::GetTimeMS();
|
||||
if (now - start >= PING_UNREACHABLE)
|
||||
break;
|
||||
|
||||
packet = peer->Receive();
|
||||
if (!packet)
|
||||
continue;
|
||||
|
||||
switch (packet->data[0])
|
||||
{
|
||||
case ID_DISCONNECTION_NOTIFICATION:
|
||||
case ID_CONNECTION_LOST:
|
||||
done = true;
|
||||
break;
|
||||
case ID_CONNECTED_PING:
|
||||
case ID_UNCONNECTED_PONG:
|
||||
{
|
||||
RakNet::BitStream bsIn(&packet->data[1], packet->length, false);
|
||||
bsIn.Read(time);
|
||||
time = now - time;
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
peer->DeallocatePacket(packet);
|
||||
}
|
||||
|
||||
peer->Shutdown(0);
|
||||
RakNet::RakPeerInterface::DestroyInstance(peer);
|
||||
return time > PING_UNREACHABLE ? PING_UNREACHABLE : time;
|
||||
}
|
||||
|
||||
ServerExtendedData getExtendedData(const char *addr, unsigned short port)
|
||||
{
|
||||
ServerExtendedData data;
|
||||
RakNet::SocketDescriptor socketDescriptor = {0, ""};
|
||||
RakNet::RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
|
||||
peer->Startup(1, &socketDescriptor, 1);
|
||||
|
||||
stringstream sstr;
|
||||
sstr << TES3MP_VERSION;
|
||||
sstr << TES3MP_PROTO_VERSION;
|
||||
|
||||
std::string msg;
|
||||
|
||||
if (peer->Connect(addr, port, sstr.str().c_str(), (int)(sstr.str().size()), nullptr, 0, 3, 500, 0) != RakNet::CONNECTION_ATTEMPT_STARTED)
|
||||
msg = "Connection attempt failed.\n";
|
||||
|
||||
|
||||
int queue = 0;
|
||||
while (queue == 0)
|
||||
{
|
||||
for (RakNet::Packet *packet = peer->Receive(); packet; peer->DeallocatePacket(
|
||||
packet), packet = peer->Receive())
|
||||
{
|
||||
switch (packet->data[0])
|
||||
{
|
||||
case ID_CONNECTION_ATTEMPT_FAILED:
|
||||
{
|
||||
msg = "Connection failed.\n"
|
||||
"Either the IP address is wrong or a firewall on either system is blocking\n"
|
||||
"UDP packets on the port you have chosen.";
|
||||
queue = -1;
|
||||
break;
|
||||
}
|
||||
case ID_INVALID_PASSWORD:
|
||||
{
|
||||
msg = "Connection failed.\n"
|
||||
"The client or server is outdated.\n";
|
||||
queue = -1;
|
||||
break;
|
||||
}
|
||||
case ID_CONNECTION_REQUEST_ACCEPTED:
|
||||
{
|
||||
msg = "Connection accepted.\n";
|
||||
queue = 1;
|
||||
break;
|
||||
}
|
||||
case ID_DISCONNECTION_NOTIFICATION:
|
||||
throw runtime_error("ID_DISCONNECTION_NOTIFICATION.\n");
|
||||
case ID_CONNECTION_BANNED:
|
||||
throw runtime_error("ID_CONNECTION_BANNED.\n");
|
||||
case ID_CONNECTION_LOST:
|
||||
throw runtime_error("ID_CONNECTION_LOST.\n");
|
||||
default:
|
||||
printf("Connection message with identifier %i has arrived in initialization.\n", packet->data[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
puts(msg.c_str());
|
||||
|
||||
if (queue == -1) // connection is failed
|
||||
return data;
|
||||
|
||||
{
|
||||
RakNet::BitStream bs;
|
||||
bs.Write((unsigned char) (ID_USER_PACKET_ENUM + 1));
|
||||
peer->Send(&bs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, RakNet::UNASSIGNED_SYSTEM_ADDRESS, true);
|
||||
}
|
||||
|
||||
RakNet::Packet *packet;
|
||||
bool done = false;
|
||||
while (!done)
|
||||
{
|
||||
for (packet = peer->Receive(); packet; peer->DeallocatePacket(packet), packet = peer->Receive())
|
||||
{
|
||||
if (packet->data[0] == (ID_USER_PACKET_ENUM + 1))
|
||||
{
|
||||
RakNet::BitStream bs(packet->data, packet->length, false);
|
||||
bs.IgnoreBytes(1);
|
||||
size_t length = 0;
|
||||
bs.Read(length);
|
||||
for (size_t i = 0; i < length; i++)
|
||||
{
|
||||
RakNet::RakString str;
|
||||
bs.Read(str);
|
||||
data.players.emplace_back(str.C_String());
|
||||
}
|
||||
bs.Read(length);
|
||||
for (size_t i = 0; i < length; i++)
|
||||
{
|
||||
RakNet::RakString str;
|
||||
bs.Read(str);
|
||||
data.plugins.emplace_back(str.C_String());
|
||||
}
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
peer->Shutdown(0);
|
||||
RakSleep(10);
|
||||
RakNet::RakPeerInterface::DestroyInstance(peer);
|
||||
return data;
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 07.01.17.
|
||||
//
|
||||
|
||||
#ifndef NEWLAUNCHER_PING_HPP
|
||||
#define NEWLAUNCHER_PING_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
||||
#define PING_UNREACHABLE 999
|
||||
|
||||
unsigned int PingRakNetServer(const char *addr, unsigned short port);
|
||||
|
||||
struct ServerExtendedData
|
||||
{
|
||||
std::vector<std::string> players;
|
||||
std::vector<std::string> plugins;
|
||||
};
|
||||
|
||||
ServerExtendedData getExtendedData(const char *addr, unsigned short port);
|
||||
|
||||
#endif //NEWLAUNCHER_PING_HPP
|
@ -1,18 +0,0 @@
|
||||
#include "importproj.h"
|
||||
|
||||
#include <components/esm/esmreader.hpp>
|
||||
|
||||
namespace ESSImport
|
||||
{
|
||||
|
||||
void ESSImport::PROJ::load(ESM::ESMReader& esm)
|
||||
{
|
||||
while (esm.isNextSub("PNAM"))
|
||||
{
|
||||
PNAM pnam;
|
||||
esm.getHT(pnam);
|
||||
mProjectiles.push_back(pnam);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
#ifndef OPENMW_ESSIMPORT_IMPORTPROJ_H
|
||||
#define OPENMW_ESSIMPORT_IMPORTPROJ_H
|
||||
|
||||
#include <vector>
|
||||
#include <components/esm/esmcommon.hpp>
|
||||
#include <components/esm/util.hpp>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
}
|
||||
|
||||
namespace ESSImport
|
||||
{
|
||||
|
||||
struct PROJ
|
||||
{
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
struct PNAM // 184 bytes
|
||||
{
|
||||
float mAttackStrength;
|
||||
float mSpeed;
|
||||
unsigned char mUnknown[4*2];
|
||||
float mFlightTime;
|
||||
int mSplmIndex; // reference to a SPLM record (0 for ballistic projectiles)
|
||||
unsigned char mUnknown2[4];
|
||||
ESM::Vector3 mVelocity;
|
||||
ESM::Vector3 mPosition;
|
||||
unsigned char mUnknown3[4*9];
|
||||
ESM::NAME32 mActorId; // indexed refID (with the exception of "PlayerSaveGame")
|
||||
ESM::NAME32 mArrowId;
|
||||
ESM::NAME32 mBowId;
|
||||
|
||||
bool isMagic() const { return mSplmIndex != 0; }
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
std::vector<PNAM> mProjectiles;
|
||||
|
||||
void load(ESM::ESMReader& esm);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,43 +0,0 @@
|
||||
#include "importsplm.h"
|
||||
|
||||
#include <components/esm/esmreader.hpp>
|
||||
|
||||
namespace ESSImport
|
||||
{
|
||||
|
||||
void SPLM::load(ESM::ESMReader& esm)
|
||||
{
|
||||
while (esm.isNextSub("NAME"))
|
||||
{
|
||||
ActiveSpell spell;
|
||||
esm.getHT(spell.mIndex);
|
||||
esm.getHNT(spell.mSPDT, "SPDT");
|
||||
spell.mTarget = esm.getHNOString("TNAM");
|
||||
|
||||
while (esm.isNextSub("NPDT"))
|
||||
{
|
||||
ActiveEffect effect;
|
||||
esm.getHT(effect.mNPDT);
|
||||
|
||||
// Effect-specific subrecords can follow:
|
||||
// - INAM for disintegration and bound effects
|
||||
// - CNAM for summoning and command effects
|
||||
// - VNAM for vampirism
|
||||
// NOTE: There can be multiple INAMs per effect.
|
||||
// TODO: Needs more research.
|
||||
|
||||
esm.skipHSubUntil("NAM0"); // sentinel
|
||||
esm.getSubName();
|
||||
esm.skipHSub();
|
||||
|
||||
spell.mActiveEffects.push_back(effect);
|
||||
}
|
||||
|
||||
unsigned char xnam; // sentinel
|
||||
esm.getHNT(xnam, "XNAM");
|
||||
|
||||
mActiveSpells.push_back(spell);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
#ifndef OPENMW_ESSIMPORT_IMPORTSPLM_H
|
||||
#define OPENMW_ESSIMPORT_IMPORTSPLM_H
|
||||
|
||||
#include <vector>
|
||||
#include <components/esm/esmcommon.hpp>
|
||||
#include <components/esm/util.hpp>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
}
|
||||
|
||||
namespace ESSImport
|
||||
{
|
||||
|
||||
struct SPLM
|
||||
{
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
struct SPDT // 160 bytes
|
||||
{
|
||||
int mType; // 1 = spell, 2 = enchantment, 3 = potion
|
||||
ESM::NAME32 mId; // base ID of a spell/enchantment/potion
|
||||
unsigned char mUnknown[4*4];
|
||||
ESM::NAME32 mCasterId;
|
||||
ESM::NAME32 mSourceId; // empty for spells
|
||||
unsigned char mUnknown2[4*11];
|
||||
};
|
||||
|
||||
struct NPDT // 56 bytes
|
||||
{
|
||||
ESM::NAME32 mAffectedActorId;
|
||||
unsigned char mUnknown[4*2];
|
||||
int mMagnitude;
|
||||
float mSecondsActive;
|
||||
unsigned char mUnknown2[4*2];
|
||||
};
|
||||
|
||||
struct INAM // 40 bytes
|
||||
{
|
||||
int mUnknown;
|
||||
unsigned char mUnknown2;
|
||||
ESM::FIXED_STRING<35> mItemId; // disintegrated item / bound item / item to re-equip after expiration
|
||||
};
|
||||
|
||||
struct CNAM // 36 bytes
|
||||
{
|
||||
int mUnknown; // seems to always be 0
|
||||
ESM::NAME32 mSummonedOrCommandedActor[32];
|
||||
};
|
||||
|
||||
struct VNAM // 4 bytes
|
||||
{
|
||||
int mUnknown;
|
||||
};
|
||||
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
struct ActiveEffect
|
||||
{
|
||||
NPDT mNPDT;
|
||||
};
|
||||
|
||||
struct ActiveSpell
|
||||
{
|
||||
int mIndex;
|
||||
SPDT mSPDT;
|
||||
std::string mTarget;
|
||||
std::vector<ActiveEffect> mActiveEffects;
|
||||
};
|
||||
|
||||
std::vector<ActiveSpell> mActiveSpells;
|
||||
|
||||
void load(ESM::ESMReader& esm);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,176 +0,0 @@
|
||||
#include "advancedpage.hpp"
|
||||
|
||||
#include <components/config/gamesettings.hpp>
|
||||
#include <components/config/launchersettings.hpp>
|
||||
#include <QFileDialog>
|
||||
#include <QCompleter>
|
||||
#include <components/contentselector/view/contentselector.hpp>
|
||||
#include <components/contentselector/model/esmfile.hpp>
|
||||
|
||||
Launcher::AdvancedPage::AdvancedPage(Files::ConfigurationManager &cfg,
|
||||
Config::GameSettings &gameSettings,
|
||||
Settings::Manager &engineSettings, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, mCfgMgr(cfg)
|
||||
, mGameSettings(gameSettings)
|
||||
, mEngineSettings(engineSettings)
|
||||
{
|
||||
setObjectName ("AdvancedPage");
|
||||
setupUi(this);
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
void Launcher::AdvancedPage::loadCellsForAutocomplete(QStringList cellNames) {
|
||||
// Set up an auto-completer for the "Start default character at" field
|
||||
auto *completer = new QCompleter(cellNames);
|
||||
completer->setCompletionMode(QCompleter::PopupCompletion);
|
||||
completer->setCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive);
|
||||
startDefaultCharacterAtField->setCompleter(completer);
|
||||
|
||||
}
|
||||
|
||||
void Launcher::AdvancedPage::on_skipMenuCheckBox_stateChanged(int state) {
|
||||
startDefaultCharacterAtLabel->setEnabled(state == Qt::Checked);
|
||||
startDefaultCharacterAtField->setEnabled(state == Qt::Checked);
|
||||
}
|
||||
|
||||
void Launcher::AdvancedPage::on_runScriptAfterStartupBrowseButton_clicked()
|
||||
{
|
||||
QString scriptFile = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
QObject::tr("Select script file"),
|
||||
QDir::currentPath(),
|
||||
QString(tr("Text file (*.txt)")));
|
||||
|
||||
if (scriptFile.isEmpty())
|
||||
return;
|
||||
|
||||
QFileInfo info(scriptFile);
|
||||
|
||||
if (!info.exists() || !info.isReadable())
|
||||
return;
|
||||
|
||||
const QString path(QDir::toNativeSeparators(info.absoluteFilePath()));
|
||||
runScriptAfterStartupField->setText(path);
|
||||
}
|
||||
|
||||
bool Launcher::AdvancedPage::loadSettings()
|
||||
{
|
||||
// Testing
|
||||
bool skipMenu = mGameSettings.value("skip-menu").toInt() == 1;
|
||||
if (skipMenu) {
|
||||
skipMenuCheckBox->setCheckState(Qt::Checked);
|
||||
}
|
||||
startDefaultCharacterAtLabel->setEnabled(skipMenu);
|
||||
startDefaultCharacterAtField->setEnabled(skipMenu);
|
||||
|
||||
startDefaultCharacterAtField->setText(mGameSettings.value("start"));
|
||||
runScriptAfterStartupField->setText(mGameSettings.value("script-run"));
|
||||
|
||||
// Game Settings
|
||||
loadSettingBool(canLootDuringDeathAnimationCheckBox, "can loot during death animation", "Game");
|
||||
loadSettingBool(followersAttackOnSightCheckBox, "followers attack on sight", "Game");
|
||||
loadSettingBool(preventMerchantEquippingCheckBox, "prevent merchant equipping", "Game");
|
||||
loadSettingBool(rebalanceSoulGemValuesCheckBox, "rebalance soul gem values", "Game");
|
||||
loadSettingBool(chargeForEveryFollowerCheckBox, "charge for every follower travelling", "Game");
|
||||
loadSettingBool(enchantedWeaponsMagicalCheckBox, "enchanted weapons are magical", "Game");
|
||||
loadSettingBool(permanentBarterDispositionChangeCheckBox, "barter disposition change is permanent", "Game");
|
||||
|
||||
// Input Settings
|
||||
loadSettingBool(allowThirdPersonZoomCheckBox, "allow third person zoom", "Input");
|
||||
loadSettingBool(grabCursorCheckBox, "grab cursor", "Input");
|
||||
loadSettingBool(toggleSneakCheckBox, "toggle sneak", "Input");
|
||||
|
||||
// Saves Settings
|
||||
loadSettingBool(timePlayedCheckbox, "timeplayed", "Saves");
|
||||
maximumQuicksavesComboBox->setValue(mEngineSettings.getInt("max quicksaves", "Saves"));
|
||||
|
||||
// User Interface Settings
|
||||
loadSettingBool(showEffectDurationCheckBox, "show effect duration", "Game");
|
||||
loadSettingBool(showEnchantChanceCheckBox, "show enchant chance", "Game");
|
||||
loadSettingBool(showMeleeInfoCheckBox, "show melee info", "Game");
|
||||
loadSettingBool(showProjectileDamageCheckBox, "show projectile damage", "Game");
|
||||
int showOwnedIndex = mEngineSettings.getInt("show owned", "Game");
|
||||
// Match the index with the option (only 0, 1, 2, or 3 are valid). Will default to 0 if invalid.
|
||||
if (showOwnedIndex >= 0 && showOwnedIndex <= 3)
|
||||
showOwnedComboBox->setCurrentIndex(showOwnedIndex);
|
||||
|
||||
// Other Settings
|
||||
QString screenshotFormatString = QString::fromStdString(mEngineSettings.getString("screenshot format", "General")).toUpper();
|
||||
if (screenshotFormatComboBox->findText(screenshotFormatString) == -1)
|
||||
screenshotFormatComboBox->addItem(screenshotFormatString);
|
||||
screenshotFormatComboBox->setCurrentIndex(screenshotFormatComboBox->findText(screenshotFormatString));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Launcher::AdvancedPage::saveSettings()
|
||||
{
|
||||
// Ensure we only set the new settings if they changed. This is to avoid cluttering the
|
||||
// user settings file (which by definition should only contain settings the user has touched)
|
||||
|
||||
// Testing
|
||||
int skipMenu = skipMenuCheckBox->checkState() == Qt::Checked;
|
||||
if (skipMenu != mGameSettings.value("skip-menu").toInt())
|
||||
mGameSettings.setValue("skip-menu", QString::number(skipMenu));
|
||||
|
||||
QString startCell = startDefaultCharacterAtField->text();
|
||||
if (startCell != mGameSettings.value("start")) {
|
||||
mGameSettings.setValue("start", startCell);
|
||||
}
|
||||
QString scriptRun = runScriptAfterStartupField->text();
|
||||
if (scriptRun != mGameSettings.value("script-run"))
|
||||
mGameSettings.setValue("script-run", scriptRun);
|
||||
|
||||
// Game Settings
|
||||
saveSettingBool(canLootDuringDeathAnimationCheckBox, "can loot during death animation", "Game");
|
||||
saveSettingBool(followersAttackOnSightCheckBox, "followers attack on sight", "Game");
|
||||
saveSettingBool(preventMerchantEquippingCheckBox, "prevent merchant equipping", "Game");
|
||||
saveSettingBool(rebalanceSoulGemValuesCheckBox, "rebalance soul gem values", "Game");
|
||||
saveSettingBool(chargeForEveryFollowerCheckBox, "charge for every follower travelling", "Game");
|
||||
saveSettingBool(enchantedWeaponsMagicalCheckBox, "enchanted weapons are magical", "Game");
|
||||
saveSettingBool(permanentBarterDispositionChangeCheckBox, "barter disposition change is permanent", "Game");
|
||||
|
||||
// Input Settings
|
||||
saveSettingBool(allowThirdPersonZoomCheckBox, "allow third person zoom", "Input");
|
||||
saveSettingBool(grabCursorCheckBox, "grab cursor", "Input");
|
||||
saveSettingBool(toggleSneakCheckBox, "toggle sneak", "Input");
|
||||
|
||||
// Saves Settings
|
||||
saveSettingBool(timePlayedCheckbox, "timeplayed", "Saves");
|
||||
int maximumQuicksaves = maximumQuicksavesComboBox->value();
|
||||
if (maximumQuicksaves != mEngineSettings.getInt("max quicksaves", "Saves")) {
|
||||
mEngineSettings.setInt("max quicksaves", "Saves", maximumQuicksaves);
|
||||
}
|
||||
|
||||
// User Interface Settings
|
||||
saveSettingBool(showEffectDurationCheckBox, "show effect duration", "Game");
|
||||
saveSettingBool(showEnchantChanceCheckBox, "show enchant chance", "Game");
|
||||
saveSettingBool(showMeleeInfoCheckBox, "show melee info", "Game");
|
||||
saveSettingBool(showProjectileDamageCheckBox, "show projectile damage", "Game");
|
||||
int showOwnedCurrentIndex = showOwnedComboBox->currentIndex();
|
||||
if (showOwnedCurrentIndex != mEngineSettings.getInt("show owned", "Game"))
|
||||
mEngineSettings.setInt("show owned", "Game", showOwnedCurrentIndex);
|
||||
|
||||
// Other Settings
|
||||
std::string screenshotFormatString = screenshotFormatComboBox->currentText().toLower().toStdString();
|
||||
if (screenshotFormatString != mEngineSettings.getString("screenshot format", "General"))
|
||||
mEngineSettings.setString("screenshot format", "General", screenshotFormatString);
|
||||
}
|
||||
|
||||
void Launcher::AdvancedPage::loadSettingBool(QCheckBox *checkbox, const std::string &setting, const std::string &group) {
|
||||
if (mEngineSettings.getBool(setting, group))
|
||||
checkbox->setCheckState(Qt::Checked);
|
||||
}
|
||||
|
||||
void Launcher::AdvancedPage::saveSettingBool(QCheckBox *checkbox, const std::string &setting, const std::string &group) {
|
||||
bool cValue = checkbox->checkState();
|
||||
if (cValue != mEngineSettings.getBool(setting, group))
|
||||
mEngineSettings.setBool(setting, group, cValue);
|
||||
}
|
||||
|
||||
void Launcher::AdvancedPage::slotLoadedCellsChanged(QStringList cellNames)
|
||||
{
|
||||
loadCellsForAutocomplete(cellNames);
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
#ifndef ADVANCEDPAGE_H
|
||||
#define ADVANCEDPAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "ui_advancedpage.h"
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
namespace Files { struct ConfigurationManager; }
|
||||
namespace Config { class GameSettings; }
|
||||
|
||||
namespace Launcher
|
||||
{
|
||||
class AdvancedPage : public QWidget, private Ui::AdvancedPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AdvancedPage(Files::ConfigurationManager &cfg, Config::GameSettings &gameSettings,
|
||||
Settings::Manager &engineSettings, QWidget *parent = 0);
|
||||
|
||||
bool loadSettings();
|
||||
void saveSettings();
|
||||
|
||||
public slots:
|
||||
void slotLoadedCellsChanged(QStringList cellNames);
|
||||
|
||||
private slots:
|
||||
void on_skipMenuCheckBox_stateChanged(int state);
|
||||
void on_runScriptAfterStartupBrowseButton_clicked();
|
||||
|
||||
private:
|
||||
Files::ConfigurationManager &mCfgMgr;
|
||||
Config::GameSettings &mGameSettings;
|
||||
Settings::Manager &mEngineSettings;
|
||||
|
||||
/**
|
||||
* Load the cells associated with the given content files for use in autocomplete
|
||||
* @param filePaths the file paths of the content files to be examined
|
||||
*/
|
||||
void loadCellsForAutocomplete(QStringList filePaths);
|
||||
void loadSettingBool(QCheckBox *checkbox, const std::string& setting, const std::string& group);
|
||||
void saveSettingBool(QCheckBox *checkbox, const std::string& setting, const std::string& group);
|
||||
};
|
||||
}
|
||||
#endif
|
@ -1,48 +0,0 @@
|
||||
#include "cellnameloader.hpp"
|
||||
|
||||
#include <components/esm/loadcell.hpp>
|
||||
#include <components/contentselector/view/contentselector.hpp>
|
||||
|
||||
QSet<QString> CellNameLoader::getCellNames(QStringList &contentPaths)
|
||||
{
|
||||
QSet<QString> cellNames;
|
||||
ESM::ESMReader esmReader;
|
||||
|
||||
// Loop through all content files
|
||||
for (auto &contentPath : contentPaths) {
|
||||
esmReader.open(contentPath.toStdString());
|
||||
|
||||
// Loop through all records
|
||||
while(esmReader.hasMoreRecs())
|
||||
{
|
||||
ESM::NAME recordName = esmReader.getRecName();
|
||||
esmReader.getRecHeader();
|
||||
|
||||
if (isCellRecord(recordName)) {
|
||||
QString cellName = getCellName(esmReader);
|
||||
if (!cellName.isEmpty()) {
|
||||
cellNames.insert(cellName);
|
||||
}
|
||||
}
|
||||
|
||||
// Stop loading content for this record and continue to the next
|
||||
esmReader.skipRecord();
|
||||
}
|
||||
}
|
||||
|
||||
return cellNames;
|
||||
}
|
||||
|
||||
bool CellNameLoader::isCellRecord(ESM::NAME &recordName)
|
||||
{
|
||||
return recordName.intval == ESM::REC_CELL;
|
||||
}
|
||||
|
||||
QString CellNameLoader::getCellName(ESM::ESMReader &esmReader)
|
||||
{
|
||||
ESM::Cell cell;
|
||||
bool isDeleted = false;
|
||||
cell.loadNameAndData(esmReader, isDeleted);
|
||||
|
||||
return QString::fromStdString(cell.mName);
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
#ifndef OPENMW_CELLNAMELOADER_H
|
||||
#define OPENMW_CELLNAMELOADER_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
|
||||
#include <components/esm/esmreader.hpp>
|
||||
|
||||
namespace ESM {class ESMReader; struct Cell;}
|
||||
namespace ContentSelectorView {class ContentSelector;}
|
||||
|
||||
class CellNameLoader {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Returns the names of all cells contained within the given content files
|
||||
* @param contentPaths the file paths of each content file to be examined
|
||||
* @return the names of all cells
|
||||
*/
|
||||
QSet<QString> getCellNames(QStringList &contentPaths);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Returns whether or not the given record is of type "Cell"
|
||||
* @param name The name associated with the record
|
||||
* @return whether or not the given record is of type "Cell"
|
||||
*/
|
||||
bool isCellRecord(ESM::NAME &name);
|
||||
|
||||
/**
|
||||
* Returns the name of the cell
|
||||
* @param esmReader the reader currently pointed to a loaded cell
|
||||
* @return the name of the cell
|
||||
*/
|
||||
QString getCellName(ESM::ESMReader &esmReader);
|
||||
};
|
||||
|
||||
|
||||
#endif //OPENMW_CELLNAMELOADER_H
|
@ -1,32 +0,0 @@
|
||||
project(masterserver)
|
||||
|
||||
#set(CMAKE_CXX_STANDARD 14)
|
||||
add_definitions(-std=gnu++14)
|
||||
|
||||
include_directories("./")
|
||||
|
||||
set(SOURCE_FILES main.cpp MasterServer.cpp MasterServer.hpp RestServer.cpp RestServer.hpp)
|
||||
|
||||
add_executable(masterserver ${SOURCE_FILES})
|
||||
target_link_libraries(masterserver ${RakNet_LIBRARY} components)
|
||||
|
||||
option(BUILD_MASTER_TEST "build master server test program" OFF)
|
||||
|
||||
if(BUILD_MASTER_TEST)
|
||||
add_executable(ServerTest ServerTest.cpp)
|
||||
target_link_libraries(ServerTest ${RakNet_LIBRARY} components)
|
||||
endif()
|
||||
|
||||
if (UNIX)
|
||||
# Fix for not visible pthreads functions for linker with glibc 2.15
|
||||
if(NOT APPLE)
|
||||
target_link_libraries(masterserver ${CMAKE_THREAD_LIBS_INIT})
|
||||
if(BUILD_MASTER_TEST)
|
||||
target_link_libraries(ServerTest ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
endif(NOT APPLE)
|
||||
endif(UNIX)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(masterserver wsock32)
|
||||
endif(WIN32)
|
@ -1,236 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 21.04.17.
|
||||
//
|
||||
|
||||
#include <RakPeerInterface.h>
|
||||
#include <RakSleep.h>
|
||||
#include <BitStream.h>
|
||||
#include <iostream>
|
||||
#include "MasterServer.hpp"
|
||||
|
||||
#include <components/openmw-mp/Master/PacketMasterQuery.hpp>
|
||||
#include <components/openmw-mp/Master/PacketMasterUpdate.hpp>
|
||||
#include <components/openmw-mp/Master/PacketMasterAnnounce.hpp>
|
||||
#include <components/openmw-mp/Version.hpp>
|
||||
|
||||
using namespace RakNet;
|
||||
using namespace std;
|
||||
using namespace mwmp;
|
||||
using namespace chrono;
|
||||
|
||||
MasterServer::MasterServer(unsigned short maxConnections, unsigned short port)
|
||||
{
|
||||
peer = RakPeerInterface::GetInstance();
|
||||
sockdescr = SocketDescriptor(port, 0);
|
||||
peer->Startup(maxConnections, &sockdescr, 1, 1000);
|
||||
|
||||
peer->SetMaximumIncomingConnections(maxConnections);
|
||||
peer->SetIncomingPassword(TES3MP_MASTERSERVER_PASSW, (int) strlen(TES3MP_MASTERSERVER_PASSW));
|
||||
run = false;
|
||||
}
|
||||
|
||||
MasterServer::~MasterServer()
|
||||
{
|
||||
Stop(true);
|
||||
}
|
||||
|
||||
using namespace chrono;
|
||||
|
||||
void MasterServer::Thread()
|
||||
{
|
||||
unsigned char packetId = 0;
|
||||
|
||||
auto startTime = chrono::steady_clock::now();
|
||||
|
||||
BitStream send;
|
||||
PacketMasterQuery pmq(peer);
|
||||
pmq.SetSendStream(&send);
|
||||
|
||||
PacketMasterUpdate pmu(peer);
|
||||
pmu.SetSendStream(&send);
|
||||
|
||||
PacketMasterAnnounce pma(peer);
|
||||
pma.SetSendStream(&send);
|
||||
|
||||
while (run)
|
||||
{
|
||||
Packet *packet = peer->Receive();
|
||||
|
||||
auto now = steady_clock::now();
|
||||
if (now - startTime >= 60s)
|
||||
{
|
||||
startTime = steady_clock::now();
|
||||
for (auto it = servers.begin(); it != servers.end();)
|
||||
{
|
||||
|
||||
if (it->second.lastUpdate + 60s <= now)
|
||||
servers.erase(it++);
|
||||
else ++it;
|
||||
}
|
||||
for(auto id = pendingACKs.begin(); id != pendingACKs.end();)
|
||||
{
|
||||
if(now - id->second >= 30s)
|
||||
{
|
||||
cout << "timeout: " << peer->GetSystemAddressFromGuid(id->first).ToString() << endl;
|
||||
peer->CloseConnection(id->first, true);
|
||||
id = pendingACKs.erase(id);
|
||||
}
|
||||
else
|
||||
++id;
|
||||
}
|
||||
}
|
||||
|
||||
if (packet == nullptr)
|
||||
RakSleep(10);
|
||||
else
|
||||
for (; packet; peer->DeallocatePacket(packet), packet = peer->Receive())
|
||||
{
|
||||
BitStream data(packet->data, packet->length, false);
|
||||
data.Read(packetId);
|
||||
switch (packetId)
|
||||
{
|
||||
case ID_NEW_INCOMING_CONNECTION:
|
||||
cout << "New incoming connection: " << packet->systemAddress.ToString() << endl;
|
||||
break;
|
||||
case ID_DISCONNECTION_NOTIFICATION:
|
||||
cout << "Disconnected: " << packet->systemAddress.ToString() << endl;
|
||||
break;
|
||||
case ID_CONNECTION_LOST:
|
||||
cout << "Connection lost: " << packet->systemAddress.ToString() << endl;
|
||||
break;
|
||||
case ID_MASTER_QUERY:
|
||||
{
|
||||
pmq.SetServers(reinterpret_cast<map<SystemAddress, QueryData> *>(&servers));
|
||||
pmq.Send(packet->systemAddress);
|
||||
pendingACKs[packet->guid] = steady_clock::now();
|
||||
|
||||
cout << "Sent info about all " << servers.size() << " servers to "
|
||||
<< packet->systemAddress.ToString() << endl;
|
||||
break;
|
||||
}
|
||||
case ID_MASTER_UPDATE:
|
||||
{
|
||||
SystemAddress addr;
|
||||
data.Read(addr); // update 1 server
|
||||
|
||||
ServerIter it = servers.find(addr);
|
||||
if (it != servers.end())
|
||||
{
|
||||
pair<SystemAddress, QueryData> pairPtr(it->first, static_cast<QueryData>(it->second));
|
||||
pmu.SetServer(&pairPtr);
|
||||
pmu.Send(packet->systemAddress);
|
||||
pendingACKs[packet->guid] = steady_clock::now();
|
||||
cout << "Sent info about " << addr.ToString() << " to " << packet->systemAddress.ToString()
|
||||
<< endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ID_MASTER_ANNOUNCE:
|
||||
{
|
||||
ServerIter iter = servers.find(packet->systemAddress);
|
||||
|
||||
pma.SetReadStream(&data);
|
||||
SServer server;
|
||||
pma.SetServer(&server);
|
||||
pma.Read();
|
||||
|
||||
auto keepAliveFunc = [&]() {
|
||||
iter->second.lastUpdate = now;
|
||||
pma.SetFunc(PacketMasterAnnounce::FUNCTION_KEEP);
|
||||
pma.Send(packet->systemAddress);
|
||||
pendingACKs[packet->guid] = steady_clock::now();
|
||||
};
|
||||
|
||||
if (iter != servers.end())
|
||||
{
|
||||
if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_DELETE)
|
||||
{
|
||||
servers.erase(iter);
|
||||
cout << "Deleted";
|
||||
pma.Send(packet->systemAddress);
|
||||
pendingACKs[packet->guid] = steady_clock::now();
|
||||
}
|
||||
else if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_ANNOUNCE)
|
||||
{
|
||||
cout << "Updated";
|
||||
iter->second = server;
|
||||
keepAliveFunc();
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Keeping alive";
|
||||
keepAliveFunc();
|
||||
}
|
||||
}
|
||||
else if (pma.GetFunc() == PacketMasterAnnounce::FUNCTION_ANNOUNCE)
|
||||
{
|
||||
cout << "Added";
|
||||
iter = servers.insert({packet->systemAddress, server}).first;
|
||||
keepAliveFunc();
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Unknown";
|
||||
pma.SetFunc(PacketMasterAnnounce::FUNCTION_DELETE);
|
||||
pma.Send(packet->systemAddress);
|
||||
pendingACKs[packet->guid] = steady_clock::now();
|
||||
}
|
||||
cout << " server " << packet->systemAddress.ToString() << endl;
|
||||
break;
|
||||
}
|
||||
case ID_SND_RECEIPT_ACKED:
|
||||
uint32_t num;
|
||||
memcpy(&num, packet->data+1, 4);
|
||||
cout << "Packet with id " << num << " was delivered." << endl;
|
||||
pendingACKs.erase(packet->guid);
|
||||
peer->CloseConnection(packet->systemAddress, true);
|
||||
break;
|
||||
default:
|
||||
cout << "Wrong packet. id " << (unsigned) packet->data[0] << " packet length " << packet->length << " from " << packet->systemAddress.ToString() << endl;
|
||||
peer->CloseConnection(packet->systemAddress, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
peer->Shutdown(1000);
|
||||
RakPeerInterface::DestroyInstance(peer);
|
||||
cout << "Server thread stopped" << endl;
|
||||
}
|
||||
|
||||
void MasterServer::Start()
|
||||
{
|
||||
if (!run)
|
||||
{
|
||||
run = true;
|
||||
tMasterThread = thread(&MasterServer::Thread, this);
|
||||
cout << "Started" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void MasterServer::Stop(bool wait)
|
||||
{
|
||||
if (run)
|
||||
{
|
||||
run = false;
|
||||
if (wait && tMasterThread.joinable())
|
||||
tMasterThread.join();
|
||||
}
|
||||
}
|
||||
|
||||
bool MasterServer::isRunning()
|
||||
{
|
||||
return run;
|
||||
}
|
||||
|
||||
void MasterServer::Wait()
|
||||
{
|
||||
if (run)
|
||||
{
|
||||
if (tMasterThread.joinable())
|
||||
tMasterThread.join();
|
||||
}
|
||||
}
|
||||
|
||||
MasterServer::ServerMap *MasterServer::GetServers()
|
||||
{
|
||||
return &servers;
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 21.04.17.
|
||||
//
|
||||
|
||||
#ifndef NEWMASTERPROTO_MASTERSERVER_HPP
|
||||
#define NEWMASTERPROTO_MASTERSERVER_HPP
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <RakPeerInterface.h>
|
||||
#include <components/openmw-mp/Master/MasterData.hpp>
|
||||
|
||||
class MasterServer
|
||||
{
|
||||
public:
|
||||
struct Ban
|
||||
{
|
||||
RakNet::SystemAddress sa;
|
||||
bool permanent;
|
||||
struct Date
|
||||
{
|
||||
} date;
|
||||
};
|
||||
struct SServer : QueryData
|
||||
{
|
||||
std::chrono::steady_clock::time_point lastUpdate;
|
||||
};
|
||||
typedef std::map<RakNet::SystemAddress, SServer> ServerMap;
|
||||
//typedef ServerMap::const_iterator ServerCIter;
|
||||
typedef ServerMap::iterator ServerIter;
|
||||
|
||||
MasterServer(unsigned short maxConnections, unsigned short port);
|
||||
~MasterServer();
|
||||
|
||||
void Start();
|
||||
void Stop(bool wait = false);
|
||||
bool isRunning();
|
||||
void Wait();
|
||||
|
||||
ServerMap* GetServers();
|
||||
|
||||
private:
|
||||
void Thread();
|
||||
|
||||
private:
|
||||
std::thread tMasterThread;
|
||||
RakNet::RakPeerInterface* peer;
|
||||
RakNet::SocketDescriptor sockdescr;
|
||||
ServerMap servers;
|
||||
bool run;
|
||||
std::map<RakNet::RakNetGUID, std::chrono::steady_clock::time_point> pendingACKs;
|
||||
};
|
||||
|
||||
|
||||
#endif //NEWMASTERPROTO_MASTERSERVER_HPP
|
@ -1,192 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 13.05.17.
|
||||
//
|
||||
|
||||
#include "RestServer.hpp"
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace chrono;
|
||||
using namespace boost::property_tree;
|
||||
|
||||
static string response201 = "HTTP/1.1 201 Created\r\nContent-Length: 7\r\n\r\nCreated";
|
||||
static string response202 = "HTTP/1.1 202 Accepted\r\nContent-Length: 8\r\n\r\nAccepted";
|
||||
static string response400 = "HTTP/1.1 400 Bad Request\r\nContent-Length: 11\r\n\r\nbad request";
|
||||
|
||||
inline void ResponseStr(HttpServer::Response &response, string content, string type = "", string code = "200 OK")
|
||||
{
|
||||
response << "HTTP/1.1 " << code << "\r\n";
|
||||
if (!type.empty())
|
||||
response << "Content-Type: " << type <<"\r\n";
|
||||
response << "Content-Length: " << content.length() << "\r\n\r\n" << content;
|
||||
}
|
||||
|
||||
inline void ptreeToServer(boost::property_tree::ptree &pt, MasterServer::SServer &server)
|
||||
{
|
||||
server.SetName(pt.get<string>("hostname").c_str());
|
||||
server.SetGameMode(pt.get<string>("modname").c_str());
|
||||
server.SetVersion(pt.get<string>("version").c_str());
|
||||
server.SetPassword(pt.get<bool>("passw"));
|
||||
//server.query_port = pt.get<unsigned short>("query_port");
|
||||
server.SetPlayers(pt.get<unsigned>("players"));
|
||||
server.SetMaxPlayers(pt.get<unsigned>("max_players"));
|
||||
}
|
||||
|
||||
inline void queryToStringStream(stringstream &ss, string addr, MasterServer::SServer &query)
|
||||
{
|
||||
ss <<"\"" << addr << "\":{";
|
||||
ss << "\"modname\": \"" << query.GetGameMode() << "\"" << ", ";
|
||||
ss << "\"passw\": " << (query.GetPassword() ? "true" : "false") << ", ";
|
||||
ss << "\"hostname\": \"" << query.GetName() << "\"" << ", ";
|
||||
ss << "\"query_port\": " << 0 << ", ";
|
||||
ss << "\"last_update\": " << duration_cast<seconds>(steady_clock::now() - query.lastUpdate).count() << ", ";
|
||||
ss << "\"players\": " << query.GetPlayers() << ", ";
|
||||
ss << "\"version\": \"" << query.GetVersion() << "\"" << ", ";
|
||||
ss << "\"max_players\": " << query.GetMaxPlayers();
|
||||
ss << "}";
|
||||
}
|
||||
|
||||
RestServer::RestServer(unsigned short port, MasterServer::ServerMap *pMap) : serverMap(pMap)
|
||||
{
|
||||
httpServer.config.port = port;
|
||||
}
|
||||
|
||||
void RestServer::start()
|
||||
{
|
||||
static const string ValidIpAddressRegex = "(?:[0-9]{1,3}\\.){3}[0-9]{1,3}";
|
||||
static const string ValidPortRegex = "(?:[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$";
|
||||
static const string ServersRegex = "^/api/servers(?:/(" + ValidIpAddressRegex + "\\:" + ValidPortRegex + "))?";
|
||||
|
||||
httpServer.resource[ServersRegex]["GET"] = [this](auto response, auto request) {
|
||||
if (request->path_match[1].length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "{";
|
||||
auto addr = request->path_match[1].str();
|
||||
auto port = (unsigned short)stoi(&(addr[addr.find(':')+1]));
|
||||
queryToStringStream(ss, "server", serverMap->at(RakNet::SystemAddress(addr.c_str(), port)));
|
||||
ss << "}";
|
||||
ResponseStr(*response, ss.str(), "application/json");
|
||||
}
|
||||
catch(out_of_range e)
|
||||
{
|
||||
*response << response400;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static string str;
|
||||
|
||||
//if (updatedCache)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "{";
|
||||
ss << "\"list servers\":{";
|
||||
for (auto query = serverMap->begin(); query != serverMap->end(); query++)
|
||||
{
|
||||
queryToStringStream(ss, query->first.ToString(true, ':'), query->second);
|
||||
if (next(query) != serverMap->end())
|
||||
ss << ", ";
|
||||
}
|
||||
ss << "}}";
|
||||
ResponseStr(*response, ss.str(), "application/json");
|
||||
updatedCache = false;
|
||||
}
|
||||
*response << str;
|
||||
}
|
||||
};
|
||||
|
||||
//Add query for < 0.6 servers
|
||||
httpServer.resource[ServersRegex]["POST"] = [this](auto response, auto request) {
|
||||
try
|
||||
{
|
||||
ptree pt;
|
||||
read_json(request->content, pt);
|
||||
|
||||
MasterServer::SServer server;
|
||||
ptreeToServer(pt, server);
|
||||
|
||||
unsigned short port = pt.get<unsigned short>("port");
|
||||
server.lastUpdate = steady_clock::now();
|
||||
serverMap->insert({RakNet::SystemAddress(request->remote_endpoint_address.c_str(), port), server});
|
||||
updatedCache = true;
|
||||
|
||||
*response << response201;
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
*response << response400;
|
||||
}
|
||||
};
|
||||
|
||||
//Update query for < 0.6 servers
|
||||
httpServer.resource[ServersRegex]["PUT"] = [this](auto response, auto request) {
|
||||
auto addr = request->path_match[1].str();
|
||||
auto port = (unsigned short)stoi(&(addr[addr.find(':')+1]));
|
||||
|
||||
auto query = serverMap->find(RakNet::SystemAddress(request->remote_endpoint_address.c_str(), port));
|
||||
|
||||
if (query == serverMap->end())
|
||||
{
|
||||
cout << request->remote_endpoint_address + ": Trying to update a non-existent server or without permissions." << endl;
|
||||
*response << response400;
|
||||
return;
|
||||
}
|
||||
|
||||
if (request->content.size() != 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
ptree pt;
|
||||
read_json(request->content, pt);
|
||||
|
||||
ptreeToServer(pt, query->second);
|
||||
|
||||
updatedCache = true;
|
||||
}
|
||||
catch(exception &e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
*response << response400;
|
||||
}
|
||||
}
|
||||
|
||||
query->second.lastUpdate = steady_clock::now();
|
||||
|
||||
*response << response202;
|
||||
};
|
||||
|
||||
httpServer.resource["/api/servers/info"]["GET"] = [this](auto response, auto /*request*/) {
|
||||
stringstream ss;
|
||||
ss << '{';
|
||||
ss << "\"servers\": " << serverMap->size();
|
||||
unsigned int players = 0;
|
||||
for (auto s : *serverMap)
|
||||
players += s.second.GetPlayers();
|
||||
ss << ", \"players\": " << players;
|
||||
ss << "}";
|
||||
|
||||
ResponseStr(*response, ss.str(), "application/json");
|
||||
};
|
||||
|
||||
httpServer.default_resource["GET"]=[](auto response, auto /*request*/) {
|
||||
*response << response400;
|
||||
};
|
||||
|
||||
httpServer.start();
|
||||
}
|
||||
|
||||
void RestServer::cacheUpdated()
|
||||
{
|
||||
updatedCache = true;
|
||||
}
|
||||
|
||||
void RestServer::stop()
|
||||
{
|
||||
httpServer.stop();
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 13.05.17.
|
||||
//
|
||||
|
||||
#ifndef NEWRESTAPI_RESTSERVER_HPP
|
||||
#define NEWRESTAPI_RESTSERVER_HPP
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "MasterServer.hpp"
|
||||
#include "SimpleWeb/http_server.hpp"
|
||||
|
||||
typedef SimpleWeb::Server<SimpleWeb::HTTP> HttpServer;
|
||||
|
||||
class RestServer
|
||||
{
|
||||
public:
|
||||
RestServer(unsigned short port, MasterServer::ServerMap *pMap);
|
||||
void start();
|
||||
void stop();
|
||||
void cacheUpdated();
|
||||
|
||||
private:
|
||||
HttpServer httpServer;
|
||||
MasterServer::ServerMap *serverMap;
|
||||
bool updatedCache = true;
|
||||
};
|
||||
|
||||
|
||||
#endif //NEWRESTAPI_RESTSERVER_HPP
|
@ -1,186 +0,0 @@
|
||||
//
|
||||
// Created by koncord on 21.04.17.
|
||||
//
|
||||
|
||||
#include <RakPeerInterface.h>
|
||||
#include <RakSleep.h>
|
||||
#include <BitStream.h>
|
||||
#include <iostream>
|
||||
#include <Kbhit.h>
|
||||
#include <Gets.h>
|
||||
#include <components/openmw-mp/Master/MasterData.hpp>
|
||||
#include <components/openmw-mp/Master/PacketMasterAnnounce.hpp>
|
||||
#include <components/openmw-mp/Master/PacketMasterUpdate.hpp>
|
||||
#include <components/openmw-mp/Master/PacketMasterQuery.hpp>
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace RakNet;
|
||||
using namespace mwmp;
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "Server test" << endl;
|
||||
|
||||
SystemAddress masterAddr("127.0.0.1", 25560);
|
||||
|
||||
RakPeerInterface *peer = RakNet::RakPeerInterface::GetInstance();
|
||||
|
||||
RakNet::SocketDescriptor sd(25565, 0);
|
||||
peer->Startup(8, &sd, 1);
|
||||
|
||||
ConnectionAttemptResult result = peer->Connect(masterAddr.ToString(false), masterAddr.GetPort(), "pass",
|
||||
(int)(strlen("pass")), 0, 0, 5, 500);
|
||||
|
||||
assert(result == RakNet::CONNECTION_ATTEMPT_STARTED);
|
||||
|
||||
char message[2048];
|
||||
BitStream send;
|
||||
|
||||
PacketMasterQuery pmq(peer);
|
||||
pmq.SetSendStream(&send);
|
||||
|
||||
PacketMasterAnnounce pma(peer);
|
||||
pma.SetSendStream(&send);
|
||||
|
||||
while (true)
|
||||
{
|
||||
RakSleep(30);
|
||||
|
||||
if (kbhit())
|
||||
{
|
||||
Gets(message, sizeof(message));
|
||||
|
||||
if (strcmp(message, "quit") == 0)
|
||||
{
|
||||
puts("Quitting.");
|
||||
break;
|
||||
}
|
||||
else if (strcmp(message, "send") == 0)
|
||||
{
|
||||
puts("Sending data about server");
|
||||
QueryData server;
|
||||
server.SetName("Super Server");
|
||||
server.SetPlayers(0);
|
||||
server.SetMaxPlayers(0);
|
||||
|
||||
pma.SetServer(&server);
|
||||
pma.SetFunc(PacketMasterAnnounce::FUNCTION_ANNOUNCE);
|
||||
pma.Send(masterAddr);
|
||||
}
|
||||
else if (strcmp(message, "get") == 0)
|
||||
{
|
||||
puts("Request query info");
|
||||
send.Reset();
|
||||
send.Write((unsigned char) (ID_MASTER_QUERY));
|
||||
peer->Send(&send, HIGH_PRIORITY, RELIABLE_ORDERED, CHANNEL_MASTER, masterAddr, false);
|
||||
}
|
||||
else if (strcmp(message, "getme") == 0)
|
||||
{
|
||||
send.Reset();
|
||||
send.Write((unsigned char) (ID_MASTER_UPDATE));
|
||||
send.Write(SystemAddress("127.0.0.1", 25565));
|
||||
peer->Send(&send, HIGH_PRIORITY, RELIABLE_ORDERED, CHANNEL_MASTER, masterAddr, false);
|
||||
}
|
||||
else if (strcmp(message, "status") == 0)
|
||||
{
|
||||
cout << (peer->GetConnectionState(masterAddr) == IS_CONNECTED ? "Connected" : "Not connected") << endl;
|
||||
}
|
||||
else if (strcmp(message, "keep") == 0)
|
||||
{
|
||||
cout << "Sending keep alive" << endl;
|
||||
pma.SetFunc(PacketMasterAnnounce::FUNCTION_KEEP);
|
||||
pma.Send(masterAddr);
|
||||
}
|
||||
}
|
||||
|
||||
for (RakNet::Packet *packet = peer->Receive(); packet; peer->DeallocatePacket(packet), packet = peer->Receive())
|
||||
{
|
||||
BitStream data(packet->data, packet->length, false);
|
||||
unsigned char packetID;
|
||||
data.Read(packetID);
|
||||
switch (packetID)
|
||||
{
|
||||
case ID_DISCONNECTION_NOTIFICATION:
|
||||
// Connection lost normally
|
||||
printf("ID_DISCONNECTION_NOTIFICATION\n");
|
||||
break;
|
||||
case ID_ALREADY_CONNECTED:
|
||||
// Connection lost normally
|
||||
printf("ID_ALREADY_CONNECTED with guid %lu\n", packet->guid.g);
|
||||
break;
|
||||
case ID_INCOMPATIBLE_PROTOCOL_VERSION:
|
||||
printf("ID_INCOMPATIBLE_PROTOCOL_VERSION\n");
|
||||
break;
|
||||
case ID_REMOTE_DISCONNECTION_NOTIFICATION: // Server telling the clients of another client disconnecting gracefully. You can manually broadcast this in a peer to peer enviroment if you want.
|
||||
printf("ID_REMOTE_DISCONNECTION_NOTIFICATION\n");
|
||||
break;
|
||||
case ID_REMOTE_CONNECTION_LOST: // Server telling the clients of another client disconnecting forcefully. You can manually broadcast this in a peer to peer enviroment if you want.
|
||||
printf("ID_REMOTE_CONNECTION_LOST\n");
|
||||
break;
|
||||
case ID_REMOTE_NEW_INCOMING_CONNECTION: // Server telling the clients of another client connecting. You can manually broadcast this in a peer to peer enviroment if you want.
|
||||
printf("ID_REMOTE_NEW_INCOMING_CONNECTION\n");
|
||||
break;
|
||||
case ID_CONNECTION_BANNED: // Banned from this server
|
||||
printf("We are banned from this server.\n");
|
||||
break;
|
||||
case ID_CONNECTION_ATTEMPT_FAILED:
|
||||
printf("Connection attempt failed\n");
|
||||
break;
|
||||
case ID_NO_FREE_INCOMING_CONNECTIONS:
|
||||
// Sorry, the server is full. I don't do anything here but
|
||||
// A real app should tell the user
|
||||
printf("ID_NO_FREE_INCOMING_CONNECTIONS\n");
|
||||
break;
|
||||
|
||||
case ID_INVALID_PASSWORD:
|
||||
printf("ID_INVALID_PASSWORD\n");
|
||||
break;
|
||||
|
||||
case ID_CONNECTION_LOST:
|
||||
// Couldn't deliver a reliable packet - i.e. the other system was abnormally
|
||||
// terminated
|
||||
printf("ID_CONNECTION_LOST\n");
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case ID_CONNECTION_REQUEST_ACCEPTED:
|
||||
// This tells the client they have connected
|
||||
printf("ID_CONNECTION_REQUEST_ACCEPTED to %s with GUID %s\n", packet->systemAddress.ToString(true),
|
||||
packet->guid.ToString());
|
||||
printf("My external address is %s\n", peer->GetExternalID(packet->systemAddress).ToString(true));
|
||||
break;
|
||||
case ID_MASTER_QUERY:
|
||||
{
|
||||
map<SystemAddress, QueryData> servers;
|
||||
|
||||
pmq.SetReadStream(&data);
|
||||
pmq.SetServers(&servers);
|
||||
pmq.Read();
|
||||
|
||||
cout << "Received query data about " << servers.size() << " servers" << endl;
|
||||
|
||||
for (auto serv : servers)
|
||||
cout << serv.second.GetName() << endl;
|
||||
|
||||
break;
|
||||
}
|
||||
case ID_MASTER_UPDATE:
|
||||
{
|
||||
pair<SystemAddress, QueryData> serverPair;
|
||||
PacketMasterUpdate pmu(peer);
|
||||
pmu.SetReadStream(&data);
|
||||
pmu.SetServer(&serverPair);
|
||||
pmu.Read();
|
||||
cout << "Received info about " << serverPair.first.ToString() << endl;
|
||||
cout << serverPair.second.GetName() << endl;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
cout << "Wrong packet" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
peer->Shutdown(1000);
|
||||
RakPeerInterface::DestroyInstance(peer);
|
||||
}
|
@ -1,511 +0,0 @@
|
||||
#ifndef BASE_SERVER_HPP
|
||||
#define BASE_SERVER_HPP
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <thread>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
|
||||
#ifndef CASE_INSENSITIVE_EQUALS_AND_HASH
|
||||
#define CASE_INSENSITIVE_EQUALS_AND_HASH
|
||||
|
||||
//Based on http://www.boost.org/doc/libs/1_60_0/doc/html/unordered/hash_equality.html
|
||||
struct case_insensitive_equals
|
||||
{
|
||||
bool operator()(const std::string &key1, const std::string &key2) const
|
||||
{
|
||||
return boost::algorithm::iequals(key1, key2);
|
||||
}
|
||||
};
|
||||
|
||||
struct case_insensitive_hash
|
||||
{
|
||||
size_t operator()(const std::string &key) const
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
for (auto &c: key)
|
||||
boost::hash_combine(seed, std::tolower(c));
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
namespace SimpleWeb
|
||||
{
|
||||
template<class socket_type>
|
||||
class Server;
|
||||
|
||||
template<class socket_type>
|
||||
class ServerBase
|
||||
{
|
||||
public:
|
||||
virtual ~ServerBase()
|
||||
{}
|
||||
|
||||
class Response : public std::ostream
|
||||
{
|
||||
friend class ServerBase<socket_type>;
|
||||
|
||||
boost::asio::streambuf streambuf;
|
||||
|
||||
std::shared_ptr<socket_type> socket;
|
||||
|
||||
Response(const std::shared_ptr<socket_type> &socket) : std::ostream(&streambuf), socket(socket)
|
||||
{}
|
||||
|
||||
public:
|
||||
size_t size()
|
||||
{
|
||||
return streambuf.size();
|
||||
}
|
||||
|
||||
/// If true, force server to close the connection after the response have been sent.
|
||||
///
|
||||
/// This is useful when implementing a HTTP/1.0-server sending content
|
||||
/// without specifying the content length.
|
||||
bool close_connection_after_response = false;
|
||||
};
|
||||
|
||||
class Content : public std::istream
|
||||
{
|
||||
friend class ServerBase<socket_type>;
|
||||
|
||||
public:
|
||||
size_t size()
|
||||
{
|
||||
return streambuf.size();
|
||||
}
|
||||
|
||||
std::string string()
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << rdbuf();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
private:
|
||||
boost::asio::streambuf &streambuf;
|
||||
|
||||
Content(boost::asio::streambuf &streambuf) : std::istream(&streambuf), streambuf(streambuf)
|
||||
{}
|
||||
};
|
||||
|
||||
class Request
|
||||
{
|
||||
friend class ServerBase<socket_type>;
|
||||
|
||||
friend class Server<socket_type>;
|
||||
|
||||
public:
|
||||
std::string method, path, http_version;
|
||||
|
||||
Content content;
|
||||
|
||||
std::unordered_multimap<std::string, std::string, case_insensitive_hash, case_insensitive_equals> header;
|
||||
|
||||
std::smatch path_match;
|
||||
|
||||
std::string remote_endpoint_address;
|
||||
unsigned short remote_endpoint_port;
|
||||
|
||||
private:
|
||||
Request(const socket_type &socket) : content(streambuf)
|
||||
{
|
||||
try
|
||||
{
|
||||
remote_endpoint_address = socket.lowest_layer().remote_endpoint().address().to_string();
|
||||
remote_endpoint_port = socket.lowest_layer().remote_endpoint().port();
|
||||
}
|
||||
catch (...)
|
||||
{}
|
||||
}
|
||||
|
||||
boost::asio::streambuf streambuf;
|
||||
};
|
||||
|
||||
class Config
|
||||
{
|
||||
friend class ServerBase<socket_type>;
|
||||
|
||||
Config(unsigned short port) : port(port)
|
||||
{}
|
||||
|
||||
public:
|
||||
/// Port number to use. Defaults to 80 for HTTP and 443 for HTTPS.
|
||||
unsigned short port;
|
||||
/// Number of threads that the server will use when start() is called. Defaults to 1 thread.
|
||||
size_t thread_pool_size = 1;
|
||||
/// Timeout on request handling. Defaults to 5 seconds.
|
||||
size_t timeout_request = 5;
|
||||
/// Timeout on content handling. Defaults to 300 seconds.
|
||||
size_t timeout_content = 300;
|
||||
/// IPv4 address in dotted decimal form or IPv6 address in hexadecimal notation.
|
||||
/// If empty, the address will be any address.
|
||||
std::string address;
|
||||
/// Set to false to avoid binding the socket to an address that is already in use. Defaults to true.
|
||||
bool reuse_address = true;
|
||||
};
|
||||
|
||||
///Set before calling start().
|
||||
Config config;
|
||||
|
||||
private:
|
||||
class regex_orderable : public std::regex
|
||||
{
|
||||
std::string str;
|
||||
public:
|
||||
regex_orderable(const char *regex_cstr) : std::regex(regex_cstr), str(regex_cstr)
|
||||
{}
|
||||
|
||||
regex_orderable(const std::string ®ex_str) : std::regex(regex_str), str(regex_str)
|
||||
{}
|
||||
|
||||
bool operator<(const regex_orderable &rhs) const
|
||||
{
|
||||
return str < rhs.str;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
/// Warning: do not add or remove resources after start() is called
|
||||
std::map<regex_orderable, std::map<std::string,
|
||||
std::function<void(std::shared_ptr<typename ServerBase<socket_type>::Response>,
|
||||
std::shared_ptr<typename ServerBase<socket_type>::Request>)>>>
|
||||
resource;
|
||||
|
||||
std::map<std::string,
|
||||
std::function<void(std::shared_ptr<typename ServerBase<socket_type>::Response>,
|
||||
std::shared_ptr<typename ServerBase<socket_type>::Request>)>> default_resource;
|
||||
|
||||
std::function<
|
||||
void(std::shared_ptr<typename ServerBase<socket_type>::Request>,
|
||||
const boost::system::error_code &)>
|
||||
on_error;
|
||||
|
||||
std::function<void(std::shared_ptr<socket_type> socket,
|
||||
std::shared_ptr<typename ServerBase<socket_type>::Request>)> on_upgrade;
|
||||
|
||||
virtual void start()
|
||||
{
|
||||
if (!io_service)
|
||||
io_service = std::make_shared<boost::asio::io_service>();
|
||||
|
||||
if (io_service->stopped())
|
||||
io_service->reset();
|
||||
|
||||
boost::asio::ip::tcp::endpoint endpoint;
|
||||
if (config.address.size() > 0)
|
||||
endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(config.address),
|
||||
config.port);
|
||||
else
|
||||
endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), config.port);
|
||||
|
||||
if (!acceptor)
|
||||
acceptor = std::unique_ptr<boost::asio::ip::tcp::acceptor>(
|
||||
new boost::asio::ip::tcp::acceptor(*io_service));
|
||||
acceptor->open(endpoint.protocol());
|
||||
acceptor->set_option(boost::asio::socket_base::reuse_address(config.reuse_address));
|
||||
acceptor->bind(endpoint);
|
||||
acceptor->listen();
|
||||
|
||||
accept();
|
||||
|
||||
//If thread_pool_size>1, start m_io_service.run() in (thread_pool_size-1) threads for thread-pooling
|
||||
threads.clear();
|
||||
for (size_t c = 1; c < config.thread_pool_size; c++)
|
||||
{
|
||||
threads.emplace_back([this]()
|
||||
{
|
||||
io_service->run();
|
||||
});
|
||||
}
|
||||
|
||||
//Main thread
|
||||
if (config.thread_pool_size > 0)
|
||||
io_service->run();
|
||||
|
||||
//Wait for the rest of the threads, if any, to finish as well
|
||||
for (auto &t: threads)
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
acceptor->close();
|
||||
if (config.thread_pool_size > 0)
|
||||
io_service->stop();
|
||||
}
|
||||
|
||||
///Use this function if you need to recursively send parts of a longer message
|
||||
void send(const std::shared_ptr<Response> &response,
|
||||
const std::function<void(const boost::system::error_code &)> &callback = nullptr) const
|
||||
{
|
||||
boost::asio::async_write(*response->socket, response->streambuf, [this, response, callback]
|
||||
(const boost::system::error_code &ec, size_t /*bytes_transferred*/)
|
||||
{
|
||||
if (callback)
|
||||
callback(ec);
|
||||
});
|
||||
}
|
||||
|
||||
/// If you have your own boost::asio::io_service, store its pointer here before running start().
|
||||
/// You might also want to set config.thread_pool_size to 0.
|
||||
std::shared_ptr<boost::asio::io_service> io_service;
|
||||
protected:
|
||||
std::unique_ptr<boost::asio::ip::tcp::acceptor> acceptor;
|
||||
std::vector<std::thread> threads;
|
||||
|
||||
ServerBase(unsigned short port) : config(port)
|
||||
{}
|
||||
|
||||
virtual void accept()=0;
|
||||
|
||||
std::shared_ptr<boost::asio::deadline_timer>
|
||||
get_timeout_timer(const std::shared_ptr<socket_type> &socket, long seconds)
|
||||
{
|
||||
if (seconds == 0)
|
||||
return nullptr;
|
||||
|
||||
auto timer = std::make_shared<boost::asio::deadline_timer>(*io_service);
|
||||
timer->expires_from_now(boost::posix_time::seconds(seconds));
|
||||
timer->async_wait([socket](const boost::system::error_code &ec)
|
||||
{
|
||||
if (!ec)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
socket->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
|
||||
socket->lowest_layer().close();
|
||||
}
|
||||
});
|
||||
return timer;
|
||||
}
|
||||
|
||||
void read_request_and_content(const std::shared_ptr<socket_type> &socket)
|
||||
{
|
||||
//Create new streambuf (Request::streambuf) for async_read_until()
|
||||
//shared_ptr is used to pass temporary objects to the asynchronous functions
|
||||
std::shared_ptr<Request> request(new Request(*socket));
|
||||
|
||||
//Set timeout on the following boost::asio::async-read or write function
|
||||
auto timer = this->get_timeout_timer(socket, config.timeout_request);
|
||||
|
||||
boost::asio::async_read_until(*socket, request->streambuf, "\r\n\r\n", [this, socket, request, timer]
|
||||
(const boost::system::error_code &ec,
|
||||
size_t bytes_transferred)
|
||||
{
|
||||
if (timer)
|
||||
timer->cancel();
|
||||
if (!ec)
|
||||
{
|
||||
//request->streambuf.size() is not necessarily the same as bytes_transferred, from Boost-docs:
|
||||
//"After a successful async_read_until operation, the streambuf may contain additional data beyond the delimiter"
|
||||
//The chosen solution is to extract lines from the stream directly when parsing the header. What is left of the
|
||||
//streambuf (maybe some bytes of the content) is appended to in the async_read-function below (for retrieving content).
|
||||
size_t num_additional_bytes =
|
||||
request->streambuf.size() - bytes_transferred;
|
||||
|
||||
if (!this->parse_request(request))
|
||||
return;
|
||||
|
||||
//If content, read that as well
|
||||
auto it = request->header.find("Content-Length");
|
||||
if (it != request->header.end())
|
||||
{
|
||||
unsigned long long content_length;
|
||||
try
|
||||
{
|
||||
content_length = stoull(it->second);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
if (on_error)
|
||||
on_error(request, boost::system::error_code(
|
||||
boost::system::errc::protocol_error,
|
||||
boost::system::generic_category()));
|
||||
return;
|
||||
}
|
||||
if (content_length > num_additional_bytes)
|
||||
{
|
||||
//Set timeout on the following boost::asio::async-read or write function
|
||||
auto timer = this->get_timeout_timer(socket,
|
||||
config.timeout_content);
|
||||
boost::asio::async_read(*socket, request->streambuf,
|
||||
boost::asio::transfer_exactly(
|
||||
content_length -
|
||||
num_additional_bytes),
|
||||
[this, socket, request, timer]
|
||||
(const boost::system::error_code &ec,
|
||||
size_t /*bytes_transferred*/)
|
||||
{
|
||||
if (timer)
|
||||
timer->cancel();
|
||||
if (!ec)
|
||||
this->find_resource(socket,
|
||||
request);
|
||||
else if (on_error)
|
||||
on_error(request, ec);
|
||||
});
|
||||
}
|
||||
else
|
||||
this->find_resource(socket, request);
|
||||
}
|
||||
else
|
||||
this->find_resource(socket, request);
|
||||
}
|
||||
else if (on_error)
|
||||
on_error(request, ec);
|
||||
});
|
||||
}
|
||||
|
||||
bool parse_request(const std::shared_ptr<Request> &request) const
|
||||
{
|
||||
std::string line;
|
||||
getline(request->content, line);
|
||||
size_t method_end;
|
||||
if ((method_end = line.find(' ')) != std::string::npos)
|
||||
{
|
||||
size_t path_end;
|
||||
if ((path_end = line.find(' ', method_end + 1)) != std::string::npos)
|
||||
{
|
||||
request->method = line.substr(0, method_end);
|
||||
request->path = line.substr(method_end + 1, path_end - method_end - 1);
|
||||
|
||||
size_t protocol_end;
|
||||
if ((protocol_end = line.find('/', path_end + 1)) != std::string::npos)
|
||||
{
|
||||
if (line.compare(path_end + 1, protocol_end - path_end - 1, "HTTP") != 0)
|
||||
return false;
|
||||
request->http_version = line.substr(protocol_end + 1, line.size() - protocol_end - 2);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
getline(request->content, line);
|
||||
size_t param_end;
|
||||
while ((param_end = line.find(':')) != std::string::npos)
|
||||
{
|
||||
size_t value_start = param_end + 1;
|
||||
if ((value_start) < line.size())
|
||||
{
|
||||
if (line[value_start] == ' ')
|
||||
value_start++;
|
||||
if (value_start < line.size())
|
||||
request->header.emplace(line.substr(0, param_end),
|
||||
line.substr(value_start, line.size() - value_start - 1));
|
||||
}
|
||||
|
||||
getline(request->content, line);
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void find_resource(const std::shared_ptr<socket_type> &socket, const std::shared_ptr<Request> &request)
|
||||
{
|
||||
//Upgrade connection
|
||||
if (on_upgrade)
|
||||
{
|
||||
auto it = request->header.find("Upgrade");
|
||||
if (it != request->header.end())
|
||||
{
|
||||
on_upgrade(socket, request);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//Find path- and method-match, and call write_response
|
||||
for (auto ®ex_method: resource)
|
||||
{
|
||||
auto it = regex_method.second.find(request->method);
|
||||
if (it != regex_method.second.end())
|
||||
{
|
||||
std::smatch sm_res;
|
||||
if (std::regex_match(request->path, sm_res, regex_method.first))
|
||||
{
|
||||
request->path_match = std::move(sm_res);
|
||||
write_response(socket, request, it->second);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
auto it = default_resource.find(request->method);
|
||||
if (it != default_resource.end())
|
||||
{
|
||||
write_response(socket, request, it->second);
|
||||
}
|
||||
}
|
||||
|
||||
void write_response(const std::shared_ptr<socket_type> &socket, const std::shared_ptr<Request> &request,
|
||||
std::function<void(std::shared_ptr<typename ServerBase<socket_type>::Response>,
|
||||
std::shared_ptr<
|
||||
typename ServerBase<socket_type>::Request>)> &resource_function)
|
||||
{
|
||||
//Set timeout on the following boost::asio::async-read or write function
|
||||
auto timer = this->get_timeout_timer(socket, config.timeout_content);
|
||||
|
||||
auto response = std::shared_ptr<Response>(new Response(socket), [this, request, timer]
|
||||
(Response *response_ptr)
|
||||
{
|
||||
auto response = std::shared_ptr<Response>(response_ptr);
|
||||
this->send(response, [this, response, request, timer](
|
||||
const boost::system::error_code &ec)
|
||||
{
|
||||
if (timer)
|
||||
timer->cancel();
|
||||
if (!ec)
|
||||
{
|
||||
if (response->close_connection_after_response)
|
||||
return;
|
||||
|
||||
auto range = request->header.equal_range(
|
||||
"Connection");
|
||||
for (auto it = range.first; it != range.second; it++)
|
||||
{
|
||||
if (boost::iequals(it->second, "close"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (boost::iequals(it->second, "keep-alive"))
|
||||
{
|
||||
this->read_request_and_content(
|
||||
response->socket);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (request->http_version >= "1.1")
|
||||
this->read_request_and_content(response->socket);
|
||||
}
|
||||
else if (on_error)
|
||||
on_error(request, ec);
|
||||
});
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
resource_function(response, request);
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
if (on_error)
|
||||
on_error(request, boost::system::error_code(boost::system::errc::operation_canceled,
|
||||
boost::system::generic_category()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif //BASE_SERVER_HPP
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* https://github.com/eidheim/Simple-Web-Server/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2014-2016 Ole Christian Eidheim
|
||||
*/
|
||||
|
||||
#ifndef SERVER_HTTP_HPP
|
||||
#define SERVER_HTTP_HPP
|
||||
|
||||
#include "base_server.hpp"
|
||||
|
||||
namespace SimpleWeb
|
||||
{
|
||||
|
||||
template<class socket_type>
|
||||
class Server : public ServerBase<socket_type> {};
|
||||
|
||||
typedef boost::asio::ip::tcp::socket HTTP;
|
||||
|
||||
template<>
|
||||
class Server<HTTP> : public ServerBase<HTTP>
|
||||
{
|
||||
public:
|
||||
Server() : ServerBase<HTTP>::ServerBase(80)
|
||||
{}
|
||||
|
||||
protected:
|
||||
virtual void accept()
|
||||
{
|
||||
//Create new socket for this connection
|
||||
//Shared_ptr is used to pass temporary objects to the asynchronous functions
|
||||
auto socket = std::make_shared<HTTP>(*io_service);
|
||||
|
||||
acceptor->async_accept(*socket, [this, socket](const boost::system::error_code &ec)
|
||||
{
|
||||
//Immediately start accepting a new connection (if io_service hasn't been stopped)
|
||||
if (ec != boost::asio::error::operation_aborted)
|
||||
accept();
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
boost::asio::ip::tcp::no_delay option(true);
|
||||
socket->set_option(option);
|
||||
|
||||
this->read_request_and_content(socket);
|
||||
}
|
||||
else if (on_error)
|
||||
on_error(std::shared_ptr<Request>(new Request(*socket)), ec);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //SERVER_HTTP_HPP
|
@ -1,91 +0,0 @@
|
||||
#ifndef HTTPS_SERVER_HPP
|
||||
#define HTTPS_SERVER_HPP
|
||||
|
||||
#include "base_server.hpp"
|
||||
#include <boost/asio/ssl.hpp>
|
||||
#include <openssl/ssl.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace SimpleWeb
|
||||
{
|
||||
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> HTTPS;
|
||||
|
||||
template<>
|
||||
class Server<HTTPS> : public ServerBase<HTTPS>
|
||||
{
|
||||
std::string session_id_context;
|
||||
bool set_session_id_context = false;
|
||||
public:
|
||||
Server(const std::string &cert_file, const std::string &private_key_file,
|
||||
const std::string &verify_file = std::string()) : ServerBase<HTTPS>::ServerBase(443),
|
||||
context(boost::asio::ssl::context::tlsv12)
|
||||
{
|
||||
context.use_certificate_chain_file(cert_file);
|
||||
context.use_private_key_file(private_key_file, boost::asio::ssl::context::pem);
|
||||
|
||||
if (verify_file.size() > 0)
|
||||
{
|
||||
context.load_verify_file(verify_file);
|
||||
context.set_verify_mode(boost::asio::ssl::verify_peer | boost::asio::ssl::verify_fail_if_no_peer_cert |
|
||||
boost::asio::ssl::verify_client_once);
|
||||
set_session_id_context = true;
|
||||
}
|
||||
}
|
||||
|
||||
void start()
|
||||
{
|
||||
if (set_session_id_context)
|
||||
{
|
||||
// Creating session_id_context from address:port but reversed due to small SSL_MAX_SSL_SESSION_ID_LENGTH
|
||||
session_id_context = std::to_string(config.port) + ':';
|
||||
session_id_context.append(config.address.rbegin(), config.address.rend());
|
||||
SSL_CTX_set_session_id_context(context.native_handle(),
|
||||
reinterpret_cast<const unsigned char *>(session_id_context.data()),
|
||||
std::min<size_t>(session_id_context.size(),
|
||||
SSL_MAX_SSL_SESSION_ID_LENGTH));
|
||||
}
|
||||
ServerBase::start();
|
||||
}
|
||||
|
||||
protected:
|
||||
boost::asio::ssl::context context;
|
||||
|
||||
virtual void accept()
|
||||
{
|
||||
//Create new socket for this connection
|
||||
//Shared_ptr is used to pass temporary objects to the asynchronous functions
|
||||
auto socket = std::make_shared<HTTPS>(*io_service, context);
|
||||
|
||||
acceptor->async_accept((*socket).lowest_layer(), [this, socket](const boost::system::error_code &ec)
|
||||
{
|
||||
//Immediately start accepting a new connection (if io_service hasn't been stopped)
|
||||
if (ec != boost::asio::error::operation_aborted)
|
||||
accept();
|
||||
|
||||
|
||||
if (!ec)
|
||||
{
|
||||
boost::asio::ip::tcp::no_delay option(true);
|
||||
socket->lowest_layer().set_option(option);
|
||||
|
||||
//Set timeout on the following boost::asio::ssl::stream::async_handshake
|
||||
auto timer = get_timeout_timer(socket, config.timeout_request);
|
||||
socket->async_handshake(boost::asio::ssl::stream_base::server, [this, socket, timer]
|
||||
(const boost::system::error_code &ec)
|
||||
{
|
||||
if (timer)
|
||||
timer->cancel();
|
||||
if (!ec)
|
||||
read_request_and_content(socket);
|
||||
else if (on_error)
|
||||
on_error(std::shared_ptr<Request>(new Request(*socket)), ec);
|
||||
});
|
||||
}
|
||||
else if (on_error)
|
||||
on_error(std::shared_ptr<Request>(new Request(*socket)), ec);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //HTTPS_SERVER_HPP
|
@ -1,37 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <Kbhit.h>
|
||||
#include <RakSleep.h>
|
||||
#include "MasterServer.hpp"
|
||||
#include "RestServer.hpp"
|
||||
|
||||
using namespace RakNet;
|
||||
using namespace std;
|
||||
|
||||
unique_ptr<RestServer> restServer;
|
||||
unique_ptr<MasterServer> masterServer;
|
||||
bool run = true;
|
||||
|
||||
int main()
|
||||
{
|
||||
masterServer.reset(new MasterServer(2000, 25560));
|
||||
restServer.reset(new RestServer(8080, masterServer->GetServers()));
|
||||
|
||||
auto onExit = [](int /*sig*/){
|
||||
restServer->stop();
|
||||
masterServer->Stop(false);
|
||||
masterServer->Wait();
|
||||
run = false;
|
||||
};
|
||||
|
||||
signal(SIGINT, onExit);
|
||||
signal(SIGTERM, onExit);
|
||||
|
||||
masterServer->Start();
|
||||
|
||||
thread server_thread([]() { restServer->start(); });
|
||||
|
||||
server_thread.join();
|
||||
masterServer->Wait();
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
#include "editor.hpp"
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QIcon>
|
||||
#include <QMetaType>
|
||||
|
||||
#include "model/doc/messages.hpp"
|
||||
|
||||
#include "model/world/universalid.hpp"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include <QDir>
|
||||
#endif
|
||||
|
||||
Q_DECLARE_METATYPE (std::string)
|
||||
|
||||
class Application : public QApplication
|
||||
{
|
||||
private:
|
||||
|
||||
bool notify (QObject *receiver, QEvent *event)
|
||||
{
|
||||
try
|
||||
{
|
||||
return QApplication::notify (receiver, event);
|
||||
}
|
||||
catch (const std::exception& exception)
|
||||
{
|
||||
std::cerr << "An exception has been caught: " << exception.what() << std::endl;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Application (int& argc, char *argv[]) : QApplication (argc, argv) {}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
setenv("OSG_GL_TEXTURE_STORAGE", "OFF", 0);
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
// To allow background thread drawing in OSG
|
||||
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
|
||||
|
||||
Q_INIT_RESOURCE (resources);
|
||||
|
||||
qRegisterMetaType<std::string> ("std::string");
|
||||
qRegisterMetaType<CSMWorld::UniversalId> ("CSMWorld::UniversalId");
|
||||
qRegisterMetaType<CSMDoc::Message> ("CSMDoc::Message");
|
||||
|
||||
Application application (argc, argv);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
QDir dir(QCoreApplication::applicationDirPath());
|
||||
if (dir.dirName() == "MacOS") {
|
||||
dir.cdUp();
|
||||
dir.cdUp();
|
||||
dir.cdUp();
|
||||
}
|
||||
QDir::setCurrent(dir.absolutePath());
|
||||
#endif
|
||||
|
||||
application.setWindowIcon (QIcon (":./openmw-cs.png"));
|
||||
|
||||
CS::Editor editor;
|
||||
|
||||
if(!editor.makeIPCServer())
|
||||
{
|
||||
editor.connectToIPCServer();
|
||||
return 0;
|
||||
}
|
||||
return editor.run();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << "ERROR: " << e.what() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue