Merge branch 'mika-n-jay' into jay

This commit is contained in:
Travis Nickles 2019-05-30 16:00:51 -05:00
commit 147d9666b6
10 changed files with 120 additions and 16 deletions

View File

@ -212,15 +212,16 @@ namespace DS4Windows
Task.Run(() => Task.Run(() =>
{ {
var UDP_SERVER_PORT = Global.getUDPServerPortNum(); var UDP_SERVER_PORT = Global.getUDPServerPortNum();
var UDP_SERVER_LISTEN_ADDRESS = Global.getUDPServerListenAddress();
try try
{ {
_udpServer.Start(UDP_SERVER_PORT); _udpServer.Start(UDP_SERVER_PORT, UDP_SERVER_LISTEN_ADDRESS);
LogDebug("UDP server listening on port " + UDP_SERVER_PORT); LogDebug($"UDP server listening on address {UDP_SERVER_LISTEN_ADDRESS} port {UDP_SERVER_PORT}");
} }
catch (System.Net.Sockets.SocketException ex) catch (System.Net.Sockets.SocketException ex)
{ {
var errMsg = String.Format("Couldn't start UDP server on port {0}, outside applications won't be able to access pad data ({1})", UDP_SERVER_PORT, ex.SocketErrorCode); var errMsg = String.Format("Couldn't start UDP server on address {0}:{1}, outside applications won't be able to access pad data ({2})", UDP_SERVER_LISTEN_ADDRESS, UDP_SERVER_PORT, ex.SocketErrorCode);
LogDebug(errMsg, true); LogDebug(errMsg, true);
AppLogger.LogToTray(errMsg, true, true); AppLogger.LogToTray(errMsg, true, true);
@ -286,9 +287,11 @@ namespace DS4Windows
await Task.Delay(100); await Task.Delay(100);
var UDP_SERVER_PORT = Global.getUDPServerPortNum(); var UDP_SERVER_PORT = Global.getUDPServerPortNum();
var UDP_SERVER_LISTEN_ADDRESS = Global.getUDPServerListenAddress();
try try
{ {
_udpServer.Start(UDP_SERVER_PORT); _udpServer.Start(UDP_SERVER_PORT, UDP_SERVER_LISTEN_ADDRESS);
foreach (DS4Device dev in devices) foreach (DS4Device dev in devices)
{ {
dev.queueEvent(() => dev.queueEvent(() =>
@ -296,11 +299,11 @@ namespace DS4Windows
dev.Report += dev.MotionEvent; dev.Report += dev.MotionEvent;
}); });
} }
LogDebug("UDP server listening on port " + UDP_SERVER_PORT); LogDebug($"UDP server listening on address {UDP_SERVER_LISTEN_ADDRESS} port {UDP_SERVER_PORT}");
} }
catch (System.Net.Sockets.SocketException ex) catch (System.Net.Sockets.SocketException ex)
{ {
var errMsg = String.Format("Couldn't start UDP server on port {0}, outside applications won't be able to access pad data ({1})", UDP_SERVER_PORT, ex.SocketErrorCode); var errMsg = String.Format("Couldn't start UDP server on address {0}:{1}, outside applications won't be able to access pad data ({2})", UDP_SERVER_LISTEN_ADDRESS, UDP_SERVER_PORT, ex.SocketErrorCode);
LogDebug(errMsg, true); LogDebug(errMsg, true);
AppLogger.LogToTray(errMsg, true, true); AppLogger.LogToTray(errMsg, true, true);
@ -517,15 +520,16 @@ namespace DS4Windows
{ {
//var UDP_SERVER_PORT = 26760; //var UDP_SERVER_PORT = 26760;
var UDP_SERVER_PORT = Global.getUDPServerPortNum(); var UDP_SERVER_PORT = Global.getUDPServerPortNum();
var UDP_SERVER_LISTEN_ADDRESS = Global.getUDPServerListenAddress();
try try
{ {
_udpServer.Start(UDP_SERVER_PORT); _udpServer.Start(UDP_SERVER_PORT, UDP_SERVER_LISTEN_ADDRESS);
LogDebug("UDP server listening on port " + UDP_SERVER_PORT); LogDebug($"UDP server listening on address {UDP_SERVER_LISTEN_ADDRESS} port {UDP_SERVER_PORT}");
} }
catch (System.Net.Sockets.SocketException ex) catch (System.Net.Sockets.SocketException ex)
{ {
var errMsg = String.Format("Couldn't start UDP server on port {0}, outside applications won't be able to access pad data ({1})", UDP_SERVER_PORT, ex.SocketErrorCode); var errMsg = String.Format("Couldn't start UDP server on address {0}:{1}, outside applications won't be able to access pad data ({2})", UDP_SERVER_LISTEN_ADDRESS, UDP_SERVER_PORT, ex.SocketErrorCode);
LogDebug(errMsg, true); LogDebug(errMsg, true);
AppLogger.LogToTray(errMsg, true, true); AppLogger.LogToTray(errMsg, true, true);

View File

@ -709,6 +709,15 @@ namespace DS4Windows
m_Config.udpServPort = value; m_Config.udpServPort = value;
} }
public static string getUDPServerListenAddress()
{
return m_Config.udpServListenAddress;
}
public static void setUDPServerListenAddress(string value)
{
m_Config.udpServListenAddress = value.Trim();
}
public static bool UseWhiteIcon public static bool UseWhiteIcon
{ {
set { m_Config.useWhiteIcon = value; } set { m_Config.useWhiteIcon = value; }
@ -1721,6 +1730,7 @@ namespace DS4Windows
public int flashWhenLateAt = 20; public int flashWhenLateAt = 20;
public bool useUDPServ = false; public bool useUDPServ = false;
public int udpServPort = 26760; public int udpServPort = 26760;
public string udpServListenAddress = "127.0.0.1"; // 127.0.0.1=IPAddress.Loopback (default), 0.0.0.0=IPAddress.Any as all interfaces, x.x.x.x = Specific ipv4 interface address or hostname
public bool useCustomSteamFolder; public bool useCustomSteamFolder;
public string customSteamFolder; public string customSteamFolder;
// Cache whether profile has custom action // Cache whether profile has custom action
@ -3385,6 +3395,8 @@ namespace DS4Windows
catch { missingSetting = true; } catch { missingSetting = true; }
try { Item = m_Xdoc.SelectSingleNode("/Profile/UDPServerPort"); int temp; int.TryParse(Item.InnerText, out temp); udpServPort = Math.Min(Math.Max(temp, 1024), 65535); } try { Item = m_Xdoc.SelectSingleNode("/Profile/UDPServerPort"); int temp; int.TryParse(Item.InnerText, out temp); udpServPort = Math.Min(Math.Max(temp, 1024), 65535); }
catch { missingSetting = true; } catch { missingSetting = true; }
try { Item = m_Xdoc.SelectSingleNode("/Profile/UDPServerListenAddress"); udpServListenAddress = Item.InnerText; }
catch { missingSetting = true; }
try { Item = m_Xdoc.SelectSingleNode("/Profile/UseCustomSteamFolder"); Boolean.TryParse(Item.InnerText, out useCustomSteamFolder); } try { Item = m_Xdoc.SelectSingleNode("/Profile/UseCustomSteamFolder"); Boolean.TryParse(Item.InnerText, out useCustomSteamFolder); }
catch { missingSetting = true; } catch { missingSetting = true; }
try { Item = m_Xdoc.SelectSingleNode("/Profile/CustomSteamFolder"); customSteamFolder = Item.InnerText; } try { Item = m_Xdoc.SelectSingleNode("/Profile/CustomSteamFolder"); customSteamFolder = Item.InnerText; }
@ -3458,6 +3470,7 @@ namespace DS4Windows
XmlNode xmlWhiteIcon = m_Xdoc.CreateNode(XmlNodeType.Element, "WhiteIcon", null); xmlWhiteIcon.InnerText = useWhiteIcon.ToString(); Node.AppendChild(xmlWhiteIcon); XmlNode xmlWhiteIcon = m_Xdoc.CreateNode(XmlNodeType.Element, "WhiteIcon", null); xmlWhiteIcon.InnerText = useWhiteIcon.ToString(); Node.AppendChild(xmlWhiteIcon);
XmlNode xmlUseUDPServ = m_Xdoc.CreateNode(XmlNodeType.Element, "UseUDPServer", null); xmlUseUDPServ.InnerText = useUDPServ.ToString(); Node.AppendChild(xmlUseUDPServ); XmlNode xmlUseUDPServ = m_Xdoc.CreateNode(XmlNodeType.Element, "UseUDPServer", null); xmlUseUDPServ.InnerText = useUDPServ.ToString(); Node.AppendChild(xmlUseUDPServ);
XmlNode xmlUDPServPort = m_Xdoc.CreateNode(XmlNodeType.Element, "UDPServerPort", null); xmlUDPServPort.InnerText = udpServPort.ToString(); Node.AppendChild(xmlUDPServPort); XmlNode xmlUDPServPort = m_Xdoc.CreateNode(XmlNodeType.Element, "UDPServerPort", null); xmlUDPServPort.InnerText = udpServPort.ToString(); Node.AppendChild(xmlUDPServPort);
XmlNode xmlUDPServListenAddress = m_Xdoc.CreateNode(XmlNodeType.Element, "UDPServerListenAddress", null); xmlUDPServListenAddress.InnerText = udpServListenAddress; Node.AppendChild(xmlUDPServListenAddress);
XmlNode xmlUseCustomSteamFolder = m_Xdoc.CreateNode(XmlNodeType.Element, "UseCustomSteamFolder", null); xmlUseCustomSteamFolder.InnerText = useCustomSteamFolder.ToString(); Node.AppendChild(xmlUseCustomSteamFolder); XmlNode xmlUseCustomSteamFolder = m_Xdoc.CreateNode(XmlNodeType.Element, "UseCustomSteamFolder", null); xmlUseCustomSteamFolder.InnerText = useCustomSteamFolder.ToString(); Node.AppendChild(xmlUseCustomSteamFolder);
XmlNode xmlCustomSteamFolder = m_Xdoc.CreateNode(XmlNodeType.Element, "CustomSteamFolder", null); xmlCustomSteamFolder.InnerText = customSteamFolder; Node.AppendChild(xmlCustomSteamFolder); XmlNode xmlCustomSteamFolder = m_Xdoc.CreateNode(XmlNodeType.Element, "CustomSteamFolder", null); xmlCustomSteamFolder.InnerText = customSteamFolder; Node.AppendChild(xmlCustomSteamFolder);

View File

@ -396,7 +396,7 @@ namespace DS4Windows
} }
} }
public void Start(int port) public void Start(int port, string listenAddress = "")
{ {
if (running) if (running)
{ {
@ -409,7 +409,35 @@ namespace DS4Windows
} }
udpSock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); udpSock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
try { udpSock.Bind(new IPEndPoint(IPAddress.Loopback, port)); } try
{
IPAddress udpListenIPAddress;
if (listenAddress == "127.0.0.1" || listenAddress == "")
{
// Listen on local looback interface (default option). Does not allow remote client connections
udpListenIPAddress = IPAddress.Loopback;
}
else if (listenAddress == "0.0.0.0")
{
// Listen on all IPV4 interfaces.
// Remote client connections allowed. If the local network is not "safe" then may not be a good idea, because at the moment incoming connections are not authenticated in any way
udpListenIPAddress = IPAddress.Any;
}
else
{
// Listen on a specific hostname or IPV4 interface address. If the hostname has multiple interfaces then use the first IPV4 address because it is usually the primary IP addr.
// Remote client connections allowed.
IPAddress[] ipAddresses = Dns.GetHostAddresses(listenAddress);
udpListenIPAddress = null;
foreach (IPAddress ip4 in ipAddresses.Where(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork))
{
udpListenIPAddress = ip4;
break;
}
if (udpListenIPAddress == null) throw new SocketException(10049 /*WSAEADDRNOTAVAIL*/);
}
udpSock.Bind(new IPEndPoint(udpListenIPAddress, port));
}
catch (SocketException ex) catch (SocketException ex)
{ {
udpSock.Close(); udpSock.Close();

View File

@ -154,6 +154,7 @@
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.ckUdpServ = new System.Windows.Forms.CheckBox(); this.ckUdpServ = new System.Windows.Forms.CheckBox();
this.nUDUdpPortNum = new System.Windows.Forms.NumericUpDown(); this.nUDUdpPortNum = new System.Windows.Forms.NumericUpDown();
this.tBUdpListenAddress = new System.Windows.Forms.TextBox();
this.languagePackComboBox1 = new DS4Windows.DS4Forms.LanguagePackComboBox(); this.languagePackComboBox1 = new DS4Windows.DS4Forms.LanguagePackComboBox();
this.cBCustomSteam = new System.Windows.Forms.CheckBox(); this.cBCustomSteam = new System.Windows.Forms.CheckBox();
this.tBSteamFolder = new System.Windows.Forms.TextBox(); this.tBSteamFolder = new System.Windows.Forms.TextBox();
@ -1171,6 +1172,7 @@
this.panel4.Controls.Add(this.label2); this.panel4.Controls.Add(this.label2);
this.panel4.Controls.Add(this.ckUdpServ); this.panel4.Controls.Add(this.ckUdpServ);
this.panel4.Controls.Add(this.nUDUdpPortNum); this.panel4.Controls.Add(this.nUDUdpPortNum);
this.panel4.Controls.Add(this.tBUdpListenAddress);
resources.ApplyResources(this.panel4, "panel4"); resources.ApplyResources(this.panel4, "panel4");
this.panel4.Name = "panel4"; this.panel4.Name = "panel4";
// //
@ -1205,6 +1207,12 @@
0, 0,
0}); 0});
// //
// tBUdpListenAddress
//
resources.ApplyResources(this.tBUdpListenAddress, "tBUdpListenAddress");
this.tBUdpListenAddress.Name = "tBUdpListenAddress";
this.tBUdpListenAddress.TextChanged += new System.EventHandler(this.tBUdpListenAddress_TextChanged);
//
// languagePackComboBox1 // languagePackComboBox1
// //
this.languagePackComboBox1.AutoValidate = System.Windows.Forms.AutoValidate.Disable; this.languagePackComboBox1.AutoValidate = System.Windows.Forms.AutoValidate.Disable;
@ -1520,6 +1528,7 @@
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.CheckBox ckUdpServ; private System.Windows.Forms.CheckBox ckUdpServ;
private System.Windows.Forms.NumericUpDown nUDUdpPortNum; private System.Windows.Forms.NumericUpDown nUDUdpPortNum;
private System.Windows.Forms.TextBox tBUdpListenAddress;
private System.Windows.Forms.CheckBox cBCustomSteam; private System.Windows.Forms.CheckBox cBCustomSteam;
private System.Windows.Forms.TextBox tBSteamFolder; private System.Windows.Forms.TextBox tBSteamFolder;
//private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; //private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;

View File

@ -328,8 +328,10 @@ namespace DS4Windows.Forms
StartWindowsCheckBox.CheckedChanged += new EventHandler(StartWindowsCheckBox_CheckedChanged); StartWindowsCheckBox.CheckedChanged += new EventHandler(StartWindowsCheckBox_CheckedChanged);
new ToolTip().SetToolTip(StartWindowsCheckBox, Properties.Resources.RunAtStartup); new ToolTip().SetToolTip(StartWindowsCheckBox, Properties.Resources.RunAtStartup);
ckUdpServ.Checked = nUDUdpPortNum.Enabled = isUsingUDPServer(); ckUdpServ.Checked = nUDUdpPortNum.Enabled = tBUdpListenAddress.Enabled = isUsingUDPServer();
nUDUdpPortNum.Value = getUDPServerPortNum(); nUDUdpPortNum.Value = getUDPServerPortNum();
tBUdpListenAddress.Text = getUDPServerListenAddress();
new ToolTip().SetToolTip(ckUdpServ, Properties.Resources.UdpServer);
ckUdpServ.CheckedChanged += CkUdpServ_CheckedChanged; ckUdpServ.CheckedChanged += CkUdpServ_CheckedChanged;
nUDUdpPortNum.Leave += NUDUdpPortNum_Leave; nUDUdpPortNum.Leave += NUDUdpPortNum_Leave;
@ -2594,6 +2596,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
} }
nUDUdpPortNum.Enabled = state; nUDUdpPortNum.Enabled = state;
tBUdpListenAddress.Enabled = state;
} }
private void NUDUdpPortNum_Leave(object sender, EventArgs e) private void NUDUdpPortNum_Leave(object sender, EventArgs e)
@ -2603,6 +2606,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
{ {
setUDPServerPort(curValue); setUDPServerPort(curValue);
nUDUdpPortNum.Enabled = false; nUDUdpPortNum.Enabled = false;
tBUdpListenAddress.Enabled = false;
WaitUDPPortChange(); WaitUDPPortChange();
} }
} }
@ -2614,9 +2618,15 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
{ {
await TaskRunner.Run(() => Program.rootHub.UseUDPPort()); await TaskRunner.Run(() => Program.rootHub.UseUDPPort());
nUDUdpPortNum.Enabled = true; nUDUdpPortNum.Enabled = true;
tBUdpListenAddress.Enabled = true;
} }
} }
private void tBUdpListenAddress_TextChanged(object sender, EventArgs e)
{
setUDPServerListenAddress(tBUdpListenAddress.Text.Trim());
}
private void cBFlashWhenLate_CheckedChanged(object sender, EventArgs e) private void cBFlashWhenLate_CheckedChanged(object sender, EventArgs e)
{ {
FlashWhenLate = cBFlashWhenLate.Checked; FlashWhenLate = cBFlashWhenLate.Checked;

View File

@ -2707,7 +2707,7 @@
<value>NoControl</value> <value>NoControl</value>
</data> </data>
<data name="label2.Location" type="System.Drawing.Point, System.Drawing"> <data name="label2.Location" type="System.Drawing.Point, System.Drawing">
<value>118, 2</value> <value>200, 2</value>
</data> </data>
<data name="label2.Size" type="System.Drawing.Size, System.Drawing"> <data name="label2.Size" type="System.Drawing.Size, System.Drawing">
<value>26, 13</value> <value>26, 13</value>
@ -2764,7 +2764,7 @@
<value>False</value> <value>False</value>
</data> </data>
<data name="nUDUdpPortNum.Location" type="System.Drawing.Point, System.Drawing"> <data name="nUDUdpPortNum.Location" type="System.Drawing.Point, System.Drawing">
<value>150, 0</value> <value>230, 0</value>
</data> </data>
<data name="nUDUdpPortNum.Size" type="System.Drawing.Size, System.Drawing"> <data name="nUDUdpPortNum.Size" type="System.Drawing.Size, System.Drawing">
<value>66, 20</value> <value>66, 20</value>
@ -2784,11 +2784,35 @@
<data name="&gt;&gt;nUDUdpPortNum.ZOrder" xml:space="preserve"> <data name="&gt;&gt;nUDUdpPortNum.ZOrder" xml:space="preserve">
<value>2</value> <value>2</value>
</data> </data>
<data name="tBUdpListenAddress.Enabled" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="tBUdpListenAddress.Location" type="System.Drawing.Point, System.Drawing">
<value>90, 0</value>
</data>
<data name="tBUdpListenAddress.Size" type="System.Drawing.Size, System.Drawing">
<value>100, 20</value>
</data>
<data name="tBUdpListenAddress.TabIndex" type="System.Int32, mscorlib">
<value>64</value>
</data>
<data name="&gt;&gt;tBUdpListenAddress.Name" xml:space="preserve">
<value>tBUdpListenAddress</value>
</data>
<data name="&gt;&gt;tBUdpListenAddress.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;tBUdpListenAddress.Parent" xml:space="preserve">
<value>panel4</value>
</data>
<data name="&gt;&gt;tBUdpListenAddress.ZOrder" xml:space="preserve">
<value>3</value>
</data>
<data name="panel4.Location" type="System.Drawing.Point, System.Drawing"> <data name="panel4.Location" type="System.Drawing.Point, System.Drawing">
<value>274, 82</value> <value>274, 82</value>
</data> </data>
<data name="panel4.Size" type="System.Drawing.Size, System.Drawing"> <data name="panel4.Size" type="System.Drawing.Size, System.Drawing">
<value>219, 23</value> <value>300, 23</value>
</data> </data>
<data name="panel4.TabIndex" type="System.Int32, mscorlib"> <data name="panel4.TabIndex" type="System.Int32, mscorlib">
<value>64</value> <value>64</value>

View File

@ -49,6 +49,7 @@ namespace DS4Windows
new VidPidInfo(RAZER_VID, 0x1004), // Razer Raiju Ultimate Edition (wired) new VidPidInfo(RAZER_VID, 0x1004), // Razer Raiju Ultimate Edition (wired)
new VidPidInfo(RAZER_VID, 0x1009), // Razer Raiju Ultimate Edition (BT). Doesn't work yet for some reason even when non-steam Razer driver lists the BT Razer Ultimate with this ID. new VidPidInfo(RAZER_VID, 0x1009), // Razer Raiju Ultimate Edition (BT). Doesn't work yet for some reason even when non-steam Razer driver lists the BT Razer Ultimate with this ID.
new VidPidInfo(SONY_VID, 0x05C5), // CronusMax (PS4 Output Mode) new VidPidInfo(SONY_VID, 0x05C5), // CronusMax (PS4 Output Mode)
new VidPidInfo(0x0C12, 0x57AB), // Warrior Joypad JS083 (wired). Custom lightbar color doesn't work, but everything else works OK (except touchpad and gyro because the gamepad doesnt have those).
}; };
private static string devicePathToInstanceId(string devicePath) private static string devicePathToInstanceId(string devicePath)

