mirror of
https://github.com/openbullet/openbullet.git
synced 2023-10-21 07:33:42 -05:00
Changed storage of clients in BotData to a more dynamic way
This commit is contained in:
@@ -171,9 +171,9 @@ namespace RuriLib
|
||||
public override void Process(BotData data)
|
||||
{
|
||||
// Get easy handles
|
||||
var tcp = data.TCPClient;
|
||||
var net = data.NETStream;
|
||||
var ssl = data.SSLStream;
|
||||
var tcp = data.GetCustomObject("TCPClient") as TcpClient;
|
||||
var net = data.GetCustomObject("NETStream") as NetworkStream;
|
||||
var ssl = data.GetCustomObject("SSLStream") as SslStream;
|
||||
byte[] buffer = new byte[2048];
|
||||
int bytes = -1;
|
||||
string response = "";
|
||||
@@ -189,7 +189,6 @@ namespace RuriLib
|
||||
tcp = new TcpClient();
|
||||
tcp.Connect(h, p);
|
||||
|
||||
|
||||
if (tcp.Connected)
|
||||
{
|
||||
net = tcp.GetStream();
|
||||
@@ -211,10 +210,10 @@ namespace RuriLib
|
||||
}
|
||||
|
||||
// Save the TCP client and the streams
|
||||
data.TCPClient = tcp;
|
||||
data.NETStream = net;
|
||||
data.SSLStream = ssl;
|
||||
data.TCPSSL = UseSSL;
|
||||
data.CustomObjects["TCPClient"] = tcp;
|
||||
data.CustomObjects["NETStream"] = net;
|
||||
data.CustomObjects["SSLStream"] = ssl;
|
||||
data.CustomObjects["TCPSSL"] = UseSSL;
|
||||
|
||||
data.Log(new LogEntry($"Succesfully connected to host {h} on port {p}. The server says:", Colors.Green));
|
||||
data.Log(new LogEntry(response, Colors.GreenYellow));
|
||||
@@ -304,7 +303,8 @@ namespace RuriLib
|
||||
}
|
||||
data.Log(new LogEntry("> " + msg, Colors.White));
|
||||
|
||||
if (data.TCPSSL)
|
||||
var TCPSSL = data.GetCustomObject("TCPSSL") as bool?;
|
||||
if (TCPSSL.HasValue && TCPSSL.Value)
|
||||
{
|
||||
ssl.Write(b);
|
||||
bytes = ssl.Read(buffer, 0, buffer.Length);
|
||||
|
||||
+12
-11
@@ -65,18 +65,9 @@ namespace RuriLib
|
||||
|
||||
/// <summary>Whether the browser is open or not.</summary>
|
||||
public bool BrowserOpen { get; set; }
|
||||
|
||||
/// <summary>The TCP Client used for TCP blocks.</summary>
|
||||
public TcpClient TCPClient { get; set; }
|
||||
|
||||
/// <summary>The NET Stream used for TCP blocks with unencrypted connection.</summary>
|
||||
public NetworkStream NETStream { get; set; }
|
||||
|
||||
/// <summary>The SSL Stream used for TCP blocks with encrypted connection.</summary>
|
||||
public SslStream SSLStream { get; set; }
|
||||
|
||||
/// <summary>Whether to use SSL for the current TCPClient.</summary>
|
||||
public bool TCPSSL { get; set; } = true;
|
||||
/// <summary>A dictionary of object that can be used for keeping session-based objects through different blocks.</summary>
|
||||
public Dictionary<string, object> CustomObjects { get; set; }
|
||||
|
||||
/// <summary>The wrapped data line that needs to be checked.</summary>
|
||||
public CData Data { get; set; }
|
||||
@@ -230,5 +221,15 @@ namespace RuriLib
|
||||
{
|
||||
LogBuffer.Add(new LogEntry("", Colors.White));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a custom object from the
|
||||
/// </summary>
|
||||
/// <param name="key">The key of the object in the dictionary</param>
|
||||
/// <returns>The object or null if the key was not found</returns>
|
||||
public object GetCustomObject(string key)
|
||||
{
|
||||
return CustomObjects.ContainsKey(key) ? CustomObjects[key] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user