summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lang/english.txt19
-rw-r--r--src/main_gui.cpp9
-rw-r--r--src/network/network.cpp104
-rw-r--r--src/network/network_chat_gui.cpp2
-rw-r--r--src/network/network_client.cpp34
-rw-r--r--src/network/network_client.h4
-rw-r--r--src/network/network_func.h4
-rw-r--r--src/network/network_internal.h4
-rw-r--r--src/network/network_server.cpp60
-rw-r--r--src/network/network_type.h10
10 files changed, 116 insertions, 134 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 725af58a0..a15c54cd6 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1570,7 +1570,6 @@ STR_NETWORK_ERR_SERVER_BANNED :{WHITE} You are
STR_NETWORK_ERR_KICKED :{WHITE} You were kicked out of the game
STR_NETWORK_ERR_CHEATER :{WHITE} Cheating is not allowed on this server
-STR_NETWORK_ERR_LEFT :has left the game
############ Leave those lines in this order!!
STR_NETWORK_ERR_CLIENT_GENERAL :general error
STR_NETWORK_ERR_CLIENT_DESYNC :desync error
@@ -1588,9 +1587,20 @@ STR_NETWORK_ERR_CLIENT_KICKED :kicked by serve
STR_NETWORK_ERR_CLIENT_CHEATER :was trying to use a cheat
STR_NETWORK_ERR_CLIENT_SERVER_FULL :server full
############ End of leave-in-this-order
-STR_NETWORK_CLIENT_JOINED :has joined the game
-STR_NETWORK_GIVE_MONEY :gave your company some money ({CURRENCY})
-STR_NETWORK_GAVE_MONEY_AWAY :you gave {RAW_STRING} some money ({CURRENCY})
+STR_NETWORK_SERVER_MESSAGE :*** {2:STRING}
+############ Leave those lines in this order!!
+STR_NETWORK_SERVER_MESSAGE_GAME_PAUSED_PLAYERS :Game paused (not enough players)
+STR_NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_PLAYERS :Game unpaused (enough players)
+STR_NETWORK_SERVER_MESSAGE_GAME_PAUSED_CONNECT :Game paused (connecting client)
+STR_NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_CONNECT :Game unpaused (client connected)
+STR_NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_CONNECT_FAIL :Game unpaused (client failed to connect)
+############ End of leave-in-this-order
+STR_NETWORK_CLIENT_LEAVING :leaving
+STR_NETWORK_CLIENT_JOINED :*** {RAW_STRING} has joined the game
+STR_NETWORK_CLIENT_LEFT :*** {RAW_STRING} has left the game ({2:STRING})
+STR_NETWORK_NAME_CHANGE :*** {RAW_STRING} has changed his/her name to {RAW_STRING}
+STR_NETWORK_GIVE_MONEY :*** {RAW_STRING} gave your company {2:CURRENCY}
+STR_NETWORK_GAVE_MONEY_AWAY :*** You gave {1:RAW_STRING} {2:CURRENCY}
STR_NETWORK_CHAT_COMPANY_CAPTION :[Team] :
STR_NETWORK_CHAT_COMPANY :[Team] {RAW_STRING}: {GRAY}{RAW_STRING}
STR_NETWORK_CHAT_TO_COMPANY :[Team] To {RAW_STRING}: {GRAY}{RAW_STRING}
@@ -1600,7 +1610,6 @@ STR_NETWORK_CHAT_TO_CLIENT :[Private] To {R
STR_NETWORK_CHAT_ALL_CAPTION :[All] :
STR_NETWORK_CHAT_ALL :[All] {RAW_STRING}: {GRAY}{RAW_STRING}
STR_NETWORK_CHAT_OSKTITLE :{BLACK}Enter text for network chat
-STR_NETWORK_NAME_CHANGE :has changed his/her name to
STR_NETWORK_SERVER_SHUTDOWN :{WHITE} The server closed the session
STR_NETWORK_SERVER_REBOOT :{WHITE} The server is restarting...{}Please wait...
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index 905aa8458..8fc7a4ea0 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -49,14 +49,15 @@ void CcGiveMoney(bool success, TileIndex tile, uint32 p1, uint32 p2)
#ifdef ENABLE_NETWORK
if (!success || !_settings_game.economy.give_money) return;
- char msg[20];
/* Inform the company of the action of one of it's clients (controllers). */
- snprintf(msg, sizeof(msg), "%d", p1);
+ char msg[64];
+ SetDParam(0, p2);
+ GetString(msg, STR_COMPANY_NAME, lastof(msg));
if (!_network_server) {
- NetworkClientSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg);
+ NetworkClientSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, p1);
} else {
- NetworkServerSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, CLIENT_ID_SERVER);
+ NetworkServerSendChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, CLIENT_ID_SERVER, p1);
}
#endif /* ENABLE_NETWORK */
}
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 7f54ef42e..9b2083efe 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -184,69 +184,35 @@ 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, ConsoleColour color, bool self_send, const char *name, const char *str, ...)
+void NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str, int64 data)
{
- char buf[1024];
- va_list va;
const int duration = 10; // Game days the messages stay visible
- char message[1024];
- char temp[1024];
-
- va_start(va, str);
- vsnprintf(buf, lengthof(buf), str, va);
- va_end(va);
+ StringID strid;
switch (action) {
case NETWORK_ACTION_SERVER_MESSAGE:
+ /* Ignore invalid messages */
+ if (data >= NETWORK_SERVER_MESSAGE_END) return;
+
+ strid = STR_NETWORK_SERVER_MESSAGE;
color = CC_DEFAULT;
- snprintf(message, sizeof(message), "*** %s", buf);
- break;
- case NETWORK_ACTION_JOIN:
- 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 = CC_DEFAULT;
- GetString(temp, STR_NETWORK_ERR_LEFT, lastof(temp));
- snprintf(message, sizeof(message), "*** %s %s (%s)", name, temp, buf);
- break;
- case NETWORK_ACTION_GIVE_MONEY:
- if (self_send) {
- SetDParamStr(0, name);
- SetDParam(1, atoi(buf));
- GetString(temp, STR_NETWORK_GAVE_MONEY_AWAY, lastof(temp));
- snprintf(message, sizeof(message), "*** %s", temp);
- } else {
- SetDParam(0, atoi(buf));
- GetString(temp, STR_NETWORK_GIVE_MONEY, lastof(temp));
- snprintf(message, sizeof(message), "*** %s %s", name, temp);
- }
- break;
- case NETWORK_ACTION_NAME_CHANGE:
- GetString(temp, STR_NETWORK_NAME_CHANGE, lastof(temp));
- snprintf(message, sizeof(message), "*** %s %s %s", name, temp, buf);
- break;
- case NETWORK_ACTION_CHAT_COMPANY:
- SetDParamStr(0, name);
- SetDParamStr(1, buf);
- GetString(temp, self_send ? STR_NETWORK_CHAT_TO_COMPANY : STR_NETWORK_CHAT_COMPANY, lastof(temp));
- strecpy(message, temp, lastof(message));
- break;
- case NETWORK_ACTION_CHAT_CLIENT:
- SetDParamStr(0, name);
- SetDParamStr(1, buf);
- GetString(temp, self_send ? STR_NETWORK_CHAT_TO_CLIENT : STR_NETWORK_CHAT_CLIENT, lastof(temp));
- strecpy(message, temp, lastof(message));
- break;
- default:
- SetDParamStr(0, name);
- SetDParamStr(1, buf);
- GetString(temp, STR_NETWORK_CHAT_ALL, lastof(temp));
- strecpy(message, temp, lastof(message));
+ data = STR_NETWORK_SERVER_MESSAGE_GAME_PAUSED_PLAYERS + data;
break;
+ case NETWORK_ACTION_JOIN: strid = STR_NETWORK_CLIENT_JOINED; break;
+ case NETWORK_ACTION_LEAVE: strid = STR_NETWORK_CLIENT_LEFT; break;
+ case NETWORK_ACTION_NAME_CHANGE: strid = STR_NETWORK_NAME_CHANGE; break;
+ case NETWORK_ACTION_GIVE_MONEY: strid = self_send ? STR_NETWORK_GAVE_MONEY_AWAY : STR_NETWORK_GIVE_MONEY; break;
+ case NETWORK_ACTION_CHAT_COMPANY: strid = self_send ? STR_NETWORK_CHAT_TO_COMPANY : STR_NETWORK_CHAT_COMPANY; break;
+ case NETWORK_ACTION_CHAT_CLIENT: strid = self_send ? STR_NETWORK_CHAT_TO_CLIENT : STR_NETWORK_CHAT_CLIENT; break;
+ default: strid = STR_NETWORK_CHAT_ALL; break;
}
+ char message[1024];
+ SetDParamStr(0, name);
+ SetDParamStr(1, str);
+ SetDParam(2, data);
+ GetString(message, strid, lastof(message));
+
DebugDumpCommands("ddc:cmsg:%d;%d;%s\n", _date, _date_fract, message);
IConsolePrintF(color, "%s", message);
NetworkAddChatMessage(color, duration, "%s", message);
@@ -320,11 +286,12 @@ static void NetworkClientError(NetworkRecvStatus res, NetworkClientSocket* cs)
_networking = false;
}
-/** Retrieve a string representation of an internal error number
- * @param buf buffer where the error message will be stored
+/**
+ * Retrieve the string id of an internal error number
* @param err NetworkErrorCode
- * @return returns a pointer to the error message (buf) */
-char* GetNetworkErrorMsg(char* buf, NetworkErrorCode err, const char* last)
+ * @return the StringID
+ */
+StringID GetNetworkErrorMsg(NetworkErrorCode err)
{
/* List of possible network errors, used by
* PACKET_SERVER_ERROR and PACKET_CLIENT_ERROR */
@@ -348,7 +315,7 @@ char* GetNetworkErrorMsg(char* buf, NetworkErrorCode err, const char* last)
if (err >= (ptrdiff_t)lengthof(network_error_strings)) err = NETWORK_ERROR_GENERAL;
- return GetString(buf, network_error_strings[err], last);
+ return err;
}
/* Count the number of active clients connected */
@@ -376,13 +343,13 @@ void CheckMinActiveClients()
_min_active_clients_paused = true;
DoCommandP(0, 1, 0, CMD_PAUSE);
- NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (not enough players)", CLIENT_ID_SERVER);
+ NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "", CLIENT_ID_SERVER, NETWORK_SERVER_MESSAGE_GAME_PAUSED_PLAYERS);
} else {
if (!_min_active_clients_paused) return;
_min_active_clients_paused = false;
DoCommandP(0, 0, 0, CMD_PAUSE);
- NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (enough players)", CLIENT_ID_SERVER);
+ NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "", CLIENT_ID_SERVER, NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_PLAYERS);
}
}
@@ -449,21 +416,17 @@ void NetworkCloseClient(NetworkClientSocket *cs)
if (!cs->has_quit && _network_server && cs->status > STATUS_INACTIVE) {
// We did not receive a leave message from this client...
- NetworkErrorCode errorno = NETWORK_ERROR_CONNECTION_LOST;
- char str[100];
char client_name[NETWORK_CLIENT_NAME_LENGTH];
NetworkClientSocket *new_cs;
NetworkGetClientName(client_name, sizeof(client_name), cs);
- GetNetworkErrorMsg(str, errorno, lastof(str));
-
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_ERR_CLIENT_CONNECTION_LOST);
// Inform other clients of this... strange leaving ;)
FOR_ALL_CLIENT_SOCKETS(new_cs) {
if (new_cs->status > STATUS_AUTH && cs != new_cs) {
- SEND_COMMAND(PACKET_SERVER_ERROR_QUIT)(new_cs, cs->client_id, errorno);
+ SEND_COMMAND(PACKET_SERVER_ERROR_QUIT)(new_cs, cs->client_id, NETWORK_ERROR_CONNECTION_LOST);
}
}
}
@@ -471,7 +434,7 @@ void NetworkCloseClient(NetworkClientSocket *cs)
/* When the client was PRE_ACTIVE, the server was in pause mode, so unpause */
if (cs->status == STATUS_PRE_ACTIVE && _settings_client.network.pause_on_join) {
DoCommandP(0, 0, 0, CMD_PAUSE);
- NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused", CLIENT_ID_SERVER);
+ NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "", CLIENT_ID_SERVER, NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_CONNECT_FAIL);
}
if (_network_server) {
@@ -635,11 +598,14 @@ static bool NetworkListen()
// Close all current connections
static void NetworkClose()
{
+ /* The pool is already empty, so we already closed the connections */
+ if (GetNetworkClientSocketPoolSize() == 0) return;
+
NetworkClientSocket *cs;
FOR_ALL_CLIENT_SOCKETS(cs) {
if (!_network_server) {
- SEND_COMMAND(PACKET_CLIENT_QUIT)("leaving");
+ SEND_COMMAND(PACKET_CLIENT_QUIT)();
cs->Send_Packets();
}
NetworkCloseClient(cs);
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index 43505cf75..56b86687e 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -257,7 +257,7 @@ static void SendChat(const char *buf, DestType type, int dest)
{
if (StrEmpty(buf)) return;
if (!_network_server) {
- SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf);
+ SEND_COMMAND(PACKET_CLIENT_CHAT)((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
} else {
NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
}
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index da0c1f421..401e12901 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -234,7 +234,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp)
}
// Send a chat-packet over the network
-DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType type, int dest, const char *msg)
+DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
{
//
// Packet: CLIENT_CHAT
@@ -244,6 +244,7 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType
// uint8: Destination Type (see network_data.h, DestType);
// uint32: Destination CompanyID/Client-identifier
// String: Message (max NETWORK_CHAT_LENGTH)
+ // uint64: Some arbitrary number
//
Packet *p = NetworkSend_Init(PACKET_CLIENT_CHAT);
@@ -252,6 +253,8 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType
p->Send_uint8 (type);
p->Send_uint32(dest);
p->Send_string(msg);
+ p->Send_uint64(data);
+
MY_CLIENT->Send_Packet(p);
}
@@ -299,17 +302,15 @@ DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name)
}
// Send an quit-packet over the network
-DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)(const char *leavemsg)
+DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)()
{
//
// Packet: CLIENT_QUIT
// Function: The client is quiting the game
// Data:
- // String: leave-message
//
Packet *p = NetworkSend_Init(PACKET_CLIENT_QUIT);
- p->Send_string(leavemsg);
MY_CLIENT->Send_Packet(p);
}
@@ -405,7 +406,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, CC_DEFAULT, false, ci->client_name, "%s", name);
+ NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, name);
} else if (playas != ci->client_playas) {
// The client changed from client-player..
// Do not display that for now
@@ -708,6 +709,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
ClientID client_id = (ClientID)p->Recv_uint32();
bool self_send = p->Recv_bool();
p->Recv_string(msg, NETWORK_CHAT_LENGTH);
+ int64 data = p->Recv_uint64();
ci_to = NetworkFindClientInfoFromClientID(client_id);
if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY;
@@ -742,21 +744,17 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
}
if (ci != NULL)
- NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), self_send, name, "%s", msg);
+ NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), self_send, name, msg, data);
return NETWORK_RECV_STATUS_OKAY;
}
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT)
{
- char str[100];
- NetworkClientInfo *ci;
-
ClientID client_id = (ClientID)p->Recv_uint32();
- GetNetworkErrorMsg(str, (NetworkErrorCode)p->Recv_uint8(), lastof(str));
- ci = NetworkFindClientInfoFromClientID(client_id);
+ NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
if (ci != NULL) {
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str);
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, NULL, GetNetworkErrorMsg((NetworkErrorCode)p->Recv_uint8()));
delete ci;
}
@@ -767,15 +765,13 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_ERROR_QUIT)
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_QUIT)
{
- char str[100];
NetworkClientInfo *ci;
ClientID client_id = (ClientID)p->Recv_uint32();
- p->Recv_string(str, lengthof(str));
ci = NetworkFindClientInfoFromClientID(client_id);
if (ci != NULL) {
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, "%s", str);
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, ci->client_name, NULL, STR_NETWORK_CLIENT_LEAVING);
delete ci;
} else {
DEBUG(net, 0, "Unknown client (%d) is leaving the game", client_id);
@@ -793,7 +789,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_JOIN)
NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(client_id);
if (ci != NULL)
- NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name, "");
+ NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, false, ci->client_name);
InvalidateWindow(WC_CLIENT_LIST, 0);
@@ -929,7 +925,7 @@ void NetworkUpdateClientName()
SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_settings_client.network.client_name);
} else {
if (NetworkFindName(_settings_client.network.client_name)) {
- NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _settings_client.network.client_name);
+ NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, _settings_client.network.client_name);
strecpy(ci->client_name, _settings_client.network.client_name, lastof(ci->client_name));
NetworkUpdateClientInfo(CLIENT_ID_SERVER);
}
@@ -937,9 +933,9 @@ void NetworkUpdateClientName()
}
}
-void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg)
+void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
{
- SEND_COMMAND(PACKET_CLIENT_CHAT)(action, type, dest, msg);
+ SEND_COMMAND(PACKET_CLIENT_CHAT)(action, type, dest, msg, data);
}
void NetworkClientSetPassword(const char *password)
diff --git a/src/network/network_client.h b/src/network/network_client.h
index f2f920728..b85ad9d5b 100644
--- a/src/network/network_client.h
+++ b/src/network/network_client.h
@@ -11,8 +11,8 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GAME_INFO);
DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_COMPANY_INFO);
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_COMMAND)(CommandPacket *cp);
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_ERROR)(NetworkErrorCode errorno);
-DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)(const char *leavemsg);
-DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType desttype, int dest, const char *msg);
+DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_QUIT)();
+DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_CHAT)(NetworkAction action, DestType desttype, int dest, const char *msg, int64 data);
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_PASSWORD)(NetworkPasswordType type, const char *password);
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_PASSWORD)(const char *password);
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_SET_NAME)(const char *name);
diff --git a/src/network/network_func.h b/src/network/network_func.h
index 32f0265a0..51249f8da 100644
--- a/src/network/network_func.h
+++ b/src/network/network_func.h
@@ -38,7 +38,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
void NetworkUpdateClientInfo(ClientID client_id);
bool NetworkClientConnectGame(const char *host, uint16 port);
void NetworkClientSendRcon(const char *password, const char *command);
-void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg);
+void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0);
void NetworkClientSetPassword(const char *password);
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
void NetworkPrintClients();
@@ -57,7 +57,7 @@ const char* GetClientIP(const NetworkClientInfo *ci);
void NetworkServerSendRcon(ClientID client_id, ConsoleColour colour_code, const char *string);
void NetworkServerSendError(ClientID client_id, NetworkErrorCode error);
-void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id);
+void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data = 0);
void NetworkInitChatMessage();
void CDECL NetworkAddChatMessage(uint16 color, uint8 duration, const char *message, ...);
diff --git a/src/network/network_internal.h b/src/network/network_internal.h
index 1434e47e0..229428a90 100644
--- a/src/network/network_internal.h
+++ b/src/network/network_internal.h
@@ -135,12 +135,12 @@ void NetworkAddCommandQueue(NetworkClientSocket *cs, CommandPacket *cp);
// from network.c
void NetworkCloseClient(NetworkClientSocket *cs);
-void CDECL NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str, ...);
+void NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str = "", int64 data = 0);
void NetworkGetClientName(char *clientname, size_t size, const NetworkClientSocket *cs);
uint NetworkCalculateLag(const NetworkClientSocket *cs);
byte NetworkGetCurrentLanguageIndex();
NetworkClientSocket *NetworkFindClientStateFromClientID(ClientID client_id);
-char* GetNetworkErrorMsg(char* buf, NetworkErrorCode err, const char* last);
+StringID GetNetworkErrorMsg(NetworkErrorCode err);
bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]);
// Macros to make life a bit more easier
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 3226da0bf..5f5d5692c 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -143,7 +143,8 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientSocket *cs, Netw
p->Send_uint8(error);
cs->Send_Packet(p);
- GetNetworkErrorMsg(str, error, lastof(str));
+ StringID strid = GetNetworkErrorMsg(error);
+ GetString(str, strid, lastof(str));
// Only send when the current client was in game
if (cs->status > STATUS_AUTH) {
@@ -154,7 +155,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientSocket *cs, Netw
DEBUG(net, 1, "'%s' made an error and has been disconnected. Reason: '%s'", client_name, str);
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, strid);
FOR_ALL_CLIENT_SOCKETS(new_cs) {
if (new_cs->status > STATUS_AUTH && new_cs != cs) {
@@ -497,15 +498,16 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkClientSocket *cs, Co
cs->Send_Packet(p);
}
-DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkClientSocket *cs, NetworkAction action, ClientID client_id, bool self_send, const char *msg)
+DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkClientSocket *cs, NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data)
{
//
// Packet: SERVER_CHAT
// Function: Sends a chat-packet to the client
// Data:
// uint8: ActionID (see network_data.h, NetworkAction)
- // uint32: Client-identifier
+ // uint32: Client-identifier
// String: Message (max NETWORK_CHAT_LENGTH)
+ // uint64: Arbitrary data
//
Packet *p = NetworkSend_Init(PACKET_SERVER_CHAT);
@@ -514,6 +516,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHAT)(NetworkClientSocket *cs, Netwo
p->Send_uint32(client_id);
p->Send_bool (self_send);
p->Send_string(msg);
+ p->Send_uint64(data);
cs->Send_Packet(p);
}
@@ -537,7 +540,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkClientSocket *cs,
cs->Send_Packet(p);
}
-DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(NetworkClientSocket *cs, ClientID client_id, const char *leavemsg)
+DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(NetworkClientSocket *cs, ClientID client_id)
{
//
// Packet: SERVER_ERROR_QUIT
@@ -545,13 +548,11 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_QUIT)(NetworkClientSocket *cs, Clien
// of that.
// Data:
// uint32: Client-identifier
- // String: leave-message
//
Packet *p = NetworkSend_Init(PACKET_SERVER_QUIT);
p->Send_uint32(client_id);
- p->Send_string(leavemsg);
cs->Send_Packet(p);
}
@@ -781,7 +782,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK)
NetworkGetClientName(client_name, sizeof(client_name), cs);
- NetworkTextMessage(NETWORK_ACTION_JOIN, CC_DEFAULT, 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
@@ -806,7 +807,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK)
/* Now pause the game till the client is in sync */
DoCommandP(0, 1, 0, CMD_PAUSE);
- NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game paused (incoming client)", CLIENT_ID_SERVER);
+ NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "", CLIENT_ID_SERVER, NETWORK_SERVER_MESSAGE_GAME_PAUSED_CONNECT);
}
} else {
// Wrong status for this packet, give a warning to client, and close connection
@@ -967,11 +968,12 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
NetworkGetClientName(client_name, sizeof(client_name), cs);
- GetNetworkErrorMsg(str, errorno, lastof(str));
+ StringID strid = GetNetworkErrorMsg(errorno);
+ GetString(str, strid, lastof(str));
DEBUG(net, 2, "'%s' reported an error and is closing its connection (%s)", client_name, str);
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, strid);
FOR_ALL_CLIENT_SOCKETS(new_cs) {
if (new_cs->status > STATUS_AUTH) {
@@ -987,7 +989,6 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
// The client wants to leave. Display this and report it to the other
// clients.
NetworkClientSocket *new_cs;
- char str[100];
char client_name[NETWORK_CLIENT_NAME_LENGTH];
// The client was never joined.. thank the client for the packet, but ignore it
@@ -996,15 +997,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
return;
}
- p->Recv_string(str, lengthof(str));
-
NetworkGetClientName(client_name, sizeof(client_name), cs);
- NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "%s", str);
+ NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_CLIENT_LEAVING);
FOR_ALL_CLIENT_SOCKETS(new_cs) {
if (new_cs->status > STATUS_AUTH) {
- SEND_COMMAND(PACKET_SERVER_QUIT)(new_cs, cs->client_id, str);
+ SEND_COMMAND(PACKET_SERVER_QUIT)(new_cs, cs->client_id);
}
}
@@ -1031,7 +1030,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK)
if (_settings_client.network.pause_on_join) {
DoCommandP(0, 0, 0, CMD_PAUSE);
- NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (client connected)", CLIENT_ID_SERVER);
+ NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "", CLIENT_ID_SERVER, NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_CONNECT);
}
CheckMinActiveClients();
@@ -1048,7 +1047,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK)
-void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id)
+void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id, int64 data)
{
NetworkClientSocket *cs;
const NetworkClientInfo *ci, *ci_own, *ci_to;
@@ -1060,12 +1059,12 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
ci = NetworkFindClientInfoFromClientID(from_id);
/* Display the text locally, and that is it */
if (ci != NULL)
- NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), false, ci->client_name, "%s", msg);
+ NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), false, ci->client_name, msg, data);
} else {
/* Else find the client to send the message to */
FOR_ALL_CLIENT_SOCKETS(cs) {
if (cs->client_id == (ClientID)dest) {
- SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_id, false, msg);
+ SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_id, false, msg, data);
break;
}
}
@@ -1077,11 +1076,11 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
ci = NetworkFindClientInfoFromClientID(from_id);
ci_to = NetworkFindClientInfoFromClientID((ClientID)dest);
if (ci != NULL && ci_to != NULL)
- NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), true, ci_to->client_name, "%s", msg);
+ NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), true, ci_to->client_name, msg, data);
} else {
FOR_ALL_CLIENT_SOCKETS(cs) {
if (cs->client_id == from_id) {
- SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, (ClientID)dest, true, msg);
+ SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, (ClientID)dest, true, msg, data);
break;
}
}
@@ -1096,7 +1095,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
FOR_ALL_CLIENT_SOCKETS(cs) {
ci = cs->GetInfo();
if (ci->client_playas == (CompanyID)dest) {
- SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_id, false, msg);
+ SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_id, false, msg, data);
if (cs->client_id == from_id) show_local = false;
ci_to = ci; // Remember a client that is in the company for company-name
}
@@ -1105,7 +1104,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
ci = NetworkFindClientInfoFromClientID(from_id);
ci_own = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
if (ci != NULL && ci_own != NULL && ci_own->client_playas == dest) {
- NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), false, ci->client_name, "%s", msg);
+ NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), false, ci->client_name, msg, data);
if (from_id == CLIENT_ID_SERVER) show_local = false;
ci_to = ci_own;
}
@@ -1120,11 +1119,11 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
StringID str = IsValidCompanyID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
SetDParam(0, ci_to->client_playas);
GetString(name, str, lastof(name));
- NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci_own->client_playas), true, name, "%s", msg);
+ NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci_own->client_playas), true, name, msg, data);
} else {
FOR_ALL_CLIENT_SOCKETS(cs) {
if (cs->client_id == from_id) {
- SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, ci_to->client_id, true, msg);
+ SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, ci_to->client_id, true, msg, data);
}
}
}
@@ -1136,11 +1135,11 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
/* fall-through to next case */
case DESTTYPE_BROADCAST:
FOR_ALL_CLIENT_SOCKETS(cs) {
- SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_id, false, msg);
+ SEND_COMMAND(PACKET_SERVER_CHAT)(cs, action, from_id, false, msg, data);
}
ci = NetworkFindClientInfoFromClientID(from_id);
if (ci != NULL)
- NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), false, ci->client_name, "%s", msg);
+ NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColor(ci->client_playas), false, ci->client_name, msg, data);
break;
}
}
@@ -1159,6 +1158,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
char msg[NETWORK_CHAT_LENGTH];
p->Recv_string(msg, NETWORK_CHAT_LENGTH);
+ int64 data = p->Recv_uint64();
const NetworkClientInfo *ci = cs->GetInfo();
switch (action) {
@@ -1168,7 +1168,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
case NETWORK_ACTION_CHAT:
case NETWORK_ACTION_CHAT_CLIENT:
case NETWORK_ACTION_CHAT_COMPANY:
- NetworkServerSendChat(action, desttype, dest, msg, cs->client_id);
+ NetworkServerSendChat(action, desttype, dest, msg, cs->client_id, data);
break;
default:
IConsolePrintF(CC_ERROR, "WARNING: invalid chat action from client %d (IP: %s).", ci->client_id, GetClientIP(ci));
@@ -1215,7 +1215,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME)
if (ci != NULL) {
// Display change
if (NetworkFindName(client_name)) {
- NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", client_name);
+ NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, client_name);
strecpy(ci->client_name, client_name, lastof(ci->client_name));
NetworkUpdateClientInfo(ci->client_id);
}
diff --git a/src/network/network_type.h b/src/network/network_type.h
index 2878819b5..a65e66386 100644
--- a/src/network/network_type.h
+++ b/src/network/network_type.h
@@ -81,6 +81,16 @@ enum NetworkAction {
NETWORK_ACTION_NAME_CHANGE,
};
+/** Messages the server can give */
+enum NetworkServerMessage {
+ NETWORK_SERVER_MESSAGE_GAME_PAUSED_PLAYERS, ///< Game paused (not enough players)
+ NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_PLAYERS, ///< Game unpaused (enough players)
+ NETWORK_SERVER_MESSAGE_GAME_PAUSED_CONNECT, ///< Game paused (connecting client)
+ NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_CONNECT, ///< Game unpaused (client connected)
+ NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_CONNECT_FAIL, ///< Game unpaused (client failed to connect)
+ NETWORK_SERVER_MESSAGE_END
+};
+
enum NetworkErrorCode {
NETWORK_ERROR_GENERAL, // Try to use this one like never