deathkiller / jazz2

🎮 · Jazz² Resurrection: Open-source reimplementation of Jazz Jackrabbit 2
https://deat.tk/jazz2/
GNU General Public License v3.0
495 stars 18 forks source link

Fix /connect:host:port arg parsing #31

Closed chewi closed 4 years ago

chewi commented 4 years ago

I tried to connect to my own private server but it was just ignoring the /connect arg. I eventually figured out why!

While on the subject, I've noticed that if you try to connect to a non-existent server, you just end up with a horribly glitchy window.

deathkiller commented 4 years ago

That's strange, because it should be fine already. Your fix will break it for IPv6 addresses. Can you tell me full command line input what did you try to use?

chewi commented 4 years ago

I was trying mono Jazz2.exe /connect:SOMEHOST:7777.

args[i].LastIndexOf(':', 10) searches backwards from index 10, which is O in this case. Maybe it should be 9? That aside, it returns 8, the index of the first :.

It then tries to parse a number from args[i].Substring(idx + 1), which is SOMEHOST:7777 in this case. That fails so it gives up.

It looked very much like you meant to use args[i].IndexOf(':', 10) because that searches forwards instead and hence returns 17, the index of the second :. The number is then parsed from just 7777.

If you want to to work for IPv6 then you'll have to chop off the leading /connect: first.

deathkiller commented 4 years ago

Ah, sorry, I forgot how LastIndexOf works. Should be fixed now.

chewi commented 4 years ago

Thanks! And just to let you know, the packages are in Gentoo now. :grinning:

deathkiller commented 4 years ago

Great, thanks! Can you tell me where I can find it?

chewi commented 4 years ago

It should show up here and here soon.