src/network/network_client.cpp
author rubidium
Fri, 30 May 2008 18:20:26 +0000
changeset 10792 95b6eb9fcc9e
parent 10784 c3c7b558b4f1
child 11156 cf146f346724
permissions -rw-r--r--
(svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10421
diff changeset
     3
/** @file network_client.cpp Client part of the network protocol. */
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10421
diff changeset
     4
4826
63b1eb7c966b (svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents: 4512
diff changeset
     5
#ifdef ENABLE_NETWORK
63b1eb7c966b (svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents: 4512
diff changeset
     6
5720
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5683
diff changeset
     7
#include "../stdafx.h"
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5683
diff changeset
     8
#include "../debug.h"
7762
03721db0ac1c (svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
rubidium
parents: 7718
diff changeset
     9
#include "../openttd.h"
10792
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
    10
#include "network_internal.h"
5720
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5683
diff changeset
    11
#include "core/tcp.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    12
#include "network_client.h"
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    13
#include "network_gamelist.h"
4512
7151d4ee3a0f (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4428
diff changeset
    14
#include "network_gui.h"
5720
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5683
diff changeset
    15
#include "../saveload.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    16
#include "../command_func.h"
10684
7cc2278c2ac0 (svn r13228) -Codechange: split console.h.
rubidium
parents: 10429
diff changeset
    17
#include "../console_func.h"
5720
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5683
diff changeset
    18
#include "../variables.h"
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5683
diff changeset
    19
#include "../ai/ai.h"
8626
440dfcd14c4a (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8612
diff changeset
    20
#include "../core/alloc_func.hpp"
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7027
diff changeset
    21
#include "../fileio.h"
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    22
#include "../md5.h"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8602
diff changeset
    23
#include "../strings_func.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8626
diff changeset
    24
#include "../window_func.h"
8710
52015340050c (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8636
diff changeset
    25
#include "../string_func.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8748
diff changeset
    26
#include "../player_func.h"
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8748
diff changeset
    27
#include "../player_base.h"
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8748
diff changeset
    28
#include "../player_gui.h"
10402
b168fbb99f7c (svn r12944) -Codechange: use rev.h instead of externs at many places
smatz
parents: 10233
diff changeset
    29
#include "../rev.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    30
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    31
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    32
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    33
// This file handles all the client-commands
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    34
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    35
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    36
// So we don't make too much typos ;)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    37
#define MY_CLIENT DEREF_CLIENT(0)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    38
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    39
static uint32 last_ack_frame;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    40
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    41
/** One bit of 'entropy' used to generate a salt for the company passwords. */
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    42
static uint32 _password_game_seed;
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    43
/** The other bit of 'entropy' used to generate a salt for the company passwords. */
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    44
static char _password_server_unique_id[NETWORK_UNIQUE_ID_LENGTH];
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    45
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    46
/** Make sure the unique ID length is the same as a md5 hash. */
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    47
assert_compile(NETWORK_UNIQUE_ID_LENGTH == 16 * 2 + 1);
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    48
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    49
/**
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    50
 * Generates a hashed password for the company name.
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    51
 * @param password the password to 'encrypt'.
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    52
 * @return the hashed password.
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    53
 */
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    54
static const char *GenerateCompanyPasswordHash(const char *password)
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    55
{
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    56
	if (StrEmpty(password)) return password;
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    57
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    58
	char salted_password[NETWORK_UNIQUE_ID_LENGTH];
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    59
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    60
	memset(salted_password, 0, sizeof(salted_password));
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    61
	snprintf(salted_password, sizeof(salted_password), "%s", password);
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    62
	/* Add the game seed and the server's unique ID as the salt. */
8748
b8883e9894b9 (svn r11816) -Fix: forgot clearing one byte, causing the passwords to differ slightly on different platforms.
rubidium
parents: 8710
diff changeset
    63
	for (uint i = 0; i < NETWORK_UNIQUE_ID_LENGTH - 1; i++) salted_password[i] ^= _password_server_unique_id[i] ^ (_password_game_seed >> i);
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    64
8629
c764b6319d60 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8627
diff changeset
    65
	Md5 checksum;
c764b6319d60 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8627
diff changeset
    66
	uint8 digest[16];
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    67
	static char hashed_password[NETWORK_UNIQUE_ID_LENGTH];
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    68
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    69
	/* Generate the MD5 hash */
8748
b8883e9894b9 (svn r11816) -Fix: forgot clearing one byte, causing the passwords to differ slightly on different platforms.
rubidium
parents: 8710
diff changeset
    70
	checksum.Append((const uint8*)salted_password, sizeof(salted_password) - 1);
8629
c764b6319d60 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8627
diff changeset
    71
	checksum.Finish(digest);
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    72
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    73
	for (int di = 0; di < 16; di++) sprintf(hashed_password + di * 2, "%02x", digest[di]);
8748
b8883e9894b9 (svn r11816) -Fix: forgot clearing one byte, causing the passwords to differ slightly on different platforms.
rubidium
parents: 8710
diff changeset
    74
	hashed_password[lengthof(hashed_password) - 1] = '\0';
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    75
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    76
	return hashed_password;
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    77
}
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    78
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    79
/**
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    80
 * Hash the current company password; used when the server 'player' sets his/her password.
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    81
 */
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    82
void HashCurrentCompanyPassword()
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    83
{
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    84
	if (StrEmpty(_network_player_info[_local_player].password)) return;
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    85
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10703
diff changeset
    86
	_password_game_seed = _settings_game.game_creation.generation_seed;
10784
c3c7b558b4f1 (svn r13334) -Codechange: move the network settings variables from network/network_internal to settings.
rubidium
parents: 10775
diff changeset
    87
	ttd_strlcpy(_password_server_unique_id, _settings_client.network.network_id, sizeof(_password_server_unique_id));
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    88
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    89
	const char *new_pw = GenerateCompanyPasswordHash(_network_player_info[_local_player].password);
10415
53ed7c3b441c (svn r12957) -Codechange: do not misuse snprintf when you just want to copy a string, also use DEBUG instead of fprintf in one case.
rubidium
parents: 10402
diff changeset
    90
	ttd_strlcpy(_network_player_info[_local_player].password, new_pw, sizeof(_network_player_info[_local_player].password));
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    91
}
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    92
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
    93
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    94
// **********
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    95
// Sending functions
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    96
//   DEF_CLIENT_SEND_COMMAND has no parameters
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    97
// **********
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    98
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    99
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   100
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   101
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   102
	// Packet: CLIENT_COMPANY_INFO
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   103
	// Function: Request company-info (in detail)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   104
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   105
	//    <none>
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   106
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   107
	Packet *p;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   108
	_network_join_status = NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   109
	InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   110
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   111
	p = NetworkSend_Init(PACKET_CLIENT_COMPANY_INFO);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   112
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   113
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   114
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   115
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
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
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   118
	// Packet: CLIENT_JOIN
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   119
	// Function: Try to join the server
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   120
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   121
	//    String: OpenTTD Revision (norev000 if no revision)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   122
	//    String: Player Name (max NETWORK_NAME_LENGTH)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   123
	//    uint8:  Play as Player id (1..MAX_PLAYERS)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   124
	//    uint8:  Language ID
602
9bbe42a9e3ed (svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents: 571
diff changeset
   125
	//    String: Unique id to find the player back in server-listing
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   126
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   127
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   128
	Packet *p;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   129
	_network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   130
	InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   131
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   132
	p = NetworkSend_Init(PACKET_CLIENT_JOIN);
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   133
	p->Send_string(_openttd_revision);
10784
c3c7b558b4f1 (svn r13334) -Codechange: move the network settings variables from network/network_internal to settings.
rubidium
parents: 10775
diff changeset
   134
	p->Send_string(_settings_client.network.player_name); // Player name
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   135
	p->Send_uint8 (_network_playas);      // PlayAs
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   136
	p->Send_uint8 (NETLANG_ANY);          // Language
10784
c3c7b558b4f1 (svn r13334) -Codechange: move the network settings variables from network/network_internal to settings.
rubidium
parents: 10775
diff changeset
   137
	p->Send_string(_settings_client.network.network_id);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   138
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   139
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   140
6123
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   141
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   142
{
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   143
	//
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   144
	// Packet: CLIENT_NEWGRFS_CHECKED
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   145
	// Function: Tell the server that we have the required GRFs
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   146
	// Data:
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   147
	//
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   148
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   149
	Packet *p = NetworkSend_Init(PACKET_CLIENT_NEWGRFS_CHECKED);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   150
	MY_CLIENT->Send_Packet(p);
6123
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   151
}
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   152
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   153
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_PASSWORD)(NetworkPasswordType type, const char *password)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   154
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   155
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   156
	// Packet: CLIENT_PASSWORD
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   157
	// Function: Send a password to the server to authorize
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   158
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   159
	//    uint8:  NetworkPasswordType
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   160
	//    String: Password
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   161
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   162
	Packet *p = NetworkSend_Init(PACKET_CLIENT_PASSWORD);
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   163
	p->Send_uint8 (type);
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   164
	p->Send_string(type == NETWORK_GAME_PASSWORD ? password : GenerateCompanyPasswordHash(password));
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   165
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   166
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   167
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   168
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GETMAP)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   169
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   170
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   171
	// Packet: CLIENT_GETMAP
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   172
	// Function: Request the map from the server
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   173
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   174
	//    <none>
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   175
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   176
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   177
	Packet *p = NetworkSend_Init(PACKET_CLIENT_GETMAP);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   178
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   179
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   180
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   181
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_MAP_OK)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   182
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   183
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   184
	// Packet: CLIENT_MAP_OK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   185
	// Function: Tell the server that we are done receiving/loading the map
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   186
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   187
	//    <none>
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   188
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   189
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   190
	Packet *p = NetworkSend_Init(PACKET_CLIENT_MAP_OK);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   191
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   192
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   193
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   194
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_ACK)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   195
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   196
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   197
	// Packet: CLIENT_ACK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   198
	// Function: Tell the server we are done with this frame
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   199
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   200
	//    uint32: current FrameCounter of the client
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   201
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   202
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   203
	Packet *p = NetworkSend_Init(PACKET_CLIENT_ACK);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   204
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   205
	p->Send_uint32(_frame_counter);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   206
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   207
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   208
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   209
// Send a command packet to the server
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   210
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   211
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   212
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   213
	// Packet: CLIENT_COMMAND
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   214
	// Function: Send a DoCommand to the Server
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   215
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   216
	//    uint8:  PlayerID (0..MAX_PLAYERS-1)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   217
	//    uint32: CommandID (see command.h)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   218
	//    uint32: P1 (free variables used in DoCommand)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   219
	//    uint32: P2
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   220
	//    uint32: Tile
1820
9b6458526480 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1797
diff changeset
   221
	//    string: text
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   222
	//    uint8:  CallBackID (see callback_table.c)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   223
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   224
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   225
	Packet *p = NetworkSend_Init(PACKET_CLIENT_COMMAND);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   226
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   227
	p->Send_uint8 (cp->player);
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   228
	p->Send_uint32(cp->cmd);
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   229
	p->Send_uint32(cp->p1);
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   230
	p->Send_uint32(cp->p2);
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   231
	p->Send_uint32((uint32)cp->tile);
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   232
	p->Send_string(cp->text);
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   233
	p->Send_uint8 (cp->callback);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   234
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   235
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   236
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   237
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   238
// Send a chat-packet over the network
4906
8a10678a62a3 (svn r6876) -Codechange: Change the naming of _PLAYER in DESTTYPE_PLAYER/NETWORK_ACTION_CHAT_PLAYER
Darkvater
parents: 4880
diff changeset
   239
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType type, int dest, const char *msg)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   240
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   241
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   242
	// Packet: CLIENT_CHAT
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   243
	// Function: Send a chat-packet to the serve
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   244
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   245
	//    uint8:  ActionID (see network_data.h, NetworkAction)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   246
	//    uint8:  Destination Type (see network_data.h, DestType);
7027
f3d60745346d (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6988
diff changeset
   247
	//    uint16: Destination Player
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   248
	//    String: Message (max MAX_TEXT_MSG_LEN)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   249
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   250
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   251
	Packet *p = NetworkSend_Init(PACKET_CLIENT_CHAT);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   252
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   253
	p->Send_uint8 (action);
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   254
	p->Send_uint8 (type);
7027
f3d60745346d (svn r9719) -Fix: in-game private messages did not work for clients with a Client ID > 255.
rubidium
parents: 6988
diff changeset
   255
	p->Send_uint16(dest);
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   256
	p->Send_string(msg);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   257
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   258
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   259
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   260
// Send an error-packet over the network
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   261
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_ERROR)(NetworkErrorCode errorno)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   262
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   263
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   264
	// Packet: CLIENT_ERROR
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   265
	// Function: The client made an error and is quiting the game
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   266
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   267
	//    uint8:  ErrorID (see network_data.h, NetworkErrorCode)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   268
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   269
	Packet *p = NetworkSend_Init(PACKET_CLIENT_ERROR);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   270
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   271
	p->Send_uint8(errorno);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   272
	MY_CLIENT->Send_Packet(p);
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
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   275
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password)
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
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   278
	// Packet: PACKET_CLIENT_SET_PASSWORD
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   279
	// Function: Set the password for the clients current company
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   280
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   281
	//    String: Password
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
	Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_PASSWORD);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   284
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   285
	p->Send_string(GenerateCompanyPasswordHash(password));
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   286
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   287
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   288
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   289
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   290
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   291
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   292
	// Packet: PACKET_CLIENT_SET_NAME
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   293
	// Function: Gives the player a new name
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   294
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   295
	//    String: Name
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   296
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   297
	Packet *p = NetworkSend_Init(PACKET_CLIENT_SET_NAME);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   298
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   299
	p->Send_string(name);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   300
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   301
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   302
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   303
// Send an quit-packet over the network
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   304
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)(const char *leavemsg)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   305
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   306
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   307
	// Packet: CLIENT_QUIT
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   308
	// Function: The client is quiting the game
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   309
	// Data:
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   310
	//    String: leave-message
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   311
	//
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   312
	Packet *p = NetworkSend_Init(PACKET_CLIENT_QUIT);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   313
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   314
	p->Send_string(leavemsg);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   315
	MY_CLIENT->Send_Packet(p);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   316
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   317
1026
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   318
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_RCON)(const char *pass, const char *command)
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   319
{
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   320
	Packet *p = NetworkSend_Init(PACKET_CLIENT_RCON);
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   321
	p->Send_string(pass);
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   322
	p->Send_string(command);
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   323
	MY_CLIENT->Send_Packet(p);
1026
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   324
}
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   325
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   326
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   327
// **********
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   328
// Receiving functions
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   329
//   DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   330
// **********
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   331
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7027
diff changeset
   332
extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm, Subdirectory subdir);
10233
c08376c16fb2 (svn r12765) -Codechange: move some stuff out of variables.h that required including other headers in variables.h.
rubidium
parents: 8760
diff changeset
   333
extern StringID _switch_mode_errorstr;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   334
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   335
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FULL)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   336
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   337
	// We try to join a server which is full
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   338
	_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_FULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   339
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   340
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   341
	return NETWORK_RECV_STATUS_SERVER_FULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   342
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   343
841
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 779
diff changeset
   344
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_BANNED)
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 779
diff changeset
   345
{
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 779
diff changeset
   346
	// We try to join a server where we are banned
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 779
diff changeset
   347
	_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_BANNED;
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 779
diff changeset
   348
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 779
diff changeset
   349
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 779
diff changeset
   350
	return NETWORK_RECV_STATUS_SERVER_BANNED;
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 779
diff changeset
   351
}
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 779
diff changeset
   352
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   353
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   354
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   355
	byte company_info_version;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   356
	int i;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   357
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   358
	company_info_version = p->Recv_uint8();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   359
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   360
	if (!MY_CLIENT->has_quit && company_info_version == NETWORK_COMPANY_INFO_VERSION) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   361
		byte total;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   362
		PlayerID current;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   363
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   364
		total = p->Recv_uint8();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   365
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   366
		// There is no data at all..
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   367
		if (total == 0) return NETWORK_RECV_STATUS_CLOSE_QUERY;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   368
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   369
		current = (Owner)p->Recv_uint8();
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   370
		if (!IsValidPlayer(current)) return NETWORK_RECV_STATUS_CLOSE_QUERY;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   371
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   372
		p->Recv_string(_network_player_info[current].company_name, sizeof(_network_player_info[current].company_name));
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   373
		_network_player_info[current].inaugurated_year = p->Recv_uint32();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   374
		_network_player_info[current].company_value    = p->Recv_uint64();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   375
		_network_player_info[current].money            = p->Recv_uint64();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   376
		_network_player_info[current].income           = p->Recv_uint64();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   377
		_network_player_info[current].performance      = p->Recv_uint16();
