/*

 BabbleMud - A MUD server

 Author:  Nick Gammon 
          http://www.gammon.com.au/ 

 Date:    22nd July 2004

(C) Copyright Nick Gammon 2004. Permission to copy, use, modify, sell and
distribute this software is granted provided this copyright notice appears
in all copies. This software is provided "as is" without express or implied
warranty, and with no claim as to its suitability for any purpose.
 
*/

// standard library includes ...

#include <iostream>

using namespace std; 

#include "constants.h"
#include "globals.h"
#include "gameutils.h"

void LoadThings ();
int InitComms ();
void MainLoop ();
void CloseComms ();
   
// main program
int main ()
{

  cout << MUDNAME << " version " << VERSION << endl;
  cout << "Started up at: " << stringDate (time (NULL)) << endl;
  
  try
    {
    LoadThings ();    // load stuff
   
    if (InitComms ()) // listen for new connections
      return 1;
        
    Event e (eSendToAll, 30000, -1);
    e.sets ("msg", "Something goes 'bing'!");
    
    eventQueue ().push (e);
        
    gamelog ("Game startup");
    
    MainLoop ();    // handle player input/output
      
    // game over - tell them all
    SendToAll ("\n\n** Game shut down. **\n\n");
    
    CloseComms ();  // stop listening

    gamelog ("Game shutdown");

   }
  catch (exception & e)
    {
    cerr << "Exception raised: " << e.what () << endl;
    return 1;
    }
  
  cout << "Game shut down." << endl;  
  cout << "Shut down at: " << stringDate (time (NULL)) << endl;
  return 0;
}   // end of main
