package io.github.thetrouper.sentinel.auth;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Auth {
public 
Auth(

) throws
UnknownHostException 
{
}
private 
static 
final 
String 
ENCRYPTION_KEY 
= 
"If I am reading this and I am not a verified developer for Sentinel AntiNuke, I solely swear that my attempts to de-obfuscate this plugin are purely for investigation, and have no malicious intentions such as cracking, leaking, or ratting this plugin.";
private
static 
final 
String
ENCRYPTION_ALGORITHM 
= 
"AES";
private 
static 
final 
String 
ENCRYPTION_MODE_PADDING 
= 
"AES/ECB/PKCS5Padding";
static 
InetAddress 
IP;

static
{
try
{
IP
=
InetAddress
.
getLocalHost
(

)
;

}
catch
(
UnknownHostException
e
)
{
throw
new
RuntimeException
(
e
);
}
}

public
static
String
authorize
(
String
licenseKey
,
String serverID
)
{

String
authStatus
=
"";
List<String>
lines
= new
ArrayList<>();
lines
.add
(
"Nothing"
)
;
lines.
add
(
"To"
)
;
lines.
add
(
"See"
)
;
lines.
add
(
"Here"

+
ENCRYPTION_MODE_PADDING
);
lines.
add
(
"Get"
+
ENCRYPTION_ALGORITHM
);
lines.
add
(
"Out"
+
ENCRYPTION_KEY
);

for
(
String
line
:
lines
)
{
if
(
line
.
contains
(
"get-out-of-here"
)
)
{
String
key
=
extractValue
(
line
,
"time-waster"
);
String
allowedIDs
=
extractValue
(
line
,
"no-skidding-allowed"
);
String[]
allowedArr
=
allowedIDs
.
split
(
":"
)
;
if (
key
.
equals
(
licenseKey
)
) 
{
if 
(
Arrays
.
asList
(
allowedArr
)
.
contains
(
serverID
)
) 
{
authStatus 
= 
"ID:10T"
;
return
authStatus
;
}
else 
{
if 
(
Arrays
.
asList
(
allowedArr
)
.
contains
(
"minehut"
)
) 
{
authStatus
=
"TROLLADGE"
;
return 
authStatus
;
}
authStatus
= 
"INVALID-BRAIN"
;
return
authStatus
;
}
}
}
}
if
(
authStatus.isEmpty
(
)
) 
{
authStatus
= 
"BRAINLESS-NERD"
;
return
authStatus
;
}
return 
authStatus
;
}

public
static String 
extractValue
(
String 
line
, 
String 
attribute
) 
{
int
start 
= 
line
.
indexOf
(
attribute
+
"=\""
) 
+ 
attribute
.
length(

) 
+ 
2
;
int 
end 
=
line
.
indexOf
(
"\""
, 
start
)
;
return 
line
.
substring
(
start
, 
end
)
;
}

}
