From c99347bf9108367c02dcbdebadec0b978a750c57 Mon Sep 17 00:00:00 2001
From: Stefan Dombrowski <stefan@uni-bonn.de>
Date: Sat, 4 Sep 2010 23:50:20 +0200
Subject: Fixing segmentation fault if server is given on command line

If server and port was given on the command line, then the server type
was unknown. The command line options do work now, but only if standard
ports 6901 and 9601 are used.

This resolves http://bugs.manasource.org/view.php?id=177

TODO: Query the server about itself and choose the server type based on that.

Reviewed-by: Jaxad0127
---
 src/net/net.cpp | 12 +++++++++++-
 src/net/net.h   |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

(limited to 'src/net')

diff --git a/src/net/net.cpp b/src/net/net.cpp
index 5e7c989f..7e7395a6 100644
--- a/src/net/net.cpp
+++ b/src/net/net.cpp
@@ -22,6 +22,7 @@
 #include "net/net.h"
 
 #include "main.h"
+#include "log.h"
 
 #include "net/adminhandler.h"
 #include "net/charhandler.h"
@@ -41,6 +42,8 @@
 
 #include "net/manaserv/generalhandler.h"
 
+#include "utils/gettext.h"
+
 Net::AdminHandler *adminHandler = NULL;
 Net::CharHandler *charHandler = NULL;
 Net::ChatHandler *chatHandler = NULL;
@@ -124,12 +127,19 @@ namespace Net
 {
 ServerInfo::Type networkType = ServerInfo::UNKNOWN;
 
-void connectToServer(const ServerInfo &server)
+void connectToServer(ServerInfo &server)
 {
     if (server.type == ServerInfo::UNKNOWN)
     {
         // TODO: Query the server about itself and choose the netcode based on
         // that
+
+        if (server.port == 6901)
+            server.type = ServerInfo::TMWATHENA;
+        else if (server.port == 9601)
+            server.type = ServerInfo::MANASERV;
+        else
+            logger->error(_("Unknown Server Type! Exiting."));
     }
 
     if (networkType == server.type && getGeneralHandler() != NULL)
diff --git a/src/net/net.h b/src/net/net.h
index 9d9ee10e..6029f3ba 100644
--- a/src/net/net.h
+++ b/src/net/net.h
@@ -67,7 +67,7 @@ ServerInfo::Type getNetworkType();
 /**
  * Handles server detection and connection
  */
-void connectToServer(const ServerInfo &server);
+void connectToServer(ServerInfo &server);
 
 void unload();
 
-- 
cgit v1.2.3-70-g09d2