Merge branch 'master' into jgrpp-beta
# Conflicts: # src/cargopacket.h # src/lang/korean.txt # src/linkgraph/linkgraph.h # src/linkgraph/linkgraphjob.h # src/linkgraph/linkgraphschedule.h # src/network/network_admin.h # src/network/network_func.h # src/network/network_server.cpp # src/network/network_server.h # src/order_base.h # src/rail_cmd.cpp # src/saveload/company_sl.cpp # src/saveload/depot_sl.cpp # src/saveload/economy_sl.cpp # src/saveload/linkgraph_sl.cpp # src/saveload/map_sl.cpp # src/saveload/newgrf_sl.cpp # src/saveload/order_sl.cpp # src/saveload/saveload.cpp # src/saveload/saveload.h # src/saveload/signs_sl.cpp # src/saveload/station_sl.cpp # src/saveload/subsidy_sl.cpp # src/saveload/town_sl.cpp # src/saveload/vehicle_sl.cpp # src/script/api/script_object.cpp # src/settings.cpp # src/string.cpp # src/string_func.h # src/table/CMakeLists.txt # src/table/settings/settings.ini # src/viewport_sprite_sorter_sse4.cpp
This commit is contained in:
@@ -443,12 +443,12 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo()
|
||||
* @param error The error to disconnect for.
|
||||
* @param reason In case of kicking a client, specifies the reason for kicking the client.
|
||||
*/
|
||||
NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode error, const char *reason)
|
||||
NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode error, const std::string &reason)
|
||||
{
|
||||
Packet *p = new Packet(PACKET_SERVER_ERROR, SHRT_MAX);
|
||||
|
||||
p->Send_uint8(error);
|
||||
if (reason != nullptr) p->Send_string(reason);
|
||||
if (!reason.empty()) p->Send_string(reason);
|
||||
this->SendPacket(p);
|
||||
|
||||
StringID strid = GetNetworkErrorMsg(error);
|
||||
@@ -461,7 +461,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode err
|
||||
|
||||
DEBUG(net, 1, "'%s' made an error and has been disconnected: %s", client_name, GetString(strid).c_str());
|
||||
|
||||
if (error == NETWORK_ERROR_KICKED && reason != nullptr) {
|
||||
if (error == NETWORK_ERROR_KICKED && !reason.empty()) {
|
||||
NetworkTextMessage(NETWORK_ACTION_KICKED, CC_DEFAULT, false, client_name, reason, strid);
|
||||
} else {
|
||||
NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, "", strid);
|
||||
@@ -823,7 +823,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame()
|
||||
* @param colour The colour of the result.
|
||||
* @param command The command that was executed.
|
||||
*/
|
||||
NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult(uint16 colour, const char *command)
|
||||
NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult(uint16 colour, const std::string &command)
|
||||
{
|
||||
Packet *p = new Packet(PACKET_SERVER_RCON, SHRT_MAX);
|
||||
|
||||
@@ -928,8 +928,6 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
|
||||
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||
}
|
||||
|
||||
char name[NETWORK_CLIENT_NAME_LENGTH];
|
||||
CompanyID playas;
|
||||
char client_revision[NETWORK_REVISION_LENGTH];
|
||||
|
||||
p->Recv_string(client_revision, sizeof(client_revision));
|
||||
@@ -941,8 +939,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
|
||||
return this->SendError(NETWORK_ERROR_WRONG_REVISION);
|
||||
}
|
||||
|
||||
p->Recv_string(name, sizeof(name));
|
||||
playas = (Owner)p->Recv_uint8();
|
||||
std::string client_name = p->Recv_string(NETWORK_CLIENT_NAME_LENGTH);
|
||||
CompanyID playas = (Owner)p->Recv_uint8();
|
||||
|
||||
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CLIENT_QUIT;
|
||||
|
||||
@@ -965,14 +963,14 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!NetworkIsValidClientName(name)) {
|
||||
if (!NetworkIsValidClientName(client_name)) {
|
||||
/* An invalid client name was given. However, the client ensures the name
|
||||
* is valid before it is sent over the network, so something went horribly
|
||||
* wrong. This is probably someone trying to troll us. */
|
||||
return this->SendError(NETWORK_ERROR_INVALID_CLIENT_NAME);
|
||||
}
|
||||
|
||||
if (!NetworkFindName(name, lastof(name))) { // Change name if duplicate
|
||||
if (!NetworkMakeClientNameUnique(client_name)) { // Change name if duplicate
|
||||
/* We could not create a name for this client */
|
||||
return this->SendError(NETWORK_ERROR_NAME_IN_USE);
|
||||
}
|
||||
@@ -981,7 +979,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
|
||||
NetworkClientInfo *ci = new NetworkClientInfo(this->client_id);
|
||||
this->SetInfo(ci);
|
||||
ci->join_date = _date;
|
||||
ci->client_name = name;
|
||||
ci->client_name = client_name;
|
||||
ci->client_playas = playas;
|
||||
DEBUG(desync, 1, "client: date{%08x; %02x; %02x}; client: %02x; company: %02x", _date, _date_fract, _tick_skip_counter, (int)ci->index, (int)ci->client_playas);
|
||||
|
||||
@@ -1528,10 +1526,9 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet
|
||||
return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||
}
|
||||
|
||||
char client_name[NETWORK_CLIENT_NAME_LENGTH];
|
||||
NetworkClientInfo *ci;
|
||||
|
||||
p->Recv_string(client_name, sizeof(client_name));
|
||||
std::string client_name = p->Recv_string(NETWORK_CLIENT_NAME_LENGTH);
|
||||
ci = this->GetInfo();
|
||||
|
||||
if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CLIENT_QUIT;
|
||||
@@ -1545,7 +1542,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(Packet
|
||||
}
|
||||
|
||||
/* Display change */
|
||||
if (NetworkFindName(client_name, lastof(client_name))) {
|
||||
if (NetworkMakeClientNameUnique(client_name)) {
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, client_name);
|
||||
ci->client_name = client_name;
|
||||
NetworkUpdateClientInfo(ci->client_id);
|
||||
@@ -1558,15 +1555,13 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
|
||||
{
|
||||
if (this->status != STATUS_ACTIVE) return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
|
||||
|
||||
char command[NETWORK_RCONCOMMAND_LENGTH];
|
||||
|
||||
if (_settings_client.network.rcon_password.empty()) {
|
||||
NetworkServerSendRcon(this->client_id, CC_ERROR, "Access Denied");
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
std::string password = p->Recv_string(NETWORK_PASSWORD_LENGTH);
|
||||
p->Recv_string(command, sizeof(command));
|
||||
std::string command = p->Recv_string(NETWORK_RCONCOMMAND_LENGTH);
|
||||
|
||||
if (password != GenerateCompanyPasswordHash(_settings_client.network.rcon_password.c_str(), _settings_client.network.network_id.c_str(), _settings_game.game_creation.generation_seed ^ this->rcon_hash_bits)) {
|
||||
DEBUG(net, 0, "[rcon] wrong password from client-id %d", this->client_id);
|
||||
@@ -1574,10 +1569,10 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(Packet *p)
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
DEBUG(net, 3, "[rcon] Client-id %d executed: %s", this->client_id, command);
|
||||
DEBUG(net, 3, "[rcon] Client-id %d executed: %s", this->client_id, command.c_str());
|
||||
|
||||
_redirect_console_to_client = this->client_id;
|
||||
IConsoleCmdExec(command);
|
||||
IConsoleCmdExec(command.c_str());
|
||||
_redirect_console_to_client = INVALID_CLIENT_ID;
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
@@ -1837,42 +1832,40 @@ static void NetworkAutoCleanCompanies()
|
||||
/**
|
||||
* Check whether a name is unique, and otherwise try to make it unique.
|
||||
* @param new_name The name to check/modify.
|
||||
* @param last The last writeable element of the buffer.
|
||||
* @return True if an unique name was achieved.
|
||||
*/
|
||||
bool NetworkFindName(char *new_name, const char *last)
|
||||
bool NetworkMakeClientNameUnique(std::string &name)
|
||||
{
|
||||
bool found_name = false;
|
||||
bool is_name_unique = false;
|
||||
uint number = 0;
|
||||
char original_name[NETWORK_CLIENT_NAME_LENGTH];
|
||||
std::string original_name = name;
|
||||
|
||||
strecpy(original_name, new_name, lastof(original_name));
|
||||
|
||||
while (!found_name) {
|
||||
found_name = true;
|
||||
while (!is_name_unique) {
|
||||
is_name_unique = true;
|
||||
for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
|
||||
if (ci->client_name.compare(new_name) == 0) {
|
||||
if (ci->client_name.compare(name) == 0) {
|
||||
/* Name already in use */
|
||||
found_name = false;
|
||||
is_name_unique = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Check if it is the same as the server-name */
|
||||
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
|
||||
if (ci != nullptr) {
|
||||
if (ci->client_name.compare(new_name) == 0) found_name = false; // name already in use
|
||||
if (ci->client_name.compare(name) == 0) is_name_unique = false; // name already in use
|
||||
}
|
||||
|
||||
if (!found_name) {
|
||||
if (!is_name_unique) {
|
||||
/* Try a new name (<name> #1, <name> #2, and so on) */
|
||||
name = original_name + " #" + std::to_string(number);
|
||||
|
||||
/* Something's really wrong when there're more names than clients */
|
||||
if (number++ > MAX_CLIENTS) break;
|
||||
seprintf(new_name, last, "%s #%d", original_name, number);
|
||||
/* The constructed client name is larger than the limit,
|
||||
* so... bail out as no valid name can be created. */
|
||||
if (name.size() >= NETWORK_CLIENT_NAME_LENGTH) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return found_name;
|
||||
return is_name_unique;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1881,7 +1874,7 @@ bool NetworkFindName(char *new_name, const char *last)
|
||||
* @param new_name the new name for the client
|
||||
* @return true iff the name was changed
|
||||
*/
|
||||
bool NetworkServerChangeClientName(ClientID client_id, const char *new_name)
|
||||
bool NetworkServerChangeClientName(ClientID client_id, const std::string &new_name)
|
||||
{
|
||||
/* Check if the name's already in use */
|
||||
for (NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
|
||||
@@ -2213,7 +2206,7 @@ void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
|
||||
* @param colour_code The colour of the text.
|
||||
* @param string The actual reply.
|
||||
*/
|
||||
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string)
|
||||
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const std::string &string)
|
||||
{
|
||||
NetworkClientSocket::GetByClientID(client_id)->SendRConResult(colour_code, string);
|
||||
}
|
||||
@@ -2223,7 +2216,7 @@ void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const cha
|
||||
* @param client_id The client to kick.
|
||||
* @param reason In case of kicking a client, specifies the reason for kicking the client.
|
||||
*/
|
||||
void NetworkServerKickClient(ClientID client_id, const char *reason)
|
||||
void NetworkServerKickClient(ClientID client_id, const std::string &reason)
|
||||
{
|
||||
if (client_id == CLIENT_ID_SERVER) return;
|
||||
NetworkClientSocket::GetByClientID(client_id)->SendError(NETWORK_ERROR_KICKED, reason);
|
||||
@@ -2235,7 +2228,7 @@ void NetworkServerKickClient(ClientID client_id, const char *reason)
|
||||
* @param ban Whether to ban or kick.
|
||||
* @param reason In case of kicking a client, specifies the reason for kicking the client.
|
||||
*/
|
||||
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const char *reason)
|
||||
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const std::string &reason)
|
||||
{
|
||||
return NetworkServerKickOrBanIP(NetworkClientSocket::GetByClientID(client_id)->GetClientIP(), ban, reason);
|
||||
}
|
||||
@@ -2246,7 +2239,7 @@ uint NetworkServerKickOrBanIP(ClientID client_id, bool ban, const char *reason)
|
||||
* @param ban Whether to ban or just kick.
|
||||
* @param reason In case of kicking a client, specifies the reason for kicking the client.
|
||||
*/
|
||||
uint NetworkServerKickOrBanIP(const char *ip, bool ban, const char *reason)
|
||||
uint NetworkServerKickOrBanIP(const std::string &ip, bool ban, const std::string &reason)
|
||||
{
|
||||
/* Add address to ban-list */
|
||||
if (ban) {
|
||||
@@ -2270,7 +2263,7 @@ uint NetworkServerKickOrBanIP(const char *ip, bool ban, const char *reason)
|
||||
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
|
||||
if (cs->client_id == CLIENT_ID_SERVER) continue;
|
||||
if (cs->client_id == _redirect_console_to_client) continue;
|
||||
if (cs->client_address.IsInNetmask(ip)) {
|
||||
if (cs->client_address.IsInNetmask(ip.c_str())) {
|
||||
NetworkServerKickClient(cs->client_id, reason);
|
||||
n++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user