Change chat arbitrary data field from an int64 to a struct.
This commit is contained in:
@@ -230,7 +230,7 @@ bool NetworkCompanyIsPassworded(CompanyID company_id)
|
|||||||
/* This puts a text-message to the console, or in the future, the chat-box,
|
/* This puts a text-message to the console, or in the future, the chat-box,
|
||||||
* (to keep it all a bit more general)
|
* (to keep it all a bit more general)
|
||||||
* If 'self_send' is true, this is the client who is sending the message */
|
* If 'self_send' is true, this is the client who is sending the message */
|
||||||
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str, int64 data)
|
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str, NetworkTextMessageData data)
|
||||||
{
|
{
|
||||||
StringID strid;
|
StringID strid;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
@@ -266,7 +266,7 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
|
|||||||
char message[1024];
|
char message[1024];
|
||||||
SetDParamStr(0, name);
|
SetDParamStr(0, name);
|
||||||
SetDParamStr(1, str);
|
SetDParamStr(1, str);
|
||||||
SetDParam(2, data);
|
SetDParam(2, data.data);
|
||||||
|
|
||||||
/* All of these strings start with "***". These characters are interpreted as both left-to-right and
|
/* All of these strings start with "***". These characters are interpreted as both left-to-right and
|
||||||
* right-to-left characters depending on the context. As the next text might be an user's name, the
|
* right-to-left characters depending on the context. As the next text might be an user's name, the
|
||||||
|
@@ -473,7 +473,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
|
|||||||
* @param msg The actual message.
|
* @param msg The actual message.
|
||||||
* @param data Arbitrary extra data.
|
* @param data Arbitrary extra data.
|
||||||
*/
|
*/
|
||||||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data)
|
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, NetworkTextMessageData data)
|
||||||
{
|
{
|
||||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_CHAT);
|
Packet *p = new Packet(ADMIN_PACKET_SERVER_CHAT);
|
||||||
|
|
||||||
@@ -481,7 +481,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action
|
|||||||
p->Send_uint8 (desttype);
|
p->Send_uint8 (desttype);
|
||||||
p->Send_uint32(client_id);
|
p->Send_uint32(client_id);
|
||||||
p->Send_string(msg);
|
p->Send_string(msg);
|
||||||
p->Send_uint64(data);
|
data.send(p);
|
||||||
|
|
||||||
this->SendPacket(p);
|
this->SendPacket(p);
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
@@ -935,7 +935,7 @@ void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bc
|
|||||||
/**
|
/**
|
||||||
* Send chat to the admin network (if they did opt in for the respective update).
|
* Send chat to the admin network (if they did opt in for the respective update).
|
||||||
*/
|
*/
|
||||||
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data, bool from_admin)
|
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, NetworkTextMessageData data, bool from_admin)
|
||||||
{
|
{
|
||||||
if (from_admin) return;
|
if (from_admin) return;
|
||||||
|
|
||||||
|
@@ -65,7 +65,7 @@ public:
|
|||||||
NetworkRecvStatus SendCompanyEconomy();
|
NetworkRecvStatus SendCompanyEconomy();
|
||||||
NetworkRecvStatus SendCompanyStats();
|
NetworkRecvStatus SendCompanyStats();
|
||||||
|
|
||||||
NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data);
|
NetworkRecvStatus SendChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, NetworkTextMessageData data);
|
||||||
NetworkRecvStatus SendRcon(uint16 colour, const char *command);
|
NetworkRecvStatus SendRcon(uint16 colour, const char *command);
|
||||||
NetworkRecvStatus SendConsole(const char *origin, const char *command);
|
NetworkRecvStatus SendConsole(const char *origin, const char *command);
|
||||||
NetworkRecvStatus SendGameScript(const char *json);
|
NetworkRecvStatus SendGameScript(const char *json);
|
||||||
@@ -117,7 +117,7 @@ void NetworkAdminCompanyInfo(const Company *company, bool new_company);
|
|||||||
void NetworkAdminCompanyUpdate(const Company *company);
|
void NetworkAdminCompanyUpdate(const Company *company);
|
||||||
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
|
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr);
|
||||||
|
|
||||||
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, int64 data = 0, bool from_admin = false);
|
void NetworkAdminChat(NetworkAction action, DestType desttype, ClientID client_id, const char *msg, NetworkTextMessageData data = NetworkTextMessageData(), bool from_admin = false);
|
||||||
void NetworkAdminUpdate(AdminUpdateFrequency freq);
|
void NetworkAdminUpdate(AdminUpdateFrequency freq);
|
||||||
void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string);
|
void NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, const char *string);
|
||||||
void NetworkAdminConsole(const char *origin, const char *string);
|
void NetworkAdminConsole(const char *origin, const char *string);
|
||||||
|
@@ -273,7 +273,7 @@ static void SendChat(const char *buf, DestType type, int dest)
|
|||||||
{
|
{
|
||||||
if (StrEmpty(buf)) return;
|
if (StrEmpty(buf)) return;
|
||||||
if (!_network_server) {
|
if (!_network_server) {
|
||||||
MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, 0);
|
MyClient::SendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, NetworkTextMessageData());
|
||||||
} else {
|
} else {
|
||||||
NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
|
NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
|
||||||
}
|
}
|
||||||
|
@@ -416,7 +416,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendCommand(const CommandPacke
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Send a chat-packet over the network */
|
/** Send a chat-packet over the network */
|
||||||
NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
|
NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action, DestType type, int dest, const char *msg, NetworkTextMessageData data)
|
||||||
{
|
{
|
||||||
Packet *p = new Packet(PACKET_CLIENT_CHAT);
|
Packet *p = new Packet(PACKET_CLIENT_CHAT);
|
||||||
|
|
||||||
@@ -424,7 +424,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action,
|
|||||||
p->Send_uint8 (type);
|
p->Send_uint8 (type);
|
||||||
p->Send_uint32(dest);
|
p->Send_uint32(dest);
|
||||||
p->Send_string(msg);
|
p->Send_string(msg);
|
||||||
p->Send_uint64(data);
|
data.send(p);
|
||||||
|
|
||||||
my_client->SendPacket(p);
|
my_client->SendPacket(p);
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
@@ -948,7 +948,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
|
|||||||
ClientID client_id = (ClientID)p->Recv_uint32();
|
ClientID client_id = (ClientID)p->Recv_uint32();
|
||||||
bool self_send = p->Recv_bool();
|
bool self_send = p->Recv_bool();
|
||||||
p->Recv_string(msg, NETWORK_CHAT_LENGTH);
|
p->Recv_string(msg, NETWORK_CHAT_LENGTH);
|
||||||
int64 data = p->Recv_uint64();
|
NetworkTextMessageData data;
|
||||||
|
data.recv(p);
|
||||||
|
|
||||||
ci_to = NetworkClientInfo::GetByClientID(client_id);
|
ci_to = NetworkClientInfo::GetByClientID(client_id);
|
||||||
if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY;
|
if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY;
|
||||||
@@ -1248,7 +1249,7 @@ void NetworkUpdateClientName()
|
|||||||
* @param msg The actual message.
|
* @param msg The actual message.
|
||||||
* @param data Arbitrary extra data.
|
* @param data Arbitrary extra data.
|
||||||
*/
|
*/
|
||||||
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data)
|
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, NetworkTextMessageData data)
|
||||||
{
|
{
|
||||||
MyClient::SendChat(action, type, dest, msg, data);
|
MyClient::SendChat(action, type, dest, msg, data);
|
||||||
}
|
}
|
||||||
|
@@ -94,7 +94,7 @@ public:
|
|||||||
static NetworkRecvStatus SendGamePassword(const char *password);
|
static NetworkRecvStatus SendGamePassword(const char *password);
|
||||||
static NetworkRecvStatus SendCompanyPassword(const char *password);
|
static NetworkRecvStatus SendCompanyPassword(const char *password);
|
||||||
|
|
||||||
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data);
|
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, NetworkTextMessageData data);
|
||||||
static NetworkRecvStatus SendSetPassword(const char *password);
|
static NetworkRecvStatus SendSetPassword(const char *password);
|
||||||
static NetworkRecvStatus SendSetName(const char *name);
|
static NetworkRecvStatus SendSetName(const char *name);
|
||||||
static NetworkRecvStatus SendRCon(const char *password, const char *command);
|
static NetworkRecvStatus SendRCon(const char *password, const char *command);
|
||||||
|
@@ -56,7 +56,7 @@ void NetworkClientsToSpectators(CompanyID cid);
|
|||||||
void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const char *join_server_password = NULL, const char *join_company_password = NULL);
|
void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const char *join_server_password = NULL, const char *join_company_password = NULL);
|
||||||
void NetworkClientRequestMove(CompanyID company, const char *pass = "");
|
void NetworkClientRequestMove(CompanyID company, const char *pass = "");
|
||||||
void NetworkClientSendRcon(const char *password, const char *command);
|
void NetworkClientSendRcon(const char *password, const char *command);
|
||||||
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data = 0);
|
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const char *msg, NetworkTextMessageData data = NetworkTextMessageData());
|
||||||
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
|
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
|
||||||
bool NetworkCompanyIsPassworded(CompanyID company_id);
|
bool NetworkCompanyIsPassworded(CompanyID company_id);
|
||||||
bool NetworkMaxCompaniesReached();
|
bool NetworkMaxCompaniesReached();
|
||||||
@@ -77,7 +77,7 @@ bool NetworkServerChangeClientName(ClientID client_id, const char *new_name);
|
|||||||
|
|
||||||
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
|
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
|
||||||
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string);
|
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string);
|
||||||
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data = 0, bool from_admin = false);
|
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, NetworkTextMessageData data = NetworkTextMessageData(), bool from_admin = false);
|
||||||
|
|
||||||
void NetworkServerKickClient(ClientID client_id);
|
void NetworkServerKickClient(ClientID client_id);
|
||||||
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban);
|
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban);
|
||||||
|
@@ -165,7 +165,7 @@ void NetworkFreeLocalCommandQueue();
|
|||||||
void NetworkSyncCommandQueue(NetworkClientSocket *cs);
|
void NetworkSyncCommandQueue(NetworkClientSocket *cs);
|
||||||
|
|
||||||
void NetworkError(StringID error_string);
|
void NetworkError(StringID error_string);
|
||||||
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str = "", int64 data = 0);
|
void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str = "", NetworkTextMessageData data = NetworkTextMessageData());
|
||||||
uint NetworkCalculateLag(const NetworkClientSocket *cs);
|
uint NetworkCalculateLag(const NetworkClientSocket *cs);
|
||||||
StringID GetNetworkErrorMsg(NetworkErrorCode err);
|
StringID GetNetworkErrorMsg(NetworkErrorCode err);
|
||||||
bool NetworkFindName(char *new_name, const char *last);
|
bool NetworkFindName(char *new_name, const char *last);
|
||||||
|
@@ -748,7 +748,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand(const CommandPacke
|
|||||||
* @param msg The actual message.
|
* @param msg The actual message.
|
||||||
* @param data Arbitrary extra data.
|
* @param data Arbitrary extra data.
|
||||||
*/
|
*/
|
||||||
NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data)
|
NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action, ClientID client_id, bool self_send, const char *msg, NetworkTextMessageData data)
|
||||||
{
|
{
|
||||||
if (this->status < STATUS_PRE_ACTIVE) return NETWORK_RECV_STATUS_OKAY;
|
if (this->status < STATUS_PRE_ACTIVE) return NETWORK_RECV_STATUS_OKAY;
|
||||||
|
|
||||||
@@ -758,7 +758,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action,
|
|||||||
p->Send_uint32(client_id);
|
p->Send_uint32(client_id);
|
||||||
p->Send_bool (self_send);
|
p->Send_bool (self_send);
|
||||||
p->Send_string(msg);
|
p->Send_string(msg);
|
||||||
p->Send_uint64(data);
|
data.send(p);
|
||||||
|
|
||||||
this->SendPacket(p);
|
this->SendPacket(p);
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
@@ -1265,7 +1265,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(Packet *p)
|
|||||||
* @param data Arbitrary data.
|
* @param data Arbitrary data.
|
||||||
* @param from_admin Whether the origin is an admin or not.
|
* @param from_admin Whether the origin is an admin or not.
|
||||||
*/
|
*/
|
||||||
void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id, int64 data, bool from_admin)
|
void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, const char *msg, ClientID from_id, NetworkTextMessageData data, bool from_admin)
|
||||||
{
|
{
|
||||||
NetworkClientSocket *cs;
|
NetworkClientSocket *cs;
|
||||||
const NetworkClientInfo *ci, *ci_own, *ci_to;
|
const NetworkClientInfo *ci, *ci_own, *ci_to;
|
||||||
@@ -1392,7 +1392,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *p)
|
|||||||
char msg[NETWORK_CHAT_LENGTH];
|
char msg[NETWORK_CHAT_LENGTH];
|
||||||
|
|
||||||
p->Recv_string(msg, NETWORK_CHAT_LENGTH);
|
p->Recv_string(msg, NETWORK_CHAT_LENGTH);
|
||||||
int64 data = p->Recv_uint64();
|
NetworkTextMessageData data;
|
||||||
|
data.recv(p);
|
||||||
|
|
||||||
NetworkClientInfo *ci = this->GetInfo();
|
NetworkClientInfo *ci = this->GetInfo();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
@@ -95,7 +95,7 @@ public:
|
|||||||
|
|
||||||
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci);
|
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci);
|
||||||
NetworkRecvStatus SendError(NetworkErrorCode error);
|
NetworkRecvStatus SendError(NetworkErrorCode error);
|
||||||
NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data);
|
NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, const char *msg, NetworkTextMessageData data);
|
||||||
NetworkRecvStatus SendJoin(ClientID client_id);
|
NetworkRecvStatus SendJoin(ClientID client_id);
|
||||||
NetworkRecvStatus SendFrame();
|
NetworkRecvStatus SendFrame();
|
||||||
NetworkRecvStatus SendSync();
|
NetworkRecvStatus SendSync();
|
||||||
|
@@ -131,5 +131,20 @@ enum NetworkErrorCode {
|
|||||||
NETWORK_ERROR_END,
|
NETWORK_ERROR_END,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NetworkTextMessageData {
|
||||||
|
int64 data;
|
||||||
|
|
||||||
|
NetworkTextMessageData(int64 data = 0)
|
||||||
|
: data(data) { }
|
||||||
|
|
||||||
|
template <typename T> void recv(T *p) {
|
||||||
|
this->data = p->Recv_uint64();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> void send(T *p) const {
|
||||||
|
p->Send_uint64(this->data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
#endif /* NETWORK_TYPE_H */
|
#endif /* NETWORK_TYPE_H */
|
||||||
|
Reference in New Issue
Block a user