0
\$\begingroup\$

On the game I'm working on I wanted the singleplayer mode to use an integrated server to make adding more players via networking easier. The way I have it right now is I open a server and connects the client to my local address which works fine. But the problem is that if I play the game Singleplayer I don't want to leave anything exposed to the internet while only playing locally. Is there any way to limit the "range" of the server to only let communication happen via LAN?

Thanks in advance!

EDIT: I am using kryonet for networking. The game is written with LibGDX.

\$\endgroup\$
  • \$\begingroup\$ On a LAN network, you don't need to use a server, as you can connect with another system directly. What language / libraries / tools are you using for networking? \$\endgroup\$ – TomTsagk Sep 30 at 16:14
  • \$\begingroup\$ I'm using kryonet for networking. What could other system mean? Like an event system or something else? Thank you! \$\endgroup\$ – Dennis Björk Sep 30 at 18:25
  • \$\begingroup\$ Try to listen on 127.0.0.1 instead of 0.0.0.0 interface, 127.0.0.1 will only be accessible to host, 0.0.0.0 is accessible from outside the machine (For.e.g over the LAN) \$\endgroup\$ – AEonAX Oct 1 at 8:46
1
\$\begingroup\$

if I play the game Singleplayer I don't want to leave anything exposed to the internet while only playing locally

That is usually not a problem, because usually the LAN is behind a NAT installed by the ISP. Such that you actually do not have an public IP to which other can connect... instead everybody outside your LAN sees the router/gateway IP.

Is there any way to limit the "range" of the server to only let communication happen via LAN?

What you want is a subnet mask. All the IPs in the same network will match within the mask... to put it another way, the subnet mask defines up to what point IPs in the same network are equal.

The server can be programmed to use the subnet mask to compare its IP with the origin IP and allow or deny connections based on that. See Test with Java if two IPs are in the same network.

In the odd case where you cannot※ get mask programmatically, you can always let the user specify as part of server configuration.

You may, of course, use a whitelist of IPs, or a simple ACL.


※: I'm not familiar with Kryonet or whatever or not it will filter by subnet out of the box, so I looked it up, and found this:

// Java 1.5 doesn't support getting the subnet mask

-- Source.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.