mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-04 09:23:12 +02:00
Win32 code cleanups
This commit is contained in:
@@ -259,3 +259,6 @@
|
||||
- Removed the * and ^ flags from /whois if PREFIX_AQ is not enabled (requested by many people)
|
||||
- Updated the /who docs to use correct English
|
||||
- Added documentation for the /who and /whois flags (#0001881) reported by AngryWolf and Bugz.
|
||||
- Added src/win32/win32.c for generic win32 helper functions
|
||||
- Renamed src/win32/win32gui.c to src/win32/gui.c
|
||||
- Reorganized much of the Windows code
|
||||
|
||||
+10
-6
@@ -141,7 +141,8 @@ EXP_OBJ_FILES=SRC/CHANNEL.OBJ SRC/SEND.OBJ SRC/SOCKET.OBJ \
|
||||
SRC/RANDOM.OBJ SRC/EXTCMODES.OBJ SRC/MD5.OBJ \
|
||||
SRC/EXTBANS.OBJ $(ZIPOBJ) $(CURLOBJ)
|
||||
|
||||
OBJ_FILES=$(EXP_OBJ_FILES) SRC/WIN32GUI.OBJ SRC/SERVICE.OBJ SRC/DEBUG.OBJ
|
||||
OBJ_FILES=$(EXP_OBJ_FILES) SRC/GUI.OBJ SRC/SERVICE.OBJ SRC/DEBUG.OBJ \
|
||||
SRC/WIN32.OBJ
|
||||
|
||||
MOD_FILES=SRC/MODULES/L_COMMANDS.C SRC/MODULES/M_CHGHOST.C SRC/MODULES/M_SDESC.C \
|
||||
SRC/MODULES/M_SETIDENT.C SRC/MODULES/M_SETNAME.C SRC/MODULES/M_SETHOST.C \
|
||||
@@ -362,18 +363,21 @@ src/hash.obj: src/hash.c $(INCLUDES) ./include/hash.h
|
||||
src/crule.obj: src/crule.c $(INCLUDES)
|
||||
$(CC) $(CFLAGS) src/crule.c
|
||||
|
||||
src/win32gui.obj: src/win32/win32gui.c $(INCLUDES) ./include/resource.h
|
||||
$(CC) $(CFLAGS) src/win32/win32gui.c
|
||||
src/gui.obj: src/win32/gui.c $(INCLUDES) ./include/resource.h
|
||||
$(CC) $(CFLAGS) src/win32/gui.c
|
||||
|
||||
src/service.obj: src/win32/service.c $(INCLUDES)
|
||||
$(CC) $(CFLAGS) src/win32/service.c
|
||||
|
||||
src/unreal.obj: src/win32/unreal.c $(INCLUDES)
|
||||
$(CC) $(CFLAGS) src/win32/unreal.c
|
||||
|
||||
src/debug.obj: src/win32/debug.c $(INCLUDES)
|
||||
$(CC) $(CFLAGS) src/win32/debug.c
|
||||
|
||||
src/win32.obj: src/win32/win32.c $(INCLUDES)
|
||||
$(CC) $(CFLAGS) src/win32/win32.c
|
||||
|
||||
src/unreal.obj: src/win32/unreal.c $(INCLUDES)
|
||||
$(CC) $(CFLAGS) src/win32/unreal.c
|
||||
|
||||
src/res_comp.obj: src/res_comp.c $(INCLUDES)
|
||||
$(CC) $(CFLAGS) src/res_comp.c
|
||||
|
||||
|
||||
+88
-58
@@ -1,6 +1,6 @@
|
||||
/************************************************************************
|
||||
* IRC - Internet Relay Chat, win32/debug.c
|
||||
* Copyright (C) 2002 Dominick Meglio (codemastr)
|
||||
* Copyright (C) 2002-2004 Dominick Meglio (codemastr)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -33,16 +33,24 @@
|
||||
#define IRCDTOTALVERSION BASE_VERSION PATCH1 PATCH2 PATCH3 PATCH4 PATCH5 PATCH6 PATCH7 PATCH8 PATCH9
|
||||
#endif
|
||||
#define BUFFERSIZE 0x200
|
||||
|
||||
extern OSVERSIONINFO VerInfo;
|
||||
extern char OSName[256];
|
||||
extern char backupbuf[8192];
|
||||
extern char *buildid;
|
||||
extern char serveropts[];
|
||||
extern char *extraflags;
|
||||
void CleanUp(void);
|
||||
extern BOOL IsService;
|
||||
void CleanUp(void);
|
||||
|
||||
__inline char *StackTrace(EXCEPTION_POINTERS *e) {
|
||||
/* Runs a stack trace
|
||||
* Parameters:
|
||||
* e - The exception information
|
||||
* Returns:
|
||||
* The stack trace with function and line number information
|
||||
*/
|
||||
__inline char *StackTrace(EXCEPTION_POINTERS *e)
|
||||
{
|
||||
static char buffer[5000];
|
||||
char curmodule[32];
|
||||
DWORD symOptions, dwDisp, frame;
|
||||
@@ -51,6 +59,8 @@ __inline char *StackTrace(EXCEPTION_POINTERS *e) {
|
||||
IMAGEHLP_LINE pLine;
|
||||
IMAGEHLP_MODULE pMod;
|
||||
STACKFRAME Stack;
|
||||
|
||||
/* Load the stack information */
|
||||
Stack.AddrPC.Offset = e->ContextRecord->Eip;
|
||||
Stack.AddrPC.Mode = AddrModeFlat;
|
||||
Stack.AddrFrame.Offset = e->ContextRecord->Ebp;
|
||||
@@ -60,6 +70,7 @@ __inline char *StackTrace(EXCEPTION_POINTERS *e) {
|
||||
else
|
||||
hProcess = GetCurrentProcess();
|
||||
|
||||
/* Initialize symbol retrieval system */
|
||||
SymInitialize(hProcess, NULL, TRUE);
|
||||
SymSetOptions(SYMOPT_LOAD_LINES|SYMOPT_UNDNAME);
|
||||
bzero(pSym, sizeof(IMAGEHLP_SYMBOL)+500);
|
||||
@@ -69,69 +80,65 @@ __inline char *StackTrace(EXCEPTION_POINTERS *e) {
|
||||
pLine.SizeOfStruct = sizeof(IMAGEHLP_LINE);
|
||||
bzero(&pMod, sizeof(IMAGEHLP_MODULE));
|
||||
pMod.SizeOfStruct = sizeof(IMAGEHLP_MODULE);
|
||||
|
||||
/* Retrieve the first module name */
|
||||
SymGetModuleInfo(hProcess, Stack.AddrPC.Offset, &pMod);
|
||||
strcpy(curmodule, pMod.ModuleName);
|
||||
sprintf(buffer, "\tModule: %s\n", pMod.ModuleName);
|
||||
for (frame = 0; ; frame++) {
|
||||
|
||||
/* Walk through the stack */
|
||||
for (frame = 0; ; frame++)
|
||||
{
|
||||
char buf[500];
|
||||
if (!StackWalk(IMAGE_FILE_MACHINE_I386, GetCurrentProcess(), GetCurrentThread(),
|
||||
&Stack, NULL, NULL, SymFunctionTableAccess, SymGetModuleBase, NULL))
|
||||
break;
|
||||
SymGetModuleInfo(hProcess, Stack.AddrPC.Offset, &pMod);
|
||||
if (strcmp(curmodule, pMod.ModuleName)) {
|
||||
if (strcmp(curmodule, pMod.ModuleName))
|
||||
{
|
||||
strcpy(curmodule, pMod.ModuleName);
|
||||
sprintf(buf, "\tModule: %s\n", pMod.ModuleName);
|
||||
strcat(buffer, buf);
|
||||
}
|
||||
SymGetLineFromAddr(hProcess, Stack.AddrPC.Offset, &dwDisp, &pLine);
|
||||
SymGetSymFromAddr(hProcess, Stack.AddrPC.Offset, &dwDisp, pSym);
|
||||
sprintf(buf, "\t\t#%d %s:%d: %s\n", frame, pLine.FileName, pLine.LineNumber, pSym->Name);
|
||||
sprintf(buf, "\t\t#%d %s:%d: %s\n", frame, pLine.FileName, pLine.LineNumber,
|
||||
pSym->Name);
|
||||
strcat(buffer, buf);
|
||||
}
|
||||
return buffer;
|
||||
|
||||
}
|
||||
|
||||
__inline char *GetRegisters(CONTEXT *context) {
|
||||
/* Retrieves the values of several registers
|
||||
* Parameters:
|
||||
* context - The CPU context
|
||||
* Returns:
|
||||
* The values of the EAX/EBX/ECX/EDX/ESI/EDI/EIP/EBP/ESP registers
|
||||
*/
|
||||
__inline char *GetRegisters(CONTEXT *context)
|
||||
{
|
||||
static char buffer[1024];
|
||||
|
||||
sprintf(buffer, "\tEAX=0x%08x EBX=0x%08x ECX=0x%08x\n"
|
||||
"\tEDX=0x%08x ESI=0x%08x EDI=0x%08x\n"
|
||||
"\tEIP=0x%08x EBP=0x%08x ESP=0x%08x\n",
|
||||
context->Eax, context->Ebx, context->Ecx, context->Edx,
|
||||
context->Esi, context->Edi, context->Eip, context->Ebp,
|
||||
context->Esp);
|
||||
context->Eax, context->Ebx, context->Ecx, context->Edx,
|
||||
context->Esi, context->Edi, context->Eip, context->Ebp,
|
||||
context->Esp);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/*__inline char *GetCpuName() {
|
||||
static char cpuname[48];
|
||||
__try {
|
||||
_asm {
|
||||
mov eax,080000002h
|
||||
CPUID
|
||||
mov DWORD PTR [cpuname+0],eax
|
||||
mov DWORD PTR [cpuname+4],ebx
|
||||
mov DWORD PTR [cpuname+8],ecx
|
||||
mov DWORD PTR [cpuname+12],edx
|
||||
mov eax,080000003h
|
||||
CPUID
|
||||
mov DWORD PTR [cpuname+16],eax
|
||||
mov DWORD PTR [cpuname+20],ebx
|
||||
mov DWORD PTR [cpuname+24],ecx
|
||||
mov DWORD PTR [cpuname+28],edx
|
||||
mov eax,080000004h
|
||||
CPUID
|
||||
mov DWORD PTR [cpuname+32],eax
|
||||
mov DWORD PTR [cpuname+36],ebx
|
||||
mov DWORD PTR [cpuname+40],ecx
|
||||
mov DWORD PTR [cpuname+44],edx
|
||||
}
|
||||
} __except(EXCEPTION_EXECUTE_HANDLER) { return NULL; }
|
||||
return cpuname;
|
||||
}*/
|
||||
|
||||
__inline char *GetException(DWORD code) {
|
||||
switch (code) {
|
||||
/* Convert the exception code to a human readable string
|
||||
* Parameters:
|
||||
* code - The exception code to convert
|
||||
* Returns:
|
||||
* The exception code represented as a string
|
||||
*/
|
||||
__inline char *GetException(DWORD code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case EXCEPTION_ACCESS_VIOLATION:
|
||||
return "Access Violation";
|
||||
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
|
||||
@@ -172,46 +179,69 @@ __inline char *GetException(DWORD code) {
|
||||
return "Single Step";
|
||||
case EXCEPTION_STACK_OVERFLOW:
|
||||
return "Stack Overflow";
|
||||
default:
|
||||
return "Unknown Exception";
|
||||
}
|
||||
return "Unknown Exception";
|
||||
}
|
||||
|
||||
|
||||
LONG __stdcall ExceptionFilter(EXCEPTION_POINTERS *e) {
|
||||
/* Callback for the exception handler
|
||||
* Parameters:
|
||||
* e - The exception information
|
||||
* Returns:
|
||||
* EXCEPTION_EXECUTE_HANDLER to terminate the process
|
||||
* Side Effects:
|
||||
* wircd.PID.core is created
|
||||
* If not running in service mode, a message box is displayed,
|
||||
* else output is written to service.log
|
||||
*/
|
||||
LONG __stdcall ExceptionFilter(EXCEPTION_POINTERS *e)
|
||||
{
|
||||
MEMORYSTATUS memStats;
|
||||
char file[512], text[1024];
|
||||
FILE *fd;
|
||||
time_t timet = time(NULL);
|
||||
|
||||
sprintf(file, "wircd.%d.core", getpid());
|
||||
fd = fopen(file, "w");
|
||||
GlobalMemoryStatus(&memStats);
|
||||
fprintf(fd, "Generated at %s\n%s (%d.%d.%d)\n%s[%s%s%s] (%s)\n-----------------\nMemory Information:\n"
|
||||
"\tPhysical: (Available:%ldMB/Total:%ldMB)\n\tVirtual: (Available:%ldMB/Total:%ldMB)\n"
|
||||
"-----------------\nException:\n\t%s\n-----------------\nBackup Buffer:\n\t%s\n"
|
||||
"-----------------\nRegisters:\n%s-----------------\nStack Trace:\n%s", asctime(gmtime(&timet)),
|
||||
OSName, VerInfo.dwMajorVersion, VerInfo.dwMinorVersion, VerInfo.dwBuildNumber,
|
||||
IRCDTOTALVERSION, serveropts, extraflags ? extraflags : "", tainted ? "3" : "",
|
||||
buildid, memStats.dwAvailPhys/1048576, memStats.dwTotalPhys/1048576,
|
||||
memStats.dwAvailVirtual/1048576, memStats.dwTotalVirtual/1048576,
|
||||
GetException(e->ExceptionRecord->ExceptionCode), backupbuf,
|
||||
GetRegisters(e->ContextRecord), StackTrace(e));
|
||||
fprintf(fd, "Generated at %s\n%s (%d.%d.%d)\n%s[%s%s%s] (%s)\n"
|
||||
"-----------------\nMemory Information:\n"
|
||||
"\tPhysical: (Available:%ldMB/Total:%ldMB)\n"
|
||||
"\tVirtual: (Available:%ldMB/Total:%ldMB)\n"
|
||||
"-----------------\nException:\n\t%s\n-----------------\n"
|
||||
"Backup Buffer:\n\t%s\n-----------------\nRegisters:\n"
|
||||
"%s-----------------\nStack Trace:\n%s",
|
||||
asctime(gmtime(&timet)), OSName, VerInfo.dwMajorVersion,
|
||||
VerInfo.dwMinorVersion, VerInfo.dwBuildNumber, IRCDTOTALVERSION,
|
||||
serveropts, extraflags ? extraflags : "", tainted ? "3" : "",
|
||||
buildid, memStats.dwAvailPhys/1048576, memStats.dwTotalPhys/1048576,
|
||||
memStats.dwAvailVirtual/1048576, memStats.dwTotalVirtual/1048576,
|
||||
GetException(e->ExceptionRecord->ExceptionCode), backupbuf,
|
||||
GetRegisters(e->ContextRecord), StackTrace(e));
|
||||
|
||||
sprintf(text, "UnrealIRCd has encountered a fatal error. Debugging information has"
|
||||
" been dumped to wircd.%d.core, please email this file to coders@lists.unrealircd.org.",
|
||||
getpid());
|
||||
" been dumped to wircd.%d.core, please email this file to "
|
||||
"coders@lists.unrealircd.org.", getpid());
|
||||
fclose(fd);
|
||||
|
||||
if (!IsService)
|
||||
MessageBox(NULL, text, "Fatal Error", MB_OK);
|
||||
else {
|
||||
else
|
||||
{
|
||||
FILE *fd = fopen("service.log", "a");
|
||||
fprintf(fd, "UnrealIRCd has encountered a fatal error. Debugging information has"
|
||||
" been dumped to wircd.%d.core, please email this file to coders@lists.unrealircd.org.", getpid());
|
||||
|
||||
fprintf(fd, "UnrealIRCd has encountered a fatal error. Debugging information "
|
||||
"has been dumped to wircd.%d.core, please email this file to "
|
||||
"coders@lists.unrealircd.org.", getpid());
|
||||
fclose(fd);
|
||||
}
|
||||
CleanUp();
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
|
||||
void InitDebug(void) {
|
||||
/* Initializes the exception handler */
|
||||
void InitDebug(void)
|
||||
{
|
||||
SetUnhandledExceptionFilter(&ExceptionFilter);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+67
-66
@@ -1,6 +1,6 @@
|
||||
/************************************************************************
|
||||
* IRC - Internet Relay Chat, win32/service.c
|
||||
* Copyright (C) 2002 Dominick Meglio (codemastr)
|
||||
* Copyright (C) 2002-2004 Dominick Meglio (codemastr)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -27,22 +27,48 @@
|
||||
#include <string.h>
|
||||
|
||||
SERVICE_STATUS IRCDStatus;
|
||||
SERVICE_STATUS_HANDLE IRCDStatusHandle;
|
||||
SERVICE_STATUS_HANDLE IRCDStatusHandle;
|
||||
|
||||
/* Signal to rehash */
|
||||
#define IRCD_SERVICE_CONTROL_REHASH 128
|
||||
|
||||
BOOL IsService = FALSE;
|
||||
|
||||
extern OSVERSIONINFO VerInfo;
|
||||
#define WIN32_VERSION BASE_VERSION PATCH1 PATCH2 PATCH3 PATCH4
|
||||
|
||||
VOID WINAPI IRCDCtrlHandler(DWORD opcode) {
|
||||
|
||||
/* Places the service in the STOPPED state
|
||||
* Parameters:
|
||||
* code - The error code (or 0)
|
||||
*/
|
||||
void SetServiceStop(int code)
|
||||
{
|
||||
IRCDStatus.dwCurrentState = SERVICE_STOPPED;
|
||||
IRCDStatus.dwCheckPoint = 0;
|
||||
IRCDStatus.dwWaitHint = 0;
|
||||
IRCDStatus.dwWin32ExitCode = code;
|
||||
IRCDStatus.dwServiceSpecificExitCode = code;
|
||||
SetServiceStatus(IRCDStatusHandle, &IRCDStatus);
|
||||
}
|
||||
|
||||
/* Handles the service messages
|
||||
* Parameters:
|
||||
* opcode - The message to process
|
||||
*/
|
||||
VOID WINAPI IRCDCtrlHandler(DWORD opcode)
|
||||
{
|
||||
DWORD status;
|
||||
int i;
|
||||
aClient *acptr;
|
||||
if (opcode == SERVICE_CONTROL_STOP) {
|
||||
|
||||
/* Stopping */
|
||||
if (opcode == SERVICE_CONTROL_STOP)
|
||||
{
|
||||
IRCDStatus.dwCurrentState = SERVICE_STOP_PENDING;
|
||||
SetServiceStatus(IRCDStatusHandle, &IRCDStatus);
|
||||
for (i = 0; i <= LastSlot; i++) {
|
||||
|
||||
for (i = 0; i <= LastSlot; i++)
|
||||
{
|
||||
if (!(acptr = local[i]))
|
||||
continue;
|
||||
if (IsClient(acptr))
|
||||
@@ -56,91 +82,66 @@ VOID WINAPI IRCDCtrlHandler(DWORD opcode) {
|
||||
for (i = LastSlot; i >= 0; i--)
|
||||
if ((acptr = local[i]) && DBufLength(&acptr->sendQ) > 0)
|
||||
(void)send_queued(acptr);
|
||||
IRCDStatus.dwWin32ExitCode = 0;
|
||||
IRCDStatus.dwCurrentState = SERVICE_STOPPED;
|
||||
IRCDStatus.dwCheckPoint = 0;
|
||||
IRCDStatus.dwWaitHint = 0;
|
||||
SetServiceStatus(IRCDStatusHandle, &IRCDStatus);
|
||||
SetServiceStop(0);
|
||||
}
|
||||
else if (opcode == IRCD_SERVICE_CONTROL_REHASH) {
|
||||
/* Rehash */
|
||||
else if (opcode == IRCD_SERVICE_CONTROL_REHASH)
|
||||
rehash(&me,&me,0);
|
||||
}
|
||||
|
||||
SetServiceStatus(IRCDStatusHandle, &IRCDStatus);
|
||||
SetServiceStatus(IRCDStatusHandle, &IRCDStatus);
|
||||
}
|
||||
|
||||
VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv) {
|
||||
/* Entry point function
|
||||
* Parameters:
|
||||
* dwArgc - Argument count
|
||||
* lpszArgv - Arguments
|
||||
*/
|
||||
VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)
|
||||
{
|
||||
WSADATA WSAData;
|
||||
DWORD error = 0;
|
||||
char path[MAX_PATH], *folder;
|
||||
|
||||
IsService = TRUE;
|
||||
|
||||
/* Initialize the service structure */
|
||||
IRCDStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||
IRCDStatus.dwCurrentState = SERVICE_START_PENDING;
|
||||
IRCDStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN;
|
||||
IRCDStatus.dwWin32ExitCode = NO_ERROR;
|
||||
IRCDStatus.dwServiceSpecificExitCode = 0;
|
||||
IRCDStatus.dwCheckPoint = 0;
|
||||
IRCDStatus.dwWaitHint = 0;
|
||||
IRCDStatus.dwWaitHint = 0;
|
||||
|
||||
GetModuleFileName(NULL,path,MAX_PATH);
|
||||
folder = strrchr(path, '\\');
|
||||
*folder = 0;
|
||||
chdir(path);
|
||||
IRCDStatusHandle = RegisterServiceCtrlHandler("unreal", IRCDCtrlHandler);
|
||||
|
||||
/* Register the service controller */
|
||||
IRCDStatusHandle = RegisterServiceCtrlHandler("unreal", IRCDCtrlHandler);
|
||||
|
||||
VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
GetVersionEx(&VerInfo);
|
||||
strcpy(OSName, "Windows ");
|
||||
if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
|
||||
if (VerInfo.dwMajorVersion == 4) {
|
||||
if (VerInfo.dwMinorVersion == 0) {
|
||||
strcat(OSName, "95 ");
|
||||
if (!strcmp(VerInfo.szCSDVersion," C"))
|
||||
strcat(OSName, "OSR2 ");
|
||||
}
|
||||
else if (VerInfo.dwMinorVersion == 10) {
|
||||
strcat(OSName, "98 ");
|
||||
if (!strcmp(VerInfo.szCSDVersion, " A"))
|
||||
strcat(OSName, "SE ");
|
||||
}
|
||||
else if (VerInfo.dwMinorVersion == 90)
|
||||
strcat(OSName, "Me ");
|
||||
}
|
||||
}
|
||||
else if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
if (VerInfo.dwMajorVersion == 3 && VerInfo.dwMinorVersion == 51)
|
||||
strcat(OSName, "NT 3.51 ");
|
||||
else if (VerInfo.dwMajorVersion == 4 && VerInfo.dwMinorVersion == 0)
|
||||
strcat(OSName, "NT 4.0 ");
|
||||
else if (VerInfo.dwMajorVersion == 5) {
|
||||
if (VerInfo.dwMinorVersion == 0)
|
||||
strcat(OSName, "2000 ");
|
||||
else if (VerInfo.dwMinorVersion == 1)
|
||||
strcat(OSName, "XP ");
|
||||
else if (VerInfo.dwMinorVersion == 2)
|
||||
strcat(OSName, "Server 2003 ");
|
||||
}
|
||||
strcat(OSName, VerInfo.szCSDVersion);
|
||||
}
|
||||
if (OSName[strlen(OSName)-1] == ' ')
|
||||
OSName[strlen(OSName)-1] = 0;
|
||||
GetOSName(VerInfo, OSName);
|
||||
|
||||
InitDebug();
|
||||
if ((error = WSAStartup(MAKEWORD(1, 1), &WSAData)) != 0) {
|
||||
IRCDStatus.dwCurrentState = SERVICE_STOPPED;
|
||||
IRCDStatus.dwCheckPoint = 0;
|
||||
IRCDStatus.dwWaitHint = 0;
|
||||
IRCDStatus.dwWin32ExitCode = error;
|
||||
IRCDStatus.dwServiceSpecificExitCode = error;
|
||||
SetServiceStatus(IRCDStatusHandle, &IRCDStatus);
|
||||
|
||||
/* Initialize Winsocks */
|
||||
if ((error = WSAStartup(MAKEWORD(1, 1), &WSAData)) != 0)
|
||||
{
|
||||
SetServiceStop(error);
|
||||
return;
|
||||
}
|
||||
if ((error = InitwIRCD(dwArgc, lpszArgv)) != 1) {
|
||||
IRCDStatus.dwCurrentState = SERVICE_STOPPED;
|
||||
IRCDStatus.dwCheckPoint = 0;
|
||||
IRCDStatus.dwWaitHint = 0;
|
||||
IRCDStatus.dwWin32ExitCode = error;
|
||||
IRCDStatus.dwServiceSpecificExitCode = error;
|
||||
SetServiceStatus(IRCDStatusHandle, &IRCDStatus);
|
||||
|
||||
/* Initialize the IRCd */
|
||||
if ((error = InitwIRCD(dwArgc, lpszArgv)) != 1)
|
||||
{
|
||||
SetServiceStop(error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Go into the running state */
|
||||
IRCDStatus.dwCurrentState = SERVICE_RUNNING;
|
||||
IRCDStatus.dwCheckPoint = 0;
|
||||
IRCDStatus.dwWaitHint = 0;
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/************************************************************************
|
||||
* IRC - Internet Relay Chat, win32/win32.c
|
||||
* Copyright (C) 2004 Dominick Meglio (codemastr)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 1, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
/* Retrieves the OS name as a string
|
||||
* Parameters:
|
||||
* VerInfo - The version information from GetVersionEx
|
||||
* OSName - The buffer to write the OS name to
|
||||
*/
|
||||
void GetOSName(OSVERSIONINFO VerInfo, char *OSName)
|
||||
{
|
||||
int len;
|
||||
strcpy(OSName, "Windows ");
|
||||
if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
|
||||
{
|
||||
if (VerInfo.dwMajorVersion == 4)
|
||||
{
|
||||
if (VerInfo.dwMinorVersion == 0)
|
||||
{
|
||||
strcat(OSName, "95 ");
|
||||
if (!strcmp(VerInfo.szCSDVersion, " C"))
|
||||
strcat(OSName, "OSR2 ");
|
||||
}
|
||||
else if (VerInfo.dwMinorVersion == 10)
|
||||
{
|
||||
strcat(OSName, "98 ");
|
||||
if (!strcmp(VerInfo.szCSDVersion, " A"))
|
||||
strcat(OSName, "SE ");
|
||||
}
|
||||
else if (VerInfo.dwMinorVersion == 90)
|
||||
strcat(OSName, "Me ");
|
||||
}
|
||||
}
|
||||
else if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
||||
{
|
||||
if (VerInfo.dwMajorVersion == 3 && VerInfo.dwMinorVersion == 51)
|
||||
strcat(OSName, "NT 3.51 ");
|
||||
else if (VerInfo.dwMajorVersion == 4 && VerInfo.dwMinorVersion == 0)
|
||||
strcat(OSName, "NT 4.0 ");
|
||||
else if (VerInfo.dwMajorVersion == 5)
|
||||
{
|
||||
if (VerInfo.dwMinorVersion == 0)
|
||||
strcat(OSName, "2000 ");
|
||||
else if (VerInfo.dwMinorVersion == 1)
|
||||
strcat(OSName, "XP ");
|
||||
else if (VerInfo.dwMinorVersion == 2)
|
||||
strcat(OSName, "Server 2003 ");
|
||||
}
|
||||
strcat(OSName, VerInfo.szCSDVersion);
|
||||
}
|
||||
|
||||
len = strlen(OSName)-1;
|
||||
if (OSName[len] == ' ')
|
||||
OSName[len] = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user