HOSTING INTERFACE
NOTE: This project has been repurposed as the WC2 Plugin Framework (BELOW)The hosting / port forwarding / firewall hole punching thing has been an issue since BNE came out.
I started on a fix for this last year, however my current work commitments mean that I am unlikely to find the time to finish this in the forseeable future.
I have completed what is probably the trickiest part of the project which is to provide an interface between the appropriate parts of the wc2 process and an external program, so I have decided to release this in the hope that someone else can put the time into developing and testing the rest of it.
---------------------------------------------------
So how does this work?If you copy the included PE files into an existing BNE installation you should find that when you join a game you will get a message on the screen saying "JOINING" then the game name, and likewise when you create a game you will get a message saying "HOSTING" then the game name.
If you look at the host.dll source code you will see where these messages are being generated.
The host.dll module is required to export 3 functions called "w2p_init", "create_game" and "join_game".
> w2p_init has no arguments and is called when the exe is first started. Any initialization code should go here.
> create_game will be passed a pointer to the game name and called when the player creates a game.
> join_game will be passed a pointer to the game name and called when the player joins a game.
----------------------------------------
So what needs to be done with this to fix the hosting problem?There's a bit of work to do yet, but its all bread & butter networking stuff so I'm hoping there are people in the community that can do the job....
You will need to make a custom server, and your own "host.dll" that exports those 3 functions. The example source is in C++, however any language capable of building a normal windows dll can be used.
w2p_init() will just have whatever initialization code is required to support the rest of the project. Possibly a TCP connection to the hosting server could be started here, but personally I think this would be more reliable being done on a game-by-game basis.
join_game() should be fairly simple, it just needs to send a message (probably over TCP) to the server saying "im trying to join this game" with the player's name, the game name, and the client's game port, the terminate the connection. Probably the server should be able to find the ip address from the incoming message, or possibly the client will have to obtain its own external address and supply it as part of the message.
create_game() when hosting, the client will need to negotiate a TCP connection with the server and supply the name of the game it is hosting, then start a thread that listens to that connection for messages from the server. It should get a message from the server over the TCP connection when a player is trying to join with the IP address and game port of the joining client. When this message is received it will need to ping the joining cllient with appropriate UDP packets to facillitate the hole-punching. Finally it will need to notify the server when the game is starting then terminate the listening thread.
The Server:The server will need to listen for and accept incoming TCP connection from clients, and maintain a list of the active hosting connections.
When a client notifies that it is hosting a game, the game name should be stored in the list.
When a hosting client notifies that the game has started, terminate the connection and remove the game from the list.
When a client notifies that it is joining a game, look up the game name in the list, then notify the hosting client of the joining clients IP address and game port.
Joining clients are not required to be stored in the list for basic functionality, however it might be a god idea to store the info for a short amount of time to protect against faulty clients or DDOS etc.
--------------------------
There will no doubt be lots of lots of dev and testing required, but I think it is quite achievable. I am very happy to offer whatever technical support I can, but I simply don't have the time right now to develop the whole thing on my own.
one, two, three ..... GO!