src/network/network_client.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 10242 52b4a9006029
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
     2 
     2 
     3 #ifdef ENABLE_NETWORK
     3 #ifdef ENABLE_NETWORK
     4 
     4 
     5 #include "../stdafx.h"
     5 #include "../stdafx.h"
     6 #include "../debug.h"
     6 #include "../debug.h"
     7 #include "../string.h"
       
     8 #include "../openttd.h"
     7 #include "../openttd.h"
     9 #include "../strings.h"
       
    10 #include "network_data.h"
     8 #include "network_data.h"
    11 #include "core/tcp.h"
     9 #include "core/tcp.h"
    12 #include "../date.h"
       
    13 #include "table/strings.h"
       
    14 #include "../functions.h"
       
    15 #include "network_client.h"
    10 #include "network_client.h"
    16 #include "network_gamelist.h"
    11 #include "network_gamelist.h"
    17 #include "network_gui.h"
    12 #include "network_gui.h"
    18 #include "../saveload.h"
    13 #include "../saveload.h"
    19 #include "../command.h"
    14 #include "../command_func.h"
    20 #include "../window.h"
       
    21 #include "../console.h"
    15 #include "../console.h"
    22 #include "../variables.h"
    16 #include "../variables.h"
    23 #include "../ai/ai.h"
    17 #include "../ai/ai.h"
    24 #include "../helpers.hpp"
    18 #include "../core/alloc_func.hpp"
    25 #include "../fileio.h"
    19 #include "../fileio.h"
    26 #include "../md5.h"
    20 #include "../md5.h"
       
    21 #include "../strings_func.h"
       
    22 #include "../window_func.h"
       
    23 #include "../string_func.h"
       
    24 #include "../player_func.h"
       
    25 #include "../player_base.h"
       
    26 #include "../player_gui.h"
       
    27 
       
    28 #include "table/strings.h"
    27 
    29 
    28 // This file handles all the client-commands
    30 // This file handles all the client-commands
    29 
    31 
    30 
    32 
    31 // So we don't make too much typos ;)
    33 // So we don't make too much typos ;)
    53 	char salted_password[NETWORK_UNIQUE_ID_LENGTH];
    55 	char salted_password[NETWORK_UNIQUE_ID_LENGTH];
    54 
    56 
    55 	memset(salted_password, 0, sizeof(salted_password));
    57 	memset(salted_password, 0, sizeof(salted_password));
    56 	snprintf(salted_password, sizeof(salted_password), "%s", password);
    58 	snprintf(salted_password, sizeof(salted_password), "%s", password);
    57 	/* Add the game seed and the server's unique ID as the salt. */
    59 	/* Add the game seed and the server's unique ID as the salt. */
    58 	for (uint i = 0; i < NETWORK_UNIQUE_ID_LENGTH; i++) salted_password[i] ^= _password_server_unique_id[i] ^ (_password_game_seed >> i);
    60 	for (uint i = 0; i < NETWORK_UNIQUE_ID_LENGTH - 1; i++) salted_password[i] ^= _password_server_unique_id[i] ^ (_password_game_seed >> i);
    59 
    61 
    60 	md5_state_t state;
    62 	Md5 checksum;
    61 	md5_byte_t digest[16];
    63 	uint8 digest[16];
    62 	static char hashed_password[NETWORK_UNIQUE_ID_LENGTH];
    64 	static char hashed_password[NETWORK_UNIQUE_ID_LENGTH];
    63 
    65 
    64 	/* Generate the MD5 hash */
    66 	/* Generate the MD5 hash */
    65 	md5_init(&state);
    67 	checksum.Append((const uint8*)salted_password, sizeof(salted_password) - 1);
    66 	md5_append(&state, (const md5_byte_t*)salted_password, sizeof(salted_password));
    68 	checksum.Finish(digest);
    67 	md5_finish(&state, digest);
       
    68 
    69 
    69 	for (int di = 0; di < 16; di++) sprintf(hashed_password + di * 2, "%02x", digest[di]);
    70 	for (int di = 0; di < 16; di++) sprintf(hashed_password + di * 2, "%02x", digest[di]);
       
    71 	hashed_password[lengthof(hashed_password) - 1] = '\0';
    70 
    72 
    71 	return hashed_password;
    73 	return hashed_password;
    72 }
    74 }
    73 
    75 
    74 /**
    76 /**