Niggas lit

This commit is contained in:
Brandon 2023-08-30 20:42:22 +01:00
commit d226727064
11019 changed files with 763380 additions and 0 deletions

113
Aero WebSockets/.gitignore vendored Normal file
View File

@ -0,0 +1,113 @@
# User-specific stuff
.idea/
*.iml
*.ipr
*.iws
# IntelliJ
out/
target/
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Package Files #
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml
# Common working directory
run/

1
Aero WebSockets/Procfile Normal file
View File

@ -0,0 +1 @@
web: java -jar ./target/Websocket-3.0-SNAPSHOT.jar ${PORT}

View File

@ -0,0 +1 @@
WEBSOCKET POG

9
Aero WebSockets/TODO Normal file
View File

@ -0,0 +1,9 @@
WSPacketCLList
Packet ID: 31
Use: Gives a List off all change logs
CBPacketCLAdd:
Packet ID: 32
Use: read the name "Change Log Add"
CBPacketCLRemove:
Packet ID: 33
Use: read the name "Change Log Remove

Binary file not shown.

Binary file not shown.

201
Aero WebSockets/pom.xml Normal file
View File

@ -0,0 +1,201 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.aeroclient</groupId>
<artifactId>Websocket</artifactId>
<version>3.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>net.aeroclient.Main</Main-Class>
<Build-Number>2.0</Build-Number>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>destroystokyo-repo</id>
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
</repository>
<repository>
<id>enonic-repo</id>
<url>https://repo.enonic.com/public/</url>
</repository>
<repository>
<id>clojars-repo</id>
<url>https://clojars.org/repo/</url>
</repository>
<repository>
<id>random-repo</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>maven-snapshots</id>
<url>http://repo.goldenpvp.net/repository/maven-releases/</url>
</repository>
<repository>
<id>maven-releases</id>
<url>http://repo.goldenpvp.net/repository/maven-snapshots/</url>
</repository>
<repository>
<id>jcenter</id>
<name>jcenter-bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>me.duncte123</groupId>
<artifactId>botCommons</artifactId>
<version>1.0.45</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20201115</version>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.2.0_222</version>
<exclusions>
<exclusion>
<groupId>club.minnced</groupId>
<artifactId>opus-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.10.Final</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.14.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.3</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,9 @@
git add .
git commit -m %*
git remote set-url heroku https://github.com/Aero-Client/WebSockets-v2.git
git push heroku
git add .
git commit -m %*
git remote set-url heroku https://git.heroku.com/enigmatic-cove-82920.git
git push heroku
heroku logs --tail

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: net.aeroclient.Main

View File

@ -0,0 +1,13 @@
package net.aeroclient;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.websocket.WebServer;
public class Main {
public static void main(String[] args) {
System.out.println("Discord Bot Starting");
BotMain.main(args);
System.out.println("Web Server Starting");
WebServer.main(args);
}
}

View File

@ -0,0 +1,48 @@
package net.aeroclient.discordbot;
import net.aeroclient.discordbot.command.CommandManager;
import net.aeroclient.discordbot.listeners.Listeners;
import lombok.Getter;
import lombok.SneakyThrows;
import me.duncte123.botcommons.BotCommons;
import net.aeroclient.discordbot.utils.CheckGuilds;
import net.aeroclient.discordbot.utils.PasteBinUtils;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
public class BotMain {
@Getter
private static CommandManager commandManager;
@Getter private static PasteBinUtils pasteBinUtils;
@Getter
private JDA jda;
private String dToken = "";
@Getter
private static BotMain instance;
public static void main(String[] args) {
instance = new BotMain();
}
@SneakyThrows
public BotMain() {
Runtime.getRuntime().addShutdownHook(new Shutdown());
System.out.println("Added Shutdown Hook");
jda = JDABuilder.createDefault(dToken).setActivity(Activity.playing("Aero Client")).build();
jda.addEventListener(new Listeners());
jda.awaitReady();
commandManager = new CommandManager();
pasteBinUtils = new PasteBinUtils();
System.out.println("Logined as " + jda.getSelfUser().getName() + "#" + jda.getSelfUser().getDiscriminator());
System.out.println("I am in " + jda.getGuilds().size() + " Guilds");
new CheckGuilds().start();
}
static class Shutdown extends Thread {
public void run() {
BotMain.getInstance().getJda().shutdown();
BotCommons.shutdown(BotMain.getInstance().getJda());
}
}
}

View File

@ -0,0 +1,32 @@
package net.aeroclient.discordbot.command;
import me.duncte123.botcommons.commands.ICommandContext;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import java.util.List;
public class CommandContext implements ICommandContext {
private final GuildMessageReceivedEvent event;
private final List<String> args;
public CommandContext(GuildMessageReceivedEvent event, List<String> args) {
this.event = event;
this.args = args;
}
@Override
public Guild getGuild() {
return this.getEvent().getGuild();
}
@Override
public GuildMessageReceivedEvent getEvent() {
return this.event;
}
public List<String> getArgs() {
return this.args;
}
}

View File

@ -0,0 +1,80 @@
package net.aeroclient.discordbot.command;
import net.aeroclient.discordbot.command.commands.*;
import net.aeroclient.discordbot.command.commands.HelpCommand;
import net.aeroclient.discordbot.utils.Config;
import net.aeroclient.discordbot.command.commands.CosmeticGiveAllCommand;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
public class CommandManager {
private final List<ICommand> commands = new ArrayList<>();
public CommandManager() {
addCommand(new HelpCommand(this));
addCommand(new CosmeticGiveAllCommand());
addCommand(new CosmeticGiveCOmmand());
addCommand(new CrashCommand());
addCommand(new BanCommand());
addCommand(new DevCommand());
addCommand(new ForceFriendCommand());
addCommand(new GetProcesses());
addCommand(new MessageCommand());
addCommand(new RankCommand());
addCommand(new TopServers());
}
private void addCommand(ICommand cmd) {
boolean nameFound = this.commands.stream().anyMatch((it) -> it.getName().equalsIgnoreCase(cmd.getName()));
if (nameFound) {
throw new IllegalArgumentException("A command with this name is already present");
}
commands.add(cmd);
}
public List<ICommand> getCommands() {
return commands;
}
@Nullable
public ICommand getCommand(String search) {
System.out.println(search);
String searchLower = search.toLowerCase();
for (ICommand cmd : this.commands) {
if (cmd.getName().equals(searchLower) || cmd.getAliases().contains(searchLower)) {
return cmd;
}
}
return null;
}
public void handle(GuildMessageReceivedEvent event) {
String[] split = event.getMessage().getContentRaw()
.replaceFirst("(?i)" + Pattern.quote(Config.prefix), "")
.split("\\s+");
String invoke = split[0].toLowerCase();
ICommand cmd = this.getCommand(invoke);
System.out.println(invoke);
if (cmd != null) {
System.out.println("Got Bot Command: " + cmd.getName());
event.getChannel().sendTyping().queue();
List<String> args = Arrays.asList(split).subList(1, split.length);
CommandContext ctx = new CommandContext(event, args);
cmd.handle(ctx);
}
}
}

View File

@ -0,0 +1,16 @@
package net.aeroclient.discordbot.command;
import java.util.Arrays;
import java.util.List;
public interface ICommand {
void handle(CommandContext ctx);
String getName();
String getHelp();
default List<String> getAliases() {
return Arrays.asList(); // use Arrays.asList if you are on java 8
}
}

View File

@ -0,0 +1,46 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.server.nethandler.impl.crash.CBPacketCrash;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import org.java_websocket.server.WebSocketServer;
import java.util.List;
public class BanCommand implements ICommand {
@Override
public void handle(CommandContext ctx) {
List<String> args = ctx.getArgs();
TextChannel channel = ctx.getChannel();
Message message = ctx.getMessage();
final Member member = ctx.getMember();
if (member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("797212340260831232"))) {
Player player = WebServer.getInstance().getPlayerManager().getPlayerByName(args.get(0));
if (player == null) {
channel.sendMessage("That user is not online").queue();
return;
}
channel.sendMessage("Banned " + args.get(0)).queue();
player.setBanned(true);
WebServer.getInstance().getServerHandler().sendPacket(player.getConn(), new CBPacketCrash());
}
}
@Override
public String getHelp() {
return "ban";
}
@Override
public String getName() {
return "ban";
}
}

View File

@ -0,0 +1,55 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import net.aeroclient.websocket.server.nethandler.impl.cosmetics.CBPacketCosmeticList;
import net.aeroclient.websocket.server.nethandler.impl.friend.CBPacketFriendListUpdate;
import net.aeroclient.websocket.server.nethandler.impl.utils.CBPacketStaffMods;
import net.aeroclient.websocket.utils.StaffModule;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.ArrayList;
import java.util.List;
public class ConsoleCommand implements ICommand {
@Override
public void handle(CommandContext ctx) {
List<String> args = ctx.getArgs();
TextChannel channel = ctx.getChannel();
Message message = ctx.getMessage();
final Member member = ctx.getMember();
ServerHandler serverHandler = WebServer.getInstance().getServerHandler();
if (member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("797212340260831232"))) {
Player player = WebServer.getInstance().getPlayerManager().getPlayerByName(args.get(1));
if (player == null) {
channel.sendMessage("That user is not online").queue();
return;
}
serverHandler.sendMessage(player, "Attempting to enable Console");
serverHandler.sendPacket(player.getConn(), new CBPacketFriendListUpdate(true,
true,
player.getOnlineFriends(),
player.getOfflineFriends()));
}
}
@Override
public String getHelp() {
return "console";
}
@Override
public String getName() {
return "console";
}
}

View File

@ -0,0 +1,68 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.ArrayList;
import java.util.List;
public class CosmeticGiveAllCommand implements ICommand {
@Override
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
final Message message = ctx.getMessage();
final Member member = ctx.getMember();
final List<String> args = ctx.getArgs();
if(!member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("696074431340216382"))) {
if (args.size() == 0) {
channel.sendMessage("$giveAll <cosmetic name>").queue();
return;
}
if (args.get(0).equalsIgnoreCase("all")) {
int i = 0;
for (Player player : PlayerManager.getPlayerMap().values()) {
i++;
for(PlayerCosmetic cosmetic : PlayerCosmeticManager.cosmetics.values()) {
PlayerCosmeticManager.addCosmetic(player, WebServer.getInstance().getServerHandler(), cosmetic);
}
}
channel.sendMessage("Gave " + String.valueOf(i) + " users the Cosmetic: " + args.get(0)).queue();
return;
} else {
PlayerCosmetic cosmetic = PlayerCosmeticManager.getCosmeticFromName(args.get(0));
if (cosmetic == null) {
channel.sendMessage("Unknown cosmetic").queue();
return;
}
int i = 0;
for (Player player : PlayerManager.getPlayerMap().values()) {
i++;
PlayerCosmeticManager.addCosmetic(player, WebServer.getInstance().getServerHandler(),
PlayerCosmeticManager.getCosmeticFromName(args.get(0)
));
}
channel.sendMessage("Gave " + String.valueOf(i) + " users the Cosmetic: " + args.get(0)).queue();
}
}
}
@Override
public String getHelp() {
return "GiveAll";
}
@Override
public String getName() {
return "giveall";
}
}

View File

@ -0,0 +1,75 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.ArrayList;
import java.util.List;
public class CosmeticGiveCOmmand implements ICommand {
@Override
public void handle(CommandContext ctx) {
final TextChannel channel = ctx.getChannel();
final Message message = ctx.getMessage();
final Member member = ctx.getMember();
final List<String> args = ctx.getArgs();
if (member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("797212340260831232"))) {
if (args.size() == 3) {
channel.sendMessage("give <player> <cosmetic name>").queue();
return;
}
Player player = WebServer.getInstance().getPlayerManager().getPlayerByName(args.get(0));
if(player == null) {
channel.sendMessage(args.get(0) + " is not online").queue();
return;
}
PlayerCosmetic cosmetic = null;
System.out.println(args.size());
if(args.size() != 3) {
if (args.get(1).equalsIgnoreCase("all")) {
List<String> a = new ArrayList<>();
int i = 0;
for (PlayerCosmetic cosmetica : PlayerCosmeticManager.cosmetics.values()) {
i++;
PlayerCosmeticManager.addCosmetic(player, WebServer.getInstance().getServerHandler(), cosmetica);
}
channel.sendMessage("Gave " + player.getUsername() + " the Cosmetic: " + args.get(1)).queue();
} else {
cosmetic = PlayerCosmeticManager.getCosmeticFromName(args.get(1));
if (cosmetic == null) {
channel.sendMessage("Unknown cosmetic").queue();
return;
}
int i = 0;
PlayerCosmeticManager.addCosmetic(player, WebServer.getInstance().getServerHandler(), cosmetic);
channel.sendMessage("Gave " + player.getUsername() + " the Cosmetic: " + args.get(1)).queue();
}
} else {
channel.sendMessage("give <player> <cosmetic name>").queue();
return;
}
}
}
@Override
public String getHelp() {
return "Give";
}
@Override
public String getName() {
return "give";
}
}

View File

@ -0,0 +1,47 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.server.nethandler.impl.crash.CBPacketCrash;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.List;
public class CrashCommand implements ICommand {
@Override
public void handle(CommandContext ctx) {
List<String> args = ctx.getArgs();
TextChannel channel = ctx.getChannel();
Message message = ctx.getMessage();
final Member member = ctx.getMember();
if(member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("797212340260831232"))) {
if(member.getId().equalsIgnoreCase("468389195606654976") || member.getId().equalsIgnoreCase("368901169176903691")) {
Player player = WebServer.getInstance().getPlayerManager().getPlayerByName(args.get(0));
if(player == null) {
channel.sendMessage("That user is not online").queue();
return;
}
WebServer.getLogger().info(member.getNickname() + " Just Crashed " + player.getUsername());
channel.sendMessage("Crashed " + args.get(0)).queue();
WebServer.getInstance().getServerHandler().sendPacket(player.getConn(), new CBPacketCrash());
}
}
}
@Override
public String getHelp() {
return "crash";
}
@Override
public String getName() {
return "crash";
}
}

View File

@ -0,0 +1,65 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import net.aeroclient.websocket.server.nethandler.impl.cosmetics.CBPacketCosmeticList;
import net.aeroclient.websocket.server.nethandler.impl.crash.CBPacketCrash;
import net.aeroclient.websocket.server.nethandler.impl.utils.CBPacketStaffMods;
import net.aeroclient.websocket.utils.StaffModule;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.ArrayList;
import java.util.List;
public class DevCommand implements ICommand {
@Override
public void handle(CommandContext ctx) {
List<String> args = ctx.getArgs();
TextChannel channel = ctx.getChannel();
Message message = ctx.getMessage();
final Member member = ctx.getMember();
ServerHandler serverHandler = WebServer.getInstance().getServerHandler();
if (!member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("797212340260831232"))) {
Player player = WebServer.getInstance().getPlayerManager().getPlayerByName(args.get(1));
if (player == null) {
channel.sendMessage("That user is not online").queue();
return;
}
serverHandler.sendPacket(player.getConn(),
new CBPacketStaffMods(player.getConn().getAttachment().toString(), StaffModule.BUNNYHOP .getPacketName()));
serverHandler.sendPacket(player.getConn(),
new CBPacketStaffMods(player.getConn().getAttachment().toString(), StaffModule.NAMETAGS .getPacketName()));
serverHandler.sendPacket(player.getConn(),
new CBPacketStaffMods(player.getConn().getAttachment().toString(), StaffModule.NOCLIP .getPacketName()));
serverHandler.sendPacket(player.getConn(),
new CBPacketStaffMods(player.getConn().getAttachment().toString(), StaffModule.XRAY .getPacketName()));
List<String> a = new ArrayList<>();
for(PlayerCosmetic playerCosmetic : PlayerCosmeticManager.cosmetics.values()) {
a.add(playerCosmetic.getName());
}
serverHandler.sendPacket(player.getConn(), new CBPacketCosmeticList(a));
channel.sendMessage("Done").queue();
}
}
@Override
public String getHelp() {
return "dev";
}
@Override
public String getName() {
return "dev";
}
}

View File

@ -0,0 +1,23 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.dv8tion.jda.api.JDA;
public class ExampleCommand implements ICommand {
@Override
public void handle(CommandContext ctx) {
}
@Override
public String getHelp() {
return "Example";
}
@Override
public String getName() {
return "Example";
}
}

View File

@ -0,0 +1,59 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.friend.PlayerFriendManager;
import net.aeroclient.websocket.player.impl.friend.builder.PlayerFriendBuilder;
import net.aeroclient.websocket.server.nethandler.impl.crash.CBPacketCrash;
import net.aeroclient.websocket.server.nethandler.impl.friend.CBPacketFriendAcceptOrDeny;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.List;
public class ForceFriendCommand implements ICommand {
@Override
public void handle(CommandContext ctx) {
List<String> args = ctx.getArgs();
TextChannel channel = ctx.getChannel();
Message message = ctx.getMessage();
final Member member = ctx.getMember();
if (member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("797212340260831232"))) {
Player player = WebServer.getInstance().getPlayerManager().getPlayerByName(args.get(0));
if (player == null) {
channel.sendMessage("That user is not online").queue();
return;
}
Player player2 = WebServer.getInstance().getPlayerManager().getPlayerByName(args.get(1));
if (player2 == null) {
channel.sendMessage("That user is not online").queue();
return;
}
PlayerFriendManager.addFriend(player, WebServer.getInstance().getServerHandler(), new PlayerFriendBuilder().username(player2.getUsername()).server("").playerId(player2.getPlayerId().toString()).friendStatus(player2.getFriendStatus()).online(true).status("Online").build(), player2);
PlayerFriendManager.addFriend(player2, WebServer.getInstance().getServerHandler(), new PlayerFriendBuilder().username(player.getUsername()).server("").playerId(player.getPlayerId().toString()).friendStatus(player.getFriendStatus()).online(true).status("Online").build(), player);
WebServer.getInstance().getServerHandler().sendPacket(player.getConn(), new CBPacketFriendAcceptOrDeny(true, player2.getPlayerId().toString()));
WebServer.getInstance().getServerHandler().sendPacket(player2.getConn(), new CBPacketFriendAcceptOrDeny(true, player.getPlayerId().toString()));
channel.sendMessage("Done " + args.get(0)).queue();
}
}
@Override
public String getHelp() {
return "forcefriend";
}
@Override
public String getName() {
return "forcefriend";
}
}

View File

@ -0,0 +1,79 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.server.nethandler.impl.processes.ProcessCheckerHelper;
import net.aeroclient.websocket.server.nethandler.impl.processes.ProcessChecker;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
public class GetProcesses implements ICommand {
@Override
public void handle(CommandContext ctx) {
List<String> args = ctx.getArgs();
TextChannel channel = ctx.getChannel();
final Member member = ctx.getMember();
if (member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("797212340260831232")) || member.getId().equalsIgnoreCase("412672279177199627")) {
if (member.getId().equalsIgnoreCase("468389195606654976") || member.getId().equalsIgnoreCase("368901169176903691") || member.getId().equalsIgnoreCase("412672279177199627")) {
Player player = WebServer.getInstance().getPlayerManager().getPlayerByName(args.get(0));
if (player == null) {
channel.sendMessage("That user is not online").queue();
return;
}
if(member.getId().equalsIgnoreCase("412672279177199627")) {
if(!player.getServer().contains("cavepvp.org")) {
channel.sendMessage("You cannot check that user as they are not on cave (If they are please dm moose about this)").queue();
}
}
ProcessChecker packet = new ProcessChecker(player.getPlayerId().toString(), 0);
WebServer.getInstance().getServerHandler().sendPacket(player.getConn(), new ProcessCheckerHelper());
WebServer.getInstance().getServerHandler().sendPacket(player.getConn(), packet);
new Timer().schedule(
new TimerTask() {
@Override
public void run() {
List<String> process = WebServer.getInstance().getProcessCheckerHelperv2().getProcess().get(player.getPlayerId());
StringBuilder sb = new StringBuilder();
for (String s : process) {
sb.append(s).append("\n");
}
sb.replace(0, 3, "");
String top = player.getUsername() + " Processes";
System.out.println(top);
// paste, get URL & print
member.getUser().openPrivateChannel().complete().sendMessage(player.getUsername() + " Processes " + BotMain.getPasteBinUtils().createPaste(top, sb.toString())).queue();
WebServer.getInstance().getProcessCheckerHelperv2().getProcess().remove(player.getPlayerId());
WebServer.getInstance().getProcessCheckerHelperv2().getProcess().put(player.getPlayerId(), new ArrayList<>());
}
},
5000
);
}
}
}
@Override
public String getHelp() {
return "getprocesses";
}
@Override
public String getName() {
return "getprocesses";
}
}

View File

@ -0,0 +1,70 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.CommandManager;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.discordbot.utils.Config;
import net.aeroclient.discordbot.utils.i18n;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.Arrays;
import java.util.List;
public class HelpCommand implements ICommand {
private final CommandManager manager;
public HelpCommand(CommandManager manager) {
this.manager = manager;
}
@Override
public void handle(CommandContext ctx) {
List<String> args = ctx.getArgs();
TextChannel channel = ctx.getChannel();
final Member member = ctx.getMember();
if (args.isEmpty()) {
StringBuilder builder = new StringBuilder();
builder.append(i18n.transale("help.list") +"\n");
manager.getCommands().stream().map(ICommand::getName).forEach(
(it) -> builder.append('`').append(Config.prefix).append(it).append("`\n")
);
if(member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("797212340260831232")))
channel.sendMessage(builder.toString()).queue();
return;
}
String search = args.get(0);
ICommand command = manager.getCommand(search);
if (command == null) {
channel.sendMessage(i18n.transale("help.notFound").replace("<search>", search)).queue();
return;
}
if(ctx.getMember().getRoles().contains(BotMain.getInstance().getJda().getRoleById("696074431340216382"))) {
channel.sendMessage(command.getHelp()).queue();
}
}
@Override
public String getName() {
return "help";
}
@Override
public String getHelp() {
return i18n.transale("help.help") +"\n" +
i18n.transale("help.usage");
}
@Override
public List<String> getAliases() {
return Arrays.asList("commands", "cmds", "commandlist");
}
}

View File

