Merge pull request #1285 from ludovic111/fix/friends-server-thread
🤖 Agent: merged on verify plus local proof. tools/test_friends.py passes with the host on its server thread and in the frame (code, self-hosted relay and short code, stop). Parity --changed: 22/0. Whichever of #1271 and this lands second drops #1271's server-thread greying of the Friends icon.
This commit is contained in:
@@ -52,10 +52,12 @@ impl Game<'_> {
|
||||
if self.friends.is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
if self.remote.is_some() || self.title.is_some() {
|
||||
// Single player on its server thread shares that server, as Open to
|
||||
// LAN publishes it; another server can't be shared.
|
||||
if self.title.is_some() || (self.remote.is_some() && self.integrated.is_none()) {
|
||||
return Err("open a singleplayer world first".into());
|
||||
}
|
||||
let opened_lan = self.lan.is_none();
|
||||
let opened_lan = self.lan_port().is_none();
|
||||
if opened_lan {
|
||||
// ShareToLanScreen's defaults, as the world options screen offers them.
|
||||
self.lan_open(LanSettings {
|
||||
@@ -171,14 +173,20 @@ impl Game<'_> {
|
||||
|
||||
/// What the pause menu shows.
|
||||
pub(super) fn friends_view(&self) -> FriendsView {
|
||||
let guests = self
|
||||
.lan
|
||||
.as_ref()
|
||||
.map(|h| h.hub.guests.iter().map(|g| g.name.clone()).collect())
|
||||
.unwrap_or_default();
|
||||
let guests = match &self.lan {
|
||||
Some(h) => h.hub.guests.iter().map(|g| g.name.clone()).collect(),
|
||||
// On the server thread: the other players the server lists.
|
||||
None if self.integrated.is_some() => {
|
||||
let me = self.options.player_name();
|
||||
let mut names = self.remote_online_names().unwrap_or_default();
|
||||
names.retain(|n| *n != me);
|
||||
names
|
||||
}
|
||||
None => Vec::new(),
|
||||
};
|
||||
let Some(s) = &self.friends else {
|
||||
return FriendsView {
|
||||
shown: self.remote.is_none(),
|
||||
shown: self.remote.is_none() || self.integrated.is_some(),
|
||||
..FriendsView::default()
|
||||
};
|
||||
};
|
||||
|
||||
+15
-3
@@ -15,6 +15,9 @@ is off: nothing leaves the machine.
|
||||
|
||||
python3 tools/test_friends.py --client target/fast/horizon-client --relay target/fast/horizon-relay
|
||||
|
||||
`--server-thread` runs the host's world on its integrated server's own
|
||||
thread (the window is a client of it, as Open to LAN publishes it).
|
||||
|
||||
`--role host|guest` runs one side only (two machines, e.g. over a tailnet):
|
||||
the host prints the code, the guest takes it with `--code` (`--relay-url`
|
||||
for a relay elsewhere, `--path relay` to force it). Needs a display on Linux
|
||||
@@ -86,8 +89,12 @@ class Game:
|
||||
# Extra words before and after the client (`--xvfb`, `--offscreen`).
|
||||
prefix = []
|
||||
extra = []
|
||||
# The host's world on its server thread (`--server-thread`), else in the window.
|
||||
server_thread = False
|
||||
|
||||
def __init__(self, client, resources, work, name, env):
|
||||
# Either way explicitly, whatever the game's default.
|
||||
env = dict(env, HORIZON_SERVER_THREAD='1' if Game.server_thread and name == 'host' else '0')
|
||||
self.home = work / name
|
||||
self.home.mkdir()
|
||||
self.endpoint = self.home / 'c.sock'
|
||||
@@ -155,7 +162,9 @@ def play_together(host, guest, name, round_index):
|
||||
# The host moves; the guest sees the host's player there.
|
||||
hp = host('status')['player']['position']
|
||||
target = [hp[0] + 3.0, hp[1], hp[2] + 1.0]
|
||||
host(f'tp {target[0]} {target[1]} {target[2]}')
|
||||
# The /tp command, not the control socket's local move: on the server thread the window is a
|
||||
# client, and its server has the last word on where the host stands.
|
||||
host(f'command tp @s {target[0]} {target[1]} {target[2]}')
|
||||
guest.wait('status', lambda v: any(math.dist(p, target) < 0.6 for p in v['server']['player_positions']), 20,
|
||||
'host movement on the guest')
|
||||
# A block the host places, which the guest sees and then breaks.
|
||||
@@ -163,8 +172,9 @@ def play_together(host, guest, name, round_index):
|
||||
feet = [math.floor(gp[0]), math.floor(gp[1]), math.floor(gp[2])]
|
||||
block = [feet[0] + 2, feet[1] + 1, feet[2]]
|
||||
# Clear the line of sight (the test terrain has hills), then the block at eye level.
|
||||
host(f'fill {feet[0] + 1} {feet[1]} {feet[2]} {feet[0] + 1} {feet[1] + 2} {feet[2]} minecraft:air')
|
||||
host(f'setblock {block[0]} {block[1]} {block[2]} minecraft:gold_block')
|
||||
# As commands, for the same reason as the /tp above.
|
||||
host(f'command fill {feet[0] + 1} {feet[1]} {feet[2]} {feet[0] + 1} {feet[1] + 2} {feet[2]} minecraft:air')
|
||||
host(f'command setblock {block[0]} {block[1]} {block[2]} minecraft:gold_block')
|
||||
guest.wait(f'getblock {block[0]} {block[1]} {block[2]}', lambda v: v['block'] == 'minecraft:gold_block', 20,
|
||||
'the host block on the guest')
|
||||
eye = [gp[0], gp[1] + 1.62, gp[2]]
|
||||
@@ -343,10 +353,12 @@ def main():
|
||||
parser.add_argument('--hold', type=float, default=0, help='guest: stay this many seconds before leaving')
|
||||
parser.add_argument('--baseline', action='store_true', help='first run the same checks over plain LAN')
|
||||
parser.add_argument('--offscreen', action='store_true', help='run the games without a window')
|
||||
parser.add_argument('--server-thread', action='store_true', help="the host's world on its server thread")
|
||||
parser.add_argument('--xvfb', action='store_true', help='run the games under xvfb-run (headless Linux)')
|
||||
args = parser.parse_args()
|
||||
Game.prefix = ['xvfb-run', '-a'] if args.xvfb else []
|
||||
Game.extra = ['--offscreen'] if args.offscreen else []
|
||||
Game.server_thread = args.server_thread
|
||||
args.client, args.resources = args.client.resolve(), args.resources.resolve()
|
||||
# Short: Unix socket paths are limited to about 100 bytes.
|
||||
with tempfile.TemporaryDirectory(prefix='hzf-', dir='/tmp') as directory:
|
||||
|
||||
Reference in New Issue
Block a user