video/dedicated_v.c
author matthijs
Wed, 22 Mar 2006 22:26:16 +0000
branch0.4.5
changeset 9958 bed516c67d61
parent 2791 f8ffac7515d4
child 4300 687a17c9c557
permissions -rw-r--r--
(svn r4041) [Debian] Change next version number to 0.4.6 instead of 0.4.5.1.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2181
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2181
diff changeset
     2
2189
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     3
#include "../stdafx.h"
543
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: 2189
diff changeset
     7
#include "../openttd.h"
2189
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     8
#include "../debug.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     9
#include "../functions.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    10
#include "../gfx.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    11
#include "../network.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    12
#include "../window.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    13
#include "../console.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    14
#include "../variables.h"
2195
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2189
diff changeset
    15
#include "dedicated_v.h"
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    16
2497
1c8460570c0d (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    17
#ifdef BEOS_NET_SERVER
1c8460570c0d (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    18
#include <net/socket.h>
1c8460570c0d (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    19
#endif
1c8460570c0d (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    20
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    21
#ifdef __OS2__
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    22
#	include <sys/time.h> /* gettimeofday */
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    23
#	include <sys/types.h>
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    24
#	include <unistd.h>
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    25
#	include <conio.h>
2181
659d7d8d1ccd (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    26
659d7d8d1ccd (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    27
#	define INCL_DOS
659d7d8d1ccd (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    28
#	include <os2.h>
659d7d8d1ccd (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    29
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    30
#	define STDIN 0  /* file descriptor for standard input */
810
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
    31
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2228
diff changeset
    32
/**
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    33
 * Switches OpenTTD to a console app at run-time, instead of a PM app
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    34
 * Necessary to see stdout, etc. */
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    35
static void OS2_SwitchToConsoleMode(void)
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    36
{
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    37
	PPIB pib;
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    38
	PTIB tib;
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    39
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    40
	DosGetInfoBlocks(&tib, &pib);
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    41
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    42
	// Change flag from PM to VIO
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    43
	pib->pib_ultype = 3;
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    44
}
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    45
#endif
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    46
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    47
#ifdef UNIX
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    48
#	include <sys/time.h> /* gettimeofday */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    49
#	include <sys/types.h>
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    50
#	include <unistd.h>
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    51
#	include <signal.h>
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    52
#	define STDIN 0  /* file descriptor for standard input */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    53
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    54
/* Signal handlers */
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    55
static void DedicatedSignalHandler(int sig)
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    56
{
736
53618d1ade61 (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
    57
	_exit_game = true;
53618d1ade61 (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
    58
	signal(sig, DedicatedSignalHandler);
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    59
}
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    60
#endif
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    61
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    62
#ifdef WIN32
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    63
#include <windows.h> /* GetTickCount */
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    64
#include <conio.h>
1114
5433cbd50835 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    65
#include <time.h>
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    66
static HANDLE hEvent;
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    67
static HANDLE hThread; // Thread to close
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    68
static char _win_console_thread_buffer[200];
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    69
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    70
/* Windows Console thread. Just loop and signal when input has been received */
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    71
static void WINAPI CheckForConsoleInput(void)
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    72
{
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    73
	while (true) {
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    74
		fgets(_win_console_thread_buffer, lengthof(_win_console_thread_buffer), stdin);
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    75
		SetEvent(hEvent); // signal input waiting that the line is ready
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    76
	}
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    77
}
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    78
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    79
static void CreateWindowsConsoleThread(void)
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    80
{
1114
5433cbd50835 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    81
	static char tbuffer[9];
1762
01d1e351aafe (svn r2266) - Feature: it is now possible to start a dedicated server on Win98/95, for the few sadistic geeks that really want to do this (thanks for testing Hackykid). Also fix up another glitch in console output
Darkvater
parents: 1626
diff changeset
    82
	DWORD dwThreadId;
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    83
	/* Create event to signal when console input is ready */
1114
5433cbd50835 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    84
	hEvent = CreateEvent(NULL, false, false, _strtime(tbuffer));
5433cbd50835 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    85
	if (hEvent == NULL)
5433cbd50835 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    86
		error("Cannot create console event!");
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    87
1762
01d1e351aafe (svn r2266) - Feature: it is now possible to start a dedicated server on Win98/95, for the few sadistic geeks that really want to do this (thanks for testing Hackykid). Also fix up another glitch in console output
Darkvater
parents: 1626
diff changeset
    88
	hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CheckForConsoleInput, NULL, 0, &dwThreadId);
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    89
	if (hThread == NULL)
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    90
		error("Cannot create console thread!");
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    91
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2195
diff changeset
    92
	DEBUG(driver, 1) ("Windows console thread started...");
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    93
}
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    94
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    95
static void CloseWindowsConsoleThread(void)
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    96
{
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    97
	CloseHandle(hThread);
1114
5433cbd50835 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    98
	CloseHandle(hEvent);
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2195
diff changeset
    99
	DEBUG(driver, 1) ("Windows console thread shut down...");
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   100
}
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   101
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   102
#endif
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   103
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   104
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   105
static void *_dedicated_video_mem;
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   106
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   107
extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm);
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   108
extern void SwitchMode(int new_mode);
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   109
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   110
1301
313804601383 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1299
diff changeset
   111
static const char *DedicatedVideoStart(const char * const *parm)
313804601383 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1299
diff changeset
   112
{
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   113
	_screen.width = _screen.pitch = _cur_resolution[0];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   114
	_screen.height = _cur_resolution[1];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   115
	_dedicated_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   116
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   117
	_debug_net_level = 6;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   118
	_debug_misc_level = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   119
626
78c7e1c9f7c5 (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   120
#ifdef WIN32
78c7e1c9f7c5 (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   121
	// For win32 we need to allocate an console (debug mode does the same)
78c7e1c9f7c5 (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   122
	CreateConsole();
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   123
	CreateWindowsConsoleThread();
626
78c7e1c9f7c5 (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   124
	SetConsoleTitle("OpenTTD Dedicated Server");
78c7e1c9f7c5 (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   125
#endif
78c7e1c9f7c5 (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   126
810
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   127
#ifdef __OS2__
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   128
	// For OS/2 we also need to switch to console mode instead of PM mode
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   129
	OS2_SwitchToConsoleMode();
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   130
#endif
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   131
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2195
diff changeset
   132
	DEBUG(driver, 1)("Loading dedicated server...");
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   133
	return NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   134
}
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   135
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   136
static void DedicatedVideoStop(void)
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   137
{
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   138
#ifdef WIN32
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   139
	CloseWindowsConsoleThread();
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   140
#endif
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1090
diff changeset
   141
	free(_dedicated_video_mem);
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   142
}
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   143
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   144
static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   145
static bool DedicatedVideoChangeRes(int w, int h) { return false; }
1829
0b6de3b4458a (svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents: 1794
diff changeset
   146
static void DedicatedVideoFullScreen(bool fs) {}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   147
1090
7a367d006de9 (svn r1591) Make dedicated servers on OS/2 check for input the UNIX way
tron
parents: 1046
diff changeset
   148
#if defined(UNIX) || defined(__OS2__)
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   149
static bool InputWaiting(void)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   150
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   151
	struct timeval tv;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   152
	fd_set readfds;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   153
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   154
	tv.tv_sec = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   155
	tv.tv_usec = 1;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   156
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   157
	FD_ZERO(&readfds);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   158
	FD_SET(STDIN, &readfds);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   159
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   160
	/* don't care about writefds and exceptfds: */
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   161
	return select(STDIN + 1, &readfds, NULL, NULL, &tv) > 0;
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   162
}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   163
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   164
static uint32 GetTime(void)
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   165
{
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   166
	struct timeval tim;
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   167
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   168
	gettimeofday(&tim, NULL);
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   169
	return tim.tv_usec / 1000 + tim.tv_sec * 1000;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   170
}
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   171
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   172
#else
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   173
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   174
static bool InputWaiting(void)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   175
{
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   176
	return WaitForSingleObject(hEvent, 1) == WAIT_OBJECT_0;
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   177
}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1090
diff changeset
   178
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   179
static uint32 GetTime(void)
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   180
{
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   181
	return GetTickCount();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   182
}
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   183
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   184
#endif
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   185
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   186
static void DedicatedHandleKeyInput(void)
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   187
{
721
20591395836b (svn r1173) -Fix: [Network] Console input in dedicated server for windows was not
truelight
parents: 720
diff changeset
   188
	static char input_line[200] = "";
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   189
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   190
	if (!InputWaiting())
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   191
		return;
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   192
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   193
	if (_exit_game)
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   194
		return;
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   195
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
   196
#if defined(UNIX) || defined(__OS2__)
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   197
		fgets(input_line, lengthof(input_line), stdin);
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   198
#else
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   199
		strncpy(input_line, _win_console_thread_buffer, lengthof(input_line));
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   200
#endif
736
53618d1ade61 (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
   201
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   202
	/* XXX - strtok() does not 'forget' \n\r if it is the first character! */
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   203
	strtok(input_line, "\r\n"); // Forget about the final \n (or \r)
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   204
	{ /* Remove any special control characters */
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   205
		uint i;
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   206
		for (i = 0; i < lengthof(input_line); i++) {
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   207
			if (input_line[i] == '\n' || input_line[i] == '\r') // cut missed beginning '\0'
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   208
				input_line[i] = '\0';
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   209
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   210
			if (input_line[i] == '\0')
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   211
				break;
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   212
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   213
			if (!IS_INT_INSIDE(input_line[i], ' ', 256))
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   214
				input_line[i] = ' ';
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   215
		}
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   216
	}
1046
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   217
d46ccd96c40f (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   218
	IConsoleCmdExec(input_line); // execute command
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   219
}
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   220
2228
7014d372374f (svn r2748) Remove unused cruft from the main loop
tron
parents: 2210
diff changeset
   221
static void DedicatedVideoMainLoop(void)
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   222
{
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   223
	uint32 next_tick;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   224
	uint32 cur_ticks;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   225
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   226
	next_tick = GetTime() + 30;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   227
770
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 736
diff changeset
   228
	/* Signal handlers */
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   229
#ifdef UNIX
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   230
	signal(SIGTERM, DedicatedSignalHandler);
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   231
	signal(SIGINT, DedicatedSignalHandler);
736
53618d1ade61 (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
   232
	signal(SIGQUIT, DedicatedSignalHandler);
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   233
#endif
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   234
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   235
	// Load the dedicated server stuff
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   236
	_is_network_server = true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   237
	_network_dedicated = true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   238
	_network_playas = OWNER_SPECTATOR;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   239
	_local_player = OWNER_SPECTATOR;
1414
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   240
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   241
	/* If SwitchMode is SM_LOAD, it means that the user used the '-g' options */
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   242
	if (_switch_mode != SM_LOAD) {
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   243
		_switch_mode = SM_NONE;
1794
44f9deff97ed (svn r2298) - CodeChange: removed CmdAbuses: CmdSetTownNameType(), CmdStartNewGame(), CmdCreateScenario(), CmdSetNewLandscapeType() and CmdGenRandomNewGame().
Darkvater
parents: 1762
diff changeset
   244
		GenRandomNewGame(Random(), InteractiveRandom());
1414
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   245
	} else {
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   246
		_switch_mode = SM_NONE;
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   247
		/* First we need to test if the savegame can be loaded, else we will end up playing the
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   248
		 *  intro game... */
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   249
		if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   250
			/* Loading failed, pop out.. */
1626
6429294a2009 (svn r2130) Various spelling fixes in messages.
pasky
parents: 1614
diff changeset
   251
			DEBUG(net, 0)("Loading requested map failed. Aborting.");
1414
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   252
			_networking = false;
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   253
		} else {
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   254
			/* We can load this game, so go ahead */
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   255
			SwitchMode(SM_LOAD);
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   256
		}
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   257
	}
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   258
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   259
	// Done loading, start game!
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   260
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   261
	if (!_networking) {
1626
6429294a2009 (svn r2130) Various spelling fixes in messages.
pasky
parents: 1614
diff changeset
   262
		DEBUG(net, 1)("Dedicated server could not be launched. Aborting.");
2228
7014d372374f (svn r2748) Remove unused cruft from the main loop
tron
parents: 2210
diff changeset
   263
		return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   264
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   265
2228
7014d372374f (svn r2748) Remove unused cruft from the main loop
tron
parents: 2210
diff changeset
   266
	while (!_exit_game) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   267
		InteractiveRandom(); // randomness
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   268
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   269
		if (!_dedicated_forks)
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   270
			DedicatedHandleKeyInput();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   271
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   272
		cur_ticks = GetTime();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   273
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   274
		if (cur_ticks >= next_tick) {
1543
d502c1c2ea80 (svn r2047) -Fix: never commit your own personal changes... :(
truelight
parents: 1542
diff changeset
   275
			next_tick += 30;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   276
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   277
			GameLoop();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   278
			_screen.dst_ptr = _dedicated_video_mem;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   279
			UpdateWindows();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   280
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   281
		CSleep(1);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   282
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   283
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   284
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   285
const HalVideoDriver _dedicated_video_driver = {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   286
	DedicatedVideoStart,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   287
	DedicatedVideoStop,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   288
	DedicatedVideoMakeDirty,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   289
	DedicatedVideoMainLoop,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   290
	DedicatedVideoChangeRes,
1829
0b6de3b4458a (svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents: 1794
diff changeset
   291
	DedicatedVideoFullScreen,
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   292
};
2195
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2189
diff changeset
   293
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2189
diff changeset
   294
#endif /* ENABLE_NETWORK */