Skip to content

Attempted modernizing of SC-Docker networking and debugging#93

Open
KarlIsWright wants to merge 9 commits intoGames-and-Simulations:masterfrom
KarlIsWright:master
Open

Attempted modernizing of SC-Docker networking and debugging#93
KarlIsWright wants to merge 9 commits intoGames-and-Simulations:masterfrom
KarlIsWright:master

Conversation

@KarlIsWright
Copy link

This PR improves the StarCraft Docker environment with several key enhancements:

Networking Changes

  • Update Docker networking to use sc_net bridge network with isolation disabled
  • Add privileged the --cap-add=NET_RAW --cap-add=NET_ADMIN & --privileged flags to containers to help with network broadcast multicast issue.

Debugging Features

  • Add comprehensive debug mode with strace and tcpdump monitoring
  • Add --debug flag that uses special debug container and implies --log_level DEBUG & --log_verbose
  • Add debug container with X11 desktop and debugging tools
  • Add hook scripts for runtime configuration and debugging

Wine Environment Modernization

  • Modernize Wine base from Ubuntu 18.04/Wine 2.x to Ubuntu 22.04/Wine 6.x
  • Fix headless mode display issues with proper Xvfb setup

BWAPI Enhancements

  • Add configurable BWAPI settings via environment variables
  • Took remaining step to add support for BWAPI 4.4.0
  • Add new --manual flag which disables auto_menu in the 'human' container only

General Improvements

  • Improve error handling and logging throughout
  • Container was crashing if replay was already present, changed to handle gracefully.
  • Add comprehensive documentation and scripts

Remaining Issues

  • Containers running in rootless podman can see a game hosted by another container, but cannot join it.
    This is because default podmad rootless containers do not support broadcast/multicast

These changes bring update packages, and significant debugging improvements.

KarlIsWright and others added 9 commits August 21, 2025 00:58
- Update Docker networking to use sc_net bridge network with isolation disabled
- Add comprehensive debug mode with strace and tcpdump monitoring
- Add privileged networking capabilities for better LAN discovery
- Modernize Wine base from Ubuntu 18.04/Wine 2.x to Ubuntu 22.04/Wine 6.x
- Add configurable BWAPI settings via environment variables
- Add debug container with X11 desktop and debugging tools
- Using --debug flag uses special debug container and implies --log_level DEBUG & --log_verbose
- Fix headless mode display issues with proper Xvfb setup
- Add hook scripts for runtime configuration and debugging
- Improve error handling and logging throughout
Summary\n\nThis commit addresses stability and LAN connectivity issues observed when running StarCraft in containers (especially under rootless Podman).\n\nKey changes\n\n- Xvfb auth removal:\n  - Remove "-auth ~/.Xauthority" from all Xvfb invocations to avoid referencing a non-existent .Xauthority file that prevented the virtual display from starting reliably.\n  - Applied to docker/scripts/play_common.sh and the debug image startup script.\n\n- Wine/winetricks networking stack:\n  - Install DirectPlay and related networking components (wininet, winhttp, urlmon) into the Wine prefix using winetricks.\n  - Run winetricks under xvfb-run during build to avoid DISPLAY issues.\n  - Add cabextract as a winetricks dependency.\n\n- Debug image hardening:\n  - Add cabextract to dbg image.\n  - Execute optional patch scripts conditionally (tolerate forks without these scripts).\n  - Ensure winetricks networking components are preinstalled in the dbg image as well.\n\n- Runtime/container options:\n  - Grant NET_BIND_SERVICE in addition to NET_RAW and NET_ADMIN.\n  - Restrict "privileged" to debug mode only (kept with seccomp=unconfined for tooling).\n\n- Misc:\n  - Avoid running the hello-world container as part of ensure_docker_can_run() to reduce unnecessary side effects.\n\nFiles changed\n\n- docker/dockerfiles/wine.dockerfile\n  - Add cabextract.\n  - Install wine32 + winetricks and preinstall DirectPlay/wininet/winhttp/urlmon (via xvfb-run).\n\n- docker/dockerfiles/dbg.dockerfile\n  - Add cabextract.\n  - Make patch scripts optional and robust if missing.\n  - Preinstall DirectPlay & other networking libs via winetricks (xvfb-run).\n  - Remove -auth from Xvfb in the dbg startup flow.\n\n- docker/scripts/play_common.sh\n  - Remove -auth ~/.Xauthority from both headless and GUI Xvfb startups; keep logs directed to files when LOG_GUI is enabled.\n\n- scbw/docker_utils.py\n  - Add NET_BIND_SERVICE in cap_add; only use privileged in --debug.\n  - Comment out hello-world check in ensure_docker_can_run().\n\nWhy\n\n- Xvfb would fail to start in certain environments because the referenced .Xauthority did not exist inside the container; removing -auth makes the display reliable and unblocks Wine GUI apps.\n- StarCraft LAN relies on legacy DirectPlay; without installing it in the Wine prefix, LAN mode could stall or fail.\n- Rootless Podman needs extra care with capabilities and privileges. This change narrows default privileges and enables extended privileges only when explicitly debugging.\n\nNotes\n\n- Rootless NAT (pasta / slirp4netns) still limits L2 broadcast discovery; "direct IP join" via bwheadless (e.g., --lan-sendto) remains the recommended workaround under rootless setups.\n
Added cross-platform safety for chmod operations and comprehensive Podman usage guide

