Commit graph

20136 commits

Author SHA1 Message Date
ChillerDragon ffd0da09e9 Mark some character methods const 2024-05-29 08:13:16 +08:00
Dennis Felsing 1460081d8c
Merge pull request #8402 from Robyt3/Menus-Keyreader-UI-Inactive
Prevent UI elements from being hovered while key reader is active
2024-05-28 02:04:17 +00:00
Robert Müller bd5ca951a7 Prevent UI elements from being hovered while key reader is active
Since the key reader will intercept the next input, the other UI elements should not react to the hovered mouse.
2024-05-27 20:20:25 +02:00
ChillerDragon c1a5e59d9f Exclude enough checks to pass with clang tidy 19 2024-05-26 19:31:54 +08:00
ChillerDragon 59cb7ef5a9 Fix clang-analyzer-unix.StdCLibraryFunctions
```
/home/chiller/Desktop/git/ddnet/src/base/system.cpp:1989:10: error: The 1st argument to 'connect' is < 0 but should be >= 0 [clang-analyzer-unix.StdCLibraryFunctions,-warnings-as-errors]
 1989 |                 return connect(sock->ipv4sock, (struct sockaddr *)&addr, sizeof(addr));
      |                        ^
```
2024-05-26 19:31:54 +08:00
ChillerDragon 64505273a9 Remove redundant casts 2024-05-26 19:31:54 +08:00
ChillerDragon 0a505c25d7 Don't return from void methods 2024-05-26 19:31:54 +08:00
ChillerDragon c4f68f50ea Remove unnecessary object creation in emplace_front
Fixes

```
/home/chiller/Desktop/git/ddnet/src/engine/client/updater.cpp:186:27: error: unnecessary temporary object created while calling emplace_front [modernize-use-emplace,-warnings-as-errors]
  186 |         m_FileJobs.emplace_front(std::make_pair(pFile, Job));
      |                                  ^~~~~~~~~~~~~~~          ~
```
2024-05-26 19:31:54 +08:00
heinrich5991 5ad62b5732
Merge pull request #8398 from Robyt3/Base-secure_random_init-check
Ensure return value of `secure_random_init` is always checked
2024-05-26 10:21:26 +00:00
Robert Müller 583845fc60 Ensure return value of secure_random_init is always checked 2024-05-26 11:59:26 +02:00
Dennis Felsing 9bd5aacc2b
Merge pull request #8396 from Robyt3/Android-Storage-Refactoring
Improve Android storage usage, faster launch, remove permissions
2024-05-26 04:19:27 +00:00
Robert Müller 986508e091 Improve Android storage usage, faster launch, remove permissions
Split the user storage location and the data folder in the app specific external storage in the folders `data` and `user` instead of writing the user setting directly to the external storage.

Remove unnecessary storage permissions. The client only accesses files in its own external storage location, hence these permissions are not necessary for Android API 19 and higher, which is always given as we only target API 19 and higher.

Only unpack changed assets when their hash in the integrity index is different instead of unpacking all assets again, so the app starts faster after updates. Avoid unpacking the entire integrity index file unless it changed, by initially reading only the first hash directly from the asset, so the app starts faster when the data is up-to-date.

Add error handling for external storage not being accessible and other I/O errors during unpacking of assets.

Add `android_main.h` header to export the `InitAndroid` function and potentially other functions in the future. The `extern "C"` and `__attribute__((visibility("default")))` attributes seem to be unnecessary, as this function is only called directly from the native code like many other functions without these attributes.

Initialize the Android storage after the loggers, so the log message are printed properly.

Add documentation for the use of `std::exit` on Android, which is used to forcefully terminate the entire process, to ensure that static variables will be initialized correctly when the app is started again after quitting. Returning from the main function is not enough, as this only results in the native thread terminating, but the Java thread will continue. Java does not support unloading libraries once they have been loaded, so all static variables will not have their expected initial values anymore when the app is started again after quitting.

Use `fs_chdir` and `fs_makedir` instead of `chdir` and `mkdir`.
2024-05-25 21:09:42 +02:00
Dennis Felsing dd85209a8e
Merge pull request #8394 from Robyt3/Android-Building-Cleanup
Further clean up and improve the Android building scripts, lower minimum target API to 19
2024-05-24 00:47:38 +00:00
Robert Müller 1dfed5434e Lower minimum SDK to 19, remove unnecessary Gradle dependencies
SDK 19 is the lowest API level support by SDL2 because it is the lowest API level supported by the latest NDK toolchain. According to https://www.composables.com/tools/distribution-chart this should cover virtually all Android devices.

