Compare commits

...

17 Commits

Author SHA1 Message Date
Jonathan G Rennison 6056a00222 Fix incorrect train weight used for infrastructure sharing track fees 3 weeks ago
Jonathan G Rennison 0150f8f570 Merge branch 'master' into jgrpp
# Conflicts:
#	src/network/network_server.cpp
3 weeks ago
Loïc Guilloux bd7120bae4
Fix #12316, 268e512: Support for enum storage type in GenerateWidget.cmake (#12321) 2 months ago
merni-ns af1bd43b30
Codefix 4c0dca1: [CI] Fix typo in workflow file (#12318) 2 months ago
Peter Nelson 0058ebe472
Codechange: Check cheap station-facility-filter before expensive in-use-filter. (#12317) 2 months ago
Loïc Guilloux 818a57c9af
Codechange: Actually use LIT_NONE (#12314) 2 months ago
SamuXarick d7c5e9e8ab Codechange: Where the ship comes from is already known
This simplifies the handling of variables.

`ChooseShipTrack` is called upon entering `tile`, and looking further back to the caller, it can be deduced that `v->tile` matches `src_tile`. With that said, `enterdir` can also be removed, as it's not used anywhere else.

`CreateRandomPath` and `GetRandomFollowUpTrackdir` is being fed `src_tile` as it's 2nd parameter. This could be eliminated, as `v` is also being passed to it. Just use `v->tile` in those functions.
2 months ago
Patric Stout 7f49b6f25a
Codefix: allow preview label on PRs against release branches too (#12310) 2 months ago
Patric Stout 5f4f9334ce
Codefix f1e999ec: use RandomRange(l) instead of _random.Next(l) (#12274) 2 months ago
merni-ns 4c0dca1411
Codechange: [CI] Move Release CI build to MacOS runner (#12309) 2 months ago
Rubidium fe12d38024 Codechange: split initiating of joining and identification of the client 2 months ago
Rubidium 15d02f51ed Codechange: use span to send bytes to Packet and add span recv function 2 months ago
Rubidium b6c75dec3a Codechange: explicitly allow only one state in initial handshake/authorization 2 months ago
Rubidium 26d1d5d6e7 Codechange: move decision whether to check NewGRFs to SendNewGRFCheck, just like for sending game/company passwords 2 months ago
Rubidium 6eff879e49 Codechange: pass the socket handler that is going to send the packet into the packet 2 months ago
Rubidium 3c488e1eb8 Codechange: don't check things outside the lock, that could change while waiting on the lock 2 months ago
Rubidium ec4104ec6c Codechange: do not pass the socket when the receiver already knows it 2 months ago

@ -30,15 +30,10 @@ jobs:
fail-fast: false
matrix:
include:
- name: Clang - Debug
- name: Clang
compiler: clang-15
cxxcompiler: clang++-15
libraries: libsdl2-dev
- name: Clang - Release
compiler: clang-15
cxxcompiler: clang++-15
libraries: libsdl2-dev
extra-cmake-parameters: -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPTION_USE_ASSERTS=OFF
- name: GCC - SDL2
compiler: gcc
cxxcompiler: g++
@ -66,10 +61,16 @@ jobs:
fail-fast: false
matrix:
include:
- arch: arm64
- name: arm64 - Debug
arch: arm64
full_arch: arm64
extra-cmake-parameters: -DCMAKE_BUILD_TYPE=Debug
- name: arm64 - Release
arch: arm64
full_arch: arm64
extra-cmake-parameters: -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPTION_USE_ASSERTS=OFF
name: Mac OS (${{ matrix.arch }})
name: Mac OS (${{ matrix.name }})
uses: ./.github/workflows/ci-macos.yml
secrets: inherit
@ -77,6 +78,7 @@ jobs:
with:
arch: ${{ matrix.arch }}
full_arch: ${{ matrix.full_arch }}
extra-cmake-parameters: ${{ matrix.extra-cmake-parameters }}
windows:
strategy:

@ -9,6 +9,10 @@ on:
full_arch:
required: true
type: string
extra-cmake-parameters:
required: false
type: string
default: ""
env:
CTEST_OUTPUT_ON_FAILURE: 1
@ -78,6 +82,7 @@ jobs:
-DCMAKE_OSX_ARCHITECTURES=${{ inputs.full_arch }} \
-DVCPKG_TARGET_TRIPLET=${{ inputs.arch }}-osx \
-DCMAKE_TOOLCHAIN_FILE=${{ runner.temp }}/vcpkg/scripts/buildsystems/vcpkg.cmake \
${{ inputs.extra-cmake-parameters }} \
# EOF
echo "::endgroup::"

@ -7,6 +7,7 @@ on:
- synchronize
branches:
- master
- release/**
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}

@ -56,11 +56,14 @@ foreach(ENUM IN LISTS ENUM_LINES)
endif()
# Check for enum match
if("${LINE}" MATCHES "^ *enum *${ENUM_PATTERN} *\{")
if("${LINE}" MATCHES "^ *enum *${ENUM_PATTERN}( *: *[^ ]*)? *\{")
# REGEX REPLACE does a REGEX MATCHALL and fails if an empty string is matched
string(REGEX MATCH "[^ ]*" RESULT "${LINE}")
string(REPLACE "${RESULT}" "" RM_INDENT "${LINE}")
string(REGEX MATCH " *: *[^ ]*" RESULT "${LINE}")
string(REPLACE "${RESULT}" "" LINE "${LINE}")
set(ACTIVE 1)
if(ACTIVE_COMMENT GREATER 0)
string(APPEND ${PLACE_HOLDER} "\n${COMMENT}")

@ -60,21 +60,6 @@ void PayStationSharingFee(Vehicle *v, const Station *st)
PaySharingFee(v, st->owner, (cost << 8) / DAY_TICKS);
}
uint16_t is2_GetWeight(Train *v)
{
uint16_t weight = (CargoSpec::Get(v->cargo_type)->weight * v->cargo.StoredCount() * FreightWagonMult(v->cargo_type)) / 16;
/* Vehicle weight is not added for articulated parts. */
if (!v->IsArticulatedPart()) {
weight += GetVehicleProperty(v, PROP_TRAIN_WEIGHT, RailVehInfo(v->engine_type)->weight);
}
/* Powered wagons have extra weight added. */
if (HasBit(v->flags, VRF_POWEREDWAGON)) {
weight += RailVehInfo(v->gcache.first_engine)->pow_wag_weight;
}
return weight;
}
/**
* Pay the daily fee for trains on foreign tracks.
* @param v The vehicle to pay the fee for.
@ -85,9 +70,9 @@ void PayDailyTrackSharingFee(Train *v)
if (owner == v->owner) return;
Money cost = _settings_game.economy.sharing_fee[VEH_TRAIN] << 8;
/* Cost is calculated per 1000 tonnes */
cost = cost * is2_GetWeight(v) / 1000;
cost = (cost * v->gcache.cached_weight) / 1000;
/* Only pay the required fraction */
cost = cost * v->running_ticks / DAY_TICKS;
cost = (cost * v->running_ticks) / DAY_TICKS;
if (cost != 0) PaySharingFee(v, owner, cost);
}

@ -118,21 +118,20 @@ struct PacketWriter : SaveFilter {
/**
* Transfer all packets from here to the network's queue while holding
* the lock on our mutex.
* @param socket The network socket to write to.
* @return True iff the last packet of the map has been sent.
*/
bool TransferToNetworkQueue(ServerNetworkGameSocketHandler *socket)
bool TransferToNetworkQueue()
{
std::lock_guard<std::mutex> lock(this->mutex);
if (this->map_size_packet) {
/* Don't queue the PACKET_SERVER_MAP_SIZE before the corresponding PACKET_SERVER_MAP_BEGIN */
socket->SendPrependPacket(std::move(this->map_size_packet), PACKET_SERVER_MAP_BEGIN);
this->cs->SendPrependPacket(std::move(this->map_size_packet), PACKET_SERVER_MAP_BEGIN);
}
bool last_packet = false;
for (auto &p : this->packets) {
if (p->GetPacketType() == PACKET_SERVER_MAP_DONE) last_packet = true;
socket->SendPacket(std::move(p));
this->cs->SendPacket(std::move(p));
}
this->packets.clear();
@ -142,13 +141,13 @@ struct PacketWriter : SaveFilter {
void Write(byte *buf, size_t size) override
{
std::lock_guard<std::mutex> lock(this->mutex);
/* We want to abort the saving when the socket is closed. */
if (this->cs == nullptr) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
if (this->current == nullptr) this->current = std::make_unique<Packet>(PACKET_SERVER_MAP_DATA, TCP_MTU);
std::lock_guard<std::mutex> lock(this->mutex);
byte *bufe = buf + size;
while (buf != bufe) {
size_t written = this->current->Send_binary_until_full(buf, bufe);
@ -165,11 +164,11 @@ struct PacketWriter : SaveFilter {
void Finish() override
{
std::lock_guard<std::mutex> lock(this->mutex);
/* We want to abort the saving when the socket is closed. */
if (this->cs == nullptr) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
std::lock_guard<std::mutex> lock(this->mutex);
/* Make sure the last packet is flushed. */
if (this->current != nullptr) this->packets.push_back(std::move(this->current));
@ -489,6 +488,17 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendDesyncLog(const std::strin
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck()
{
auto p = std::make_unique<Packet>(PACKET_SERVER_CHECK_NEWGRFS, TCP_MTU);
/* Invalid packet when status is anything but STATUS_INACTIVE. */
if (this->status != STATUS_INACTIVE) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
this->status = STATUS_NEWGRFS_CHECK;
if (_grfconfig == nullptr) {
/* There are no NewGRFs, continue with the game password. */
return this->SendNeedGamePassword();
}
const GRFConfig *c;
uint grf_count = 0;
@ -508,15 +518,16 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck()
/** Request the game password. */
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedGamePassword()
{
/* Invalid packet when status is anything but STATUS_NEWGRFS_CHECK. */
if (this->status != STATUS_NEWGRFS_CHECK) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
this->status = STATUS_AUTH_GAME;
if (_settings_client.network.server_password.empty()) {
/* Do not actually need a game password, continue with the company password. */
return this->SendNeedCompanyPassword();
}
/* Invalid packet when status is STATUS_AUTH_GAME or higher */
if (this->status >= STATUS_AUTH_GAME) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
this->status = STATUS_AUTH_GAME;
/* Reset 'lag' counters */
this->last_frame = this->last_frame_server = _frame_counter;
@ -533,15 +544,16 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedGamePassword()
/** Request the company password. */
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedCompanyPassword()
{
/* Invalid packet when status is anything but STATUS_AUTH_GAME. */
if (this->status != STATUS_AUTH_GAME) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
this->status = STATUS_AUTH_COMPANY;
NetworkClientInfo *ci = this->GetInfo();
if (!Company::IsValidID(ci->client_playas) || _network_company_states[ci->client_playas].password.empty()) {
return this->SendWelcome();
}
/* Invalid packet when status is STATUS_AUTH_COMPANY or higher */
if (this->status >= STATUS_AUTH_COMPANY) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
this->status = STATUS_AUTH_COMPANY;
/* Reset 'lag' counters */
this->last_frame = this->last_frame_server = _frame_counter;
@ -555,10 +567,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedCompanyPassword()
/** Send the client a welcome message with some basic information. */
NetworkRecvStatus ServerNetworkGameSocketHandler::SendWelcome()
{
/* Invalid packet when status is AUTH or higher */
if (this->status >= STATUS_AUTHORIZED) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
/* Invalid packet when status is anything but STATUS_AUTH_COMPANY. */
if (this->status != STATUS_AUTH_COMPANY) return this->CloseConnection(NETWORK_RECV_STATUS_MALFORMED_PACKET);
this->status = STATUS_AUTHORIZED;
/* Reset 'lag' counters */
this->last_frame = this->last_frame_server = _frame_counter;
@ -659,7 +672,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
}
if (this->status == STATUS_MAP) {
bool last_packet = this->savegame->TransferToNetworkQueue(this);
bool last_packet = this->savegame->TransferToNetworkQueue();
if (last_packet) {
/* Done reading, make sure saving is done as well */
this->savegame->Destroy();
@ -1015,13 +1028,6 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet &p)
/* Make sure companies to which people try to join are not autocleaned */
if (Company::IsValidID(playas)) _network_company_states[playas].months_empty = 0;
this->status = STATUS_NEWGRFS_CHECK;
if (_grfconfig == nullptr) {
/* Continue asking for the game password. */
return this->SendNeedGamePassword();
}
return this->SendNewGRFCheck();
}

@ -180,7 +180,7 @@ public:
TrackdirBits dirs = follower.m_new_td_bits;
const TrackdirBits dirs_without_90_degree = dirs & ~TrackdirCrossesTrackdirs(dir);
if (dirs_without_90_degree != TRACKDIR_BIT_NONE) dirs = dirs_without_90_degree;
const int strip_amount = _random.Next(CountBits(dirs));
const int strip_amount = RandomRange(CountBits(dirs));
for (int s = 0; s < strip_amount; ++s) RemoveFirstTrackdir(&dirs);
return { follower.m_new_tile, FindFirstTrackdir(dirs) };
}

@ -303,8 +303,8 @@ protected:
this->stations_per_cargo_type_no_rating = 0;
for (const Station *st : Station::Iterate()) {
if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
if (this->filter.facilities & st->facilities) { // only stations with selected facilities
if ((this->filter.facilities & st->facilities) != 0) { // only stations with selected facilities
if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
bool has_rating = false;
/* Add to the station/cargo counts. */
for (CargoID j = 0; j < NUM_CARGO; j++) {

@ -526,9 +526,9 @@ cat = SC_BASIC
var = gui.liveries
type = SLE_UINT8
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
def = 2
min = 0
max = 2
def = LIT_ALL
min = LIT_NONE
max = LIT_ALL
str = STR_CONFIG_SETTING_LIVERIES
strhelp = STR_CONFIG_SETTING_LIVERIES_HELPTEXT
strval = STR_CONFIG_SETTING_LIVERIES_NONE

Loading…
Cancel
Save