[atlantik-cvs] CVS: kdegames/atlantik/client main.h,1.29,1.30 selectserver_widget.cpp,1.18,1.19 selectserver_widget.h,1.9,1.10

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

Modified Files:
	main.h selectserver_widget.cpp selectserver_widget.h 
Log Message:
only show localhost server when it is available

Index: main.h
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/main.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- main.h	6 Jan 2003 01:34:47 -0000	1.29
+++ main.h	7 Jan 2003 22:23:31 -0000	1.30
@@ -18,7 +18,7 @@
 #define ATLANTIK_MAIN_H
 
 #define	ATLANTIK_VERSION 060
-#define	ATLANTIK_VERSION_STRING "0.6.0 (CVS >= 20030105)"
+#define	ATLANTIK_VERSION_STRING "0.6.0 (CVS >= 20030107)"
 #define ATLANTIK_VERSION_MAJOR 0
 #define ATLANTIK_VERSION_MINOR 6
 #define ATLANTIK_VERSION_RELEASE 0

Index: selectserver_widget.cpp
===================================================================
RCS file: /home/kde/kdegames/atlantik/client/selectserver_widget.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- selectserver_widget.cpp	13 Aug 2002 18:09:42 -0000	1.18
+++ selectserver_widget.cpp	7 Jan 2003 22:23:31 -0000	1.19
@@ -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,41 +66,60 @@
 	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(monopigatorClear()), this, SLOT(slotMonopigatorClear()));
+	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::checkLocalServer()
+{
+	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::slotMonopigatorClear()
 {
 	m_serverList->clear();
+	if (m_localServerAvailable)
+		slotLocalConnected();
+
 	validateConnectButton();
 //	emit statusChanged();
 }
@@ -111,12 +131,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 +187,15 @@
 		m_onlineGameButton->toggle();
 }
 
-void SelectServer::connectClicked()
+void SelectServer::slotRefresh()
+{
+	m_localServerAvailable = false;
+
+	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.10
diff -u -d -r1.9 -r1.10
--- selectserver_widget.h	1 Aug 2002 15:16:25 -0000	1.9
+++ selectserver_widget.h	7 Jan 2003 22:23:31 -0000	1.10
@@ -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,8 +43,6 @@
 		int portToConnect();
 
 	public slots:
-		void initMonopigator();
-
 		void validateRadioButtons();
 		void validateConnectButton();
 
@@ -50,20 +51,28 @@
 		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.