⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 1998  Mark Baysinger (mbaysing@ucsd.edu) * Copyright (C) 1998,1999,2000  Ross Combs (rocombs@cs.nmsu.edu) * * 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 2 * of the License, 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */#include "common/setup_before.h"#include <stdio.h>#ifdef HAVE_STDDEF_H# include <stddef.h>#else# ifndef NULL#  define NULL ((void *)0)# endif#endif#ifdef STDC_HEADERS# include <stdlib.h>#else# ifdef HAVE_MALLOC_H#  include <malloc.h># endif#endif#include "compat/exitstatus.h"#ifdef HAVE_STRING_H# include <string.h>#else# ifdef HAVE_STRINGS_H#  include <strings.h># endif#endif#include "compat/strdup.h"#include <errno.h>#include "compat/strerror.h"#ifdef HAVE_UNISTD_H# include <unistd.h>#endif#include "compat/stdfileno.h"#include "compat/psock.h"#include "common/hexdump.h"#include "channel.h"#include "game.h"#include "server.h"#include "common/eventlog.h"#include "account.h"#include "connection.h"#include "game.h"#include "common/version.h"#include "prefs.h"#include "ladder.h"#include "adbanner.h"#include "ipban.h"#include "autoupdate.h"#include "helpfile.h"#include "timer.h"#include "watch.h"#include "common/tracker.h"#include "realm.h"#include "character.h"#include "common/give_up_root_privileges.h"#include "versioncheck.h"#include "storage.h"#include "anongame.h"#include "command_groups.h"#include "output.h"#include "alias_command.h"#include "anongame_infos.h"#include "anongame_maplists.h"#include "tournament.h"#include "news.h"#include "clan.h"#include "team.h"#include "topic.h"#include "support.h"#include "common/trans.h"#include "common/xalloc.h"#include "common/fdwatch.h"#include "attrlayer.h"#ifdef WIN32# include "win32/service.h"#endif#ifdef WIN32_GUI# include "win32/winmain.h"# define printf gui_printf#endif#include "cmdline.h"#include "common/setup_after.h"/* out of memory safety */#define OOM_SAFE_MEM	1000000		/* 1 Mbyte of safety memory */void *oom_buffer = NULL;static int bnetd_oom_handler(void){    /* no safety buffer, sorry :( */    if (!oom_buffer) return 0;    /* free the safety buffer hoping next allocs will succeed */    free(oom_buffer);    oom_buffer = NULL;    eventlog(eventlog_level_fatal,__FUNCTION__,"out of memory, forcing immediate shutdown");    /* shutdown immediatly */    server_quit_delay(-1);    return 1;	/* ask xalloc codes to retry the allocation request */}static int oom_setup(void){    /* use calloc so it initilizez the memory so it will make some lazy      * allocators really alocate it (ex. the linux kernel)     */    oom_buffer = calloc(1, OOM_SAFE_MEM);    if (!oom_buffer) return -1;    xalloc_setcb(bnetd_oom_handler);    return 0;}static void oom_free(void){    if (oom_buffer) free(oom_buffer);    oom_buffer = NULL;}FILE	*hexstrm = NULL;char serviceLongName[] = "PvPGN service";char serviceName[] = "pvpgn";char serviceDescription[] = "Player vs. Player Gaming Network - Server";/*  * by quetzal. indicates service status * -1 - not in service mode *  0 - stopped *  1 - running *  2 - paused */int g_ServiceStatus = -1;/* added some more exit status --> put in "compat/exitstatus.h" ??? */#define STATUS_OOM_FAILURE		20#define STATUS_STORAGE_FAILURE		30#define STATUS_PSOCK_FAILURE		35#define STATUS_MAPLISTS_FAILURE		40#define STATUS_MATCHLISTS_FAILURE	50#define STATUS_LADDERLIST_FAILURE	60#define STATUS_WAR3XPTABLES_FAILURE	70#define STATUS_SUPPORT_FAILURE          80#define STATUS_FDWATCH_FAILURE          90int pre_server_startup(void);void post_server_shutdown(int status);int eventlog_startup(void);int fork_bnetd(int foreground);char * write_to_pidfile(void);void pvpgn_greeting(void);int eventlog_startup(void){    char const * levels;    char *       temp;    char const * tok;        eventlog_clear_level();    if ((levels = prefs_get_loglevels())) {	temp = xstrdup(levels);	tok = strtok(temp,","); /* strtok modifies the string it is passed */	while (tok) {	    if (eventlog_add_level(tok)<0)		eventlog(eventlog_level_error,__FUNCTION__,"could not add log level \"%s\"",tok);	    tok = strtok(NULL,",");	}	xfree(temp);    }    if (eventlog_open(prefs_get_logfile())<0) {	if (prefs_get_logfile()) {	    eventlog(eventlog_level_fatal,__FUNCTION__,"could not use file \"%s\" for the eventlog (exiting)",prefs_get_logfile());	} else {	    eventlog(eventlog_level_fatal,__FUNCTION__,"no logfile specified in configuration file \"%s\" (exiting)",cmdline_get_preffile());	}	return -1;    }    eventlog(eventlog_level_info,__FUNCTION__,"logging event levels: %s",prefs_get_loglevels());    return 0;}int fork_bnetd(int foreground){    int		pid;    #ifdef DO_DAEMONIZE    if (!foreground) {	if (chdir("/")<0) {	    eventlog(eventlog_level_error,__FUNCTION__,"could not change working directory to / (chdir: %s)",pstrerror(errno));	    return -1;	}		switch ((pid = fork())) {	    case -1:		eventlog(eventlog_level_error,__FUNCTION__,"could not fork (fork: %s)",pstrerror(errno));		return -1;	    case 0: /* child */		break;	    default: /* parent */		return pid;	}#ifndef WITH_D2		close(STDINFD);	close(STDOUTFD);	close(STDERRFD);#endif# ifdef HAVE_SETPGID	if (setpgid(0,0)<0) {	    eventlog(eventlog_level_error,__FUNCTION__,"could not create new process group (setpgid: %s)",pstrerror(errno));	    return -1;	}# else#  ifdef HAVE_SETPGRP#   ifdef SETPGRP_VOID        if (setpgrp()<0) {            eventlog(eventlog_level_error,__FUNCTION__,"could not create new process group (setpgrp: %s)",pstrerror(errno));            return -1;        }#   else	if (setpgrp(0,0)<0) {	    eventlog(eventlog_level_error,__FUNCTION__,"could not create new process group (setpgrp: %s)",pstrerror(errno));	    return -1;	}#   endif#  else#   ifdef HAVE_SETSID	if (setsid()<0) {	    eventlog(eventlog_level_error,__FUNCTION__,"could not create new process group (setsid: %s)",pstrerror(errno));	    return -1;	}#   else#    error "One of setpgid(), setpgrp(), or setsid() is required"#   endif#  endif# endif    }    return 0;#endifreturn 0;}char * write_to_pidfile(void){    char *pidfile = xstrdup(prefs_get_pidfile());        if (pidfile[0]=='\0') {	xfree((void *)pidfile); /* avoid warning */	return NULL;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -