network_server.c
changeset 4912 d04b3f2bca70
parent 4906 8a10678a62a3
child 4944 c61494b1ec35
equal deleted inserted replaced
4911:84e907c7822a 4912:d04b3f2bca70
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 #ifdef ENABLE_NETWORK
     3 #ifdef ENABLE_NETWORK
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
       
     6 #include "openttd.h" // XXX StringID
     6 #include "debug.h"
     7 #include "debug.h"
     7 #include "string.h"
     8 #include "string.h"
     8 #include "strings.h"
     9 #include "strings.h"
     9 #include "network_data.h"
    10 #include "network_data.h"
    10 #include "train.h"
    11 #include "train.h"
   142 	Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR);
   143 	Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR);
   143 
   144 
   144 	NetworkSend_uint8(p, error);
   145 	NetworkSend_uint8(p, error);
   145 	NetworkSend_Packet(p, cs);
   146 	NetworkSend_Packet(p, cs);
   146 
   147 
   147 	GetNetworkErrorMsg(str, error);
   148 	GetNetworkErrorMsg(str, error, lastof(str));
   148 
   149 
   149 	// Only send when the current client was in game
   150 	// Only send when the current client was in game
   150 	if (cs->status > STATUS_AUTH) {
   151 	if (cs->status > STATUS_AUTH) {
   151 		NetworkClientState *new_cs;
   152 		NetworkClientState *new_cs;
   152 		char client_name[NETWORK_CLIENT_NAME_LENGTH];
   153 		char client_name[NETWORK_CLIENT_NAME_LENGTH];
   897 		return;
   898 		return;
   898 	}
   899 	}
   899 
   900 
   900 	NetworkGetClientName(client_name, sizeof(client_name), cs);
   901 	NetworkGetClientName(client_name, sizeof(client_name), cs);
   901 
   902 
   902 	GetNetworkErrorMsg(str, errorno);
   903 	GetNetworkErrorMsg(str, errorno, lastof(str));
   903 
   904 
   904 	DEBUG(net, 2)("[NET] %s reported an error and is closing his connection (%s)", client_name, str);
   905 	DEBUG(net, 2)("[NET] %s reported an error and is closing his connection (%s)", client_name, str);
   905 
   906 
   906 	NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, "%s", str);
   907 	NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, "%s", str);
   907 
   908 
  1041 
  1042 
  1042 		// Display the message locally (so you know you have sent it)
  1043 		// Display the message locally (so you know you have sent it)
  1043 		if (ci != NULL && show_local) {
  1044 		if (ci != NULL && show_local) {
  1044 			if (from_index == NETWORK_SERVER_INDEX) {
  1045 			if (from_index == NETWORK_SERVER_INDEX) {
  1045 				char name[NETWORK_NAME_LENGTH];
  1046 				char name[NETWORK_NAME_LENGTH];
  1046 				GetString(name, GetPlayer(ci_to->client_playas)->name_1);
  1047 				GetString(name, GetPlayer(ci_to->client_playas)->name_1, lastof(name));
  1047 				NetworkTextMessage(action, GetDrawStringPlayerColor(ci_own->client_playas), true, name, "%s", msg);
  1048 				NetworkTextMessage(action, GetDrawStringPlayerColor(ci_own->client_playas), true, name, "%s", msg);
  1048 			} else {
  1049 			} else {
  1049 				FOR_ALL_CLIENTS(cs) {
  1050 				FOR_ALL_CLIENTS(cs) {
  1050 					if (cs->index == from_index) {
  1051 					if (cs->index == from_index) {
  1051 						SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, ci_to->client_index, true, msg);
  1052 						SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, ci_to->client_index, true, msg);
  1209 		ttd_strlcpy(_network_player_info[p->index].password, password, sizeof(_network_player_info[p->index].password));
  1210 		ttd_strlcpy(_network_player_info[p->index].password, password, sizeof(_network_player_info[p->index].password));
  1210 
  1211 
  1211 		// Grap the company name
  1212 		// Grap the company name
  1212 		SetDParam(0, p->name_1);
  1213 		SetDParam(0, p->name_1);
  1213 		SetDParam(1, p->name_2);
  1214 		SetDParam(1, p->name_2);
  1214 		GetString(_network_player_info[p->index].company_name, STR_JUST_STRING);
  1215 		GetString(_network_player_info[p->index].company_name, STR_JUST_STRING, lastof(_network_player_info[p->index].company_name));
  1215 
  1216 
  1216 		// Check the income
  1217 		// Check the income
  1217 		if (_cur_year - 1 == p->inaugurated_year) {
  1218 		if (_cur_year - 1 == p->inaugurated_year) {
  1218 			// The player is here just 1 year, so display [2], else display[1]
  1219 			// The player is here just 1 year, so display [2], else display[1]
  1219 			for (i = 0; i < lengthof(p->yearly_expenses[2]); i++) {
  1220 			for (i = 0; i < lengthof(p->yearly_expenses[2]); i++) {