45 filespec = malloc(strlen(dir)+2+1);
46 strcpy(filespec, dir);
47 index = strlen(filespec)-1;
49 filespec[
index] =
'\0';
50 strcat(filespec,
"/*");
52 dp = (DIR *)malloc(
sizeof(DIR));
55 dp->dir = strdup(dir);
57 if ((
handle = _findfirst(filespec, &(dp->fileinfo))) < 0) {
78 if (!dp || dp->finished)
81 if (dp->offset != 0) {
82 if (_findnext(dp->handle, &(dp->fileinfo)) < 0) {
92 strncpy(dp->dent.d_name, dp->fileinfo.name, _MAX_FNAME);
93 dp->dent.d_name[_MAX_FNAME] =
'\0';
96 dp->dent.d_reclen = strlen(dp->dent.d_name)+
sizeof(char)+
sizeof(dp->dent.d_ino)+
sizeof(dp->dent.d_reclen)+
sizeof(dp->dent.d_off);
97 dp->dent.d_off = dp->offset;
113 _findclose(dp->handle);
132 dir_Info->handle = 0;
133 dir_Info->offset = 0;
134 dir_Info->finished = 0;
136 filespec = malloc(strlen(dir_Info->dir)+2+1);
137 strcpy(filespec, dir_Info->dir);
138 index = strlen(filespec)-1;
140 filespec[
index] =
'\0';
141 strcat(filespec,
"/*");
143 if ((
handle = _findfirst(filespec, &(dir_Info->fileinfo))) < 0) {
144 if (errno == ENOENT) {
145 dir_Info->finished = 1;
148 dir_Info->handle =
handle;
162 SERVICE_STATUS m_ServiceStatus;
164 SERVICE_STATUS_HANDLE m_ServiceStatusHandle;
166 #define SERVICE_NAME L"Crossfire"
168 #define SERVICE_DISPLAY L"Crossfire server"
170 #define SERVICE_DESCRIPTION L"Crossfire is a multiplayer online RPG game."
179 TCHAR strDir[MAX_PATH];
180 HANDLE schSCManager, schService;
181 wchar_t *strDescription = SERVICE_DESCRIPTION;
183 GetModuleFileName(NULL, strDir, MAX_PATH);
184 wcscat(strDir, L
" -srv");
186 schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
188 if (schSCManager == NULL) {
189 printf(
"openscmanager failed");
193 schService = CreateService(schSCManager,
197 SERVICE_WIN32_OWN_PROCESS,
198 SERVICE_DEMAND_START,
199 SERVICE_ERROR_NORMAL,
207 if (schService == NULL) {
208 printf(
"createservice failed");
212 ChangeServiceConfig2(schService, SERVICE_CONFIG_DESCRIPTION, &strDescription);
214 CloseServiceHandle(schService);
215 CloseServiceHandle(schSCManager);
227 schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
229 if (schSCManager == NULL) {
230 printf(
"open failed");
234 hService = OpenService(schSCManager, SERVICE_NAME, SERVICE_ALL_ACCESS);
236 if (hService == NULL) {
237 printf(
"openservice failed");
241 if (DeleteService(hService) == 0) {
242 printf(
"Delete failed");
246 if (CloseServiceHandle(hService) == 0) {
247 printf(
"close failed");
251 if (!CloseServiceHandle(schSCManager)) {
252 printf(
"close schSCManager failed");
265 void WINAPI ServiceCtrlHandler(DWORD Opcode) {
267 case SERVICE_CONTROL_PAUSE:
268 m_ServiceStatus.dwCurrentState = SERVICE_PAUSED;
271 case SERVICE_CONTROL_CONTINUE:
272 m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
275 case SERVICE_CONTROL_STOP:
276 m_ServiceStatus.dwWin32ExitCode = 0;
277 m_ServiceStatus.dwCurrentState = SERVICE_STOPPED;
278 m_ServiceStatus.dwCheckPoint = 0;
279 m_ServiceStatus.dwWaitHint = 0;
281 SetServiceStatus(m_ServiceStatusHandle, &m_ServiceStatus);
289 case SERVICE_CONTROL_INTERROGATE:
295 extern int main(
int argc,
char **argv);
304 void WINAPI ServiceMain(DWORD argc, LPTSTR *argv) {
308 GetModuleFileName(NULL, strDir, 1024);
309 strSlash = wcschr(strDir,
'\\');
314 m_ServiceStatus.dwServiceType = SERVICE_WIN32;
315 m_ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
316 m_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
317 m_ServiceStatus.dwWin32ExitCode = 0;
318 m_ServiceStatus.dwServiceSpecificExitCode = 0;
319 m_ServiceStatus.dwCheckPoint = 0;
320 m_ServiceStatus.dwWaitHint = 0;
322 m_ServiceStatusHandle = RegisterServiceCtrlHandler(SERVICE_NAME, ServiceCtrlHandler);
323 if (m_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0) {
327 m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
328 m_ServiceStatus.dwCheckPoint = 0;
329 m_ServiceStatus.dwWaitHint = 0;
330 SetServiceStatus(m_ServiceStatusHandle, &m_ServiceStatus);
342 SERVICE_TABLE_ENTRY DispatchTable[] = {
343 { SERVICE_NAME, ServiceMain },
346 StartServiceCtrlDispatcher(DispatchTable);