mirror of
https://github.com/openbullet/openbullet.git
synced 2023-10-21 07:33:42 -05:00
Added TCP WaitForHello on Connect.
This commit is contained in:
@@ -368,7 +368,7 @@ Syntax:
|
|||||||
TCP COMMAND [ARGUMENTS]
|
TCP COMMAND [ARGUMENTS]
|
||||||
|
|
||||||
Allowed Commands:
|
Allowed Commands:
|
||||||
CONNECT "HOST" "PORT" [UseSSL?] [-> VAR/CAP "NAME"]
|
CONNECT "HOST" "PORT" [UseSSL?] [WaitForHello?] [-> VAR/CAP "NAME"]
|
||||||
SEND "MESSAGE" [WebSocket?] [-> VAR/CAP "NAME"]
|
SEND "MESSAGE" [WebSocket?] [-> VAR/CAP "NAME"]
|
||||||
DISCONNECT
|
DISCONNECT
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,8 @@
|
|||||||
<Label Content="Port:"/>
|
<Label Content="Port:"/>
|
||||||
<TextBox Text="{Binding Port}"/>
|
<TextBox Text="{Binding Port}"/>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
<CheckBox Content="SSL" IsChecked="{Binding UseSSL}" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
|
<CheckBox Content="SSL" IsChecked="{Binding UseSSL}" VerticalContentAlignment="Center"/>
|
||||||
|
<CheckBox Content="Wait for hello" IsChecked="{Binding WaitForHello}" VerticalContentAlignment="Center"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem x:Name="sendTab">
|
<TabItem x:Name="sendTab">
|
||||||
|
|||||||
+19
-11
@@ -52,6 +52,10 @@ namespace RuriLib
|
|||||||
/// <summary>Whether to treat the message as a WebSocket payload (adds the frame overhead bytes).</summary>
|
/// <summary>Whether to treat the message as a WebSocket payload (adds the frame overhead bytes).</summary>
|
||||||
public bool WebSocket { get { return webSocket; } set { webSocket = value; OnPropertyChanged(); } }
|
public bool WebSocket { get { return webSocket; } set { webSocket = value; OnPropertyChanged(); } }
|
||||||
|
|
||||||
|
private bool waitForHello = true;
|
||||||
|
/// <summary>Whether to wait for the server hello message once connected.</summary>
|
||||||
|
public bool WaitForHello { get { return waitForHello; } set { waitForHello = value; OnPropertyChanged(); } }
|
||||||
|
|
||||||
private string message = "";
|
private string message = "";
|
||||||
/// <summary>The message sent to the host.</summary>
|
/// <summary>The message sent to the host.</summary>
|
||||||
public string Message { get { return message; } set { message = value; OnPropertyChanged(); } }
|
public string Message { get { return message; } set { message = value; OnPropertyChanged(); } }
|
||||||
@@ -92,7 +96,7 @@ namespace RuriLib
|
|||||||
Host = LineParser.ParseLiteral(ref input, "Host");
|
Host = LineParser.ParseLiteral(ref input, "Host");
|
||||||
Port = LineParser.ParseLiteral(ref input, "Port");
|
Port = LineParser.ParseLiteral(ref input, "Port");
|
||||||
|
|
||||||
if (LineParser.Lookahead(ref input) == TokenType.Boolean)
|
while (LineParser.Lookahead(ref input) == TokenType.Boolean)
|
||||||
LineParser.SetBool(ref input, this);
|
LineParser.SetBool(ref input, this);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -143,7 +147,8 @@ namespace RuriLib
|
|||||||
writer
|
writer
|
||||||
.Literal(Host)
|
.Literal(Host)
|
||||||
.Literal(Port)
|
.Literal(Port)
|
||||||
.Boolean(UseSSL, "UseSSL");
|
.Boolean(UseSSL, "UseSSL")
|
||||||
|
.Boolean(WaitForHello, "WaitForHello");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TCPCommand.Send:
|
case TCPCommand.Send:
|
||||||
@@ -184,22 +189,23 @@ namespace RuriLib
|
|||||||
tcp = new TcpClient();
|
tcp = new TcpClient();
|
||||||
tcp.Connect(h, p);
|
tcp.Connect(h, p);
|
||||||
|
|
||||||
|
|
||||||
if (tcp.Connected)
|
if (tcp.Connected)
|
||||||
{
|
{
|
||||||
net = tcp.GetStream();
|
net = tcp.GetStream();
|
||||||
if (UseSSL)
|
|
||||||
{
|
|
||||||
ssl = new SslStream(net);
|
|
||||||
ssl.AuthenticateAsClient(h);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Wait a bit and read the Stream if not Empty
|
if (UseSSL)
|
||||||
Thread.Sleep(200);
|
|
||||||
if (net.DataAvailable)
|
|
||||||
{
|
{
|
||||||
|
ssl = new SslStream(net);
|
||||||
|
ssl.AuthenticateAsClient(h);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WaitForHello)
|
||||||
|
{
|
||||||
|
// Read the stream to make sure we are connected
|
||||||
if (UseSSL) bytes = ssl.Read(buffer, 0, buffer.Length);
|
if (UseSSL) bytes = ssl.Read(buffer, 0, buffer.Length);
|
||||||
else bytes = net.Read(buffer, 0, buffer.Length);
|
else bytes = net.Read(buffer, 0, buffer.Length);
|
||||||
|
|
||||||
// Save the response as ASCII in the SOURCE variable
|
// Save the response as ASCII in the SOURCE variable
|
||||||
response = Encoding.ASCII.GetString(buffer, 0, bytes);
|
response = Encoding.ASCII.GetString(buffer, 0, bytes);
|
||||||
}
|
}
|
||||||
@@ -247,6 +253,7 @@ namespace RuriLib
|
|||||||
// Manual implementation of the WebSocket frame
|
// Manual implementation of the WebSocket frame
|
||||||
if (WebSocket)
|
if (WebSocket)
|
||||||
{
|
{
|
||||||
|
#region WebSocket
|
||||||
List<byte> bl = new List<byte>();
|
List<byte> bl = new List<byte>();
|
||||||
|
|
||||||
// (FIN=1) (RSV1=0) (RSV2=0) (RSV3=0) (OPCODE=0001) = 128 + 1 = 129
|
// (FIN=1) (RSV1=0) (RSV2=0) (RSV3=0) (OPCODE=0001) = 128 + 1 = 129
|
||||||
@@ -289,6 +296,7 @@ namespace RuriLib
|
|||||||
}
|
}
|
||||||
|
|
||||||
b = bl.ToArray();
|
b = bl.ToArray();
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user