@@ -20,6 +20,8 @@ class AutoCode : RustPlugin
20
20
private Data data ;
21
21
private Dictionary < BasePlayer , TempCodeLockInfo > tempCodeLocks ;
22
22
23
+ private const string HiddenCode = "****" ;
24
+
23
25
#region Hooks
24
26
25
27
void Init ( )
@@ -117,14 +119,13 @@ void OnEntitySpawned(CodeLock codeLock)
117
119
// Lock the lock.
118
120
codeLock . SetFlag ( BaseEntity . Flags . Locked , true ) ;
119
121
120
- // Don't display code if in streamer mode.
121
- if ( ! player . net . connection . info . GetBool ( "global.streamermode" ) )
122
+ if ( ! settings . quietMode )
122
123
{
123
124
Message (
124
125
player ,
125
126
string . Format (
126
127
lang . GetMessage ( "CodeAutoLocked" , this , player . UserIDString ) ,
127
- settings . code
128
+ Utils . ShouldHideCode ( player , settings ) ? HiddenCode : settings . code
128
129
)
129
130
) ;
130
131
}
@@ -159,24 +160,32 @@ object CanUseLockedEntity(BasePlayer player, CodeLock codeLock)
159
160
protected override void LoadDefaultMessages ( )
160
161
{
161
162
lang . RegisterMessages ( new Dictionary < string , string >
162
- {
163
- { "NoPermission" , "You don't have permission." } ,
164
- { "CodeAutoLocked" , "Code lock placed with code {0}." } ,
165
- { "CodeUpdated" , "Your new code is {0}." } ,
166
- { "GuestCodeUpdated" , "Your new guest code is {0}." } ,
167
- { "CodeRemoved" , "Your code has been removed." } ,
168
- { "GuestCodeRemoved" , "Your guest code has been removed." } ,
169
- { "InvalidArgsTooMany" , "Too many arguments supplied." } ,
170
- { "Info" , "Code: {0}\n Guest Code: {1}\n \n Usage: {2}" } ,
171
- { "NotSet" , "Not set." } ,
172
- { "SyntaxError" , "Syntax Error: expected command in the form:\n {0}" } ,
173
- { "SpamPrevention" , "Too many recent code sets. Please wait {0} and try again." } ,
174
- { "InvalidArguments" , "Invalid arguments supplied." } ,
175
- { "ErrorNoPlayerFound" , "Error: No player found." } ,
176
- { "ErrorMoreThanOnePlayerFound" , "Error: More than one player found." } ,
177
- { "ResettingAllLockOuts" , "Resetting lock outs for all players." } ,
178
- { "ResettingLockOut" , "Resetting lock outs for {0}." } ,
179
- } , this ) ;
163
+ {
164
+ { "Help" , "Usage:\n {0}" } ,
165
+ { "Description" , "Automatically set the code on code locks you place.\n \n Code: {0}\n Guest Code: {1}\n Quiet Mode: {2}" } ,
166
+ { "NoPermission" , "You don't have permission." } ,
167
+ { "CodeAutoLocked" , "Code lock placed with code {0}." } ,
168
+ { "CodeAutoLockedWithGuest" , "Code lock placed with code {0} and guest code {1}." } ,
169
+ { "CodeUpdated" , "Your auto-code has changed to {0}." } ,
170
+ { "CodeUpdatedHidden" , "New auto-code set." } ,
171
+ { "GuestCodeUpdated" , "Your guest auto-code has changed to {0}." } ,
172
+ { "GuestCodeUpdatedHidden" , "New guest auto-code set." } ,
173
+ { "CodeRemoved" , "Your auto-code has been removed." } ,
174
+ { "GuestCodeRemoved" , "Your guest auto-code has been removed." } ,
175
+ { "InvalidArgsTooMany" , "Too many arguments supplied." } ,
176
+ { "NotSet" , "Not set" } ,
177
+ { "SyntaxError" , "Syntax Error: expected command in the form:\n {0}" } ,
178
+ { "SpamPrevention" , "Too many recent auto-code sets. Please wait {0} and try again." } ,
179
+ { "InvalidArguments" , "Invalid arguments supplied." } ,
180
+ { "ErrorNoPlayerFound" , "Error: No player found." } ,
181
+ { "ErrorMoreThanOnePlayerFound" , "Error: More than one player found." } ,
182
+ { "ResettingAllLockOuts" , "Resetting lock outs for all players." } ,
183
+ { "ResettingLockOut" , "Resetting lock outs for {0}." } ,
184
+ { "QuietModeEnable" , "Quiet mode now enabled.\n Less messages will be shown and your auto-code will be hidden." } ,
185
+ { "QuietModeDisable" , "Quiet mode now disabled." } ,
186
+ { "Enabled" , "Enabled" } ,
187
+ { "Disabled" , "Disabled" }
188
+ } , this ) ;
180
189
}
181
190
182
191
#endregion
@@ -210,7 +219,9 @@ public string GetCode(BasePlayer player, bool guest = false)
210
219
/// <param name="player">The player to set the code for.</param>
211
220
/// <param name="code">The code to set for the given player.</param>
212
221
/// <param name="guest">If true, the guest code will be set instead of the main code.</param>
213
- public void SetCode ( BasePlayer player , string code , bool guest = false )
222
+ /// <param name="quiet">If true, no output message will be shown to the player.</param>
223
+ /// <param name="hideCode">If true, the new code won't be displayed to the user. Has no effect if quiet is true.</param>
224
+ public void SetCode ( BasePlayer player , string code , bool guest = false , bool quiet = false , bool hideCode = false )
214
225
{
215
226
if ( ! data . Inst . playerSettings . ContainsKey ( player . userID ) )
216
227
{
@@ -255,15 +266,18 @@ public void SetCode(BasePlayer player, string code, bool guest = false)
255
266
// Locked out?
256
267
if ( lockedOut )
257
268
{
258
- Message (
259
- player ,
260
- string . Format (
261
- lang . GetMessage ( "SpamPrevention" , this , player . UserIDString ) ,
262
- TimeSpan . FromSeconds ( Math . Ceiling ( settings . lockedOutUntil - currentTime ) ) . ToString ( @"d\d\ h\h\ mm\m\ ss\s" ) . TrimStart ( ' ' , 'd' , 'h' , 'm' , 's' , '0' ) ,
263
- config . Options . SpamPrevention . LockOutTime ,
264
- config . Options . SpamPrevention . WindowTime
265
- )
266
- ) ;
269
+ if ( ! quiet )
270
+ {
271
+ Message (
272
+ player ,
273
+ string . Format (
274
+ lang . GetMessage ( "SpamPrevention" , this , player . UserIDString ) ,
275
+ TimeSpan . FromSeconds ( Math . Ceiling ( settings . lockedOutUntil - currentTime ) ) . ToString ( @"d\d\ h\h\ mm\m\ ss\s" ) . TrimStart ( ' ' , 'd' , 'h' , 'm' , 's' , '0' ) ,
276
+ config . Options . SpamPrevention . LockOutTime ,
277
+ config . Options . SpamPrevention . WindowTime
278
+ )
279
+ ) ;
280
+ }
267
281
return ;
268
282
}
269
283
@@ -286,15 +300,18 @@ public void SetCode(BasePlayer player, string code, bool guest = false)
286
300
287
301
settings . lastSet = currentTime ;
288
302
289
- // Don't display code if in streamer mode.
290
- if ( ! player . net . connection . info . GetBool ( "global.streamermode" ) )
303
+ if ( ! quiet )
291
304
{
305
+ hideCode = hideCode || Utils . ShouldHideCode ( player , settings ) ;
306
+
292
307
Message (
293
308
player ,
294
- string . Format (
295
- lang . GetMessage ( guest ? "GuestCodeUpdated" : "CodeUpdated" , this , player . UserIDString ) ,
296
- code
297
- )
309
+ hideCode
310
+ ? lang . GetMessage ( guest ? "GuestCodeUpdatedHidden" : "CodeUpdatedHidden" , this , player . UserIDString )
311
+ : string . Format (
312
+ lang . GetMessage ( guest ? "GuestCodeUpdated" : "CodeUpdated" , this , player . UserIDString ) ,
313
+ code
314
+ )
298
315
) ;
299
316
}
300
317
}
@@ -314,7 +331,8 @@ public void ToggleEnabled(BasePlayer player)
314
331
/// </summary>
315
332
/// <param name="player">The player to remove the code of.</param>
316
333
/// <param name="guest">If true, the guest code will be removed instead of the main code.</param>
317
- public void RemoveCode ( BasePlayer player , bool guest = false )
334
+ /// <param name="quiet">If true, no output message will be shown to the player.</param>
335
+ public void RemoveCode ( BasePlayer player , bool guest = false , bool quiet = false )
318
336
{
319
337
if ( ! data . Inst . playerSettings . ContainsKey ( player . userID ) )
320
338
{
@@ -332,10 +350,13 @@ public void RemoveCode(BasePlayer player, bool guest = false)
332
350
// Remove the guest code both then removing the main code and when just removing the guest code.
333
351
settings . guestCode = null ;
334
352
335
- Message (
336
- player ,
337
- lang . GetMessage ( guest ? "GuestCodeRemoved" : "CodeRemoved" , this , player . UserIDString )
338
- ) ;
353
+ if ( ! quiet )
354
+ {
355
+ Message (
356
+ player ,
357
+ lang . GetMessage ( guest ? "GuestCodeRemoved" : "CodeRemoved" , this , player . UserIDString )
358
+ ) ;
359
+ }
339
360
}
340
361
341
362
[ ObsoleteAttribute ( "This method is deprecated. Call IsValidCode instead." , false ) ]
@@ -426,6 +447,27 @@ public void OpenCodeLockUI(BasePlayer player, bool guest = false)
426
447
} ) ;
427
448
}
428
449
450
+ /// <summary>
451
+ /// Remove all lock outs caused by spam protection.
452
+ /// </summary>
453
+ /// <param name="player">The player to toggle quiet mode for.</param>
454
+ /// <param name="quiet">If true, no output message will be shown to the player.</param>
455
+ public void ToggleQuietMode ( BasePlayer player , bool quiet = false )
456
+ {
457
+ // Load the player's settings.
458
+ Data . Structure . PlayerSettings settings = data . Inst . playerSettings [ player . userID ] ;
459
+
460
+ settings . quietMode = ! settings . quietMode ;
461
+
462
+ if ( ! quiet )
463
+ {
464
+ Message (
465
+ player ,
466
+ lang . GetMessage ( settings . quietMode ? "QuietModeEnable" : "QuietModeDisable" , this , player . UserIDString )
467
+ ) ;
468
+ }
469
+ }
470
+
429
471
/// <summary>
430
472
/// Reset (remove) all lock outs caused by spam protection.
431
473
/// </summary>
@@ -719,6 +761,7 @@ public class PlayerSettings
719
761
{
720
762
public string code = null ;
721
763
public string guestCode = null ;
764
+ public bool quietMode = false ;
722
765
public double lastSet = 0 ;
723
766
public int timesSetInSpamWindow = 0 ;
724
767
public double lockedOutUntil = 0 ;
@@ -771,6 +814,7 @@ private class Commands
771
814
public string PickCode = "pick" ;
772
815
public string RandomCode = "random" ;
773
816
public string RemoveCode = "remove" ;
817
+ public string QuietMode = "quiet" ;
774
818
775
819
public Commands ( AutoCode plugin )
776
820
{
@@ -924,6 +968,27 @@ private void HandleUse(BasePlayer player, string label, string[] args)
924
968
return ;
925
969
}
926
970
971
+ // Toggle quiet mode.
972
+ if ( operation == QuietMode )
973
+ {
974
+ if ( guest )
975
+ {
976
+ SyntaxError ( player , label , args ) ;
977
+ return ;
978
+ }
979
+ if ( args . Length > 1 )
980
+ {
981
+ plugin . Message (
982
+ player ,
983
+ string . Format ( plugin . lang . GetMessage ( "InvalidArgsTooMany" , plugin , player . UserIDString ) , label )
984
+ ) ;
985
+ return ;
986
+ }
987
+
988
+ plugin . ToggleQuietMode ( player ) ;
989
+ return ;
990
+ }
991
+
927
992
// Remove?
928
993
if ( operation == RemoveCode )
929
994
{
@@ -952,7 +1017,14 @@ private void HandleUse(BasePlayer player, string label, string[] args)
952
1017
return ;
953
1018
}
954
1019
955
- plugin . SetCode ( player , plugin . GenerateRandomCode ( ) , guest ) ;
1020
+ var hideCode = false ;
1021
+ if ( plugin . data . Inst . playerSettings . ContainsKey ( player . userID ) )
1022
+ {
1023
+ Data . Structure . PlayerSettings settings = plugin . data . Inst . playerSettings [ player . userID ] ;
1024
+ hideCode = settings . quietMode ;
1025
+ }
1026
+
1027
+ plugin . SetCode ( player , plugin . GenerateRandomCode ( ) , guest , false , hideCode ) ;
956
1028
return ;
957
1029
}
958
1030
@@ -982,18 +1054,19 @@ private void ShowInfo(BasePlayer player, string label, string[] args)
982
1054
{
983
1055
string code = null ;
984
1056
string guestCode = null ;
1057
+ bool quietMode = false ;
985
1058
986
1059
if ( plugin . data . Inst . playerSettings . ContainsKey ( player . userID ) )
987
1060
{
988
1061
Data . Structure . PlayerSettings settings = plugin . data . Inst . playerSettings [ player . userID ] ;
989
1062
code = settings . code ;
990
1063
guestCode = settings . guestCode ;
1064
+ quietMode = settings . quietMode ;
991
1065
992
- // Hide codes for those in streamer mode.
993
- if ( player . net . connection . info . GetBool ( "global.streamermode" ) )
1066
+ if ( Utils . ShouldHideCode ( player , settings ) )
994
1067
{
995
- code = code == null ? null : "****" ;
996
- guestCode = guestCode == null ? null : "****" ;
1068
+ code = code == null ? null : HiddenCode ;
1069
+ guestCode = guestCode == null ? null : HiddenCode ;
997
1070
}
998
1071
}
999
1072
@@ -1028,16 +1101,18 @@ private void SyntaxError(BasePlayer player, string label, string[] args)
1028
1101
/// <returns></returns>
1029
1102
private string UsageInfo ( string label )
1030
1103
{
1031
- return string . Format ( "/{0} {1}" , label , HelpGetAllUseCommandArguments ( ) ) ;
1032
- }
1033
-
1034
- /// <summary>
1035
- /// Get all the arguments that can be supplied to the "use" command.
1036
- /// </summary>
1037
- /// <returns></returns>
1038
- private string HelpGetAllUseCommandArguments ( )
1039
- {
1040
- return string . Format ( "[{0}] {1}" , Guest , string . Join ( "|" , new string [ ] { "1234" , RandomCode , PickCode , RemoveCode } ) ) ;
1104
+ return string . Format (
1105
+ "/{0} <{1}>" ,
1106
+ label ,
1107
+ string . Join ( "|" , new string [ ] {
1108
+ string . Format (
1109
+ "[{0}] <{1}>" ,
1110
+ Guest ,
1111
+ string . Join ( "|" , new string [ ] { "1234" , PickCode , RandomCode , RemoveCode } )
1112
+ ) ,
1113
+ QuietMode
1114
+ } )
1115
+ ) ;
1041
1116
}
1042
1117
}
1043
1118
@@ -1051,6 +1126,14 @@ private static class Utils
1051
1126
/// </summary>
1052
1127
/// <returns>The number of seconds that have passed since 1970-01-01.</returns>
1053
1128
public static double CurrentTime ( ) => DateTime . UtcNow . Subtract ( new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 ) ) . TotalSeconds ;
1129
+
1130
+ /// <summary>
1131
+ /// Should the code for the given player be hidden in messages?
1132
+ /// </summary>
1133
+ public static bool ShouldHideCode ( BasePlayer player , Data . Structure . PlayerSettings settings )
1134
+ {
1135
+ return settings . quietMode || player . net . connection . info . GetBool ( "global.streamermode" ) ;
1136
+ }
1054
1137
}
1055
1138
1056
1139
/// <summary>
0 commit comments