6169
31cdbb4845f1 (svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents: 6153
diff changeset
   378
		_network_player_info[current].use_password     = p->Recv_bool();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   379
		for (i = 0; i < NETWORK_VEHICLE_TYPES; i++)
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   380
			_network_player_info[current].num_vehicle[i] = p->Recv_uint16();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   381
		for (i = 0; i < NETWORK_STATION_TYPES; i++)
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   382
			_network_player_info[current].num_station[i] = p->Recv_uint16();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   383
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   384
		p->Recv_string(_network_player_info[current].players, sizeof(_network_player_info[current].players));
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   385
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   386
		InvalidateWindow(WC_NETWORK_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   387
734
018e549265ed (svn r1186) -Fix: [Network] You can now join a company on a server where a company
truelight
parents: 722
diff changeset
   388
		return NETWORK_RECV_STATUS_OKAY;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   389
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   390
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   391
	return NETWORK_RECV_STATUS_CLOSE_QUERY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   392
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   393
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   394
// This packet contains info about the client (playas and name)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   395
//  as client we save this in NetworkClientInfo, linked via 'index'
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   396
//  which is always an unique number on a server.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   397
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   398
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   399
	NetworkClientInfo *ci;
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   400
	uint16 index = p->Recv_uint16();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   401
	PlayerID playas = (Owner)p->Recv_uint8();
662
029d67bd54e6 (svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents: 659
diff changeset
   402
	char name[NETWORK_NAME_LENGTH];
8303
67babdcebe96 (svn r11357) -Fix: NetworkUniqueID could be 80 chars, while the max size we generate is 32. So reduce the size a bit. Pointed out by dihedral, so give him a big hug ;)
truelight
parents: 7762
diff changeset
   403
	char unique_id[NETWORK_UNIQUE_ID_LENGTH];
662
029d67bd54e6 (svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents: 659
diff changeset
   404
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   405
	p->Recv_string(name, sizeof(name));
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   406
	p->Recv_string(unique_id, sizeof(unique_id));
903
f860c7234167 (svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents: 841
diff changeset
   407
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   408
	if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
662
029d67bd54e6 (svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents: 659
diff changeset
   409
029d67bd54e6 (svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents: 659
diff changeset
   410
	/* Do we receive a change of data? Most likely we changed playas */
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   411
	if (index == _network_own_client_index) _network_playas = playas;
2684
8aba54c245cc (svn r3226) -Fix: GPMI implementation had minor glitches
truelight
parents: 2373
diff changeset
   412
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   413
	ci = NetworkFindClientInfoFromIndex(index);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   414
	if (ci != NULL) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   415
		if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   416
			// Client name changed, display the change
10685
955ddec7961e (svn r13229) -Codechange: replace some global variables that are only initialised once and always with the same value with enums.
rubidium
parents: 10684
diff changeset
   417
			NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", name);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   418
		} else if (playas != ci->client_playas) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   419
			// The player changed from client-player..
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   420
			// Do not display that for now
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   421
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   422
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   423
		ci->client_playas = playas;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   424
		ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
662
029d67bd54e6 (svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents: 659
diff changeset
   425
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   426
		InvalidateWindow(WC_CLIENT_LIST, 0);
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   427
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   428
		return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   429
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   430
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   431
	// We don't have this index yet, find an empty index, and put the data there
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   432
	ci = NetworkFindClientInfoFromIndex(NETWORK_EMPTY_INDEX);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   433
	if (ci != NULL) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   434
		ci->client_index = index;
662
029d67bd54e6 (svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents: 659
diff changeset
   435
		ci->client_playas = playas;
029d67bd54e6 (svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents: 659
diff changeset
   436
029d67bd54e6 (svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents: 659
diff changeset
   437
		ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
029d67bd54e6 (svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents: 659
diff changeset
   438
		ttd_strlcpy(ci->unique_id, unique_id, sizeof(ci->unique_id));
029d67bd54e6 (svn r1096) -Fix: [Network] PlayAs is now registered correctly
truelight
parents: 659
diff changeset
   439
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   440
		InvalidateWindow(WC_CLIENT_LIST, 0);
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   441
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   442
		return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   443
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   444
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   445
	// Here the program should never ever come.....
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   446
	return NETWORK_RECV_STATUS_MALFORMED_PACKET;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   447
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   448
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   449
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   450
{
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   451
	NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   452
2879
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   453
	switch (error) {
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   454
		/* We made an error in the protocol, and our connection is closed.... */
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   455
		case NETWORK_ERROR_NOT_AUTHORIZED:
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   456
		case NETWORK_ERROR_NOT_EXPECTED:
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   457
		case NETWORK_ERROR_PLAYER_MISMATCH:
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   458
			_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_ERROR;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   459
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   460
		case NETWORK_ERROR_FULL:
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   461
			_switch_mode_errorstr = STR_NETWORK_ERR_SERVER_FULL;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   462
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   463
		case NETWORK_ERROR_WRONG_REVISION:
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   464
			_switch_mode_errorstr = STR_NETWORK_ERR_WRONG_REVISION;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   465
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   466
		case NETWORK_ERROR_WRONG_PASSWORD:
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   467
			_switch_mode_errorstr = STR_NETWORK_ERR_WRONG_PASSWORD;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   468
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   469
		case NETWORK_ERROR_KICKED:
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   470
			_switch_mode_errorstr = STR_NETWORK_ERR_KICKED;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   471
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   472
		case NETWORK_ERROR_CHEATER:
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   473
			_switch_mode_errorstr = STR_NETWORK_ERR_CHEATER;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   474
			break;
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   475
		default:
d270cb37c0ec (svn r3427) - Feature: Allow seeing and setting the maximum amount of companies and spectators for a server. This can be changed/viewed during runtime as well in the console.
Darkvater
parents: 2817
diff changeset
   476
			_switch_mode_errorstr = STR_NETWORK_ERR_LOSTCONNECTION;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   477
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   478
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   479
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   480
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   481
	return NETWORK_RECV_STATUS_SERVER_ERROR;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   482
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   483
6123
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   484
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS)
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   485
{
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   486
	uint grf_count = p->Recv_uint8();
6123
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   487
	NetworkRecvStatus ret = NETWORK_RECV_STATUS_OKAY;
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   488
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   489
	/* Check all GRFs */
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   490
	for (; grf_count > 0; grf_count--) {
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   491
		GRFConfig c;
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   492
		MY_CLIENT->Recv_GRFIdentifier(p, &c);
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   493
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   494
		/* Check whether we know this GRF */
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   495
		const GRFConfig *f = FindGRFConfig(c.grfid, c.md5sum);
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   496
		if (f == NULL) {
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   497
			/* We do not know this GRF, bail out of initialization */
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   498
			char buf[sizeof(c.md5sum) * 2 + 1];
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   499
			md5sumToString(buf, lastof(buf), c.md5sum);
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   500
			DEBUG(grf, 0, "NewGRF %08X not found; checksum %s", BSWAP32(c.grfid), buf);
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   501
			ret = NETWORK_RECV_STATUS_NEWGRF_MISMATCH;
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   502
		}
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   503
	}
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   504
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   505
	if (ret == NETWORK_RECV_STATUS_OKAY) {
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   506
		/* Start receiving the map */
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   507
		SEND_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)();
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   508
	} else {
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   509
		/* NewGRF mismatch, bail out */
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   510
		_switch_mode_errorstr = STR_NETWORK_ERR_NEWGRF_MISMATCH;
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   511
	}
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   512
	return ret;
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   513
}
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   514
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   515
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   516
{
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   517
	NetworkPasswordType type = (NetworkPasswordType)p->Recv_uint8();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   518
4512
7151d4ee3a0f (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4428
diff changeset
   519
	switch (type) {
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   520
		case NETWORK_COMPANY_PASSWORD:
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   521
			/* Initialize the password hash salting variables. */
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   522
			_password_game_seed = p->Recv_uint32();
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   523
			p->Recv_string(_password_server_unique_id, sizeof(_password_server_unique_id));
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   524
			if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   525
4512
7151d4ee3a0f (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4428
diff changeset
   526
		case NETWORK_GAME_PASSWORD:
7151d4ee3a0f (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4428
diff changeset
   527
			ShowNetworkNeedPassword(type);
7151d4ee3a0f (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4428
diff changeset
   528
			return NETWORK_RECV_STATUS_OKAY;
7151d4ee3a0f (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4428
diff changeset
   529
7151d4ee3a0f (svn r6297) -Codechange: Disentangle the query window mess a bit: Move the network game password handling somewhere were it belongs to
tron
parents: 4428
diff changeset
   530
		default: return NETWORK_RECV_STATUS_MALFORMED_PACKET;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   531
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   532
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   533
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   534
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WELCOME)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   535
{
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   536
	_network_own_client_index = p->Recv_uint16();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   537
8495
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   538
	/* Initialize the password hash salting variables, even if they were previously. */
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   539
	_password_game_seed = p->Recv_uint32();
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   540
	p->Recv_string(_password_server_unique_id, sizeof(_password_server_unique_id));
51009cfec3de (svn r11557) -Codechange: send and store the passwords a little more secure to/in the servers.
rubidium
parents: 8303
diff changeset
   541
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   542
	// Start receiving the map
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   543
	SEND_COMMAND(PACKET_CLIENT_GETMAP)();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   544
	return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   545
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   546
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   547
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_WAIT)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   548
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   549
	_network_join_status = NETWORK_JOIN_STATUS_WAITING;
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   550
	_network_join_waiting = p->Recv_uint8();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   551
	InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   552
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   553
	// We are put on hold for receiving the map.. we need GUI for this ;)
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   554
	DEBUG(net, 1, "The server is currently busy sending the map to someone else, please wait..." );
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   555
	DEBUG(net, 1, "There are %d clients in front of you", _network_join_waiting);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   556
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   557
	return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   558
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   559
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   560
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   561
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   562
	static FILE *file_pointer;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   563
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   564
	byte maptype;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   565
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   566
	maptype = p->Recv_uint8();
903
f860c7234167 (svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents: 841
diff changeset
   567
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   568
	if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   569
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   570
	// First packet, init some stuff
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   571
	if (maptype == MAP_PACKET_START) {
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7027
diff changeset
   572
		file_pointer = FioFOpenFile("network_client.tmp", "wb", AUTOSAVE_DIR);;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   573
		if (file_pointer == NULL) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   574
			_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   575
			return NETWORK_RECV_STATUS_SAVEGAME;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   576
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   577
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   578
		_frame_counter = _frame_counter_server = _frame_counter_max = p->Recv_uint32();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   579
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   580
		_network_join_kbytes = 0;
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   581
		_network_join_kbytes_total = p->Recv_uint32() / 1024;
5954
5100190669ac (svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents: 5875
diff changeset
   582
5100190669ac (svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents: 5875
diff changeset
   583
		/* If the network connection has been closed due to loss of connection
5100190669ac (svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents: 5875
diff changeset
   584
		 * or when _network_join_kbytes_total is 0, the join status window will
5100190669ac (svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents: 5875
diff changeset
   585
		 * do a division by zero. When the connection is lost, we just return
5100190669ac (svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents: 5875
diff changeset
   586
		 * that. If kbytes_total is 0, the packet must be malformed as a
5100190669ac (svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents: 5875
diff changeset
   587
		 * savegame less than 1 kilobyte is practically impossible. */
5100190669ac (svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents: 5875
diff changeset
   588
		if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
5100190669ac (svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents: 5875
diff changeset
   589
		if (_network_join_kbytes_total == 0) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
5100190669ac (svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents: 5875
diff changeset
   590
5100190669ac (svn r8167) -Fix (FS#556): a network client crashes, due to a division by zero, when the connection gets lost at the right moment or when the packet is malformed (server sends size 0 for the map).
rubidium
parents: 5875
diff changeset
   591
		_network_join_status = NETWORK_JOIN_STATUS_DOWNLOADING;
6988
76eba6a9cc6f (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6573
diff changeset
   592
		InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   593
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   594
		// The first packet does not contain any more data
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   595
		return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   596
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   597
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   598
	if (maptype == MAP_PACKET_NORMAL) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   599
		// We are still receiving data, put it to the file
10421
1daeaead8993 (svn r12963) -Fix (r12960): loading some NewGRFs could cause an infinite loop.
rubidium
parents: 10418
diff changeset
   600
		if (fwrite(p->buffer + p->pos, 1, p->size - p->pos, file_pointer) != (size_t)(p->size - p->pos)) {
10418
3ac4a89469df (svn r12960) -Codechange: handle return values of (some) file system related functions.
rubidium
parents: 10415
diff changeset
   601
			_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
3ac4a89469df (svn r12960) -Codechange: handle return values of (some) file system related functions.
rubidium
parents: 10415
diff changeset
   602
			return NETWORK_RECV_STATUS_SAVEGAME;
3ac4a89469df (svn r12960) -Codechange: handle return values of (some) file system related functions.
rubidium
parents: 10415
diff changeset
   603
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   604
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   605
		_network_join_kbytes = ftell(file_pointer) / 1024;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   606
		InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   607
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   608
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   609
	// Check if this was the last packet
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   610
	if (maptype == MAP_PACKET_END) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   611
		fclose(file_pointer);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   612
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   613
		_network_join_status = NETWORK_JOIN_STATUS_PROCESSING;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   614
		InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   615
5664
dbbf4f842a00 (svn r7616) -Cleanup:
Darkvater
parents: 5568
diff changeset
   616
		/* The map is done downloading, load it */
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7027
diff changeset
   617
		if (!SafeSaveOrLoad("network_client.tmp", SL_LOAD, GM_NORMAL, AUTOSAVE_DIR)) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   618
			DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   619
			_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   620
			return NETWORK_RECV_STATUS_SAVEGAME;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   621
		}
5683
dca046ba7aa3 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5664
diff changeset
   622
		/* If the savegame has successfully loaded, ALL windows have been removed,
dca046ba7aa3 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5664
diff changeset
   623
		 * only toolbar/statusbar and gamefield are visible */
1500
228f77e88adf (svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents: 1317
diff changeset
   624
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   625
		// Say we received the map and loaded it correctly!
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   626
		SEND_COMMAND(PACKET_CLIENT_MAP_OK)();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   627
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   628
		/* New company/spectator (invalid player) or company we want to join is not active
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   629
		 * Switch local player to spectator and await the server's judgement */
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   630
		if (_network_playas == PLAYER_NEW_COMPANY || !IsValidPlayer(_network_playas) ||
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   631
				!GetPlayer(_network_playas)->is_active) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   632
5564
6e1b3ea1ba7f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5296
diff changeset
   633
			SetLocalPlayer(PLAYER_SPECTATOR);
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   634
5683
dca046ba7aa3 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5664
diff changeset
   635
			if (_network_playas != PLAYER_SPECTATOR) {
1797
a19c4181f1b7 (svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents: 1500
diff changeset
   636
				/* We have arrived and ready to start playing; send a command to make a new player;
a19c4181f1b7 (svn r2301) - CodeChange: prettyify ChangeOwnerShipOfPlayerItems() a bit
Darkvater
parents: 1500
diff changeset
   637
				 * the server will give us a client-id and let us in */
5683
dca046ba7aa3 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5664
diff changeset
   638
				_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
dca046ba7aa3 (svn r7638) -Codechange: Remove special window ShowJoinStatusWindowAfterJoin and shuffle around
Darkvater
parents: 5664
diff changeset
   639
				ShowJoinStatusWindow();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   640
				NetworkSend_Command(0, 0, 0, CMD_PLAYER_CTRL, NULL);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   641
			}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   642
		} else {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   643
			// take control over an existing company
5564
6e1b3ea1ba7f (svn r7561) -Fix (FS#431): core and (patches) GUI were not in-sync with respect to autorenew settings. This is only a temporary fix, as the definite fix needs to move the autorenew settings to a per-company settings window.
rubidium
parents: 5296
diff changeset
   644
			SetLocalPlayer(_network_playas);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   645
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   646
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   647
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   648
	return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   649
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   650
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   651
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_FRAME)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   652
{
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   653
	_frame_counter_server = p->Recv_uint32();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   654
	_frame_counter_max = p->Recv_uint32();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   655
#ifdef ENABLE_NETWORK_SYNC_EVERY_FRAME
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   656
	// Test if the server supports this option
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   657
	//  and if we are at the frame the server is
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   658
	if (p->pos < p->size) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   659
		_sync_frame = _frame_counter_server;
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   660
		_sync_seed_1 = p->Recv_uint32();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   661
#ifdef NETWORK_SEND_DOUBLE_SEED
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   662
		_sync_seed_2 = p->Recv_uint32();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   663
#endif
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   664
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   665
#endif
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   666
	DEBUG(net, 5, "Received FRAME %d", _frame_counter_server);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   667
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   668
	// Let the server know that we received this frame correctly
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   669
	//  We do this only once per day, to save some bandwidth ;)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   670
	if (!_network_first_time && last_ack_frame < _frame_counter) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   671
		last_ack_frame = _frame_counter + DAY_TICKS;
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   672
		DEBUG(net, 4, "Sent ACK at %d", _frame_counter);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   673
		SEND_COMMAND(PACKET_CLIENT_ACK)();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   674
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   675
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   676
	return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   677
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   678
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   679
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SYNC)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   680
{
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   681
	_sync_frame = p->Recv_uint32();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   682
	_sync_seed_1 = p->Recv_uint32();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   683
#ifdef NETWORK_SEND_DOUBLE_SEED
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   684
	_sync_seed_2 = p->Recv_uint32();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   685
#endif
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   686
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   687
	return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   688
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   689
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   690
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   691
{
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
   692
	CommandPacket *cp = MallocT<CommandPacket>(1);
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   693
	cp->player   = (PlayerID)p->Recv_uint8();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   694
	cp->cmd      = p->Recv_uint32();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   695
	cp->p1       = p->Recv_uint32();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   696
	cp->p2       = p->Recv_uint32();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   697
	cp->tile     = p->Recv_uint32();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   698
	p->Recv_string(cp->text, sizeof(cp->text));
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   699
	cp->callback = p->Recv_uint8();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   700
	cp->frame    = p->Recv_uint32();
7718
220603f0122e (svn r10501) -Fix [FS#1015]: error dialog was sometimes shown on all clients when a command failed instead of only the client that actually did the command.
rubidium
parents: 7556
diff changeset
   701
	cp->my_cmd   = p->Recv_bool();
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   702
	cp->next     = NULL;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   703
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   704
	// The server did send us this command..
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   705
	//  queue it in our own queue, so we can handle it in the upcoming frame!
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   706
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   707
	if (_local_command_queue == NULL) {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   708
		_local_command_queue = cp;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   709
	} else {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   710
		// Find last packet
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   711
		CommandPacket *c = _local_command_queue;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   712
		while (c->next != NULL) c = c->next;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   713
		c->next = cp;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   714
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   715
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   716
	return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   717
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   718
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   719
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   720
{
4946
42acc5fef0af (svn r6934) -Cleanup: Some minor cleanup for network_client and removing 'stupid' comment
Darkvater
parents: 4945
diff changeset
   721
	char name[NETWORK_NAME_LENGTH], msg[MAX_TEXT_MSG_LEN];
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   722
	const NetworkClientInfo *ci = NULL, *ci_to;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   723
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   724
	NetworkAction action = (NetworkAction)p->Recv_uint8();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   725
	uint16 index = p->Recv_uint16();
6169
31cdbb4845f1 (svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents: 6153
diff changeset
   726
	bool self_send = p->Recv_bool();
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   727
	p->Recv_string(msg, MAX_TEXT_MSG_LEN);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   728
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   729
	ci_to = NetworkFindClientInfoFromIndex(index);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   730
	if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   731
4946
42acc5fef0af (svn r6934) -Cleanup: Some minor cleanup for network_client and removing 'stupid' comment
Darkvater
parents: 4945
diff changeset
   732
	/* Did we initiate the action locally? */
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   733
	if (self_send) {
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   734
		switch (action) {
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   735
			case NETWORK_ACTION_CHAT_CLIENT:
4946
42acc5fef0af (svn r6934) -Cleanup: Some minor cleanup for network_client and removing 'stupid' comment
Darkvater
parents: 4945
diff changeset
   736
				/* For speaking to client we need the client-name */
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   737
				snprintf(name, sizeof(name), "%s", ci_to->client_name);
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   738
				ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   739
				break;
4945
c5c9bfb156fb (svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents: 4912
diff changeset
   740
c5c9bfb156fb (svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents: 4912
diff changeset
   741
			/* For speaking to company or giving money, we need the player-name */
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   742
			case NETWORK_ACTION_GIVE_MONEY:
4945
c5c9bfb156fb (svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents: 4912
diff changeset
   743
				if (!IsValidPlayer(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
c5c9bfb156fb (svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents: 4912
diff changeset
   744
				/* fallthrough */
c5c9bfb156fb (svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents: 4912
diff changeset
   745
			case NETWORK_ACTION_CHAT_COMPANY: {
7556
de5c6eb5465d (svn r10325) -Fix (r10323): Missed 3 company name references
peter1138
parents: 7425
diff changeset
   746
				StringID str = IsValidPlayer(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
de5c6eb5465d (svn r10325) -Fix (r10323): Missed 3 company name references
peter1138
parents: 7425
diff changeset
   747
				SetDParam(0, ci_to->client_playas);
4878
744717de172e (svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents: 4861
diff changeset
   748
4945
c5c9bfb156fb (svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents: 4912
diff changeset
   749
				GetString(name, str, lastof(name));
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   750
				ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
4945
c5c9bfb156fb (svn r6933) -Feature: Allow spectators to speak to eachother (team)
Darkvater
parents: 4912
diff changeset
   751
			} break;
4946
42acc5fef0af (svn r6934) -Cleanup: Some minor cleanup for network_client and removing 'stupid' comment
Darkvater
parents: 4945
diff changeset
   752
42acc5fef0af (svn r6934) -Cleanup: Some minor cleanup for network_client and removing 'stupid' comment
Darkvater
parents: 4945
diff changeset
   753
			default: NOT_REACHED(); break;
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   754
		}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   755
	} else {
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   756
		/* Display message from somebody else */
602
9bbe42a9e3ed (svn r1026) -Add: [Network] Added unique id, so in network, each client has an
truelight
parents: 571
diff changeset
   757
		snprintf(name, sizeof(name), "%s", ci_to->client_name);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   758
		ci = ci_to;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   759
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   760
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   761
	if (ci != NULL)
10685
955ddec7961e (svn r13229) -Codechange: replace some global variables that are only initialised once and always with the same value with enums.
rubidium
parents: 10684
diff changeset
   762
		NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), self_send, name, "%s", msg);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   763
	return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   764
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   765
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   766
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   767
{
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   768
	char str[100];
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   769
	uint16 index;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   770
	NetworkClientInfo *ci;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   771
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   772
	index = p->Recv_uint16();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   773
	GetNetworkErrorMsg(str, (NetworkErrorCode)p->Recv_uint8(), lastof(str));
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   774
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   775
	ci = NetworkFindClientInfoFromIndex(index);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   776
	if (ci != NULL) {
10685
955ddec7961e (svn r13229) -Codechange: replace some global variables that are only initialised once and always with the same value with enums.
rubidium
parents: 10684
diff changeset
   777
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   778
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   779
		// The client is gone, give the NetworkClientInfo free
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   780
		ci->client_index = NETWORK_EMPTY_INDEX;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   781
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   782
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   783
	InvalidateWindow(WC_CLIENT_LIST, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   784
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   785
	return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   786
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   787
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   788
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   789
{
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   790
	char str[100];
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   791
	uint16 index;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   792
	NetworkClientInfo *ci;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   793
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   794
	index = p->Recv_uint16();
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   795
	p->Recv_string(str, lengthof(str));
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   796
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   797
	ci = NetworkFindClientInfoFromIndex(index);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   798
	if (ci != NULL) {
10685
955ddec7961e (svn r13229) -Codechange: replace some global variables that are only initialised once and always with the same value with enums.
rubidium
parents: 10684
diff changeset
   799
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   800
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   801
		// The client is gone, give the NetworkClientInfo free
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   802
		ci->client_index = NETWORK_EMPTY_INDEX;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   803
	} else {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   804
		DEBUG(net, 0, "Unknown client (%d) is leaving the game", index);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   805
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   806
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   807
	InvalidateWindow(WC_CLIENT_LIST, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   808
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   809
	// If we come here it means we could not locate the client.. strange :s
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   810
	return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   811
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   812
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   813
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_JOIN)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   814
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   815
	uint16 index;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   816
	NetworkClientInfo *ci;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   817
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   818
	index = p->Recv_uint16();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   819
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   820
	ci = NetworkFindClientInfoFromIndex(index);
722
d0b031be5232 (svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents: 717
diff changeset
   821
	if (ci != NULL)
10685
955ddec7961e (svn r13229) -Codechange: replace some global variables that are only initialised once and always with the same value with enums.
rubidium
parents: 10684
diff changeset
   822
		NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name, "");
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   823
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   824
	InvalidateWindow(WC_CLIENT_LIST, 0);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   825
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   826
	return NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   827
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   828
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   829
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   830
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   831
	_switch_mode_errorstr = STR_NETWORK_SERVER_SHUTDOWN;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   832
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   833
	return NETWORK_RECV_STATUS_SERVER_ERROR;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   834
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   835
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   836
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME)
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   837
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   838
	// To trottle the reconnects a bit, every clients waits
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   839
	//  his _local_player value before reconnecting
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4840
diff changeset
   840
	// PLAYER_SPECTATOR is currently 255, so to avoid long wait periods
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   841
	//  set the max to 10.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   842
	_network_reconnect = min(_local_player + 1, 10);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   843
	_switch_mode_errorstr = STR_NETWORK_SERVER_REBOOT;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   844
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   845
	return NETWORK_RECV_STATUS_SERVER_ERROR;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   846
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   847
1026
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   848
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_RCON)
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   849
{
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   850
	char rcon_out[NETWORK_RCONCOMMAND_LENGTH];
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   851
10685
955ddec7961e (svn r13229) -Codechange: replace some global variables that are only initialised once and always with the same value with enums.
rubidium
parents: 10684
diff changeset
   852
	ConsoleColour color_code = (ConsoleColour)p->Recv_uint16();
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   853
	p->Recv_string(rcon_out, sizeof(rcon_out));
1026
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   854
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   855
	IConsolePrint(color_code, rcon_out);
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   856
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   857
	return NETWORK_RECV_STATUS_OKAY;
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   858
}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   859
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   860
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   861
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   862
// The layout for the receive-functions by the client
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   863
typedef NetworkRecvStatus NetworkClientPacket(Packet *p);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   864
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   865
// This array matches PacketType. At an incoming
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   866
//  packet it is matches against this array
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   867
//  and that way the right function to handle that
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   868
//  packet is found.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   869
static NetworkClientPacket* const _network_client_packet[] = {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   870
	RECEIVE_COMMAND(PACKET_SERVER_FULL),
841
8f0a68c6f43b (svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents: 779
diff changeset
   871
	RECEIVE_COMMAND(PACKET_SERVER_BANNED),
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   872
	NULL, /*PACKET_CLIENT_JOIN,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   873
	RECEIVE_COMMAND(PACKET_SERVER_ERROR),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   874
	NULL, /*PACKET_CLIENT_COMPANY_INFO,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   875
	RECEIVE_COMMAND(PACKET_SERVER_COMPANY_INFO),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   876
	RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   877
	RECEIVE_COMMAND(PACKET_SERVER_NEED_PASSWORD),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   878
	NULL, /*PACKET_CLIENT_PASSWORD,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   879
	RECEIVE_COMMAND(PACKET_SERVER_WELCOME),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   880
	NULL, /*PACKET_CLIENT_GETMAP,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   881
	RECEIVE_COMMAND(PACKET_SERVER_WAIT),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   882
	RECEIVE_COMMAND(PACKET_SERVER_MAP),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   883
	NULL, /*PACKET_CLIENT_MAP_OK,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   884
	RECEIVE_COMMAND(PACKET_SERVER_JOIN),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   885
	RECEIVE_COMMAND(PACKET_SERVER_FRAME),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   886
	RECEIVE_COMMAND(PACKET_SERVER_SYNC),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   887
	NULL, /*PACKET_CLIENT_ACK,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   888
	NULL, /*PACKET_CLIENT_COMMAND,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   889
	RECEIVE_COMMAND(PACKET_SERVER_COMMAND),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   890
	NULL, /*PACKET_CLIENT_CHAT,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   891
	RECEIVE_COMMAND(PACKET_SERVER_CHAT),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   892
	NULL, /*PACKET_CLIENT_SET_PASSWORD,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   893
	NULL, /*PACKET_CLIENT_SET_NAME,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   894
	NULL, /*PACKET_CLIENT_QUIT,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   895
	NULL, /*PACKET_CLIENT_ERROR,*/
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   896
	RECEIVE_COMMAND(PACKET_SERVER_QUIT),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   897
	RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   898
	RECEIVE_COMMAND(PACKET_SERVER_SHUTDOWN),
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   899
	RECEIVE_COMMAND(PACKET_SERVER_NEWGAME),
1026
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   900
	RECEIVE_COMMAND(PACKET_SERVER_RCON),
5b2681cad645 (svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents: 1013
diff changeset
   901
	NULL, /*PACKET_CLIENT_RCON,*/
6123
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   902
	RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS),
87aa45c64f8f (svn r8461) -Feature: check for NewGRF compatability before actually downloading the map from a game server when connecting from the command prompt and internal console.
rubidium
parents: 5954
diff changeset
   903
	NULL, /*PACKET_CLIENT_NEWGRFS_CHECKED,*/
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   904
};
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   905
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   906
// If this fails, check the array above with network_data.h
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   907
assert_compile(lengthof(_network_client_packet) == PACKET_END);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   908
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   909
// Is called after a client is connected to the server
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6169
diff changeset
   910
void NetworkClient_Connected()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   911
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   912
	// Set the frame-counter to 0 so nothing happens till we are ready
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   913
	_frame_counter = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   914
	_frame_counter_server = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   915
	last_ack_frame = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   916
	// Request the game-info
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   917
	SEND_COMMAND(PACKET_CLIENT_JOIN)();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   918
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   919
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   920
// Reads the packets from the socket-stream, if available
5875
4a1391019791 (svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents: 5860
diff changeset
   921
NetworkRecvStatus NetworkClient_ReadPackets(NetworkTCPSocketHandler *cs)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   922
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   923
	Packet *p;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   924
	NetworkRecvStatus res = NETWORK_RECV_STATUS_OKAY;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   925
6153
2ecdbf81caa7 (svn r8525) -Codechange: make NetworkSend_Packet(s) and NetworkRecv_Packet functions of NetworkTCPSocketHandler.
rubidium
parents: 6151
diff changeset
   926
	while (res == NETWORK_RECV_STATUS_OKAY && (p = cs->Recv_Packet(&res)) != NULL) {
6151
4b5e33f35bbe (svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents: 6149
diff changeset
   927
		byte type = p->Recv_uint8();
4880
0708f34e3586 (svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents: 4878
diff changeset
   928
		if (type < PACKET_END && _network_client_packet[type] != NULL && !MY_CLIENT->has_quit) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   929
			res = _network_client_packet[type](p);
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 1962
diff changeset
   930
		} else {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   931
			res = NETWORK_RECV_STATUS_MALFORMED_PACKET;
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5564
diff changeset
   932
			DEBUG(net, 0, "[client] received invalid packet type %d", type);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   933
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   934
6149
44aedfd50791 (svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents: 6123
diff changeset
   935
		delete p;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   936
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   937
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   938
	return res;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   939
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   940
10792
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   941
void NetworkClientSendRcon(const char *password, const char *command)
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   942
{
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   943
	SEND_COMMAND(PACKET_CLIENT_RCON)(password, command);
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   944
}
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   945
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   946
void NetworkUpdatePlayerName()
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   947
{
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   948
	NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   949
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   950
	if (ci == NULL) return;
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   951
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   952
	/* Don't change the name if it is the same as the old name */
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   953
	if (strcmp(ci->client_name, _settings_client.network.player_name) != 0) {
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   954
		if (!_network_server) {
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   955
			SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_settings_client.network.player_name);
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   956
		} else {
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   957
			if (NetworkFindName(_settings_client.network.player_name)) {
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   958
				NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _settings_client.network.player_name);
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   959
				ttd_strlcpy(ci->client_name, _settings_client.network.player_name, sizeof(ci->client_name));
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   960
				NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   961
			}
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   962
		}
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   963
	}
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   964
}
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   965
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   966
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg)
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   967
{
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   968
	SEND_COMMAND(PACKET_CLIENT_CHAT)(action, type, dest, msg);
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   969
}
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   970
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   971
void NetworkClientSetPassword()
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   972
{
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   973
	SEND_COMMAND(PACKET_CLIENT_SET_PASSWORD)(_network_player_info[_local_player].password);
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   974
}
95b6eb9fcc9e (svn r13343) -Codechange: reorder/move variable/functions in the network headers so that nothing from the network directory needs to include basically all network headers.
rubidium
parents: 10784
diff changeset
   975
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   976
#endif /* ENABLE_NETWORK */