(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)

This commit is contained in:
truelight 2004-12-19 15:14:55 +00:00
parent 96c1e88d56
commit db16262698
8 changed files with 165 additions and 99 deletions

View File

@ -712,7 +712,7 @@ DEF_CONSOLE_CMD(ConSet) {
SEND_COMMAND(PACKET_CLIENT_SET_NAME)(argv[2]);
else {
if (NetworkFindName(argv[2])) {
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, ci->client_name, argv[2]);
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, argv[2]);
ttd_strlcpy(ci->client_name, argv[2], sizeof(ci->client_name));
NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
}

View File

@ -1351,10 +1351,28 @@ STR_NETWORK_ERR_CLIENT_PLAYER_MISMATCH :wrong player-id in DoCommand
STR_NETWORK_ERR_CLIENT_KICKED :kicked by server
############ End of leave-in-this-order
STR_NETWORK_CLIENT_JOINED :has joined the game
STR_NETWORK_GIVE_MONEY :gave you some money ({CURRENCY})
STR_NETWORK_SERVER_SHUTDOWN :{WHITE} The server closed the session
STR_NETWORK_GIVE_MONEY :gave your company some money ({CURRENCY})
STR_NETWORK_GAVE_MONEY_AWAY :you gave {STRING} some money ({CURRENCY})
STR_NETWORK_CHAT_COMPANY :[Team] {STRING}:
STR_NETWORK_CHAT_TO_COMPANY :[Team] To {STRING}:
STR_NETWORK_CHAT_CLIENT :[Private] {STRING}:
STR_NETWORK_CHAT_TO_CLIENT :[Private] To {STRING}:
STR_NETWORK_CHAT_ALL :[All] {STRING}:
STR_NETWORK_NAME_CHANGE :has changed his name to
STR_NETWORK_SERVER_SHUTDOWN :{WHITE} The server closed the session
STR_NETWORK_SERVER_REBOOT :{WHITE} The server is restarting...{}Please wait...
STR_NETWORK_SERVER :Server
STR_NETWORK_CLIENT :Client
STR_NETWORK_CLIENTLIST_NONE :(none)
STR_NETWORK_CLIENTLIST_KICK :Kick
STR_NETWORK_CLIENTLIST_GIVE_MONEY :Give money
STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL :Speak to all
STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY :Speak to company
STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT :Private message
STR_NETWORK_SEND :{BLACK}Send
############ end network gui strings

View File

@ -91,8 +91,7 @@ void HandleOnEditText(WindowEvent *e) {
if (!DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY)) break;
// Inform the player of this action
SetDParam(0, money);
GetString(msg, STR_NETWORK_GIVE_MONEY);
snprintf(msg, 100, "%d", money);
if (!_network_server)
SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg);

View File

