HoMM3 TCP/IP networking howto

The old Heroes games developed by New World Computing. Please specify which game you are referring to in your post.
User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

HoMM3 TCP/IP networking howto

Unread postby GreatEmerald » 22 May 2016, 22:37

Today I managed to set up a network play in vanilla HoMM3 Complete. Between three people, who were using Windows 8.1, Windows 10 and Linux. Using no external tools whatsoever (yes, no bloody GameRanger, Hamachi, VPN, etc.!), via TCP/IP. That's quite a feat, but turns out that it's pretty simple in the end, one just has to understand how the underlying technology works.

HoMM3 was made in the early days of DirectX (in 1999, DirectX 6 was the latest version), using its DirectPlay as middleware to set up network games. Since DirectX 8, DirectPlay has changed considerably, and since DirectX 9 it has been deprecated altogether. However, its support still survives to this day with varying degrees of functionality.

DirectPlay relies on a server (dplaysvr.exe) that is game-agnostic and that creates a two-way link between the host and the clients. A useful Microsoft document about it can still be found here: https://support.microsoft.com/en-us/kb/240429

This means two things in practice. First, both the host and clients have to have DirectPlay installed. On recent Windows (8.0, 8.1, 10), this is achieved by checking Legacy → DirectPlay in Windows Features, as seen here: https://windowsforum.com/threads/turn-o ... 10.205952/ (note that it is on by default already, so for the most part you don't need to do anything here). On Wine (Linux or OS X), this means running winetricks directplay.

