@@ -232,6 +232,44 @@ private EKeyReemeResult RedeemCDK(UnturnedPlayer player, string CDK)
232
232
233
233
private bool KeyVailed ( CDKData cdk )
234
234
{
235
+ if ( Main . Instance . Configuration . Instance . ByPassKeyVailed )
236
+ {
237
+ return true ;
238
+ }
239
+
240
+ // 密钥验证逻辑
241
+ // 首先判断载具栏是否为空字符串,如果不是,则尝试解析GUID 如果是空GUID则为无效KEY,反之尝试用尼尔森接口解析GUID,如果GUID无效,则视为无效KET
242
+ // 然后尝试解析数字ID,如果不是数字ID,则视为无效KEY
243
+ // 物品字符串验证逻辑为将物品字符串使用英文逗号分割,检查分割后的列表,如果存在非数字值,则视为无效KEY
244
+ // 数量字符串验证逻辑为,将字符串使用英文逗号分割,如果物品和数量的长度不同,则视为无效KEY
245
+ // 除此之外验证数量是否为无效值,例如超出最大值,或非数字
246
+ if ( ! string . IsNullOrEmpty ( cdk . Vehicle ) )
247
+ {
248
+ if ( Guid . TryParse ( cdk . Vehicle , out Guid result ) )
249
+ {
250
+ if ( result == Guid . Empty )
251
+ {
252
+ Logger . LogError ( string . Format ( "can't use a empty GUID in CDK:{0}" , cdk . CDK ) ) ;
253
+ return false ;
254
+ }
255
+
256
+ var gid = Assets . find ( result ) ;
257
+ if ( gid == null )
258
+ {
259
+ Logger . LogError ( string . Format ( "CDK: {0} use an invailed vehicle GUID" , cdk . CDK ) ) ;
260
+ return false ;
261
+ }
262
+ }
263
+ else
264
+ {
265
+ if ( ! ushort . TryParse ( cdk . Vehicle , out ushort vehicleID ) )
266
+ {
267
+ Logger . LogError ( string . Format ( "CDK: {0} use an invailed vehicle id" , cdk . CDK ) ) ;
268
+ return false ;
269
+ }
270
+ }
271
+ }
272
+
235
273
if ( cdk . Amount == string . Empty && cdk . Items != string . Empty )
236
274
{
237
275
var list = cdk . Items . Split ( ',' ) . ToList ( ) ;
@@ -243,39 +281,41 @@ private bool KeyVailed(CDKData cdk)
243
281
return false ;
244
282
}
245
283
}
246
- return true ;
247
284
}
248
- List < string > listitem = cdk . Items . Split ( ',' ) . ToList ( ) ;
249
- List < string > listamount = cdk . Amount . Split ( ',' ) . ToList ( ) ;
250
- if ( listitem . Count != 0 && listamount . Count != 0 )
285
+
286
+ if ( cdk . Amount != string . Empty && cdk . Items != string . Empty )
251
287
{
252
- if ( listitem . Count != listamount . Count )
253
- {
254
- Logger . LogError ( String . Format ( "CDK:{0} Items and Amount Column length not equal! " , cdk . CDK ) ) ;
255
- return false ;
256
- }
257
-
258
- for ( int i = 0 ; i < listitem . Count ; i ++ )
288
+ List < string > listitem = cdk . Items . Split ( ',' ) . ToList ( ) ;
289
+ List < string > listamount = cdk . Amount . Split ( ',' ) . ToList ( ) ;
290
+ if ( listitem . Count != 0 && listamount . Count != 0 )
259
291
{
260
- if ( ! ushort . TryParse ( listitem [ i ] , out ushort id ) )
292
+ if ( listitem . Count != listamount . Count )
261
293
{
262
- Logger . LogError ( String . Format ( "CDK:{0} has id in Items not a ushort! " , cdk . CDK ) ) ;
294
+ Logger . LogError ( String . Format ( "CDK:{0} Items and Amount Column length not equal! " , cdk . CDK ) ) ;
263
295
return false ;
264
296
}
265
- }
266
297
267
- for ( int i = 0 ; i < listamount . Count ; i ++ )
268
- {
269
- if ( ! byte . TryParse ( listamount [ i ] , out byte am ) )
298
+ for ( int i = 0 ; i < listitem . Count ; i ++ )
270
299
{
271
- Logger . LogError ( String . Format ( "CDK:{0} has amount in Amount not a byte. MAX 255!" , cdk . CDK ) ) ;
272
- return false ;
300
+ if ( ! ushort . TryParse ( listitem [ i ] , out ushort id ) )
301
+ {
302
+ Logger . LogError ( String . Format ( "CDK:{0} has id in Items not a ushort!" , cdk . CDK ) ) ;
303
+ return false ;
304
+ }
305
+ }
306
+
307
+ for ( int i = 0 ; i < listamount . Count ; i ++ )
308
+ {
309
+ if ( ! byte . TryParse ( listamount [ i ] , out byte am ) )
310
+ {
311
+ Logger . LogError ( String . Format ( "CDK:{0} has amount in Amount not a byte. MAX 255!" , cdk . CDK ) ) ;
312
+ return false ;
313
+ }
273
314
}
274
315
}
275
- return true ;
276
316
}
277
317
278
- return false ;
318
+ return true ;
279
319
}
280
320
281
321
private void ExecuteUconomy ( UnturnedPlayer player , CDKData cdkdata )
0 commit comments