The Problem
Some friends of mine play a game which involves a maximum of 4 players. I am trying to write a program which will allow a 5th person to monitor what is going on in the game without actually being in the game.
Background
The multiplayer portion of the game functions as such:
One player is designated as the "host". All other players connect to the host by entering the hosts' ip address. The host's machine is responsible for controlling the game's AI. When an event occurs in game, the host copy of the game sends the event to each of the other players' game (Clients). If a client player performs an action, their game sends the action to the host, who in turn sends it to the rest of the players so that an action by any player is visible to all of the others. The host and clients all utilize a single TCP port predefined in the game's configuration file (ex: port 58282). The game is a real-time strategy game (not turn-based).
Constraints
1. The mechanics of the game are not changeable. It is pre-compiled and there is no way to change the multiplayer mechanics.
2. The game uses TCP to communicate between the server and clients
The Question
Is there a way to have a separate program, which is running on either the host or client computer listen to the game's port (while the game is going on)? I am aware that TCP only allows one socket per port per ip address, so having both the game and a seperate program listen to the same port at the same time is problematic. Assuming I launch the external app before the game and have the app listen to the game's port, is there a way for the app to hear the host over the game port, take/copy that information, and then forward it to the game? (Sort of like a local man-in-the-middle)
The Ultimate Question
Is this possible given the constraints? Am I going about it in the best way?
I'll answer the second question first. You're not going the right way. The right way would be implementing some functionality in the server to allow a separate "client" to connect on another port to collect statistics periodically.
is there a way for the app to hear the host over the game port, take/copy that information, and then forward it to the game?
You don't need to do a mitm. You can do a simple packet capture, with something as ubiquitous as tcpdump
or wireshark
. For example, to capture everything on that TCP port:
tcpdump -n -w capture.pcap tcp port 58282
The other applications will never know you captured the data.