Jump to content

Recommended Posts

I have multiple dedicated servers, and I want to restrict each of them to a region based on geolocation. 

I see that dedicated servers sometimes print a message like CLOSE_CONNECTION_WITH_REASON, followed by a reason. At this point the client's ID and IP is received by the server. I was wondering if I can hook into this step and manually reject connections from a range of IPs.

Any help is appreciated.

 

Edited by JackJohnsn

I believe there's a way to do this, albeit a way that clients are capable of circumventing thanks to how I'm thinking of it.

Is there a particular reason you're trying to do this, or a situation you're trying to encounter/avoid?

  • Like 1
4 hours ago, penguin0616 said:

Is there a particular reason you're trying to do this, or a situation you're trying to encounter/avoid?

Just trying to lock each server to its specified region. Specifically on SEA. 

Could you please provide some info about your method?

You can use TheNet:GetCountryCode() as a method of determining a client's country.
It isn't perfect but I believe it is your best bet.

A server mod with all_clients_require_mod could perform the check provided it is running on a client, and if not correct, disconnect the user. 

Only issue is you'd have to come up with a table of all the country codes, and I don't know how they choose them.

 

Edited by penguin0616
  • Like 1
On 2/1/2021 at 8:21 AM, penguin0616 said:

You can use TheNet:GetCountryCode() as a method of determining a client's country

Thanks, but I'm mostly interested in how and when to execute the code. Such as when you use AddClassPostConstruct() to modify a class's constructor.

So basically where should I attach my custom function to?

Quote

So basically where should I attach my custom function to?

You can attach it pretty much anywhere you want, you just have to do *something* when the mod gets loaded on the client.

Quote

but I'm mostly interested in how and when to execute the code

The only how/when condition that's worth worrying about is making sure your mod instance is running on a client, which you can verify with a standard mastersim check. Doing the check on a server could end up leading to a crash, which is probably not desired.

Spoiler

If you don't have any preference or have no clue on where you want to put your function, you can use an AddSimPostInit.
Though that will mean the client is in the server longer before you get to do a check.

 

Edited by penguin0616
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...