id
int64
0
877k
file_name
stringlengths
3
109
file_path
stringlengths
13
185
content
stringlengths
31
9.38M
size
int64
31
9.38M
language
stringclasses
1 value
extension
stringclasses
11 values
total_lines
int64
1
340k
avg_line_length
float64
2.18
149k
max_line_length
int64
7
2.22M
alphanum_fraction
float64
0
1
repo_name
stringlengths
6
66
repo_stars
int64
94
47.3k
repo_forks
int64
0
12k
repo_open_issues
int64
0
3.4k
repo_license
stringclasses
11 values
repo_extraction_date
stringclasses
197 values
exact_duplicates_redpajama
bool
2 classes
near_duplicates_redpajama
bool
2 classes
exact_duplicates_githubcode
bool
2 classes
exact_duplicates_stackv2
bool
1 class
exact_duplicates_stackv1
bool
2 classes
near_duplicates_githubcode
bool
2 classes
near_duplicates_stackv1
bool
2 classes
near_duplicates_stackv2
bool
1 class
1,538,899
organization_multi_tab.h
altlinux_admc/src/admc/multi_tabs/organization_multi_tab.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef ORGANIZATION_MULTI_TAB_H #define ORGANIZATION_MULTI_TAB_H #include <QWidget> class AttributeEdit; class QCheckBox; namespace Ui { class OrganizationMultiTab; } class OrganizationMultiTab final : public QWidget { Q_OBJECT public: Ui::OrganizationMultiTab *ui; OrganizationMultiTab(QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent); ~OrganizationMultiTab(); }; #endif /* ORGANIZATION_MULTI_TAB_H */
1,253
C++
.h
35
33.6
125
0.764463
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,900
account_multi_tab.h
altlinux_admc/src/admc/multi_tabs/account_multi_tab.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef ACCOUNT_MULTI_TAB_H #define ACCOUNT_MULTI_TAB_H /** * General multi tab that contains general object * attributes. */ #include <QWidget> class AttributeEdit; class AdInterface; class QCheckBox; namespace Ui { class AccountMultiTab; } class AccountMultiTab final : public QWidget { Q_OBJECT public: Ui::AccountMultiTab *ui; AccountMultiTab(AdInterface &ad, QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent); ~AccountMultiTab(); }; #endif /* ACCOUNT_MULTI_TAB_H */
1,323
C++
.h
40
30.925
137
0.756672
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,901
profile_multi_tab.h
altlinux_admc/src/admc/multi_tabs/profile_multi_tab.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef PROFILE_MULTI_TAB_H #define PROFILE_MULTI_TAB_H #include <QWidget> class AttributeEdit; class QCheckBox; namespace Ui { class ProfileMultiTab; } class ProfileMultiTab final : public QWidget { Q_OBJECT public: Ui::ProfileMultiTab *ui; ProfileMultiTab(QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent); ~ProfileMultiTab(); }; #endif /* PROFILE_MULTI_TAB_H */
1,213
C++
.h
35
32.457143
120
0.75641
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,902
general_user_multi_tab.h
altlinux_admc/src/admc/multi_tabs/general_user_multi_tab.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef GENERAL_USER_MULTI_TAB_H #define GENERAL_USER_MULTI_TAB_H /** * General multi tab for users. */ #include <QWidget> class AttributeEdit; class QCheckBox; namespace Ui { class GeneralUserMultiTab; } class GeneralUserMultiTab final : public QWidget { Q_OBJECT public: Ui::GeneralUserMultiTab *ui; GeneralUserMultiTab(QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent); ~GeneralUserMultiTab(); }; #endif /* GENERAL_USER_MULTI_TAB_H */
1,289
C++
.h
38
31.736842
124
0.756844
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,903
address_multi_tab.h
altlinux_admc/src/admc/multi_tabs/address_multi_tab.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef ADDRESS_MULTI_TAB_H #define ADDRESS_MULTI_TAB_H /** * General multi tab that contains general object * attributes. */ #include <QWidget> class AttributeEdit; class QCheckBox; namespace Ui { class AddressMultiTab; } class AddressMultiTab final : public QWidget { Q_OBJECT public: Ui::AddressMultiTab *ui; AddressMultiTab(QList<AttributeEdit *> *edit_list, QHash<AttributeEdit *, QCheckBox *> *check_map, QWidget *parent); ~AddressMultiTab(); }; #endif /* ADDRESS_MULTI_TAB_H */
1,287
C++
.h
39
30.820513
120
0.754641
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,904
upn_multi_edit.h
altlinux_admc/src/admc/attribute_edits/upn_multi_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef UPN_MULTI_EDIT_H #define UPN_MULTI_EDIT_H /** * Edit for editing UPN suffixes of multiple objects. * This special version is needed because when editing * multiple objects, only the suffix is edited, so * normal UpnEdit doesn't work for this. */ #include "attribute_edits/attribute_edit.h" class QComboBox; class UpnMultiEdit final : public AttributeEdit { Q_OBJECT public: UpnMultiEdit(QComboBox *upn_suffix_combo, AdInterface &ad, QObject *parent); bool apply(AdInterface &ad, const QString &target) const override; void set_enabled(const bool enabled) override; private: QComboBox *upn_suffix_combo; }; #endif /* UPN_MULTI_EDIT_H */
1,451
C++
.h
39
34.897436
80
0.757835
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,905
delegation_edit.h
altlinux_admc/src/admc/attribute_edits/delegation_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef DELEGATION_EDIT_H #define DELEGATION_EDIT_H #include "attribute_edits/attribute_edit.h" class QRadioButton; class DelegationEdit final : public AttributeEdit { Q_OBJECT public: DelegationEdit(QRadioButton *off_button, QRadioButton *on_button, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; private: QRadioButton *off_button; QRadioButton *on_button; }; #endif /* DELEGATION_EDIT_H */
1,292
C++
.h
34
35.558824
87
0.760991
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,906
logon_hours_dialog.h
altlinux_admc/src/admc/attribute_edits/logon_hours_dialog.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef LOGON_HOURS_DIALOG_H #define LOGON_HOURS_DIALOG_H /** * Dialog for editing logon hours of a user account. */ #include <QDialog> class QStandardItemModel; // NOTE: this is the order in logon hours value. Different // from the display order in the dialog where first day is monday enum Weekday { Weekday_Sunday, Weekday_Monday, Weekday_Tuesday, Weekday_Wednesday, Weekday_Thursday, Weekday_Friday, Weekday_Saturday, Weekday_COUNT, }; #define DAYS_IN_WEEK 7 #define HOURS_IN_DAY 24 #define LOGON_HOURS_SIZE (7 * 3) namespace Ui { class LogonHoursDialog; } class LogonHoursDialog : public QDialog { Q_OBJECT public: Ui::LogonHoursDialog *ui; LogonHoursDialog(const QByteArray &value, QWidget *parent); ~LogonHoursDialog(); QByteArray get() const; private: QStandardItemModel *model; QByteArray original_value; void load(const QByteArray &value); void switch_to_local_time(); void on_local_time_button_toggled(bool checked); int get_offset() const; bool is_local_time; }; QList<QList<bool>> logon_hours_to_bools(const QByteArray &byte_list, const int time_offset = 0); QByteArray logon_hours_to_bytes(const QList<QList<bool>> bool_list, const int time_offset = 0); int get_current_utc_offset(); #endif /* LOGON_HOURS_DIALOG_H */
2,103
C++
.h
64
30.0625
96
0.746542
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,907
unlock_edit.h
altlinux_admc/src/admc/attribute_edits/unlock_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef UNLOCK_EDIT_H #define UNLOCK_EDIT_H /** * Unlocks the account, if pressed down (when being applied, * NOT immediately. Doesn't implement the reverse operation * (locking) because that's only doable by the server. The * edit changes has two style options, to put the checkbox * on the right or left side of texts. Right checkbox style * is to fit in with forms with other similar edits (account * tab). Left checkbox style is to fit next to other * checkboxes (change password dialog). */ #include "attribute_edits/attribute_edit.h" class QCheckBox; class UnlockEdit final : public AttributeEdit { Q_OBJECT public: UnlockEdit(QCheckBox *check_arg, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; static QString label_text(); private: QCheckBox *check; }; #endif /* UNLOCK_EDIT_H */
1,699
C++
.h
44
36.25
72
0.753949
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,908
logon_computers_edit.h
altlinux_admc/src/admc/attribute_edits/logon_computers_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef LOGON_COMPUTERS_EDIT_H #define LOGON_COMPUTERS_EDIT_H #include "attribute_edits/attribute_edit.h" class QPushButton; class LogonComputersEdit final : public AttributeEdit { Q_OBJECT public: LogonComputersEdit(QPushButton *button, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; private: QPushButton *button; QString current_value; void open_dialog(); }; #endif /* LOGON_COMPUTERS_EDIT_H */
1,302
C++
.h
35
34.657143
72
0.759333
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,909
protect_deletion_edit.h
altlinux_admc/src/admc/attribute_edits/protect_deletion_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef PROTECT_DELETION_EDIT_H #define PROTECT_DELETION_EDIT_H /** * Checkbox edit that modifies ACL to protect (or not) * against deletion by denying/allowing deletion. */ #include "attribute_edits/attribute_edit.h" class QCheckBox; class ProtectDeletionEdit final : public AttributeEdit { Q_OBJECT public: ProtectDeletionEdit(QCheckBox *check, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; void set_enabled(const bool enabled); private: QCheckBox *check; }; #endif /* PROTECT_DELETION_EDIT_H */
1,404
C++
.h
38
34.526316
72
0.759764
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,910
string_other_edit.h
altlinux_admc/src/admc/attribute_edits/string_other_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef STRING_OTHER_EDIT_H #define STRING_OTHER_EDIT_H #include "attribute_edits/attribute_edit.h" class StringEdit; class QPushButton; class QLineEdit; /** * Edit for attributes which have "other" version which is * multi-valued. For example "telephone" and * "otherTelephone". Contains a StringEdit for the attribute * itself and an "Other" button next to it which opens a * dialog through which other values are edited. */ class StringOtherEdit final : public AttributeEdit { Q_OBJECT public: StringOtherEdit(QLineEdit *line_edit, QPushButton *other_button, const QString &main_attribute_arg, const QString &other_attribute_arg, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; // Sets read only property on both main edit and // edit dialog for "Other" values. Dialog for // "Other" values can still be opened to view them, // while read only is active. void set_read_only(const bool read_only); bool apply(AdInterface &ad, const QString &dn) const override; private: StringEdit *main_edit; QPushButton *other_button; QLineEdit *line_edit; bool read_only; const QString other_attribute; QList<QByteArray> other_values; void on_other_button(); }; #endif /* STRING_OTHER_EDIT_H */
2,070
C++
.h
53
36.169811
157
0.749127
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,911
group_scope_edit.h
altlinux_admc/src/admc/attribute_edits/group_scope_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef GROUP_SCOPE_EDIT_H #define GROUP_SCOPE_EDIT_H #include "attribute_edits/attribute_edit.h" class QComboBox; class GroupScopeEdit final : public AttributeEdit { Q_OBJECT public: GroupScopeEdit(QComboBox *combo, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; private: QComboBox *combo; }; #endif /* GROUP_SCOPE_EDIT_H */
1,222
C++
.h
33
34.666667
72
0.757191
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,912
general_name_edit.h
altlinux_admc/src/admc/attribute_edits/general_name_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef GENERAL_NAME_EDIT_H #define GENERAL_NAME_EDIT_H /** * Edit for displaying name of object in a label. Used * in general tabs of the properties dialog */ #include "attribute_edits/attribute_edit.h" class QLabel; class GeneralNameEdit final : public AttributeEdit { Q_OBJECT public: GeneralNameEdit(QLabel *label, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; private: QLabel *label; }; #endif /* GENERAL_NAME_EDIT_H */
1,259
C++
.h
36
32.722222
72
0.754733
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,913
account_option_edit.h
altlinux_admc/src/admc/attribute_edits/account_option_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef ACCOUNT_OPTION_EDIT_H #define ACCOUNT_OPTION_EDIT_H #include "attribute_edits/attribute_edit.h" #include "ad_defines.h" class QCheckBox; class QWidget; class AccountOptionEdit final : public AttributeEdit { Q_OBJECT public: AccountOptionEdit(QCheckBox *check, const AccountOption option_arg, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; private: AccountOption option; QCheckBox *check; }; void account_option_setup_conflicts(const QHash<AccountOption, QCheckBox *> &check_map); #endif /* ACCOUNT_OPTION_EDIT_H */
1,425
C++
.h
37
36.135135
89
0.765772
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,914
string_list_edit.h
altlinux_admc/src/admc/attribute_edits/string_list_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef STRING_LIST_EDIT_H #define STRING_LIST_EDIT_H #include "attribute_edits/attribute_edit.h" class QPushButton; class StringListEdit final : public AttributeEdit { Q_OBJECT public: StringListEdit(QPushButton *button, const QString &attribute, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; private: QPushButton *button; QString attribute; QList<QByteArray> values; void on_button(); }; #endif /* STRING_LIST_EDIT_H */
1,333
C++
.h
36
34.388889
83
0.755435
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,915
string_large_edit.h
altlinux_admc/src/admc/attribute_edits/string_large_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef STRING_LARGE_EDIT_H #define STRING_LARGE_EDIT_H /** * Edit for large, multi-line strings. Uses QPlainTextEdit * instead of QLineEdit. */ #include "attribute_edits/attribute_edit.h" class QPlainTextEdit; class StringLargeEdit final : public AttributeEdit { Q_OBJECT public: StringLargeEdit(QPlainTextEdit *edit, const QString &attribute_arg, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; private: QPlainTextEdit *edit; QString attribute; bool ignore_on_text_changed; void on_text_changed(); }; #endif /* STRING_LARGE_EDIT_H */
1,448
C++
.h
40
33.65
89
0.75554
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,916
gpoptions_edit.h
altlinux_admc/src/admc/attribute_edits/gpoptions_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef GPOPTIONS_EDIT_H #define GPOPTIONS_EDIT_H #include "attribute_edits/attribute_edit.h" class QCheckBox; class GpoptionsEdit final : public AttributeEdit { Q_OBJECT public: GpoptionsEdit(QCheckBox *check, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; signals: void gp_options_changed(bool is_checked) const; private: QCheckBox *check; }; #endif /* GPOPTIONS_EDIT_H */
1,276
C++
.h
35
34.028571
72
0.758313
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,917
computer_sam_name_edit.h
altlinux_admc/src/admc/attribute_edits/computer_sam_name_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef COMPUTER_SAM_NAME_EDIT_H #define COMPUTER_SAM_NAME_EDIT_H #include "attribute_edits/attribute_edit.h" class QLineEdit; class ComputerSamNameEdit final : public AttributeEdit { Q_OBJECT public: ComputerSamNameEdit(QLineEdit *edit, QLineEdit *domain_edit, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool verify(AdInterface &ad, const QString &dn) const override; bool apply(AdInterface &ad, const QString &dn) const override; void set_enabled(const bool enabled); private: QLineEdit *edit; }; #endif /* COMPUTER_SAM_NAME_EDIT_H */
1,383
C++
.h
35
36.971429
82
0.758955
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,918
country_combo.h
altlinux_admc/src/admc/attribute_edits/country_combo.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef COUNTRY_COMBO_H #define COUNTRY_COMBO_H class QComboBox; class AdObject; class AdInterface; class QString; void country_combo_load_data(); void country_combo_init(QComboBox *combo); void country_combo_load(QComboBox *combo, const AdObject &object); bool country_combo_apply(const QComboBox *combo, AdInterface &ad, const QString &dn); #endif /* COUNTRY_COMBO_H */
1,150
C++
.h
30
36.6
85
0.768817
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,919
account_option_multi_edit.h
altlinux_admc/src/admc/attribute_edits/account_option_multi_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef ACCOUNT_OPTION_MULTI_EDIT_H #define ACCOUNT_OPTION_MULTI_EDIT_H /** * Edit for editing account options of multiple objects * at the same time. Needed because in this case all of * the checks are grouped together, unlike the normal * account option edit. */ #include "attribute_edits/attribute_edit.h" #include "ad_defines.h" #include <QHash> class QCheckBox; class AccountOptionMultiEdit final : public AttributeEdit { Q_OBJECT public: AccountOptionMultiEdit(const QHash<AccountOption, QCheckBox *> &check_map, QObject *parent); bool apply(AdInterface &ad, const QString &target) const override; void set_enabled(const bool enabled) override; private: QHash<AccountOption, QCheckBox *> check_map; }; #endif /* ACCOUNT_OPTION_MULTI_EDIT_H */
1,558
C++
.h
41
35.707317
96
0.763106
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,920
password_edit.h
altlinux_admc/src/admc/attribute_edits/password_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef PASSWORD_EDIT_H #define PASSWORD_EDIT_H #include "attribute_edits/attribute_edit.h" class QLineEdit; class QCheckBox; class PasswordEdit final : public AttributeEdit { Q_OBJECT public: PasswordEdit(QLineEdit *edit_arg, QLineEdit *confirm_edit_arg, QCheckBox *show_password_check, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool verify(AdInterface &ad, const QString &dn) const override; bool apply(AdInterface &ad, const QString &dn) const override; QLineEdit *get_edit() const; QLineEdit *get_confirm_edit() const; private: QLineEdit *edit; QLineEdit *confirm_edit; void on_show_password_check(bool checked); }; #endif /* PASSWORD_EDIT_H */
1,509
C++
.h
39
35.974359
116
0.754278
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,921
manager_edit.h
altlinux_admc/src/admc/attribute_edits/manager_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef MANAGER_EDIT_H #define MANAGER_EDIT_H /** * Edit for editing manager. Displays current manager and * allows changing manager, opening manager properties and * clearing manager. Accepts manager attribute argument * because there are two manager attributes: "manager" and * "managedBy". */ #include "attribute_edits/attribute_edit.h" class ManagerWidget; class ManagerEdit final : public AttributeEdit { Q_OBJECT public: ManagerEdit(ManagerWidget *widget_arg, const QString &manager_attribute_arg, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; void set_enabled(const bool enabled) override; QString get_manager() const; private: ManagerWidget *widget; QString manager_attribute; }; #endif /* MANAGER_EDIT_H */
1,633
C++
.h
43
35.465116
98
0.762176
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,922
dn_edit.h
altlinux_admc/src/admc/attribute_edits/dn_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2021 BaseALT Ltd. * Copyright (C) 2020-2021 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef DN_EDIT_H #define DN_EDIT_H #include "attribute_edits/attribute_edit.h" class QLineEdit; class DNEdit final : public AttributeEdit { Q_OBJECT public: DNEdit(QLineEdit *edit_arg, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; private: QLineEdit *edit; }; #endif /* DN_EDIT_H */
1,114
C++
.h
32
32.53125
72
0.750698
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,923
country_edit.h
altlinux_admc/src/admc/attribute_edits/country_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef COUNTRY_EDIT_H #define COUNTRY_EDIT_H #include "attribute_edits/attribute_edit.h" class QComboBox; class CountryEdit final : public AttributeEdit { Q_OBJECT public: CountryEdit(QComboBox *combo, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; void set_enabled(const bool enabled) override; private: QComboBox *combo; }; #endif /* COUNTRY_EDIT_H */
1,255
C++
.h
34
34.470588
72
0.756178
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,924
laps_expiry_edit.h
altlinux_admc/src/admc/attribute_edits/laps_expiry_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef LAPS_EXPIRY_EDIT_H #define LAPS_EXPIRY_EDIT_H #include "attribute_edits/attribute_edit.h" class QDateTimeEdit; class QPushButton; class LAPSExpiryEdit final : public AttributeEdit { Q_OBJECT public: LAPSExpiryEdit(QDateTimeEdit *edit_arg, QPushButton *reset_expiry_button, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; private: QDateTimeEdit *edit; void reset_expiry(); }; #endif /* LAPS_EXPIRY_EDIT_H */
1,315
C++
.h
35
35.142857
95
0.76022
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,925
attribute_edit.h
altlinux_admc/src/admc/attribute_edits/attribute_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef ATTRIBUTE_EDIT_H #define ATTRIBUTE_EDIT_H #include <QObject> /** * AttributeEdit's wrap regular Qt widgets so that they can * be used to edit attributes of an AD object. Depending on * what kind of attribute is being edited, different widgets * are used to represent different data types. */ class AdInterface; class AdObject; class AttributeEdit : public QObject { Q_OBJECT public: // Verify edit. Verify process will stop on first // failure. This is so that only one failure message is // shown at a time. static bool verify(const QList<AttributeEdit *> &edit_list, AdInterface &ad, const QString &dn); // Applies edits. If one of the edits fails to apply // midway, the apply process still continues. This is // so that if more errors occur, they are all gathered // together and presented to the user together. If // process stopped on first error, the user would have // to apply multiple times while fixing errors to see // all of them. static bool apply(const QList<AttributeEdit *> &edit_list, AdInterface &ad, const QString &dn); static void load(const QList<AttributeEdit *> &edit_list, AdInterface &ad, const AdObject &object); using QObject::QObject; // Load state from object, used to initialize or // reset edit. virtual void load(AdInterface &ad, const AdObject &object); // Verify current input. This is for the kinds of errors // that the server doesn't or can't check for. For // example password confirmation matching password. // Should be called before apply(). virtual bool verify(AdInterface &ad, const QString &dn) const; // Apply current input by making a modification to the // AD server virtual bool apply(AdInterface &ad, const QString &dn) const; virtual void set_enabled(const bool enabled); signals: // Emitted when edit was edited by user void edited(); }; #endif /* ATTRIBUTE_EDIT_H */
2,737
C++
.h
64
39.375
103
0.733734
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,926
expiry_widget.h
altlinux_admc/src/admc/attribute_edits/expiry_widget.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef EXPIRY_WIDGET_H #define EXPIRY_WIDGET_H #include <QWidget> class AdInterface; class AdObject; namespace Ui { class ExpiryWidget; } class ExpiryWidget final : public QWidget { Q_OBJECT public: Ui::ExpiryWidget *ui; ExpiryWidget(QWidget *parent = nullptr); ~ExpiryWidget(); void load(const AdObject &object); bool apply(AdInterface &ad, const QString &dn) const; signals: void edited(); private: QString get_new_value() const; void on_never_check(); void on_end_of_check(); }; #endif /* EXPIRY_WIDGET_H */
1,336
C++
.h
43
28.488372
72
0.741231
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,927
datetime_edit.h
altlinux_admc/src/admc/attribute_edits/datetime_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef DATETIME_EDIT_H #define DATETIME_EDIT_H #include "attribute_edits/attribute_edit.h" #include <QString> class QDateTimeEdit; class DateTimeEdit final : public AttributeEdit { Q_OBJECT public: DateTimeEdit(QDateTimeEdit *edit, const QString &attribute_arg, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; private: QString attribute; QDateTimeEdit *edit; }; #endif /* DATETIME_EDIT_H */
1,292
C++
.h
35
34.485714
85
0.759808
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,928
manager_widget.h
altlinux_admc/src/admc/attribute_edits/manager_widget.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef MANAGER_WIDGET_H #define MANAGER_WIDGET_H #include <QWidget> class AdObject; class AdInterface; namespace Ui { class ManagerWidget; } class ManagerWidget final : public QWidget { Q_OBJECT public: Ui::ManagerWidget *ui; ManagerWidget(QWidget *parent = nullptr); ~ManagerWidget(); void set_attribute(const QString &attribute); void load(const AdObject &object); bool apply(AdInterface &ad, const QString &dn) const; QString get_manager() const; void reset(); signals: void edited(); private slots: void on_change(); void on_properties(); void on_clear(); private: QString manager_attribute; QString current_value; void load_value(const QString &value); }; #endif /* MANAGER_WIDGET_H */
1,544
C++
.h
50
27.96
72
0.739865
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,929
group_type_edit.h
altlinux_admc/src/admc/attribute_edits/group_type_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef GROUP_TYPE_EDIT_H #define GROUP_TYPE_EDIT_H #include "attribute_edits/attribute_edit.h" class QComboBox; class GroupTypeEdit final : public AttributeEdit { Q_OBJECT public: GroupTypeEdit(QComboBox *combo, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; private: QComboBox *combo; }; #endif /* GROUP_TYPE_EDIT_H */
1,217
C++
.h
33
34.515152
72
0.75616
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,930
expiry_edit.h
altlinux_admc/src/admc/attribute_edits/expiry_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef EXPIRY_EDIT_H #define EXPIRY_EDIT_H #include "attribute_edits/attribute_edit.h" class ExpiryWidget; class ExpiryEdit final : public AttributeEdit { Q_OBJECT public: ExpiryEdit(ExpiryWidget *edit_widget, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; void set_enabled(const bool enabled) override; private: ExpiryWidget *edit_widget; QString get_new_value() const; }; #endif /* EXPIRY_EDIT_H */
1,307
C++
.h
35
34.8
72
0.755538
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,931
upn_suffix_combo.h
altlinux_admc/src/admc/attribute_edits/upn_suffix_combo.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef UPN_SUFFIX_COMBO_H #define UPN_SUFFIX_COMBO_H class AdInterface; class AdObject; class QComboBox; void upn_suffix_combo_init(QComboBox *combo, AdInterface &ad); void upn_suffix_combo_load(QComboBox *combo, const AdObject &object); #endif /* UPN_SUFFIX_COMBO_H */
1,049
C++
.h
27
37.037037
72
0.764244
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,932
sam_name_edit.h
altlinux_admc/src/admc/attribute_edits/sam_name_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef SAM_NAME_EDIT_H #define SAM_NAME_EDIT_H #include "attribute_edits/attribute_edit.h" class QLineEdit; class SamNameEdit final : public AttributeEdit { Q_OBJECT public: SamNameEdit(QLineEdit *edit, QLineEdit *domain_edit, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool verify(AdInterface &ad, const QString &dn) const override; bool apply(AdInterface &ad, const QString &dn) const override; void set_enabled(const bool enabled); private: QLineEdit *edit; }; bool sam_name_edit_verify(QLineEdit *edit); #endif /* SAM_NAME_EDIT_H */
1,385
C++
.h
36
35.944444
74
0.754478
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,933
logon_computers_dialog.h
altlinux_admc/src/admc/attribute_edits/logon_computers_dialog.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef LOGON_COMPUTERS_DIALOG_H #define LOGON_COMPUTERS_DIALOG_H #include <QDialog> namespace Ui { class LogonComputersDialog; } class LogonComputersDialog final : public QDialog { Q_OBJECT public: Ui::LogonComputersDialog *ui; LogonComputersDialog(const QString &value, QWidget *parent); ~LogonComputersDialog(); QString get() const; private: void on_add_button(); void on_remove_button(); }; #endif /* LOGON_COMPUTERS_DIALOG_H */
1,244
C++
.h
37
31.135135
72
0.754591
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,934
logon_hours_edit.h
altlinux_admc/src/admc/attribute_edits/logon_hours_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef LOGON_HOURS_EDIT_H #define LOGON_HOURS_EDIT_H #include "attribute_edits/attribute_edit.h" class QPushButton; class LogonHoursEdit final : public AttributeEdit { Q_OBJECT public: LogonHoursEdit(QPushButton *button, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; private: QPushButton *button; QByteArray current_value; void open_dialog(); }; #endif /* LOGON_HOURS_EDIT_H */
1,285
C++
.h
35
34.171429
72
0.756039
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,935
string_edit.h
altlinux_admc/src/admc/attribute_edits/string_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef STRING_EDIT_H #define STRING_EDIT_H #include "attribute_edits/attribute_edit.h" class QLineEdit; class StringEdit final : public AttributeEdit { Q_OBJECT public: StringEdit(QLineEdit *edit_arg, const QString &attribute_arg, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool apply(AdInterface &ad, const QString &dn) const override; void set_enabled(const bool enabled) override; private: QLineEdit *edit; QString attribute; friend class StringOtherEdit; }; #endif /* STRING_EDIT_H */
1,340
C++
.h
36
34.611111
83
0.756173
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,936
upn_edit.h
altlinux_admc/src/admc/attribute_edits/upn_edit.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef UPN_EDIT_H #define UPN_EDIT_H #include "attribute_edits/attribute_edit.h" class QLineEdit; class AdInterface; class QComboBox; class UpnEdit final : public AttributeEdit { Q_OBJECT public: UpnEdit(QLineEdit *prefix_edit, QComboBox *suffix_combo, QObject *parent); void load(AdInterface &ad, const AdObject &object) override; bool verify(AdInterface &ad, const QString &dn) const override; bool apply(AdInterface &ad, const QString &dn) const override; void init_suffixes(AdInterface &ad); private: QLineEdit *prefix_edit; QComboBox *upn_suffix_combo; friend class StringOtherEdit; QString get_new_value() const; void on_suffix_combo_changed(); void update_prefix_limit(); }; #endif /* UPN_EDIT_H */
1,539
C++
.h
42
33.833333
78
0.750504
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,937
rename_user_dialog.h
altlinux_admc/src/admc/rename_dialogs/rename_user_dialog.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef RENAME_USER_DIALOG_H #define RENAME_USER_DIALOG_H #include "rename_object_dialog.h" class AdInterface; class RenameObjectHelper; namespace Ui { class RenameUserDialog; } class RenameUserDialog final : public RenameObjectDialog { Q_OBJECT public: Ui::RenameUserDialog *ui; RenameUserDialog(AdInterface &ad, const QString &target, QWidget *parent); ~RenameUserDialog(); void accept() override; QString get_new_dn() const override; private: RenameObjectHelper *helper; }; #endif /* RENAME_USER_DIALOG_H */
1,323
C++
.h
39
31.487179
78
0.761381
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,938
rename_policy_dialog.h
altlinux_admc/src/admc/rename_dialogs/rename_policy_dialog.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef RENAME_POLICY_DIALOG_H #define RENAME_POLICY_DIALOG_H /** * Special rename dialog for policy objects. Policy objects * are never renamed because their names are GUID's. Instead * their display name attribute is modified. */ #include <QDialog> class QPushButton; class AdInterface; namespace Ui { class RenamePolicyDialog; } class RenamePolicyDialog final : public QDialog { Q_OBJECT public: Ui::RenamePolicyDialog *ui; RenamePolicyDialog(AdInterface &ad, const QString &target_dn, QWidget *parent); ~RenamePolicyDialog(); void accept() override; private: QString target_dn; QString target_name; private slots: void on_edited(); }; #endif /* RENAME_DIALOG_POLICY_H */
1,497
C++
.h
46
30.108696
83
0.75886
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,939
rename_group_dialog.h
altlinux_admc/src/admc/rename_dialogs/rename_group_dialog.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef RENAME_GROUP_DIALOG_H #define RENAME_GROUP_DIALOG_H #include "rename_object_dialog.h" class AdInterface; class RenameObjectHelper; namespace Ui { class RenameGroupDialog; } class RenameGroupDialog final : public RenameObjectDialog { Q_OBJECT public: Ui::RenameGroupDialog *ui; RenameGroupDialog(AdInterface &ad, const QString &target, QWidget *parent); ~RenameGroupDialog(); void accept() override; QString get_new_dn() const override; private: RenameObjectHelper *helper; }; #endif /* RENAME_GROUP_DIALOG_H */
1,331
C++
.h
39
31.692308
79
0.762871
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,940
rename_other_dialog.h
altlinux_admc/src/admc/rename_dialogs/rename_other_dialog.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef RENAME_OTHER_DIALOG_H #define RENAME_OTHER_DIALOG_H #include "rename_object_dialog.h" class AdInterface; class RenameObjectHelper; namespace Ui { class RenameOtherDialog; } class RenameOtherDialog final : public RenameObjectDialog { Q_OBJECT public: Ui::RenameOtherDialog *ui; RenameOtherDialog(AdInterface &ad, const QString &target, QWidget *parent); ~RenameOtherDialog(); void accept() override; QString get_new_dn() const override; private: RenameObjectHelper *helper; }; #endif /* RENAME_OTHER_DIALOG_H */
1,331
C++
.h
39
31.692308
79
0.762871
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,941
rename_object_dialog.h
altlinux_admc/src/admc/rename_dialogs/rename_object_dialog.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef RENAME_OBJECT_DIALOG_H #define RENAME_OBJECT_DIALOG_H #include <QDialog> class RenameObjectDialog : public QDialog { public: using QDialog::QDialog; virtual QString get_new_dn() const = 0; }; #endif /* RENAME_OBJECT_DIALOG_H */
1,024
C++
.h
28
34.428571
72
0.753535
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,942
policy_results_widget.h
altlinux_admc/src/admc/results_widgets/policy_results_widget.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef POLICY_RESULTS_WIDGET_H #define POLICY_RESULTS_WIDGET_H /** * Displays OU's linked to currently selected policy. */ #include <QWidget> #include "gplink.h" class QStandardItemModel; class QStandardItem; class QMenu; class ResultsView; class ADMCTestPolicyResultsWidget; namespace Ui { class PolicyResultsWidget; } class PolicyResultsWidget final : public QWidget { Q_OBJECT public: Ui::PolicyResultsWidget *ui; PolicyResultsWidget(QWidget *parent); ~PolicyResultsWidget(); // Loads links for this policy. Nothing is done if given // index is not a policy. void update(const QModelIndex &index); void update(const QString &gpo); ResultsView *get_view() const; QString get_current_gpo() const; signals: void ou_gplink_changed(const QString &ou_dn, const Gplink &gplink, const QString &policy_dn, GplinkOption option = GplinkOption_NoOption); private: QStandardItemModel *model; QString gpo; QMenu *context_menu; void on_item_changed(QStandardItem *item); void open_context_menu(const QPoint &pos); void delete_link(); friend class ADMCTestPolicyResultsWidget; }; #endif /* POLICY_RESULTS_WIDGET_H */
1,970
C++
.h
58
31.086207
142
0.757256
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,943
drag_drop_links_model.h
altlinux_admc/src/admc/results_widgets/policy_ou_results_widget/drag_drop_links_model.h
#ifndef DRAGDROPLINKSMODEL_H #define DRAGDROPLINKSMODEL_H #include <QStandardItemModel> #include <QSet> #include <QMap> #include "gplink.h" template <class T> class QList; class QPersistentModelIndex; enum LinkedPoliciesColumn { LinkedPoliciesColumn_Order, LinkedPoliciesColumn_Name, LinkedPoliciesColumn_Enforced, LinkedPoliciesColumn_Disabled, LinkedPoliciesColumn_COUNT, }; enum LinkedPoliciesRole { LinkedPoliciesRole_DN = Qt::UserRole + 1, LinkedPoliciesRole_COUNT, }; const QSet<LinkedPoliciesColumn> option_columns = { LinkedPoliciesColumn_Enforced, LinkedPoliciesColumn_Disabled, }; const QMap<LinkedPoliciesColumn, GplinkOption> column_to_option = { {LinkedPoliciesColumn_Enforced, GplinkOption_Enforced}, {LinkedPoliciesColumn_Disabled, GplinkOption_Disabled}, }; class DragDropLinksModel : public QStandardItemModel { Q_OBJECT public: explicit DragDropLinksModel(const Gplink &gplink, int rows, int columns, QObject *parent = nullptr); virtual QMimeData *mimeData(const QModelIndexList &indexes) const override; virtual Qt::DropActions supportedDropActions() const override; virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const; void arrange_orders_from_gplink(const Gplink &gplink); void update_sort_column(LinkedPoliciesColumn column); signals: void link_orders_changed(const Gplink &gplink); private: const QString links_model_mime_type = "application/vnd.text.list"; const Gplink &gplink_ref; LinkedPoliciesColumn sort_column; void load_row(QList<QStandardItem*> &item_row, int order, const QString &dn, const QString &display_name); }; #endif // DRAGDROPLINKSMODEL_H
1,902
C++
.h
48
36.270833
133
0.791508
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,944
policy_ou_results_widget.h
altlinux_admc/src/admc/results_widgets/policy_ou_results_widget/policy_ou_results_widget.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef POLICY_OU_RESULTS_WIDGET_H #define POLICY_OU_RESULTS_WIDGET_H /** * Displays OU's linked to currently selected policy. */ #include <QWidget> class ConsoleWidget; class LinkedPoliciesWidget; class InheritedPoliciesWidget; //class ADMCTestPolicyOUResultsWidget; namespace Ui { class PolicyOUResultsWidget; } class PolicyOUResultsWidget final : public QWidget { Q_OBJECT public: Ui::PolicyOUResultsWidget *ui; PolicyOUResultsWidget(ConsoleWidget *console); ~PolicyOUResultsWidget(); // Loads links for given OU. Nothing is done if given // index is not an OU in policy tree. void update(const QModelIndex &index); void update_inheritance_widget(const QModelIndex &index); void update_links_widget(const QModelIndex &index); private: ConsoleWidget *console; LinkedPoliciesWidget *links_widget; InheritedPoliciesWidget *inheritance_widget; // friend ADMCTestPolicyOUResultsWidget; }; #endif /* POLICY_OU_RESULTS_WIDGET_H */
1,767
C++
.h
50
32.66
72
0.770674
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,945
policy_ou_results_widget_p.h
altlinux_admc/src/admc/results_widgets/policy_ou_results_widget/policy_ou_results_widget_p.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef POLICY_OU_RESULTS_WIDGET_P_H #define POLICY_OU_RESULTS_WIDGET_P_H enum LinkedPoliciesColumn { PolicyOUResultsColumn_Order, PolicyOUResultsColumn_Name, LinkedPoliciesColumn_Enforced, LinkedPoliciesColumn_Disabled, PolicyOUResultsColumn_COUNT, }; #endif /* POLICY_OU_RESULTS_WIDGET_P_H */
1,093
C++
.h
29
35.241379
72
0.766038
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,946
linked_policies_widget.h
altlinux_admc/src/admc/results_widgets/policy_ou_results_widget/linked_policies_widget.h
#ifndef LINKED_POLICIES_WIDGET_H #define LINKED_POLICIES_WIDGET_H #include "gplink.h" #include <QWidget> class QStandardItemModel; class QStandardItem; class QMenu; class ResultsView; class ConsoleWidget; class ADMCTestPolicyOUResultsWidget; class AdObject; class AdInterface; class DragDropLinksModel; namespace Ui { class LinkedPoliciesWidget; } class LinkedPoliciesWidget final : public QWidget { Q_OBJECT public: explicit LinkedPoliciesWidget(ConsoleWidget *console_arg, QWidget *parent = nullptr); ~LinkedPoliciesWidget(); // Loads links for given OU. Nothing is done if given // index is not an OU in policy tree. void update(const QModelIndex &ou_index); signals: void gplink_changed(const QModelIndex &index); private: Ui::LinkedPoliciesWidget *ui; ConsoleWidget *console; DragDropLinksModel *model; Gplink gplink; QString ou_dn; QMenu *context_menu; void on_item_changed(QStandardItem *item); void open_context_menu(const QPoint &pos); void remove_link(); void move_up(); void move_down(); void update_link_items(); void modify_gplink(void (*modify_function)(Gplink &, const QString &)); void update_policy_link_icons(const QModelIndex &changed_item_index, bool is_checked, GplinkOption option); QList<AdObject> gpo_object_list(AdInterface &ad); void load_item_row(const AdObject &gpo_object, QList<QStandardItem*> row); }; #endif // LINKED_POLICIES_WIDGET_H
1,472
C++
.h
45
29.4
111
0.761837
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,947
inherited_policies_widget.h
altlinux_admc/src/admc/results_widgets/policy_ou_results_widget/inherited_policies_widget.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2023 BaseALT Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef INHERITED_POLICIES_WIDGET_H #define INHERITED_POLICIES_WIDGET_H #include <QWidget> #include <QModelIndex> namespace Ui { class InheritedPoliciesWidget; } class QStandardItemModel; class ConsoleWidget; class QStandardItem; class QStringList; class InheritedPoliciesWidget final : public QWidget { Q_OBJECT public: enum InheritedPoliciesColumns { InheritedPoliciesColumns_Prority, InheritedPoliciesColumns_Name, InheritedPoliciesColumns_Location, InheritedPoliciesColumns_Status, InheritedPoliciesColumns_COUNT }; enum RowRoles { RowRole_DN = Qt::UserRole + 1, RowRole_IsEnforced, }; explicit InheritedPoliciesWidget(ConsoleWidget *console_arg, QWidget *parent = nullptr); ~InheritedPoliciesWidget(); void update(const QModelIndex &index); void hide_not_enforced_inherited_links(bool hide); private: QStandardItemModel *model; Ui::InheritedPoliciesWidget *ui; ConsoleWidget *console; QModelIndex selected_scope_index; void add_enabled_policy_items(const QModelIndex &index, bool inheritance_blocked = false); void remove_link_duplicates(); void set_priority_to_items(); void load_item(const QList<QStandardItem *> row, const QModelIndex &ou_index, const QString &policy_dn, bool is_enforced); }; #endif // INHERITED_POLICIES_WIDGET_H
2,106
C++
.h
59
32.101695
126
0.760453
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,948
pso_results_widget.h
altlinux_admc/src/admc/results_widgets/pso_results_widget/pso_results_widget.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2024 BaseALT Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef PSO_RESULTS_WIDGET_H #define PSO_RESULTS_WIDGET_H #include <QWidget> #include "ad_object.h" namespace Ui { class PSOResultsWidget; } class PSOResultsWidget : public QWidget { Q_OBJECT public: explicit PSOResultsWidget(QWidget *parent = nullptr); ~PSOResultsWidget(); void update(const QModelIndex &index); void update(const AdObject &pso); private: Ui::PSOResultsWidget *ui; AdObject saved_pso_object; void on_apply(); void on_edit(); void on_cancel(); QStringList changed_setting_attrs(); void set_editable(bool is_editable); }; #endif // PSO_RESULTS_WIDGET_H
1,357
C++
.h
43
28.813953
72
0.744632
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,949
pso_edit_widget.h
altlinux_admc/src/admc/results_widgets/pso_results_widget/pso_edit_widget.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2024 BaseALT Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef PSO_EDIT_WIDGET_H #define PSO_EDIT_WIDGET_H #include <QWidget> namespace Ui { class PSOEditWidget; } class AdObject; class QListWidgetItem; class QLineEdit; class QSpinBox; class QCheckBox; class PSOEditWidget final : public QWidget { Q_OBJECT public: explicit PSOEditWidget(QWidget *parent = nullptr); ~PSOEditWidget(); void update(const AdObject &passwd_settings_obj); void update_defaults(); void set_read_only(bool read_only); /*! * Gets password setting attribute's values hash */ QHash<QString, QList<QByteArray>> pso_settings_values(); QHash<QString, QList<QString>> pso_settings_string_values(); QStringList applied_dn_list() const; QLineEdit *name_line_edit(); /*! * Compares current settings with default (except name and precedence). * Returns true if at least one is not default. */ bool settings_are_default(); private: Ui::PSOEditWidget *ui; QStringList dn_applied_list; QHash<QString, QList<QByteArray>> default_setting_values; void on_add(); void on_remove(); /*! * Returns appropriate timespan unit value depending on given attribute. * It is used to fill password timespan setting checkboxes. */ int spinbox_timespan_units(const AdObject &obj, const QString &attribute); enum AppliedItemRole { AppliedItemRole_DN = Qt::UserRole }; }; #endif // PSO_EDIT_WIDGET_H
2,168
C++
.h
65
29.784615
78
0.729057
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,950
domain_info_results_widget.h
altlinux_admc/src/admc/results_widgets/domain_info_results_widget/domain_info_results_widget.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2023 BaseALT Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef DOMAIN_INFO_RESULTS_WIDGET_H #define DOMAIN_INFO_RESULTS_WIDGET_H #include <QWidget> namespace Ui { class DomainInfoResultsWidget; } class ConsoleWidget; class AdInterface; class QStandardItemModel; class AdObject; class QStandardItem; class QSpinBox; template <typename T, typename U> class QHash; class QLabel; struct DomainInfo_SearchResults { QList<QStandardItem*> tree_items; QString domain_functional_level; QString forest_functional_level; QString domain_schema_version; QString domain_controller_version; }; class DomainInfoResultsWidget : public QWidget { Q_OBJECT enum DomainInfoTreeItemRole { DomainInfoTreeItemRole_DN = Qt::UserRole + 1, DomainInfoTreeItemRole_ItemType, DomainInfoRole_COUNT }; enum DomainInfoTreeItemType { DomainInfoTreeItemType_Site, DomainInfoTreeItemType_ServersContainer, DomainInfoTreeItemType_Host, DomainInfoTreeItemType_FSMO_Container, DomainInfoTreeItemType_FSMO_Role, DomainInfoTreeItemType_COUNT }; enum DomainSchemaVersion { DomainSchemaVersion_WindowsServer2008R2 = 47, DomainSchemaVersion_WindowsServer2012 = 56, DomainSchemaVersion_WindowsServer2012R2 = 69, DomainSchemaVersion_WindowsServer2016 = 87, DomainSchemaVersion_WindowsServer2019 = 88, }; public: explicit DomainInfoResultsWidget(ConsoleWidget *console_arg); ~DomainInfoResultsWidget(); void update(); public slots: void update_fsmo_roles(const QString &new_master_dn, const QString &fsmo_role_string); private: Ui::DomainInfoResultsWidget *ui; ConsoleWidget *console; QStandardItemModel *model; void update_defaults(); QList<QStandardItem*> get_tree_items(AdInterface &ad); DomainInfo_SearchResults search_results(); void populate_widgets(DomainInfo_SearchResults results); void add_host_items(QStandardItem *site_item, const AdObject &site_object, AdInterface &ad); void set_label_failed(QLabel *label, bool failed); QStandardItem *add_tree_item(const QString &text, const QIcon &icon, DomainInfoTreeItemType type, QStandardItem *parent_item = nullptr); QString schema_version_to_string(int version); QString functionality_level_to_string(int level); }; #endif // DOMAIN_INFO_RESULTS_WIDGET_H
3,083
C++
.h
84
32.607143
140
0.762752
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,951
fsmo_tab.h
altlinux_admc/src/admc/fsmo/fsmo_tab.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef FSMO_TAB_H #define FSMO_TAB_H #include <QWidget> class AdInterface; namespace Ui { class FSMOTab; } class FSMOTab final : public QWidget { Q_OBJECT public: Ui::FSMOTab *ui; FSMOTab(const QString &title, const QString &role_dn); ~FSMOTab(); void load(AdInterface &ad); private: QString role_dn; void change_master(); signals: // TODO: Remove tabs and use signal from fsmo_dialog directly void master_changed(const QString &new_master_dn, const QString &string_fsmo_role); }; #endif /* FSMO_TAB_H */
1,328
C++
.h
41
29.780488
87
0.740392
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,952
fsmo_utils.h
altlinux_admc/src/admc/fsmo/fsmo_utils.h
#ifndef FSMO_UTILS_H #define FSMO_UTILS_H class QString; class AdInterface; class ConsoleWidget; extern bool gpo_edit_without_PDC_disabled; enum FSMORole { FSMORole_DomainDNS, FSMORole_ForestDNS, FSMORole_PDCEmulation, FSMORole_Schema, FSMORole_DomainNaming, FSMORole_Infrastructure, FSMORole_RidAllocation, FSMORole_COUNT, }; QString string_fsmo_role(FSMORole role); QString fsmo_string_from_dn(const QString &fsmo_role_dn); // Returns the DN of the object that // store's role's master in it's attributes QString dn_from_role(FSMORole role); FSMORole fsmo_role_from_dn(const QString &role_dn); QString current_master_for_role(AdInterface &ad, FSMORole role); // Returns dns host name of role's master object (DC) QString current_master_for_role_dn(AdInterface &ad, QString role_dn); bool current_dc_is_master_for_role(AdInterface &ad, FSMORole role); void connect_host_with_role(AdInterface &ad, FSMORole role); void connect_to_PDC_emulator(AdInterface &ad, ConsoleWidget *console); #endif // FSMO_UTILS_H
1,054
C++
.h
29
33.758621
70
0.785361
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,953
fsmo_dialog.h
altlinux_admc/src/admc/fsmo/fsmo_dialog.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef FSMO_DIALOG_H #define FSMO_DIALOG_H /** * Dialog for viewing and editing FSMO roles. */ #include <QDialog> class AdInterface; namespace Ui { class FSMODialog; } class FSMODialog : public QDialog { Q_OBJECT public: Ui::FSMODialog *ui; FSMODialog(AdInterface &ad, QWidget *parent); ~FSMODialog(); private slots: void gpo_edit_PDC_check_toggled(bool is_checked); signals: void master_changed(const QString &new_master_dn, const QString &string_fsmo_role); }; #endif /* FSMO_DIALOG_H */
1,303
C++
.h
41
29.414634
87
0.748
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,954
customize_columns_dialog.h
altlinux_admc/src/admc/console_widget/customize_columns_dialog.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef CUSTOMIZE_COLUMNS_DIALOG_H #define CUSTOMIZE_COLUMNS_DIALOG_H /** * Dialog for customizing columns of a view. Presents a list * of checkbox which correspond to view's columns. When * dialog is accepted, the columns that were unchecked are * hidden. Used by console widgets for results views but may * be used for other views as well. */ #include <QDialog> class CustomizeColumnsDialogPrivate; class QTreeView; class CustomizeColumnsDialog final : public QDialog { Q_OBJECT public: CustomizeColumnsDialog(QTreeView *view, const QList<int> &default_columns, QWidget *parent); public slots: void accept() override; private: CustomizeColumnsDialogPrivate *d; }; #endif /* CUSTOMIZE_COLUMNS_DIALOG_H */
1,511
C++
.h
41
34.658537
96
0.769336
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,955
customize_columns_dialog_p.h
altlinux_admc/src/admc/console_widget/customize_columns_dialog_p.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef CUSTOMIZE_COLUMNS_DIALOG_P_H #define CUSTOMIZE_COLUMNS_DIALOG_P_H /** * Private header for CustomizeColumnsDialog. */ class CustomizeColumnsDialog; class QTreeView; class QCheckBox; class CustomizeColumnsDialogPrivate final : public QObject { public: QList<int> default_columns; QList<QCheckBox *> checkbox_list; QTreeView *view; CustomizeColumnsDialogPrivate(CustomizeColumnsDialog *q); void restore_defaults(); }; #endif /* CUSTOMIZE_COLUMNS_DIALOG_P_H */
1,270
C++
.h
36
32.944444
72
0.767537
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,957
console_impl.h
altlinux_admc/src/admc/console_widget/console_impl.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef CONSOLE_IMPL_H #define CONSOLE_IMPL_H /** * Base class for implementing item logic specific to * different item types. You should implement this class for * each type of item that you use. Implemented functions * will be called by console. */ #include <QObject> #include "console_widget/console_widget.h" class ConsoleWidget; class ResultsView; class ConsoleImpl : public QObject { Q_OBJECT public: ConsoleImpl(ConsoleWidget *console_arg); // Called when a scope item of this type. Fetching // happens when using the user selects or expands an // item for the first time. Typically this is where you // would load children of an item, if they need to be // loaded dynamically. If children of your item type are // static, you don't need to implement this. virtual void fetch(const QModelIndex &index); // Called when items are dragged on top of an item of // this type to determine whether dropping is allowed. // Note that dragged items may be of any type and even // contain mixed types. virtual bool can_drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type); // Called when items are dropped onto item of this type. // In the implementation, move items or perform other // operations as necessary. virtual void drop(const QList<QPersistentModelIndex> &dropped_list, const QSet<int> &dropped_type_list, const QPersistentModelIndex &target, const int target_type); // Called when description bar text needs to be updated // and currently selected scope item is of this type. // Return whatever text should be displayed. virtual QString get_description(const QModelIndex &index) const; // Called when an item of this type is activated, by // being double clicked or pressed enter on. Implement // appropriate response if needed. virtual void activate(const QModelIndex &index); // Called when an item of this type is selected in the // scope pane. virtual void selected_as_scope(const QModelIndex &index); // Return all custom actions that are available for this // type. This will be used to determine the order of // actions in the menu. virtual QList<QAction *> get_all_custom_actions() const; // Return a set of custom actions that should be // disabled virtual QSet<QAction *> get_disabled_custom_actions(const QModelIndex &index, const bool single_selection) const; // Return all custom actions that are available for this // item. This should be a subset of all possible // actions. virtual QSet<QAction *> get_custom_actions(const QModelIndex &index, const bool single_selection) const; // Return a set of standard actions that should be // displayed for this item virtual QSet<StandardAction> get_standard_actions(const QModelIndex &index, const bool single_selection) const; // Return a set of standard actions that should be // disabled virtual QSet<StandardAction> get_disabled_standard_actions(const QModelIndex &index, const bool single_selection) const; // NOTE: It is possible to select indexes of mixed type. // For this reason, action f-ns will be called with // index lists that only contain indexes of the same // type as this impl. Use this list, NOT the // list from console's get_selected_items(). // Implementations of standard actions. Note that you // don't have to implement all of these, only the ones // that you return from get_standard_actions(). virtual void copy(const QList<QModelIndex> &index_list); virtual void cut(const QList<QModelIndex> &index_list); virtual void rename(const QList<QModelIndex> &index_list); virtual void delete_action(const QList<QModelIndex> &index_list); virtual void paste(const QList<QModelIndex> &index_list); virtual void print(const QList<QModelIndex> &index_list); virtual void refresh(const QList<QModelIndex> &index_list); virtual void properties(const QList<QModelIndex> &index_list); // Override to provide custom header labels and default // columns. You need to do this if you are defining a // results view. virtual QList<QString> column_labels() const; virtual QList<int> default_columns() const; virtual void update_results_widget(const QModelIndex &index) const; QVariant save_state() const; void restore_state(const QVariant &state); QWidget *widget() const; ResultsView *view() const; protected: ConsoleWidget *console; // Here are the options for results widget and view: // 1. Widget only - provide your own custom widget using // set_results_widget(). // 2. View only - provide a view using // set_results_view(). // 3. View and widget - provide both using setters. // Default behavior is a blank widget. void set_results_view(ResultsView *view); void set_results_widget(QWidget *widget); private: ResultsView *results_view; QWidget *results_widget; }; #endif /* CONSOLE_IMPL_H */
5,917
C++
.h
121
44.702479
172
0.735784
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,958
results_view.h
altlinux_admc/src/admc/console_widget/results_view.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef RESULTS_VIEW_H #define RESULTS_VIEW_H /** * This view is really a container for multiple view types: * icons, list and details (tree view). Wraps some signals * and functions for child views and provides a way to * switch between views. */ #include <QWidget> class QTreeView; class QStackedWidget; class QAbstractItemView; class QAbstractItemModel; class QSortFilterProxyModel; class QModelIndex; enum ResultsViewType { ResultsViewType_Icons, ResultsViewType_List, ResultsViewType_Detail, }; class ResultsView final : public QWidget { Q_OBJECT public: ResultsView(QWidget *parent); void set_model(QAbstractItemModel *model); void set_parent(const QModelIndex &source_index); void set_view_type(const ResultsViewType type); QAbstractItemView *current_view() const; ResultsViewType current_view_type() const; QTreeView *detail_view() const; // Returns selected indexes in current view. If current // view type is detail (QTreeView), then returns one // index per selected row at column 0 QList<QModelIndex> get_selected_indexes() const; QVariant save_state() const; // NOTE: if state is empty, default columns are shown // and others are hidden void restore_state(const QVariant &state, const QList<int> &default_columns); void set_drag_drop_enabled(const bool enabled); void set_drag_drop_internal(); void set_row_hidden(int row, bool hidden); signals: void activated(const QModelIndex &index); void context_menu(const QPoint pos); void selection_changed(); private: QStackedWidget *stacked_widget; QHash<ResultsViewType, QAbstractItemView *> views; QSortFilterProxyModel *proxy_model; ResultsViewType m_current_view_type; QTreeView *m_detail_view; void on_item_activated(const QModelIndex &index); }; #endif /* RESULTS_VIEW_H */
2,657
C++
.h
73
33.150685
81
0.753019
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,959
console_drag_model.h
altlinux_admc/src/admc/console_widget/console_drag_model.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef CONSOLE_DRAG_MODEL_H #define CONSOLE_DRAG_MODEL_H #include <QStandardItemModel> class ConsoleWidget; /** * Implements drag and drop. Note that this only implements * the framework for drag and drop. The actual logic is * implemented by console widget and console types. */ class ConsoleDragModel : public QStandardItemModel { Q_OBJECT public: ConsoleDragModel(ConsoleWidget *console_arg); QMimeData *mimeData(const QModelIndexList &indexes) const override; bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override; private: ConsoleWidget *console; }; #endif /* CONSOLE_DRAG_MODEL_H */
1,599
C++
.h
39
38.589744
134
0.769181
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,960
console_widget.h
altlinux_admc/src/admc/console_widget/console_widget.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef CONSOLE_WIDGET_H #define CONSOLE_WIDGET_H /** * The central widget of the app through which the user can * browse and manipulate objects. Contains two panes: * "scope" and "results". Scope pane contains a tree of * items. Each scope item has it's own "results" which are * displayed in the results pane when the scope item is * selected. Results can contain children of the scope item. * Results may also display a custom widget. Note that this * class only deals with general "items" and doesn't define * how items are loaded, displayed or interacted with. That * is defined by subclassing ConsoleImpl and registering * implementations using register_impl() function. * Implementations are assigned to item types which should * be defined outside of this class. */ #include <QWidget> class ConsoleWidgetPrivate; class QStandardItem; class QMenu; class ConsoleImpl; class ConsoleDragModel; #define UNUSED_ARG(x) (void) (x) enum ConsoleRolePublic { ConsoleRole_Type = Qt::UserRole + 19, // NOTE: when implementing custom roles, make sure they do // not conflict with console roles, like this: // // enum YourRole { // YourRole_First = ConsoleRole_LAST + 1, // YourRole_Second = ConsoleRole_LAST + 2, // ... // }; ConsoleRole_LAST = Qt::UserRole + 20, }; enum StandardAction { StandardAction_Copy, StandardAction_Cut, StandardAction_Rename, StandardAction_Delete, StandardAction_Paste, StandardAction_Print, StandardAction_Refresh, StandardAction_Properties, }; class ConsoleWidgetActions final { public: QAction *navigate_up; QAction *navigate_back; QAction *navigate_forward; QAction *refresh; QAction *customize_columns; QAction *view_icons; QAction *view_list; QAction *view_detail; QAction *toggle_console_tree; QAction *toggle_description_bar; }; class ConsoleWidget final : public QWidget { Q_OBJECT public: ConsoleWidget(QWidget *parent); // Sets and connects actions to internal slots // NOTE: must be called before restore_state(), so that // action state is restored void set_actions(const ConsoleWidgetActions &actions_arg); // NOTE: you must register all impl's before adding // items void register_impl(const int type, ConsoleImpl *impl); // These f-ns are for adding items to console. Items // returned from these f-ns should be used to set text, // icon and your custom data roles. add_scope_item() // adds an item that is shown both in scope and results. // add_results_item() adds an item that is shown only in // results. QList<QStandardItem *> add_scope_item(const int type, const QModelIndex &parent); QList<QStandardItem *> add_results_item(const int type, const QModelIndex &parent); // Deletes an item and all of it's columns void delete_item(const QModelIndex &index); // Sets current scope item in the scope tree void set_current_scope(const QModelIndex &index); // Calls refresh() of the console impl for this item // type void refresh_scope(const QModelIndex &index); // Gets selected item(s) from currently focused // view, which could be scope or results. Only the // main (first column) item is returned for each // selected row. There is always at least one // selected item. If results is currently focused // but has no selection, selected items from scope // are returned instead. QList<QModelIndex> get_selected_items(const int type) const; // Get a single selected item. Use if you are sure // that there's only one (dialog that uses one // selected item for example). QModelIndex get_selected_item(const int type) const; // NOTE: Search is inclusive, examining the given parent // and all of it's descendants. Pass QModelIndex() // parent to search the whole model. If no type is // given, then items of all types will be returned. QList<QModelIndex> search_items(const QModelIndex &parent, int role, const QVariant &value, const QList<int> &type = QList<int>()) const; QList<QModelIndex> search_items(const QModelIndex &parent, const QList<int> &type) const; // Single index versions of search f-ns. Use when you // expect only one valid result or none. QModelIndex() // is returned if no items are found. QModelIndex search_item(const QModelIndex &parent, int role, const QVariant &value, const QList<int> &type = QList<int>()) const; QModelIndex search_item(const QModelIndex &parent, const QList<int> &type) const; QModelIndex get_current_scope_item() const; int get_child_count(const QModelIndex &index) const; QStandardItem *get_item(const QModelIndex &index) const; QList<QStandardItem *> get_row(const QModelIndex &index) const; QVariant save_state() const; // NOTE: all impls should be registered before this is // called so that their state can be restored void restore_state(const QVariant &state); void delete_children(const QModelIndex &parent); void set_scope_view_visible(const bool visible); // Setups the action menu in menubar. Action menu opened // by right click is setup automatically. Note that this // must be called *after* all register_impl() calls. void setup_menubar_action_menu(QMenu *menu); // Define custom sort index for scope item. By default // scope items are sorted by their item text. Use sort // indexes if you need more fine-grained sort behavior. // Default sort index is "0". Note that this doesn't // affect order in results pane. void set_item_sort_index(const QModelIndex &index, const int sort_index); void update_current_item_results_widget(); // Gets current scope item's result widget for given // scope item index. Can return nullptr. QWidget *get_result_widget_for_index(const QModelIndex &index); // Removes all items from scope tree view except top domain info item. // It is used when domain changes. void clear_scope_tree(); void expand_item(const QModelIndex &index); QPersistentModelIndex domain_info_index(); signals: // Emitted when selection in the whole console // widget changes, both in scope and results panes. // Can be caused by selection change in focused // view or change of which view is focused. void selection_changed(); void fsmo_master_changed(const QString &new_master_dn, const QString &string_fsmo_role); protected: void resizeEvent(QResizeEvent *event) override; private: ConsoleWidgetPrivate *d; friend ConsoleDragModel; }; int console_item_get_type(const QModelIndex &index); bool console_item_get_was_fetched(const QModelIndex &index); #endif /* CONSOLE_WIDGET_H */
7,580
C++
.h
172
40.02907
141
0.730628
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,961
console_widget_p.h
altlinux_admc/src/admc/console_widget/console_widget_p.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef CONSOLE_WIDGET_P_H #define CONSOLE_WIDGET_P_H /** * Private header for ConsoleWidget. */ #include "console_widget/console_widget.h" #include "console_widget/results_view.h" #include <QCoreApplication> #include <QSet> #include <QPersistentModelIndex> class QLabel; class QStackedWidget; class ScopeProxyModel; class ConsoleDragModel; class QStandardItemModel; class ConsoleWidget; class QSplitter; class ConsoleImpl; enum ConsoleRole { // Determines whether scope item was fetched ConsoleRole_WasFetched = Qt::UserRole + 1, ConsoleRole_SortIndex = Qt::UserRole + 2, ConsoleRole_IsScope = Qt::UserRole + 3, // NOTE: don't go above ConsoleRole_Type and // ConsoleRole_LAST (defined in public header) // NOTE: these roles are "public" defined in public header // ConsoleRole_Type = Qt::UserRole + 19, // ConsoleRole_LAST = Qt::UserRole + 20 }; class ConsoleWidgetPrivate : public QObject { Q_OBJECT public: ConsoleWidget *q; QTreeView *scope_view; ConsoleDragModel *model; ScopeProxyModel *scope_proxy_model; QWidget *description_bar; QLabel *description_bar_left; QLabel *description_bar_right; QAbstractItemView *focused_view; QStackedWidget *results_stacked_widget; QSplitter *splitter; QHash<int, ConsoleImpl *> impl_map; QWidget *default_results_widget; ConsoleImpl *default_impl; ConsoleWidgetActions actions; QList<QPersistentModelIndex> dropped_list; QSet<int> dropped_type_list; // NOTE: target history stores target items' id's. // History lists are in order of ascending time. // ... past.last() -> current -> future.first() ... QList<QPersistentModelIndex> targets_past; QList<QPersistentModelIndex> targets_future; QHash<StandardAction, QAction *> standard_action_map; QPersistentModelIndex domain_info_index; ConsoleWidgetPrivate(ConsoleWidget *q_arg); void update_navigation_actions(); void update_view_actions(); void start_drag(const QList<QPersistentModelIndex> &dropped_list_arg); bool can_drop(const QModelIndex &target); void drop(const QModelIndex &target); void set_results_to_type(const ResultsViewType type); void fetch_scope(const QModelIndex &index); ConsoleImpl *get_current_scope_impl() const; ConsoleImpl *get_impl(const QModelIndex &index) const; void update_description(); QList<QModelIndex> get_all_selected_items() const; QList<QAction *> get_custom_action_list() const; void open_context_menu(const QPoint &global_pos); void add_actions(QMenu *menu); bool update_actions(); public slots: void on_current_scope_item_changed(const QModelIndex &current, const QModelIndex &); void on_scope_items_about_to_be_removed(const QModelIndex &parent, int first, int last); void on_focus_changed(QWidget *old, QWidget *now); void on_refresh(); void on_customize_columns(); void on_navigate_up(); void on_navigate_back(); void on_navigate_forward(); void on_view_icons(); void on_view_list(); void on_view_detail(); void on_toggle_console_tree(); void on_toggle_description_bar(); void on_standard_action(const StandardAction action_enum); void on_results_context_menu(const QPoint &pos); void on_scope_context_menu(const QPoint &pos); void on_scope_expanded(const QModelIndex &index); void on_results_activated(const QModelIndex &index); }; #endif /* CONSOLE_WIDGET_P_H */
4,266
C++
.h
111
34.63964
92
0.739173
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,962
ad_interface.h
altlinux_admc/src/adldap/ad_interface.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef AD_INTERFACE_H #define AD_INTERFACE_H /** * Interface to AD server. Provides a way to search and * modify objects. */ #include <QCoreApplication> #include <QHash> #include <QSet> #include "ad_defines.h" class AdInterfacePrivate; class QString; class QByteArray; class QDateTime; class AdObject; class AdConfig; template <typename T> class QList; typedef void TALLOC_CTX; enum AdMessageType { AdMessageType_Success, AdMessageType_Error }; // Some f-ns in this class reuse other f-ns and this // enum is used to turn off status messages of child // f-ns which are otherwise displayed by default. enum DoStatusMsg { DoStatusMsg_Yes, DoStatusMsg_No }; class AdCookie { public: AdCookie(); ~AdCookie(); bool more_pages() const; private: struct berval *cookie; friend class AdInterface; friend class AdInterfacePrivate; }; class AdMessage { public: AdMessage(const QString &text, const AdMessageType &type); QString text() const; AdMessageType type() const; private: QString m_text; AdMessageType m_type; }; class AdInterface { Q_DECLARE_TR_FUNCTIONS(AdInterface) public: AdInterface(); ~AdInterface(); /** * Set this config instance to be used for all * adinterface's going forward. If adconfig is unset, * AdInterface defaults to outputting raw attribute * values. Note that AdInterface is not responsible for * deleting AdConfig instance. */ static void set_config(AdConfig *config); static void set_log_searches(const bool enabled); static void set_dc(const QString &dc); static void set_sasl_nocanon(const bool is_on); static void set_port(const int port); static void set_cert_strategy(const CertStrategy strategy); static void set_domain_is_default(const bool is_default); static void set_custom_domain(const QString &domain); bool is_connected() const; QList<AdMessage> messages() const; bool any_error_messages() const; void clear_messages(); AdConfig *adconfig() const; QString client_user() const; bool logged_in_as_domain_admin(); QString get_dc() const; QString get_domain() const; // NOTE: Updates dc for AdInterface instance from static AdInterfacePrivate::s_dc. // It is needed when DC changes after AdInterface object was constructed. void update_dc(); // NOTE: If request attributes list is empty, all // attributes are returned // This is a simplified version that searches all pages // in one go QHash<QString, AdObject> search(const QString &base, const SearchScope scope, const QString &filter, const QList<QString> &attributes, const bool get_sacl = false); // This is a more complicated version of search() which // separates the search process by pages as they arrive // from the server. In general you can use the simpler // search(). This version is for cases where you want to // display search results as they come in instead of all // at once. bool search_paged(const QString &base, const SearchScope scope, const QString &filter, const QList<QString> &attributes, QHash<QString, AdObject> *results, AdCookie *cookie, const bool get_sacl = false); // Simplest search f-n that only searches for attributes // of one object AdObject search_object(const QString &dn, const QList<QString> &attributes = QList<QString>(), const bool get_sacl = false); bool attribute_replace_values(const QString &dn, const QString &attribute, const QList<QByteArray> &values, const DoStatusMsg do_msg = DoStatusMsg_Yes, const bool set_dacl = false); bool attribute_replace_value(const QString &dn, const QString &attribute, const QByteArray &value, const DoStatusMsg do_msg = DoStatusMsg_Yes, const bool set_dacl = false); bool attribute_add_value(const QString &dn, const QString &attribute, const QByteArray &value, const DoStatusMsg do_msg = DoStatusMsg_Yes); bool attribute_delete_value(const QString &dn, const QString &attribute, const QByteArray &value, const DoStatusMsg do_msg = DoStatusMsg_Yes); bool attribute_replace_string(const QString &dn, const QString &attribute, const QString &value, const DoStatusMsg do_msg = DoStatusMsg_Yes); bool attribute_replace_int(const QString &dn, const QString &attribute, const int value, const DoStatusMsg do_msg = DoStatusMsg_Yes); bool attribute_replace_datetime(const QString &dn, const QString &attribute, const QDateTime &datetime); // NOTE: attrs_map should contain attribute values // that will be added to the newly created object. // Note that it *must* contain a valid value for // objectClass attribute. bool object_add(const QString &dn, const QHash<QString, QList<QString>> &attrs_map); // Simplified version that only only adds one // objectClass value bool object_add(const QString &dn, const QString &object_class); bool object_delete(const QString &dn, const DoStatusMsg do_msg = DoStatusMsg_Yes); bool object_move(const QString &dn, const QString &new_container); bool object_rename(const QString &dn, const QString &new_name); bool group_add_member(const QString &group_dn, const QString &user_dn); bool group_remove_member(const QString &group_dn, const QString &user_dn); bool group_set_scope(const QString &dn, GroupScope scope, const DoStatusMsg do_msg = DoStatusMsg_Yes); bool group_set_type(const QString &dn, GroupType type); bool user_set_primary_group(const QString &group_dn, const QString &user_dn); bool user_set_pass(const QString &dn, const QString &password, const DoStatusMsg do_msg = DoStatusMsg_Yes); bool user_set_account_option(const QString &dn, AccountOption option, bool set); bool user_unlock(const QString &dn); bool computer_reset_account(const QString &dn); // "dn_out" is set to the dn of created gpo bool gpo_add(const QString &name, QString &dn_out); bool gpo_delete(const QString &dn, bool *deleted_object); bool gpo_check_perms(const QString &gpo, bool *ok); bool gpo_sync_perms(const QString &gpo); bool gpo_get_sysvol_version(const AdObject &gpc_object, int *version); QString filesys_path_to_smb_path(const QString &filesys_path) const; private: AdInterfacePrivate *d; bool ldap_init(); void ldap_free(); }; QList<QString> get_domain_hosts(const QString &domain, const QString &site); #endif /* AD_INTERFACE_H */
7,238
C++
.h
156
42.480769
207
0.739847
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,963
ad_config.h
altlinux_admc/src/adldap/ad_config.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef AD_CONFIG_H #define AD_CONFIG_H /** * Provides access to constant server data, which includes * configuration data and some DN's. All of the data is * loaded once to avoid unnecessary server requests. */ #include "ad_defines.h" #include <QLocale> class AdConfigPrivate; class AdInterface; class QLocale; class QString; class QLineEdit; class QByteArray; template <typename T> class QList; // NOTE: name strings to reduce confusion typedef QString ObjectClass; typedef QString Attribute; class AdConfig { public: AdConfig(); ~AdConfig(); void load(AdInterface &ad, const QLocale &locale); QString domain() const; QString domain_dn() const; QString configuration_dn() const; QString schema_dn() const; QString partitions_dn() const; QString extended_rights_dn() const; QString policies_dn() const; bool control_is_supported(const QString &control_oid) const; QString domain_sid() const; QString get_attribute_display_name(const Attribute &attribute, const ObjectClass &objectClass) const; QString get_class_display_name(const ObjectClass &objectClass) const; QList<Attribute> get_columns() const; QString get_column_display_name(const Attribute &attribute) const; int get_column_index(const QString &attribute) const; QList<ObjectClass> get_filter_containers() const; QList<ObjectClass> get_possible_superiors(const QList<ObjectClass> &object_classes) const; ObjectClass get_parent_class(const ObjectClass &object_class) const; // Returns all ancestors of given class and the // given class itself QList<ObjectClass> get_inherit_chain(const ObjectClass &object_class) const; QList<Attribute> get_optional_attributes(const QList<ObjectClass> &object_classes) const; QList<Attribute> get_mandatory_attributes(const QList<ObjectClass> &object_classes) const; QList<Attribute> get_find_attributes(const ObjectClass &object_class) const; AttributeType get_attribute_type(const Attribute &attribute) const; LargeIntegerSubtype get_attribute_large_integer_subtype(const Attribute &attribute) const; bool get_attribute_is_number(const Attribute &attribute) const; bool get_attribute_is_single_valued(const Attribute &attribute) const; bool get_attribute_is_system_only(const Attribute &attribute) const; int get_attribute_range_upper(const Attribute &attribute) const; bool get_attribute_is_backlink(const Attribute &attribute) const; bool get_attribute_is_constructed(const Attribute &attribute) const; // Limit's edit's max valid input length based on // the upper range defined for attribute in schema void limit_edit(QLineEdit *edit, const QString &attribute); QByteArray get_right_guid(const QString &right_cn) const; QString get_right_name(const QByteArray &right_guid, const QLocale::Language language) const; int get_rights_valid_accesses(const QString &rights_cn) const; // Returns extended rights that apply to given // classes QList<QString> get_extended_rights_list(const QList<QString> &class_list) const; QString guid_to_attribute(const QByteArray &guid) const; QString guid_to_class(const QByteArray &guid) const; QList<QString> get_noncontainer_classes(); bool rights_applies_to_class(const QString &rights_cn, const QList<QString> &class_list) const; private: AdConfigPrivate *d; }; #endif /* AD_CONFIG_H */
4,219
C++
.h
92
42.25
105
0.763716
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,964
ad_filter.h
altlinux_admc/src/adldap/ad_filter.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef AD_FILTER_H #define AD_FILTER_H /** * Functions for constructing an LDAP filter. */ #include <QString> enum Condition { Condition_Contains, Condition_Equals, Condition_NotEquals, Condition_StartsWith, Condition_EndsWith, Condition_Set, Condition_Unset, Condition_COUNT, }; extern const QList<QString> filter_classes; QString filter_CONDITION(const Condition condition, const QString &attribute, const QString &value = QString()); // If arguments for AND/OR are empty, empty string is returned QString filter_AND(const QList<QString> &subfilters); QString filter_OR(const QList<QString> &subfilters); // Adds advanced view filter, depending on current advanced // view setting QString add_advanced_view_filter(const QString &filter); QString condition_to_display_string(const Condition condition); // Search all the way to the root through the chain of // ancestry until it finds a match. This method works only with DN-type // attributes QString filter_matching_rule_in_chain(const QString &attribute, const QString &dn_value); // Filter that accepts any DN from given list QString filter_dn_list(const QList<QString> &dn_list); #endif /* AD_FILTER_H */
1,982
C++
.h
51
36.607843
112
0.768629
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,965
ad_utils.h
altlinux_admc/src/adldap/ad_utils.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef AD_UTILS_H #define AD_UTILS_H /** * Various f-ns related to AD attributes which do not * interact with the server. */ #include "ad_defines.h" #include <QHash> class QString; class QDateTime; class QByteArray; class AdConfig; class QTranslator; class QLocale; bool large_integer_datetime_is_never(const QString &value); QString datetime_qdatetime_to_string(const QString &attribute, const QDateTime &datetime, const AdConfig *adconfig); QDateTime datetime_string_to_qdatetime(const QString &attribute, const QString &raw_value, const AdConfig *adconfig); QString account_option_string(const AccountOption &option); int account_option_bit(const AccountOption &option); int group_scope_bit(GroupScope scope); QString group_scope_string(GroupScope scope); QString group_type_string(GroupType type); QString group_type_string_adjective(GroupType type); QString filesys_path_to_smb_path(const QString &sysvol_path); QString extract_rid_from_sid(const QByteArray &sid, AdConfig *adconfig); bool ad_string_to_bool(const QString &string); QString dn_get_rdn(const QString &dn); QString dn_get_name(const QString &dn); QString dn_get_parent(const QString &dn); QString dn_get_parent_canonical(const QString &dn); QString dn_rename(const QString &dn, const QString &new_name); QString dn_move(const QString &dn, const QString &new_parent_dn); QString dn_canonical(const QString &dn); QString dn_from_name_and_parent(const QString &name, const QString &parent, const QString &object_class); QString get_default_domain_from_krb5(); int bitmask_set(const int input_mask, const int mask_to_set, const bool is_set); bool bitmask_is_set(const int input_mask, const int mask_to_read); // NOTE: uses a buffer that is capped at 100 strings, so // pointers returned from this become invalid after 99 more // calls. Only use this to give cstr args to C routines in // the same scope. Keep this far away from any recursion. const char *cstr(const QString &qstr); // NOTE: you must call Q_INIT_RESOURCE(adldap) before // calling this bool load_adldap_translation(QTranslator &translator, const QLocale &locale); QByteArray guid_string_to_bytes(const QString &guid_string); QByteArray sid_string_to_bytes(const QString &sid_string); QString attribute_type_display_string(const AttributeType type); QString int_to_hex_string(const int n); QHash<int, QString> attribute_value_bit_string_map(const QString &attribute); #endif /* AD_UTILS_H */
3,221
C++
.h
70
44.414286
117
0.784984
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,966
ad_interface_p.h
altlinux_admc/src/adldap/ad_interface_p.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef AD_INTERFACE_P_H #define AD_INTERFACE_P_H #include <QCoreApplication> #include <QList> #include <QMutex> class AdInterface; class AdConfig; class QString; typedef struct ldap LDAP; typedef struct _SMBCCTX SMBCCTX; class AdInterfacePrivate { Q_DECLARE_TR_FUNCTIONS(AdInterfacePrivate) friend AdInterface; static QMutex mutex; public: AdInterfacePrivate(AdInterface *q); LDAP *ld; bool is_connected; QString domain; QString dc; QString client_user; QList<AdMessage> messages; void success_message(const QString &msg, const DoStatusMsg do_msg = DoStatusMsg_Yes); void error_message(const QString &context, const QString &error, const DoStatusMsg do_msg = DoStatusMsg_Yes); void error_message_plain(const QString &text, const DoStatusMsg do_msg = DoStatusMsg_Yes); QString default_error() const; int get_ldap_result() const; bool search_paged_internal(const char *base, const int scope, const char *filter, char **attributes, QHash<QString, AdObject> *results, AdCookie *cookie, const bool get_sacl); bool connect_via_ldap(const char *uri); bool delete_gpt(const QString &parent_path); bool smb_path_is_dir(const QString &path, bool *ok); // Returns GPT contents including the root path, in // order of increasing depth, so root path is first QList<QString> gpo_get_gpt_contents(const QString &gpt_root_path, bool *ok); private: static AdConfig *adconfig; static bool s_log_searches; static QString s_dc; static void *s_sasl_nocanon; static int s_port; static bool s_domain_is_default; static QString s_custom_domain; static CertStrategy s_cert_strat; static SMBCCTX *smbc; AdInterface *q; }; #endif /* AD_INTERFACE_P_H */
2,540
C++
.h
66
35.106061
179
0.744214
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,967
ad_display.h
altlinux_admc/src/adldap/ad_display.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef ATTRIBUTE_DISPLAY_H #define ATTRIBUTE_DISPLAY_H /** * Functions for converting raw attribute values (bytes) * into strings fit for displaying to user. If no adconfig * is given, then raw attribute values are returned. */ class AdConfig; class QString; class QByteArray; template <typename T> class QList; QString attribute_display_value(const QString &attribute, const QByteArray &value, const AdConfig *adconfig); QString attribute_display_values(const QString &attribute, const QList<QByteArray> &values, const AdConfig *adconfig); QString object_sid_display_value(const QByteArray &sid_bytes); bool attribute_value_is_hex_displayed(const QString &attribute); #endif /* ATTRIBUTE_DISPLAY_H */
1,485
C++
.h
36
39.527778
118
0.778547
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,968
ad_security.h
altlinux_admc/src/adldap/ad_security.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /** * Functions for working with AD security and security * descriptors. */ #ifndef AD_SECURITY_H #define AD_SECURITY_H #include "ad_defines.h" #include <QByteArray> #include <QLocale> class AdInterface; class AdConfig; class AdObject; struct security_descriptor; struct dom_sid; typedef void TALLOC_CTX; extern const QList<QString> well_known_sid_list; extern const QList<uint32_t> common_rights_list; enum SecurityRightStateType { SecurityRightStateType_Allow, SecurityRightStateType_Deny, SecurityRightStateType_COUNT, }; enum SecurityRightStateInherited { SecurityRightStateInherited_Yes, SecurityRightStateInherited_No, SecurityRightStateInherited_COUNT, }; class SecurityRightState { public: SecurityRightState(const bool data[SecurityRightStateInherited_COUNT][SecurityRightStateType_COUNT]); bool get(const SecurityRightStateInherited inherited, const SecurityRightStateType type) const; private: bool data[SecurityRightStateInherited_COUNT][SecurityRightStateType_COUNT]; }; class SecurityRight { public: uint32_t access_mask; QByteArray object_type; }; QString ad_security_get_well_known_trustee_name(const QByteArray &trustee); QString ad_security_get_trustee_name(AdInterface &ad, const QByteArray &trustee); bool ad_security_get_protected_against_deletion(const AdObject &object); bool ad_security_set_protected_against_deletion(AdInterface &ad, const QString dn, const bool enabled); bool ad_security_get_user_cant_change_pass(const AdObject *object, AdConfig *adconfig); bool ad_security_set_user_cant_change_pass(AdInterface *ad, const QString &dn, const bool enabled); bool ad_security_replace_security_descriptor(AdInterface &ad, const QString &dn, security_descriptor *new_sd); // Returns the full right name, adding "Write" or // "Read" depending on access mask. QString ad_security_get_right_name(AdConfig *adconfig, const uint32_t access_mask, const QByteArray &object_type, QLocale::Language language); // NOTE: returned sd needs to be free'd with // security_descriptor_free() security_descriptor *security_descriptor_make_from_bytes(const QByteArray &sd_bytes); security_descriptor *security_descriptor_make_from_bytes(TALLOC_CTX *mem_ctx, const QByteArray &sd_bytes); security_descriptor *security_descriptor_copy(security_descriptor *sd); void security_descriptor_free(security_descriptor *sd); void security_descriptor_sort_dacl(security_descriptor *sd); QList<QByteArray> security_descriptor_get_trustee_list(security_descriptor *sd); SecurityRightState security_descriptor_get_right(const security_descriptor *sd, const QByteArray &trustee, const uint32_t access_mask, const QByteArray &object_type); void security_descriptor_print(security_descriptor *sd, AdInterface &ad); bool security_descriptor_verify_acl_order(security_descriptor *sd); // Remove all ACE's from DACL for given trustee. Note // that inherited ACE's are untouched, so trustee might // still have ace's remaining after this is called. void security_descriptor_remove_trustee(security_descriptor *sd, const QList<QByteArray> &trustee_list); // "Complete" versions of add/remove right f-ns that do A // LOT more than just add rights. They also take care // of superior and subordinate rights to follow a logic // of a typical gui checklist of rights. void security_descriptor_add_right(security_descriptor *sd, AdConfig *adconfig, const QList<QString> &class_list, const QByteArray &trustee, const uint32_t access_mask, const QByteArray &object_type, const bool allow); void security_descriptor_remove_right(security_descriptor *sd, AdConfig *adconfig, const QList<QString> &class_list, const QByteArray &trustee, const uint32_t access_mask, const QByteArray &object_type, const bool allow); QList<SecurityRight> ad_security_get_right_list_for_class(AdConfig *adconfig, const QList<QString> &class_list); QList<SecurityRight> ad_security_get_superior_right_list(const uint32_t access_mask, const QByteArray &object_type); QList<SecurityRight> ad_security_get_subordinate_right_list(AdConfig *adconfig, const uint32_t access_mask, const QByteArray &object_type, const QList<QString> &class_list); #endif /* AD_SECURITY_H */
4,961
C++
.h
93
51.44086
221
0.799959
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,969
gplink.h
altlinux_admc/src/adldap/gplink.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef GPLINK_H #define GPLINK_H #include <QHash> #include <QList> #include <QString> enum GplinkOption { GplinkOption_NoOption, GplinkOption_Disabled, GplinkOption_Enforced }; /** * Class to store a gplink attribute for easy manipulation. * Gplink attribute primer: an ordered list of GPO container * DN's with each GPO being assigned an "option" value. * Options specify whether policy is disabled and/or * enforced. */ class Gplink { public: Gplink(); Gplink(const Gplink &other); Gplink(const QString &gplink_string); Gplink &operator=(const Gplink &other); QString to_string() const; bool contains(const QString &gpo) const; // NOTE: this returns a list of GPO DN's with correct // letter case. Gplink string contains DN's in a // different letter case that is not appropriate for // LDAP operations. QList<QString> get_gpo_list() const; void add(const QString &gpo_case); void remove(const QString &gpo_case); void move_up(const QString &gpo_case); void move_down(const QString &gpo_case); void move(int from_order, int to_order); bool get_option(const QString &gpo, const GplinkOption option) const; void set_option(const QString &gpo, const GplinkOption option, const bool value); bool equals(const Gplink &other) const; int get_gpo_order(const QString &gpo) const; int get_max_order() const; QStringList enforced_gpo_dn_list() const; QStringList disabled_gpo_dn_list() const; private: QList<QString> gpo_list; QHash<QString, int> options; }; #endif /* GPLINK_H */
2,381
C++
.h
66
32.787879
85
0.732609
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,970
ad_config_p.h
altlinux_admc/src/adldap/ad_config_p.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef AD_CONFIG_P_H #define AD_CONFIG_P_H #include "ad_object.h" #include <QByteArray> #include <QHash> #include <QList> #include <QString> // NOTE: name strings to reduce confusion typedef QString ObjectClass; typedef QString Attribute; class AdConfigPrivate { public: AdConfigPrivate(); QString domain; QString domain_dn; QString configuration_dn; QString schema_dn; QString domain_sid; QList<ObjectClass> filter_containers; QList<Attribute> columns; QHash<Attribute, QString> column_display_names; QHash<ObjectClass, QString> class_display_names; QHash<ObjectClass, QList<Attribute>> find_attributes; QHash<ObjectClass, QHash<Attribute, QString>> attribute_display_names; QHash<Attribute, AdObject> attribute_schemas; QHash<ObjectClass, AdObject> class_schemas; QList<ObjectClass> add_auxiliary_classes(const QList<QString> &object_classes) const; QHash<QString, QByteArray> right_to_guid_map; QHash<QByteArray, QString> right_guid_to_cn_map; QHash<QByteArray, QString> rights_guid_to_name_map; QHash<QString, QByteArray> rights_name_to_guid_map; QHash<QByteArray, QList<QString>> rights_applies_to_map; QList<QString> extended_rights_list; QHash<QString, int> rights_valid_accesses_map; QHash<QByteArray, QString> guid_to_attribute_map; QHash<QByteArray, QString> guid_to_class_map; QList<QString> supported_control_list; QHash<QString, QString> sub_class_of_map; }; #endif /* AD_CONFIG_P_H */
2,295
C++
.h
59
35.542373
89
0.754845
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,971
ad_defines.h
altlinux_admc/src/adldap/ad_defines.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef AD_DEFINES_H #define AD_DEFINES_H /** * AD related enums and constants. */ enum AttributeType { AttributeType_Boolean, AttributeType_Enumeration, AttributeType_Integer, AttributeType_LargeInteger, AttributeType_StringCase, AttributeType_IA5, AttributeType_NTSecDesc, AttributeType_Numeric, AttributeType_ObjectIdentifier, AttributeType_Octet, AttributeType_ReplicaLink, AttributeType_Printable, AttributeType_Sid, AttributeType_Teletex, AttributeType_Unicode, AttributeType_UTCTime, AttributeType_GeneralizedTime, AttributeType_DNString, AttributeType_DNBinary, AttributeType_DSDN, }; // NOTE: large integer type has sub types but AD schema // doesn't distinguish between them (from what I've seen). // Create enums for subtypes for easier processing. enum LargeIntegerSubtype { LargeIntegerSubtype_Integer, LargeIntegerSubtype_Datetime, LargeIntegerSubtype_Timespan, }; enum AccountOption { AccountOption_Disabled, AccountOption_CantChangePassword, AccountOption_AllowReversibleEncryption, AccountOption_PasswordExpired, AccountOption_DontExpirePassword, AccountOption_UseDesKey, AccountOption_SmartcardRequired, AccountOption_CantDelegate, AccountOption_DontRequirePreauth, AccountOption_TrustedForDelegation, AccountOption_COUNT }; enum GroupScope { GroupScope_Global, GroupScope_DomainLocal, GroupScope_Universal, GroupScope_COUNT }; enum GroupType { GroupType_Security, GroupType_Distribution, GroupType_COUNT }; enum SystemFlagsBit { SystemFlagsBit_DomainCannotMove = 0x04000000, SystemFlagsBit_DomainCannotRename = 0x08000000, SystemFlagsBit_CannotDelete = 0x80000000 }; #define ROOT_DSE "" #define ATTRIBUTE_CN "cn" #define ATTRIBUTE_USER_ACCOUNT_CONTROL "userAccountControl" #define ATTRIBUTE_LOCKOUT_TIME "lockoutTime" #define ATTRIBUTE_ACCOUNT_EXPIRES "accountExpires" #define ATTRIBUTE_PWD_LAST_SET "pwdLastSet" #define ATTRIBUTE_NAME "name" #define ATTRIBUTE_INITIALS "initials" #define ATTRIBUTE_SAM_ACCOUNT_NAME "sAMAccountName" #define ATTRIBUTE_SAM_ACCOUNT_TYPE "sAMAccountType" #define ATTRIBUTE_DISPLAY_NAME "displayName" #define ATTRIBUTE_DESCRIPTION "description" #define ATTRIBUTE_USER_PRINCIPAL_NAME "userPrincipalName" #define ATTRIBUTE_MAIL "mail" #define ATTRIBUTE_OFFICE "physicalDeliveryOfficeName" #define ATTRIBUTE_TELEPHONE_NUMBER "telephoneNumber" #define ATTRIBUTE_TELEPHONE_NUMBER_OTHER "otherTelephone" #define ATTRIBUTE_WWW_HOMEPAGE "wWWHomePage" #define ATTRIBUTE_WWW_HOMEPAGE_OTHER "url" #define ATTRIBUTE_COUNTRY_ABBREVIATION "c" #define ATTRIBUTE_COUNTRY "co" #define ATTRIBUTE_COUNTRY_CODE "countryCode" #define ATTRIBUTE_CITY "l" #define ATTRIBUTE_PO_BOX "postOfficeBox" #define ATTRIBUTE_POSTAL_CODE "postalCode" #define ATTRIBUTE_STATE "st" #define ATTRIBUTE_STREET "streetAddress" #define ATTRIBUTE_STREET_OU "street" #define ATTRIBUTE_DN "distinguishedName" #define ATTRIBUTE_OBJECT_CLASS "objectClass" #define ATTRIBUTE_WHEN_CREATED "whenCreated" #define ATTRIBUTE_WHEN_CHANGED "whenChanged" #define ATTRIBUTE_USN_CHANGED "uSNChanged" #define ATTRIBUTE_USN_CREATED "uSNCreated" #define ATTRIBUTE_OBJECT_CATEGORY "objectCategory" #define ATTRIBUTE_MEMBER "member" #define ATTRIBUTE_MEMBER_OF "memberOf" #define ATTRIBUTE_SHOW_IN_ADVANCED_VIEW_ONLY "showInAdvancedViewOnly" #define ATTRIBUTE_GROUP_TYPE "groupType" #define ATTRIBUTE_FIRST_NAME "givenName" #define ATTRIBUTE_LAST_NAME "sn" #define ATTRIBUTE_DNS_HOST_NAME "dNSHostName" #define ATTRIBUTE_INFO "info" #define ATTRIBUTE_PASSWORD "unicodePwd" #define ATTRIBUTE_GPLINK "gPLink" #define ATTRIBUTE_GPOPTIONS "gPOptions" #define ATTRIBUTE_DEPARTMENT "department" #define ATTRIBUTE_COMPANY "company" #define ATTRIBUTE_TITLE "title" #define ATTRIBUTE_LAST_LOGON "lastLogon" #define ATTRIBUTE_LAST_LOGON_TIMESTAMP "lastLogonTimestamp" #define ATTRIBUTE_PWD_LAST_SET "pwdLastSet" #define ATTRIBUTE_BAD_PWD_TIME "badPasswordTime" #define ATTRIBUTE_OBJECT_SID "objectSid" #define ATTRIBUTE_SYSTEM_FLAGS "systemFlags" #define ATTRIBUTE_MAX_PWD_AGE "maxPwdAge" #define ATTRIBUTE_MIN_PWD_AGE "minPwdAge" #define ATTRIBUTE_LOCKOUT_DURATION "lockoutDuration" #define ATTRIBUTE_IS_CRITICAL_SYSTEM_OBJECT "isCriticalSystemObject" #define ATTRIBUTE_GPC_FILE_SYS_PATH "gPCFileSysPath" #define ATTRIBUTE_GPC_FUNCTIONALITY_VERSION "gpCFunctionalityVersion" #define ATTRIBUTE_VERSION_NUMBER "versionNumber" #define ATTRIBUTE_FLAGS "flags" #define ATTRIBUTE_OBJECT_GUID "objectGUID" #define ATTRIBUTE_PRIMARY_GROUP_ID "primaryGroupID" #define ATTRIBUTE_MANAGER "manager" #define ATTRIBUTE_MANAGED_BY "managedBy" #define ATTRIBUTE_DIRECT_REPORTS "directReports" #define ATTRIBUTE_PROFILE_PATH "profilePath" #define ATTRIBUTE_SCRIPT_PATH "scriptPath" #define ATTRIBUTE_HOME_DIRECTORY "homeDirectory" #define ATTRIBUTE_LAPS_PASSWORD "ms-Mcs-AdmPwd" #define ATTRIBUTE_LAPS_EXPIRATION "ms-Mcs-AdmPwdExpirationTime" #define ATTRIBUTE_HOME_PHONE "homePhone" #define ATTRIBUTE_OTHER_HOME_PHONE "otherHomePhone" #define ATTRIBUTE_PAGER "pager" #define ATTRIBUTE_OTHER_PAGER "otherPager" #define ATTRIBUTE_MOBILE "mobile" #define ATTRIBUTE_OTHER_MOBILE "otherMobile" #define ATTRIBUTE_FAX_NUMBER "facsimileTelephoneNumber" #define ATTRIBUTE_OTHER_FAX_NUMBER "otherFacsimileTelephoneNumber" #define ATTRIBUTE_IP_PHONE "ipPhone" #define ATTRIBUTE_OTHER_IP_PHONE "otherIpPhone" #define ATTRIBUTE_UPN_SUFFIXES "uPNSuffixes" #define ATTRIBUTE_SECURITY_DESCRIPTOR "nTSecurityDescriptor" #define ATTRIBUTE_RIGHTS_GUID "rightsGuid" #define ATTRIBUTE_LOCATION "location" #define ATTRIBUTE_OS "operatingSystem" #define ATTRIBUTE_OS_VERSION "operatingSystemVersion" #define ATTRIBUTE_OS_SERVICE_PACK "operatingSystemServicePack" #define ATTRIBUTE_LOGON_HOURS "logonHours" #define ATTRIBUTE_USER_WORKSTATIONS "userWorkstations" #define ATTRIBUTE_VERSION_NUMBER "versionNumber" #define ATTRIBUTE_SUPPORTED_CONTROL "supportedControl" #define ATTRIBUTE_DS_SERVICE_NAME "dsServiceName" #define ATTRIBUTE_SCHEMA_NAMING_CONTEXT "schemaNamingContext" #define ATTRIBUTE_CONFIGURATION_NAMING_CONTEXT "configurationNamingContext" #define ATTRIBUTE_ROOT_DOMAIN_NAMING_CONTEXT "rootDomainNamingContext" #define ATTRIBUTE_FSMO_ROLE_OWNER "fSMORoleOwner" #define ATTRIBUTE_SERVER_NAME "serverName" #define ATTRIBUTE_SCHEMA_ID_GUID "schemaIDGUID" #define ATTRIBUTE_APPLIES_TO "appliesTo" #define ATTRIBUTE_VALID_ACCESSES "validAccesses" #define ATTRIBUTE_UNC_NAME "uNCName" #define ATTRIBUTE_KEYWORDS "keywords" #define ATTRIBUTE_CREATION_TIME "creationTime" #define ATTRIBUTE_LOCKOUT_OBSERVATION_WINDOW "lockOutObservationWindow" #define ATTRIBUTE_FORCE_LOGOFF "forceLogoff" #define ATTRIBUTE_MS_DS_SUPPORTED_ETYPES "msDS-SupportedEncryptionTypes" #define ATTRIBUTE_DOMAIN_FUNCTIONALITY_LEVEL "domainFunctionality" #define ATTRIBUTE_FOREST_FUNCTIONALITY_LEVEL "forestFunctionality" #define ATTRIBUTE_OBJECT_VERSION "objectVersion" #define ATTRIBUTE_SERVER_REFERENCE "serverReference" #define ATTRIBUTE_SERVER_REFERENCE_BL "serverReferenceBL" #define ATTRIBUTE_MS_DS_LOCKOUT_DURATION "msDS-LockoutDuration" #define ATTRIBUTE_MS_DS_LOCKOUT_OBSERVATION_WINDOW "msDS-LockoutObservationWindow" #define ATTRIBUTE_MS_DS_MAX_PASSWORD_AGE "msDS-MaximumPasswordAge" #define ATTRIBUTE_MS_DS_MIN_PASSWORD_AGE "msDS-MinimumPasswordAge" #define ATTRIBUTE_MS_DS_LOCKOUT_THRESHOLD "msDS-LockoutThreshold" #define ATTRIBUTE_MS_DS_MIN_PASSWORD_LENGTH "msDS-MinimumPasswordLength" #define ATTRIBUTE_MS_DS_PASSWORD_COMPLEXITY_ENABLED "msDS-PasswordComplexityEnabled" #define ATTRIBUTE_MS_DS_PASSWORD_HISTORY_LENGTH "msDS-PasswordHistoryLength" #define ATTRIBUTE_MS_DS_PASSWORD_REVERSIBLE_ENCRYPTION_ENABLED "msDS-PasswordReversibleEncryptionEnabled" #define ATTRIBUTE_MS_DS_PASSWORD_SETTINGS_PRECEDENCE "msDS-PasswordSettingsPrecedence" #define ATTRIBUTE_PSO_APPLIES_TO "msDS-PSOAppliesTo" #define CLASS_GROUP "group" #define CLASS_USER "user" #define CLASS_CONTAINER "container" #define CLASS_OU "organizationalUnit" #define CLASS_PERSON "person" #define CLASS_GP_CONTAINER "groupPolicyContainer" #define CLASS_DOMAIN "domainDNS" #define CLASS_TOP "top" #define CLASS_COMPUTER "computer" #define CLASS_ORG_PERSON "organizationalPerson" #define CLASS_CONTACT "contact" #define CLASS_PRINTER "printQueue" #define CLASS_DEFAULT "default" #define CLASS_CONFIGURATION "configuration" #define CLASS_TRUSTED_DOMAIN "trustedDomain" #define CLASS_INET_ORG_PERSON "inetOrgPerson" #define CLASS_FOREIGN_SECURITY_PRINCIPAL "foreignSecurityPrincipal" #define CLASS_SHARED_FOLDER "volume" #define CLASS_RPC_SERVICES "rpcContainer" #define CLASS_CERTIFICATE_TEMPLATE "pKICertificateTemplate" #define CLASS_MSMQ_GROUP "msMQ-Group" #define CLASS_MSMQ_QUEUE_ALIAS "msMQ-Custom-Recipient" #define CLASS_REMOTE_STORAGE_SERVICE "remoteStorageServicePoint" #define CLASS_SITE "site" #define CLASS_SERVER "server" #define CLASS_SERVERS_CONTAINER "serversContainer" #define CLASS_PSO_CONTAINER "msDS-PasswordSettingsContainer" #define CLASS_PSO "msDS-PasswordSettings" // NOTE: for schema object #define CLASS_dMD "dMD" #define CLASS_CONTROL_ACCESS_RIGHT "controlAccessRight" #define OBJECT_CATEGORY_PERSON "Person" #define OBJECT_CATEGORY_GROUP "Group" #define OBJECT_CATEGORY_OU "Organizational-Unit" #define OBJECT_CATEGORY_COMPUTER "Computer" #define OBJECT_CATEGORY_DOMAIN_DNS "Domain-DNS" #define OBJECT_CATEGORY_CONTAINER "Container" #define OBJECT_CATEGORY_GP_CONTAINER "Group-Policy-Container" #define OBJECT_CATEGORY_VOLUME "Volume" #define OBJECT_CATEGORY_BUILTIN "Builtin-Domain" #define OBJECT_CATEGORY_LOST_AND_FOUND "Lost_And_Found" #define OBJECT_CATEGORY_INFRASTRUCTURE_UPDATE "Infrastructure-Update" #define OBJECT_CATEGORY_MSDS_QUOTA_CONTAINER "ms-DS-Quota-Container" #define OBJECT_CATEGORY_SERVERS_CONTAINER "Servers-Container" #define OBJECT_CATEGORY_SITE "Site" #define OBJECT_CATEGORY_PSO_CONTAINER "ms-DS-Password-Settings-Container" #define OBJECT_CATEGORY_PSO "ms-DS-Password-Settings" // These categories are not AD object categories. They are used within ADMC context #define ADMC_CATEGORY_QUERY_ITEM "query-item" #define ADMC_CATEGORY_QUERY_FOLDER "query-folder" #define ADMC_CATEGORY_FSMO_ROLE "FSMO-role" #define ADMC_CATEGORY_FSMO_ROLE_CONTAINER "FSMO-role-container" #define ADMC_CATEGORY_GP_OBJECTS "group-policy-objects" #define ADMC_CATEGORY_ALL_POLICIES_FOLDER "all-policies-folder" #define ADMC_CATEGORY_DOMAIN_INFO_ITEM "domain-info-item" #define LOCKOUT_UNLOCKED_VALUE "0" #define AD_LARGE_INTEGER_DATETIME_NEVER_1 "0" #define AD_LARGE_INTEGER_DATETIME_NEVER_2 "9223372036854775807" #define AD_PWD_LAST_SET_EXPIRED "0" #define AD_PWD_LAST_SET_RESET "-1" #define LDAP_BOOL_TRUE "TRUE" #define LDAP_BOOL_FALSE "FALSE" #define GPOPTIONS_INHERIT "0" #define GPOPTIONS_BLOCK_INHERITANCE "1" #define GROUP_TYPE_BIT_SECURITY 0x80000000 #define GROUP_TYPE_BIT_SYSTEM 0x00000001 #define DATETIME_DISPLAY_FORMAT "dd.MM.yy hh:mm UTCt" const long long MILLIS_TO_100_NANOS = 10000LL; #define MATCHING_RULE_IN_CHAIN_OID "1.2.840.113556.1.4.1941" #define LDAP_SERVER_SD_FLAGS_OID "1.2.840.113556.1.4.801" #define OWNER_SECURITY_INFORMATION 0x01 #define GROUP_SECURITY_INFORMATION 0x02 #define SACL_SECURITY_INFORMATION 0x08 #define DACL_SECURITY_INFORMATION 0x04 #define SAM_NAME_BAD_CHARS "@\"[]:;|=+*?<>/\\," #define UPN_BAD_CHARS "#,+\"\\<>" // NOTE: names technically can contain these chars but // we choose to be more strict about it #define NAME_BAD_CHARS ",\\#+<>;\"=" #define UAC_SCRIPT 0x00000001 #define UAC_ACCOUNTDISABLE 0x00000002 #define UAC_HOMEDIR_REQUIRED 0x00000008 #define UAC_LOCKOUT 0x00000010 #define UAC_PASSWD_NOTREQD 0x00000020 #define UAC_PASSWD_CANT_CHANGE 0x00000040 #define UAC_ENCRYPTED_TEXT_PASSWORD_ALLOWED 0x00000080 #define UAC_TEMP_DUPLICATE_ACCOUNT 0x00000100 #define UAC_NORMAL_ACCOUNT 0x00000200 #define UAC_INTERDOMAIN_TRUST_ACCOUNT 0x00000800 #define UAC_WORKSTATION_TRUST_ACCOUNT 0x00001000 #define UAC_SERVER_TRUST_ACCOUNT 0x00002000 #define UAC_DONT_EXPIRE_PASSWORD 0x00010000 #define UAC_MNS_LOGON_ACCOUNT 0x00020000 #define UAC_SMARTCARD_REQUIRED 0x00040000 #define UAC_TRUSTED_FOR_DELEGATION 0x00080000 #define UAC_NOT_DELEGATED 0x00100000 #define UAC_USE_DES_KEY_ONLY 0x00200000 #define UAC_DONT_REQUIRE_PREAUTH 0x00400000 #define UAC_ERROR_PASSWORD_EXPIRED 0x00800000 #define UAC_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION 0x01000000 #define UAC_PARTIAL_SECRETS_ACCOUNT 0x04000000 #define UAC_USER_USE_AES_KEYS 0x08000000 #define SAM_DOMAIN_OBJECT 0x0 #define SAM_GROUP_OBJECT 0x10000000 #define SAM_NON_SECURITY_GROUP_OBJECT 0x10000001 #define SAM_ALIAS_OBJECT 0x20000000 #define SAM_NON_SECURITY_ALIAS_OBJECT 0x20000001 #define SAM_USER_OBJECT 0x30000000 #define SAM_NORMAL_USER_ACCOUNT 0x30000000 #define SAM_MACHINE_ACCOUNT 0x30000001 #define SAM_TRUST_ACCOUNT 0x30000002 #define SAM_APP_BASIC_GROUP 0x40000000 #define SAM_APP_QUERY_GROUP 0x40000001 #define SAM_ACCOUNT_TYPE_MAX 0x7fffffff // NOTE: this is according to Microsoft, haven't found // any better source #define SAM_NAME_MAX_LENGTH 20 #define SAM_NAME_COMPUTER_MAX_LENGTH 16 // NOTE: define supported encryption types bit flags // for msDs-SupportedEncryptionTypes attribute #define ETYPES_DES_CBC_CRC 0x00000001 #define ETYPES_DES_CBC_MD5 0x00000002 #define ETYPES_RC4_HMAC_MD5 0x00000004 #define ETYPES_AES128_CTS_HMAC_SHA1_96 0x00000008 #define ETYPES_AES256_CTS_HMAC_SHA1_96 0x00000010 enum SearchScope { SearchScope_Object, SearchScope_Children, // NOTE: Descendants scope appears to not work, from the // ldap_search manual: "Note that the latter requires // the server support the LDAP Subordinates Search Scope // extension." SearchScope_Descendants, SearchScope_All, }; enum CertStrategy { CertStrategy_Never, CertStrategy_Hard, CertStrategy_Demand, CertStrategy_Allow, CertStrategy_Try, }; #endif /* AD_DEFINES_H */
14,712
C++
.h
351
40.116809
105
0.821062
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,972
ad_object.h
altlinux_admc/src/adldap/ad_object.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef AD_OBJECT_H #define AD_OBJECT_H /** * This object is returned as a result of some AdInterface * functions. It stores AD object's attributes and provides * read-only access to them. Modifying attributes can be * done through AdInterface. Note that this object is loaded * with data once and not updated afterwards so it WILL * become out of date after any AD modification. Therefore, * do not keep it around for too long. */ #include "ad_defines.h" #include <QByteArray> #include <QHash> #include <QList> #include <QString> class QDateTime; class AdConfig; typedef void TALLOC_CTX; struct security_descriptor; class AdObject { public: AdObject(); void load(const QString &dn_arg, const QHash<QString, QList<QByteArray>> &attributes_data_arg); QString get_dn() const; QHash<QString, QList<QByteArray>> get_attributes_data() const; bool is_empty() const; bool contains(const QString &attribute) const; QList<QString> attributes() const; QList<QByteArray> get_values(const QString &attribute) const; QByteArray get_value(const QString &attribute) const; QList<QString> get_strings(const QString &attribute) const; QString get_string(const QString &attribute) const; int get_int(const QString &attribute) const; QList<int> get_ints(const QString &attribute) const; QList<bool> get_bools(const QString &attribute) const; bool get_bool(const QString &attribute) const; QDateTime get_datetime(const QString &attribute, const AdConfig *adconfig) const; bool get_system_flag(const SystemFlagsBit bit) const; bool get_account_option(AccountOption option, AdConfig *adconfig) const; GroupScope get_group_scope() const; GroupType get_group_type() const; // NOTE: this compares for the most derived class, so each object only maps to one class. For example computers have objectClass values of both "user" and "computer" but "computer" is more derived so they are only computers and not users. bool is_class(const QString &object_class) const; QList<QString> get_split_upn() const; QString get_upn_prefix() const; QString get_upn_suffix() const; // NOTE: if no mem_ctx is given, then returned value has to be free'd using security_descriptor_free() security_descriptor *get_security_descriptor(TALLOC_CTX *mem_ctx = nullptr) const; private: QString dn; QHash<QString, QList<QByteArray>> attributes_data; }; #endif /* AD_OBJECT_H */
3,246
C++
.h
73
41.219178
242
0.75246
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,973
adldap.h
altlinux_admc/src/adldap/adldap.h
/* * ADMC - AD Management Center * * Copyright (C) 2020-2022 BaseALT Ltd. * Copyright (C) 2020-2022 Dmitry Degtyarev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef ADLDAP_H #define ADLDAP_H #include "ad_config.h" #include "ad_defines.h" #include "ad_display.h" #include "ad_filter.h" #include "ad_interface.h" #include "ad_object.h" #include "ad_security.h" #include "ad_utils.h" #include "gplink.h" #endif /* ADLDAP_H */
1,043
C++
.h
31
31.967742
72
0.748266
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,974
libsmb_xattr.h
altlinux_admc/src/adldap/samba/libsmb_xattr.h
/* Unix SMB/Netbios implementation. SMB client library implementation Copyright (C) Andrew Tridgell 1998 Copyright (C) Richard Sharpe 2000, 2002 Copyright (C) John Terpstra 2000 Copyright (C) Tom Jansen (Ninja ISD) 2002 Copyright (C) Derrell Lipman 2003-2008 Copyright (C) Jeremy Allison 2007, 2008 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * This file is a copy of private samba sources. Parts of it * were removed or edited. */ #ifndef LIBSMB_XATTR_H #define LIBSMB_XATTR_H extern "C" { struct security_ace; int ace_compare(void const *ace1, void const *ace2); }; #endif /* LIBSMB_XATTR_H */
1,249
C++
.h
32
35.5
72
0.747307
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,975
misc.h
altlinux_admc/src/adldap/samba/misc.h
/* * Unix SMB/CIFS implementation. * Group Policy Object Support * Copyright (C) Wilco Baan Hofman 2010 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. */ /* * This file is a copy of private samba generated sources. */ /* header auto-generated by pidl */ #ifndef _PIDL_HEADER_misc #define _PIDL_HEADER_misc // NOTE: extra headers needed to compile #include <util/data_blob.h> #include <core/ntstatus.h> #include <stdint.h> // #include "libcli/util/ntstatus.h" #ifndef _HEADER_misc #define _HEADER_misc #define SV_TYPE_ALL ( 0xFFFFFFFF ) struct GUID { uint32_t time_low; uint16_t time_mid; uint16_t time_hi_and_version; uint8_t clock_seq[2]; uint8_t node[6]; }/* [gensize,noprint,public] */; struct ndr_syntax_id { struct GUID uuid; uint32_t if_version; }/* [public] */; struct policy_handle { uint32_t handle_type; struct GUID uuid; }/* [public] */; enum netr_SchannelType #ifndef USE_UINT_ENUMS { SEC_CHAN_NULL=(int)(0), SEC_CHAN_LOCAL=(int)(1), SEC_CHAN_WKSTA=(int)(2), SEC_CHAN_DNS_DOMAIN=(int)(3), SEC_CHAN_DOMAIN=(int)(4), SEC_CHAN_LANMAN=(int)(5), SEC_CHAN_BDC=(int)(6), SEC_CHAN_RODC=(int)(7) } #else { __do_not_use_enum_netr_SchannelType=0x7FFFFFFF} #define SEC_CHAN_NULL ( 0 ) #define SEC_CHAN_LOCAL ( 1 ) #define SEC_CHAN_WKSTA ( 2 ) #define SEC_CHAN_DNS_DOMAIN ( 3 ) #define SEC_CHAN_DOMAIN ( 4 ) #define SEC_CHAN_LANMAN ( 5 ) #define SEC_CHAN_BDC ( 6 ) #define SEC_CHAN_RODC ( 7 ) #endif ; struct KRB5_EDATA_NTSTATUS { NTSTATUS ntstatus; uint32_t unknown1; uint32_t unknown2; }/* [public] */; enum winreg_Type #ifndef USE_UINT_ENUMS { REG_NONE=(int)(0), REG_SZ=(int)(1), REG_EXPAND_SZ=(int)(2), REG_BINARY=(int)(3), REG_DWORD=(int)(4), REG_DWORD_BIG_ENDIAN=(int)(5), REG_LINK=(int)(6), REG_MULTI_SZ=(int)(7), REG_RESOURCE_LIST=(int)(8), REG_FULL_RESOURCE_DESCRIPTOR=(int)(9), REG_RESOURCE_REQUIREMENTS_LIST=(int)(10), REG_QWORD=(int)(11) } #else { __do_not_use_enum_winreg_Type=0x7FFFFFFF} #define REG_NONE ( 0 ) #define REG_SZ ( 1 ) #define REG_EXPAND_SZ ( 2 ) #define REG_BINARY ( 3 ) #define REG_DWORD ( 4 ) #define REG_DWORD_BIG_ENDIAN ( 5 ) #define REG_LINK ( 6 ) #define REG_MULTI_SZ ( 7 ) #define REG_RESOURCE_LIST ( 8 ) #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) #define REG_RESOURCE_REQUIREMENTS_LIST ( 10 ) #define REG_QWORD ( 11 ) #endif ; union winreg_Data { const char * string;/* [case(REG_SZ),flag(LIBNDR_FLAG_STR_NULLTERM|LIBNDR_FLAG_ALIGN2)] */ DATA_BLOB binary;/* [case(REG_BINARY),flag(LIBNDR_FLAG_REMAINING)] */ uint32_t value;/* [case(REG_DWORD)] */ const char ** string_array;/* [case(REG_MULTI_SZ),flag(LIBNDR_FLAG_STR_NULLTERM|LIBNDR_FLAG_ALIGN2)] */ uint64_t qword;/* [case(REG_QWORD)] */ DATA_BLOB data;/* [default,flag(LIBNDR_FLAG_REMAINING)] */ }/* [flag(LIBNDR_FLAG_LITTLE_ENDIAN),nodiscriminant,public] */; union winreg_Data_GPO { const char * string;/* [case(REG_SZ),flag(LIBNDR_FLAG_STR_NULLTERM|LIBNDR_FLAG_ALIGN2)] */ DATA_BLOB binary;/* [case(REG_BINARY),flag(LIBNDR_FLAG_REMAINING)] */ uint32_t value;/* [case(REG_DWORD)] */ uint64_t qword;/* [case(REG_QWORD)] */ DATA_BLOB data;/* [default,flag(LIBNDR_FLAG_REMAINING)] */ }/* [flag(LIBNDR_FLAG_LITTLE_ENDIAN),gensize,nodiscriminant,public] */; enum netr_SamDatabaseID #ifndef USE_UINT_ENUMS { SAM_DATABASE_DOMAIN=(int)(0), SAM_DATABASE_BUILTIN=(int)(1), SAM_DATABASE_PRIVS=(int)(2) } #else { __do_not_use_enum_netr_SamDatabaseID=0x7FFFFFFF} #define SAM_DATABASE_DOMAIN ( 0 ) #define SAM_DATABASE_BUILTIN ( 1 ) #define SAM_DATABASE_PRIVS ( 2 ) #endif ; /* bitmap svcctl_ServerType */ #define SV_TYPE_WORKSTATION ( 0x00000001 ) #define SV_TYPE_SERVER ( 0x00000002 ) #define SV_TYPE_SQLSERVER ( 0x00000004 ) #define SV_TYPE_DOMAIN_CTRL ( 0x00000008 ) #define SV_TYPE_DOMAIN_BAKCTRL ( 0x00000010 ) #define SV_TYPE_TIME_SOURCE ( 0x00000020 ) #define SV_TYPE_AFP ( 0x00000040 ) #define SV_TYPE_NOVELL ( 0x00000080 ) #define SV_TYPE_DOMAIN_MEMBER ( 0x00000100 ) #define SV_TYPE_PRINTQ_SERVER ( 0x00000200 ) #define SV_TYPE_DIALIN_SERVER ( 0x00000400 ) #define SV_TYPE_SERVER_UNIX ( 0x00000800 ) #define SV_TYPE_NT ( 0x00001000 ) #define SV_TYPE_WFW ( 0x00002000 ) #define SV_TYPE_SERVER_MFPN ( 0x00004000 ) #define SV_TYPE_SERVER_NT ( 0x00008000 ) #define SV_TYPE_POTENTIAL_BROWSER ( 0x00010000 ) #define SV_TYPE_BACKUP_BROWSER ( 0x00020000 ) #define SV_TYPE_MASTER_BROWSER ( 0x00040000 ) #define SV_TYPE_DOMAIN_MASTER ( 0x00080000 ) #define SV_TYPE_SERVER_OSF ( 0x00100000 ) #define SV_TYPE_SERVER_VMS ( 0x00200000 ) #define SV_TYPE_WIN95_PLUS ( 0x00400000 ) #define SV_TYPE_DFS_SERVER ( 0x00800000 ) #define SV_TYPE_ALTERNATE_XPORT ( 0x20000000 ) #define SV_TYPE_LOCAL_LIST_ONLY ( 0x40000000 ) #define SV_TYPE_DOMAIN_ENUM ( 0x80000000 ) #endif /* _HEADER_misc */ #endif /* _PIDL_HEADER_misc */
5,515
C++
.h
167
30.664671
107
0.705629
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,976
gp_manage.h
altlinux_admc/src/adldap/samba/gp_manage.h
/* * Unix SMB/CIFS implementation. * Group Policy Object Support * Copyright (C) Wilco Baan Hofman 2010 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. */ /* * This file is a copy of private samba sources. Parts of it * were removed or edited. */ #ifdef __cplusplus extern "C" { #endif #ifndef GP_MANAGE_H #define GP_MANAGE_H #include <ndr.h> #include <gen_ndr/security.h> #include <talloc.h> NTSTATUS gp_create_gpt_security_descriptor(TALLOC_CTX *mem_ctx, struct security_descriptor *ds_sd, struct security_descriptor **ret); #endif /* GP_MANAGE_H */ #ifdef __cplusplus } #endif
1,207
C++
.h
35
32.714286
133
0.747639
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,977
security_descriptor.h
altlinux_admc/src/adldap/samba/security_descriptor.h
/* Unix SMB/CIFS implementation. Samba utility functions Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * This file is a copy of private samba sources. Parts of it * were removed or edited. */ #ifdef __cplusplus extern "C" { #endif #ifndef __SECURITY_DESCRIPTOR_H__ #define __SECURITY_DESCRIPTOR_H__ #include <ndr.h> #include <gen_ndr/security.h> struct security_descriptor *security_descriptor_initialise(TALLOC_CTX *mem_ctx); struct security_descriptor *security_descriptor_copy(TALLOC_CTX *mem_ctx, const struct security_descriptor *osd); NTSTATUS security_descriptor_for_client(TALLOC_CTX *mem_ctx, const struct security_descriptor *ssd, uint32_t sec_info, uint32_t access_granted, struct security_descriptor **_csd); NTSTATUS security_descriptor_sacl_add(struct security_descriptor *sd, const struct security_ace *ace); NTSTATUS security_descriptor_dacl_add(struct security_descriptor *sd, const struct security_ace *ace); NTSTATUS security_descriptor_dacl_del(struct security_descriptor *sd, const struct dom_sid *trustee); NTSTATUS security_descriptor_sacl_del(struct security_descriptor *sd, const struct dom_sid *trustee); bool security_ace_equal(const struct security_ace *ace1, const struct security_ace *ace2); bool security_acl_equal(const struct security_acl *acl1, const struct security_acl *acl2); bool security_descriptor_equal(const struct security_descriptor *sd1, const struct security_descriptor *sd2); bool security_descriptor_mask_equal(const struct security_descriptor *sd1, const struct security_descriptor *sd2, uint32_t mask); struct security_descriptor *security_descriptor_append(struct security_descriptor *sd, ...); struct security_descriptor *security_descriptor_dacl_create(TALLOC_CTX *mem_ctx, uint16_t sd_type, const char *owner_sid, const char *group_sid, ...); struct security_descriptor *security_descriptor_sacl_create(TALLOC_CTX *mem_ctx, uint16_t sd_type, const char *owner_sid, const char *group_sid, ...); struct security_ace *security_ace_create(TALLOC_CTX *mem_ctx, const char *sid_str, enum security_ace_type type, uint32_t access_mask, uint8_t flags); struct security_acl *security_acl_dup(TALLOC_CTX *mem_ctx, const struct security_acl *oacl); struct security_acl *security_acl_concatenate(TALLOC_CTX *mem_ctx, const struct security_acl *acl1, const struct security_acl *acl2); uint32_t map_generic_rights_ds(uint32_t access_mask); struct security_descriptor *create_security_descriptor(TALLOC_CTX *mem_ctx, struct security_descriptor *parent_sd, struct security_descriptor *creator_sd, bool is_container, struct GUID *object_list, uint32_t inherit_flags, struct security_token *token, struct dom_sid *default_owner, /* valid only for DS, NULL for the other RSs */ struct dom_sid *default_group, /* valid only for DS, NULL for the other RSs */ uint32_t (*generic_map)(uint32_t access_mask)); bool security_descriptor_with_ms_nfs(const struct security_descriptor *psd); #endif /* __SECURITY_DESCRIPTOR_H__ */ #ifdef __cplusplus } #endif
4,715
C++
.h
89
39.52809
109
0.611714
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,978
replace.h
altlinux_admc/src/adldap/samba/replace.h
/* Unix SMB/CIFS implementation. macros to go along with the lib/replace/ portability layer code Copyright (C) Andrew Tridgell 2005 Copyright (C) Jelmer Vernooij 2006-2008 Copyright (C) Jeremy Allison 2007. ** NOTE! The following LGPL license applies to the replace ** library. This does NOT imply that all of Samba is released ** under the LGPL This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, see <http://www.gnu.org/licenses/>. */ /* * This file is a copy of private samba sources. Parts of it * were removed or edited. */ #ifndef _LIBREPLACE_REPLACE_H #define _LIBREPLACE_REPLACE_H #include <stddef.h> #include <inttypes.h> #include <ctype.h> #ifndef __PRI64_PREFIX # if __WORDSIZE == 64 && ! defined __APPLE__ # define __PRI64_PREFIX "l" # else # define __PRI64_PREFIX "ll" # endif #endif #ifndef PRIu8 # define PRIu8 "u" #endif #ifndef PRIu16 # define PRIu16 "u" #endif #ifndef PRIu32 # define PRIu32 "u" #endif #ifndef PRIu64 # define PRIu64 __PRI64_PREFIX "u" #endif #ifndef HAVE_MEMSET_S #define memset_s rep_memset_s int rep_memset_s(void *dest, size_t destsz, int ch, size_t count); #endif #define strlcpy rep_strlcpy size_t rep_strlcpy(char *d, const char *s, size_t bufsize); #ifndef MIN #define MIN(a,b) ((a)<(b)?(a):(b)) #endif #ifndef MAX #define MAX(a,b) ((a)>(b)?(a):(b)) #endif /** * Work out how many elements there are in a static array. */ #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) /** * Zero a structure. */ #define ZERO_STRUCT(x) memset_s((char *)&(x), sizeof(x), 0, sizeof(x)) /** * Zero a structure given a pointer to the structure. */ #define ZERO_STRUCTP(x) do { \ if ((x) != NULL) { \ memset_s((char *)(x), sizeof(*(x)), 0, sizeof(*(x))); \ } \ } while(0) /** * Zero a structure given a pointer to the structure - no zero check */ #define ZERO_STRUCTPN(x) memset_s((char *)(x), sizeof(*(x)), 0, sizeof(*(x))) #endif /* _LIBREPLACE_REPLACE_H */ /** * Insert an array element by moving the rest one up * */ #define ARRAY_INSERT_ELEMENT(__array,__old_last_idx,__new_elem,__new_idx) do { \ if ((__new_idx) < (__old_last_idx)) { \ const void *__src = &((__array)[(__new_idx)]); \ void *__dst = &((__array)[(__new_idx)+1]); \ size_t __num = (__old_last_idx)-(__new_idx); \ size_t __len = sizeof(*(__array)) * __num; \ memmove(__dst, __src, __len); \ } \ (__array)[(__new_idx)] = (__new_elem); \ } while(0) /** * Work out how many elements there are in a static array. */ #ifdef ARRAY_SIZE #undef ARRAY_SIZE #endif #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) /** * Remove an array element by moving the rest one down */ #define ARRAY_DEL_ELEMENT(a,i,n) \ if((i)<((n)-1)){memmove(&((a)[(i)]),&((a)[(i)+1]),(sizeof(*(a))*((n)-(i)-1)));}
3,404
C++
.h
107
29.233645
80
0.659743
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,979
secace.h
altlinux_admc/src/adldap/samba/secace.h
/* Unix SMB/CIFS implementation. Samba utility functions Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifndef _ACE_H_ #define _ACE_H_ #include <gen_ndr/security.h> /* * This file is a copy of private samba sources. Parts of it * were removed or edited. */ bool sec_ace_object(uint8_t type); bool sec_ace_callback(uint8_t type); bool sec_ace_resource(uint8_t type); #endif /*_ACE_H_*/
1,058
C++
.h
26
37.692308
72
0.754403
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,980
ndr_misc.h
altlinux_admc/src/adldap/samba/src_4_20/ndr_misc.h
/* header auto-generated by pidl */ #include <ndr.h> #include <inttypes.h> // #include "samba/misc.h" #ifndef _HEADER_NDR_misc #define _HEADER_NDR_misc extern const struct ndr_interface_table ndr_table_misc; #define NDR_MISC_CALL_COUNT (0) enum ndr_err_code ndr_push_GUID(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct GUID *r); enum ndr_err_code ndr_pull_GUID(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct GUID *r); void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *r); size_t ndr_size_GUID(const struct GUID *r, libndr_flags flags); enum ndr_err_code ndr_push_ndr_syntax_id(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct ndr_syntax_id *r); enum ndr_err_code ndr_pull_ndr_syntax_id(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct ndr_syntax_id *r); void ndr_print_ndr_syntax_id(struct ndr_print *ndr, const char *name, const struct ndr_syntax_id *r); enum ndr_err_code ndr_push_policy_handle(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct policy_handle *r); enum ndr_err_code ndr_pull_policy_handle(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct policy_handle *r); void ndr_print_policy_handle(struct ndr_print *ndr, const char *name, const struct policy_handle *r); enum ndr_err_code ndr_push_netr_SchannelType(struct ndr_push *ndr, ndr_flags_type ndr_flags, enum netr_SchannelType r); enum ndr_err_code ndr_pull_netr_SchannelType(struct ndr_pull *ndr, ndr_flags_type ndr_flags, enum netr_SchannelType *r); void ndr_print_netr_SchannelType(struct ndr_print *ndr, const char *name, enum netr_SchannelType r); enum ndr_err_code ndr_push_KRB5_EDATA_NTSTATUS(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct KRB5_EDATA_NTSTATUS *r); enum ndr_err_code ndr_pull_KRB5_EDATA_NTSTATUS(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct KRB5_EDATA_NTSTATUS *r); void ndr_print_KRB5_EDATA_NTSTATUS(struct ndr_print *ndr, const char *name, const struct KRB5_EDATA_NTSTATUS *r); enum ndr_err_code ndr_push_winreg_Type(struct ndr_push *ndr, ndr_flags_type ndr_flags, enum winreg_Type r); enum ndr_err_code ndr_pull_winreg_Type(struct ndr_pull *ndr, ndr_flags_type ndr_flags, enum winreg_Type *r); void ndr_print_winreg_Type(struct ndr_print *ndr, const char *name, enum winreg_Type r); enum ndr_err_code ndr_push_winreg_Data(struct ndr_push *ndr, ndr_flags_type ndr_flags, const union winreg_Data *r); enum ndr_err_code ndr_pull_winreg_Data(struct ndr_pull *ndr, ndr_flags_type ndr_flags, union winreg_Data *r); void ndr_print_winreg_Data(struct ndr_print *ndr, const char *name, const union winreg_Data *r); enum ndr_err_code ndr_push_winreg_Data_GPO(struct ndr_push *ndr, ndr_flags_type ndr_flags, const union winreg_Data_GPO *r); enum ndr_err_code ndr_pull_winreg_Data_GPO(struct ndr_pull *ndr, ndr_flags_type ndr_flags, union winreg_Data_GPO *r); void ndr_print_winreg_Data_GPO(struct ndr_print *ndr, const char *name, const union winreg_Data_GPO *r); size_t ndr_size_winreg_Data_GPO(const union winreg_Data_GPO *r, uint32_t level, libndr_flags flags); enum ndr_err_code ndr_push_netr_SamDatabaseID(struct ndr_push *ndr, ndr_flags_type ndr_flags, enum netr_SamDatabaseID r); enum ndr_err_code ndr_pull_netr_SamDatabaseID(struct ndr_pull *ndr, ndr_flags_type ndr_flags, enum netr_SamDatabaseID *r); void ndr_print_netr_SamDatabaseID(struct ndr_print *ndr, const char *name, enum netr_SamDatabaseID r); enum ndr_err_code ndr_push_svcctl_ServerType(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t r); enum ndr_err_code ndr_pull_svcctl_ServerType(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *r); void ndr_print_svcctl_ServerType(struct ndr_print *ndr, const char *name, uint32_t r); #endif /* _HEADER_NDR_misc */
3,739
C++
.h
41
90.097561
132
0.767731
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,981
dom_sid.h
altlinux_admc/src/adldap/samba/src_4_20/dom_sid.h
/* Unix SMB/CIFS implementation. Samba utility functions Copyright (C) Stefan (metze) Metzmacher 2002-2004 Copyright (C) Andrew Tridgell 1992-2004 Copyright (C) Jeremy Allison 1999 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * This file is a copy of private samba sources. Parts of it * were removed or edited. */ #ifndef _DOM_SID_H_ #define _DOM_SID_H_ #ifdef __cplusplus extern "C" { #endif #include "replace.h" #include <talloc.h> #include "util/data_blob.h" #include "gen_ndr/security.h" /* Some well-known SIDs */ extern const struct dom_sid global_sid_World_Domain; extern const struct dom_sid global_sid_World; extern const struct dom_sid global_sid_Local_Authority; extern const struct dom_sid global_sid_Creator_Owner_Domain; extern const struct dom_sid global_sid_NT_Authority; extern const struct dom_sid global_sid_Enterprise_DCs; extern const struct dom_sid global_sid_System; extern const struct dom_sid global_sid_NULL; extern const struct dom_sid global_sid_Self; extern const struct dom_sid global_sid_Authenticated_Users; extern const struct dom_sid global_sid_Network; extern const struct dom_sid global_sid_Asserted_Identity; extern const struct dom_sid global_sid_Asserted_Identity_Service; extern const struct dom_sid global_sid_Asserted_Identity_Authentication_Authority; extern const struct dom_sid global_sid_Creator_Owner; extern const struct dom_sid global_sid_Creator_Group; extern const struct dom_sid global_sid_Owner_Rights; extern const struct dom_sid global_sid_Anonymous; extern const struct dom_sid global_sid_Compounded_Authentication; extern const struct dom_sid global_sid_Claims_Valid; extern const struct dom_sid global_sid_Builtin; extern const struct dom_sid global_sid_Builtin_Administrators; extern const struct dom_sid global_sid_Builtin_Users; extern const struct dom_sid global_sid_Builtin_Guests; extern const struct dom_sid global_sid_Builtin_Power_Users; extern const struct dom_sid global_sid_Builtin_Account_Operators; extern const struct dom_sid global_sid_Builtin_Server_Operators; extern const struct dom_sid global_sid_Builtin_Print_Operators; extern const struct dom_sid global_sid_Builtin_Backup_Operators; extern const struct dom_sid global_sid_Builtin_Replicator; extern const struct dom_sid global_sid_Builtin_PreWin2kAccess; extern const struct dom_sid global_sid_Unix_Users; extern const struct dom_sid global_sid_Unix_Groups; extern const struct dom_sid global_sid_Unix_NFS; extern const struct dom_sid global_sid_Unix_NFS_Users; extern const struct dom_sid global_sid_Unix_NFS_Groups; extern const struct dom_sid global_sid_Unix_NFS_Mode; extern const struct dom_sid global_sid_Unix_NFS_Other; extern const struct dom_sid global_sid_Samba_SMB3; extern const struct dom_sid global_sid_Samba_NPA_Flags; #define SAMBA_NPA_FLAGS_NEED_IDLE 1 #define SAMBA_NPA_FLAGS_WINBIND_OFF 2 struct auth_SidAttr; bool dom_sid_lookup_is_predefined_domain(const char *domain); int dom_sid_compare_auth(const struct dom_sid *sid1, const struct dom_sid *sid2); int dom_sid_compare(const struct dom_sid *sid1, const struct dom_sid *sid2); int dom_sid_compare_domain(const struct dom_sid *sid1, const struct dom_sid *sid2); bool dom_sid_equal(const struct dom_sid *sid1, const struct dom_sid *sid2); bool sid_append_rid(struct dom_sid *sid, uint32_t rid); bool string_to_sid(struct dom_sid *sidout, const char *sidstr); bool dom_sid_parse_endp(const char *sidstr,struct dom_sid *sidout, const char **endp); bool dom_sid_parse(const char *sidstr, struct dom_sid *ret); struct dom_sid *dom_sid_parse_talloc(TALLOC_CTX *mem_ctx, const char *sidstr); struct dom_sid *dom_sid_parse_length(TALLOC_CTX *mem_ctx, const DATA_BLOB *sid); struct dom_sid *dom_sid_dup(TALLOC_CTX *mem_ctx, const struct dom_sid *dom_sid); struct dom_sid *dom_sid_add_rid(TALLOC_CTX *mem_ctx, const struct dom_sid *domain_sid, uint32_t rid); NTSTATUS dom_sid_split_rid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, struct dom_sid **domain, uint32_t *rid); bool dom_sid_in_domain(const struct dom_sid *domain_sid, const struct dom_sid *sid); bool dom_sid_has_account_domain(const struct dom_sid *sid); bool dom_sid_is_valid_account_domain(const struct dom_sid *sid); #define DOM_SID_STR_BUFLEN (15*11+25) char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid); struct dom_sid_buf { char buf[DOM_SID_STR_BUFLEN]; }; char *dom_sid_str_buf(const struct dom_sid *sid, struct dom_sid_buf *dst); const char *sid_type_lookup(uint32_t sid_type); const struct security_token *get_system_token(void); bool sid_compose(struct dom_sid *dst, const struct dom_sid *domain_sid, uint32_t rid); bool sid_split_rid(struct dom_sid *sid, uint32_t *rid); bool sid_peek_rid(const struct dom_sid *sid, uint32_t *rid); bool sid_peek_check_rid(const struct dom_sid *exp_dom_sid, const struct dom_sid *sid, uint32_t *rid); void sid_copy(struct dom_sid *dst, const struct dom_sid *src); ssize_t sid_parse(const uint8_t *inbuf, size_t len, struct dom_sid *sid); NTSTATUS add_sid_to_array(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, struct dom_sid **sids, uint32_t *num); NTSTATUS add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, struct dom_sid **sids, uint32_t *num_sids); NTSTATUS add_sid_to_array_attrs(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, uint32_t attrs, struct auth_SidAttr **sids, uint32_t *num); NTSTATUS add_sid_to_array_attrs_unique(TALLOC_CTX *mem_ctx, const struct dom_sid *sid, uint32_t attrs, struct auth_SidAttr **sids, uint32_t *num_sids); void del_sid_from_array(const struct dom_sid *sid, struct dom_sid **sids, uint32_t *num); bool add_rid_to_array_unique(TALLOC_CTX *mem_ctx, uint32_t rid, uint32_t **pp_rids, size_t *p_num); bool is_null_sid(const struct dom_sid *sid); bool sids_contains_sid(const struct dom_sid *sids, const uint32_t num_sids, const struct dom_sid *sid); bool sid_attrs_contains_sid(const struct auth_SidAttr *sids, const uint32_t num_sids, const struct dom_sid *sid); bool sids_contains_sid_attrs(const struct auth_SidAttr *sids, const uint32_t num_sids, const struct dom_sid *sid, uint32_t attrs); #ifdef __cplusplus } #endif #endif /*_DOM_SID_H_*/
6,912
C++
.h
139
47.223022
101
0.764619
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,982
ndr_security.h
altlinux_admc/src/adldap/samba/src_4_20/ndr_security.h
/* header auto-generated by pidl */ #ifdef __cplusplus extern "C" { #endif #include <ndr.h> #include "gen_ndr/security.h" #ifndef _HEADER_NDR_security #define _HEADER_NDR_security //#include "../libcli/security/security.h" #define NDR_SECURITY_UUID "cbf7d408-2d6c-11e2-ae5b-0b5692790e18" #define NDR_SECURITY_VERSION 0.0 #define NDR_SECURITY_NAME "security" #define NDR_SECURITY_HELPSTRING NULL extern const struct ndr_interface_table ndr_table_security; #define NDR_SECURITY_CALL_COUNT (0) enum ndr_err_code ndr_push_dom_sid(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct dom_sid *r); enum ndr_err_code ndr_pull_dom_sid(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct dom_sid *r); void ndr_print_dom_sid(struct ndr_print *ndr, const char *name, const struct dom_sid *r); size_t ndr_size_dom_sid(const struct dom_sid *r, libndr_flags flags); void ndr_print_se_privilege(struct ndr_print *ndr, const char *name, uint64_t r); void ndr_print_lsa_SystemAccessModeFlags(struct ndr_print *ndr, const char *name, uint32_t r); enum ndr_err_code ndr_push_security_ace_flags(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint8_t r); enum ndr_err_code ndr_pull_security_ace_flags(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint8_t *r); void ndr_print_security_ace_flags(struct ndr_print *ndr, const char *name, uint8_t r); enum ndr_err_code ndr_push_security_ace_type(struct ndr_push *ndr, ndr_flags_type ndr_flags, enum security_ace_type r); enum ndr_err_code ndr_pull_security_ace_type(struct ndr_pull *ndr, ndr_flags_type ndr_flags, enum security_ace_type *r); void ndr_print_security_ace_type(struct ndr_print *ndr, const char *name, enum security_ace_type r); void ndr_print_security_ace_object_flags(struct ndr_print *ndr, const char *name, uint32_t r); void ndr_print_security_ace_object_type(struct ndr_print *ndr, const char *name, const union security_ace_object_type *r); void ndr_print_security_ace_object_inherited_type(struct ndr_print *ndr, const char *name, const union security_ace_object_inherited_type *r); void ndr_print_security_ace_object(struct ndr_print *ndr, const char *name, const struct security_ace_object *r); enum ndr_err_code ndr_push_security_claim_value_type(struct ndr_push *ndr, ndr_flags_type ndr_flags, enum security_claim_value_type r); enum ndr_err_code ndr_pull_security_claim_value_type(struct ndr_pull *ndr, ndr_flags_type ndr_flags, enum security_claim_value_type *r); void ndr_print_security_claim_value_type(struct ndr_print *ndr, const char *name, enum security_claim_value_type r); void ndr_print_claim_values(struct ndr_print *ndr, const char *name, const union claim_values *r); enum ndr_err_code ndr_push_CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 *r); enum ndr_err_code ndr_pull_CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 *r); void ndr_print_CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1(struct ndr_print *ndr, const char *name, const struct CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 *r); size_t ndr_size_CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1(const struct CLAIM_SECURITY_ATTRIBUTE_RELATIVE_V1 *r, libndr_flags flags); enum ndr_err_code ndr_push_security_ace_object_ctr(struct ndr_push *ndr, ndr_flags_type ndr_flags, const union security_ace_object_ctr *r); enum ndr_err_code ndr_pull_security_ace_object_ctr(struct ndr_pull *ndr, ndr_flags_type ndr_flags, union security_ace_object_ctr *r); void ndr_print_security_ace_object_ctr(struct ndr_print *ndr, const char *name, const union security_ace_object_ctr *r); enum ndr_err_code ndr_push_security_ace_coda(struct ndr_push *ndr, ndr_flags_type ndr_flags, const union security_ace_coda *r); enum ndr_err_code ndr_pull_security_ace_coda(struct ndr_pull *ndr, ndr_flags_type ndr_flags, union security_ace_coda *r); void ndr_print_security_ace_coda(struct ndr_print *ndr, const char *name, const union security_ace_coda *r); size_t ndr_size_security_ace_coda(const union security_ace_coda *r, uint32_t level, libndr_flags flags); enum ndr_err_code ndr_push_security_ace(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct security_ace *r); enum ndr_err_code ndr_pull_security_ace(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct security_ace *r); void ndr_print_security_ace(struct ndr_print *ndr, const char *name, const struct security_ace *r); size_t ndr_size_security_ace(const struct security_ace *r, libndr_flags flags); void ndr_print_security_acl_revision(struct ndr_print *ndr, const char *name, enum security_acl_revision r); enum ndr_err_code ndr_push_security_acl(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct security_acl *r); enum ndr_err_code ndr_pull_security_acl(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct security_acl *r); void ndr_print_security_acl(struct ndr_print *ndr, const char *name, const struct security_acl *r); size_t ndr_size_security_acl(const struct security_acl *r, libndr_flags flags); enum ndr_err_code ndr_push_security_descriptor_revision(struct ndr_push *ndr, ndr_flags_type ndr_flags, enum security_descriptor_revision r); enum ndr_err_code ndr_pull_security_descriptor_revision(struct ndr_pull *ndr, ndr_flags_type ndr_flags, enum security_descriptor_revision *r); void ndr_print_security_descriptor_revision(struct ndr_print *ndr, const char *name, enum security_descriptor_revision r); enum ndr_err_code ndr_push_security_descriptor_type(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint16_t r); enum ndr_err_code ndr_pull_security_descriptor_type(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint16_t *r); void ndr_print_security_descriptor_type(struct ndr_print *ndr, const char *name, uint16_t r); enum ndr_err_code ndr_push_security_descriptor(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct security_descriptor *r); enum ndr_err_code ndr_pull_security_descriptor(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct security_descriptor *r); void ndr_print_security_descriptor(struct ndr_print *ndr, const char *name, const struct security_descriptor *r); size_t ndr_size_security_descriptor(const struct security_descriptor *r, libndr_flags flags); enum ndr_err_code ndr_push_sec_desc_buf(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct sec_desc_buf *r); enum ndr_err_code ndr_pull_sec_desc_buf(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct sec_desc_buf *r); void ndr_print_sec_desc_buf(struct ndr_print *ndr, const char *name, const struct sec_desc_buf *r); enum ndr_err_code ndr_push_security_GroupAttrs(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t r); enum ndr_err_code ndr_pull_security_GroupAttrs(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *r); void ndr_print_security_GroupAttrs(struct ndr_print *ndr, const char *name, uint32_t r); void ndr_print_claims_evaluation_control(struct ndr_print *ndr, const char *name, enum claims_evaluation_control r); enum ndr_err_code ndr_push_security_token(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct security_token *r); enum ndr_err_code ndr_pull_security_token(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct security_token *r); void ndr_print_security_token(struct ndr_print *ndr, const char *name, const struct security_token *r); enum ndr_err_code ndr_push_security_token_descriptor_fuzzing_pair(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct security_token_descriptor_fuzzing_pair *r); enum ndr_err_code ndr_pull_security_token_descriptor_fuzzing_pair(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct security_token_descriptor_fuzzing_pair *r); void ndr_print_security_token_descriptor_fuzzing_pair(struct ndr_print *ndr, const char *name, const struct security_token_descriptor_fuzzing_pair *r); enum ndr_err_code ndr_push_security_unix_token(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct security_unix_token *r); enum ndr_err_code ndr_pull_security_unix_token(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct security_unix_token *r); void ndr_print_security_unix_token(struct ndr_print *ndr, const char *name, const struct security_unix_token *r); enum ndr_err_code ndr_push_security_secinfo(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t r); enum ndr_err_code ndr_pull_security_secinfo(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *r); void ndr_print_security_secinfo(struct ndr_print *ndr, const char *name, uint32_t r); enum ndr_err_code ndr_push_LSAP_TOKEN_INFO_INTEGRITY(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct LSAP_TOKEN_INFO_INTEGRITY *r); enum ndr_err_code ndr_pull_LSAP_TOKEN_INFO_INTEGRITY(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct LSAP_TOKEN_INFO_INTEGRITY *r); void ndr_print_LSAP_TOKEN_INFO_INTEGRITY(struct ndr_print *ndr, const char *name, const struct LSAP_TOKEN_INFO_INTEGRITY *r); size_t ndr_size_LSAP_TOKEN_INFO_INTEGRITY(const struct LSAP_TOKEN_INFO_INTEGRITY *r, libndr_flags flags); enum ndr_err_code ndr_push_kerb_EncTypes(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t r); enum ndr_err_code ndr_pull_kerb_EncTypes(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *r); void ndr_print_kerb_EncTypes(struct ndr_print *ndr, const char *name, uint32_t r); enum ndr_err_code ndr_push_security_autoinherit(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t r); enum ndr_err_code ndr_pull_security_autoinherit(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *r); void ndr_print_security_autoinherit(struct ndr_print *ndr, const char *name, uint32_t r); #endif /* _HEADER_NDR_security */ #ifdef __cplusplus } #endif
9,677
C++
.h
98
97.693878
170
0.779194
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,983
ndr_misc.h
altlinux_admc/src/adldap/samba/src_older/ndr_misc.h
/* * Unix SMB/CIFS implementation. * Group Policy Object Support * Copyright (C) Wilco Baan Hofman 2010 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. */ /* * This file is a copy of private samba generated sources. */ #ifdef __cplusplus extern "C" { #endif #include <ndr.h> /* header auto-generated by pidl */ // #include "librpc/ndr/libndr.h" // #include "bin/default/librpc/gen_ndr/misc.h" #ifndef _HEADER_NDR_misc #define _HEADER_NDR_misc extern const struct ndr_interface_table ndr_table_misc; #define NDR_MISC_CALL_COUNT (0) enum ndr_err_code ndr_push_GUID(struct ndr_push *ndr, int ndr_flags, const struct GUID *r); enum ndr_err_code ndr_pull_GUID(struct ndr_pull *ndr, int ndr_flags, struct GUID *r); void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *r); size_t ndr_size_GUID(const struct GUID *r, int flags); enum ndr_err_code ndr_push_ndr_syntax_id(struct ndr_push *ndr, int ndr_flags, const struct ndr_syntax_id *r); enum ndr_err_code ndr_pull_ndr_syntax_id(struct ndr_pull *ndr, int ndr_flags, struct ndr_syntax_id *r); void ndr_print_ndr_syntax_id(struct ndr_print *ndr, const char *name, const struct ndr_syntax_id *r); enum ndr_err_code ndr_push_policy_handle(struct ndr_push *ndr, int ndr_flags, const struct policy_handle *r); enum ndr_err_code ndr_pull_policy_handle(struct ndr_pull *ndr, int ndr_flags, struct policy_handle *r); void ndr_print_policy_handle(struct ndr_print *ndr, const char *name, const struct policy_handle *r); enum ndr_err_code ndr_push_netr_SchannelType(struct ndr_push *ndr, int ndr_flags, enum netr_SchannelType r); enum ndr_err_code ndr_pull_netr_SchannelType(struct ndr_pull *ndr, int ndr_flags, enum netr_SchannelType *r); void ndr_print_netr_SchannelType(struct ndr_print *ndr, const char *name, enum netr_SchannelType r); enum ndr_err_code ndr_push_KRB5_EDATA_NTSTATUS(struct ndr_push *ndr, int ndr_flags, const struct KRB5_EDATA_NTSTATUS *r); enum ndr_err_code ndr_pull_KRB5_EDATA_NTSTATUS(struct ndr_pull *ndr, int ndr_flags, struct KRB5_EDATA_NTSTATUS *r); void ndr_print_KRB5_EDATA_NTSTATUS(struct ndr_print *ndr, const char *name, const struct KRB5_EDATA_NTSTATUS *r); enum ndr_err_code ndr_push_winreg_Type(struct ndr_push *ndr, int ndr_flags, enum winreg_Type r); enum ndr_err_code ndr_pull_winreg_Type(struct ndr_pull *ndr, int ndr_flags, enum winreg_Type *r); void ndr_print_winreg_Type(struct ndr_print *ndr, const char *name, enum winreg_Type r); enum ndr_err_code ndr_push_winreg_Data(struct ndr_push *ndr, int ndr_flags, const union winreg_Data *r); enum ndr_err_code ndr_pull_winreg_Data(struct ndr_pull *ndr, int ndr_flags, union winreg_Data *r); void ndr_print_winreg_Data(struct ndr_print *ndr, const char *name, const union winreg_Data *r); enum ndr_err_code ndr_push_winreg_Data_GPO(struct ndr_push *ndr, int ndr_flags, const union winreg_Data_GPO *r); enum ndr_err_code ndr_pull_winreg_Data_GPO(struct ndr_pull *ndr, int ndr_flags, union winreg_Data_GPO *r); void ndr_print_winreg_Data_GPO(struct ndr_print *ndr, const char *name, const union winreg_Data_GPO *r); size_t ndr_size_winreg_Data_GPO(const union winreg_Data_GPO *r, uint32_t level, int flags); enum ndr_err_code ndr_push_netr_SamDatabaseID(struct ndr_push *ndr, int ndr_flags, enum netr_SamDatabaseID r); enum ndr_err_code ndr_pull_netr_SamDatabaseID(struct ndr_pull *ndr, int ndr_flags, enum netr_SamDatabaseID *r); void ndr_print_netr_SamDatabaseID(struct ndr_print *ndr, const char *name, enum netr_SamDatabaseID r); enum ndr_err_code ndr_push_svcctl_ServerType(struct ndr_push *ndr, int ndr_flags, uint32_t r); enum ndr_err_code ndr_pull_svcctl_ServerType(struct ndr_pull *ndr, int ndr_flags, uint32_t *r); void ndr_print_svcctl_ServerType(struct ndr_print *ndr, const char *name, uint32_t r); #endif /* _HEADER_NDR_misc */ #ifdef __cplusplus } #endif
4,443
C++
.h
68
63.941176
121
0.759789
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,984
ndr_security.h
altlinux_admc/src/adldap/samba/src_older/ndr_security.h
/* * Unix SMB/CIFS implementation. * Group Policy Object Support * Copyright (C) Wilco Baan Hofman 2010 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses/>. */ /* * This file is a copy of private samba sources. */ #ifdef __cplusplus extern "C" { #endif #include <ndr.h> #include <gen_ndr/security.h> /* header auto-generated by pidl */ // #include "librpc/ndr/libndr.h" // #include "bin/default/librpc/gen_ndr/security.h" #ifndef _HEADER_NDR_security #define _HEADER_NDR_security #define NDR_SECURITY_UUID "cbf7d408-2d6c-11e2-ae5b-0b5692790e18" #define NDR_SECURITY_VERSION 0.0 #define NDR_SECURITY_NAME "security" #define NDR_SECURITY_HELPSTRING NULL extern const struct ndr_interface_table ndr_table_security; #define NDR_SECURITY_CALL_COUNT (0) enum ndr_err_code ndr_push_dom_sid(struct ndr_push *ndr, int ndr_flags, const struct dom_sid *r); enum ndr_err_code ndr_pull_dom_sid(struct ndr_pull *ndr, int ndr_flags, struct dom_sid *r); void ndr_print_dom_sid(struct ndr_print *ndr, const char *name, const struct dom_sid *r); size_t ndr_size_dom_sid(const struct dom_sid *r, int flags); void ndr_print_se_privilege(struct ndr_print *ndr, const char *name, uint64_t r); void ndr_print_lsa_SystemAccessModeFlags(struct ndr_print *ndr, const char *name, uint32_t r); enum ndr_err_code ndr_push_security_ace_flags(struct ndr_push *ndr, int ndr_flags, uint8_t r); enum ndr_err_code ndr_pull_security_ace_flags(struct ndr_pull *ndr, int ndr_flags, uint8_t *r); void ndr_print_security_ace_flags(struct ndr_print *ndr, const char *name, uint8_t r); enum ndr_err_code ndr_push_security_ace_type(struct ndr_push *ndr, int ndr_flags, enum security_ace_type r); enum ndr_err_code ndr_pull_security_ace_type(struct ndr_pull *ndr, int ndr_flags, enum security_ace_type *r); void ndr_print_security_ace_type(struct ndr_print *ndr, const char *name, enum security_ace_type r); void ndr_print_security_ace_object_flags(struct ndr_print *ndr, const char *name, uint32_t r); void ndr_print_security_ace_object_type(struct ndr_print *ndr, const char *name, const union security_ace_object_type *r); void ndr_print_security_ace_object_inherited_type(struct ndr_print *ndr, const char *name, const union security_ace_object_inherited_type *r); void ndr_print_security_ace_object(struct ndr_print *ndr, const char *name, const struct security_ace_object *r); enum ndr_err_code ndr_push_security_ace_object_ctr(struct ndr_push *ndr, int ndr_flags, const union security_ace_object_ctr *r); enum ndr_err_code ndr_pull_security_ace_object_ctr(struct ndr_pull *ndr, int ndr_flags, union security_ace_object_ctr *r); void ndr_print_security_ace_object_ctr(struct ndr_print *ndr, const char *name, const union security_ace_object_ctr *r); enum ndr_err_code ndr_push_security_ace(struct ndr_push *ndr, int ndr_flags, const struct security_ace *r); enum ndr_err_code ndr_pull_security_ace(struct ndr_pull *ndr, int ndr_flags, struct security_ace *r); void ndr_print_security_ace(struct ndr_print *ndr, const char *name, const struct security_ace *r); size_t ndr_size_security_ace(const struct security_ace *r, int flags); void ndr_print_security_acl_revision(struct ndr_print *ndr, const char *name, enum security_acl_revision r); enum ndr_err_code ndr_push_security_acl(struct ndr_push *ndr, int ndr_flags, const struct security_acl *r); enum ndr_err_code ndr_pull_security_acl(struct ndr_pull *ndr, int ndr_flags, struct security_acl *r); void ndr_print_security_acl(struct ndr_print *ndr, const char *name, const struct security_acl *r); size_t ndr_size_security_acl(const struct security_acl *r, int flags); enum ndr_err_code ndr_push_security_descriptor_revision(struct ndr_push *ndr, int ndr_flags, enum security_descriptor_revision r); enum ndr_err_code ndr_pull_security_descriptor_revision(struct ndr_pull *ndr, int ndr_flags, enum security_descriptor_revision *r); void ndr_print_security_descriptor_revision(struct ndr_print *ndr, const char *name, enum security_descriptor_revision r); enum ndr_err_code ndr_push_security_descriptor_type(struct ndr_push *ndr, int ndr_flags, uint16_t r); enum ndr_err_code ndr_pull_security_descriptor_type(struct ndr_pull *ndr, int ndr_flags, uint16_t *r); void ndr_print_security_descriptor_type(struct ndr_print *ndr, const char *name, uint16_t r); enum ndr_err_code ndr_push_security_descriptor(struct ndr_push *ndr, int ndr_flags, const struct security_descriptor *r); enum ndr_err_code ndr_pull_security_descriptor(struct ndr_pull *ndr, int ndr_flags, struct security_descriptor *r); void ndr_print_security_descriptor(struct ndr_print *ndr, const char *name, const struct security_descriptor *r); size_t ndr_size_security_descriptor(const struct security_descriptor *r, int flags); enum ndr_err_code ndr_push_sec_desc_buf(struct ndr_push *ndr, int ndr_flags, const struct sec_desc_buf *r); enum ndr_err_code ndr_pull_sec_desc_buf(struct ndr_pull *ndr, int ndr_flags, struct sec_desc_buf *r); void ndr_print_sec_desc_buf(struct ndr_print *ndr, const char *name, const struct sec_desc_buf *r); enum ndr_err_code ndr_push_security_GroupAttrs(struct ndr_push *ndr, int ndr_flags, uint32_t r); enum ndr_err_code ndr_pull_security_GroupAttrs(struct ndr_pull *ndr, int ndr_flags, uint32_t *r); void ndr_print_security_GroupAttrs(struct ndr_print *ndr, const char *name, uint32_t r); enum ndr_err_code ndr_push_security_token(struct ndr_push *ndr, int ndr_flags, const struct security_token *r); enum ndr_err_code ndr_pull_security_token(struct ndr_pull *ndr, int ndr_flags, struct security_token *r); void ndr_print_security_token(struct ndr_print *ndr, const char *name, const struct security_token *r); enum ndr_err_code ndr_push_security_unix_token(struct ndr_push *ndr, int ndr_flags, const struct security_unix_token *r); enum ndr_err_code ndr_pull_security_unix_token(struct ndr_pull *ndr, int ndr_flags, struct security_unix_token *r); void ndr_print_security_unix_token(struct ndr_print *ndr, const char *name, const struct security_unix_token *r); enum ndr_err_code ndr_push_security_secinfo(struct ndr_push *ndr, int ndr_flags, uint32_t r); enum ndr_err_code ndr_pull_security_secinfo(struct ndr_pull *ndr, int ndr_flags, uint32_t *r); void ndr_print_security_secinfo(struct ndr_print *ndr, const char *name, uint32_t r); enum ndr_err_code ndr_push_LSAP_TOKEN_INFO_INTEGRITY(struct ndr_push *ndr, int ndr_flags, const struct LSAP_TOKEN_INFO_INTEGRITY *r); enum ndr_err_code ndr_pull_LSAP_TOKEN_INFO_INTEGRITY(struct ndr_pull *ndr, int ndr_flags, struct LSAP_TOKEN_INFO_INTEGRITY *r); void ndr_print_LSAP_TOKEN_INFO_INTEGRITY(struct ndr_print *ndr, const char *name, const struct LSAP_TOKEN_INFO_INTEGRITY *r); size_t ndr_size_LSAP_TOKEN_INFO_INTEGRITY(const struct LSAP_TOKEN_INFO_INTEGRITY *r, int flags); enum ndr_err_code ndr_push_kerb_EncTypes(struct ndr_push *ndr, int ndr_flags, uint32_t r); enum ndr_err_code ndr_pull_kerb_EncTypes(struct ndr_pull *ndr, int ndr_flags, uint32_t *r); void ndr_print_kerb_EncTypes(struct ndr_print *ndr, const char *name, uint32_t r); enum ndr_err_code ndr_push_security_autoinherit(struct ndr_push *ndr, int ndr_flags, uint32_t r); enum ndr_err_code ndr_pull_security_autoinherit(struct ndr_pull *ndr, int ndr_flags, uint32_t *r); void ndr_print_security_autoinherit(struct ndr_print *ndr, const char *name, uint32_t r); #endif /* _HEADER_NDR_security */ #ifdef __cplusplus } #endif
7,970
C++
.h
104
75.375
142
0.76928
altlinux/admc
36
14
14
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,985
about.cpp
LazyT_lmgr/about.cpp
#include "about.h" aboutDialog::aboutDialog(QWidget *parent) : QDialog(parent) { setupUi(this); layout()->setSizeConstraint(QLayout::SetFixedSize); setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint); label_Name->setText(QString("%1").arg(APPNAME)); label_Version->setText(tr("Version %1 - %2").arg(APPVERS, APPDATE)); textEdit->setAlignment(Qt::AlignCenter); textEdit->textCursor().insertText(tr("This program is Freeware and may be installed and used free of charge for non-commercial use on as many computers as you like without limitations.\n\nA liability for any damages resulting from the use is excluded. Use at your own risk!")); textEdit->moveCursor(QTextCursor::Start); textEdit->setFixedHeight(5 * textEdit->fontMetrics().height() + textEdit->document()->documentMargin() + 2); } void aboutDialog::mouseReleaseEvent(QMouseEvent *me) { QWidget *child = QWidget::childAt(me->pos()); if(child) { QString name = child->objectName(); if(name == "label_Mail") { QDesktopServices::openUrl(QUrl(QByteArray::fromBase64("bWFpbHRvOkxhenlUQG1haWxib3gub3JnP3N1YmplY3Q9TE1HUiZib2R5PVdyaXRlIGluIEVuZ2xpc2ggb3IgR2VybWFuIHBsZWFzZS4uLg=="))); } else if(name == "label_Forum") { QDesktopServices::openUrl(QUrl(QByteArray::fromBase64("aHR0cHM6Ly9mb3J1bS54ZGEtZGV2ZWxvcGVycy5jb20vazIwLXByby90aGVtZXMvYXBwLWxvZ28tbWFuYWdlci1zcGxhc2gtc2NyZWVucy10NDA4NDQ1NQ=="))); } else if(name == "label_Donation") { if(QMessageBox::warning(this, APPNAME, tr("Please note the following points:\n\n* The payment is made voluntarily without the acquisition of claims.\n* You receive no rights to the offered software.\n* Because this is not a donation in juridical sense no certificate can be issued.\n\nWould you like to support the further development of this project nevertheless?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { QDesktopServices::openUrl(QUrl(QByteArray::fromBase64("aHR0cHM6Ly93d3cucGF5cGFsLmNvbS9jZ2ktYmluL3dlYnNjcj9jbWQ9X2RvbmF0aW9ucyZidXNpbmVzcz1MYXp5VEBtYWlsYm94Lm9yZyZpdGVtX25hbWU9TG9nbyUyME1hbmFnZXImYW1vdW50PTAmY3VycmVuY3lfY29kZT1FVVI="))); } } } }
2,152
C++
.cpp
36
57.138889
445
0.792319
LazyT/lmgr
35
8
0
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,986
mainwindow.cpp
LazyT_lmgr/mainwindow.cpp
#include "mainwindow.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow win; win.show(); return app.exec(); } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // QApplication::setStyle("Fusion"); QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton); if(!QLocale::system().name().startsWith("en_")) { if(appTranslator.load("lmgr_" + QLocale::system().name(), QApplication::applicationDirPath() + "/lng")) { QApplication::installTranslator(&appTranslator); if(baseTranslator.load("qtbase_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { QApplication::installTranslator(&baseTranslator); } else if(baseTranslator.load("qtbase_" + QLocale::system().name(), QApplication::applicationDirPath() + "/lng")) { QApplication::installTranslator(&baseTranslator); } if(helpTranslator.load("qt_help_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { QApplication::installTranslator(&helpTranslator); } else if(helpTranslator.load("qt_help_" + QLocale::system().name(), QApplication::applicationDirPath() + "/lng")) { QApplication::installTranslator(&helpTranslator); } } } setupUi(this); lcd = new QLCDNumber(1); lcd->setToolTip(tr("Logo Screens")); lcd->setStatusTip(tr("Logo Screens")); toolBar->insertWidget(actionNextLogo, lcd); logo_5->hide(); logo_6->hide(); logo_7->hide(); logo_8->hide(); logo_9->hide(); resize(0, 0); QTimer::singleShot(1, this, SLOT(centerOnScreen())); } void MainWindow::centerOnScreen() { lcd->setMinimumWidth(lcd->width() + 20); lcd->setMaximumHeight(lcd->height() - 20); move(screen()->geometry().center() - rect().center()); } quint32 MainWindow::calcLogo(int pos) { QByteArray data = logo.mid(pos, 4); return (static_cast<quint8>(data.at(1)) << 24 | static_cast<quint8>(data.at(0)) << 16 | static_cast<quint8>(data.at(3)) << 8 | static_cast<quint8>(data.at(2))) >> 4; } bool MainWindow::loadLogo(quint32 ofs, quint32 len, int index) { QPixmap pm; QLabel *img[9] = { label_1_img, label_2_img, label_3_img, label_4_img, label_5_img, label_6_img, label_7_img, label_8_img, label_9_img }; QLabel *txt[9] = { label_1_txt, label_2_txt, label_3_txt, label_4_txt, label_5_txt, label_6_txt, label_7_txt, label_8_txt, label_9_txt }; bool result = pm.loadFromData(logo.mid(ofs, len), "BMP"); if(result) { img[index]->setPixmap(pm); txt[index]->setText(QString("%1 x %2\n").arg(pm.width()).arg(pm.height()) + "0x" + QString("%1\n").arg(ofs, 8, 16, QChar('0')).toUpper() + "0x" + QString("%1").arg(len, 8, 16, QChar('0')).toUpper()); } else { img[index]->setPixmap(QPixmap(":/png/png/warning.png").scaled(128, 128, Qt::KeepAspectRatio)); txt[index]->setText("\n?\n"); } return result; } void MainWindow::saveLogo(QFile &file, int index) { QByteArray arr; QBuffer buf(&arr); QLabel *img[9] = { label_1_img, label_2_img, label_3_img, label_4_img, label_5_img, label_6_img, label_7_img, label_8_img, label_9_img }; buf.open(QIODevice::WriteOnly); img[index]->pixmap()->save(&buf, "BMP"); file.write(arr); file.write(QByteArray(logo_len[index] - arr.size(), 0x00)); buf.close(); } void MainWindow::importImage(QLabel *pic, QLabel *txt, int ofs, int len) { QFile file(QFileDialog::getOpenFileName(this, tr("Import Logo Screen"), QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)+ QString("/logo%1.png").arg(pic->objectName().mid(6, 1)), "Images (*.png *.jpg *.bmp)", nullptr, QFileDialog::DontUseNativeDialog)); if(!file.fileName().isEmpty()) { QPixmap img(file.fileName()); if(img.width() != pic->pixmap()->width() || img.height() != pic->pixmap()->height()) { QMessageBox::warning(this, APPNAME, tr("Selected logo screen will be scaled from %1x%2 to %3x%4!").arg(img.width()).arg(img.height()).arg(pic->pixmap()->width()).arg(pic->pixmap()->height())); } pic->setPixmap(img.scaled(pic->pixmap()->width(), pic->pixmap()->height())); txt->setText(QString("%1 x %2\n").arg(pic->pixmap()->width()).arg(pic->pixmap()->height()) + "0x" + QString("%1\n").arg(ofs, 8, 16, QChar('0')).toUpper() + "0x" + QString("%1").arg(len, 8, 16, QChar('0')).toUpper()); } } void MainWindow::exportImage(QLabel *label) { QImage img = label->pixmap()->toImage().convertToFormat(QImage::Format_RGB888); QFile save(QFileDialog::getSaveFileName(this, tr("Export Logo Screen"), QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + QString("/logo%1.png").arg(label->objectName().mid(6, 1)), "Images (*.png *.jpg *.bmp);;Raw (*.raw)", nullptr, QFileDialog::DontUseNativeDialog)); if(!save.fileName().isEmpty()) { if(save.fileName().endsWith(".raw")) { bool rc = false; qint64 bytes = -1; if((rc = save.open(QIODevice::WriteOnly))) { bytes = save.write(reinterpret_cast<char*>(img.bits()), img.sizeInBytes()); save.close(); } if(rc == false || bytes == -1) { QMessageBox::warning(this, APPNAME, tr("Logo screen export failed!\n\n%1").arg(save.errorString())); } else { QMessageBox::information(this, APPNAME, tr("Logo screen export successfull.")); } } else { if(img.save(save.fileName())) { QMessageBox::information(this, APPNAME, tr("Logo screen export successfull.")); } else { QMessageBox::warning(this, APPNAME, tr("Logo screen export failed!\n\n%1").arg(save.errorString())); } } } } void MainWindow::on_actionExit_triggered() { close(); } bool MainWindow::on_actionOpen_triggered() { QFile file(QFileDialog::getOpenFileName(this, open_text, QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/logo.img", "logo*.img", nullptr, QFileDialog::DontUseNativeDialog)); flash_file = file.fileName(); open_text = tr("Import Logo Image"); if(!file.fileName().isEmpty()) { if(file.open(QIODevice::ReadOnly)) { logo = file.readAll(); file.close(); if(logo.mid(0x4000, 8) != "LOGO!!!!") { QMessageBox::warning(this, APPNAME, tr("Doesn't look like a supported logo image!\n\nNo \"LOGO!!!!\" header @ 0x4000...")); } else { int index = 0; int logos = 0; bool mixed = true; bool failed = false; quint32 val1, val2; startscreen = 0; logo_9->hide(); logo_8->hide(); logo_7->hide(); logo_6->hide(); logo_5->hide(); logo_4->show(); logo_3->show(); logo_2->show(); logo_1->show(); actionPrevLogo->setEnabled(false); actionNextLogo->setEnabled(false); pushButton_1_imp->setEnabled(false); pushButton_2_imp->setEnabled(false); pushButton_3_imp->setEnabled(false); pushButton_4_imp->setEnabled(false); pushButton_5_imp->setEnabled(false); pushButton_6_imp->setEnabled(false); pushButton_7_imp->setEnabled(false); pushButton_8_imp->setEnabled(false); pushButton_9_imp->setEnabled(false); pushButton_1_exp->setEnabled(false); pushButton_2_exp->setEnabled(false); pushButton_3_exp->setEnabled(false); pushButton_4_exp->setEnabled(false); pushButton_5_exp->setEnabled(false); pushButton_6_exp->setEnabled(false); pushButton_7_exp->setEnabled(false); pushButton_8_exp->setEnabled(false); pushButton_9_exp->setEnabled(false); actionSave->setEnabled(false); if(logo.mid(calcLogo(0x4008), 2).toHex() == "424d" && logo.mid(calcLogo(0x400C), 2).toHex() == "424d") { while(logo.mid(calcLogo(0x4008 + logos*4), 2).toHex() == "424d") { logos++; }; mixed = false; } do { if(mixed) { val1 = calcLogo(0x4008 + index*8 + 0); val2 = calcLogo(0x4008 + index*8 + 4); } else { val1 = calcLogo(0x4008 + index*4 + 0); val2 = calcLogo(0x4008 + index*4 + logos*4); } if(val1 && val2) { if(index < 9) { logo_ofs[index] = val1; logo_len[index] = val2; if(!loadLogo(val1, val2, index)) { failed = true; } } index++; } } while((val1 && val2)); screens = index; lcd->display(screens); if(screens > 4) { actionNextLogo->setEnabled(true); } if(screens > 9) { QMessageBox::warning(this, APPNAME, tr("More than 9 logo screens found!\n\nThis is not supported yet...")); actionSave->setEnabled(false); return false; } if(failed) { QMessageBox::warning(this, APPNAME, tr("Could not load logo screens!")); return false; } else { pushButton_1_imp->setEnabled(true); pushButton_2_imp->setEnabled(true); pushButton_3_imp->setEnabled(true); pushButton_4_imp->setEnabled(true); pushButton_5_imp->setEnabled(true); pushButton_6_imp->setEnabled(true); pushButton_7_imp->setEnabled(true); pushButton_8_imp->setEnabled(true); pushButton_9_imp->setEnabled(true); pushButton_1_exp->setEnabled(true); pushButton_2_exp->setEnabled(true); pushButton_3_exp->setEnabled(true); pushButton_4_exp->setEnabled(true); pushButton_5_exp->setEnabled(true); pushButton_6_exp->setEnabled(true); pushButton_7_exp->setEnabled(true); pushButton_8_exp->setEnabled(true); pushButton_9_exp->setEnabled(true); actionSave->setEnabled(true); } return true; } } else { QMessageBox::warning(this, APPNAME, tr("Could not open logo image!\n\n%1").arg(file.errorString())); } } return false; } void MainWindow::on_actionSave_triggered() { QFile file(QFileDialog::getSaveFileName(this, tr("Export Logo Image"), QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/logo.img", "logo*.img", nullptr, QFileDialog::DontUseNativeDialog)); if(!file.fileName().isEmpty()) { if(file.open(QIODevice::WriteOnly)) { file.write(logo.mid(0, logo_ofs[0])); for(int logo = 0; logo < screens; logo++) { saveLogo(file, logo); } file.close(); QMessageBox::information(this, APPNAME, tr("Logo image saved successfully.")); } else { QMessageBox::critical(this, APPNAME, tr("Could not save logo image!\n\n%1").arg(file.errorString())); } } } void MainWindow::on_actionDump_triggered() { if(QMessageBox::question(this, APPNAME, tr("Dumping logo image needs root!\n\nReally continue?")) == QMessageBox::Yes) { flashDialog(this, DUMP).exec(); } } void MainWindow::on_actionFlash_triggered() { if(QMessageBox::question(this, APPNAME, tr("Flashing wrong logo image may brick your device!\n\nReally continue?")) == QMessageBox::Yes) { open_text = tr("Flash Logo Image"); if(on_actionOpen_triggered()) { flashDialog(this, FLASH).exec(); } } } void MainWindow::on_actionPrevLogo_triggered() { QWidget *logos[9] = { logo_1, logo_2, logo_3, logo_4, logo_5, logo_6, logo_7, logo_8, logo_9 }; if(startscreen > 0) { startscreen--; logos[startscreen + 4]->hide(); logos[startscreen]->show(); } if(startscreen == 0) { actionPrevLogo->setEnabled(false); } if(!actionNextLogo->isEnabled()) { actionNextLogo->setEnabled(true); } } void MainWindow::on_actionNextLogo_triggered() { QWidget *logos[9] = { logo_1, logo_2, logo_3, logo_4, logo_5, logo_6, logo_7, logo_8, logo_9 }; if(startscreen < screens - 4) { logos[startscreen]->hide(); logos[startscreen + 4]->show(); startscreen++; } if(startscreen == screens - 4) { actionNextLogo->setEnabled(false); } if(!actionPrevLogo->isEnabled()) { actionPrevLogo->setEnabled(true); } } void MainWindow::on_actionAbout_triggered() { aboutDialog(this).exec(); } void MainWindow::on_actionHelp_triggered() { helpDialog(this).exec(); } void MainWindow::on_actionUpdate_triggered() { new onlineUpdDialog(this, false); } void MainWindow::on_pushButton_1_imp_clicked() { importImage(label_1_img, label_1_txt, logo_ofs[0], logo_len[0]); } void MainWindow::on_pushButton_2_imp_clicked() { importImage(label_2_img, label_2_txt, logo_ofs[1], logo_len[1]); } void MainWindow::on_pushButton_3_imp_clicked() { importImage(label_3_img, label_3_txt, logo_ofs[2], logo_len[2]); } void MainWindow::on_pushButton_4_imp_clicked() { importImage(label_4_img, label_4_txt, logo_ofs[3], logo_len[3]); } void MainWindow::on_pushButton_5_imp_clicked() { importImage(label_5_img, label_5_txt, logo_ofs[4], logo_len[4]); } void MainWindow::on_pushButton_6_imp_clicked() { importImage(label_6_img, label_6_txt, logo_ofs[5], logo_len[5]); } void MainWindow::on_pushButton_7_imp_clicked() { importImage(label_7_img, label_7_txt, logo_ofs[6], logo_len[6]); } void MainWindow::on_pushButton_8_imp_clicked() { importImage(label_8_img, label_8_txt, logo_ofs[7], logo_len[7]); } void MainWindow::on_pushButton_9_imp_clicked() { importImage(label_9_img, label_9_txt, logo_ofs[8], logo_len[8]); } void MainWindow::on_pushButton_1_exp_clicked() { exportImage(label_1_img); } void MainWindow::on_pushButton_2_exp_clicked() { exportImage(label_2_img); } void MainWindow::on_pushButton_3_exp_clicked() { exportImage(label_3_img); } void MainWindow::on_pushButton_4_exp_clicked() { exportImage(label_4_img); } void MainWindow::on_pushButton_5_exp_clicked() { exportImage(label_5_img); } void MainWindow::on_pushButton_6_exp_clicked() { exportImage(label_6_img); } void MainWindow::on_pushButton_7_exp_clicked() { exportImage(label_7_img); } void MainWindow::on_pushButton_8_exp_clicked() { exportImage(label_8_img); } void MainWindow::on_pushButton_9_exp_clicked() { exportImage(label_9_img); } void MainWindow::keyPressEvent(QKeyEvent *ke) { if(ke->key() == Qt::Key_F1) { on_actionHelp_triggered(); } else if(ke->key() == Qt::Key_Escape) { close(); } QMainWindow::keyPressEvent(ke); } void MainWindow::closeEvent(QCloseEvent *ce) { if(forceclose || QMessageBox::question(this, APPNAME, tr("Really exit program?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { ce->accept(); } else { ce->ignore(); } }
14,014
C++
.cpp
462
27.080087
288
0.680003
LazyT/lmgr
35
8
0
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,987
help.cpp
LazyT_lmgr/help.cpp
#include "help.h" helpDialog::helpDialog(QWidget *parent) : QDialog(parent) { setupUi(this); setWindowFlags(Qt::Window | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint); lng = QFile::exists(QString("%1/hlp/%2.qhc").arg(QApplication::applicationDirPath()).arg(QLocale::system().name().mid(0, 2))) ? QLocale::system().name().mid(0, 2) : "en"; helpEngine = new QHelpEngine(QString("%1/hlp/%2.qhc").arg(QApplication::applicationDirPath()).arg(lng)); helpEngine->setupData(); contentWidget = helpEngine->contentWidget(); verticalLayout->addWidget((QWidget*)contentWidget); helpBrowser->setHelpEngine(helpEngine); helpBrowser->setSource(QUrl(QString("qthelp://de.lazyt.lmgr/help/%1.html").arg(lng))); connect(contentWidget, SIGNAL(clicked(QModelIndex)), this, SLOT(setSourceFromContent(QModelIndex))); connect(contentWidget, SIGNAL(activated(QModelIndex)), this, SLOT(setSourceFromContent(QModelIndex))); QTimer::singleShot(100, this, SLOT(expand())); } void helpDialog::setSourceFromContent(QModelIndex index) { helpBrowser->setSource(helpEngine->contentModel()->contentItemAt(index)->url()); } void helpDialog::expand() { contentWidget->expandAll(); }
1,182
C++
.cpp
24
47.25
171
0.766551
LazyT/lmgr
35
8
0
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,988
flash.cpp
LazyT_lmgr/flash.cpp
#include "flash.h" flashDialog::flashDialog(QWidget *parent, bool mode) : QDialog(parent) { setupUi(this); setWindowFlags(Qt::Window | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint); buttonBox->button(QDialogButtonBox::Retry)->setEnabled(false); if(mode == DUMP) { setWindowTitle(tr("Dump Logo Image")); label_4->setDisabled(true); label_fbt->setDisabled(true); } usbmode = mode; QTimer::singleShot(250, this, SLOT(initADB())); } void flashDialog::prg_errorOccurred(__attribute__((unused)) QProcess::ProcessError error) { QMessageBox::critical(this, APPNAME,tr("Could not run command!\n\n%1").arg(process->errorString())); failed = true; running = false; } void flashDialog::prg_readyReadStandardOutput() { QString response = process->readAll(); response.replace("\r\n", "\n"); if(response != "\r\n" && response != "\n") { process_output = response; if(!response.endsWith("\n")) { response.append("\n"); } if(response.contains("error") || response.contains("FAILED") || response.contains("unauthorized") || response.contains("permissions") || response.contains("denied")) { textcolor = textEdit->textColor(); textEdit->setTextColor(Qt::red); textEdit->append(response.replace("\n\n", "\n")); textEdit->setTextColor(textcolor); } else { textEdit->append(response.replace("\n\n", "\n")); } } } void flashDialog::prg_finished(__attribute__((unused)) int exitCode, __attribute__((unused)) QProcess::ExitStatus exitStatus) { running = false; } void flashDialog::sendCommand(QString cmd) { textcolor = textEdit->textColor(); fontweight = textEdit->fontWeight(); textEdit->setTextColor(Qt::blue); textEdit->setFontWeight(QFont::Bold); textEdit->append(cmd); textEdit->setTextColor(textcolor); textEdit->setFontWeight(fontweight); failed = false; running = true; process->start(QString("%1/%2").arg(QApplication::applicationDirPath()).arg(cmd)); while(running) { QApplication::processEvents(); } } void flashDialog::initADB() { process = new QProcess(this); process->setProcessChannelMode(QProcess::MergedChannels); connect(process, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(prg_errorOccurred(QProcess::ProcessError))); connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(prg_readyReadStandardOutput())); connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(prg_finished(int, QProcess::ExitStatus))); sendCommand("adb devices"); if(process_output.contains("List of devices attached\n\n")) { label_adb->setPixmap(QPixmap(":/png/png/con-err.png")); buttonBox->button(QDialogButtonBox::Retry)->setEnabled(true); QMessageBox::warning(this, APPNAME, tr("No device found!\n\nConnect device via usb and try again...")); } else if(process_output.contains("unauthorized")) { label_serial->setText(process_output.split("\n").at(1).split("\t").at(0)); label_adb->setPixmap(QPixmap(":/png/png/con-err.png")); buttonBox->button(QDialogButtonBox::Retry)->setEnabled(true); QMessageBox::warning(this, APPNAME, tr("Unauthorized device found!\n\nAuthorize on phone and try again...")); } else if(process_output.contains("permissions")) { label_serial->setText(process_output.split("\n").at(1).split("\t").at(0)); label_adb->setPixmap(QPixmap(":/png/png/con-err.png")); buttonBox->button(QDialogButtonBox::Retry)->setEnabled(true); QMessageBox::warning(this, APPNAME, tr("No permissions for device!\n\nFix and try again...")); } else if(process_output.contains("List of devices attached\n")) { buttonBox->button(QDialogButtonBox::Retry)->setEnabled(false); label_serial->setText(process_output.split("\n").at(1).split("\t").at(0)); label_adb->setPixmap(QPixmap(":/png/png/con-suc.png")); sendCommand("adb shell getprop ro.product.model"); label_model->setText(process_output.simplified()); sendCommand("adb shell getprop ro.product.device"); label_device->setText(process_output.simplified()); foreach(QString device, devices) { supported = false; if(device == label_device->text()) { supported = true; break; } } if(!supported) { QMessageBox::warning(this, APPNAME, tr("Unsupported device detected!\n\nUse at your own risk and report model if succesfully...")); } if(usbmode == FLASH) { startFlashing(); } else { startDumping(); } } else if(!failed) { QMessageBox::warning(this, APPNAME, tr("Unexpected response from device!")); } } void flashDialog::startFlashing() { if(QMessageBox::question(this, APPNAME, tr("Start fastboot to flash logo image?")) == QMessageBox::Yes) { sendCommand("adb reboot-bootloader"); textEdit->append("\nWaiting 5 seconds for device to finish reboot...\n"); QCoreApplication::processEvents(); QThread::msleep(5000); label_fbt->setPixmap(QPixmap(":/png/png/con-err.png")); abort = false; do { QThread::msleep(1000); sendCommand("fastboot devices"); } while(!abort && (process_output.isEmpty() || !process_output.contains("\tfastboot\n"))); if(abort) { QMessageBox::warning(this, APPNAME, tr("Waiting for fastboot aborted!")); } else { label_fbt->setPixmap(QPixmap(":/png/png/con-suc.png")); sendCommand("fastboot flash logo " + reinterpret_cast<MainWindow*>(parent())->flash_file); if(process_output.contains("error") || process_output.contains("FAILED")) { QMessageBox::warning(this, APPNAME, tr("Flashing logo image failed!\n\nSee log for details...")); } else { QMessageBox::information(this, APPNAME, tr("Flashing logo image finished.\n\nClick OK to reboot device...")); } sendCommand("fastboot reboot"); } } } void flashDialog::startDumping() { sendCommand("adb shell \"su -c dd if=/dev/block/bootdevice/by-name/logo of=/sdcard/logo.img\""); if(process_output.contains("denied")) { buttonBox->button(QDialogButtonBox::Retry)->setEnabled(true); QMessageBox::warning(this, APPNAME, tr("Access denied!\n\nGrant root permissions and try again...")); } else if(process_output.contains("copied")) { sendCommand("adb pull /sdcard/logo.img " + QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/logo.img"); if(process_output.contains("pulled")) { QMessageBox::information(this, APPNAME, tr("Dumping logo image finished.")); } else { QMessageBox::warning(this, APPNAME, tr("Dumping logo image failed!\n\nSee log for details...")); } } else if(!failed) { QMessageBox::warning(this, APPNAME, tr("Unexpected response from device!")); } } void flashDialog::accept() { if(usbmode == FLASH) { initADB(); } else { label_model->text() == "?" ? initADB() : startDumping(); } } void flashDialog::reject() { if(running) { if(QMessageBox::question(this, APPNAME, tr("Really abort running command?")) == QMessageBox::Yes) { abort = true; running = false; } } else { if(!failed) { sendCommand("adb kill-server"); } QDialog::reject(); } }
7,014
C++
.cpp
221
28.868778
167
0.714519
LazyT/lmgr
35
8
0
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,989
flash.h
LazyT_lmgr/flash.h
#ifndef FLASHDLG_H #define FLASHDLG_H #include "ui_flash.h" #include "mainwindow.h" class flashDialog : public QDialog, private Ui::Dialog_Flash { Q_OBJECT public: flashDialog(QWidget*, bool); private: QProcess *process; QString process_output; QStringList devices = { "beryllium", "cepheus", "crux", "davinci", "davinciin", "dipper", "equuleus", "grus", "phoenix", "phoenixin", "pyxis", "raphael", "raphaelin", "tucana", "ursa", "vela" }; QColor textcolor; int fontweight; bool usbmode, running, failed, abort, supported; private slots: void initADB(); void sendCommand(QString); void startFlashing(); void startDumping(); void prg_errorOccurred(QProcess::ProcessError); void prg_readyReadStandardOutput(); void prg_finished(int, QProcess::ExitStatus); void accept(); void reject(); }; #endif // FLASHDLG_H
837
C++
.h
28
27.857143
195
0.747804
LazyT/lmgr
35
8
0
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,990
helpbrowser.h
LazyT_lmgr/helpbrowser.h
#ifndef HELPBROWSER_H #define HELPBROWSER_H #include <QWidget> #include <QTextBrowser> #include <QHelpEngine> class HelpBrowser : public QTextBrowser { public: HelpBrowser(QWidget *parent = NULL) : QTextBrowser(parent) {}; void setHelpEngine(QHelpEngine *engine) { helpEngine = engine; }; QVariant loadResource(int type, const QUrl &name) { return (name.scheme() == "qthelp" ? QVariant(helpEngine->fileData(name)) : QTextBrowser::loadResource(type, name)); } private: QHelpEngine *helpEngine; }; #endif // HELPBROWSER_H
532
C++
.h
15
33.666667
170
0.770138
LazyT/lmgr
35
8
0
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,991
help.h
LazyT_lmgr/help.h
#ifndef HELPDLG_H #define HELPDLG_H #include "ui_help.h" #include "mainwindow.h" class helpDialog : public QDialog, private Ui::Dialog_Help { Q_OBJECT public: helpDialog(QWidget*); private: QString lng; QHelpEngine *helpEngine; QHelpContentWidget *contentWidget; private slots: void setSourceFromContent(QModelIndex); void expand(); }; #endif // HELPDLG_H
373
C++
.h
18
18.777778
58
0.8
LazyT/lmgr
35
8
0
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,992
mainwindow.h
LazyT_lmgr/mainwindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #define APPNAME "Logo Manager" #define APPVERS "1.1.0" #define APPDATE "23.04.2020" #include <QApplication> #include <QMainWindow> #include <QMessageBox> #include <QCloseEvent> #include <QTranslator> #include <QLibraryInfo> #include <QDebug> #include <QFileDialog> #include <QStandardPaths> #include <QtEndian> #include <QDesktopServices> #include <QTimer> #include <QBuffer> #include <QProcess> #include <QThread> #include <QHelpEngine> #include <QHelpContentWidget> #include <QScreen> #include <QLCDNumber> #include <QNetworkAccessManager> #include <QNetworkRequest> #include <QNetworkReply> #include <QElapsedTimer> #include <QJsonArray> #include <QJsonDocument> #include <QJsonObject> #include "ui_mainwindow.h" #include "about.h" #include "flash.h" #include "help.h" #include "onlineupd.h" enum { FLASH, DUMP }; class MainWindow : public QMainWindow, private Ui::MainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); bool forceclose = false; QString flash_file; private: QTranslator baseTranslator, helpTranslator, appTranslator; QLCDNumber *lcd; int screens, startscreen; QByteArray logo; QString open_text = tr("Import Logo Image"); void importImage(QLabel*, QLabel*, int, int); void exportImage(QLabel*); quint32 logo_ofs[9]; quint32 logo_len[9]; bool loadLogo(quint32, quint32, int); void saveLogo(QFile&, int); quint32 calcLogo(int); /* struct LOGO_HEADER { quint8 magic[8] = { 0x4C, 0x4F, 0x47, 0x4F, 0x21, 0x21, 0x21, 0x21 }; // "LOGO!!!!" quint32 logo_offset_1; quint32 logo_length_1; quint32 logo_offset_n; quint32 logo_length_n; or quint32 logo_offset_1; quint32 logo_offset_n; quint32 logo_length_1; quint32 logo_length_n; }logo_header; */ private slots: void centerOnScreen(); void on_actionExit_triggered(); bool on_actionOpen_triggered(); void on_actionSave_triggered(); void on_actionDump_triggered(); void on_actionFlash_triggered(); void on_actionPrevLogo_triggered(); void on_actionNextLogo_triggered(); void on_actionAbout_triggered(); void on_actionHelp_triggered(); void on_actionUpdate_triggered(); void on_pushButton_1_imp_clicked(); void on_pushButton_2_imp_clicked(); void on_pushButton_3_imp_clicked(); void on_pushButton_4_imp_clicked(); void on_pushButton_5_imp_clicked(); void on_pushButton_6_imp_clicked(); void on_pushButton_7_imp_clicked(); void on_pushButton_8_imp_clicked(); void on_pushButton_9_imp_clicked(); void on_pushButton_1_exp_clicked(); void on_pushButton_2_exp_clicked(); void on_pushButton_3_exp_clicked(); void on_pushButton_4_exp_clicked(); void on_pushButton_5_exp_clicked(); void on_pushButton_6_exp_clicked(); void on_pushButton_7_exp_clicked(); void on_pushButton_8_exp_clicked(); void on_pushButton_9_exp_clicked(); void keyPressEvent(QKeyEvent*); void closeEvent(QCloseEvent*); }; #endif // MAINWINDOW_H
2,926
C++
.h
106
25.688679
85
0.769782
LazyT/lmgr
35
8
0
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,993
about.h
LazyT_lmgr/about.h
#ifndef ABOUTDLG_H #define ABOUTDLG_H #include "ui_about.h" #include "mainwindow.h" class aboutDialog : public QDialog, private Ui::Dialog_About { Q_OBJECT public: aboutDialog(QWidget*); private slots: void mouseReleaseEvent(QMouseEvent*); }; #endif // ABOUTDLG_H
274
C++
.h
13
19.307692
60
0.791339
LazyT/lmgr
35
8
0
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,994
onlineupd.h
LazyT_lmgr/onlineupd.h
#ifndef ONLINEUPDDLG_H #define ONLINEUPDDLG_H #include "ui_onlineupd.h" #include "mainwindow.h" #ifdef Q_OS_LINUX #define BIN ".AppImage" #define IMG ":/png/png/upd_lin.png" #elif defined Q_OS_WIN #define BIN ".exe" #define IMG ":/png/png/upd_win.png" #elif defined Q_OS_OSX #define BIN ".dmg" #define IMG ":/png/png/upd_mac.png" #endif #define RELEASE "https://api.github.com/repos/lazyt/lmgr/releases/latest" class onlineUpdDialog : public QDialog, private Ui::Dialog_OnlineUpdate { Q_OBJECT public: onlineUpdDialog(QWidget*, bool); private: bool silent; QNetworkAccessManager *netmgr; QNetworkRequest request; QNetworkReply *reply; QByteArray download; QString url; int size; private slots: void checkUpdate(); void downloadProgress(qint64, qint64); void finished(QNetworkReply*); void reject(); void on_buttonBox_clicked(QAbstractButton*); }; #endif // ONLINEUPDDLG_H
904
C++
.h
36
23.222222
73
0.776869
LazyT/lmgr
35
8
0
GPL-3.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,995
pathfind.cpp
EnergeticBark_OpenTTD-3DS/src/pathfind.cpp
/* $Id$ */ /** @file pathfind.cpp Implementation of the oldest supported pathfinder. */ #include "stdafx.h" #include "station_map.h" #include "settings_type.h" #include "pathfind.h" #include "debug.h" #include "tunnelbridge_map.h" #include "core/random_func.hpp" #include "core/alloc_type.hpp" #include "tunnelbridge.h" /* remember which tiles we have already visited so we don't visit them again. */ static bool TPFSetTileBit(TrackPathFinder *tpf, TileIndex tile, int dir) { uint hash, val, offs; TrackPathFinderLink *link, *new_link; uint bits = 1 << dir; if (tpf->disable_tile_hash) return true; hash = PATHFIND_HASH_TILE(tile); val = tpf->hash_head[hash]; if (val == 0) { /* unused hash entry, set the appropriate bit in it and return true * to indicate that a bit was set. */ tpf->hash_head[hash] = bits; tpf->hash_tile[hash] = tile; return true; } else if (!(val & 0x8000)) { /* single tile */ if (tile == tpf->hash_tile[hash]) { /* found another bit for the same tile, * check if this bit is already set, if so, return false */ if (val & bits) return false; /* otherwise set the bit and return true to indicate that the bit * was set */ tpf->hash_head[hash] = val | bits; return true; } else { /* two tiles with the same hash, need to make a link */ /* allocate a link. if out of links, handle this by returning * that a tile was already visisted. */ if (tpf->num_links_left == 0) { return false; } tpf->num_links_left--; link = tpf->new_link++; /* move the data that was previously in the hash_??? variables * to the link struct, and let the hash variables point to the link */ link->tile = tpf->hash_tile[hash]; tpf->hash_tile[hash] = PATHFIND_GET_LINK_OFFS(tpf, link); link->flags = tpf->hash_head[hash]; tpf->hash_head[hash] = 0xFFFF; // multi link link->next = 0xFFFF; } } else { /* a linked list of many tiles, * find the one corresponding to the tile, if it exists. * otherwise make a new link */ offs = tpf->hash_tile[hash]; do { link = PATHFIND_GET_LINK_PTR(tpf, offs); if (tile == link->tile) { /* found the tile in the link list, * check if the bit was alrady set, if so return false to indicate that the * bit was already set */ if (link->flags & bits) return false; link->flags |= bits; return true; } } while ((offs=link->next) != 0xFFFF); } /* get here if we need to add a new link to link, * first, allocate a new link, in the same way as before */ if (tpf->num_links_left == 0) { return false; } tpf->num_links_left--; new_link = tpf->new_link++; /* then fill the link with the new info, and establish a ptr from the old * link to the new one */ new_link->tile = tile; new_link->flags = bits; new_link->next = 0xFFFF; link->next = PATHFIND_GET_LINK_OFFS(tpf, new_link); return true; } static void TPFModeShip(TrackPathFinder *tpf, TileIndex tile, DiagDirection direction) { assert(tpf->tracktype == TRANSPORT_WATER); if (IsTileType(tile, MP_TUNNELBRIDGE)) { /* wrong track type */ if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) return; DiagDirection dir = GetTunnelBridgeDirection(tile); /* entering tunnel / bridge? */ if (dir == direction) { TileIndex endtile = GetOtherTunnelBridgeEnd(tile); tpf->rd.cur_length += GetTunnelBridgeLength(tile, endtile) + 1; TPFSetTileBit(tpf, tile, 14); TPFSetTileBit(tpf, endtile, 14); tile = endtile; } else { /* leaving tunnel / bridge? */ if (ReverseDiagDir(dir) != direction) return; } } /* This addition will sometimes overflow by a single tile. * The use of TILE_MASK here makes sure that we still point at a valid * tile, and then this tile will be in the sentinel row/col, so GetTileTrackStatus will fail. */ tile = TILE_MASK(tile + TileOffsByDiagDir(direction)); if (++tpf->rd.cur_length > 50) return; TrackBits bits = TrackStatusToTrackBits(GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type)) & DiagdirReachesTracks(direction); if (bits == TRACK_BIT_NONE) return; assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY()); bool only_one_track = true; do { Track track = RemoveFirstTrack(&bits); if (bits != TRACK_BIT_NONE) only_one_track = false; RememberData rd = tpf->rd; /* Change direction 4 times only */ if (!only_one_track && track != tpf->rd.last_choosen_track) { if (++tpf->rd.depth > 4) { tpf->rd = rd; return; } tpf->rd.last_choosen_track = track; } tpf->the_dir = TrackEnterdirToTrackdir(track, direction); if (!tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length)) { TPFModeShip(tpf, tile, TrackdirToExitdir(tpf->the_dir)); } tpf->rd = rd; } while (bits != TRACK_BIT_NONE); } /** * Checks if any vehicle can enter/leave tile in given diagdir * Checks only for rail/road depots and road non-drivethrough stations * @param tile tile to check * @param side side of tile we are trying to leave/enter * @param tracktype type of transport * @pre tile has trackbit at that diagdir * @return true iff vehicle can enter/leve the tile in given side */ static inline bool CanAccessTileInDir(TileIndex tile, DiagDirection side, TransportType tracktype) { if (tracktype == TRANSPORT_RAIL) { /* depot from wrong side */ if (IsRailDepotTile(tile) && GetRailDepotDirection(tile) != side) return false; } else if (tracktype == TRANSPORT_ROAD) { /* depot from wrong side */ if (IsRoadDepotTile(tile) && GetRoadDepotDirection(tile) != side) return false; /* non-driverthrough road station from wrong side */ if (IsStandardRoadStopTile(tile) && GetRoadStopDir(tile) != side) return false; } return true; } static void TPFModeNormal(TrackPathFinder *tpf, TileIndex tile, DiagDirection direction) { const TileIndex tile_org = tile; if (IsTileType(tile, MP_TUNNELBRIDGE)) { /* wrong track type */ if (GetTunnelBridgeTransportType(tile) != tpf->tracktype) return; DiagDirection dir = GetTunnelBridgeDirection(tile); /* entering tunnel / bridge? */ if (dir == direction) { TileIndex endtile = GetOtherTunnelBridgeEnd(tile); tpf->rd.cur_length += GetTunnelBridgeLength(tile, endtile) + 1; TPFSetTileBit(tpf, tile, 14); TPFSetTileBit(tpf, endtile, 14); tile = endtile; } else { /* leaving tunnel / bridge? */ if (ReverseDiagDir(dir) != direction) return; } } else { /* can we leave tile in this dir? */ if (!CanAccessTileInDir(tile, direction, tpf->tracktype)) return; } tile += TileOffsByDiagDir(direction); /* can we enter tile in this dir? */ if (!CanAccessTileInDir(tile, ReverseDiagDir(direction), tpf->tracktype)) return; /* Check if the new tile is a tunnel or bridge head and that the direction * and transport type match */ if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (GetTunnelBridgeDirection(tile) != direction || GetTunnelBridgeTransportType(tile) != tpf->tracktype) { return; } } TrackdirBits trackdirbits = TrackStatusToTrackdirBits(GetTileTrackStatus(tile, tpf->tracktype, tpf->sub_type)); /* Check in case of rail if the owner is the same */ if (tpf->tracktype == TRANSPORT_RAIL) { if (trackdirbits != TRACKDIR_BIT_NONE && TrackStatusToTrackdirBits(GetTileTrackStatus(tile_org, TRANSPORT_RAIL, 0)) != TRACKDIR_BIT_NONE) { if (GetTileOwner(tile_org) != GetTileOwner(tile)) return; } } tpf->rd.cur_length++; trackdirbits &= DiagdirReachesTrackdirs(direction); TrackBits bits = TrackdirBitsToTrackBits(trackdirbits); if (bits != TRACK_BIT_NONE) { if (!tpf->disable_tile_hash || (tpf->rd.cur_length <= 64 && (KillFirstBit(bits) == 0 || ++tpf->rd.depth <= 7))) { do { Track track = RemoveFirstTrack(&bits); tpf->the_dir = TrackEnterdirToTrackdir(track, direction); RememberData rd = tpf->rd; /* make sure we are not leaving from invalid side */ if (TPFSetTileBit(tpf, tile, tpf->the_dir) && CanAccessTileInDir(tile, TrackdirToExitdir(tpf->the_dir), tpf->tracktype) && !tpf->enum_proc(tile, tpf->userdata, tpf->the_dir, tpf->rd.cur_length) ) { TPFModeNormal(tpf, tile, TrackdirToExitdir(tpf->the_dir)); } tpf->rd = rd; } while (bits != TRACK_BIT_NONE); } } } void FollowTrack(TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data) { assert(IsValidDiagDirection(direction)); SmallStackSafeStackAlloc<TrackPathFinder, 1> tpf; /* initialize path finder variables */ tpf->userdata = data; tpf->enum_proc = enum_proc; tpf->new_link = tpf->links; tpf->num_links_left = lengthof(tpf->links); tpf->rd.cur_length = 0; tpf->rd.depth = 0; tpf->rd.last_choosen_track = INVALID_TRACK; tpf->disable_tile_hash = (flags & PATHFIND_FLAGS_DISABLE_TILE_HASH) != 0; tpf->tracktype = tt; tpf->sub_type = sub_type; if ((flags & PATHFIND_FLAGS_SHIP_MODE) != 0) { tpf->enum_proc(tile, data, INVALID_TRACKDIR, 0); TPFModeShip(tpf, tile, direction); } else { /* clear the hash_heads */ memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); TPFModeNormal(tpf, tile, direction); } if (after_proc != NULL) after_proc(tpf); } struct StackedItem { TileIndex tile; uint16 cur_length; ///< This is the current length to this tile. uint16 priority; ///< This is the current length + estimated length to the goal. TrackdirByte track; byte depth; byte state; byte first_track; }; struct HashLink { TileIndex tile; uint16 typelength; uint16 next; }; struct NewTrackPathFinder { NTPEnumProc *enum_proc; void *userdata; TileIndex dest; TransportType tracktype; RailTypes railtypes; uint maxlength; HashLink *new_link; uint num_links_left; uint nstack; StackedItem stack[256]; ///< priority queue of stacked items uint16 hash_head[0x400]; ///< hash heads. 0 means unused. 0xFFFC = length, 0x3 = dir TileIndex hash_tile[0x400]; ///< tiles. or links. HashLink links[0x400]; ///< hash links }; #define NTP_GET_LINK_OFFS(tpf, link) ((byte*)(link) - (byte*)tpf->links) #define NTP_GET_LINK_PTR(tpf, link_offs) (HashLink*)((byte*)tpf->links + (link_offs)) #define ARR(i) tpf->stack[(i)-1] /** called after a new element was added in the queue at the last index. * move it down to the proper position */ static inline void HeapifyUp(NewTrackPathFinder *tpf) { StackedItem si; int i = ++tpf->nstack; while (i != 1 && ARR(i).priority < ARR(i>>1).priority) { /* the child element is larger than the parent item. * swap the child item and the parent item. */ si = ARR(i); ARR(i) = ARR(i >> 1); ARR(i >> 1) = si; i >>= 1; } } /** called after the element 0 was eaten. fill it with a new element */ static inline void HeapifyDown(NewTrackPathFinder *tpf) { StackedItem si; int i = 1, j; int n; assert(tpf->nstack > 0); n = --tpf->nstack; if (n == 0) return; // heap is empty so nothing to do? /* copy the last item to index 0. we use it as base for heapify. */ ARR(1) = ARR(n + 1); while ((j = i * 2) <= n) { /* figure out which is smaller of the children. */ if (j != n && ARR(j).priority > ARR(j + 1).priority) j++; // right item is smaller assert(i <= n && j <= n); if (ARR(i).priority <= ARR(j).priority) break; // base elem smaller than smallest, done! /* swap parent with the child */ si = ARR(i); ARR(i) = ARR(j); ARR(j) = si; i = j; } } /** mark a tile as visited and store the length of the path. * if we already had a better path to this tile, return false. * otherwise return true. */ static bool NtpVisit(NewTrackPathFinder *tpf, TileIndex tile, DiagDirection dir, uint length) { uint hash,head; HashLink *link, *new_link; assert(length < 16384-1); hash = PATHFIND_HASH_TILE(tile); /* never visited before? */ if ((head=tpf->hash_head[hash]) == 0) { tpf->hash_tile[hash] = tile; tpf->hash_head[hash] = dir | (length << 2); return true; } if (head != 0xffff) { if (tile == tpf->hash_tile[hash] && (head & 0x3) == (uint)dir) { /* longer length */ if (length >= (head >> 2)) return false; tpf->hash_head[hash] = dir | (length << 2); return true; } /* two tiles with the same hash, need to make a link * allocate a link. if out of links, handle this by returning * that a tile was already visisted. */ if (tpf->num_links_left == 0) { DEBUG(ntp, 1, "No links left"); return false; } tpf->num_links_left--; link = tpf->new_link++; /* move the data that was previously in the hash_??? variables * to the link struct, and let the hash variables point to the link */ link->tile = tpf->hash_tile[hash]; tpf->hash_tile[hash] = NTP_GET_LINK_OFFS(tpf, link); link->typelength = tpf->hash_head[hash]; tpf->hash_head[hash] = 0xFFFF; // multi link link->next = 0xFFFF; } else { /* a linked list of many tiles, * find the one corresponding to the tile, if it exists. * otherwise make a new link */ uint offs = tpf->hash_tile[hash]; do { link = NTP_GET_LINK_PTR(tpf, offs); if (tile == link->tile && (link->typelength & 0x3U) == (uint)dir) { if (length >= (uint)(link->typelength >> 2)) return false; link->typelength = dir | (length << 2); return true; } } while ((offs = link->next) != 0xFFFF); } /* get here if we need to add a new link to link, * first, allocate a new link, in the same way as before */ if (tpf->num_links_left == 0) { DEBUG(ntp, 1, "No links left"); return false; } tpf->num_links_left--; new_link = tpf->new_link++; /* then fill the link with the new info, and establish a ptr from the old * link to the new one */ new_link->tile = tile; new_link->typelength = dir | (length << 2); new_link->next = 0xFFFF; link->next = NTP_GET_LINK_OFFS(tpf, new_link); return true; } /** * Checks if the shortest path to the given tile/dir so far is still the given * length. * @return true if the length is still the same * @pre The given tile/dir combination should be present in the hash, by a * previous call to NtpVisit(). */ static bool NtpCheck(NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint length) { uint hash,head,offs; HashLink *link; hash = PATHFIND_HASH_TILE(tile); head=tpf->hash_head[hash]; assert(head); if (head != 0xffff) { assert( tpf->hash_tile[hash] == tile && (head & 3) == dir); assert( (head >> 2) <= length); return length == (head >> 2); } /* else it's a linked list of many tiles */ offs = tpf->hash_tile[hash]; for (;;) { link = NTP_GET_LINK_PTR(tpf, offs); if (tile == link->tile && (link->typelength & 0x3U) == dir) { assert((uint)(link->typelength >> 2) <= length); return length == (uint)(link->typelength >> 2); } offs = link->next; assert(offs != 0xffff); } } static uint DistanceMoo(TileIndex t0, TileIndex t1) { const uint dx = Delta(TileX(t0), TileX(t1)); const uint dy = Delta(TileY(t0), TileY(t1)); const uint straightTracks = 2 * min(dx, dy); // The number of straight (not full length) tracks /* OPTIMISATION: * Original: diagTracks = max(dx, dy) - min(dx,dy); * Proof: * (dx-dy) - straightTracks == (min + max) - straightTracks = min + // max - 2 * min = max - min */ const uint diagTracks = dx + dy - straightTracks; // The number of diagonal (full tile length) tracks. return diagTracks*DIAG_FACTOR + straightTracks*STR_FACTOR; } /* These has to be small cause the max length of a track * is currently limited to 16384 */ static const byte _length_of_track[16] = { DIAG_FACTOR, DIAG_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, 0, 0, DIAG_FACTOR, DIAG_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, 0, 0 }; /* new more optimized pathfinder for trains... * Tile is the tile the train is at. * direction is the tile the train is moving towards. */ static void NTPEnum(NewTrackPathFinder *tpf, TileIndex tile, DiagDirection direction) { TrackBits bits, allbits; Trackdir track; TileIndex tile_org; StackedItem si; int estimation; /* Need to have a special case for the start. * We shouldn't call the callback for the current tile. */ si.cur_length = 1; // Need to start at 1 cause 0 is a reserved value. si.depth = 0; si.state = 0; si.first_track = 0xFF; goto start_at; for (;;) { /* Get the next item to search from from the priority queue */ do { if (tpf->nstack == 0) return; // nothing left? then we're done! si = tpf->stack[0]; tile = si.tile; HeapifyDown(tpf); /* Make sure we havn't already visited this tile. */ } while (!NtpCheck(tpf, tile, ReverseDiagDir(TrackdirToExitdir(ReverseTrackdir(si.track))), si.cur_length)); /* Add the length of this track. */ si.cur_length += _length_of_track[si.track]; callback_and_continue: if (tpf->enum_proc(tile, tpf->userdata, si.first_track, si.cur_length)) return; assert(si.track <= 13); direction = TrackdirToExitdir(si.track); start_at: /* If the tile is the entry tile of a tunnel, and we're not going out of the tunnel, * need to find the exit of the tunnel. */ if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (GetTunnelBridgeDirection(tile) != ReverseDiagDir(direction)) { /* We are not just driving out of the tunnel/bridge */ if (GetTunnelBridgeDirection(tile) != direction || GetTunnelBridgeTransportType(tile) != tpf->tracktype) { /* We are not driving into the tunnel/bridge, or it is an invalid tunnel/bridge */ continue; } if (!HasBit(tpf->railtypes, GetRailType(tile))) { bits = TRACK_BIT_NONE; break; } TileIndex endtile = GetOtherTunnelBridgeEnd(tile); si.cur_length += DIAG_FACTOR * (GetTunnelBridgeLength(tile, endtile) + 1); tile = endtile; /* tile now points to the exit tile of the tunnel/bridge */ } } /* This is a special loop used to go through * a rail net and find the first intersection */ tile_org = tile; for (;;) { assert(direction <= 3); tile += TileOffsByDiagDir(direction); /* too long search length? bail out. */ if (si.cur_length >= tpf->maxlength) { DEBUG(ntp, 1, "Cur_length too big"); bits = TRACK_BIT_NONE; break; } /* Not a regular rail tile? * Then we can't use the code below, but revert to more general code. */ if (!IsTileType(tile, MP_RAILWAY) || !IsPlainRailTile(tile)) { /* We found a tile which is not a normal railway tile. * Determine which tracks that exist on this tile. */ bits = TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)) & DiagdirReachesTrackdirs(direction)); /* Check that the tile contains exactly one track */ if (bits == 0 || KillFirstBit(bits) != 0) break; if (!HasBit(tpf->railtypes, GetRailType(tile))) { bits = TRACK_BIT_NONE; break; } /******************* * If we reach here, the tile has exactly one track. * tile - index to a tile that is not rail tile, but still straight (with optional signals) * bits - bitmask of which track that exist on the tile (exactly one bit is set) * direction - which direction are we moving in? *******************/ si.track = TrackEnterdirToTrackdir(FindFirstTrack(bits), direction); si.cur_length += _length_of_track[si.track]; goto callback_and_continue; } /* Regular rail tile, determine which tracks exist. */ allbits = GetTrackBits(tile); /* Which tracks are reachable? */ bits = allbits & DiagdirReachesTracks(direction); /* The tile has no reachable tracks => End of rail segment * or Intersection => End of rail segment. We check this agains all the * bits, not just reachable ones, to prevent infinite loops. */ if (bits == TRACK_BIT_NONE || TracksOverlap(allbits)) break; if (!HasBit(tpf->railtypes, GetRailType(tile))) { bits = TRACK_BIT_NONE; break; } /* If we reach here, the tile has exactly one track, and this track is reachable = > Rail segment continues */ track = TrackEnterdirToTrackdir(FindFirstTrack(bits), direction); assert(track != INVALID_TRACKDIR); si.cur_length += _length_of_track[track]; /* Check if this rail is an upwards slope. If it is, then add a penalty. */ if (IsDiagonalTrackdir(track) && IsUphillTrackdir(GetTileSlope(tile, NULL), track)) { /* upwards slope. add some penalty. */ si.cur_length += 4 * DIAG_FACTOR; } /* railway tile with signals..? */ if (HasSignals(tile)) { if (!HasSignalOnTrackdir(tile, track)) { /* if one way signal not pointing towards us, stop going in this direction => End of rail segment. */ if (HasSignalOnTrackdir(tile, ReverseTrackdir(track)) && IsOnewaySignal(tile, TrackdirToTrack(track))) { bits = TRACK_BIT_NONE; break; } } else if (GetSignalStateByTrackdir(tile, track) == SIGNAL_STATE_GREEN) { /* green signal in our direction. either one way or two way. */ si.state |= 3; } else { /* reached a red signal. */ if (HasSignalOnTrackdir(tile, ReverseTrackdir(track))) { /* two way red signal. unless we passed another green signal on the way, * stop going in this direction => End of rail segment. * this is to prevent us from going into a full platform. */ if (!(si.state & 1)) { bits = TRACK_BIT_NONE; break; } } if (!(si.state & 2)) { /* Is this the first signal we see? And it's red... add penalty */ si.cur_length += 10 * DIAG_FACTOR; si.state += 2; // remember that we added penalty. /* Because we added a penalty, we can't just continue as usual. * Need to get out and let A* do it's job with * possibly finding an even shorter path. */ break; } } if (tpf->enum_proc(tile, tpf->userdata, si.first_track, si.cur_length)) return; // Don't process this tile any further } /* continue with the next track */ direction = TrackdirToExitdir(track); /* safety check if we're running around chasing our tail... (infinite loop) */ if (tile == tile_org) { bits = TRACK_BIT_NONE; break; } } /* There are no tracks to choose between. * Stop searching in this direction */ if (bits == TRACK_BIT_NONE) continue; /**************** * We got multiple tracks to choose between (intersection). * Branch the search space into several branches. ****************/ /* Check if we've already visited this intersection. * If we've already visited it with a better length, then * there's no point in visiting it again. */ if (!NtpVisit(tpf, tile, direction, si.cur_length)) continue; /* Push all possible alternatives that we can reach from here * onto the priority heap. * 'bits' contains the tracks that we can choose between. */ /* First compute the estimated distance to the target. * This is used to implement A* */ estimation = 0; if (tpf->dest != 0) estimation = DistanceMoo(tile, tpf->dest); si.depth++; if (si.depth == 0) continue; // We overflowed our depth. No more searching in this direction. si.tile = tile; while (bits != TRACK_BIT_NONE) { Track track = RemoveFirstTrack(&bits); si.track = TrackEnterdirToTrackdir(track, direction); assert(si.track != 0xFF); si.priority = si.cur_length + estimation; /* out of stack items, bail out? */ if (tpf->nstack >= lengthof(tpf->stack)) { DEBUG(ntp, 1, "Out of stack"); break; } tpf->stack[tpf->nstack] = si; HeapifyUp(tpf); }; /* If this is the first intersection, we need to fill the first_track member. * so the code outside knows which path is better. * also randomize the order in which we search through them. */ if (si.depth == 1) { assert(tpf->nstack == 1 || tpf->nstack == 2 || tpf->nstack == 3); if (tpf->nstack != 1) { uint32 r = Random(); if (r & 1) Swap(tpf->stack[0].track, tpf->stack[1].track); if (tpf->nstack != 2) { TrackdirByte t = tpf->stack[2].track; if (r & 2) Swap(tpf->stack[0].track, t); if (r & 4) Swap(tpf->stack[1].track, t); tpf->stack[2].first_track = tpf->stack[2].track = t; } tpf->stack[0].first_track = tpf->stack[0].track; tpf->stack[1].first_track = tpf->stack[1].track; } } /* Continue with the next from the queue... */ } } /** new pathfinder for trains. better and faster. */ void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc *enum_proc, void *data) { SmallStackSafeStackAlloc<NewTrackPathFinder, 1> tpf; tpf->dest = dest; tpf->userdata = data; tpf->enum_proc = enum_proc; tpf->tracktype = TRANSPORT_RAIL; tpf->railtypes = railtypes; tpf->maxlength = min(_settings_game.pf.opf.pf_maxlength * 3, 10000); tpf->nstack = 0; tpf->new_link = tpf->links; tpf->num_links_left = lengthof(tpf->links); memset(tpf->hash_head, 0, sizeof(tpf->hash_head)); NTPEnum(tpf, tile, direction); }
24,897
C++
.cpp
656
34.565549
173
0.67754
EnergeticBark/OpenTTD-3DS
34
1
4
GPL-2.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,996
engine.cpp
EnergeticBark_OpenTTD-3DS/src/engine.cpp
/* $Id$ */ /** @file engine.cpp Base for all engine handling. */ #include "stdafx.h" #include "debug.h" #include "company_func.h" #include "command_func.h" #include "news_func.h" #include "variables.h" #include "aircraft.h" #include "newgrf_engine.h" #include "group.h" #include "strings_func.h" #include "gfx_func.h" #include "core/random_func.hpp" #include "window_func.h" #include "date_func.h" #include "autoreplace_gui.h" #include "string_func.h" #include "oldpool_func.h" #include "ai/ai.hpp" #include "vehicle_func.h" #include "settings_type.h" #include "table/strings.h" #include "table/engines.h" DEFINE_OLD_POOL_GENERIC(Engine, Engine) EngineOverrideManager _engine_mngr; /** Year that engine aging stops. Engines will not reduce in reliability * and no more engines will be introduced */ Year _year_engine_aging_stops; /** Number of engines of each vehicle type in original engine data */ const uint8 _engine_counts[4] = { lengthof(_orig_rail_vehicle_info), lengthof(_orig_road_vehicle_info), lengthof(_orig_ship_vehicle_info), lengthof(_orig_aircraft_vehicle_info), }; /** Offset of the first engine of each vehicle type in original engine data */ const uint8 _engine_offsets[4] = { 0, lengthof(_orig_rail_vehicle_info), lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info), lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info), }; const uint EngineOverrideManager::NUM_DEFAULT_ENGINES = _engine_counts[VEH_TRAIN] + _engine_counts[VEH_ROAD] + _engine_counts[VEH_SHIP] + _engine_counts[VEH_AIRCRAFT]; Engine::Engine() : name(NULL), overrides_count(0), overrides(NULL) { } Engine::Engine(VehicleType type, EngineID base) { this->type = type; this->internal_id = base; this->list_position = base; /* Check if this base engine is within the original engine data range */ if (base >= _engine_counts[type]) { /* Mark engine as valid anyway */ this->info.climates = 0x80; /* Set model life to maximum to make wagons available */ this->info.base_life = 0xFF; return; } /* Copy the original engine info for this slot */ this->info = _orig_engine_info[_engine_offsets[type] + base]; /* Copy the original engine data for this slot */ switch (type) { default: NOT_REACHED(); case VEH_TRAIN: this->u.rail = _orig_rail_vehicle_info[base]; this->image_index = this->u.rail.image_index; this->info.string_id = STR_8000_KIRBY_PAUL_TANK_STEAM + base; /* Set the default model life of original wagons to "infinite" */ if (this->u.rail.railveh_type == RAILVEH_WAGON) this->info.base_life = 0xFF; break; case VEH_ROAD: this->u.road = _orig_road_vehicle_info[base]; this->image_index = this->u.road.image_index; this->info.string_id = STR_8074_MPS_REGAL_BUS + base; break; case VEH_SHIP: this->u.ship = _orig_ship_vehicle_info[base]; this->image_index = this->u.ship.image_index; this->info.string_id = STR_80CC_MPS_OIL_TANKER + base; break; case VEH_AIRCRAFT: this->u.air = _orig_aircraft_vehicle_info[base]; this->image_index = this->u.air.image_index; this->info.string_id = STR_80D7_SAMPSON_U52 + base; break; } } Engine::~Engine() { UnloadWagonOverrides(this); free(this->name); } /** * Determines the default cargo type of an engine. * * Usually a valid cargo is returned, even though the vehicle has zero capacity, and can therefore not carry anything. But the cargotype is still used * for livery selection etc.. * * Vehicles with CT_INVALID as default cargo are usally not available, but it can appear as default cargo of articulated parts. * * @return The default cargo type. * @see CanCarryCargo */ CargoID Engine::GetDefaultCargoType() const { switch (this->type) { case VEH_TRAIN: return this->u.rail.cargo_type; case VEH_ROAD: return this->u.road.cargo_type; case VEH_SHIP: return this->u.ship.cargo_type; case VEH_AIRCRAFT: return FindFirstRefittableCargo(this->index); default: NOT_REACHED(); } } /** * Determines whether an engine can carry something. * A vehicle cannot carry anything if its capacity is zero, or none of the possible cargos is available in the climate. * @return true if the vehicle can carry something. */ bool Engine::CanCarryCargo() const { /* For engines that can appear in a consist (i.e. rail vehicles and (articulated) road vehicles), a capacity * of zero is a special case, to define the vehicle to not carry anything. The default cargotype is still used * for livery selection etc. * Note: Only the property is tested. A capacity callback returning 0 does not have the same effect. */ switch (this->type) { case VEH_TRAIN: if (this->u.rail.capacity == 0) return false; break; case VEH_ROAD: if (this->u.road.capacity == 0) return false; break; case VEH_SHIP: case VEH_AIRCRAFT: break; default: NOT_REACHED(); } return this->GetDefaultCargoType() != CT_INVALID; } /** * Determines the default cargo capacity of an engine for display purposes. * * For planes carrying both passenger and mail this is the passenger capacity. * For multiheaded engines this is the capacity of both heads. * For articulated engines use GetCapacityOfArticulatedParts * * @return The default capacity * @see GetDefaultCargoType */ uint Engine::GetDisplayDefaultCapacity() const { if (!this->CanCarryCargo()) return 0; switch (type) { case VEH_TRAIN: return GetEngineProperty(this->index, 0x14, this->u.rail.capacity) + (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? this->u.rail.capacity : 0); case VEH_ROAD: return GetEngineProperty(this->index, 0x0F, this->u.road.capacity); case VEH_SHIP: return GetEngineProperty(this->index, 0x0D, this->u.ship.capacity); case VEH_AIRCRAFT: return AircraftDefaultCargoCapacity(this->GetDefaultCargoType(), &this->u.air); default: NOT_REACHED(); } } Money Engine::GetRunningCost() const { switch (this->type) { case VEH_ROAD: return this->u.road.running_cost * GetPriceByIndex(this->u.road.running_cost_class) >> 8; case VEH_TRAIN: return GetEngineProperty(this->index, 0x0D, this->u.rail.running_cost) * GetPriceByIndex(this->u.rail.running_cost_class) >> 8; case VEH_SHIP: return GetEngineProperty(this->index, 0x0F, this->u.ship.running_cost) * _price.ship_running >> 8; case VEH_AIRCRAFT: return GetEngineProperty(this->index, 0x0E, this->u.air.running_cost) * _price.aircraft_running >> 8; default: NOT_REACHED(); } } Money Engine::GetCost() const { switch (this->type) { case VEH_ROAD: return GetEngineProperty(this->index, 0x11, this->u.road.cost_factor) * (_price.roadveh_base >> 3) >> 5; case VEH_TRAIN: if (this->u.rail.railveh_type == RAILVEH_WAGON) { return (GetEngineProperty(this->index, 0x17, this->u.rail.cost_factor) * _price.build_railwagon) >> 8; } else { return GetEngineProperty(this->index, 0x17, this->u.rail.cost_factor) * (_price.build_railvehicle >> 3) >> 5; } case VEH_SHIP: return GetEngineProperty(this->index, 0x0A, this->u.ship.cost_factor) * (_price.ship_base >> 3) >> 5; case VEH_AIRCRAFT: return GetEngineProperty(this->index, 0x0B, this->u.air.cost_factor) * (_price.aircraft_base >> 3) >> 5; default: NOT_REACHED(); } } /** * Returns max speed for display purposes * @return max speed in km-ish/h */ uint Engine::GetDisplayMaxSpeed() const { switch (this->type) { case VEH_TRAIN: return GetEngineProperty(this->index, 0x09, this->u.rail.max_speed); case VEH_ROAD: return this->u.road.max_speed / 2; case VEH_SHIP: return GetEngineProperty(this->index, 0x0B, this->u.ship.max_speed) / 2; case VEH_AIRCRAFT: return this->u.air.max_speed; default: NOT_REACHED(); } } uint Engine::GetPower() const { /* Currently only trains have 'power' */ switch (this->type) { case VEH_TRAIN: return GetEngineProperty(this->index, 0x0B, this->u.rail.power); default: NOT_REACHED(); } } /** * Returns the weight for display purposes. * For dual-headed train-engines this is the weight of both heads * @return weight in display units metric tons */ uint Engine::GetDisplayWeight() const { /* Currently only trains have 'weight' */ switch (this->type) { case VEH_TRAIN: return GetEngineProperty(this->index, 0x16, this->u.rail.weight) << (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 1 : 0); default: NOT_REACHED(); } } /** * Returns the tractive effort for display purposes. * For dual-headed train-engines this is the tractive effort of both heads * @return tractive effort in display units kN */ uint Engine::GetDisplayMaxTractiveEffort() const { /* Currently only trains have 'tractive effort' */ switch (this->type) { case VEH_TRAIN: return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, 0x1F, this->u.rail.tractive_effort)) / 256; default: NOT_REACHED(); } } /** * Initializes the EngineOverrideManager with the default engines. */ void EngineOverrideManager::ResetToDefaultMapping() { this->Clear(); for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) { for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) { EngineIDMapping *eid = this->Append(); eid->type = type; eid->grfid = INVALID_GRFID; eid->internal_id = internal_id; eid->substitute_id = internal_id; } } } /** * Looks up an EngineID in the EngineOverrideManager * @param type Vehicle type * @param grf_local_id The local id in the newgrf * @param grfid The GrfID that defines the scope of grf_local_id. * If a newgrf overrides the engines of another newgrf, the "scope grfid" is the ID of the overridden newgrf. * If dynnamic_engines is disabled, all newgrf share the same ID scope identified by INVALID_GRFID. * @return The engine ID if present, or INVALID_ENGINE if not. */ EngineID EngineOverrideManager::GetID(VehicleType type, uint16 grf_local_id, uint32 grfid) { const EngineIDMapping *end = this->End(); EngineID index = 0; for (const EngineIDMapping *eid = this->Begin(); eid != end; eid++, index++) { if (eid->type == type && eid->grfid == grfid && eid->internal_id == grf_local_id) { return index; } } return INVALID_ENGINE; } /** Sets cached values in Company::num_vehicles and Group::num_vehicles */ void SetCachedEngineCounts() { uint engines = GetEnginePoolSize(); /* Set up the engine count for all companies */ Company *c; FOR_ALL_COMPANIES(c) { free(c->num_engines); c->num_engines = CallocT<EngineID>(engines); } /* Recalculate */ Group *g; FOR_ALL_GROUPS(g) { free(g->num_engines); g->num_engines = CallocT<EngineID>(engines); } const Vehicle *v; FOR_ALL_VEHICLES(v) { if (!IsEngineCountable(v)) continue; assert(v->engine_type < engines); GetCompany(v->owner)->num_engines[v->engine_type]++; if (v->group_id == DEFAULT_GROUP) continue; g = GetGroup(v->group_id); assert(v->type == g->vehicle_type); assert(v->owner == g->owner); g->num_engines[v->engine_type]++; } } void SetupEngines() { _Engine_pool.CleanPool(); _Engine_pool.AddBlockToPool(); assert(_engine_mngr.Length() >= _engine_mngr.NUM_DEFAULT_ENGINES); const EngineIDMapping *end = _engine_mngr.End(); uint index = 0; for (const EngineIDMapping *eid = _engine_mngr.Begin(); eid != end; eid++, index++) { const Engine *e = new Engine(eid->type, eid->internal_id); assert(e->index == index); } } void ShowEnginePreviewWindow(EngineID engine); /* Determine if an engine type is a wagon (and not a loco) */ static bool IsWagon(EngineID index) { const Engine *e = GetEngine(index); return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON; } static void CalcEngineReliability(Engine *e) { uint age = e->age; /* Check for early retirement */ if (e->company_avail != 0 && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) { int retire_early = e->info.retire_early; uint retire_early_max_age = max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12); if (retire_early != 0 && age >= retire_early_max_age) { /* Early retirement is enabled and we're past the date... */ e->company_avail = 0; AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); } } if (age < e->duration_phase_1) { uint start = e->reliability_start; e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start; } else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _settings_game.vehicle.never_expire_vehicles || e->info.base_life == 0xFF) { /* We are at the peak of this engines life. It will have max reliability. * This is also true if the engines never expire. They will not go bad over time */ e->reliability = e->reliability_max; } else if ((age -= e->duration_phase_2) < e->duration_phase_3) { uint max = e->reliability_max; e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max; } else { /* time's up for this engine. * We will now completely retire this design */ e->company_avail = 0; e->reliability = e->reliability_final; /* Kick this engine out of the lists */ AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); } InvalidateWindowClasses(WC_BUILD_VEHICLE); // Update to show the new reliability InvalidateWindowClasses(WC_REPLACE_VEHICLE); } void SetYearEngineAgingStops() { /* Determine last engine aging year, default to 2050 as previously. */ _year_engine_aging_stops = 2050; const Engine *e; FOR_ALL_ENGINES(e) { const EngineInfo *ei = &e->info; /* Exclude certain engines */ if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue; if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue; /* Base year ending date on half the model life */ YearMonthDay ymd; ConvertDateToYMD(ei->base_intro + (ei->lifelength * DAYS_IN_LEAP_YEAR) / 2, &ymd); _year_engine_aging_stops = max(_year_engine_aging_stops, ymd.year); } } void StartupOneEngine(Engine *e, Date aging_date) { const EngineInfo *ei = &e->info; uint32 r; e->age = 0; e->flags = 0; e->company_avail = 0; /* The magic value of 729 days below comes from the NewGRF spec. If the * base intro date is before 1922 then the random number of days is not * added. */ r = Random(); e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro; if (e->intro_date <= _date) { e->age = (aging_date - e->intro_date) >> 5; e->company_avail = (CompanyMask)-1; e->flags |= ENGINE_AVAILABLE; } e->reliability_start = GB(r, 16, 14) + 0x7AE0; r = Random(); e->reliability_max = GB(r, 0, 14) + 0xBFFF; e->reliability_final = GB(r, 16, 14) + 0x3FFF; r = Random(); e->duration_phase_1 = GB(r, 0, 5) + 7; e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96; e->duration_phase_3 = GB(r, 9, 7) + 120; e->reliability_spd_dec = ei->decay_speed << 2; CalcEngineReliability(e); e->lifelength = ei->lifelength + _settings_game.vehicle.extend_vehicle_life; /* prevent certain engines from ever appearing. */ if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) { e->flags |= ENGINE_AVAILABLE; e->company_avail = 0; } } void StartupEngines() { Engine *e; /* Aging of vehicles stops, so account for that when starting late */ const Date aging_date = min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 1)); FOR_ALL_ENGINES(e) { StartupOneEngine(e, aging_date); } /* Update the bitmasks for the vehicle lists */ Company *c; FOR_ALL_COMPANIES(c) { c->avail_railtypes = GetCompanyRailtypes(c->index); c->avail_roadtypes = GetCompanyRoadtypes(c->index); } } static void AcceptEnginePreview(EngineID eid, CompanyID company) { Engine *e = GetEngine(eid); Company *c = GetCompany(company); SetBit(e->company_avail, company); if (e->type == VEH_TRAIN) { const RailVehicleInfo *rvi = RailVehInfo(eid); assert(rvi->railtype < RAILTYPE_END); SetBit(c->avail_railtypes, rvi->railtype); } else if (e->type == VEH_ROAD) { SetBit(c->avail_roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); } e->preview_company_rank = 0xFF; if (company == _local_company) { AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); } } static CompanyID GetBestCompany(uint8 pp) { const Company *c; int32 best_hist; CompanyID best_company; CompanyMask mask = 0; do { best_hist = -1; best_company = INVALID_COMPANY; FOR_ALL_COMPANIES(c) { if (c->block_preview == 0 && !HasBit(mask, c->index) && c->old_economy[0].performance_history > best_hist) { best_hist = c->old_economy[0].performance_history; best_company = c->index; } } if (best_company == INVALID_COMPANY) return INVALID_COMPANY; SetBit(mask, best_company); } while (--pp != 0); return best_company; } void EnginesDailyLoop() { if (_cur_year >= _year_engine_aging_stops) return; Engine *e; FOR_ALL_ENGINES(e) { EngineID i = e->index; if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { if (e->flags & ENGINE_OFFER_WINDOW_OPEN) { if (e->preview_company_rank != 0xFF && !--e->preview_wait) { e->flags &= ~ENGINE_OFFER_WINDOW_OPEN; DeleteWindowById(WC_ENGINE_PREVIEW, i); e->preview_company_rank++; } } else if (e->preview_company_rank != 0xFF) { CompanyID best_company = GetBestCompany(e->preview_company_rank); if (best_company == INVALID_COMPANY) { e->preview_company_rank = 0xFF; continue; } e->flags |= ENGINE_OFFER_WINDOW_OPEN; e->preview_wait = 20; AI::NewEvent(best_company, new AIEventEnginePreview(i)); if (IsInteractiveCompany(best_company)) ShowEnginePreviewWindow(i); } } } } /** Accept an engine prototype. XXX - it is possible that the top-company * changes while you are waiting to accept the offer? Then it becomes invalid * @param tile unused * @param flags operation to perfom * @param p1 engine-prototype offered * @param p2 unused */ CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { Engine *e; if (!IsEngineIndex(p1)) return CMD_ERROR; e = GetEngine(p1); if (GetBestCompany(e->preview_company_rank) != _current_company) return CMD_ERROR; if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_company); return CommandCost(); } StringID GetEngineCategoryName(EngineID engine); static void NewVehicleAvailable(Engine *e) { Vehicle *v; Company *c; EngineID index = e->index; /* In case the company didn't build the vehicle during the intro period, * prevent that company from getting future intro periods for a while. */ if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { FOR_ALL_COMPANIES(c) { uint block_preview = c->block_preview; if (!HasBit(e->company_avail, c->index)) continue; /* We assume the user did NOT build it.. prove me wrong ;) */ c->block_preview = 20; FOR_ALL_VEHICLES(v) { if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP || (v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) { if (v->owner == c->index && v->engine_type == index) { /* The user did prove me wrong, so restore old value */ c->block_preview = block_preview; break; } } } } } e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE; AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); /* Now available for all companies */ e->company_avail = (CompanyMask)-1; /* Do not introduce new rail wagons */ if (IsWagon(index)) return; if (e->type == VEH_TRAIN) { /* maybe make another rail type available */ RailType railtype = e->u.rail.railtype; assert(railtype < RAILTYPE_END); FOR_ALL_COMPANIES(c) SetBit(c->avail_railtypes, railtype); } else if (e->type == VEH_ROAD) { /* maybe make another road type available */ FOR_ALL_COMPANIES(c) SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); } AI::BroadcastNewEvent(new AIEventEngineAvailable(index)); SetDParam(0, GetEngineCategoryName(index)); SetDParam(1, index); AddNewsItem(STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, index, 0); } void EnginesMonthlyLoop() { if (_cur_year < _year_engine_aging_stops) { Engine *e; FOR_ALL_ENGINES(e) { /* Age the vehicle */ if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) { e->age++; CalcEngineReliability(e); } if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + DAYS_IN_YEAR)) { /* Introduce it to all companies */ NewVehicleAvailable(e); } else if (!(e->flags & (ENGINE_AVAILABLE | ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) { /* Introduction date has passed.. show introducing dialog to one companies. */ e->flags |= ENGINE_EXCLUSIVE_PREVIEW; /* Do not introduce new rail wagons */ if (!IsWagon(e->index)) e->preview_company_rank = 1; // Give to the company with the highest rating. } } } } static bool IsUniqueEngineName(const char *name) { const Engine *e; FOR_ALL_ENGINES(e) { if (e->name != NULL && strcmp(e->name, name) == 0) return false; } return true; } /** Rename an engine. * @param tile unused * @param flags operation to perfom * @param p1 engine ID to rename * @param p2 unused */ CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { if (!IsEngineIndex(p1)) return CMD_ERROR; bool reset = StrEmpty(text); if (!reset) { if (strlen(text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR; if (!IsUniqueEngineName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { Engine *e = GetEngine(p1); free(e->name); if (reset) { e->name = NULL; } else { e->name = strdup(text); } MarkWholeScreenDirty(); } return CommandCost(); } /** Check if an engine is buildable. * @param engine index of the engine to check. * @param type the type the engine should be. * @param company index of the company. * @return True if an engine is valid, of the specified type, and buildable by * the given company. */ bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company) { /* check if it's an engine that is in the engine array */ if (!IsEngineIndex(engine)) return false; const Engine *e = GetEngine(engine); /* check if it's an engine of specified type */ if (e->type != type) return false; /* check if it's available */ if (!HasBit(e->company_avail, company)) return false; if (type == VEH_TRAIN) { /* Check if the rail type is available to this company */ const Company *c = GetCompany(company); if (!HasBit(c->avail_railtypes, RailVehInfo(engine)->railtype)) return false; } return true; } /** * Check if an engine is refittable. * Note: Likely you want to use IsArticulatedVehicleRefittable(). * @param engine index of the engine to check. * @return true if the engine is refittable. */ bool IsEngineRefittable(EngineID engine) { /* check if it's an engine that is in the engine array */ if (!IsEngineIndex(engine)) return false; const Engine *e = GetEngine(engine); if (e->type == VEH_SHIP && !e->u.ship.refittable) return false; if (!e->CanCarryCargo()) return false; const EngineInfo *ei = &e->info; if (ei->refit_mask == 0) return false; /* Are there suffixes? * Note: This does not mean the suffixes are actually available for every consist at any time. */ if (HasBit(ei->callbackmask, CBM_VEHICLE_CARGO_SUFFIX)) return true; /* Is there any cargo except the default cargo? */ CargoID default_cargo = e->GetDefaultCargoType(); return default_cargo != CT_INVALID && ei->refit_mask != 1U << default_cargo; }
23,781
C++
.cpp
672
32.75744
167
0.705513
EnergeticBark/OpenTTD-3DS
34
1
4
GPL-2.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,997
signs_cmd.cpp
EnergeticBark_OpenTTD-3DS/src/signs_cmd.cpp
/* $Id$ */ /** @file signs_cmd.cpp Handling of sign related commands. */ #include "stdafx.h" #include "landscape.h" #include "company_func.h" #include "signs_base.h" #include "signs_func.h" #include "command_func.h" #include "tilehighlight_func.h" #include "window_func.h" #include "map_func.h" #include "string_func.h" #include "table/strings.h" SignID _new_sign_id; /** * Place a sign at the given coordinates. Ownership of sign has * no effect whatsoever except for the colour the sign gets for easy recognition, * but everybody is able to rename/remove it. * @param tile tile to place sign at * @param flags type of operation * @param p1 unused * @param p2 unused */ CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { /* Try to locate a new sign */ if (!Sign::CanAllocateItem()) return_cmd_error(STR_2808_TOO_MANY_SIGNS); /* Check sign text length if any */ if (!StrEmpty(text) && strlen(text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR; /* When we execute, really make the sign */ if (flags & DC_EXEC) { Sign *si = new Sign(_current_company); int x = TileX(tile) * TILE_SIZE; int y = TileY(tile) * TILE_SIZE; si->x = x; si->y = y; si->z = GetSlopeZ(x, y); if (!StrEmpty(text)) { si->name = strdup(text); } UpdateSignVirtCoords(si); MarkSignDirty(si); InvalidateWindowData(WC_SIGN_LIST, 0, 0); _new_sign_id = si->index; } return CommandCost(); } /** Rename a sign. If the new name of the sign is empty, we assume * the user wanted to delete it. So delete it. Ownership of signs * has no meaning/effect whatsoever except for eyecandy * @param tile unused * @param flags type of operation * @param p1 index of the sign to be renamed/removed * @param p2 unused * @return 0 if succesfull, otherwise CMD_ERROR */ CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { if (!IsValidSignID(p1)) return CMD_ERROR; /* Rename the signs when empty, otherwise remove it */ if (!StrEmpty(text)) { if (strlen(text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR; if (flags & DC_EXEC) { Sign *si = GetSign(p1); /* Delete the old name */ free(si->name); /* Assign the new one */ si->name = strdup(text); si->owner = _current_company; /* Update; mark sign dirty twice, because it can either becom longer, or shorter */ MarkSignDirty(si); UpdateSignVirtCoords(si); MarkSignDirty(si); InvalidateWindowData(WC_SIGN_LIST, 0, 1); } } else { // Delete sign if (flags & DC_EXEC) { Sign *si = GetSign(p1); MarkSignDirty(si); delete si; InvalidateWindowData(WC_SIGN_LIST, 0, 0); } } return CommandCost(); } /** * Callback function that is called after a sign is placed * @param success of the operation * @param tile unused * @param p1 unused * @param p2 unused */ void CcPlaceSign(bool success, TileIndex tile, uint32 p1, uint32 p2) { if (success) { ShowRenameSignWindow(GetSign(_new_sign_id)); ResetObjectToPlace(); } } /** * * PlaceProc function, called when someone pressed the button if the * sign-tool is selected * @param tile on which to place the sign */ void PlaceProc_Sign(TileIndex tile) { DoCommandP(tile, 0, 0, CMD_PLACE_SIGN | CMD_MSG(STR_2809_CAN_T_PLACE_SIGN_HERE), CcPlaceSign); }
3,335
C++
.cpp
109
28.229358
102
0.709698
EnergeticBark/OpenTTD-3DS
34
1
4
GPL-2.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
false
false
false
1,538,998
autoreplace_cmd.cpp
EnergeticBark_OpenTTD-3DS/src/autoreplace_cmd.cpp
/* $Id$ */ /** @file autoreplace_cmd.cpp Deals with autoreplace execution but not the setup */ #include "stdafx.h" #include "company_func.h" #include "vehicle_gui.h" #include "train.h" #include "rail.h" #include "command_func.h" #include "engine_base.h" #include "engine_func.h" #include "vehicle_func.h" #include "functions.h" #include "autoreplace_func.h" #include "articulated_vehicles.h" #include "core/alloc_func.hpp" #include "table/strings.h" /** Figure out if two engines got at least one type of cargo in common (refitting if needed) * @param engine_a one of the EngineIDs * @param engine_b the other EngineID * @param type the type of the engines * @return true if they can both carry the same type of cargo (or at least one of them got no capacity at all) */ static bool EnginesGotCargoInCommon(EngineID engine_a, EngineID engine_b, VehicleType type) { uint32 available_cargos_a = GetUnionOfArticulatedRefitMasks(engine_a, type, true); uint32 available_cargos_b = GetUnionOfArticulatedRefitMasks(engine_b, type, true); return (available_cargos_a == 0 || available_cargos_b == 0 || (available_cargos_a & available_cargos_b) != 0); } /** * Checks some basic properties whether autoreplace is allowed * @param from Origin engine * @param to Destination engine * @param company Company to check for * @return true if autoreplace is allowed */ bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company) { /* First we make sure that it's a valid type the user requested * check that it's an engine that is in the engine array */ if (!IsEngineIndex(from) || !IsEngineIndex(to)) return false; /* we can't replace an engine into itself (that would be autorenew) */ if (from == to) return false; VehicleType type = GetEngine(from)->type; /* check that the new vehicle type is available to the company and its type is the same as the original one */ if (!IsEngineBuildable(to, type, company)) return false; switch (type) { case VEH_TRAIN: { const RailVehicleInfo *rvi_from = RailVehInfo(from); const RailVehicleInfo *rvi_to = RailVehInfo(to); /* make sure the railtypes are compatible */ if ((GetRailTypeInfo(rvi_from->railtype)->compatible_railtypes & GetRailTypeInfo(rvi_to->railtype)->compatible_railtypes) == 0) return false; /* make sure we do not replace wagons with engines or vise versa */ if ((rvi_from->railveh_type == RAILVEH_WAGON) != (rvi_to->railveh_type == RAILVEH_WAGON)) return false; break; } case VEH_ROAD: /* make sure that we do not replace a tram with a normal road vehicles or vise versa */ if (HasBit(EngInfo(from)->misc_flags, EF_ROAD_TRAM) != HasBit(EngInfo(to)->misc_flags, EF_ROAD_TRAM)) return false; break; case VEH_AIRCRAFT: /* make sure that we do not replace a plane with a helicopter or vise versa */ if ((AircraftVehInfo(from)->subtype & AIR_CTOL) != (AircraftVehInfo(to)->subtype & AIR_CTOL)) return false; break; default: break; } /* the engines needs to be able to carry the same cargo */ return EnginesGotCargoInCommon(from, to, type); } /** Transfer cargo from a single (articulated )old vehicle to the new vehicle chain * @param old_veh Old vehicle that will be sold * @param new_head Head of the completely constructed new vehicle chain * @param part_of_chain The vehicle is part of a train */ static void TransferCargo(Vehicle *old_veh, Vehicle *new_head, bool part_of_chain) { assert(!part_of_chain || new_head->IsPrimaryVehicle()); /* Loop through source parts */ for (Vehicle *src = old_veh; src != NULL; src = src->Next()) { if (!part_of_chain && src->type == VEH_TRAIN && src != old_veh && src != old_veh->u.rail.other_multiheaded_part && !IsArticulatedPart(src)) { /* Skip vehicles, which do not belong to old_veh */ src = GetLastEnginePart(src); continue; } if (src->cargo_type >= NUM_CARGO || src->cargo.Count() == 0) continue; /* Find free space in the new chain */ for (Vehicle *dest = new_head; dest != NULL && src->cargo.Count() > 0; dest = dest->Next()) { if (!part_of_chain && dest->type == VEH_TRAIN && dest != new_head && dest != new_head->u.rail.other_multiheaded_part && !IsArticulatedPart(dest)) { /* Skip vehicles, which do not belong to new_head */ dest = GetLastEnginePart(dest); continue; } if (dest->cargo_type != src->cargo_type) continue; uint amount = min(src->cargo.Count(), dest->cargo_cap - dest->cargo.Count()); if (amount <= 0) continue; src->cargo.MoveTo(&dest->cargo, amount); } } /* Update train weight etc., the old vehicle will be sold anyway */ if (part_of_chain && new_head->type == VEH_TRAIN) TrainConsistChanged(new_head, true); } /** * Tests whether refit orders that applied to v will also apply to the new vehicle type * @param v The vehicle to be replaced * @param engine_type The type we want to replace with * @return true iff all refit orders stay valid */ static bool VerifyAutoreplaceRefitForOrders(const Vehicle *v, EngineID engine_type) { const Order *o; const Vehicle *u; uint32 union_refit_mask_a = GetUnionOfArticulatedRefitMasks(v->engine_type, v->type, false); uint32 union_refit_mask_b = GetUnionOfArticulatedRefitMasks(engine_type, v->type, false); if (v->type == VEH_TRAIN) { u = v->First(); } else { u = v; } FOR_VEHICLE_ORDERS(u, o) { if (!o->IsRefit()) continue; CargoID cargo_type = o->GetRefitCargo(); if (!HasBit(union_refit_mask_a, cargo_type)) continue; if (!HasBit(union_refit_mask_b, cargo_type)) return false; } return true; } /** * Function to find what type of cargo to refit to when autoreplacing * @param *v Original vehicle, that is being replaced * @param engine_type The EngineID of the vehicle that is being replaced to * @param part_of_chain The vehicle is part of a train * @return The cargo type to replace to * CT_NO_REFIT is returned if no refit is needed * CT_INVALID is returned when both old and new vehicle got cargo capacity and refitting the new one to the old one's cargo type isn't possible */ static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, bool part_of_chain) { CargoID cargo_type; if (GetUnionOfArticulatedRefitMasks(engine_type, v->type, true) == 0) return CT_NO_REFIT; // Don't try to refit an engine with no cargo capacity if (IsArticulatedVehicleCarryingDifferentCargos(v, &cargo_type)) return CT_INVALID; // We cannot refit to mixed cargos in an automated way uint32 available_cargo_types = GetIntersectionOfArticulatedRefitMasks(engine_type, v->type, true); if (cargo_type == CT_INVALID) { if (v->type != VEH_TRAIN) return CT_NO_REFIT; // If the vehicle does not carry anything at all, every replacement is fine. if (!part_of_chain) return CT_NO_REFIT; /* the old engine didn't have cargo capacity, but the new one does * now we will figure out what cargo the train is carrying and refit to fit this */ for (v = v->First(); v != NULL; v = v->Next()) { if (v->cargo_cap == 0) continue; /* Now we found a cargo type being carried on the train and we will see if it is possible to carry to this one */ if (HasBit(available_cargo_types, v->cargo_type)) { /* Do we have to refit the vehicle, or is it already carrying the right cargo? */ uint16 *default_capacity = GetCapacityOfArticulatedParts(engine_type, v->type); for (CargoID cid = 0; cid < NUM_CARGO; cid++) { if (cid != v->cargo_type && default_capacity[cid] > 0) return v->cargo_type; } return CT_NO_REFIT; } } return CT_NO_REFIT; // We failed to find a cargo type on the old vehicle and we will not refit the new one } else { if (!HasBit(available_cargo_types, cargo_type)) return CT_INVALID; // We can't refit the vehicle to carry the cargo we want if (part_of_chain && !VerifyAutoreplaceRefitForOrders(v, engine_type)) return CT_INVALID; // Some refit orders lose their effect /* Do we have to refit the vehicle, or is it already carrying the right cargo? */ uint16 *default_capacity = GetCapacityOfArticulatedParts(engine_type, v->type); for (CargoID cid = 0; cid < NUM_CARGO; cid++) { if (cid != cargo_type && default_capacity[cid] > 0) return cargo_type; } return CT_NO_REFIT; } } /** Get the EngineID of the replacement for a vehicle * @param v The vehicle to find a replacement for * @param c The vehicle's owner (it's faster to forward the pointer than refinding it) * @return the EngineID of the replacement. INVALID_ENGINE if no buildable replacement is found */ static EngineID GetNewEngineType(const Vehicle *v, const Company *c) { assert(v->type != VEH_TRAIN || !IsArticulatedPart(v)); if (v->type == VEH_TRAIN && IsRearDualheaded(v)) { /* we build the rear ends of multiheaded trains with the front ones */ return INVALID_ENGINE; } EngineID e = EngineReplacementForCompany(c, v->engine_type, v->group_id); if (e != INVALID_ENGINE && IsEngineBuildable(e, v->type, _current_company)) { return e; } if (v->NeedsAutorenewing(c) && // replace if engine is too old IsEngineBuildable(v->engine_type, v->type, _current_company)) { // engine can still be build return v->engine_type; } return INVALID_ENGINE; } /** Builds and refits a replacement vehicle * Important: The old vehicle is still in the original vehicle chain (used for determining the cargo when the old vehicle did not carry anything, but the new one does) * @param old_veh A single (articulated/multiheaded) vehicle that shall be replaced. * @param new_vehicle Returns the newly build and refittet vehicle * @param part_of_chain The vehicle is part of a train * @return cost or error */ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehicle, bool part_of_chain) { *new_vehicle = NULL; /* Shall the vehicle be replaced? */ const Company *c = GetCompany(_current_company); EngineID e = GetNewEngineType(old_veh, c); if (e == INVALID_ENGINE) return CommandCost(); // neither autoreplace is set, nor autorenew is triggered /* Does it need to be refitted */ CargoID refit_cargo = GetNewCargoTypeForReplace(old_veh, e, part_of_chain); if (refit_cargo == CT_INVALID) return CommandCost(); // incompatible cargos /* Build the new vehicle */ CommandCost cost = DoCommand(old_veh->tile, e, 0, DC_EXEC | DC_AUTOREPLACE, GetCmdBuildVeh(old_veh)); if (cost.Failed()) return cost; Vehicle *new_veh = GetVehicle(_new_vehicle_id); *new_vehicle = new_veh; /* Refit the vehicle if needed */ if (refit_cargo != CT_NO_REFIT) { cost.AddCost(DoCommand(0, new_veh->index, refit_cargo, DC_EXEC, GetCmdRefitVeh(new_veh))); assert(cost.Succeeded()); // This should be ensured by GetNewCargoTypeForReplace() } /* Try to reverse the vehicle, but do not care if it fails as the new type might not be reversible */ if (new_veh->type == VEH_TRAIN && HasBit(old_veh->u.rail.flags, VRF_REVERSE_DIRECTION)) { DoCommand(0, new_veh->index, true, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION); } return cost; } /** Issue a start/stop command * @param v a vehicle * @param evaluate_callback shall the start/stop callback be evaluated? * @return success or error */ static inline CommandCost StartStopVehicle(const Vehicle *v, bool evaluate_callback) { return DoCommand(0, v->index, evaluate_callback ? 1 : 0, DC_EXEC | DC_AUTOREPLACE, CMD_START_STOP_VEHICLE); } /** Issue a train vehicle move command * @param v The vehicle to move * @param after The vehicle to insert 'v' after, or NULL to start new chain * @param whole_chain move all vehicles following 'v' (true), or only 'v' (false) * @return success or error */ static inline CommandCost MoveVehicle(const Vehicle *v, const Vehicle *after, DoCommandFlag flags, bool whole_chain) { return DoCommand(0, v->index | (after != NULL ? after->index : INVALID_VEHICLE) << 16, whole_chain ? 1 : 0, flags, CMD_MOVE_RAIL_VEHICLE); } /** Copy head specific things to the new vehicle chain after it was successfully constructed * @param old_head The old front vehicle (no wagons attached anymore) * @param new_head The new head of the completely replaced vehicle chain * @param flags the command flags to use */ static CommandCost CopyHeadSpecificThings(Vehicle *old_head, Vehicle *new_head, DoCommandFlag flags) { CommandCost cost = CommandCost(); /* Share orders */ if (cost.Succeeded() && old_head != new_head) cost.AddCost(DoCommand(0, (old_head->index << 16) | new_head->index, CO_SHARE, DC_EXEC, CMD_CLONE_ORDER)); /* Copy group membership */ if (cost.Succeeded() && old_head != new_head) cost.AddCost(DoCommand(0, old_head->group_id, new_head->index, DC_EXEC, CMD_ADD_VEHICLE_GROUP)); /* Perform start/stop check whether the new vehicle suits newgrf restrictions etc. */ if (cost.Succeeded()) { /* Start the vehicle, might be denied by certain things */ assert((new_head->vehstatus & VS_STOPPED) != 0); cost.AddCost(StartStopVehicle(new_head, true)); /* Stop the vehicle again, but do not care about evil newgrfs allowing starting but not stopping :p */ if (cost.Succeeded()) cost.AddCost(StartStopVehicle(new_head, false)); } /* Last do those things which do never fail (resp. we do not care about), but which are not undo-able */ if (cost.Succeeded() && old_head != new_head && (flags & DC_EXEC) != 0) { /* Copy vehicle name */ if (old_head->name != NULL) { DoCommand(0, new_head->index, 0, DC_EXEC | DC_AUTOREPLACE, CMD_RENAME_VEHICLE, old_head->name); } /* Copy other things which cannot be copied by a command and which shall not stay resetted from the build vehicle command */ new_head->CopyVehicleConfigAndStatistics(old_head); /* Switch vehicle windows to the new vehicle, so they are not closed when the old vehicle is sold */ ChangeVehicleViewWindow(old_head->index, new_head->index); } return cost; } /** Replace a single unit in a free wagon chain * @param single_unit vehicle to let autoreplace/renew operator on * @param flags command flags * @param nothing_to_do is set to 'false' when something was done (only valid when not failed) * @return cost or error */ static CommandCost ReplaceFreeUnit(Vehicle **single_unit, DoCommandFlag flags, bool *nothing_to_do) { Vehicle *old_v = *single_unit; assert(old_v->type == VEH_TRAIN && !IsArticulatedPart(old_v) && !IsRearDualheaded(old_v)); CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0); /* Build and refit replacement vehicle */ Vehicle *new_v = NULL; cost.AddCost(BuildReplacementVehicle(old_v, &new_v, false)); /* Was a new vehicle constructed? */ if (cost.Succeeded() && new_v != NULL) { *nothing_to_do = false; if ((flags & DC_EXEC) != 0) { /* Move the new vehicle behind the old */ MoveVehicle(new_v, old_v, DC_EXEC, false); /* Take over cargo * Note: We do only transfer cargo from the old to the new vehicle. * I.e. we do not transfer remaining cargo to other vehicles. * Else you would also need to consider moving cargo to other free chains, * or doing the same in ReplaceChain(), which would be quite troublesome. */ TransferCargo(old_v, new_v, false); *single_unit = new_v; } /* Sell the old vehicle */ cost.AddCost(DoCommand(0, old_v->index, 0, flags, GetCmdSellVeh(old_v))); /* If we are not in DC_EXEC undo everything */ if ((flags & DC_EXEC) == 0) { DoCommand(0, new_v->index, 0, DC_EXEC, GetCmdSellVeh(new_v)); } } return cost; } /** Replace a whole vehicle chain * @param chain vehicle chain to let autoreplace/renew operator on * @param flags command flags * @param wagon_removal remove wagons when the resulting chain occupies more tiles than the old did * @param nothing_to_do is set to 'false' when something was done (only valid when not failed) * @return cost or error */ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon_removal, bool *nothing_to_do) { Vehicle *old_head = *chain; assert(old_head->IsPrimaryVehicle()); CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0); if (old_head->type == VEH_TRAIN) { /* Store the length of the old vehicle chain, rounded up to whole tiles */ uint16 old_total_length = (old_head->u.rail.cached_total_length + TILE_SIZE - 1) / TILE_SIZE * TILE_SIZE; int num_units = 0; ///< Number of units in the chain for (Vehicle *w = old_head; w != NULL; w = GetNextUnit(w)) num_units++; Vehicle **old_vehs = CallocT<Vehicle *>(num_units); ///< Will store vehicles of the old chain in their order Vehicle **new_vehs = CallocT<Vehicle *>(num_units); ///< New vehicles corresponding to old_vehs or NULL if no replacement Money *new_costs = MallocT<Money>(num_units); ///< Costs for buying and refitting the new vehicles /* Collect vehicles and build replacements * Note: The replacement vehicles can only successfully build as long as the old vehicles are still in their chain */ int i; Vehicle *w; for (w = old_head, i = 0; w != NULL; w = GetNextUnit(w), i++) { assert(i < num_units); old_vehs[i] = w; CommandCost ret = BuildReplacementVehicle(old_vehs[i], &new_vehs[i], true); cost.AddCost(ret); if (cost.Failed()) break; new_costs[i] = ret.GetCost(); if (new_vehs[i] != NULL) *nothing_to_do = false; } Vehicle *new_head = (new_vehs[0] != NULL ? new_vehs[0] : old_vehs[0]); /* Note: When autoreplace has already failed here, old_vehs[] is not completely initialized. But it is also not needed. */ if (cost.Succeeded()) { /* Separate the head, so we can start constructing the new chain */ Vehicle *second = GetNextUnit(old_head); if (second != NULL) cost.AddCost(MoveVehicle(second, NULL, DC_EXEC | DC_AUTOREPLACE, true)); assert(GetNextUnit(new_head) == NULL); /* Append engines to the new chain * We do this from back to front, so that the head of the temporary vehicle chain does not change all the time. * OTOH the vehicle attach callback is more expensive this way :s */ Vehicle *last_engine = NULL; ///< Shall store the last engine unit after this step if (cost.Succeeded()) { for (int i = num_units - 1; i > 0; i--) { Vehicle *append = (new_vehs[i] != NULL ? new_vehs[i] : old_vehs[i]); if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) continue; if (last_engine == NULL) last_engine = append; cost.AddCost(MoveVehicle(append, new_head, DC_EXEC, false)); if (cost.Failed()) break; } if (last_engine == NULL) last_engine = new_head; } /* When wagon removal is enabled and the new engines without any wagons are already longer than the old, we have to fail */ if (cost.Succeeded() && wagon_removal && new_head->u.rail.cached_total_length > old_total_length) cost = CommandCost(STR_TRAIN_TOO_LONG_AFTER_REPLACEMENT); /* Append/insert wagons into the new vehicle chain * We do this from back to front, so we can stop when wagon removal or maximum train length (i.e. from mammoth-train setting) is triggered. */ if (cost.Succeeded()) { for (int i = num_units - 1; i > 0; i--) { assert(last_engine != NULL); Vehicle *append = (new_vehs[i] != NULL ? new_vehs[i] : old_vehs[i]); if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) { /* Insert wagon after 'last_engine' */ CommandCost res = MoveVehicle(append, last_engine, DC_EXEC, false); if (res.Succeeded() && wagon_removal && new_head->u.rail.cached_total_length > old_total_length) { MoveVehicle(append, NULL, DC_EXEC | DC_AUTOREPLACE, false); break; } cost.AddCost(res); if (cost.Failed()) break; } else { /* We have reached 'last_engine', continue with the next engine towards the front */ assert(append == last_engine); last_engine = GetPrevUnit(last_engine); } } } /* Sell superfluous new vehicles that could not be inserted. */ if (cost.Succeeded() && wagon_removal) { for (int i = 1; i < num_units; i++) { Vehicle *wagon = new_vehs[i]; if (wagon == NULL) continue; if (wagon->First() == new_head) break; assert(RailVehInfo(wagon->engine_type)->railveh_type == RAILVEH_WAGON); /* Sell wagon */ CommandCost ret = DoCommand(0, wagon->index, 0, DC_EXEC, GetCmdSellVeh(wagon)); assert(ret.Succeeded()); new_vehs[i] = NULL; /* Revert the money subtraction when the vehicle was built. * This value is different from the sell value, esp. because of refitting */ cost.AddCost(-new_costs[i]); } } /* The new vehicle chain is constructed, now take over orders and everything... */ if (cost.Succeeded()) cost.AddCost(CopyHeadSpecificThings(old_head, new_head, flags)); if (cost.Succeeded()) { /* Success ! */ if ((flags & DC_EXEC) != 0 && new_head != old_head) { *chain = new_head; } /* Transfer cargo of old vehicles and sell them */ for (int i = 0; i < num_units; i++) { Vehicle *w = old_vehs[i]; /* Is the vehicle again part of the new chain? * Note: We cannot test 'new_vehs[i] != NULL' as wagon removal might cause to remove both */ if (w->First() == new_head) continue; if ((flags & DC_EXEC) != 0) TransferCargo(w, new_head, true); /* Sell the vehicle. * Note: This might temporarly construct new trains, so use DC_AUTOREPLACE to prevent * it from failing due to engine limits. */ cost.AddCost(DoCommand(0, w->index, 0, flags | DC_AUTOREPLACE, GetCmdSellVeh(w))); if ((flags & DC_EXEC) != 0) { old_vehs[i] = NULL; if (i == 0) old_head = NULL; } } } /* If we are not in DC_EXEC undo everything, i.e. rearrange old vehicles. * We do this from back to front, so that the head of the temporary vehicle chain does not change all the time. * Note: The vehicle attach callback is disabled here :) */ if ((flags & DC_EXEC) == 0) { /* Separate the head, so we can reattach the old vehicles */ Vehicle *second = GetNextUnit(old_head); if (second != NULL) MoveVehicle(second, NULL, DC_EXEC | DC_AUTOREPLACE, true); assert(GetNextUnit(old_head) == NULL); for (int i = num_units - 1; i > 0; i--) { CommandCost ret = MoveVehicle(old_vehs[i], old_head, DC_EXEC | DC_AUTOREPLACE, false); assert(ret.Succeeded()); } } } /* Finally undo buying of new vehicles */ if ((flags & DC_EXEC) == 0) { for (int i = num_units - 1; i >= 0; i--) { if (new_vehs[i] != NULL) { DoCommand(0, new_vehs[i]->index, 0, DC_EXEC, GetCmdSellVeh(new_vehs[i])); new_vehs[i] = NULL; } } } free(old_vehs); free(new_vehs); free(new_costs); } else { /* Build and refit replacement vehicle */ Vehicle *new_head = NULL; cost.AddCost(BuildReplacementVehicle(old_head, &new_head, true)); /* Was a new vehicle constructed? */ if (cost.Succeeded() && new_head != NULL) { *nothing_to_do = false; /* The new vehicle is constructed, now take over orders and everything... */ cost.AddCost(CopyHeadSpecificThings(old_head, new_head, flags)); if (cost.Succeeded()) { /* The new vehicle is constructed, now take over cargo */ if ((flags & DC_EXEC) != 0) { TransferCargo(old_head, new_head, true); *chain = new_head; } /* Sell the old vehicle */ cost.AddCost(DoCommand(0, old_head->index, 0, flags, GetCmdSellVeh(old_head))); } /* If we are not in DC_EXEC undo everything */ if ((flags & DC_EXEC) == 0) { DoCommand(0, new_head->index, 0, DC_EXEC, GetCmdSellVeh(new_head)); } } } return cost; } /** Autoreplaces a vehicle * Trains are replaced as a whole chain, free wagons in depot are replaced on their own * @param tile not used * @param flags type of operation * @param p1 Index of vehicle * @param p2 not used */ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0); bool nothing_to_do = true; if (!IsValidVehicleID(p1)) return CMD_ERROR; Vehicle *v = GetVehicle(p1); if (!CheckOwnership(v->owner)) return CMD_ERROR; if (!v->IsInDepot()) return CMD_ERROR; if (HASBITS(v->vehstatus, VS_CRASHED)) return CMD_ERROR; bool free_wagon = false; if (v->type == VEH_TRAIN) { if (IsArticulatedPart(v) || IsRearDualheaded(v)) return CMD_ERROR; free_wagon = !IsFrontEngine(v); if (free_wagon && IsFrontEngine(v->First())) return CMD_ERROR; } else { if (!v->IsPrimaryVehicle()) return CMD_ERROR; } const Company *c = GetCompany(_current_company); bool wagon_removal = c->renew_keep_length; /* Test whether any replacement is set, before issuing a whole lot of commands that would end in nothing changed */ Vehicle *w = v; bool any_replacements = false; while (w != NULL && !any_replacements) { any_replacements = (GetNewEngineType(w, c) != INVALID_ENGINE); w = (!free_wagon && w->type == VEH_TRAIN ? GetNextUnit(w) : NULL); } if (any_replacements) { bool was_stopped = free_wagon || ((v->vehstatus & VS_STOPPED) != 0); /* Stop the vehicle */ if (!was_stopped) cost.AddCost(StartStopVehicle(v, true)); if (cost.Failed()) return cost; assert(v->IsStoppedInDepot()); /* We have to construct the new vehicle chain to test whether it is valid. * Vehicle construction needs random bits, so we have to save the random seeds * to prevent desyncs and to replay newgrf callbacks during DC_EXEC */ SavedRandomSeeds saved_seeds; SaveRandomSeeds(&saved_seeds); if (free_wagon) { cost.AddCost(ReplaceFreeUnit(&v, flags & ~DC_EXEC, &nothing_to_do)); } else { cost.AddCost(ReplaceChain(&v, flags & ~DC_EXEC, wagon_removal, &nothing_to_do)); } RestoreRandomSeeds(saved_seeds); if (cost.Succeeded() && (flags & DC_EXEC) != 0) { CommandCost ret; if (free_wagon) { ret = ReplaceFreeUnit(&v, flags, &nothing_to_do); } else { ret = ReplaceChain(&v, flags, wagon_removal, &nothing_to_do); } assert(ret.Succeeded() && ret.GetCost() == cost.GetCost()); } /* Restart the vehicle */ if (!was_stopped) cost.AddCost(StartStopVehicle(v, false)); } if (cost.Succeeded() && nothing_to_do) cost = CommandCost(STR_AUTOREPLACE_NOTHING_TO_DO); return cost; }
26,164
C++
.cpp
550
44.274545
167
0.69949
EnergeticBark/OpenTTD-3DS
34
1
4
GPL-2.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false
1,539,000
industry_cmd.cpp
EnergeticBark_OpenTTD-3DS/src/industry_cmd.cpp
/* $Id$ */ /** @file industry_cmd.cpp Handling of industry tiles. */ #include "stdafx.h" #include "openttd.h" #include "clear_map.h" #include "industry_map.h" #include "station_map.h" #include "train.h" #include "landscape.h" #include "viewport_func.h" #include "command_func.h" #include "town.h" #include "news_func.h" #include "variables.h" #include "cheat_type.h" #include "genworld.h" #include "tree_map.h" #include "newgrf.h" #include "newgrf_commons.h" #include "newgrf_industries.h" #include "newgrf_industrytiles.h" #include "autoslope.h" #include "transparency.h" #include "water.h" #include "strings_func.h" #include "functions.h" #include "window_func.h" #include "date_func.h" #include "vehicle_func.h" #include "sound_func.h" #include "oldpool_func.h" #include "animated_tile_func.h" #include "effectvehicle_func.h" #include "ai/ai.hpp" #include "table/strings.h" #include "table/industry_land.h" #include "table/build_industry.h" void ShowIndustryViewWindow(int industry); void BuildOilRig(TileIndex tile); static byte _industry_sound_ctr; static TileIndex _industry_sound_tile; int _total_industries; ///< General counter uint16 _industry_counts[NUM_INDUSTRYTYPES]; ///< Number of industries per type ingame IndustrySpec _industry_specs[NUM_INDUSTRYTYPES]; IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES]; /** This function initialize the spec arrays of both * industry and industry tiles. * It adjusts the enabling of the industry too, based on climate availability. * This will allow for clearer testings */ void ResetIndustries() { memset(&_industry_specs, 0, sizeof(_industry_specs)); memcpy(&_industry_specs, &_origin_industry_specs, sizeof(_origin_industry_specs)); /* once performed, enable only the current climate industries */ for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) { _industry_specs[i].enabled = i < NEW_INDUSTRYOFFSET && HasBit(_origin_industry_specs[i].climate_availability, _settings_game.game_creation.landscape); } memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs)); memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs)); /* Reset any overrides that have been set. */ _industile_mngr.ResetOverride(); _industry_mngr.ResetOverride(); } void ResetIndustryCreationProbility(IndustryType type) { assert(type < INVALID_INDUSTRYTYPE); _industry_specs[type].appear_creation[_settings_game.game_creation.landscape] = 0; } DEFINE_OLD_POOL_GENERIC(Industry, Industry) /** * Retrieve the type for this industry. Although it is accessed by a tile, * it will return the general type of industry, and not the sprite index * as would do GetIndustryGfx. * @param tile that is queried * @pre IsTileType(tile, MP_INDUSTRY) * @return general type for this industry, as defined in industry.h **/ IndustryType GetIndustryType(TileIndex tile) { assert(IsTileType(tile, MP_INDUSTRY)); const Industry *ind = GetIndustryByTile(tile); return ind->IsValid() ? ind->type : (IndustryType)IT_INVALID; } /** * Accessor for array _industry_specs. * This will ensure at once : proper access and * not allowing modifications of it. * @param thistype of industry (which is the index in _industry_specs) * @pre thistype < NUM_INDUSTRYTYPES * @return a pointer to the corresponding industry spec **/ const IndustrySpec *GetIndustrySpec(IndustryType thistype) { assert(thistype < NUM_INDUSTRYTYPES); return &_industry_specs[thistype]; } /** * Accessor for array _industry_tile_specs. * This will ensure at once : proper access and * not allowing modifications of it. * @param gfx of industrytile (which is the index in _industry_tile_specs) * @pre gfx < INVALID_INDUSTRYTILE * @return a pointer to the corresponding industrytile spec **/ const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx) { assert(gfx < INVALID_INDUSTRYTILE); return &_industry_tile_specs[gfx]; } Industry::~Industry() { if (CleaningPool()) return; /* Industry can also be destroyed when not fully initialized. * This means that we do not have to clear tiles either. */ if (this->width == 0) { this->xy = INVALID_TILE; return; } BEGIN_TILE_LOOP(tile_cur, this->width, this->height, this->xy); if (IsTileType(tile_cur, MP_INDUSTRY)) { if (GetIndustryIndex(tile_cur) == this->index) { /* MakeWaterKeepingClass() can also handle 'land' */ MakeWaterKeepingClass(tile_cur, OWNER_NONE); } } else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { DeleteOilRig(tile_cur); } END_TILE_LOOP(tile_cur, this->width, this->height, this->xy); if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) { /* Remove the farmland and convert it to regular tiles over time. */ BEGIN_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiffXY(21, 21)) { tile_cur = TILE_MASK(tile_cur); if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) && GetIndustryIndexOfField(tile_cur) == this->index) { SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY); } } END_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiff(21, 21)) } /* don't let any disaster vehicle target invalid industry */ ReleaseDisastersTargetingIndustry(this->index); DecIndustryTypeCount(this->type); DeleteSubsidyWithIndustry(this->index); DeleteWindowById(WC_INDUSTRY_VIEW, this->index); InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0); this->xy = INVALID_TILE; } static void IndustryDrawSugarMine(const TileInfo *ti) { const DrawIndustryAnimationStruct *d; if (!IsIndustryCompleted(ti->tile)) return; d = &_draw_industry_spec1[GetIndustryAnimationState(ti->tile)]; AddChildSpriteScreen(SPR_IT_SUGAR_MINE_SIEVE + d->image_1, PAL_NONE, d->x, 0); if (d->image_2 != 0) { AddChildSpriteScreen(SPR_IT_SUGAR_MINE_CLOUDS + d->image_2 - 1, PAL_NONE, 8, 41); } if (d->image_3 != 0) { AddChildSpriteScreen(SPR_IT_SUGAR_MINE_PILE + d->image_3 - 1, PAL_NONE, _drawtile_proc1[d->image_3 - 1].x, _drawtile_proc1[d->image_3 - 1].y); } } static void IndustryDrawToffeeQuarry(const TileInfo *ti) { uint8 x = 0; if (IsIndustryCompleted(ti->tile)) { x = _industry_anim_offs_toffee[GetIndustryAnimationState(ti->tile)]; if (x == 0xFF) x = 0; } AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_SHOVEL, PAL_NONE, 22 - x, 24 + x); AddChildSpriteScreen(SPR_IT_TOFFEE_QUARRY_TOFFEE, PAL_NONE, 6, 14); } static void IndustryDrawBubbleGenerator( const TileInfo *ti) { if (IsIndustryCompleted(ti->tile)) { AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_BUBBLE, PAL_NONE, 5, _industry_anim_offs_bubbles[GetIndustryAnimationState(ti->tile)]); } else { AddChildSpriteScreen(SPR_IT_BUBBLE_GENERATOR_SPRING, PAL_NONE, 3, 67); } } static void IndustryDrawToyFactory(const TileInfo *ti) { const DrawIndustryAnimationStruct *d; d = &_industry_anim_offs_toys[GetIndustryAnimationState(ti->tile)]; if (d->image_1 != 0xFF) { AddChildSpriteScreen(SPR_IT_TOY_FACTORY_CLAY, PAL_NONE, d->x, 96 + d->image_1); } if (d->image_2 != 0xFF) { AddChildSpriteScreen(SPR_IT_TOY_FACTORY_ROBOT, PAL_NONE, 16 - d->image_2 * 2, 100 + d->image_2); } AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP, PAL_NONE, 7, d->image_3); AddChildSpriteScreen(SPR_IT_TOY_FACTORY_STAMP_HOLDER, PAL_NONE, 0, 42); } static void IndustryDrawCoalPlantSparks(const TileInfo *ti) { if (IsIndustryCompleted(ti->tile)) { uint8 image = GetIndustryAnimationState(ti->tile); if (image != 0 && image < 7) { AddChildSpriteScreen(image + SPR_IT_POWER_PLANT_TRANSFORMERS, PAL_NONE, _coal_plant_sparks[image - 1].x, _coal_plant_sparks[image - 1].y ); } } } typedef void IndustryDrawTileProc(const TileInfo *ti); static IndustryDrawTileProc * const _industry_draw_tile_procs[5] = { IndustryDrawSugarMine, IndustryDrawToffeeQuarry, IndustryDrawBubbleGenerator, IndustryDrawToyFactory, IndustryDrawCoalPlantSparks, }; static void DrawTile_Industry(TileInfo *ti) { IndustryGfx gfx = GetIndustryGfx(ti->tile); Industry *ind = GetIndustryByTile(ti->tile); const IndustryTileSpec *indts = GetIndustryTileSpec(gfx); const DrawBuildingsTileStruct *dits; SpriteID image; SpriteID pal; /* Retrieve pointer to the draw industry tile struct */ if (gfx >= NEW_INDUSTRYTILEOFFSET) { /* Draw the tile using the specialized method of newgrf industrytile. * DrawNewIndustry will return false if ever the resolver could not * find any sprite to display. So in this case, we will jump on the * substitute gfx instead. */ if (indts->grf_prop.spritegroup != NULL && DrawNewIndustryTile(ti, ind, gfx, indts)) { return; } else { /* No sprite group (or no valid one) found, meaning no graphics associated. * Use the substitute one instead */ if (indts->grf_prop.subst_id != INVALID_INDUSTRYTILE) { gfx = indts->grf_prop.subst_id; /* And point the industrytile spec accordingly */ indts = GetIndustryTileSpec(gfx); } } } dits = &_industry_draw_tile_data[gfx << 2 | (indts->anim_state ? GetIndustryAnimationState(ti->tile) & INDUSTRY_COMPLETED : GetIndustryConstructionStage(ti->tile))]; image = dits->ground.sprite; if (HasBit(image, PALETTE_MODIFIER_COLOUR) && dits->ground.pal == PAL_NONE) { pal = GENERAL_SPRITE_COLOUR(ind->random_colour); } else { pal = dits->ground.pal; } /* DrawFoundation() modifes ti->z and ti->tileh */ if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); /* If the ground sprite is the default flat water sprite, draw also canal/river borders. * Do not do this if the tile's WaterClass is 'land'. */ if (image == SPR_FLAT_WATER_TILE && IsIndustryTileOnWater(ti->tile)) { DrawWaterClassGround(ti); } else { DrawGroundSprite(image, pal); } /* If industries are transparent and invisible, do not draw the upper part */ if (IsInvisibilitySet(TO_INDUSTRIES)) return; /* Add industry on top of the ground? */ image = dits->building.sprite; if (image != 0) { AddSortableSpriteToDraw(image, (HasBit(image, PALETTE_MODIFIER_COLOUR) && dits->building.pal == PAL_NONE) ? GENERAL_SPRITE_COLOUR(ind->random_colour) : dits->building.pal, ti->x + dits->subtile_x, ti->y + dits->subtile_y, dits->width, dits->height, dits->dz, ti->z, IsTransparencySet(TO_INDUSTRIES)); if (IsTransparencySet(TO_INDUSTRIES)) return; } { int proc = dits->draw_proc - 1; if (proc >= 0) _industry_draw_tile_procs[proc](ti); } } static uint GetSlopeZ_Industry(TileIndex tile, uint x, uint y) { return GetTileMaxZ(tile); } static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh) { IndustryGfx gfx = GetIndustryGfx(tile); /* For NewGRF industry tiles we might not be drawing a foundation. We need to * account for this, as other structures should * draw the wall of the foundation in this case. */ if (gfx >= NEW_INDUSTRYTILEOFFSET) { const IndustryTileSpec *indts = GetIndustryTileSpec(gfx); if (indts->grf_prop.spritegroup != NULL && HasBit(indts->callback_flags, CBM_INDT_DRAW_FOUNDATIONS)) { uint32 callback_res = GetIndustryTileCallback(CBID_INDUSTRY_DRAW_FOUNDATIONS, 0, 0, gfx, GetIndustryByTile(tile), tile); if (callback_res == 0) return FOUNDATION_NONE; } } return FlatteningFoundation(tileh); } static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac) { IndustryGfx gfx = GetIndustryGfx(tile); const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); /* When we have to use a callback, we put our data in the next two variables */ CargoID raw_accepts_cargo[lengthof(itspec->accepts_cargo)]; uint8 raw_acceptance[lengthof(itspec->acceptance)]; /* And then these will always point to a same sized array with the required data */ const CargoID *accepts_cargo = itspec->accepts_cargo; const uint8 *acceptance = itspec->acceptance; if (HasBit(itspec->callback_flags, CBM_INDT_ACCEPT_CARGO)) { uint16 res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, GetIndustryByTile(tile), tile); if (res != CALLBACK_FAILED) { accepts_cargo = raw_accepts_cargo; for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile); } } if (HasBit(itspec->callback_flags, CBM_INDT_CARGO_ACCEPTANCE)) { uint16 res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, GetIndustryByTile(tile), tile); if (res != CALLBACK_FAILED) { acceptance = raw_acceptance; for (uint i = 0; i < lengthof(itspec->accepts_cargo); i++) raw_acceptance[i] = GB(res, i * 4, 4); } } for (byte i = 0; i < lengthof(itspec->accepts_cargo); i++) { CargoID a = accepts_cargo[i]; /* Only set the value once. */ if (a != CT_INVALID && ac[a] == 0) ac[a] = acceptance[i]; } } static void GetTileDesc_Industry(TileIndex tile, TileDesc *td) { const Industry *i = GetIndustryByTile(tile); const IndustrySpec *is = GetIndustrySpec(i->type); td->owner[0] = i->owner; td->str = is->name; if (!IsIndustryCompleted(tile)) { SetDParamX(td->dparam, 0, td->str); td->str = STR_2058_UNDER_CONSTRUCTION; } if (is->grf_prop.grffile != NULL) { td->grf = GetGRFConfig(is->grf_prop.grffile->grfid)->name; } } static CommandCost ClearTile_Industry(TileIndex tile, DoCommandFlag flags) { Industry *i = GetIndustryByTile(tile); const IndustrySpec *indspec = GetIndustrySpec(i->type); /* water can destroy industries * in editor you can bulldoze industries * with magic_bulldozer cheat you can destroy industries * (area around OILRIG is water, so water shouldn't flood it */ if ((_current_company != OWNER_WATER && _game_mode != GM_EDITOR && !_cheats.magic_bulldozer.value) || ((flags & DC_AUTO) != 0) || (_current_company == OWNER_WATER && ((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) || HasBit(GetIndustryTileSpec(GetIndustryGfx(tile))->slopes_refused, 5)))) { SetDParam(0, indspec->name); return_cmd_error(flags & DC_AUTO ? STR_4800_IN_THE_WAY : INVALID_STRING_ID); } if (flags & DC_EXEC) { AI::BroadcastNewEvent(new AIEventIndustryClose(i->index)); delete i; } return CommandCost(EXPENSES_CONSTRUCTION, indspec->GetRemovalCost()); } static void TransportIndustryGoods(TileIndex tile) { Industry *i = GetIndustryByTile(tile); const IndustrySpec *indspec = GetIndustrySpec(i->type); bool moved_cargo = false; for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) { uint cw = min(i->produced_cargo_waiting[j], 255); if (cw > indspec->minimal_cargo && i->produced_cargo[j] != CT_INVALID) { i->produced_cargo_waiting[j] -= cw; /* fluctuating economy? */ if (_economy.fluct <= 0) cw = (cw + 1) / 2; i->this_month_production[j] += cw; uint am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[j], cw); i->this_month_transported[j] += am; moved_cargo |= (am != 0); } } if (moved_cargo && !StartStopIndustryTileAnimation(i, IAT_INDUSTRY_DISTRIBUTES_CARGO)) { uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production; if (newgfx != INDUSTRYTILE_NOANIM) { ResetIndustryConstructionStage(tile); SetIndustryCompleted(tile, true); SetIndustryGfx(tile, newgfx); MarkTileDirtyByTile(tile); } } } static void AnimateTile_Industry(TileIndex tile) { byte m; IndustryGfx gfx = GetIndustryGfx(tile); if (GetIndustryTileSpec(gfx)->animation_info != 0xFFFF) { AnimateNewIndustryTile(tile); return; } switch (gfx) { case GFX_SUGAR_MINE_SIEVE: if ((_tick_counter & 1) == 0) { m = GetIndustryAnimationState(tile) + 1; switch (m & 7) { case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break; case 6: SndPlayTileFx(SND_29_RIP, tile); break; } if (m >= 96) { m = 0; DeleteAnimatedTile(tile); } SetIndustryAnimationState(tile, m); MarkTileDirtyByTile(tile); } break; case GFX_TOFFEE_QUARY: if ((_tick_counter & 3) == 0) { m = GetIndustryAnimationState(tile); if (_industry_anim_offs_toffee[m] == 0xFF) { SndPlayTileFx(SND_30_CARTOON_SOUND, tile); } if (++m >= 70) { m = 0; DeleteAnimatedTile(tile); } SetIndustryAnimationState(tile, m); MarkTileDirtyByTile(tile); } break; case GFX_BUBBLE_CATCHER: if ((_tick_counter & 1) == 0) { m = GetIndustryAnimationState(tile); if (++m >= 40) { m = 0; DeleteAnimatedTile(tile); } SetIndustryAnimationState(tile, m); MarkTileDirtyByTile(tile); } break; /* Sparks on a coal plant */ case GFX_POWERPLANT_SPARKS: if ((_tick_counter & 3) == 0) { m = GetIndustryAnimationState(tile); if (m == 6) { SetIndustryAnimationState(tile, 0); DeleteAnimatedTile(tile); } else { SetIndustryAnimationState(tile, m + 1); MarkTileDirtyByTile(tile); } } break; case GFX_TOY_FACTORY: if ((_tick_counter & 1) == 0) { m = GetIndustryAnimationState(tile) + 1; switch (m) { case 1: SndPlayTileFx(SND_2C_MACHINERY, tile); break; case 23: SndPlayTileFx(SND_2B_COMEDY_HIT, tile); break; case 28: SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile); break; default: if (m >= 50) { int n = GetIndustryAnimationLoop(tile) + 1; m = 0; if (n >= 8) { n = 0; DeleteAnimatedTile(tile); } SetIndustryAnimationLoop(tile, n); } } SetIndustryAnimationState(tile, m); MarkTileDirtyByTile(tile); } break; case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2: case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4: case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6: case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8: if ((_tick_counter & 3) == 0) { IndustryGfx gfx = GetIndustryGfx(tile); gfx = (gfx < 155) ? gfx + 1 : 148; SetIndustryGfx(tile, gfx); MarkTileDirtyByTile(tile); } break; case GFX_OILWELL_ANIMATED_1: case GFX_OILWELL_ANIMATED_2: case GFX_OILWELL_ANIMATED_3: if ((_tick_counter & 7) == 0) { bool b = Chance16(1, 7); IndustryGfx gfx = GetIndustryGfx(tile); m = GetIndustryAnimationState(tile) + 1; if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) { SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED); SetIndustryConstructionStage(tile, 3); DeleteAnimatedTile(tile); } else { SetIndustryAnimationState(tile, m); SetIndustryGfx(tile, gfx); MarkTileDirtyByTile(tile); } } break; case GFX_COAL_MINE_TOWER_ANIMATED: case GFX_COPPER_MINE_TOWER_ANIMATED: case GFX_GOLD_MINE_TOWER_ANIMATED: { int state = _tick_counter & 0x7FF; if ((state -= 0x400) < 0) return; if (state < 0x1A0) { if (state < 0x20 || state >= 0x180) { m = GetIndustryAnimationState(tile); if (!(m & 0x40)) { SetIndustryAnimationState(tile, m | 0x40); SndPlayTileFx(SND_0B_MINING_MACHINERY, tile); } if (state & 7) return; } else { if (state & 3) return; } m = (GetIndustryAnimationState(tile) + 1) | 0x40; if (m > 0xC2) m = 0xC0; SetIndustryAnimationState(tile, m); MarkTileDirtyByTile(tile); } else if (state >= 0x200 && state < 0x3A0) { int i; i = (state < 0x220 || state >= 0x380) ? 7 : 3; if (state & i) return; m = (GetIndustryAnimationState(tile) & 0xBF) - 1; if (m < 0x80) m = 0x82; SetIndustryAnimationState(tile, m); MarkTileDirtyByTile(tile); } } break; } } static void CreateChimneySmoke(TileIndex tile) { uint x = TileX(tile) * TILE_SIZE; uint y = TileY(tile) * TILE_SIZE; uint z = GetTileMaxZ(tile); CreateEffectVehicle(x + 15, y + 14, z + 59, EV_CHIMNEY_SMOKE); } static void MakeIndustryTileBigger(TileIndex tile) { byte cnt = GetIndustryConstructionCounter(tile) + 1; byte stage; if (cnt != 4) { SetIndustryConstructionCounter(tile, cnt); return; } stage = GetIndustryConstructionStage(tile) + 1; SetIndustryConstructionCounter(tile, 0); SetIndustryConstructionStage(tile, stage); StartStopIndustryTileAnimation(tile, IAT_CONSTRUCTION_STATE_CHANGE); if (stage == INDUSTRY_COMPLETED) SetIndustryCompleted(tile, true); MarkTileDirtyByTile(tile); if (!IsIndustryCompleted(tile)) return; IndustryGfx gfx = GetIndustryGfx(tile); if (gfx >= NEW_INDUSTRYTILEOFFSET) { /* New industries are already animated on construction. */ return; } switch (gfx) { case GFX_POWERPLANT_CHIMNEY: CreateChimneySmoke(tile); break; case GFX_OILRIG_1: if (GetIndustryGfx(tile + TileDiffXY(0, 1)) == GFX_OILRIG_1) BuildOilRig(tile); break; case GFX_TOY_FACTORY: case GFX_BUBBLE_CATCHER: case GFX_TOFFEE_QUARY: SetIndustryAnimationState(tile, 0); SetIndustryAnimationLoop(tile, 0); break; case GFX_PLASTIC_FOUNTAIN_ANIMATED_1: case GFX_PLASTIC_FOUNTAIN_ANIMATED_2: case GFX_PLASTIC_FOUNTAIN_ANIMATED_3: case GFX_PLASTIC_FOUNTAIN_ANIMATED_4: case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6: case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8: AddAnimatedTile(tile); break; } } static void TileLoopIndustry_BubbleGenerator(TileIndex tile) { int dir; Vehicle *v; static const int8 _bubble_spawn_location[3][4] = { { 11, 0, -4, -14 }, { -4, -10, -4, 1 }, { 49, 59, 60, 65 }, }; SndPlayTileFx(SND_2E_EXTRACT_AND_POP, tile); dir = Random() & 3; v = CreateEffectVehicleAbove( TileX(tile) * TILE_SIZE + _bubble_spawn_location[0][dir], TileY(tile) * TILE_SIZE + _bubble_spawn_location[1][dir], _bubble_spawn_location[2][dir], EV_BUBBLE ); if (v != NULL) v->u.effect.animation_substate = dir; } static void TileLoop_Industry(TileIndex tile) { IndustryGfx newgfx; IndustryGfx gfx; if (IsIndustryTileOnWater(tile)) TileLoop_Water(tile); TriggerIndustryTile(tile, INDTILE_TRIGGER_TILE_LOOP); if (!IsIndustryCompleted(tile)) { MakeIndustryTileBigger(tile); return; } if (_game_mode == GM_EDITOR) return; TransportIndustryGoods(tile); if (StartStopIndustryTileAnimation(tile, IAT_TILELOOP)) return; newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_next; if (newgfx != INDUSTRYTILE_NOANIM) { ResetIndustryConstructionStage(tile); SetIndustryGfx(tile, newgfx); MarkTileDirtyByTile(tile); return; } gfx = GetIndustryGfx(tile); switch (gfx) { case GFX_COAL_MINE_TOWER_NOT_ANIMATED: case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: if (!(_tick_counter & 0x400) && Chance16(1, 2)) { switch (gfx) { case GFX_COAL_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COAL_MINE_TOWER_ANIMATED; break; case GFX_COPPER_MINE_TOWER_NOT_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_ANIMATED; break; case GFX_GOLD_MINE_TOWER_NOT_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_ANIMATED; break; } SetIndustryGfx(tile, gfx); SetIndustryAnimationState(tile, 0x80); AddAnimatedTile(tile); } break; case GFX_OILWELL_NOT_ANIMATED: if (Chance16(1, 6)) { SetIndustryGfx(tile, GFX_OILWELL_ANIMATED_1); SetIndustryAnimationState(tile, 0); AddAnimatedTile(tile); } break; case GFX_COAL_MINE_TOWER_ANIMATED: case GFX_COPPER_MINE_TOWER_ANIMATED: case GFX_GOLD_MINE_TOWER_ANIMATED: if (!(_tick_counter & 0x400)) { switch (gfx) { case GFX_COAL_MINE_TOWER_ANIMATED: gfx = GFX_COAL_MINE_TOWER_NOT_ANIMATED; break; case GFX_COPPER_MINE_TOWER_ANIMATED: gfx = GFX_COPPER_MINE_TOWER_NOT_ANIMATED; break; case GFX_GOLD_MINE_TOWER_ANIMATED: gfx = GFX_GOLD_MINE_TOWER_NOT_ANIMATED; break; } SetIndustryGfx(tile, gfx); SetIndustryCompleted(tile, true); SetIndustryConstructionStage(tile, 3); DeleteAnimatedTile(tile); } break; case GFX_POWERPLANT_SPARKS: if (Chance16(1, 3)) { SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile); AddAnimatedTile(tile); } break; case GFX_COPPER_MINE_CHIMNEY: CreateEffectVehicleAbove(TileX(tile) * TILE_SIZE + 6, TileY(tile) * TILE_SIZE + 6, 43, EV_SMOKE); break; case GFX_TOY_FACTORY: { Industry *i = GetIndustryByTile(tile); if (i->was_cargo_delivered) { i->was_cargo_delivered = false; SetIndustryAnimationLoop(tile, 0); AddAnimatedTile(tile); } } break; case GFX_BUBBLE_GENERATOR: TileLoopIndustry_BubbleGenerator(tile); break; case GFX_TOFFEE_QUARY: AddAnimatedTile(tile); break; case GFX_SUGAR_MINE_SIEVE: if (Chance16(1, 3)) AddAnimatedTile(tile); break; } } static bool ClickTile_Industry(TileIndex tile) { ShowIndustryViewWindow(GetIndustryIndex(tile)); return true; } static TrackStatus GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { return 0; } static void GetProducedCargo_Industry(TileIndex tile, CargoID *b) { const Industry *i = GetIndustryByTile(tile); b[0] = i->produced_cargo[0]; b[1] = i->produced_cargo[1]; } static void ChangeTileOwner_Industry(TileIndex tile, Owner old_owner, Owner new_owner) { /* If the founder merges, the industry was created by the merged company */ Industry *i = GetIndustryByTile(tile); if (i->founder == old_owner) i->founder = (new_owner == INVALID_OWNER) ? OWNER_NONE : new_owner; } static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}; static bool IsBadFarmFieldTile(TileIndex tile) { switch (GetTileType(tile)) { case MP_CLEAR: return IsClearGround(tile, CLEAR_FIELDS) || IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT); case MP_TREES: return (GetTreeGround(tile) == TREE_GROUND_SHORE); default: return true; } } static bool IsBadFarmFieldTile2(TileIndex tile) { switch (GetTileType(tile)) { case MP_CLEAR: return IsClearGround(tile, CLEAR_SNOW) || IsClearGround(tile, CLEAR_DESERT); case MP_TREES: return (GetTreeGround(tile) == TREE_GROUND_SHORE); default: return true; } } static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direction) { do { tile = TILE_MASK(tile); if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) { byte or_ = type; if (or_ == 1 && Chance16(1, 7)) or_ = 2; if (direction == AXIS_X) { SetFenceSE(tile, or_); } else { SetFenceSW(tile, or_); } } tile += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1)); } while (--size); } static void PlantFarmField(TileIndex tile, IndustryID industry) { uint size_x, size_y; uint32 r; uint count; uint counter; uint field_type; int type; if (_settings_game.game_creation.landscape == LT_ARCTIC) { if (GetTileZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine()) return; } /* determine field size */ r = (Random() & 0x303) + 0x404; if (_settings_game.game_creation.landscape == LT_ARCTIC) r += 0x404; size_x = GB(r, 0, 8); size_y = GB(r, 8, 8); /* offset tile to match size */ tile -= TileDiffXY(size_x / 2, size_y / 2); if (TileX(tile) + size_x >= MapSizeX() || TileY(tile) + size_y >= MapSizeY()) return; /* check the amount of bad tiles */ count = 0; BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) assert(cur_tile < MapSize()); count += IsBadFarmFieldTile(cur_tile); END_TILE_LOOP(cur_tile, size_x, size_y, tile) if (count * 2 >= size_x * size_y) return; /* determine type of field */ r = Random(); counter = GB(r, 5, 3); field_type = GB(r, 8, 8) * 9 >> 8; /* make field */ BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile) assert(cur_tile < MapSize()); if (!IsBadFarmFieldTile2(cur_tile)) { MakeField(cur_tile, field_type, industry); SetClearCounter(cur_tile, counter); MarkTileDirtyByTile(cur_tile); } END_TILE_LOOP(cur_tile, size_x, size_y, tile) type = 3; if (_settings_game.game_creation.landscape != LT_ARCTIC && _settings_game.game_creation.landscape != LT_TROPIC) { type = _plantfarmfield_type[Random() & 0xF]; } SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, AXIS_Y); SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X); SetupFarmFieldFence(tile + TileDiffXY(size_x - 1, 0), size_y, type, AXIS_Y); SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, AXIS_X); } void PlantRandomFarmField(const Industry *i) { int x = i->width / 2 + Random() % 31 - 16; int y = i->height / 2 + Random() % 31 - 16; TileIndex tile = TileAddWrap(i->xy, x, y); if (tile != INVALID_TILE) PlantFarmField(tile, i->index); } /** * Search callback function for ChopLumberMillTrees * @param tile to test * @param user_data that is passed by the caller. In this case, nothing * @return the result of the test */ static bool SearchLumberMillTrees(TileIndex tile, void *user_data) { if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees CompanyID old_company = _current_company; /* found a tree */ _current_company = OWNER_NONE; _industry_sound_ctr = 1; _industry_sound_tile = tile; SndPlayTileFx(SND_38_CHAINSAW, tile); DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); _current_company = old_company; return true; } return false; } /** * Perform a circular search around the Lumber Mill in order to find trees to cut * @param i industry */ static void ChopLumberMillTrees(Industry *i) { TileIndex tile = i->xy; if (!IsIndustryCompleted(tile)) return; ///< Can't proceed if not completed if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, NULL)) ///< 40x40 tiles to search i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo } static void ProduceIndustryGoods(Industry *i) { uint32 r; uint num; const IndustrySpec *indsp = GetIndustrySpec(i->type); /* play a sound? */ if ((i->counter & 0x3F) == 0) { if (Chance16R(1, 14, r) && (num = indsp->number_of_sounds) != 0) { SndPlayTileFx( (SoundFx)(indsp->random_sounds[((r >> 16) * num) >> 16]), i->xy); } } i->counter--; /* produce some cargo */ if ((i->counter & 0xFF) == 0) { if (HasBit(indsp->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1); IndustryBehaviour indbehav = indsp->behaviour; i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + i->production_rate[0]); i->produced_cargo_waiting[1] = min(0xffff, i->produced_cargo_waiting[1] + i->production_rate[1]); if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) { bool plant; if (HasBit(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) { plant = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, Random(), 0, i, i->type, i->xy) != 0); } else { plant = Chance16(1, 8); } if (plant) PlantRandomFarmField(i); } if ((indbehav & INDUSTRYBEH_CUT_TREES) != 0) { bool cut = ((i->counter & 0x1FF) == 0); if (HasBit(indsp->callback_flags, CBM_IND_SPECIAL_EFFECT)) { cut = (GetIndustryCallback(CBID_INDUSTRY_SPECIAL_EFFECT, 0, 1, i, i->type, i->xy) != 0); } if (cut) ChopLumberMillTrees(i); } TriggerIndustry(i, INDUSTRY_TRIGGER_INDUSTRY_TICK); StartStopIndustryTileAnimation(i, IAT_INDUSTRY_TICK); } } void OnTick_Industry() { Industry *i; if (_industry_sound_ctr != 0) { _industry_sound_ctr++; if (_industry_sound_ctr == 75) { SndPlayTileFx(SND_37_BALLOON_SQUEAK, _industry_sound_tile); } else if (_industry_sound_ctr == 160) { _industry_sound_ctr = 0; SndPlayTileFx(SND_36_CARTOON_CRASH, _industry_sound_tile); } } if (_game_mode == GM_EDITOR) return; FOR_ALL_INDUSTRIES(i) { ProduceIndustryGoods(i); } } static bool CheckNewIndustry_NULL(TileIndex tile) { return true; } static bool CheckNewIndustry_Forest(TileIndex tile) { if (_settings_game.game_creation.landscape == LT_ARCTIC) { if (GetTileZ(tile) < HighestSnowLine() + TILE_HEIGHT * 2U) { _error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED; return false; } } return true; } static bool CheckNewIndustry_OilRefinery(TileIndex tile) { if (_game_mode == GM_EDITOR) return true; if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _settings_game.game_creation.oil_refinery_limit) return true; _error_message = STR_483B_CAN_ONLY_BE_POSITIONED; return false; } extern bool _ignore_restrictions; static bool CheckNewIndustry_OilRig(TileIndex tile) { if (_game_mode == GM_EDITOR && _ignore_restrictions) return true; if (TileHeight(tile) == 0 && DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _settings_game.game_creation.oil_refinery_limit) return true; _error_message = STR_483B_CAN_ONLY_BE_POSITIONED; return false; } static bool CheckNewIndustry_Farm(TileIndex tile) { if (_settings_game.game_creation.landscape == LT_ARCTIC) { if (GetTileZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) { _error_message = STR_0239_SITE_UNSUITABLE; return false; } } return true; } static bool CheckNewIndustry_Plantation(TileIndex tile) { if (GetTropicZone(tile) == TROPICZONE_DESERT) { _error_message = STR_0239_SITE_UNSUITABLE; return false; } return true; } static bool CheckNewIndustry_Water(TileIndex tile) { if (GetTropicZone(tile) != TROPICZONE_DESERT) { _error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT; return false; } return true; } static bool CheckNewIndustry_Lumbermill(TileIndex tile) { if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) { _error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST; return false; } return true; } static bool CheckNewIndustry_BubbleGen(TileIndex tile) { return GetTileZ(tile) <= TILE_HEIGHT * 4; } typedef bool CheckNewIndustryProc(TileIndex tile); static CheckNewIndustryProc * const _check_new_industry_procs[CHECK_END] = { CheckNewIndustry_NULL, CheckNewIndustry_Forest, CheckNewIndustry_OilRefinery, CheckNewIndustry_Farm, CheckNewIndustry_Plantation, CheckNewIndustry_Water, CheckNewIndustry_Lumbermill, CheckNewIndustry_BubbleGen, CheckNewIndustry_OilRig }; static const Town *CheckMultipleIndustryInTown(TileIndex tile, int type) { const Town *t; const Industry *i; t = ClosestTownFromTile(tile, UINT_MAX); if (_settings_game.economy.multiple_industry_per_town) return t; FOR_ALL_INDUSTRIES(i) { if (i->type == (byte)type && i->town == t) { _error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN; return NULL; } } return t; } bool IsSlopeRefused(Slope current, Slope refused) { if (IsSteepSlope(current)) return true; if (current != SLOPE_FLAT) { if (IsSteepSlope(refused)) return true; Slope t = ComplementSlope(current); if (refused & SLOPE_W && (t & SLOPE_NW)) return true; if (refused & SLOPE_S && (t & SLOPE_NE)) return true; if (refused & SLOPE_E && (t & SLOPE_SW)) return true; if (refused & SLOPE_N && (t & SLOPE_SE)) return true; } return false; } static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, bool *custom_shape_check = NULL) { _error_message = STR_0239_SITE_UNSUITABLE; bool refused_slope = false; bool custom_shape = false; do { IndustryGfx gfx = GetTranslatedIndustryTileID(it->gfx); if (TileX(tile) + it->ti.x >= MapSizeX()) return false; if (TileY(tile) + it->ti.y >= MapSizeY()) return false; TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); if (!IsValidTile(cur_tile)) { if (gfx == GFX_WATERTILE_SPECIALCHECK) continue; return false; } if (gfx == GFX_WATERTILE_SPECIALCHECK) { if (!IsTileType(cur_tile, MP_WATER) || GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) { return false; } } else { if (!EnsureNoVehicleOnGround(cur_tile)) return false; if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return false; const IndustryTileSpec *its = GetIndustryTileSpec(gfx); IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour; /* Perform land/water check if not disabled */ if (!HasBit(its->slopes_refused, 5) && (IsWaterTile(cur_tile) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return false; if (HasBit(its->callback_flags, CBM_INDT_SHAPE_CHECK)) { custom_shape = true; if (!PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index)) return false; } else { Slope tileh = GetTileSlope(cur_tile, NULL); refused_slope |= IsSlopeRefused(tileh, its->slopes_refused); } if ((ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) || // Tile must be a house ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) && IsTileType(cur_tile, MP_HOUSE))) { // Tile is allowed to be a house (and it is a house) if (!IsTileType(cur_tile, MP_HOUSE)) { _error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS; return false; } /* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */ CompanyID old_company = _current_company; _current_company = OWNER_TOWN; bool not_clearable = CmdFailed(DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR)); _current_company = old_company; if (not_clearable) return false; } else { /* Clear the tiles, but do not affect town ratings */ bool not_clearable = CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR)); if (not_clearable) return false; } } } while ((++it)->ti.x != -0x80); if (custom_shape_check != NULL) *custom_shape_check = custom_shape; /* It is almost impossible to have a fully flat land in TG, so what we * do is that we check if we can make the land flat later on. See * CheckIfCanLevelIndustryPlatform(). */ return !refused_slope || (_settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !custom_shape && !_ignore_restrictions); } static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t) { if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) { _error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS; return false; } if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) { _error_message = STR_0239_SITE_UNSUITABLE; return false; } return true; } static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal) { int size_x, size_y; uint curh; size_x = 2; size_y = 2; /* Check if we don't leave the map */ if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false; tile += TileDiffXY(-1, -1); BEGIN_TILE_LOOP(tile_walk, size_x, size_y, tile) { curh = TileHeight(tile_walk); /* Is the tile clear? */ if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES)) return false; /* Don't allow too big of a change if this is the sub-tile check */ if (internal != 0 && Delta(curh, height) > 1) return false; /* Different height, so the surrounding tiles of this tile * has to be correct too (in level, or almost in level) * else you get a chain-reaction of terraforming. */ if (internal == 0 && curh != height) { if (TileX(tile_walk) == 0 || TileY(tile_walk) == 0 || !CheckCanTerraformSurroundingTiles(tile_walk + TileDiffXY(-1, -1), height, internal + 1)) return false; } } END_TILE_LOOP(tile_walk, size_x, size_y, tile); return true; } /** * This function tries to flatten out the land below an industry, without * damaging the surroundings too much. */ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags, const IndustryTileTable *it, int type) { const int MKEND = -0x80; // used for last element in an IndustryTileTable (see build_industry.h) int max_x = 0; int max_y = 0; TileIndex cur_tile; uint size_x, size_y; uint h, curh; /* Finds dimensions of largest variant of this industry */ do { if (it->gfx == 0xFF) continue; // FF been a marquer for a check on clear water, skip it if (it->ti.x > max_x) max_x = it->ti.x; if (it->ti.y > max_y) max_y = it->ti.y; } while ((++it)->ti.x != MKEND); /* Remember level height */ h = TileHeight(tile); if (TileX(tile) <= 1 || TileY(tile) <= 1) return false; /* Check that all tiles in area and surrounding are clear * this determines that there are no obstructing items */ cur_tile = tile + TileDiffXY(-1, -1); size_x = max_x + 4; size_y = max_y + 4; /* Check if we don't leave the map */ if (TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false; /* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry. * Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */ CompanyID old_company = _current_company; _current_company = OWNER_TOWN; BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) { curh = TileHeight(tile_walk); if (curh != h) { /* This tile needs terraforming. Check if we can do that without * damaging the surroundings too much. */ if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) { _current_company = old_company; return false; } /* This is not 100% correct check, but the best we can do without modifying the map. * What is missing, is if the difference in height is more than 1.. */ if (CmdFailed(DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) { _current_company = old_company; return false; } } } END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) if (flags & DC_EXEC) { /* Terraform the land under the industry */ BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) { curh = TileHeight(tile_walk); while (curh != h) { /* We give the terraforming for free here, because we can't calculate * exact cost in the test-round, and as we all know, that will cause * a nice assert if they don't match ;) */ DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND); curh += (curh > h) ? -1 : 1; } } END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) } _current_company = old_company; return true; } static bool CheckIfFarEnoughFromIndustry(TileIndex tile, int type) { const IndustrySpec *indspec = GetIndustrySpec(type); const Industry *i; if (_settings_game.economy.same_industry_close && indspec->IsRawIndustry()) /* Allow primary industries to be placed close to any other industry */ return true; FOR_ALL_INDUSTRIES(i) { /* Within 14 tiles from another industry is considered close */ bool in_low_distance = DistanceMax(tile, i->xy) <= 14; /* check if an industry that accepts the same goods is nearby */ if (in_low_distance && !indspec->IsRawIndustry() && // not a primary industry? indspec->accepts_cargo[0] == i->accepts_cargo[0] && ( /* at least one of those options must be true */ _game_mode != GM_EDITOR || // editor must not be stopped !_settings_game.economy.same_industry_close || !_settings_game.economy.multiple_industry_per_town)) { _error_message = STR_INDUSTRY_TOO_CLOSE; return false; } /* check if there are any conflicting industry types around */ if ((i->type == indspec->conflicting[0] || i->type == indspec->conflicting[1] || i->type == indspec->conflicting[2]) && in_low_distance) { _error_message = STR_INDUSTRY_TOO_CLOSE; return false; } } return true; } /** Production level maximum, minimum and default values. * It is not a value been really used in order to change, but rather an indicator * of how the industry is behaving. */ enum ProductionLevels { PRODLEVEL_CLOSURE = 0x00, ///< signal set to actually close the industry PRODLEVEL_MINIMUM = 0x04, ///< below this level, the industry is set to be closing PRODLEVEL_DEFAULT = 0x10, ///< default level set when the industry is created PRODLEVEL_MAXIMUM = 0x80, ///< the industry is running at full speed }; static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, byte layout, const Town *t, Owner owner, Owner founder) { const IndustrySpec *indspec = GetIndustrySpec(type); uint32 r; uint j; i->xy = tile; i->width = i->height = 0; i->type = type; IncIndustryTypeCount(type); i->produced_cargo[0] = indspec->produced_cargo[0]; i->produced_cargo[1] = indspec->produced_cargo[1]; i->accepts_cargo[0] = indspec->accepts_cargo[0]; i->accepts_cargo[1] = indspec->accepts_cargo[1]; i->accepts_cargo[2] = indspec->accepts_cargo[2]; i->production_rate[0] = indspec->production_rate[0]; i->production_rate[1] = indspec->production_rate[1]; /* don't use smooth economy for industries using production related callbacks */ if (_settings_game.economy.smooth_economy && !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks !(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE)) // production change callbacks ) { i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255); i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255); } i->town = t; i->owner = owner; r = Random(); i->random_colour = GB(r, 0, 4); i->counter = GB(r, 4, 12); i->random = GB(r, 16, 16); i->produced_cargo_waiting[0] = 0; i->produced_cargo_waiting[1] = 0; i->incoming_cargo_waiting[0] = 0; i->incoming_cargo_waiting[1] = 0; i->incoming_cargo_waiting[2] = 0; i->this_month_production[0] = 0; i->this_month_production[1] = 0; i->this_month_transported[0] = 0; i->this_month_transported[1] = 0; i->last_month_pct_transported[0] = 0; i->last_month_pct_transported[1] = 0; i->last_month_transported[0] = 0; i->last_month_transported[1] = 0; i->was_cargo_delivered = false; i->last_prod_year = _cur_year; i->last_month_production[0] = i->production_rate[0] * 8; i->last_month_production[1] = i->production_rate[1] * 8; i->founder = founder; if (HasBit(indspec->callback_flags, CBM_IND_DECIDE_COLOUR)) { uint16 res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE); if (res != CALLBACK_FAILED) i->random_colour = GB(res, 0, 4); } if (HasBit(indspec->callback_flags, CBM_IND_INPUT_CARGO_TYPES)) { for (j = 0; j < lengthof(i->accepts_cargo); j++) i->accepts_cargo[j] = CT_INVALID; for (j = 0; j < lengthof(i->accepts_cargo); j++) { uint16 res = GetIndustryCallback(CBID_INDUSTRY_INPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE); if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break; i->accepts_cargo[j] = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile); } } if (HasBit(indspec->callback_flags, CBM_IND_OUTPUT_CARGO_TYPES)) { for (j = 0; j < lengthof(i->produced_cargo); j++) i->produced_cargo[j] = CT_INVALID; for (j = 0; j < lengthof(i->produced_cargo); j++) { uint16 res = GetIndustryCallback(CBID_INDUSTRY_OUTPUT_CARGO_TYPES, j, 0, i, type, INVALID_TILE); if (res == CALLBACK_FAILED || GB(res, 0, 8) == CT_INVALID) break; i->produced_cargo[j] = GetCargoTranslation(GB(res, 0, 8), indspec->grf_prop.grffile); } } i->construction_date = _date; i->construction_type = (_game_mode == GM_EDITOR) ? ICT_SCENARIO_EDITOR : (_generating_world ? ICT_MAP_GENERATION : ICT_NORMAL_GAMEPLAY); /* Adding 1 here makes it conform to specs of var44 of varaction2 for industries * 0 = created prior of newindustries * else, chosen layout + 1 */ i->selected_layout = layout + 1; if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0; i->prod_level = PRODLEVEL_DEFAULT; do { TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); if (it->gfx != GFX_WATERTILE_SPECIALCHECK) { byte size; size = it->ti.x; if (size > i->width) i->width = size; size = it->ti.y; if (size > i->height)i->height = size; WaterClass wc = (IsWaterTile(cur_tile) ? GetWaterClass(cur_tile) : WATER_CLASS_INVALID); DoCommand(cur_tile, 0, 0, DC_EXEC | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR); MakeIndustry(cur_tile, i->index, it->gfx, Random(), wc); if (_generating_world) { SetIndustryConstructionCounter(cur_tile, 3); SetIndustryConstructionStage(cur_tile, 2); } /* it->gfx is stored in the map. But the translated ID cur_gfx is the interesting one */ IndustryGfx cur_gfx = GetTranslatedIndustryTileID(it->gfx); const IndustryTileSpec *its = GetIndustryTileSpec(cur_gfx); if (its->animation_info != 0xFFFF) AddAnimatedTile(cur_tile); } } while ((++it)->ti.x != -0x80); i->width++; i->height++; if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) { for (j = 0; j != 50; j++) PlantRandomFarmField(i); } InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0); } /** Helper function for Build/Fund an industry * @param tile tile where industry is built * @param type of industry to build * @param flags of operations to conduct * @param indspec pointer to industry specifications * @param itspec_index the index of the itsepc to build/fund * @param seed random seed (possibly) used by industries * @param founder Founder of the industry * @return the pointer of the newly created industry, or NULL if it failed */ static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, uint itspec_index, uint32 seed, Owner founder) { const IndustryTileTable *it = indspec->table[itspec_index]; bool custom_shape_check = false; if (!CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, &custom_shape_check)) return NULL; if (HasBit(GetIndustrySpec(type)->callback_flags, CBM_IND_LOCATION)) { if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index, seed)) return NULL; } else { if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL; } if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DC_NONE, it, type)) return NULL; if (!CheckIfFarEnoughFromIndustry(tile, type)) return NULL; const Town *t = CheckMultipleIndustryInTown(tile, type); if (t == NULL) return NULL; if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL; if (!Industry::CanAllocateItem()) return NULL; if (flags & DC_EXEC) { Industry *i = new Industry(tile); if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type); DoCreateNewIndustry(i, tile, type, it, itspec_index, t, OWNER_NONE, founder); return i; } /* We need to return a non-NULL pointer to tell we have created an industry. * However, we haven't created a real one (no DC_EXEC), so return a fake one. */ return GetIndustry(0); } /** Build/Fund an industry * @param tile tile where industry is built * @param flags of operations to conduct * @param p1 various bitstuffed elements * - p1 = (bit 0 - 15) - industry type see build_industry.h and see industry.h * - p1 = (bit 16 - 31) - first layout to try * @param p2 seed to use for variable 8F * @return index of the newly create industry, or CMD_ERROR if it failed */ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { const IndustrySpec *indspec = GetIndustrySpec(GB(p1, 0, 16)); const Industry *ind = NULL; /* Check if the to-be built/founded industry is available for this climate. */ if (!indspec->enabled) { return CMD_ERROR; } /* If the setting for raw-material industries is not on, you cannot build raw-material industries. * Raw material industries are industries that do not accept cargo (at least for now) */ if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 0 && indspec->IsRawIndustry()) { return CMD_ERROR; } if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry()) { if (flags & DC_EXEC) { /* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */ CompanyID founder = _current_company; _current_company = OWNER_TOWN; /* Prospecting has a chance to fail, however we cannot guarantee that something can * be built on the map, so the chance gets lower when the map is fuller, but there * is nothing we can really do about that. */ if (Random() <= indspec->prospecting_chance) { for (int i = 0; i < 5000; i++) { /* We should not have more than one Random() in a function call * because parameter evaluation order is not guaranteed in the c++ standard */ tile = RandomTile(); ind = CreateNewIndustryHelper(tile, p1, flags, indspec, RandomRange(indspec->num_table), p2, founder); if (ind != NULL) { break; } } } _current_company = founder; } } else { int count = indspec->num_table; const IndustryTileTable * const *itt = indspec->table; int num = Clamp(GB(p1, 16, 16), 0, count - 1); _error_message = STR_0239_SITE_UNSUITABLE; do { if (--count < 0) return CMD_ERROR; if (--num < 0) num = indspec->num_table - 1; } while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1)); ind = CreateNewIndustryHelper(tile, p1, flags, indspec, num, p2, _current_company); if (ind == NULL) return CMD_ERROR; } if (flags & DC_EXEC && _game_mode != GM_EDITOR && ind != NULL) { SetDParam(0, indspec->name); if (indspec->new_industry_text > STR_LAST_STRINGID) { SetDParam(1, STR_TOWN); SetDParam(2, ind->town->index); } else { SetDParam(1, ind->town->index); } AddNewsItem(indspec->new_industry_text, NS_INDUSTRY_OPEN, ind->xy, 0); AI::BroadcastNewEvent(new AIEventIndustryOpen(ind->index)); } return CommandCost(EXPENSES_OTHER, indspec->GetConstructionCost()); } static Industry *CreateNewIndustry(TileIndex tile, IndustryType type) { const IndustrySpec *indspec = GetIndustrySpec(type); uint32 seed = Random(); return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, RandomRange(indspec->num_table), seed, OWNER_NONE); } enum { NB_NUMOFINDUSTRY = 11, NB_DIFFICULTY_LEVEL = 5, }; static const byte _numof_industry_table[NB_DIFFICULTY_LEVEL][NB_NUMOFINDUSTRY] = { /* difficulty settings for number of industries */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // none {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, // very low {0, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5}, // low {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, // normal {0, 2, 3, 4, 6, 7, 8, 9, 10, 10, 10}, // high }; /** This function is the one who really do the creation work * of random industries during game creation * @param type IndustryType of the desired industry * @param amount of industries that need to be built */ static void PlaceInitialIndustry(IndustryType type, int amount) { /* We need to bypass the amount given in parameter if it exceeds the maximum dimension of the * _numof_industry_table. newgrf can specify a big amount */ int num = (amount > NB_NUMOFINDUSTRY) ? amount : _numof_industry_table[_settings_game.difficulty.number_industries][amount]; const IndustrySpec *ind_spc = GetIndustrySpec(type); /* These are always placed next to the coastline, so we scale by the perimeter instead. */ num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num); if (_settings_game.difficulty.number_industries != 0) { CompanyID old_company = _current_company; _current_company = OWNER_NONE; assert(num > 0); do { uint i; IncreaseGeneratingWorldProgress(GWP_INDUSTRY); for (i = 0; i < 2000; i++) { if (CreateNewIndustry(RandomTile(), type) != NULL) break; } } while (--num); _current_company = old_company; } } /** This function will create ramdon industries during game creation. * It will scale the amount of industries by map size as well as difficulty level */ void GenerateIndustries() { uint i = 0; uint8 chance; IndustryType it; const IndustrySpec *ind_spc; /* Find the total amount of industries */ if (_settings_game.difficulty.number_industries > 0) { for (it = 0; it < NUM_INDUSTRYTYPES; it++) { ind_spc = GetIndustrySpec(it); if (!CheckIfCallBackAllowsAvailability(it, IACT_MAPGENERATION)) { ResetIndustryCreationProbility(it); } chance = ind_spc->appear_creation[_settings_game.game_creation.landscape]; if (ind_spc->enabled && chance > 0) { /* once the chance of appearance is determind, it have to be scaled by * the difficulty level. The "chance" in question is more an index into * the _numof_industry_table,in fact */ int num = (chance > NB_NUMOFINDUSTRY) ? chance : _numof_industry_table[_settings_game.difficulty.number_industries][chance]; /* These are always placed next to the coastline, so we scale by the perimeter instead. */ num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num); i += num; } } } SetGeneratingWorldProgress(GWP_INDUSTRY, i); if (_settings_game.difficulty.number_industries > 0) { for (it = 0; it < NUM_INDUSTRYTYPES; it++) { /* Once the number of industries has been determined, let's really create them. * The test for chance allows us to try create industries that are available only * for this landscape. * @todo : Do we really have to pass chance as un-scaled value, since we've already * processed that scaling above? No, don't think so. Will find a way. */ ind_spc = GetIndustrySpec(it); if (ind_spc->enabled) { chance = ind_spc->appear_creation[_settings_game.game_creation.landscape]; if (chance > 0) PlaceInitialIndustry(it, chance); } } } } static void UpdateIndustryStatistics(Industry *i) { byte pct; bool refresh = false; for (byte j = 0; j < lengthof(i->produced_cargo); j++) { if (i->produced_cargo[j] != CT_INVALID) { pct = 0; if (i->this_month_production[j] != 0) { i->last_prod_year = _cur_year; pct = min(i->this_month_transported[j] * 256 / i->this_month_production[j], 255); } i->last_month_pct_transported[j] = pct; i->last_month_production[j] = i->this_month_production[j]; i->this_month_production[j] = 0; i->last_month_transported[j] = i->this_month_transported[j]; i->this_month_transported[j] = 0; refresh = true; } } if (refresh) InvalidateWindow(WC_INDUSTRY_VIEW, i->index); } /** Simple helper that will collect data for the generation of industries */ struct ProbabilityHelper { uint16 prob; ///< probability IndustryType ind; ///< industry id correcponding }; /** * Try to create a random industry, during gameplay */ static void MaybeNewIndustry(void) { Industry *ind; // will receive the industry's creation pointer IndustryType rndtype, j; // Loop controlers const IndustrySpec *ind_spc; uint num = 0; ProbabilityHelper cumulative_probs[NUM_INDUSTRYTYPES]; // probability collector uint16 probability_max = 0; /* Generate a list of all possible industries that can be built. */ for (j = 0; j < NUM_INDUSTRYTYPES; j++) { ind_spc = GetIndustrySpec(j); byte chance = ind_spc->appear_ingame[_settings_game.game_creation.landscape]; if (!ind_spc->enabled || chance == 0) continue; /* If there is no Callback CBID_INDUSTRY_AVAILABLE or if this one did anot failed, * and if appearing chance for this landscape is above 0, this industry can be chosen */ if (CheckIfCallBackAllowsAvailability(j, IACT_RANDOMCREATION)) { probability_max += chance; /* adds the result for this industry */ cumulative_probs[num].ind = j; cumulative_probs[num++].prob = probability_max; } } /* Find a random type, with maximum being what has been evaluate above*/ rndtype = RandomRange(probability_max); for (j = 0; j < NUM_INDUSTRYTYPES; j++) { /* and choose the index of the industry that matches as close as possible this random type */ if (cumulative_probs[j].prob >= rndtype) break; } ind_spc = GetIndustrySpec(cumulative_probs[j].ind); /* Check if it is allowed */ if ((ind_spc->behaviour & INDUSTRYBEH_BEFORE_1950) && _cur_year > 1950) return; if ((ind_spc->behaviour & INDUSTRYBEH_AFTER_1960) && _cur_year < 1960) return; /* try to create 2000 times this industry */ num = 2000; for (;;) { ind = CreateNewIndustry(RandomTile(), cumulative_probs[j].ind); if (ind != NULL) break; if (--num == 0) return; } SetDParam(0, ind_spc->name); if (ind_spc->new_industry_text > STR_LAST_STRINGID) { SetDParam(1, STR_TOWN); SetDParam(2, ind->town->index); } else { SetDParam(1, ind->town->index); } AddNewsItem(ind_spc->new_industry_text, NS_INDUSTRY_OPEN, ind->xy, 0); AI::BroadcastNewEvent(new AIEventIndustryOpen(ind->index)); } /** * Protects an industry from closure if the appropriate flags and conditions are met * INDUSTRYBEH_CANCLOSE_LASTINSTANCE must be set (which, by default, it is not) and the * count of industries of this type must one (or lower) in order to be protected * against closure. * @param type IndustryType been queried * @result true if protection is on, false otherwise (except for oil wells) */ static bool CheckIndustryCloseDownProtection(IndustryType type) { const IndustrySpec *indspec = GetIndustrySpec(type); /* oil wells (or the industries with that flag set) are always allowed to closedown */ if (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD && _settings_game.game_creation.landscape == LT_TEMPERATE) return false; return (indspec->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE) == 0 && GetIndustryTypeCount(type) <= 1; } /** * Can given cargo type be accepted or produced by the industry? * @param cargo: Cargo type * @param ind: Industry * @param *c_accepts: Pointer to boolean for acceptance of cargo * @param *c_produces: Pointer to boolean for production of cargo * @return: \c *c_accepts is set when industry accepts the cargo type, * \c *c_produces is set when the industry produces the cargo type */ static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accepts, bool *c_produces) { const IndustrySpec *indspec = GetIndustrySpec(ind->type); /* Check for acceptance of cargo */ for (byte j = 0; j < lengthof(ind->accepts_cargo); j++) { if (ind->accepts_cargo[j] == CT_INVALID) continue; if (cargo == ind->accepts_cargo[j]) { if (HasBit(indspec->callback_flags, CBM_IND_REFUSE_CARGO)) { uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, 0, GetReverseCargoTranslation(cargo, indspec->grf_prop.grffile), ind, ind->type, ind->xy); if (res == 0) continue; } *c_accepts = true; break; } } /* Check for produced cargo */ for (byte j = 0; j < lengthof(ind->produced_cargo); j++) { if (ind->produced_cargo[j] == CT_INVALID) continue; if (cargo == ind->produced_cargo[j]) { *c_produces = true; break; } } } /** * Compute who can service the industry. * * Here, 'can service' means that he/she has trains and stations close enough * to the industry with the right cargo type and the right orders (ie has the * technical means). * * @param ind: Industry being investigated. * * @return: 0 if nobody can service the industry, 2 if the local company can * service the industry, and 1 otherwise (only competitors can service the * industry) */ int WhoCanServiceIndustry(Industry *ind) { /* Find all stations within reach of the industry */ StationList stations; FindStationsAroundTiles(ind->xy, ind->width, ind->height, &stations); if (stations.Length() == 0) return 0; // No stations found at all => nobody services const Vehicle *v; int result = 0; FOR_ALL_VEHICLES(v) { /* Is it worthwhile to try this vehicle? */ if (v->owner != _local_company && result != 0) continue; /* Check whether it accepts the right kind of cargo */ bool c_accepts = false; bool c_produces = false; if (v->type == VEH_TRAIN && IsFrontEngine(v)) { for (const Vehicle *u = v; u != NULL; u = u->Next()) { CanCargoServiceIndustry(u->cargo_type, ind, &c_accepts, &c_produces); } } else if (v->type == VEH_ROAD || v->type == VEH_SHIP || v->type == VEH_AIRCRAFT) { CanCargoServiceIndustry(v->cargo_type, ind, &c_accepts, &c_produces); } else { continue; } if (!c_accepts && !c_produces) continue; // Wrong cargo /* Check orders of the vehicle. * We cannot check the first of shared orders only, since the first vehicle in such a chain * may have a different cargo type. */ const Order *o; FOR_VEHICLE_ORDERS(v, o) { if (o->IsType(OT_GOTO_STATION) && !(o->GetUnloadType() & OUFB_TRANSFER)) { /* Vehicle visits a station to load or unload */ Station *st = GetStation(o->GetDestination()); if (!st->IsValid()) continue; /* Same cargo produced by industry is dropped here => not serviced by vehicle v */ if ((o->GetUnloadType() & OUFB_UNLOAD) && !c_accepts) break; if (stations.Contains(st)) { if (v->owner == _local_company) return 2; // Company services industry result = 1; // Competitor services industry } } } } return result; } /** * Report news that industry production has changed significantly * * @param ind: Industry with changed production * @param type: Cargo type that has changed * @param percent: Percentage of change (>0 means increase, <0 means decrease) */ static void ReportNewsProductionChangeIndustry(Industry *ind, CargoID type, int percent) { NewsSubtype ns; switch (WhoCanServiceIndustry(ind)) { case 0: ns = NS_INDUSTRY_NOBODY; break; case 1: ns = NS_INDUSTRY_OTHER; break; case 2: ns = NS_INDUSTRY_COMPANY; break; default: NOT_REACHED(); break; } SetDParam(2, abs(percent)); SetDParam(0, GetCargo(type)->name); SetDParam(1, ind->index); AddNewsItem( percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN, ns, ind->xy + TileDiffXY(1, 1), 0 ); } enum { PERCENT_TRANSPORTED_60 = 153, PERCENT_TRANSPORTED_80 = 204, }; /** Change industry production or do closure * @param i Industry for which changes are performed * @param monthly true if it's the monthly call, false if it's the random call */ static void ChangeIndustryProduction(Industry *i, bool monthly) { StringID str = STR_NULL; bool closeit = false; const IndustrySpec *indspec = GetIndustrySpec(i->type); bool standard = false; bool suppress_message = false; bool recalculate_multipliers = false; ///< reinitialize production_rate to match prod_level /* don't use smooth economy for industries using production related callbacks */ bool smooth_economy = _settings_game.economy.smooth_economy && !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks !(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE)); // production change callbacks byte div = 0; byte mul = 0; int8 increment = 0; bool callback_enabled = HasBit(indspec->callback_flags, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE); if (callback_enabled) { uint16 res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->xy); if (res != CALLBACK_FAILED) { // failed callback means "do nothing" suppress_message = HasBit(res, 7); /* Get the custom message if any */ if (HasBit(res, 8)) str = MapGRFStringID(indspec->grf_prop.grffile->grfid, GB(GetRegister(0x100), 0, 16)); res = GB(res, 0, 4); switch(res) { default: NOT_REACHED(); case 0x0: break; // Do nothing, but show the custom message if any case 0x1: div = 1; break; // Halve industry production. If production reaches the quarter of the default, the industry is closed instead. case 0x2: mul = 1; break; // Double industry production if it hasn't reached eight times of the original yet. case 0x3: closeit = true; break; // The industry announces imminent closure, and is physically removed from the map next month. case 0x4: standard = true; break; // Do the standard random production change as if this industry was a primary one. case 0x5: case 0x6: case 0x7: // Divide production by 4, 8, 16 case 0x8: div = res - 0x3; break; // Divide production by 32 case 0x9: case 0xA: case 0xB: // Multiply production by 4, 8, 16 case 0xC: mul = res - 0x7; break; // Multiply production by 32 case 0xD: // decrement production case 0xE: // increment production increment = res == 0x0D ? -1 : 1; break; case 0xF: // Set production to third byte of register 0x100 i->prod_level = Clamp(GB(GetRegister(0x100), 16, 8), PRODLEVEL_MINIMUM, PRODLEVEL_MAXIMUM); recalculate_multipliers = true; break; } } } else { if (monthly != smooth_economy) return; if (indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return; } if (standard || (!callback_enabled && (indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0)) { /* decrease or increase */ bool only_decrease = (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _settings_game.game_creation.landscape == LT_TEMPERATE; if (smooth_economy) { closeit = true; for (byte j = 0; j < lengthof(i->produced_cargo); j++) { if (i->produced_cargo[j] == CT_INVALID) continue; uint32 r = Random(); int old_prod, new_prod, percent; /* If over 60% is transported, mult is 1, else mult is -1. */ int mult = (i->last_month_pct_transported[j] > PERCENT_TRANSPORTED_60) ? 1 : -1; new_prod = old_prod = i->production_rate[j]; /* For industries with only_decrease flags (temperate terrain Oil Wells), * the multiplier will always be -1 so they will only decrease. */ if (only_decrease) { mult = -1; /* For normal industries, if over 60% is transported, 33% chance for decrease. * Bonus for very high station ratings (over 80%): 16% chance for decrease. */ } else if (Chance16I(1, ((i->last_month_pct_transported[j] > PERCENT_TRANSPORTED_80) ? 6 : 3), r)) { mult *= -1; } /* 4.5% chance for 3-23% (or 1 unit for very low productions) production change, * determined by mult value. If mult = 1 prod. increases, else (-1) it decreases. */ if (Chance16I(1, 22, r >> 16)) { new_prod += mult * (max(((RandomRange(50) + 10) * old_prod) >> 8, 1U)); } /* Prevent production to overflow or Oil Rig passengers to be over-"produced" */ new_prod = Clamp(new_prod, 1, 255); if (((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0) && j == 1) new_prod = Clamp(new_prod, 0, 16); /* Do not stop closing the industry when it has the lowest possible production rate */ if (new_prod == old_prod && old_prod > 1) { closeit = false; continue; } percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100); i->production_rate[j] = new_prod; /* Close the industry when it has the lowest possible production rate */ if (new_prod > 1) closeit = false; if (abs(percent) >= 10) { ReportNewsProductionChangeIndustry(i, i->produced_cargo[j], percent); } } } else { if (only_decrease || Chance16(1, 3)) { /* If more than 60% transported, 66% chance of increase, else 33% chance of increase */ if (!only_decrease && (i->last_month_pct_transported[0] > PERCENT_TRANSPORTED_60) != Chance16(1, 3)) { mul = 1; // Increase production } else { div = 1; // Decrease production } } } } if (!callback_enabled && indspec->life_type & INDUSTRYLIFE_PROCESSING) { if ( (byte)(_cur_year - i->last_prod_year) >= 5 && Chance16(1, smooth_economy ? 180 : 2)) { closeit = true; } } /* Increase if needed */ while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) { i->prod_level = min(i->prod_level * 2, PRODLEVEL_MAXIMUM); recalculate_multipliers = true; if (str == STR_NULL) str = indspec->production_up_text; } /* Decrease if needed */ while (div-- != 0 && !closeit) { if (i->prod_level == PRODLEVEL_MINIMUM) { closeit = true; } else { i->prod_level = max(i->prod_level / 2, (int)PRODLEVEL_MINIMUM); // typecast to int required to please MSVC recalculate_multipliers = true; if (str == STR_NULL) str = indspec->production_down_text; } } /* Increase or Decreasing the production level if needed */ if (increment != 0) { if (increment < 0 && i->prod_level == PRODLEVEL_MINIMUM) { closeit = true; } else { i->prod_level = ClampU(i->prod_level + increment, PRODLEVEL_MINIMUM, PRODLEVEL_MAXIMUM); recalculate_multipliers = true; } } /* Recalculate production_rate * For non-smooth economy these should always be synchronized with prod_level */ if (recalculate_multipliers) { /* Rates are rounded up, so e.g. oilrig always produces some passengers */ i->production_rate[0] = min((indspec->production_rate[0] * i->prod_level + PRODLEVEL_DEFAULT - 1) / PRODLEVEL_DEFAULT, 0xFF); i->production_rate[1] = min((indspec->production_rate[1] * i->prod_level + PRODLEVEL_DEFAULT - 1) / PRODLEVEL_DEFAULT, 0xFF); } /* Close if needed and allowed */ if (closeit && !CheckIndustryCloseDownProtection(i->type)) { i->prod_level = PRODLEVEL_CLOSURE; str = indspec->closure_text; } if (!suppress_message && str != STR_NULL) { NewsSubtype ns; /* Compute news category */ if (closeit) { ns = NS_INDUSTRY_CLOSE; AI::BroadcastNewEvent(new AIEventIndustryClose(i->index)); } else { switch (WhoCanServiceIndustry(i)) { case 0: ns = NS_INDUSTRY_NOBODY; break; case 1: ns = NS_INDUSTRY_OTHER; break; case 2: ns = NS_INDUSTRY_COMPANY; break; default: NOT_REACHED(); break; } } /* Set parameters of news string */ if (str > STR_LAST_STRINGID) { SetDParam(0, STR_TOWN); SetDParam(1, i->town->index); SetDParam(2, indspec->name); } else if (closeit) { SetDParam(0, STR_INDUSTRY_FORMAT); SetDParam(1, i->town->index); SetDParam(2, indspec->name); } else { SetDParam(0, i->index); } /* and report the news to the user */ AddNewsItem(str, ns, i->xy + TileDiffXY(1, 1), 0); } } /** Daily handler for the industry changes * Taking the original map size of 256*256, the number of random changes was always of just one unit. * But it cannot be the same on smaller or bigger maps. That number has to be scaled up or down. * For small maps, it implies that less than one change per month is required, while on bigger maps, * it would be way more. The daily loop handles those changes. */ void IndustryDailyLoop() { _economy.industry_daily_change_counter += _economy.industry_daily_increment; /* Bits 16-31 of industry_construction_counter contain the number of industries to change/create today, * the lower 16 bit are a fractional part that might accumulate over several days until it * is sufficient for an industry. */ uint16 change_loop = _economy.industry_daily_change_counter >> 16; /* Reset the active part of the counter, just keeping the "factional part" */ _economy.industry_daily_change_counter &= 0xFFFF; if (change_loop == 0) { return; // Nothing to do? get out } CompanyID old_company = _current_company; _current_company = OWNER_NONE; /* perform the required industry changes for the day */ for (uint16 j = 0; j < change_loop; j++) { /* 3% chance that we start a new industry */ if (Chance16(3, 100)) { MaybeNewIndustry(); } else { Industry *i = GetRandomIndustry(); if (i != NULL) ChangeIndustryProduction(i, false); } } _current_company = old_company; /* production-change */ InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1); } void IndustryMonthlyLoop() { Industry *i; CompanyID old_company = _current_company; _current_company = OWNER_NONE; FOR_ALL_INDUSTRIES(i) { UpdateIndustryStatistics(i); if (i->prod_level == PRODLEVEL_CLOSURE) { delete i; } else { ChangeIndustryProduction(i, true); } } _current_company = old_company; /* production-change */ InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1); } void InitializeIndustries() { _Industry_pool.CleanPool(); _Industry_pool.AddBlockToPool(); ResetIndustryCounts(); _industry_sound_tile = 0; } bool IndustrySpec::IsRawIndustry() const { /* Lumber mills are extractive/organic, but can always be built like a non-raw industry */ return (this->life_type & (INDUSTRYLIFE_EXTRACTIVE | INDUSTRYLIFE_ORGANIC)) != 0 && (this->behaviour & INDUSTRYBEH_CUT_TREES) == 0; } Money IndustrySpec::GetConstructionCost() const { return (_price.build_industry * (_settings_game.construction.raw_industry_construction == 1 && this->IsRawIndustry() ? this->raw_industry_cost_multiplier : this->cost_multiplier )) >> 8; } Money IndustrySpec::GetRemovalCost() const { return (_price.remove_house * this->removal_cost_multiplier) >> 8; } static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new) { if (AutoslopeEnabled()) { /* We imitate here TTDP's behaviour: * - Both new and old slope must not be steep. * - TileMaxZ must not be changed. * - Allow autoslope by default. * - Disallow autoslope if callback succeeds and returns non-zero. */ Slope tileh_old = GetTileSlope(tile, NULL); /* TileMaxZ must not be changed. Slopes must not be steep. */ if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) { const IndustryGfx gfx = GetIndustryGfx(tile); const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx); /* Call callback 3C 'disable autosloping for industry tiles'. */ if (HasBit(itspec->callback_flags, CBM_INDT_AUTOSLOPE)) { /* If the callback fails, allow autoslope. */ uint16 res = GetIndustryTileCallback(CBID_INDUSTRY_AUTOSLOPE, 0, 0, gfx, GetIndustryByTile(tile), tile); if ((res == 0) || (res == CALLBACK_FAILED)) return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); } else { /* allow autoslope */ return CommandCost(EXPENSES_CONSTRUCTION, _price.terraform); } } } return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); } extern const TileTypeProcs _tile_type_industry_procs = { DrawTile_Industry, // draw_tile_proc GetSlopeZ_Industry, // get_slope_z_proc ClearTile_Industry, // clear_tile_proc GetAcceptedCargo_Industry, // get_accepted_cargo_proc GetTileDesc_Industry, // get_tile_desc_proc GetTileTrackStatus_Industry, // get_tile_track_status_proc ClickTile_Industry, // click_tile_proc AnimateTile_Industry, // animate_tile_proc TileLoop_Industry, // tile_loop_proc ChangeTileOwner_Industry, // change_tile_owner_proc GetProducedCargo_Industry, // get_produced_cargo_proc NULL, // vehicle_enter_tile_proc GetFoundation_Industry, // get_foundation_proc TerraformTile_Industry, // terraform_tile_proc };
78,954
C++
.cpp
2,016
36.206349
211
0.704476
EnergeticBark/OpenTTD-3DS
34
1
4
GPL-2.0
9/20/2024, 10:44:59 PM (Europe/Amsterdam)
false
false
false
false
false
true
false
false