The dependencies on Kotlin and various `androidx`-Packages were entirely unnecessary and can be removed.
2024-05-23 22:09:23 +02:00
Robert Müller 63710a18a4 Preserve filenames and line numbers in ProGuard for debugging 2024-05-23 22:08:42 +02:00
Robert Müller 7de52fd46f Improve Android build script output, improve colors
Abort the Android CMake build immediately if any of the command line arguments is not specified, instead of assuming default values.

Add more log messages for different build steps to improve progress reporting and improve the existing log messages.

Improve and fix colors of log messages. Previously, some log message colors were not terminated properly, causing the output color of subsequent commands to change.

Avoid some error messages when the build script is executed for the first time, i.e. when cleanup of the previous build is not necessary because the files do not exist yet.

Make some related variable names more readable by removing the unnecessary underscore and `DEFAULT` prefixes.
2024-05-23 22:08:34 +02:00
Robert Müller 1a3b2eac10 Abort build script if CMake build failed for any architecture
Abort the build script when the CMake build fails for any of the selected architectures. Previously, the build may have continued and caused an APK without the respective library files to be built.
2024-05-23 20:48:56 +02:00
Robert Müller c8f0391c62 Remove unnecessary copy_dummy_files_rec function
Create the folder and copy the file manually instead of using a separate function for this, as the function is only used once.
2024-05-23 20:48:20 +02:00
Robert Müller d9f810691b Remove duplicate dynamic loading of game library
SDL automatically loads the libraries specified in the array returned by the `getLibraries` method, so loading it manually is unnecessary. SDL also has additional error handling to quit the app with an appropriate error message popup if the library could not be loaded, which was not handled previously.
2024-05-23 20:47:18 +02:00
Robert Müller 41738f1880 Ensure libary is copied successfully, remove unnecessary copies
Ensure that the main game library is copied successfully. Remove unnecessary copies of library files that do not exist and are unused, which were causing error messages during the build.
2024-05-23 20:46:35 +02:00
Robert Müller d9686591f0 Ensure APK build type parameter is valid
Abort build script if the build type parameter value is not valid, instead of assuming the debug build.
2024-05-23 20:45:52 +02:00
Robert Müller e981d48b24 Extract build_gradle function, fix Gradle use without arguments
Extract `build_gradle` function to reduce duplicate code for running the Gradle build. Remove the initial invocation of Gradle without a build target, which has no effect and was causing an error message during the build.
2024-05-23 20:45:42 +02:00
Robert Müller 6a453d10b4 Remove unused _RELEASE_TYPE_APK_NAME variable
This variable is always empty.
2024-05-23 20:43:53 +02:00
Robert Müller 69102880c9 Remove unused GE_NO_APK_BUILD variable
This variable is always empty and we don't need to support not building the APK file.
2024-05-23 20:43:53 +02:00
Robert Müller 930836f349 Split compile_source function for readability
Split the `compile_source` function into `compile_source_android` and `compile_source_webasm` instead of using a parameter to switch between the functionality.
2024-05-23 20:43:53 +02:00
Robert Müller 45f619722b Avoid duplicate creation of ddnet-libs directory
Avoid error messages due to `ddnet-libs` directory already existing and being created multiple times.
2024-05-23 20:43:53 +02:00
Robert Müller 60733bc033 Remove redundant check for existing directory with mkdir -p
The `mkdir -p` command is already idempotent so separately checking whether the directory exists is not necessary.
2024-05-23 20:43:30 +02:00
Robert Müller e9581b87ba Ensure specified target system for buiding libraries is valid
Abort building libraries if the specified target system is not one of the supported values.
2024-05-23 20:42:25 +02:00
Robert Müller 2844ad7239 Remove redundant OS_NAME_PATH variable
This variable was simply assigned the same value as the `OS_NAME` variable.
2024-05-23 18:06:59 +02:00
Robert Müller 0da30b7857 Remove obsolete autogen.sh usage for OpenSSL build
The OpenSSL project does not contain an `autogen.sh` file anymore, which was causing an error message when building the libraries.
2024-05-23 18:06:59 +02:00
heinrich5991 60fb40676a
Merge pull request #8310 from ChillerDragon/pr_shfmt
Use shfmt as formatter for shell scripts
2024-05-23 06:26:50 +00:00
ChillerDragon c75584406a Use shfmt as formatter for shell scripts 2024-05-23 08:05:00 +08:00
heinrich5991 1e11fffb03
Merge pull request #8390 from Robyt3/Base-chdir-getcwd-Cleanup
Minor refactoring of `fs_chdir` and `fs_getcwd` functions
2024-05-22 21:25:27 +00:00
heinrich5991 848f4a846b
Merge pull request #8334 from Robyt3/Android-Building-Fix
Fix the Android build and improve the Android building `README.md`
2024-05-22 21:19:40 +00:00
Robert Müller 68d474c81f
Merge pull request #8363 from heinrich5991/pr_ddnet_str_from_int
Optimize `str_format(…, …, "%d", …)` using templates
2024-05-22 21:01:17 +00:00
Robert Müller f04bea6b4b Minor refactoring of fs_chdir and fs_getcwd functions
Remove unnecessary `fs_is_dir` check in the `fs_chdir` function. The `SetCurrentDirectoryW` and `chdir` functions would already include such necessary checks anyway.

