Mutliplayer IP issues

Blitz3D Forums/Blitz3D Programming/Mutliplayer IP issues

Liberator(Posted 2005) [#1]
I have made multiplayer games before (not using blitz) and a huge issue that I ran into is IPs. What I set up was much like counterstike where you go to join a game, you join a game using a central server. the server sends down the IP of the host and the joining player then connects directly to them.

Now, problem is that I have two IPs I have to deal with. A local computer's IP addy, and a internet IP. For example you have a household with 3 computers, all connected to one router. The router has an IP like 87.34.123.321 and then each of the 3 computers has their own local IP within the router like 192.168.100.2. Ok so I know both these IP...however when I tell blitz to connect to another computers IP, I obviously have to use the internet IP. Problem is, when the router gets the packet, it doesnt know where to send it, so it ignores it. I can't tell the packet to go to two different IP addresses....so how do I get past this?

The soultion i came up with was opening up a port on the router then having the packet forwarded to the correct IP address....however this was so hard for players to understand, no one ended up being able to get it working.

Also, many many professional games are able to not have players go through extreme lengths to host and join over the internet....so why then is this such a headache? isnt there just a way to say "I want to connect to this computer" without having to disable ports, bake a cake and learn to fly?


jfk EO-11110(Posted 2005) [#2]
Most routers are preconfigured in a way they will block data that comes trough "uncommon" ports, so you have to use a common port or tell the users to make sure the port is not blocked by a firewall, be it software or hardware, eg a router.

Well, as far as I see the client sends a request that is answererd by the server. The router should undertand this and send the answer to the right lan client, probably using some kind of session ID. Well, I must confess, I'm only guessing.

Did you try the GNet solution that is using a webserver, php and mySql?


Tibit(Posted 2005) [#3]
There is only one magic solution (that I have heard of) which is the method MSN uses for filetransfers. That method requires "Plug N play" router support which in turn is not 100%. Anyhow you can't rely on that for games.

Also note that most peer to peer programs like DC++ do require you to forward ports if you are behind a router (or be passive - use the hub to relay searches). As do all games I can think of, right? Actually there is people who are not behind a router.

I know it is possible to connect several local computers to online servers as long as they initiate the connection. WOW,UT,Quake.. The only time you should need to forward ports is when you host a game behind a router and you want people to connect to you directly (you external ip).

After initiating contact (to a server for example) the router seems to understand which packets are going back. Even if you are not forwarding any ports. So the solution would be to connect to a external server (Think Gamespy, Gnet should work for this), let people connect to a chat room or so you can connect to them - giving them a way back to your local computer.

I know this works but perhaps there is circumstances where it does not?


ozak(Posted 2005) [#4]
The user definately needs to setup port forwarding on their router.


Tibit(Posted 2005) [#5]
ozak do you mean to host a game or to join one?


ozak(Posted 2005) [#6]
To host a game. Everybody should be able to join, unless their firewall blocks access the other way. (Which it usually doesn't. It's mostly on coorporate networks, that access to MSN and gaming ports are blocked for "security" reasons :)

Letting outside users connect to a specified port is as usual as security risk, although if the program responding on a specific port is not flawed in any way it's safe enough.

XP SP2 actually seperates code and data segments (at last *sigh*) so buffer overrun errors are accounted for :)


Liberator(Posted 2005) [#7]
These are good points. The thing is with my game Lazer I made, people downloaded the game, and then hosted a game. When they told their friends in a different house to connect to their game, it gave them a timeout error and would not connect them - what happened next? Emails in MY mailbox saying my game has bugs....it seems that port forwarding for 'casually hosting' games is not yet common knowledge. I tried to explain to them.. "well see, you have to go to your routers main interface panel, and forward ports 1626 to your ip address which you can figure out by doing this this and this..." by time i got done explaining it they had already gone "screw it" and played anther game where this is not an issue.

Making players fustrated is one of the best ways to guarantee that they don't want to buy your game, so I don't look highly upon asking my customers to re-configure their routers...at least I know I'm not going crazy and this really is an issue people have to face...but has any other blitz developers run into this problem? I can't imagine someone who spent months making a huge multiplayer game, and then realizing their air-tight code wont work cuz players don't want to invest the time in learning how to host a game....


ozak(Posted 2005) [#8]
I worked on a multiplayer game once, and I never had issues with people connecting. But I did host the server myself.

It's not unfair to request that users who want to host games should configure their router.

You could just allow the user to change ports and then suggest they use port 80. this might however clash with any webservers currently running on the LAN :)

Some nasty firewalls even scans packages and only lets HTTP packages through in which case you'll have to support wrapping your packages inside "html" :)

If people have an outside IP they should tell the others to connect to that IP. If there are multiple computers behind that IP then port forwarding must be used.

Having a master server hosted by you where servers "sign up" is another way to go but a bit harder and usually only recommended for huge online games.
This would allow the master server to direct the traffic, but hosts would still need their router configured. There's just no other way about it.

A last suggestion is to look at your default port. Is it within the user range (which I totally forgot :). Some routers might have whole port ranges open, while locking out anything outside those.

But don't start explaining people technical stuff. Tell them to look at their router manual. Even huge games like counterstrike and everquest needs open ports just to play.
You don't want to be excusing yourself. Make it very clear on your website and in the manual that this is a requirement. So people can see it before they buy, because then it's their own decision and can hardly come as a surprise later :)


A default router configuration however usually either blocks everything or nothing at all.
Please make sure that people have software firewalls turned off as those are guaranteed to be restrictive (*cough* windows firewall * cough*)
Zonealarm asks you if you want allow a certain program trying to send network packets access.

Long post. Maybe I repeated myself :)


Tibit(Posted 2005) [#9]
To have your game connect to a Master Server is the way to go. Doing that while listing all games would allow anyone to join games, and those with static ips, to host - for everyone to join. My question is: Have anyone used GNet for this, does it work?


jfk EO-11110(Posted 2005) [#10]
Just a note to zonealarm and other Firewalls that are throwing prompts to the user: When your game runs in Fullscreen, it's a random game if this popup prompt is visible at all, or if it's drawn to the backbuffer, because when you use FLIP, Blitz's Doublebuffer system will flip, but Windows will always draw to buffer 1. For a simple workaround see code archives: "coordinated Flip", in "Misc" AFAIR.


_PJ_(Posted 2005) [#11]
@Wave some firewalls will not allow that sort of behaviour and it is usually such an integral part of their working there is very little you can do to help it.


Tibit(Posted 2005) [#12]
Malice, what did you mean, Plug N Play support?


_Skully(Posted 2005) [#13]
I was working on a network layer a long long time ago that was going to allow auto-forwarding. So essentially each computer on the inside domain would route through one computer to fix that problem.

Never happened but hey... life got in the way


Andy UK(Posted 2005) [#14]
ok as far as i know(tested) if you connect to a host/server on a certain port , the server can send info back on the same port to you and you dont need a port open to recieve it. i think the router leaves the port you send the data on open for a second or two incase there is a response. Counterstrike uses this as you dont need to setup port forwarding to connect to the server. The only thing you need is the port open at the server end if its behind a router. The same thing applies to Internet explorer, when u connect to say "www.google.com" on port 80, you recieve the page data back without the need to have port 80 open at your end. Basically the rule is, if you send a packet of data through a router to a server, the port you sent it through should stay open to allow a response to come back. This is especially true for tcp connections as without you realising, every packet you send, a response is recieved and port 80 isnt open on your router.


ozak(Posted 2005) [#15]
Indeed. Joining is no problem unless you have a VERY restrictive firewall like coorporate style. Hosting needs a port open if you are behind a firewall (which you really should be these days).

Alternative is to host game on port 80 which might clash with any webservers running on your system/LAN. Some firewalls check traffic on port 80 for genuine HTML content but that can be fooled by wrapping your packets in html :)