00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <cstdlib>
00030 #include <cstring>
00031 #include <csignal>
00032
00033 #include <QCoreApplication>
00034 #include <QDir>
00035
00036 #include "Archivero.hpp"
00037 #include "Ejecutor.hpp"
00038 #include "Guardian.hpp"
00039 #include "Log.hpp"
00040 #include "Mensajero.hpp"
00041 #include "Servidor.hpp"
00042
00043
00044 QDir dir_datos (".");
00045 Archivero *miArchiv;
00046 Ejecutor *miEjecut;
00047 Guardian *miGuard;
00048 Mensajero *miMensaj;
00049 Servidor *miServer;
00050
00051
00053 void CompruebaDirDatos ()
00054 {
00055
00056 QStringList lista (dir_datos.entryList (QDir::Files | QDir::Readable).filter
00057 ("entidad.dtd", Qt::CaseInsensitive));
00058
00059 QStringList::iterator iter (lista.begin());
00060
00061 for ( ; iter != lista.end(); ++iter)
00062 if ((*iter).length() == 11)
00063 break;
00064
00065 if (iter == lista.end())
00066 qFatal ("Directorio de datos \"%s\" incorrecto.",
00067 dir_datos.absolutePath().toLatin1().constData());
00068 }
00069
00071 void GestionaSenyal (int num)
00072 {
00073 QString numstr;
00074 numstr.setNum (num);
00075
00076 Log (8, "Señal recibida");
00077 Log (7, " (número de señal: " + numstr + ")");
00078 Log (8, ", cerrando el MUD.\n");
00079
00080 delete miMensaj;
00081 delete miServer;
00082 delete miEjecut;
00083 delete miArchiv;
00084 delete miGuard;
00085
00086 exit (0);
00087 }
00088
00090 void LeeOpciones (const int argc, char **argv)
00091 {
00092 for (unsigned short s = 1; s < argc; s++)
00093 {
00094 if (!strcmp (argv[s], "--help"))
00095 {
00096 Log (10, "MUnDoCAAD MUD Engine\n"
00097 "Copyright (C) 2002-2005 José Manuel Ferrer Ortiz\n\n"
00098 "Este programa es software libre; puedes redistribuirlo y/o "
00099 "modificarlo bajo los\ntérminos de la GNU General Public License "
00100 "versión 2, como ha sido publicada por\nla Free Software "
00101 "Foundation.\n\n"
00102 "Este programa se distribuye con la esperanza de que sea útil, pero "
00103 "SIN NINGUNA\nGARANTÍA. Vea la GNU General Public License versión "
00104 "2 para más detalles.\n\n"
00105 "Modo de empleo:\n" +
00106 QString (argv[0]) + " [-p prolijidad] [-d directorio de datos] "
00107 "[-f fichero de registro] [--help]\n");
00108 exit (0);
00109 }
00110 if (!strcmp (argv[s], "-p"))
00111 {
00112 s++;
00113 if (s >= argc)
00114 qFatal ("Faltan parámetros.");
00115 prolijidad = (unsigned char) strtoul (argv[s], NULL, 10);
00116 }
00117 else if (!strcmp (argv[s], "-d"))
00118 {
00119 s++;
00120 if (s >= argc)
00121 qFatal ("Faltan parámetros.");
00122 dir_datos = QDir::cleanPath (argv[s]);
00123 }
00124 else if (!strcmp (argv[s], "-f"))
00125 {
00126 s++;
00127 if (s >= argc)
00128 qFatal ("Faltan parámetros.");
00129 if ((fichero_log = fopen (argv[s], "a")) == NULL)
00130 {
00131 perror ("fopen()");
00132 exit (-1);
00133 }
00134 }
00135 else
00136 qFatal ("Parámetro en la posición %d (\"%s\") inesperado.", s + 1,
00137 argv[s]);
00138 }
00139 }
00140
00141 int main (int argc, char **argv)
00142 {
00143 qInstallMsgHandler (ManejadorMensajes);
00144 QCoreApplication aplicacion (argc, argv);
00145
00146 LeeOpciones (argc, argv);
00147
00148
00149 Log (9, "MUnDoCAAD MUD Engine\n"
00150 "Copyright (C) 2002-2005 José Manuel Ferrer Ortiz\n\n");
00151
00152 CompruebaDirDatos();
00153 Log (5, "Directorio de datos del MUD: " + dir_datos.absolutePath() + "\n");
00154
00155
00156 signal (SIGINT, GestionaSenyal);
00157 signal (SIGTERM, GestionaSenyal);
00158
00159 miArchiv = new Archivero;
00160 miEjecut = new Ejecutor;
00161 miGuard = new Guardian;
00162 miMensaj = new Mensajero;
00163 miServer = new Servidor;
00164
00165 return (aplicacion.exec());
00166 }