| 1 |
/*******************************************************/ |
/*******************************************************/ |
| 2 |
/* */ |
/* */ |
| 3 |
/* LeafOK Innd */ |
/* LeafOK Innbbsd */ |
| 4 |
/* Copyright (C) LeafOK.com, 2003-2004 */ |
/* Copyright (C) LeafOK.com, 2003-2005 */ |
| 5 |
/* */ |
/* */ |
| 6 |
/* Programmed by Leaf */ |
/* Programmed by Leaf */ |
| 7 |
/* E-mail:leaf@leafok.com QQ:6049044 */ |
/* E-mail:leaflet@leafok.com QQ:6049044 */ |
| 8 |
/* */ |
/* */ |
| 9 |
/* http://bbs.leafok.com */ |
/* http://bbs.leafok.com */ |
| 10 |
/* http://bbs.leafok.net */ |
/* http://bbs.leafok.net */ |
| 20 |
#include ".\innbbsd.h" |
#include ".\innbbsd.h" |
| 21 |
#include ".\service.h" |
#include ".\service.h" |
| 22 |
#include ".\bbs_fun.h" |
#include ".\bbs_fun.h" |
| 23 |
|
#include ".\App_common.h" |
| 24 |
|
|
| 25 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 26 |
#define new DEBUG_NEW |
#define new DEBUG_NEW |
| 46 |
return 1; |
return 1; |
| 47 |
} |
} |
| 48 |
|
|
|
// TODO: 在此处为应用程序的行为编写代码。 |
|
|
|
|
| 49 |
// System settings |
// System settings |
| 50 |
const char* logfile_file = _T("innbbsd.log"); |
const char* conf_file = _T("innbbsd.conf"); |
| 51 |
|
const char* log_file = _T("innbbsd.log"); |
| 52 |
|
|
| 53 |
syslog.open(logfile_file,ios_base::out | ios_base::app); |
// Get application path |
| 54 |
|
CString app_path; |
| 55 |
|
int pos; |
| 56 |
|
|
| 57 |
|
app_path = argv[0]; |
| 58 |
|
pos = app_path.ReverseFind('\\'); |
| 59 |
|
if (pos != -1) |
| 60 |
|
app_path = app_path.Left(pos + 1); |
| 61 |
|
else |
| 62 |
|
app_path = ""; |
| 63 |
|
|
| 64 |
|
syslog.open(app_path + log_file, ios_base::out | ios_base::app); |
| 65 |
|
|
| 66 |
|
// Report program information |
| 67 |
|
syslog << "********************" << endl; |
| 68 |
|
syslog << App_common::GetVersion() << endl; |
| 69 |
|
syslog << App_common::Copyright << endl; |
| 70 |
|
syslog << logfile::log_head << "Starting up..." << endl; |
| 71 |
|
|
| 72 |
|
// Initialize sockets |
| 73 |
if(!AfxSocketInit()) |
if(!AfxSocketInit()) |
| 74 |
{ |
{ |
| 75 |
syslog << logfile::log_head << "Sockets init failed" << endl; |
syslog << logfile::log_head << "Sockets init failed" << endl; |
| 79 |
// Create the service object |
// Create the service object |
| 80 |
service innbbsd_srv; |
service innbbsd_srv; |
| 81 |
|
|
| 82 |
CString conf_file; |
innbbsd_srv.ctrld.load_conf(app_path + conf_file); |
|
conf_file = argv[0]; |
|
|
conf_file = conf_file.Left(conf_file.ReverseFind('\\')) + "\\innbbsd.conf"; |
|
|
|
|
|
innbbsd_srv.ctrld.load_conf(conf_file); |
|
| 83 |
|
|
| 84 |
//Standalone mode |
//Standalone mode |
| 85 |
if (argc == 2 && _stricmp(argv[1], "-s") == 0) |
if (argc == 2 && _stricmp(argv[1], "-s") == 0) |
| 86 |
{ |
{ |
| 87 |
innbbsd_srv.ctrld.begin(); |
innbbsd_srv.ctrld.InitThreadPool(); |
| 88 |
innbbsd_srv.ctrld.StartupChild(); |
|
| 89 |
|
if (innbbsd_srv.ctrld.begin() == 0) |
| 90 |
|
{ |
| 91 |
|
syslog << logfile::log_head << "Begin CONTROLD ... OK" << endl; |
| 92 |
|
|
| 93 |
|
innbbsd_srv.ctrld.StartupChild(); |
| 94 |
|
|
| 95 |
|
while (innbbsd_srv.ctrld.IsRunning()) |
| 96 |
|
{ |
| 97 |
|
Sleep(100); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
innbbsd_srv.ctrld.ShutdownChild(); |
| 101 |
|
} |
| 102 |
|
else |
| 103 |
|
{ |
| 104 |
|
syslog << logfile::log_head << "Begin CONTROLD ... Failed" << endl; |
| 105 |
|
} |
| 106 |
|
|
| 107 |
while (innbbsd_srv.ctrld.IsRunning()) |
if (innbbsd_srv.ctrld.end() == 0) |
| 108 |
|
{ |
| 109 |
|
syslog << logfile::log_head << "End CONTROLD ... OK" << endl; |
| 110 |
|
} |
| 111 |
|
else |
| 112 |
{ |
{ |
| 113 |
Sleep(100); |
syslog << logfile::log_head << "End CONTROLD ... Failed" << endl; |
| 114 |
} |
} |
| 115 |
|
|
| 116 |
|
innbbsd_srv.ctrld.CleanupThreadPool(); |
| 117 |
|
|
| 118 |
innbbsd_srv.ctrld.bbsd.end(); |
ExitProcess(0); |
|
innbbsd_srv.ctrld.innd.end(); |
|
|
innbbsd_srv.ctrld.outd.end(); |
|
|
innbbsd_srv.ctrld.end(); |
|
| 119 |
|
|
| 120 |
return 0; |
return 0; |
| 121 |
} |
} |
| 122 |
|
|
| 123 |
// Parse for standard arguments (install, uninstall, version etc.) |
// Display version infomation |
| 124 |
|
if (argc == 2 && _stricmp(argv[1], "-c") == 0) |
| 125 |
|
{ |
| 126 |
|
cout << App_common::GetVersion() << endl; |
| 127 |
|
cout << App_common::Copyright << endl; |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
// Parse for standard arguments (install, uninstall, version etc.) |
| 131 |
if (!innbbsd_srv.ParseStandardArgs(argc, argv)) { |
if (!innbbsd_srv.ParseStandardArgs(argc, argv)) { |
| 132 |
//DebugBreak(); |
//DebugBreak(); |
| 133 |
innbbsd_srv.StartService(); |
innbbsd_srv.StartService(); |