Search Unity

How do I prompt a firewall expection on build start?

Discussion in 'Multiplayer' started by munkbusiness, Jan 30, 2018.

  1. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    So I have a game that uses NetworkTransport and udp broadcasts to access other devices running the app.

    I know that firewall blocks this as it works fine in editor where firewall has an exception, and it works fine when built to an .exe if I manually disable firewall, and doesn't work if I don't.

    It isn't very consumer friendly to ask them to disable the firewall or to go into settings and make an exception, so I want to know how to prompt the firewall pop-up that often appears in other online games, so that the user just have to click ok to a pop-up to allow connections for that specific program.
     
  2. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    Have I misunderstood something about how firewall works, or have no one experienced this? (Bumb)
     
  3. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    AFAIK the firewall prompt is something OS does automatically when it detects an application wants to host/listen on a specific port. I don't think you can force it.
     
    Joe-Censored likes this.
  4. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    I had a sneaking suspicion, but what do I do then if the OS doesn't pick up that my application wants to host/listen, but still blocks it.

    It is even the very first thing my application does, right after boot.
     
  5. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    This depends on the firewall the user has. If a user has a firewall that only allow user whitelisted software as an example, there is no way to disable that without heavily going against the users will and even then it will be difficult. As for the operatingsystems os. I know windows have ways for you to ask them about firewall. You can even modify firewall settings from your application if ran with admin. And you could request admin while the application is being ran.
     
  6. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    I don't want to disable firewall, but rather have the typical pop-up that asks for white listing the game. I am primarily developing for windows, so if you have any more info on asking windows about firewall that would help a lot.

    I don't like the idea of modifying the firewall by gaining admin access though.
     
  7. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    If you are talking about the Windows Defender Firewall that was introduced in XP. It will prompt users automatically. When you execute the exe it will automatically pop up a prompt, note that it only does this once. If the user press cancel, it will add a blacklist in the windows firewall. If you press allow it will add a whitelist. This firewall also has a nice API for you to use.
    https://msdn.microsoft.com/en-us/library/aa366458(VS.85).aspx
    As for third party firewalls, you are probably better of not trying. They are often developed to be secure and don't want programs modifying them. Personally I use a whitelist firewall on my linux machine which means I specifically have to whitelist applications I trust to allow them to make inbound and outbound connections. But windows protects these third party firewalls in a similar way they protect third party antivirus's. They are not treated as usual programs but rather have special limitations.
     
  8. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    I am talking about Windows Defender Firewall, at least for me to make it work I am whitelisting my build through Windows Firewall in Control Panel.

    So my problem is exactly that I am not getting the behaviour that you mention on any of my machines: "It will prompt users automatically. When you execute the exe it will automatically pop up a prompt, note that it only does this once."

    I never got that pop-up, which is why i started this thread.

    I am not worried about Linux users as they typically know what they are doing with computers. And I am not talking about any specialised Firewalls (at least I am pretty sure I am not).
     
  9. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    What port is your application using/listening on?
     
  10. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    I just checked, and I am using port: 47777

    I cannot remember if that was just a default port from a tutorial I followed or if it is some arbitrary number I picked.
     
  11. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    But firewall is not blocking your application correct?
    If so, firewall will only prompt you to allow access if access is blocked.
     
  12. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    Firewall is preventing my application from picking up other players, I thing it is the broadcast, but it might be the handshaking, but one of those two. When I build it doesn't connect, unless I manually give the build permission in my firewall settings or disable firewall all together. It works fine in the editor, but only because the editor also has permission.

    Anecdote if that randomly helps anything: When I updated from 2017.3.0 to 2017.3.1 the editor was blocked so I had to give it permission again.
     
  13. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Probably you pressed cancel the first time it came up, thus blacklisting it. Try renaming the build to a random name and see if it appear
     
  14. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    I would be suprised if I cancelled it on my first build as I took me sometime to figure out what was wrong back then. I just send my build to a fresh PC to test it out there also, and nothing popped up.

    I also tried building with a new name and even changed the product name in PlayerSettings in case that was the thing.

    To clarify, I am not using any internet based connection, I am using broadcasting and NetworkTransport for local only.
     
  15. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Oh, that might be a difference then. Please check what the Firewall has to say about the application after on the new PC. Since it's not doing any outbound network connections per say (even though it should use the network adapter?). Something might be going on. Check if the firewall treats it as blocked, allowed or neutral by default. I am unsure of this. But as I stated earlier. The Windows Defender Firewall has API's you can use.
     
  16. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    Just checked the inbound, outbound, and monitoring rules on the other PC i tested it on. I couldn't find anything about the build file there.

    Same goes for the builds with other names on my own machine.
     
  17. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    Still haven't found a solution, outside of maybe hijacking the player's firewall with the API. Since I am using NetworkTransport, maybe @aabramychev has an idea? Otherwise still open for input.
     
  18. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    Bump, still really need a solution.
     
  19. chambe89

    chambe89

    Joined:
    Dec 3, 2018
    Posts:
    2
    Did you find any solution about this?
     
  20. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    Yes and no. Still no solution from prompting with Unity. So what I ended up doing was enabling firewall through an installer for Windows. Kinda S***ty way to do it, but less work for the player. I work on windows so I have no idea whether this issue exists on Mac and Linux to begin with.
     
  21. Runster

    Runster

    Joined:
    Dec 28, 2017
    Posts:
    1
    Did your installer solution is working with steam? If yes could you tell me how to make it?
     
  22. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    55
    The project I needed it for was paused for scoope reasons, but I plan to get back at it in a few months. I have sadly not tried for steam, but that would be a MAJOR issue, so I will keep lurking.
     
  23. espen_skaar

    espen_skaar

    Joined:
    Aug 4, 2022
    Posts:
    1
    what a piece of crap