-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
222 lines (183 loc) · 9.13 KB
/
Main.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using Rocket.API.Collections;
using Rocket.Core.Plugins;
using Rocket.Unturned;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Enumerations;
using Rocket.Unturned.Events;
using Rocket.Unturned.Player;
using SDG.Unturned;
using Logger = Rocket.Core.Logging.Logger;
namespace AuthMe
{
public class MQSPlugin : RocketPlugin<Config>
{
public static MQSPlugin Instance;
public PasswordDatabase PasswordDatabase { get; private set; }
public List<UnturnedPlayer> PlayersLogged = new List<UnturnedPlayer>();
public PasswordServices PasswordServices { get; private set; }
protected override void Load()
{
Instance = this;
PasswordDatabase = new PasswordDatabase();
PasswordDatabase.Reload();
PasswordServices = gameObject.AddComponent<PasswordServices>();
Logger.LogWarning("++++++++++++++++++++++++++++++++++++++");
Logger.LogWarning($"[{Name}] has been loaded! ");
Logger.LogWarning("Dev: MQS#7816");
Logger.LogWarning("Join this Discord for Support: https://discord.gg/Ssbpd9cvgp");
Logger.LogWarning("++++++++++++++++++++++++++++++++++++++");
DamageTool.damagePlayerRequested += OnPlayerDamage;
U.Events.OnPlayerConnected += player => OnPlayerConnected();
UnturnedPlayerEvents.OnPlayerChatted += OnPlayerChatted;
UnturnedPlayerEvents.OnPlayerInventoryAdded += OnInventoryAdd;
}
private void OnPlayerDamage(ref DamagePlayerParameters parameters, ref bool shouldAllow)
{
UnturnedPlayer player = UnturnedPlayer.FromCSteamID(parameters.killer);
var user = MQSPlugin.Instance.PasswordServices.database.Data.FirstOrDefault(x => x.Name.Equals(player.DisplayName));
LoggedComponent L = player.GetComponent<LoggedComponent>();
if (Instance.Configuration.Instance.RestrictDamageOnLogging)
{
if (player == null)
{
if (L.Logged == false)
{
shouldAllow = false;
}
}
else if (player != null)
{
if (L.Logged == false)
{
shouldAllow = false;
}
}
}
}
private void OnInventoryAdd(UnturnedPlayer player, InventoryGroup inventoryGroup, byte inventoryIndex, ItemJar P)
{
if (MQSPlugin.Instance.Configuration.Instance.RestrictLootOnLogging)
{
LoggedComponent L = player.GetComponent<LoggedComponent>();
if (L.Logged == false)
{
player.Inventory.removeItem((byte)inventoryGroup, inventoryIndex);
UnturnedChat.Say(player, MQSPlugin.Instance.Translate("MustBeLoggedToLoot"), true);
}
}
}
private void OnPlayerChatted(UnturnedPlayer player, ref UnityEngine.Color color, string message, EChatMode chatMode, ref bool cancel)
{
var user = MQSPlugin.Instance.PasswordServices.database.Data.FirstOrDefault(x => x.Name.Equals(player.DisplayName, StringComparison.OrdinalIgnoreCase));
LoggedComponent L = player.GetComponent<LoggedComponent>();
if (L.Logged == false)
{
if (message.StartsWith("/login".ToLower()))
{
return;
}
if (message.StartsWith("/register".ToLower()))
{
return;
}
cancel = Instance.Configuration.Instance.RestrictChatOnLogging;
UnturnedChat.Say(player, MQSPlugin.Instance.Translate("MustBeLoggedToChat"), true);
}
else if (player.DisplayName != user.Name)
{
cancel = Instance.Configuration.Instance.RestrictChatOnLogging;
UnturnedChat.Say(player, MQSPlugin.Instance.Translate("MustBeRegisteredToChat"), true);
}
}
private void OnPlayerConnected(UnturnedPlayer player)
{
var user = MQSPlugin.Instance.PasswordServices.database.Data.FirstOrDefault(x => x.Name.Equals(player.DisplayName, StringComparison.OrdinalIgnoreCase));
LoggedComponent L = player.GetComponent<LoggedComponent>();
if (user == null)
{
if (L.Logged == false)
{
player.Player.voice.allowVoiceChat = Instance.Configuration.Instance.AllowVoiceChatOnLogging;
player.Player.movement.sendPluginSpeedMultiplier(Instance.Configuration.Instance.SpeedOnLogging);
player.Player.movement.sendPluginJumpMultiplier(Instance.Configuration.Instance.JumpOnLogging);
player.Player.movement.sendPluginGravityMultiplier(Instance.Configuration.Instance.GravityOnLogging);
if (Instance.Configuration.Instance.GodModeOnLogging)
{
if (player.GodMode == false)
{
player.GodMode = !player.GodMode;
}
}
UnturnedChat.Say(player, MQSPlugin.Instance.Translate("RegisterMessage"), true);
}
}
else if (user != null)
{
if (L.Logged == false)
{
player.Player.movement.sendPluginSpeedMultiplier(0);
player.Player.movement.sendPluginJumpMultiplier(0);
player.Player.movement.sendPluginGravityMultiplier(0);
if (player.GodMode == false)
{
player.GodMode = !player.GodMode;
}
UnturnedChat.Say(player, MQSPlugin.Instance.Translate("LoginMessage"), true);
}
}
}
public void LogPlayer(UnturnedPlayer player)
{
LoggedComponent L = player.GetComponent<LoggedComponent>();
L.Logged = true;
player.Player.movement.sendPluginSpeedMultiplier(1);
player.Player.movement.sendPluginJumpMultiplier(1);
player.Player.movement.sendPluginGravityMultiplier(1);
if (player.GodMode == true)
{
player.GodMode = !player.GodMode;
}
player.Player.voice.allowVoiceChat = true;
}
protected override void Unload()
{
Instance = null;
Destroy(PasswordServices);
Logger.LogWarning("++++++++++++++++++++++++++++++++++++++");
Logger.LogWarning($"[{Name}] has been unloaded! ");
Logger.LogWarning("++++++++++++++++++++++++++++++++++++++");
PlayersLogged = null;
DamageTool.damagePlayerRequested -= OnPlayerDamage;
U.Events.OnPlayerConnected -= player => OnPlayerConnected();
UnturnedPlayerEvents.OnPlayerChatted -= OnPlayerChatted;
UnturnedPlayerEvents.OnPlayerInventoryAdded -= OnInventoryAdd;
}
public override TranslationList DefaultTranslations =>
new TranslationList
{
{ "RegisterMessage", "Register with /register [Password]" },
{ "LoginMessage", "Login with /login [Password]" },
{ "SuccesfullyLogged", "Succesfully Logged!" },
{ "SuccesfullyRegistered", "You have been registered! Use /login [Password] to log in."},
{ "WrongPassword", "The provided password is wrong." },
{ "RegisterUsage", "Usage: /register [Password]"},
{ "NameAlreadyRegistered", "This name is already registered!" },
{ "PasswordNotProvided", "You must provide a password!" },
{ "MustBeLoggedToChat", "You must be logged to use the Chat! /Login [Password]!" },
{ "MustBeLoggedToLoot", "You must be logged to loot items! /Login [Password]" },
{ "MustBeRegisteredToChat", "You must be registered to send messages! /Register [Password]!" },
{ "NotRegistered", "You are not registred. Use /register [Password]" },
{ "GlobalWipe", "Global Kicking required to reset passwords" },
{ "NotRegistered", "You are not registred. Use /register [Password]" },
{ "ResetPassUsage", "Usage: /resetpass [Old Password]" },
{ "ResetPass", "Your password has been deleted from our database. Rejoin to register" },
{ "NoPassword", "You do not have a password!" },
{ "WipePassUsage", "Usage: /wipepass [Player]" },
{ "PlayerNoPassword", "This player does not have a password!" },
{ "InvalidName", "Invalid name!" }
};
}
}