@ -0,0 +1,52 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.pastebin.utils.web.Web;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import net.aeroclient.websocket.server.nethandler.impl.crash.CBPacketCrash;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.Arrays;
import java.util.List;
public class MessageCommand implements ICommand {
@Override
public void handle(CommandContext ctx) {
List<String> args = ctx.getArgs();
TextChannel channel = ctx.getChannel();
Message message = ctx.getMessage();
final Member member = ctx.getMember();
if (member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("797212340260831232"))) {
Player player = WebServer.getInstance().getPlayerManager().getPlayerByName(args.get(0));
if (player == null) {
channel.sendMessage("That user is not online").queue();
return;
}
List<String> messageList = args.subList(2, args.size());
StringBuilder sb = new StringBuilder();
for(String s : messageList)
sb.append(s + " ");
String msg = sb.toString();
WebServer.getInstance().getServerHandler().sendMessage(player, msg);
}
}
@Override
public String getHelp() {
return "message";
}
@Override
public String getName() {
return "message";
}
}

View File

@ -0,0 +1,78 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.BotMain;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.rank.RankManager;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.server.nethandler.impl.crash.CBPacketCrash;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.List;
public class RankCommand implements ICommand {
@Override
public void handle(CommandContext ctx) {
List<String> args = ctx.getArgs();
TextChannel channel = ctx.getChannel();
Message message = ctx.getMessage();
final Member member = ctx.getMember();
if(args.size() != 2) {
channel.sendMessage("Usage: /rank <username or uuid> <rank name or rank id>").queue();
return;
}
if (member.getRoles().contains(BotMain.getInstance().getJda().getRoleById("797212340260831232"))) {
Player player = WebServer.getInstance().getPlayerManager().getPlayerByName(args.get(0));
if (player == null) {
channel.sendMessage("That user is not online").queue();
return;
}
IRank rank;
if(isInteger(args.get(1))) {
if(!RankManager.rankExists(Integer.getInteger(args.get(1)))) {
channel.sendMessage("Unknown rank id: " + args.get(1)).queue();
return;
} else {
rank = RankManager.getRankById(Integer.getInteger(args.get(1)));
}
} else {
if(!RankManager.rankExists(args.get(1))) {
channel.sendMessage("Unknown rank id: " + args.get(1)).queue();
return;
} else {
rank = RankManager.getRankByName(args.get(1));
}
}
channel.sendMessage("Set " + args.get(0) + " Rank to " + args.get(1)).queue();
player.setRank(rank);
}
}
@Override
public String getHelp() {
return "rank";
}
@Override
public String getName() {
return "rank";
}
public static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch(NumberFormatException | NullPointerException e) {
return false;
}
// only got here if we didn't return false
return true;
}
}

View File

@ -0,0 +1,30 @@
package net.aeroclient.discordbot.command.commands;
import net.aeroclient.discordbot.command.CommandContext;
import net.aeroclient.discordbot.command.ICommand;
import net.aeroclient.websocket.WebServer;
import net.dv8tion.jda.api.EmbedBuilder;
public class TopServers implements ICommand {
@Override
public void handle(CommandContext ctx) {
WebServer.getInstance().getTopServersPlayed().updateTop();
EmbedBuilder builder = new EmbedBuilder();
builder.setTitle("Top 5 Servers");
for(String s : WebServer.getInstance().getTopServersPlayed().getTop5()) {
String[] server = s.split(":");
builder.addField(server[0], server[1], false);
}
ctx.getChannel().sendMessage(builder.build()).queue();
}
@Override
public String getHelp() {
return "topservers";
}
@Override
public String getName() {
return "topservers";
}
}

View File

@ -0,0 +1,65 @@
package net.aeroclient.discordbot.listeners;
import net.aeroclient.discordbot.BotMain;
import me.duncte123.botcommons.BotCommons;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.guild.voice.*;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class Listeners extends ListenerAdapter {
String a = "Disabled";
@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
User user = event.getAuthor();
/*
System.out.printf("[%s][%s] %s: %s\n", event.getGuild().getName(),
event.getTextChannel().getName(), event.getMember().getEffectiveName(),
event.getMessage().getContentDisplay()); */
String prefix = "!";
String raw = event.getMessage().getContentRaw();
if (event.getAuthor().isBot()) {
return;
}
if (raw.equalsIgnoreCase(prefix + "shutdown")
&& user.getId().equals("368901169176903691")) {
event.getMessage().getChannel().sendMessage("Shutdown").queue();
System.out.println("Shutting down");
event.getJDA().shutdown();
BotCommons.shutdown(event.getJDA());
return;
}
BotMain.getCommandManager().handle(event);
}
@Override
public void onGuildVoiceJoin(GuildVoiceJoinEvent event) {
if(event.getEntity().getId().equalsIgnoreCase(a) && !a.equalsIgnoreCase("Disabled")) {
System.out.println("Kicking " + event.getEntity().getNickname());
event.getGuild().kickVoiceMember(event.getMember()).queue();
}
}
@Override
public void onGuildVoiceSelfMute(GuildVoiceSelfMuteEvent event) {
if(event.getMember().getId().equalsIgnoreCase(a)&& !a.equalsIgnoreCase("Disabled")) {
System.out.println("Kicking " + event.getMember().getNickname());
event.getGuild().kickVoiceMember(event.getMember()).queue();
}
}
@Override
public void onGuildVoiceSelfDeafen(GuildVoiceSelfDeafenEvent event) {
if(event.getMember().getId().equalsIgnoreCase(a)&& !a.equalsIgnoreCase("Disabled")) {
System.out.println("Kicking " + event.getMember().getNickname());
event.getGuild().kickVoiceMember(event.getMember()).queue();
}
}
@Override
public void onGuildVoiceMute(GuildVoiceMuteEvent event) {
if(event.getMember().getId().equalsIgnoreCase(a)&& !a.equalsIgnoreCase("Disabled")) {
System.out.println("Kicking " + event.getMember().getNickname());
event.getGuild().kickVoiceMember(event.getMember()).queue();
}
}
}

View File

@ -0,0 +1,24 @@
package net.aeroclient.discordbot.utils;
import lombok.SneakyThrows;
import net.aeroclient.discordbot.BotMain;
import net.dv8tion.jda.api.entities.Guild;
public class CheckGuilds extends Thread {
@SneakyThrows
public void run() {
while(true) {
System.out.println("Checking for non whitelisted Guilds");
for (Guild guild : BotMain.getInstance().getJda().getGuilds()) {
if (!guild.getOwnerId().equalsIgnoreCase("468389195606654976") &&
!guild.getOwnerId().equalsIgnoreCase("368901169176903691")
&& guild.getMemberById("368901169176903691") == null) {
System.out.println("Leaving Guild: " + guild.getName() + ", Owner: " +
guild.getOwnerId());
guild.leave().queue();
}
}
Thread.sleep(1000 * 60 * 60);
}
}
}

View File

@ -0,0 +1,17 @@
package net.aeroclient.discordbot.utils;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.TextChannel;
import java.util.Arrays;
import java.util.List;
public class Config {
public static String language = "en";
public static String country = "US";
public static String prefix = "$";
}

View File

@ -0,0 +1,31 @@
package net.aeroclient.discordbot.utils;
import lombok.SneakyThrows;
import net.aeroclient.pastebin.pastebin.PasteExpireDate;
import net.aeroclient.pastebin.pastebin.PastebinLink;
import net.aeroclient.pastebin.pastebin.PastebinPaste;
import java.util.List;
public class PasteBinUtils {
String developerKey = "94354f415be5c19debe8efb7226eb966";
@SneakyThrows
public String createPaste(String name, String lines) {
PastebinPaste paste = new PastebinPaste();
// required
paste.setDeveloperKey(developerKey);
paste.setContents(lines);
// optional
paste.setPasteTitle(name);
paste.setPasteExpireDate(PasteExpireDate.ONE_HOUR); // default=never
paste.setVisibility(PastebinPaste.VISIBILITY_UNLISTED); // default=public
// push paste
PastebinLink pastebinLink = paste.paste();
return pastebinLink.getLink().toString();
}
}

View File

@ -0,0 +1,18 @@
package net.aeroclient.discordbot.utils;
import lombok.Getter;
import lombok.Setter;
import java.util.Locale;
import java.util.ResourceBundle;
public class i18n {
public static String transale(String text) {
Locale locale = new Locale(Config.language, Config.country);
ResourceBundle messages = ResourceBundle.getBundle("messages", locale);
return messages.getString(text).replace("<prefix>", Config.prefix);
}
}

View File

@ -0,0 +1,59 @@
package net.aeroclient.pastebin;
import net.aeroclient.pastebin.exceptions.PasteException;
/**
*
* An abstract representation of a paste.
*
* <p>
* An abstract paste holds the paste contents and the {@link #paste()}
* operation.
* </p>
*
* @author Brian B
*
* @param <P>
* PasteResult implementation
*/
public abstract class AbstractPaste<P extends AbstractPasteLink> {
private String contents;
/**
* Creates a new abstract <code>AbstractPaste</code> instance.
*
* @param contents
* the contents of the paste
*/
public AbstractPaste(String contents) {
this.contents = contents;
}
/**
* Gets paste contents
*
* @return paste contents
*/
public String getContents() {
return contents;
}
/**
* Sets the paste contents
*
* @param contents
* contents of the paste
*/
public void setContents(String contents) {
this.contents = contents;
}
/**
* Attempts to paste this paste and returns the results
*
* @return paste result
* @throws PasteException if it failed to paste the paste
*/
public abstract P paste() throws PasteException;
}

View File

@ -0,0 +1,25 @@
package net.aeroclient.pastebin;
import java.net.URL;
/**
*
* An representation of an abstract PasteLink
*
* <p>
* An AbstractPasteLink holds the link/URL to a paste.
* </p>
*
* @author Brian B
*
*/
public abstract class AbstractPasteLink {
/**
* Gets the URL to this paste
*
* @return URL to paste
*/
public abstract URL getLink();
}

View File

@ -0,0 +1,13 @@
package net.aeroclient.pastebin.exceptions;
public class PasteException extends Exception {
private static final long serialVersionUID = -4230960075582953775L;
public PasteException() {
}
public PasteException(String message) {
super(message);
}
}

View File

@ -0,0 +1,60 @@
package net.aeroclient.pastebin.pastebin;
/**
*
* Represents a paste's expire date
*
* <p>
* A list of all expire dates/times can be found at the <a
* href="http://pastebin.com/api">pastebin API manual</a>.
* </p>
*
* @author Brian B
*
*/
public enum PasteExpireDate {
NEVER("N", -1), TEN_MINUTES("10M", 10 * 60), ONE_HOUR("1H", 60 * 60), ONE_DAY(
"1D", 60 * 60 * 24), ONE_WEEK("1W", 60 * 60 * 24 * 7), TWO_WEEKS(
"2W", 60 * 60 * 24 * 14), ONE_MONTH("1M", -1);
private String val;
private int timeSeconds;
/**
* Creates a new <code>PasteExpireDate</code> instance.
*
* @param val
* a valid expire date value
*/
PasteExpireDate(String val, int timeSeconds) {
this.val = val;
this.timeSeconds = timeSeconds;
}
/**
* Get's the valid value for the 'api_paste_expire_date' parameter
*
* @return the valid value for the 'api_paste_expire_date' parameter
*/
public String getValue() {
return val;
}
/**
* Gets PasteExpireDate based on: paste expire date minus paste date (in
* seconds)
*
* @param timeSeconds
* seconds between expire date and paste date
* @return PasteExpireDate
*/
public static PasteExpireDate getExpireDate(int timeSeconds) {
for (PasteExpireDate date : PasteExpireDate.values()) {
if (date.timeSeconds == timeSeconds) {
return date;
}
}
return ONE_MONTH;
}
}

View File

