1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #include <dialogs/NetworkSelectDialog.h>
22 #include <dialogs/MsgBoxDialog.h>
23 #include <dialogs/NetworkChatDialog.h>
24 #include <GLW/GLWWindowManager.h>
25 #include <GLW/GLWFont.h>
26 #include <GLW/GLWTranslate.h>
27 #include <GLW/GLWPanel.h>
28 #include <GLEXT/GLViewPort.h>
29 #include <GLEXT/GLTextureStore.h>
30 #include <serverbrowser/ServerBrowser.h>
31 #include <client/ScorchedClient.h>
32 #include <client/ClientParams.h>
33 #include <client/ClientMain.h>
34 #include <common/Defines.h>
35 #include <common/OptionsScorched.h>
36 
37 struct ColumnInfo
38 {
39 	GLWIconTable::Column col;
40 	const char *dataName;
41 };
getGamesCols()42 static ColumnInfo *getGamesCols()
43 {
44 	static ColumnInfo gamescols[] =
45 	{
46 		GLWIconTable::Column(LANG_STRING(""), 60), "",
47 		GLWIconTable::Column(LANG_RESOURCE("SERVER_NAME", "Server Name"), 255), "servername",
48 		GLWIconTable::Column(LANG_RESOURCE("PLYRS", "Plyrs"), 60), "noplayers",
49 		GLWIconTable::Column(LANG_RESOURCE("ROUND", "Round"), 55), "round",
50 		GLWIconTable::Column(LANG_RESOURCE("MOD", "Mod"), 95), "mod",
51 		GLWIconTable::Column(LANG_RESOURCE("GAME_TYPE", "Game Type"), 200), "gametype",
52 		GLWIconTable::Column(LANG_STRING(""), -1), ""
53 	};
54 	return gamescols;
55 }
56 
getPlayerCols()57 static ColumnInfo *getPlayerCols()
58 {
59 	static ColumnInfo playerscols[] =
60 	{
61 		GLWIconTable::Column(LANG_RESOURCE("PLAYER", "Player"), 270), "pn",
62 		GLWIconTable::Column(LANG_RESOURCE("SCORE", "Score"), 260), "ps",
63 		GLWIconTable::Column(LANG_RESOURCE("TIME", "Time"), 140), "pt",
64 		GLWIconTable::Column(LANG_RESOURCE("REAL", "Real"), 60), "pa",
65 		GLWIconTable::Column(LANG_STRING(""), -1), ""
66 	};
67 	return playerscols;
68 }
69 
70 NetworkSelectDialog *NetworkSelectDialog::instance_ = 0;
71 
instance()72 NetworkSelectDialog *NetworkSelectDialog::instance()
73 {
74 	if (!instance_)
75 	{
76 		instance_ = new NetworkSelectDialog;
77 	}
78 	return instance_;
79 }
80 
NetworkSelectDialog()81 NetworkSelectDialog::NetworkSelectDialog() :
82 	GLWWindow("Network", 780.0f, 560.0f, eHideName, ""),
83 	totalTime_(0.0f), invalidateId_(0),
84 	okTex_(ImageID(S3D::eDataLocation,
85 		"data/images/ok.bmp",
86 		"data/images/mask.bmp")),
87 	questionTex_(ImageID(S3D::eDataLocation,
88 		"data/images/question.bmp",
89 		"data/images/mask.bmp")),
90 	warningTex_(ImageID(S3D::eDataLocation,
91 		"data/images/warn.bmp",
92 		"data/images/mask.bmp")),
93 	noentryTex_(ImageID(S3D::eDataLocation,
94 		"data/images/noentry.bmp",
95 		"data/images/mask.bmp")),
96 	exclaimTex_(ImageID(S3D::eDataLocation,
97 		"data/images/exclaim.bmp",
98 		"data/images/mask.bmp")),
99 	keyTex_(ImageID(S3D::eDataLocation,
100 		"data/images/key.bmp",
101 		"data/images/keya.bmp",
102 		true)),
103 	cogTex_(ImageID(S3D::eDataLocation,
104 		"data/images/cog.bmp",
105 		"data/images/coga.bmp",
106 		true)),
107 	tankTex_(ImageID(S3D::eDataLocation,
108 		"",
109 		"data/images/tank2.png"))
110 {
111 	std::list<GLWIconTable::Column> gamescolumns, playerscolumns;
112 	for (int i=0;; i++)
113 	{
114 		if (getGamesCols()[i].col.width == -1) break;
115 		gamescolumns.push_back(getGamesCols()[i].col);
116 	}
117 	for (int i=0;; i++)
118 	{
119 		if (getPlayerCols()[i].col.width == -1) break;
120 		playerscolumns.push_back(getPlayerCols()[i].col);
121 	}
122 
123 	gamesIconTable_ = new GLWIconTable(10.0f, 165.0f, 760.0f, 350.0f, &gamescolumns, 20.0f);
124 	addWidget(gamesIconTable_);
125 	gamesIconTable_->setHandler(this);
126 
127 	playersIconTable_ = new GLWIconTable(10.0f, 45.0f, 760.0f, 110.0f, &playerscolumns, 20.0f);
128 	addWidget(playersIconTable_);
129 	playersIconTable_->setHandler(this);
130 
131 	ok_ = (GLWTextButton *) addWidget(
132 		new GLWTextButton(LANG_RESOURCE("JOIN_GAME", "Join Game"), 640, 10, 130, this,
133 		GLWButton::ButtonFlagCenterX));
134 	cancelId_ = addWidget(
135 		new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 530, 10, 105, this,
136 		GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX))->getId();
137 	refresh_ = (GLWTextButton *) addWidget(
138 		new GLWTextButton(LANG_RESOURCE("REFRESH_LIST", "Refresh List"), 175, 10, 150, this,
139 		GLWButton::ButtonFlagCenterX));
140 	favourites_ = (GLWTextButton *) addWidget(
141 		new GLWTextButton(LANG_RESOURCE("ADD_FAVOURITE", "Add Favourite"), 10, 10, 155, this,
142 		GLWButton::ButtonFlagCenterX));
143 
144 	addWidget(new GLWPanel(220.0f, 525.0f, 300.0f, 25.0f, true));
145 	ipaddress_ = (GLWLabel *) addWidget(
146 		new GLWLabel(225.0f, 525.0f));
147 	connectTo_ = (GLWTextButton *) addWidget(
148 		new GLWTextButton(LANG_RESOURCE("CONNECT_TO_LABEL", "Connect To :"), 75.0f, 527.0f, 135, this,
149 		GLWButton::ButtonFlagCenterX));
150 
151 	refreshType_ = (GLWDropDownText *) addWidget(
152 		new GLWDropDownText(530.0f, 525.0f, 150.0f));
153 	refreshType_->addText(LANG_RESOURCE("INTERNET", "Internet"), "Internet");
154 	refreshType_->addText(LANG_RESOURCE("LAN", "LAN"), "LAN");
155 	refreshType_->addText(LANG_RESOURCE("FAVOURITES", "Favourites"), "Favourites");
156 	refreshType_->setCurrentText(LANG_RESOURCE("INTERNET", "Internet"));
157 	refreshType_->setHandler(this);
158 }
159 
~NetworkSelectDialog()160 NetworkSelectDialog::~NetworkSelectDialog()
161 {
162 
163 }
164 
draw()165 void NetworkSelectDialog::draw()
166 {
167 	if (needCentered_)
168 	{
169 		int wWidth = GLViewPort::getWidth();
170 		int wHeight = GLViewPort::getHeight();
171 		setX((wWidth - getW()) / 2.0f);
172 		setY(MAX(0, (wHeight - getH()) - 25.0f));
173 		needCentered_ = false;
174 	}
175 
176 	GLWWindow::draw();
177 }
178 
simulate(float frameTime)179 void NetworkSelectDialog::simulate(float frameTime)
180 {
181 	GLWWindow::simulate(frameTime);
182 
183 	totalTime_ += frameTime;
184 	if (totalTime_ > 1.0f)
185 	{
186 		updateTable();
187 	}
188 }
189 
drawIcon(GLTexture * tex,float & x,float y,LangString & message)190 void NetworkSelectDialog::drawIcon(GLTexture *tex, float &x, float y, LangString &message)
191 {
192 	GLState state(GLState::TEXTURE_ON | GLState::BLEND_ON);
193 	glColor3f(1.0f, 1.0f, 1.0f);
194 	tex->draw();
195 
196 	float w = 18.0f;
197 	float h = 18.0f;
198 	glBegin(GL_QUADS);
199 		glTexCoord2f(0.0f, 0.0f);
200 		glVertex2f(x, y);
201 		glTexCoord2f(1.0f, 0.0f);
202 		glVertex2f(x + w, y);
203 		glTexCoord2f(1.0f, 1.0f);
204 		glVertex2f(x + w, y + h);
205 		glTexCoord2f(0.0f, 1.0f);
206 		glVertex2f(x, y + h);
207 	glEnd();
208 
209 	if (GLWToolTip::instance()->addToolTip(&colToolTip_,
210 		GLWTranslate::getPosX() + x,
211 		GLWTranslate::getPosY() + y,
212 		w, h))
213 	{
214 		colToolTip_.setText(ToolTip::ToolTipInfo,
215 			LANG_RESOURCE("STATUS_ICON", "Status Icon"), message);
216 	}
217 
218 	x += w;
219 }
220 
getTexture(int row,LangString * & message)221 GLTexture *NetworkSelectDialog::getTexture(int row, LangString *&message)
222 {
223 	std::string pversion =
224 		ServerBrowser::instance()->getServerList().
225 			getEntryValue(row, "protocolversion");
226 	std::string version =
227 		ServerBrowser::instance()->getServerList().
228 			getEntryValue(row, "version");
229 	if (!serverCompatable(pversion, version))
230 	{
231 		LANG_RESOURCE_CONST_VAR(INCOMPATIBLE,
232 			"INCOMPATIBLE_VERSION", "Incompatible version.");
233 		message = &INCOMPATIBLE;
234 		return noentryTex_.getTexture();
235 	}
236 
237 	std::string clients =
238 		ServerBrowser::instance()->getServerList().
239 			getEntryValue(row, "noplayers");
240 	std::string maxclients =
241 		ServerBrowser::instance()->getServerList().
242 			getEntryValue(row, "maxplayers");
243 	if (clients.size() > 0 &&
244 		0 == strcmp(clients.c_str(), maxclients.c_str()))
245 	{
246 		LANG_RESOURCE_CONST_VAR(SERVER_FULL,
247 			"SERVER_FULL", "Server is full.");
248 		message = &SERVER_FULL;
249 		return exclaimTex_.getTexture();
250 	}
251 
252 	std::string state =
253 		ServerBrowser::instance()->getServerList().
254 			getEntryValue(row, "state");
255 	if (0 == strcmp(state.c_str(), "Waiting"))
256 	{
257 		LANG_RESOURCE_CONST_VAR(NOT_STARTED,
258 			"GAME_NOT_STARTED", "Game has not started.");
259 		message = &NOT_STARTED;
260 		return warningTex_.getTexture();
261 	}
262 	if (0 == strcmp(state.c_str(), "Started"))
263 	{
264 		LANG_RESOURCE_CONST_VAR(GAME_PROGESS,
265 			"GAME_IN_PROGRESS", "Game in progress and spaces on server.");
266 		message = &GAME_PROGESS;
267 		return okTex_.getTexture();
268 	}
269 
270 	LANG_RESOURCE_CONST_VAR(CANNOT_CONTACT_SERVER,
271 		"CANNOT_CONTACT_SERVER", "Cannot contact server.");
272 	message = &CANNOT_CONTACT_SERVER;
273 	return questionTex_.getTexture();
274 }
275 
drawColumn(unsigned int id,int row,int col,float x,float y,float w)276 void NetworkSelectDialog::drawColumn(unsigned int id, int row, int col,
277 	float x, float y, float w)
278 {
279 	if (id == gamesIconTable_->getId()) drawColumnGames(id, row, col, x, y, w);
280 	else if (id == playersIconTable_->getId()) drawColumnPlayers(id, row, col, x, y, w);
281 }
282 
drawColumnGames(unsigned int id,int row,int col,float x,float y,float w)283 void NetworkSelectDialog::drawColumnGames(unsigned int id, int row, int col,
284 	float x, float y, float w)
285 {
286 	if (row < 0 || row >= ServerBrowser::instance()->getServerList().getNoEntries())
287 	{
288 		return;
289 	}
290 
291 	std::string value, tipValue;
292 	if (col == 0)
293 	{
294 		LANG_RESOURCE_CONST_VAR(NONE, "NONE", "None");
295 
296 		{
297 			LangString *message = &NONE;
298 			GLTexture *tex = getTexture(row, message);
299 			drawIcon(tex, x, y, *message);
300 		}
301 
302 		std::string key =
303 			ServerBrowser::instance()->getServerList().
304 				getEntryValue(row, "password");
305 		if (0 == strcmp(key.c_str(), "On"))
306 		{
307 			LANG_RESOURCE_CONST_VAR(
308 				PASSWORD_PROTECTED, "PASSWORD_PROTECTED", "Password protected.");
309 			drawIcon(keyTex_.getTexture(), x, y, PASSWORD_PROTECTED);
310 		}
311 
312 		std::string officialStr =
313 			ServerBrowser::instance()->getServerList().
314 				getEntryValue(row, "type");
315 		if (officialStr == "official")
316 		{
317 			LANG_RESOURCE_CONST_VAR(
318 				OFFICAL_SERVER, "OFFICAL_SERVER", "An offical server.");
319 			drawIcon(tankTex_.getTexture(), x, y, OFFICAL_SERVER);
320 		}
321 		else if (officialStr == "mod")
322 		{
323 			LANG_RESOURCE_CONST_VAR(
324 				MOD_SERVER, "MOD_SERVER", "Home of mod server.");
325 			drawIcon(cogTex_.getTexture(), x, y, MOD_SERVER);
326 		}
327 	}
328 	else if (col == 2)
329 	{
330 		std::string clients =
331 			ServerBrowser::instance()->getServerList().
332 				getEntryValue(row, "noplayers");
333 		std::string maxclients =
334 			ServerBrowser::instance()->getServerList().
335 				getEntryValue(row, "maxplayers");
336 		std::string compplayers =
337 			ServerBrowser::instance()->getServerList().
338 				getEntryValue(row, "compplayers");
339 
340 		std::string name;
341 		if (compplayers.c_str()[0])
342 		{
343 			name = S3D::formatStringBuffer("%s/%s (%i)", clients.c_str(), maxclients.c_str(),
344 				(atoi(clients.c_str()) - atoi(compplayers.c_str())));
345 		}
346 		else
347 		{
348 			name = S3D::formatStringBuffer("%s/%s (?)", clients.c_str(), maxclients.c_str());
349 		}
350 
351 		std::string message = name;
352 		int noplayers = atoi(clients.c_str());
353 		for (int i=0; i<noplayers; i++)
354 		{
355 			std::string pn =
356 				ServerBrowser::instance()->getServerList().getEntryValue(
357 					row, S3D::formatStringBuffer("pn%i", i));
358 			std::string pa =
359 				ServerBrowser::instance()->getServerList().getEntryValue(
360 					row, S3D::formatStringBuffer("pa%i", i));
361 
362 			message.append(S3D::formatStringBuffer("\n%i: %s: %s",
363 				i, pa.c_str(), pn.c_str()));
364 		}
365 
366 		value = S3D::formatStringBuffer("%s", name.c_str());
367 		tipValue = S3D::formatStringBuffer("%s", message.c_str());
368 	}
369 	else
370 	{
371 		tipValue = value = ServerBrowser::instance()->getServerList().getEntryValue(row, getGamesCols()[col].dataName);
372 		if (value.empty() && col == 1)
373 		{
374 			tipValue = value = ServerBrowser::instance()->getServerList().getEntryValue(row, "address");
375 		}
376 	}
377 
378 	if (!value.empty())
379 	{
380 		Vector color(0.3f, 0.3f, 0.3f);
381 		GLWFont::instance()->getGameFont()->drawWidth(w,
382 			color,
383 			10.0f, x + 3.0f, y + 5.0f, 0.0f, value);
384 
385 		if (!tipValue.empty())
386 		{
387 			if (GLWToolTip::instance()->addToolTip(&colToolTip_,
388 				GLWTranslate::getPosX() + x,
389 				GLWTranslate::getPosY() + y,
390 				w, 20.0f))
391 			{
392 				colToolTip_.setText(ToolTip::ToolTipInfo,
393 					getGamesCols()[col].col.name,
394 					LANG_STRING(tipValue));
395 			}
396 		}
397 	}
398 }
399 
drawColumnPlayers(unsigned int id,int row,int col,float x,float y,float w)400 void NetworkSelectDialog::drawColumnPlayers(unsigned int id, int row, int col,
401 	float x, float y, float w)
402 {
403 	int gamesrow = gamesIconTable_->getSelected();
404 	if (gamesrow < 0 || gamesrow >= ServerBrowser::instance()->getServerList().getNoEntries())
405 	{
406 		return;
407 	}
408 
409 	std::string valuestr =
410 		ServerBrowser::instance()->getServerList().getEntryValue(
411 			gamesrow, S3D::formatStringBuffer("%s%i", getPlayerCols()[col].dataName, row));
412 	const char *value = valuestr.c_str();
413 
414 	Vector color(0.3f, 0.3f, 0.3f);
415 	GLWFont::instance()->getGameFont()->drawWidth(w,
416 		color,
417 		10.0f, x + 3.0f, y + 5.0f, 0.0f, value);
418 }
419 
serverCompatable(std::string pversion,std::string version)420 bool NetworkSelectDialog::serverCompatable(std::string pversion, std::string version)
421 {
422 	if (pversion.size() > 0 &&
423 		pversion != S3D::ScorchedProtocolVersion)
424 	{
425 		return false;
426 	}
427 
428 	return true;
429 }
430 
rowSelected(unsigned int id,int row)431 void NetworkSelectDialog::rowSelected(unsigned int id, int row)
432 {
433 	if (id == gamesIconTable_->getId()) rowSelectedGames(id, row);
434 }
435 
rowSelectedGames(unsigned int id,int row)436 void NetworkSelectDialog::rowSelectedGames(unsigned int id, int row)
437 {
438 	if (row < 0 || row >= ServerBrowser::instance()->getServerList().getNoEntries())
439 	{
440 		return;
441 	}
442 
443 	// Check if we have any information for this row
444 	std::string ipaddress = ServerBrowser::instance()->
445 		getServerList().getEntryValue(row, "address");
446 	if (ipaddress.empty()) return;
447 
448 	// Check if this server is compatible
449 	std::string protocolVersion =
450 		ServerBrowser::instance()->getServerList().getEntryValue(row, "protocolversion");
451 	std::string version =
452 		ServerBrowser::instance()->getServerList().getEntryValue(row, "version");
453 	if (!serverCompatable(protocolVersion, version))
454 	{
455 		LangString msg = LANG_RESOURCE_4("INCOMPATIBLE_VERSION_WARNING",
456 			"Warning: This server is running a incompatible version of Scorched3D.\n"
457 			"You cannot connect to this server.\n\n"
458 			"This server is running Scorched build {0} ({1}).\n"
459 			"You are running Scorched build {2} ({3}).\n\n"
460 			"The latest version of Scorched3D can be downloaded from \n"
461 			"http://www.scorched3d.co.uk\n",
462 			version, protocolVersion,
463 			S3D::ScorchedVersion, S3D::ScorchedProtocolVersion);
464 		MsgBoxDialog::show(msg);
465 	}
466 
467 	// Set ip address for this server
468 	setIPAddress(LANG_STRING(ipaddress));
469 
470 	// Set players for this server
471 	std::string players =
472 		ServerBrowser::instance()->getServerList().getEntryValue(row, "noplayers");
473 	int noplayers = atoi(players.c_str());
474 	playersIconTable_->setItemCount(noplayers);
475 }
476 
rowChosen(unsigned int id,int row)477 void NetworkSelectDialog::rowChosen(unsigned int id, int row)
478 {
479 	if (id == gamesIconTable_->getId()) rowChosenGames(id, row);
480 }
481 
rowChosenGames(unsigned int id,int row)482 void NetworkSelectDialog::rowChosenGames(unsigned int id, int row)
483 {
484 	if (ok_->getEnabled()) buttonDown(ok_->getId());
485 }
486 
columnSelected(unsigned int id,int col)487 void NetworkSelectDialog::columnSelected(unsigned int id, int col)
488 {
489 	if (id == gamesIconTable_->getId()) columnSelectedGames(id, col);
490 }
491 
columnSelectedGames(unsigned int id,int col)492 void NetworkSelectDialog::columnSelectedGames(unsigned int id, int col)
493 {
494 	ServerBrowser::instance()->getServerList().sortEntries(getGamesCols()[col].dataName);
495 }
496 
display()497 void NetworkSelectDialog::display()
498 {
499 	GLWWindowManager::instance()->showWindow(NetworkChatDialog::instance()->getId());
500 
501 	setIPAddress(LangString());
502 	refreshType_->setCurrentText(LANG_RESOURCE("INTERNET", "Internet"));
503 }
504 
hide()505 void NetworkSelectDialog::hide()
506 {
507 	GLWWindowManager::instance()->hideWindow(NetworkChatDialog::instance()->getId());
508 
509 	stopRefresh();
510 }
511 
updateTable()512 void NetworkSelectDialog::updateTable()
513 {
514 	// Check if we are refreshing
515 	// Set the button accordingly
516 	if (!ServerBrowser::instance()->getRefreshing())
517 	{
518 		refresh_->setText(LANG_RESOURCE("REFRESH_LIST", "Refresh List"));
519 	}
520 	else
521 	{
522 		refresh_->setText(LANG_RESOURCE("STOP_REFRESH", "Stop Refresh"));
523 	}
524 
525 	// Check if we have more items to display
526 	if (invalidateId_ != ServerBrowser::instance()->
527 		getServerList().getRefreshId())
528 	{
529 		invalidateId_ = ServerBrowser::instance()->
530 			getServerList().getRefreshId();
531 		gamesIconTable_->setItemCount(
532 			ServerBrowser::instance()->getServerList().getNoEntries());
533 	}
534 }
535 
select(unsigned int id,const int pos,GLWSelectorEntry value)536 void NetworkSelectDialog::select(unsigned int id, const int pos, GLWSelectorEntry value)
537 {
538 	if (refreshType_->isSelected(LANG_RESOURCE("FAVOURITES", "Favourites")))
539 	{
540 		favourites_->setText(LANG_RESOURCE("DELETE_FAVOURITE", "Del Favourite"));
541 	}
542 	else
543 	{
544 		favourites_->setText(LANG_RESOURCE("ADD_FAVOURITE", "Add Favourite"));
545 	}
546 
547 	startRefresh();
548 }
549 
startRefresh()550 void NetworkSelectDialog::startRefresh()
551 {
552 	stopRefresh();
553 
554 	gamesIconTable_->setItemCount(0);
555 	playersIconTable_->setItemCount(0);
556 
557 	ServerBrowser::RefreshType t = ServerBrowser::RefreshNone;
558 	if (refreshType_->isSelected(LANG_RESOURCE("LAN", "LAN"))) t = ServerBrowser::RefreshLan;
559 	else if (refreshType_->isSelected(LANG_RESOURCE("INTERNET", "Internet"))) t = ServerBrowser::RefreshNet;
560 	else if (refreshType_->isSelected(LANG_RESOURCE("FAVOURITES", "Favourites"))) t = ServerBrowser::RefreshFavourites;
561 
562 	ServerBrowser::instance()->refreshList(t);
563 	updateTable();
564 }
565 
stopRefresh()566 void NetworkSelectDialog::stopRefresh()
567 {
568 	ServerBrowser::instance()->cancel();
569 	updateTable();
570 }
571 
setIPAddress(const LangString & text)572 void NetworkSelectDialog::setIPAddress(const LangString &text)
573 {
574 	ok_->setEnabled(text[0]!='\0');
575 	favourites_->setEnabled(text[0]!='\0');
576 	ipaddress_->setText(text);
577 }
578 
textBoxResult(TextBoxDialog * dialog,const LangString & result)579 void NetworkSelectDialog::textBoxResult(TextBoxDialog *dialog, const LangString &result)
580 {
581 	setIPAddress(result);
582 }
583 
buttonDown(unsigned int id)584 void NetworkSelectDialog::buttonDown(unsigned int id)
585 {
586 	if (id == refresh_->getId())
587 	{
588 		if (ServerBrowser::instance()->getRefreshing())
589 		{
590 			stopRefresh();
591 		}
592 		else
593 		{
594 			startRefresh();
595 		}
596 	}
597 	else if (id == ok_->getId())
598 	{
599 		GLWWindowManager::instance()->hideWindow(id_);
600 
601 		if (!ipaddress_->getText().empty())
602 		{
603 			ClientParams::instance()->reset();
604 			ClientParams::instance()->setConnect(ipaddress_->getText().c_str());
605 			ClientMain::startClient();
606 		}
607 	}
608 	else if (id == favourites_->getId())
609 	{
610 		if (!ipaddress_->getText().empty())
611 		{
612 			std::set<std::string> favs =
613 				ServerBrowser::instance()->getCollect().getFavourites();
614 
615 			if (refreshType_->isSelected(LANG_RESOURCE("FAVOURITES", "Favourites")))
616 			{
617 				favs.erase(ipaddress_->getText().c_str());
618 			}
619 			else
620 			{
621 				favs.insert(ipaddress_->getText().c_str());
622 			}
623 			ServerBrowser::instance()->getCollect().setFavourites(favs);
624 
625 			if (refreshType_->isSelected(LANG_RESOURCE("FAVOURITES", "Favourites")))
626 			{
627 				startRefresh();
628 			}
629 		}
630 	}
631 	else if (id == cancelId_)
632 	{
633 		GLWWindowManager::instance()->hideWindow(id_);
634 	}
635 	else if (id == connectTo_->getId())
636 	{
637 		TextBoxDialog::instance()->show(LANG_RESOURCE("EDIT_CONNECTION",
638 			"Edit connection details : HostName or HostName:Port\n"
639 			"e.g. 192.168.1.1:27270 or 192.168.1.2 or scorched3d.co.uk:27270"),
640 			ipaddress_->getLangString(), this);
641 	}
642 }
643