dedicated.c
author KUDr
Sat, 30 Dec 2006 18:25:01 +0000
branchcustombridgeheads
changeset 5609 ec38986d2c8e
parent 2294 a938c5ecb1c4
permissions -rw-r--r--
(svn r7655) [cbh] - Fix: [YAPF] another assert (on opposite cbh when it contained choice). Now it is possible to reach choice when exiting wormhole. So the wormhole cost must be taken into consideration when starting new YAPF node.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2177
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2177
diff changeset
     2
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     3
#include "stdafx.h"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     4
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     5
#ifdef ENABLE_NETWORK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     6
2195
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
     7
#if defined(UNIX) && !defined(__MORPHOS__)
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
     8
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
     9
#include "openttd.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1959
diff changeset
    10
#include "variables.h"
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    11
2195
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
    12
#include <sys/types.h>
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2186
diff changeset
    13
#include <unistd.h>
2177
73d67828ea5e (svn r2691) Separate dedicated video driver and fix bemidi declarations
tron
parents: 2163
diff changeset
    14
774
258c11431acb (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents: 770
diff changeset
    15
void DedicatedFork(void)
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    16
{
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    17
	/* Fork the program */
1406
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1301
diff changeset
    18
	pid_t pid = fork();
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1301
diff changeset
    19
	switch (pid) {
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    20
		case -1:
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    21
			perror("Unable to fork");
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    22
			exit(1);
2294
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    23
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    24
		case 0: { // We're the child
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    25
			FILE* f;
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    26
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    27
			/* Open the log-file to log all stuff too */
2294
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    28
			f = fopen(_log_file, "a");
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    29
			if (f == NULL) {
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    30
				perror("Unable to open logfile");
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    31
				exit(1);
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    32
			}
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    33
			/* Redirect stdout and stderr to log-file */
2294
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    34
			if (dup2(fileno(f), fileno(stdout)) == -1) {
1626
6429294a2009 (svn r2130) Various spelling fixes in messages.
pasky
parents: 1614
diff changeset
    35
				perror("Rerouting stdout");
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    36
				exit(1);
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    37
			}
2294
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    38
			if (dup2(fileno(f), fileno(stderr)) == -1) {
1626
6429294a2009 (svn r2130) Various spelling fixes in messages.
pasky
parents: 1614
diff changeset
    39
				perror("Rerouting stderr");
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    40
				exit(1);
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    41
			}
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    42
			break;
2294
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    43
		}
a938c5ecb1c4 (svn r2818) Don't tell the world about a local variable which is only used once
tron
parents: 2195
diff changeset
    44
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    45
		default:
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    46
			// We're the parent
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    47
			printf("Loading dedicated server...\n");
1406
2d5baabe4046 (svn r1910) Move two variables out of variables.h which are only used locally
tron
parents: 1301
diff changeset
    48
			printf("  - Forked to background with pid %d\n", pid);
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    49
			exit(0);
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    50
	}
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    51
}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    52
#endif
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    53
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    54
#else
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    55
774
258c11431acb (svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents: 770
diff changeset
    56
void DedicatedFork(void) {}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    57
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    58
#endif /* ENABLE_NETWORK */