/*

 BabbleMud - A MUD server

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

(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 "globals.h"

using namespace std; 


// global variables
bool   bStopNow = false;      // when set, the MUD shuts down
time_t tLastMessage = 0;      // time we last sent a periodic message 
int    iMudControl = NO_SOCKET;  // socket for accepting new players 
int    iWebControl = NO_SOCKET;  // socket for accepting new web clients 

// we do it this way to avoid the "static initialisation order fiasco"
// see: C++ FAQ Lite by Marshall Cline
//    http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.11
// and also: Effective C++ Second Edition p 217 (Scott Meyers)
//   (item 47: "Ensure that non-local static objects are intialised before
//             they are used")
//
//  Effectively what might happen wihout doing this is that a map element
//   might be used before the map's constructor is called, leading to a crash.


// I have to do it with a define and not a class or we simply move the
// problem into when does the class get instantiated
#define MAKE_STATIC_HANDLER(type, name)  \
type & name ()  \
  {  \
  static type name##_;  \
  return name##_;  \
  }
  
// errors (for throwing)
MAKE_STATIC_HANDLER (StringMap, errormap);
// messages (for general use)
MAKE_STATIC_HANDLER (StringMap, messagemap);
// commands (from commands file)
MAKE_STATIC_HANDLER (ObjectList, commands);
// command handlers
MAKE_STATIC_HANDLER (CommandHandlerMap, getCommandHandlerMap);
// web page handlers
MAKE_STATIC_HANDLER (WebHandlerMap, getWebHandlerMap);
// connection state handlers
MAKE_STATIC_HANDLER (StateHandlerMap, getStateMap);
// event handlers
MAKE_STATIC_HANDLER (EventHandlerMap, getEventHandlerMap);
// control items
MAKE_STATIC_HANDLER (TopThing, control);
// map of all rooms
MAKE_STATIC_HANDLER (WorldMap, world);
// objects 
MAKE_STATIC_HANDLER (ObjectList, objects);
// mobs 
MAKE_STATIC_HANDLER (ObjectList, mobs);
// resets 
MAKE_STATIC_HANDLER (ObjectList, resets);
// rooms 
MAKE_STATIC_HANDLER (ObjectList, rooms);
// list of all connected players
MAKE_STATIC_HANDLER (PlayerList, playerlist);   
// list of all connected web clients
MAKE_STATIC_HANDLER (WebClientList, webclientlist);   
// list of all mobs
MAKE_STATIC_HANDLER (CharacterList, moblist);   
// events queue
MAKE_STATIC_HANDLER (EventQueue, eventQueue);   
// characters playing (including mobs)
MAKE_STATIC_HANDLER (PlayingMap, playing);   
// miscellaneous server info (not saved)
MAKE_STATIC_HANDLER (thing, serverInfo);   
// failed passwords
MAKE_STATIC_HANDLER (StringIntMap, badWebPasswords);
MAKE_STATIC_HANDLER (StringIntMap, badPlayerPasswords);

ofstream logFileGeneral;
ofstream logFileFailedCommands;
ofstream logFileFailedMobCommands;
ofstream logFileWebServer;

#undef MAKE_STATIC_HANDLER