@ -38,6 +38,7 @@ static uint16 _network_client_index = NETWORK_SERVER_INDEX + 1;
/* Some externs / forwards */
extern void ShowJoinStatusWindow();
extern void StateGameLoop();
extern uint GetCurrentCurrencyRate();
// Function that looks up the CI for a given client-index
NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index)
@ -76,50 +77,88 @@ void NetworkGetClientName(char *client_name, size_t size, const NetworkClientSta
// This puts a text-message to the console, or in the future, the chat-box,
// (to keep it all a bit more general)
void CDECL NetworkTextMessage(NetworkAction action, uint16 color, const char *name, const char *str, ...)
// 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, ...)
{
char buf[1024];
va_list va;
const int duration = 10; // Game days the messages stay visible
char message[1024];
char temp[1024];
StringID TempStr = STR_NULL;
va_start(va, str);
vsprintf(buf, str, va);
va_end(va);
switch (action) {
case NETWORK_ACTION_JOIN_LEAVE:
IConsolePrintF(color, "*** %s %s", name, buf);
AddTextMessage(color, duration, "*** %s %s", name, buf);
case NETWORK_ACTION_JOIN:
GetString(temp, STR_NETWORK_CLIENT_JOINED);
snprintf(message, sizeof(message), "*** %s %s", name, temp);
break;
case NETWORK_ACTION_LEAVE:
GetString(temp, STR_NETWORK_ERR_LEFT);
snprintf(message, sizeof(message), "*** %s %s (%s)", name, temp, buf);
break;
case NETWORK_ACTION_GIVE_MONEY:
IConsolePrintF(color, "*** %s %s", name, buf);
AddTextMessage(color, duration, "*** %s %s", name, buf);
if (self_send) {
TempStr = AllocateName(name, 0);
SetDParam(0, TempStr);
SetDParam(1, atoi(buf));
GetString(temp, STR_NETWORK_GAVE_MONEY_AWAY);
DeleteName(TempStr);
snprintf(message, sizeof(message), "*** %s", temp);
} else {
SetDParam(0, atoi(buf));
GetString(temp, STR_NETWORK_GIVE_MONEY);
snprintf(message, sizeof(message), "*** %s %s", name, temp);
}
break;
case NETWORK_ACTION_CHAT_PLAYER:
IConsolePrintF(color, "[Team] %s: %s", name, buf);
AddTextMessage(color, duration, "[Team] %s: %s", name, buf);
if (self_send) {
TempStr = AllocateName(name, 0);
SetDParam(0, TempStr);
GetString(temp, STR_NETWORK_CHAT_TO_COMPANY);
DeleteName(TempStr);
snprintf(message, sizeof(message), "%s %s", temp, buf);
} else {
TempStr = AllocateName(name, 0);
SetDParam(0, TempStr);
GetString(temp, STR_NETWORK_CHAT_COMPANY);
DeleteName(TempStr);
snprintf(message, sizeof(message), "%s %s", temp, buf);
}
break;
case NETWORK_ACTION_CHAT_CLIENT:
IConsolePrintF(color, "[Private] %s: %s", name, buf);
AddTextMessage(color, duration, "[Private] %s: %s", name, buf);
break;
case NETWORK_ACTION_CHAT_TO_CLIENT:
IConsolePrintF(color, "[Private] To %s: %s", name, buf);
AddTextMessage(color, duration, "[Private] To %s: %s", name, buf);
break;
case NETWORK_ACTION_CHAT_TO_PLAYER:
IConsolePrintF(color, "[Team] To %s: %s", name, buf);
AddTextMessage(color, duration, "[Team] To %s: %s", name, buf);
if (self_send) {
TempStr = AllocateName(name, 0);
SetDParam(0, TempStr);
GetString(temp, STR_NETWORK_CHAT_TO_CLIENT);
DeleteName(TempStr);
snprintf(message, sizeof(message), "%s %s", temp, buf);
} else {
TempStr = AllocateName(name, 0);
SetDParam(0, TempStr);
GetString(temp, STR_NETWORK_CHAT_CLIENT);
DeleteName(TempStr);
snprintf(message, sizeof(message), "%s %s", temp, buf);
}
break;
case NETWORK_ACTION_NAME_CHANGE:
IConsolePrintF(color, "*** %s changed his name to %s", name, buf);
AddTextMessage(color, duration, "*** %s changed his name to %s", name, buf);
GetString(temp, STR_NETWORK_NAME_CHANGE);
snprintf(message, sizeof(message), "*** %s %s %s", name, temp, buf);
break;
default:
IConsolePrintF(color, "[All] %s: %s", name, buf);
AddTextMessage(color, duration, "[All] %s: %s", name, buf);
TempStr = AllocateName(name, 0);
SetDParam(0, TempStr);
GetString(temp, STR_NETWORK_CHAT_ALL);
DeleteName(TempStr);
snprintf(message, sizeof(message), "%s %s", temp, buf);
break;
}
IConsolePrintF(color, message);
AddTextMessage(color, duration, message);
}
// Calculate the frame-lag of a client
@ -444,16 +483,15 @@ void NetworkCloseClient(NetworkClientState *cs)
if (!cs->quited && _network_server && cs->status > STATUS_INACTIVE) {
// We did not receive a leave message from this client...
NetworkErrorCode errorno = NETWORK_ERROR_CONNECTION_LOST;
char str1[100], str2[100];
char str[100];
char client_name[NETWORK_NAME_LENGTH];
NetworkClientState *new_cs;
NetworkGetClientName(client_name, sizeof(client_name), cs);
GetString(str1, STR_NETWORK_ERR_LEFT);
GetString(str2, STR_NETWORK_ERR_CLIENT_GENERAL + errorno);
GetString(str, STR_NETWORK_ERR_CLIENT_GENERAL + errorno);
NetworkTextMessage(NETWORK_ACTION_JOIN_LEAVE, 1, client_name, "%s (%s)", str1, str2);
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, str);
// Inform other clients of this... strange leaving ;)
FOR_ALL_CLIENTS(new_cs) {

View File

@ -332,7 +332,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, ci->client_name, name);
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, name);
} else if (playas != ci->client_playas) {
// The player changed from client-player..
// Do not display that for now
@ -341,6 +341,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
ci->client_playas = playas;
ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
InvalidateWindow(WC_CLIENT_LIST, 0);
return NETWORK_RECV_STATUS_OKAY;
}
@ -353,6 +355,8 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
ttd_strlcpy(ci->unique_id, unique_id, sizeof(ci->unique_id));
InvalidateWindow(WC_CLIENT_LIST, 0);
return NETWORK_RECV_STATUS_OKAY;
}
@ -596,45 +600,60 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
NetworkClientInfo *ci, *ci_to;
uint16 index;
char name[NETWORK_NAME_LENGTH];
bool self_send;
index = NetworkRecv_uint16(p);
self_send = NetworkRecv_uint8(p);
NetworkRecv_string(p, msg, MAX_TEXT_MSG_LEN);
ci_to = NetworkFindClientInfoFromIndex(index);
if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY;
if (action == NETWORK_ACTION_CHAT_TO_CLIENT) {
snprintf(name, sizeof(name), "%s", ci_to->client_name);
ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
} else if (action == NETWORK_ACTION_CHAT_TO_PLAYER) {
GetString(name, DEREF_PLAYER(ci_to->client_playas-1)->name_1);
ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
/* Do we display the action locally? */
if (self_send) {
switch (action) {
case NETWORK_ACTION_CHAT_CLIENT:
/* For speak to client we need the client-name */
snprintf(name, sizeof(name), "%s", ci_to->client_name);
ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
break;
case NETWORK_ACTION_CHAT_PLAYER:
case NETWORK_ACTION_GIVE_MONEY:
/* For speak to player or give money, we need the player-name */
GetString(name, DEREF_PLAYER(ci_to->client_playas-1)->name_1);
ci = NetworkFindClientInfoFromIndex(_network_own_client_index);
break;
default:
/* This should never happen */
NOT_REACHED();
break;
}
} else {
/* Display message from somebody else */
snprintf(name, sizeof(name), "%s", ci_to->client_name);
ci = ci_to;
}
if (ci != NULL)
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), name, "%s", msg);
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), self_send, name, "%s", msg);
return NETWORK_RECV_STATUS_OKAY;
}
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT)
{
int errorno;
char str1[100], str2[100];
char str[100];
uint16 index;
NetworkClientInfo *ci;
index = NetworkRecv_uint16(p);
errorno = NetworkRecv_uint8(p);
GetString(str1, STR_NETWORK_ERR_LEFT);
GetString(str2, STR_NETWORK_ERR_CLIENT_GENERAL + errorno);
GetString(str, STR_NETWORK_ERR_CLIENT_GENERAL + errorno);
ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) {
NetworkTextMessage(NETWORK_ACTION_JOIN_LEAVE, 1, ci->client_name, "%s (%s)", str1, str2);
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, ci->client_name, str);
// The client is gone, give the NetworkClientInfo free
ci->client_index = NETWORK_EMPTY_INDEX;
@ -647,18 +666,16 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT)
{
char str1[100], str2[100];
char str[100];
uint16 index;
NetworkClientInfo *ci;
index = NetworkRecv_uint16(p);
NetworkRecv_string(p, str2, 100);
GetString(str1, STR_NETWORK_ERR_LEFT);
NetworkRecv_string(p, str, 100);
ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) {
NetworkTextMessage(NETWORK_ACTION_JOIN_LEAVE, 1, ci->client_name, "%s (%s)", str1, str2);
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, ci->client_name, str);
// The client is gone, give the NetworkClientInfo free
ci->client_index = NETWORK_EMPTY_INDEX;
@ -674,18 +691,14 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_JOIN)
{
char str1[100];
uint16 index;
NetworkClientInfo *ci;
index = NetworkRecv_uint16(p);
GetString(str1, STR_NETWORK_CLIENT_JOINED);
ci = NetworkFindClientInfoFromIndex(index);
if (ci != NULL) {
NetworkTextMessage(NETWORK_ACTION_JOIN_LEAVE, 1, ci->client_name, "%s", str1);
}
if (ci != NULL)
NetworkTextMessage(NETWORK_ACTION_JOIN, 1, false, ci->client_name, "");
InvalidateWindow(WC_CLIENT_LIST, 0);

View File

@ -91,12 +91,11 @@ typedef enum {
// Actions that can be used for NetworkTextMessage
typedef enum {
NETWORK_ACTION_JOIN_LEAVE,
NETWORK_ACTION_JOIN,
NETWORK_ACTION_LEAVE,
NETWORK_ACTION_CHAT,
NETWORK_ACTION_CHAT_PLAYER,
NETWORK_ACTION_CHAT_CLIENT,
NETWORK_ACTION_CHAT_TO_CLIENT,
NETWORK_ACTION_CHAT_TO_PLAYER,
NETWORK_ACTION_GIVE_MONEY,
NETWORK_ACTION_NAME_CHANGE,
} NetworkAction;
@ -212,7 +211,7 @@ void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp);
// from network.c
void NetworkCloseClient(NetworkClientState *cs);
void CDECL NetworkTextMessage(NetworkAction action, uint16 color, const char *name, const char *str, ...);
void CDECL NetworkTextMessage(NetworkAction action, uint16 color, bool self_send, const char *name, const char *str, ...);
void NetworkGetClientName(char *clientname, size_t size, const NetworkClientState *cs);
uint NetworkCalculateLag(const NetworkClientState *cs);
byte NetworkGetCurrentLanguageIndex();

View File

@ -983,22 +983,22 @@ static Window *PopupClientList(Window *w, int client_no, int x, int y)
i = 0;
if (_network_own_client_index != ci->client_index) {
sprintf(_clientlist_action[i],"Private message");
GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_CLIENT);
_clientlist_proc[i++] = &ClientList_SpeakToClient;
}
if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) {
sprintf(_clientlist_action[i],"Speak to company");
GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY);
_clientlist_proc[i++] = &ClientList_SpeakToPlayer;
}
sprintf(_clientlist_action[i],"Speak to all");
GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL);
_clientlist_proc[i++] = &ClientList_SpeakToAll;
if (_network_own_client_index != ci->client_index) {
if (_network_playas >= 1 && _network_playas <= MAX_PLAYERS) {
// We are no spectator
if (ci->client_playas >= 1 && ci->client_playas <= MAX_PLAYERS) {
sprintf(_clientlist_action[i],"Give money");
GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY);
_clientlist_proc[i++] = &ClientList_GiveMoney;
}
}
@ -1006,7 +1006,7 @@ static Window *PopupClientList(Window *w, int client_no, int x, int y)
// A server can kick clients (but not hisself)
if (_network_server && _network_own_client_index != ci->client_index) {
sprintf(_clientlist_action[i],"Kick");
GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_KICK);
_clientlist_proc[i++] = &ClientList_Kick;
/* sprintf(clientlist_action[i],"Ban");
@ -1014,7 +1014,7 @@ static Window *PopupClientList(Window *w, int client_no, int x, int y)
}
if (i == 0) {
sprintf(_clientlist_action[i],"(none)");
GetString(_clientlist_action[i], STR_NETWORK_CLIENTLIST_NONE);
_clientlist_proc[i++] = &ClientList_None;
}
@ -1116,9 +1116,9 @@ static void ClientListWndProc(Window *w, WindowEvent *e)
colour = 0x10;
if (ci->client_index == NETWORK_SERVER_INDEX) {
DoDrawString("Server", 4, y, colour);
DrawString(4, y, STR_NETWORK_SERVER, colour);
} else
DoDrawString("Client", 4, y, colour);
DrawString(4, y, STR_NETWORK_CLIENT, colour);
// Filter out spectators
if (ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS)

View File

@ -131,7 +131,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientState *cs, Netwo
//
NetworkClientState *new_cs;
char str1[100], str2[100];
char str[100];
char client_name[NETWORK_NAME_LENGTH];
Packet *p = NetworkSend_Init(PACKET_SERVER_ERROR);
@ -142,12 +142,11 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientState *cs, Netwo
if (cs->status > STATUS_AUTH) {
NetworkGetClientName(client_name, sizeof(client_name), cs);
GetString(str1, STR_NETWORK_ERR_LEFT);
GetString(str2, STR_NETWORK_ERR_CLIENT_GENERAL + error);
GetString(str, STR_NETWORK_ERR_CLIENT_GENERAL + error);
DEBUG(net, 2)("[NET] %s made an error (%s) and his connection is closed", client_name, str2);
DEBUG(net, 2)("[NET] %s made an error (%s) and his connection is closed", client_name, str);
NetworkTextMessage(NETWORK_ACTION_JOIN_LEAVE, 1, client_name, "%s (%s)", str1, str2);
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, str);
FOR_ALL_CLIENTS(new_cs) {
if (new_cs->status > STATUS_AUTH && new_cs != cs) {
@ -472,7 +471,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkClientState *cs, Com
NetworkSend_Packet(p, cs);
}
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkClientState *cs, NetworkAction action, uint16 client_index, const char *msg)
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkClientState *cs, NetworkAction action, uint16 client_index, bool self_send, const char *msg)
{
//
// Packet: SERVER_CHAT
@ -487,6 +486,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkClientState *cs, Networ
NetworkSend_uint8(p, action);
NetworkSend_uint16(p, client_index);
NetworkSend_uint8(p, self_send);
NetworkSend_string(p, msg);
NetworkSend_Packet(p, cs);
@ -710,13 +710,11 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK)
// Client has the map, now start syncing
if (cs->status == STATUS_DONE_MAP && !cs->quited) {
char client_name[NETWORK_NAME_LENGTH];
char str[100];
NetworkClientState *new_cs;
GetString(str, STR_NETWORK_CLIENT_JOINED);
NetworkGetClientName(client_name, sizeof(client_name), cs);
NetworkTextMessage(NETWORK_ACTION_JOIN_LEAVE, 1, client_name, str);
NetworkTextMessage(NETWORK_ACTION_JOIN, 1, 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
@ -834,7 +832,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
// to us. Display the error and report it to the other clients
NetworkClientState *new_cs;
byte errorno = NetworkRecv_uint8(p);
char str1[100], str2[100];
char str[100];
char client_name[NETWORK_NAME_LENGTH];
// The client was never joined.. thank the client for the packet, but ignore it
@ -845,12 +843,11 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
NetworkGetClientName(client_name, sizeof(client_name), cs);
GetString(str1, STR_NETWORK_ERR_LEFT);
GetString(str2, STR_NETWORK_ERR_CLIENT_GENERAL + errorno);
GetString(str, STR_NETWORK_ERR_CLIENT_GENERAL + errorno);
DEBUG(net, 2)("[NET] %s reported an error and is closing his connection (%s)", client_name, str2);
DEBUG(net, 2)("[NET] %s reported an error and is closing his connection (%s)", client_name, str);
NetworkTextMessage(NETWORK_ACTION_JOIN_LEAVE, 1, client_name, "%s (%s)", str1, str2);
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, str);
FOR_ALL_CLIENTS(new_cs) {
if (new_cs->status > STATUS_AUTH) {
@ -866,7 +863,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
// The client wants to leave. Display this and report it to the other
// clients.
NetworkClientState *new_cs;
char str1[100], str2[100];
char str[100];
char client_name[NETWORK_NAME_LENGTH];
// The client was never joined.. thank the client for the packet, but ignore it
@ -875,17 +872,15 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
return;
}
NetworkRecv_string(p, str2, 100);
NetworkRecv_string(p, str, 100);
NetworkGetClientName(client_name, sizeof(client_name), cs);
GetString(str1, STR_NETWORK_ERR_LEFT);
NetworkTextMessage(NETWORK_ACTION_JOIN_LEAVE, 1, client_name, "%s (%s)", str1, str2);
NetworkTextMessage(NETWORK_ACTION_LEAVE, 1, false, client_name, str);
FOR_ALL_CLIENTS(new_cs) {
if (new_cs->status > STATUS_AUTH) {
SEND_COMMAND(PACKET_SERVER_QUIT)(new_cs, cs->index, str2);
SEND_COMMAND(PACKET_SERVER_QUIT)(new_cs, cs->index, str);
}
}
@ -913,14 +908,17 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
switch (desttype) {
case DESTTYPE_CLIENT:
if (dest == 1) {
/* Are we sending to the server? */
if (dest == NETWORK_SERVER_INDEX) {
ci = NetworkFindClientInfoFromIndex(from_index);
/* Display the text locally, and that is it */
if (ci != NULL)
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), ci->client_name, "%s", msg);
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), false, ci->client_name, "%s", msg);
} else {
/* Else find the client to send the message to */
FOR_ALL_CLIENTS(cs) {
if (cs->index == dest) {
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, msg);
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, false, msg);
break;
}
}
@ -928,15 +926,15 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
// Display the message locally (so you know you have sent it)
if (from_index != dest) {
if (from_index == 1) {
if (from_index == NETWORK_SERVER_INDEX) {
ci = NetworkFindClientInfoFromIndex(from_index);
ci_to = NetworkFindClientInfoFromIndex(dest);
if (ci != NULL && ci_to != NULL)
NetworkTextMessage(NETWORK_ACTION_CHAT_TO_CLIENT, GetDrawStringPlayerColor(ci->client_playas-1), ci_to->client_name, "%s", msg);
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), true, ci_to->client_name, "%s", msg);
} else {
FOR_ALL_CLIENTS(cs) {
if (cs->index == from_index) {
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, NETWORK_ACTION_CHAT_TO_CLIENT, dest, msg);
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, dest, true, msg);
break;
}
}
@ -946,10 +944,11 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
case DESTTYPE_PLAYER: {
bool show_local = true; // If this is false, the message is already displayed
// on the client who did sent it.
/* Find all clients that belong to this player */
FOR_ALL_CLIENTS(cs) {
ci = DEREF_CLIENT_INFO(cs);
if (ci->client_playas == dest) {
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, msg);
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, false, msg);
if (cs->index == from_index)
show_local = false;
}
@ -957,7 +956,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-1), ci->client_name, "%s", msg);
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), false, ci->client_name, "%s", msg);
if (from_index == NETWORK_SERVER_INDEX)
show_local = false;
}
@ -967,11 +966,11 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
if (from_index == NETWORK_SERVER_INDEX) {
char name[NETWORK_NAME_LENGTH];
GetString(name, DEREF_PLAYER(ci->client_playas-1)->name_1);
NetworkTextMessage(NETWORK_ACTION_CHAT_TO_PLAYER, GetDrawStringPlayerColor(ci->client_playas-1), name, "%s", msg);
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), true, name, "%s", msg);
} else {
FOR_ALL_CLIENTS(cs) {
if (cs->index == from_index) {
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, NETWORK_ACTION_CHAT_TO_PLAYER, from_index, msg);
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, true, msg);
}
}
}
@ -983,11 +982,11 @@ void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest,
/* fall-through to next case */
case DESTTYPE_BROADCAST:
FOR_ALL_CLIENTS(cs) {
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, msg);
SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_index, false, msg);
}
ci = NetworkFindClientInfoFromIndex(from_index);
if (ci != NULL)
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), ci->client_name, "%s", msg);
NetworkTextMessage(action, GetDrawStringPlayerColor(ci->client_playas-1), false, ci->client_name, "%s", msg);
break;
}
}
@ -1028,7 +1027,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME)
if (ci != NULL) {
// Display change
if (NetworkFindName(name)) {
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, ci->client_name, name);
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, false, ci->client_name, name);
ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
NetworkUpdateClientInfo(ci->client_index);
}