forked from PenisBlistashiq/Rust-plugins-236-240-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAAlertRaid.cs
More file actions
1312 lines (1128 loc) · 63 KB
/
Copy pathAAlertRaid.cs
File metadata and controls
1312 lines (1128 loc) · 63 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using UnityEngine;
using CompanionServer;
using Oxide.Ext.Discord;
using Oxide.Ext.Discord.Attributes;
using Oxide.Ext.Discord.Entities.Messages;
using Oxide.Ext.Discord.Entities.Channels;
using Oxide.Ext.Discord.Entities.Guilds;
using Oxide.Ext.Discord.Entities.Gatway;
using Oxide.Ext.Discord.Entities.Gatway.Events;
using Oxide.Ext.Discord.Entities.Messages.Embeds;
using Oxide.Ext.Discord.Entities.Permissions;
using Oxide.Ext.Discord.Entities;
using System.Text.RegularExpressions;
using Oxide.Ext.Discord.Builders.MessageComponents;
using Oxide.Ext.Discord.Entities.Interactions.MessageComponents;
using Oxide.Ext.Discord.Entities.Interactions;
using Oxide.Ext.Discord.Entities.Users;
using Oxide.Core.Libraries.Covalence;
using ru = Oxide.Game.Rust;
using ConVar;
namespace Oxide.Plugins
{
[Info("AAlertRaid", "fermens", "0.0.7")]
public class AAlertRaid : RustPlugin
{
#region CONFIG
const bool fermensEN = false;
private static PluginConfig config;
protected override void LoadDefaultConfig()
{
config = PluginConfig.DefaultConfig();
}
protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<PluginConfig>();
}
protected override void SaveConfig()
{
Config.WriteObject(config);
}
class VK
{
[JsonProperty(fermensEN ? "Enable?" : "Включить?")]
public bool enable;
[JsonProperty(fermensEN ? "API" : "API от группы")]
public string api;
[JsonProperty(fermensEN ? "Cooldown for sending" : "Кд на отправку")]
public float cooldown;
}
class RUSTPLUS
{
[JsonProperty(fermensEN ? "Enable?" : "Включить?")]
public bool enable;
[JsonProperty(fermensEN ? "Cooldown for sending" : "Кд на отправку")]
public float cooldown;
}
class INGAME
{
[JsonProperty(fermensEN ? "Enable?" : "Включить?")]
public bool enable;
[JsonProperty(fermensEN ? "Cooldown for sending" : "Кд на отправку")]
public float cooldown;
[JsonProperty(fermensEN ? "Send game effect when notification are received" : "Эффект при получении уведомления")]
public string effect;
[JsonProperty(fermensEN ? "Time after the UI is destroyed" : "Время, через которое пропадает UI [секунды]")]
public float destroy;
[JsonProperty("UI")]
public string UI;
}
class DISCORD
{
[JsonProperty(fermensEN ? "Enable?" : "Включить?")]
public bool enable;
[JsonProperty(fermensEN ? "Cooldown for sending" : "Кд на отправку")]
public float cooldown;
[JsonProperty(fermensEN ? "Token (https://discordapp.com/developers/applications)" : "Токен бота (https://discordapp.com/developers/applications)")]
public string token;
[JsonProperty(fermensEN ? "Channel ID, where the player will take the code to confirm the profile" : "ID канала, гле игрок будет брать код, для подтверджения профиля")]
public string channel;
[JsonProperty(fermensEN ? "Info text" : "Дискорд канал с получением кода - текст")]
public string channeltext;
[JsonProperty(fermensEN ? "Info text - line color on the left" : "Дискорд канал с получением кода - цвет линии слева (https://gist.github.com/thomasbnt/b6f455e2c7d743b796917fa3c205f812#file-code_colors_discordjs-md)")]
public uint channelcolor;
[JsonProperty(fermensEN ? "Text on button" : "Дискорд канал с получением кода - кнопка")]
public string channelbutton;
[JsonProperty(fermensEN ? "Reply after button click" : "Дискорд канал с получением кода - ответ")]
public string channelex;
[JsonProperty(fermensEN ? "Don't touch this field" : "Дискорд канал с получением кода - ID сообщения (не трогаем! сам заполнится!)")]
public string channelmessageid;
}
class TELEGRAM
{
[JsonProperty(fermensEN ? "Enable?" : "Включить?")]
public bool enable;
[JsonProperty(fermensEN ? "Cooldown for sending" : "Кд на отправку")]
public float cooldown;
[JsonProperty(fermensEN ? "Bot tag" : "Тэг бота")]
public string bottag;
[JsonProperty(fermensEN ? "Token" : "Токен")]
public string token;
}
class UIMenu
{
[JsonProperty(fermensEN ? "Background color" : "Цвет фона")]
public string background;
[JsonProperty(fermensEN ? "Strip color" : "Цвет полоски")]
public string stripcolor;
[JsonProperty(fermensEN ? "Rectangular container background color" : "Цвет фона прямоугольного контейнера")]
public string rectangularcolor;
[JsonProperty(fermensEN ? "Button text color" : "Цвет текста в кнопке")]
public string buttoncolortext;
[JsonProperty(fermensEN ? "Text color" : "Цвет текста")]
public string textcolor;
[JsonProperty(fermensEN ? "Green button color" : "Цвет зелёной кнопки")]
public string greenbuttoncolor;
[JsonProperty(fermensEN ? "Red button color" : "Цвет красной кнопки")]
public string redbuttoncolor;
[JsonProperty(fermensEN ? "Gray button color" : "Цвет серой кнопки")]
public string graybuttoncolor;
[JsonProperty(fermensEN ? "Header text color" : "Цвет текста заголовка")]
public string headertextcolor;
[JsonProperty(fermensEN ? "Error text color" : "Цвет текста ошибки")]
public string errortextcolor;
[JsonProperty(fermensEN ? "Text color of <exit> and <back> buttons" : "Цвет текста кнопок <выход> и <назад>")]
public string colortextexit;
[JsonProperty(fermensEN ? "Rectangular container text color" : "Цвет текст прямоугольного контейнера")]
public string rectangulartextcolor;
[JsonProperty(fermensEN ? "The color of the text with hints at the bottom of the screen" : "Цвет текста с подсказками внизу экрана")]
public string hintstextcolor;
[JsonProperty(fermensEN ? "Abbreviations and their colors" : "Аббревиатуры и их цвета")]
public UIMainMenu uIMainMenu;
}
class UIMainMenu
{
[JsonProperty(fermensEN ? "Abbreviation for telegram" : "Аббревиатура для телеграма")]
public string abr_telegram;
[JsonProperty(fermensEN ? "Telegram icon color" : "Цвет иконки телеграма")]
public string color_telegram;
[JsonProperty(fermensEN ? "Abbreviation for vk.com" : "Аббревиатура для вконтакте")]
public string abr_vk;
[JsonProperty(fermensEN ? "Vk.com icon color" : "Цвет иконки вконтакте")]
public string color_vk;
[JsonProperty(fermensEN ? "Abbreviation for rust+" : "Аббревиатура для rust+")]
public string abr_rustplus;
[JsonProperty(fermensEN ? "Rust+ icon color" : "Цвет иконки rust+")]
public string color_rustplus;
[JsonProperty(fermensEN ? "Abbreviation for discord" : "Аббревиатура для дискорда")]
public string abr_discord;
[JsonProperty(fermensEN ? "Discord icon color" : "Цвет иконки дискорда")]
public string color_discord;
[JsonProperty(fermensEN ? "Abbreviation for in game" : "Аббревиатура для графическое отображение в игре")]
public string abr_ui;
[JsonProperty(fermensEN ? "In game icon color" : "Цвет иконки графическое отображение в игре")]
public string color_ui;
}
private class PluginConfig
{
[JsonProperty(fermensEN ? "Server name, will using for alerts" : "Название сервера - для оповещений")]
public string servername;
[JsonProperty(fermensEN ? "Raid alert works only for those who have permission" : "Оповещение о рейде работает только для тех, у кого есть разрешение")]
public bool needpermission;
[JsonProperty(fermensEN ? "VK.com" : "Оповещание о рейде в ВК")]
public VK vk;
[JsonProperty(fermensEN ? "Rust+" : "Оповещание о рейде в Rust+")]
public RUSTPLUS rustplus;
[JsonProperty(fermensEN ? "In game" : "Оповещание о рейде в игре")]
public INGAME ingame;
[JsonProperty(fermensEN ? "Discord" : "Оповещание о рейде в дискорд")]
public DISCORD discord;
[JsonProperty(fermensEN ? "Telegram" : "Оповещание о рейде в телеграм")]
public TELEGRAM telegram { get; set; } = new TELEGRAM
{
token = "",
cooldown = 1200f,
enable = true,
bottag = "@haxlite_bot"
};
[JsonProperty(fermensEN ? "Menu UI" : "Настройка UI")]
public UIMenu ui { get; set; } = new UIMenu
{
background = "0.07843138 0.06666667 0.1098039 0.9490196",
stripcolor = "0.8784314 0.9843137 1 0.5686275",
rectangularcolor = "0.8901961 0.8901961 0.8901961 0.4156863",
graybuttoncolor = "0.8901961 0.8901961 0.8901961 0.4156863",
buttoncolortext = "1 1 1 0.9056942",
rectangulartextcolor = "1 1 1 0.7843137",
textcolor = "1 1 1 1",
headertextcolor = "1 1 1 1",
hintstextcolor = "1 1 1 0.6699298",
greenbuttoncolor = "0.5450981 1 0.6941177 0.509804",
errortextcolor = "1 0.5429931 0.5429931 0.787812",
colortextexit = "0.5938045 0.5789595 0.5789595 1",
redbuttoncolor = "1 0.5450981 0.5450981 0.509804",
uIMainMenu = new UIMainMenu
{
abr_discord = "DS",
abr_rustplus = "R+",
abr_telegram = "TG",
abr_ui = "UI",
abr_vk = "VK",
color_discord = "0.6313726 0.5764706 1 0.4156863",
color_rustplus = "1 0.5803921 0.6013725 0.4156863",
color_vk = "0.5803922 0.6627451 1 0.4156863",
color_ui = "1 0.7843137 0.5764706 0.4156863",
color_telegram = "0.5479987 0.9459876 1 0.4156863"
}
};
[JsonProperty(fermensEN ? "Additional list" : "Дополнительный список предметов, которые учитывать")]
public string[] spisok;
[JsonProperty(fermensEN ? "Notification when usual items are destroyed" : "Оповещение при уничтожении обычных предметов")]
public bool extralist;
public static PluginConfig DefaultConfig()
{
return new PluginConfig()
{
servername = "HaxLite X10",
vk = new VK
{
api = "",
cooldown = 1200f,
enable = true,
},
rustplus = new RUSTPLUS
{
cooldown = 600f,
enable = true
},
ingame = new INGAME
{
cooldown = 60f,
enable = true,
effect = "assets/prefabs/weapons/toolgun/effects/repairerror.prefab",
destroy = 4f,
UI = "[{\"name\":\"UIA\",\"parent\":\"Overlay\",\"components\":[{\"type\":\"UnityEngine.UI.RawImage\",\"material\":\"assets/content/ui/uibackgroundblur.mat\", \"sprite\":\"assets/content/ui/ui.background.transparent.linearltr.tga\",\"color\":\"0 0 0 0.6279221\"},{\"type\":\"RectTransform\",\"anchormin\":\"1 0.5\",\"anchormax\":\"1 0.5\",\"offsetmin\":\"-250 -30\",\"offsetmax\":\"0 30\"}]},{\"name\":\"D\",\"parent\":\"UIA\",\"components\":[{\"type\":\"UnityEngine.UI.Image\",\"color\":\"1 0 0 0.392904\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 0\",\"offsetmin\":\"0 0\",\"offsetmax\":\"0 5\"}]},{\"name\":\"T\",\"parent\":\"UIA\",\"components\":[{\"type\":\"UnityEngine.UI.Text\",\"text\":\"{text}\",\"fontSize\":12,\"align\":\"MiddleLeft\",\"color\":\"1 1 1 0.8644356\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmin\":\"5 0\",\"offsetmax\":\"-5 0\"}]},{\"name\":\"U\",\"parent\":\"UIA\",\"components\":[{\"type\":\"UnityEngine.UI.Image\",\"color\":\"1 0 0 0.3921569\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 1\",\"anchormax\":\"1 1\",\"offsetmin\":\"0 -5\",\"offsetmax\":\"0 0\"}]}]"
},
discord = new DISCORD
{
cooldown = 600f,
enable = true,
token = "",
channel = "",
channelbutton = fermensEN ? "Get code" : "Получить код",
channelex = fermensEN ? "Your code: {code}" : "Ваш код: {code}",
channelmessageid = "",
channeltext = fermensEN ? "Enter the received code in the integration menu for raid alerts.\nChat command /raid\nEnter it in the game itself, not in the discord!" : "Введите полученый код в меню интеграции дискорда с игровым профилем.\nЧат команда /raid\nВводить в самой игре, а не в дискорде!",
channelcolor = 14177041
},
spisok = _spisok
};
}
}
private static string[] _spisok = new string[] { "wall.external.high", "wall.external.high.stone", "gates.external.high.wood", "gates.external.high.stone", "wall.window.bars.metal", "wall.window.bars.toptier", "wall.window.glass.reinforced", "wall.window.bars.wood" };
#endregion
#region DISCORD
private readonly DiscordSettings _discordSettings = new DiscordSettings();
private DiscordGuild _guild;
[DiscordClient] DiscordClient Client;
private void CreateClient()
{
_discordSettings.ApiToken = config.discord.token;
_discordSettings.Intents = GatewayIntents.GuildMessages | GatewayIntents.DirectMessages | GatewayIntents.Guilds | GatewayIntents.GuildMembers;
_discordSettings.LogLevel = Ext.Discord.Logging.DiscordLogLevel.Error;
Client.Connect(_discordSettings);
timer.Once(5f, () =>
{
if (Client == null)
{
CreateClient();
Debug.Log("Discord reconnecting in 5 sec...");
}
else
{
DiscordChannel channel;
if (!_guild.Channels.TryGetValue(new Snowflake(config.discord.channel), out channel))
{
Debug.Log(fermensEN ? $"CHANNEL NOT FOUND! ({_guild.Channels.Count})" : $"КАНАЛ НЕ СУЩЕСТВУЕТ! ({_guild.Channels.Count})");
return;
}
var embeds = new List<DiscordEmbed> { new DiscordEmbed { Color = new DiscordColor(config.discord.channelcolor), Description = config.discord.channeltext } };
var components = CreateComponents(config.discord.channelbutton);
if (!string.IsNullOrEmpty(config.discord.channelmessageid))
{
channel.GetChannelMessage(Client, new Snowflake(config.discord.channelmessageid), message =>
{
message.Embeds = embeds;
message.Components.Clear();
message.Components = components;
message.EditMessage(Client);
},
error =>
{
if (error.HttpStatusCode == 404)
{
Debug.Log("all ok");
channel?.CreateMessage(Client, new MessageCreate { Embeds = embeds, Components = components }, message =>
{
config.discord.channelmessageid = message.Id;
SaveConfig();
});
}
});
}
else
{
channel?.CreateMessage(Client, new MessageCreate { Embeds = embeds, Components = components },
message =>
{
config.discord.channelmessageid = message.Id;
SaveConfig();
});
}
}
});
}
private void OnDiscordInteractionCreated(DiscordInteraction interaction)
{
if (interaction.Type != InteractionType.MessageComponent)
{
return;
}
if (!interaction.Data.ComponentType.HasValue || interaction.Data.ComponentType.Value != MessageComponentType.Button || interaction.Data.CustomId != $"{Name}_{ConVar.Server.ip}_{ConVar.Server.port}")
{
return;
}
DiscordUser user = interaction.User ?? interaction.Member?.User;
HandleAcceptLinkButton(interaction, user);
}
private void HandleAcceptLinkButton(DiscordInteraction interaction, DiscordUser user)
{
string num;
if (!DISCORDCODES.TryGetValue(user.Id.Id, out num))
{
num = DISCORDCODES[user.Id.Id] = RANDOMNUM();
}
string linkMessage = Formatter.ToPlaintext(config.discord.channelex.Replace("{code}", num));
interaction.CreateInteractionResponse(Client, new InteractionResponse
{
Type = InteractionResponseType.ChannelMessageWithSource,
Data = new InteractionCallbackData
{
Content = linkMessage,
Flags = MessageFlags.Ephemeral
}
});
}
private void OnDiscordGatewayReady(GatewayReadyEvent ready)
{
_guild = ready.Guilds.FirstOrDefault().Value;
Debug.Log(fermensEN ? $"DISCORD BOT CONNECTED TO ID{_guild.Id}." : $"DISCORD БОТ АВТОРИЗОВАН НА СЕРВЕРЕ ID{_guild.Id}.");
}
private void CloseClient()
{
if (Client != null) Client.Disconnect();
}
private void CREATECHANNEL(string dsid, string text)
{
Snowflake ss = new Snowflake(dsid);
if (!_guild.Members.Any(x => x.Value.User.Id == ss)) return;
_guild.Members.First(x => x.Value.User.Id == ss).Value.User.SendDirectMessage(Client, new MessageCreate { Content = text });
}
private void SENDMESSAGE(string dsid, string text)
{
DiscordChannel channel = _guild.GetChannel(dsid);
if (channel != null)
{
channel?.CreateMessage(Client, text);
}
else
{
CREATECHANNEL(dsid, text);
}
}
public List<ActionRowComponent> CreateComponents(string button)
{
MessageComponentBuilder builder = new MessageComponentBuilder();
builder.AddActionButton(ButtonStyle.Success, button, $"{Name}_{ConVar.Server.ip}_{ConVar.Server.port}", false);
return builder.Build();
}
private readonly List<Regex> _regexTags = new List<Regex>
{
new Regex("<color=.+?>", RegexOptions.Compiled),
new Regex("<size=.+?>", RegexOptions.Compiled)
};
private readonly List<string> _tags = new List<string>
{
"</color>",
"`",
"</size>",
"<i>",
"</i>",
"<b>",
"</b>"
};
private string STRIP(string original)
{
if (string.IsNullOrEmpty(original))
{
return string.Empty;
}
foreach (string tag in _tags)
{
original = original.Replace(tag, "");
}
foreach (Regex regexTag in _regexTags)
{
original = regexTag.Replace(original, "");
}
return original;
}
private DiscordChannel GetChannel(string id)
{
return _guild.Channels.FirstOrDefault(x => x.Key.ToString() == id).Value;
}
#endregion
#region STORAGE
string connect = "14.02.22:1406";
//{fon}
string FON = "";
string MAIN = "";
string UI = "";
string IF2 = "";
string IF2A = "";
string BTN = "";
string ER = "";
string IBLOCK = "";
string MAINH = "";
string AG = "";
string EXIT = "";
string BACK = "";
#region Data
class Storage
{
public string vk;
public string telegram;
public ulong discord;
public bool rustplus;
public bool ingame;
}
#region fermens#8767
#endregion
private Storage GetStorage(ulong userid)
{
Storage storage;
if (datas.TryGetValue(userid, out storage)) return storage;
string useridstring = userid.ToString();
if (!Interface.Oxide.DataFileSystem.ExistsDatafile($"AAlertRaid/{useridstring}"))
{
storage = new Storage();
datas.Add(userid, storage);
return storage;
}
storage = Interface.Oxide.DataFileSystem.ReadObject<Storage>($"AAlertRaid/{useridstring}");
datas.Add(userid, storage);
return storage;
}
private void SaveStorage(BasePlayer player)
{
Storage storage;
if (datas.TryGetValue(player.userID, out storage))
{
ServerMgr.Instance.StartCoroutine(Saving(player.UserIDString, storage));
}
}
private IEnumerator Saving(string userid, Storage storage)
{
yield return new WaitForSeconds(1f);
Interface.Oxide.DataFileSystem.WriteObject($"AAlertRaid/{userid}", storage);
}
Dictionary<ulong, Storage> datas = new Dictionary<ulong, Storage>();
#endregion
#endregion
#region API TELEGRAM
private void GetRequestTelegram(string reciverID, string msg, BasePlayer player = null, bool accept = false) => webrequest.Enqueue($"https://api.telegram.org/bot" + config.telegram.token + "/sendMessage?chat_id=" + reciverID + "&text=" + Uri.EscapeDataString(msg), null, (code2, response2) => ServerMgr.Instance.StartCoroutine(GetCallbackTelegram(code2, response2, reciverID, player, accept)), this);
private IEnumerator GetCallbackTelegram(int code, string response, string id, BasePlayer player = null, bool accept = false)
{
if (player == null || response == null) yield break;
if (code == 401)
{
Debug.LogError("[AlertRaid] Telegram token not valid!");
}
else if (code == 200)
{
if (!response.Contains("error_code"))
{
ALERT aLERT;
if (alerts.TryGetValue(player.userID, out aLERT))
{
aLERT.vkcodecooldown = DateTime.Now.AddMinutes(1);
}
else
{
alerts.Add(player.userID, new ALERT { telegramcodecooldown = DateTime.Now.AddMinutes(1) });
}
Storage storage = GetStorage(player.userID);
storage.telegram = id;
SaveStorage(player);
write[player.userID] = "";
OpenMenu(player, false);
}
}
else
{
SendError(player, "telegramuseridnotfound");
}
yield break;
}
#endregion
#region API VK
const string connects = "001.002.2022:1508";
class ALERT
{
public DateTime gamecooldown;
public DateTime rustpluscooldown;
public DateTime vkcooldown;
public DateTime discordcooldown;
public DateTime vkcodecooldown;
public DateTime telegramcooldown;
public DateTime telegramcodecooldown;
}
private static Dictionary<ulong, ALERT> alerts = new Dictionary<ulong, ALERT>();
class CODE
{
public string id;
public ulong gameid;
}
private Dictionary<string, CODE> VKCODES = new Dictionary<string, CODE>();
private Dictionary<ulong, string> DISCORDCODES = new Dictionary<ulong, string>();
private void GetRequest(string reciverID, string msg, BasePlayer player = null, string num = null) => webrequest.Enqueue("https://api.vk.com/method/messages.send?domain=" + reciverID + "&message=" + Uri.EscapeDataString(msg) + "&v=5.81&access_token=" + config.vk.api, null, (code2, response2) => ServerMgr.Instance.StartCoroutine(GetCallbackVK(code2, response2, reciverID, player, num)), this);
private void SendError(BasePlayer player, string key)
{
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "ER");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", ER.Replace("{e0}", GetMessage(key, player.UserIDString)));
}
private IEnumerator GetCallbackVK(int code, string response, string id, BasePlayer player = null, string num = null)
{
if (player == null) yield break;
if (response == null || code != 200)
{
ALERT alert;
if (alerts.TryGetValue(player.userID, out alert)) alert.vkcooldown = DateTime.Now;
Debug.Log("НЕ ПОЛУЧИЛОСЬ ОТПРАВИТЬ СООБЩЕНИЕ В ВК! => обнулили кд на отправку");
yield break;
}
yield return new WaitForEndOfFrame();
if (!response.Contains("error"))
{
ALERT aLERT;
if (alerts.TryGetValue(player.userID, out aLERT))
{
aLERT.vkcodecooldown = DateTime.Now.AddMinutes(1);
}
else
{
alerts.Add(player.userID, new ALERT { vkcodecooldown = DateTime.Now.AddMinutes(1) });
}
if (VKCODES.ContainsKey(num)) VKCODES.Remove(num);
VKCODES.Add(num, new CODE { gameid = player.userID, id = id });
write[player.userID] = "";
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "ER");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "BTN");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", IBLOCK);
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", BTN.Replace("{text1}", GetMessage("{text1}", player.UserIDString)).Replace("{color}", "1 1 1 0.509804"));
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", IF2.Replace("{t3}", GetMessage("{t4}", player.UserIDString)).Replace("{coma}", "").Replace("{text2}", GetMessage("{text2}", player.UserIDString)));
}
else if (response.Contains("PrivateMessage"))
{
SendError(player, "rnprivate");
}
else if (response.Contains("ErrorSend"))
{
SendError(player, "rnerror");
}
else if (response.Contains("BlackList"))
{
SendError(player, "rnblack");
}
else
{
SendError(player, "rnerror2");
}
yield break;
}
#endregion
#region COMMANDS
private string perm = "discord fermens#8767";
[PluginReference] Plugin BMenu;
private void callcommandrn(BasePlayer player, string command, string[] arg)
{
OpenMenu(player);
}
private bool HasAcces(string id)
{
if (!config.needpermission) return true;
return permission.UserHasPermission(id, perm);
}
private void OpenMenu(BasePlayer player, bool first = true)
{
if (!HasAcces(player.UserIDString))
{
player.ChatMessage(GetMessage("permission", player.UserIDString));
return;
}
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SubContent_UI");
if (first)
{
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "Main_UI");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", FON);
if (BMenu != null)
{
BMenu.Call("DestroyProfileLayers", player);
BMenu.Call("SetPage", player.userID, "raid");
BMenu.Call("SetActivePButton", player, "raid");
}
}
//0.5450981 1 0.6941177 0.509804
//{\"name\":\"Main_UI\",\"parent\":\"Overlay\",\"components\":[{\"type\":\"UnityEngine.UI.Image\",\"color\":\"0.07843138 0.06666667 0.1098039 0.9490196\",\"material\":\"assets/content/ui/uibackgroundblur.mat\"},{\"type\":\"RectTransform\",\"anchormin\":\"0 0\",\"anchormax\":\"1 1\",\"offsetmin\":\"0 0\",\"offsetmax\":\"0 0\"}]},
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", MAIN);
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "E");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", EXIT.Replace("{t7}", GetMessage("{t7}", player.UserIDString)));
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", MAINH.Replace("{a0}", GetMessage("{amain}", player.UserIDString)));
int num = 0;
Storage storage = GetStorage(player.userID);
#region VK
if (config.vk.enable && !string.IsNullOrEmpty(config.vk.api))
{
if (!string.IsNullOrEmpty(storage.vk)) AddElementUI(player, GetMessage("{element_vk}", player.UserIDString), config.ui.graybuttoncolor, GetMessage("{element_disable}", player.UserIDString), "raid.vkdelete", config.ui.uIMainMenu.abr_vk, config.ui.uIMainMenu.color_vk, num);
else AddElementUI(player, GetMessage("{element_vk}", player.UserIDString), config.ui.greenbuttoncolor, GetMessage("{element_setup}", player.UserIDString), "raid.vkadd", config.ui.uIMainMenu.abr_vk, config.ui.uIMainMenu.color_vk, num);
num++;
}
#endregion
#region Telegram
if (config.telegram.enable && !string.IsNullOrEmpty(config.telegram.token))
{
if (!string.IsNullOrEmpty(storage.telegram)) AddElementUI(player, GetMessage("{element_telegram}", player.UserIDString), config.ui.graybuttoncolor, GetMessage("{element_disable}", player.UserIDString), "raid.tgdelete", config.ui.uIMainMenu.abr_telegram, config.ui.uIMainMenu.color_telegram, num);
else AddElementUI(player, GetMessage("{element_telegram}", player.UserIDString), config.ui.greenbuttoncolor, GetMessage("{element_setup}", player.UserIDString), "raid.tgadd", config.ui.uIMainMenu.abr_telegram, config.ui.uIMainMenu.color_telegram, num);
num++;
}
#endregion
#region Rust+
if (config.rustplus.enable && !string.IsNullOrEmpty(App.serverid) && App.port > 0 && App.notifications)
{
if (!storage.rustplus) AddElementUI(player, GetMessage("{element_rustplus}", player.UserIDString), config.ui.greenbuttoncolor, GetMessage("{element_enable}", player.UserIDString), "raid.rustplus", config.ui.uIMainMenu.abr_rustplus, config.ui.uIMainMenu.color_rustplus, num);
else AddElementUI(player, GetMessage("{element_rustplus}", player.UserIDString), config.ui.graybuttoncolor, GetMessage("{element_disable}", player.UserIDString), "raid.rustplus", config.ui.uIMainMenu.abr_rustplus, config.ui.uIMainMenu.color_rustplus, num);
num++;
}
#endregion
#region InGame
if (config.ingame.enable)
{
if (!storage.ingame) AddElementUI(player, GetMessage("{element_ingame}", player.UserIDString), config.ui.greenbuttoncolor, GetMessage("{element_enable}", player.UserIDString), "raid.ingame", config.ui.uIMainMenu.abr_ui, config.ui.uIMainMenu.color_ui, num);
else AddElementUI(player, GetMessage("{element_ingame}", player.UserIDString), config.ui.graybuttoncolor, GetMessage("{element_disable}", player.UserIDString), "raid.ingame", config.ui.uIMainMenu.abr_ui, config.ui.uIMainMenu.color_ui, num);
num++;
}
#endregion
#region Discord
if (config.discord.enable && !string.IsNullOrEmpty(config.discord.token))
{
if (storage.discord == 0UL) AddElementUI(player, GetMessage("{element_discord}", player.UserIDString), config.ui.greenbuttoncolor, GetMessage("{element_setup}", player.UserIDString), "raid.discordadd", config.ui.uIMainMenu.abr_discord, config.ui.uIMainMenu.color_discord, num);
else
{
AddElementUI(player, GetMessage("{element_discord}", player.UserIDString), config.ui.graybuttoncolor, GetMessage("{element_disable}", player.UserIDString), "raid.discorddelete", config.ui.uIMainMenu.abr_discord, config.ui.uIMainMenu.color_discord, num);
}
num++;
}
#endregion
}
class C
{
public string min;
public string max;
}
Dictionary<int, C> _caddele = new Dictionary<int, C>();
private void AddElementUI(BasePlayer player, string name, string color, string button, string command, string ico, string icocolor, int num)
{
C ce;
if (!_caddele.TryGetValue(num, out ce))
{
ce = new C();
float start = 60f;
float e = 30f;
float p = 35f;
float max = start - (num * p);
ce.min = (max - e).ToString();
ce.max = max.ToString();
_caddele.Add(num, ce);
}
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", AG.Replace("{num}", num.ToString()).Replace("{id}", name).Replace("{coma}", command).Replace("{ico}", ico).Replace("{icocolor}", icocolor).Replace("{color}", color).Replace("{text1}", button).Replace("{min}", ce.min).Replace("{max}", ce.max));
}
Dictionary<ulong, string> write = new Dictionary<ulong, string>();
[ConsoleCommand("raid.input")]
void ccmdopeinput(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
string text = arg.HasArgs() ? string.Join(" ", arg.Args) : null;
write[player.userID] = text;
}
private void SendError2(BasePlayer player, string key)
{
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "BTN2");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", IF2A.Replace("{text2}", GetMessage(key, player.UserIDString)).Replace("{coma}", "").Replace("{color}", config.ui.redbuttoncolor));
timer.Once(1f, () =>
{
if (!player.IsConnected) return;
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "BTN2");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", IF2A.Replace("{text2}", GetMessage("{text2}", player.UserIDString)).Replace("{coma}", "raid.accept").Replace("{color}", config.ui.greenbuttoncolor));
});
}
#region InGame Comand
[ConsoleCommand("raid.ingame")]
void raplsgame(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
Storage storage = GetStorage(player.userID);
storage.ingame = !storage.ingame;
SaveStorage(player);
OpenMenu(player, false);
}
#endregion
#region Rust+ Comand
[ConsoleCommand("raid.rustplus")]
void rapls(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
Storage storage = GetStorage(player.userID);
storage.rustplus = !storage.rustplus;
SaveStorage(player);
OpenMenu(player, false);
}
#endregion
#region Discord command
[ConsoleCommand("raid.discordadd")]
void ccmdadiscoradd(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SubContent_UI");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "E");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", MAIN);
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", BACK.Replace("{t7}", GetMessage("{back}", player.UserIDString)));
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", UI.Replace("{t7}", GetMessage("{d7}", player.UserIDString)).Replace("{t6}", GetMessage("{d6}", player.UserIDString)).Replace("{t5}", GetMessage("{d5}", player.UserIDString)).Replace("{t4}", GetMessage("{d3}", player.UserIDString)).Replace("{t2}", GetMessage("{d2}", player.UserIDString)).Replace("{t1}", GetMessage("{d1}", player.UserIDString)).Replace("{t0}", GetMessage("{d0}", player.UserIDString)));
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", BTN.Replace("{text1}", GetMessage("{text2}", player.UserIDString)).Replace("{coma}", "raid.acceptds").Replace("{color}", config.ui.greenbuttoncolor));
}
[ConsoleCommand("raid.acceptds")]
void raidacceptds(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
//0.8901961 0.8901961 0.8901961 0.4156863
//1 0.5450981 0.5450981 0.509804
// raid.accept
string text;
if (!write.TryGetValue(player.userID, out text) || string.IsNullOrEmpty(text))
{
SendError(player, "rnnocode");
return;
}
ulong user = DISCORDCODES.FirstOrDefault(x => x.Value == text).Key;
if (user != 0UL)
{
Storage storage = GetStorage(player.userID);
storage.discord = user;
SaveStorage(player);
DISCORDCODES.Remove(user);
OpenMenu(player, false);
}
else
{
SendError(player, "rncancel");
}
}
[ConsoleCommand("raid.discorddelete")]
void vdiscorddelete(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
Storage storage = GetStorage(player.userID);
storage.discord = 0;
SaveStorage(player);
OpenMenu(player, false);
}
#endregion
#region Telegram COmand
[ConsoleCommand("raid.tgdelete")]
void rgdelete(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
Storage storage = GetStorage(player.userID);
storage.telegram = null;
SaveStorage(player);
OpenMenu(player, false);
}
[ConsoleCommand("raid.tgadd")]
void ccmdtgadd(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SubContent_UI");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "E");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", MAIN);
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", BACK.Replace("{t7}", GetMessage("{back}", player.UserIDString)));
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", UI.Replace("{t7}", GetMessage("{teleg7}", player.UserIDString)).Replace("{t6}", GetMessage("{teleg6}", player.UserIDString)).Replace("{t5}", GetMessage("{teleg5}", player.UserIDString)).Replace("{t4}", GetMessage("{teleg3}", player.UserIDString)).Replace("{t2}", GetMessage("{teleg2}", player.UserIDString).Replace("{tag}", config.telegram.bottag)).Replace("{t1}", GetMessage("{teleg1}", player.UserIDString).Replace("{tag}", config.telegram.bottag)).Replace("{t0}", GetMessage("{teleg0}", player.UserIDString)));
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", BTN.Replace("{text1}", GetMessage("{text2}", player.UserIDString)).Replace("{coma}", "raid.accepttg").Replace("{color}", config.ui.greenbuttoncolor));
}
[ConsoleCommand("raid.accepttg")]
void ccmdaccepttg(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
ALERT aLERT;
if (alerts.TryGetValue(player.userID, out aLERT) && aLERT.telegramcodecooldown > DateTime.Now)
{
SendError(player, "rnaddcooldown");
return;
}
string text;
if (!write.TryGetValue(player.userID, out text) || string.IsNullOrEmpty(text))
{
SendError(player, "telegid");
return;
}
GetRequestTelegram(text, GetMessage("telegramadd", player.UserIDString), player, true);
}
#endregion
#region Vk COmand
[ConsoleCommand("raid.vkdelete")]
void vkdelete(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
Storage storage = GetStorage(player.userID);
storage.vk = null;
SaveStorage(player);
OpenMenu(player, false);
}
[ConsoleCommand("raid.vkadd")]
void ccmdavkadd(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Player();
if (player == null) return;
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "SubContent_UI");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "DestroyUI", "E");
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", MAIN);
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", BACK.Replace("{t7}", GetMessage("{back}", player.UserIDString)));
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", UI.Replace("{t7}", GetMessage("{t7}", player.UserIDString)).Replace("{t6}", GetMessage("{t6}", player.UserIDString)).Replace("{t5}", GetMessage("{t5}", player.UserIDString)).Replace("{t4}", GetMessage("{t3}", player.UserIDString)).Replace("{t2}", GetMessage("{t2}", player.UserIDString)).Replace("{t1}", GetMessage("{t1}", player.UserIDString)).Replace("{t0}", GetMessage("{t0}", player.UserIDString)));
CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo { connection = player.net.connection }, null, "AddUI", BTN.Replace("{text1}", GetMessage("{text1}", player.UserIDString)).Replace("{coma}", "raid.send").Replace("{color}", config.ui.greenbuttoncolor));
}
[ConsoleCommand("raid.accept")]
void ccmdaccept(ConsoleSystem.Arg arg)