Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5829 in orxonox.OLD for branches/network/src/orxonox.cc


Ignore:
Timestamp:
Nov 30, 2005, 9:43:05 AM (18 years ago)
Author:
patrick
Message:

network: much work on multiplayability, does not yet work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/orxonox.cc

    r5822 r5829  
    5757#include "load_param_description.h"
    5858
     59#include "network_manager.h"
     60
    5961#include <string.h>
    6062
     
    7981  this->argc = 0;
    8082  this->argv = NULL;
     83
     84  /* this way, there is no network enabled: */
     85  this->clientName = NULL;
     86  this->port = -1;
    8187
    8288  this->configFileName = NULL;
     
    118124
    119125  PRINT(3)
    120       (
    121       "===================================================\n" \
    122       "Thanks for playing orxonox.\n" \
    123       "visit: http://www.orxonox.net for new versions.\n" \
    124       "===================================================\n" \
    125       ORXONOX_LICENSE_SHORT
    126       );
     126  (
     127    "===================================================\n" \
     128    "Thanks for playing orxonox.\n" \
     129    "visit: http://www.orxonox.net for new versions.\n" \
     130    "===================================================\n" \
     131    ORXONOX_LICENSE_SHORT
     132  );
    127133
    128134  Orxonox::singletonRef = NULL;
     
    137143void Orxonox::restart()
    138144{
    139 //   int argc = this->argc;
    140 //   char** argv = this->argv;
    141 //
    142 //   Orxonox *orx = Orxonox::getInstance();
    143 //
    144 //   delete orx;
    145 //
    146 //   orx = Orxonox::getInstance();
    147 //
    148 //   if((*orx).init(argc, argv) == -1)
    149 //   {
    150 //     PRINTF(1)("! Orxonox initialization failed\n");
    151 //     return;
    152 //   }
    153 //
    154 //   printf("finished inizialisation\n");
    155 //   orx->start();
     145  //   int argc = this->argc;
     146  //   char** argv = this->argv;
     147  //
     148  //   Orxonox *orx = Orxonox::getInstance();
     149  //
     150  //   delete orx;
     151  //
     152  //   orx = Orxonox::getInstance();
     153  //
     154  //   if((*orx).init(argc, argv) == -1)
     155  //   {
     156  //     PRINTF(1)("! Orxonox initialization failed\n");
     157  //     return;
     158  //   }
     159  //
     160  //   printf("finished inizialisation\n");
     161  //   orx->start();
    156162}
    157163
     
    179185 * initialize Orxonox with command line
    180186 */
    181 int Orxonox::init (int argc, char** argv)
     187int Orxonox::init (int argc, char** argv, const char* name, int port)
    182188{
    183189  this->argc = argc;
    184190  this->argv = argv;
    185   // parse command line
    186   // config file
     191
     192  this->clientName = name;
     193  this->port = port;
    187194
    188195  // initialize the Config-file
    189196  this->getConfigFile();
    190197
    191   // initialize everything
    192   SDL_Init(SDL_INIT_TIMER);
    193198  // windows must not write into stdout.txt and stderr.txt
    194199#ifdef __WIN32__
     
    197202#endif
    198203
    199   if( initResources () == -1) return -1;
    200   if( initVideo() == -1) return -1;
    201   if( initSound() == -1) return -1;
    202   if( initInput() == -1) return -1;
    203   if( initNetworking () == -1) return -1;
    204   if( initMisc () == -1) return -1;
    205 
    206   return 0;
    207 }
     204  // initialize everything
     205  SDL_Init(SDL_INIT_TIMER);
     206  if( initResources () == -1)
     207    return -1;
     208  if( initVideo() == -1)
     209    return -1;
     210  if( initSound() == -1)
     211    return -1;
     212  if( initInput() == -1)
     213    return -1;
     214  if( initNetworking () == -1)
     215    return -1;
     216  if( initMisc () == -1)
     217    return -1;
     218
     219  return 0;
     220}
     221
    208222
    209223/**
    210224 * initializes SDL and OpenGL
    211 */
     225 */
    212226int Orxonox::initVideo()
    213227{
     
    226240  return 0;
    227241}
     242
    228243
    229244/**
     
    262277  PRINT(3)("> Initializing networking\n");
    263278
    264   printf("  ---Not yet implemented-FIXME--\n");
     279  NetworkManager::getInstance();
     280
     281  if( this->clientName != NULL) // we are a client
     282    NetworkManager::getInstance()->establishConnection(this->clientName, port);
     283  else if( this->port > 0)      // we are a server
     284    NetworkManager::getInstance()->createServer(port);
     285
    265286  return 0;
    266287}
     
    281302  {
    282303    if (!ResourceManager::getInstance()->setDataDir(dataPath) &&
    283          !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
     304        !ResourceManager::getInstance()->verifyDataDir(DEFAULT_DATA_DIR_CHECKFILE))
    284305    {
    285306      PRINTF(1)("Data Could not be located in %s\n", dataPath);
     
    300321    exit(-1);
    301322  }
    302    //! @todo this is a hack and should be loadable
     323  //! @todo this is a hack and should be loadable
    303324  char* imageDir = ResourceManager::getInstance()->getFullName("maps");
    304325  ResourceManager::getInstance()->addImageDir(imageDir);
     
    374395int main(int argc, char** argv)
    375396{
    376   // here the pre-arguments are loaded, these are needed to go either to orxonx itself, Help, or Benchmark.
    377397  int i;
    378398  for(i = 1; i < argc; ++i)
     399  {
     400    if(     !strcmp( "--help", argv[i])     || !strcmp("-h", argv[i]))
     401      return showHelp(argc, argv);
     402    else if(!strcmp( "--gui", argv[i])      || !strcmp("-g", argv[i]))
     403      showGui = true;
     404    else if(!strcmp( "--client", argv[i])   || !strcmp("-c", argv[i]))
     405      return startNetworkOrxonox(argc, argv);
     406    else if(!strcmp( "--server", argv[i])   || !strcmp("-s", argv[i]))
     407      return startNetworkOrxonox(argc, argv);
     408    else if(!strcmp( "--license", argv[i])  || !strcmp("-s", argv[i]))
     409      return PRINT(0)(ORXONOX_LICENSE_SHORT);
     410  }
     411
     412  return startOrxonox(argc, argv, NULL, -1);
     413}
     414
     415
     416
     417int showHelp(int argc, char** argv)
     418{
     419  PRINT(0)("Orxonox Version %s\n", PACKAGE_VERSION);
     420  PRINT(0)(" Starts Orxonox - The most furious 3D Action Game :)\n");
     421  PRINT(0)("\n");
     422  PRINT(0)("Common options:\n");
     423  PRINT(0)(" -g, --gui                        starts the orxonox with the configuration GUI \n");
     424  PRINT(0)(" -h, --help                       shows this help\n");
     425  PRINT(0)("\n");
     426  PRINT(0)("Network options:\n");
     427  PRINT(0)(" -s, --server [port]              starts Orxonox and listens on the [port] for players\n");
     428  PRINT(0)(" -c, --client [hostname] [port]   starts Orxonox as a Client\n");
     429  PRINT(0)(" -c, --client [ip address] [port] starts Orxonox as a Client\n");
     430  PRINT(0)("\n");
     431  PRINT(0)("Other options:\n");
     432  PRINT(0)("     --license     prints the licence and exit\n\n");
     433  PRINT(0)("\n");
     434
     435  //   {
     436  //     Gui* gui = new Gui(argc, argv);
     437  //     gui->printHelp();
     438  //     delete gui;
     439  //   }
     440}
     441
     442
     443
     444
     445/**
     446 * starts orxonox in network mode
     447 * @param argc parameters count given to orxonox
     448 * @param argv parameters given to orxonox
     449 */
     450int startNetworkOrxonox(int argc, char** argv)
     451{
     452
     453  int i;
     454  for(i = 0; i < argc; ++i )
     455  {
     456    if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i]))
    379457    {
    380       if(! strcmp( "--help", argv[i]) || !strcmp("-h", argv[i])) return startHelp(argc, argv);
    381 //      else if(!strcmp( "--benchmark", argv[i]) || !strcmp("-b", argv[i])) return startBenchmarks();
    382       else if(!strcmp( "--gui", argv[i]) || !strcmp("-g", argv[i])) showGui = true;
    383       //      else PRINTF(2)("Orxonox does not understand the arguments %s\n", argv[i]);
     458      if( argc <= (i+2))
     459      {
     460        printf(" Wrong arguments try following notations:\n");
     461        printf("   --client [server ip address] [port number]\n");
     462        printf("   --client [dns name] [port number]\n");
     463        return 0;
     464      }
     465
     466      const char* name = argv[i+1];
     467      int port = atoi(argv[i+2]);
     468      printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port);
     469
     470      startOrxonox(argc, argv, name, port);
    384471    }
    385 
    386   return startOrxonox(argc, argv);
    387 }
    388 
    389 
    390 
    391 int startHelp(int argc, char** argv)
    392 {
    393   PRINT(0)("orxonox: starts the orxonox game - rules\n");
    394   PRINT(0)("usage: orxonox [arg [arg...]]\n\n");
    395   PRINT(0)("valid options:\n");
    396   {
    397     Gui* gui = new Gui(argc, argv);
    398     gui->printHelp();
    399     delete gui;
    400   }
    401   PRINT(0)(" -b|--benchmark:\t\tstarts the orxonox benchmark\n");
    402   PRINT(0)(" -h|--help:\t\t\tshows this help\n");
     472    else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i]))
     473    {
     474      if( argc <= (i+1))
     475      {
     476        printf(" Wrong arguments try following notations:\n");
     477        printf("   --server [port number]\n");
     478        return 0;
     479      }
     480
     481      int port = atoi(argv[i+1]);
     482      printf("Starting Orxonox as server, listening on port %i\n", port);
     483
     484      startOrxonox(argc, argv, NULL, port);
     485    }
     486  }
    403487}
    404488
     
    410494 * @param argv parameters given to orxonox
    411495 */
    412 int startOrxonox(int argc, char** argv)
     496int startOrxonox(int argc, char** argv, const char* name, int port)
    413497{
    414498  // checking for existence of the configuration-files, or if the lock file is still used
    415499  if (showGui || (!ResourceManager::isFile("./orxonox.conf") &&
    416       !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
     500                  !ResourceManager::isFile(DEFAULT_CONFIG_FILE))
    417501#if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails
    418        || ResourceManager::isFile(DEFAULT_LOCK_FILE)
     502      || ResourceManager::isFile(DEFAULT_LOCK_FILE)
    419503#endif
    420504     )
    421     {
    422       if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
    423         ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
    424 
    425       // starting the GUI
    426       Gui* gui = new Gui(argc, argv);
    427       gui->startGui();
    428 
    429       if (! gui->startOrxonox)
    430         return 0;
    431 
    432       delete gui;
    433     }
     505  {
     506    if (ResourceManager::isFile(DEFAULT_LOCK_FILE))
     507      ResourceManager::deleteFile(DEFAULT_LOCK_FILE);
     508
     509    // starting the GUI
     510    Gui* gui = new Gui(argc, argv);
     511    gui->startGui();
     512
     513    if (! gui->startOrxonox)
     514      return 0;
     515
     516    delete gui;
     517  }
    434518
    435519  PRINT(0)(">>> Starting Orxonox <<<\n");
     
    439523  Orxonox *orx = Orxonox::getInstance();
    440524
    441   if(orx->init(argc, argv) == -1)
    442     {
    443       PRINTF(1)("! Orxonox initialization failed\n");
    444       return -1;
    445     }
    446 
    447     printf("finished inizialisation\n");
     525  if( orx->init(argc, argv, name, port) == -1)
     526  {
     527    PRINTF(1)("! Orxonox initialization failed\n");
     528    return -1;
     529  }
     530
     531  printf("finished inizialisation\n");
    448532  orx->start();
    449533
Note: See TracChangeset for help on using the changeset viewer.