[atlantik-cvs] CVS: kdegames/atlantik/client monopigator.cpp,1.9,1.9.8.1 monopigator.h,1.8,1.8.8.1 selectserver_widget.cpp,1.18,1.18.6.1 selectserver_widget.h,1.9,1.9.6.1

[email protected]
Newsgroups gmane.comp.kde.devel.atlantik
Message-ID <[email protected]>
Update of /home/kde/kdegames/atlantik/client
In directory office:/tmp/cvs-serv19892/client

Modified Files:
      Tag: KDE_3_1_BRANCH
	monopigator.cpp monopigator.h selectserver_widget.cpp 
	selectserver_widget.h 
Log Message:
backport from HEAD bugfix: only show localhost server when it is available

Index: monopigator.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/monopigator.cpp,v
retrieving revision 1.9
retrieving revision 1.9.8.1
diff -u -d -r1.9 -r1.9.8.1
--- monopigator.cpp	29 Jun 2002 12:51:33 -0000	1.9
+++ monopigator.cpp	7 Jan 2003 22:57:46 -0000	1.9.8.1
@@ -61,8 +61,6 @@
 			if (eTop.tagName() != "monopigator")
 				return;
 
-			emit monopigatorClear();
-
 			QDomNode n = eTop.firstChild();
 			while(!n.isNull())
 			{

Index: monopigator.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/monopigator.h,v
retrieving revision 1.8
retrieving revision 1.8.8.1
diff -u -d -r1.8 -r1.8.8.1
--- monopigator.h	29 Jun 2002 12:51:33 -0000	1.8
+++ monopigator.h	7 Jan 2003 22:57:46 -0000	1.8.8.1
@@ -32,7 +32,6 @@
 	void loadData(const KURL &);
 
 signals:
-	void monopigatorClear();
 	void monopigatorAdd(QString host, QString port, QString version, int users);
 	void finished();
 

Index: selectserver_widget.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectserver_widget.cpp,v
retrieving revision 1.18
retrieving revision 1.18.6.1
diff -u -d -r1.18 -r1.18.6.1
--- selectserver_widget.cpp	13 Aug 2002 18:09:42 -0000	1.18
+++ selectserver_widget.cpp	7 Jan 2003 22:57:46 -0000	1.18.6.1
@@ -1,4 +1,4 @@
-// Copyright (c) 2002 Rob Kaper <[email protected]>
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License
@@ -18,6 +18,7 @@
 #include <qradiobutton.h>
 
 #include <kdialog.h>
+#include <kextendedsocket.h>
 #include <klocale.h>
 #include <kiconloader.h>
 
@@ -53,7 +54,7 @@
 
 	connect(m_serverList, SIGNAL(clicked(QListViewItem *)), this, SLOT(validateConnectButton()));
 //	connect(m_serverList, SIGNAL(clicked(QListViewItem *)), this, SLOT(slotListClicked(QListViewItem *)));
-	connect(m_serverList, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(connectClicked()));
+	connect(m_serverList, SIGNAL(doubleClicked(QListViewItem *)), this, SLOT(slotConnect()));
 	connect(m_serverList, SIGNAL(rightButtonClicked(QListViewItem *, const QPoint &, int)), this, SLOT(validateConnectButton()));
 	connect(m_serverList, SIGNAL(selectionChanged(QListViewItem *)), this, SLOT(validateConnectButton()));
 
@@ -65,43 +66,51 @@
 	m_refreshButton = new KPushButton(BarIcon("reload", KIcon::SizeSmall), i18n("Refresh"), this);
 	buttonBox->addWidget(m_refreshButton);
 
-	connect(m_refreshButton, SIGNAL(clicked()), this, SLOT(initMonopigator()));
+	connect(m_refreshButton, SIGNAL(clicked()), this, SLOT(slotRefresh()));
 
 	m_connectButton = new KPushButton(BarIcon("forward", KIcon::SizeSmall), i18n("Connect"), this);
 	m_connectButton->setEnabled(false);
 	buttonBox->addWidget(m_connectButton);
 
-	connect(m_connectButton, SIGNAL(clicked()), this, SLOT(connectClicked()));
+	connect(m_connectButton, SIGNAL(clicked()), this, SLOT(slotConnect()));
 	
     // Status indicator
 	status_label = new QLabel(this);
 	m_mainLayout->addWidget(status_label);
 
 	// Monopigator
-	monopigator = new Monopigator();
+	m_monopigator = new Monopigator();
 
-	connect(monopigator, SIGNAL(monopigatorClear()), this, SLOT(slotMonopigatorClear()));
-	connect(monopigator, SIGNAL(monopigatorAdd(QString, QString, QString, int)), this, SLOT(slotMonopigatorAdd(QString, QString, QString, int)));
-	connect(monopigator, SIGNAL(finished()), SLOT(monopigatorFinished()));
+	connect(m_monopigator, SIGNAL(monopigatorAdd(QString, QString, QString, int)), this, SLOT(slotMonopigatorAdd(QString, QString, QString, int)));
+	connect(m_monopigator, SIGNAL(finished()), SLOT(monopigatorFinished()));
 
 	// Until we have a good way to use start a local monopd server, disable this button
 //	m_localGameButton->setEnabled(false);
 
-	initMonopigator();
+	slotRefresh();
+}
+
+SelectServer::~SelectServer()
+{
+	delete m_monopigator;
+	delete m_localSocket;
 }
 
 void SelectServer::initMonopigator()
 {
 	// Hardcoded, but there aren't any other Monopigator root servers at the moment
 	status_label->setText(i18n("Retrieving server list..."));
-	monopigator->loadData("http://gator.monopd.net/");
+	m_monopigator->loadData("http://gator.monopd.net/");
 }
 
