-
Notifications
You must be signed in to change notification settings - Fork 4
/
BotManager.cs
129 lines (103 loc) · 3.55 KB
/
BotManager.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using BrokeProtocol.Utility.Networking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using BrokeProtocol.Utility;
using Proyecto26;
using BrokeProtocol.Managers;
using BrokeProtocolClient.utils;
namespace BrokeProtocolClient.modules.exploit.botter
{
class BotManager
{
Mode mode = Mode.Auto;
private readonly HashSet<RequestHelper> requestHelpers = new HashSet<RequestHelper>();
public List<Bot> Bots = new List<Bot>();
public BotManager()
{
}
public void AddBot(Bot bot, string hostname, ushort port)
{
bot.manager = this;
Bots.Add(bot);
bot.Connect(hostname, port);
}
public void DisconnectAll()
{
Bots.ForEach(bot => { bot.Disconnect(); Bots.Remove(bot); });
}
public void DisconnectByName(string username)
{
Bots.Where(bot => bot.username == username).ToList().ForEach(bot => { bot.Disconnect(); Bots.Remove(bot); });
}
public void SendMessageAll(string message)
{
Bots.ForEach(bot => bot.SendGlobalMessage(message));
}
public void SendMessageByName(string username, string message)
{
Bots.Where(bot => bot.username == username).ToList().ForEach(bot => bot.SendGlobalMessage(message));
}
public void Login(string username)
{
Bots.Where(bot => bot.username == username).ToList().ForEach(bot => bot.Login());
}
public void LoginAll()
{
Bots.ForEach(bot => bot.Login());
}
public void Register(string username)
{
Bots.Where(bot => bot.username == username).ToList().ForEach(bot => bot.Register());
}
public void RegisterAll()
{
Bots.ForEach(bot => bot.Register());
}
public void ConnectRandomServer(Bot bot)
{
string url = "https://brokeprotocol.com/servers.json";
RequestHelper helper = new RequestHelper { Uri = url.RandomURL() };
requestHelpers.Add(helper);
RestClient.Get(helper).Then(delegate (ResponseHelper response)
{
List<ServerData> sertverList = JsonConvert.DeserializeObject<List<ServerData>>(response.Text.Trim());
int iteration = 0;
ServerData server;
do
{
if (iteration > 100)
{
ConsoleBase.WriteLine($"[-] Server not found");
return;
}
iteration++;
server = Utils.RandomFromList(sertverList);
}
while (server.Whitelist);
AddBot(bot, server.IP, server.Port);
})
.Catch(delegate (Exception e)
{
ConsoleBase.WriteLine($"Error getting servers: { (e != null ? e.ToString() : "Unknown") }");
})
.Finally(delegate () { requestHelpers.Remove(helper); });
}
public void SetMode(Mode mode)
{
this.mode = mode;
}
public bool IsMode(Mode mode)
{
return this.mode == mode;
}
public enum Mode
{
Auto,
Manual
}
}
}