View File

@ -2099,6 +2099,15 @@ namespace DS4Windows.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Enable UDP server. Server listen address and port. Address value options: 127.0.0.1 localhost only | 0.0.0.0 all addresses | Specific host name or IP address..
/// </summary>
public static string UdpServer {
get {
return ResourceManager.GetString("UdpServer", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Unassigned. /// Looks up a localized string similar to Unassigned.
/// </summary> /// </summary>

View File

@ -600,4 +600,7 @@
<data name="UACTask" xml:space="preserve"> <data name="UACTask" xml:space="preserve">
<value>DS4Windows sovellus pitää käynnistää järjestelmävalvojan oikeuksilla tämän toiminnon käyttämiseksi.</value> <value>DS4Windows sovellus pitää käynnistää järjestelmävalvojan oikeuksilla tämän toiminnon käyttämiseksi.</value>
</data> </data>
<data name="UdpServer" xml:space="preserve">
<value>Aktivoi UDP palvelu. Palvelun osoite ja portti. Osoitevaihtoehdot: 127.0.0.1 paikallinen | 0.0.0.0 kaikki liittymät | Tietty palvelinnimi tai IP numero.</value>
</data>
</root> </root>

View File

@ -823,4 +823,7 @@
<data name="EnableTouchToggle" xml:space="preserve"> <data name="EnableTouchToggle" xml:space="preserve">
<value>Allow touchpad mouse function to get toggled with PS + Touchpad Click.</value> <value>Allow touchpad mouse function to get toggled with PS + Touchpad Click.</value>
</data> </data>
<data name="UdpServer" xml:space="preserve">
<value>Enable UDP server. Server listen address and port. Address value options: 127.0.0.1 localhost only | 0.0.0.0 all addresses | Specific host name or IP address.</value>
</data>
</root> </root>