From b9ccba6ed488dcadcb6c15dc419fc072dc123556 Mon Sep 17 00:00:00 2001 From: lotodore Date: Mon, 4 Jun 2007 16:19:11 +0000 Subject: [PATCH] Proper detection whether SCTP is available. Do not update player names on configuration change if network client is running. --- .../joinnetworkgamedialogimpl.cpp | 3 +++ src/gui/qt/mainwindow/mainwindowimpl.cpp | 6 +----- .../qt/settingsdialog/settingsdialogimpl.cpp | 4 +++- src/net/linux/socket_startup.cpp | 19 +++++++++++++++++++ src/net/socket_startup.h | 4 +++- src/net/win32/socket_startup.cpp | 6 ++++++ src/session.cpp | 3 ++- src/session.h | 7 ------- 8 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.cpp b/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.cpp index c19d6322..32e0f65a 100644 --- a/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.cpp +++ b/src/gui/qt/joinnetworkgamedialog/joinnetworkgamedialogimpl.cpp @@ -21,6 +21,7 @@ #include "session.h" #include "configfile.h" #include "tinyxml.h" +#include using namespace std; @@ -90,6 +91,8 @@ void joinNetworkGameDialogImpl::exec() { fillServerProfileList(); } + checkBox_sctp->setEnabled(socket_has_sctp()); + QDialog::exec(); } diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 749bcda6..d05a7454 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -511,10 +511,6 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent) myWaitingForServerGameDialog = new waitForServerToStartGameDialogImpl(this); myAboutPokerthDialog = new aboutPokerthImpl(this); - //dialog settings -// mySettingsDialog->checkBox_useSctp->setEnabled(mySession->hasSctp()); -// myJoinNetworkGameDialog->checkBox_sctp->setEnabled(mySession->hasSctp()); - // //ShortCuts // QShortcut *quitPokerTHKeys = new QShortcut(QKeySequence(Qt::Key_Control + Qt::Key_Q), this); // connect( quitPokerTHKeys, SIGNAL(activated() ), actionQuit, SLOT( trigger() ) ); @@ -798,7 +794,7 @@ void mainWindowImpl::callSettingsDialog() { else { groupBox_RightToolBox->hide(); } //Falls Spielernamen geändert wurden --> neu zeichnen --> erst beim nächsten Neustart neu ausgelesen - if (mySettingsDialog->getPlayerNickIsChanged() && mySession->getCurrentGame()) { + if (mySettingsDialog->getPlayerNickIsChanged() && mySession->getCurrentGame() && !mySession->isNetworkClientRunning()) { HandInterface *currentHand = mySession->getCurrentGame()->getCurrentHand(); currentHand->getPlayerArray()[0]->setMyName(mySettingsDialog->lineEdit_HumanPlayerName->text().toUtf8().constData()); diff --git a/src/gui/qt/settingsdialog/settingsdialogimpl.cpp b/src/gui/qt/settingsdialog/settingsdialogimpl.cpp index bf2140f2..9738b662 100644 --- a/src/gui/qt/settingsdialog/settingsdialogimpl.cpp +++ b/src/gui/qt/settingsdialog/settingsdialogimpl.cpp @@ -21,6 +21,7 @@ #include "myavatarlistitem.h" #include "configfile.h" +#include #include @@ -135,7 +136,8 @@ void settingsDialogImpl::exec() { lineEdit_logDir->setText(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str())); spinBox_logStoreDuration->setValue(myConfig->readConfigInt("LogStoreDuration")); comboBox_logInterval->setCurrentIndex(myConfig->readConfigInt("LogInterval")); - + + checkBox_useSctp->setEnabled(socket_has_sctp()); QDialog::exec(); diff --git a/src/net/linux/socket_startup.cpp b/src/net/linux/socket_startup.cpp index bbb13167..b3c521d5 100644 --- a/src/net/linux/socket_startup.cpp +++ b/src/net/linux/socket_startup.cpp @@ -22,6 +22,10 @@ #include +#include +#include +#include + bool socket_startup() { @@ -33,3 +37,18 @@ socket_cleanup() { } +bool +socket_has_sctp() +{ +#ifdef IPPROTO_SCTP + int test = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); + + if (test == -1) + return false; + close(test); + return true; +#else + return false; +#endif +} + diff --git a/src/net/socket_startup.h b/src/net/socket_startup.h index f395ef91..8e18e5d0 100644 --- a/src/net/socket_startup.h +++ b/src/net/socket_startup.h @@ -16,12 +16,14 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -/* Socket startup/cleanup functions (required for Win32). */ +/* Socket startup/cleanup/detection functions. */ #ifndef _SOCKET_STARTUP_H_ #define _SOCKET_STARTUP_H_ bool socket_startup(); void socket_cleanup(); +bool socket_has_sctp(); + #endif diff --git a/src/net/win32/socket_startup.cpp b/src/net/win32/socket_startup.cpp index 2aec0c21..52f2fe49 100644 --- a/src/net/win32/socket_startup.cpp +++ b/src/net/win32/socket_startup.cpp @@ -66,3 +66,9 @@ socket_cleanup() WSACleanup(); } +bool +socket_has_sctp() +{ + return false; /* no SCTP on Windows */ +} + diff --git a/src/session.cpp b/src/session.cpp index 4b46895e..0016f4cb 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -34,7 +34,7 @@ using namespace std; Session::Session(GuiInterface *g, ConfigFile *c) -: currentGameID(0), myNetClient(0), myNetServer(0), myGui(g), myConfig(c), thisHasSctp(0) +: currentGameID(0), myNetClient(0), myNetServer(0), myGui(g), myConfig(c) { } @@ -210,3 +210,4 @@ bool Session::isNetworkClientRunning() const // TODO return myNetClient != NULL; } + diff --git a/src/session.h b/src/session.h index 49d7dc64..04c694b7 100755 --- a/src/session.h +++ b/src/session.h @@ -63,10 +63,6 @@ public: bool isNetworkClientRunning() const; // TODO hack - void setHasSctp ( bool theValue ) { thisHasSctp = theValue; } - bool hasSctp() const { return thisHasSctp; } - - private: int currentGameID; @@ -77,9 +73,6 @@ private: boost::shared_ptr currentGame; GuiInterface *myGui; ConfigFile *myConfig; - - bool thisHasSctp; - };