Index: trunk/src/orxonox.cc
===================================================================
--- trunk/src/orxonox.cc	(revision 5982)
+++ trunk/src/orxonox.cc	(revision 5996)
@@ -57,4 +57,6 @@
 #include "load_param_description.h"
 
+#include "network_manager.h"
+
 #include <string.h>
 
@@ -79,4 +81,8 @@
   this->argc = 0;
   this->argv = NULL;
+
+  /* this way, there is no network enabled: */
+  this->serverName = NULL;
+  this->port = -1;
 
   this->configFileName = NULL;
@@ -118,11 +124,11 @@
 
   PRINT(3)
-      (
-      "===================================================\n" \
-      "Thanks for playing orxonox.\n" \
-      "visit: http://www.orxonox.net for new versions.\n" \
-      "===================================================\n" \
-      ORXONOX_LICENSE_SHORT
-      );
+  (
+    "===================================================\n" \
+    "Thanks for playing orxonox.\n" \
+    "visit: http://www.orxonox.net for new versions.\n" \
+    "===================================================\n" \
+    ORXONOX_LICENSE_SHORT
+  );
 
   Orxonox::singletonRef = NULL;
@@ -137,21 +143,21 @@
 void Orxonox::restart()
 {
-//   int argc = this->argc;
-//   char** argv = this->argv;
-//
-//   Orxonox *orx = Orxonox::getInstance();
-//
-//   delete orx;
-//
-//   orx = Orxonox::getInstance();
-//
-//   if((*orx).init(argc, argv) == -1)
-//   {
-//     PRINTF(1)("! Orxonox initialization failed\n");
-//     return;
-//   }
-//
-//   printf("finished inizialisation\n");
-//   orx->start();
+  //   int argc = this->argc;
+  //   char** argv = this->argv;
+  //
+  //   Orxonox *orx = Orxonox::getInstance();
+  //
+  //   delete orx;
+  //
+  //   orx = Orxonox::getInstance();
+  //
+  //   if((*orx).init(argc, argv) == -1)
+  //   {
+  //     PRINTF(1)("! Orxonox initialization failed\n");
+  //     return;
+  //   }
+  //
+  //   printf("finished inizialisation\n");
+  //   orx->start();
 }
 
@@ -179,16 +185,15 @@
  * initialize Orxonox with command line
  */
-int Orxonox::init (int argc, char** argv)
+int Orxonox::init (int argc, char** argv, const char* name, int port)
 {
   this->argc = argc;
   this->argv = argv;
-  // parse command line
-  // config file
+
+  this->serverName = name;
+  this->port = port;
 
   // initialize the Config-file
   this->getConfigFile();
 
-  // initialize everything
-  SDL_Init(SDL_INIT_TIMER);
   // windows must not write into stdout.txt and stderr.txt
 #ifdef __WIN32__
@@ -197,17 +202,26 @@
 #endif
 
-  if( initResources () == -1) return -1;
-  if( initVideo() == -1) return -1;
-  if( initSound() == -1) return -1;
-  if( initInput() == -1) return -1;
-  if( initNetworking () == -1) return -1;
-  if( initMisc () == -1) return -1;
-
-  return 0;
-}
+  // initialize everything
+  SDL_Init(SDL_INIT_TIMER);
+  if( initResources () == -1)
+    return -1;
+  if( initVideo() == -1)
+    return -1;
+  if( initSound() == -1)
+    return -1;
+  if( initInput() == -1)
+    return -1;
+  if( initNetworking () == -1)
+    return -1;
+  if( initMisc () == -1)
+    return -1;
+
+  return 0;
+}
+
 
 /**
  * initializes SDL and OpenGL
-*/
+ */
 int Orxonox::initVideo()
 {
@@ -226,4 +240,5 @@
   return 0;
 }
+
 
 /**
@@ -263,5 +278,9 @@
   PRINT(3)("> Initializing networking\n");
 
-  printf("  ---Not yet implemented-FIXME--\n");
+  if( this->serverName != NULL) // we are a client
+    NetworkManager::getInstance()->establishConnection(this->serverName, port);
+  else if( this->port > 0)      // we are a server
+    NetworkManager::getInstance()->createServer(port);
+
   return 0;
 }
@@ -282,5 +301,5 @@
   {
     if (!ResourceManager::getInstance()->setDataDir(dataPath) &&
-         !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
+        !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
     {
       PRINTF(1)("Data Could not be located in %s\n", dataPath);
@@ -301,5 +320,5 @@
     exit(-1);
   }
-   //! @todo this is a hack and should be loadable
+  //! @todo this is a hack and should be loadable
   char* imageDir = ResourceManager::getInstance()->getFullName("maps");
   ResourceManager::getInstance()->addImageDir(imageDir);
@@ -332,5 +351,10 @@
 
   this->gameLoader = GameLoader::getInstance();
-  this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
+
+  if( this->port != -1 || this->serverName != NULL)
+    this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc"); /* actualy loadNetworkCampaign*/
+  else
+    this->gameLoader->loadCampaign("worlds/DefaultCampaign.oxc");
+
   //  this->gameLoader->loadDebugCampaign(DEBUG_CAMPAIGN_0);
   this->gameLoader->init();