-void SelectServer::slotMonopigatorClear()
+void SelectServer::checkLocalServer()
 {
-	m_serverList->clear();
-	validateConnectButton();
-//	emit statusChanged();
+	m_localSocket = new KExtendedSocket(0, 0, KExtendedSocket::inputBufferedSocket);
+	connect(m_localSocket, SIGNAL(connectionSuccess()), this, SLOT(slotLocalConnected()));
+	connect(m_localSocket, SIGNAL(connectionFailed(int)), this, SLOT(slotLocalError()));
+	m_localSocket->setAddress("localhost", 1234);
+	m_localSocket->enableRead(true);
+	m_localSocket->startAsyncConnect();
 }
 
 void SelectServer::slotMonopigatorAdd(QString host, QString port, QString version, int users)
@@ -111,12 +120,25 @@
 	validateConnectButton();
 }
 
-void SelectServer::monopigatorFinished()
+void SelectServer::slotLocalConnected()
 {
-	// TODO : remove, this is temporarily until there is a good way to fork a server
+	m_localServerAvailable = true;
+
 	QListViewItem *item = new QListViewItem(m_serverList, "localhost", i18n("unknown"), i18n("unknown"), QString::number(1234));
 	item->setPixmap(0, BarIcon("atlantik", KIcon::SizeSmall));
+
 	validateConnectButton();
+}
+
+void SelectServer::slotLocalError()
+{
+	m_localServerAvailable = false;
+
+	// TODO: fork server or offer option to do so
+}
+
+void SelectServer::monopigatorFinished()
+{
 	status_label->setText(i18n("Retrieved server list."));
 }
 
@@ -154,7 +176,18 @@
 		m_onlineGameButton->toggle();
 }
 
-void SelectServer::connectClicked()
+void SelectServer::slotRefresh()
+{
+	m_localServerAvailable = false;
+
+	m_serverList->clear();
+	validateConnectButton();
+
+	checkLocalServer();
+	initMonopigator();
+}
+
+void SelectServer::slotConnect()
 {
 	if (QListViewItem *item = m_serverList->selectedItem())
 		emit serverConnect(item->text(0), item->text(3).toInt());

Index: selectserver_widget.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectserver_widget.h,v
retrieving revision 1.9
retrieving revision 1.9.6.1
diff -u -d -r1.9 -r1.9.6.1
--- selectserver_widget.h	1 Aug 2002 15:16:25 -0000	1.9
+++ selectserver_widget.h	7 Jan 2003 22:57:46 -0000	1.9.6.1
@@ -1,4 +1,4 @@
-// Copyright (c) 2002 Rob Kaper <[email protected]>
+// Copyright (c) 2002-2003 Rob Kaper <[email protected]>
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License
@@ -27,12 +27,15 @@
 
 #include "monopigator.h"
 
+class KExtendedSocket;
+
 class SelectServer : public QWidget
 {
 Q_OBJECT
 
 public:
 	SelectServer(QWidget *parent, const char *name=0);
+	virtual ~SelectServer();
 
 	void initPage();
 		bool validateNext();
@@ -40,30 +43,35 @@
 		int portToConnect();
 
 	public slots:
-		void initMonopigator();
-
 		void validateRadioButtons();
 		void validateConnectButton();
 
-		void slotMonopigatorClear();
 		void slotMonopigatorAdd(QString host, QString port, QString version, int users);
 		void slotListClicked(QListViewItem *);
 
 	private slots:
-		void connectClicked();
+		void slotConnect();
+		void slotRefresh();
+		void slotLocalConnected();
+		void slotLocalError();
 		void monopigatorFinished();
 
 	signals:
 		void serverConnect(const QString host, int port);
 //		void statusChanged();
 
-	private:
+private:
+	void checkLocalServer();
+	void initMonopigator();
+
 		QVBoxLayout *m_mainLayout;
 		QLabel *status_label;
 		QRadioButton *m_localGameButton, *m_onlineGameButton;
 		KListView *m_serverList;
 		KPushButton *m_refreshButton, *m_connectButton;
-		Monopigator *monopigator;
+		Monopigator *m_monopigator;
+		KExtendedSocket *m_localSocket;
+		bool m_localServerAvailable;
 };
 
 #endif
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.