mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
4 Commits
502a52edd5
...
344bdafb53
Author | SHA1 | Date |
---|---|---|
|
344bdafb53 | |
|
1cdafcd7ac | |
|
ae3352582a | |
|
48b6b1844a |
|
@ -116,6 +116,8 @@ SQVM::SQVM(SQSharedState *ss)
|
|||
_can_suspend = false;
|
||||
_in_stackoverflow = false;
|
||||
_ops_till_suspend = 0;
|
||||
_ops_till_suspend_error_threshold = INT64_MIN;
|
||||
_ops_till_suspend_error_label = nullptr;
|
||||
_callsstack = nullptr;
|
||||
_callsstacksize = 0;
|
||||
_alloccallsstacksize = 0;
|
||||
|
@ -744,6 +746,10 @@ exception_restore:
|
|||
{
|
||||
DecreaseOps(1);
|
||||
if (ShouldSuspend()) { _suspended = SQTrue; _suspended_traps = traps; return true; }
|
||||
if (IsOpsTillSuspendError()) {
|
||||
Raise_Error(fmt::format("excessive CPU usage in {}", _ops_till_suspend_error_label));
|
||||
SQ_THROW();
|
||||
}
|
||||
|
||||
const SQInstruction &_i_ = *ci->_ip++;
|
||||
#ifdef _DEBUG_DUMP
|
||||
|
|
|
@ -168,6 +168,8 @@ public:
|
|||
|
||||
SQBool _can_suspend;
|
||||
SQInteger _ops_till_suspend;
|
||||
SQInteger _ops_till_suspend_error_threshold;
|
||||
const char *_ops_till_suspend_error_label;
|
||||
SQBool _in_stackoverflow;
|
||||
|
||||
bool ShouldSuspend()
|
||||
|
@ -175,6 +177,11 @@ public:
|
|||
return _can_suspend && _ops_till_suspend <= 0;
|
||||
}
|
||||
|
||||
bool IsOpsTillSuspendError()
|
||||
{
|
||||
return _ops_till_suspend < _ops_till_suspend_error_threshold;
|
||||
}
|
||||
|
||||
void DecreaseOps(SQInteger amount)
|
||||
{
|
||||
if (_ops_till_suspend - amount < _ops_till_suspend) _ops_till_suspend -= amount;
|
||||
|
|
|
@ -903,7 +903,7 @@ STR_NEWS_VEHICLE_IS_UNPROFITABLE :{WHITE}{VEHICLE
|
|||
STR_NEWS_AIRCRAFT_DEST_TOO_FAR :{WHITE}{VEHICLE} can't get to the next destination because it is out of range
|
||||
|
||||
STR_NEWS_ORDER_REFIT_FAILED :{WHITE}{VEHICLE} stopped because an ordered refit failed
|
||||
STR_NEWS_VEHICLE_AUTORENEW_FAILED :{WHITE}Autorenew failed on {VEHICLE}{}{STRING}
|
||||
STR_NEWS_VEHICLE_AUTORENEW_FAILED :{WHITE}Autorenew failed on {VEHICLE}{}{STRING2}
|
||||
|
||||
STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE :{BIG_FONT}{BLACK}New {STRING} now available!
|
||||
STR_NEWS_NEW_VEHICLE_TYPE :{BIG_FONT}{BLACK}{ENGINE}
|
||||
|
@ -4475,9 +4475,9 @@ STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP :{BLACK}How to c
|
|||
STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS :is equal to
|
||||
STR_ORDER_CONDITIONAL_COMPARATOR_NOT_EQUALS :is not equal to
|
||||
STR_ORDER_CONDITIONAL_COMPARATOR_LESS_THAN :is less than
|
||||
STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS :is less or equal to
|
||||
STR_ORDER_CONDITIONAL_COMPARATOR_LESS_EQUALS :is less than or equal to
|
||||
STR_ORDER_CONDITIONAL_COMPARATOR_MORE_THAN :is more than
|
||||
STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS :is more or equal to
|
||||
STR_ORDER_CONDITIONAL_COMPARATOR_MORE_EQUALS :is more than or equal to
|
||||
STR_ORDER_CONDITIONAL_COMPARATOR_IS_TRUE :is true
|
||||
STR_ORDER_CONDITIONAL_COMPARATOR_IS_FALSE :is false
|
||||
|
||||
|
|
|
@ -1120,11 +1120,11 @@ STR_NUM_CUSTOM :Pielāgots
|
|||
STR_NUM_CUSTOM_NUMBER :Pielāgots ({NUM})
|
||||
|
||||
STR_VARIETY_NONE :Nav
|
||||
STR_VARIETY_VERY_LOW :Ļoti zema
|
||||
STR_VARIETY_LOW :Zema
|
||||
STR_VARIETY_MEDIUM :Vidēja
|
||||
STR_VARIETY_HIGH :Augsta
|
||||
STR_VARIETY_VERY_HIGH :Ļoti augsta
|
||||
STR_VARIETY_VERY_LOW :Ļoti zems
|
||||
STR_VARIETY_LOW :Zems
|
||||
STR_VARIETY_MEDIUM :Vidējs
|
||||
STR_VARIETY_HIGH :Augsts
|
||||
STR_VARIETY_VERY_HIGH :Ļoti augsts
|
||||
|
||||
###length 5
|
||||
STR_AI_SPEED_VERY_SLOW :Ļoti lēns
|
||||
|
@ -2432,7 +2432,7 @@ STR_NETWORK_CLIENT_LIST_NEW_COMPANY :(Jauna kompāni
|
|||
STR_NETWORK_CLIENT_LIST_NEW_COMPANY_TOOLTIP :{BLACK}Izveidot jaunu kompāniju un pievienoties tai
|
||||
STR_NETWORK_CLIENT_LIST_PLAYER_ICON_SELF_TOOLTIP :{BLACK}Tas esat jūs
|
||||
STR_NETWORK_CLIENT_LIST_PLAYER_ICON_HOST_TOOLTIP :{BLACK}Šis ir spēles īpašnieks
|
||||
STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT :{BLACK}Klientu: {NUM}; uzņēmumu: {NUM}/{NUM}
|
||||
STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT :{BLACK}klientu: {NUM}; kompāniju: {NUM}/{NUM}
|
||||
STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT_TOOLTIP :{BLACK}Pašlaik savienoto klientu skaits, uzņēmumu skaits un maksimālais servera administratora atļautais uzņēmumu skaits
|
||||
|
||||
# Matches ConnectionType
|
||||
|
@ -2506,8 +2506,8 @@ STR_NETWORK_ERROR_LOSTCONNECTION :{WHITE}Tīkla s
|
|||
STR_NETWORK_ERROR_SAVEGAMEERROR :{WHITE}Nevar ielādēt saglabāto spēli
|
||||
STR_NETWORK_ERROR_SERVER_START :{WHITE}Nevar uzsākt servera darbību
|
||||
STR_NETWORK_ERROR_SERVER_ERROR :{WHITE}Tika pielaista protokola kļūda un savienojums tika slēgts
|
||||
STR_NETWORK_ERROR_BAD_PLAYER_NAME :{WHITE} Jūsu spēlētāja vārds nav iestatīts. Nosaukumu var iestatīt vMultiplayer loga augšdaļā
|
||||
STR_NETWORK_ERROR_BAD_SERVER_NAME :{WHITE} Jūsu servera nosaukums nav iestatīts. Nosaukumu var iestatīt Multiplayer loga augšdaļā
|
||||
STR_NETWORK_ERROR_BAD_PLAYER_NAME :{WHITE} Jūsu spēlētāja vārds nav iestatīts. Nosaukumu var iestatīt šī loga augšdaļā
|
||||
STR_NETWORK_ERROR_BAD_SERVER_NAME :{WHITE} Jūsu servera nosaukums nav iestatīts. Nosaukumu var iestatīt vairākspēlētāju loga augšdaļā
|
||||
STR_NETWORK_ERROR_WRONG_REVISION :{WHITE}Klienta pārskats neatbilst servera pārskatam
|
||||
STR_NETWORK_ERROR_WRONG_PASSWORD :{WHITE}Nepareiza parole
|
||||
STR_NETWORK_ERROR_SERVER_FULL :{WHITE}Serveris ir pilns
|
||||
|
|
|
@ -2724,7 +2724,7 @@ STR_NETWORK_START_SERVER_NEW_GAME_NAME_TOOLTIP :{BLACK}Nazwa gr
|
|||
STR_NETWORK_START_SERVER_SET_PASSWORD :{BLACK}Ustaw hasło
|
||||
STR_NETWORK_START_SERVER_PASSWORD_TOOLTIP :{BLACK}Zabezpiecz grę hasłem jeśli nie chcesz, by była publicznie dostępna
|
||||
|
||||
STR_NETWORK_START_SERVER_VISIBILITY_LABEL :{BLACK}Widoczność
|
||||
STR_NETWORK_START_SERVER_VISIBILITY_LABEL :{BLACK}Widoczność:
|
||||
STR_NETWORK_START_SERVER_VISIBILITY_TOOLTIP :{BLACK}Czy inni ludzie mogą zobaczyć twój serwer na publicznej liście
|
||||
STR_NETWORK_START_SERVER_CLIENTS_SELECT :{BLACK}{NUM} klient{P "" ów ów}
|
||||
STR_NETWORK_START_SERVER_NUMBER_OF_CLIENTS :{BLACK}Dopuszczalna liczba klientów:
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
#include "script_list.hpp"
|
||||
#include "script_controller.hpp"
|
||||
#include "../../debug.h"
|
||||
#include "../../core/backup_type.hpp"
|
||||
#include "../../script/squirrel.hpp"
|
||||
#include <../squirrel/sqvm.h>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
|
@ -866,6 +868,14 @@ SQInteger ScriptList::Valuate(HSQUIRRELVM vm)
|
|||
bool backup_allow = ScriptObject::GetAllowDoCommand();
|
||||
ScriptObject::SetAllowDoCommand(false);
|
||||
|
||||
/* Limit the total number of ops that can be consumed by a valuate operation */
|
||||
SQInteger new_ops_error_threshold = vm->_ops_till_suspend_error_threshold;
|
||||
if (vm->_ops_till_suspend_error_threshold == INT64_MIN) {
|
||||
new_ops_error_threshold = vm->_ops_till_suspend - MAX_VALUATE_OPS;
|
||||
vm->_ops_till_suspend_error_label = "valuator function";
|
||||
}
|
||||
AutoRestoreBackup ops_error_threshold_backup(vm->_ops_till_suspend_error_threshold, new_ops_error_threshold);
|
||||
|
||||
/* Push the function to call */
|
||||
sq_push(vm, 2);
|
||||
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
|
||||
#include "script_object.hpp"
|
||||
|
||||
/** Maximum number of operations allowed for valuating a list. */
|
||||
static const int MAX_VALUATE_OPS = 500000;
|
||||
|
||||
class ScriptListSorter;
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "../../depot_map.h"
|
||||
#include "../../vehicle_base.h"
|
||||
#include "../../train.h"
|
||||
#include "../../core/backup_type.hpp"
|
||||
#include <../squirrel/sqvm.h>
|
||||
|
||||
#include "../../safeguards.h"
|
||||
|
||||
|
@ -41,6 +43,14 @@ ScriptVehicleList::ScriptVehicleList(HSQUIRRELVM vm)
|
|||
bool backup_allow = ScriptObject::GetAllowDoCommand();
|
||||
ScriptObject::SetAllowDoCommand(false);
|
||||
|
||||
/* Limit the total number of ops that can be consumed by a filter operation, if a filter function is present */
|
||||
SQInteger new_ops_error_threshold = vm->_ops_till_suspend_error_threshold;
|
||||
if (nparam >= 1 && vm->_ops_till_suspend_error_threshold == INT64_MIN) {
|
||||
new_ops_error_threshold = vm->_ops_till_suspend - MAX_VALUATE_OPS;
|
||||
vm->_ops_till_suspend_error_label = "vehicle filter function";
|
||||
}
|
||||
AutoRestoreBackup ops_error_threshold_backup(vm->_ops_till_suspend_error_threshold, new_ops_error_threshold);
|
||||
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if (v->owner != ScriptObject::GetCompany() && !ScriptCompanyMode::IsDeity()) continue;
|
||||
if (!v->IsPrimaryVehicle() && !(v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon())) continue;
|
||||
|
|
Loading…
Reference in New Issue