Merge branch 'send_money_company' into jgrpp
This commit is contained in:
@@ -230,8 +230,9 @@ bool NetworkCompanyIsPassworded(CompanyID company_id)
|
||||
/* 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 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)
|
||||
{
|
||||
char message_src[256];
|
||||
StringID strid;
|
||||
switch (action) {
|
||||
case NETWORK_ACTION_SERVER_MESSAGE:
|
||||
@@ -257,7 +258,22 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
|
||||
break;
|
||||
case NETWORK_ACTION_LEAVE: strid = STR_NETWORK_MESSAGE_CLIENT_LEFT; break;
|
||||
case NETWORK_ACTION_NAME_CHANGE: strid = STR_NETWORK_MESSAGE_NAME_CHANGE; break;
|
||||
case NETWORK_ACTION_GIVE_MONEY: strid = self_send ? STR_NETWORK_MESSAGE_GAVE_MONEY_AWAY : STR_NETWORK_MESSAGE_GIVE_MONEY; break;
|
||||
|
||||
case NETWORK_ACTION_GIVE_MONEY:
|
||||
SetDParamStr(0, name);
|
||||
SetDParam(1, data.auxdata >> 16);
|
||||
GetString(message_src, STR_NETWORK_MESSAGE_MONEY_GIVE_SRC_DESCRIPTION, lastof(message_src));
|
||||
name = message_src;
|
||||
if (self_send) {
|
||||
strid = STR_NETWORK_MESSAGE_GAVE_MONEY_AWAY;
|
||||
} else if ((CompanyID) (data.auxdata & 0xFFFF) == _local_company) {
|
||||
strid = STR_NETWORK_MESSAGE_GIVE_MONEY;
|
||||
} else {
|
||||
strid = STR_NETWORK_MESSAGE_MONEY_GIVEN;
|
||||
SetDParam(3, data.auxdata & 0xFFFF);
|
||||
}
|
||||
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;
|
||||
@@ -266,7 +282,7 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
|
||||
char message[1024];
|
||||
SetDParamStr(0, name);
|
||||
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
|
||||
* 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 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);
|
||||
|
||||
@@ -481,7 +481,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendChat(NetworkAction action
|
||||
p->Send_uint8 (desttype);
|
||||
p->Send_uint32(client_id);
|
||||
p->Send_string(msg);
|
||||
p->Send_uint64(data);
|
||||
data.send(p);
|
||||
|
||||
this->SendPacket(p);
|
||||
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).
|
||||
*/
|
||||
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;
|
||||
|
||||
|
@@ -65,7 +65,7 @@ public:
|
||||
NetworkRecvStatus SendCompanyEconomy();
|
||||
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 SendConsole(const char *origin, const char *command);
|
||||
NetworkRecvStatus SendGameScript(const char *json);
|
||||
@@ -117,7 +117,7 @@ void NetworkAdminCompanyInfo(const Company *company, bool new_company);
|
||||
void NetworkAdminCompanyUpdate(const Company *company);
|
||||
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 NetworkServerSendAdminRcon(AdminIndex admin_index, TextColour colour_code, 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 (!_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 {
|
||||
NetworkServerSendChat((NetworkAction)(NETWORK_ACTION_CHAT + type), type, dest, buf, CLIENT_ID_SERVER);
|
||||
}
|
||||
|
@@ -421,7 +421,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendCommand(const CommandPacke
|
||||
}
|
||||
|
||||
/** 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);
|
||||
|
||||
@@ -429,7 +429,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendChat(NetworkAction action,
|
||||
p->Send_uint8 (type);
|
||||
p->Send_uint32(dest);
|
||||
p->Send_string(msg);
|
||||
p->Send_uint64(data);
|
||||
data.send(p);
|
||||
|
||||
my_client->SendPacket(p);
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
@@ -953,7 +953,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
|
||||
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();
|
||||
NetworkTextMessageData data;
|
||||
data.recv(p);
|
||||
|
||||
ci_to = NetworkClientInfo::GetByClientID(client_id);
|
||||
if (ci_to == NULL) return NETWORK_RECV_STATUS_OKAY;
|
||||
@@ -1253,7 +1254,7 @@ void NetworkUpdateClientName()
|
||||
* @param msg The actual message.
|
||||
* @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);
|
||||
}
|
||||
|
@@ -94,7 +94,7 @@ public:
|
||||
static NetworkRecvStatus SendGamePassword(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 SendSetName(const char *name);
|
||||
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 NetworkClientRequestMove(CompanyID company, const char *pass = "");
|
||||
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 NetworkCompanyIsPassworded(CompanyID company_id);
|
||||
bool NetworkMaxCompaniesReached();
|
||||
@@ -77,7 +77,7 @@ bool NetworkServerChangeClientName(ClientID client_id, const char *new_name);
|
||||
|
||||
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
|
||||
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);
|
||||
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban);
|
||||
|
@@ -1664,8 +1664,7 @@ NetworkCompanyInfo *GetLobbyCompanyInfo(CompanyID company)
|
||||
}
|
||||
|
||||
/* The window below gives information about the connected clients
|
||||
* and also makes able to give money to them, kick them (if server)
|
||||
* and stuff like that. */
|
||||
* and also makes able to kick them (if server) and stuff like that. */
|
||||
|
||||
extern void DrawCompanyIcon(CompanyID cid, int x, int y);
|
||||
|
||||
@@ -1697,11 +1696,6 @@ static void ClientList_Ban(const NetworkClientInfo *ci)
|
||||
NetworkServerKickOrBanIP(ci->client_id, true);
|
||||
}
|
||||
|
||||
static void ClientList_GiveMoney(const NetworkClientInfo *ci)
|
||||
{
|
||||
ShowNetworkGiveMoneyWindow(ci->client_playas);
|
||||
}
|
||||
|
||||
static void ClientList_SpeakToClient(const NetworkClientInfo *ci)
|
||||
{
|
||||
ShowNetworkChatQueryWindow(DESTTYPE_CLIENT, ci->client_id);
|
||||
@@ -1760,13 +1754,6 @@ struct NetworkClientListPopupWindow : Window {
|
||||
}
|
||||
this->AddAction(STR_NETWORK_CLIENTLIST_SPEAK_TO_ALL, &ClientList_SpeakToAll);
|
||||
|
||||
if (_network_own_client_id != ci->client_id) {
|
||||
/* We are no spectator and the company we want to give money to is no spectator and money gifts are allowed. */
|
||||
if (Company::IsValidID(_local_company) && Company::IsValidID(ci->client_playas) && _settings_game.economy.give_money) {
|
||||
this->AddAction(STR_NETWORK_CLIENTLIST_GIVE_MONEY, &ClientList_GiveMoney);
|
||||
}
|
||||
}
|
||||
|
||||
/* A server can kick clients (but not himself). */
|
||||
if (_network_server && _network_own_client_id != ci->client_id) {
|
||||
this->AddAction(STR_NETWORK_CLIENTLIST_KICK, &ClientList_Kick);
|
||||
|
@@ -165,7 +165,7 @@ void NetworkFreeLocalCommandQueue();
|
||||
void NetworkSyncCommandQueue(NetworkClientSocket *cs);
|
||||
|
||||
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);
|
||||
StringID GetNetworkErrorMsg(NetworkErrorCode err);
|
||||
bool NetworkFindName(char *new_name, const char *last);
|
||||
|
@@ -748,7 +748,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand(const CommandPacke
|
||||
* @param msg The actual message.
|
||||
* @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;
|
||||
|
||||
@@ -758,7 +758,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat(NetworkAction action,
|
||||
p->Send_uint32(client_id);
|
||||
p->Send_bool (self_send);
|
||||
p->Send_string(msg);
|
||||
p->Send_uint64(data);
|
||||
data.send(p);
|
||||
|
||||
this->SendPacket(p);
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
@@ -1270,7 +1270,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(Packet *p)
|
||||
* @param data Arbitrary data.
|
||||
* @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;
|
||||
const NetworkClientInfo *ci, *ci_own, *ci_to;
|
||||
@@ -1368,15 +1368,17 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
||||
DEBUG(net, 0, "[server] received unknown chat destination type %d. Doing broadcast instead", desttype);
|
||||
/* FALL THROUGH */
|
||||
case DESTTYPE_BROADCAST:
|
||||
case DESTTYPE_BROADCAST_SS:
|
||||
FOR_ALL_CLIENT_SOCKETS(cs) {
|
||||
cs->SendChat(action, from_id, false, msg, data);
|
||||
cs->SendChat(action, from_id, (desttype == DESTTYPE_BROADCAST_SS && from_id == cs->client_id), msg, data);
|
||||
}
|
||||
|
||||
NetworkAdminChat(action, desttype, from_id, msg, data, from_admin);
|
||||
|
||||
ci = NetworkClientInfo::GetByClientID(from_id);
|
||||
if (ci != NULL) {
|
||||
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas), false, ci->client_name, msg, data);
|
||||
NetworkTextMessage(action, GetDrawStringCompanyColour(ci->client_playas),
|
||||
(desttype == DESTTYPE_BROADCAST_SS && from_id == CLIENT_ID_SERVER), ci->client_name, msg, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1395,7 +1397,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(Packet *p)
|
||||
char 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();
|
||||
switch (action) {
|
||||
|
@@ -95,7 +95,7 @@ public:
|
||||
|
||||
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci);
|
||||
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 SendFrame();
|
||||
NetworkRecvStatus SendSync();
|
||||
|
@@ -81,6 +81,7 @@ enum NetworkPasswordType {
|
||||
/** Destination of our chat messages. */
|
||||
enum DestType {
|
||||
DESTTYPE_BROADCAST, ///< Send message/notice to all clients (All)
|
||||
DESTTYPE_BROADCAST_SS, ///< Send message/notice to all clients (All), but tag the broadcast to self as a self-send
|
||||
DESTTYPE_TEAM, ///< Send message/notice to everyone playing the same company (Team)
|
||||
DESTTYPE_CLIENT, ///< Send message/notice to only a certain client (Private)
|
||||
};
|
||||
@@ -130,5 +131,23 @@ enum NetworkErrorCode {
|
||||
NETWORK_ERROR_END,
|
||||
};
|
||||
|
||||
struct NetworkTextMessageData {
|
||||
int64 data;
|
||||
int64 auxdata;
|
||||
|
||||
NetworkTextMessageData(int64 data = 0, int64 auxdata = 0)
|
||||
: data(data), auxdata(auxdata) { }
|
||||
|
||||
template <typename T> void recv(T *p) {
|
||||
this->data = p->Recv_uint64();
|
||||
this->auxdata = p->Recv_uint64();
|
||||
}
|
||||
|
||||
template <typename T> void send(T *p) const {
|
||||
p->Send_uint64(this->data);
|
||||
p->Send_uint64(this->auxdata);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
#endif /* NETWORK_TYPE_H */
|
||||
|
Reference in New Issue
Block a user