@@ -375,31 +399,94 @@
 int main(int argc, char** argv)
 {
-  // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
   int i;
   for(i = 1; i < argc; ++i)
+  {
+    if(     !strcmp( "--help", argv[i])     || !strcmp("-h", argv[i]))
+      return showHelp(argc, argv);
+    else if(!strcmp( "--gui", argv[i])      || !strcmp("-g", argv[i]))
+      showGui = true;
+    else if(!strcmp( "--client", argv[i])   || !strcmp("-c", argv[i]))
+      return startNetworkOrxonox(argc, argv);
+    else if(!strcmp( "--server", argv[i])   || !strcmp("-s", argv[i]))
+      return startNetworkOrxonox(argc, argv);
+    else if(!strcmp( "--license", argv[i])  || !strcmp("-s", argv[i]))
+      return PRINT(0)(ORXONOX_LICENSE_SHORT);
+  }
+
+  return startOrxonox(argc, argv, NULL, -1);
+}
+
+
+
+int showHelp(int argc, char** argv)
+{
+  PRINT(0)("Orxonox Version %s\n", PACKAGE_VERSION);
+  PRINT(0)(" Starts Orxonox - The most furious 3D Action Game :)\n");
+  PRINT(0)("\n");
+  PRINT(0)("Common options:\n");
+  PRINT(0)(" -g, --gui                        starts the orxonox with the configuration GUI \n");
+  PRINT(0)(" -h, --help                       shows this help\n");
+  PRINT(0)("\n");
+  PRINT(0)("Network options:\n");
+  PRINT(0)(" -s, --server [port]              starts Orxonox and listens on the [port] for players\n");
+  PRINT(0)(" -c, --client [hostname] [port]   starts Orxonox as a Client\n");
+  PRINT(0)(" -c, --client [ip address] [port] starts Orxonox as a Client\n");
+  PRINT(0)("\n");
+  PRINT(0)("Other options:\n");
+  PRINT(0)("     --license     prints the licence and exit\n\n");
+  PRINT(0)("\n");
+
+  //   {
+  //     Gui* gui = new Gui(argc, argv);
+  //     gui->printHelp();
+  //     delete gui;
+  //   }
+}
+
+
+
+
+/**
+ * starts orxonox in network mode
+ * @param argc parameters count given to orxonox
+ * @param argv parameters given to orxonox
+ */
+int startNetworkOrxonox(int argc, char** argv)
+{
+
+  int i;
+  for(i = 0; i < argc; ++i )
+  {
+    if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i]))
     {
-      if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
-//      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
-      else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
-      //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
+      if( argc <= (i+2))
+      {
+        printf(" Wrong arguments try following notations:\n");
+        printf("   --client [server ip address] [port number]\n");
+        printf("   --client [dns name] [port number]\n");
+        return 0;
+      }
+
+      const char* name = argv[i+1];
+      int port = atoi(argv[i+2]);
+      printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port);
+
+      startOrxonox(argc, argv, name, port);
     }
-
-  return startOrxonox(argc, argv);
-}
-
-
-
-int startHelp(int argc, char** argv)
-{
-  PRINT(0)("orxonox: starts the orxonox game - rules\n");
-  PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
-  PRINT(0)("valid options:\n");
-  {
-    Gui* gui = new Gui(argc, argv);
-    gui->printHelp();
-    delete gui;
-  }
-  PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
-  PRINT(0)(" -h|--help:\t\t\tshows this help\n");
+    else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i]))
+    {
+      if( argc <= (i+1))
+      {
+        printf(" Wrong arguments try following notations:\n");
+        printf("   --server [port number]\n");
+        return 0;
+      }
+
+      int port = atoi(argv[i+1]);
+      printf("Starting Orxonox as server, listening on port %i\n", port);
+
+      startOrxonox(argc, argv, NULL, port);
+    }
+  }
 }
 
@@ -411,26 +498,26 @@
  * @param argv parameters given to orxonox
  */
-int startOrxonox(int argc, char** argv)
+int startOrxonox(int argc, char** argv, const char* name, int port)
 {
   // checking for existence of the configuration-files, or if the lock file is still used
   if (showGui || (!ResourceManager::isFile("./orxonox.conf") &&
-      !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
+                  !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
 #if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails
-       || ResourceManager::isFile(DEFAULT_LOCK_FILE)
+      || ResourceManager::isFile(DEFAULT_LOCK_FILE)
 #endif
      )
-    {
-      if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
-        ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
-
-      // starting the GUI
-      Gui* gui = new Gui(argc, argv);
-      gui->startGui();
-
-      if (! gui->startOrxonox)
-        return 0;
-
-      delete gui;
-    }
+  {
+    if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
+      ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
+
+    // starting the GUI
+    Gui* gui = new Gui(argc, argv);
+    gui->startGui();
+
+    if (! gui->startOrxonox)
+      return 0;
+
+    delete gui;
+  }
 
   PRINT(0)(">>> Starting Orxonox <<<\n");
@@ -440,11 +527,11 @@
   Orxonox *orx = Orxonox::getInstance();
 
-  if(orx->init(argc, argv) == -1)
-    {
-      PRINTF(1)("! Orxonox initialization failed\n");
-      return -1;
-    }
-
-    printf("finished inizialisation\n");
+  if( orx->init(argc, argv, name, port) == -1)
+  {
+    PRINTF(1)("! Orxonox initialization failed\n");
+    return -1;
+  }
+
+  printf("finished inizialisation\n");
   orx->start();
 