Assert that `GetCurrentDirectoryW` was successful instead of logging an error message. This function should only potentially fail if the current working directory was changed by another thread between the two calls, which should not happen in our code.
2024-05-22 19:22:23 +02:00
Dennis Felsing 9048bf2997
Merge pull request #7820 from gerdoe-jr/set-rescue
Add `/rescuemode` support
2024-05-22 17:22:07 +00:00
heinrich5991 df9980ee3e Optimize str_format(…, …, "%d", …) using templates
This would make the function `str_from_int` unnecessary, at least
user-facing.

Advantage: User doesn't have to care about `str_from_int`/`str_format`
distinction.

Disadvantage: We're adding some template programming to `system.h`,
potentially slowing all compilation.
2024-05-22 14:44:46 +02:00
heinrich5991 612a71f874
Merge pull request #8351 from ChillerDragon/pr_rcon_percentage
Show percentage of loaded rcon commands (closed #7769)
2024-05-22 08:39:40 +00:00
heinrich5991 7c4d3a5978
Merge pull request #8391 from hardliner66/fix_econ
Allow econ to succeed, even if ipv6 econ fails to bind to socket
2024-05-21 19:20:14 +00:00
Steve Biedermann 3af8c00fc7 allow ipv4 econ to succeed, even if ipv6 econ fails to open port 2024-05-21 20:55:30 +02:00
Robert Müller 1316ac3c70 Improve the Android building README.md 2024-05-21 17:38:48 +02:00
Robert Müller e4a7fd59f7 Determine default version name and code from version.h
Parse `GAME_RELEASE_VERSION` and `DDNET_VERSION_NUMBER` definitions from `src/game/version.h` by default, so specifying a version manually is usually not necessary.
2024-05-21 17:38:48 +02:00
Robert Müller 51e4e41805 Change tw.DDNet package name to org.ddnet.client 2024-05-21 17:38:48 +02:00
Robert Müller 664b0e98bb Upgrade Gradle and fix Android deprecation errors
Upgrade to Gradle 8.5 and Gradle Plugin 8.3.0 for compatibility with Java 21. Explicity set Java version 21 in `build.gradle`. Increment compile and target SDK version to 34 accordingly.

Remove the explicitly defined, obsolete `buildToolsVersion` property in `build.gradle`, as it is now automatically derived by Gradle.

Replace the deprecated property `android:extractNativeLibs` in `AndroidMainfest.xml` with `useLegacyPackaging` in `build.gradle`.

Replace the deprecated package definition `package="tw.DDNet"` in `AndroidMainfest.xml` with `namespace("tw.DDNet")` in `build.gradle`.

Add the required property `android:exported="true"` to the main activity in `AndroidMainfest.xml`.
2024-05-21 17:38:42 +02:00
Robert Müller cdbe1f775a Various fixes/improvements to Android building scripts
Use [cargo-ndk](https://github.com/bbqsrc/cargo-ndk) to configure cargo for building with the Android NDK. The output of `cargo ndk` is written to a subfolder for the target triplet, which cannot be changed by parameter. Therefore, the `CARGO_BUILD_DIR` is changed to this subfolder for the Android build, so the build process can find the output.

Use `$HOME` instead of `~` because cargo-ndk cannot correctly access the folder otherwise (will fail with error message indicating it could not determine the NDK version).

Add `DDNET_TEST_NO_LINK=ON` CMake argument, to fix Rust linking errors with tests.

Add additional CMake arguments to specify system name, API version and NDK location. Upgrade to Android API 34.

Use `nproc` instead of `32` threads for building.
2024-05-21 17:36:47 +02:00
Robert Müller b2c2a74db7 Remove unused shell script function arguments
Only the first two arguments of the `build_for_type` and `copy_libs` functions are used.
2024-05-21 17:36:47 +02:00
Robert Müller ceb1640320 Fix incorrect CMake target name in cmake_android.sh
The name of the main target was changed from `DDNet` to `game-client`.
2024-05-21 17:36:46 +02:00
Robert Müller 468cd85839 Add build folder parameter to cmake_android.sh
Add a parameter instead of using the fixed build folder `build_android`.
2024-05-21 17:36:46 +02:00
Robert Müller 9afe7444c1 Fix SDL3 being used in gen_libs.sh
The SDL default branch is now SDL3, so we need to check out specifically the SDL2 branch.
2024-05-21 17:36:46 +02:00