Start_Common.ps1 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright Epic Games, Inc. All Rights Reserved.
  2. # Do setup as a common task, it is smart and will not reinstall if not required.
  3. Start-Process -FilePath "$PSScriptRoot\setup.bat" -Wait -NoNewWindow
  4. $global:ScriptName = $MyInvocation.MyCommand.Name
  5. $global:PublicIP = $null
  6. $global:StunServer = $null
  7. $global:TurnServer = $null
  8. $global:CirrusCmd = $null
  9. function print_usage {
  10. echo "
  11. Usage (in MS Windows Power Shell):
  12. $global:ScriptName [--help] [--publicip <IP Address>] [--turn <turn server>] [--stun <stun server>] [cirrus options...]
  13. Where:
  14. --help will print this message and stop this script.
  15. --publicip is used to define public ip address (using default port) for turn server, syntax: --publicip ; it is used for
  16. default value: Retrieved from 'curl https://api.ipify.org' or if unsuccessful then set to 127.0.0.1. It is the IP address of the Cirrus server and the default IP address of the TURN server
  17. --turn defines what TURN server to be used, syntax: --turn 127.0.0.1:19303
  18. default value: as above, IP address downloaded from https://api.ipify.org; in case if download failure it is set to 127.0.0.1
  19. --stun defined what STUN server to be used, syntax: --stun stun.l.google.com:19302
  20. default value as above
  21. Other options: stored and passed to the Cirrus server. All parameters printed once the script values are set.
  22. Command line options might be omitted to run with defaults and it is a good practice to omit specific ones when just starting the TURN or the STUN server alone, not the whole set of scripts.
  23. "
  24. exit 1
  25. }
  26. function print_parameters {
  27. echo ""
  28. echo "$scriptname is running with the following parameters:"
  29. echo "--------------------------------------"
  30. if ($global:StunServer -ne $null) { echo "STUN server : $global:StunServer" }
  31. if ($global:TurnServer -ne $null) { echo "TURN server : $global:TurnServer" }
  32. echo "Public IP address : $global:PublicIP"
  33. echo "Cirrus server command line arguments: $global:CirrusCmd"
  34. echo ""
  35. }
  36. function set_start_default_values($SetTurnServerVar, $SetStunServerVar) {
  37. # publicip and cirruscmd are always needed
  38. $global:PublicIP = Invoke-WebRequest -Uri "https://api.ipify.org" -UseBasicParsing
  39. if ($global:PublicIP -eq $null -Or $global:PublicIP.length -eq 0) {
  40. $global:PublicIP = "127.0.0.1"
  41. } else {
  42. $global:PublicIP = ($global:PublicIP).Content
  43. }
  44. $global:cirruscmd = ""
  45. if ($SetTurnServerVar -eq "y") {
  46. $global:TurnServer = $global:PublicIP + ":19303"
  47. }
  48. if ($SetStunServerVar -eq "y") {
  49. $global:StunServer = "stun.l.google.com:19302"
  50. }
  51. }
  52. function use_args($arg) {
  53. $CmdArgs = $arg -split (" ")
  54. while($CmdArgs.count -gt 0) {
  55. $Cmd, $CmdArgs = $CmdArgs
  56. if ($Cmd -eq "--stun") {
  57. $global:StunServer, $CmdArgs = $CmdArgs
  58. } elseif ($Cmd -eq "--turn") {
  59. $global:TurnServer, $CmdArgs = $CmdArgs
  60. } elseif ($Cmd -eq "--publicip") {
  61. $global:PublicIP, $CmdArgs = $CmdArgs
  62. $global:TurnServer = $global:publicip + ":19303"
  63. } elseif ($Cmd -eq "--help") {
  64. print_usage
  65. } else {
  66. echo "Unknown command, adding to cirrus command line: $Cmd"
  67. $global:CirrusCmd += " $Cmd"
  68. }
  69. }
  70. }