Commit graph

124 commits

Author SHA1 Message Date
Robert Müller 25e6eed0e8 Fix compilation with VS2022 with exception handling enabled
By moving the calling convention `APIENTRY`, which expands to `__stdcall`, inside the parenthesis.

```
Severity	Code	Description	Project	File	Line	Suppression State
Error	C2143	syntax error: missing ')' before '('	engine-shared	src\base\system.cpp	4242
Warning	C4229	anachronism used: modifiers on data are ignored	engine-shared	src\base\system.cpp	4242
Error	C2059	syntax error: ')'	engine-shared	src\base\system.cpp	4242
Error	C2059	syntax error: ')'	engine-shared	src\base\system.cpp	4242
Error	C3536	'exception_log_file_path_func': cannot be used before it is initialized	engine-shared	src\base\system.cpp	4246
Error	C2446	'==': no conversion from 'nullptr' to 'int'	engine-shared	src\base\system.cpp	4246
Error	C2064	term does not evaluate to a function taking 1 arguments	engine-shared	src\base\system.cpp	4249
```
2022-10-16 18:16:58 +02:00
bors[bot] bd3b4f2d50
Merge #5942
5942: Support unicode with ExcHndl, use upstream module offsets, handle errors r=def- a=Robyt3

Update Dr. Mingw (ExcHndl) to 0.9.8.

Use the new `ExcHndlSetLogFileNameW` function to set the exception log file name using wide characters, to support paths containing unicode.

It's not necessary to call `ExcHndlInit` explicitly after loading `exchndl.dll`, as the `DllMain` will already initialize the exception handler when the DLL is loaded. Module offsets are supported by upstream ExcHndl now, so we don't need to provide our own version that supplies the module offset to `ExcHndlInit` anymore. Upstream ExcHndl will also resolve the source code lines for addresses automatically, when the executable is build with debug information.

Handle the cases that the exception handling module cannot be loaded and that the `ExcHndlSetLogFileNameW` function cannot be found in the module.

Update `scripts/parse_drmingw.sh`:

- Parse both old and new module offsets.
- Use tabs instead of spaces consistently.
- Reset the ANSI color after printing colored messages.

Closes #5877.

Needs https://github.com/ddnet/ddnet-libs/pull/34.

Example crash logs:

- [crash_debug_old.RTP.txt](https://github.com/ddnet/ddnet/files/9768008/crash_debug_old.RTP.txt)
- [crash_debug_new.RTP.txt](https://github.com/ddnet/ddnet/files/9768011/crash_debug_new.RTP.txt)
- [crash_release_old.RTP.txt](https://github.com/ddnet/ddnet/files/9768010/crash_release_old.RTP.txt)
- [crash_release_new.RTP.txt](https://github.com/ddnet/ddnet/files/9768009/crash_release_new.RTP.txt)

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-10-12 21:44:43 +00:00
Robert Müller fb317779fc Support unicode with ExcHndl, use upstream module offsets, handle errors
Update Dr. Mingw (ExcHndl) to 0.9.8.

Use the new `ExcHndlSetLogFileNameW` function to set the exception log file name using wide characters, to support paths containing unicode.

It's not necessary to call `ExcHndlInit` explicitly after loading `exchndl.dll`, as the `DllMain` will already initialize the exception handler when the DLL is loaded.
Module offsets are supported by upstream ExcHndl now, so we don't need to provide our own version that supplies the module offset to `ExcHndlInit` anymore.
Upstream ExcHndl will also resolve the source code lines for addresses automatically, when the executable is build with debug information.

Handle the cases that the exception handling module cannot be loaded and that the `ExcHndlSetLogFileNameW` function cannot be found in the module.

Update `scripts/parse_drmingw.sh`:

- Parse both old and new module offsets.
- Use tabs instead of spaces consistently.
- Reset the ANSI color after printing colored messages.
2022-10-12 21:11:35 +02:00
Robert Müller c68841a733 Ensure Windows DDE conversations are finished in open_link
Use `ShellExecuteExW` instead of `ShellExecuteW` to pass the additional flag `SEE_MASK_NOASYNC`. This should ensure that DDE (Dynamic data exchange) conversations are finished before the function returns, as it would otherwise be necessary to manually pump messages on the calling thread. DDE conversations may be initiated when shell extensions are loaded via `ShellExecute`. Failing to answer the DDE messages will block the calling UI thread and may cause a dead-lock.

The flag `SEE_MASK_FLAG_NO_UI` is used to prevent native error message popups when the link/file cannot be opened.

Additionally, the `ShellExecute` verb is changed from `"open"` to `NULL`, which will cause the default shell handler to be used instead, as the `"open"` verb may not be available for all targets. Though for most targets it will be the default verb anyway.

References:

- https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew
- https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shellexecuteinfow
- https://devblogs.microsoft.com/oldnewthing/20070430-00/?p=27063
- https://learn.microsoft.com/en-us/windows/win32/dataxchg/about-dynamic-data-exchange

Yet another attempt at solving #5744.
2022-10-12 17:18:57 +02:00
Robert Müller 4bb549b68e Initialize the Windows COM library on all threads
Use threading model `COINIT_APARTMENTTHREADED` on threads that own a window (the main client thread) and `COINIT_MULTITHREADED` on all other threads.

Add assertions to ensure that the COM library is initialized successfully and only once per thread.

References:

- https://learn.microsoft.com/en-us/windows/win32/learnwin32/initializing-the-com-library
- https://learn.microsoft.com/en-us/windows/win32/com/single-threaded-apartments
- https://learn.microsoft.com/en-us/windows/win32/com/multithreaded-apartments

Yet another attempt at solving #5744.
2022-10-12 17:18:57 +02:00
Robert Müller 1697231916 Handle non-default Windows directory in os_version_str
- Retrieve version information of `kernel32.dll` without providing a fixed path to the Windows directory, to handle the case that Windows is not installed in the default location `C:\Windows`. This works because `GetFileVersionInfoSizeW` and `GetFileVersionInfoW` use the search sequence defined by `LoadLibrary`, so they will find the DLL without the path explicitly being specified. The version is retrieved from `kernel32.dll` instead of `user32.dll`, as the former is more commonly used for this purpose.
- Use the unicode (wide character) functions consistently instead of the ANSI functions.
- Use the correct format specifier `%hu` for `unsigned short` (i.e. `WORD` in the Windows API).

References:

- https://learn.microsoft.com/en-us/windows/win32/api/winver/nf-winver-getfileversioninfosizew
- https://learn.microsoft.com/en-us/windows/win32/api/winver/nf-winver-getfileversioninfow
- https://stackoverflow.com/a/44672263/1708371
2022-10-03 13:17:26 +02:00
Robert Müller c924f6bb25 Use str_isspace in str_skip_(to_)whitespace(s), add tests
Update the `str_skip_to_whitespace(_const)` functions according to their documentation, which already stated that `\r` was also considered as whitespace.
2022-09-30 14:54:33 +02:00
Robert Müller 9472db419b Fix str_hex and add tests
- Properly null-terminate the destination buffer when the data size is zero.
- Fix early loop exit when destination buffer is too small for all data.
2022-09-30 14:54:33 +02:00
Robert Müller 02a7913121 Sort filenames case insensitive with str_comp_filenames, add tests
This changes `str_comp_filenames` so it sorts filenames case insensitive while also comparing digits characters as numbers.

This makes filename sorting consistent with the behavior in Windows Explorer.
2022-09-30 14:48:52 +02:00
Robert Müller ce145cfa4e Improve str_trim_words and add tests
- Change argument and return value to `const char *`, as the string is not modified by this function.
- Use our own `str_isspace` instead of standard library `isspace`.
- Always trim leading whitespace to correctly handle inputs with leading whitespace.
2022-09-30 12:29:32 +02:00
Robert Müller e98728f8f0 Extend str_isspace to consider \r as whitespace, add documentation
This allows the function to be reused in more places where `\r` is also considered as whitespace.
2022-09-30 12:13:23 +02:00
Robert Müller 61f763ff2c Use GetCurrentDirectoryW instead of _wgetcwd
For more consistent usage of the Windows API. `_wgetcwd` seems to be a wrapper around `GetCurrentDirectoryW` anyway, at least in the [Wine API](https://source.winehq.org/ident?_i=_wgetcwd).

Pass the correct size of the wide char buffer instead of passing the size of the output parameter buffer.

Remove a nullptr check. The argument should never be null and we don't check for null arguments anywhere else.
2022-09-24 17:09:31 +02:00
Robert Müller 2ba67c2306 Use SetCurrentDirectoryW instead of _wchdir
For more consistent usage of the Windows API. `_wchdir` seems to be a wrapper around `SetCurrentDirectoryW` anyway, at least in the [Wine API](https://source.winehq.org/ident?_i=_wchdir).
2022-09-24 17:09:31 +02:00
Robert Müller 8fb79242bf Use CreateDirectoryW + GetLastError instead of _wmkdir + errno
For more consistent usage of the Windows API. `_wmkdir` seems to be a wrapper around `CreateDirectoryW` anyway, at least in the [Wine API](https://source.winehq.org/ident?_i=_wmkdir).
2022-09-24 17:09:31 +02:00
heinrich5991 47d06bd0ca Fix receiving IPv6 packets after IPv4 ones on Linux
Previously, the socket addresses were truncated as the `msg_namelen`
field is both input **and** output: After receiving an IPv4 packet, the
socket address field would be too short for an IPv6 address.
2022-09-20 01:06:56 +02:00
heinrich5991 911835f940 Add str_has_cc to check for control characters in strings 2022-09-11 23:39:16 +02:00
Robert Müller 9a76ebdcb6 Save and restore FPU control word when calling ShellExecute
ShellExecute may load additional DLLs in the current context, which might change the FPU control word.

Another potential fix for #5744.

Sources:
- https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6457572
- https://web.archive.org/web/20070730055602/http://tolstoy.newcastle.edu.au/R/devel/06/02/4262.html
- http://www.delphigroups.info/2/d3/420953-2.html (only available in Google Cache for me)
- f4d80957e8/src/windows/native/sun/windows/awt_Desktop.cpp (L46-L49)
2022-09-05 22:18:39 +02:00
def 91bc21c489 No need for lengthy semaphore names on macOS, pointer address is enough
Also check on init failure and at least log, same as on UNIX
2022-08-30 10:09:35 +02:00
Robert Müller 713b6584f0 Add str_countchr to count occurrences of a char in a string 2022-08-23 10:08:46 +02:00
bors[bot] f355a3467f
Merge #5760
5760: Fix variable shadow warnings with MinGW r=def- a=Robyt3

```
ddnet/src/base/system.cpp: In function 'int byteval(const char*, unsigned char*)':
ddnet/src/base/system.cpp:3044:32: warning: declaration of 'byte' shadows a global declaration [-Wshadow]
 3044 | static int byteval(const char *byte, unsigned char *dst)
      |                    ~~~~~~~~~~~~^~~~
In file included from msys64/mingw64/include/objbase.h:8,
                 from ddnet/src/base/system.cpp:68:
msys64/mingw64/include/rpcndr.h:63:25: note: shadowed declaration is here
   63 |   typedef unsigned char byte;
      |                         ^~~~
ddnet/src/base/system.cpp: In function 'unsigned char str_byte_next(const char**)':
ddnet/src/base/system.cpp:3557:23: warning: declaration of 'byte' shadows a global declaration [-Wshadow]
 3557 |         unsigned char byte = **ptr;
      |                       ^~~~
msys64/mingw64/include/rpcndr.h:63:25: note: shadowed declaration is here
   63 |   typedef unsigned char byte;
      |                         ^~~~
ddnet/src/base/system.cpp: In function 'int str_utf8_decode(const char**)':
ddnet/src/base/system.cpp:3577:31: warning: declaration of 'byte' shadows a global declaration [-Wshadow]
 3577 |                 unsigned char byte = str_byte_next(ptr);
      |                               ^~~~
msys64/mingw64/include/rpcndr.h:63:25: note: shadowed declaration is here
   63 |   typedef unsigned char byte;
      |                         ^~~~
```

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-08-21 09:08:57 +00:00
Robert Müller 64042d29df Fix variable shadow warnings with MinGW
```
ddnet/src/base/system.cpp: In function 'int byteval(const char*, unsigned char*)':
ddnet/src/base/system.cpp:3044:32: warning: declaration of 'byte' shadows a global declaration [-Wshadow]
 3044 | static int byteval(const char *byte, unsigned char *dst)
      |                    ~~~~~~~~~~~~^~~~
In file included from msys64/mingw64/include/objbase.h:8,
                 from ddnet/src/base/system.cpp:68:
msys64/mingw64/include/rpcndr.h:63:25: note: shadowed declaration is here
   63 |   typedef unsigned char byte;
      |                         ^~~~
ddnet/src/base/system.cpp: In function 'unsigned char str_byte_next(const char**)':
ddnet/src/base/system.cpp:3557:23: warning: declaration of 'byte' shadows a global declaration [-Wshadow]
 3557 |         unsigned char byte = **ptr;
      |                       ^~~~
msys64/mingw64/include/rpcndr.h:63:25: note: shadowed declaration is here
   63 |   typedef unsigned char byte;
      |                         ^~~~
ddnet/src/base/system.cpp: In function 'int str_utf8_decode(const char**)':
ddnet/src/base/system.cpp:3577:31: warning: declaration of 'byte' shadows a global declaration [-Wshadow]
 3577 |                 unsigned char byte = str_byte_next(ptr);
      |                               ^~~~
msys64/mingw64/include/rpcndr.h:63:25: note: shadowed declaration is here
   63 |   typedef unsigned char byte;
      |                         ^~~~
```
2022-08-21 10:44:08 +02:00
Robert Müller 37cadc5c09 Add CWindowsComLifecycle RAII wrapper for Windows COM library 2022-08-21 10:34:37 +02:00
bors[bot] 4fc6a5b924
Merge #5754 #5757
5754: Auto refresh skins when changing related settings r=def- a=Jupeyy

motivation: downloaded skins aren't resettet, e.g. if they failed before. config change -> resets everything

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


5757: Make file link absolute, add `fs_is_relative_path` r=def- a=Robyt3

This fixes links not opening for relative paths, as links like `file://temp/skins` cannot be resolved by the shell.

Closes #5746.

## Checklist

- [X] Tested the change ingame (only on Windows)
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Jupeyy <jupjopjap@gmail.com>
Co-authored-by: Robert Müller <robytemueller@gmail.com>
2022-08-20 20:34:45 +00:00
Robert Müller 21fe945ca7 Make file link absolute, add fs_is_relative_path
This fixes links not opening for relative paths, as links like `file://temp/skins` cannot be resolved by the shell.
2022-08-20 20:56:46 +02:00
Robert Müller ec55212c52 Fix symlink handling of fs_listdir
On Windows, the check was incorrectly using logical or instead of bitwise or. Checking for the flag `FILE_ATTRIBUTE_REPARSE_POINT` is not necessary, as the `FILE_ATTRIBUTE_DIRECTORY` will correctly be set when the target of a symbolic link is a directory. This otherwise causes symbolic links to files to be incorrectly handled as directories.

On Linux, the minor performance optimization of using `entry->d_type` is reverted and `fs_is_dir` is used instead. This internally uses `stat`, which correctly returns the attributes for the symbolic link targets.
2022-08-20 15:57:43 +02:00
Patiga b580b83d31 List symlinks in list_dir
This functionality was lost in 082e26d5b
In my case I have a lot of symlinks in the maps folder (Downloads,
ddnet-maps, map_archive)
2022-08-18 12:51:22 +02:00
def c94de9b764 Further clang-tidy 14 issues (fixes #5612) 2022-07-27 09:07:47 +02:00
bors[bot] a3001f3bd1
Merge #5205
5205: Allow multiple addresses per server in the serverbrowser r=def- a=heinrich5991

Support is incomplete for `leak_ip_address_to_all_servers` (will only
ping the first address of each server) and for the `leak_ip` setting
(which will also only ping the first address of each server).

Fixes #5158.

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: heinrich5991 <heinrich5991@gmail.com>
2022-07-10 23:31:21 +00:00
def aa788e228c Search in $PATH for server executable (fixes #5594) 2022-07-10 23:59:28 +02:00
heinrich5991 a9bf09f769 Move websocket address handling out of the client 2022-07-10 16:53:12 +02:00
heinrich5991 2e34cf4d4b Make NETADDR comparable and hashable 2022-07-10 16:39:29 +02:00
Alexander Akulich 6d9284adc1 Port some code to str_copy() template 2022-07-09 19:40:58 +03:00
Chairn a9ee57aeb7 Fix unsafe defines 2022-06-27 18:51:02 +02:00
Chairn a50ddb75ff clang-format 2022-06-25 15:30:39 +02:00
Chairn 5f5b80ae57 Use [[fallthrough]] attribute rather than comment 2022-06-25 15:21:44 +02:00
Robert Müller 0813fbb537 Move android log include to correct file 2022-06-17 17:39:25 +02:00
Robert Müller 557ee84001 Organize base includes 2022-06-17 17:39:25 +02:00
Robert Müller da5ec5a0d2 Include <iterator> instead of <array> for std::size
As `std::size` nominally resides in `<iterator>`.
2022-06-17 17:39:24 +02:00
Robert Müller c7fb013607 Add io_read_all, io_read_all_str and mem_has_null:
- `io_read_all` reads all bytes from a file handle into a new buffer. It should only need one allocation per file in cases where the actual file size matches the expected file size. Otherwise it falls back to doubling the buffer size if the actual file size is larger than expected to avoid TOCTOU problems.
- `io_read_all_str` reads all bytes from a file handle into a new buffer and also ensures that the buffer is null-terminated and contains no other null-characters.
- `mem_has_null` is a utility used by `io_read_all_str` to ensure that no null-characters exist in the bytes read from the file.
2022-06-16 10:19:36 +02:00
heinrich5991 b3a3604c36 Remove namespace tw
It didn't have a clear role, it just acted as a distinguisher between
two functions with the same name.

Rename `tw::time_get` to `time_get_nanoseconds` and delete the old
`time_get_nanoseconds`. Move `CCmdlineFix` and the typed
`net_socket_read_wait` function to the global namespace.
2022-06-13 18:07:29 +02:00
Robert Müller 3dd2df285a Use MultiByteToWideChar instead of str_utf16le_encode 2022-06-05 20:51:56 +02:00
Dennis Felsing 51909c19ab Add CLockScope
Remove unused lock and scope in threading.h

Not sure if this is preferred

We could also try switching to std::mutex
2022-06-03 12:21:23 +02:00
Robert Müller 0af146eb3b Remove unused includes from base 2022-05-29 19:49:38 +02:00
def d6c1c7790c Handle failed socket creation (fixes #5267)
by returning nullpointer, as the calling functions expect

Broken in 471bb441a1
2022-05-29 00:43:07 +02:00
Jupeyy 3c597aff95 Switch to nanoseconds 2022-05-18 18:05:41 +02:00
heinrich5991 52d0dc8b5b Add functions to encode/decode base64 2022-05-13 09:00:48 +02:00
heinrich5991 fa4bcd5ec0 Unify logging infrastructure between IConsole and dbg_msg
This makes the "black console window" less important on Windows (or
anywhere else, for that matter), lets you see logs from other threads in
the f1 console, and removes the distinction between `IConsole::Print`
and `dbg_msg`.
2022-04-29 15:21:26 +02:00
Dennis Felsing 50e9e4c8c4 Use XDG_DATA_HOME 2022-04-25 09:50:46 +02:00
Dennis Felsing 843acf6a5a Use std::size instead of sizeof(a) / sizeof(a[0]) 2022-03-30 18:55:04 +02:00
Chairn d4aac67929 Fixed some useless double promotion 2022-03-23 18:22:08 +01:00