46 Commits

Author SHA1 Message Date
Dylan K. Taylor
9ef835c82d
Merge remote-tracking branch 'origin/legacy/pm4' into stable 2023-07-21 11:07:32 +01:00
Dylan K. Taylor
9b43ddecbd
Drop usages of Process:kill() with subprocesses parameter
we don't need this any more with console reader improvements, and this was not working correctly anyway.

closes #5234
2023-07-20 17:10:39 +01:00
Dylan K. Taylor
e0630fbb25
pmmpthread support 2023-05-20 01:29:26 +01:00
Dylan K. Taylor
222415859a
Require pthreads ^5.1
This version of pthreads has a substantially improved API, improved
performance, improved memory usage, and much less magical and broken
behaviour.
2023-01-23 20:02:33 +00:00
Dylan K. Taylor
7bcc663b60
Migrate core code to using symfony/filesystem
webmozart/path-util is retained for plugin compatibility, but is dropped in 5.0
2022-10-14 21:51:29 +01:00
Dylan K. Taylor
f88ae93897
BC break: Replaced webmozart/path-util with symfony/filesystem, closes #5332 2022-10-13 16:43:36 +01:00
Dylan K. Taylor
4b41b2f9ae
Merge remote-tracking branch 'origin/next-minor' into next-major 2022-09-28 16:15:35 +01:00
Dylan T
b87e4d8bd3
Introduce and use TextFormat::addBase() (#5268)
This function adds "base" format to a string. The given formats are inserted directly after any RESET code in the sequence.

An example of where this is needed is in the logger.

Without this change, the following code:
$logger->notice("I'm a " . TextFormat::RED . "special" . TextFormat::RESET . " cookie");

causes the "cookie" part of the message to show as grey, instead of the expected aqua for NOTICE level messages.

There are also many workarounds for this problem throughout the server, mostly in command outputs, being forced to use WHITE instead of RESET to avoid breaking the logger output.
2022-09-28 16:13:11 +01:00
Dylan K. Taylor
6f4ea886b0
Merge branch 'next-minor' into next-major 2022-09-28 00:39:00 +01:00
Dylan K. Taylor
cfb0cad7e0
Console commands now write to stdout directly, instead of being fed through the logger
this has a number of implications:
- Console command outputs are now (obviously) not logged. This is consistent with every other type of command sender, be it RCON, players, or anything else.
- The assumption that the console command sender must be able to see the logger output is now broken, since the command sender can receive output separately from the logs.

In the future, it might be desirable to send the console command output to stderr instead of stdout, so that stdout can be silenced while still allowing commands to be used.

closes #2543
2022-09-27 21:03:03 +01:00
Dylan K. Taylor
f80ffd8de0
Merge branch 'next-minor' into next-major 2022-09-15 13:59:21 +01:00
Dylan K. Taylor
b3f03d7ae6
Poll console on the main thread, instead of using a separate thread
There's no need to use an extra thread for this, since there's no concern of a socket getting stuck in a blocking read.

This is one less thing that can go wrong because of pthreads.
2022-09-02 00:58:49 +01:00
Dylan K. Taylor
2585160ca2
ConsoleReaderChildProcess: Commit suicide if the parent process dies and doesn't clean up
This happens if the main server process was forcibly killed, e.g. by the kill command on Linux, or taskkill/TaskManager on Windows.

Previously, the process would stick around as a zombie, which messed up terminals in some cases (e.g. git bash), though even having zombies with no side effects is bad enough.
2022-09-02 00:25:31 +01:00
Dylan K. Taylor
aa9f8781ff
Merge branch 'next-minor' into next-major 2022-06-07 19:56:26 +01:00
Dylan K. Taylor
083a35f970
Modernize property type declarations 2022-06-04 18:16:32 +01:00
Dylan K. Taylor
38d6284671
Use PHP-CS-Fixer to enforce file header presence 2022-06-04 17:34:49 +01:00
Dylan K. Taylor
d4b7f66e15
Promote some constructors 2022-05-17 22:34:58 +01:00
Dylan K. Taylor
20eb80fc9a
Modernize private property declarations in src/console 2022-05-17 20:34:55 +01:00
Dylan K. Taylor
856fd2a33b
fix PHPStan failures 2022-03-09 17:26:05 +00:00
Dylan K. Taylor
22bc3bc3f9
Replace disallowed operators in src/console/ 2022-01-20 16:49:04 +00:00
Dylan K. Taylor
8a94aa10a4
Merge branch 'stable' into next-minor 2021-12-14 00:34:54 +00:00
Dylan K. Taylor
e81bee3866
ConsoleReaderThread: disable opcache for console reader subprocess 2021-12-10 23:24:18 +00:00
Dylan K. Taylor
889d048ca3
Make use of Utils::assumeNotFalse() in a bunch of places
I've stuck to only doing this in the places where I'm sure we should never get false back. Other places I'm less sure of (and I found more bugs along the way).
2021-12-08 19:39:04 +00:00
Dylan K. Taylor
f239b077b9
Fixed PHPStan complaints 2021-11-30 00:36:38 +00:00
Dylan K. Taylor
6f8f460a6c
Partially revert "ConsoleReaderChildProcess: Commit suicide in more cases"
This reverts commit cbe0f44c4f7bc3715acbf148f981bd93111c4c8f.

This achieves the same result as the reverted commit wrt. process in the
same manner (writing a keepalive into the socket and checking if it
failed to send). However, it does _not_ allow the process to die on
reaching pipe EOF, since this can cause many spams of subprocesses when
stdin is actually not a tty (e.g. in a Docker container).
2021-11-30 00:27:52 +00:00
Dylan K. Taylor
882df94bcb
ConsoleReaderThread: fixed zombie process leak 2021-11-29 23:45:10 +00:00
Dylan K. Taylor
2bb97d8904
Be quiet CS 2021-11-22 15:40:47 +00:00
Dylan K. Taylor
d3878b2d57
fixed spam 2021-11-22 15:37:33 +00:00
Dylan K. Taylor
cbe0f44c4f
ConsoleReaderChildProcess: Commit suicide in more cases
this makes it slightly less annoying to get rid of as an orphan process, though it still won't immediately die.
2021-11-22 14:58:45 +00:00
Dylan K. Taylor
4dc13ab3da
ConsoleReaderThread: strip control characters
this fixes a bug I encountered when accidentally pressing ctrl+a+d (which inserts a chr(1) character), because it made the server unable to find the command - but still reported an error containing what looked like a valid command (character isn't printable).
2021-11-02 15:11:23 +00:00
Dylan K. Taylor
b9d9b69bbe
ConsoleReaderThread: trim the string before returning it
it will have a newline at the end that was added by the subprocess when posting it to the main process.
2021-10-26 01:07:14 +01:00
Dylan K. Taylor
32588d79c8
ConsoleReaderThread: remove useless code 2021-09-10 13:54:42 +01:00
Dylan K. Taylor
a5b85e095a
Fixed some missing function imports
these weren't getting corrected since php-cs-fixer 3.0 due to a change in the default configuration for native_function_invocation. Since the builds are randomly choosing to use php-cs-fixer 2.19 at the moment, the consistency is a problem.
2021-08-19 15:40:43 +01:00
Dylan K. Taylor
5da90b9530
Stop auto-translating strings when not asked
fixes #4371
2021-08-15 20:44:27 +01:00
Dylan K. Taylor
789a669395
Rename TranslationContainer -> Translatable 2021-08-15 16:17:46 +01:00
Dylan K. Taylor
b4c0ddd155
Use native union types for TranslationContainer|string 2021-08-10 15:17:26 +01:00
Dylan K. Taylor
de61417bb6
Simplify console subprocess require hack 2021-08-08 18:53:13 +01:00
Dylan K. Taylor
4c10dcaa53
ConsoleReaderThread: fixed UTF-8 paths getting corrupted on the way to the subprocess in some cases
I was never able to reproduce this, but it appears that Windows breaks the character encoding of command parameters (and also unicode environment variables, even though UNICODE_ENVIRONMENT should be set in php-src) when the file path contains Unicode characters (such as Cyrillic).
We workaround this problem using base64, which is an abysmally shitty hack, but not worse than using a subprocess for ConsoleReader in the first place. PHP fucking sucks, and so does Windows.
closes #4353
2021-08-08 16:19:08 +01:00
Dylan K. Taylor
50b4ec0d20
Override timeout for the subprocess also 2021-08-03 18:50:36 +01:00
Dylan K. Taylor
16965fa742
ConsoleReaderThread: override default socket timeout for accept
otherwise, people can break the console reader by setting the default timeout to zero or some other small value.
2021-08-03 18:48:18 +01:00
Dylan K. Taylor
f9863acadc
Restart console reader subprocess if it dies
this can happen for a bunch of different reasons, which are all indistinguishable. This also fixes pmmp/PcntlSignalHandler#3.
2021-07-26 15:38:38 +01:00
Dylan T
c2c9132812 ConsoleReaderThread: say what actually happened when we fail to read commands 2021-07-26 15:17:24 +01:00
Dylan T
c7bb77e24a ConsoleReaderChildProcess: die voluntarily if connection to server process is closed
this happens if the parent process is killed via SIGINT, because its stdin will be closed, interrupting a blocking read. This might also happen if the user pressed CTRL+D, so we don't die unless end of socket stream was also detected.

closes #4335
2021-07-26 15:07:47 +01:00
Dylan T
1246d1b7ef
Use a subprocess for reading lines from STDIN (#4332)
this FINALLY provides us with a way to deal with Windows without needing to forcibly terminate the entire server on shutdown.
2021-07-24 22:10:50 +01:00
Dylan K. Taylor
e14bad4ea6
Rename CommandReader and friends to ConsoleReader 2021-06-26 19:29:58 +01:00
Dylan K. Taylor
a70bd115f1
Moved console-specific stuff to its own namespace
this stuff has different functionality than everything else in the
command namespace (specifically console handling), so it doesn't belong
in here.

I know that this will probably break some plugins, but I don't care,
because plugins shouldn't have been abusing ConsoleCommandSender in the
first place.
2021-06-26 19:24:46 +01:00