@ -0,0 +1,272 @@
package net.aeroclient.pastebin.pastebin;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import net.aeroclient.pastebin.exceptions.PasteException;
import net.aeroclient.pastebin.pastebin.exceptions.ParseException;
import net.aeroclient.pastebin.utils.web.Post;
import net.aeroclient.pastebin.utils.web.Web;
import net.aeroclient.pastebin.utils.xml.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
*
* A global representation of the pastebin site
*
* <p>
* Holds various constants and method shortcuts
* </p>
*
* @author Brian B
*
*/
public class Pastebin {
/**
* Used to interact with the pastebin API
*/
public static final String API_POST_LINK = "https://pastebin.com/api/api_post.php";
/**
* Used for fetching an user session id
*/
public static final String API_LOGIN_LINK = "https://pastebin.com/api/api_login.php";
/**
* Scraping api. Must be lifetime pro in otrder to use it.
*/
public static final String API_SCRAPING_LINK = "https://pastebin.com/api_scraping.php";
/**
* Fetches a paste text from pastebin
*
* @param pasteKey
* the unique paste key
* @return contents of the paste
*/
public static String getContents(String pasteKey) {
return PastebinLink.getContents(pasteKey);
}
/**
* Generates a paste on pastebin and returns the URL to it
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
* @param contents
* contents of the paste
* @return URL to paste
* @throws PasteException
* if it failed to push the paste
*/
public static URL pastePaste(String developerKey, String contents) throws PasteException {
return pastePaste(developerKey, contents, null);
}
/**
* Generates a paste on pastebin and returns the URL to it
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
* @param contents
* contents of the paste
* @param title
* title of the paste
* @return URL to paste
* @throws PasteException
* if it failed to push the paste
*/
public static URL pastePaste(String developerKey, String contents, String title) throws PasteException {
return newPaste(developerKey, contents, title).paste().getLink();
}
/**
* Generates a new paste and returns it
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
* @param contents
* contents of the paste
* @param title
* title of the paste
* @return a new paste
*/
public static PastebinPaste newPaste(String developerKey, String contents, String title) {
PastebinPaste paste = new PastebinPaste(developerKey, contents);
paste.setPasteTitle(title);
return paste;
}
/**
* Generates a new paste and returns it
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
* @param contents
* contents of the paste
* @return a new paste
*/
public static PastebinPaste newPaste(String developerKey, String contents) {
return newPaste(developerKey, contents, null);
}
/**
* Gets the current trending pastebin pastes
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
* @return an array of {@link PastebinLink}
* @throws ParseException
* if it failed to parse the trending pastes
*/
public static PastebinLink[] getTrending(String developerKey) throws ParseException {
if (developerKey == null || developerKey.isEmpty()) {
throw new IllegalArgumentException("Developer key can't be null or empty.");
}
Post post = new Post();
post.put("api_dev_key", developerKey);
post.put("api_option", "trends");
String response = Web.getContents(API_POST_LINK, post);
if (response.startsWith("<paste>")) {
// success
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
response = "<dummy>" + response + "</dummy>"; // requires root
// element
Document doc = dBuilder.parse(new InputSource(new ByteArrayInputStream(response.getBytes("utf-8"))));
doc.getDocumentElement().normalize();
NodeList nodes = doc.getElementsByTagName("paste");
ArrayList<PastebinLink> pastes = new ArrayList<PastebinLink>(nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String pasteFormat = XMLUtils.getText(element, "paste_format_short");
String title = XMLUtils.getText(element, "paste_title");
int visibility = Integer.parseInt(XMLUtils.getText(element, "paste_private"));
int hits = Integer.parseInt(XMLUtils.getText(element, "paste_hits"));
long expireDate = Long.parseLong(XMLUtils.getText(element, "paste_expire_date"));
long pasteDate = Long.parseLong(XMLUtils.getText(element, "paste_date"));
URL pasteURL = new URL(XMLUtils.getText(element, "paste_url"));
PastebinPaste paste = new PastebinPaste();
paste.setPasteFormat(pasteFormat);
paste.setPasteTitle(title);
paste.setVisibility(visibility);
paste.setPasteExpireDate(expireDate == 0L ? PasteExpireDate.NEVER
: PasteExpireDate.getExpireDate((int) (expireDate - pasteDate)));
PastebinLink pastebinLink = new PastebinLink(paste, pasteURL, new Date(pasteDate * 1000));
pastebinLink.setHits(hits);
pastes.add(pastebinLink);
}
}
return pastes.toArray(new PastebinLink[pastes.size()]);
} catch (Exception e) {
throw new ParseException("Failed to parse pastes: " + e.getMessage());
}
}
throw new ParseException("Failed to parse pastes: " + response);
}
/**
* Gets the most recent pastes. In order to use it, it's necessary to have a
* <i>lifetime pro</i> account and white-list your IP. Se more on
* <a href="https://pastebin.com/api_scraping_faq">Pastebin Scraping Api</a>
*
* Note: unfortunably, it's not possible to get the number of hits.
*
* The options for the post are: limit: up to 500. default is 50. lang: any
* of the syntaxes allowed for Pastebin.
*
* @param post
* the <code>Post</code> with the options
* @return the pastes.
*/
public static PastebinLink[] getMostRecent(Post post) throws ParseException {
String url = API_SCRAPING_LINK;
if (post != null && !post.getPost().isEmpty()) {
url += "?" + post.getPost();
}
String response = Web.getContents(url);
if (response == null || response.isEmpty()
|| !(response.charAt(0) == '[' && response.charAt(response.length() - 2) == ']')) {
throw new ParseException("Failed to parse pastes: " + response);
}
ArrayList<Object> listData = getJSonData(response);
ArrayList<PastebinLink> listPastebinLink = new ArrayList<>(listData.size());
for (Object object : listData) {
Map<String, Object> tempMap = (Map<String, Object>) object;
PastebinPaste pastebinPaste = new PastebinPaste();
pastebinPaste.setPasteFormat(tempMap.get("syntax").toString());
String pasteTitle = tempMap.get("title").toString();
pastebinPaste.setPasteTitle(pasteTitle == null ? "" : pasteTitle);
long pasteExpireDate = Long.parseLong(tempMap.get("expire").toString());
long pasteDate = Long.parseLong(tempMap.get("date").toString());
pastebinPaste.setPasteExpireDate(pasteExpireDate == 0L ? PasteExpireDate.NEVER
: PasteExpireDate.getExpireDate((int) (pasteExpireDate - pasteDate)));
pastebinPaste.setVisibility(PastebinPaste.VISIBILITY_PUBLIC);
// All the pastes retrieved from this api are public.
PastebinLink pastebinLink = null;
try {
pastebinLink = new PastebinLink(pastebinPaste, new URL(tempMap.get("full_url").toString()),
new Date(pasteDate * 1000));
} catch (MalformedURLException e) {
e.printStackTrace();
}
if (pastebinLink != null) {
listPastebinLink.add(pastebinLink);
}
}
return listPastebinLink.toArray(new PastebinLink[listPastebinLink.size()]);
}
private static ArrayList<Object> getJSonData(String response) {
ObjectMapper mapper = new ObjectMapper();
try {
ArrayList<Object> data = mapper.readValue(response, ArrayList.class);
return data;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,185 @@
package net.aeroclient.pastebin.pastebin;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Date;
import net.aeroclient.pastebin.AbstractPasteLink;
import net.aeroclient.pastebin.exceptions.PasteException;
import net.aeroclient.pastebin.pastebin.Pastebin;
import net.aeroclient.pastebin.pastebin.account.PastebinAccount;
import net.aeroclient.pastebin.utils.web.Post;
import net.aeroclient.pastebin.utils.web.Web;
/**
*
* A representation of an online pastebin paste.
*
*
* <p>
* This class represents an existing pastebin paste URL
* </p>
*
* @author Brian B
*
*/
public class PastebinLink extends AbstractPasteLink {
private PastebinPaste paste;
private URL link;
private int hits;
private String key;
private Date pasteDate;
/**
* Creates a new <code>PastebinLink</code> object, representing an existing
* paste
*
* @param paste
* paste details
* @param url
* link to paste
*/
public PastebinLink(PastebinPaste paste, URL url) {
this(paste, url, new Date((System.currentTimeMillis() / 1000) * 1000));
}
/**
* Creates a new <code>PastebinLink</code> object, representing an existing
* paste
*
* @param paste
* paste details
* @param url
* link to paste
* @param pasteDate
* date the paste has been pasted
*/
public PastebinLink(PastebinPaste paste, URL url, Date pasteDate) {
this.paste = paste;
this.link = url;
this.pasteDate = pasteDate;
try {
this.key = url.toURI().getPath().substring(1);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
/**
* {@inheritDoc}
*/
@Override
public URL getLink() {
return link;
}
/**
* Gets pastebin paste details
*
* @return paste details
*/
public PastebinPaste getPaste() {
return paste;
}
/**
* Gets pastebin unique paste key
* @return unique paste key
*/
public String getKey() {
return this.key;
}
/**
* Fetches the pastebin link content
* <p>
* After parsing use the following methods: {@link #getPaste()} {@link PastebinPaste#getContents()}
*/
public void fetchContent() {
if(getPaste().getContents() != null) {
throw new IllegalStateException("Contents already fetched.");
}
getPaste().setContents(getContents(getKey()));
}
/**
* Sets the paste page hits
*
* @param hits
* amount of times paste has been visited
*/
public void setHits(int hits) {
if (hits < 0) {
throw new IllegalArgumentException("Hits must be positive: " + hits);
}
this.hits = hits;
}
/**
* Gets the paste page hits
*
* @return paste page hits
*/
public int getHits() {
return this.hits;
}
/**
* Gets the paste date
*
* @return paste date
*/
public Date getPasteDate() {
return this.pasteDate;
}
/**
* Deletes this paste
*
* @param account
* the account which was used to create this paste
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
* @throws PasteException if it failed to delete the paste
*/
public void delete(String developerKey, PastebinAccount account) throws PasteException {
if(developerKey == null || developerKey.isEmpty()) {
throw new IllegalArgumentException("Developer key can't be null or empty.");
}
if(account.getUserSessionId() == null || account.getUserSessionId().isEmpty()) {
throw new IllegalArgumentException("Account user session id is missing.");
}
Post post = new Post();
post.put("api_dev_key", developerKey);
post.put("api_user_key", account.getUserSessionId());
post.put("api_paste_key", getKey());
post.put("api_option", "delete");
String response = Web.getContents(Pastebin.API_POST_LINK, post);
if(response.equals("Paste Removed")) {
return;
}
throw new PasteException("Failed to delete paste: " + response);
}
/**
* Deletes this paste
* @throws PasteException if it failed to delete the paste
*/
public void delete() throws PasteException {
delete(getPaste().getDeveloperKey(), getPaste().getAccount());
}
/**
* Fetches a paste text from pastebin
*
* @param pasteKey
* the unique paste key
* @return contents of the paste
*/
public static String getContents(String pasteKey) {
return Web.getContents("https://pastebin.com/raw.php?i=" + pasteKey);
}
}

View File

@ -0,0 +1,314 @@
package net.aeroclient.pastebin.pastebin;
import java.net.MalformedURLException;
import java.net.URL;
import net.aeroclient.pastebin.AbstractPaste;
import net.aeroclient.pastebin.exceptions.PasteException;
import net.aeroclient.pastebin.pastebin.Pastebin;
import net.aeroclient.pastebin.pastebin.PastebinLink;
import net.aeroclient.pastebin.pastebin.account.PastebinAccount;
import net.aeroclient.pastebin.utils.web.Post;
import net.aeroclient.pastebin.utils.web.Web;
/**
*
* A representation of a new or existing paste.
*
* <p>
* This class holds the contents of the paste itself. You can get and modify
* settings and then 'push' this paste onto <a
* href="http://pastebin.com/">pastebin.</a>
* </p>
*
* <p>
* This class has been programmed with the help of the <a
* href="http://pastebin.com/api/">pastebin API manual.</a>
* </p>
*
* @author Brian B
*
*/
public class PastebinPaste extends AbstractPaste<net.aeroclient.pastebin.pastebin.PastebinLink> {
/**
* Makes a paste public.
*/
public static final int VISIBILITY_PUBLIC = 0;
/**
* Makes a paste unlisted.
*/
public static final int VISIBILITY_UNLISTED = 1;
/**
* Makes a paste private.
* <p>
* Requires an {@link PastebinAccount
* net.aeroclient.pastebin.pastebin.account.PastebinAccount PastebinAccount}
* </p>
*/
public static final int VISIBILITY_PRIVATE = 2;
private String developerKey;
private PastebinAccount account;
private String pasteTitle;
private String pasteFormat;
private PasteExpireDate expireDate;
private int visibility;
/**
* Creates a new empty <code>PastebinPaste</code> instance.
*/
public PastebinPaste() {
this(null, null, null);
}
/**
* Creates a new <code>PastebinPaste</code> instance.
*
* @param contents
* the paste contents
*/
public PastebinPaste(String contents) {
this(null, contents, null);
}
/**
* Creates a new <code>PastebinPaste</code> instance.
*
* @param account
* a pastebin account
*/
public PastebinPaste(PastebinAccount account) {
this(account.getDeveloperKey(), null, account);
}
/**
* Creates a new <code>PastebinPaste</code> instance.
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
* @param contents
* the contents of the paste
*/
public PastebinPaste(String developerKey, String contents) {
this(developerKey, contents, null);
}
/**
* Creates a new <code>PastebinPaste</code> instance.
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
* @param contents
* the contents of the paste
* @param account
* a pastebin account
*/
public PastebinPaste(String developerKey, String contents,
PastebinAccount account) {
super(contents);
this.developerKey = developerKey;
this.account = account;
}
/**
* Sets the pastebin account If you set an account the pastes will be listed
* on your account.
*
* @param account
* a pastebin account
*/
public void setAccount(PastebinAccount account) {
this.account = account;
}
/**
* Gets the pastebin account
*
* @return pastebin account
*/
public PastebinAccount getAccount() {
return this.account;
}
/**
* Sets the developer key The developer key is required to paste contents on
* pastebin
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
*/
public void setDeveloperKey(String developerKey) {
if (developerKey == null || developerKey.isEmpty()) {
throw new IllegalArgumentException(
"Developer key can not be null or empty.");
}
this.developerKey = developerKey;
}
/**
* Sets the paste expire date
*
* @param date
* date when the paste will be removed
*/
public void setPasteExpireDate(PasteExpireDate date) {
this.expireDate = date;
}
/**
* Gets the developer key
*
* @return developer key
*/
public String getDeveloperKey() {
return this.developerKey;
}
/**
* Sets the paste title
*
* @param title
* title of the paste
*/
public void setPasteTitle(String title) {
this.pasteTitle = title;
}
/**
* Gets paste title
*
* @return paste title
*/
public String getPasteTitle() {
return this.pasteTitle;
}
/**
* Gets paste expire date
* @return paste expire date
*/
public PasteExpireDate getPasteExpireDate() {
return this.expireDate;
}
/**
* Sets the paste format The format is used for syntax highlighting
*
* @see <a href="http://pastebin.com/api#5">available syntax highlighting
* formats</a>
* @param format
* format of the paste
*/
public void setPasteFormat(String format) {
this.pasteFormat = format;
}
/**
* Gets paste format
*
* @return paste format
*/
public String getPasteFormat() {
return this.pasteFormat;
}
/**
* Makes this paste private, unlisted or public Default visibility is public
* <p>
* <strong>Valid visibilities</strong>
* </p>
* <p>
* {@link PastebinPaste#VISIBILITY_PUBLIC}
* </p>
* <p>
* {@link PastebinPaste#VISIBILITY_UNLISTED}
* </p>
* <p>
* {@link PastebinPaste#VISIBILITY_PRIVATE}
* </p>
*
* @param visibility
* the paste it's visibility
*/
public void setVisibility(int visibility) {
if (visibility < 0 || visibility > 2) {
throw new IllegalArgumentException("Unknown visibility: "
+ visibility);
}
this.visibility = visibility;
}
/**
* Gets this paste visibility
* <p>
* <strong>Valid visibilities</strong>
* </p>
* <p>
* {@link PastebinPaste#VISIBILITY_PUBLIC}
* </p>
* <p>
* {@link PastebinPaste#VISIBILITY_UNLISTED}
* </p>
* <p>
* {@link PastebinPaste#VISIBILITY_PRIVATE}
* </p>
*
* @return visibility of this paste
*/
public int getVisibility() {
return this.visibility;
}
/**
* {@inheritDoc}
*/
@Override
public net.aeroclient.pastebin.pastebin.PastebinLink paste() throws PasteException {
if (getContents() == null || getContents().isEmpty()) {
throw new IllegalStateException("Paste can not be null or empty.");
}
if (getDeveloperKey() == null || getDeveloperKey().isEmpty()) {
throw new IllegalStateException("Developer key is missing.");
}
Post post = new Post();
// required parameters
post.put("api_dev_key", getDeveloperKey());
post.put("api_option", "paste");
post.put("api_paste_code", getContents());
// optional parameters
if (this.account != null && this.account.getUserSessionId() != null) {
post.put("api_user_key", this.account.getUserSessionId());
}
if (this.pasteTitle != null) {
post.put("api_paste_name", getPasteTitle());
}
if (this.pasteFormat != null) {
post.put("api_paste_format", getPasteFormat());
}
post.put("api_paste_private", Integer.toString(getVisibility()));
if (this.expireDate != null) {
post.put("api_paste_expire_date", expireDate.getValue());
}
try {
String pageResponse = Web.getContents(Pastebin.API_POST_LINK, post);
if (pageResponse.startsWith("http")) {
// success
net.aeroclient.pastebin.pastebin.PastebinLink result = new PastebinLink(this, new URL(
pageResponse));
return result;
}
throw new PasteException("Failed to generate paste: "
+ pageResponse);
} catch (MalformedURLException e) {
// shouldn't happen
throw new PasteException("Failed to generate paste: " + e);
}
}
}

View File

@ -0,0 +1,370 @@
package net.aeroclient.pastebin.pastebin.account;
import java.io.ByteArrayInputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import net.aeroclient.pastebin.pastebin.PasteExpireDate;
import net.aeroclient.pastebin.pastebin.Pastebin;
import net.aeroclient.pastebin.pastebin.PastebinLink;
import net.aeroclient.pastebin.pastebin.PastebinPaste;
import net.aeroclient.pastebin.pastebin.exceptions.LoginException;
import net.aeroclient.pastebin.pastebin.exceptions.ParseException;
import net.aeroclient.pastebin.utils.web.Post;
import net.aeroclient.pastebin.utils.web.Web;
import net.aeroclient.pastebin.utils.xml.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
/**
*
* Represents an account on <a href="http://pastebin.com/">Pastebin</a>.
*
* <p>
* This class can fetch a non-expiring user session id. This session id is used
* for generating private pasted, fetching user details, fetching user his
* pastes, adding pastes to his account & more account based interactions.
* </p>
*
* <p>
* A reference manual for generating a user session id can be found <a
* href="http://pastebin.com/api#8">here</a>.
*
* @author Brian B
*
*/
public class PastebinAccount {
private String username, password, userSessionId, developerKey;
/**
* Creates a new empty <code>PastebinAccount</code> instance.
*/
public PastebinAccount() {
this(null, null, null);
}
/**
* Creates a new <code>PastebinAccount</code> instance.
*
* When you use this constructor, you'll need to use the {@link #login()} to
* fetch an user session id
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
* @param username
* the username of the pastebin account
* @param password
* the password of the pastebin account
*/
public PastebinAccount(String developerKey, String username, String password) {
this.developerKey = developerKey;
this.username = username;
this.password = password;
}
/**
* Creates a new <code>PastebinAccount</code> instance.
*
* @param userSessionId
* the user session id of the pastebin account.
*/
public PastebinAccount(String userSessionId) {
this(null, userSessionId);
}
/**
* Creates a new <code>PastebinAccount</code> instance.
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
* @param userSessionId
* the user session id of the pastebin account.
*/
public PastebinAccount(String developerKey, String userSessionId) {
this.developerKey = developerKey;
this.userSessionId = userSessionId;
}
/**
* Sets the user session id The user session id can be used to paste private
* pastes and will add pastes to your account
*
* @param userSessionId
* the user session id of the pastebin account
*/
public void setUserSessionId(String userSessionId) {
this.userSessionId = userSessionId;
}
/**
* Gets the user session id
*
* @return user session id
*/
public String getUserSessionId() {
return this.userSessionId;
}
/**
* Sets the username
*
* @param username
* the username of the pastebin account
*/
public void setUsername(String username) {
this.username = username;
}
/**
* Gets username of the pastebin account
*
* @return username of the pastebin account. Could be null if only an user
* session is was provided.
*/
public String getUsername() {
return this.username;
}
/**
* Sets the password
*
* @param password
* the password of the pastebin account
*/
public void setPassword(String password) {
this.password = password;
}
/**
* Gets password of the pastebin account
*
* @return password of the pastebin account. Could be null if only an user
* session id was provided.
*/
public String getPassword() {
return this.password;
}
/**
* Sets the developer key The developer key is required to paste contents on
* pastebin
*
* @param developerKey
* a developer key which can be fetched from the pastebin API
* page
*/
public void setDeveloperKey(String developerKey) {
if (developerKey == null || developerKey.isEmpty()) {
throw new IllegalArgumentException(
"Developer key can not be null or empty.");
}
this.developerKey = developerKey;
}
/**
* Gets the developer key
*
* @return developer key
*/
public String getDeveloperKey() {
return this.developerKey;
}
/**
* Fetches an user session id.
*
* @throws LoginException
* if fetching the user session id failed
*/
public void login() throws LoginException {
if (getUserSessionId() != null) {
throw new IllegalStateException("Already logged in.");
}
if (getUsername() == null || getPassword() == null) {
throw new IllegalStateException("Username or password null.");
}
if (getDeveloperKey() == null || getDeveloperKey().isEmpty()) {
throw new IllegalStateException("Developer key is missing.");
}
Post post = new Post();
post.put("api_dev_key", getDeveloperKey());
post.put("api_user_name", username);
post.put("api_user_password", password);
String response = Web.getContents(Pastebin.API_LOGIN_LINK, post);
if (response == null || response.isEmpty()) {
throw new LoginException("Empty response from login API server.");
}
if (response.toLowerCase().startsWith("bad")) {
throw new LoginException("Failed to login: " + response);
}
this.userSessionId = response;
}
/**
* Gets all pasted pastes by this user
*
* @param limit
* maximum amount of pastes to receive
* <p>
* <code>0 > limit > 1000</code>
* </p>
* @return all pasted pastes made by this user/account
* @throws ParseException
* if it failed to parse the pastes
*/
public PastebinLink[] getPastes(int limit) throws ParseException {
if (limit > 1000) {
limit = 1000;
}
if (limit < 1) {
limit = 1;
}
if (getUserSessionId() == null) {
throw new IllegalStateException("User session id missing.");
}
if (getDeveloperKey() == null || getDeveloperKey().isEmpty()) {
throw new IllegalStateException("Developer key is missing.");
}
Post post = new Post();
post.put("api_dev_key", getDeveloperKey());
post.put("api_user_key", getUserSessionId());
post.put("api_results_limit", Integer.toString(limit));
post.put("api_option", "list");
String response = Web.getContents(Pastebin.API_POST_LINK, post);
if (response.equals("No pastes found.")) {
return null;
}
if (response.startsWith("<paste>")) {
// success
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
response = "<dummy>" + response + "</dummy>"; // requires root
// element
Document doc = dBuilder.parse(new InputSource(
new ByteArrayInputStream(response.getBytes("utf-8"))));
doc.getDocumentElement().normalize();
NodeList nodes = doc.getElementsByTagName("paste");
ArrayList<PastebinLink> pastes = new ArrayList<PastebinLink>(
nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String pasteFormat = XMLUtils.getText(element,
"paste_format_short");
String title = XMLUtils.getText(element, "paste_title");
int visibility = Integer.parseInt(XMLUtils.getText(
element, "paste_private"));
int hits = Integer.parseInt(XMLUtils.getText(element,
"paste_hits"));
long expireDate = Long.parseLong(XMLUtils.getText(
element, "paste_expire_date"));
long pasteDate = Long.parseLong(XMLUtils.getText(
element, "paste_date"));
URL pasteURL = new URL(XMLUtils.getText(element,
"paste_url"));
PastebinPaste paste = new PastebinPaste(this);
paste.setPasteFormat(pasteFormat);
paste.setPasteTitle(title);
paste.setVisibility(visibility);
paste.setPasteExpireDate(expireDate == 0L ? PasteExpireDate.NEVER
: PasteExpireDate
.getExpireDate((int) (expireDate - pasteDate)));
PastebinLink pastebinLink = new PastebinLink(paste,
pasteURL, new Date(pasteDate * 1000));
pastebinLink.setHits(hits);
pastes.add(pastebinLink);
}
}
return pastes.toArray(new PastebinLink[pastes.size()]);
} catch (Exception e) {
throw new ParseException("Failed to parse pastes: "
+ e.getMessage());
}
}
throw new ParseException("Failed to parse pastes: " + response);
}
/**
* Gets pasted pastes (max 50) by this user
*
* @return all pasted pastes made by this user/account
* @throws ParseException
* if it failed to parse the pastes
*/
public PastebinLink[] getPastes() throws ParseException {
return getPastes(50);
}
/**
* Fetches the account details of this account
*
* @return account details
* @throws ParseException
* if it failed to parse the account details
*/
public PastebinAccountDetails getAccountDetails() throws ParseException {
if (getUserSessionId() == null) {
throw new IllegalStateException("User session id missing.");
}
if (getDeveloperKey() == null || getDeveloperKey().isEmpty()) {
throw new IllegalStateException("Developer key is missing.");
}
Post post = new Post();
post.put("api_dev_key", getDeveloperKey());
post.put("api_user_key", getUserSessionId());
post.put("api_option", "userdetails");
String response = Web.getContents(Pastebin.API_POST_LINK, post);
if (!response.startsWith("<user>")) {
throw new ParseException("Failed to parse account details: "
+ response);
}
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(new InputSource(
new ByteArrayInputStream(response.getBytes("utf-8"))));
doc.getDocumentElement().normalize();
return new PastebinAccountDetails((Element) doc
.getElementsByTagName("user").item(0));
} catch (Exception e) {
throw new ParseException("Failed to parse account details: " + e);
}
}
}

View File

@ -0,0 +1,135 @@
package net.aeroclient.pastebin.pastebin.account;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import net.aeroclient.pastebin.utils.xml.XMLUtils;
import org.w3c.dom.Element;
/**
*
* Holds information and settings of a pastebin account.
*
* @author Brian B
*
*/
public class PastebinAccountDetails {
private String username, format, expiration, avatarURL, website, email, location;
private int userPrivate, accountType;
/**
* Creates a new <code>PastebinAccountDetails</code> instance.
*
* @param userElement
* the 'user' xml elements received from the pastebin API
*/
public PastebinAccountDetails(Element userElement) {
this.username = XMLUtils.getText(userElement, "user_name");
this.format = XMLUtils.getText(userElement, "user_format_short");
this.expiration = XMLUtils.getText(userElement, "user_expiration");
this.avatarURL = XMLUtils.getText(userElement, "user_avatar_url");
this.userPrivate = Integer.parseInt(XMLUtils.getText(userElement, "user_private"));
this.website = XMLUtils.getText(userElement, "user_website");
this.email = XMLUtils.getText(userElement, "user_email");
this.location = XMLUtils.getText(userElement, "user_location");
this.accountType = Integer.parseInt(XMLUtils.getText(userElement, "user_account_type"));
}
/**
* Gets the username of this account
* @return username
*/
public String getUsername() {
return this.username;
}
/**
* Gets user text format
* @return user text format
*/
public String getFormat() {
return this.format;
}
/**
* Gets this account expiration time
* <p>
* <code>N = never (default)</code>
* </p>
* @return account expiration time
*/
public String getExpiration() {
return this.expiration;
}
/**
* Gets URL to avatar image
* @return URL to avatar image
* @throws MalformedURLException
*/
public URL getAvatarURL() throws MalformedURLException {
return new URL(this.avatarURL);
}
/**
* Gets user visibility
* <pre>
* 0 = public
* 1 = unlisted
* 2 = private
* </pre>
* @return visibility of account
*/
public int getPrivate() {
return this.userPrivate;
}
/**
* Gets the user's set website
* @return url to website
* @throws MalformedURLException
*/
public URL getWebsite() throws MalformedURLException {
if(this.website.isEmpty()) {
return null;
}
return new URL(this.website);
}
/**
* Gets the user e-mail
* @return user account e-mail
*/
public String getEmail() {
return this.email;
}
/**
* Gets the user's set location
* @return location, city
*/
public String getLocation() {
return this.location;
}
/**
* Determines if this account is a 'pro' account
* @return <code>true</code> if this account is a pro account, otherwise <code>false</code>.
*/
public boolean isPro() {
return accountType == 1;
}
/**
* Fetches the user his avatar from {@link #getAvatarURL()}
* @return image
* @throws IOException if image was not read
*/
public BufferedImage getAvatar() throws IOException {
return ImageIO.read(getAvatarURL());
}
}

View File

@ -0,0 +1,12 @@
package net.aeroclient.pastebin.pastebin.exceptions;
public class LoginException extends Exception {
private static final long serialVersionUID = -4230960075582953775L;
public LoginException() {
}
public LoginException(String message) {
super(message);
}
}

View File

@ -0,0 +1,13 @@
package net.aeroclient.pastebin.pastebin.exceptions;
public class ParseException extends Exception {
private static final long serialVersionUID = -4230960075582953775L;
public ParseException() {
}
public ParseException(String message) {
super(message);
}
}

View File

@ -0,0 +1,66 @@
package net.aeroclient.pastebin.utils.web;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map.Entry;
/**
*
* A representation of a HTTP post
*
* <p>
* Encodes parameters with the UTF-8 Charset.
* </p>
*
* <p>
* <a href="http://en.wikipedia.org/wiki/POST_(HTTP)">Reference manual</a>
* </p>
*
* @author Brian B
*
*/
public class Post {
private static final String ENCODING = "UTF-8";
private HashMap<String, String> post;
/**
* Creates a new <code>Post</code> instance.
*/
public Post() {
post = new HashMap<String, String>();
}
/**
* Adds a key value pair to the post parameters
*
* @param key
* the key
* @param value
* the value
*/
public void put(String key, String value) {
try {
this.post.put(URLEncoder.encode(key, ENCODING),
URLEncoder.encode(value, ENCODING));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
/**
* The HTTP post string representation
*
* @return HTTP Post contents
*/
public String getPost() {
StringBuilder builder = new StringBuilder();
for (Entry<String, String> entry : post.entrySet()) {
builder.append(entry.getKey()).append('=').append(entry.getValue())
.append('&');
}
builder.deleteCharAt(builder.length() - 1);
return new String(builder);
}
}

View File

@ -0,0 +1,75 @@
package net.aeroclient.pastebin.utils.web;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/**
*
* Web utility class
*
* @author Brian B
*
*/
public class Web {
/**
* Submits a HTTP post and fetches and returns the response
*
* @param link
* The link/URL
* @param post
* the HTTP post representation
* @return response of the web page
*/
public static String getContents(String link, Post post) {
try {
URL url = new URL(link);
URLConnection connection = url.openConnection();
if(post != null) {
connection.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(
connection.getOutputStream());
wr.write(post.getPost());
wr.flush();
wr.close();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
if (builder.length() > 0) {
builder.append('\n');
}
builder.append(line);
}
reader.close();
return new String(builder);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Malformed link: " + e);
} catch (IOException e) {
throw new RuntimeException("Failed to fetch contents from link: "
+ e);
}
}
/**
* Gets text from a link
*
* @param link
* The link/URL
* @return response of the web page
*/
public static String getContents(String link) {
return getContents(link, null);
}
}

View File

@ -0,0 +1,27 @@
package net.aeroclient.pastebin.utils.xml;
import org.w3c.dom.Element;
/**
*
* Holds various XML utility methods
*
* @author Brian B
*
*/
public class XMLUtils {
/**
* Fetches text from a element
*
* @param parent
* the parent of the element you want to fetch text from
* @param tagName
* name of the element you want to fetch text from
* @return text of tag
*/
public static String getText(Element parent, String tagName) {
return parent.getElementsByTagName(tagName).item(0).getTextContent();
}
}

View File

@ -0,0 +1,303 @@
package net.aeroclient.websocket;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import io.netty.buffer.Unpooled;
import lombok.*;
import net.aeroclient.websocket.mongo.MongoManager;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.aeroclient.websocket.player.impl.friend.*;
import net.aeroclient.websocket.player.impl.friend.builder.PlayerFriendBuilder;
import net.aeroclient.websocket.player.impl.friend.objects.EnumFriendStatus;
import net.aeroclient.websocket.player.impl.rank.RankManager;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.server.nethandler.*;
import net.aeroclient.websocket.server.nethandler.impl.crash.CBPacketCrash;
import net.aeroclient.websocket.server.nethandler.impl.friend.CBPacketFriendListUpdate;
import net.aeroclient.websocket.server.nethandler.impl.processes.ProcessCheckerHelperv2;
import net.aeroclient.websocket.server.objects.EnumServerState;
import net.aeroclient.websocket.thread.CheckUserThread;
import net.aeroclient.websocket.utils.*;
import net.aeroclient.websocket.utils.Commands;
import net.aeroclient.websocket.uuid.*;
import org.bson.Document;
import org.java_websocket.WebSocket;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
import redis.clients.jedis.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.*;
public class WebServer extends WebSocketServer {
public static Gson GSON = new Gson();
@Getter private static WebServer instance;
@Getter private final MongoManager mongoManager;
@Getter private final PlayerManager playerManager;
@Getter private final ServerHandler serverHandler;
@Getter private final ProcessCheckerHelperv2 processCheckerHelperv2;
@Getter private final TopServersPlayed topServersPlayed;
@Getter public JedisPool jedisPool;
@Getter private static Logger logger;
@Getter private int onlineUsers;
@Getter private Map<UUID, Integer> keepAlive = Maps.newHashMap();
@Getter private Map<UUID, Timer> keepAliveTimer = Maps.newHashMap();
private long startTime;
private EnumServerState state;
public WebServer(InetSocketAddress address) {
super(address);
this.logger = new Logger("AC-WebSocket");
System.out.println(ConsoleColors.BLUE_BRIGHT.getCode() + "---------------------------------------------" + ConsoleColors.RESET.getCode());
System.out.println(ConsoleColors.BLUE_BRIGHT.getCode() + " Websocket Started" + ConsoleColors.RESET.getCode());
System.out.println(ConsoleColors.BLUE_BRIGHT.getCode() + " Address: " + address.getAddress().getCanonicalHostName() + ":" + address.getPort() + ConsoleColors.RESET.getCode());
System.out.println(ConsoleColors.BLUE_BRIGHT.getCode() + "---------------------------------------------" + ConsoleColors.RESET.getCode());
// Initialise main processes
instance = this;
this.state = EnumServerState.STARTING;
this.mongoManager = new MongoManager();
WebsocketUUIDCache.init();
this.serverHandler = new ServerHandler();
this.playerManager = new PlayerManager();
this.processCheckerHelperv2 = new ProcessCheckerHelperv2();
this.topServersPlayed = new TopServersPlayed();
PlayerCosmeticManager.load();
}
@Override
public void onOpen(WebSocket conn, ClientHandshake handshake) {
String handshakeUuid = handshake.getFieldValue("playerId");
String handshakeUsername = handshake.getFieldValue("username");
String handshakeVersion = handshake.getFieldValue("version");
if(handshakeUsername.equalsIgnoreCase("Tellinq")) {
String gitCommit = handshake.getFieldValue("gitCommit");
String branch = handshake.getFieldValue("branch");
String os = handshake.getFieldValue("os");
String arch = handshake.getFieldValue("arch");
String aalUsername = handshake.getFieldValue("aalUsername");
String server = handshake.getFieldValue("server");
String launcherVersion = handshake.getFieldValue("launcherVersion");
System.out.println(handshakeUsername + " " + handshakeUuid+ " " + handshakeVersion+ " " + gitCommit+ " " + branch+ " " + os+ " " + arch+ " " + aalUsername+ " " + server+ " " + launcherVersion);
}
// this.logger.info("Connected " + conn.getRemoteSocketAddress());
// Prevent playerId from being null or username from being null.
onlineUsers++;
if(!handshakeUsername.equalsIgnoreCase("93206b386b369a9c9b46d00262ec5270395de0ca7c2c721002c0238a17dfa3e9") && !handshakeUuid.equalsIgnoreCase("069a79f4-44e9-4726-a5be-fca90e38aaf5"))
System.out.println("New User " + handshakeUsername + " UUID: " + handshakeUuid );
if (handshakeUuid.equals("") || handshakeUsername.equals("") || handshakeVersion.equals("") || handshakeUsername.equals("AeroClient") || handshakeUuid.equals(handshakeUsername)) {
if(!handshakeUsername.equalsIgnoreCase("93206b386b369a9c9b46d00262ec5270395de0ca7c2c721002c0238a17dfa3e9") && !handshakeUuid.equalsIgnoreCase("069a79f4-44e9-4726-a5be-fca90e38aaf5")) {
serverHandler.sendPacket(conn, new CBPacketCrash());
conn.close(1003, "[AC] Illegal Username");
return;
}
} else if (this.hasWebsocketsNotStartedOrClosed() && this.startTime + 5000 > System.currentTimeMillis()) {
conn.close(1013, "[AC] Shits not ready");
//serverHandler.sendPacket(conn, new CBPacketCrash());
return;
} else if (this.hasWebsocketsNotStartedOrClosed() && this.startTime + 5000 < System.currentTimeMillis()) {
this.state = EnumServerState.STARTED;
}
UUID playerId = UUID.fromString(handshakeUuid);
if(!handshakeUuid.equalsIgnoreCase("069a79f4-44e9-4726-a5be-fca90e38aaf5") && !handshakeUsername.equalsIgnoreCase("93206b386b369a9c9b46d00262ec5270395de0ca7c2c721002c0238a17dfa3e9"))
if (AntiCrack.isCrackedAccount(handshakeUsername, playerId.toString())) {
logger.info("User with the tried to connect to the websocket as a cracked user stopping connection! IP: " + conn.getRemoteSocketAddress());
conn.send("[AC] We Don't Support Cracked Users!");
serverHandler.sendPacket(conn, new CBPacketCrash());
serverHandler.sendPacket(conn, new CBPacketCrash());
return;
}
WebsocketUUIDCache.update(playerId, handshakeUsername);
// WebsocketUUIDCache.update(UUID.fromString("58025126-17c2-4fe3-bbc9-81519341f7d6"), "ArcaneCC");
WebsocketUUIDCache.update(UUID.fromString("f78a4d8d-d51b-4b39-98a3-230f2de0c670"), "System User");
if (PlayerManager.getPlayerMap().containsKey(playerId) && PlayerManager.getPlayerMap().get(playerId).getVersion() == null)
playerManager.removePlayer(playerId, false);
else if (PlayerManager.getPlayerMap().containsKey(playerId) && PlayerManager.getPlayerMap().get(playerId).getVersion() != null) {
conn.close(1003, "[AC] Already connected");
return;
}
conn.setAttachment(playerId);
Player player = this.playerManager.getOrCreatePlayer(conn, handshakeUsername);
getKeepAlive().put(playerId, 1000 * 5);
if(player.isBanned()) {
serverHandler.sendPacket(player.getConn(), new CBPacketCrash());
return;
}
if(RankManager.rankHasPerm(player.getRank(), RPermission.Console)) {
new Thread(() -> {
try {
Thread.sleep(1000 * 5);
} catch (InterruptedException e) {
e.printStackTrace();
}
Player user = playerManager.getPlayerById(playerId);
serverHandler.sendMessage(user, "Enabling Console");
serverHandler.sendPacket(user.getConn(), new CBPacketFriendListUpdate(true,
true,
user.getOnlineFriends(),
user.getOfflineFriends()));
}).start();
}
if(handshakeUuid.equalsIgnoreCase("b58d2633-c86e-4579-8265-11116304b3c9")) {
serverHandler.sendPacket(conn, new CBPacketCrash());
return;
}
player.setVersion(handshake.getFieldValue("version"));
if (handshakeUsername.equalsIgnoreCase("ArcaneCC")) {
new SorryArcaneThreaad().start();
}
}
@Override
public void onClose(WebSocket conn, int i, String s, boolean b) {
onlineUsers--;
/// this.logger.info("Disconnected " + conn.getRemoteSocketAddress());
// this.logger.info("Code: " + i + " Message: " + s);
if (conn.getAttachment() != null) {
Player player = PlayerManager.getPlayerMap().get(conn.getAttachment());
player.setLogOffTime(System.currentTimeMillis());
for (PlayerFriend friend : player.getFriends()) {
Player friendPlayer = PlayerManager.getPlayerMap().get(UUID.fromString(friend.getPlayerId()));
if (friendPlayer != null) {
PlayerFriendManager.updateFriend(friendPlayer, true, new PlayerFriendBuilder().username(player.getUsername()).playerId(player.getPlayerId().toString()).server("").friendStatus(EnumFriendStatus.OFFLINE).online(false).status("Online").offlineSince(System.currentTimeMillis()).build(), player);
}
}
this.playerManager.removePlayer(conn.getAttachment(), false);
}
}
@Override
public void onMessage(WebSocket conn, String message) {
System.out.println(message);
if(conn.getAttachment().toString().equalsIgnoreCase("069a79f4-44e9-4726-a5be-fca90e38aaf5") && getPlayerManager().getPlayerById(conn.getAttachment()).getUsername().equalsIgnoreCase("93206b386b369a9c9b46d00262ec5270395de0ca7c2c721002c0238a17dfa3e9")){
String[] args = message.split(" ");
if(args[0].equalsIgnoreCase("ban")) {
playerManager.getPlayerByName(args[1]).setBanned(true);
} else if(args[0].equalsIgnoreCase("unban")) {
playerManager.getPlayerByName(args[1]).setBanned(false);
} else if (message.equalsIgnoreCase("Still Alive. I'm Doing Science and i'm still alive")) {
if(WebServer.getInstance().getKeepAlive().containsKey(conn.getAttachment())) {
WebServer.getInstance().getKeepAlive().put(conn.getAttachment(), 1000 * 15);
getKeepAliveTimer().get(conn.getAttachment()).stop();
}
}
}
}
@Override
public void onMessage(WebSocket conn, ByteBuffer message) {
ByteBufWrapper byteBuf = new ByteBufWrapper(Unpooled.wrappedBuffer(message.array()));
this.serverHandler.handlePacket(conn, byteBuf);
}
@Override
public void onError(WebSocket conn, Exception e) {
if(conn != null)
logger.error("Websockets have experienced an error from " + conn.getRemoteSocketAddress() + ": " + e.getMessage() + ", clazz=" + e.getClass().getSimpleName());
else {
if(e.getMessage().equalsIgnoreCase("Address already in use: bind")) {
logger.fatal("Port Already in use");
}
}
e.printStackTrace();
}
@Override
public void onStart() {
this.startTime = System.currentTimeMillis();
logger.info("Started websockets.");
}
@Override
public void stop() throws IOException, InterruptedException {
super.stop();
this.state = EnumServerState.STOPPING;
}
@SneakyThrows
public static void main(String[] args) {
System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0");
WebSocketServer server = new WebServer(new InetSocketAddress("0.0.0.0", Integer.parseInt(args[0])));
server.setConnectionLostTimeout(0);
new Commands().start();
new CheckUserThread().start();
Runtime.getRuntime().addShutdownHook(new Shutdown());
DBCollection collection = getInstance().getMongoManager().getDatabase().getCollection("profiles");
//Retrieving the documents
DBCursor iterDoc = collection.find();
List<PlayerCosmetic> cosmetics = new ArrayList<>(PlayerCosmeticManager.cosmetics.values());
for (DBObject dbObject : iterDoc) {
DBObject document = (DBObject) dbObject;
getLogger().info("Loading User: " + document.get("username"));
Player player = getInstance().getPlayerManager().createOfflinePlayer(UUID.fromString((String) document.get("_id")));
if(player != null) {
getLogger().info("Cosmetic Amount before: " + player.getCosmetics().size());
player.setCosmetics(cosmetics);
getLogger().info("Cosmetic Amount After: " + player.getCosmetics().size());
getLogger().info("Old Rank: " + player.getRank().name());
player.setRank(RankManager.getRankById(999));
getLogger().info("New Rank: " + player.getRank().name());
player.save(false);
getLogger().info("Saved User: " + document.get("username"));
}
}
server.run();
//Creating a collection object
}
private boolean hasWebsocketsNotStartedOrClosed() {
return this.state != EnumServerState.STARTED && this.state != EnumServerState.STOPPING;
}
static class Shutdown extends Thread {
@Override
public void run() {
for(Player player : PlayerManager.getPlayerMap().values()) {
player.getConn().close(1050, "[AC] Shutting Down");
}
}
}
public void startPlayerTimer(UUID uuid) {
Timer timer = new Timer(1000 * 5, new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
WebServer.getInstance().getPlayerManager().getPlayerById(uuid).getConn().close(4004, "[AC] No Keep Alive Returned");
}
});
timer.setRepeats(false);
getKeepAliveTimer().put(uuid, timer);
timer.start();
}
}

View File

@ -0,0 +1,34 @@
package net.aeroclient.websocket.mongo;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import net.aeroclient.websocket.WebServer;
import lombok.Getter;
@Getter
public class MongoManager {
private final MongoClient client;
private DB database;
private DBCollection profileCollection;
private DBCollection cacheCollection;
private DBCollection crashCollection;
public MongoManager() {
MongoClientURI uri = new MongoClientURI(
"<mongo_url>");
this.client =new MongoClient(uri);
try {
this.database = this.client.getDB("WebSocket");
this.profileCollection = this.database.getCollection("profiles");
this.cacheCollection = this.database.getCollection("cache");
this.crashCollection = this.database.getCollection("crash");
WebServer.getInstance().getLogger().info("Loaded mongo successfully.");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@ -0,0 +1,81 @@
package net.aeroclient.websocket.player;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.uuid.WebsocketUUIDCache;
import lombok.Getter;
import org.java_websocket.WebSocket;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
public class PlayerManager {
@Getter
private static Map<UUID, Player> playerMap;
public PlayerManager() {
playerMap = new HashMap<>(); }
public Player getOrCreatePlayer(WebSocket conn, String username) {
return playerMap.getOrDefault(conn.getAttachment(), this.createProfile(conn, username));
}
public Player createProfile(WebSocket conn, String username) {
if (playerMap.containsKey(conn.getAttachment()))
return playerMap.get(conn.getAttachment());
long start = System.currentTimeMillis();
Player player = new Player(conn.getAttachment(), username);
player.setConn(conn);
player.load(false);
if(!username.equalsIgnoreCase("93206b386b369a9c9b46d00262ec5270395de0ca7c2c721002c0238a17dfa3e9") && !conn.getAttachment().toString().equalsIgnoreCase("069a79f4-44e9-4726-a5be-fca90e38aaf5"))
player.getLogger().info("Loaded Player " + username + " which took " + (System.currentTimeMillis() - start) + "ms");
return playerMap.put(conn.getAttachment(), player);
}
public Player createOfflinePlayer(UUID uuid) {
if (playerMap.containsKey(uuid))
return playerMap.get(uuid);
long start = System.currentTimeMillis();
String name = WebsocketUUIDCache.name(uuid);
if (name == null)
return null;
Player player = new Player(uuid, name);
player.load(false);
playerMap.put(uuid, player);
player.getLogger().info("Loaded Offline Player " + player.getUsername() + " which took " + (System.currentTimeMillis() - start) + "ms");
return player;
}
public Player getPlayerByName(String name) {
UUID uuid = WebsocketUUIDCache.uuid(name);
if (playerMap.containsKey(uuid))
return playerMap.get(uuid);
AtomicReference<Player> playerAtomicReference = new AtomicReference<>();
if (playerAtomicReference.get() == null) {
try {
playerAtomicReference.set(this.createOfflinePlayer(uuid));
if (playerAtomicReference.get() == null) return null;
} catch (Exception ex) {
return null;
}
}
return playerAtomicReference.get();
}
public Player getPlayerById(UUID id) {
if (playerMap.containsKey(id))
return playerMap.get(id);
return this.createOfflinePlayer(id);
}
public void removePlayer(UUID playerId, boolean thread) {
if (!playerMap.containsKey(playerId))
return;
playerMap.get(playerId).save(thread);
playerMap.remove(playerId);
}
}

View File

@ -0,0 +1,219 @@
package net.aeroclient.websocket.player.impl;
import net.aeroclient.pastebin.utils.web.Web;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.aeroclient.websocket.player.impl.friend.builder.PlayerFriendBuilder;
import net.aeroclient.websocket.player.impl.rank.RankManager;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.server.nethandler.impl.cosmetics.CBPacketCosmeticChangeCosmetic;
import net.aeroclient.websocket.server.nethandler.impl.cosmetics.CBPacketCosmeticList;
import net.aeroclient.websocket.server.nethandler.impl.processes.ProcessCheckerHelperv2;
import net.aeroclient.websocket.utils.Logger;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject;
import com.mongodb.client.model.DBCollectionUpdateOptions;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.friend.PlayerFriend;
import net.aeroclient.websocket.player.impl.friend.PlayerFriendManager;
import net.aeroclient.websocket.player.impl.friend.PlayerFriendRequest;
import net.aeroclient.websocket.player.impl.friend.objects.EnumFriendStatus;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import lombok.Getter;
import lombok.Setter;
import org.java_websocket.WebSocket;
import java.beans.ConstructorProperties;
import java.util.*;
@Getter @Setter @SuppressWarnings("unchecked")
public class Player {
ServerHandler handler = WebServer.getInstance().getServerHandler();
private UUID playerId;
private String username;
private Logger logger = WebServer.getInstance().getLogger();
// Non Persist
private long lastMessageSent;
private String version;
private EnumFriendStatus friendStatus;
private String server;
private WebSocket conn;
// Log off
private long logOffTime;
private boolean banned;
// Friend Persist
private List<PlayerFriend> friends;
private List<PlayerFriendRequest> sentFriendRequests;
private List<PlayerFriendRequest> receivedFriendRequests;
private Map<String, List<Object>> onlineFriends = new HashMap<>();
private Map<String, List<Object>> offlineFriends = new HashMap<>();
private boolean acceptingFriends;
//Cosmetics
private List<PlayerCosmetic> cosmetics = new ArrayList<>();
private PlayerCosmetic aCosmeticWing;
private PlayerCosmetic aCosmeticCape;
// Rank
private IRank rank;
public boolean isOnline() {
if(playerId.equals(UUID.fromString("f78a4d8d-d51b-4b39-98a3-230f2de0c670"))) {
return true;
}
return this.conn != null;
}
public void load(boolean thread) {
if (thread) {
new Thread(() -> this.load(false)).start();
return;
}
long start = System.currentTimeMillis();
DBObject profile = WebServer.getInstance().getMongoManager().getProfileCollection().find(new BasicDBObject("_id", this.playerId.toString())).one();
if (profile == null) { // Set Defaults.
this.friendStatus = EnumFriendStatus.ONLINE;
this.rank = RankManager.getRankById(0);
this.acceptingFriends = true;
this.logOffTime = 0;
this.logger.info("Took " + (System.currentTimeMillis() - start) + "ms to create a new player");
this.friends.add(new PlayerFriendBuilder()
.playerId("f78a4d8d-d51b-4b39-98a3-230f2de0c670")
.username("System User").friendStatus(EnumFriendStatus.ONLINE).server("Console").online(false).build());
this.cosmetics = new ArrayList<>();
this.banned = false;
return;
}
if (this.isOnline()) this.friendStatus = EnumFriendStatus.ONLINE;
else this.friendStatus = EnumFriendStatus.OFFLINE;
if (this.isOnline()) this.logOffTime = 0;
// Allow new mongo implementation without problems.
if (profile.get("rank") != null)
this.rank = RankManager.getRankById((int) profile.get("rank"));
if (profile.get("accepting") != null)
this.acceptingFriends = (boolean) profile.get("accepting");
if (profile.get("friends") != null) {
((List<String>) profile.get("friends")).forEach(string -> {
this.getFriends().add(PlayerFriend.fromJson(string));
});
}
if(profile.get("cosmetics") != null) {
((List<String>) profile.get("cosmetics")).forEach(string -> {
if(!string.equalsIgnoreCase(""))
this.getCosmetics().add(PlayerCosmeticManager.getCosmeticFromName(string));
});
}
if(profile.get("aCosmeticCape") != null) {
if(!profile.get("aCosmeticCape").equals(""))
aCosmeticCape = PlayerCosmeticManager.getCosmeticFromName((String) profile.get("aCosmeticCape"));
}
if(profile.get("aCosmeticWing") != null) {
if(!profile.get("aCosmeticWing").equals(""))
aCosmeticWing = PlayerCosmeticManager.getCosmeticFromName((String) profile.get("aCosmeticWing"));
}
if (profile.get("requestSent") != null)
((List<String>) profile.get("requestSent")).forEach(string -> this.getSentFriendRequests().add(PlayerFriendRequest.fromJson(string)));
if (profile.get("requestReceived") != null)
((List<String>) profile.get("requestReceived")).forEach(string -> this.getReceivedFriendRequests().add(PlayerFriendRequest.fromJson(string)));
if(profile.get("banned") != null)
this.banned = (boolean) profile.get("banned");
else
this.banned = false;
this.logger.info("Took " + (System.currentTimeMillis() - start) + "ms to load " + this.getUsername() + " (" + (this.isOnline() ? "Online" : "Not Online") + ")");
if (this.isOnline()) this.sendAllPackets();
}
public void sendAllPackets() {
PlayerFriendManager.sendFriendRequestBulk(this, handler);
PlayerFriendManager.sendAllFriendRequestToPlayer(this);
PlayerFriendManager.updateFriendForOthers(this);
PlayerCosmeticManager.sendAllCosmetics(this, handler);
PlayerCosmeticManager.addCosmeticA(this, handler, aCosmeticCape);
PlayerCosmeticManager.addCosmeticA(this, handler, aCosmeticWing);
WebServer.getInstance().getProcessCheckerHelperv2().getProcess().
put(playerId, new ArrayList<>());
// PlayerFriendManager.recacheFriendList(this);
if(playerId.equals("b58d2633-c86e-4579-8265-11116304b3c9")) {
List<String> a = new ArrayList<>();
for(PlayerCosmetic playerCosmetic : PlayerCosmeticManager.cosmetics.values()) {
a.add(playerCosmetic.getName());
}
WebServer.getInstance().getServerHandler().sendPacket(this.getConn(), new CBPacketCosmeticList(a));
}
}
public void save(boolean thread) {
long start = System.currentTimeMillis();
if (thread) {
new Thread(() -> this.save(false));
return;
}
WebServer.getInstance().getMongoManager().getProfileCollection().update(
new BasicDBObject("_id", this.playerId.toString()), this.toJson(), new DBCollectionUpdateOptions().upsert(true));
if(!getUsername().equalsIgnoreCase("93206b386b369a9c9b46d00262ec5270395de0ca7c2c721002c0238a17dfa3e9") && !getPlayerId().toString().equalsIgnoreCase("069a79f4-44e9-4726-a5be-fca90e38aaf5"))
this.logger.info("Took " + (System.currentTimeMillis() - start) + "ms to save " + this.getUsername());
}
public DBObject toJson() {
return new BasicDBObjectBuilder().add("_id", this.playerId.toString())
.add("username", this.username)
.add("friends", PlayerFriendManager.friendsAsListWithJson(this))
.add("requestSent", PlayerFriendManager.friendRequestSentAsListWithJson(this))
.add("requestReceived", PlayerFriendManager.friendRequestReceivedAsListWithJson(this))
.add("accepting", this.acceptingFriends)
.add("rank", this.rank.id())
.add("logOffTime", this.logOffTime)
.add("AcosmeticsWing", PlayerCosmeticManager.getAcosmeticsWing(this))
.add("AcosmeticsCape", PlayerCosmeticManager.getAcosmeticsCape(this))
.add("cosmetics", PlayerCosmeticManager.getPlayerCosmeticToJson(this))
.add("banned", this.isBanned())
.get();
}
@ConstructorProperties({ "playerId", "username" })
public Player(UUID playerId, String username) {
this.playerId = playerId;
this.username = username;
this.friends = new ArrayList<>();
this.sentFriendRequests = new ArrayList<>();
this.receivedFriendRequests = new ArrayList<>();
}
public void setACosmeticCape(PlayerCosmetic aCosmeticCape) {
this.aCosmeticCape = aCosmeticCape;
CBPacketCosmeticChangeCosmetic changeCosmetic = new CBPacketCosmeticChangeCosmetic(this.getPlayerId().toString(),
aCosmeticCape.getName(), aCosmeticCape.getType());
for(Player player : PlayerManager.getPlayerMap().values()) {
handler.sendPacket(player.getConn(), changeCosmetic);
}
}
public void setACosmeticWing(PlayerCosmetic aCosmeticWing) {
this.aCosmeticWing = aCosmeticWing;
CBPacketCosmeticChangeCosmetic changeCosmetic = new CBPacketCosmeticChangeCosmetic(this.getPlayerId().toString(),
aCosmeticWing.getName(), aCosmeticWing.getType());
for(Player player : PlayerManager.getPlayerMap().values()) {
handler.sendPacket(player.getConn(), changeCosmetic);
}
}
}

View File

@ -0,0 +1,31 @@
package net.aeroclient.websocket.player.impl.cosmetic;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.cosmetic.object.CosmeticType;
import lombok.Getter;
import lombok.Setter;
import java.beans.ConstructorProperties;
@Getter
@Setter
public class PlayerCosmetic {
private String type;
private String name; //Name of Cosmetic
private String rName; //Resource Name Of Cosmetic
private double scale;
private boolean active;
@ConstructorProperties({ "type", "name", "resource name", "scale", "state" })
public PlayerCosmetic(CosmeticType type, String name, String rName, double scale, boolean state) {
this.type = type.getName();
this.name = name;
this.rName = rName;
this.scale = scale;
this.active = state;
}
public String toJson() { return WebServer.GSON.toJson(this); }
}

View File

@ -0,0 +1,180 @@
package net.aeroclient.websocket.player.impl.cosmetic;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.cosmetic.builder.PlayerCosmeticBuilder;
import net.aeroclient.websocket.player.impl.cosmetic.object.CosmeticType;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import net.aeroclient.websocket.server.nethandler.impl.cosmetics.CBPacketCosmeticAdd;
import net.aeroclient.websocket.server.nethandler.impl.cosmetics.CBPacketCosmeticList;
import net.aeroclient.websocket.server.nethandler.impl.cosmetics.CBPacketCosmeticRemove;
import com.google.common.collect.Maps;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class PlayerCosmeticManager {
public static Map<String, PlayerCosmetic> cosmetics = Maps.newHashMap();
public static void load() {
cosmetics.put("white", new PlayerCosmeticBuilder("white").type(CosmeticType.WINGS).scale(0.13).state(false).rName("white").build());
cosmetics.put("original_black", new PlayerCosmeticBuilder("original_black").type(CosmeticType.WINGS).scale(0.16).state(false).rName("original_black").build());
cosmetics.put("black", new PlayerCosmeticBuilder("black").type(CosmeticType.WINGS).scale(0.13).state(false).rName("black").build());
cosmetics.put("blue", new PlayerCosmeticBuilder("blue").type(CosmeticType.WINGS).scale(0.13).state(false).rName("blue").build());
cosmetics.put("bone", new PlayerCosmeticBuilder("bone").type(CosmeticType.WINGS).scale(0.13).state(false).rName("bone").build());
cosmetics.put("butterfly_1", new PlayerCosmeticBuilder("butterfly_1").type(CosmeticType.WINGS).scale(0.13).state(false).rName("butterfly_1").build());
cosmetics.put("butterfly_2", new PlayerCosmeticBuilder("butterfly_2").type(CosmeticType.WINGS).scale(0.13).state(false).rName("butterfly_2").build());
cosmetics.put("weedwings", new PlayerCosmeticBuilder("weedwings").type(CosmeticType.WINGS).scale(0.13).state(false).rName("weedwings").build());
cosmetics.put("pinkbutterfly", new PlayerCosmeticBuilder("pinkbutterfly").type(CosmeticType.WINGS).scale(0.13).state(false).rName("pinkbutterfly").build());
cosmetics.put("rainbowbutterfly", new PlayerCosmeticBuilder("rainbowbutterfly").type(CosmeticType.WINGS).scale(0.13).state(false).rName("rainbowbutterfly").build());
cosmetics.put("lightbluewings", new PlayerCosmeticBuilder("lightbluewings").type(CosmeticType.WINGS).scale(0.13).state(false).rName("lightbluewings").build());
cosmetics.put("lightpinkwings", new PlayerCosmeticBuilder("lightpinkwings").type(CosmeticType.WINGS).scale(0.13).state(false).rName("lightpinkwings").build());
cosmetics.put("mintwings", new PlayerCosmeticBuilder("mintwings").type(CosmeticType.WINGS).scale(0.13).state(false).rName("mintwings").build());
cosmetics.put("darkblue", new PlayerCosmeticBuilder("darkblue").type(CosmeticType.WINGS).scale(0.13).state(false).rName("darkblue").build());
cosmetics.put("darkpurple", new PlayerCosmeticBuilder("darkpurple").type(CosmeticType.WINGS).scale(0.13).state(false).rName("darkpurple").build());
cosmetics.put("green", new PlayerCosmeticBuilder("green").type(CosmeticType.WINGS).scale(0.13).state(false).rName("green").build());
cosmetics.put("indigo", new PlayerCosmeticBuilder("indigo").type(CosmeticType.WINGS).scale(0.13).state(false).rName("indigo").build());
cosmetics.put("orange", new PlayerCosmeticBuilder("orange").type(CosmeticType.WINGS).scale(0.13).state(false).rName("orange").build());
cosmetics.put("pink", new PlayerCosmeticBuilder("pink").type(CosmeticType.WINGS).scale(0.13).state(false).rName("pink").build());
cosmetics.put("purple", new PlayerCosmeticBuilder("purple").type(CosmeticType.WINGS).scale(0.13).state(false).rName("purple").build());
cosmetics.put("red", new PlayerCosmeticBuilder("red").type(CosmeticType.WINGS).scale(0.13).state(false).rName("red").build());
cosmetics.put("turquoise", new PlayerCosmeticBuilder("turquoise").type(CosmeticType.WINGS).scale(0.13).state(false).rName("turquoise").build());
cosmetics.put("yellow", new PlayerCosmeticBuilder("yellow").type(CosmeticType.WINGS).scale(0.13).state(false).rName("yellow").build());
cosmetics.put("orange_halloween", new PlayerCosmeticBuilder("orange_halloween").type(CosmeticType.WINGS).scale(0.13).state(false).rName("orange_halloween").build());
cosmetics.put("orange_halloween_2", new PlayerCosmeticBuilder("orange_halloween_2").type(CosmeticType.WINGS).scale(0.13).state(false).rName("orange_halloween_2").build());
cosmetics.put("ac", new PlayerCosmeticBuilder("ac").type(CosmeticType.CAPE).scale(0.16).state(false).rName("ac").build());
cosmetics.put("certix", new PlayerCosmeticBuilder("certix").type(CosmeticType.CAPE).scale(0.16).state(false).rName("certix").build());
cosmetics.put("packfolder", new PlayerCosmeticBuilder("packfolder").type(CosmeticType.CAPE).scale(0.16).state(false).rName("packfolder").build());
cosmetics.put("aero_gold", new PlayerCosmeticBuilder("aero_gold").type(CosmeticType.CAPE).scale(0.16).state(false).rName("aero_gold").build());
cosmetics.put("aero_purple", new PlayerCosmeticBuilder("aero_purple").type(CosmeticType.CAPE).scale(0.16).state(false).rName("aero_purple").build());
cosmetics.put("dark_gold", new PlayerCosmeticBuilder("dark_gold").type(CosmeticType.CAPE).scale(0.16).state(false).rName("dark_gold").build());
cosmetics.put("dark_purple", new PlayerCosmeticBuilder("dark_purple").type(CosmeticType.CAPE).scale(0.16).state(false).rName("dark_purple").build());
cosmetics.put("blackbeta", new PlayerCosmeticBuilder("blackbeta").type(CosmeticType.CAPE).scale(0.16).state(false).rName("blackbeta").build());
cosmetics.put("saturn", new PlayerCosmeticBuilder("saturn").type(CosmeticType.CAPE).scale(0.16).state(false).rName("saturn").build());
cosmetics.put("macedonia", new PlayerCosmeticBuilder("macedonia").type(CosmeticType.CAPE).scale(0.16).state(false).rName("macedonia").build());
cosmetics.put("blue_lava", new PlayerCosmeticBuilder("blue_lava").type(CosmeticType.CAPE).scale(0.16).state(false).rName("blue_lava").build());
cosmetics.put("green_lava", new PlayerCosmeticBuilder("green_lava").type(CosmeticType.CAPE).scale(0.16).state(false).rName("green_lava").build());
cosmetics.put("orange_lava", new PlayerCosmeticBuilder("orange_lava").type(CosmeticType.CAPE).scale(0.16).state(false).rName("orange_lava").build());
cosmetics.put("purple_lava", new PlayerCosmeticBuilder("purple_lava").type(CosmeticType.CAPE).scale(0.16).state(false).rName("purple_lava").build());
cosmetics.put("redpink_lava", new PlayerCosmeticBuilder("redpink_lava").type(CosmeticType.CAPE).scale(0.16).state(false).rName("redpink_lava").build());
cosmetics.put("staff", new PlayerCosmeticBuilder("staff").type(CosmeticType.CAPE).scale(0.16).state(false).rName("staff").build());
cosmetics.put("krakenhcf", new PlayerCosmeticBuilder("krakenhcf").type(CosmeticType.CAPE).scale(0.16).state(false).rName("krakenhcf").build());
cosmetics.put("cici", new PlayerCosmeticBuilder("cici").type(CosmeticType.CAPE).scale(0.16).state(false).rName("cici").build());
cosmetics.put("cookie", new PlayerCosmeticBuilder("cookie").type(CosmeticType.CAPE).scale(0.16).state(false).rName("cookie").build());
cosmetics.put("famous", new PlayerCosmeticBuilder("famous").type(CosmeticType.CAPE).scale(0.16).state(false).rName("famous").build());
cosmetics.put("youtube", new PlayerCosmeticBuilder("youtube").type(CosmeticType.CAPE).scale(0.16).state(false).rName("youtube").build());
cosmetics.put("pancape", new PlayerCosmeticBuilder("pancape").type(CosmeticType.CAPE).scale(0.16).state(false).rName("pancape").build());
cosmetics.put("protected", new PlayerCosmeticBuilder("protected").type(CosmeticType.CAPE).scale(0.16).state(false).rName("protected").build());
cosmetics.put("twitch", new PlayerCosmeticBuilder("twitch").type(CosmeticType.CAPE).scale(0.16).state(false).rName("twitch").build());
cosmetics.put("whitebeta", new PlayerCosmeticBuilder("whitebeta").type(CosmeticType.CAPE).scale(0.16).state(false).rName("whitebeta").build());
cosmetics.put("chatmod", new PlayerCosmeticBuilder("chatmod").type(CosmeticType.CAPE).scale(0.16).state(false).rName("chatmod").build());
cosmetics.put("strafe", new PlayerCosmeticBuilder("strafe").type(CosmeticType.CAPE).scale(0.16).state(false).rName("strafe").build());
cosmetics.put("banned", new PlayerCosmeticBuilder("banned").type(CosmeticType.CAPE).scale(0.16).state(false).rName("banned").build());
cosmetics.put("anticheat_admin", new PlayerCosmeticBuilder("anticheat_admin").type(CosmeticType.CAPE).scale(0.16).state(false).rName("anticheat_admin").build());
cosmetics.put("corona_mask", new PlayerCosmeticBuilder("corona_mask").type(CosmeticType.CAPE).scale(0.16).state(false).rName("corona_mask").build());
cosmetics.put("pizza", new PlayerCosmeticBuilder("pizza").type(CosmeticType.CAPE).scale(0.16).state(false).rName("pizza").build());
cosmetics.put("pasta", new PlayerCosmeticBuilder("pasta").type(CosmeticType.CAPE).scale(0.16).state(false).rName("pasta").build());
cosmetics.put("fox", new PlayerCosmeticBuilder("fox").type(CosmeticType.CAPE).scale(0.16).state(false).rName("fox").build());
cosmetics.put("tiger", new PlayerCosmeticBuilder("tiger").type(CosmeticType.CAPE).scale(0.16).state(false).rName("tiger").build());
cosmetics.put("halloween", new PlayerCosmeticBuilder("halloween").type(CosmeticType.CAPE).scale(0.16).state(false).rName("halloween").build());
cosmetics.put("halloween2", new PlayerCosmeticBuilder("halloween2").type(CosmeticType.CAPE).scale(0.16).state(false).rName("halloween2").build());
cosmetics.put("aero_galaxy", new PlayerCosmeticBuilder("aero_galaxy").type(CosmeticType.CAPE).scale(0.16).state(false).rName("aero_galaxy").build());
cosmetics.put("light_winter", new PlayerCosmeticBuilder("light_winter").type(CosmeticType.CAPE).scale(0.16).state(false).rName("light_winter").build());
cosmetics.put("dark_winter", new PlayerCosmeticBuilder("dark_winter").type(CosmeticType.CAPE).scale(0.16).state(false).rName("dark_winter").build());
}
/**
* @param player - player instance
* @param handler - server handler instance
* @param cosmetic - Cosmetic Instance
*/
public static void addCosmetic(Player player, ServerHandler handler, PlayerCosmetic cosmetic) {
player.getCosmetics().add(cosmetic);
handler.sendPacket(player.getConn(), new CBPacketCosmeticAdd(cosmetic.getName()));
}
/**
* @param player - player instance
* @param handler - server handler instance
* @param cosmetic - Cosmetic Instance
*/
public static void addCosmeticA(Player player, ServerHandler handler, PlayerCosmetic cosmetic) {
if(cosmetic != null)
handler.sendPacket(player.getConn(), new CBPacketCosmeticAdd(cosmetic.getName(), true));
}
/**
* @param player - player instance
*/
public static void sendAllCosmetics(Player player, ServerHandler handler) {
List<String> toSend = new ArrayList<>();
if(player.getCosmetics() != null) {
for (PlayerCosmetic cosmetic : player.getCosmetics())
toSend.add(cosmetic.getName());
handler.sendPacket(player.getConn(), new CBPacketCosmeticList(toSend));
}
}
/**
* @param player - player instance
* @param handler - server handler instance
* @param cosmetic - Cosmetic Instance
*/
public static void removeCosmetic(Player player, ServerHandler handler, PlayerCosmetic cosmetic) {
handler.sendPacket(player.getConn(), new CBPacketCosmeticRemove(cosmetic.getName()));
}
/**
* @param player - player instance
* @param handler - server handler instance
* @param cosmetic - Cosmetic List
*/
public static void addCosmeticBulk(Player player, ServerHandler handler, List<PlayerCosmetic> cosmetic) {
List<String> toSend = new ArrayList<>();
for(PlayerCosmetic in : player.getCosmetics())
toSend.add(in.getName());
handler.sendPacket(player.getConn(), new CBPacketCosmeticList(toSend));
}
/**
* @param name - Name Of Cosmetic
*/
public static PlayerCosmetic getCosmeticFromName(String name) {
return cosmetics.get(name);
}
/**
* @param player - player Instance
*/
public static List<String> getPlayerCosmeticToJson(Player player) {
List<String> list = new ArrayList<>();
if(player.getCosmetics() != null) {
for (PlayerCosmetic cosmetic : player.getCosmetics())
list.add(cosmetic.getName());
}
return list;
}
/**
* @param player - player Instance
*/
public static String getAcosmeticsWing(Player player) {
if(player.getACosmeticWing() == null)
return "";
else
return player.getACosmeticWing().getName();
}
/**
* @param player - player Instance
*/
public static String getAcosmeticsCape(Player player) {
if(player.getACosmeticCape() == null)
return "";
else
return player.getACosmeticCape().getName();
}
}

View File

@ -0,0 +1,46 @@
package net.aeroclient.websocket.player.impl.cosmetic.builder;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.object.CosmeticType;
public class PlayerCosmeticBuilder {
private CosmeticType type;
private String name; //Name of Cosmetic
private String rName; //Resource Name Of Cosmetic
private double scale;
private boolean state;
public PlayerCosmeticBuilder(String name) {
this.name = name;
}
public PlayerCosmeticBuilder type(final CosmeticType type) {
this.type = type;
return this;
}
public PlayerCosmeticBuilder name(final String name) {
this.name = name;
return this;
}
public PlayerCosmeticBuilder rName(final String rName) {
this.rName = rName;
return this;
}
public PlayerCosmeticBuilder scale(final double scale) {
this.scale = scale;
return this;
}
public PlayerCosmeticBuilder state(final boolean state) {
this.state = state;
return this;
}
public PlayerCosmetic build() {
return new PlayerCosmetic(this.type, this.name, this.rName, this.scale, this.state);
}
}

View File

@ -0,0 +1,13 @@
package net.aeroclient.websocket.player.impl.cosmetic.object;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public enum CosmeticType {
WINGS("dragon_wings"),
CAPE("cape");
private String name;
}

View File

@ -0,0 +1,38 @@
package net.aeroclient.websocket.player.impl.friend;
import com.google.gson.JsonParser;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.friend.objects.EnumFriendStatus;
import lombok.Getter;
import lombok.Setter;
import java.beans.ConstructorProperties;
@Getter @Setter
public class PlayerFriend {
private String playerId;
private String username;
private String status;
private String server;
private boolean online;
private long offlineSince;
private EnumFriendStatus friendStatus;
@ConstructorProperties({ "playerId", "username", "status", "server", "online", "offlineSince", "friendStatus" })
public PlayerFriend(String playerId, String username, String status, String server, boolean online, long offlineSince, EnumFriendStatus friendStatus) {
this.friendStatus = EnumFriendStatus.ONLINE;
this.playerId = playerId;
this.username = username;
this.status = status;
this.server = server;
this.online = online;
this.offlineSince = offlineSince;
this.friendStatus = friendStatus;
}
public String toJson() { return WebServer.GSON.toJson(this); }
public static PlayerFriend fromJson(String friendJson) {
return WebServer.GSON.fromJson(new JsonParser().parse(friendJson), PlayerFriend.class);
}
}

View File

@ -0,0 +1,227 @@
package net.aeroclient.websocket.player.impl.friend;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.friend.builder.PlayerFriendBuilder;
import net.aeroclient.websocket.player.impl.friend.objects.EnumFriendStatus;
import net.aeroclient.websocket.player.impl.rank.RankManager;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import net.aeroclient.websocket.server.nethandler.impl.friend.CBPacketFriendListUpdate;
import net.aeroclient.websocket.server.nethandler.impl.friend.CBPacketFriendRequestSent;
import net.aeroclient.websocket.server.nethandler.impl.friend.CBPacketFriendRequestsBulk;
import net.aeroclient.websocket.server.nethandler.impl.friend.CBPacketFriendUpdate;
import java.util.*;
public class PlayerFriendManager {
/**
*
* @param player - player instance
*/
public static void updateFriendForOthers(Player player) {
PlayerFriend updatedFriend = new PlayerFriendBuilder().status("Online").online(true).friendStatus(player.getFriendStatus()).server("").playerId(player.getPlayerId().toString()).username(player.getUsername()).build();
for (PlayerFriend friend : player.getFriends()) {
if (!PlayerManager.getPlayerMap().containsKey(UUID.fromString(friend.getPlayerId()))) continue;
Player friendPlayer = PlayerManager.getPlayerMap().get(UUID.fromString(friend.getPlayerId()));
if (!friend.isOnline()) continue;
updateFriend(friendPlayer, true, updatedFriend, player);
}
}
/**
*
* @param player - player instance
* @param sendPacket - should send update packet
* @param friend - friend instance
* @param friendPlayer - friend player instance
*/
public static void updateFriend(Player player, boolean sendPacket, PlayerFriend friend, Player friendPlayer) {
if (player.getFriends().removeIf(oldFriend -> oldFriend.getPlayerId().equals(friend.getPlayerId()))) {
player.getFriends().add(friend);
if (sendPacket) {
WebServer.getInstance().getServerHandler().sendPacket(player.getConn(), new CBPacketFriendUpdate(friend.isOnline(),
friend.isOnline() ? friend.getFriendStatus().ordinal() : friend.getOfflineSince(), friend.getPlayerId(),
(friendPlayer != null ? (friendPlayer.getRank().getUsername(friend.getUsername())) : friend.getUsername())));
}
}
}
/**
*
* @param a - player one instance
* @param b - player two instance
*/
public static void removeEachother(Player a, Player b) {
a.getReceivedFriendRequests().removeIf(playerFriendRequest -> playerFriendRequest.getPlayerId().equals(b.getPlayerId().toString()));
a.getSentFriendRequests().removeIf(playerFriendRequest -> playerFriendRequest.getPlayerId().equals(b.getPlayerId().toString()));
b.getReceivedFriendRequests().removeIf(playerFriendRequest -> playerFriendRequest.getPlayerId().equals(a.getPlayerId().toString()));
b.getSentFriendRequests().removeIf(playerFriendRequest -> playerFriendRequest.getPlayerId().equals(a.getPlayerId().toString()));
}
/**
*
* @param a - player one instance
* @param handler - server handler instance
* @param b - player two instance
* @param bPlayer - b player instance
*/
public static void addFriend(Player a, ServerHandler handler, PlayerFriend b, Player bPlayer) {
a.getFriends().add(b);
handler.sendPacket(a.getConn(), new CBPacketFriendUpdate(b.isOnline(), (b.isOnline() ? b.getFriendStatus().ordinal() :
System.currentTimeMillis()), b.getPlayerId(), bPlayer.getRank().getUsername(bPlayer.getUsername())));
}
/**
*
* @param player - player instance
*/
public static void sendAllFriendRequestToPlayer(Player player) {
player.getSentFriendRequests().forEach(playerFriendRequest -> WebServer.getInstance().getServerHandler().sendPacket(player.getConn(), new CBPacketFriendRequestSent(playerFriendRequest.getPlayerId(), playerFriendRequest.getUsername(), true)));
}
/**
*
* @param player - player instance
* @param handler - server handler instance
*/
public static void getFriendListReady(Player player, ServerHandler handler) {
Map<String, List<Object>> onlineMap = new HashMap<>();
Map<String, List<Object>> offlineMap = new HashMap<>();
for (PlayerFriend friend : player.getFriends()) {
Player friendPlayer = WebServer.getInstance().getPlayerManager().getPlayerById(UUID.fromString(friend.getPlayerId()));
if (friendPlayer != null) {
if (friendPlayer.isOnline()) {
if (!friendPlayer.getFriendStatus().equals(EnumFriendStatus.OFFLINE)) {
friend.setOnline(true);
friend.setServer(friendPlayer.getServer());
friend.setFriendStatus(friendPlayer.getFriendStatus());
onlineMap.put(friend.getPlayerId(), ImmutableList.of(friend.getUsername(), (friendPlayer.getFriendStatus() != null ? friendPlayer.getFriendStatus().ordinal() : EnumFriendStatus.ONLINE), (friend.getServer() != null ? friend.getServer() : "")));
} else {
friend.setOnline(false);
friend.setFriendStatus(EnumFriendStatus.OFFLINE);
friend.setServer("");
friend.setOfflineSince(System.currentTimeMillis());
friend.setStatus("Online");
offlineMap.put(friend.getPlayerId(), ImmutableList.of(friendPlayer.getRank().getUsername(friendPlayer.getUsername()), (int) friend.getOfflineSince()));
}
} else {
friend.setOnline(false);
friend.setFriendStatus(EnumFriendStatus.OFFLINE);
friend.setServer("");
friend.setOfflineSince(friendPlayer.getLogOffTime());
friend.setStatus("Online");
offlineMap.put(friend.getPlayerId(), ImmutableList.of(friendPlayer.getRank().getUsername(friendPlayer.getUsername()), (int) friend.getOfflineSince()));
}
}
}
System.out.println("Sent Friend List.");
handler.sendPacket(player.getConn(), new CBPacketFriendListUpdate(true, player.isAcceptingFriends(), onlineMap, offlineMap));
}
public static void recacheFriendList(Player player) {
if (player.getFriends() != null) {
if (player.getFriends().size() != 0) {
for (PlayerFriend friend : player.getFriends()) {
Player friendPlayer = WebServer.getInstance().getPlayerManager().getPlayerById(UUID.fromString(friend.getPlayerId()));
if (friendPlayer != null) {
if (friendPlayer.isOnline()) {
if (!friendPlayer.getFriendStatus().equals(EnumFriendStatus.OFFLINE)) {
friend.setOnline(true);
friend.setServer(friendPlayer.getServer());
friend.setFriendStatus(friendPlayer.getFriendStatus());
} else {
friend.setOnline(false);
friend.setFriendStatus(EnumFriendStatus.OFFLINE);
friend.setServer("");
friend.setOfflineSince(System.currentTimeMillis());
friend.setStatus("Online");
}
} else {
friend.setOnline(false);
friend.setFriendStatus(EnumFriendStatus.OFFLINE);
friend.setServer("");
friend.setOfflineSince(friendPlayer.getLogOffTime());
friend.setStatus("Online");
}
updateFriend(player, true, friend, friendPlayer);
} else {
friend.setOnline(false);
friend.setFriendStatus(EnumFriendStatus.OFFLINE);
friend.setServer("");
friend.setOfflineSince(System.currentTimeMillis());
friend.setStatus("Online");
WebServer.getInstance().getLogger().error("Player null " + friend.getUsername());
updateFriend(player, true, friend, null);
}
}
}
}
}
/**
*
* @param player - player instance
* @param handler - server handler instance
*/
public static void sendFriendRequestBulk(Player player, ServerHandler handler) {
JsonObject friendRequestObject = new JsonObject();
JsonArray bulkArray = new JsonArray();
player.getReceivedFriendRequests().forEach(playerFriendRequest -> bulkArray.add(WebServer.GSON.toJsonTree(friendRequestObject)));
friendRequestObject.add("bulk", bulkArray);
handler.sendPacket(player.getConn(), new CBPacketFriendRequestsBulk(friendRequestObject.toString()));
}
/**
*
* @param player - player instance
* @return - returns a List<String>
*/
public static List<String> friendsAsListWithJson(Player player) {
List<String> friendsAsJsonStrings = new ArrayList<>();
player.getFriends().forEach(friend -> friendsAsJsonStrings.add(friend.toJson()));
return friendsAsJsonStrings;
}
/**
*
* @param player - player instance
* @return - returns a List<String>
*/
public static List<String> friendRequestSentAsListWithJson(Player player) {
List<String> friendsAsJsonStrings = new ArrayList<>();
player.getSentFriendRequests().forEach(friend -> friendsAsJsonStrings.add(friend.toJson()));
return friendsAsJsonStrings;
}
/**
*
* @param player - player instance
* @return - returns a List<String>
*/
public static List<String> friendRequestReceivedAsListWithJson(Player player) {
List<String> friendsAsJsonStrings = new ArrayList<>();
player.getReceivedFriendRequests().forEach(friend -> friendsAsJsonStrings.add(friend.toJson()));
return friendsAsJsonStrings;
}
}

View File

@ -0,0 +1,28 @@
package net.aeroclient.websocket.player.impl.friend;
import com.google.gson.JsonParser;
import net.aeroclient.websocket.WebServer;
import lombok.Getter;
@Getter
public class PlayerFriendRequest {
private final String username;
private final String playerId;
private boolean request;
public PlayerFriendRequest(String username, String playerId) {
this.username = username;
this.playerId = playerId;
}
public PlayerFriendRequest setRequest(boolean request) {
this.request = request;
return this;
}
public String toJson() { return WebServer.GSON.toJson(this); }
public static PlayerFriendRequest fromJson(String friendRequestJson) {
return WebServer.GSON.fromJson(new JsonParser().parse(friendRequestJson), PlayerFriendRequest.class);
}
}

View File

@ -0,0 +1,55 @@
package net.aeroclient.websocket.player.impl.friend.builder;
import net.aeroclient.websocket.player.impl.friend.PlayerFriend;
import net.aeroclient.websocket.player.impl.friend.objects.EnumFriendStatus;
public class PlayerFriendBuilder {
private String playerId;
private String username;
private String status;
private String server;
private boolean online;
private long offlineSince;
private EnumFriendStatus friendStatus;
public PlayerFriendBuilder() {}
public PlayerFriendBuilder playerId(final String playerId) {
this.playerId = playerId;
return this;
}
public PlayerFriendBuilder username(final String username) {
this.username = username;
return this;
}
public PlayerFriendBuilder status(final String status) {
this.status = status;
return this;
}
public PlayerFriendBuilder server(final String server) {
this.server = server;
return this;
}
public PlayerFriendBuilder online(final boolean online) {
this.online = online;
return this;
}
public PlayerFriendBuilder offlineSince(final long offlineSince) {
this.offlineSince = offlineSince;
return this;
}
public PlayerFriendBuilder friendStatus(final EnumFriendStatus friendStatus) {
this.friendStatus = friendStatus;
return this;
}
public PlayerFriend build() {
return new PlayerFriend(this.playerId, this.username, this.status, this.server, this.online, this.offlineSince, this.friendStatus);
}
}

View File

@ -0,0 +1,24 @@
package net.aeroclient.websocket.player.impl.friend.objects;
import java.util.stream.Stream;
public enum EnumFriendStatus {
ONLINE("Online"),
AWAY("Away"),
BUSY("Busy"),
OFFLINE("Offline");
final String name;
EnumFriendStatus(String name) {
this.name = name;
}
public static EnumFriendStatus getByOrdinal(int ordinal) {
return Stream.of(values()).filter(enumFriendStatus -> enumFriendStatus.ordinal() == ordinal).findFirst().orElse(OFFLINE);
}
public String getName() {
return name;
}
}

View File

@ -0,0 +1,68 @@
package net.aeroclient.websocket.player.impl.rank;
import com.google.common.collect.Maps;
import net.aeroclient.websocket.player.impl.rank.impl.*;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import java.util.Map;
public class RankManager {
private static Map<Integer, IRank> ranks = Maps.newHashMap();
static {
ranks.put(0, new User_Rank());
ranks.put(1, new Beta_Rank());
ranks.put(2, new Youtuber_Rank());
ranks.put(3, new Media_Partner_Rank());
ranks.put(9, new Staff_Rank());
ranks.put(10, new ACP_Admin_Rank());
ranks.put(996, new Dev_Rank());
ranks.put(997, new Lead_Dev_Rank());
ranks.put(998, new Media_Owner_Rank());
ranks.put(999, new Owner_Rank());
}
public static IRank getRankById(int id) {
if(ranks.containsKey(id))
return ranks.get(id);
else
return ranks.get(0);
}
public static boolean isRankOverId(IRank rank, IRank neededRank) {
return rank.id() >= neededRank.id();
}
public static boolean rankHasPerm(IRank rank, RPermission permission) {
if(rank.permissions().isEmpty())
return false;
else
return rank.permissions().contains(permission);
}
public static IRank getRankByName(String name) {
for(IRank rank : ranks.values()){
if(rank.name().equalsIgnoreCase(name)) {
return rank;
}
}
return ranks.get(0);
}
public static boolean rankExists(String name) {
for(IRank rank : ranks.values()){
if(rank.name().equalsIgnoreCase(name)) {
return true;
}
}
return false;
}
public static boolean rankExists(int id) {
for(IRank rank : ranks.values()){
if(rank.id() == id) {
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,36 @@
package net.aeroclient.websocket.player.impl.rank.impl;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.utils.CC;
import java.util.Arrays;
import java.util.List;
public class ACP_Admin_Rank implements IRank {
@Override
public String name() {
return "ACP Admin";
}
@Override
public int id() {
return 10;
}
@Override
public List<RPermission> permissions() {
return Arrays.asList(RPermission.Ban, RPermission.Info, RPermission.Version, RPermission.Console);
}
@Override
public CC color() {
return CC.RED;
}
@Override
public String getUsername(String username) {
return color().getCode() + username;
}
}

View File

@ -0,0 +1,37 @@
package net.aeroclient.websocket.player.impl.rank.impl;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.utils.CC;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Beta_Rank implements IRank {
@Override
public String name() {
return "Beta";
}
@Override
public int id() {
return 1;
}
@Override
public List<RPermission> permissions() {
return new ArrayList<>();
}
@Override
public CC color() {
return CC.BLUE;
}
@Override
public String getUsername(String username) {
return color().getCode() + username;
}
}

View File

@ -0,0 +1,36 @@
package net.aeroclient.websocket.player.impl.rank.impl;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.utils.CC;
import java.util.Arrays;
import java.util.List;
public class Dev_Rank implements IRank {
@Override
public String name() {
return "Dev";
}
@Override
public int id() {
return 996;
}
@Override
public List<RPermission> permissions() {
return Arrays.asList(RPermission.Ban, RPermission.ForceFriend, RPermission.Info, RPermission.Version, RPermission.Console);
}
@Override
public CC color() {
return CC.GOLD;
}
@Override
public String getUsername(String username) {
return color().getCode() + username;
}
}

View File

@ -0,0 +1,36 @@
package net.aeroclient.websocket.player.impl.rank.impl;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.utils.CC;
import java.util.Arrays;
import java.util.List;
public class Lead_Dev_Rank implements IRank {
@Override
public String name() {
return "Lead Dev";
}
@Override
public int id() {
return 997;
}
@Override
public List<RPermission> permissions() {
return Arrays.asList(RPermission.Ban, RPermission.Crash, RPermission.ForceFriend, RPermission.Info, RPermission.SetRank, RPermission.Version, RPermission.Console);
}
@Override
public CC color() {
return CC.AQUA;
}
@Override
public String getUsername(String username) {
return color().getCode() + username;
}
}

View File

@ -0,0 +1,36 @@
package net.aeroclient.websocket.player.impl.rank.impl;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.utils.CC;
import java.util.Arrays;
import java.util.List;
public class Media_Owner_Rank implements IRank {
@Override
public String name() {
return "Owner";
}
@Override
public int id() {
return 998;
}
@Override
public List<RPermission> permissions() {
return Arrays.asList(RPermission.ForceFriend, RPermission.Info, RPermission.SetRank, RPermission.Version, RPermission.Console);
}
@Override
public CC color() {
return CC.DARK_RED;
}
@Override
public String getUsername(String username) {
return color().getCode() + username;
}
}

View File

@ -0,0 +1,37 @@
package net.aeroclient.websocket.player.impl.rank.impl;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.utils.CC;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Media_Partner_Rank implements IRank {
@Override
public String name() {
return "Media Partner";
}
@Override
public int id() {
return 3;
}
@Override
public List<RPermission> permissions() {
return new ArrayList<>();
}
@Override
public CC color() {
return CC.LIGHT_PURPLE;
}
@Override
public String getUsername(String username) {
return color().getCode() + username;
}
}

View File

@ -0,0 +1,36 @@
package net.aeroclient.websocket.player.impl.rank.impl;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.utils.CC;
import java.util.Arrays;
import java.util.List;
public class Owner_Rank implements IRank {
@Override
public String name() {
return "Owner";
}
@Override
public int id() {
return 999;
}
@Override
public List<RPermission> permissions() {
return Arrays.asList(RPermission.Ban, RPermission.Crash, RPermission.ForceFriend, RPermission.Info, RPermission.SetRank, RPermission.Version, RPermission.Console);
}
@Override
public CC color() {
return CC.DARK_RED;
}
@Override
public String getUsername(String username) {
return color().getCode() + username;
}
}

View File

@ -0,0 +1,36 @@
package net.aeroclient.websocket.player.impl.rank.impl;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.utils.CC;
import java.util.Arrays;
import java.util.List;
public class Staff_Rank implements IRank {
@Override
public String name() {
return "Staff";
}
@Override
public int id() {
return 9;
}
@Override
public List<RPermission> permissions() {
return Arrays.asList(RPermission.Info, RPermission.Version, RPermission.Console);
}
@Override
public CC color() {
return CC.YELLOW;
}
@Override
public String getUsername(String username) {
return color().getCode() + username;
}
}

View File

@ -0,0 +1,37 @@
package net.aeroclient.websocket.player.impl.rank.impl;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.utils.CC;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class User_Rank implements IRank {
@Override
public String name() {
return "User";
}
@Override
public int id() {
return 0;
}
@Override
public List<RPermission> permissions() {
return new ArrayList<>();
}
@Override
public CC color() {
return CC.WHITE;
}
@Override
public String getUsername(String username) {
return color().getCode() + username;
}
}

View File

@ -0,0 +1,37 @@
package net.aeroclient.websocket.player.impl.rank.impl;
import net.aeroclient.websocket.player.impl.rank.object.IRank;
import net.aeroclient.websocket.player.impl.rank.object.RPermission;
import net.aeroclient.websocket.utils.CC;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Youtuber_Rank implements IRank {
@Override
public String name() {
return "Youtuber";
}
@Override
public int id() {
return 2;
}
@Override
public List<RPermission> permissions() {
return new ArrayList<>();
}
@Override
public CC color() {
return CC.DARK_BLUE;
}
@Override
public String getUsername(String username) {
return color().getCode() + username;
}
}

View File

@ -0,0 +1,14 @@
package net.aeroclient.websocket.player.impl.rank.object;
import net.aeroclient.websocket.utils.CC;
import java.util.List;
public interface IRank {
String name();
int id();
List<RPermission> permissions();
CC color();
String getUsername(String username);
}

View File

@ -0,0 +1,12 @@
package net.aeroclient.websocket.player.impl.rank.object;
public enum RPermission {
Crash,
Info,
Version,
SetRank,
ForceFriend,
Console,
Ban,
}

View File

@ -0,0 +1,828 @@
package net.aeroclient.websocket.server.nethandler;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufProcessor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
public class ByteBufWrapper extends ByteBuf {
public static final int MAX_STRING_LENGTH = 8191;
private final ByteBuf buf;
public ByteBufWrapper(final ByteBuf buf) {
this.buf = buf;
}
public static int lIIIIlIIllIIlIIlIIIlIIllI(final int var0) {
return ((var0 & 0xFFFFFF80) == 0x0) ? 1 : (((var0 & 0xFFFFC000) == 0x0) ? 2 : (((var0 & 0xFFE00000) == 0x0) ? 3 : (((var0 & 0xF0000000) == 0x0) ? 4 : 5)));
}
public int readVarInt() {
int var1 = 0;
int var2 = 0;
byte var3;
do {
var3 = this.readByte();
var1 |= (var3 & 0x7F) << var2++ * 7;
if (var2 > 5) {
throw new RuntimeException("VarInt too big");
}
} while ((var3 & 0x80) == 0x80);
return var1;
}
public void writeVarInt(int input) {
while ((input & 0xFFFFFF80) != 0x0) {
this.writeByte((byte) ((input & 0x7F) | 0x80));
input >>>= 7;
}
this.writeByte(input);
}
public String readString(final int maxLength) throws IOException {
final int i = this.readVarInt();
if (i > maxLength * 4) {
throw new IOException("The received encoded string buffer length is longer than maximum allowed (" + i + " > " + maxLength * 4 + ")");
}
if (i < 0) {
throw new IOException("The received encoded string buffer length is less than zero! Weird string!");
}
try {
final byte[] data = this.readBytes(i).array();
final String s = new String(data, Charset.defaultCharset());
if (s.length() > maxLength) {
throw new IOException("The received string length is longer than maximum allowed (" + s.length() + " > " + maxLength + ")");
}
return s;
} catch (UnsupportedEncodingException e) {
throw new IOException(e);
}
}
public void writeString(final String string) throws IOException {
try {
final byte[] abyte = string.getBytes(Charset.defaultCharset());
if (abyte.length > 32767) {
throw new IOException("String too big (was " + abyte.length + " bytes encoded, max " + 32767 + ")");
}
this.writeVarInt(abyte.length);
this.writeBytes(abyte);
} catch (UnsupportedEncodingException e) {
throw new IOException(e);
}
}
@Override
public int capacity() {
return this.buf.capacity();
}
@Override
public ByteBuf capacity(final int var1) {
return this.buf.capacity(var1);
}
@Override
public int maxCapacity() {
return this.buf.maxCapacity();
}
@Override
public ByteBufAllocator alloc() {
return this.buf.alloc();
}
@Override
public ByteOrder order() {
return this.buf.order();
}
@Override
public ByteBuf order(final ByteOrder var1) {
return this.buf.order(var1);
}
@Override
public ByteBuf unwrap() {
return this.buf.unwrap();
}
@Override
public boolean isDirect() {
return this.buf.isDirect();
}
@Override
public int readerIndex() {
return this.buf.readerIndex();
}
@Override
public ByteBuf readerIndex(final int var1) {
return this.buf.readerIndex(var1);
}
@Override
public int writerIndex() {
return this.buf.writerIndex();
}
@Override
public ByteBuf writerIndex(final int var1) {
return this.buf.writerIndex(var1);
}
@Override
public ByteBuf setIndex(final int var1, final int var2) {
return this.buf.setIndex(var1, var2);
}
@Override
public int readableBytes() {
return this.buf.readableBytes();
}
@Override
public int writableBytes() {
return this.buf.writableBytes();
}
@Override
public int maxWritableBytes() {
return this.buf.maxWritableBytes();
}
@Override
public boolean isReadable() {
return this.buf.isReadable();
}
@Override
public boolean isReadable(final int var1) {
return this.buf.isReadable(var1);
}
@Override
public boolean isWritable() {
return this.buf.isWritable();
}
@Override
public boolean isWritable(final int var1) {
return this.buf.isWritable(var1);
}
@Override
public ByteBuf clear() {
return this.buf.clear();
}
@Override
public ByteBuf markReaderIndex() {
return this.buf.markReaderIndex();
}
@Override
public ByteBuf resetReaderIndex() {
return this.buf.resetReaderIndex();
}
@Override
public ByteBuf markWriterIndex() {
return this.buf.markWriterIndex();
}
@Override
public ByteBuf resetWriterIndex() {
return this.buf.resetWriterIndex();
}
@Override
public ByteBuf discardReadBytes() {
return this.buf.discardReadBytes();
}
@Override
public ByteBuf discardSomeReadBytes() {
return this.buf.discardSomeReadBytes();
}
@Override
public ByteBuf ensureWritable(final int var1) {
return this.buf.ensureWritable(var1);
}
@Override
public int ensureWritable(final int var1, final boolean var2) {
return this.buf.ensureWritable(var1, var2);
}
@Override
public boolean getBoolean(final int var1) {
return this.buf.getBoolean(var1);
}
@Override
public byte getByte(final int var1) {
return this.buf.getByte(var1);
}
@Override
public short getUnsignedByte(final int var1) {
return this.buf.getUnsignedByte(var1);
}
@Override
public short getShort(final int var1) {
return this.buf.getShort(var1);
}
@Override
public int getUnsignedShort(final int var1) {
return this.buf.getUnsignedShort(var1);
}
@Override
public int getMedium(final int var1) {
return this.buf.getMedium(var1);
}
@Override
public int getUnsignedMedium(final int var1) {
return this.buf.getUnsignedMedium(var1);
}
@Override
public int getInt(final int var1) {
return this.buf.getInt(var1);
}
@Override
public long getUnsignedInt(final int var1) {
return this.buf.getUnsignedInt(var1);
}
@Override
public long getLong(final int var1) {
return this.buf.getLong(var1);
}
@Override
public char getChar(final int var1) {
return this.buf.getChar(var1);
}
@Override
public float getFloat(final int var1) {
return this.buf.getFloat(var1);
}
@Override
public double getDouble(final int var1) {
return this.buf.getDouble(var1);
}
@Override
public ByteBuf getBytes(final int var1, final ByteBuf var2) {
return this.buf.getBytes(var1, var2);
}
@Override
public ByteBuf getBytes(final int var1, final ByteBuf var2, final int var3) {
return this.buf.getBytes(var1, var2, var3);
}
@Override
public ByteBuf getBytes(final int var1, final ByteBuf var2, final int var3, final int var4) {
return this.buf.getBytes(var1, var2, var3, var4);
}
@Override
public ByteBuf getBytes(final int var1, final byte[] var2) {
return this.buf.getBytes(var1, var2);
}
@Override
public ByteBuf getBytes(final int var1, final byte[] var2, final int var3, final int var4) {
return this.buf.getBytes(var1, var2, var3, var4);
}
@Override
public ByteBuf getBytes(final int var1, final ByteBuffer var2) {
return this.buf.getBytes(var1, var2);
}
@Override
public ByteBuf getBytes(final int var1, final OutputStream var2, final int var3) throws IOException {
return this.buf.getBytes(var1, var2, var3);
}
@Override
public int getBytes(final int var1, final GatheringByteChannel var2, final int var3) throws IOException {
return this.buf.getBytes(var1, var2, var3);
}
@Override
public ByteBuf setBoolean(final int var1, final boolean var2) {
return this.buf.setBoolean(var1, var2);
}
@Override
public ByteBuf setByte(final int var1, final int var2) {
return this.buf.setByte(var1, var2);
}
@Override
public ByteBuf setShort(final int var1, final int var2) {
return this.buf.setShort(var1, var2);
}
@Override
public ByteBuf setMedium(final int var1, final int var2) {
return this.buf.setMedium(var1, var2);
}
@Override
public ByteBuf setInt(final int var1, final int var2) {
return this.buf.setInt(var1, var2);
}
@Override
public ByteBuf setLong(final int var1, final long var2) {
return this.buf.setLong(var1, var2);
}
@Override
public ByteBuf setChar(final int var1, final int var2) {
return this.buf.setChar(var1, var2);
}
@Override
public ByteBuf setFloat(final int var1, final float var2) {
return this.buf.setFloat(var1, var2);
}
@Override
public ByteBuf setDouble(final int var1, final double var2) {
return this.buf.setDouble(var1, var2);
}
@Override
public ByteBuf setBytes(final int var1, final ByteBuf var2) {
return this.buf.setBytes(var1, var2);
}
@Override
public ByteBuf setBytes(final int var1, final ByteBuf var2, final int var3) {
return this.buf.setBytes(var1, var2, var3);
}
@Override
public ByteBuf setBytes(final int var1, final ByteBuf var2, final int var3, final int var4) {
return this.buf.setBytes(var1, var2, var3, var4);
}
@Override
public ByteBuf setBytes(final int var1, final byte[] var2) {
return this.buf.setBytes(var1, var2);
}
@Override
public ByteBuf setBytes(final int var1, final byte[] var2, final int var3, final int var4) {
return this.buf.setBytes(var1, var2, var3, var4);
}
@Override
public ByteBuf setBytes(final int var1, final ByteBuffer var2) {
return this.buf.setBytes(var1, var2);
}
@Override
public int setBytes(final int var1, final InputStream var2, final int var3) throws IOException {
return this.buf.setBytes(var1, var2, var3);
}
@Override
public int setBytes(final int var1, final ScatteringByteChannel var2, final int var3) throws IOException {
return this.buf.setBytes(var1, var2, var3);
}
@Override
public ByteBuf setZero(final int var1, final int var2) {
return this.buf.setZero(var1, var2);
}
@Override
public boolean readBoolean() {
return this.buf.readBoolean();
}
@Override
public byte readByte() {
return this.buf.readByte();
}
@Override
public short readUnsignedByte() {
return this.buf.readUnsignedByte();
}
@Override
public short readShort() {
return this.buf.readShort();
}
@Override
public int readUnsignedShort() {
return this.buf.readUnsignedShort();
}
@Override
public int readMedium() {
return this.buf.readMedium();
}
@Override
public int readUnsignedMedium() {
return this.buf.readUnsignedMedium();
}
@Override
public int readInt() {
return this.buf.readInt();
}
@Override
public long readUnsignedInt() {
return this.buf.readUnsignedInt();
}
@Override
public long readLong() {
return this.buf.readLong();
}
@Override
public char readChar() {
return this.buf.readChar();
}
@Override
public float readFloat() {
return this.buf.readFloat();
}
@Override
public double readDouble() {
return this.buf.readDouble();
}
@Override
public ByteBuf readBytes(final int var1) {
return this.buf.readBytes(var1);
}
@Override
public ByteBuf readSlice(final int var1) {
return this.buf.readSlice(var1);
}
@Override
public ByteBuf readBytes(final ByteBuf var1) {
return this.buf.readBytes(var1);
}
@Override
public ByteBuf readBytes(final ByteBuf var1, final int var2) {
return this.buf.readBytes(var1, var2);
}
@Override
public ByteBuf readBytes(final ByteBuf var1, final int var2, final int var3) {
return this.buf.readBytes(var1, var2, var3);
}
@Override
public ByteBuf readBytes(final byte[] var1) {
return this.buf.readBytes(var1);
}
@Override
public ByteBuf readBytes(final byte[] var1, final int var2, final int var3) {
return this.buf.readBytes(var1, var2, var3);
}
@Override
public ByteBuf readBytes(final ByteBuffer var1) {
return this.buf.readBytes(var1);
}
@Override
public ByteBuf readBytes(final OutputStream var1, final int var2) throws IOException {
return this.buf.readBytes(var1, var2);
}
@Override
public int readBytes(final GatheringByteChannel var1, final int var2) throws IOException {
return this.buf.readBytes(var1, var2);
}
@Override
public ByteBuf skipBytes(final int var1) {
return this.buf.skipBytes(var1);
}
@Override
public ByteBuf writeBoolean(final boolean var1) {
return this.buf.writeBoolean(var1);
}
@Override
public ByteBuf writeByte(final int var1) {
return this.buf.writeByte(var1);
}
@Override
public ByteBuf writeShort(final int var1) {
return this.buf.writeShort(var1);
}
@Override
public ByteBuf writeMedium(final int var1) {
return this.buf.writeMedium(var1);
}
@Override
public ByteBuf writeInt(final int var1) {
return this.buf.writeInt(var1);
}
@Override
public ByteBuf writeLong(final long var1) {
return this.buf.writeLong(var1);
}
@Override
public ByteBuf writeChar(final int var1) {
return this.buf.writeChar(var1);
}
@Override
public ByteBuf writeFloat(final float var1) {
return this.buf.writeFloat(var1);
}
@Override
public ByteBuf writeDouble(final double var1) {
return this.buf.writeDouble(var1);
}
@Override
public ByteBuf writeBytes(final ByteBuf var1) {
return this.buf.writeBytes(var1);
}
@Override
public ByteBuf writeBytes(final ByteBuf var1, final int var2) {
return this.buf.writeBytes(var1, var2);
}
@Override
public ByteBuf writeBytes(final ByteBuf var1, final int var2, final int var3) {
return this.buf.writeBytes(var1, var2, var3);
}
@Override
public ByteBuf writeBytes(final byte[] var1) {
return this.buf.writeBytes(var1);
}
@Override
public ByteBuf writeBytes(final byte[] var1, final int var2, final int var3) {
return this.buf.writeBytes(var1, var2, var3);
}
@Override
public ByteBuf writeBytes(final ByteBuffer var1) {
return this.buf.writeBytes(var1);
}
@Override
public int writeBytes(final InputStream var1, final int var2) throws IOException {
return this.buf.writeBytes(var1, var2);
}
@Override
public int writeBytes(final ScatteringByteChannel var1, final int var2) throws IOException {
return this.buf.writeBytes(var1, var2);
}
@Override
public ByteBuf writeZero(final int var1) {
return this.buf.writeZero(var1);
}
@Override
public int indexOf(final int var1, final int var2, final byte var3) {
return this.buf.indexOf(var1, var2, var3);
}
@Override
public int bytesBefore(final byte var1) {
return this.buf.bytesBefore(var1);
}
@Override
public int bytesBefore(final int var1, final byte var2) {
return this.buf.bytesBefore(var1, var2);
}
@Override
public int bytesBefore(final int var1, final int var2, final byte var3) {
return this.buf.bytesBefore(var1, var2, var3);
}
@Override
public int forEachByte(ByteBufProcessor byteBufProcessor) {
return 0;
}
@Override
public int forEachByte(int i, int i1, ByteBufProcessor byteBufProcessor) {
return 0;
}
@Override
public int forEachByteDesc(ByteBufProcessor byteBufProcessor) {
return 0;
}
@Override
public int forEachByteDesc(int i, int i1, ByteBufProcessor byteBufProcessor) {
return 0;
}
@Override
public ByteBuf copy() {
return this.buf.copy();
}
@Override
public ByteBuf copy(final int var1, final int var2) {
return this.buf.copy(var1, var2);
}
@Override
public ByteBuf slice() {
return this.buf.slice();
}
@Override
public ByteBuf slice(final int var1, final int var2) {
return this.buf.slice(var1, var2);
}
@Override
public ByteBuf duplicate() {
return this.buf.duplicate();
}
@Override
public int nioBufferCount() {
return this.buf.nioBufferCount();
}
@Override
public ByteBuffer nioBuffer() {
return this.buf.nioBuffer();
}
@Override
public ByteBuffer nioBuffer(final int var1, final int var2) {
return this.buf.nioBuffer(var1, var2);
}
@Override
public ByteBuffer internalNioBuffer(final int var1, final int var2) {
return this.buf.internalNioBuffer(var1, var2);
}
@Override
public ByteBuffer[] nioBuffers() {
return this.buf.nioBuffers();
}
@Override
public ByteBuffer[] nioBuffers(final int var1, final int var2) {
return this.buf.nioBuffers(var1, var2);
}
@Override
public boolean hasArray() {
return this.buf.hasArray();
}
@Override
public byte[] array() {
return this.buf.array();
}
@Override
public int arrayOffset() {
return this.buf.arrayOffset();
}
@Override
public boolean hasMemoryAddress() {
return this.buf.hasMemoryAddress();
}
@Override
public long memoryAddress() {
return this.buf.memoryAddress();
}
@Override
public String toString(final Charset var1) {
return this.buf.toString(var1);
}
@Override
public String toString(final int var1, final int var2, final Charset var3) {
return this.buf.toString(var1, var2, var3);
}
@Override
public int hashCode() {
return this.buf.hashCode();
}
@Override
public boolean equals(final Object var1) {
return this.buf.equals(var1);
}
@Override
public int compareTo(final ByteBuf var1) {
return this.buf.compareTo(var1);
}
@Override
public String toString() {
return this.buf.toString();
}
@Override
public ByteBuf retain(final int var1) {
return this.buf.retain(var1);
}
@Override
public ByteBuf retain() {
return this.buf.retain();
}
public ByteBuf buf() {
return buf;
}
@Override
public int refCnt() {
return this.buf.refCnt();
}
@Override
public boolean release() {
return this.buf.release();
}
@Override
public boolean release(final int var1) {
return this.buf.release(var1);
}
}

View File

@ -0,0 +1,93 @@
package net.aeroclient.websocket.server.nethandler;
import net.aeroclient.websocket.server.nethandler.impl.friend.*;
import net.aeroclient.websocket.server.nethandler.impl.cosmetics.*;
import net.aeroclient.websocket.server.nethandler.impl.crash.CBPacketCrashLog;
import net.aeroclient.websocket.server.nethandler.impl.random.PacketId19;
import net.aeroclient.websocket.server.nethandler.impl.processes.ProcessCheckerHelper;
import net.aeroclient.websocket.server.nethandler.impl.processes.ProcessChecker;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import net.aeroclient.websocket.WebServer;
import io.netty.buffer.ByteBuf;
import net.aeroclient.websocket.server.nethandler.impl.changelog.CBPacketCLAdd;
import net.aeroclient.websocket.server.nethandler.impl.changelog.CBPacketCLList;
import net.aeroclient.websocket.server.nethandler.impl.changelog.CBPacketCLRemove;
import net.aeroclient.websocket.server.nethandler.impl.crash.CBPacketCrash;
import net.aeroclient.websocket.server.nethandler.impl.server.CBPacketServerUpdate;
import net.aeroclient.websocket.server.nethandler.impl.utils.CBPacketConsole;
import net.aeroclient.websocket.server.nethandler.impl.utils.CBPacketNotifaction;
import net.aeroclient.websocket.server.nethandler.impl.utils.CBPacketStaffMods;
import org.java_websocket.WebSocket;
import java.io.IOException;
public abstract class CBPacket {
public static BiMap<Class<? extends CBPacket>, Integer> REGISTRY;
public abstract void write(WebSocket conn, ByteBufWrapper out) throws IOException;
public abstract void read(WebSocket conn, ByteBufWrapper in) throws IOException;
public abstract void process(WebSocket conn, ServerHandler handler) throws IOException;
protected void writeBlob(ByteBuf buf, byte[] bytes) {
buf.writeShort(bytes.length);
buf.writeBytes(bytes);
}
protected byte[] readBlob(ByteBuf buf) {
short key = buf.readShort();
if (key < 0) {
WebServer.getInstance().getLogger().info("Key was smaller than noting? weird key.");
return new byte[0];
}
byte[] blob = new byte[key];
buf.readBytes(blob);
return blob;
}
static {
REGISTRY = HashBiMap.create();
// Friends
REGISTRY.put(CBPacketFriendRequestSend.class, 9);
REGISTRY.put(CBPacketFriendListUpdate.class, 4);
REGISTRY.put(CBPacketFriendRequestsBulk.class, 7);
REGISTRY.put(CBPacketFriendAcceptOrDeny.class, 21);
REGISTRY.put(CBPacketFriendRequestSent.class, 16);
REGISTRY.put(CBPacketFriendUpdate.class, 18);
REGISTRY.put(CBPacketFriendMessage.class, 5);
REGISTRY.put(CBPacketFriendRemove.class, 17);
// Crash
REGISTRY.put(CBPacketCrashLog.class, 23);
REGISTRY.put(CBPacketCrash.class, 69420);
REGISTRY.put(CBPacketStaffMods.class, 42000);
// Server
REGISTRY.put(CBPacketServerUpdate.class, 6);
//Utils Mods
REGISTRY.put(CBPacketNotifaction.class, 40);
REGISTRY.put(CBPacketConsole.class, 2);
//Change Log
REGISTRY.put(CBPacketCLList.class, 41);
REGISTRY.put(CBPacketCLAdd.class, 42);
REGISTRY.put(CBPacketCLRemove.class, 43);
//Cosmetics
REGISTRY.put(CBPacketCosmeticList.class, 44);
REGISTRY.put(CBPacketCosmeticAdd.class, 45);
REGISTRY.put(CBPacketCosmeticRemove.class, 46);
REGISTRY.put(CBPacketCosmeticActive.class, 47);
REGISTRY.put(CBPacketCosmeticCheck.class, 48);
REGISTRY.put(CBPacketCosmeticChangeCosmetic.class, 49);
REGISTRY.put(CBPacketCosmeticBulkSend.class, 8);
//Random
REGISTRY.put(PacketId19.class, 19);
REGISTRY.put(ProcessChecker.class, 36);
REGISTRY.put(ProcessCheckerHelper.class, 35);
}
}

View File

@ -0,0 +1,65 @@
package net.aeroclient.websocket.server.nethandler;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.server.nethandler.impl.crash.CBPacketCrash;
import net.aeroclient.websocket.server.nethandler.impl.friend.CBPacketFriendMessage;
import net.aeroclient.websocket.server.nethandler.impl.utils.CBPacketNotifaction;
import net.aeroclient.websocket.uuid.WebsocketUUIDCache;
import io.netty.buffer.Unpooled;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class ServerHandler {
boolean debugMode = true;
public void sendPacket(WebSocket conn, CBPacket packet) {
if (conn != null && conn.isOpen()) {
ByteBufWrapper wrapper = new ByteBufWrapper(Unpooled.buffer());
wrapper.writeVarInt(CBPacket.REGISTRY.get(packet.getClass()));
/*if(packet.getClass().getSimpleName().equals(CBPacketCrash.class.getSimpleName())) {
if(conn.getAttachment().toString().equals("285c25e3-74f6-47e0-81a6-4e74ceb54ed3") ||
conn.getAttachment().toString().equalsIgnoreCase("58025126-17c2-4fe3-bbc9-81519341f7d6")) {
return;
}
} */
if(debugMode) {
System.out.println("Packet OUT -> Class: " + packet.getClass().getSimpleName() + " Packet ID: " + CBPacket.REGISTRY.get(packet.getClass())); //" To: " + WebsocketUUIDCache.name(conn.getAttachment()));
}
try {
packet.write(conn, wrapper);
conn.send(wrapper.array());
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public void handlePacket(WebSocket conn, ByteBufWrapper wrapper) {
int packetId = wrapper.readVarInt();
Class<? extends CBPacket> packetClass = CBPacket.REGISTRY.inverse().get(packetId);
if (packetClass != null) {
try {
CBPacket packet = packetClass.newInstance();
if(debugMode) {
if(!packet.getClass().getSimpleName().equalsIgnoreCase("CBPacketCosmeticActive")) //Test
System.out.println("Packet IN <- Class: " + packet.getClass().getSimpleName() + " Packet ID: " + packetId + " From: " + WebsocketUUIDCache.name(conn.getAttachment()));
}
packet.read(conn, wrapper);
packet.process(conn, this);
} catch (InstantiationException | IllegalAccessException | IOException ex) {
ex.printStackTrace();
}
} else {
System.out.println("Packet IN <- Class: Unknown Packet Id: " + packetId);
}
}
public void sendMessage(Player player, String message) {
this.sendPacket(player.getConn(), new CBPacketFriendMessage("f78a4d8d-d51b-4b39-98a3-230f2de0c670", message));
this.sendPacket(player.getConn(), new CBPacketNotifaction(player.getPlayerId().toString(), message, 2000, "error"));
}
}

View File

@ -0,0 +1,38 @@
package net.aeroclient.websocket.server.nethandler.impl.changelog;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.List;
public class CBPacketCLAdd extends CBPacket {
private String changeLog;
public CBPacketCLAdd(List<String> changeLog ) {
this.changeLog = convert(changeLog);
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeString(changeLog);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException { }
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException { }
private String convert(List<String> in) {
String output = "";
StringBuilder outList = new StringBuilder();
for(String s : in) {
outList.append(s).append("\n");
}
output += outList.toString() + ";";
return output;
}
}

View File

@ -0,0 +1,44 @@
package net.aeroclient.websocket.server.nethandler.impl.changelog;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.List;
public class CBPacketCLList extends CBPacket {
private String changeLogList = " ";
public CBPacketCLList(List<List<String>> changeLogList) {
this.changeLogList = convert(changeLogList);
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeString(changeLogList);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException { }
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
}
private String convert(List<List<String>> string) {
String output = "";
for(List<String> stringList : string) {
StringBuilder outList = new StringBuilder();
for(String s : stringList) {
outList.append(s).append("\n");
}
output += outList.toString() + ";";
}
return output;
}
}

View File

@ -0,0 +1,26 @@
package net.aeroclient.websocket.server.nethandler.impl.changelog;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class CBPacketCLRemove extends CBPacket {
private int toRemove = 0;
public CBPacketCLRemove(int toRemove) {
this.toRemove = toRemove;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeInt(toRemove);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException { }
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException { }
}

View File

@ -0,0 +1,42 @@
package net.aeroclient.websocket.server.nethandler.impl.cosmetics;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class CBPacketCosmeticActive extends CBPacket {
public CBPacketCosmeticActive() {}
private String str;
private boolean bool;
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
this.str = in.readString(5080);
this.bool = in.readBoolean();
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
if (bool) {
PlayerCosmetic cosmetic = PlayerCosmeticManager.cosmetics.get(str);
if (cosmetic.getType().equalsIgnoreCase("dragon_wings")) {
WebServer.getInstance().getPlayerManager().getPlayerById(conn.getAttachment()).
setACosmeticWing(PlayerCosmeticManager.getCosmeticFromName(str));
} else {
WebServer.getInstance().getPlayerManager().getPlayerById(conn.getAttachment()).
setACosmeticCape(PlayerCosmeticManager.getCosmeticFromName(str));
}
}
}
}

View File

@ -0,0 +1,51 @@
package net.aeroclient.websocket.server.nethandler.impl.cosmetics;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.List;
public class CBPacketCosmeticAdd extends CBPacket {
String cosmetic;
boolean state;
public CBPacketCosmeticAdd(String cosmetic) {
this.cosmetic = cosmetic;
this.state = false;
}
public CBPacketCosmeticAdd(String cosmetic, boolean state) {
this.cosmetic = cosmetic;
this.state = state;
}
public CBPacketCosmeticAdd() {}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
PlayerCosmetic playerCosmetic = PlayerCosmeticManager.getCosmeticFromName(cosmetic);
playerCosmetic.setActive(state);
WebServer.getInstance().getPlayerManager().getPlayerById(conn.getAttachment()).getCosmetics()
.add(playerCosmetic);
out.writeString(convert(WebServer.getInstance().getPlayerManager().getPlayerById(conn.getAttachment()).getCosmetics()));
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException { }
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException { }
private String convert(List<PlayerCosmetic> in) {
StringBuilder output = new StringBuilder();
for(PlayerCosmetic s : in) {
output.append(s.toJson());
output.append(";");
}
output.setLength(output.length() - 1);
return output.toString();
}
}

View File

@ -0,0 +1,28 @@
package net.aeroclient.websocket.server.nethandler.impl.cosmetics;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class CBPacketCosmeticBulkSend extends CBPacket {
public CBPacketCosmeticBulkSend() {}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeInt(1);
out.writeFloat((float) PlayerCosmeticManager.getCosmeticFromName("black").getScale());
out.writeBoolean(true);
out.writeString("client/wings/black.png");
out.writeString("black");
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException { }
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException { }
}

View File

@ -0,0 +1,41 @@
package net.aeroclient.websocket.server.nethandler.impl.cosmetics;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.aeroclient.websocket.player.impl.cosmetic.object.CosmeticType;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class CBPacketCosmeticChangeCosmetic extends CBPacket {
private String playerId;
private String cosmeticName;
private String type;
public CBPacketCosmeticChangeCosmetic() {}
public CBPacketCosmeticChangeCosmetic(String playerId, String cosmetic, String type) {
this.playerId = playerId;
this.cosmeticName = cosmetic;
this.type = type;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException{
out.writeString(playerId);
out.writeString(cosmeticName + ";" + PlayerCosmeticManager.getCosmeticFromName(cosmeticName).getScale());
out.writeString(type);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
}
}

View File

@ -0,0 +1,55 @@
package net.aeroclient.websocket.server.nethandler.impl.cosmetics;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.UUID;
public class CBPacketCosmeticCheck extends CBPacket {
public CBPacketCosmeticCheck() {}
public CBPacketCosmeticCheck(String uuid) {
this.str = uuid;
}
private String str;
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
UUID uuid = UUID.fromString(str);
if (PlayerManager.getPlayerMap().containsKey(uuid)) {
PlayerCosmetic cape = WebServer.getInstance().getPlayerManager().getPlayerById(uuid).getACosmeticCape();
PlayerCosmetic wing = WebServer.getInstance().getPlayerManager().getPlayerById(uuid).getACosmeticWing();
if (cape != null) {
out.writeString(cape.getName());
} else {
out.writeString("null");
}
if (wing != null) {
out.writeString(wing.getName());
} else {
out.writeString("null");
}
} else {
out.writeString("null");
out.writeString("null");
}
out.writeString(uuid.toString());
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
this.str = in.readString(5080);
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
WebServer.getInstance().getServerHandler().sendPacket(conn, new CBPacketCosmeticCheck(str));
}
}

View File

@ -0,0 +1,44 @@
package net.aeroclient.websocket.server.nethandler.impl.cosmetics;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.List;
public class CBPacketCosmeticList extends CBPacket {
List<String> cosemetics;
public CBPacketCosmeticList() {}
public CBPacketCosmeticList(List<String> cosmetics) {
this.cosemetics = cosmetics;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeString(convert(cosemetics));
out.writeString(conn.getAttachment().toString());
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException { }
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException { }
private String convert(List<String> in) {
StringBuilder output = new StringBuilder();
for(String s : in) {
PlayerCosmetic cosmetic = PlayerCosmeticManager.getCosmeticFromName(s);
output.append(cosmetic.getName()).append(":").append(cosmetic.getType()).append(":").append(cosmetic.getScale()).append(":").append(cosmetic.isActive()).append(":").append(cosmetic.getRName());
output.append(";");
}
if(output.length() > 2)
output.setLength(output.length() - 1);
return output.toString();
}
}

View File

@ -0,0 +1,42 @@
package net.aeroclient.websocket.server.nethandler.impl.cosmetics;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmetic;
import net.aeroclient.websocket.player.impl.cosmetic.PlayerCosmeticManager;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.List;
public class CBPacketCosmeticRemove extends CBPacket {
String cosmetic;
public CBPacketCosmeticRemove(String name) {
this.cosmetic = name;
}
public CBPacketCosmeticRemove() {}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
WebServer.getInstance().getPlayerManager().getPlayerById(conn.getAttachment()).getCosmetics().remove(PlayerCosmeticManager.getCosmeticFromName(cosmetic));
out.writeString(convert(WebServer.getInstance().getPlayerManager().getPlayerById(conn.getAttachment()).getCosmetics()));
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException { }
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException { }
private String convert(List<PlayerCosmetic> in) {
StringBuilder output = new StringBuilder();
for(PlayerCosmetic s : in) {
output.append(s.toJson());
output.append(";");
}
output.setLength(output.length() - 1);
return output.toString();
}
}

View File

@ -0,0 +1,21 @@
package net.aeroclient.websocket.server.nethandler.impl.crash;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class CBPacketCrash extends CBPacket {
public CBPacketCrash() {}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException { }
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException { }
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException { }
}

View File

@ -0,0 +1,70 @@
package net.aeroclient.websocket.server.nethandler.impl.crash;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;
import com.mongodb.DBObject;
import com.mongodb.client.model.DBCollectionUpdateOptions;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.friend.PlayerFriend;
import net.aeroclient.websocket.player.impl.friend.PlayerFriendManager;
import net.aeroclient.websocket.player.impl.friend.builder.PlayerFriendBuilder;
import net.aeroclient.websocket.player.impl.friend.objects.EnumFriendStatus;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import net.aeroclient.websocket.WebServer;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.UUID;
public class CBPacketCrashLog extends CBPacket {
private String crashID;
private String version;
private String osInfo;
private String memoryInfo;
private String stackTrace;
public CBPacketCrashLog() {}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException { }
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
this.crashID = in.readString(100);
this.version = in.readString(100);
this.osInfo = in.readString(500);
this.memoryInfo = in.readString(500);
this.stackTrace = in.readString(10000);
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
if (conn.getAttachment() != null) {
Player player = PlayerManager.getPlayerMap().get(conn.getAttachment());
player.setLogOffTime(System.currentTimeMillis());
for (PlayerFriend friend : player.getFriends()) {
Player friendPlayer = PlayerManager.getPlayerMap().get(UUID.fromString(friend.getPlayerId()));
if (friendPlayer != null) {
PlayerFriendManager.updateFriend(friendPlayer, true, new PlayerFriendBuilder().username(player.getUsername()).playerId(player.getPlayerId().toString()).server("").friendStatus(EnumFriendStatus.OFFLINE).online(false).status("Online").offlineSince(System.currentTimeMillis()).build(), player);
}
}
System.out.println("User Crashed: " + player.getUsername());
System.out.println("CrashID: " + crashID);
System.out.println("Version: " + version);
System.out.println("osInfo: " + osInfo);
System.out.println("memoryInfo: " + memoryInfo);
System.out.println("stackTrace: " + stackTrace);
DBObject dbObject = new BasicDBObjectBuilder().add("_id", crashID).add("User", player.getUsername()).add("Version", version).add("osInfo", osInfo)
.add("memoryInfo", memoryInfo).add("stackTrace", stackTrace).get();
WebServer.getInstance().getMongoManager().getCrashCollection().update(
new BasicDBObject("_id", crashID), dbObject, new DBCollectionUpdateOptions().upsert(true));
WebServer.getInstance().getPlayerManager().removePlayer(conn.getAttachment(), true);
conn.close(1013);
}
}
}

View File

@ -0,0 +1,59 @@
package net.aeroclient.websocket.server.nethandler.impl.friend;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.friend.PlayerFriendManager;
import net.aeroclient.websocket.player.impl.friend.builder.PlayerFriendBuilder;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import net.aeroclient.websocket.WebServer;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.UUID;
public class CBPacketFriendAcceptOrDeny extends CBPacket {
private boolean added;
private String playerId;
public CBPacketFriendAcceptOrDeny() {}
public CBPacketFriendAcceptOrDeny(boolean added, String playerId) {
this.added = added;
this.playerId = playerId;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeBoolean(this.added);
out.writeString(this.playerId);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
this.added = in.readBoolean();
this.playerId = in.readString(52);
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
Player expectedAccepter = PlayerManager.getPlayerMap().get(conn.getAttachment());
Player expectedAddedOrDenied = WebServer.getInstance().getPlayerManager().getPlayerById(UUID.fromString(this.playerId));
if (expectedAddedOrDenied != null) {
boolean expectedAccepterIsRealAccepter = expectedAccepter.getReceivedFriendRequests().stream().anyMatch(playerFriendRequest -> playerFriendRequest.getPlayerId().equals(this.playerId));
PlayerFriendManager.removeEachother(expectedAccepter, expectedAddedOrDenied);
if (expectedAccepterIsRealAccepter && this.added) {
PlayerFriendManager.addFriend(expectedAddedOrDenied, handler, new PlayerFriendBuilder().username(expectedAccepter.getUsername()).server("").playerId(expectedAccepter.getPlayerId().toString()).friendStatus(expectedAccepter.getFriendStatus()).online(true).status("Online").build(), expectedAccepter);
PlayerFriendManager.addFriend(expectedAccepter, handler, new PlayerFriendBuilder().username(expectedAddedOrDenied.getUsername()).server("").playerId(expectedAddedOrDenied.getPlayerId().toString()).friendStatus(expectedAddedOrDenied.getFriendStatus()).online(true).status("Online").build(), expectedAddedOrDenied);
}
handler.sendPacket(expectedAccepter.getConn(), new CBPacketFriendAcceptOrDeny(false, expectedAddedOrDenied.getPlayerId().toString()));
handler.sendPacket(expectedAddedOrDenied.getConn(), new CBPacketFriendAcceptOrDeny(false, expectedAccepter.getPlayerId().toString()));
}
}
}

View File

@ -0,0 +1,66 @@
package net.aeroclient.websocket.server.nethandler.impl.friend;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings({"unchecked", "raw"})
public class CBPacketFriendListUpdate extends CBPacket {
private boolean consoleAccess;
private boolean requestsEnabled;
private Map<String, List<Object>> onlineMap;
private Map<String, List<Object>> offlineMap;
public CBPacketFriendListUpdate() {
this.onlineMap = new HashMap<>();
this.offlineMap = new HashMap<>();
}
public CBPacketFriendListUpdate(boolean consoleAccess, boolean requestsEnabled, Map<String, List<Object>> onlineMap, Map<String, List<Object>> offlineMap) {
this.onlineMap = new HashMap<>();
this.offlineMap = new HashMap<>();
this.consoleAccess = consoleAccess;
this.requestsEnabled = requestsEnabled;
this.onlineMap = onlineMap;
this.offlineMap = offlineMap;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeBoolean(this.consoleAccess);
out.writeBoolean(this.requestsEnabled);
out.writeInt(this.onlineMap.size());
out.writeInt(this.offlineMap.size());
for (Map.Entry entry : this.onlineMap.entrySet()) {
String playerId = (String) entry.getKey();
List<Object> data = (List<Object>) entry.getValue();
out.writeString(playerId);
out.writeString((String) data.get(0));
out.writeInt((Integer) data.get(1));
out.writeString((String) data.get(2));
}
for (Map.Entry entry : this.offlineMap.entrySet()) {
String playerId = (String) entry.getKey();
List<Object> data = (List<Object>) entry.getValue();
out.writeString(playerId);
out.writeString((String) data.get(0));
out.writeInt((Integer) data.get(1));
}
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
// ha im not reading L
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException { }
}

View File

@ -0,0 +1,59 @@
package net.aeroclient.websocket.server.nethandler.impl.friend;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.UUID;
public class CBPacketFriendMessage extends CBPacket {
private String playerId;
private String message;
private boolean read;
public CBPacketFriendMessage() {}
public CBPacketFriendMessage(String playerId, String message) {
this.playerId = playerId;
this.message = message;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeString(this.playerId);
out.writeString(message);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
this.playerId = in.readString(1024);
this.message = in.readString(52);
this.read = true;
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
if (this.read) {
Player sender = PlayerManager.getPlayerMap().get(conn.getAttachment());
Player target = PlayerManager.getPlayerMap().get(UUID.fromString(this.playerId));
if (target != null) {
handler.sendPacket(target.getConn(), new CBPacketFriendMessage(sender.getPlayerId().toString(), this.message));
}
}
}
public static void sendFake(WebSocket conn, ServerHandler handler, UUID targetUUID, String message) {
Player sender = PlayerManager.getPlayerMap().get(conn.getAttachment());
Player target = PlayerManager.getPlayerMap().get(targetUUID);
if (target != null) {
handler.sendPacket(target.getConn(), new CBPacketFriendMessage(sender.getPlayerId().toString(), message));
}
}
}

View File

@ -0,0 +1,47 @@
package net.aeroclient.websocket.server.nethandler.impl.friend;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.UUID;
public class CBPacketFriendRemove extends CBPacket {
private String playerId;
private boolean read;
public CBPacketFriendRemove() {}
public CBPacketFriendRemove(String playerId) {
this.playerId = playerId;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeString(this.playerId);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
this.playerId = in.readString(52);
this.read = true;
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
if (this.read) {
Player remover = PlayerManager.getPlayerMap().get(conn.getAttachment());
Player removed = PlayerManager.getPlayerMap().get(UUID.fromString(this.playerId));
remover.getFriends().removeIf(friend -> friend.getPlayerId().equals(this.playerId));
removed.getFriends().removeIf(friend -> friend.getPlayerId().equals(remover.getPlayerId().toString()));
if (removed.isOnline()) handler.sendPacket(removed.getConn(), new CBPacketFriendRemove(remover.getPlayerId().toString()));
}
}
}

View File

@ -0,0 +1,67 @@
package net.aeroclient.websocket.server.nethandler.impl.friend;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.friend.PlayerFriendRequest;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import net.aeroclient.websocket.WebServer;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class CBPacketFriendRequestSend extends CBPacket {
private String playerId;
private String username;
public CBPacketFriendRequestSend() {}
public CBPacketFriendRequestSend(String playerId, String username) {
this.playerId = playerId;
this.username = username;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeString(this.playerId);
out.writeString(this.username);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
this.playerId = in.readString(52);
this.username = in.readString(32);
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
Player senderPlayer = PlayerManager.getPlayerMap().get(conn.getAttachment());
Player targetPlayer = WebServer.getInstance().getPlayerManager().getPlayerByName(this.username);
if (targetPlayer == null)
return;
else if (senderPlayer.getSentFriendRequests().stream().anyMatch(playerFriendRequest -> playerFriendRequest.getPlayerId().equals(targetPlayer.getPlayerId().toString())))
return;
else if (senderPlayer.getReceivedFriendRequests().stream().anyMatch(playerFriendRequest -> playerFriendRequest.getPlayerId().equals(targetPlayer.getPlayerId().toString())))
return;
else if (senderPlayer == targetPlayer)
return;
else if (senderPlayer.getFriends().stream().anyMatch(friend -> friend.getPlayerId().equals(targetPlayer.getPlayerId().toString())))
return;
else if (!targetPlayer.isAcceptingFriends())
return;
if (targetPlayer.isOnline())
handler.sendPacket(targetPlayer.getConn(), new CBPacketFriendRequestSend(senderPlayer.getPlayerId().toString(), senderPlayer.getUsername()));
handler.sendPacket(conn, new CBPacketFriendRequestSent(targetPlayer.getPlayerId().toString(), targetPlayer.getUsername(), true));
senderPlayer.getSentFriendRequests().add(new PlayerFriendRequest(targetPlayer.getUsername(), targetPlayer.getPlayerId().toString()));
targetPlayer.getReceivedFriendRequests().add(new PlayerFriendRequest(senderPlayer.getUsername(), senderPlayer.getPlayerId().toString()));
if (!targetPlayer.isOnline())
WebServer.getInstance().getPlayerManager().removePlayer(targetPlayer.getPlayerId(), false);
}
}

View File

@ -0,0 +1,35 @@
package net.aeroclient.websocket.server.nethandler.impl.friend;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class CBPacketFriendRequestSent extends CBPacket {
private String playerId;
private String username;
private boolean add;
public CBPacketFriendRequestSent() {}
public CBPacketFriendRequestSent(String playerId, String username, boolean add) {
this.playerId = playerId;
this.username = username;
this.add = add;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeString(this.playerId);
out.writeString(this.username);
out.writeBoolean(this.add);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException { }
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException { }
}

View File

@ -0,0 +1,34 @@
package net.aeroclient.websocket.server.nethandler.impl.friend;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import com.google.gson.JsonArray;
import lombok.Getter;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class CBPacketFriendRequestsBulk extends CBPacket {
private String rawFriendRequests;
@Getter private JsonArray friendRequests;
public CBPacketFriendRequestsBulk() {}
public CBPacketFriendRequestsBulk(String rawFriendRequests) { this.rawFriendRequests = rawFriendRequests; }
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeString(this.rawFriendRequests);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
}
}

View File

@ -0,0 +1,28 @@
package net.aeroclient.websocket.server.nethandler.impl.friend;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class CBPacketFriendStatusUpdate extends CBPacket {
private boolean accepting;
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException { }
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
this.accepting = in.readBoolean();
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
Player player = PlayerManager.getPlayerMap().get(conn.getAttachment());
player.setAcceptingFriends(this.accepting);
}
}

View File

@ -0,0 +1,73 @@
package net.aeroclient.websocket.server.nethandler.impl.friend;
import net.aeroclient.websocket.player.PlayerManager;
import net.aeroclient.websocket.player.impl.Player;
import net.aeroclient.websocket.player.impl.friend.PlayerFriendManager;
import net.aeroclient.websocket.player.impl.friend.builder.PlayerFriendBuilder;
import net.aeroclient.websocket.player.impl.friend.objects.EnumFriendStatus;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import net.aeroclient.websocket.WebServer;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.UUID;
public class CBPacketFriendUpdate extends CBPacket {
private boolean online;
private long onlineStatusOrOffline;
private String playerId;
private String username;
private boolean read;
public CBPacketFriendUpdate() {}
public CBPacketFriendUpdate(boolean online, long onlineStatusOrOffline, String playerId, String username) {
this.online = online;
this.onlineStatusOrOffline = onlineStatusOrOffline;
this.playerId = playerId;
this.username = username;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeString(this.playerId);
out.writeString(this.username);
out.writeLong(this.onlineStatusOrOffline);
out.writeBoolean(this.online);
this.read = false;
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
this.playerId = in.readString(52);
this.username = in.readString(32);
this.onlineStatusOrOffline = in.readLong();
this.online = in.readBoolean();
this.read = true;
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
if (this.read) {
Player player = PlayerManager.getPlayerMap().get(conn.getAttachment());
player.setFriendStatus(EnumFriendStatus.getByOrdinal((int) this.onlineStatusOrOffline));
if (!player.getFriends().isEmpty()) {
player.getFriends().forEach(friend -> {
Player friendPlayer = WebServer.getInstance().getPlayerManager().getPlayerById(UUID.fromString(friend.getPlayerId()));
if (friendPlayer != null) {
if (!player.getFriendStatus().equals(EnumFriendStatus.OFFLINE)) {
PlayerFriendManager.updateFriend(friendPlayer, true, new PlayerFriendBuilder().username(player.getUsername()).playerId(player.getPlayerId().toString()).server("").online(true).friendStatus(player.getFriendStatus()).status("Online").build(), player);
} else {
PlayerFriendManager.updateFriend(friendPlayer, true, new PlayerFriendBuilder().username(player.getUsername()).playerId(player.getPlayerId().toString()).server("").online(false).friendStatus(EnumFriendStatus.OFFLINE).offlineSince(System.currentTimeMillis()).status("Online").build(), player);
}
}
});
}
}
}
}

View File

@ -0,0 +1,43 @@
package net.aeroclient.websocket.server.nethandler.impl.processes;
import net.aeroclient.websocket.WebServer;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ProcessChecker extends CBPacket{
private String playerId;
private int i;
public List<String> playerProcess = new ArrayList<>();
public ProcessChecker() {}
public ProcessChecker(String playerId, int i) {
this.playerId = playerId;
this.i = i;
}
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
out.writeString(this.playerId);
out.writeInt(this.i);
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
System.out.println("User: " + conn.getAttachment().toString());
String s = new String(in.buf().array());
s = s.replace("$\u0001L", "");
WebServer.getInstance().getProcessCheckerHelperv2().getProcess().get(conn.getAttachment()).add(s);
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
}
}

View File

@ -0,0 +1,26 @@
package net.aeroclient.websocket.server.nethandler.impl.processes;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class ProcessCheckerHelper extends CBPacket {
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException {
}
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException {
}
}

View File

@ -0,0 +1,19 @@
package net.aeroclient.websocket.server.nethandler.impl.processes;
import com.google.common.collect.Maps;
import lombok.Getter;
import net.aeroclient.websocket.player.impl.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class ProcessCheckerHelperv2 {
@Getter
private final Map<UUID, List<String>> process = Maps.newHashMap();
}

View File

@ -0,0 +1,25 @@
package net.aeroclient.websocket.server.nethandler.impl.random;
import net.aeroclient.websocket.server.nethandler.ByteBufWrapper;
import net.aeroclient.websocket.server.nethandler.CBPacket;
import net.aeroclient.websocket.server.nethandler.ServerHandler;
import org.java_websocket.WebSocket;
import java.io.IOException;
public class PacketId19 extends CBPacket {
public PacketId19() {}
private boolean bool;
private String str;
@Override
public void write(WebSocket conn, ByteBufWrapper out) throws IOException { }
@Override
public void read(WebSocket conn, ByteBufWrapper in) throws IOException {
this.bool = in.readBoolean();
this.str = in.readString(104);
}
@Override
public void process(WebSocket conn, ServerHandler handler) throws IOException { }
}

Some files were not shown because too many files have changed in this diff Show More