-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCsgoListenerObject.cs
101 lines (87 loc) · 2.59 KB
/
CsgoListenerObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Net;
using System.Net.Sockets;
namespace remote_csgo
{
public class CsgoListenerObject
{
public TcpClient Client = new TcpClient();
public NetworkStream NetStream;
public string Hostname { get; set; }
public int Port { get; set; }
public bool Closed = false;
public void SendMessage(string Message)
{
try
{
Byte[] DataBytes = System.Text.Encoding.ASCII.GetBytes(Message + "\r");
if (NetStream.CanWrite)
{
NetStream.Write(DataBytes, 0, DataBytes.Length);
}
} catch (Exception e)
{
}
}
public void ListenerThread()
{
while (true)
{
if (Client == null || Closed)
{
break;
}
else
{
if (NetStream.DataAvailable)
{
Byte[] DataBytes = new Byte[256];
String responseData = String.Empty;
Int32 bytes = NetStream.Read(DataBytes, 0, DataBytes.Length);
responseData = System.Text.Encoding.ASCII.GetString(DataBytes, 0, bytes);
MainForm.AppendConsoleThread(this, responseData);
Console.WriteLine("Received: {0}", responseData);
}
}
Thread.Sleep(1);
}
}
public void CloseConnection()
{
Closed = true;
Client.Close();
}
public void Init()
{
try
{
Client.Connect(new IPEndPoint(IPAddress.Parse(Hostname), Port));
NetStream = Client.GetStream();
Thread Listener = new Thread(ListenerThread);
Listener.SetApartmentState(ApartmentState.STA);
Listener.Start();
}
catch (Exception){
}
}
public CsgoListenerObject()
{
Init();
}
public CsgoListenerObject(ScanObject Input)
{
this.Hostname = Input.Hostname;
this.Port = Input.Port;
Init();
}
public override string ToString()
{
return Hostname + ":" + Port;
}
}
}