-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ubivashka
authored and
Ubivashka
committed
Aug 1, 2021
1 parent
e57a31e
commit 21337e1
Showing
84 changed files
with
4,331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target/ | ||
/.classpath | ||
/.project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>me.mastercapexd</groupId> | ||
<artifactId>Auth</artifactId> | ||
<version>0.0.4-SNAPSHOT</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<repositories> | ||
<repository> | ||
<id>bungeecord-repo</id> | ||
<url>https://oss.sonatype.org/content/repositories/snapshots</url> | ||
</repository> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
<defaultGoal>clean package install</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.7.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>me.mastercapexd.auth.bungee.AuthPlugin</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
|
||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>bungeecord-api</artifactId> | ||
<version>1.17-R0.1-SNAPSHOT</version> | ||
<type>jar</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>bungeecord-api</artifactId> | ||
<version>1.17-R0.1-SNAPSHOT</version> | ||
<type>javadoc</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.U61vashka</groupId> | ||
<artifactId>VK-API-Spigot-Bungee</artifactId> | ||
<version>0.2.0-Snapshot</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mindrot</groupId> | ||
<artifactId>jbcrypt</artifactId> | ||
<version>0.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.xerial</groupId> | ||
<artifactId>sqlite-jdbc</artifactId> | ||
<version>3.36.0.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>6.0.6</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
66 changes: 66 additions & 0 deletions
66
mc-auth-fork/src/main/java/me/mastercapexd/auth/Account.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package me.mastercapexd.auth; | ||
|
||
import java.util.UUID; | ||
|
||
import me.mastercapexd.auth.utils.RandomCodeFactory; | ||
|
||
public interface Account { | ||
|
||
String getId(); | ||
|
||
IdentifierType getIdentifierType(); | ||
|
||
HashType getHashType(); | ||
|
||
UUID getUniqueId(); | ||
|
||
String getName(); | ||
|
||
String getPasswordHash(); | ||
|
||
void setPasswordHash(String passwordHash); | ||
|
||
Integer getVKId(); | ||
|
||
void setVKId(Integer id); | ||
|
||
boolean isOnline(); | ||
|
||
long getLastQuitTime(); | ||
|
||
void setLastQuitTime(long time); | ||
|
||
String getLastIpAddress(); | ||
|
||
long getLastSessionStart(); | ||
|
||
SessionResult newSession(HashType hashType, String password); | ||
|
||
SessionResult logout(long sessionDurability); | ||
|
||
boolean isSessionActive(long sessionDurability); | ||
|
||
KickResult kick(String reason); | ||
|
||
default boolean isRegistered() { | ||
return getPasswordHash() != null; | ||
} | ||
|
||
default RestoreResult restoreAccount(Integer VKuserID) { | ||
RestoreResult result = RestoreResult.ACCOUNT_VK_NOT_EQUALS; | ||
result.setPasswordHash(getPasswordHash()); | ||
if (getVKId().intValue() != VKuserID.intValue()) { | ||
return result; | ||
} | ||
String newPass = RandomCodeFactory.generateCode(7); | ||
result = RestoreResult.RESTORED; | ||
result.setPasswordHash(newPass); | ||
setPasswordHash(getHashType().hash(newPass)); | ||
return result; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
35 changes: 35 additions & 0 deletions
35
mc-auth-fork/src/main/java/me/mastercapexd/auth/AccountFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package me.mastercapexd.auth; | ||
|
||
import java.util.UUID; | ||
|
||
public interface AccountFactory { | ||
|
||
Account createAccount(String id, IdentifierType identifierType, UUID uuid, String name, HashType hashType, | ||
String password, Integer vkID, long lastQuit, String lastIp, long lastSessionStart, | ||
long sessionTime); | ||
|
||
default Account createAccount(String id, IdentifierType identifierType, UUID uuid, String name, HashType hashType, | ||
String password, String email, Integer vkId, long sessionTime) { | ||
return createAccount(id, identifierType, uuid, name, hashType, password, vkId, 0, null, 0, sessionTime); | ||
} | ||
|
||
default Account createAccount(String id, IdentifierType identifierType, UUID uuid, String name, HashType hashType, | ||
String password, Integer vkId, long sessionTime) { | ||
return createAccount(id, identifierType, uuid, name, hashType, password, vkId, 0, null, 0, sessionTime); | ||
} | ||
|
||
default Account createAccount(String id, IdentifierType identifierType, UUID uuid, String name, HashType hashType, | ||
String password, String email, long sessionTime) { | ||
return createAccount(id, identifierType, uuid, name, hashType, password, -1, 0, null, 0, sessionTime); | ||
} | ||
|
||
default Account createAccount(String id, IdentifierType identifierType, UUID uuid, String name, HashType hashType, | ||
String password, long sessionTime) { | ||
return createAccount(id, identifierType, uuid, name, hashType, password, -1, 0, null, 0, sessionTime); | ||
} | ||
|
||
default Account createAccount(String id, IdentifierType identifierType, UUID uuid, String name, HashType hashType, | ||
long sessionTime) { | ||
return createAccount(id, identifierType, uuid, name, hashType, null, -1, 0, null, 0, sessionTime); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
mc-auth-fork/src/main/java/me/mastercapexd/auth/Auth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package me.mastercapexd.auth; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.Maps; | ||
|
||
import me.mastercapexd.auth.objects.VKConfirmationEntry; | ||
import me.mastercapexd.auth.vk.accounts.VKEntryAccount; | ||
|
||
public class Auth { | ||
|
||
private static final Map<String, Account> accounts = Maps.newConcurrentMap(); | ||
private static final Map<String, Long> accountTimes = Maps.newConcurrentMap(); | ||
private static final Map<String, Integer> attempts = Maps.newConcurrentMap(); | ||
private static final Map<Integer, VKConfirmationEntry> vkConfirmationCodes = Maps.newConcurrentMap(); | ||
private static final Map<String, VKEntryAccount> enterAccounts = Maps.newConcurrentMap(); | ||
|
||
public static synchronized Collection<String> getAccountIds() { | ||
return ImmutableSet.copyOf(accounts.keySet()); | ||
} | ||
|
||
public static synchronized void addAccount(Account account) { | ||
accounts.put(account.getId(), account); | ||
accountTimes.put(account.getId(), System.currentTimeMillis()); | ||
} | ||
|
||
public static synchronized void removeAccount(String id) { | ||
accounts.remove(id); | ||
accountTimes.remove(id); | ||
attempts.remove(id); | ||
} | ||
|
||
public static synchronized boolean hasAccount(String id) { | ||
return accounts.containsKey(id); | ||
} | ||
|
||
public static synchronized Account getAccount(String id) { | ||
return accounts.getOrDefault(id, null); | ||
} | ||
|
||
public static synchronized long getJoinTime(String id) { | ||
return accountTimes.getOrDefault(id, 0L); | ||
} | ||
|
||
public static synchronized void incrementAttempts(String id) { | ||
attempts.put(id, getPlayerAttempts(id) + 1); | ||
} | ||
|
||
public static synchronized void decrementAttempts(String id) { | ||
attempts.put(id, getPlayerAttempts(id) - 1); | ||
} | ||
|
||
public static synchronized int getPlayerAttempts(String id) { | ||
return attempts.getOrDefault(id, 0); | ||
} | ||
|
||
public static synchronized void addVKConfirmationEntry(String id, Integer vkId, String code) { | ||
vkConfirmationCodes.put(vkId, new VKConfirmationEntry(id, code)); | ||
} | ||
|
||
public static synchronized void removeVKConfirmationEntry(Integer vkId) { | ||
vkConfirmationCodes.remove(vkId); | ||
} | ||
|
||
public static synchronized VKConfirmationEntry getVKConfirmationEntry(Integer vkId) { | ||
return vkConfirmationCodes.get(vkId); | ||
} | ||
|
||
public static synchronized boolean hasEntryAccount(String id) { | ||
return enterAccounts.containsKey(id); | ||
} | ||
|
||
public static synchronized boolean hasEntryAccount(Integer vkId, Integer delay) { | ||
return getEntryAccount(vkId, delay).size() > 0; | ||
} | ||
|
||
public static synchronized VKEntryAccount getEntryAccount(String id) { | ||
return enterAccounts.get(id); | ||
} | ||
|
||
public static synchronized List<VKEntryAccount> getEntryAccount(Integer vkId, Integer delay) { | ||
List<VKEntryAccount> accounts = new ArrayList<>(); | ||
for (VKEntryAccount account : enterAccounts.values()) { | ||
if (account.hasCooldownPassed(delay)) | ||
continue; | ||
if (account.getVkId().intValue() == vkId.intValue()) | ||
accounts.add(account); | ||
} | ||
return accounts; | ||
} | ||
|
||
public static synchronized VKEntryAccount getEntryAccountByButtonUUID(String buttonUUID) { | ||
for (VKEntryAccount account : enterAccounts.values()) { | ||
if (account.getButtonUuid().equals(buttonUUID)) | ||
return account; | ||
} | ||
return null; | ||
} | ||
|
||
public static synchronized void addEntryAccount(Account account, Integer vkId) { | ||
enterAccounts.put(account.getId(), new VKEntryAccount(account, vkId)); | ||
} | ||
|
||
public static synchronized void removeEntryAccount(String id) { | ||
enterAccounts.remove(id); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
mc-auth-fork/src/main/java/me/mastercapexd/auth/AuthEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package me.mastercapexd.auth; | ||
|
||
public interface AuthEngine { | ||
|
||
void start(); | ||
|
||
void stop(); | ||
} |
51 changes: 51 additions & 0 deletions
51
mc-auth-fork/src/main/java/me/mastercapexd/auth/HashType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package me.mastercapexd.auth; | ||
|
||
import org.mindrot.jbcrypt.BCrypt; | ||
|
||
import com.google.common.base.Charsets; | ||
import com.google.common.hash.Hashing; | ||
|
||
public enum HashType { | ||
|
||
MD5 { | ||
@Override | ||
public String hash(String string) { | ||
return Hashing.md5().newHasher().putString(string, Charsets.UTF_8).hash().toString(); | ||
} | ||
|
||
@Override | ||
public boolean checkHash(String string, String hash) { | ||
if (string == null || hash == null) | ||
return false; | ||
return hash(string).equals(hash); | ||
} | ||
}, | ||
SHA256 { | ||
@Override | ||
public String hash(String string) { | ||
return Hashing.sha256().newHasher().putString(string, Charsets.UTF_8).hash().toString(); | ||
} | ||
|
||
@Override | ||
public boolean checkHash(String string, String hash) { | ||
if (string == null || hash == null) | ||
return false; | ||
return hash(string).equals(hash); | ||
} | ||
}, | ||
BCRYPT { | ||
@Override | ||
public String hash(String string) { | ||
return BCrypt.hashpw(string, BCrypt.gensalt()); | ||
} | ||
|
||
@Override | ||
public boolean checkHash(String string, String hash) { | ||
return BCrypt.checkpw(string, hash); | ||
} | ||
}; | ||
|
||
public abstract String hash(String string); | ||
|
||
public abstract boolean checkHash(String string, String hash); | ||
} |
Oops, something went wrong.