EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
eve-tool.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur
24 */
25 
26 #include "eve-tool.h"
27 
28 #include "Commands.h"
29 
30 const char* const CACHE_DIR = EVEMU_ROOT "/cache";
31 const char* const LOG_FILE = EVEMU_ROOT "/log/eve-tool.log";
32 const char* const LOG_SETTINGS_FILE = EVEMU_ROOT "/etc/log.ini";
33 
34 int main( int argc, char* argv[] )
35 {
36 #if defined( HAVE_CRTDBG_H ) && !defined( NDEBUG )
37  // Under Visual Studio setup memory leak detection
38  _CrtSetDbgFlag( _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) );
39 #endif /* defined( HAVE_CRTDBG_H ) && !defined( NDEBUG ) */
40 
41  // Load server log settings ( will be removed )
43  sLog.Warning( "init", "Unable to read %s (this file is optional)", LOG_SETTINGS_FILE );
44  else
45  sLog.Success( "init", "Log settings loaded from %s", LOG_SETTINGS_FILE );
46 
47  if( !log_open_logfile( LOG_FILE ) )
48  sLog.Warning( "init", "Unable to open log file '%s', only logging to the screen now.", LOG_FILE );
49  else
50  sLog.Success( "init", "Opened log file %s", LOG_FILE );
51 
52  //skip first argument (launch path), we don't need it
53  --argc;
54  ++argv;
55 
56  for(; argc > 0; --argc, ++argv)
57  ProcessFile( *argv );
58 
59  ProcessFile( stdin );
60 
61  sLog.Log( "shutdown", "Exiting." );
62 
63  return 0;
64 }
65 
66 void ProcessString( const char* str )
67 {
68  ProcessCommand( Seperator( str ) );
69 }
70 
71 void ProcessString( const std::string& str )
72 {
73  ProcessString( str.c_str() );
74 }
75 
76 void ProcessFile( FILE* file )
77 {
78  std::string cmd;
79 
80  while( true )
81  {
82  char input = fgetc( file );
83 
84  if( '\n' == input || EOF == input )
85  {
86  if( !cmd.empty() )
87  {
88  ProcessString( cmd );
89  cmd.clear();
90  }
91 
92  if( EOF == input )
93  break;
94  }
95  else
96  cmd += input;
97  }
98 }
99 
100 void ProcessFile( const char* filename )
101 {
102  ProcessFile( std::string( filename ) );
103 }
104 
105 void ProcessFile( const std::string& filename )
106 {
107  FILE* file = fopen( filename.c_str(), "r" );
108  if( NULL == file )
109  {
110  sLog.Error( "input", "Unable to open script '%s'.", filename.c_str() );
111  return;
112  }
113 
114  sLog.Log( "input", "Queuing commands from script '%s'.", filename.c_str() );
115  ProcessFile( file );
116 
117  if( feof( file ) )
118  sLog.Success( "input", "Load of script '%s' successfully completed.", filename.c_str() );
119  else
120  sLog.Error( "input", "Error occured while reading script '%s'.", filename.c_str() );
121 
122  fclose( file );
123 }
124 
125 
126 
127 
const char *const CACHE_DIR
Definition: eve-tool.cpp:30
bool load_log_settings(const char *filename)
Definition: logsys.cpp:168
bool log_open_logfile(const char *filename)
Definition: logsys.cpp:149
void ProcessFile(FILE *file)
Loads commands from given file.
Definition: eve-tool.cpp:76
Separates string to arguments.
Definition: Seperator.h:36
#define sLog
Evaluates to a NewLog instance.
Definition: LogNew.h:250
const char *const LOG_FILE
Definition: eve-tool.cpp:31
void ProcessCommand(const Seperator &cmd)
Processed given command.
Definition: Commands.cpp:82
int main(int argc, char *argv[])
Definition: eve-tool.cpp:34
void ProcessString(const char *str)
Processes given string as command.
Definition: eve-tool.cpp:66
const char *const LOG_SETTINGS_FILE
Definition: eve-tool.cpp:32