File indexing completed on 2024-05-12 17:11:43

0001 /*************************************************************************
0002  *   Copyright (C) 2007 by Romain Campioni                               *
0003  *   Copyright (C) 2009 by Renaud Guezennec                              *
0004  *   Copyright (C) 2011 by Joseph Boudou                                 *
0005  *   https://rolisteam.org/                                           *
0006  *                                                                       *
0007  *   Rolisteam is free software; you can redistribute it and/or modify   *
0008  *   it under the terms of the GNU General Public License as published   *
0009  *   by the Free Software Foundation; either version 2 of the License,   *
0010  *   or (at your option) any later version.                              *
0011  *                                                                       *
0012  *   This program is distributed in the hope that it will be useful,     *
0013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of      *
0014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
0015  *   GNU General Public License for more details.                        *
0016  *                                                                       *
0017  *   You should have received a copy of the GNU General Public License   *
0018  *   along with this program; if not, write to the                       *
0019  *   Free Software Foundation, Inc.,                                     *
0020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           *
0021  *************************************************************************/
0022 
0023 #include <QCommandLineOption>
0024 #include <QCommandLineParser>
0025 #include <QCoreApplication>
0026 #include <QCryptographicHash>
0027 #include <QDateTime>
0028 #include <QResource>
0029 #include <QTranslator>
0030 #include <QUuid>
0031 #include <iostream>
0032 #include <string>
0033 #include <time.h>
0034 
0035 #include "rolisteamdaemon.h"
0036 #include "version.h"
0037 
0038 #ifdef Q_OS_LINUX
0039 #include "rolisteamdaemonadaptor.h"
0040 #include <QDBusConnection>
0041 #endif
0042 
0043 /**
0044  * @page Roliserver
0045  * @tableofcontents
0046  * @author Renaud Guezennec
0047  *
0048  *  @section intro_sec Introduction
0049  * Rolisteam help you to manage role playing games with your friend all over the world.<br/>
0050  * Rolisteam is a free software under GNU/GPL. Its purpose is to provide all features required to<br/>
0051  * perform Role playing games with remote friends.<br/>
0052  * It is based on Client/server architecture and it is written in C++ with Qt.<br/>
0053  *
0054  * @section features_sec Features:
0055  * - Chat with one, many and all players
0056  * - Sharing images and many other media type
0057  * - Drawing maps on the fly
0058  * - Sharing environment sound
0059  * - Multi-platform: Windows, Linux and Mac OS X
0060  * - Powerful die rolling syntax
0061  * - Theme and skin: make your own skin, save it, share it.
0062  * - Useful preferences systems
0063  *
0064  *
0065  *
0066  * @section install_sec Installation
0067  * To get documentation on how to install rolisteam: http://doc.rolisteam.org/
0068  *
0069  * @section How to stay in touch ?
0070  * Please, visit: https://rolisteam.org/
0071  *
0072  * @section tools_subsec Dependencies:
0073  * Qt6, zlib, QML,
0074  * @subpage DiceParser
0075  *
0076  * @section copyright Copyright and License
0077  * GNU/GPLv2
0078  *
0079  * <BR><BR>
0080  *
0081  *
0082  */
0083 /**
0084  * @brief main
0085  * @param argc
0086  * @param argv
0087  * @return
0088  */
0089 int main(int argc, char* argv[])
0090 {
0091     // Application creation
0092     QCoreApplication app(argc, argv);
0093 
0094     QString appName("roliserver");
0095 
0096     app.setOrganizationName("Rolisteam");
0097     app.setApplicationName(appName);
0098     app.setApplicationVersion(version::version);
0099 
0100     // QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
0101     // QString locale = QLocale::system().name();
0102 
0103     QCommandLineParser parser;
0104     parser.addHelpOption();
0105     parser.addVersionOption();
0106 
0107     QCommandLineOption configuration(QStringList() << "c"
0108                                                    << "config",
0109                                      QObject::tr("Set the path to configuration file [mandatory]"), "config");
0110     QCommandLineOption print(QStringList() << "p"
0111                                            << "print",
0112                              QObject::tr("Print a default configuration file into Standard output"), "output");
0113     QCommandLineOption hashPassword(QStringList() << "g"
0114                                                   << "generate",
0115                                     QObject::tr("Ask for password and return its hash key."), "password");
0116 
0117     parser.addOption(configuration);
0118     parser.addOption(print);
0119     parser.addOption(hashPassword);
0120 
0121     parser.parse(app.arguments());
0122     parser.process(app.arguments());
0123 
0124     bool hasConfig= parser.isSet(configuration);
0125     bool askPrint= parser.isSet(print);
0126     bool askHash= parser.isSet(hashPassword);
0127 
0128     if(askHash)
0129     {
0130         std::cout << "Please enter your password [Then Press Enter]" << std::endl;
0131         std::string password;
0132         std::cin >> password;
0133         std::cout << "The hash key is:\n"
0134                   << QCryptographicHash::hash(QByteArray::fromStdString(password), QCryptographicHash::Sha3_512)
0135                          .toBase64()
0136                          .toStdString()
0137                   << std::endl;
0138         return 0;
0139     }
0140 
0141     QString configPath;
0142 
0143     if(hasConfig)
0144     {
0145         configPath= parser.value(configuration);
0146     }
0147 
0148     RolisteamDaemon deamon;
0149 #ifdef Q_OS_LINUX
0150     new RolisteamDaemonAdaptor(&deamon);
0151 
0152     QDBusConnection connection= QDBusConnection::sessionBus();
0153     bool rel= connection.registerService("org.rolisteam.server");
0154     rel= connection.registerObject("/", &deamon);
0155 #endif
0156 
0157     if(askPrint)
0158     {
0159         QString configPathOut= parser.value(print);
0160         deamon.createEmptyConfigFile(configPathOut);
0161         return 0;
0162     }
0163     if(configPath.isEmpty())
0164     {
0165         std::cout << "Error - no configuration file" << std::endl;
0166         parser.showHelp();
0167     }
0168 
0169     if(!deamon.readConfigFile(configPath))
0170     {
0171         std::cout << "Error - Configuration file error" << std::endl;
0172         parser.showHelp();
0173     }
0174 
0175     QObject::connect(&deamon, &RolisteamDaemon::stopped, &app, &QCoreApplication::quit);
0176     deamon.start();
0177     return app.exec();
0178 }