dethrace-labs / dethrace

Reverse engineering the 1997 game "Carmageddon"
https://twitter.com/dethrace_labs
GNU General Public License v3.0
669 stars 38 forks source link

Cannot run 2 dethrace instances in multiplayer mode on same pc #338

Closed madebr closed 1 year ago

madebr commented 1 year ago

On linux, it is not possible to have 2 processes bind to the same port. So it fails here. https://github.com/dethrace-labs/dethrace/blob/1c10b74141bf111c7dfb518fa984198090b73ab4/src/DETHRACE/pc-win95/win95net.c#L328-L333

I tried using SO_REUSEPORT. This makes the network menu appear, but the host does not appear in the client.

unsigned long reuseport = 1;
setsockopt(gSocket, SOL_SOCKET, SO_REUSEPORT, &reuseport, sizeof(reuseport));
dethrace-labs commented 1 year ago

There is an existing option --no-bind that I use when running the client instance to avoid the double bind issue. Should work on linux also

madebr commented 1 year ago

Ah yes. Then it segfaults here:

#0  0x00000000005165e5 in PDNetSendMessageToAddress (pDetails=0x0, pMessage=0x12e3eb0, pAddress=0x6b3998 <gGuarantee_list+24>) at /home/maarten/projects/dethrace/src/DETHRACE/pc-win95/win95net.c:643
#1  0x00000000004922e4 in ResendGuaranteedMessages () at /home/maarten/projects/dethrace/src/DETHRACE/common/network.c:1879
#2  0x0000000000491818 in NetService (pIn_race=0) at /home/maarten/projects/dethrace/src/DETHRACE/common/network.c:1722
#3  0x0000000000487965 in ServiceTheGame (pRacing=0) at /home/maarten/projects/dethrace/src/DETHRACE/common/main.c:90
#4  0x0000000000487976 in ServiceGame () at /home/maarten/projects/dethrace/src/DETHRACE/common/main.c:95
#5  0x0000000000475c5b in DoInterfaceScreen (pSpec=0x6895a0 <interface_spec>, pOptions=1, pCurrent_choice=0) at /home/maarten/projects/dethrace/src/DETHRACE/common/intrface.c:473
#6  0x00000000004d2a5f in ChangeCar (pNet_mode=1, pCar_index=0x7fffffffde28, pNet_game=0x1462750) at /home/maarten/projects/dethrace/src/DETHRACE/common/racestrt.c:603
#7  0x00000000004964ce in ChooseNetCar (pNet_game=0x1462750, pOptions=0x1462794, pCar_index=0x7fffffffde28, pIm_the_host_so_fuck_off=0) at /home/maarten/projects/dethrace/src/DETHRACE/common/newgame.c:1709
#8  0x0000000000496769 in DoMultiPlayerStart () at /home/maarten/projects/dethrace/src/DETHRACE/common/newgame.c:1791
#9  0x000000000048a1f1 in DoMainMenu (pTime_out=30000, pSave_allowed=0, pContinue_allowed=0) at /home/maarten/projects/dethrace/src/DETHRACE/common/mainmenu.c:588
#10 0x000000000048a33b in DoMainMenuScreen (pTime_out=30000, pSave_allowed=0, pContinue_allowed=0) at /home/maarten/projects/dethrace/src/DETHRACE/common/mainmenu.c:635
#11 0x00000000004f5176 in DoProgram () at /home/maarten/projects/dethrace/src/DETHRACE/common/structur.c:662
#12 0x0000000000487a77 in GameMain (pArgc=3, pArgv=0x7fffffffe298) at /home/maarten/projects/dethrace/src/DETHRACE/common/main.c:123

As expected?

madebr commented 1 year ago

The limitation still applies, but a dethrace instance started with --no-bind will no longer be able to host a server since with https://github.com/dethrace-labs/dethrace/commit/a6e859ae5ce797f63a32efc8ded48ef0eee42974

dethrace-labs commented 1 year ago

Do you still see the segfault? on the latest networking_start_race branch both instances should be able to see each other and interact in game

madebr commented 1 year ago

No, the stacktrace happened when the network branch was in its infancy.

madebr commented 1 year ago

Closing this issue, because the main branch does not have functional multiplayer anyways.