Second, in order to have a network connection, not only does the host have to do port forwarding, but also the clients! The ports to forward are the same in both cases: Both TCP and UDP 47624 (doc says TCP is enough, but my testing shows UDP is being listened too), and both TCP and UDP 2300-2400. If this is performed correctly (the way to do it depends on your router; this is a good reference, already with the needed ports preselected: http://portforward.com/english/applicat ... efault.htm ), every machine is able to serve at least as a client (is able to see and join hosted games).

If you also want to use the machine as a host, this is a bit more complicated. Since DirectPlay is deprecated, the actual hosting parts of it have been removed from recent Windows versions, as far as I can tell. That means that you have to use either an old Windows version (perhaps in a virtual machine), or use Wine on Linux or OS X, which is fully capable of running the DirectPlay server (via the aforementioned winetricks command).

And that's it! In a nutshell: start hosting a game on one of the supported OSs via the TCP/IP option, forward ports, have client players forward their ports, and tell the host's external IP (from http://whatismyip.com or such, not the internal one that HoMM3 shows) to the clients. Easy!


For troubleshooting/reproducibility purposes, note that UPnP might influence the host/client visibility; reportedly it may be a bit broken, I tested with it disabled on both the host and clients. The host actually had only TCP 47624 and 2300 forwarded (not the whole 2300-2400 range); and in UDP it had these forwarded (most likely the ones after the first two are not needed, but I didn't want to take chances so far): 2350 47624 10062 15114 16702 2252 29474 30957 33352 36197 37317 37818 42268 46384 46747 48053 51514 55140 58930 8470

I tested (and confirmed to be working) Linux and Windows XP as hosts; and Linux, Windows XP, Windows 8.1 and Windows 10 as clients.
Hosting from Windows 8.1 or Windows 10 didn't work. Also, GameRanger doesn't even work on Linux and Windows 10 (crashes the game on the former and displays a blank game screen with an hourglass on the latter), which is why the direct solution is way nicer.

And if you want "pics or it didn't happen", I actually streamed the network game, you can see it here: https://www.twitch.tv/greatemerald/v/67948980 and https://www.twitch.tv/greatemerald/v/67969901 for a 3-way match, and https://www.twitch.tv/greatemerald/v/68000022 for a 2-way one.

Milldawg
Leprechaun
Leprechaun
Posts: 1
Joined: 08 Jan 2017

Re: HoMM3 TCP/IP networking howto

Unread postby Milldawg » 08 Jan 2017, 19:52

Thanks for this great guide, Emerald!

I have a question - it's my understanding that Heroes 3 was for Windows only, but it sounds like you're saying the game host can use OS X. How does that work?

Thanks!

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Re: HoMM3 TCP/IP networking howto

Unread postby GreatEmerald » 20 Jan 2017, 21:09

Through Wine, which is a reimplementation of Windows system libraries in free software. Wine runs on Linux, macOS, and ReactOS but not Windows itself. Wine is a Windows compatibility layer, sort of like an emulator, so you can run Windows applications in it. So while the DirectPlay libraries that the game used have been removed from Windows since Vista, it doesn't affect Wine, as it has a fully-working implementation of DirectPlay. Which makes the game work better on Wine than native Windows, ironically enough.

By the way, I've had quite a few more HoMM3 games since then, and a few HoMM4 games via TCP/IP and no external tools. One match I played a few days ago, good fun.
Last edited by GreatEmerald on 20 Jan 2017, 23:07, edited 1 time in total.

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Re: HoMM3 TCP/IP networking howto

Unread postby GreatEmerald » 23 Jul 2017, 22:45

I did some more research on how TCP/IP works. For reference, I used a packet analyser to look at the ports that are actually used. The ones that I could see were:
47624 UDP & TCP: Used for initial port negotiation. I don't think it's used for anything else at all, and the connections are super short-lived. The DirectPlay server expects a packet that contains, among other things, data in the form of the TCP port number to use followed by a bunch of zeroes followed by the string "play". In raw form, that looks like a TCP [PSH, ACK] packet with part of the content being "08 fc 00 00 00 00 00 00 00 00 00 00 00 00 70 6c 61 79". If the "play" word is not preceded by 12 pairs of zeroes and "08 fc", then you have a crippled DirectPlay implementation, see below for more info.
2300 TCP: This is the port that typically gets negotiated. Both the server and the client open one and they speak through their channel. This is used for sending room names, game version numbers, player names, map settings, chat messages, etc. and thus is basically the most important port.
2350 UDP: This port gets opened some time into the game room joining process and seems to be mostly for short server→client interactions. The client rarely uses this, only to signal intention to exit, it seems. Once the game starts, this is used for sending chat messages and some other short packets between all players.

This is when it's a 1v1 game. It is possible that more players joining will make use of ports 2301 and 2351, etc., but I still need to verify this. Both server and client need to forward ports mostly because the game does not really have a server-client model to begin with! It exists for the lobby to set map settings, but when the game starts, it is peer-to-peer: data gets sent to all players at turn end. This is how players can exit seamlessly without interrupting the flow, and every player can save and resume the game.

In case a player is not able to forward these ports: The cleanest solution that works is setting up a VPN, such as OpenVPN, on the machine that can forward ports. Routed mode works fine, no need for bridged mode. I used a TAP interface for this, but TUN might work too. Note that for games with more than two players, due to the peer-to-peer nature, if one player needs to use the VPN, all players have to use the VPN. If they don't, they will be able to join the game fine, but it will get stuck on the first turn at transferring data (perhaps unless bridged mode is used, I haven't tested that).

Note for Windows 10 users: DirectPlay seems to be deliberately crippled in Windows 10 even for clients. In the port negotiation phase, Windows 10 sends garbage instead of a port number, which leads the server to ignore it, and thus the game is not found. The solution is to install the functional DirectPlay libraries from the DirectX 9 redistributable (February 2010). Installing the redistributable is not enough, because it will not overwrite the stub libraries present in Windows 10. Instead, you need to extract the dxnt.cab file (with 7zip or the expand command) and copy the files dplaysvr.exe, dplayx.dll, dpnet.dll, dpnhpast.dll, dpnsvr.exe and dpwsockx.dll to your Windows\SysWOW64 folder (if you are running 64-bit Windows, otherwise it's system32), replacing the stub libraries there. Also note that by default Windows will not allow you to replace files in system folders. (It might be enough to copy these files to the Heroes3 folder, but it was not tested yet.) To replace system files, you have to either use a system file replacement tool, or command line tools to take ownership of the files, or boot from another OS (like Linux) to replace those files. In addition, it might be needed to pass the location of dplayx.dll, dpnet.dll and dpnhpast.dll to Windows\SysWOW64\regsvr32.exe on the command prompt in order to register those DLLs (though the DirectX installer should do that for you).

Note to Vista and later Windows users: The process above can also be used on other Windows versions to restore DirectPlay capabilities, which will allow you to host games in addition to joining them. (Tests show that dplaysvr.exe doesn't get started by default on these versions, so while it is possible to join games, it isn't possible to host them unless the procedure above is followed.)

Note on the HD mod: The HD mod puts its own dpwsockx.dll file into the Heroes3 folder, which overrides the system one. This causes hangs when trying to host. Once this file is removed or replaced with the one from the DirectX redistributable, the HD mod works fine online too.
Last edited by GreatEmerald on 31 Mar 2018, 19:41, edited 2 times in total.

pgmforever
Leprechaun
Leprechaun
Posts: 1
Joined: 21 Jan 2018

Re: HoMM3 TCP/IP networking howto

Unread postby pgmforever » 21 Jan 2018, 23:12

Sorry for reviving this old post, but it's the only one I found which seems to even remotely talk about what I have encountered.

I'm running Wine on top of XQuartz in macOS Sierra. I am able to host HoMM3 (client using Windows 8.1) games, but here it comes the catch: when using HoMM3: Complete, it runs fine. When using the WoG expansion, everything's fine up to the point I (as a host) click "BEGIN".

Then the loading screen comes up, sending map config to clients, shows "Waiting for player..." popup (on top of screen with map & home castle already shown). When the popup should disappear (because on client's side it says it's my current turn), the game freezes. I can move the cursor, no crash happens, but it's simply frozen and I need to kill the Wine process.

The fact that it freezes at the exact moment when I should be getting "WoGify options" (and that it works with the Complete version) makes me think it's something shady going on with the WoG... Has anyone else played Homm3 WOG using Tcp/ip? Could it be from something else?


TL;DR: homm3: completeworks, WOG expansion freezes on host (OS X Sierra with Wine), client Win 8.1

User avatar
Artas1984
Assassin
Assassin
Posts: 284
Joined: 06 Jan 2007
Location: Vilnius

Re: HoMM3 TCP/IP networking howto

Unread postby Artas1984 » 15 Mar 2018, 22:55

GreatEmerald wrote: Note for Windows 10 users: DirectPlay seems to be deliberately crippled in Windows 10 even for clients. In the port negotiation phase, Windows 10 sends garbage instead of a port number, which leads the server to ignore it, and thus the game is not found. The solution is to install the functional DirectPlay libraries from the DirectX 9 redistributable (February 2010). Installing the redistributable is not enough, because it will not overwrite the stub libraries present in Windows 10. Instead, you need to extract the dxnt.cab file (with 7zip or the expand command) and copy the files dplaysvr.exe, dplayx.dll, dpnet.dll, dpnhpast.dll, dpnsvr.exe and dpwsockx.dll to your Windows\SysWOW64 folder (if you are running 64-bit Windows, otherwise it's system32), replacing the stub libraries there. Also note that by default Windows will not allow you to replace files in system folders. (It might be enough to copy these files to the Heroes3 folder, but it was not tested yet.) To replace system files, you have to either use a system file replacement tool, or command line tools to take ownership of the files, or boot from another OS (like Linux) to replace those files.
Note to Vista and later Windows users: The process above can also be used on other Windows versions to restore DirectPlay capabilities, which will allow you to host games in addition to joining them. (Tests show that dplaysvr.exe doesn't get started by default on these versions, so while it is possible to join games, it isn't possible to host them unless the procedure above is followed.)

Note on the HD mod: The HD mod puts its own dpwsockx.dll file into the Heroes3 folder, which overrides the system one. This causes hangs when trying to host. Once this file is removed or replaced with the one from the DirectX redistributable, the HD mod works fine online too.
O wow, i did not expect to see such an important post!

A great post from the great emerald! How about that!

Why nobody told about this crucial info before? I had no idea Heroes 3 uses P2P instead of client/server. Moreover, i had no idea about these issues in later operating systems (is this problem only Windows 10 related?). It's not exactly crucial for me, as i play Heroes 3 on LAN with my cousin on our Windows 7 computers.

In Windows 7, i just make sure that all the necessary processes in services.msc are enabled and started if i bug into some kind of network foundation and communication error. Is it just the directplay non working in Windows 10 or are some of the some services disabled by default?

You should stick this thread Emery, this is some of the most important info i've seen about Heroes 3 in Windows 10.

PS: GE, did you change your living location?
Last edited by Artas1984 on 15 Mar 2018, 23:00, edited 5 times in total.
Heroes franchise was not about the free actions of Heroes or monsters, it was not about 3D of shiny graphics either, it was about diversity and balance, simplicity of gameplay and realistic picture, strategy in it's purest form. That's why Heroes 3 will be the greatest game of all, because only Heroes 3 has all those qualities together, no matter which one you personally like more. This statement is unquestionable, uncriticized and undeniable .

User avatar
GreatEmerald
CH Staff
CH Staff
Posts: 3330
Joined: 24 Jul 2009
Location: Netherlands

Re: HoMM3 TCP/IP networking howto

Unread postby GreatEmerald » 31 Mar 2018, 19:18

Artas1984 wrote:Why nobody told about this crucial info before? I had no idea Heroes 3 uses P2P instead of client/server. Moreover, i had no idea about these issues in later operating systems (is this problem only Windows 10 related?). It's not exactly crucial for me, as i play Heroes 3 on LAN with my cousin on our Windows 7 computers.

In Windows 7, i just make sure that all the necessary processes in services.msc are enabled and started if i bug into some kind of network foundation and communication error. Is it just the directplay non working in Windows 10 or are some of the some services disabled by default?

You should stick this thread Emery, this is some of the most important info i've seen about Heroes 3 in Windows 10.

PS: GE, did you change your living location?
Because nobody knew about it until I did a lot of testing with Wireshark :D

DirectPlay is not working properly in all Windows versions since Vista. Just that in Win10 it's completely non-functional by default. You should use the DLLs from the DirectX redistributable in any case.

Services don't matter as far as I know; the game itself spawns a dplay.exe process.

And yes, I've been in the Netherlands for a few years now, and will stay for a few more :)

Alien_Forever
Leprechaun
Leprechaun
Posts: 1
Joined: 22 Jun 2018

Re: HoMM3 TCP/IP networking howto

Unread postby Alien_Forever » 22 Jun 2018, 18:47

UPnP might influence the host/client visibility
- and worse: the connectivity to rarely visible games inevitably fails as well! That (at least on my WD My Net N900 router with the latest (year 2013) firmware) was the most terrible thing using HD Mod (from Barinov). Whilst original HoMM3 used to connect just fine, HD Mod would neither connect nor even show most the games that were already present within LAN network. Even attempt to use a VPN for port forwarding etc. (Evolve) did not help at all with UPnP on :wall: .
The HD mod puts its own dpwsockx.dll file into the Heroes3 folder, which overrides the system one. This causes hangs when trying to host. Once this file is removed or replaced with the one from the DirectX redistributable, the HD mod works fine
- I actually found that it is rather original Heroes3.exe that hangs on attempt to host if that dpwsockx.dll [version 4.7.0.700, last modified 09.09.1999] is already in the same folder AND dpwsockx.dll from DirectX 9 Feb 2010 [version 5.3.1.904, last modified 09.07.2004] is already pasted into SysWOW64 folder of Windows 10 64 bit.
Interestingly, the HD Mod itself only hangs if it had been installed prior to such DirectPlay machinery downgrade. I have reinstalled it anew and faced no hangs of that HD Mod (in host mode) ever since.

I tested all this on two machines: one with Windows 7 64 bit (no stub libraries in Windows\SysWOW64 folder manually overwritten), and another PC with the same Windows 7 64 bit (no stub libraries in Windows\SysWOW64 folder manually overwritten) + Windows 10 64bit (the stub libraries in Windows\SysWOW64 folder manually overwritten as instructed above) + Windows XP 64 bit (no modifications), all OS have DirectX 8.1 and DirectX 9 redistributable (February 2010) pre-installed, wired together through WD MyNet N900 router (original HoMM3 seem to be compatible with its UPnP whilst HD Mod is unable to connect until UPnP is disabled.)
All OS show ability of HoMM3 to host, either with or without HD Mod (latest version) installed with that dpwsockx.dll [version 4.7.0.700, last modified 09.09.1999] by default.

Many thanks for your great manual, which I find the best I have ever read!


Return to “Heroes I-IV”

Who is online

Users browsing this forum: No registered users and 10 guests