Changes:
- Made chmod operations cross-platform safe by wrapping in try/except blocks
- Added platform detection for debug logging
- Created comprehensive PODMAN.md documentation covering installation, network configuration, LAN multiplayer workarounds, known issues, and troubleshooting

The chmod operations now gracefully handle Windows environments where Unix permissions have no effect on mounted volumes
This commit represents significant work on debugging capabilities and
investigation into Docker networking limitations for StarCraft LAN play.

Key Changes:
============

1. Debug Container Improvements:
   - Removed automatic debugging processes from debug containers
   - Debug containers now start exactly like game containers
   - All debugging tools available via manual 'docker exec' commands
   - Added comprehensive DEBUG.md documentation

2. Container Runtime Detection:
   - Improved Docker/Podman runtime detection in docker_utils.py
   - Support for rootful/rootless detection
   - Better socket-based runtime discovery

3. UDP Networking Tools:
   - Added hook_init.sh for UDP relay initialization
   - Created separate UDP testing scripts:
     * udp_broadcast_receiver.sh - Listen for broadcasts
     * udp_broadcast_sender.sh - Send test broadcasts
     * udp_relay_manual.sh - Manual relay control
   - Fixed port conflicts in UDP relay implementation

4. Build System Fixes:
   - Fixed docker/build_images.sh for rootful Docker
   - Removed registry push attempts
   - Better build order handling

5. Documentation:
   - Added DEBUG.md with complete debugging guide
   - Added NETWORK_FINDINGS.md documenting UDP broadcast limitations
   - Extensive testing results and analysis

Known Issues:
=============
- Docker blocks UDP broadcasts between containers (all network types)
- StarCraft LAN discovery relies on UDP broadcasts to 255.255.255.255
- Current UDP relay scripts provide partial workaround only

Future Work:
============
- Investigate BWAPI source modification for unicast discovery
- Explore external relay service on host
- Consider alternative container runtimes

This commit establishes a solid foundation for debugging and documents
the fundamental limitations we've discovered with Docker networking.
This commit reorganizes all debug-specific scripts for better clarity
and maintainability.

Changes Made:
=============

1. Script Organization:
   - Moved all debug-specific scripts to docker/scripts/debug/
   - Added DEBUG_ prefix to clearly identify container scripts
   - Kept production scripts in docker/scripts/ unchanged

2. Renamed Scripts (with DEBUG_ prefix):
   - auto_debug_startup.sh → DEBUG_auto_startup.sh
   - internal_network_analysis.sh → DEBUG_network_analysis.sh
   - internal_network_debug.sh → DEBUG_network_debug.sh
   - patch_debug_gui.sh → DEBUG_patch_gui.sh
   - patch_play_common.sh → DEBUG_patch_play_common.sh
   - udp_broadcast_receiver.sh → DEBUG_udp_receiver.sh
   - udp_broadcast_sender.sh → DEBUG_udp_sender.sh
   - udp_relay_manual.sh → DEBUG_udp_relay.sh

3. Updated References:
   - docker/dockerfiles/dbg.dockerfile: Updated COPY paths
   - DEBUG.md: Updated all script references
   - NETWORK_FINDINGS.md: Updated script paths
   - UPSTREAM_ISSUE.md: Created comprehensive issue documentation

Benefits:
=========
- Clear separation between production and debug scripts
- DEBUG_ prefix makes it obvious which scripts are in containers
- Easier to maintain and understand the codebase
- No functional changes, purely organizational

Testing Scripts:
================
The debug/test_*.sh scripts remain for host-side testing and are
not copied into containers. These help validate networking setups
before deployment.

Documentation:
==============
Added UPSTREAM_ISSUE.md with detailed analysis of the UDP broadcast
limitation in Docker, ready to submit to the upstream repository.

This reorganization maintains backward compatibility while providing
a cleaner structure for future development.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant