mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-19 12:39:11 +00:00
(svn r13229) -Codechange: replace some global variables that are only initialised once and always with the same value with enums.
This commit is contained in:
@@ -141,7 +141,7 @@ byte NetworkSpectatorCount()
|
||||
// This puts a text-message to the console, or in the future, the chat-box,
|
||||
// (to keep it all a bit more general)
|
||||
// If 'self_send' is true, this is the client who is sending the message
|
||||
void CDECL NetworkTextMessage(NetworkAction action, uint16 color, bool self_send, const char *name, const char *str, ...)
|
||||
void CDECL NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str, ...)
|
||||
{
|
||||
char buf[1024];
|
||||
va_list va;
|
||||
@@ -155,16 +155,16 @@ void CDECL NetworkTextMessage(NetworkAction action, uint16 color, bool self_send
|
||||
|
||||
switch (action) {
|
||||
case NETWORK_ACTION_SERVER_MESSAGE:
|
||||
color = 1;
|
||||
color = CC_DEFAULT;
|
||||
snprintf(message, sizeof(message), "*** %s", buf);
|
||||
break;
|
||||
case NETWORK_ACTION_JOIN:
|
||||
color = 1;
|
||||
color = CC_DEFAULT;
|
||||
GetString(temp, STR_NETWORK_CLIENT_JOINED, lastof(temp));
|
||||
snprintf(message, sizeof(message), "*** %s %s", name, temp);
|
||||
break;
|
||||
case NETWORK_ACTION_LEAVE:
|
||||
color = 1;
|
||||
color = CC_DEFAULT;
|
||||
GetString(temp, STR_NETWORK_ERR_LEFT, lastof(temp));
|
||||
snprintf(message, sizeof(message), "*** %s %s (%s)", name, temp, buf);
|
||||
break;
|
||||
@@ -651,7 +651,7 @@ void NetworkCloseClient(NetworkTCPSocketHandler *cs)
|
||||
|
||||
GetNetworkErrorMsg(str, errorno, lastof(str));
|
||||
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, "%s", str);
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
|
||||
|
||||
// Inform other clients of this... strange leaving ;)
|
||||
FOR_ALL_CLIENTS(new_cs) {
|
||||
|
@@ -414,7 +414,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
|
||||
if (ci != NULL) {
|
||||
if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) {
|
||||
// Client name changed, display the change
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, "%s", name);
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", name);
|
||||
} else if (playas != ci->client_playas) {
|
||||
// The player changed from client-player..
|
||||
// Do not display that for now
|
||||
@@ -761,7 +761,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
|
||||
}
|
||||
|
||||
if (ci != NULL)
|
||||
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), self_send, name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), self_send, name, "%s", msg);
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
@@ -776,7 +776,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT)
|
||||
|
||||
ci = NetworkFindClientInfoFromIndex(index);
|
||||
if (ci != NULL) {
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, ci->client_name, "%s", str);
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str);
|
||||
|
||||
// The client is gone, give the NetworkClientInfo free
|
||||
ci->client_index = NETWORK_EMPTY_INDEX;
|
||||
@@ -798,7 +798,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT)
|
||||
|
||||
ci = NetworkFindClientInfoFromIndex(index);
|
||||
if (ci != NULL) {
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, ci->client_name, "%s", str);
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str);
|
||||
|
||||
// The client is gone, give the NetworkClientInfo free
|
||||
ci->client_index = NETWORK_EMPTY_INDEX;
|
||||
@@ -821,7 +821,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_JOIN)
|
||||
|
||||
ci = NetworkFindClientInfoFromIndex(index);
|
||||
if (ci != NULL)
|
||||
NetworkTextMessage(NETWORK_ACTION_JOIN, 1, false, ci->client_name, "");
|
||||
NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name, "");
|
||||
|
||||
InvalidateWindow(WC_CLIENT_LIST, 0);
|
||||
|
||||
@@ -850,9 +850,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_NEWGAME)
|
||||
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_RCON)
|
||||
{
|
||||
char rcon_out[NETWORK_RCONCOMMAND_LENGTH];
|
||||
uint16 color_code;
|
||||
|
||||
color_code = p->Recv_uint16();
|
||||
ConsoleColour color_code = (ConsoleColour)p->Recv_uint16();
|
||||
p->Recv_string(rcon_out, sizeof(rcon_out));
|
||||
|
||||
IConsolePrint(color_code, rcon_out);
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#define NETWORK_DATA_H
|
||||
|
||||
#include "../openttd.h"
|
||||
#include "../console_type.h"
|
||||
#include "network.h"
|
||||
#include "network_internal.h"
|
||||
|
||||
@@ -105,7 +106,7 @@ void NetworkAddCommandQueue(NetworkTCPSocketHandler *cs, CommandPacket *cp);
|
||||
|
||||
// from network.c
|
||||
void NetworkCloseClient(NetworkTCPSocketHandler *cs);
|
||||
void CDECL NetworkTextMessage(NetworkAction action, uint16 color, bool self_send, const char *name, const char *str, ...);
|
||||
void CDECL NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str, ...);
|
||||
void NetworkGetClientName(char *clientname, size_t size, const NetworkTCPSocketHandler *cs);
|
||||
uint NetworkCalculateLag(const NetworkTCPSocketHandler *cs);
|
||||
byte NetworkGetCurrentLanguageIndex();
|
||||
|
@@ -160,7 +160,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkTCPSocketHandler *cs,
|
||||
|
||||
DEBUG(net, 1, "'%s' made an error and has been disconnected. Reason: '%s'", client_name, str);
|
||||
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, "%s", str);
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
|
||||
|
||||
FOR_ALL_CLIENTS(new_cs) {
|
||||
if (new_cs->status > STATUS_AUTH && new_cs != cs) {
|
||||
@@ -779,7 +779,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK)
|
||||
|
||||
NetworkGetClientName(client_name, sizeof(client_name), cs);
|
||||
|
||||
NetworkTextMessage(NETWORK_ACTION_JOIN, 1, false, client_name, "");
|
||||
NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, client_name, "");
|
||||
|
||||
// Mark the client as pre-active, and wait for an ACK
|
||||
// so we know he is done loading and in sync with us
|
||||
@@ -822,17 +822,17 @@ static bool CheckCommandFlags(const CommandPacket *cp, const NetworkClientInfo *
|
||||
byte flags = GetCommandFlags(cp->cmd);
|
||||
|
||||
if (flags & CMD_SERVER && ci->client_index != NETWORK_SERVER_INDEX) {
|
||||
IConsolePrintF(_icolour_err, "WARNING: server only command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
|
||||
IConsolePrintF(CC_ERROR, "WARNING: server only command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flags & CMD_OFFLINE) {
|
||||
IConsolePrintF(_icolour_err, "WARNING: offline only command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
|
||||
IConsolePrintF(CC_ERROR, "WARNING: offline only command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cp->cmd != CMD_PLAYER_CTRL && !IsValidPlayer(cp->player) && ci->client_index != NETWORK_SERVER_INDEX) {
|
||||
IConsolePrintF(_icolour_err, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
|
||||
IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_index, GetPlayerIP(ci));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -875,7 +875,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
|
||||
|
||||
/* Check if cp->cmd is valid */
|
||||
if (!IsValidCommand(cp->cmd)) {
|
||||
IConsolePrintF(_icolour_err, "WARNING: invalid command from client %d (IP: %s).", ci->client_index, GetPlayerIP(ci));
|
||||
IConsolePrintF(CC_ERROR, "WARNING: invalid command from client %d (IP: %s).", ci->client_index, GetPlayerIP(ci));
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
|
||||
free(cp);
|
||||
return;
|
||||
@@ -892,7 +892,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
|
||||
* something pretty naughty (or a bug), and will be kicked
|
||||
*/
|
||||
if (!(cp->cmd == CMD_PLAYER_CTRL && cp->p1 == 0) && ci->client_playas != cp->player) {
|
||||
IConsolePrintF(_icolour_err, "WARNING: player %d (IP: %s) tried to execute a command as player %d, kicking...",
|
||||
IConsolePrintF(CC_ERROR, "WARNING: player %d (IP: %s) tried to execute a command as player %d, kicking...",
|
||||
ci->client_playas + 1, GetPlayerIP(ci), cp->player + 1);
|
||||
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH);
|
||||
free(cp);
|
||||
@@ -969,7 +969,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
|
||||
|
||||
DEBUG(net, 2, "'%s' reported an error and is closing its connection (%s)", client_name, str);
|
||||
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, "%s", str);
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
|
||||
|
||||
FOR_ALL_CLIENTS(new_cs) {
|
||||
if (new_cs->status > STATUS_AUTH) {
|
||||
@@ -998,7 +998,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
|
||||
|
||||
NetworkGetClientName(client_name, sizeof(client_name), cs);
|
||||
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, "%s", str);
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
|
||||
|
||||
FOR_ALL_CLIENTS(new_cs) {
|
||||
if (new_cs->status > STATUS_AUTH) {
|
||||
@@ -1052,7 +1052,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
|
||||
ci = NetworkFindClientInfoFromIndex(from_index);
|
||||
/* Display the text locally, and that is it */
|
||||
if (ci != NULL)
|
||||
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
} else {
|
||||
/* Else find the client to send the message to */
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
@@ -1069,7 +1069,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
|
||||
ci = NetworkFindClientInfoFromIndex(from_index);
|
||||
ci_to = NetworkFindClientInfoFromIndex(dest);
|
||||
if (ci != NULL && ci_to != NULL)
|
||||
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), true, ci_to->client_name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), true, ci_to->client_name, "%s", msg);
|
||||
} else {
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
if (cs->index == from_index) {
|
||||
@@ -1097,7 +1097,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
|
||||
ci = NetworkFindClientInfoFromIndex(from_index);
|
||||
ci_own = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
|
||||
if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) {
|
||||
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
if (from_index == NETWORK_SERVER_INDEX) show_local = false;
|
||||
ci_to = ci_own;
|
||||
}
|
||||
@@ -1112,7 +1112,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
|
||||
StringID str = IsValidPlayer(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
|
||||
SetDParam(0, ci_to->client_playas);
|
||||
GetString(name, str, lastof(name));
|
||||
NetworkTextMessage(action, GetDrawStringPlayerColor(ci_own->client_playas), true, name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci_own->client_playas), true, name, "%s", msg);
|
||||
} else {
|
||||
FOR_ALL_CLIENTS(cs) {
|
||||
if (cs->index == from_index) {
|
||||
@@ -1132,7 +1132,7 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
|
||||
}
|
||||
ci = NetworkFindClientInfoFromIndex(from_index);
|
||||
if (ci != NULL)
|
||||
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
NetworkTextMessage(action, (ConsoleColour)GetDrawStringPlayerColor(ci->client_playas), false, ci->client_name, "%s", msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1175,7 +1175,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME)
|
||||
if (ci != NULL) {
|
||||
// Display change
|
||||
if (NetworkFindName(client_name)) {
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, "%s", client_name);
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", client_name);
|
||||
ttd_strlcpy(ci->client_name, client_name, sizeof(ci->client_name));
|
||||
NetworkUpdateClientInfo(ci->client_index);
|
||||
}
|
||||
@@ -1412,13 +1412,13 @@ static void NetworkAutoCleanCompanies()
|
||||
if (_network_player_info[p->index].months_empty > _network_autoclean_unprotected && _network_player_info[p->index].password[0] == '\0') {
|
||||
/* Shut the company down */
|
||||
DoCommandP(0, 2, p->index, NULL, CMD_PLAYER_CTRL);
|
||||
IConsolePrintF(_icolour_def, "Auto-cleaned company #%d", p->index + 1);
|
||||
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d", p->index + 1);
|
||||
}
|
||||
/* Is the compnay empty for autoclean_protected-months, and there is a protection? */
|
||||
if (_network_player_info[p->index].months_empty > _network_autoclean_protected && _network_player_info[p->index].password[0] != '\0') {
|
||||
/* Unprotect the company */
|
||||
_network_player_info[p->index].password[0] = '\0';
|
||||
IConsolePrintF(_icolour_def, "Auto-removed protection from company #%d", p->index+1);
|
||||
IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", p->index+1);
|
||||
_network_player_info[p->index].months_empty = 0;
|
||||
}
|
||||
} else {
|
||||
@@ -1527,14 +1527,14 @@ void NetworkServer_Tick(bool send_frame)
|
||||
if (lag > 3) {
|
||||
// Client did still not report in after 4 game-day, drop him
|
||||
// (that is, the 3 of above, + 1 before any lag is counted)
|
||||
IConsolePrintF(_icolour_err,"Client #%d is dropped because the client did not respond for more than 4 game-days", cs->index);
|
||||
IConsolePrintF(CC_ERROR,"Client #%d is dropped because the client did not respond for more than 4 game-days", cs->index);
|
||||
NetworkCloseClient(cs);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Report once per time we detect the lag
|
||||
if (cs->lag_test == 0) {
|
||||
IConsolePrintF(_icolour_warn,"[%d] Client #%d is slow, try increasing *net_frame_freq to a higher value!", _frame_counter, cs->index);
|
||||
IConsolePrintF(CC_WARNING,"[%d] Client #%d is slow, try increasing *net_frame_freq to a higher value!", _frame_counter, cs->index);
|
||||
cs->lag_test = 1;
|
||||
}
|
||||
} else {
|
||||
@@ -1543,13 +1543,13 @@ void NetworkServer_Tick(bool send_frame)
|
||||
} else if (cs->status == STATUS_PRE_ACTIVE) {
|
||||
int lag = NetworkCalculateLag(cs);
|
||||
if (lag > _network_max_join_time) {
|
||||
IConsolePrintF(_icolour_err,"Client #%d is dropped because it took longer than %d ticks for him to join", cs->index, _network_max_join_time);
|
||||
IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks for him to join", cs->index, _network_max_join_time);
|
||||
NetworkCloseClient(cs);
|
||||
}
|
||||
} else if (cs->status == STATUS_INACTIVE) {
|
||||
int lag = NetworkCalculateLag(cs);
|
||||
if (lag > 4 * DAY_TICKS) {
|
||||
IConsolePrintF(_icolour_err,"Client #%d is dropped because it took longer than %d ticks to start the joining process", cs->index, 4 * DAY_TICKS);
|
||||
IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks to start the joining process", cs->index, 4 * DAY_TICKS);
|
||||
NetworkCloseClient(cs);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user