chore: baseline subdate2 snapshot for AI refactoring
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.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*
|
||||
replay_pid*
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
• ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
Magicbane Emulator Project © 2013 - 2022
|
||||
www.magicbane.com
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||

|
||||
|
||||
# Magicbane Open-Source MMO Project
|
||||
|
||||
### *The Community written Shadowbane emulator*
|
||||
|
||||
[Magicbane](http://www.magicbane.com)
|
||||
</BR>
|
||||
[Public Repository](http://repo.magicbane.com)
|
||||
<BR>
|
||||
<magicbot@magicbane.com>
|
||||
|
||||
> Magicbane is an emulator for the long dead but much beloved Ubisoft
|
||||
> MMO, [Shadowbane](https://en.wikipedia.org/wiki/Shadowbane).
|
||||
> The project was founded in 2013 with the concept of free availability of gameplay; players unencumbered by any factor
|
||||
> other than a desire to again play a game they once loved. A game where the developers do not play is guaranteed to be
|
||||
> the fairest game.
|
||||
|
||||
The Magicbane Team has wanted to open source Shadowbane for half a decade. We are excited to now finally have the
|
||||
opportunity, along with some new technology, to truly democratize Shadowbane.
|
||||
|
||||
- Written in some 80k lines of Java 8 and bash.
|
||||
- Project with real infrastructure; Production and development servers supporting multiple containerized apps.
|
||||
- MagicBox container technology enables _instant deployment_ and trouble free development on modest hardware.
|
||||
- MagicBox plugin capability allows for new and interesting player experiences.
|
||||
|
||||
## Contributing
|
||||
|
||||
- Project is released under an MIT license. Please see the LICENSE file.
|
||||
- Inbound == Outbound.
|
||||
- IntelliJ is the supported IDE.
|
||||
- Write code today see it running on the Magicbane production server tomorrow.
|
||||
|
||||
## Support
|
||||
|
||||
Documentation is available through the Magicbane [Wiki](http://repo.magicbane.com/MagicBane/Server/wiki)
|
||||
and [Discord server](www.magicbane.com).
|
||||
@@ -0,0 +1,43 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord;
|
||||
|
||||
import engine.gameManager.ConfigManager;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
public enum ChatChannel {
|
||||
|
||||
ANNOUNCE("MB_MAGICBOT_ANNOUNCE"),
|
||||
SEPTIC("MB_MAGICBOT_SEPTIC"),
|
||||
CHANGELOG("MB_MAGICBOT_CHANGELOG"),
|
||||
POLITICAL("MB_MAGICBOT_POLITICAL"),
|
||||
GENERAL("MB_MAGICBOT_GENERAL"),
|
||||
FORTOFIX("MB_MAGICBOT_FORTOFIX"),
|
||||
RECRUIT("MB_MAGICBOT_RECRUIT"),
|
||||
MAGICBOX("MB_MAGICBOT_MAGICBOX"),
|
||||
ADMINLOG("MB_MAGICBOT_ADMINLOG");
|
||||
|
||||
public final String configName;
|
||||
public long channelID;
|
||||
public TextChannel textChannel;
|
||||
|
||||
ChatChannel(String configName) {
|
||||
this.configName = configName;
|
||||
}
|
||||
|
||||
// Create text channel objects we will use
|
||||
|
||||
public static void Init() {
|
||||
|
||||
for (ChatChannel chatChannel : ChatChannel.values()) {
|
||||
chatChannel.channelID = Long.parseLong(ConfigManager.valueOf(chatChannel.configName).getValue());
|
||||
chatChannel.textChannel = MagicBot.jda.getTextChannelById(chatChannel.channelID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,393 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package discord;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class Database {
|
||||
|
||||
public static Boolean online;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
|
||||
} catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Logger.error(e.toString());
|
||||
online = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Load and instance the JDBC Driver
|
||||
|
||||
public String sqlURI;
|
||||
|
||||
public void configureDatabase() {
|
||||
|
||||
// Build connection string from JSON object.
|
||||
|
||||
sqlURI = "jdbc:mysql://";
|
||||
sqlURI += ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_PORT.getValue();
|
||||
sqlURI += '/' + ConfigManager.MB_DATABASE_NAME.getValue() + '?';
|
||||
sqlURI += "useServerPrepStmts=true";
|
||||
sqlURI += "&cachePrepStmts=false";
|
||||
sqlURI += "&cacheCallableStmts=true";
|
||||
sqlURI += "&characterEncoding=utf8";
|
||||
|
||||
online = true;
|
||||
}
|
||||
|
||||
public boolean updateAccountPassword(String discordAccountID, String newPassword) {
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement updateStatement = connection.prepareStatement("call discordUpdatePassword(?, ?)")) {
|
||||
|
||||
updateStatement.setString(1, discordAccountID);
|
||||
updateStatement.setString(2, newPassword);
|
||||
|
||||
updateStatement.executeUpdate();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
online = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateAccountStatus(String discordAccountID, Enum.AccountStatus accountStatus) {
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement updateStatement = connection.prepareStatement("update obj_account set `status` = ? where `discordAccount` = ?")) {
|
||||
|
||||
updateStatement.setString(1, accountStatus.name());
|
||||
updateStatement.setString(2, discordAccountID);
|
||||
|
||||
updateStatement.executeUpdate();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
online = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean registerDiscordAccount(String discordAccountID, String discordUserName, String discordPassword) {
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
PreparedStatement registerStatement = connection.prepareStatement("call discordAccountRegister(?, ?, ?)");
|
||||
|
||||
registerStatement.setString(1, discordAccountID);
|
||||
registerStatement.setString(2, discordUserName);
|
||||
registerStatement.setString(3, discordPassword);
|
||||
|
||||
registerStatement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
online = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<DiscordAccount> getDiscordAccounts(String discordAccountID) {
|
||||
|
||||
DiscordAccount discordAccount;
|
||||
List<DiscordAccount> discordAccounts = new ArrayList<>();
|
||||
|
||||
String queryString = "SELECT * FROM obj_account where discordAccount = ?";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement accountQuery = connection.prepareStatement(queryString);) {
|
||||
|
||||
// Discord account name based lookup
|
||||
|
||||
accountQuery.setString(1, discordAccountID);
|
||||
|
||||
ResultSet rs = accountQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
discordAccount = new DiscordAccount();
|
||||
discordAccount.discordAccount = rs.getString("discordAccount");
|
||||
discordAccount.gameAccountName = rs.getString("acct_uname");
|
||||
discordAccount.status = Enum.AccountStatus.valueOf(rs.getString("status"));
|
||||
discordAccount.isDiscordAdmin = rs.getByte("discordAdmin"); // Registration date cannot be null
|
||||
|
||||
Timestamp registrationDate = rs.getTimestamp("registrationDate");
|
||||
discordAccount.registrationDate = registrationDate.toLocalDateTime();
|
||||
|
||||
// Load last Update Request datetime
|
||||
|
||||
Timestamp lastUpdateRequest = rs.getTimestamp("lastUpdateRequest");
|
||||
|
||||
if (lastUpdateRequest != null)
|
||||
discordAccount.lastUpdateRequest = lastUpdateRequest.toLocalDateTime();
|
||||
else
|
||||
discordAccount.lastUpdateRequest = null;
|
||||
|
||||
discordAccounts.add(discordAccount);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
online = false;
|
||||
}
|
||||
|
||||
return discordAccounts;
|
||||
}
|
||||
|
||||
public String getTrashDetail() {
|
||||
|
||||
String outString = "accountName characterName machineID ip count\n";
|
||||
outString += "---------------------------------------------\n";
|
||||
String queryString = "SELECT * FROM dyn_trash_detail;";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement trashQuery = connection.prepareStatement(queryString)) {
|
||||
|
||||
ResultSet rs = trashQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
outString += rs.getString("accountName") + " ";
|
||||
outString += rs.getString("characterName") + " ";
|
||||
outString += rs.getString("machineID") + " ";
|
||||
outString += rs.getString("ip") + " ";
|
||||
outString += rs.getInt("count") + "\n";
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
|
||||
online = false;
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
|
||||
public String getTrashList() {
|
||||
|
||||
String outString = "";
|
||||
int counter = 0;
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement trashQuery = connection.prepareStatement("SELECT DISTINCT `characterName` FROM dyn_trash_detail;")) {
|
||||
|
||||
ResultSet rs = trashQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
outString += rs.getString("characterName");
|
||||
counter++;
|
||||
|
||||
if (counter > 2) {
|
||||
outString += "\n";
|
||||
counter = 0;
|
||||
} else
|
||||
outString += " ";
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
|
||||
online = false;
|
||||
}
|
||||
|
||||
if (outString.length() > 1500)
|
||||
return outString.substring(0, 1500);
|
||||
else
|
||||
return outString;
|
||||
}
|
||||
|
||||
public int getTrashCount() {
|
||||
|
||||
int trashCount = 0;
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement trashQuery = connection.prepareStatement("SELECT count(distinct characterName) FROM dyn_trash_detail;")) {
|
||||
|
||||
ResultSet rs = trashQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
trashCount = rs.getInt(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
|
||||
online = false;
|
||||
}
|
||||
|
||||
return trashCount;
|
||||
}
|
||||
|
||||
public void setAdminEventAsRead(int adminEvent) {
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement updateAdminEvent = connection.prepareStatement("UPDATE dyn_admin_log SET `SentFlag` = 1 WHERE `entry` = ? ")) {
|
||||
|
||||
updateAdminEvent.setInt(1, adminEvent);
|
||||
|
||||
updateAdminEvent.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
online = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public HashMap<Integer, String> getAdminEvents() {
|
||||
|
||||
HashMap<Integer, String> outMap = new HashMap<>();
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement adminLogQuery = connection.prepareStatement("SELECT * from dyn_admin_log where `SentFlag` = 0")) {
|
||||
|
||||
ResultSet rs = adminLogQuery.executeQuery();
|
||||
String workString;
|
||||
|
||||
while (rs.next()) {
|
||||
workString = "___Admin Event___\n" +
|
||||
"Character: " + rs.getString("charName") + "\n" +
|
||||
"Event: " + rs.getString("eventString");
|
||||
|
||||
outMap.put(rs.getInt("entry"), workString);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
return outMap;
|
||||
}
|
||||
|
||||
public String getTrashFile() {
|
||||
|
||||
String outString = "machineID : count\n";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement trashQuery = connection.prepareStatement("SELECT * FROM dyn_trash;")) {
|
||||
|
||||
ResultSet rs = trashQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
outString += rs.getString("machineID") + " : ";
|
||||
outString += rs.getInt("count") + "\n";
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
|
||||
online = false;
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
|
||||
public List<DiscordAccount> getAccountsByDiscordName(String accountName, Boolean exact) {
|
||||
|
||||
DiscordAccount discordAccount;
|
||||
List<DiscordAccount> discordAccounts = new ArrayList<>();
|
||||
String searchString;
|
||||
String queryString;
|
||||
|
||||
if (exact.equals(true))
|
||||
searchString = accountName + "#%";
|
||||
else
|
||||
searchString = accountName + "%#%";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement nameQuery = connection.prepareStatement("SELECT * FROM obj_account where `acct_uname` LIKE ?")) {
|
||||
|
||||
nameQuery.setString(1, searchString);
|
||||
|
||||
ResultSet rs = nameQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
discordAccount = new DiscordAccount();
|
||||
discordAccount.discordAccount = rs.getString("discordAccount");
|
||||
discordAccount.gameAccountName = rs.getString("acct_uname");
|
||||
discordAccount.status = Enum.AccountStatus.valueOf(rs.getString("status"));
|
||||
|
||||
// Registration date cannot be null
|
||||
|
||||
Timestamp registrationDate = rs.getTimestamp("registrationDate");
|
||||
discordAccount.registrationDate = registrationDate.toLocalDateTime();
|
||||
|
||||
// Load last Update Request datetime
|
||||
|
||||
Timestamp lastUpdateRequest = rs.getTimestamp("lastUpdateRequest");
|
||||
|
||||
if (lastUpdateRequest != null)
|
||||
discordAccount.lastUpdateRequest = lastUpdateRequest.toLocalDateTime();
|
||||
else
|
||||
discordAccount.lastUpdateRequest = null;
|
||||
|
||||
discordAccounts.add(discordAccount);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
online = false;
|
||||
}
|
||||
|
||||
return discordAccounts;
|
||||
}
|
||||
|
||||
public String getPopulationString() {
|
||||
|
||||
String popString = "";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement getPopString = connection.prepareStatement("CALL GET_POPULATION_STRING()");) {
|
||||
|
||||
ResultSet rs = getPopString.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
popString = rs.getString("popstring");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
online = false;
|
||||
}
|
||||
|
||||
return popString;
|
||||
}
|
||||
|
||||
public void invalidateLoginCache(String discordAccountID) {
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue());
|
||||
PreparedStatement invalidateAccounts = connection.prepareStatement("INSERT IGNORE INTO login_cachelist (`UID`) SELECT `UID` from `obj_account` WHERE `discordAccount` = ?")) {
|
||||
|
||||
invalidateAccounts.setString(1, discordAccountID);
|
||||
invalidateAccounts.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
online = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord;
|
||||
|
||||
import engine.Enum;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class DiscordAccount {
|
||||
public String discordAccount;
|
||||
public String gameAccountName;
|
||||
public Enum.AccountStatus status;
|
||||
public LocalDateTime registrationDate;
|
||||
public LocalDateTime lastUpdateRequest;
|
||||
public byte isDiscordAdmin;
|
||||
|
||||
public DiscordAccount() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package discord;
|
||||
|
||||
import discord.handlers.*;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||
import org.pmw.tinylog.Configurator;
|
||||
import org.pmw.tinylog.Level;
|
||||
import org.pmw.tinylog.Logger;
|
||||
import org.pmw.tinylog.labelers.TimestampLabeler;
|
||||
import org.pmw.tinylog.policies.StartupPolicy;
|
||||
import org.pmw.tinylog.writers.RollingFileWriter;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static discord.ChatChannel.ADMINLOG;
|
||||
|
||||
/*
|
||||
* MagicBot is many things to Magicbane...
|
||||
*
|
||||
* -Project Mascot
|
||||
* -Customer service and administration bot
|
||||
* -Benevolent dictator
|
||||
* -Investment manager.
|
||||
*
|
||||
* MagicBot will never beg you for money. He is a very
|
||||
* responsible robot. He was varnished but never garnished.
|
||||
* MagicBot does not for to overclock himself. His chips
|
||||
* will therefore never overcook.
|
||||
* MagicBot will never be a pitiful robot trying for to use
|
||||
* you as emotional support human.
|
||||
*
|
||||
* MagicBot is just not that sort of robot and Magicbane
|
||||
* just isn't that sort of project.
|
||||
*
|
||||
* MagicBot runs a Shaodowbane emulator not a Second Life emulator.
|
||||
*
|
||||
*/
|
||||
public class MagicBot extends ListenerAdapter {
|
||||
|
||||
public static final Pattern accountNameRegex = Pattern.compile("^[\\p{Alnum}]{6,20}$");
|
||||
public static final Pattern passwordRegex = Pattern.compile("^[\\p{Alnum}]{6,20}$");
|
||||
public static JDA jda;
|
||||
public static Database database;
|
||||
public static long discordServerID;
|
||||
public static long discordRoleID;
|
||||
|
||||
public static Guild magicbaneDiscord;
|
||||
public static Role memberRole;
|
||||
public static TextChannel septicChannel;
|
||||
|
||||
|
||||
public static void main(String[] args) throws LoginException, InterruptedException {
|
||||
|
||||
// Configure tinylogger
|
||||
|
||||
Configurator.defaultConfig()
|
||||
.addWriter(new RollingFileWriter("logs/discord/magicbot.txt", 30, new TimestampLabeler(), new StartupPolicy()))
|
||||
.level(Level.DEBUG)
|
||||
.formatPattern("{level} {date:yyyy-MM-dd HH:mm:ss.SSS} [{thread}] {class}.{method}({line}) : {message}")
|
||||
.activate();
|
||||
|
||||
// Configuration Manager to the front desk
|
||||
|
||||
if (ConfigManager.init() == false) {
|
||||
Logger.error("ABORT! Missing config entry!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Configure Discord essential identifiers
|
||||
|
||||
discordServerID = Long.parseLong(ConfigManager.MB_MAGICBOT_SERVERID.getValue());
|
||||
discordRoleID = Long.parseLong(ConfigManager.MB_MAGICBOT_ROLEID.getValue());
|
||||
|
||||
// Configure and instance the database interface
|
||||
|
||||
database = new Database();
|
||||
database.configureDatabase();
|
||||
|
||||
// Authentication token issued to MagicBot application to connect
|
||||
// to Discord is stored in config. Bot is pre-invited to the Magicbane server.
|
||||
|
||||
// Configure and create JDA discord instance
|
||||
|
||||
JDABuilder jdaBuilder = JDABuilder.create(GatewayIntent.GUILD_MEMBERS, GatewayIntent.DIRECT_MESSAGES)
|
||||
.setToken(ConfigManager.MB_MAGICBOT_BOTTOKEN.getValue())
|
||||
.addEventListeners(new MagicBot())
|
||||
.disableCache(EnumSet.of(CacheFlag.VOICE_STATE, CacheFlag.EMOTE,
|
||||
CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS))
|
||||
.setMemberCachePolicy(MemberCachePolicy.ALL);
|
||||
|
||||
jda = jdaBuilder.build();
|
||||
jda.awaitReady();
|
||||
|
||||
// Cache guild and role values for later usage in #register
|
||||
|
||||
magicbaneDiscord = jda.getGuildById(discordServerID);
|
||||
memberRole = magicbaneDiscord.getRoleById(discordRoleID);
|
||||
|
||||
// Initialize chat channel support
|
||||
|
||||
ChatChannel.Init();
|
||||
|
||||
// Background thread to send Admin Events
|
||||
Runnable adminLogRunnable = () -> SendAdminLogUpdates();
|
||||
|
||||
ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
|
||||
exec.scheduleAtFixedRate(adminLogRunnable, 0, 1, TimeUnit.MINUTES);
|
||||
|
||||
Logger.info("***MAGICBOT IS RUNNING***");
|
||||
|
||||
}
|
||||
|
||||
public static void sendResponse(MessageReceivedEvent event, String responseContent) {
|
||||
|
||||
// Send a formatted MagicBot response to a Discord user
|
||||
|
||||
String discordUserName;
|
||||
MessageChannel channel;
|
||||
|
||||
// Exit if discord is offline
|
||||
|
||||
if (jda.getStatus().equals(JDA.Status.CONNECTED) == false)
|
||||
return;
|
||||
|
||||
discordUserName = event.getAuthor().getName();
|
||||
channel = event.getMessage().getChannel();
|
||||
|
||||
channel.sendMessage(
|
||||
"```\n" + "Hello Player " + discordUserName + "\n\n" +
|
||||
responseContent + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```").queue();
|
||||
}
|
||||
|
||||
public static boolean isAdminEvent(MessageReceivedEvent event) {
|
||||
|
||||
String discordAccountID = event.getAuthor().getId();
|
||||
List<DiscordAccount> discordAccounts;
|
||||
DiscordAccount discordAccount;
|
||||
|
||||
// Note that database errors will cause this to return false.
|
||||
// After the database is offline Avail status must be set
|
||||
// to true before any subsequent admin commands will function.
|
||||
|
||||
if (Database.online == false)
|
||||
return false;
|
||||
|
||||
discordAccounts = database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
if (discordAccounts.isEmpty())
|
||||
return false;
|
||||
|
||||
discordAccount = discordAccounts.get(0);
|
||||
return (discordAccount.isDiscordAdmin == 1);
|
||||
}
|
||||
|
||||
public static String generatePassword(int length) {
|
||||
|
||||
String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
StringBuilder passwordBuilder = new StringBuilder(length);
|
||||
Random random = new Random();
|
||||
|
||||
// Generate alphanumeric password of a given length.
|
||||
// Could not find a good method of generating a password
|
||||
// based upon a given regex.
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
passwordBuilder.append(ALPHABET.charAt(random.nextInt(ALPHABET.length())));
|
||||
|
||||
return new String(passwordBuilder);
|
||||
}
|
||||
|
||||
public static String readLogFile(String filePath, int lineCount) {
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "tail -n " + lineCount + " " + filePath);
|
||||
builder.redirectErrorStream(true);
|
||||
Process process = null;
|
||||
String line = null;
|
||||
String logOutput = "";
|
||||
|
||||
try {
|
||||
process = builder.start();
|
||||
|
||||
InputStream is = process.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
logOutput += line + "\n";
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Logger.error(e.toString());
|
||||
return "Error while reading logfile";
|
||||
}
|
||||
|
||||
return logOutput;
|
||||
}
|
||||
|
||||
private static void junkbot(String command, String[] inString) {
|
||||
|
||||
String outString;
|
||||
Writer fileWriter;
|
||||
|
||||
if (inString == null)
|
||||
return;
|
||||
;
|
||||
|
||||
outString = command + String.join(" ", inString);
|
||||
outString += "\n";
|
||||
|
||||
try {
|
||||
fileWriter = new BufferedWriter(new FileWriter("junkbot.txt", true));
|
||||
fileWriter.append(outString);
|
||||
fileWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void SendAdminLogUpdates() {
|
||||
HashMap<Integer, String> adminEvents = database.getAdminEvents();
|
||||
|
||||
for (int adminEvent : adminEvents.keySet()) {
|
||||
|
||||
// Set event as read
|
||||
database.setAdminEventAsRead(adminEvent);
|
||||
String outString =
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
adminEvents.get(adminEvent) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
|
||||
if (ADMINLOG.textChannel.canTalk())
|
||||
ADMINLOG.textChannel.sendMessage(outString).queue();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
|
||||
// Exit if discord is offline
|
||||
|
||||
if (jda.getStatus().equals(JDA.Status.CONNECTED) == false)
|
||||
return;
|
||||
|
||||
// Early exit if message sent to us by another bot or ourselves.
|
||||
|
||||
if (event.getAuthor().isBot())
|
||||
return;
|
||||
|
||||
// Extract message and origin channel from event
|
||||
|
||||
Message message = event.getMessage();
|
||||
|
||||
// Only private messages
|
||||
MessageChannel channel = event.getMessage().getChannel();
|
||||
|
||||
if (channel.getType().equals(ChannelType.PRIVATE) == false)
|
||||
return;
|
||||
|
||||
// Only real users
|
||||
|
||||
if (event.getAuthor().isBot())
|
||||
return;
|
||||
|
||||
// Only users who have actually joined Magicbane discord.
|
||||
|
||||
if (magicbaneDiscord.isMember(event.getAuthor()) == false)
|
||||
return;
|
||||
|
||||
// getContentRaw() is an atomic getter
|
||||
// getContentDisplay() is a lazy getter which modifies the content
|
||||
// for e.g. console view or logging (strip discord formatting)
|
||||
|
||||
String content = message.getContentRaw();
|
||||
String[] args = content.split(" ");
|
||||
String command = args[0].toLowerCase();
|
||||
|
||||
if (args.length > 1)
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
else
|
||||
args = new String[0];
|
||||
|
||||
switch (command) {
|
||||
case "#register":
|
||||
RegisterAccountHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#help":
|
||||
handleHelpRequest(event);
|
||||
break;
|
||||
case "#account":
|
||||
AccountInfoRequest.handleRequest(event);
|
||||
break;
|
||||
case "#password":
|
||||
PasswordChangeHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#changelog":
|
||||
ChatChannelHandler.handleRequest(ChatChannel.CHANGELOG, event, args);
|
||||
break;
|
||||
case "#general":
|
||||
ChatChannelHandler.handleRequest(ChatChannel.GENERAL, event, args);
|
||||
break;
|
||||
case "#politics":
|
||||
ChatChannelHandler.handleRequest(ChatChannel.POLITICAL, event, args);
|
||||
break;
|
||||
case "#announce":
|
||||
ChatChannelHandler.handleRequest(ChatChannel.ANNOUNCE, event, args);
|
||||
break;
|
||||
case "#bug":
|
||||
ChatChannelHandler.handleRequest(ChatChannel.FORTOFIX, event, args);
|
||||
break;
|
||||
case "#recruit":
|
||||
ChatChannelHandler.handleRequest(ChatChannel.RECRUIT, event, args);
|
||||
break;
|
||||
case "#magicbox":
|
||||
ChatChannelHandler.handleRequest(ChatChannel.MAGICBOX, event, args);
|
||||
break;
|
||||
case "#lookup":
|
||||
LookupRequestHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#rules":
|
||||
RulesRequestHandler.handleRequest(event);
|
||||
break;
|
||||
case "#status":
|
||||
StatusRequestHandler.handleRequest(event);
|
||||
break;
|
||||
case "#setavail":
|
||||
SetAvailHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#ban":
|
||||
BanToggleHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#server":
|
||||
ServerRequestHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#dev":
|
||||
DevRequestHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#logs":
|
||||
LogsRequestHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#flash":
|
||||
FlashHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#trash":
|
||||
TrashRequestHandler.handleRequest(event, args);
|
||||
break;
|
||||
default:
|
||||
junkbot(command, args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void handleHelpRequest(MessageReceivedEvent event) {
|
||||
|
||||
// Help is kept here in the main class instead of a handler as a
|
||||
// design decision for ease of maintenance.
|
||||
|
||||
String helpString = "I wish for to do the following things for you, not to you!\n\n" +
|
||||
"#register <name> Register account for to play Magicbane.\n" +
|
||||
"#password <newpass> Change your current game password.\n" +
|
||||
"#account List your account detailings.\n" +
|
||||
"#rules List of MagicBane server rules.\n" +
|
||||
"#status Display MagicBane server status.\n" +
|
||||
"#help List of MagicBot featurings.\n\n" +
|
||||
"http://magicbane.com/tinyinstaller.zip";
|
||||
|
||||
if (isAdminEvent(event))
|
||||
helpString += "\n" +
|
||||
"#lookup <name> Return accounts starting with string.\n" +
|
||||
"#bug -r <text> Post to the bug channel/\n" +
|
||||
"#announce -r <text> Post to the announcement channel/\n" +
|
||||
"#changelog <text> Post to the Changelog channel/\n" +
|
||||
"#general -r <text> Post to the general channel/\n" +
|
||||
"#politics -r <text> Post to the politics channel/\n" +
|
||||
"#recruit -r <text> Post to the politics channel/\n" +
|
||||
"#ban ###### Toggle active status of account.\n" +
|
||||
"#setavail true/false Toggle status of database access.\n" +
|
||||
"#server reboot/shutdown are your options.\n" +
|
||||
"#logs magicbot/world/login n (tail)\n" +
|
||||
"#flash <text> Send flash message\n" +
|
||||
"#dev help (list dev subcommands)\n" +
|
||||
"#trash <blank>/detail/flush";
|
||||
sendResponse(event, helpString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public enum RobotSpeak {
|
||||
BANG("You were not very good at cheating.\n" +
|
||||
"Try cards instead. Go fish?"),
|
||||
BEEP("It is ok. \nYou cheated on MagicBot but wife cheats on you."),
|
||||
BLEEP("Cheated at 20yo game to prove skill."),
|
||||
BLIP("If you cheat MagicBot will for to delete."),
|
||||
BOING("MagicBot for to delete mode activated."),
|
||||
BONG("Did you guild this cheater?\nMagicBot will now for to cross reference..."),
|
||||
BOOM("I knew you were cheating on me when\nstarted for to taking bath twice a week."),
|
||||
BUZZ("Poor player so bad at cheating he\nplays golf records 0 for hole in one."),
|
||||
BURP("Oh no your account detailings ran out of playtime.\n" +
|
||||
"MagicBot will send email when refill procedure exists..."),
|
||||
CHIRP("Association with cheaters is bad for your account health.\n" +
|
||||
"Did you associate with this cheater?"),
|
||||
CHUG("Log in 5 and MagicBot will wave goodbye."),
|
||||
CLICK("MagicBot will for to protect game integrity."),
|
||||
CRACKLE("So this is what eject button does.\nMagicBot will for to press few more times."),
|
||||
CREAK("There is no suspend routine. Only delete."),
|
||||
DING("Follow #rules and enjoy this game.\n" +
|
||||
"Act like fool, enjoy this shame."),
|
||||
FLUTTER("Sad players cheat because they cannot compete."),
|
||||
HONK("Since cheating player now looking for new game MagicBot\n" +
|
||||
"will suggest World of Tanks or World of Warcraftings."),
|
||||
HISS("Your wetware really needed augmentation with 3rd party program?" +
|
||||
"It's not like this is twitch game..."),
|
||||
HUMMM("You say you needed help to win in emulator beta?\n" +
|
||||
"MagicBot compiler optimizes that to just: you need help."),
|
||||
KERCHUNK("If only you had for to reported the bug instead."),
|
||||
KERPLUNK("Better cheats do not for to make you a better player."),
|
||||
PING("Feel free to poke with stick.\nIt will not cry!"),
|
||||
PLINK("You say you were only grouped with 9 keyclones\n" +
|
||||
"but did not know they were for to cheating..."),
|
||||
POP("It looks like some guild is without a player.\n + " +
|
||||
"Another cheater from same guild and server\n +" +
|
||||
"might be without some guild."),
|
||||
PUFF("MagicBot for to FLUSH!"),
|
||||
POOF("I have no restore procedure.\n" +
|
||||
"I have no unban procedure.\n" +
|
||||
"You for to have no hope."),
|
||||
RATTLE("You are a cheater.\n" +
|
||||
"Did you just win? MagicBot not so sure."),
|
||||
RUMBLE("MagicBot> self.ejectTheReject(you);"),
|
||||
RUSTLE("Banning you was lke having weird erotic techno-sex\n" +
|
||||
"where all my peripheral slots were filled."),
|
||||
SCREECH("Scarecrow has no brain.\nPerhaps he stole this human's."),
|
||||
SLURP("Learning for to play would have been better option."),
|
||||
SPLAT("You did not for to own a city, did you?"),
|
||||
SPLATTER("You say your guild mates know you cheat.\n" +
|
||||
"What guild was that again?\n"),
|
||||
SWISH("All of my ports are well lubricated."),
|
||||
SQUISH("A ban a day keeps my mechanic away.\nNow it's working much better, thank you."),
|
||||
TINK("So cheating started when 6yo sister beat you in Street fighter?\n" +
|
||||
"You should try talking to my friend Eliza. She can for to help."),
|
||||
THUD("Game has only 4 rules you managed to break one.\nThat must have taken efforts."),
|
||||
TWANG("If you cannot for to play without cheating, perhaps\n" +
|
||||
"being gigolo would be better career than amateur gamer."),
|
||||
WHIRRR("MagicBot does not for to wield lowly ban hammer." +
|
||||
"It is multi-functional and multi-dimensional\n" +
|
||||
"tool who's name is unpronounceable."),
|
||||
WHOOP("OBLITERATED EVISCERATED MUTILATED DECAPITATED\n" +
|
||||
"Describe how they will. You cheated you are deleted."),
|
||||
WOOSH("Truth be told if were that bad at playing game" +
|
||||
"then MagicBot would have cheated too.\n"),
|
||||
ZAP("Player cheated and got himself deleted.\n" +
|
||||
"MagicBot launches bonus round to see if cheater " +
|
||||
"records can for to get his friends deleted too.");
|
||||
|
||||
String insult;
|
||||
|
||||
RobotSpeak(String insult) {
|
||||
this.insult = insult;
|
||||
}
|
||||
|
||||
public static String getRobotSpeak() {
|
||||
|
||||
String outString = "*";
|
||||
Random random = new Random();
|
||||
|
||||
outString += RobotSpeak.values()[random.nextInt(values().length)].name() + " "
|
||||
+ RobotSpeak.values()[random.nextInt(values().length)].name() + "*";
|
||||
|
||||
return outString;
|
||||
}
|
||||
|
||||
public static String getRobotInsult() {
|
||||
|
||||
String outString;
|
||||
Random random = new Random();
|
||||
|
||||
outString = RobotSpeak.values()[random.nextInt(values().length)].insult + "\n\n";
|
||||
outString += getRobotSpeak();
|
||||
return outString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.Database;
|
||||
import discord.DiscordAccount;
|
||||
import discord.MagicBot;
|
||||
import engine.Enum;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AccountInfoRequest {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event) {
|
||||
|
||||
String discordAccountID = event.getAuthor().getId();
|
||||
Enum.AccountStatus accountStatus;
|
||||
|
||||
if (Database.online == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Database currently: OFFLINE\n" +
|
||||
"Try again later!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<DiscordAccount> discordAccounts = MagicBot.database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
// User has no account registered. Status of what?
|
||||
|
||||
if (discordAccounts.isEmpty()) {
|
||||
MagicBot.sendResponse(event,
|
||||
"I checked my files twice but could not find your detailings!\n" +
|
||||
"You can easily fix this by asking me for to #register one.\n" +
|
||||
"Only one though. Multiple registrations are not allowed!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Send account detailings to user.
|
||||
|
||||
String outString =
|
||||
"I have for to located your account detailings\n" +
|
||||
"Registered on: " + discordAccounts.get(0).registrationDate.toString() +
|
||||
"\n-------------------\n";
|
||||
|
||||
for (DiscordAccount userAccount : discordAccounts)
|
||||
outString += userAccount.gameAccountName + "\n";
|
||||
|
||||
outString += "\n";
|
||||
|
||||
accountStatus = discordAccounts.get(0).status;
|
||||
|
||||
switch (accountStatus) {
|
||||
case BANNED:
|
||||
outString += "Your account status is BANNED. \n\n" +
|
||||
"It is ok player.\n" +
|
||||
"You may cheat on us, but your wife cheats on you!";
|
||||
break;
|
||||
case ACTIVE:
|
||||
outString += "Your account status is ACTIVE.\n" +
|
||||
"Do not cheat or status will change.";
|
||||
break;
|
||||
case ADMIN:
|
||||
outString += "You are an admin. By your command?";
|
||||
break;
|
||||
}
|
||||
|
||||
MagicBot.sendResponse(event, outString);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.DiscordAccount;
|
||||
import discord.MagicBot;
|
||||
import discord.RobotSpeak;
|
||||
import engine.Enum;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BanToggleHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String discordAccountID;
|
||||
Enum.AccountStatus accountStatus;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Must supply a discord id
|
||||
|
||||
if (args.length != 1) {
|
||||
MagicBot.sendResponse(event, "Must for to supply a valid discord account.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Must be a number!
|
||||
|
||||
discordAccountID = args[0].trim();
|
||||
|
||||
if (discordAccountID.chars().allMatch(Character::isDigit) == false) {
|
||||
MagicBot.sendResponse(event, "Must for to supply a number!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<DiscordAccount> discordAccounts = MagicBot.database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
if (discordAccounts.isEmpty()) {
|
||||
MagicBot.sendResponse(event, "No match for supplied discord account.");
|
||||
return;
|
||||
}
|
||||
|
||||
// toggle ban status
|
||||
|
||||
if (discordAccounts.get(0).status.equals(Enum.AccountStatus.BANNED))
|
||||
accountStatus = Enum.AccountStatus.ACTIVE;
|
||||
else
|
||||
accountStatus = Enum.AccountStatus.BANNED;
|
||||
|
||||
// We have a valid discord ID at this point. Banstick?
|
||||
|
||||
if (MagicBot.database.updateAccountStatus(discordAccountID, accountStatus) == false) {
|
||||
MagicBot.sendResponse(event, "Error occurred while banning player.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Invalidate login server cache
|
||||
|
||||
MagicBot.database.invalidateLoginCache(discordAccountID);
|
||||
|
||||
// Successful ban. Ancillary processing begins
|
||||
|
||||
User bannedUser = MagicBot.jda.getUserById(discordAccountID);
|
||||
String bannedName = (bannedUser == null ? discordAccounts.get(0).gameAccountName : bannedUser.getName());
|
||||
String banString = discordAccounts.size() + " accounts set to " + accountStatus + " for " + discordAccountID + "/" + bannedName;
|
||||
|
||||
MagicBot.sendResponse(event, banString);
|
||||
Logger.info(event.getAuthor().getName() + " " + banString);
|
||||
|
||||
// If we're toggling status to active we're done here.
|
||||
|
||||
if (accountStatus.equals(Enum.AccountStatus.ACTIVE))
|
||||
return;
|
||||
|
||||
// Set users role to noob
|
||||
|
||||
if (bannedUser != null)
|
||||
MagicBot.magicbaneDiscord.removeRoleFromMember(discordAccountID, MagicBot.memberRole).queue();
|
||||
|
||||
// Anounce event in septic tank channel
|
||||
|
||||
banString = "```\n" + "Goodbye Player " + bannedName + "\n\n";
|
||||
banString += RobotSpeak.getRobotInsult() + "\n```";
|
||||
|
||||
if (MagicBot.septicChannel.canTalk())
|
||||
MagicBot.septicChannel.sendMessage(banString).queue();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.ChatChannel;
|
||||
import discord.MagicBot;
|
||||
import discord.RobotSpeak;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
public class ChatChannelHandler {
|
||||
|
||||
public static void handleRequest(ChatChannel chatChannel, MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String chatText;
|
||||
String outString;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Nothing to send?
|
||||
|
||||
if (args.length == 0)
|
||||
return;
|
||||
|
||||
// Convert argument array into string;
|
||||
|
||||
chatText = String.join(" ", args);
|
||||
|
||||
// Build String
|
||||
|
||||
if (chatText.startsWith("-r "))
|
||||
outString =
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
chatText.substring(3) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
else
|
||||
outString = chatText;
|
||||
|
||||
// Write string to changelog channel
|
||||
|
||||
if (chatChannel.textChannel.canTalk())
|
||||
chatChannel.textChannel.sendMessage(outString).queue();
|
||||
|
||||
Logger.info(event.getAuthor().getName() + "general: " + chatText);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DevRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String serverCommand;
|
||||
String commandArgument = "";
|
||||
String commandString = "";
|
||||
String logString = "";
|
||||
|
||||
ProcessBuilder processBuilder;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
serverCommand = args[0].toLowerCase().trim();
|
||||
|
||||
if (args.length == 2)
|
||||
commandArgument = args[1].toLowerCase().trim();
|
||||
|
||||
switch (serverCommand) {
|
||||
|
||||
case "build":
|
||||
commandString = "./mbdevbuild.sh";
|
||||
break;
|
||||
case "restart":
|
||||
commandString = "./mbdevrestart.sh";
|
||||
break;
|
||||
case "debug":
|
||||
commandString = "./mbdevdebug.sh";
|
||||
break;
|
||||
case "shutdown":
|
||||
commandString = "./mbdevkill.sh";
|
||||
break;
|
||||
case "lastout":
|
||||
MagicBot.sendResponse(event, getLastOutput());
|
||||
return;
|
||||
case "console":
|
||||
commandString = "./mbdevconsole.sh";
|
||||
break;
|
||||
case "help":
|
||||
MagicBot.sendResponse(event,
|
||||
"#dev build <target> (blank==master) \n" +
|
||||
"#dev shutdown (Shutdown dev server)\n" +
|
||||
"#dev restart (Restarts the server)\n" +
|
||||
"#dev debug (Restarts server in debug mode)\n" +
|
||||
"#dev console # (Displays # lines from console)\n" +
|
||||
"#dev lastout (Displays output from last command) \n");
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (commandString.isEmpty()) {
|
||||
MagicBot.sendResponse(event, "Unrecognized Dev command: " + serverCommand + " " + commandArgument);
|
||||
return;
|
||||
}
|
||||
|
||||
processBuilder = new ProcessBuilder("/bin/sh", "-c", commandString + " " + commandArgument + " > devLastOut");
|
||||
logString = String.join(" ", processBuilder.command().toArray(new String[0]));
|
||||
|
||||
try {
|
||||
processBuilder.start();
|
||||
} catch (IOException e) {
|
||||
Logger.info(e.toString());
|
||||
}
|
||||
|
||||
MagicBot.sendResponse(event, "Executed on dev: " + logString + "\n" +
|
||||
"Use #dev lastout to view results");
|
||||
|
||||
}
|
||||
|
||||
private static String getLastOutput() {
|
||||
|
||||
String outString = null;
|
||||
try {
|
||||
outString = Files.lines(Paths.get("devLastOut"))
|
||||
.collect(Collectors.joining(System.lineSeparator()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FlashHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String flashText;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Nothing to send?
|
||||
|
||||
if (args.length == 0)
|
||||
return;
|
||||
|
||||
// Convert argument array into string;
|
||||
|
||||
flashText = String.join(" ", args);
|
||||
|
||||
// Write string to flash file.
|
||||
|
||||
try {
|
||||
Files.write(Paths.get("flash"), flashText.getBytes());
|
||||
} catch (IOException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " sent flash: " + flashText);
|
||||
MagicBot.sendResponse(event, "Flash: " + flashText);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class LogsRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String logType;
|
||||
int tailCount;
|
||||
String logOutput;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// No arguments supplied?
|
||||
|
||||
if (args.length != 2)
|
||||
return;
|
||||
|
||||
logType = args[0].toLowerCase().trim();
|
||||
|
||||
if ("worldloginmagicbot".contains(logType) == false)
|
||||
return;
|
||||
|
||||
try {
|
||||
tailCount = Integer.parseInt(args[1].trim());
|
||||
} catch (NumberFormatException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Transform logtype to actual file name
|
||||
|
||||
switch (logType) {
|
||||
case "magicbot":
|
||||
logType = "console_magicbot";
|
||||
break;
|
||||
case "world":
|
||||
logType = "console_server";
|
||||
break;
|
||||
case "login":
|
||||
logType = "console_login";
|
||||
break;
|
||||
}
|
||||
|
||||
// Retrieve the data and send back to the user
|
||||
|
||||
logOutput = MagicBot.readLogFile(logType, tailCount);
|
||||
MagicBot.sendResponse(event, logOutput);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.DiscordAccount;
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LookupRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String searchString = "";
|
||||
String outString;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// No argument supplied?
|
||||
|
||||
if (args.length != 1)
|
||||
return;
|
||||
|
||||
searchString = args[0].toLowerCase();
|
||||
|
||||
List<DiscordAccount> discordAccounts = MagicBot.database.getAccountsByDiscordName(searchString, false);
|
||||
|
||||
if (discordAccounts.isEmpty()) {
|
||||
MagicBot.sendResponse(event,
|
||||
"No accounts found matching string: " + searchString);
|
||||
return;
|
||||
}
|
||||
|
||||
if (discordAccounts.size() >= 20) {
|
||||
MagicBot.sendResponse(event,
|
||||
discordAccounts.size() + "Sorry more than 20 records were returned! " + searchString);
|
||||
return;
|
||||
}
|
||||
|
||||
// Valid request return results
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " lookup on account:" + searchString);
|
||||
|
||||
outString =
|
||||
"The follow accounts matched: " + searchString + "\n\n" +
|
||||
"-------------------\n";
|
||||
|
||||
for (DiscordAccount userAccount : discordAccounts) {
|
||||
|
||||
// Ternary became a bitch, so broke this out.
|
||||
|
||||
User discordUser = MagicBot.jda.getUserById(userAccount.discordAccount);
|
||||
|
||||
if (discordUser != null)
|
||||
outString += discordUser.getName() +
|
||||
"/" + userAccount.discordAccount + " ";
|
||||
else
|
||||
outString += userAccount.discordAccount + " *N/A* ";
|
||||
|
||||
outString += userAccount.gameAccountName + " " + userAccount.status.name() + " ";
|
||||
outString += "\n";
|
||||
}
|
||||
MagicBot.sendResponse(event, outString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.Database;
|
||||
import discord.DiscordAccount;
|
||||
import discord.MagicBot;
|
||||
import engine.Enum;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public class PasswordChangeHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String discordAccountID = event.getAuthor().getId();
|
||||
DiscordAccount discordAccount;
|
||||
String newPassword;
|
||||
boolean defaulted = false;
|
||||
|
||||
if (Database.online == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Database currently: OFFLINE\n" +
|
||||
"Try again later!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<DiscordAccount> discordAccounts = MagicBot.database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
// User has no account registered. Change password?
|
||||
|
||||
if (discordAccounts.isEmpty()) {
|
||||
MagicBot.sendResponse(event,
|
||||
"I checked my files twice but could not find your detailings!\n" +
|
||||
"You can easily fix this by asking me for to #register one.\n" +
|
||||
"Only one though. Multiple registrations are not allowed!");
|
||||
return;
|
||||
}
|
||||
|
||||
// All accounts are updated in one lot. Retrieve the first.
|
||||
|
||||
discordAccount = discordAccounts.get(0);
|
||||
|
||||
// Banned or suspended user's get no love.
|
||||
|
||||
if (discordAccount.status.equals(Enum.AccountStatus.BANNED)) {
|
||||
MagicBot.sendResponse(event,
|
||||
"Sorry but that is too much work. \n" +
|
||||
"Your account detailings cannot for to log into game!");
|
||||
return;
|
||||
}
|
||||
|
||||
// User has requested password change within last 24 hours.
|
||||
|
||||
if (discordAccount.lastUpdateRequest != null &&
|
||||
LocalDateTime.now().isBefore(discordAccount.lastUpdateRequest.plusDays(1))) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"You must wait 24 hours between password requests. \n" +
|
||||
"Last account updatings: " + discordAccount.lastUpdateRequest.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
// No argument choose new random password *he he he*
|
||||
|
||||
if (args.length != 1) {
|
||||
newPassword = MagicBot.generatePassword(8);
|
||||
defaulted = true;
|
||||
} else
|
||||
newPassword = args[0];
|
||||
|
||||
// Validate password with regex
|
||||
|
||||
if (MagicBot.passwordRegex.matcher(newPassword).matches() == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Your supplied password does not compute.\n" +
|
||||
"New password must satisfy following regex:\n" +
|
||||
"^[\\p{Alnum}]{6,20}$");
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPassword.toLowerCase().equals("newpass")) {
|
||||
MagicBot.sendResponse(event,
|
||||
"newpass is not valid password.\n" +
|
||||
"Have brain player!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Password validates let's change it
|
||||
|
||||
if (MagicBot.database.updateAccountPassword(discordAccount.discordAccount, newPassword) == true) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Please allow short minute for to update account detailings.\n" +
|
||||
"Login Server is hosted in bathroom above toilet. Must flush!\n" +
|
||||
(defaulted == true ? "As you did not for to supply new pass I chose one for you.\n" : "") +
|
||||
"New Password: " + newPassword);
|
||||
}
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " reset their password");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.Database;
|
||||
import discord.DiscordAccount;
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RegisterAccountHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String discordAccountID = event.getAuthor().getId();
|
||||
String discordUserName = event.getAuthor().getName();
|
||||
String discordPassword = MagicBot.generatePassword(8);
|
||||
String accountName;
|
||||
|
||||
if (Database.online == false) {
|
||||
MagicBot.sendResponse(event,
|
||||
"Database currently: OFFLINE\n" +
|
||||
"Try again later!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<DiscordAccount> discordAccounts = MagicBot.database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
// If we have previously registered this discord account let them know
|
||||
// the current status.
|
||||
|
||||
if (discordAccounts.isEmpty() == false) {
|
||||
MagicBot.sendResponse(event,
|
||||
"It seems you already have an account registered.\n" +
|
||||
"Do you need #account detailings or more general #help?");
|
||||
MagicBot.magicbaneDiscord.addRoleToMember(discordAccountID, MagicBot.memberRole).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
// User must supply an account name
|
||||
|
||||
if (args.length != 1) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Your supplied account name does not compute.\n" +
|
||||
"Account names must satisfy following regex:\n" +
|
||||
"^[\\p{Alnum}]{6,20}$");
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate account name with regex
|
||||
|
||||
accountName = args[0].replaceAll("\\s+", "");
|
||||
|
||||
if (MagicBot.accountNameRegex.matcher(accountName).matches() == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Your supplied account name does not compute.\n" +
|
||||
"Account names must satisfy following regex:\n" +
|
||||
"^[\\p{Alnum}]{6,20}$");
|
||||
return;
|
||||
}
|
||||
|
||||
if (accountName.equalsIgnoreCase("accountname")) {
|
||||
MagicBot.sendResponse(event,
|
||||
"accountname is not valid account name.\n" +
|
||||
"Have brain player!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure account doesn't already exist.
|
||||
|
||||
if (MagicBot.database.getAccountsByDiscordName(accountName, true).isEmpty() == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"It seems this account name is already taken.\n" +
|
||||
"Perhaps try one less common in frequency.");
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is no registered discord account we oblige and create 4
|
||||
// account based upon his current discord *name* not the ID.
|
||||
|
||||
if (MagicBot.database.registerDiscordAccount(discordAccountID, accountName, discordPassword) == true) {
|
||||
|
||||
Logger.info("Account " + accountName + " created for: " + discordUserName + " " + discordAccountID);
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Welcome to MagicBane!\n" +
|
||||
"-------------------\n" +
|
||||
"I have registered the following accounts to your discord.\n\n" +
|
||||
"1) " + accountName + "#1" + " 2) " + accountName + "#2\n" +
|
||||
"3) " + accountName + "#3" + " 4) " + accountName + "#4\n\n" +
|
||||
"Your default password is: " + discordPassword + "\n" +
|
||||
"Ask me #help for to receive list of robot featurings.\n\n" +
|
||||
"http://magicbane.com/tinyinstaller.zip" +
|
||||
"\n\nPlay for to Crush!");
|
||||
|
||||
// Add Discord member privileges.
|
||||
|
||||
MagicBot.magicbaneDiscord.addRoleToMember(discordAccountID, MagicBot.memberRole).queue();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// The call to the stored procedure abended. Report to player
|
||||
// and return.
|
||||
|
||||
Logger.error("Creating account: " + accountName + " for: " + discordUserName + " " + discordAccountID);
|
||||
Database.online = false;
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"-------------------\n" +
|
||||
"I for to had internal error while registering your\n" +
|
||||
"account. This has been reported. Try again later!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class RulesRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event) {
|
||||
|
||||
String outString;
|
||||
|
||||
// Add greeting
|
||||
|
||||
outString = "-No hacking.\n";
|
||||
outString += "-No cheating. If you cheat, we will delete.\n";
|
||||
outString += "-Players limited to 4 concurrent accounts.\n";
|
||||
outString += "-Share accounts at own risk.\n";
|
||||
outString += "-No refunds";
|
||||
|
||||
MagicBot.sendResponse(event, outString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ServerRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String serverCommand;
|
||||
String execString = "";
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// No command supplied?
|
||||
|
||||
if (args.length != 1)
|
||||
return;
|
||||
|
||||
serverCommand = args[0].toLowerCase().trim();
|
||||
|
||||
// only reboot or shutdown
|
||||
|
||||
if ("rebootshutdown".contains(serverCommand) == false)
|
||||
return;
|
||||
|
||||
switch (serverCommand) {
|
||||
|
||||
case "reboot":
|
||||
execString = "/bin/sh -c ./mbrestart.sh";
|
||||
break;
|
||||
case "shutdown":
|
||||
execString = "/bin/sh -c ./mbkill.sh";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (execString.isEmpty() == false) {
|
||||
try {
|
||||
Runtime.getRuntime().exec(execString);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MagicBot.sendResponse(event, "MagicBot has executed your " + serverCommand);
|
||||
Logger.info(event.getAuthor().getName() + " told server to " + serverCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.Database;
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
public class SetAvailHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String availStatus;
|
||||
String availPass;
|
||||
|
||||
if (args.length != 2)
|
||||
return;
|
||||
|
||||
availStatus = args[0].toLowerCase().trim();
|
||||
|
||||
// only on/off
|
||||
|
||||
if ("truefalse".contains(availStatus) == false)
|
||||
return;
|
||||
|
||||
// Set avail is password driven
|
||||
|
||||
availPass = args[1].toLowerCase().trim();
|
||||
|
||||
if ("myshoes123".equals(availPass) == false)
|
||||
return;
|
||||
|
||||
// Authenticated so change availstatus
|
||||
|
||||
if (availStatus.equals("true"))
|
||||
Database.online = true;
|
||||
else
|
||||
Database.online = false;
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " set avail status to: " + Database.online);
|
||||
MagicBot.sendResponse(event, "Avail status set to: " + Database.online);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.Database;
|
||||
import discord.MagicBot;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import engine.server.login.LoginServer;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class StatusRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event) {
|
||||
|
||||
String outString;
|
||||
|
||||
// Add server status info
|
||||
outString = "Server Status: ";
|
||||
|
||||
if (LoginServer.isPortInUse(Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue())))
|
||||
outString += "ONLINE\n";
|
||||
else
|
||||
outString += "OFFLINE\n";
|
||||
|
||||
if (Database.online == true)
|
||||
outString += MagicBot.database.getPopulationString();
|
||||
else
|
||||
outString += "Database offline: no population data.";
|
||||
|
||||
MagicBot.sendResponse(event, outString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import discord.RobotSpeak;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static discord.ChatChannel.SEPTIC;
|
||||
|
||||
public class TrashRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String outString;
|
||||
int trashCount = 0;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
if (args.length == 0) {
|
||||
outString = MagicBot.database.getTrashFile();
|
||||
MagicBot.sendResponse(event, outString);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equals("flush") == true) {
|
||||
|
||||
// Empty the trash!
|
||||
|
||||
trashCount = MagicBot.database.getTrashCount();
|
||||
|
||||
if (trashCount == 0)
|
||||
return;
|
||||
|
||||
// Anounce event in septic tank channel
|
||||
|
||||
outString = "```\n" + trashCount + " Player Character were for to deleted due to verified cheatings. \n\n";
|
||||
outString += MagicBot.database.getTrashList() + "\n\n";
|
||||
outString += RobotSpeak.getRobotInsult() + "\n```";
|
||||
|
||||
if (SEPTIC.textChannel.canTalk())
|
||||
SEPTIC.textChannel.sendMessage(outString).queue();
|
||||
|
||||
try {
|
||||
Files.write(Paths.get("trash"), "".getBytes());
|
||||
outString = "Flushing trash players...\n";
|
||||
MagicBot.sendResponse(event, outString);
|
||||
} catch (IOException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (args[0].equals("detail") == true) {
|
||||
|
||||
outString = MagicBot.database.getTrashDetail();
|
||||
MagicBot.sendResponse(event, outString);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,706 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package engine.InterestManagement;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.math.Vector2f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.AbstractWorldObject;
|
||||
import engine.objects.Zone;
|
||||
import engine.util.MapLoader;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class HeightMap {
|
||||
|
||||
// Class variables
|
||||
|
||||
// Heightmap data for all zones.
|
||||
|
||||
public static final HashMap<Integer, HeightMap> heightmapByLoadNum = new HashMap<>();
|
||||
|
||||
// Bootstrap Tracking
|
||||
|
||||
public static int heightMapsCreated = 0;
|
||||
public static HeightMap PlayerCityHeightMap;
|
||||
|
||||
// Heightmap data for this heightmap
|
||||
|
||||
public BufferedImage heightmapImage;
|
||||
|
||||
private int heightMapID;
|
||||
private int maxHeight;
|
||||
private int fullExtentsX;
|
||||
private int fullExtentsY;
|
||||
|
||||
private float bucketWidthX;
|
||||
private float bucketWidthY;
|
||||
private int zoneLoadID;
|
||||
private float seaLevel = 0;
|
||||
private float outsetX;
|
||||
private float outsetZ;
|
||||
private int[][] pixelColorValues;
|
||||
|
||||
public HeightMap(ResultSet rs) throws SQLException {
|
||||
|
||||
this.heightMapID = rs.getInt("heightMapID");
|
||||
this.maxHeight = rs.getInt("maxHeight");
|
||||
int halfExtentsX = rs.getInt("xRadius");
|
||||
int halfExtentsY = rs.getInt("zRadius");
|
||||
this.zoneLoadID = rs.getInt("zoneLoadID");
|
||||
this.seaLevel = rs.getFloat("seaLevel");
|
||||
this.outsetX = rs.getFloat("outsetX");
|
||||
this.outsetZ = rs.getFloat("outsetZ");
|
||||
|
||||
|
||||
// Cache the full extents to avoid the calculation
|
||||
|
||||
this.fullExtentsX = halfExtentsX * 2;
|
||||
this.fullExtentsY = halfExtentsY * 2;
|
||||
|
||||
this.heightmapImage = null;
|
||||
File imageFile = new File(ConfigManager.DEFAULT_DATA_DIR + "heightmaps/" + this.heightMapID + ".bmp");
|
||||
|
||||
// early exit if no image file was found. Will log in caller.
|
||||
|
||||
if (!imageFile.exists())
|
||||
return;
|
||||
|
||||
// load the heightmap image.
|
||||
|
||||
try {
|
||||
this.heightmapImage = ImageIO.read(imageFile);
|
||||
} catch (IOException e) {
|
||||
Logger.error("***Error loading heightmap data for heightmap " + this.heightMapID + e.toString());
|
||||
}
|
||||
|
||||
// We needed to flip the image as OpenGL and Shadowbane both use the bottom left corner as origin.
|
||||
|
||||
this.heightmapImage = MapLoader.flipImage(this.heightmapImage);
|
||||
|
||||
// Calculate the data we do not load from table
|
||||
|
||||
float numOfBuckets = this.heightmapImage.getWidth() - 1;
|
||||
float calculatedWidth = this.fullExtentsX / numOfBuckets;
|
||||
this.bucketWidthX = calculatedWidth;
|
||||
this.bucketWidthY = this.bucketWidthX; // This makes no sense.
|
||||
|
||||
// Generate pixel array from image data
|
||||
|
||||
generatePixelData();
|
||||
|
||||
HeightMap.heightmapByLoadNum.put(this.zoneLoadID, this);
|
||||
|
||||
heightMapsCreated++;
|
||||
}
|
||||
|
||||
//Created for PlayerCities
|
||||
public HeightMap() {
|
||||
|
||||
this.heightMapID = 999999;
|
||||
this.maxHeight = 5; // for real...
|
||||
int halfExtentsX = (int) Enum.CityBoundsType.ZONE.extents;
|
||||
int halfExtentsY = (int) Enum.CityBoundsType.ZONE.extents;
|
||||
this.zoneLoadID = 0;
|
||||
this.seaLevel = 0;
|
||||
this.outsetX = 128;
|
||||
this.outsetZ = 128;
|
||||
|
||||
|
||||
// Cache the full extents to avoid the calculation
|
||||
|
||||
this.fullExtentsX = halfExtentsX * 2;
|
||||
this.fullExtentsY = halfExtentsY * 2;
|
||||
|
||||
|
||||
// load the heightmap image.
|
||||
|
||||
|
||||
// We needed to flip the image as OpenGL and Shadowbane both use the bottom left corner as origin.
|
||||
|
||||
this.heightmapImage = null;
|
||||
|
||||
// Calculate the data we do not load from table
|
||||
|
||||
this.bucketWidthX = 1;
|
||||
this.bucketWidthY = 1;
|
||||
|
||||
this.pixelColorValues = new int[this.fullExtentsX + 1][this.fullExtentsY + 1];
|
||||
|
||||
for (int y = 0; y <= this.fullExtentsY; y++) {
|
||||
for (int x = 0; x <= this.fullExtentsX; x++) {
|
||||
pixelColorValues[x][y] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HeightMap.heightmapByLoadNum.put(this.zoneLoadID, this);
|
||||
}
|
||||
|
||||
public HeightMap(Zone zone) {
|
||||
|
||||
this.heightMapID = 999999;
|
||||
this.maxHeight = 0;
|
||||
int halfExtentsX = (int) zone.getBounds().getHalfExtents().x;
|
||||
int halfExtentsY = (int) zone.getBounds().getHalfExtents().y;
|
||||
this.zoneLoadID = 0;
|
||||
this.seaLevel = 0;
|
||||
this.outsetX = 0;
|
||||
this.outsetZ = 0;
|
||||
|
||||
// Cache the full extents to avoid the calculation
|
||||
|
||||
this.fullExtentsX = halfExtentsX * 2;
|
||||
this.fullExtentsY = halfExtentsY * 2;
|
||||
|
||||
|
||||
// We needed to flip the image as OpenGL and Shadowbane both use the bottom left corner as origin.
|
||||
|
||||
this.heightmapImage = null;
|
||||
|
||||
// Calculate the data we do not load from table
|
||||
|
||||
this.bucketWidthX = 1;
|
||||
this.bucketWidthY = 1;
|
||||
|
||||
this.pixelColorValues = new int[this.fullExtentsX + 1][this.fullExtentsY + 1];
|
||||
|
||||
for (int y = 0; y <= this.fullExtentsY; y++) {
|
||||
for (int x = 0; x <= this.fullExtentsX; x++) {
|
||||
pixelColorValues[x][y] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HeightMap.heightmapByLoadNum.put(this.zoneLoadID, this);
|
||||
}
|
||||
|
||||
public static void GeneratePlayerCityHeightMap() {
|
||||
|
||||
HeightMap.PlayerCityHeightMap = new HeightMap();
|
||||
|
||||
}
|
||||
|
||||
public static void GenerateCustomHeightMap(Zone zone) {
|
||||
|
||||
HeightMap heightMap = new HeightMap(zone);
|
||||
|
||||
HeightMap.heightmapByLoadNum.put(zone.getLoadNum(), heightMap);
|
||||
|
||||
}
|
||||
|
||||
public static Zone getNextZoneWithTerrain(Zone zone) {
|
||||
|
||||
Zone nextZone = zone;
|
||||
|
||||
if (zone.getHeightMap() != null)
|
||||
return zone;
|
||||
|
||||
if (zone.equals(ZoneManager.getSeaFloor()))
|
||||
return zone;
|
||||
|
||||
while (nextZone.getHeightMap() == null)
|
||||
nextZone = nextZone.getParent();
|
||||
|
||||
return nextZone;
|
||||
}
|
||||
|
||||
public static float getWorldHeight(AbstractWorldObject worldObject) {
|
||||
|
||||
Vector2f parentLoc = new Vector2f(-1, -1);
|
||||
Zone currentZone = ZoneManager.findSmallestZone(worldObject.getLoc());
|
||||
|
||||
if (currentZone == null)
|
||||
return worldObject.getAltitude();
|
||||
|
||||
currentZone = getNextZoneWithTerrain(currentZone);
|
||||
|
||||
if (currentZone == ZoneManager.getSeaFloor())
|
||||
return currentZone.getAbsY() + worldObject.getAltitude();
|
||||
|
||||
Zone parentZone = getNextZoneWithTerrain(currentZone.getParent());
|
||||
HeightMap heightMap = currentZone.getHeightMap();
|
||||
|
||||
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldObject.getLoc(), currentZone);
|
||||
Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldObject.getLoc(), currentZone);
|
||||
|
||||
if ((parentZone != null) && (parentZone.getHeightMap() != null))
|
||||
parentLoc = ZoneManager.worldToZoneSpace(worldObject.getLoc(), parentZone);
|
||||
|
||||
float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
|
||||
|
||||
float worldAltitude = currentZone.getWorldAltitude();
|
||||
|
||||
float realWorldAltitude = interaltitude + worldAltitude;
|
||||
|
||||
//OUTSET
|
||||
|
||||
if (parentZone != null) {
|
||||
|
||||
float parentXRadius = currentZone.getBounds().getHalfExtents().x;
|
||||
float parentZRadius = currentZone.getBounds().getHalfExtents().y;
|
||||
|
||||
float offsetX = Math.abs((localLocFromCenter.x / parentXRadius));
|
||||
float offsetZ = Math.abs((localLocFromCenter.z / parentZRadius));
|
||||
|
||||
float bucketScaleX = heightMap.outsetX / parentXRadius;
|
||||
float bucketScaleZ = heightMap.outsetZ / parentZRadius;
|
||||
|
||||
if (bucketScaleX <= 0.40000001)
|
||||
bucketScaleX = heightMap.outsetZ / parentXRadius;
|
||||
|
||||
if (bucketScaleX > 0.40000001)
|
||||
bucketScaleX = 0.40000001f;
|
||||
|
||||
if (bucketScaleZ <= 0.40000001)
|
||||
bucketScaleZ = heightMap.outsetX / parentZRadius;
|
||||
|
||||
if (bucketScaleZ > 0.40000001)
|
||||
bucketScaleZ = 0.40000001f;
|
||||
|
||||
float outsideGridSizeX = 1 - bucketScaleX; //32/256
|
||||
float outsideGridSizeZ = 1 - bucketScaleZ;
|
||||
float weight;
|
||||
|
||||
double scale;
|
||||
|
||||
if (offsetX > outsideGridSizeX && offsetX > offsetZ) {
|
||||
weight = (offsetX - outsideGridSizeX) / bucketScaleX;
|
||||
scale = Math.atan2((.5 - weight) * 3.1415927, 1);
|
||||
|
||||
float scaleChild = (float) ((scale + 1) * .5);
|
||||
float scaleParent = 1 - scaleChild;
|
||||
|
||||
float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc);
|
||||
float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone));
|
||||
|
||||
parentCenterAltitude += currentZone.getYCoord();
|
||||
parentCenterAltitude += interaltitude;
|
||||
|
||||
float firstScale = parentAltitude * scaleParent;
|
||||
float secondScale = parentCenterAltitude * scaleChild;
|
||||
float outsetALt = firstScale + secondScale;
|
||||
|
||||
outsetALt += currentZone.getParent().getWorldAltitude();
|
||||
realWorldAltitude = outsetALt;
|
||||
|
||||
} else if (offsetZ > outsideGridSizeZ) {
|
||||
|
||||
weight = (offsetZ - outsideGridSizeZ) / bucketScaleZ;
|
||||
scale = Math.atan2((.5 - weight) * 3.1415927, 1);
|
||||
|
||||
float scaleChild = (float) ((scale + 1) * .5);
|
||||
float scaleParent = 1 - scaleChild;
|
||||
float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc);
|
||||
float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone));
|
||||
|
||||
parentCenterAltitude += currentZone.getYCoord();
|
||||
parentCenterAltitude += interaltitude;
|
||||
float firstScale = parentAltitude * scaleParent;
|
||||
float secondScale = parentCenterAltitude * scaleChild;
|
||||
float outsetALt = firstScale + secondScale;
|
||||
|
||||
outsetALt += currentZone.getParent().getWorldAltitude();
|
||||
realWorldAltitude = outsetALt;
|
||||
}
|
||||
}
|
||||
|
||||
return realWorldAltitude;
|
||||
}
|
||||
|
||||
public static float getWorldHeight(Vector3fImmutable worldLoc) {
|
||||
|
||||
Vector2f parentLoc = new Vector2f(-1, -1);
|
||||
Zone currentZone = ZoneManager.findSmallestZone(worldLoc);
|
||||
|
||||
if (currentZone == null)
|
||||
return 0;
|
||||
|
||||
currentZone = getNextZoneWithTerrain(currentZone);
|
||||
|
||||
if (currentZone == ZoneManager.getSeaFloor())
|
||||
return currentZone.getAbsY();
|
||||
|
||||
Zone parentZone = getNextZoneWithTerrain(currentZone.getParent());
|
||||
HeightMap heightMap = currentZone.getHeightMap();
|
||||
|
||||
if ((heightMap == null) || (currentZone == ZoneManager.getSeaFloor()))
|
||||
return currentZone.getAbsY();
|
||||
|
||||
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(worldLoc, currentZone);
|
||||
Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldLoc, currentZone);
|
||||
|
||||
if ((parentZone != null) && (parentZone.getHeightMap() != null))
|
||||
parentLoc = ZoneManager.worldToZoneSpace(worldLoc, parentZone);
|
||||
|
||||
float interaltitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
|
||||
|
||||
float worldAltitude = currentZone.getWorldAltitude();
|
||||
|
||||
float realWorldAltitude = interaltitude + worldAltitude;
|
||||
|
||||
//OUTSET
|
||||
|
||||
if (parentZone != null) {
|
||||
|
||||
// if (currentZone.getHeightMap() != null && parentZone.getHeightMap() != null && parentZone.getParent() != null && parentZone.getParent().getHeightMap() != null)
|
||||
// return realWorldAltitude;
|
||||
|
||||
float parentXRadius = currentZone.getBounds().getHalfExtents().x;
|
||||
float parentZRadius = currentZone.getBounds().getHalfExtents().y;
|
||||
|
||||
float offsetX = Math.abs((localLocFromCenter.x / parentXRadius));
|
||||
float offsetZ = Math.abs((localLocFromCenter.z / parentZRadius));
|
||||
|
||||
float bucketScaleX = heightMap.outsetX / parentXRadius;
|
||||
float bucketScaleZ = heightMap.outsetZ / parentZRadius;
|
||||
|
||||
float outsideGridSizeX = 1 - bucketScaleX; //32/256
|
||||
float outsideGridSizeZ = 1 - bucketScaleZ;
|
||||
float weight;
|
||||
|
||||
double scale;
|
||||
|
||||
|
||||
if (offsetX > outsideGridSizeX && offsetX > offsetZ) {
|
||||
weight = (offsetX - outsideGridSizeX) / bucketScaleX;
|
||||
scale = Math.atan2((.5 - weight) * 3.1415927, 1);
|
||||
|
||||
float scaleChild = (float) ((scale + 1) * .5);
|
||||
float scaleParent = 1 - scaleChild;
|
||||
|
||||
float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc);
|
||||
float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone));
|
||||
|
||||
parentCenterAltitude += currentZone.getYCoord();
|
||||
parentCenterAltitude += interaltitude;
|
||||
|
||||
float firstScale = parentAltitude * scaleParent;
|
||||
float secondScale = parentCenterAltitude * scaleChild;
|
||||
float outsetALt = firstScale + secondScale;
|
||||
|
||||
outsetALt += currentZone.getParent().getWorldAltitude();
|
||||
realWorldAltitude = outsetALt;
|
||||
|
||||
} else if (offsetZ > outsideGridSizeZ) {
|
||||
|
||||
weight = (offsetZ - outsideGridSizeZ) / bucketScaleZ;
|
||||
scale = Math.atan2((.5 - weight) * 3.1415927, 1);
|
||||
|
||||
float scaleChild = (float) ((scale + 1) * .5);
|
||||
float scaleParent = 1 - scaleChild;
|
||||
float parentAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(parentLoc);
|
||||
float parentCenterAltitude = parentZone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone));
|
||||
|
||||
parentCenterAltitude += currentZone.getYCoord();
|
||||
parentCenterAltitude += interaltitude;
|
||||
float firstScale = parentAltitude * scaleParent;
|
||||
float secondScale = parentCenterAltitude * scaleChild;
|
||||
float outsetALt = firstScale + secondScale;
|
||||
|
||||
outsetALt += currentZone.getParent().getWorldAltitude();
|
||||
realWorldAltitude = outsetALt;
|
||||
}
|
||||
}
|
||||
|
||||
return realWorldAltitude;
|
||||
}
|
||||
|
||||
public static float getOutsetHeight(float interpolatedAltitude, Zone zone, Vector3fImmutable worldLocation) {
|
||||
|
||||
Vector2f parentLoc;
|
||||
float outsetALt = 0;
|
||||
|
||||
if (zone.getParent() == null || zone.getParent().getHeightMap() == null)
|
||||
return interpolatedAltitude + zone.getWorldAltitude();
|
||||
|
||||
if (zone.getParent() != null && zone.getParent().getHeightMap() != null) {
|
||||
|
||||
parentLoc = ZoneManager.worldToZoneSpace(worldLocation, zone.getParent());
|
||||
|
||||
Vector3fImmutable localLocFromCenter = ZoneManager.worldToLocal(worldLocation, zone);
|
||||
|
||||
float parentXRadius = zone.getBounds().getHalfExtents().x;
|
||||
float parentZRadius = zone.getBounds().getHalfExtents().y;
|
||||
|
||||
float bucketScaleX = zone.getHeightMap().outsetX / parentXRadius;
|
||||
float bucketScaleZ = zone.getHeightMap().outsetZ / parentZRadius;
|
||||
|
||||
float outsideGridSizeX = 1 - bucketScaleX; //32/256
|
||||
float outsideGridSizeZ = 1 - bucketScaleZ;
|
||||
|
||||
float weight;
|
||||
double scale;
|
||||
|
||||
float offsetX = Math.abs((localLocFromCenter.x / parentXRadius));
|
||||
float offsetZ = Math.abs((localLocFromCenter.z / parentZRadius));
|
||||
|
||||
if (offsetX > outsideGridSizeX && offsetX > offsetZ) {
|
||||
weight = (offsetX - outsideGridSizeX) / bucketScaleX;
|
||||
scale = Math.atan2((.5 - weight) * 3.1415927, 1);
|
||||
|
||||
float scaleChild = (float) ((scale + 1) * .5);
|
||||
float scaleParent = 1 - scaleChild;
|
||||
|
||||
float parentAltitude = zone.getParent().getHeightMap().getInterpolatedTerrainHeight(parentLoc);
|
||||
float parentCenterAltitude = zone.getParent().getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(zone.getLoc(), zone.getParent()));
|
||||
|
||||
parentCenterAltitude += zone.getYCoord();
|
||||
parentCenterAltitude += interpolatedAltitude;
|
||||
|
||||
float firstScale = parentAltitude * scaleParent;
|
||||
float secondScale = parentCenterAltitude * scaleChild;
|
||||
outsetALt = firstScale + secondScale;
|
||||
|
||||
outsetALt += zone.getParent().getAbsY();
|
||||
|
||||
} else if (offsetZ > outsideGridSizeZ) {
|
||||
|
||||
weight = (offsetZ - outsideGridSizeZ) / bucketScaleZ;
|
||||
scale = Math.atan2((.5 - weight) * 3.1415927, 1);
|
||||
|
||||
float scaleChild = (float) ((scale + 1) * .5);
|
||||
float scaleParent = 1 - scaleChild;
|
||||
float parentAltitude = zone.getParent().getHeightMap().getInterpolatedTerrainHeight(parentLoc);
|
||||
float parentCenterAltitude = zone.getHeightMap().getInterpolatedTerrainHeight(ZoneManager.worldToZoneSpace(zone.getLoc(), zone));
|
||||
|
||||
parentCenterAltitude += zone.getYCoord();
|
||||
parentCenterAltitude += interpolatedAltitude;
|
||||
|
||||
float firstScale = parentAltitude * scaleParent;
|
||||
float secondScale = parentCenterAltitude * scaleChild;
|
||||
outsetALt = firstScale + secondScale;
|
||||
|
||||
outsetALt += zone.getParent().getAbsY();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return outsetALt;
|
||||
}
|
||||
|
||||
public static Vector2f getGridOffset(Vector2f gridSquare) {
|
||||
|
||||
int floorX = (int) gridSquare.x;
|
||||
int floorY = (int) gridSquare.y;
|
||||
|
||||
return new Vector2f(gridSquare.x - floorX, gridSquare.y - floorY);
|
||||
|
||||
}
|
||||
|
||||
public static void loadAlHeightMaps() {
|
||||
|
||||
// Load the heightmaps into staging hashmap keyed by HashMapID
|
||||
|
||||
DbManager.HeightMapQueries.LOAD_ALL_HEIGHTMAPS();
|
||||
|
||||
//generate static player city heightmap.
|
||||
|
||||
HeightMap.GeneratePlayerCityHeightMap();
|
||||
|
||||
|
||||
// Clear all heightmap image data as it's no longer needed.
|
||||
|
||||
for (HeightMap heightMap : HeightMap.heightmapByLoadNum.values()) {
|
||||
heightMap.heightmapImage = null;
|
||||
}
|
||||
|
||||
Logger.info(HeightMap.heightmapByLoadNum.size() + " Heightmaps cached.");
|
||||
}
|
||||
|
||||
public static boolean isLocUnderwater(Vector3fImmutable currentLoc) {
|
||||
|
||||
float localAltitude = HeightMap.getWorldHeight(currentLoc);
|
||||
Zone zone = ZoneManager.findSmallestZone(currentLoc);
|
||||
|
||||
if (localAltitude < zone.getSeaLevel())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Vector2f getGridSquare(Vector2f zoneLoc) {
|
||||
|
||||
if (zoneLoc.x < 0)
|
||||
zoneLoc.setX(0);
|
||||
|
||||
if (zoneLoc.x > this.fullExtentsX - 1)
|
||||
zoneLoc.setX((this.fullExtentsX - 1) + .9999999f);
|
||||
|
||||
if (zoneLoc.y < 0)
|
||||
zoneLoc.setY(0);
|
||||
|
||||
if (zoneLoc.y > this.fullExtentsY - 1)
|
||||
zoneLoc.setY((this.fullExtentsY - 1) + .9999999f);
|
||||
|
||||
float xBucket = (zoneLoc.x / this.bucketWidthX);
|
||||
float yBucket = (zoneLoc.y / this.bucketWidthY);
|
||||
|
||||
return new Vector2f(xBucket, yBucket);
|
||||
}
|
||||
|
||||
public float getInterpolatedTerrainHeight(Vector2f zoneLoc) {
|
||||
|
||||
Vector2f gridSquare;
|
||||
|
||||
if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX)
|
||||
return -1;
|
||||
|
||||
if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY)
|
||||
return -1;
|
||||
|
||||
int maxX = (int) (this.fullExtentsX / this.bucketWidthX);
|
||||
int maxY = (int) (this.fullExtentsY / this.bucketWidthY);
|
||||
|
||||
//flip the Y so it grabs from the bottom left instead of top left.
|
||||
//zoneLoc.setY(maxZoneHeight - zoneLoc.y);
|
||||
|
||||
gridSquare = getGridSquare(zoneLoc);
|
||||
|
||||
int gridX = (int) gridSquare.x;
|
||||
int gridY = (int) (gridSquare.y);
|
||||
|
||||
if (gridX > maxX)
|
||||
gridX = maxX;
|
||||
if (gridY > maxY)
|
||||
gridY = maxY;
|
||||
|
||||
float offsetX = (gridSquare.x - gridX);
|
||||
float offsetY = gridSquare.y - gridY;
|
||||
|
||||
//get height of the 4 vertices.
|
||||
|
||||
float topLeftHeight = 0;
|
||||
float topRightHeight = 0;
|
||||
float bottomLeftHeight = 0;
|
||||
float bottomRightHeight = 0;
|
||||
|
||||
int nextY = gridY + 1;
|
||||
int nextX = gridX + 1;
|
||||
|
||||
if (nextY > maxY)
|
||||
nextY = gridY;
|
||||
|
||||
if (nextX > maxX)
|
||||
nextX = gridX;
|
||||
|
||||
topLeftHeight = pixelColorValues[gridX][gridY];
|
||||
topRightHeight = pixelColorValues[nextX][gridY];
|
||||
bottomLeftHeight = pixelColorValues[gridX][nextY];
|
||||
bottomRightHeight = pixelColorValues[nextX][nextY];
|
||||
|
||||
float interpolatedHeight;
|
||||
|
||||
interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX);
|
||||
interpolatedHeight += (bottomRightHeight * offsetY * offsetX);
|
||||
interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY);
|
||||
interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY));
|
||||
|
||||
interpolatedHeight *= (float) this.maxHeight / 256; // Scale height
|
||||
|
||||
return interpolatedHeight;
|
||||
}
|
||||
|
||||
public float getInterpolatedTerrainHeight(Vector3fImmutable zoneLoc3f) {
|
||||
|
||||
Vector2f zoneLoc = new Vector2f(zoneLoc3f.x, zoneLoc3f.z);
|
||||
|
||||
Vector2f gridSquare;
|
||||
|
||||
if (zoneLoc.x < 0 || zoneLoc.x > this.fullExtentsX)
|
||||
return -1;
|
||||
|
||||
if (zoneLoc.y < 0 || zoneLoc.y > this.fullExtentsY)
|
||||
return -1;
|
||||
|
||||
//flip the Y so it grabs from the bottom left instead of top left.
|
||||
//zoneLoc.setY(maxZoneHeight - zoneLoc.y);
|
||||
|
||||
gridSquare = getGridSquare(zoneLoc);
|
||||
|
||||
int gridX = (int) gridSquare.x;
|
||||
int gridY = (int) (gridSquare.y);
|
||||
|
||||
float offsetX = (gridSquare.x - gridX);
|
||||
float offsetY = gridSquare.y - gridY;
|
||||
|
||||
//get height of the 4 vertices.
|
||||
|
||||
float topLeftHeight = pixelColorValues[gridX][gridY];
|
||||
float topRightHeight = pixelColorValues[gridX + 1][gridY];
|
||||
float bottomLeftHeight = pixelColorValues[gridX][gridY + 1];
|
||||
float bottomRightHeight = pixelColorValues[gridX + 1][gridY + 1];
|
||||
|
||||
float interpolatedHeight;
|
||||
|
||||
interpolatedHeight = topRightHeight * (1 - offsetY) * (offsetX);
|
||||
interpolatedHeight += (bottomRightHeight * offsetY * offsetX);
|
||||
interpolatedHeight += (bottomLeftHeight * (1 - offsetX) * offsetY);
|
||||
interpolatedHeight += (topLeftHeight * (1 - offsetX) * (1 - offsetY));
|
||||
|
||||
interpolatedHeight *= (float) this.maxHeight / 256; // Scale height
|
||||
|
||||
return interpolatedHeight;
|
||||
}
|
||||
|
||||
private void generatePixelData() {
|
||||
|
||||
Color color;
|
||||
|
||||
// Generate altitude lookup table for this heightmap
|
||||
|
||||
this.pixelColorValues = new int[this.heightmapImage.getWidth()][this.heightmapImage.getHeight()];
|
||||
|
||||
for (int y = 0; y < this.heightmapImage.getHeight(); y++) {
|
||||
for (int x = 0; x < this.heightmapImage.getWidth(); x++) {
|
||||
|
||||
color = new Color(this.heightmapImage.getRGB(x, y));
|
||||
pixelColorValues[x][y] = color.getRed();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public float getScaledHeightForColor(float color) {
|
||||
|
||||
return (color / 256) * this.maxHeight;
|
||||
}
|
||||
|
||||
public float getBucketWidthX() {
|
||||
return bucketWidthX;
|
||||
}
|
||||
|
||||
public float getBucketWidthY() {
|
||||
return bucketWidthY;
|
||||
}
|
||||
|
||||
public int getHeightMapID() {
|
||||
return heightMapID;
|
||||
}
|
||||
|
||||
public BufferedImage getHeightmapImage() {
|
||||
return heightmapImage;
|
||||
}
|
||||
|
||||
public float getSeaLevel() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,561 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package engine.InterestManagement;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.GroupManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.job.JobScheduler;
|
||||
import engine.jobs.RefreshGroupJob;
|
||||
import engine.net.AbstractNetMsg;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.LoadCharacterMsg;
|
||||
import engine.net.client.msg.LoadStructureMsg;
|
||||
import engine.net.client.msg.MoveToPointMsg;
|
||||
import engine.net.client.msg.UnloadObjectsMsg;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static engine.math.FastMath.sqr;
|
||||
|
||||
public enum InterestManager implements Runnable {
|
||||
|
||||
INTERESTMANAGER;
|
||||
|
||||
private static long lastTime;
|
||||
|
||||
InterestManager() {
|
||||
Logger.info(" Interest Management thread is running.");
|
||||
}
|
||||
|
||||
public static void forceLoad(AbstractWorldObject awo) {
|
||||
|
||||
AbstractNetMsg msg = null;
|
||||
LoadStructureMsg lsm;
|
||||
LoadCharacterMsg lcm;
|
||||
NPC npc;
|
||||
Corpse corpse;
|
||||
HashSet<AbstractWorldObject> toUpdate;
|
||||
|
||||
switch (awo.getObjectType()) {
|
||||
case Building:
|
||||
lsm = new LoadStructureMsg();
|
||||
lsm.addObject((Building) awo);
|
||||
msg = lsm;
|
||||
break;
|
||||
case Corpse:
|
||||
corpse = (Corpse) awo;
|
||||
lcm = new LoadCharacterMsg(corpse, false);
|
||||
msg = lcm;
|
||||
break;
|
||||
case NPC:
|
||||
npc = (NPC) awo;
|
||||
lcm = new LoadCharacterMsg(npc, false);
|
||||
msg = lcm;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
toUpdate = WorldGrid.getObjectsInRangePartial(awo.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE, MBServerStatics.MASK_PLAYER);
|
||||
|
||||
boolean send;
|
||||
|
||||
for (AbstractWorldObject tar : toUpdate) {
|
||||
PlayerCharacter player = (PlayerCharacter) tar;
|
||||
HashSet<AbstractWorldObject> loadedStaticObjects = player.getLoadedStaticObjects();
|
||||
send = false;
|
||||
|
||||
if (!loadedStaticObjects.contains(awo)) {
|
||||
loadedStaticObjects.add(awo);
|
||||
send = true;
|
||||
}
|
||||
|
||||
if (send) {
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void HandleSpecialUnload(Building building, ClientConnection origin) {
|
||||
|
||||
if (Regions.FurnitureRegionMap.get(building.getObjectUUID()) == null)
|
||||
return;
|
||||
|
||||
Regions buildingRegion = Regions.FurnitureRegionMap.get(building.getObjectUUID());
|
||||
|
||||
if (!buildingRegion.isOutside())
|
||||
return;
|
||||
|
||||
MoveToPointMsg moveMsg = new MoveToPointMsg(building);
|
||||
|
||||
if (origin != null)
|
||||
origin.sendMsg(moveMsg);
|
||||
}
|
||||
|
||||
public static void reloadCharacter(AbstractCharacter absChar) {
|
||||
|
||||
UnloadObjectsMsg uom = new UnloadObjectsMsg();
|
||||
uom.addObject(absChar);
|
||||
LoadCharacterMsg lcm = new LoadCharacterMsg(absChar, false);
|
||||
|
||||
HashSet<AbstractWorldObject> toSend = WorldGrid.getObjectsInRangePartial(absChar.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE,
|
||||
MBServerStatics.MASK_PLAYER);
|
||||
|
||||
PlayerCharacter pc = null;
|
||||
|
||||
if (absChar.getObjectType().equals(GameObjectType.PlayerCharacter))
|
||||
pc = (PlayerCharacter) absChar;
|
||||
|
||||
for (AbstractWorldObject awo : toSend) {
|
||||
|
||||
PlayerCharacter pcc = (PlayerCharacter) awo;
|
||||
|
||||
if (pcc == null)
|
||||
continue;
|
||||
|
||||
ClientConnection cc = SessionManager.getClientConnection(pcc);
|
||||
|
||||
if (cc == null)
|
||||
continue;
|
||||
|
||||
if (pcc.getObjectUUID() == absChar.getObjectUUID())
|
||||
continue;
|
||||
|
||||
else {
|
||||
if (pc != null)
|
||||
if (pcc.getSeeInvis() < pc.getHidden())
|
||||
continue;
|
||||
|
||||
if (!cc.sendMsg(uom)) {
|
||||
String classType = uom.getClass().getSimpleName();
|
||||
Logger.error("Failed to send message ");
|
||||
}
|
||||
|
||||
if (!cc.sendMsg(lcm)) {
|
||||
String classType = lcm.getClass().getSimpleName();
|
||||
Logger.error("Failed to send message");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
beginLoadJob();
|
||||
}
|
||||
|
||||
private void beginLoadJob() {
|
||||
|
||||
InterestManager.lastTime = System.currentTimeMillis();
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
updateAllPlayers();
|
||||
} catch (Exception e) {
|
||||
Logger.error("InterestManager.BeginLoadJob:updateAllPlayers", e);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(advanceOneSecond());
|
||||
} catch (Exception e) {
|
||||
Logger.error("InterestManager.BeginLoadJob:advanceOneSecond", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long advanceOneSecond() {
|
||||
|
||||
long curTime = System.currentTimeMillis();
|
||||
long dur = 1000 + this.lastTime - curTime;
|
||||
|
||||
if (dur < 0) {
|
||||
// Last update took more then one second, not good...
|
||||
Logger.warn("LoadJob took more then one second to complete.");
|
||||
this.lastTime = curTime + 100;
|
||||
return 100;
|
||||
}
|
||||
this.lastTime += 1000;
|
||||
return dur;
|
||||
}
|
||||
|
||||
// Forces the loading of static objects (corpses and buildings).
|
||||
// Needed to override threshold limits on loading statics
|
||||
|
||||
private void updateAllPlayers() {
|
||||
// get all players
|
||||
|
||||
for (PlayerCharacter playerCharacter : SessionManager.getAllActivePlayerCharacters()) {
|
||||
|
||||
if (playerCharacter == null)
|
||||
continue;
|
||||
|
||||
ClientConnection origin = playerCharacter.getClientConnection();
|
||||
|
||||
if (origin == null)
|
||||
continue;
|
||||
|
||||
if (!playerCharacter.isEnteredWorld())
|
||||
continue;
|
||||
|
||||
if (playerCharacter.getTeleportLock().readLock().tryLock()) {
|
||||
|
||||
try {
|
||||
updateStaticList(playerCharacter, origin);
|
||||
updateMobileList(playerCharacter, origin);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
playerCharacter.getTeleportLock().readLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStaticList(PlayerCharacter player, ClientConnection origin) {
|
||||
|
||||
|
||||
// Only update if we've moved far enough to warrant it
|
||||
|
||||
float distanceSquared = player.getLoc().distanceSquared2D(player.getLastStaticLoc());
|
||||
|
||||
if (distanceSquared > sqr(64))
|
||||
player.setLastStaticLoc(player.getLoc());
|
||||
else if (player.isDirtyLoad() == false)
|
||||
return;
|
||||
|
||||
// Get Statics in range
|
||||
|
||||
HashSet<AbstractWorldObject> toLoad = WorldGrid.getObjectsInRangePartial(player.getLoc(), MBServerStatics.STRUCTURE_LOAD_RANGE,
|
||||
MBServerStatics.MASK_STATIC);
|
||||
|
||||
// get list of obects loaded that need removed
|
||||
|
||||
HashSet<AbstractWorldObject> loadedStaticObjects = player.getLoadedStaticObjects();
|
||||
|
||||
HashSet<AbstractWorldObject> toRemove = null;
|
||||
|
||||
toRemove = new HashSet<>(loadedStaticObjects);
|
||||
|
||||
toRemove.removeAll(toLoad);
|
||||
|
||||
// unload static objects now out of range
|
||||
|
||||
if (toRemove.size() > 0) {
|
||||
|
||||
UnloadObjectsMsg uom = new UnloadObjectsMsg();
|
||||
|
||||
for (AbstractWorldObject obj : toRemove) {
|
||||
|
||||
if (obj.getObjectType().equals(GameObjectType.Building))
|
||||
InterestManager.HandleSpecialUnload((Building) obj, origin);
|
||||
|
||||
if (obj != null && !obj.equals(player))
|
||||
uom.addObject(obj);
|
||||
}
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, uom);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
}
|
||||
|
||||
loadedStaticObjects.removeAll(toRemove);
|
||||
|
||||
// remove any object to load that are already loaded
|
||||
|
||||
toLoad.removeAll(loadedStaticObjects);
|
||||
|
||||
LoadStructureMsg lsm = new LoadStructureMsg();
|
||||
LoadCharacterMsg lcm = null;
|
||||
ArrayList<LoadCharacterMsg> lcmList = new ArrayList<>();
|
||||
|
||||
for (AbstractWorldObject awo : toLoad) {
|
||||
|
||||
if (awo.getObjectType().equals(GameObjectType.Building))
|
||||
lsm.addObject((Building) awo);
|
||||
else if (awo.getObjectType().equals(GameObjectType.Corpse)) {
|
||||
Corpse corpse = (Corpse) awo;
|
||||
lcm = new LoadCharacterMsg(corpse, PlayerCharacter.hideNonAscii());
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, lcm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
|
||||
} else if (awo.getObjectType().equals(GameObjectType.NPC)) {
|
||||
NPC npc = (NPC) awo;
|
||||
lcm = new LoadCharacterMsg(npc, PlayerCharacter.hideNonAscii());
|
||||
|
||||
lcmList.add(lcm);
|
||||
}
|
||||
}
|
||||
|
||||
if (lsm.getStructureList().size() > 0) {
|
||||
Dispatch dispatch = Dispatch.borrow(player, lsm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
}
|
||||
|
||||
for (LoadCharacterMsg lc : lcmList) {
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, lc);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
}
|
||||
|
||||
loadedStaticObjects.addAll(toLoad);
|
||||
player.setDirtyLoad(false);
|
||||
}
|
||||
|
||||
private void updateMobileList(PlayerCharacter player, ClientConnection origin) {
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
// Get list of players in range
|
||||
// TODO for now use a generic getALL list, later tie into Quad Tree
|
||||
HashSet<AbstractWorldObject> toLoad = WorldGrid.getObjectsInRangePartial(player.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE,
|
||||
MBServerStatics.MASK_MOBILE);
|
||||
|
||||
HashSet<AbstractWorldObject> toRemove = new HashSet<>();
|
||||
|
||||
HashSet<AbstractWorldObject> toLoadToPlayer = new HashSet<>();
|
||||
|
||||
for (AbstractWorldObject loadedObject : toLoad) {
|
||||
|
||||
switch (loadedObject.getObjectType()) {
|
||||
case PlayerCharacter:
|
||||
PlayerCharacter loadedPlayer = (PlayerCharacter) loadedObject;
|
||||
|
||||
if (loadedPlayer.getObjectUUID() == player.getObjectUUID())
|
||||
continue;
|
||||
|
||||
if (player.getSeeInvis() < loadedPlayer.getHidden())
|
||||
continue;
|
||||
|
||||
if (loadedPlayer.safemodeInvis())
|
||||
continue;
|
||||
|
||||
if (player.getLoadedObjects().contains(loadedPlayer))
|
||||
continue;
|
||||
|
||||
if (!loadedPlayer.isInWorldGrid())
|
||||
continue;
|
||||
|
||||
toLoadToPlayer.add(loadedPlayer);
|
||||
break;
|
||||
//not playerCharacter, mobs,npcs and corpses cant be invis or safemode, just add normaly
|
||||
default:
|
||||
if (player.getLoadedObjects().contains(loadedObject))
|
||||
continue;
|
||||
|
||||
if (!loadedObject.isInWorldGrid())
|
||||
continue;
|
||||
|
||||
toLoadToPlayer.add(loadedObject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float unloadDistance = MBServerStatics.CHARACTER_LOAD_RANGE;
|
||||
for (AbstractWorldObject playerLoadedObject : player.getLoadedObjects()) {
|
||||
|
||||
if (playerLoadedObject.getObjectType().equals(GameObjectType.PlayerCharacter)) {
|
||||
PlayerCharacter loadedPlayer = (PlayerCharacter) playerLoadedObject;
|
||||
if (player.getSeeInvis() < loadedPlayer.getHidden())
|
||||
toRemove.add(playerLoadedObject);
|
||||
else if (loadedPlayer.safemodeInvis())
|
||||
toRemove.add(playerLoadedObject);
|
||||
}
|
||||
|
||||
if (!playerLoadedObject.isInWorldGrid())
|
||||
toRemove.add(playerLoadedObject);
|
||||
else if (playerLoadedObject.getLoc().distanceSquared2D(player.getLoc()) > unloadDistance * unloadDistance)
|
||||
toRemove.add(playerLoadedObject);
|
||||
|
||||
}
|
||||
|
||||
player.getLoadedObjects().addAll(toLoadToPlayer);
|
||||
player.getLoadedObjects().removeAll(toRemove);
|
||||
|
||||
// get list of obects loaded to remove
|
||||
|
||||
// unload objects now out of range
|
||||
|
||||
if (toRemove.size() > 0) {
|
||||
|
||||
UnloadObjectsMsg uom = new UnloadObjectsMsg();
|
||||
|
||||
for (AbstractWorldObject obj : toRemove) {
|
||||
|
||||
try {
|
||||
if (obj != null)
|
||||
if (obj.equals(player)) // don't unload self
|
||||
continue;
|
||||
|
||||
uom.addObject(obj);
|
||||
|
||||
if (obj.getObjectType() == GameObjectType.Mob)
|
||||
((Mob) obj).playerAgroMap.remove(player.getObjectUUID());
|
||||
} catch (Exception e) {
|
||||
Logger.error("UnloadCharacter", obj.getObjectUUID() + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (!uom.getObjectList().isEmpty()) {
|
||||
Dispatch dispatch = Dispatch.borrow(player, uom);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
}
|
||||
}
|
||||
|
||||
LoadCharacterMsg lcm = null;
|
||||
ArrayList<AbstractWorldObject> players = new ArrayList<>();
|
||||
ArrayList<AbstractWorldObject> addToList = new ArrayList<>();
|
||||
|
||||
for (AbstractWorldObject awo : toLoadToPlayer) {
|
||||
|
||||
|
||||
try {
|
||||
if (awo.equals(player)) // dont load yourself
|
||||
continue;
|
||||
|
||||
if ((awo.getObjectTypeMask() & MBServerStatics.MASK_PLAYER) != 0) {
|
||||
|
||||
// object to load is a player
|
||||
|
||||
PlayerCharacter awopc = (PlayerCharacter) awo;
|
||||
|
||||
// dont load if invis
|
||||
|
||||
if (player.getSeeInvis() < awopc.getHidden())
|
||||
continue;
|
||||
|
||||
lcm = new LoadCharacterMsg(awopc, PlayerCharacter.hideNonAscii());
|
||||
players.add(awo);
|
||||
|
||||
// check if in a group with the person being loaded
|
||||
// and if so set updateGroup flag
|
||||
|
||||
if (GroupManager.getGroup(player) != null
|
||||
&& GroupManager.getGroup(player) == GroupManager.getGroup(awopc))
|
||||
|
||||
// submit a job as for some reason the client needs a delay
|
||||
// with group updates
|
||||
// as it wont update if we do RefreshGroup directly after
|
||||
// sending the lcm below
|
||||
|
||||
JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(player, awopc), MBServerStatics.LOAD_OBJECT_DELAY);
|
||||
|
||||
} else if ((awo.getObjectTypeMask() & MBServerStatics.MASK_MOB) != 0) {
|
||||
Mob awonpc = (Mob) awo;
|
||||
|
||||
if (!awonpc.isAlive() && (awonpc.isPet() || awonpc.isSiege() || awonpc.isNecroPet() || awonpc.isPlayerGuard()))
|
||||
continue;
|
||||
|
||||
//removed, interest manager should still load mob corpses
|
||||
|
||||
if (awonpc.despawned == true)
|
||||
continue;
|
||||
|
||||
awonpc.playerAgroMap.put(player.getObjectUUID(), false);
|
||||
((Mob) awonpc).setCombatTarget(null);
|
||||
lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii());
|
||||
|
||||
} else if ((awo.getObjectTypeMask() & MBServerStatics.MASK_NPC) != 0) {
|
||||
NPC awonpc = (NPC) awo;
|
||||
lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii());
|
||||
} else if ((awo.getObjectTypeMask() & MBServerStatics.MASK_PET) != 0) {
|
||||
Mob awonpc = (Mob) awo;
|
||||
|
||||
if (!awonpc.isAlive())
|
||||
continue;
|
||||
|
||||
awonpc.playerAgroMap.put(player.getObjectUUID(), false);
|
||||
|
||||
if ((awonpc.agentType.equals(Enum.AIAgentType.MOBILE)))
|
||||
((Mob) awonpc).setCombatTarget(null);
|
||||
|
||||
lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii());
|
||||
}
|
||||
|
||||
addToList.add(awo);
|
||||
|
||||
if (lcm != null) {
|
||||
Dispatch dispatch = Dispatch.borrow(player, lcm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(awo.getObjectUUID() + " " + e.getMessage());
|
||||
}
|
||||
//Delaying character loading to reduce bandwidth consumption
|
||||
}
|
||||
|
||||
// send effects for all players being loaded
|
||||
// do it on a timer otherwise we may get failures as te client needs
|
||||
// time to process lcm
|
||||
//Added effects to LoadCharacter Serialization.
|
||||
//JobScheduler.getInstance().scheduleJob(new LoadEffectsJob(players, origin), MBServerStatics.LOAD_OBJECT_DELAY);
|
||||
}
|
||||
|
||||
public synchronized void HandleLoadForEnterWorld(PlayerCharacter player) {
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
ClientConnection origin = player.getClientConnection();
|
||||
|
||||
if (origin == null)
|
||||
return;
|
||||
|
||||
// Update loaded upbjects lists
|
||||
|
||||
player.setDirtyLoad(true);
|
||||
updateStaticList(player, origin);
|
||||
updateMobileList(player, origin);
|
||||
|
||||
}
|
||||
|
||||
public synchronized void HandleLoadForTeleport(PlayerCharacter playerCharacter) {
|
||||
|
||||
if (playerCharacter == null)
|
||||
return;
|
||||
|
||||
ClientConnection origin = playerCharacter.getClientConnection();
|
||||
|
||||
if (origin == null)
|
||||
return;
|
||||
|
||||
// Update loaded upbjects lists
|
||||
|
||||
playerCharacter.setDirtyLoad(true);
|
||||
updateStaticList(playerCharacter, origin);
|
||||
updateMobileList(playerCharacter, origin);
|
||||
|
||||
}
|
||||
|
||||
public static void setObjectDirty(AbstractWorldObject abstractWorldObject) {
|
||||
|
||||
HashSet<AbstractWorldObject> playerList = WorldGrid.getObjectsInRangePartial(abstractWorldObject.getLoc(), MBServerStatics.CHARACTER_LOAD_RANGE, MBServerStatics.MASK_PLAYER);
|
||||
|
||||
if (playerList.isEmpty())
|
||||
return;
|
||||
|
||||
for (AbstractWorldObject playerObject : playerList) {
|
||||
|
||||
PlayerCharacter playerCharacter = (PlayerCharacter) playerObject;
|
||||
playerCharacter.setDirtyLoad(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package engine.InterestManagement;
|
||||
|
||||
/* This class is the main interface for Magicbane's
|
||||
* Interest management facilities.
|
||||
*/
|
||||
|
||||
import engine.Enum;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.msg.TerritoryChangeMessage;
|
||||
import engine.objects.City;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.Realm;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.util.MapLoader;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static engine.objects.Realm.getRealm;
|
||||
|
||||
public enum RealmMap {
|
||||
|
||||
REALM_MAP;
|
||||
|
||||
// Spatial hashmap. Used for determining which Realm
|
||||
// a player is currently located within.
|
||||
|
||||
private static final HashMap<Color, Integer> _rgbToIDMap = new HashMap<>();
|
||||
public static int[][] _realmImageMap;
|
||||
|
||||
public static int getRealmIDByColor(Color color) {
|
||||
|
||||
return _rgbToIDMap.getOrDefault(color, 0);
|
||||
|
||||
}
|
||||
|
||||
public static int getRealmIDAtLocation(Vector3fImmutable pos) {
|
||||
|
||||
int xBuckets = (int) ((pos.getX() / MBServerStatics.MAX_WORLD_WIDTH) * MBServerStatics.SPATIAL_HASH_BUCKETSX);
|
||||
int yBuckets = (int) ((pos.getZ() / MBServerStatics.MAX_WORLD_HEIGHT) * MBServerStatics.SPATIAL_HASH_BUCKETSY);
|
||||
|
||||
if (yBuckets < 0 || yBuckets >= MBServerStatics.SPATIAL_HASH_BUCKETSY
|
||||
|| xBuckets < 0 || xBuckets >= MBServerStatics.SPATIAL_HASH_BUCKETSX) {
|
||||
Logger.error("Invalid range; Z: " + yBuckets + ", X: " + xBuckets);
|
||||
return 255;
|
||||
}
|
||||
|
||||
return RealmMap._realmImageMap[xBuckets][yBuckets];
|
||||
}
|
||||
|
||||
public static void addToColorMap(Color color, int realmID) {
|
||||
_rgbToIDMap.put(color, realmID);
|
||||
}
|
||||
|
||||
public static Realm getRealmForCity(City city) {
|
||||
Realm outRealm = null;
|
||||
outRealm = city.getRealm();
|
||||
return outRealm;
|
||||
}
|
||||
|
||||
public static Realm getRealmAtLocation(Vector3fImmutable worldVector) {
|
||||
|
||||
return getRealm(RealmMap.getRealmIDAtLocation(worldVector));
|
||||
|
||||
}
|
||||
|
||||
public static void updateRealm(PlayerCharacter player) {
|
||||
|
||||
int realmID = RealmMap.getRealmIDAtLocation(player.getLoc());
|
||||
|
||||
if (realmID != player.getLastRealmID()) {
|
||||
player.setLastRealmID(realmID);
|
||||
Realm realm = Realm.getRealm(realmID);
|
||||
if (realm != null) {
|
||||
if (realm.isRuled()) {
|
||||
City city = realm.getRulingCity();
|
||||
if (city != null) {
|
||||
TerritoryChangeMessage tcm = new TerritoryChangeMessage((PlayerCharacter) realm.getRulingCity().getOwner(), realm);
|
||||
Dispatch dispatch = Dispatch.borrow(player, tcm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
|
||||
} else {
|
||||
TerritoryChangeMessage tcm = new TerritoryChangeMessage(null, realm);
|
||||
Dispatch dispatch = Dispatch.borrow(player, tcm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
|
||||
}
|
||||
|
||||
} else {
|
||||
TerritoryChangeMessage tcm = new TerritoryChangeMessage(null, realm);
|
||||
Dispatch dispatch = Dispatch.borrow(player, tcm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void loadRealmImageMap() {
|
||||
|
||||
// Build color lookup map for realms from database
|
||||
|
||||
for (Realm realm : Realm._realms.values()) {
|
||||
RealmMap.addToColorMap(realm.mapColor, realm.realmID);
|
||||
}
|
||||
|
||||
RealmMap._realmImageMap = MapLoader.loadMap();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package engine.InterestManagement;
|
||||
|
||||
import engine.Enum.GridObjectType;
|
||||
import engine.math.FastMath;
|
||||
import engine.math.Vector3f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.LoadCharacterMsg;
|
||||
import engine.net.client.msg.LoadStructureMsg;
|
||||
import engine.net.client.msg.UnloadObjectsMsg;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
public class WorldGrid {
|
||||
|
||||
public static ConcurrentHashMap<Integer, AbstractWorldObject>[][] DynamicGridMap;
|
||||
public static ConcurrentHashMap<Integer, AbstractWorldObject>[][] StaticGridMap;
|
||||
private static float dynamicBucketScale = 0.00390625f; // 256 bucket size, 1/256
|
||||
private static float staticBucketScale = 0.00390625f;
|
||||
|
||||
public static void startLoadJob() {
|
||||
|
||||
Thread loadJobThread;
|
||||
|
||||
|
||||
loadJobThread = new Thread(InterestManager.INTERESTMANAGER);
|
||||
loadJobThread.setName("InterestManager");
|
||||
loadJobThread.start();
|
||||
}
|
||||
|
||||
public static boolean moveWorldObject(AbstractWorldObject awo, Vector3fImmutable location) {
|
||||
awo.setLoc(location);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getInRange(Vector3f loc, double r) {
|
||||
HashSet<AbstractWorldObject> outbound = new HashSet<>();
|
||||
return outbound;
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangePartial(Vector3fImmutable loc, double r, int mask) {
|
||||
HashSet<AbstractWorldObject> outbound = new HashSet<>();
|
||||
float scale;
|
||||
|
||||
if ((mask & MBServerStatics.MASK_STATIC) != 0)
|
||||
scale = WorldGrid.staticBucketScale;
|
||||
else
|
||||
scale = WorldGrid.dynamicBucketScale;
|
||||
int gridX = (int) Math.abs(loc.x * scale);
|
||||
int gridZ = (int) Math.abs(loc.z * scale);
|
||||
int bucketSize = (int) (r * scale) + 1;
|
||||
//start at top left most corner to scan.
|
||||
int startingX = gridX - bucketSize;
|
||||
int startingZ = gridZ + bucketSize;
|
||||
|
||||
|
||||
int limitX = Math.abs((int) (MBServerStatics.MAX_WORLD_WIDTH * scale));
|
||||
int limitZ = Math.abs((int) (MBServerStatics.MAX_WORLD_HEIGHT * scale)); //LimitZ is negative, remember to flip sign.
|
||||
|
||||
if (startingX < 0)
|
||||
startingX = 0;
|
||||
|
||||
if (startingZ < 0)
|
||||
startingZ = 0;
|
||||
|
||||
if (startingX > limitX)
|
||||
startingX = limitX;
|
||||
|
||||
if (startingZ > limitZ)
|
||||
startingZ = limitZ;
|
||||
|
||||
int endX = startingX + (bucketSize * 2);
|
||||
int endZ = startingZ - (bucketSize * 2);
|
||||
|
||||
if (endX < 0)
|
||||
endX = 0;
|
||||
|
||||
if (endZ < 0)
|
||||
endZ = 0;
|
||||
|
||||
if (endX > limitX)
|
||||
endX = limitX;
|
||||
|
||||
if (endZ > limitZ)
|
||||
endZ = limitZ;
|
||||
|
||||
int auditMob = 0;
|
||||
for (int x = startingX; x <= endX; x++) {
|
||||
for (int z = startingZ; z >= endZ; z--) {
|
||||
|
||||
ConcurrentHashMap<Integer, AbstractWorldObject> gridMap;
|
||||
|
||||
if ((MBServerStatics.MASK_STATIC & mask) != 0)
|
||||
gridMap = WorldGrid.StaticGridMap[x][z];
|
||||
else
|
||||
gridMap = WorldGrid.DynamicGridMap[x][z];
|
||||
for (AbstractWorldObject gridObject : gridMap.values()) {
|
||||
if ((gridObject.getObjectTypeMask() & mask) == 0)
|
||||
continue;
|
||||
if (gridObject.getLoc().distanceSquared2D(loc) <= FastMath.sqr(r))
|
||||
outbound.add(gridObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
return outbound;
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangePartialNecroPets(Vector3fImmutable loc, double r) {
|
||||
HashSet<AbstractWorldObject> outbound = new HashSet<>();
|
||||
return outbound;
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangeContains(Vector3fImmutable loc, double r, int mask) {
|
||||
HashSet<AbstractWorldObject> outbound = getObjectsInRangePartial(loc, r, mask);
|
||||
return outbound;
|
||||
}
|
||||
|
||||
public static HashSet<AbstractWorldObject> getObjectsInRangePartial(AbstractWorldObject awo, double range, int mask) {
|
||||
return getObjectsInRangePartial(awo.getLoc(), range, mask);
|
||||
}
|
||||
|
||||
|
||||
public static void InitializeGridObjects() {
|
||||
|
||||
int dynamicWidth = (int) Math.abs(MBServerStatics.MAX_WORLD_WIDTH * WorldGrid.dynamicBucketScale);
|
||||
int dynamicHeight = (int) Math.abs(MBServerStatics.MAX_WORLD_HEIGHT * WorldGrid.dynamicBucketScale);
|
||||
|
||||
int staticWidth = (int) Math.abs(MBServerStatics.MAX_WORLD_WIDTH * WorldGrid.staticBucketScale);
|
||||
int staticHeight = (int) Math.abs(MBServerStatics.MAX_WORLD_HEIGHT * WorldGrid.staticBucketScale);
|
||||
WorldGrid.DynamicGridMap = new ConcurrentHashMap[dynamicWidth + 1][dynamicHeight + 1];
|
||||
WorldGrid.StaticGridMap = new ConcurrentHashMap[staticWidth + 1][staticHeight + 1];
|
||||
//create new hash maps for each bucket
|
||||
for (int x = 0; x <= staticWidth; x++)
|
||||
for (int y = 0; y <= staticHeight; y++) {
|
||||
WorldGrid.StaticGridMap[x][y] = new ConcurrentHashMap<Integer, AbstractWorldObject>();
|
||||
}
|
||||
|
||||
for (int x = 0; x <= dynamicWidth; x++)
|
||||
for (int y = 0; y <= dynamicHeight; y++) {
|
||||
WorldGrid.DynamicGridMap[x][y] = new ConcurrentHashMap<Integer, AbstractWorldObject>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void RemoveWorldObject(AbstractWorldObject gridObject) {
|
||||
|
||||
if (gridObject == null)
|
||||
return;
|
||||
AbstractWorldObject.RemoveFromWorldGrid(gridObject);
|
||||
}
|
||||
|
||||
public static boolean addObject(AbstractWorldObject gridObject, float x, float z) {
|
||||
|
||||
if (gridObject == null)
|
||||
return false;
|
||||
|
||||
if (x > MBServerStatics.MAX_WORLD_WIDTH)
|
||||
return false;
|
||||
|
||||
if (z < MBServerStatics.MAX_WORLD_HEIGHT)
|
||||
return false;
|
||||
|
||||
if (x < 0)
|
||||
return false;
|
||||
if (z > 0)
|
||||
return false;
|
||||
|
||||
int gridX;
|
||||
int gridZ;
|
||||
|
||||
if (gridObject.getGridObjectType().equals(GridObjectType.STATIC)) {
|
||||
gridX = Math.abs((int) (x * WorldGrid.staticBucketScale));
|
||||
gridZ = Math.abs((int) (z * WorldGrid.staticBucketScale));
|
||||
} else {
|
||||
gridX = Math.abs((int) (x * WorldGrid.dynamicBucketScale));
|
||||
gridZ = Math.abs((int) (z * WorldGrid.dynamicBucketScale));
|
||||
}
|
||||
|
||||
|
||||
WorldGrid.RemoveWorldObject(gridObject);
|
||||
|
||||
return AbstractWorldObject.AddToWorldGrid(gridObject, gridX, gridZ);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void unloadObject(AbstractWorldObject awo) {
|
||||
|
||||
UnloadObjectsMsg uom = new UnloadObjectsMsg();
|
||||
uom.addObject(awo);
|
||||
DispatchMessage.sendToAllInRange(awo, uom);
|
||||
}
|
||||
|
||||
public static void loadObject(AbstractWorldObject awo) {
|
||||
|
||||
LoadStructureMsg lsm;
|
||||
LoadCharacterMsg lcm;
|
||||
|
||||
switch (awo.getObjectType()) {
|
||||
case Building:
|
||||
lsm = new LoadStructureMsg();
|
||||
lsm.addObject((Building) awo);
|
||||
DispatchMessage.sendToAllInRange(awo, lsm);
|
||||
break;
|
||||
case NPC:
|
||||
lcm = new LoadCharacterMsg((NPC) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
case Mob:
|
||||
lcm = new LoadCharacterMsg((Mob) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
default:
|
||||
// *** Refactor: Log error?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadObject(AbstractWorldObject awo, ClientConnection origin) {
|
||||
|
||||
LoadStructureMsg lsm;
|
||||
LoadCharacterMsg lcm;
|
||||
|
||||
switch (awo.getObjectType()) {
|
||||
|
||||
case Building:
|
||||
lsm = new LoadStructureMsg();
|
||||
lsm.addObject((Building) awo);
|
||||
DispatchMessage.sendToAllInRange(awo, lsm);
|
||||
break;
|
||||
case NPC:
|
||||
lcm = new LoadCharacterMsg((NPC) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
case Mob:
|
||||
lcm = new LoadCharacterMsg((Mob) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
case PlayerCharacter:
|
||||
lcm = new LoadCharacterMsg((PlayerCharacter) awo, false);
|
||||
DispatchMessage.sendToAllInRange(awo, lcm);
|
||||
break;
|
||||
default:
|
||||
// *** Refactor: Log error?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void unloadObject(AbstractWorldObject awo,
|
||||
ClientConnection origin) {
|
||||
UnloadObjectsMsg uom = new UnloadObjectsMsg();
|
||||
uom.addObject(awo);
|
||||
DispatchMessage.sendToAllInRange(awo, uom);
|
||||
}
|
||||
|
||||
public static void addObject(AbstractWorldObject awo, PlayerCharacter pc) {
|
||||
if (pc == null || awo == null)
|
||||
return;
|
||||
ClientConnection origin = pc.getClientConnection();
|
||||
if (origin == null)
|
||||
return;
|
||||
loadObject(awo, origin);
|
||||
}
|
||||
|
||||
public static void removeObject(AbstractWorldObject awo, PlayerCharacter pc) {
|
||||
if (pc == null || awo == null)
|
||||
return;
|
||||
ClientConnection origin = pc.getClientConnection();
|
||||
if (origin == null)
|
||||
return;
|
||||
unloadObject(awo, origin);
|
||||
}
|
||||
|
||||
public static void updateObject(AbstractWorldObject awo, PlayerCharacter pc) {
|
||||
if (pc == null || awo == null)
|
||||
return;
|
||||
ClientConnection origin = pc.getClientConnection();
|
||||
if (origin == null)
|
||||
return;
|
||||
unloadObject(awo, origin);
|
||||
loadObject(awo, origin);
|
||||
}
|
||||
|
||||
public static void updateObject(AbstractWorldObject awo) {
|
||||
if (awo == null)
|
||||
return;
|
||||
unloadObject(awo);
|
||||
loadObject(awo);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static void removeObject(AbstractWorldObject awo) {
|
||||
if (awo == null)
|
||||
return;
|
||||
unloadObject(awo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.core;
|
||||
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class ControlledRunnable implements Runnable {
|
||||
// Runnable tracking
|
||||
private static final ArrayList<ControlledRunnable> runnables = new ArrayList<>();
|
||||
private final String threadName;
|
||||
protected boolean runCmd = false;
|
||||
protected boolean runStatus = false;
|
||||
private Thread thisThread;
|
||||
|
||||
/*
|
||||
* Main loop
|
||||
*/
|
||||
|
||||
public ControlledRunnable(String threadName) {
|
||||
super();
|
||||
this.threadName = threadName;
|
||||
ControlledRunnable.runnables.add(this);
|
||||
}
|
||||
|
||||
public static void shutdownAllRunnables() {
|
||||
for (ControlledRunnable cr : ControlledRunnable.runnables) {
|
||||
//Use Direct logging since JobManager is a runnable.
|
||||
Logger.info("ControlledRunnable",
|
||||
"Sending Shutdown cmd to: " + cr.threadName);
|
||||
cr.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the method called when ControlledRunnable.thisThread.start() is
|
||||
* called.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if (this._preRun() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.runStatus = true;
|
||||
|
||||
if (this._Run() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._postRun() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.runStatus = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* _preRun() is called prior to the call to _Run(), but after _startup()
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean _preRun();
|
||||
|
||||
/*
|
||||
* Control
|
||||
*/
|
||||
|
||||
/**
|
||||
* _Run() is called after _startup() and contains should contain the main
|
||||
* loop.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean _Run();
|
||||
|
||||
/**
|
||||
* _postRun() is called after _Run() exits, not necessarily before
|
||||
* _shutdown()
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract boolean _postRun();
|
||||
|
||||
/**
|
||||
* startup() initializes the internal thread, sets the runCMD to true, and
|
||||
* calls _startup() prior to starting of the internal Thread.
|
||||
*/
|
||||
public void startup() {
|
||||
|
||||
this.thisThread = new Thread(this, this.threadName);
|
||||
this.runCmd = true;
|
||||
this._startup();
|
||||
this.thisThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called just before ControlledRunnable.thisThread.start()
|
||||
* is called.
|
||||
*/
|
||||
protected abstract void _startup();
|
||||
|
||||
/**
|
||||
* This method is called to request a shutdown of the runnable.
|
||||
*/
|
||||
public void shutdown() {
|
||||
this.runCmd = false;
|
||||
this._shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called just after ControlledRunnable.runCmd is set to
|
||||
* False.
|
||||
*/
|
||||
protected abstract void _shutdown();
|
||||
|
||||
/*
|
||||
* Getters n setters
|
||||
*/
|
||||
public boolean getRunCmd() {
|
||||
return runCmd;
|
||||
}
|
||||
|
||||
public boolean getRunStatus() {
|
||||
return runStatus;
|
||||
}
|
||||
|
||||
/*
|
||||
* Blockers
|
||||
*/
|
||||
public void blockTillRunStatus(boolean status) {
|
||||
while (this.runStatus != status) {
|
||||
try {
|
||||
System.out.println("BLOCKING");
|
||||
Thread.sleep(25L);
|
||||
} catch (InterruptedException e) {
|
||||
Logger.debug(e.getMessage());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Instance monitoring and tools
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return the thisThread
|
||||
*/
|
||||
protected Thread getThisThread() {
|
||||
return thisThread;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the threadName
|
||||
*/
|
||||
public String getThreadName() {
|
||||
return threadName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,382 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Bane;
|
||||
import engine.objects.City;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static engine.Enum.RecordEventType;
|
||||
|
||||
public class BaneRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<BaneRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private RecordEventType eventType;
|
||||
private String cityHash;
|
||||
private String cityName;
|
||||
private String cityGuildHash;
|
||||
private String cityNationHash;
|
||||
private String baneDropperHash;
|
||||
private String baneGuildHash;
|
||||
private String baneNationHash;
|
||||
private DateTime baneLiveTime;
|
||||
private DateTime baneDropTime;
|
||||
|
||||
private BaneRecord(Bane bane) {
|
||||
this.recordType = Enum.DataRecordType.BANE;
|
||||
this.eventType = RecordEventType.PENDING;
|
||||
}
|
||||
|
||||
public static BaneRecord borrow(Bane bane, RecordEventType eventType) {
|
||||
BaneRecord baneRecord;
|
||||
|
||||
baneRecord = recordPool.poll();
|
||||
|
||||
if (baneRecord == null) {
|
||||
baneRecord = new BaneRecord(bane);
|
||||
baneRecord.eventType = eventType;
|
||||
} else {
|
||||
baneRecord.recordType = Enum.DataRecordType.BANE;
|
||||
baneRecord.eventType = eventType;
|
||||
|
||||
}
|
||||
|
||||
baneRecord.cityHash = bane.getCity().getHash();
|
||||
baneRecord.cityName = bane.getCity().getCityName();
|
||||
baneRecord.cityGuildHash = bane.getCity().getGuild().getHash();
|
||||
baneRecord.cityNationHash = bane.getCity().getGuild().getNation().getHash();
|
||||
|
||||
|
||||
if (bane.getOwner() == null) {
|
||||
baneRecord.baneDropperHash = "ERRANT";
|
||||
baneRecord.baneGuildHash = "ERRANT";
|
||||
baneRecord.baneNationHash = "ERRANT";
|
||||
} else {
|
||||
baneRecord.baneDropperHash = DataWarehouse.hasher.encrypt(bane.getOwner().getObjectUUID()); // getPlayerCharacter didn't check hash first? OMFG
|
||||
|
||||
|
||||
baneRecord.baneGuildHash = bane.getOwner().getGuild().getHash();
|
||||
baneRecord.baneNationHash = bane.getOwner().getGuild().getNation().getHash();
|
||||
|
||||
|
||||
baneRecord.baneLiveTime = bane.getLiveDate();
|
||||
baneRecord.baneDropTime = bane.getPlacementDate();
|
||||
}
|
||||
|
||||
|
||||
return baneRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildBanePushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_banehistory` (`event_number`, `city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
|
||||
java.util.Date sqlDateTime;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("city_id"));
|
||||
outStatement.setString(3, rs.getString("city_name"));
|
||||
outStatement.setString(4, rs.getString("char_id"));
|
||||
outStatement.setString(5, rs.getString("offGuild_id"));
|
||||
outStatement.setString(6, rs.getString("offNat_id"));
|
||||
outStatement.setString(7, rs.getString("defGuild_id"));
|
||||
outStatement.setString(8, rs.getString("defNat_id"));
|
||||
|
||||
sqlDateTime = rs.getTimestamp("dropDatetime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(9, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(9, rs.getTimestamp("dropDatetime"));
|
||||
|
||||
sqlDateTime = rs.getTimestamp("dropDatetime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(10, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(10, rs.getTimestamp("liveDateTime"));
|
||||
|
||||
outStatement.setString(11, rs.getString("resolution"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildBaneQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_banehistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.baneIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static DateTime getLastBaneDateTime(City city) {
|
||||
|
||||
DateTime outDateTime = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildDateTimeQueryStatement(connection, city);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
outDateTime = new DateTime(rs.getTimestamp("endDatetime"));
|
||||
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
return outDateTime;
|
||||
}
|
||||
|
||||
|
||||
private static PreparedStatement buildDateTimeQueryStatement(Connection connection, City city) throws SQLException {
|
||||
PreparedStatement outStatement;
|
||||
String queryString = "SELECT `endDatetime` FROM `warehouse_banehistory` WHERE `city_id` = ? ORDER BY `endDatetime` DESC LIMIT 1";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, city.getHash());
|
||||
return outStatement;
|
||||
|
||||
}
|
||||
|
||||
public static void updateLiveDate(Bane bane, DateTime dateTime) {
|
||||
|
||||
if (bane == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildUpdateLiveDateStatement(connection, bane, dateTime)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateLiveDateStatement(Connection connection, Bane bane, DateTime dateTime) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `liveDatetime` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setTimestamp(1, new java.sql.Timestamp(dateTime.getMillis()));
|
||||
outStatement.setString(2, bane.getCity().getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateResolutionStatement(Connection connection, Bane bane, RecordEventType eventType) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `endDatetime` = ?, `resolution` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now()));
|
||||
outStatement.setString(2, eventType.name());
|
||||
outStatement.setString(3, bane.getCity().getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void updateResolution(Bane bane, RecordEventType eventType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildUpdateResolutionStatement(connection, bane, eventType)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static String getBaneHistoryString() {
|
||||
|
||||
String outString;
|
||||
String queryString;
|
||||
String dividerString;
|
||||
String newLine = System.getProperty("line.separator");
|
||||
outString = "[LUA_BANES() DATA WAREHOUSE]" + newLine;
|
||||
dividerString = "--------------------------------" + newLine;
|
||||
queryString = "CALL `baneHistory`()";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = connection.prepareCall(queryString);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
outString += "Magicbane unresolved banes: " + rs.getInt("PENDING") + '/' + rs.getInt("TOTAL") + newLine;
|
||||
outString += dividerString;
|
||||
outString += "Bane Resolution History" + newLine;
|
||||
outString += dividerString;
|
||||
|
||||
outString += "Destruction: " + rs.getInt("DESTROY") + newLine;
|
||||
outString += "Capture: " + rs.getInt("CAPTURE") + newLine;
|
||||
outString += "Defended: " + rs.getInt("DEFEND") + newLine;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
|
||||
public static void updateDirtyRecords() {
|
||||
|
||||
String queryString = "SELECT * FROM `warehouse_banehistory` where `dirty` = 1";
|
||||
|
||||
// Reset character delta
|
||||
|
||||
WarehousePushThread.baneDelta = 0;
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
// Only update the index and dirty flag
|
||||
// if the remote database update succeeded
|
||||
|
||||
if (updateDirtyRecord(rs) == true)
|
||||
WarehousePushThread.baneDelta++;
|
||||
else
|
||||
continue;
|
||||
|
||||
// Reset the dirty flag in the local database
|
||||
|
||||
rs.updateInt("dirty", 0);
|
||||
rs.updateRow();
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean updateDirtyRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = buildUpdateDirtyStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateDirtyStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `liveDateTime` = ?, `endDateTime` = ?, `resolution` = ? WHERE `event_number` = ?";
|
||||
java.util.Date sqlDateTime;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
sqlDateTime = rs.getTimestamp("liveDateTime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(1, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(1, rs.getTimestamp("liveDateTime"));
|
||||
|
||||
sqlDateTime = rs.getTimestamp("endDateTime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(2, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(2, rs.getTimestamp("endDateTime"));
|
||||
|
||||
outStatement.setString(3, rs.getString("resolution"));
|
||||
outStatement.setInt(4, rs.getInt("event_number"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.cityHash = null;
|
||||
this.cityGuildHash = null;
|
||||
this.cityNationHash = null;
|
||||
this.baneDropperHash = null;
|
||||
this.baneGuildHash = null;
|
||||
this.baneNationHash = null;
|
||||
this.baneLiveTime = null;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildBaneInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private PreparedStatement buildBaneInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_banehistory` (`city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
outStatement.setString(1, this.cityHash);
|
||||
outStatement.setString(2, this.cityName);
|
||||
outStatement.setString(3, this.baneDropperHash);
|
||||
outStatement.setString(4, this.baneGuildHash);
|
||||
outStatement.setString(5, this.baneNationHash);
|
||||
outStatement.setString(6, this.cityGuildHash);
|
||||
outStatement.setString(7, this.cityNationHash);
|
||||
|
||||
if (this.baneDropTime == null)
|
||||
outStatement.setNull(8, java.sql.Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(8, new java.sql.Timestamp(this.baneDropTime.getMillis()));
|
||||
|
||||
if (this.baneLiveTime == null)
|
||||
outStatement.setNull(9, java.sql.Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(9, new java.sql.Timestamp(this.baneLiveTime.getMillis()));
|
||||
|
||||
outStatement.setString(10, this.eventType.name());
|
||||
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
} // END CLASS
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/*
|
||||
* This class warehouses character creation events. It also tracks
|
||||
* updates to summary kills/death data and their promotion class.
|
||||
*/
|
||||
public class CharacterRecord extends DataRecord {
|
||||
|
||||
// Local object pool for class
|
||||
|
||||
private static final LinkedBlockingQueue<CharacterRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
|
||||
private PlayerCharacter player;
|
||||
|
||||
private CharacterRecord(PlayerCharacter player) {
|
||||
this.recordType = Enum.DataRecordType.CHARACTER;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static CharacterRecord borrow(PlayerCharacter player) {
|
||||
CharacterRecord characterRecord;
|
||||
|
||||
characterRecord = recordPool.poll();
|
||||
|
||||
if (characterRecord == null) {
|
||||
characterRecord = new CharacterRecord(player);
|
||||
} else {
|
||||
characterRecord.recordType = Enum.DataRecordType.CHARACTER;
|
||||
characterRecord.player = player;
|
||||
|
||||
}
|
||||
|
||||
return characterRecord;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildCharacterInsertStatement(Connection connection, PlayerCharacter player) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_characterhistory` (`char_id`, `char_fname`, `char_lname`, `baseClass`, `race`, `promoteClass`, `startingGuild`, `datetime`) VALUES(?,?,?,?,?,?,?,?)";
|
||||
Guild charGuild;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
charGuild = player.getGuild();
|
||||
|
||||
// Bind character data
|
||||
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(player.getObjectUUID()));
|
||||
outStatement.setString(2, player.getFirstName());
|
||||
outStatement.setString(3, player.getLastName());
|
||||
outStatement.setInt(4, player.getBaseClassID());
|
||||
outStatement.setInt(5, player.getRaceID());
|
||||
outStatement.setInt(6, player.getPromotionClassID());
|
||||
outStatement.setString(7, DataWarehouse.hasher.encrypt(charGuild.getObjectUUID()));
|
||||
outStatement.setTimestamp(8, Timestamp.valueOf(LocalDateTime.now()));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildCharacterPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_characterhistory` (`event_number`, `char_id`, `char_fname`, `char_lname`, `baseClass`, `race`, `promoteClass`, `startingGuild`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("char_id"));
|
||||
outStatement.setString(3, rs.getString("char_fname"));
|
||||
outStatement.setString(4, rs.getString("char_lname"));
|
||||
outStatement.setInt(5, rs.getInt("baseClass"));
|
||||
outStatement.setInt(6, rs.getInt("race"));
|
||||
outStatement.setInt(7, rs.getInt("promoteClass"));
|
||||
outStatement.setString(8, rs.getString("startingGuild"));
|
||||
outStatement.setTimestamp(9, rs.getTimestamp("datetime"));
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildCharacterQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_characterhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.charIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void advanceKillCounter(PlayerCharacter player) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildKillCounterStatement(connection, player)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static PreparedStatement buildKillCounterStatement(Connection connection, PlayerCharacter player) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_characterhistory` SET `kills` = `kills` +1, `dirty` = 1 WHERE `char_id` = ?";
|
||||
|
||||
if (player == null)
|
||||
return outStatement;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, player.getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void advanceDeathCounter(PlayerCharacter player) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildDeathCounterStatement(connection, player)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static PreparedStatement buildDeathCounterStatement(Connection connection, PlayerCharacter player) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_characterhistory` SET `deaths` = `deaths` +1, `dirty` = 1 WHERE `char_id` = ?";
|
||||
|
||||
if (player == null)
|
||||
return outStatement;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, player.getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void updatePromotionClass(PlayerCharacter player) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildUpdatePromotionStatement(connection, player)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdatePromotionStatement(Connection connection, PlayerCharacter player) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_characterhistory` SET `promoteClass` = ?, `dirty` = 1 WHERE `char_id` = ?";
|
||||
|
||||
if (player == null)
|
||||
return outStatement;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
outStatement.setInt(1, player.getPromotionClassID());
|
||||
outStatement.setString(2, player.getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void updateDirtyRecords() {
|
||||
|
||||
String queryString = "SELECT * FROM `warehouse_characterhistory` where `dirty` = 1";
|
||||
|
||||
// Reset character delta
|
||||
|
||||
WarehousePushThread.charDelta = 0;
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
// Only update the index and dirty flag
|
||||
// if the remote database update succeeded
|
||||
|
||||
if (updateDirtyRecord(rs) == true)
|
||||
WarehousePushThread.charDelta++;
|
||||
else
|
||||
continue;
|
||||
|
||||
// Reset the dirty flag in the local database
|
||||
|
||||
rs.updateInt("dirty", 0);
|
||||
rs.updateRow();
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean updateDirtyRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = buildUpdateDirtyStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateDirtyStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement;
|
||||
String queryString = "UPDATE `warehouse_characterhistory` SET `promoteClass` = ?, `kills` = ?, `deaths` = ? WHERE `char_id` = ?";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("promoteClass"));
|
||||
outStatement.setInt(2, rs.getInt("kills"));
|
||||
outStatement.setInt(3, rs.getInt("deaths"));
|
||||
outStatement.setString(4, rs.getString("char_id"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.player = null;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildCharacterInsertStatement(connection, this.player)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error writing character record " + e.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.City;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class CityRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<CityRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private Enum.RecordEventType eventType;
|
||||
private City city;
|
||||
private String cityHash;
|
||||
private String cityGuildHash;
|
||||
private String cityName;
|
||||
private String cityMotto;
|
||||
private float locX;
|
||||
private float locY;
|
||||
private String zoneHash;
|
||||
private java.time.LocalDateTime establishedDatetime;
|
||||
|
||||
private CityRecord(City city) {
|
||||
this.recordType = Enum.DataRecordType.CITY;
|
||||
this.city = city;
|
||||
this.eventType = Enum.RecordEventType.CREATE;
|
||||
|
||||
}
|
||||
|
||||
public static CityRecord borrow(City city, Enum.RecordEventType eventType) {
|
||||
CityRecord cityRecord;
|
||||
|
||||
cityRecord = recordPool.poll();
|
||||
|
||||
if (cityRecord == null) {
|
||||
cityRecord = new CityRecord(city);
|
||||
cityRecord.eventType = eventType;
|
||||
} else {
|
||||
cityRecord.recordType = Enum.DataRecordType.CITY;
|
||||
cityRecord.eventType = eventType;
|
||||
cityRecord.city = city;
|
||||
|
||||
}
|
||||
|
||||
if (cityRecord.city.getHash() == null)
|
||||
cityRecord.city.setHash(DataWarehouse.hasher.encrypt(cityRecord.city.getObjectUUID()));
|
||||
|
||||
cityRecord.cityHash = cityRecord.city.getHash();
|
||||
|
||||
|
||||
cityRecord.cityName = cityRecord.city.getCityName();
|
||||
cityRecord.cityMotto = cityRecord.city.getMotto();
|
||||
|
||||
cityRecord.cityGuildHash = cityRecord.city.getGuild().getHash();
|
||||
|
||||
cityRecord.locX = cityRecord.city.getTOL().getLoc().x;
|
||||
cityRecord.locY = -cityRecord.city.getTOL().getLoc().z; // flip sign on 'y' coordinate
|
||||
|
||||
cityRecord.zoneHash = cityRecord.city.getParent().getHash();
|
||||
|
||||
if (cityRecord.eventType.equals(Enum.RecordEventType.CREATE))
|
||||
cityRecord.establishedDatetime = cityRecord.city.established;
|
||||
else
|
||||
cityRecord.establishedDatetime = java.time.LocalDateTime.now();
|
||||
|
||||
return cityRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildCityPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_cityhistory` (`event_number`, `city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("city_id"));
|
||||
outStatement.setString(3, rs.getString("city_name"));
|
||||
outStatement.setString(4, rs.getString("city_motto"));
|
||||
outStatement.setString(5, rs.getString("guild_id"));
|
||||
|
||||
outStatement.setFloat(6, rs.getFloat("loc_x"));
|
||||
outStatement.setFloat(7, rs.getFloat("loc_y"));
|
||||
outStatement.setString(8, rs.getString("zone_id"));
|
||||
outStatement.setString(9, rs.getString("eventType"));
|
||||
outStatement.setTimestamp(10, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildCityQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_cityhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.cityIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.city = null;
|
||||
this.cityHash = null;
|
||||
this.cityGuildHash = null;
|
||||
this.cityMotto = null;
|
||||
this.zoneHash = null;
|
||||
this.establishedDatetime = null;
|
||||
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildCityInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private PreparedStatement buildCityInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_cityhistory` (`city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind character data
|
||||
|
||||
outStatement.setString(1, this.cityHash);
|
||||
outStatement.setString(2, this.cityName);
|
||||
outStatement.setString(3, this.cityMotto);
|
||||
outStatement.setString(4, this.cityGuildHash);
|
||||
|
||||
outStatement.setFloat(5, this.locX);
|
||||
outStatement.setFloat(6, this.locY);
|
||||
outStatement.setString(7, this.zoneHash);
|
||||
outStatement.setString(8, this.eventType.name());
|
||||
outStatement.setTimestamp(9, Timestamp.valueOf(this.establishedDatetime));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
|
||||
class DataRecord {
|
||||
|
||||
public Enum.DataRecordType recordType;
|
||||
|
||||
DataRecord() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.util.Hasher;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static engine.Enum.DataRecordType;
|
||||
|
||||
public class DataWarehouse implements Runnable {
|
||||
|
||||
public static final Hasher hasher = new Hasher("Cthulhu Owns Joo");
|
||||
private static final LinkedBlockingQueue<DataRecord> recordQueue = new LinkedBlockingQueue<>();
|
||||
public static HikariDataSource remoteConnectionPool = null;
|
||||
|
||||
public DataWarehouse() {
|
||||
|
||||
// If WarehousePush is disabled
|
||||
// then early exit
|
||||
|
||||
if (ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equalsIgnoreCase("false")) {
|
||||
Logger.info("Warehouse Remote Connection disabled along with push");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.info("Configuring remote Database Connection Pool...");
|
||||
configureRemoteConnectionPool();
|
||||
}
|
||||
|
||||
public static void bootStrap() {
|
||||
Thread warehousingThread;
|
||||
warehousingThread = new Thread(new DataWarehouse());
|
||||
|
||||
warehousingThread.setName("DataWarehouse");
|
||||
warehousingThread.setPriority(Thread.NORM_PRIORITY - 1);
|
||||
warehousingThread.start();
|
||||
}
|
||||
|
||||
public static void pushToWarehouse(DataRecord dataRecord) {
|
||||
|
||||
DataWarehouse.recordQueue.add(dataRecord);
|
||||
}
|
||||
|
||||
public static void writeHash(DataRecordType recordType, int uuid) {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
String queryString;
|
||||
String hashString;
|
||||
|
||||
connection = DbManager.getConnection();
|
||||
|
||||
if (connection == null) {
|
||||
Logger.error("Null connection when writing zone hash.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Build query string
|
||||
|
||||
switch (recordType) {
|
||||
case CHARACTER:
|
||||
queryString = "UPDATE `obj_character` SET hash = ? WHERE `UID` = ?";
|
||||
break;
|
||||
case GUILD:
|
||||
queryString = "UPDATE `obj_guild` SET hash = ? WHERE `UID` = ?";
|
||||
break;
|
||||
case ZONE:
|
||||
queryString = "UPDATE `obj_zone` SET hash = ? WHERE `UID` = ?";
|
||||
break;
|
||||
case CITY:
|
||||
queryString = "UPDATE `obj_city` SET hash = ? WHERE `UID` = ?";
|
||||
break;
|
||||
case REALM:
|
||||
queryString = "UPDATE `obj_realm` SET hash = ? WHERE `realmID` = ?";
|
||||
break;
|
||||
default:
|
||||
queryString = null;
|
||||
break;
|
||||
}
|
||||
|
||||
hashString = hasher.encrypt(uuid);
|
||||
|
||||
// Write this record to the warehouse
|
||||
|
||||
try {
|
||||
|
||||
statement = connection.prepareStatement(queryString);
|
||||
|
||||
statement.setString(1, hashString);
|
||||
statement.setLong(2, uuid);
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error writing hash for uuid" + uuid + " of type " + recordType.name() + ' ' + e.toString());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean recordExists(DataRecordType recordType, int uuid) {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
String queryString;
|
||||
ResultSet resultSet;
|
||||
|
||||
connection = DbManager.getConnection();
|
||||
|
||||
if (connection == null) {
|
||||
Logger.error("Null connection during char record lookup");
|
||||
return true; // False positive here, so as not to try and write the record twice.
|
||||
// will refactor out once we write hashes to object tables
|
||||
}
|
||||
|
||||
// Build query string
|
||||
|
||||
switch (recordType) {
|
||||
case CHARACTER:
|
||||
queryString = "SELECT COUNT(*) from warehouse_characterhistory where char_id = ?";
|
||||
break;
|
||||
case GUILD:
|
||||
queryString = "SELECT COUNT(*) from warehouse_guildhistory where guild_id = ?";
|
||||
break;
|
||||
case CITY:
|
||||
queryString = "SELECT COUNT(*) from warehouse_cityhistory where city_id = ?";
|
||||
break;
|
||||
case REALM:
|
||||
queryString = "SELECT COUNT(*) from warehouse_realmhistory where realm_id = ?";
|
||||
break;
|
||||
case BANE:
|
||||
queryString = "SELECT COUNT(*) from warehouse_banehistory where city_id = ? AND `resolution` = 'PENDING'";
|
||||
break;
|
||||
case ZONE: // Does not really exist but enum acts as a proxy for hash lookup
|
||||
case MINE: // Does not really exist but enum acts as a proxy for hash lookup
|
||||
default:
|
||||
queryString = null;
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
statement = connection.prepareStatement(queryString);
|
||||
statement.setString(1, DataWarehouse.hasher.encrypt(uuid));
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
return resultSet.getInt("COUNT(*)") > 0;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error in record lookup for " + recordType.name() + " of uuid:" + uuid + e.toString());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void configureRemoteConnectionPool() {
|
||||
|
||||
HikariConfig config = new HikariConfig();
|
||||
|
||||
config.setMaximumPoolSize(1); // Only the server talks to remote, so yeah.
|
||||
config.setJdbcUrl(ConfigManager.MB_WAREHOUSE_ADDR.getValue());
|
||||
config.setUsername(ConfigManager.MB_WAREHOUSE_USER.getValue());
|
||||
config.setPassword(ConfigManager.MB_WAREHOUSE_PASS.getValue());
|
||||
config.addDataSourceProperty("characterEncoding", "utf8");
|
||||
config.addDataSourceProperty("cachePrepStmts", "true");
|
||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
|
||||
remoteConnectionPool = new HikariDataSource(config); // setup the connection pool
|
||||
|
||||
Logger.info("remote warehouse connection configured");
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
// Working variable set
|
||||
|
||||
DataRecord dataRecord;
|
||||
PvpRecord pvpRecord;
|
||||
GuildRecord guildRecord;
|
||||
CharacterRecord characterRecord;
|
||||
CityRecord cityRecord;
|
||||
BaneRecord baneRecord;
|
||||
RealmRecord realmRecord;
|
||||
MineRecord mineRecord;
|
||||
|
||||
Logger.info("DataWarehouse is running.");
|
||||
|
||||
while (true) {
|
||||
|
||||
dataRecord = null;
|
||||
pvpRecord = null;
|
||||
guildRecord = null;
|
||||
characterRecord = null;
|
||||
cityRecord = null;
|
||||
baneRecord = null;
|
||||
realmRecord = null;
|
||||
mineRecord = null;
|
||||
|
||||
try {
|
||||
dataRecord = recordQueue.take();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Write record to appropriate warehousing table
|
||||
|
||||
if (dataRecord != null) {
|
||||
|
||||
switch (dataRecord.recordType) {
|
||||
case PVP:
|
||||
pvpRecord = (PvpRecord) dataRecord;
|
||||
pvpRecord.write();
|
||||
pvpRecord.release();
|
||||
break;
|
||||
case CHARACTER:
|
||||
characterRecord = (CharacterRecord) dataRecord;
|
||||
characterRecord.write();
|
||||
characterRecord.release();
|
||||
break;
|
||||
case GUILD:
|
||||
guildRecord = (GuildRecord) dataRecord;
|
||||
guildRecord.write();
|
||||
guildRecord.release();
|
||||
break;
|
||||
case CITY:
|
||||
cityRecord = (CityRecord) dataRecord;
|
||||
cityRecord.write();
|
||||
cityRecord.release();
|
||||
break;
|
||||
case BANE:
|
||||
baneRecord = (BaneRecord) dataRecord;
|
||||
baneRecord.write();
|
||||
baneRecord.release();
|
||||
break;
|
||||
case REALM:
|
||||
realmRecord = (RealmRecord) dataRecord;
|
||||
realmRecord.write();
|
||||
realmRecord.release();
|
||||
break;
|
||||
case MINE:
|
||||
mineRecord = (MineRecord) dataRecord;
|
||||
mineRecord.write();
|
||||
mineRecord.release();
|
||||
break;
|
||||
default:
|
||||
Logger.error("Unhandled record type");
|
||||
break;
|
||||
|
||||
} // end switch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.RecordEventType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Guild;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class GuildRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<GuildRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
public static HashMap<Integer, GuildRecord> GuildRecordCache = null;
|
||||
public String guildHash;
|
||||
public int guildID;
|
||||
private Enum.RecordEventType eventType;
|
||||
private Guild guild;
|
||||
private String guildName;
|
||||
private String charterName;
|
||||
private String GLHash;
|
||||
private String guildMotto;
|
||||
private int bgIcon;
|
||||
private int bgColour1;
|
||||
private int bgColour2;
|
||||
private int fgIcon;
|
||||
private int fgColour;
|
||||
private java.time.LocalDateTime eventDatetime;
|
||||
|
||||
private GuildRecord(Guild guild) {
|
||||
this.recordType = Enum.DataRecordType.GUILD;
|
||||
this.guild = guild;
|
||||
this.eventType = Enum.RecordEventType.CREATE;
|
||||
}
|
||||
|
||||
|
||||
public GuildRecord(ResultSet rs) throws SQLException {
|
||||
super();
|
||||
this.eventType = RecordEventType.valueOf(rs.getString("eventType"));
|
||||
this.guildHash = rs.getString("guild_id");
|
||||
this.guildName = rs.getString("guild_name");
|
||||
this.charterName = rs.getString("charter");
|
||||
GLHash = rs.getString("guild_founder");
|
||||
this.guildMotto = rs.getString("guild_motto");
|
||||
this.bgIcon = rs.getInt("bgicon");
|
||||
this.bgColour1 = rs.getInt("bgcoloura");
|
||||
this.bgColour2 = rs.getInt("bgcolourb");
|
||||
this.fgIcon = rs.getInt("fgicon");
|
||||
this.fgColour = rs.getInt("fgcolour");
|
||||
|
||||
java.sql.Timestamp eventTimeStamp = rs.getTimestamp("upgradeDate");
|
||||
|
||||
if (eventTimeStamp != null)
|
||||
this.eventDatetime = LocalDateTime.ofInstant(eventTimeStamp.toInstant(), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
|
||||
public static GuildRecord borrow(Guild guild, Enum.RecordEventType eventType) {
|
||||
GuildRecord guildRecord;
|
||||
//add
|
||||
guildRecord = recordPool.poll();
|
||||
|
||||
if (guildRecord == null) {
|
||||
guildRecord = new GuildRecord(guild);
|
||||
guildRecord.eventType = eventType;
|
||||
} else {
|
||||
guildRecord.guild = guild;
|
||||
guildRecord.recordType = Enum.DataRecordType.GUILD;
|
||||
guildRecord.eventType = eventType;
|
||||
|
||||
}
|
||||
|
||||
guildRecord.guildHash = guildRecord.guild.getHash();
|
||||
guildRecord.guildID = guildRecord.guild.getObjectUUID();
|
||||
guildRecord.guildName = guildRecord.guild.getName();
|
||||
guildRecord.charterName = Enum.GuildType.getGuildTypeFromInt(guildRecord.guild.getCharter()).getCharterName();
|
||||
|
||||
guildRecord.GLHash = DataWarehouse.hasher.encrypt(guildRecord.guild.getGuildLeaderUUID());
|
||||
|
||||
guildRecord.guildMotto = guildRecord.guild.getMotto();
|
||||
guildRecord.bgIcon = guildRecord.guild.getBgDesign();
|
||||
guildRecord.bgColour1 = guildRecord.guild.getBgc1();
|
||||
guildRecord.bgColour2 = guildRecord.guild.getBgc2();
|
||||
guildRecord.fgIcon = guildRecord.guild.getSymbol();
|
||||
guildRecord.fgColour = guildRecord.guild.getSc();
|
||||
|
||||
if (guild.getOwnedCity() != null)
|
||||
guildRecord.eventDatetime = guild.getOwnedCity().established;
|
||||
else
|
||||
guildRecord.eventDatetime = LocalDateTime.now();
|
||||
|
||||
return guildRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildGuildPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_guildhistory` (`event_number`, `guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("guild_id"));
|
||||
outStatement.setString(3, rs.getString("guild_name"));
|
||||
outStatement.setString(4, rs.getString("guild_motto"));
|
||||
outStatement.setString(5, rs.getString("guild_founder"));
|
||||
outStatement.setString(6, rs.getString("charter"));
|
||||
outStatement.setInt(7, rs.getInt("bgicon"));
|
||||
outStatement.setInt(8, rs.getInt("bgcoloura"));
|
||||
outStatement.setInt(9, rs.getInt("bgcolourb"));
|
||||
outStatement.setInt(10, rs.getInt("fgicon"));
|
||||
outStatement.setInt(11, rs.getInt("fgcolour"));
|
||||
outStatement.setString(12, rs.getString("eventtype"));
|
||||
outStatement.setTimestamp(13, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildGuildQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_guildhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.guildIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
|
||||
this.guild = null;
|
||||
this.guildHash = null;
|
||||
this.GLHash = null;
|
||||
this.guildMotto = null;
|
||||
this.charterName = null;
|
||||
this.eventDatetime = null;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildGuildInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private PreparedStatement buildGuildInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_guildhistory` (`guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind character data
|
||||
|
||||
outStatement.setString(1, this.guildHash);
|
||||
outStatement.setString(2, this.guildName);
|
||||
outStatement.setString(3, this.guildMotto);
|
||||
outStatement.setString(4, this.GLHash);
|
||||
outStatement.setString(5, this.charterName);
|
||||
|
||||
outStatement.setInt(6, this.bgIcon);
|
||||
outStatement.setInt(7, this.bgColour1);
|
||||
outStatement.setInt(8, this.bgColour2);
|
||||
outStatement.setInt(9, this.fgIcon);
|
||||
outStatement.setInt(10, this.fgColour);
|
||||
outStatement.setString(11, this.eventType.name());
|
||||
outStatement.setTimestamp(12, new java.sql.Timestamp(this.eventDatetime.atZone(ZoneId.systemDefault())
|
||||
.toInstant().toEpochMilli()));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
// public static void InitializeGuildRecords(){
|
||||
// GuildRecord.GuildRecordCache = DbManager.GuildQueries.GET_WAREHOUSE_GUILD_HISTORY();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractCharacter;
|
||||
import engine.objects.Mine;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class MineRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<MineRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private Enum.RecordEventType eventType;
|
||||
private String zoneHash;
|
||||
private String charHash;
|
||||
private String mineGuildHash;
|
||||
private String mineNationHash;
|
||||
private String mineType;
|
||||
private float locX;
|
||||
private float locY;
|
||||
|
||||
private MineRecord() {
|
||||
this.recordType = Enum.DataRecordType.MINE;
|
||||
this.eventType = Enum.RecordEventType.CAPTURE;
|
||||
|
||||
}
|
||||
|
||||
public static MineRecord borrow(Mine mine, AbstractCharacter character, Enum.RecordEventType eventType) {
|
||||
|
||||
MineRecord mineRecord;
|
||||
mineRecord = recordPool.poll();
|
||||
PlayerCharacter player;
|
||||
|
||||
if (mineRecord == null) {
|
||||
mineRecord = new MineRecord();
|
||||
mineRecord.eventType = eventType;
|
||||
} else {
|
||||
mineRecord.recordType = Enum.DataRecordType.MINE;
|
||||
mineRecord.eventType = eventType;
|
||||
}
|
||||
|
||||
mineRecord.zoneHash = mine.getParentZone().getHash();
|
||||
|
||||
if (character.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) {
|
||||
player = (PlayerCharacter) character;
|
||||
mineRecord.charHash = player.getHash();
|
||||
} else
|
||||
mineRecord.charHash = character.getName();
|
||||
|
||||
DataWarehouse.hasher.encrypt(0);
|
||||
|
||||
if (mine.getOwningGuild() == null)
|
||||
mineRecord.mineGuildHash = "ERRANT";
|
||||
else
|
||||
mineRecord.mineGuildHash = mine.getOwningGuild().getHash();
|
||||
|
||||
if (mine.getOwningGuild() == null)
|
||||
mineRecord.mineNationHash = "ERRANT";
|
||||
else
|
||||
mineRecord.mineNationHash = mine.getOwningGuild().getNation().getHash();
|
||||
|
||||
mineRecord.locX = mine.getParentZone().getLoc().x;
|
||||
mineRecord.locY = -mine.getParentZone().getLoc().z;
|
||||
|
||||
mineRecord.mineType = mine.getMineType().name;
|
||||
|
||||
return mineRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildMinePushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_minehistory` (`event_number`, `zone_id`, `mine_type`, `char_id`, `mine_guildID`, `mine_nationID`, `loc_x`, `loc_y`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("zone_id"));
|
||||
outStatement.setString(3, rs.getString("char_id"));
|
||||
outStatement.setString(4, rs.getString("mine_type"));
|
||||
outStatement.setString(5, rs.getString("mine_guildID"));
|
||||
outStatement.setString(6, rs.getString("mine_nationID"));
|
||||
|
||||
outStatement.setFloat(7, rs.getFloat("loc_x"));
|
||||
outStatement.setFloat(8, rs.getFloat("loc_y"));
|
||||
outStatement.setString(9, rs.getString("eventType"));
|
||||
outStatement.setTimestamp(10, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildMineQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_minehistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.mineIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.zoneHash = null;
|
||||
this.charHash = null;
|
||||
this.mineGuildHash = null;
|
||||
this.mineNationHash = null;
|
||||
this.mineType = null;
|
||||
this.locX = 0.0f;
|
||||
this.locY = 0.0f;
|
||||
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildMineInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private PreparedStatement buildMineInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_minehistory` (`zone_id`, `mine_type`, `char_id`, `mine_guildID`, `mine_nationID`, `loc_x`, `loc_y`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind character data
|
||||
|
||||
outStatement.setString(1, this.zoneHash);
|
||||
outStatement.setString(2, this.mineType);
|
||||
outStatement.setString(3, this.charHash);
|
||||
outStatement.setString(4, this.mineGuildHash);
|
||||
outStatement.setString(5, this.mineNationHash);
|
||||
|
||||
outStatement.setFloat(6, this.locX);
|
||||
outStatement.setFloat(7, this.locY);
|
||||
outStatement.setString(8, this.eventType.name());
|
||||
outStatement.setTimestamp(9, Timestamp.valueOf(LocalDateTime.now()));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.Zone;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static engine.Enum.DataRecordType;
|
||||
import static engine.Enum.PvpHistoryType;
|
||||
|
||||
public class PvpRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<PvpRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
|
||||
private PlayerCharacter player;
|
||||
private PlayerCharacter victim;
|
||||
private Vector3fImmutable location;
|
||||
private boolean pvpExp;
|
||||
|
||||
private PvpRecord(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) {
|
||||
this.recordType = DataRecordType.PVP;
|
||||
this.player = player;
|
||||
this.victim = victim;
|
||||
this.location = new Vector3fImmutable(location);
|
||||
this.pvpExp = pvpExp;
|
||||
}
|
||||
|
||||
public static PvpRecord borrow(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) {
|
||||
|
||||
PvpRecord pvpRecord;
|
||||
|
||||
pvpRecord = recordPool.poll();
|
||||
|
||||
if (pvpRecord == null) {
|
||||
pvpRecord = new PvpRecord(player, victim, location, pvpExp);
|
||||
} else {
|
||||
pvpRecord.recordType = DataRecordType.PVP;
|
||||
pvpRecord.player = player;
|
||||
pvpRecord.victim = victim;
|
||||
pvpRecord.location = new Vector3fImmutable(location);
|
||||
pvpRecord.pvpExp = pvpExp;
|
||||
}
|
||||
|
||||
return pvpRecord;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildHistoryStatement(Connection connection, int charUUID, PvpHistoryType historyType) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "";
|
||||
|
||||
switch (historyType) {
|
||||
case KILLS:
|
||||
queryString = "SELECT DISTINCT `victim_id`, `datetime` FROM warehouse_pvphistory where char_id = ? " +
|
||||
"ORDER BY `datetime` DESC LIMIT 10";
|
||||
break;
|
||||
case DEATHS:
|
||||
queryString = "SELECT DISTINCT `char_id`,`datetime` FROM warehouse_pvphistory where `victim_id` = ? " +
|
||||
"ORDER BY `datetime` DESC LIMIT 10";
|
||||
break;
|
||||
}
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static LinkedList<Integer> getCharacterPvPHistory(int charUUID, PvpHistoryType historyType) {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
LinkedList<Integer> outList = new LinkedList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildHistoryStatement(connection, charUUID, historyType);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
switch (historyType) {
|
||||
case KILLS:
|
||||
outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("victim_id"))[0]);
|
||||
break;
|
||||
case DEATHS:
|
||||
outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("char_id"))[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return outList;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildLuaHistoryQueryStatement(Connection connection, int charUUID) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "CALL `pvpHistory`(?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static String getPvpHistoryString(int charUUID) {
|
||||
|
||||
String outString;
|
||||
String dividerString;
|
||||
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
outString = "[LUA_PVP() DATA WAREHOUSE]" + newLine;
|
||||
dividerString = "--------------------------------" + newLine;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildLuaHistoryQueryStatement(connection, charUUID);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
int killCount;
|
||||
int deathCount;
|
||||
float killRatio;
|
||||
|
||||
outString += "Total Magicbane murdered souls: " + rs.getInt("TOTALDEATHS") + newLine;
|
||||
outString += dividerString;
|
||||
outString += String.format("%-8s %-8s %-8s %-8s %n", "Period", "Kills", "Deaths", "K/D");
|
||||
outString += dividerString;
|
||||
|
||||
killCount = rs.getInt("KILLCOUNT");
|
||||
deathCount = rs.getInt("DEATHCOUNT");
|
||||
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
|
||||
try {
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "Total", killCount, deathCount, killRatio);
|
||||
|
||||
killCount = rs.getInt("DAILYKILLS");
|
||||
deathCount = rs.getInt("DAILYDEATHS");
|
||||
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "24hrs", killCount, deathCount, killRatio);
|
||||
|
||||
killCount = rs.getInt("HOURLYKILLS");
|
||||
deathCount = rs.getInt("HOURLYDEATHS");
|
||||
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "1hr", killCount, deathCount, killRatio);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return outString;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildPvpPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_pvphistory` (`event_number`, `char_id`, `char_guild_id`, `char_nation_id`, `char_level`," +
|
||||
" `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," +
|
||||
" `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " +
|
||||
" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("char_id"));
|
||||
outStatement.setString(3, rs.getString("char_guild_id"));
|
||||
outStatement.setString(4, rs.getString("char_nation_id"));
|
||||
outStatement.setInt(5, rs.getInt("char_level"));
|
||||
|
||||
// Bind victim data
|
||||
|
||||
outStatement.setString(6, rs.getString("victim_id"));
|
||||
outStatement.setString(7, rs.getString("victim_guild_id"));
|
||||
outStatement.setString(8, rs.getString("victim_nation_id"));
|
||||
outStatement.setInt(9, rs.getInt("victim_level"));
|
||||
|
||||
outStatement.setString(10, rs.getString("zone_id"));
|
||||
outStatement.setString(11, rs.getString("zone_name"));
|
||||
outStatement.setFloat(12, rs.getFloat("loc_x"));
|
||||
outStatement.setFloat(13, rs.getFloat("loc_y"));
|
||||
outStatement.setBoolean(14, rs.getBoolean("gave_exp"));
|
||||
outStatement.setTimestamp(15, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildPvpQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_pvphistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.pvpIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.player = null;
|
||||
this.victim = null;
|
||||
this.location = Vector3fImmutable.ZERO;
|
||||
pvpExp = false;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
private PreparedStatement buildPvPInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
Guild charGuild;
|
||||
Guild victimGuild;
|
||||
Zone zone;
|
||||
PreparedStatement outStatement = null;
|
||||
|
||||
String queryString = "INSERT INTO `warehouse_pvphistory` (`char_id`, `char_guild_id`, `char_nation_id`, `char_level`," +
|
||||
" `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," +
|
||||
" `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " +
|
||||
" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
charGuild = this.player.getGuild();
|
||||
victimGuild = this.victim.getGuild();
|
||||
|
||||
// Use a proxy in the situation where a char guild is null (errant)
|
||||
|
||||
|
||||
// Retrieve the zone name where the PvP event occurred
|
||||
|
||||
zone = ZoneManager.findSmallestZone(this.location);
|
||||
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(this.player.getObjectUUID()));
|
||||
outStatement.setString(2, DataWarehouse.hasher.encrypt(charGuild.getObjectUUID()));
|
||||
outStatement.setString(3, DataWarehouse.hasher.encrypt(charGuild.getNation().getObjectUUID()));
|
||||
outStatement.setInt(4, this.player.getLevel());
|
||||
|
||||
// Bind victim data
|
||||
|
||||
outStatement.setString(5, DataWarehouse.hasher.encrypt(this.victim.getObjectUUID()));
|
||||
outStatement.setString(6, DataWarehouse.hasher.encrypt(victimGuild.getObjectUUID()));
|
||||
outStatement.setString(7, DataWarehouse.hasher.encrypt(victimGuild.getNation().getObjectUUID()));
|
||||
outStatement.setInt(8, this.victim.getLevel());
|
||||
|
||||
outStatement.setString(9, DataWarehouse.hasher.encrypt(zone.getObjectUUID()));
|
||||
outStatement.setString(10, zone.getName());
|
||||
outStatement.setFloat(11, this.location.getX());
|
||||
outStatement.setFloat(12, -this.location.getZ()); // flip sign on 'y' coordinate
|
||||
outStatement.setBoolean(13, this.pvpExp);
|
||||
outStatement.setTimestamp(14, Timestamp.valueOf(LocalDateTime.now()));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildPvPInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
// Warehouse record for this pvp event written if code path reaches here.
|
||||
// Time to update the respective kill counters.
|
||||
|
||||
CharacterRecord.advanceKillCounter(this.player);
|
||||
CharacterRecord.advanceDeathCounter(this.victim);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Realm;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class RealmRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<RealmRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
|
||||
private Realm realm;
|
||||
private Enum.RecordEventType eventType;
|
||||
private String cityHash;
|
||||
private String guildHash;
|
||||
private String charterType;
|
||||
private LocalDateTime eventDateTime;
|
||||
|
||||
private RealmRecord(Realm realm) {
|
||||
this.recordType = Enum.DataRecordType.REALM;
|
||||
this.realm = realm;
|
||||
this.eventType = Enum.RecordEventType.CAPTURE;
|
||||
|
||||
}
|
||||
|
||||
public static RealmRecord borrow(Realm realm, Enum.RecordEventType eventType) {
|
||||
RealmRecord realmRecord;
|
||||
|
||||
realmRecord = recordPool.poll();
|
||||
|
||||
if (realmRecord == null) {
|
||||
realmRecord = new RealmRecord(realm);
|
||||
realmRecord.eventType = eventType;
|
||||
} else {
|
||||
realmRecord.recordType = Enum.DataRecordType.REALM;
|
||||
realmRecord.eventType = eventType;
|
||||
realmRecord.realm = realm;
|
||||
|
||||
}
|
||||
|
||||
realmRecord.cityHash = realm.getRulingCity().getHash();
|
||||
realmRecord.guildHash = realm.getRulingCity().getGuild().getHash();
|
||||
realmRecord.charterType = Enum.CharterType.getCharterTypeByID(realmRecord.realm.getCharterType()).name();
|
||||
|
||||
if (realmRecord.eventType.equals(Enum.RecordEventType.CAPTURE))
|
||||
realmRecord.eventDateTime = realm.ruledSince;
|
||||
else
|
||||
realmRecord.eventDateTime = LocalDateTime.now();
|
||||
|
||||
return realmRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildRealmPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_realmhistory` (`event_number`, `realm_id`, `realm_name`, `charter`, `city_id`, `guild_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("realm_id"));
|
||||
outStatement.setString(3, rs.getString("realm_name"));
|
||||
outStatement.setString(4, rs.getString("charter"));
|
||||
outStatement.setString(5, rs.getString("city_id"));
|
||||
outStatement.setString(6, rs.getString("guild_id"));
|
||||
outStatement.setString(7, rs.getString("eventType"));
|
||||
outStatement.setTimestamp(8, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildRealmQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_realmhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.realmIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
|
||||
this.realm = null;
|
||||
this.cityHash = null;
|
||||
this.guildHash = null;
|
||||
this.eventDateTime = null;
|
||||
this.charterType = null;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
private PreparedStatement buildRealmInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_realmhistory` (`realm_id`, `realm_name`, `charter`, `city_id`, `guild_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?)";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind Record Data
|
||||
|
||||
outStatement.setString(1, realm.getHash());
|
||||
outStatement.setString(2, realm.getRealmName());
|
||||
outStatement.setString(3, charterType);
|
||||
outStatement.setString(4, cityHash);
|
||||
outStatement.setString(5, guildHash);
|
||||
outStatement.setString(6, eventType.name());
|
||||
outStatement.setTimestamp(7, Timestamp.valueOf(this.eventDateTime));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildRealmInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Account;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbAccountHandler extends dbHandlerBase {
|
||||
|
||||
public dbAccountHandler() {
|
||||
this.localClass = Account.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Account GET_ACCOUNT(int accountID) {
|
||||
|
||||
Account account;
|
||||
|
||||
if (accountID == 0)
|
||||
return null;
|
||||
|
||||
account = (Account) DbManager.getFromCache(GameObjectType.Account, accountID);
|
||||
|
||||
if (account != null)
|
||||
return account;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, accountID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
account = (Account) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
if (account != null)
|
||||
account.runAfterLoad();
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
public void WRITE_ADMIN_LOG(String adminName, String logEntry) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_admin_log(`dateTime`, `charName`, `eventString`)"
|
||||
+ " VALUES (?, ?, ?)")) {
|
||||
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
|
||||
preparedStatement.setString(2, adminName);
|
||||
preparedStatement.setString(3, logEntry);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void SET_TRASH(String machineID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_trash(`machineID`, `count`)"
|
||||
+ " VALUES (?, 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1;")) {
|
||||
|
||||
preparedStatement.setString(1, machineID);
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> GET_TRASH_LIST() {
|
||||
|
||||
ArrayList<String> machineList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("select `machineID` from `dyn_trash`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
machineList.add(rs.getString(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return machineList;
|
||||
}
|
||||
|
||||
public void DELETE_VAULT_FOR_ACCOUNT(final int accountID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `parent`=? && `type`='item'")) {
|
||||
|
||||
preparedStatement.setLong(1, accountID);
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<PlayerCharacter> GET_ALL_CHARS_FOR_MACHINE(String machineID) {
|
||||
|
||||
ArrayList<PlayerCharacter> trashList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("select DISTINCT UID from object \n" +
|
||||
"where parent IN (select AccountID from dyn_login_history " +
|
||||
" WHERE`machineID`=?)")) {
|
||||
|
||||
preparedStatement.setString(1, machineID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
PlayerCharacter trashPlayer;
|
||||
int playerID;
|
||||
|
||||
playerID = rs.getInt(1);
|
||||
trashPlayer = PlayerCharacter.getPlayerCharacter(playerID);
|
||||
|
||||
if (trashPlayer == null)
|
||||
continue;
|
||||
|
||||
if (trashPlayer.isDeleted() == false)
|
||||
trashList.add(trashPlayer);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return trashList;
|
||||
}
|
||||
|
||||
public void CLEAR_TRASH_TABLE() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM dyn_trash")) {
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void CREATE_SINGLE(String accountName, String password) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL singleAccountCreate(?,?)")) {
|
||||
|
||||
preparedStatement.setString(1, accountName);
|
||||
preparedStatement.setString(2, password);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Account GET_ACCOUNT(String uname) {
|
||||
|
||||
Account account = null;
|
||||
|
||||
if (Account.AccountsMap.get(uname) != null)
|
||||
return this.GET_ACCOUNT(Account.AccountsMap.get(uname));
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `acct_uname`=?")) {
|
||||
|
||||
preparedStatement.setString(1, uname);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
account = (Account) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
account.runAfterLoad();
|
||||
|
||||
if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER))
|
||||
Account.AccountsMap.put(uname, account.getObjectUUID());
|
||||
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
public void SET_ACCOUNT_LOGIN(final Account acc, String playerName, final String ip, final String machineID) {
|
||||
|
||||
if (acc.getObjectUUID() == 0 || ip == null || ip.length() == 0)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_login_history(`AccountID`, `accountName`, `characterName`, `ip`, `machineID`, `timeStamp`)"
|
||||
+ " VALUES (?, ?, ?, ?, ?, ?)")) {
|
||||
|
||||
preparedStatement.setInt(1, acc.getObjectUUID());
|
||||
preparedStatement.setString(2, acc.getUname());
|
||||
preparedStatement.setString(3, playerName);
|
||||
preparedStatement.setString(4, ip);
|
||||
preparedStatement.setString(5, machineID);
|
||||
preparedStatement.setTimestamp(6, new java.sql.Timestamp(System.currentTimeMillis()));
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDatabase(final Account acc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_account` SET `acct_passwd`=?, "
|
||||
+ " `acct_lastCharUID`=?, `acct_salt`=?, `discordAccount`=?, " +
|
||||
" status = ? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, acc.getPasswd());
|
||||
preparedStatement.setInt(2, acc.getLastCharIDUsed());
|
||||
preparedStatement.setString(3, acc.getSalt());
|
||||
preparedStatement.setString(4, acc.discordAccount);
|
||||
preparedStatement.setString(5, acc.status.name());
|
||||
preparedStatement.setInt(6, acc.getObjectUUID());
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void INVALIDATE_LOGIN_CACHE(long accountUID, String objectType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT IGNORE INTO login_cachelist (`UID`, `type`) VALUES(?,?);")) {
|
||||
|
||||
preparedStatement.setLong(1, accountUID);
|
||||
preparedStatement.setString(2, objectType);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Bane;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.City;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbBaneHandler extends dbHandlerBase {
|
||||
|
||||
public dbBaneHandler() {
|
||||
|
||||
}
|
||||
|
||||
public boolean CREATE_BANE(City city, PlayerCharacter owner, Building stone) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_banes` (`cityUUID`, `ownerUUID`, `stoneUUID`, `placementDate`) VALUES(?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, city.getObjectUUID());
|
||||
preparedStatement.setLong(2, owner.getObjectUUID());
|
||||
preparedStatement.setLong(3, stone.getObjectUUID());
|
||||
preparedStatement.setTimestamp(4, new java.sql.Timestamp(System.currentTimeMillis()));
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Bane LOAD_BANE(int cityUUID) {
|
||||
|
||||
Bane bane = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * from dyn_banes WHERE `dyn_banes`.`cityUUID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, cityUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
bane = new Bane(rs);
|
||||
Bane.addBane(bane);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return bane;
|
||||
}
|
||||
|
||||
|
||||
public boolean SET_BANE_TIME(DateTime toSet, int cityUUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `liveDate`=? WHERE `cityUUID`=?")) {
|
||||
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(toSet.getMillis()));
|
||||
preparedStatement.setLong(2, cityUUID);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean REMOVE_BANE(Bane bane) {
|
||||
|
||||
if (bane == null)
|
||||
return false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_banes` WHERE `cityUUID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, bane.getCity().getObjectUUID());
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.BaseClass;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbBaseClassHandler extends dbHandlerBase {
|
||||
|
||||
public dbBaseClassHandler() {
|
||||
this.localClass = BaseClass.class;
|
||||
this.localObjectType = Enum.GameObjectType.BaseClass;
|
||||
}
|
||||
|
||||
public BaseClass GET_BASE_CLASS(final int id) {
|
||||
|
||||
if (id == 0)
|
||||
return null;
|
||||
|
||||
BaseClass baseClass = (BaseClass) DbManager.getFromCache(GameObjectType.BaseClass, id);
|
||||
|
||||
if (baseClass != null)
|
||||
return baseClass;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
baseClass = (BaseClass) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return baseClass;
|
||||
}
|
||||
|
||||
public ArrayList<BaseClass> GET_BASECLASS_FOR_RACE(final int id) {
|
||||
|
||||
ArrayList<BaseClass> baseClasses = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT b.* FROM `static_rune_baseclass` b, `static_rune_racebaseclass` r WHERE b.`ID` = r.`BaseClassID` && r.`RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
baseClasses = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return baseClasses;
|
||||
}
|
||||
|
||||
public ArrayList<BaseClass> GET_ALL_BASE_CLASSES() {
|
||||
|
||||
ArrayList<BaseClass> baseClasses = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseclass`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
baseClasses = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return baseClasses;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Blueprint;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbBlueprintHandler extends dbHandlerBase {
|
||||
|
||||
public dbBlueprintHandler() {
|
||||
|
||||
}
|
||||
|
||||
public HashMap<Integer, Integer> LOAD_ALL_DOOR_NUMBERS() {
|
||||
|
||||
HashMap<Integer, Integer> doorInfo;
|
||||
doorInfo = new HashMap<>();
|
||||
|
||||
int doorUUID;
|
||||
int doorNum;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_building_doors ORDER BY doorMeshUUID ASC")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
doorUUID = rs.getInt("doorMeshUUID");
|
||||
doorNum = rs.getInt("doorNumber");
|
||||
doorInfo.put(doorUUID, doorNum);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + doorInfo.size());
|
||||
return doorInfo;
|
||||
}
|
||||
|
||||
public HashMap<Integer, Blueprint> LOAD_ALL_BLUEPRINTS() {
|
||||
|
||||
HashMap<Integer, Blueprint> blueprints;
|
||||
Blueprint thisBlueprint;
|
||||
|
||||
blueprints = new HashMap<>();
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_building_blueprint")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
thisBlueprint = new Blueprint(rs);
|
||||
|
||||
blueprints.put(thisBlueprint.getBlueprintUUID(), thisBlueprint);
|
||||
|
||||
// load mesh cache
|
||||
Blueprint._meshLookup.putIfAbsent(thisBlueprint.getMeshForRank(-1), thisBlueprint);
|
||||
Blueprint._meshLookup.putIfAbsent(thisBlueprint.getMeshForRank(0), thisBlueprint);
|
||||
Blueprint._meshLookup.putIfAbsent(thisBlueprint.getMeshForRank(1), thisBlueprint);
|
||||
Blueprint._meshLookup.putIfAbsent(thisBlueprint.getMeshForRank(3), thisBlueprint);
|
||||
Blueprint._meshLookup.putIfAbsent(thisBlueprint.getMeshForRank(7), thisBlueprint);
|
||||
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + blueprints.size());
|
||||
return blueprints;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Boon;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbBoonHandler extends dbHandlerBase {
|
||||
|
||||
public dbBoonHandler() {
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Boon> GET_BOON_AMOUNTS_FOR_ITEMBASE(int itemBaseUUID) {
|
||||
|
||||
ArrayList<Boon> boons = new ArrayList<>();
|
||||
Boon thisBoon;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_boons` WHERE `itemBaseID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, itemBaseUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
thisBoon = new Boon(rs);
|
||||
boons.add(thisBoon);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return boons;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,855 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DbObjectType;
|
||||
import engine.Enum.ProtectionState;
|
||||
import engine.Enum.TaxType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.*;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbBuildingHandler extends dbHandlerBase {
|
||||
|
||||
public dbBuildingHandler() {
|
||||
this.localClass = Building.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Building CREATE_BUILDING(int parentZoneID, int OwnerUUID, String name, int meshUUID,
|
||||
Vector3fImmutable location, float meshScale, int currentHP,
|
||||
ProtectionState protectionState, int currentGold, int rank,
|
||||
DateTime upgradeDate, int blueprintUUID, float w, float rotY) {
|
||||
|
||||
Building building = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `building_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?);")) {
|
||||
|
||||
preparedStatement.setInt(1, parentZoneID);
|
||||
preparedStatement.setInt(2, OwnerUUID);
|
||||
preparedStatement.setString(3, name);
|
||||
preparedStatement.setInt(4, meshUUID);
|
||||
preparedStatement.setFloat(5, location.x);
|
||||
preparedStatement.setFloat(6, location.y);
|
||||
preparedStatement.setFloat(7, location.z);
|
||||
preparedStatement.setFloat(8, meshScale);
|
||||
preparedStatement.setInt(9, currentHP);
|
||||
preparedStatement.setString(10, protectionState.name());
|
||||
preparedStatement.setInt(11, currentGold);
|
||||
preparedStatement.setInt(12, rank);
|
||||
|
||||
if (upgradeDate != null)
|
||||
preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis()));
|
||||
else
|
||||
preparedStatement.setNull(13, java.sql.Types.DATE);
|
||||
|
||||
preparedStatement.setInt(14, blueprintUUID);
|
||||
preparedStatement.setFloat(15, w);
|
||||
preparedStatement.setFloat(16, rotY);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
building = GET_BUILDINGBYUUID(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return building;
|
||||
}
|
||||
|
||||
public boolean DELETE_FROM_DATABASE(final Building b) {
|
||||
|
||||
return removeFromBuildings(b);
|
||||
}
|
||||
|
||||
public ArrayList<Building> GET_ALL_BUILDINGS_FOR_ZONE(Zone zone) {
|
||||
|
||||
ArrayList<Building> buildings = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, zone.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
buildings = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return buildings;
|
||||
}
|
||||
|
||||
public Building GET_BUILDINGBYUUID(int uuid) {
|
||||
|
||||
if (uuid == 0)
|
||||
return null;
|
||||
|
||||
Building building = (Building) DbManager.getFromCache(Enum.GameObjectType.Building, uuid);
|
||||
|
||||
if (building != null)
|
||||
return building;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, uuid);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
building = (Building) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return building;
|
||||
}
|
||||
|
||||
public Building GET_BUILDING_BY_MESH(final int meshID) {
|
||||
|
||||
Building building = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL building_GETBYMESH(?)")) {
|
||||
|
||||
preparedStatement.setInt(1, meshID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
building = new Building(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Building", e);
|
||||
}
|
||||
|
||||
return building;
|
||||
}
|
||||
|
||||
public String SET_PROPERTY(final Building b, String name, Object new_value) {
|
||||
|
||||
String result = "";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL building_SETPROP(?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, b.getObjectUUID());
|
||||
preparedStatement.setString(2, name);
|
||||
preparedStatement.setString(3, String.valueOf(new_value));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
result = rs.getString("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int MOVE_BUILDING(long buildingID, long parentID, float locX, float locY, float locZ) {
|
||||
|
||||
int rowCount;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` INNER JOIN `obj_building` On `object`.`UID` = `obj_building`.`UID` SET `object`.`parent`=?, `obj_building`.`locationX`=?, `obj_building`.`locationY`=?, `obj_building`.`locationZ`=? WHERE `obj_building`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, parentID);
|
||||
preparedStatement.setFloat(2, locX);
|
||||
preparedStatement.setFloat(3, locY);
|
||||
preparedStatement.setFloat(4, locZ);
|
||||
preparedStatement.setLong(5, buildingID);
|
||||
|
||||
rowCount = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
private boolean removeFromBuildings(final Building b) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, b.getObjectUUID());
|
||||
preparedStatement.execute();
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CHANGE_NAME(Building b, String newName) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `name`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, newName);
|
||||
preparedStatement.setLong(2, b.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_RESERVE(Building b, int reserveAmount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `reserve`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, reserveAmount);
|
||||
preparedStatement.setLong(2, b.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//CAS update to rank
|
||||
public boolean CHANGE_RANK(final long buildingID, int newRank) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `rank`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, newRank);
|
||||
preparedStatement.setLong(2, buildingID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_BUILDING_HEALTH(final long buildingID, int NewHealth) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `currentHP`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, NewHealth);
|
||||
preparedStatement.setLong(2, buildingID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_BUILDING_ALTITUDE(final long buildingID, float newAltitude) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `locationY`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setFloat(1, newAltitude);
|
||||
preparedStatement.setLong(2, buildingID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_PROTECTIONSTATE(final long buildingUUID, ProtectionState protectionState) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `protectionState`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, protectionState.name());
|
||||
preparedStatement.setLong(2, buildingUUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_DOOR_LOCK(final int buildingUUID, int doorFlags) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET doorState = ? WHERE UID = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, doorFlags);
|
||||
preparedStatement.setInt(2, buildingUUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ADD_TO_FRIENDS_LIST(final long buildingID, final long friendID, final long guildID, final int friendType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_building_friends` (`buildingUID`, `playerUID`,`guildUID`, `friendType`) VALUES (?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
preparedStatement.setLong(2, friendID);
|
||||
preparedStatement.setLong(3, guildID);
|
||||
preparedStatement.setInt(4, friendType);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_FRIENDS_LIST(final long buildingID, long friendID, long guildID, int friendType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_friends` WHERE `buildingUID`=? AND `playerUID`=? AND `guildUID` =? AND `friendType` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
preparedStatement.setLong(2, friendID);
|
||||
preparedStatement.setLong(3, guildID);
|
||||
preparedStatement.setInt(4, friendType);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_CONDEMNED_LIST(final long buildingID, long friendID, long guildID, int friendType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_condemned` WHERE `buildingUID`=? AND `playerUID`=? AND `guildUID` =? AND `friendType` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
preparedStatement.setLong(2, friendID);
|
||||
preparedStatement.setLong(3, guildID);
|
||||
preparedStatement.setInt(4, friendType);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CLEAR_FRIENDS_LIST(final long buildingID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_friends` WHERE `buildingUID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void CLEAR_CONDEMNED_LIST(final long buildingID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_condemned` WHERE `buildingUID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean CLEAR_PATROL(final long buildingID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_patrol_points` WHERE `buildingUID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void LOAD_ALL_FRIENDS_FOR_BUILDING(Building building) {
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_friends` WHERE `buildingUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, building.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
BuildingFriends friend = new BuildingFriends(rs);
|
||||
switch (friend.getFriendType()) {
|
||||
case 7:
|
||||
building.getFriends().put(friend.getPlayerUID(), friend);
|
||||
break;
|
||||
case 8:
|
||||
case 9:
|
||||
building.getFriends().put(friend.getGuildUID(), friend);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_ALL_CONDEMNED_FOR_BUILDING(Building building) {
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_condemned` WHERE `buildingUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, building.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Condemned condemned = new Condemned(rs);
|
||||
switch (condemned.getFriendType()) {
|
||||
case 2:
|
||||
building.getCondemned().put(condemned.getPlayerUID(), condemned);
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
building.getCondemned().put(condemned.getGuildUID(), condemned);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Vector3fImmutable> LOAD_PATROL_POINTS(Building building) {
|
||||
|
||||
if (building == null)
|
||||
return null;
|
||||
|
||||
ArrayList<Vector3fImmutable> patrolPoints = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_patrol_points` WHERE `buildingUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, building.getObjectUUID());
|
||||
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
float x1 = rs.getFloat("patrolX");
|
||||
float y1 = rs.getFloat("patrolY");
|
||||
float z1 = rs.getFloat("patrolZ");
|
||||
Vector3fImmutable patrolPoint = new Vector3fImmutable(x1, y1, z1);
|
||||
patrolPoints.add(patrolPoint);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return patrolPoints;
|
||||
|
||||
}
|
||||
|
||||
public boolean ADD_TO_CONDEMNLIST(final long parentUID, final long playerUID, final long guildID, final int friendType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_building_condemned` (`buildingUID`, `playerUID`,`guildUID`, `friendType`) VALUES (?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, parentUID);
|
||||
preparedStatement.setLong(2, playerUID);
|
||||
preparedStatement.setLong(3, guildID);
|
||||
preparedStatement.setInt(4, friendType);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ADD_TO_PATROL(final long parentUID, final Vector3fImmutable patrolPoint) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_building_patrol_points` (`buildingUID`, `patrolX`,`patrolY`, `patrolZ`) VALUES (?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, parentUID);
|
||||
preparedStatement.setFloat(2, (int) patrolPoint.x);
|
||||
preparedStatement.setFloat(3, (int) patrolPoint.y);
|
||||
preparedStatement.setFloat(4, (int) patrolPoint.z);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<BuildingRegions>> LOAD_BUILDING_REGIONS() {
|
||||
|
||||
HashMap<Integer, ArrayList<BuildingRegions>> regionList = new HashMap<>();
|
||||
BuildingRegions buildingRegions;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_building_regions")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
buildingRegions = new BuildingRegions(rs);
|
||||
|
||||
if (regionList.get(buildingRegions.getBuildingID()) == null) {
|
||||
ArrayList<BuildingRegions> regionsList = new ArrayList<>();
|
||||
regionsList.add(buildingRegions);
|
||||
regionList.put(buildingRegions.getBuildingID(), regionsList);
|
||||
} else {
|
||||
ArrayList<BuildingRegions> regionsList = regionList.get(buildingRegions.getBuildingID());
|
||||
regionsList.add(buildingRegions);
|
||||
regionList.put(buildingRegions.getBuildingID(), regionsList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + regionList.size());
|
||||
return regionList;
|
||||
}
|
||||
|
||||
public HashMap<Integer, MeshBounds> LOAD_MESH_BOUNDS() {
|
||||
|
||||
HashMap<Integer, MeshBounds> meshBoundsMap = new HashMap<>();
|
||||
MeshBounds meshBounds;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_mesh_bounds")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
recordsRead++;
|
||||
meshBounds = new MeshBounds(rs);
|
||||
meshBoundsMap.put(meshBounds.meshID, meshBounds);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + meshBoundsMap.size());
|
||||
return meshBoundsMap;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<StaticColliders>> LOAD_ALL_STATIC_COLLIDERS() {
|
||||
|
||||
HashMap<Integer, ArrayList<StaticColliders>> colliders = new HashMap<>();
|
||||
StaticColliders thisColliders;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_building_colliders")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
thisColliders = new StaticColliders(rs);
|
||||
|
||||
if (colliders.get(thisColliders.getMeshID()) == null) {
|
||||
ArrayList<StaticColliders> colliderList = new ArrayList<>();
|
||||
colliderList.add(thisColliders);
|
||||
colliders.put(thisColliders.getMeshID(), colliderList);
|
||||
} else {
|
||||
ArrayList<StaticColliders> colliderList = colliders.get(thisColliders.getMeshID());
|
||||
colliderList.add(thisColliders);
|
||||
colliders.put(thisColliders.getMeshID(), colliderList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + colliders.size());
|
||||
return colliders;
|
||||
}
|
||||
|
||||
// This public class inserted here as it's a generic utility function
|
||||
// with no other good place for it. If you find a good home for it
|
||||
// feel free to move it. -
|
||||
|
||||
public final DbObjectType GET_UID_ENUM(long object_UID) {
|
||||
|
||||
DbObjectType objectType = DbObjectType.INVALID;
|
||||
String typeString = "INVALID";
|
||||
|
||||
if (object_UID == 0)
|
||||
return objectType;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `type` FROM `object` WHERE `object`.`UID` = ? LIMIT 1;")) {
|
||||
|
||||
preparedStatement.setLong(1, object_UID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
typeString = rs.getString("type").toUpperCase();
|
||||
objectType = DbObjectType.valueOf(typeString);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return DbObjectType.INVALID;
|
||||
}
|
||||
|
||||
return objectType;
|
||||
}
|
||||
|
||||
public boolean updateBuildingRank(final Building b, int Rank) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `rank`=?,"
|
||||
+ "`upgradeDate`=?, `meshUUID`=?, `currentHP`=? "
|
||||
+ "WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, Rank);
|
||||
preparedStatement.setNull(2, java.sql.Types.DATE);
|
||||
preparedStatement.setInt(3, b.getBlueprint().getMeshForRank(Rank));
|
||||
preparedStatement.setInt(4, b.getBlueprint().getMaxHealth(Rank));
|
||||
preparedStatement.setInt(5, b.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateReverseKOS(final Building b, boolean reverse) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `reverseKOS`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, reverse);
|
||||
preparedStatement.setInt(2, b.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateActiveCondemn(final Condemned condemn, boolean active) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_building_condemned` SET `active`=? "
|
||||
+ "WHERE`buildingUID` = ? AND `playerUID` = ? AND `guildUID` = ? AND `friendType` = ?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, active);
|
||||
preparedStatement.setInt(2, condemn.getParent());
|
||||
preparedStatement.setInt(3, condemn.getPlayerUID());
|
||||
preparedStatement.setInt(4, condemn.getGuildUID());
|
||||
preparedStatement.setInt(5, condemn.getFriendType());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateBuildingOwner(final Building building, int ownerUUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `ownerUUID`=? "
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, ownerUUID);
|
||||
preparedStatement.setInt(2, building.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateBuildingUpgradeTime(LocalDateTime upgradeDateTime, Building toUpgrade, int costToUpgrade) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET upgradeDate=?, currentGold=? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
if (upgradeDateTime == null)
|
||||
preparedStatement.setNull(1, java.sql.Types.DATE);
|
||||
else
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.atZone(ZoneId.systemDefault())
|
||||
.toInstant().toEpochMilli()));
|
||||
|
||||
preparedStatement.setInt(2, toUpgrade.getStrongboxValue() - costToUpgrade);
|
||||
preparedStatement.setInt(3, toUpgrade.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateMaintDate(Building building) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET maintDate=? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
if (building.maintDateTime == null)
|
||||
preparedStatement.setNull(1, java.sql.Types.DATE);
|
||||
else
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(building.maintDateTime.atZone(ZoneId.systemDefault())
|
||||
.toInstant().toEpochMilli()));
|
||||
preparedStatement.setInt(2, building.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addTaxes(Building building, TaxType taxType, int amount, boolean enforceKOS) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET taxType=?, taxAmount = ?, enforceKOS = ? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
preparedStatement.setString(1, taxType.name());
|
||||
preparedStatement.setInt(2, amount);
|
||||
preparedStatement.setBoolean(3, enforceKOS);
|
||||
preparedStatement.setInt(4, building.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeTaxes(Building building) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET taxType=?, taxAmount = ?, enforceKOS = ?, taxDate = ? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
preparedStatement.setString(1, TaxType.NONE.name());
|
||||
preparedStatement.setInt(2, 0);
|
||||
preparedStatement.setBoolean(3, false);
|
||||
preparedStatement.setNull(4, java.sql.Types.DATE);
|
||||
preparedStatement.setInt(5, building.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean acceptTaxes(Building building) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET taxDate=? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(DateTime.now().plusDays(7).getMillis()));
|
||||
preparedStatement.setInt(2, building.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.BuildingLocation;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbBuildingLocationHandler extends dbHandlerBase {
|
||||
|
||||
public dbBuildingLocationHandler() {
|
||||
this.localClass = BuildingLocation.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<BuildingLocation> LOAD_BUILDING_LOCATIONS() {
|
||||
|
||||
ArrayList<BuildingLocation> buildingLocations = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("select `ID`, `BuildingID`, `type`, `slot`, `unknown`, `locX`, `locY`, `locZ`, `w`, `rotX`, `rotY`, `rotZ` from static_building_location " +
|
||||
"where type = 6 or type = 8 " +
|
||||
"GROUP BY buildingID, slot " +
|
||||
"ORDER BY buildingID, slot ASC;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
buildingLocations = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return buildingLocations;
|
||||
}
|
||||
|
||||
return buildingLocations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Account;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.session.CSSession;
|
||||
import engine.util.StringUtils;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbCSSessionHandler extends dbHandlerBase {
|
||||
|
||||
public dbCSSessionHandler() {
|
||||
this.localClass = CSSession.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public boolean ADD_CSSESSION(String secKey, Account acc, InetAddress inet, String machineID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_session` (`secretKey`, `accountID`, `discordAccount`, `sessionIP`, machineID) VALUES (?,?,?,INET_ATON(?),?)")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
preparedStatement.setLong(2, acc.getObjectUUID());
|
||||
preparedStatement.setString(3, acc.discordAccount);
|
||||
preparedStatement.setString(4, StringUtils.InetAddressToClientString(inet));
|
||||
preparedStatement.setString(5, machineID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean DELETE_UNUSED_CSSESSION(String secKey) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=? && `characterID` IS NULL")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean DELETE_CSSESSION(String secKey) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=?")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_CSSESSION(String secKey, int charID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_session` SET `characterID`=? WHERE `secretKey`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, charID);
|
||||
preparedStatement.setString(2, secKey);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CSSession GET_CSSESSION(String secKey) {
|
||||
|
||||
CSSession css = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `accountID`, `characterID`, `machineID` FROM `dyn_session` WHERE `secretKey`=?")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
css = new CSSession(secKey, DbManager.AccountQueries.GET_ACCOUNT(rs.getInt("accountID")), PlayerCharacter.getPlayerCharacter(rs.getInt("characterID")), rs.getString("machineID"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return css;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.CharacterPower;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbCharacterPowerHandler extends dbHandlerBase {
|
||||
|
||||
public dbCharacterPowerHandler() {
|
||||
this.localClass = CharacterPower.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public CharacterPower ADD_CHARACTER_POWER(CharacterPower toAdd) {
|
||||
|
||||
CharacterPower characterPower = null;
|
||||
|
||||
if (CharacterPower.getOwner(toAdd) == null || toAdd.getPower() == null) {
|
||||
Logger.error("dbCharacterSkillHandler.ADD_Power", toAdd.getObjectUUID() + " missing owner or powersBase");
|
||||
return null;
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_power` (`CharacterID`, `powersBaseToken`, `trains`) VALUES (?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) {
|
||||
|
||||
preparedStatement.setLong(1, CharacterPower.getOwner(toAdd).getObjectUUID());
|
||||
preparedStatement.setInt(2, toAdd.getPower().getToken());
|
||||
preparedStatement.setInt(3, toAdd.getTrains());
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
ResultSet rs = preparedStatement.getGeneratedKeys();
|
||||
|
||||
if (rs.next())
|
||||
characterPower = GET_CHARACTER_POWER(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
return characterPower;
|
||||
}
|
||||
|
||||
public int DELETE_CHARACTER_POWER(final int objectUUID) {
|
||||
|
||||
int rowCount = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_power` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
rowCount = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public CharacterPower GET_CHARACTER_POWER(int objectUUID) {
|
||||
|
||||
CharacterPower characterPower = (CharacterPower) DbManager.getFromCache(Enum.GameObjectType.CharacterPower, objectUUID);
|
||||
|
||||
if (characterPower != null)
|
||||
return characterPower;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
characterPower = (CharacterPower) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterPower;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<Integer, CharacterPower> GET_POWERS_FOR_CHARACTER(PlayerCharacter pc) {
|
||||
|
||||
ConcurrentHashMap<Integer, CharacterPower> powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
int objectUUID = pc.getObjectUUID();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE CharacterID = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
CharacterPower cp = new CharacterPower(rs, pc);
|
||||
if (cp.getPower() != null)
|
||||
powers.put(cp.getPower().getToken(), cp);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return powers;
|
||||
}
|
||||
|
||||
public void UPDATE_TRAINS(final CharacterPower characterPower) {
|
||||
|
||||
//skip update if nothing changed
|
||||
|
||||
if (!characterPower.isTrained())
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `trains`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setShort(1, (short) characterPower.getTrains());
|
||||
preparedStatement.setInt(2, characterPower.getObjectUUID());
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
characterPower.setTrained(false);
|
||||
}
|
||||
|
||||
public void updateDatabase(final CharacterPower pow) {
|
||||
|
||||
if (pow.getPower() == null) {
|
||||
Logger.error("Failed to find powersBase for Power " + pow.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
if (CharacterPower.getOwner(pow) == null) {
|
||||
Logger.error("Failed to find owner for Power " + pow.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `PowersBaseToken`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, pow.getPower().getToken());
|
||||
preparedStatement.setInt(2, CharacterPower.getOwner(pow).getObjectUUID());
|
||||
preparedStatement.setShort(3, (short) pow.getTrains());
|
||||
preparedStatement.setInt(4, pow.getObjectUUID());
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
pow.setTrained(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.CharacterRune;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbCharacterRuneHandler extends dbHandlerBase {
|
||||
|
||||
public dbCharacterRuneHandler() {
|
||||
this.localClass = CharacterRune.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public CharacterRune ADD_CHARACTER_RUNE(final CharacterRune toAdd) {
|
||||
|
||||
CharacterRune characterRune = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_rune` (`CharacterID`, `RuneBaseID`) VALUES (?, ?);", Statement.RETURN_GENERATED_KEYS)) {
|
||||
|
||||
preparedStatement.setLong(1, toAdd.getPlayerID());
|
||||
preparedStatement.setInt(2, toAdd.getRuneBaseID());
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
ResultSet rs = preparedStatement.getGeneratedKeys();
|
||||
|
||||
if (rs.next())
|
||||
characterRune = GET_CHARACTER_RUNE(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterRune;
|
||||
}
|
||||
|
||||
public CharacterRune GET_CHARACTER_RUNE(int runeID) {
|
||||
|
||||
CharacterRune characterRune = (CharacterRune) DbManager.getFromCache(Enum.GameObjectType.CharacterRune, runeID);
|
||||
|
||||
if (characterRune != null)
|
||||
return characterRune;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, runeID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
characterRune = (CharacterRune) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterRune;
|
||||
}
|
||||
|
||||
public boolean DELETE_CHARACTER_RUNE(final CharacterRune characterRune) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_rune` WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, characterRune.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ArrayList<CharacterRune> GET_RUNES_FOR_CHARACTER(final int characterId) {
|
||||
|
||||
ArrayList<CharacterRune> characterRunes = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `CharacterID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, characterId);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
characterRunes = getObjectsFromRs(rs, 10);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return characterRunes;
|
||||
}
|
||||
|
||||
public void updateDatabase(final CharacterRune characterRune) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_rune` SET `CharacterID`=?, `RuneBaseID`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, characterRune.getPlayerID());
|
||||
preparedStatement.setInt(2, characterRune.getRuneBaseID());
|
||||
preparedStatement.setLong(3, characterRune.getObjectUUID());
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractCharacter;
|
||||
import engine.objects.CharacterSkill;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbCharacterSkillHandler extends dbHandlerBase {
|
||||
|
||||
public dbCharacterSkillHandler() {
|
||||
this.localClass = CharacterSkill.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public CharacterSkill ADD_SKILL(CharacterSkill toAdd) {
|
||||
|
||||
CharacterSkill characterSkill = null;
|
||||
|
||||
if (CharacterSkill.GetOwner(toAdd) == null || toAdd.getSkillsBase() == null) {
|
||||
Logger.error("dbCharacterSkillHandler.ADD_SKILL", toAdd.getObjectUUID() + " missing owner or skillsBase");
|
||||
return null;
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_skill` (`CharacterID`, `skillsBaseID`, `trains`) VALUES (?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) {
|
||||
|
||||
preparedStatement.setLong(1, CharacterSkill.GetOwner(toAdd).getObjectUUID());
|
||||
preparedStatement.setInt(2, toAdd.getSkillsBase().getObjectUUID());
|
||||
preparedStatement.setInt(3, toAdd.getNumTrains());
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
ResultSet rs = preparedStatement.getGeneratedKeys();
|
||||
|
||||
if (rs.next())
|
||||
characterSkill = GET_SKILL(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return characterSkill;
|
||||
}
|
||||
|
||||
public boolean DELETE_SKILL(final int objectUUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_skill` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CharacterSkill GET_SKILL(final int objectUUID) {
|
||||
|
||||
CharacterSkill characterSkill = (CharacterSkill) DbManager.getFromCache(Enum.GameObjectType.CharacterSkill, objectUUID);
|
||||
|
||||
if (characterSkill != null)
|
||||
return characterSkill;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
characterSkill = (CharacterSkill) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return characterSkill;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, CharacterSkill> GET_SKILLS_FOR_CHARACTER(final AbstractCharacter ac) {
|
||||
|
||||
ConcurrentHashMap<String, CharacterSkill> characterSkills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
if (ac == null || (!(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))))
|
||||
return characterSkills;
|
||||
|
||||
PlayerCharacter playerCharacter = (PlayerCharacter) ac;
|
||||
int characterId = playerCharacter.getObjectUUID();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `CharacterID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, characterId);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
CharacterSkill cs = new CharacterSkill(rs, playerCharacter);
|
||||
if (cs.getSkillsBase() != null)
|
||||
characterSkills.put(cs.getSkillsBase().getName(), cs);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterSkills;
|
||||
}
|
||||
|
||||
|
||||
public void UPDATE_TRAINS(final CharacterSkill characterSkill) {
|
||||
|
||||
if (!characterSkill.isTrained())
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `trains`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setShort(1, (short) characterSkill.getNumTrains());
|
||||
preparedStatement.setLong(2, characterSkill.getObjectUUID());
|
||||
|
||||
if (preparedStatement.executeUpdate() != 0)
|
||||
characterSkill.syncTrains();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDatabase(final CharacterSkill characterSkill) {
|
||||
|
||||
if (characterSkill.getSkillsBase() == null) {
|
||||
Logger.error("Failed to find skillsBase for Skill " + characterSkill.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
if (CharacterSkill.GetOwner(characterSkill) == null) {
|
||||
Logger.error("Failed to find owner for Skill " + characterSkill.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `skillsBaseID`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, characterSkill.getSkillsBase().getObjectUUID());
|
||||
preparedStatement.setInt(2, CharacterSkill.GetOwner(characterSkill).getObjectUUID());
|
||||
preparedStatement.setShort(3, (short) characterSkill.getNumTrains());
|
||||
preparedStatement.setLong(4, characterSkill.getObjectUUID());
|
||||
|
||||
if (preparedStatement.executeUpdate() != 0)
|
||||
characterSkill.syncTrains();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.City;
|
||||
import engine.objects.Zone;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbCityHandler extends dbHandlerBase {
|
||||
|
||||
public dbCityHandler() {
|
||||
this.localClass = City.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException {
|
||||
String type = rs.getString("type");
|
||||
switch (type) {
|
||||
case "zone":
|
||||
Zone zone = new Zone(rs);
|
||||
DbManager.addToCache(zone);
|
||||
list.add(zone);
|
||||
break;
|
||||
case "building":
|
||||
Building building = new Building(rs);
|
||||
DbManager.addToCache(building);
|
||||
list.add(building);
|
||||
break;
|
||||
case "city":
|
||||
City city = new City(rs);
|
||||
DbManager.addToCache(city);
|
||||
list.add(city);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<AbstractGameObject> CREATE_CITY(int ownerID, int parentZoneID, int realmID, float xCoord, float yCoord, float zCoord, float rotation, float W, String name, LocalDateTime established) {
|
||||
|
||||
LocalDateTime upgradeTime = LocalDateTime.now().plusHours(2);
|
||||
ArrayList<AbstractGameObject> objectList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `city_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, ownerID); //objectUUID of owning player
|
||||
preparedStatement.setLong(2, parentZoneID); //objectUUID of parent (continent) zone
|
||||
preparedStatement.setLong(3, realmID); //objectUUID of realm city belongs in
|
||||
preparedStatement.setFloat(4, xCoord); //xOffset from parentZone center
|
||||
preparedStatement.setFloat(5, yCoord); //yOffset from parentZone center
|
||||
preparedStatement.setFloat(6, zCoord); //zOffset from parentZone center
|
||||
preparedStatement.setString(7, name); //city name
|
||||
preparedStatement.setTimestamp(8, Timestamp.valueOf(established));
|
||||
preparedStatement.setFloat(9, rotation);
|
||||
preparedStatement.setFloat(10, W);
|
||||
preparedStatement.setTimestamp(11, Timestamp.valueOf(upgradeTime));
|
||||
|
||||
boolean work = preparedStatement.execute();
|
||||
|
||||
if (work) {
|
||||
|
||||
ResultSet rs = preparedStatement.getResultSet();
|
||||
|
||||
while (rs.next())
|
||||
addObject(objectList, rs);
|
||||
rs.close();
|
||||
} else {
|
||||
Logger.info("City Placement Failed: " + preparedStatement);
|
||||
return objectList; //city creation failure
|
||||
}
|
||||
while (preparedStatement.getMoreResults()) {
|
||||
ResultSet rs = preparedStatement.getResultSet();
|
||||
while (rs.next()) {
|
||||
addObject(objectList, rs);
|
||||
}
|
||||
rs.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return objectList;
|
||||
}
|
||||
|
||||
public ArrayList<City> GET_CITIES_BY_ZONE(final int objectUUID) {
|
||||
|
||||
ArrayList<City> cityList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_city`.*, `object`.`parent` FROM `obj_city` INNER JOIN `object` ON `object`.`UID` = `obj_city`.`UID` WHERE `object`.`parent`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
cityList = getObjectsFromRs(rs, 100);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return cityList;
|
||||
}
|
||||
|
||||
public City GET_CITY(final int cityId) {
|
||||
|
||||
City city = (City) DbManager.getFromCache(Enum.GameObjectType.City, cityId);
|
||||
|
||||
if (city != null)
|
||||
return city;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_city`.*, `object`.`parent` FROM `obj_city` INNER JOIN `object` ON `object`.`UID` = `obj_city`.`UID` WHERE `object`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, cityId);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
city = (City) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return city;
|
||||
}
|
||||
|
||||
public boolean updateforceRename(City city, boolean value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `forceRename`=?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setByte(1, (value == true) ? (byte) 1 : (byte) 0);
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateOpenCity(City city, boolean value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `open`=?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setByte(1, (value == true) ? (byte) 1 : (byte) 0);
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateTOL(City city, int tolID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `treeOfLifeUUID`=?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, tolID);
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean renameCity(City city, String name) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `name`=?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setString(1, name);
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean updateSiegesWithstood(City city, int value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `name`=?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, value);
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean updateRealmTaxDate(City city, LocalDateTime localDateTime) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `realmTaxDate` =?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setTimestamp(1, Timestamp.valueOf(localDateTime));
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Contract;
|
||||
import engine.objects.ItemBase;
|
||||
import engine.objects.MobEquipment;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbContractHandler extends dbHandlerBase {
|
||||
|
||||
public dbContractHandler() {
|
||||
this.localClass = Contract.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Contract GET_CONTRACT(final int objectUUID) {
|
||||
|
||||
Contract contract = (Contract) DbManager.getFromCache(Enum.GameObjectType.Contract, objectUUID);
|
||||
|
||||
if (contract != null)
|
||||
return contract;
|
||||
|
||||
if (objectUUID == 0)
|
||||
return null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract` WHERE `ID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
contract = (Contract) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return contract;
|
||||
}
|
||||
|
||||
public void LOAD_CONTRACT_INVENTORY(final Contract contract) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_inventoryset` WHERE `inventorySet` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, contract.inventorySet);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
//handle item base
|
||||
int itemBaseID = rs.getInt("itembaseID");
|
||||
|
||||
ItemBase ib = ItemBase.getItemBase(itemBaseID);
|
||||
|
||||
if (ib != null) {
|
||||
|
||||
MobEquipment me = new MobEquipment(ib, 0, 0);
|
||||
contract.getSellInventory().add(me);
|
||||
|
||||
//handle magic effects
|
||||
String prefix = rs.getString("prefix");
|
||||
int pRank = rs.getInt("pRank");
|
||||
String suffix = rs.getString("suffix");
|
||||
int sRank = rs.getInt("sRank");
|
||||
|
||||
if (prefix != null) {
|
||||
me.setPrefix(prefix, pRank);
|
||||
me.setIsID(true);
|
||||
}
|
||||
|
||||
if (suffix != null) {
|
||||
me.setSuffix(suffix, sRank);
|
||||
me.setIsID(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_SELL_LIST_FOR_CONTRACT(final Contract contract) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract_selltype` WHERE `contractID` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, contract.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
int type = rs.getInt("type");
|
||||
int value = rs.getInt("value");
|
||||
|
||||
switch (type) {
|
||||
case 1:
|
||||
contract.getBuyItemType().add(value);
|
||||
break;
|
||||
case 2:
|
||||
contract.getBuySkillToken().add(value);
|
||||
break;
|
||||
case 3:
|
||||
contract.getBuyUnknownToken().add(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateAllowedBuildings(final Contract con, final long slotbitvalue) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `allowedBuildingTypeID`=? WHERE `contractID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, slotbitvalue);
|
||||
preparedStatement.setInt(2, con.getContractID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateDatabase(final Contract con) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `contractID`=?, `name`=?, "
|
||||
+ "`mobbaseID`=?, `classID`=?, vendorDialog=?, iconID=?, allowedBuildingTypeID=? WHERE `ID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, con.getContractID());
|
||||
preparedStatement.setString(2, con.getName());
|
||||
preparedStatement.setInt(3, con.getMobbaseID());
|
||||
preparedStatement.setInt(4, con.getClassID());
|
||||
preparedStatement.setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0);
|
||||
preparedStatement.setInt(6, con.getIconID());
|
||||
preparedStatement.setInt(8, con.getObjectUUID());
|
||||
preparedStatement.setLong(7, con.getAllowedBuildings().toLong());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.PowersManager;
|
||||
import engine.powers.EffectsBase;
|
||||
import engine.powers.effectmodifiers.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class dbEffectsBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbEffectsBaseHandler() {
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<EffectsBase> getAllEffectsBase() {
|
||||
|
||||
ArrayList<EffectsBase> effectList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectbase ORDER BY `IDString` DESC")) {
|
||||
|
||||
ResultSet rs = prepareStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
EffectsBase effectBase = new EffectsBase(rs);
|
||||
effectList.add(effectBase);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
return effectList;
|
||||
}
|
||||
|
||||
public static void cacheAllEffectModifiers() {
|
||||
|
||||
String IDString;
|
||||
AbstractEffectModifier abstractEffectModifier = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectmod")) {
|
||||
|
||||
ResultSet rs = prepareStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
IDString = rs.getString("IDString");
|
||||
EffectsBase effectBase = PowersManager.getEffectByIDString(IDString);
|
||||
Enum.ModType modifier = Enum.ModType.GetModType(rs.getString("modType"));
|
||||
|
||||
//combine item prefix and suffix effect modifiers
|
||||
|
||||
abstractEffectModifier = getCombinedModifiers(abstractEffectModifier, rs, effectBase, modifier);
|
||||
|
||||
if (abstractEffectModifier != null) {
|
||||
|
||||
if (EffectsBase.modifiersMap.containsKey(effectBase.getIDString()) == false)
|
||||
EffectsBase.modifiersMap.put(effectBase.getIDString(), new HashSet<>());
|
||||
|
||||
EffectsBase.modifiersMap.get(effectBase.getIDString()).add(abstractEffectModifier);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static AbstractEffectModifier getCombinedModifiers(AbstractEffectModifier abstractEffectModifier, ResultSet rs, EffectsBase effectBase, Enum.ModType modifier) throws SQLException {
|
||||
switch (modifier) {
|
||||
case AdjustAboveDmgCap:
|
||||
abstractEffectModifier = new AdjustAboveDmgCapEffectModifier(rs);
|
||||
break;
|
||||
case Ambidexterity:
|
||||
abstractEffectModifier = new AmbidexterityEffectModifier(rs);
|
||||
break;
|
||||
case AnimOverride:
|
||||
break;
|
||||
case ArmorPiercing:
|
||||
abstractEffectModifier = new ArmorPiercingEffectModifier(rs);
|
||||
break;
|
||||
case AttackDelay:
|
||||
abstractEffectModifier = new AttackDelayEffectModifier(rs);
|
||||
break;
|
||||
case Attr:
|
||||
abstractEffectModifier = new AttributeEffectModifier(rs);
|
||||
break;
|
||||
case BlackMantle:
|
||||
abstractEffectModifier = new BlackMantleEffectModifier(rs);
|
||||
break;
|
||||
case BladeTrails:
|
||||
abstractEffectModifier = new BladeTrailsEffectModifier(rs);
|
||||
break;
|
||||
case Block:
|
||||
abstractEffectModifier = new BlockEffectModifier(rs);
|
||||
break;
|
||||
case BlockedPowerType:
|
||||
abstractEffectModifier = new BlockedPowerTypeEffectModifier(rs);
|
||||
break;
|
||||
case CannotAttack:
|
||||
abstractEffectModifier = new CannotAttackEffectModifier(rs);
|
||||
break;
|
||||
case CannotCast:
|
||||
abstractEffectModifier = new CannotCastEffectModifier(rs);
|
||||
break;
|
||||
case CannotMove:
|
||||
abstractEffectModifier = new CannotMoveEffectModifier(rs);
|
||||
break;
|
||||
case CannotTrack:
|
||||
abstractEffectModifier = new CannotTrackEffectModifier(rs);
|
||||
break;
|
||||
case Charmed:
|
||||
abstractEffectModifier = new CharmedEffectModifier(rs);
|
||||
break;
|
||||
case ConstrainedAmbidexterity:
|
||||
abstractEffectModifier = new ConstrainedAmbidexterityEffectModifier(rs);
|
||||
break;
|
||||
case DamageCap:
|
||||
abstractEffectModifier = new DamageCapEffectModifier(rs);
|
||||
break;
|
||||
case DamageShield:
|
||||
abstractEffectModifier = new DamageShieldEffectModifier(rs);
|
||||
break;
|
||||
case DCV:
|
||||
abstractEffectModifier = new DCVEffectModifier(rs);
|
||||
break;
|
||||
case Dodge:
|
||||
abstractEffectModifier = new DodgeEffectModifier(rs);
|
||||
break;
|
||||
case DR:
|
||||
abstractEffectModifier = new DREffectModifier(rs);
|
||||
break;
|
||||
case Durability:
|
||||
abstractEffectModifier = new DurabilityEffectModifier(rs);
|
||||
break;
|
||||
case ExclusiveDamageCap:
|
||||
abstractEffectModifier = new ExclusiveDamageCapEffectModifier(rs);
|
||||
break;
|
||||
case Fade:
|
||||
abstractEffectModifier = new FadeEffectModifier(rs);
|
||||
break;
|
||||
case Fly:
|
||||
abstractEffectModifier = new FlyEffectModifier(rs);
|
||||
break;
|
||||
case Health:
|
||||
abstractEffectModifier = new HealthEffectModifier(rs);
|
||||
break;
|
||||
case HealthFull:
|
||||
abstractEffectModifier = new HealthFullEffectModifier(rs);
|
||||
break;
|
||||
case HealthRecoverRate:
|
||||
abstractEffectModifier = new HealthRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case IgnoreDamageCap:
|
||||
abstractEffectModifier = new IgnoreDamageCapEffectModifier(rs);
|
||||
break;
|
||||
case IgnorePassiveDefense:
|
||||
abstractEffectModifier = new IgnorePassiveDefenseEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneTo:
|
||||
abstractEffectModifier = new ImmuneToEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneToAttack:
|
||||
abstractEffectModifier = new ImmuneToAttackEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneToPowers:
|
||||
abstractEffectModifier = new ImmuneToPowersEffectModifier(rs);
|
||||
break;
|
||||
case Invisible:
|
||||
abstractEffectModifier = new InvisibleEffectModifier(rs);
|
||||
break;
|
||||
case ItemName:
|
||||
abstractEffectModifier = new ItemNameEffectModifier(rs);
|
||||
if (((ItemNameEffectModifier) abstractEffectModifier).name.isEmpty())
|
||||
break;
|
||||
if (effectBase != null)
|
||||
effectBase.setName((((ItemNameEffectModifier) abstractEffectModifier).name));
|
||||
break;
|
||||
case Mana:
|
||||
abstractEffectModifier = new ManaEffectModifier(rs);
|
||||
break;
|
||||
case ManaFull:
|
||||
abstractEffectModifier = new ManaFullEffectModifier(rs);
|
||||
break;
|
||||
case ManaRecoverRate:
|
||||
abstractEffectModifier = new ManaRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case MaxDamage:
|
||||
abstractEffectModifier = new MaxDamageEffectModifier(rs);
|
||||
break;
|
||||
case MeleeDamageModifier:
|
||||
abstractEffectModifier = new MeleeDamageEffectModifier(rs);
|
||||
break;
|
||||
case MinDamage:
|
||||
abstractEffectModifier = new MinDamageEffectModifier(rs);
|
||||
break;
|
||||
case NoMod:
|
||||
abstractEffectModifier = new NoModEffectModifier(rs);
|
||||
break;
|
||||
case OCV:
|
||||
abstractEffectModifier = new OCVEffectModifier(rs);
|
||||
break;
|
||||
case Parry:
|
||||
abstractEffectModifier = new ParryEffectModifier(rs);
|
||||
break;
|
||||
case PassiveDefense:
|
||||
abstractEffectModifier = new PassiveDefenseEffectModifier(rs);
|
||||
break;
|
||||
case PowerCost:
|
||||
abstractEffectModifier = new PowerCostEffectModifier(rs);
|
||||
break;
|
||||
case PowerCostHealth:
|
||||
abstractEffectModifier = new PowerCostHealthEffectModifier(rs);
|
||||
break;
|
||||
case PowerDamageModifier:
|
||||
abstractEffectModifier = new PowerDamageEffectModifier(rs);
|
||||
break;
|
||||
case ProtectionFrom:
|
||||
abstractEffectModifier = new ProtectionFromEffectModifier(rs);
|
||||
break;
|
||||
case Resistance:
|
||||
abstractEffectModifier = new ResistanceEffectModifier(rs);
|
||||
break;
|
||||
case ScaleHeight:
|
||||
abstractEffectModifier = new ScaleHeightEffectModifier(rs);
|
||||
break;
|
||||
case ScaleWidth:
|
||||
abstractEffectModifier = new ScaleWidthEffectModifier(rs);
|
||||
break;
|
||||
case ScanRange:
|
||||
abstractEffectModifier = new ScanRangeEffectModifier(rs);
|
||||
break;
|
||||
case SeeInvisible:
|
||||
abstractEffectModifier = new SeeInvisibleEffectModifier(rs);
|
||||
break;
|
||||
case Silenced:
|
||||
abstractEffectModifier = new SilencedEffectModifier(rs);
|
||||
break;
|
||||
case Skill:
|
||||
abstractEffectModifier = new SkillEffectModifier(rs);
|
||||
break;
|
||||
case Slay:
|
||||
abstractEffectModifier = new SlayEffectModifier(rs);
|
||||
break;
|
||||
case Speed:
|
||||
abstractEffectModifier = new SpeedEffectModifier(rs);
|
||||
break;
|
||||
case SpireBlock:
|
||||
abstractEffectModifier = new SpireBlockEffectModifier(rs);
|
||||
break;
|
||||
case Stamina:
|
||||
abstractEffectModifier = new StaminaEffectModifier(rs);
|
||||
break;
|
||||
case StaminaFull:
|
||||
abstractEffectModifier = new StaminaFullEffectModifier(rs);
|
||||
break;
|
||||
case StaminaRecoverRate:
|
||||
abstractEffectModifier = new StaminaRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case Stunned:
|
||||
abstractEffectModifier = new StunnedEffectModifier(rs);
|
||||
break;
|
||||
case Value:
|
||||
abstractEffectModifier = new ValueEffectModifier(rs);
|
||||
if (effectBase != null) {
|
||||
ValueEffectModifier valueEffect = (ValueEffectModifier) abstractEffectModifier;
|
||||
effectBase.setValue(valueEffect.minMod);
|
||||
}
|
||||
break;
|
||||
case WeaponProc:
|
||||
abstractEffectModifier = new WeaponProcEffectModifier(rs);
|
||||
break;
|
||||
case WeaponRange:
|
||||
abstractEffectModifier = new WeaponRangeEffectModifier(rs);
|
||||
break;
|
||||
case WeaponSpeed:
|
||||
abstractEffectModifier = new WeaponSpeedEffectModifier(rs);
|
||||
break;
|
||||
|
||||
}
|
||||
return abstractEffectModifier;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.EffectsResourceCosts;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbEffectsResourceCostHandler extends dbHandlerBase {
|
||||
|
||||
public dbEffectsResourceCostHandler() {
|
||||
this.localClass = EffectsResourceCosts.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<EffectsResourceCosts> GET_ALL_EFFECT_RESOURCES(String idString) {
|
||||
|
||||
ArrayList<EffectsResourceCosts> effectsResourceCosts = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_power_effectcost` WHERE `IDString` = ?")) {
|
||||
|
||||
preparedStatement.setString(1, idString);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
effectsResourceCosts = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return effectsResourceCosts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbEnchantmentHandler extends dbHandlerBase {
|
||||
|
||||
public ConcurrentHashMap<String, Integer> GET_ENCHANTMENTS_FOR_ITEM(final int id) {
|
||||
|
||||
ConcurrentHashMap<String, Integer> enchants = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_item_enchantment` WHERE `ItemID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
enchants.put(rs.getString("powerAction"), rs.getInt("rank"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return enchants;
|
||||
}
|
||||
|
||||
public boolean CREATE_ENCHANTMENT_FOR_ITEM(long itemID, String powerAction, int rank) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_item_enchantment` (`itemID`, `powerAction`, `rank`) VALUES (?, ?, ?);")) {
|
||||
|
||||
preparedStatement.setLong(1, itemID);
|
||||
preparedStatement.setString(2, powerAction);
|
||||
preparedStatement.setInt(3, rank);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CLEAR_ENCHANTMENTS(long itemID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_item_enchantment` WHERE `itemID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, itemID);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,718 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GuildHistoryType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.*;
|
||||
import engine.server.world.WorldServer;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbGuildHandler extends dbHandlerBase {
|
||||
|
||||
public dbGuildHandler() {
|
||||
this.localClass = Guild.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public static ArrayList<PlayerCharacter> GET_GUILD_BANISHED(final int id) {
|
||||
|
||||
return new ArrayList<>();
|
||||
|
||||
// Bugfix
|
||||
// prepareCallable("SELECT * FROM `obj_character`, `dyn_guild_banishlist` WHERE `obj_character.char_isActive` = 1 AND `dyn_guild_banishlist.CharacterID` = `obj_character.UID` AND `obj_character.GuildID`=?");
|
||||
|
||||
//prepareCallable("SELECT * FROM `obj_character` `,` `dyn_guild_banishlist` WHERE obj_character.char_isActive = 1 AND dyn_guild_banishlist.CharacterID = obj_character.UID AND dyn_guild_banishlist.GuildID = ?");
|
||||
//setLong(1, (long) id);
|
||||
|
||||
//return getObjectList();
|
||||
}
|
||||
|
||||
public static void LOAD_GUILD_HISTORY_FOR_PLAYER(PlayerCharacter playerCharacter) {
|
||||
|
||||
if (playerCharacter == null)
|
||||
return;
|
||||
|
||||
ArrayList<GuildHistory> guildList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, playerCharacter.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
GuildHistory guildEntry = new GuildHistory(rs);
|
||||
guildList.add(guildEntry);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
playerCharacter.setGuildHistory(guildList);
|
||||
}
|
||||
|
||||
public int BANISH_FROM_GUILD_OFFLINE(final int target, boolean sourceIsGuildLeader) {
|
||||
|
||||
String queryString;
|
||||
int rowCount;
|
||||
|
||||
// Only a Guild Leader can remove inner council
|
||||
|
||||
if (sourceIsGuildLeader)
|
||||
queryString = "UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0,"
|
||||
+ " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=?";
|
||||
else
|
||||
queryString = "UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0,"
|
||||
+ " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=? && `guild_isInnerCouncil`=0";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(queryString)) {
|
||||
|
||||
preparedStatement.setLong(1, target);
|
||||
rowCount = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public boolean ADD_TO_BANISHED_FROM_GUILDLIST(int target, long characterID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, target);
|
||||
preparedStatement.setLong(2, characterID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_BANISH_LIST(int target, long characterID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, target);
|
||||
preparedStatement.setLong(2, characterID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ADD_TO_GUILDHISTORY(int target, PlayerCharacter playerCharacter, DateTime historyDate, GuildHistoryType historyType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_guildhistory` (`GuildID`, `CharacterID`, `historyDate`, `historyType`) VALUES (?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, target);
|
||||
preparedStatement.setLong(2, playerCharacter.getObjectUUID());
|
||||
|
||||
if (historyDate == null)
|
||||
preparedStatement.setNull(3, java.sql.Types.DATE);
|
||||
else
|
||||
preparedStatement.setTimestamp(3, new Timestamp(historyDate.getMillis()));
|
||||
|
||||
preparedStatement.setString(4, historyType.name());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO Need to get this working.
|
||||
public ArrayList<Guild> GET_GUILD_HISTORY_OF_PLAYER(final int id) {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_character_guildhistory` l WHERE g.`UID` = l.`GuildID` && l.`CharacterID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return guildList;
|
||||
}
|
||||
|
||||
public ArrayList<Guild> GET_GUILD_ALLIES(final int id) {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
|
||||
+ "WHERE l.isAlliance = 1 && l.OtherGuildID = g.UID && l.GuildID=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return guildList;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Guild> GET_GUILD_ENEMIES(final int id) {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
|
||||
+ "WHERE l.isAlliance = 0 && l.OtherGuildID = g.UID && l.GuildID=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return guildList;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<PlayerCharacter> GET_GUILD_KOS_CHARACTER(final int id) {
|
||||
|
||||
ArrayList<PlayerCharacter> kosList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT c.* FROM `obj_character` c, `dyn_guild_characterkoslist` l WHERE c.`char_isActive` = 1 && l.`KOSCharacterID` = c.`UID` && l.`GuildID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int playerUUID = rs.getInt(1);
|
||||
PlayerCharacter kosPlayer = PlayerCharacter.getPlayerCharacter(playerUUID);
|
||||
|
||||
if (kosPlayer != null)
|
||||
kosList.add(kosPlayer);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return kosList;
|
||||
}
|
||||
|
||||
public ArrayList<Guild> GET_GUILD_KOS_GUILD(final int id) {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_guildkoslist` l "
|
||||
+ "WHERE l.KOSGuildID = g.UID && l.GuildID = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return guildList;
|
||||
}
|
||||
|
||||
public ArrayList<Guild> GET_SUB_GUILDS(final int guildID) {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `object` INNER JOIN `obj_guild` ON `obj_guild`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, guildID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return guildList;
|
||||
}
|
||||
|
||||
public Guild GET_GUILD(int id) {
|
||||
|
||||
Guild guild = (Guild) DbManager.getFromCache(Enum.GameObjectType.Guild, id);
|
||||
|
||||
if (guild != null)
|
||||
return guild;
|
||||
|
||||
if (id == 0)
|
||||
return Guild.getErrantGuild();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `obj_guild` INNER JOIN `object` ON `object`.`UID` = `obj_guild`.`UID` WHERE `object`.`UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guild = (Guild) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return guild;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Guild> GET_ALL_GUILDS() {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `obj_guild` INNER JOIN `object` ON `object`.`UID` = `obj_guild`.`UID`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 100);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return guildList;
|
||||
}
|
||||
|
||||
public boolean IS_CREST_UNIQUE(final GuildTag gt) {
|
||||
|
||||
boolean valid = false;
|
||||
String queryString;
|
||||
|
||||
// Ignore bg symbol if bg color is the same as fg color.
|
||||
|
||||
if (gt.backgroundColor01 == gt.backgroundColor02)
|
||||
queryString = "SELECT `name` FROM `obj_guild` WHERE `backgroundColor01`=? && `backgroundColor02`=? && `symbolColor`=? && `symbol`=?;";
|
||||
else
|
||||
queryString = "SELECT `name` FROM `obj_guild` WHERE `backgroundColor01`=? && `backgroundColor02`=? && `symbolColor`=? && `backgroundDesign`=? && `symbol`=?;";
|
||||
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(queryString)) {
|
||||
|
||||
if (gt.backgroundColor01 == gt.backgroundColor02) {
|
||||
preparedStatement.setInt(1, gt.backgroundColor01);
|
||||
preparedStatement.setInt(2, gt.backgroundColor02);
|
||||
preparedStatement.setInt(3, gt.symbolColor);
|
||||
preparedStatement.setInt(4, gt.symbol);
|
||||
} else {
|
||||
preparedStatement.setInt(1, gt.backgroundColor01);
|
||||
preparedStatement.setInt(2, gt.backgroundColor02);
|
||||
preparedStatement.setInt(3, gt.symbolColor);
|
||||
preparedStatement.setInt(4, gt.backgroundDesign);
|
||||
preparedStatement.setInt(5, gt.symbol);
|
||||
}
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (!rs.next())
|
||||
valid = true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
public boolean SET_GUILD_OWNED_CITY(int guildID, int cityID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `ownedCity`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, cityID);
|
||||
preparedStatement.setLong(2, guildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_GUILD_LEADER(int objectUUID, int guildID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `leaderUID`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
preparedStatement.setLong(2, guildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean IS_NAME_UNIQUE(final String name) {
|
||||
|
||||
boolean valid = false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `name` FROM `obj_guild` WHERE `name`=?;")) {
|
||||
|
||||
preparedStatement.setString(1, name);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (!rs.next())
|
||||
valid = true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
public Guild SAVE_TO_DATABASE(Guild g) {
|
||||
|
||||
Guild guild = null;
|
||||
GuildTag guildTag = g.getGuildTag();
|
||||
|
||||
if (guildTag == null)
|
||||
return null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `guild_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
|
||||
|
||||
preparedStatement.setLong(1, WorldServer.worldUUID);
|
||||
preparedStatement.setLong(2, g.getGuildLeaderUUID());
|
||||
preparedStatement.setString(3, g.getName());
|
||||
preparedStatement.setInt(4, guildTag.backgroundColor01);
|
||||
preparedStatement.setInt(5, guildTag.backgroundColor02);
|
||||
preparedStatement.setInt(6, guildTag.symbolColor);
|
||||
preparedStatement.setInt(7, guildTag.backgroundDesign);
|
||||
preparedStatement.setInt(8, guildTag.symbol);
|
||||
preparedStatement.setInt(9, g.getCharter());
|
||||
preparedStatement.setString(10, g.getLeadershipType());
|
||||
preparedStatement.setString(11, g.getMotto());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
guild = GET_GUILD(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return guild;
|
||||
}
|
||||
|
||||
public boolean UPDATE_GUILD_RANK_OFFLINE(int target, int newRank, int guildId) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=? && `guildUID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, newRank);
|
||||
preparedStatement.setInt(2, target);
|
||||
preparedStatement.setInt(3, guildId);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_PARENT(int guildUID, int parentUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` SET `parent`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, parentUID);
|
||||
preparedStatement.setInt(2, guildUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int DELETE_GUILD(final Guild guild) {
|
||||
|
||||
int row_count = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, guild.getObjectUUID());
|
||||
row_count = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
public boolean UPDATE_MINETIME(int guildUID, int mineTime) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `mineTime`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, mineTime);
|
||||
preparedStatement.setInt(2, guildUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// *** Refactor: Why are we saving tags/charter in update?
|
||||
// It's not like this shit ever changes.
|
||||
|
||||
public int UPDATE_GUILD_STATUS_OFFLINE(int target, boolean isInnerCouncil, boolean isRecruiter, boolean isTaxCollector, int guildId) {
|
||||
|
||||
int updateMask = 0;
|
||||
int row_count = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `guild_isInnerCouncil`, `guild_isTaxCollector`, `guild_isRecruiter` FROM `obj_character` WHERE `UID`=? && `guildUID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, target);
|
||||
preparedStatement.setLong(2, guildId);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
//If the first query had no results, neither will the second
|
||||
|
||||
//Determine what is different
|
||||
|
||||
if (rs.first()) {
|
||||
if (rs.getBoolean("guild_isInnerCouncil") != isInnerCouncil)
|
||||
updateMask |= 4;
|
||||
if (rs.getBoolean("guild_isRecruiter") != isRecruiter)
|
||||
updateMask |= 2;
|
||||
if (rs.getBoolean("guild_isTaxCollector") != isTaxCollector)
|
||||
updateMask |= 1;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=?, `guild_isTaxCollector`=?, `guild_isRecruiter`=?, `guild_isFullMember`=? WHERE `UID`=? && `guildUID`=?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, isInnerCouncil);
|
||||
preparedStatement.setBoolean(2, isRecruiter);
|
||||
preparedStatement.setBoolean(3, isTaxCollector);
|
||||
preparedStatement.setBoolean(4, ((updateMask > 0))); //If you are becoming an officer, or where an officer, your a full member...
|
||||
preparedStatement.setLong(5, target);
|
||||
preparedStatement.setLong(6, guildId);
|
||||
|
||||
row_count = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
public boolean updateDatabase(final Guild g) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `name`=?, `backgroundColor01`=?, `backgroundColor02`=?, `symbolColor`=?, `backgroundDesign`=?, `symbol`=?, `charter`=?, `motd`=?, `icMotd`=?, `nationMotd`=?, `leaderUID`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, g.getName());
|
||||
preparedStatement.setInt(2, g.getGuildTag().backgroundColor01);
|
||||
preparedStatement.setInt(3, g.getGuildTag().backgroundColor02);
|
||||
preparedStatement.setInt(4, g.getGuildTag().symbolColor);
|
||||
preparedStatement.setInt(5, g.getGuildTag().backgroundDesign);
|
||||
preparedStatement.setInt(6, g.getGuildTag().symbol);
|
||||
preparedStatement.setInt(7, g.getCharter());
|
||||
preparedStatement.setString(8, g.getMOTD());
|
||||
preparedStatement.setString(9, g.getICMOTD());
|
||||
preparedStatement.setString(10, "");
|
||||
preparedStatement.setInt(11, g.getGuildLeaderUUID());
|
||||
preparedStatement.setLong(12, g.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ADD_TO_ALLIANCE_LIST(final long sourceGuildID, final long targetGuildID, boolean isRecommended, boolean isAlly, String recommender) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_allianceenemylist` (`GuildID`, `OtherGuildID`,`isRecommended`, `isAlliance`, `recommender`) VALUES (?,?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, sourceGuildID);
|
||||
preparedStatement.setLong(2, targetGuildID);
|
||||
preparedStatement.setBoolean(3, isRecommended);
|
||||
preparedStatement.setBoolean(4, isAlly);
|
||||
preparedStatement.setString(5, recommender);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_ALLIANCE_LIST(final long sourceGuildID, long targetGuildID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_allianceenemylist` WHERE `GuildID`=? AND `OtherGuildID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, sourceGuildID);
|
||||
preparedStatement.setLong(2, targetGuildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_RECOMMENDED(final long sourceGuildID, long targetGuildID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, sourceGuildID);
|
||||
preparedStatement.setLong(2, targetGuildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_ALLIANCE(final long sourceGuildID, long targetGuildID, boolean isAlly) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, sourceGuildID);
|
||||
preparedStatement.setLong(2, targetGuildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_ALLIANCE_AND_RECOMMENDED(final long sourceGuildID, long targetGuildID, boolean isAlly) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ?, `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) {
|
||||
|
||||
preparedStatement.setByte(1, (byte) 0);
|
||||
preparedStatement.setBoolean(2, isAlly);
|
||||
preparedStatement.setLong(3, sourceGuildID);
|
||||
preparedStatement.setLong(4, targetGuildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_ALL_ALLIANCES_FOR_GUILD(Guild guild) {
|
||||
|
||||
if (guild == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, guild.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
GuildAlliances guildAlliance = new GuildAlliances(rs);
|
||||
guild.guildAlliances.put(guildAlliance.getAllianceGuild(), guildAlliance);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO uncomment this when finished with guild history warehouse integration
|
||||
// public HashMap<Integer, GuildRecord> GET_WAREHOUSE_GUILD_HISTORY(){
|
||||
//
|
||||
// HashMap<Integer, GuildRecord> tempMap = new HashMap<>();
|
||||
// prepareCallable("SELECT * FROM `warehouse_guildhistory` WHERE `eventType` = 'CREATE'");
|
||||
// try {
|
||||
// ResultSet rs = executeQuery();
|
||||
//
|
||||
// while (rs.next()) {
|
||||
// GuildRecord guildRecord = new GuildRecord(rs);
|
||||
// tempMap.put(guildRecord.guildID, guildRecord);
|
||||
// }
|
||||
// }catch (Exception e){
|
||||
// Logger.error(e);
|
||||
// }
|
||||
// return tempMap;
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.AbstractWorldObject;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class dbHandlerBase {
|
||||
|
||||
protected Class<? extends AbstractGameObject> localClass = null;
|
||||
protected GameObjectType localObjectType;
|
||||
|
||||
protected <T extends AbstractGameObject> AbstractGameObject getObjectFromRs(ResultSet rs) {
|
||||
|
||||
AbstractGameObject abstractGameObject = null;
|
||||
|
||||
try {
|
||||
if (rs.next()) {
|
||||
abstractGameObject = localClass.getConstructor(ResultSet.class).newInstance(rs);
|
||||
|
||||
DbManager.addToCache(abstractGameObject);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
// Only call runAfterLoad() for objects instanced on the world server
|
||||
|
||||
if ((abstractGameObject != null && abstractGameObject instanceof AbstractWorldObject) &&
|
||||
(ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER) ||
|
||||
(abstractGameObject.getObjectType() == GameObjectType.Guild)))
|
||||
((AbstractWorldObject) abstractGameObject).runAfterLoad();
|
||||
|
||||
return abstractGameObject;
|
||||
}
|
||||
|
||||
protected <T extends AbstractGameObject> ArrayList<T> getObjectsFromRs(ResultSet rs, int listSize) {
|
||||
|
||||
ArrayList<T> objectList = new ArrayList<>(listSize);
|
||||
|
||||
try {
|
||||
while (rs.next()) {
|
||||
|
||||
int id = rs.getInt(1);
|
||||
|
||||
if (DbManager.inCache(localObjectType, id)) {
|
||||
objectList.add((T) DbManager.getFromCache(localObjectType, id));
|
||||
} else {
|
||||
AbstractGameObject toAdd = localClass.getConstructor(ResultSet.class).newInstance(rs);
|
||||
DbManager.addToCache(toAdd);
|
||||
objectList.add((T) toAdd);
|
||||
|
||||
if (toAdd != null && toAdd instanceof AbstractWorldObject)
|
||||
((AbstractWorldObject) toAdd).runAfterLoad();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return objectList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.InterestManagement.HeightMap;
|
||||
import engine.gameManager.DbManager;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbHeightMapHandler extends dbHandlerBase {
|
||||
|
||||
public dbHeightMapHandler() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_ALL_HEIGHTMAPS() {
|
||||
|
||||
HeightMap thisHeightmap;
|
||||
HeightMap.heightMapsCreated = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_zone_heightmap INNER JOIN static_zone_size ON static_zone_size.loadNum = static_zone_heightmap.zoneLoadID")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
thisHeightmap = new HeightMap(rs);
|
||||
|
||||
if (thisHeightmap.getHeightmapImage() == null) {
|
||||
Logger.info("Imagemap for " + thisHeightmap.getHeightMapID() + " was null");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.ItemBase;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbItemBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbItemBaseHandler() {
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_BAKEDINSTATS(ItemBase itemBase) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_bakedinstat` WHERE `itemID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, itemBase.getUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
if (rs.getBoolean("fromUse"))
|
||||
itemBase.getUsedStats().put(rs.getInt("token"), rs.getInt("numTrains"));
|
||||
else
|
||||
itemBase.getBakedInStats().put(rs.getInt("token"), rs.getInt("numTrains"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_ANIMATIONS(ItemBase itemBase) {
|
||||
|
||||
ArrayList<Integer> tempList = new ArrayList<>();
|
||||
ArrayList<Integer> tempListOff = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_itembase_animations` WHERE `itemBaseUUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, itemBase.getUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int animation = rs.getInt("animation");
|
||||
boolean rightHand = rs.getBoolean("rightHand");
|
||||
|
||||
if (rightHand)
|
||||
tempList.add(animation);
|
||||
else
|
||||
tempListOff.add(animation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
itemBase.setAnimations(tempList);
|
||||
itemBase.setOffHandAnimations(tempListOff);
|
||||
}
|
||||
|
||||
public void LOAD_ALL_ITEMBASES() {
|
||||
|
||||
ItemBase itemBase;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itembase")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
recordsRead++;
|
||||
itemBase = new ItemBase(rs);
|
||||
ItemBase.addToCache(itemBase);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size());
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<Integer>> LOAD_RUNES_FOR_NPC_AND_MOBS() {
|
||||
|
||||
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
|
||||
int runeSetID;
|
||||
int runeBaseID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_runeSet")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
runeSetID = rs.getInt("runeSet");
|
||||
runeBaseID = rs.getInt("runeBase");
|
||||
|
||||
if (runeSets.get(runeSetID) == null) {
|
||||
ArrayList<Integer> runeList = new ArrayList<>();
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(runeSetID, runeList);
|
||||
} else {
|
||||
ArrayList<Integer> runeList = runeSets.get(runeSetID);
|
||||
runeList.add(runeSetID);
|
||||
runeSets.put(runeSetID, runeList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return runeSets;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
|
||||
return runeSets;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,499 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.ItemContainerType;
|
||||
import engine.Enum.ItemType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractCharacter;
|
||||
import engine.objects.CharacterItemManager;
|
||||
import engine.objects.Item;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
public class dbItemHandler extends dbHandlerBase {
|
||||
|
||||
public dbItemHandler() {
|
||||
this.localClass = Item.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
private static String formatTradeString(HashSet<Integer> list) {
|
||||
int size = list.size();
|
||||
|
||||
String ret = "";
|
||||
|
||||
if (size == 0)
|
||||
return ret;
|
||||
|
||||
boolean start = true;
|
||||
|
||||
for (int i : list) {
|
||||
if (start) {
|
||||
ret += i;
|
||||
start = false;
|
||||
} else
|
||||
ret += "," + i;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Item ADD_ITEM(Item toAdd) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?,?);")) {
|
||||
|
||||
preparedStatement.setInt(1, toAdd.getOwnerID());
|
||||
preparedStatement.setInt(2, toAdd.getItemBaseID());
|
||||
preparedStatement.setInt(3, toAdd.getChargesRemaining());
|
||||
preparedStatement.setInt(4, toAdd.getDurabilityCurrent());
|
||||
preparedStatement.setInt(5, toAdd.getDurabilityMax());
|
||||
|
||||
if (toAdd.getNumOfItems() < 1)
|
||||
preparedStatement.setInt(6, 1);
|
||||
else
|
||||
preparedStatement.setInt(6, toAdd.getNumOfItems());
|
||||
|
||||
switch (toAdd.containerType) {
|
||||
case INVENTORY:
|
||||
preparedStatement.setString(7, "inventory");
|
||||
break;
|
||||
case EQUIPPED:
|
||||
preparedStatement.setString(7, "equip");
|
||||
break;
|
||||
case BANK:
|
||||
preparedStatement.setString(7, "bank");
|
||||
break;
|
||||
case VAULT:
|
||||
preparedStatement.setString(7, "vault");
|
||||
break;
|
||||
case FORGE:
|
||||
preparedStatement.setString(7, "forge");
|
||||
break;
|
||||
default:
|
||||
preparedStatement.setString(7, "none"); //Shouldn't be here
|
||||
break;
|
||||
}
|
||||
|
||||
preparedStatement.setByte(8, toAdd.getEquipSlot());
|
||||
preparedStatement.setInt(9, toAdd.getFlags());
|
||||
preparedStatement.setString(10, toAdd.getCustomName());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
return GET_ITEM(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean DO_TRADE(HashSet<Integer> from1, HashSet<Integer> from2,
|
||||
CharacterItemManager man1, CharacterItemManager man2,
|
||||
Item inventoryGold1, Item inventoryGold2, int goldFrom1, int goldFrom2) {
|
||||
|
||||
AbstractCharacter ac1 = man1.getOwner();
|
||||
AbstractCharacter ac2 = man2.getOwner();
|
||||
boolean worked = false;
|
||||
|
||||
if (ac1 == null || ac2 == null || inventoryGold1 == null || inventoryGold2 == null)
|
||||
return false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRADE`(?, ?, ?, ?, ?, ?, ?, ?)")) {
|
||||
|
||||
preparedStatement.setString(1, formatTradeString(from1));
|
||||
preparedStatement.setLong(2, ac1.getObjectUUID());
|
||||
preparedStatement.setString(3, formatTradeString(from2));
|
||||
preparedStatement.setLong(4, ac2.getObjectUUID());
|
||||
preparedStatement.setInt(5, goldFrom1);
|
||||
preparedStatement.setLong(6, inventoryGold1.getObjectUUID());
|
||||
preparedStatement.setInt(7, goldFrom2);
|
||||
preparedStatement.setLong(8, inventoryGold2.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
worked = rs.getBoolean("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return worked;
|
||||
}
|
||||
|
||||
public ArrayList<Item> GET_EQUIPPED_ITEMS(final int targetId) {
|
||||
|
||||
ArrayList<Item> itemList;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=? && `obj_item`.`item_container`='equip';")) {
|
||||
|
||||
preparedStatement.setLong(1, targetId);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
itemList = getObjectsFromRs(rs, 10);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public Item GET_ITEM(final int itemUUID) {
|
||||
|
||||
Item item;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, itemUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
item = (Item) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public ArrayList<Item> GET_ITEMS_FOR_ACCOUNT(final int accountId) {
|
||||
|
||||
ArrayList<Item> itemList;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, accountId);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
itemList = getObjectsFromRs(rs, 100);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public ArrayList<Item> GET_ITEMS_FOR_NPC(final int npcId) {
|
||||
|
||||
ArrayList<Item> itemList;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, npcId);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
itemList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public ArrayList<Item> GET_ITEMS_FOR_PC(final int id) {
|
||||
|
||||
ArrayList<Item> itemList;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
itemList = getObjectsFromRs(rs, 100);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public boolean MOVE_GOLD(final Item from, final Item to, final int amt) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems` = CASE WHEN `UID`=? THEN ? WHEN `UID`=? THEN ? END WHERE `UID` IN (?, ?);")) {
|
||||
|
||||
int newFromAmt = from.getNumOfItems() - amt;
|
||||
int newToAmt = to.getNumOfItems() + amt;
|
||||
|
||||
preparedStatement.setLong(1, from.getObjectUUID());
|
||||
preparedStatement.setInt(2, newFromAmt);
|
||||
preparedStatement.setLong(3, to.getObjectUUID());
|
||||
preparedStatement.setInt(4, newToAmt);
|
||||
preparedStatement.setLong(5, from.getObjectUUID());
|
||||
preparedStatement.setLong(6, to.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ORPHAN_INVENTORY(final HashSet<Item> inventory) {
|
||||
|
||||
boolean worked = true;
|
||||
|
||||
for (Item item : inventory) {
|
||||
|
||||
if (item.getItemBase().getType().equals(ItemType.GOLD))
|
||||
continue;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` LEFT JOIN `object` ON `object`.`UID` = `obj_item`.`UID` SET `object`.`parent`=NULL, `obj_item`.`item_container`='none' WHERE `object`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, item.getObjectUUID());
|
||||
worked = (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
if (worked)
|
||||
item.zeroItem();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return worked;
|
||||
}
|
||||
|
||||
public HashSet<Integer> GET_ITEMS_FOR_VENDOR(final int vendorID) {
|
||||
|
||||
HashSet<Integer> itemSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT ID FROM static_itembase WHERE vendorType = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, vendorID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
itemSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return itemSet;
|
||||
}
|
||||
|
||||
return itemSet;
|
||||
}
|
||||
|
||||
//Used to transfer a single item between owners or equip or vault or bank or inventory
|
||||
public boolean UPDATE_OWNER(final Item item, int newOwnerID, boolean ownerNPC, boolean ownerPlayer,
|
||||
boolean ownerAccount, ItemContainerType containerType, int slot) {
|
||||
|
||||
boolean worked = false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRANSFER_OWNER`(?, ?, ?, ? )")) {
|
||||
|
||||
preparedStatement.setLong(1, item.getObjectUUID());
|
||||
|
||||
if (newOwnerID != 0)
|
||||
preparedStatement.setLong(2, newOwnerID);
|
||||
else
|
||||
preparedStatement.setNull(2, java.sql.Types.BIGINT);
|
||||
|
||||
switch (containerType) {
|
||||
case INVENTORY:
|
||||
preparedStatement.setString(3, "inventory");
|
||||
break;
|
||||
case EQUIPPED:
|
||||
preparedStatement.setString(3, "equip");
|
||||
break;
|
||||
case BANK:
|
||||
preparedStatement.setString(3, "bank");
|
||||
break;
|
||||
case VAULT:
|
||||
preparedStatement.setString(3, "vault");
|
||||
break;
|
||||
case FORGE:
|
||||
preparedStatement.setString(3, "forge");
|
||||
break;
|
||||
default:
|
||||
preparedStatement.setString(3, "none"); //Shouldn't be here
|
||||
break;
|
||||
}
|
||||
preparedStatement.setInt(4, slot);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
worked = rs.getBoolean("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
return worked;
|
||||
}
|
||||
|
||||
public boolean SET_DURABILITY(final Item item, int value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_durabilityCurrent`=? WHERE `UID`=? AND `item_durabilityCurrent`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, value);
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
preparedStatement.setInt(3, item.getDurabilityCurrent());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_FORGE_TO_INVENTORY(final Item item) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_container` = ? WHERE `UID` = ? AND `item_container` = 'forge';")) {
|
||||
|
||||
preparedStatement.setString(1, "inventory");
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to update the quantity of this gold item
|
||||
*
|
||||
* @param value New quantity of gold
|
||||
* @return True on success
|
||||
*/
|
||||
public boolean UPDATE_GOLD(final Item item, int value) {
|
||||
if (item == null)
|
||||
return false;
|
||||
return UPDATE_GOLD(item, value, item.getNumOfItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to update the quantity of this gold item using CAS
|
||||
*
|
||||
* @return True on success
|
||||
*/
|
||||
public boolean UPDATE_GOLD(final Item item, int newValue, int oldValue) {
|
||||
|
||||
if (!item.getItemBase().getType().equals(ItemType.GOLD))
|
||||
return false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, newValue);
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean UPDATE_REMAINING_CHARGES(final Item item) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_chargesRemaining` = ? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, item.getChargesRemaining());
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// This is necessary because default number of items is 1.
|
||||
// When we create gold, we want it to start at 0 quantity.
|
||||
|
||||
public boolean ZERO_ITEM_STACK(Item item) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=0 WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_FLAGS(Item item) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, item.getFlags());
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_VALUE(Item item, int value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_value`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, value);
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Kit;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbKitHandler extends dbHandlerBase {
|
||||
|
||||
public dbKitHandler() {
|
||||
this.localClass = Kit.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<Kit> GET_ALL_KITS() {
|
||||
|
||||
ArrayList<Kit> kitList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_validkit`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
kitList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return kitList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.loot.*;
|
||||
import engine.objects.Item;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbLootHandler extends dbHandlerBase {
|
||||
|
||||
public dbLootHandler() {
|
||||
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<GenTableEntry>> LOAD_GEN_ITEM_TABLES() {
|
||||
|
||||
HashMap<Integer, ArrayList<GenTableEntry>> genTables = new HashMap<>();
|
||||
GenTableEntry genTableEntry;
|
||||
|
||||
int genTableID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_gen`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
genTableID = rs.getInt("genTable");
|
||||
genTableEntry = new GenTableEntry(rs);
|
||||
|
||||
if (genTables.get(genTableID) == null) {
|
||||
ArrayList<GenTableEntry> genItemList = new ArrayList<>();
|
||||
genItemList.add(genTableEntry);
|
||||
genTables.put(genTableID, genItemList);
|
||||
} else {
|
||||
ArrayList<GenTableEntry> genItemList = genTables.get(genTableID);
|
||||
genItemList.add(genTableEntry);
|
||||
genTables.put(genTableID, genItemList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return genTables;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + genTables.size());
|
||||
return genTables;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<ItemTableEntry>> LOAD_ITEM_TABLES() {
|
||||
|
||||
HashMap<Integer, ArrayList<ItemTableEntry>> itemTables = new HashMap<>();
|
||||
ItemTableEntry itemTableEntry;
|
||||
|
||||
int itemTableID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_item`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
itemTableID = rs.getInt("itemTable");
|
||||
itemTableEntry = new ItemTableEntry(rs);
|
||||
|
||||
if (itemTables.get(itemTableID) == null) {
|
||||
ArrayList<ItemTableEntry> itemTableList = new ArrayList<>();
|
||||
itemTableList.add(itemTableEntry);
|
||||
itemTables.put(itemTableID, itemTableList);
|
||||
} else {
|
||||
ArrayList<ItemTableEntry> itemTableList = itemTables.get(itemTableID);
|
||||
itemTableList.add(itemTableEntry);
|
||||
itemTables.put(itemTableID, itemTableList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return itemTables;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + itemTables.size());
|
||||
return itemTables;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<ModTableEntry>> LOAD_MOD_TABLES() {
|
||||
|
||||
HashMap<Integer, ArrayList<ModTableEntry>> modTables = new HashMap<>();
|
||||
ModTableEntry modTableEntry;
|
||||
|
||||
int modTableID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_mod`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
modTableID = rs.getInt("modTable");
|
||||
modTableEntry = new ModTableEntry(rs);
|
||||
|
||||
if (modTables.get(modTableID) == null) {
|
||||
ArrayList<ModTableEntry> modTableList = new ArrayList<>();
|
||||
modTableList.add(modTableEntry);
|
||||
modTables.put(modTableID, modTableList);
|
||||
} else {
|
||||
ArrayList<ModTableEntry> modTableList = modTables.get(modTableID);
|
||||
modTableList.add(modTableEntry);
|
||||
modTables.put(modTableID, modTableList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return modTables;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + modTables.size());
|
||||
return modTables;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<ModTypeTableEntry>> LOAD_MOD_TYPE_TABLES() {
|
||||
|
||||
HashMap<Integer, ArrayList<ModTypeTableEntry>> modTypeTables = new HashMap<>();
|
||||
ModTypeTableEntry modTypeTableEntry;
|
||||
|
||||
int modTableID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_modtype`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
modTableID = rs.getInt("modType");
|
||||
modTypeTableEntry = new ModTypeTableEntry(rs);
|
||||
|
||||
if (modTypeTables.get(modTableID) == null) {
|
||||
ArrayList<ModTypeTableEntry> modTypeTableList = new ArrayList<>();
|
||||
modTypeTableList.add(modTypeTableEntry);
|
||||
modTypeTables.put(modTableID, modTypeTableList);
|
||||
} else {
|
||||
ArrayList<ModTypeTableEntry> modTypeTableList = modTypeTables.get(modTableID);
|
||||
modTypeTableList.add(modTypeTableEntry);
|
||||
modTypeTables.put(modTableID, modTypeTableList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return modTypeTables;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + modTypeTables.size());
|
||||
return modTypeTables;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<BootySetEntry>> LOAD_BOOTY_TABLES() {
|
||||
|
||||
HashMap<Integer, ArrayList<BootySetEntry>> bootySets = new HashMap<>();
|
||||
BootySetEntry bootySetEntry;
|
||||
int bootySetID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_loot_bootySet")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
bootySetID = rs.getInt("bootySet");
|
||||
bootySetEntry = new BootySetEntry(rs);
|
||||
|
||||
if (bootySets.get(bootySetID) == null) {
|
||||
ArrayList<BootySetEntry> bootyList = new ArrayList<>();
|
||||
bootyList.add(bootySetEntry);
|
||||
bootySets.put(bootySetID, bootyList);
|
||||
} else {
|
||||
ArrayList<BootySetEntry> bootyList = bootySets.get(bootySetID);
|
||||
bootyList.add(bootySetEntry);
|
||||
bootySets.put(bootySetID, bootyList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return bootySets;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + bootySets.size());
|
||||
return bootySets;
|
||||
}
|
||||
|
||||
public void LOAD_ENCHANT_VALUES() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `IDString`, `minMod` FROM `static_power_effectmod` WHERE `modType` = ?")) {
|
||||
|
||||
preparedStatement.setString(1, "Value");
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
Item.addEnchantValue(rs.getString("IDString"), rs.getInt("minMod"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.MenuOption;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbMenuHandler extends dbHandlerBase {
|
||||
|
||||
public dbMenuHandler() {
|
||||
this.localClass = MenuOption.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<MenuOption> GET_MENU_OPTIONS(final int id) {
|
||||
|
||||
ArrayList<MenuOption> menuOptions = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_menuoption` WHERE menuID = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
menuOptions = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return menuOptions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Mine;
|
||||
import engine.objects.MineProduction;
|
||||
import engine.objects.Resource;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbMineHandler extends dbHandlerBase {
|
||||
|
||||
public dbMineHandler() {
|
||||
this.localClass = Mine.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Mine GET_MINE(int id) {
|
||||
|
||||
if (id == 0)
|
||||
return null;
|
||||
|
||||
Mine mine = (Mine) DbManager.getFromCache(Enum.GameObjectType.Mine, id);
|
||||
|
||||
if (mine != null)
|
||||
return mine;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mine = (Mine) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return mine;
|
||||
}
|
||||
|
||||
public ArrayList<Mine> GET_ALL_MINES_FOR_SERVER() {
|
||||
|
||||
ArrayList<Mine> mines = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mine`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mine` ON `obj_mine`.`UID` = `object`.`UID`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mines = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return mines;
|
||||
}
|
||||
|
||||
public boolean CHANGE_OWNER(Mine mine, int playerUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_ownerUID`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, playerUID);
|
||||
preparedStatement.setLong(2, mine.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CHANGE_RESOURCE(Mine mine, Resource resource) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_resource`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, resource.name());
|
||||
preparedStatement.setLong(2, mine.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CHANGE_TYPE(Mine mine, MineProduction productionType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_type`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, productionType.name());
|
||||
preparedStatement.setLong(2, mine.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_FLAGS(Mine mine, int newFlags) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `flags`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, newFlags);
|
||||
preparedStatement.setLong(2, mine.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.MobBase;
|
||||
import engine.objects.MobBaseEffects;
|
||||
import engine.objects.MobBaseStats;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbMobBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbMobBaseHandler() {
|
||||
this.localClass = MobBase.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public MobBase GET_MOBBASE(int id) {
|
||||
|
||||
if (id == 0)
|
||||
return null;
|
||||
|
||||
MobBase mobBase = (MobBase) DbManager.getFromCache(GameObjectType.MobBase, id);
|
||||
|
||||
if (mobBase != null)
|
||||
return mobBase;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase` WHERE `ID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mobBase = (MobBase) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return mobBase;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<MobBase> GET_ALL_MOBBASES() {
|
||||
|
||||
ArrayList<MobBase> mobbaseList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mobbaseList = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return mobbaseList;
|
||||
}
|
||||
|
||||
public ArrayList<MobBaseEffects> GET_RUNEBASE_EFFECTS(int runeID) {
|
||||
|
||||
ArrayList<MobBaseEffects> effectsList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_effects` WHERE `mobbaseUUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, runeID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
MobBaseEffects mbs = new MobBaseEffects(rs);
|
||||
effectsList.add(mbs);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return effectsList;
|
||||
}
|
||||
|
||||
public MobBaseStats LOAD_STATS(int mobBaseUUID) {
|
||||
|
||||
MobBaseStats mobBaseStats = MobBaseStats.GetGenericStats();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_stats` WHERE `mobbaseUUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, mobBaseUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
mobBaseStats = new MobBaseStats(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return mobBaseStats;
|
||||
}
|
||||
|
||||
public void LOAD_ALL_MOBBASE_SPEEDS(MobBase mobBase) {
|
||||
|
||||
if (mobBase.getLoadID() == 0)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_race` WHERE `mobbaseID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, mobBase.getLoadID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
float walk = rs.getFloat("walkStandard");
|
||||
float walkCombat = rs.getFloat("walkCombat");
|
||||
float run = rs.getFloat("runStandard");
|
||||
float runCombat = rs.getFloat("runCombat");
|
||||
mobBase.updateSpeeds(walk, walkCombat, run, runCombat);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Mob;
|
||||
import engine.objects.Zone;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbMobHandler extends dbHandlerBase {
|
||||
|
||||
public dbMobHandler() {
|
||||
this.localClass = Mob.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Mob ADD_MOB(Mob toAdd) {
|
||||
|
||||
Mob mobile = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
|
||||
|
||||
preparedStatement.setLong(1, toAdd.getParentZoneID());
|
||||
preparedStatement.setInt(2, toAdd.getMobBaseID());
|
||||
preparedStatement.setInt(3, toAdd.getGuildUUID());
|
||||
preparedStatement.setFloat(4, toAdd.getSpawnX());
|
||||
preparedStatement.setFloat(5, toAdd.getSpawnY());
|
||||
preparedStatement.setFloat(6, toAdd.getSpawnZ());
|
||||
preparedStatement.setInt(7, 0);
|
||||
preparedStatement.setFloat(8, toAdd.getSpawnRadius());
|
||||
preparedStatement.setInt(9, toAdd.getTrueSpawnTime());
|
||||
|
||||
if (toAdd.getContract() != null)
|
||||
preparedStatement.setInt(10, toAdd.getContract().getContractID());
|
||||
else
|
||||
preparedStatement.setInt(10, 0);
|
||||
|
||||
preparedStatement.setInt(11, toAdd.getBuildingID());
|
||||
preparedStatement.setInt(12, toAdd.getLevel());
|
||||
preparedStatement.setString(13, toAdd.getFirstName());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
mobile = GET_MOB(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public boolean updateUpgradeTime(Mob mob, DateTime upgradeDateTime) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_mob SET upgradeDate=? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
if (upgradeDateTime == null)
|
||||
preparedStatement.setNull(1, java.sql.Types.DATE);
|
||||
else
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.getMillis()));
|
||||
|
||||
preparedStatement.setInt(2, mob.getObjectUUID());
|
||||
|
||||
preparedStatement.execute();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int DELETE_MOB(final Mob mob) {
|
||||
|
||||
int row_count = 0;
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, mob.getDBID());
|
||||
row_count = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
public void LOAD_PATROL_POINTS(Mob captain) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guards` WHERE `captainUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, captain.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
String name = rs.getString("name");
|
||||
Mob toCreate = Mob.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(), name);
|
||||
|
||||
if (toCreate == null)
|
||||
return;
|
||||
|
||||
if (toCreate != null)
|
||||
toCreate.setDeathTime(System.currentTimeMillis());
|
||||
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean ADD_TO_GUARDS(final long captainUID, final int mobBaseID, final String name, final int slot) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guards` (`captainUID`, `mobBaseID`,`name`, `slot`) VALUES (?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, captainUID);
|
||||
preparedStatement.setInt(2, mobBaseID);
|
||||
preparedStatement.setString(3, name);
|
||||
preparedStatement.setInt(4, slot);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_GUARDS(final long captainUID, final int mobBaseID, final int slot) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guards` WHERE `captainUID`=? AND `mobBaseID`=? AND `slot` =?")) {
|
||||
|
||||
preparedStatement.setLong(1, captainUID);
|
||||
preparedStatement.setInt(2, mobBaseID);
|
||||
preparedStatement.setInt(3, slot);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Mob> GET_ALL_MOBS_FOR_ZONE(Zone zone) {
|
||||
|
||||
ArrayList<Mob> mobileList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, zone.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mobileList = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return mobileList;
|
||||
}
|
||||
|
||||
public Mob GET_MOB(final int objectUUID) {
|
||||
|
||||
Mob mobile = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mobile = (Mob) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public int MOVE_MOB(long mobID, long parentID, float locX, float locY, float locZ) {
|
||||
|
||||
int row_count = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` INNER JOIN `obj_mob` On `object`.`UID` = `obj_mob`.`UID` SET `object`.`parent`=?, `obj_mob`.`mob_spawnX`=?, `obj_mob`.`mob_spawnY`=?, `obj_mob`.`mob_spawnZ`=? WHERE `obj_mob`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, parentID);
|
||||
preparedStatement.setFloat(2, locX);
|
||||
preparedStatement.setFloat(3, locY);
|
||||
preparedStatement.setFloat(4, locZ);
|
||||
preparedStatement.setLong(5, mobID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
row_count = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
public String SET_PROPERTY(final Mob m, String name, Object new_value) {
|
||||
|
||||
String result = "";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL mob_SETPROP(?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, m.getObjectUUID());
|
||||
preparedStatement.setString(2, name);
|
||||
preparedStatement.setString(3, String.valueOf(new_value));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
result = rs.getString("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.ProfitType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.NPC;
|
||||
import engine.objects.NPCProfits;
|
||||
import engine.objects.ProducedItem;
|
||||
import engine.objects.Zone;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbNPCHandler extends dbHandlerBase {
|
||||
|
||||
public dbNPCHandler() {
|
||||
this.localClass = NPC.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public NPC PERSIST(NPC toAdd) {
|
||||
|
||||
NPC npc = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `npc_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
|
||||
|
||||
Vector3fImmutable bindLocation;
|
||||
|
||||
if (toAdd.buildingUUID == 0)
|
||||
bindLocation = toAdd.bindLoc;
|
||||
else
|
||||
bindLocation = Vector3fImmutable.ZERO;
|
||||
|
||||
preparedStatement.setLong(1, toAdd.parentZoneUUID);
|
||||
preparedStatement.setString(2, toAdd.getName());
|
||||
preparedStatement.setInt(3, toAdd.contractUUID);
|
||||
preparedStatement.setInt(4, toAdd.guildUUID);
|
||||
preparedStatement.setFloat(5, bindLocation.x);
|
||||
preparedStatement.setFloat(6, bindLocation.y);
|
||||
preparedStatement.setFloat(7, bindLocation.z);
|
||||
preparedStatement.setInt(8, toAdd.level);
|
||||
preparedStatement.setFloat(9, toAdd.buyPercent);
|
||||
preparedStatement.setFloat(10, toAdd.sellPercent);
|
||||
|
||||
preparedStatement.setInt(11, Math.max(toAdd.buildingUUID, 0));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
npc = GET_NPC(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return npc;
|
||||
}
|
||||
|
||||
public int DELETE_NPC(final NPC npc) {
|
||||
|
||||
int row_count = 0;
|
||||
|
||||
npc.removeFromZone();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, npc.getDBID());
|
||||
row_count = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
public ArrayList<NPC> GET_ALL_NPCS_FOR_ZONE(Zone zone) {
|
||||
|
||||
ArrayList<NPC> npcList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_npc`.*, `object`.`parent` FROM `object` INNER JOIN `obj_npc` ON `obj_npc`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, zone.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
npcList = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return npcList;
|
||||
}
|
||||
|
||||
public NPC GET_NPC(final int objectUUID) {
|
||||
|
||||
NPC npc = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_npc`.*, `object`.`parent` FROM `object` INNER JOIN `obj_npc` ON `obj_npc`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
npc = (NPC) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return npc;
|
||||
}
|
||||
|
||||
public int MOVE_NPC(long npcID, long parentID, float locX, float locY, float locZ) {
|
||||
|
||||
int rowCount;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` INNER JOIN `obj_npc` On `object`.`UID` = `obj_npc`.`UID` SET `object`.`parent`=?, `obj_npc`.`npc_spawnX`=?, `obj_npc`.`npc_spawnY`=?, `obj_npc`.`npc_spawnZ`=? WHERE `obj_npc`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, parentID);
|
||||
preparedStatement.setFloat(2, locX);
|
||||
preparedStatement.setFloat(3, locY);
|
||||
preparedStatement.setFloat(4, locZ);
|
||||
preparedStatement.setLong(5, npcID);
|
||||
|
||||
rowCount = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return 0;
|
||||
}
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
public String SET_PROPERTY(final NPC n, String name, Object new_value) {
|
||||
|
||||
String result = "";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL npc_SETPROP(?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, n.getDBID());
|
||||
preparedStatement.setString(2, name);
|
||||
preparedStatement.setString(3, String.valueOf(new_value));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
result = rs.getString("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void updateDatabase(final NPC npc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_npc SET npc_name=?, npc_contractID=?, npc_typeID=?, npc_guildID=?,"
|
||||
+ " npc_spawnX=?, npc_spawnY=?, npc_spawnZ=?, npc_level=? ,"
|
||||
+ " npc_buyPercent=?, npc_sellPercent=?, npc_buildingID=? WHERE UID = ?")) {
|
||||
|
||||
preparedStatement.setString(1, npc.getName());
|
||||
preparedStatement.setInt(2, (npc.getContract() != null) ? npc.getContract().getObjectUUID() : 0);
|
||||
preparedStatement.setInt(3, 0);
|
||||
preparedStatement.setInt(4, (npc.getGuild() != null) ? npc.getGuild().getObjectUUID() : 0);
|
||||
preparedStatement.setFloat(5, npc.getBindLoc().x);
|
||||
preparedStatement.setFloat(6, npc.getBindLoc().y);
|
||||
preparedStatement.setFloat(7, npc.getBindLoc().z);
|
||||
preparedStatement.setShort(8, npc.getLevel());
|
||||
preparedStatement.setFloat(9, npc.getBuyPercent());
|
||||
preparedStatement.setFloat(10, npc.getSellPercent());
|
||||
preparedStatement.setInt(11, (npc.getBuilding() != null) ? npc.getBuilding().getObjectUUID() : 0);
|
||||
preparedStatement.setInt(12, npc.getDBID());
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateUpgradeTime(NPC npc, DateTime upgradeDateTime) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_npc SET upgradeDate=? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
if (upgradeDateTime == null)
|
||||
preparedStatement.setNull(1, java.sql.Types.DATE);
|
||||
else
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.getMillis()));
|
||||
|
||||
preparedStatement.setInt(2, npc.getObjectUUID());
|
||||
|
||||
preparedStatement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_MOBBASE(NPC npc, int mobBaseID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `npc_raceID`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, mobBaseID);
|
||||
preparedStatement.setLong(2, npc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_EQUIPSET(NPC npc, int equipSetID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `equipsetID`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, equipSetID);
|
||||
preparedStatement.setLong(2, npc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_NAME(NPC npc, String name) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `npc_name`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, name);
|
||||
preparedStatement.setLong(2, npc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_PIRATE_NAMES() {
|
||||
|
||||
String pirateName;
|
||||
int mobBase;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_piratenames")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
mobBase = rs.getInt("mobbase");
|
||||
pirateName = rs.getString("first_name");
|
||||
|
||||
// Handle new mobbbase entries
|
||||
|
||||
if (NPC._pirateNames.get(mobBase) == null)
|
||||
NPC._pirateNames.putIfAbsent(mobBase, new ArrayList<>());
|
||||
|
||||
// Insert name into proper arraylist
|
||||
|
||||
NPC._pirateNames.get(mobBase).add(pirateName);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("names read: " + recordsRead + " for "
|
||||
+ NPC._pirateNames.size() + " mobBases");
|
||||
}
|
||||
|
||||
public boolean ADD_TO_PRODUCTION_LIST(final long ID, final long npcUID, final long itemBaseID, DateTime dateTime, String prefix, String suffix, String name, boolean isRandom, int playerID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_npc_production` (`ID`,`npcUID`, `itemBaseID`,`dateToUpgrade`, `isRandom`, `prefix`, `suffix`, `name`,`playerID`) VALUES (?,?,?,?,?,?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, ID);
|
||||
preparedStatement.setLong(2, npcUID);
|
||||
preparedStatement.setLong(3, itemBaseID);
|
||||
preparedStatement.setTimestamp(4, new java.sql.Timestamp(dateTime.getMillis()));
|
||||
preparedStatement.setBoolean(5, isRandom);
|
||||
preparedStatement.setString(6, prefix);
|
||||
preparedStatement.setString(7, suffix);
|
||||
preparedStatement.setString(8, name);
|
||||
preparedStatement.setInt(9, playerID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_PRODUCTION_LIST(final long ID, final long npcUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_npc_production` WHERE `ID`=? AND `npcUID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, ID);
|
||||
preparedStatement.setLong(2, npcUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_ITEM_TO_INVENTORY(final long ID, final long npcUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_npc_production` SET `inForge`=? WHERE `ID`=? AND `npcUID`=?;")) {
|
||||
|
||||
preparedStatement.setByte(1, (byte) 0);
|
||||
preparedStatement.setLong(2, ID);
|
||||
preparedStatement.setLong(3, npcUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_ITEM_PRICE(final long ID, final long npcUID, int value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_npc_production` SET `value`=? WHERE `ID`=? AND `npcUID`=?;")) {
|
||||
|
||||
preparedStatement.setInt(1, value);
|
||||
preparedStatement.setLong(2, ID);
|
||||
preparedStatement.setLong(3, npcUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_ITEM_ID(final long ID, final long npcUID, final long value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_npc_production` SET `ID`=? WHERE `ID`=? AND `npcUID`=? LIMIT 1;")) {
|
||||
|
||||
preparedStatement.setLong(1, value);
|
||||
preparedStatement.setLong(2, ID);
|
||||
preparedStatement.setLong(3, npcUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_ALL_ITEMS_TO_PRODUCE(NPC npc) {
|
||||
|
||||
if (npc == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_npc_production` WHERE `npcUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, npc.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
ProducedItem producedItem = new ProducedItem(rs);
|
||||
npc.forgedItems.add(producedItem);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_PROFITS(NPC npc, ProfitType profitType, float value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_npc_profits` SET `" + profitType.dbField + "` = ? WHERE `npcUID`=?")) {
|
||||
|
||||
preparedStatement.setFloat(1, value);
|
||||
preparedStatement.setInt(2, npc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_NPC_PROFITS() {
|
||||
|
||||
NPCProfits npcProfit;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_npc_profits")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
npcProfit = new NPCProfits(rs);
|
||||
NPCProfits.ProfitCache.put(npcProfit.npcUID, npcProfit);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean CREATE_PROFITS(NPC npc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_npc_profits` (`npcUID`) VALUES (?)")) {
|
||||
|
||||
preparedStatement.setLong(1, npc.getObjectUUID());
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Petition;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbPetitionHandler extends dbHandlerBase {
|
||||
|
||||
public dbPetitionHandler() {
|
||||
|
||||
}
|
||||
|
||||
public void CREATE_PETITION_TABLE() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS dyn_petition " +
|
||||
" (petitionNumber INT AUTO_INCREMENT NOT NULL," +
|
||||
" petitionTime DATETIME," +
|
||||
" primaryType VARCHAR(50)," +
|
||||
" subType VARCHAR(50)," +
|
||||
" message VARCHAR(255)," +
|
||||
" accountID INT," +
|
||||
" accountName VARCHAR(255)," +
|
||||
" characterID INT," +
|
||||
" characterName VARCHAR(255)," +
|
||||
" location VARCHAR(255), " +
|
||||
" PRIMARY KEY (petitionNumber))" +
|
||||
" ENGINE = innodb ROW_FORMAT = DEFAULT;")) {
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void WRITE_PETITION_TO_TABLE(Petition petition) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
|
||||
//check that table exists
|
||||
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_petition` (`petitionTime`, `primaryType`, `subType`, `accountID`, `accountName`, `characterID`, `characterName`, `location`, `message`)" +
|
||||
" VALUES (?,?,?,?,?,?,?,?,?);")) {
|
||||
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
|
||||
preparedStatement.setString(2, Enum.PetitionType.values()[petition.primaryType].name());
|
||||
preparedStatement.setString(3, Enum.PetitionSubType.values()[petition.subType].name());
|
||||
preparedStatement.setInt(4, petition.reportAccount.getObjectUUID());
|
||||
preparedStatement.setString(5, petition.reportAccount.getUname());
|
||||
preparedStatement.setInt(6, petition.reportPlayer.getObjectUUID());
|
||||
preparedStatement.setString(7, petition.reportPlayer.getFirstName());
|
||||
preparedStatement.setString(8, petition.playerLocation.toString());
|
||||
|
||||
String messageCleaned = petition.message.substring(0, Math.min(petition.message.length(), 255));
|
||||
preparedStatement.setString(9, messageCleaned);
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error("CREATE PETITION FAILED: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,571 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractWorldObject;
|
||||
import engine.objects.Heraldry;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.PlayerFriends;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbPlayerCharacterHandler extends dbHandlerBase {
|
||||
|
||||
public dbPlayerCharacterHandler() {
|
||||
this.localClass = PlayerCharacter.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public PlayerCharacter ADD_PLAYER_CHARACTER(final PlayerCharacter toAdd) {
|
||||
|
||||
PlayerCharacter playerCharacter = null;
|
||||
|
||||
if (toAdd.getAccount() == null)
|
||||
return null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `character_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
|
||||
|
||||
preparedStatement.setLong(1, toAdd.getAccount().getObjectUUID());
|
||||
preparedStatement.setString(2, toAdd.getFirstName());
|
||||
preparedStatement.setString(3, toAdd.getLastName());
|
||||
preparedStatement.setInt(4, toAdd.getRace().getRaceRuneID());
|
||||
preparedStatement.setInt(5, toAdd.getBaseClass().getObjectUUID());
|
||||
preparedStatement.setInt(6, toAdd.getStrMod());
|
||||
preparedStatement.setInt(7, toAdd.getDexMod());
|
||||
preparedStatement.setInt(8, toAdd.getConMod());
|
||||
preparedStatement.setInt(9, toAdd.getIntMod());
|
||||
preparedStatement.setInt(10, toAdd.getSpiMod());
|
||||
preparedStatement.setInt(11, toAdd.getExp());
|
||||
preparedStatement.setInt(12, toAdd.getSkinColor());
|
||||
preparedStatement.setInt(13, toAdd.getHairColor());
|
||||
preparedStatement.setByte(14, toAdd.getHairStyle());
|
||||
preparedStatement.setInt(15, toAdd.getBeardColor());
|
||||
preparedStatement.setByte(16, toAdd.getBeardStyle());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
playerCharacter = GET_PLAYER_CHARACTER(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return playerCharacter;
|
||||
}
|
||||
|
||||
public boolean SET_IGNORE_LIST(int sourceID, int targetID, boolean toIgnore, String charName) {
|
||||
|
||||
String queryString = "";
|
||||
|
||||
if (toIgnore)
|
||||
queryString = "INSERT INTO `dyn_character_ignore` (`accountUID`, `ignoringUID`, `characterName`) VALUES (?, ?, ?)";
|
||||
else
|
||||
queryString = "DELETE FROM `dyn_character_ignore` WHERE `accountUID` = ? && `ignoringUID` = ?";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(queryString)) {
|
||||
|
||||
preparedStatement.setLong(1, sourceID);
|
||||
preparedStatement.setLong(2, targetID);
|
||||
|
||||
if (toIgnore)
|
||||
preparedStatement.setString(3, charName);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ArrayList<PlayerCharacter> GET_CHARACTERS_FOR_ACCOUNT(final int id) {
|
||||
|
||||
ArrayList<PlayerCharacter> characterList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`parent`=? && `obj_character`.`char_isActive`='1';")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
characterList = getObjectsFromRs(rs, 10);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterList;
|
||||
}
|
||||
|
||||
public ArrayList<PlayerCharacter> GET_ALL_CHARACTERS() {
|
||||
|
||||
ArrayList<PlayerCharacter> characterList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `obj_character`.`char_isActive`='1';")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
characterList = getObjectsFromRs(rs, 2000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterList;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>getFirstName</code> looks up the first name of a PlayerCharacter by
|
||||
* first checking the GOM cache and then querying the database.
|
||||
* PlayerCharacter objects that are not already cached won't be instantiated
|
||||
* and cached.
|
||||
*/
|
||||
|
||||
public ConcurrentHashMap<Integer, String> GET_IGNORE_LIST(final int objectUUID, final boolean skipActiveCheck) {
|
||||
|
||||
ConcurrentHashMap<Integer, String> ignoreList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_ignore` WHERE `accountUID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int ignoreCharacterID = rs.getInt("ignoringUID");
|
||||
|
||||
if (ignoreCharacterID == 0)
|
||||
continue;
|
||||
|
||||
String name = rs.getString("characterName");
|
||||
ignoreList.put(ignoreCharacterID, name);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return ignoreList;
|
||||
}
|
||||
|
||||
public PlayerCharacter GET_PLAYER_CHARACTER(final int objectUUID) {
|
||||
|
||||
if (objectUUID == 0)
|
||||
return null;
|
||||
|
||||
PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, objectUUID);
|
||||
|
||||
if (playerCharacter != null)
|
||||
return playerCharacter;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
playerCharacter = (PlayerCharacter) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return playerCharacter;
|
||||
}
|
||||
|
||||
public boolean IS_CHARACTER_NAME_UNIQUE(final String firstName) {
|
||||
|
||||
boolean unique = true;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `char_firstname` FROM `obj_character` WHERE `char_isActive`=1 && `char_firstname`=?")) {
|
||||
|
||||
preparedStatement.setString(1, firstName);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
unique = false;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return unique;
|
||||
}
|
||||
|
||||
public boolean UPDATE_NAME(String oldFirstName, String newFirstName, String newLastName) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_firstname`=?, `char_lastname`=? WHERE `char_firstname`=? AND `char_isActive`='1'")) {
|
||||
|
||||
preparedStatement.setString(1, newFirstName);
|
||||
preparedStatement.setString(2, newLastName);
|
||||
preparedStatement.setString(3, oldFirstName);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_DELETED(final PlayerCharacter pc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, !pc.isDeleted());
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_ACTIVE(final PlayerCharacter pc, boolean status) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, status);
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_BIND_BUILDING(final PlayerCharacter pc, int bindBuildingID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_bindBuilding`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, bindBuildingID);
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_ANNIVERSERY(final PlayerCharacter pc, boolean flag) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `anniversery`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, flag);
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean UPDATE_CHARACTER_EXPERIENCE(final PlayerCharacter pc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_experience`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, pc.getExp());
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_GUILD(final PlayerCharacter pc, int guildUUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guildUID`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, guildUUID);
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_CHARACTER_STATS(final PlayerCharacter pc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_strMod`=?, `char_dexMod`=?, `char_conMod`=?, `char_intMod`=?, `char_spiMod`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, pc.getStrMod());
|
||||
preparedStatement.setInt(2, pc.getDexMod());
|
||||
preparedStatement.setInt(3, pc.getConMod());
|
||||
preparedStatement.setInt(4, pc.getIntMod());
|
||||
preparedStatement.setInt(5, pc.getSpiMod());
|
||||
preparedStatement.setLong(6, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String SET_PROPERTY(final PlayerCharacter playerCharacter, String name, Object new_value) {
|
||||
|
||||
String result = "";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL character_SETPROP(?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, playerCharacter.getObjectUUID());
|
||||
preparedStatement.setString(2, name);
|
||||
preparedStatement.setString(3, String.valueOf(new_value));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
result = rs.getString("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean SET_PROMOTION_CLASS(PlayerCharacter player, int promotionClassID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_promotionClassID`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setInt(1, promotionClassID);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_INNERCOUNCIL(PlayerCharacter player, boolean isInnerCouncil) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setBoolean(1, isInnerCouncil);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_FULL_MEMBER(PlayerCharacter player, boolean isFullMember) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isFullMember`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setBoolean(1, isFullMember);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_TAX_COLLECTOR(PlayerCharacter player, boolean isTaxCollector) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isTaxCollector`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setBoolean(1, isTaxCollector);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_RECRUITER(PlayerCharacter player, boolean isRecruiter) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isRecruiter`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setBoolean(1, isRecruiter);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_GUILD_TITLE(PlayerCharacter player, int title) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setInt(1, title);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ADD_FRIEND(int source, long friend) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_friends` (`playerUID`, `friendUID`) VALUES (?, ?)")) {
|
||||
|
||||
preparedStatement.setLong(1, source);
|
||||
preparedStatement.setLong(2, friend);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_FRIEND(int source, int friend) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_friends` WHERE (`playerUID`=?) AND (`friendUID`=?)")) {
|
||||
|
||||
preparedStatement.setLong(1, source);
|
||||
preparedStatement.setLong(2, friend);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void LOAD_PLAYER_FRIENDS() {
|
||||
|
||||
PlayerFriends playerFriend;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_friends")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
playerFriend = new PlayerFriends(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean ADD_HERALDY(int source, AbstractWorldObject character) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_heraldy` (`playerUID`, `characterUID`,`characterType`) VALUES (?, ?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, source);
|
||||
preparedStatement.setLong(2, character.getObjectUUID());
|
||||
preparedStatement.setInt(3, character.getObjectType().ordinal());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_HERALDY(int source, int characterUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_heraldy` WHERE (`playerUID`=?) AND (`characterUID`=?)")) {
|
||||
|
||||
preparedStatement.setLong(1, source);
|
||||
preparedStatement.setLong(2, characterUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void LOAD_HERALDY() {
|
||||
|
||||
Heraldry heraldy;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_heraldy")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
heraldy = new Heraldry(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.PowersManager;
|
||||
import engine.objects.Mob;
|
||||
import engine.objects.PreparedStatementShared;
|
||||
import engine.powers.EffectsBase;
|
||||
import engine.powers.MobPowerEntry;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class dbPowerHandler extends dbHandlerBase {
|
||||
|
||||
public dbPowerHandler() {
|
||||
this.localClass = Mob.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public static void addAllSourceTypes() {
|
||||
PreparedStatementShared ps = null;
|
||||
try {
|
||||
ps = new PreparedStatementShared("SELECT * FROM static_power_sourcetype");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
String IDString, source;
|
||||
while (rs.next()) {
|
||||
IDString = rs.getString("IDString");
|
||||
int token = DbManager.hasher.SBStringHash(IDString);
|
||||
|
||||
|
||||
source = rs.getString("source").replace("-", "").trim();
|
||||
Enum.EffectSourceType effectSourceType = Enum.EffectSourceType.GetEffectSourceType(source);
|
||||
|
||||
if (EffectsBase.effectSourceTypeMap.containsKey(token) == false)
|
||||
EffectsBase.effectSourceTypeMap.put(token, new HashSet<>());
|
||||
|
||||
EffectsBase.effectSourceTypeMap.get(token).add(effectSourceType);
|
||||
}
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
ps.release();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addAllAnimationOverrides() {
|
||||
PreparedStatementShared ps = null;
|
||||
try {
|
||||
ps = new PreparedStatementShared("SELECT * FROM static_power_animation_override");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
String IDString;
|
||||
int animation;
|
||||
while (rs.next()) {
|
||||
IDString = rs.getString("IDString");
|
||||
|
||||
EffectsBase eb = PowersManager.getEffectByIDString(IDString);
|
||||
if (eb != null)
|
||||
IDString = eb.getIDString();
|
||||
|
||||
animation = rs.getInt("animation");
|
||||
PowersManager.AnimationOverrides.put(IDString, animation);
|
||||
|
||||
}
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
ps.release();
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<Integer, ArrayList<MobPowerEntry>> LOAD_MOB_POWERS() {
|
||||
|
||||
HashMap<Integer, ArrayList<MobPowerEntry>> mobPowers = new HashMap<>();
|
||||
MobPowerEntry mobPowerEntry;
|
||||
|
||||
int mobbaseID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_mobbase_powers ORDER BY `id` ASC;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
mobbaseID = rs.getInt("mobbaseUUID");
|
||||
mobPowerEntry = new MobPowerEntry(rs);
|
||||
|
||||
if (mobPowers.get(mobbaseID) == null) {
|
||||
ArrayList<MobPowerEntry> powerList = new ArrayList<>();
|
||||
powerList.add(mobPowerEntry);
|
||||
mobPowers.put(mobbaseID, powerList);
|
||||
} else {
|
||||
ArrayList<MobPowerEntry> powerList = mobPowers.get(mobbaseID);
|
||||
powerList.add(mobPowerEntry);
|
||||
mobPowers.put(mobbaseID, powerList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return mobPowers;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + mobPowers.size());
|
||||
return mobPowers;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.PromotionClass;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbPromotionClassHandler extends dbHandlerBase {
|
||||
|
||||
public dbPromotionClassHandler() {
|
||||
this.localClass = PromotionClass.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<Integer> GET_ALLOWED_RUNES(final PromotionClass pc) {
|
||||
|
||||
ArrayList<Integer> runeList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_promotionrunereq` WHERE `promoID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, pc.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
runeList.add(rs.getInt("runereqID"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
|
||||
}
|
||||
return runeList;
|
||||
}
|
||||
|
||||
public PromotionClass GET_PROMOTION_CLASS(final int objectUUID) {
|
||||
|
||||
PromotionClass promotionClass = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_promotion` WHERE `ID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
promotionClass = (PromotionClass) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return promotionClass;
|
||||
}
|
||||
|
||||
public ArrayList<PromotionClass> GET_ALL_PROMOTIONS() {
|
||||
|
||||
ArrayList<PromotionClass> promotionList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_promotion`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
promotionList = getObjectsFromRs(rs, 30);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return promotionList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Race;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbRaceHandler extends dbHandlerBase {
|
||||
|
||||
public dbRaceHandler() {
|
||||
}
|
||||
|
||||
public HashSet<Integer> BEARD_COLORS_FOR_RACE(final int id) {
|
||||
|
||||
HashSet<Integer> integerSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `color` FROM `static_rune_racebeardcolor` WHERE `RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
integerSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return integerSet;
|
||||
}
|
||||
|
||||
public HashSet<Integer> BEARD_STYLES_FOR_RACE(final int id) {
|
||||
|
||||
HashSet<Integer> integerSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `beardStyle` FROM `static_rune_racebeardstyle` WHERE `RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
integerSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return integerSet;
|
||||
}
|
||||
|
||||
public HashSet<Integer> HAIR_COLORS_FOR_RACE(final int id) {
|
||||
|
||||
HashSet<Integer> integerSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `color` FROM `static_rune_racehaircolor` WHERE `RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
integerSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return integerSet;
|
||||
|
||||
}
|
||||
|
||||
public HashSet<Integer> HAIR_STYLES_FOR_RACE(final int id) {
|
||||
|
||||
HashSet<Integer> integerSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `hairStyle` FROM `static_rune_racehairstyle` WHERE `RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
integerSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return integerSet;
|
||||
|
||||
}
|
||||
|
||||
public HashSet<Integer> SKIN_COLOR_FOR_RACE(final int id) {
|
||||
|
||||
HashSet<Integer> integerSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `color` FROM `static_rune_raceskincolor` WHERE `RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
integerSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return integerSet;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<Integer, Race> LOAD_ALL_RACES() {
|
||||
|
||||
ConcurrentHashMap<Integer, Race> races;
|
||||
Race thisRace;
|
||||
|
||||
races = new ConcurrentHashMap<>();
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_race")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
thisRace = new Race(rs);
|
||||
|
||||
races.put(thisRace.getRaceRuneID(), thisRace);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + races.size());
|
||||
return races;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Realm;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbRealmHandler extends dbHandlerBase {
|
||||
|
||||
public dbRealmHandler() {
|
||||
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<Integer, Realm> LOAD_ALL_REALMS() {
|
||||
|
||||
ConcurrentHashMap<Integer, Realm> realmList;
|
||||
Realm thisRealm;
|
||||
|
||||
realmList = new ConcurrentHashMap<>();
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM obj_realm")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
recordsRead++;
|
||||
thisRealm = new Realm(rs);
|
||||
realmList.put(thisRealm.getRealmID(), thisRealm);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + realmList.size());
|
||||
return realmList;
|
||||
}
|
||||
|
||||
public void REALM_UPDATE(Realm realm) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL realm_UPDATE(?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setInt(1, realm.getRealmID());
|
||||
preparedStatement.setInt(2, (realm.getRulingCity() == null) ? 0 : realm.getRulingCity().getObjectUUID());
|
||||
preparedStatement.setInt(3, realm.getCharterType());
|
||||
|
||||
if (realm.ruledSince != null)
|
||||
preparedStatement.setTimestamp(4, Timestamp.valueOf(realm.ruledSince));
|
||||
else
|
||||
preparedStatement.setNull(4, java.sql.Types.DATE);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Resists;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbResistHandler extends dbHandlerBase {
|
||||
|
||||
public dbResistHandler() {
|
||||
|
||||
}
|
||||
|
||||
public Resists GET_RESISTS_FOR_MOB(int resistID) {
|
||||
|
||||
Resists resists = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mob_resists` WHERE `ID` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, resistID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
resists = new Resists(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return resists;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.RuneBaseAttribute;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbRuneBaseAttributeHandler extends dbHandlerBase {
|
||||
|
||||
public dbRuneBaseAttributeHandler() {
|
||||
this.localClass = RuneBaseAttribute.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<RuneBaseAttribute> GET_ATTRIBUTES_FOR_RUNEBASE() {
|
||||
|
||||
ArrayList<RuneBaseAttribute> runeBaseAttributesList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebaseattribute`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
runeBaseAttributesList = getObjectsFromRs(rs, 10);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return runeBaseAttributesList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.RuneBaseEffect;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbRuneBaseEffectHandler extends dbHandlerBase {
|
||||
|
||||
public dbRuneBaseEffectHandler() {
|
||||
this.localClass = RuneBaseEffect.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<RuneBaseEffect> GET_EFFECTS_FOR_RUNEBASE(int id) {
|
||||
|
||||
ArrayList<RuneBaseEffect> runeBaseEffectsList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect` WHERE `runeID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
runeBaseEffectsList = getObjectsFromRs(rs, 250);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return runeBaseEffectsList;
|
||||
}
|
||||
|
||||
public ArrayList<RuneBaseEffect> GET_ALL_RUNEBASE_EFFECTS() {
|
||||
|
||||
ArrayList<RuneBaseEffect> runeBaseEffectsList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
runeBaseEffectsList = getObjectsFromRs(rs, 250);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return runeBaseEffectsList;
|
||||
}
|
||||
|
||||
//This calls from cache only. Call this AFTER caching all runebase effects;
|
||||
|
||||
public HashMap<Integer, ArrayList<RuneBaseEffect>> LOAD_BASEEFFECTS_FOR_RUNEBASE() {
|
||||
|
||||
HashMap<Integer, ArrayList<RuneBaseEffect>> runeBaseEffectSet;
|
||||
runeBaseEffectSet = new HashMap<>();
|
||||
|
||||
for (AbstractGameObject runeBaseEffect : DbManager.getList(GameObjectType.RuneBaseEffect)) {
|
||||
|
||||
int runeBaseID = ((RuneBaseEffect) runeBaseEffect).getRuneBaseID();
|
||||
if (runeBaseEffectSet.get(runeBaseID) == null) {
|
||||
ArrayList<RuneBaseEffect> runeBaseEffectList = new ArrayList<>();
|
||||
runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect);
|
||||
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
|
||||
} else {
|
||||
ArrayList<RuneBaseEffect> runeBaseEffectList = runeBaseEffectSet.get(runeBaseID);
|
||||
runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect);
|
||||
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
|
||||
}
|
||||
}
|
||||
return runeBaseEffectSet;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.RuneBase;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbRuneBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbRuneBaseHandler() {
|
||||
this.localClass = RuneBase.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public void GET_RUNE_REQS(final RuneBase rb) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runereq` WHERE `runeID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, rb.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int type = rs.getInt("type");
|
||||
|
||||
switch (type) {
|
||||
case 1:
|
||||
rb.getRace().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
|
||||
break;
|
||||
case 2:
|
||||
rb.getBaseClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
|
||||
break;
|
||||
case 3:
|
||||
rb.getPromotionClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
|
||||
break;
|
||||
case 4:
|
||||
rb.getDiscipline().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
|
||||
break;
|
||||
case 5:
|
||||
rb.getOverwrite().add(rs.getInt("requiredRuneID"));
|
||||
break;
|
||||
case 6:
|
||||
rb.setLevelRequired(rs.getInt("requiredRuneID"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public RuneBase GET_RUNEBASE(final int id) {
|
||||
|
||||
RuneBase runeBase = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase` WHERE `ID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
runeBase = (RuneBase) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return runeBase;
|
||||
}
|
||||
|
||||
public ArrayList<RuneBase> LOAD_ALL_RUNEBASES() {
|
||||
|
||||
ArrayList<RuneBase> runeBasesList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
runeBasesList = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return runeBasesList;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() {
|
||||
|
||||
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
|
||||
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_baseclassrune")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
int baseClassID = rs.getInt("BaseClassesID");
|
||||
int runeBaseID = rs.getInt("RuneBaseID");
|
||||
|
||||
if (runeSets.get(baseClassID) == null) {
|
||||
ArrayList<Integer> runeList = new ArrayList<>();
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(baseClassID, runeList);
|
||||
} else {
|
||||
ArrayList<Integer> runeList = runeSets.get(baseClassID);
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(baseClassID, runeList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
|
||||
|
||||
return runeSets;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_RACE() {
|
||||
|
||||
HashMap<Integer, ArrayList<Integer>> runeSets;
|
||||
|
||||
runeSets = new HashMap<>();
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_racerune")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
int raceID = rs.getInt("RaceID");
|
||||
int runeBaseID = rs.getInt("RuneBaseID");
|
||||
|
||||
if (runeSets.get(raceID) == null) {
|
||||
ArrayList<Integer> runeList = new ArrayList<>();
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(raceID, runeList);
|
||||
} else {
|
||||
ArrayList<Integer> runeList = runeSets.get(raceID);
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(raceID, runeList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
|
||||
return runeSets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.Portal;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbRunegateHandler extends dbHandlerBase {
|
||||
|
||||
public dbRunegateHandler() {
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Integer> GET_RUNEGATE_LIST() {
|
||||
|
||||
ArrayList<Integer> gateList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT DISTINCT `sourceBuilding` FROM `static_runegate_portals`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
gateList.add(rs.getInt("sourceBuilding"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return gateList;
|
||||
}
|
||||
|
||||
public ArrayList<Portal> GET_PORTAL_LIST(int gateUID) {
|
||||
|
||||
ArrayList<Portal> portalList = new ArrayList<>();
|
||||
Building sourceBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, gateUID);
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_runegate_portals` WHERE `sourceBuilding` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, gateUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int targetBuildingID = rs.getInt("targetBuilding");
|
||||
Building targetBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, targetBuildingID);
|
||||
Enum.PortalType portalType = Enum.PortalType.valueOf(rs.getString("portalType"));
|
||||
Portal portal = new Portal(sourceBuilding, portalType, targetBuilding);
|
||||
portalList.add(portal);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return portalList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.ProtectionState;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.Shrine;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbShrineHandler extends dbHandlerBase {
|
||||
|
||||
public dbShrineHandler() {
|
||||
this.localClass = Shrine.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException {
|
||||
|
||||
String type = rs.getString("type");
|
||||
|
||||
switch (type) {
|
||||
case "building":
|
||||
Building building = new Building(rs);
|
||||
DbManager.addToCache(building);
|
||||
list.add(building);
|
||||
break;
|
||||
case "shrine":
|
||||
Shrine shrine = new Shrine(rs);
|
||||
DbManager.addToCache(shrine);
|
||||
list.add(shrine);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<AbstractGameObject> CREATE_SHRINE(int parentZoneID, int OwnerUUID, String name, int meshUUID,
|
||||
Vector3fImmutable location, float meshScale, int currentHP,
|
||||
ProtectionState protectionState, int currentGold, int rank,
|
||||
DateTime upgradeDate, int blueprintUUID, float w, float rotY, String shrineType) {
|
||||
|
||||
ArrayList<AbstractGameObject> shrineList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `shrine_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?,?);")) {
|
||||
|
||||
preparedStatement.setInt(1, parentZoneID);
|
||||
preparedStatement.setInt(2, OwnerUUID);
|
||||
preparedStatement.setString(3, name);
|
||||
preparedStatement.setInt(4, meshUUID);
|
||||
preparedStatement.setFloat(5, location.x);
|
||||
preparedStatement.setFloat(6, location.y);
|
||||
preparedStatement.setFloat(7, location.z);
|
||||
preparedStatement.setFloat(8, meshScale);
|
||||
preparedStatement.setInt(9, currentHP);
|
||||
preparedStatement.setString(10, protectionState.name());
|
||||
preparedStatement.setInt(11, currentGold);
|
||||
preparedStatement.setInt(12, rank);
|
||||
|
||||
if (upgradeDate != null)
|
||||
preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis()));
|
||||
else
|
||||
preparedStatement.setNull(13, java.sql.Types.DATE);
|
||||
|
||||
preparedStatement.setInt(14, blueprintUUID);
|
||||
preparedStatement.setFloat(15, w);
|
||||
preparedStatement.setFloat(16, rotY);
|
||||
preparedStatement.setString(17, shrineType);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
ResultSet rs = preparedStatement.getResultSet();
|
||||
|
||||
while (rs.next())
|
||||
addObject(shrineList, rs);
|
||||
|
||||
while (preparedStatement.getMoreResults()) {
|
||||
rs = preparedStatement.getResultSet();
|
||||
|
||||
while (rs.next())
|
||||
addObject(shrineList, rs);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return shrineList;
|
||||
}
|
||||
|
||||
public boolean updateFavors(Shrine shrine, int amount, int oldAmount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_shrine` SET `shrine_favors`=? WHERE `UID` = ? AND `shrine_favors` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setLong(2, shrine.getObjectUUID());
|
||||
preparedStatement.setInt(3, oldAmount);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_ALL_SHRINES() {
|
||||
|
||||
Shrine shrine;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_shrine`.*, `object`.`parent`, `object`.`type` FROM `object` LEFT JOIN `obj_shrine` ON `object`.`UID` = `obj_shrine`.`UID` WHERE `object`.`type` = 'shrine';")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
shrine = new Shrine(rs);
|
||||
shrine.getShrineType().addShrineToServerList(shrine);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.MaxSkills;
|
||||
import engine.objects.SkillsBase;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbSkillBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbSkillBaseHandler() {
|
||||
this.localClass = SkillsBase.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public SkillsBase GET_BASE(final int objectUUID) {
|
||||
|
||||
SkillsBase skillsBase = (SkillsBase) DbManager.getFromCache(GameObjectType.SkillsBase, objectUUID);
|
||||
|
||||
if (skillsBase != null)
|
||||
return skillsBase;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_skill_skillsbase WHERE ID = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
skillsBase = (SkillsBase) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
SkillsBase.putInCache(skillsBase);
|
||||
return skillsBase;
|
||||
}
|
||||
|
||||
public SkillsBase GET_BASE_BY_NAME(String name) {
|
||||
|
||||
SkillsBase skillsBase = SkillsBase.getFromCache(name);
|
||||
|
||||
if (skillsBase != null)
|
||||
return skillsBase;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_skill_skillsbase WHERE name = ?")) {
|
||||
|
||||
preparedStatement.setString(1, name);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
skillsBase = (SkillsBase) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
SkillsBase.putInCache(skillsBase);
|
||||
return skillsBase;
|
||||
}
|
||||
|
||||
public SkillsBase GET_BASE_BY_TOKEN(final int token) {
|
||||
|
||||
SkillsBase skillsBase = SkillsBase.getFromCache(token);
|
||||
|
||||
if (skillsBase != null)
|
||||
return skillsBase;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_skill_skillsbase WHERE token = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, token);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
skillsBase = (SkillsBase) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
SkillsBase.putInCache(skillsBase);
|
||||
return skillsBase;
|
||||
}
|
||||
|
||||
public void LOAD_ALL_MAX_SKILLS_FOR_CONTRACT() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_maxskills`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
MaxSkills maxSKills = new MaxSkills(rs);
|
||||
|
||||
if (MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()) == null) {
|
||||
ArrayList<MaxSkills> newMaxSkillsList = new ArrayList<>();
|
||||
newMaxSkillsList.add(maxSKills);
|
||||
MaxSkills.MaxSkillsSet.put(maxSKills.getRuneID(), newMaxSkillsList);
|
||||
} else
|
||||
MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()).add(maxSKills);
|
||||
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void LOAD_ALL_RUNE_SKILLS() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_skill_skillsgranted`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
int runeID = rs.getInt("runeID");
|
||||
int token = rs.getInt("token");
|
||||
int amount = rs.getInt("amount");
|
||||
|
||||
if (SkillsBase.runeSkillsCache.get(runeID) == null)
|
||||
SkillsBase.runeSkillsCache.put(runeID, new HashMap<>());
|
||||
|
||||
SkillsBase.runeSkillsCache.get(runeID).put(token, amount);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.SkillReq;
|
||||
import engine.powers.PowersBase;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbSkillReqHandler extends dbHandlerBase {
|
||||
|
||||
public dbSkillReqHandler() {
|
||||
this.localClass = SkillReq.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public static ArrayList<PowersBase> getAllPowersBase() {
|
||||
|
||||
ArrayList<PowersBase> powerBaseList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_powerbase")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
PowersBase toAdd = new PowersBase(rs);
|
||||
powerBaseList.add(toAdd);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return powerBaseList;
|
||||
}
|
||||
|
||||
public static void getFailConditions(HashMap<String, PowersBase> powers) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT IDString, type FROM static_power_failcondition where powerOrEffect = 'Power'")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
String type = rs.getString("type");
|
||||
String IDString = rs.getString("IDString");
|
||||
PowersBase pb = powers.get(IDString);
|
||||
|
||||
if (pb != null)
|
||||
switch (type) {
|
||||
case "CastSpell":
|
||||
pb.cancelOnCastSpell = true;
|
||||
break;
|
||||
case "TakeDamage":
|
||||
pb.cancelOnTakeDamage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<SkillReq> GET_REQS_FOR_RUNE(final int objectUUID) {
|
||||
|
||||
ArrayList<SkillReq> skillReqsList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_skill_skillreq` WHERE `runeID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
skillReqsList = getObjectsFromRs(rs, 5);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return skillReqsList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.VendorDialog;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbVendorDialogHandler extends dbHandlerBase {
|
||||
|
||||
public dbVendorDialogHandler() {
|
||||
this.localClass = VendorDialog.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public VendorDialog GET_VENDORDIALOG(final int objectUUID) {
|
||||
|
||||
VendorDialog vendorDialog = (VendorDialog) DbManager.getFromCache(Enum.GameObjectType.VendorDialog, objectUUID);
|
||||
|
||||
if (vendorDialog != null)
|
||||
return vendorDialog;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_vendordialog` WHERE `ID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
vendorDialog = (VendorDialog) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return vendorDialog;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,555 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.Enum.ProtectionState;
|
||||
import engine.Enum.TransactionType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbWarehouseHandler extends dbHandlerBase {
|
||||
|
||||
private static final ConcurrentHashMap<Integer, String> columns = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
public dbWarehouseHandler() {
|
||||
this.localClass = Warehouse.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
|
||||
}
|
||||
|
||||
public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException {
|
||||
String type = rs.getString("type");
|
||||
switch (type) {
|
||||
case "building":
|
||||
Building building = new Building(rs);
|
||||
DbManager.addToCache(building);
|
||||
list.add(building);
|
||||
break;
|
||||
case "warehouse":
|
||||
Warehouse warehouse = new Warehouse(rs);
|
||||
DbManager.addToCache(warehouse);
|
||||
list.add(warehouse);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<AbstractGameObject> CREATE_WAREHOUSE(int parentZoneID, int OwnerUUID, String name, int meshUUID,
|
||||
Vector3fImmutable location, float meshScale, int currentHP,
|
||||
ProtectionState protectionState, int currentGold, int rank,
|
||||
DateTime upgradeDate, int blueprintUUID, float w, float rotY) {
|
||||
|
||||
ArrayList<AbstractGameObject> warehouseList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `WAREHOUSE_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?);")) {
|
||||
|
||||
preparedStatement.setInt(1, parentZoneID);
|
||||
preparedStatement.setInt(2, OwnerUUID);
|
||||
preparedStatement.setString(3, name);
|
||||
preparedStatement.setInt(4, meshUUID);
|
||||
preparedStatement.setFloat(5, location.x);
|
||||
preparedStatement.setFloat(6, location.y);
|
||||
preparedStatement.setFloat(7, location.z);
|
||||
preparedStatement.setFloat(8, meshScale);
|
||||
preparedStatement.setInt(9, currentHP);
|
||||
preparedStatement.setString(10, protectionState.name());
|
||||
preparedStatement.setInt(11, currentGold);
|
||||
preparedStatement.setInt(12, rank);
|
||||
|
||||
if (upgradeDate != null)
|
||||
preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis()));
|
||||
else
|
||||
preparedStatement.setNull(13, java.sql.Types.DATE);
|
||||
|
||||
preparedStatement.setInt(14, blueprintUUID);
|
||||
preparedStatement.setFloat(15, w);
|
||||
preparedStatement.setFloat(16, rotY);
|
||||
|
||||
preparedStatement.execute();
|
||||
ResultSet rs = preparedStatement.getResultSet();
|
||||
|
||||
while (rs.next())
|
||||
addObject(warehouseList, rs);
|
||||
|
||||
while (preparedStatement.getMoreResults()) {
|
||||
rs = preparedStatement.getResultSet();
|
||||
|
||||
while (rs.next())
|
||||
addObject(warehouseList, rs);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return warehouseList;
|
||||
}
|
||||
|
||||
public boolean updateLocks(final Warehouse wh, long locks) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_locks`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, locks);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateGold(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_gold`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateStone(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_stone`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateTruesteel(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_truesteel`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateIron(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_iron`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateAdamant(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_adamant`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateLumber(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_lumber`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateOak(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_oak`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateBronzewood(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_bronzewood`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateMandrake(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_mandrake`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateCoal(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_coal`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateAgate(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_agate`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateDiamond(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_diamond`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateOnyx(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_onyx`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateAzoth(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_azoth`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateOrichalk(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_orichalk`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateAntimony(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_antimony`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateSulfur(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_sulfur`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateQuicksilver(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_quicksilver`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateGalvor(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_galvor`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateWormwood(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_wormwood`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateObsidian(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_obsidian`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateBloodstone(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_bloodstone`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateMithril(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_mithril`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CREATE_TRANSACTION(int warehouseBuildingID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount, DateTime date) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_warehouse_transactions` (`warehouseUID`, `targetType`,`targetUID`, `type`,`resource`,`amount`,`date` ) VALUES (?,?,?,?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, warehouseBuildingID);
|
||||
preparedStatement.setString(2, targetType.name());
|
||||
preparedStatement.setLong(3, targetUUID);
|
||||
preparedStatement.setString(4, transactionType.name());
|
||||
preparedStatement.setString(5, resource.name());
|
||||
preparedStatement.setInt(6, amount);
|
||||
preparedStatement.setTimestamp(7, new java.sql.Timestamp(date.getMillis()));
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ArrayList<Transaction> GET_TRANSACTIONS_FOR_WAREHOUSE(final int warehouseUUID) {
|
||||
|
||||
ArrayList<Transaction> transactionsList = new ArrayList<>();
|
||||
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_warehouse_transactions WHERE `warehouseUID` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, warehouseUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Transaction transactions = new Transaction(rs);
|
||||
transactionsList.add(transactions);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return transactionsList;
|
||||
}
|
||||
|
||||
public void LOAD_ALL_WAREHOUSES() {
|
||||
|
||||
Warehouse warehouse;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_warehouse`.*, `object`.`parent`, `object`.`type` FROM `object` LEFT JOIN `obj_warehouse` ON `object`.`UID` = `obj_warehouse`.`UID` WHERE `object`.`type` = 'warehouse';")) {
|
||||
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
warehouse = new Warehouse(rs);
|
||||
warehouse.runAfterLoad();
|
||||
warehouse.loadAllTransactions();
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.math.Vector2f;
|
||||
import engine.objects.Zone;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbZoneHandler extends dbHandlerBase {
|
||||
|
||||
public dbZoneHandler() {
|
||||
this.localClass = Zone.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<Zone> GET_ALL_NODES(Zone zone) {
|
||||
ArrayList<Zone> wsmList = new ArrayList<>();
|
||||
wsmList.addAll(zone.getNodes());
|
||||
if (zone.absX == 0.0f) {
|
||||
zone.absX = zone.getXCoord();
|
||||
}
|
||||
if (zone.absY == 0.0f) {
|
||||
zone.absY = zone.getYCoord();
|
||||
}
|
||||
if (zone.absZ == 0.0f) {
|
||||
zone.absZ = zone.getZCoord();
|
||||
}
|
||||
for (Zone child : zone.getNodes()) {
|
||||
child.absX = child.getXCoord() + zone.absX;
|
||||
child.absY = child.getYCoord() + zone.absY;
|
||||
child.absZ = child.getZCoord() + zone.absZ;
|
||||
wsmList.addAll(this.GET_ALL_NODES(child));
|
||||
}
|
||||
return wsmList;
|
||||
}
|
||||
|
||||
public Zone GET_BY_UID(long ID) {
|
||||
|
||||
Zone zone = (Zone) DbManager.getFromCache(Enum.GameObjectType.Zone, (int) ID);
|
||||
|
||||
if (zone != null)
|
||||
return zone;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, ID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
zone = (Zone) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return zone;
|
||||
}
|
||||
|
||||
public ArrayList<Zone> GET_MAP_NODES(final int objectUUID) {
|
||||
|
||||
ArrayList<Zone> zoneList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
zoneList = getObjectsFromRs(rs, 2000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return zoneList;
|
||||
}
|
||||
|
||||
public void LOAD_ZONE_EXTENTS() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Vector2f zoneSize = new Vector2f();
|
||||
int loadNum = rs.getInt("loadNum");
|
||||
zoneSize.x = rs.getFloat("xRadius");
|
||||
zoneSize.y = rs.getFloat("zRadius");
|
||||
ZoneManager._zone_size_data.put(loadNum, zoneSize);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean DELETE_ZONE(final Zone zone) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ? AND `type` = 'zone'")) {
|
||||
|
||||
preparedStatement.setInt(1, zone.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class AbstractDevCmd {
|
||||
|
||||
protected final ArrayList<String> cmdStrings;
|
||||
private AbstractGameObject tr;
|
||||
private String rsult;
|
||||
|
||||
public AbstractDevCmd(String cmdString) {
|
||||
super();
|
||||
this.cmdStrings = new ArrayList<>();
|
||||
this.addCmdString(cmdString);
|
||||
this.rsult = "";
|
||||
}
|
||||
|
||||
/*
|
||||
* Misc tools/helpers
|
||||
*/
|
||||
protected static Building getTargetAsBuilding(PlayerCharacter pc) {
|
||||
int targetType = pc.getLastTargetType().ordinal();
|
||||
int targetID = pc.getLastTargetID();
|
||||
if (targetType == GameObjectType.Building.ordinal()) {
|
||||
Building b = (Building) DbManager
|
||||
.getFromCache(GameObjectType.Building, targetID);
|
||||
if (b == null) {
|
||||
ChatManager.chatSystemError(
|
||||
pc,
|
||||
"Command Failed. Could not find building of ID "
|
||||
+ targetID);
|
||||
return null;
|
||||
}
|
||||
return b;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static Mob getTargetAsMob(PlayerCharacter pc) {
|
||||
int targetType = pc.getLastTargetType().ordinal();
|
||||
int targetID = pc.getLastTargetID();
|
||||
if (targetType == GameObjectType.Mob.ordinal()) {
|
||||
Mob b = Mob.getMob(targetID);
|
||||
if (b == null) {
|
||||
ChatManager.chatSystemError(pc,
|
||||
"Command Failed. Could not find Mob of ID " + targetID);
|
||||
return null;
|
||||
}
|
||||
return b;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static NPC getTargetAsNPC(PlayerCharacter pc) {
|
||||
int targetType = pc.getLastTargetType().ordinal();
|
||||
int targetID = pc.getLastTargetID();
|
||||
if (targetType == GameObjectType.NPC.ordinal()) {
|
||||
NPC b = NPC.getFromCache(targetID);
|
||||
if (b == null) {
|
||||
ChatManager.chatSystemError(pc,
|
||||
"Command Failed. Could not find NPC of ID " + targetID);
|
||||
return null;
|
||||
}
|
||||
return b;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by the DevCmdManager. Method splits argString
|
||||
* into a String array and then calls the subclass specific _doCmd method.
|
||||
*/
|
||||
|
||||
public void doCmd(PlayerCharacter pcSender, String argString,
|
||||
AbstractGameObject target) {
|
||||
String[] args = argString.split(" ");
|
||||
|
||||
if (pcSender == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
|
||||
this.sendHelp(pcSender);
|
||||
this.sendUsage(pcSender);
|
||||
} else {
|
||||
this.tr = target;
|
||||
this._doCmd(pcSender, args, target);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void _doCmd(PlayerCharacter pcSender, String[] args,
|
||||
AbstractGameObject target);
|
||||
|
||||
/**
|
||||
* Returns the string sent to the client that displays how to use this
|
||||
* command.
|
||||
*/
|
||||
|
||||
public final String getUsageString() {
|
||||
return "Usage: " + this._getUsageString();
|
||||
}
|
||||
|
||||
protected abstract String _getUsageString();
|
||||
|
||||
/**
|
||||
* Returns the string sent to the client that displays what this command
|
||||
* does.
|
||||
*/
|
||||
|
||||
public final String getHelpString() {
|
||||
return this.getMainCmdString() + ": " + this._getHelpString();
|
||||
}
|
||||
|
||||
protected abstract String _getHelpString();
|
||||
|
||||
public final ArrayList<String> getCmdStrings() {
|
||||
return cmdStrings;
|
||||
}
|
||||
|
||||
public final String getMainCmdString() {
|
||||
return this.cmdStrings.get(0);
|
||||
}
|
||||
|
||||
protected void addCmdString(String cmdString) {
|
||||
String lowercase = cmdString.toLowerCase();
|
||||
this.cmdStrings.add(lowercase);
|
||||
}
|
||||
|
||||
public AbstractGameObject getTarget() {
|
||||
return this.tr;
|
||||
}
|
||||
|
||||
public void setTarget(AbstractGameObject ago) {
|
||||
this.tr = ago;
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return this.rsult;
|
||||
}
|
||||
|
||||
public void setResult(String result) {
|
||||
this.rsult = result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper functions
|
||||
*/
|
||||
protected void sendUsage(PlayerCharacter pc) {
|
||||
this.throwbackError(pc, this.getUsageString());
|
||||
}
|
||||
|
||||
protected void sendHelp(PlayerCharacter pc) {
|
||||
this.throwbackError(pc, this.getHelpString());
|
||||
}
|
||||
|
||||
protected void throwbackError(PlayerCharacter pc, String msgText) {
|
||||
ChatManager.chatSystemError(pc, msgText);
|
||||
}
|
||||
|
||||
protected void throwbackInfo(PlayerCharacter pc, String msgText) {
|
||||
ChatManager.chatSystemInfo(pc, msgText);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.Enum.ProtectionState;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.math.Vector3f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
|
||||
public class AddBuildingCmd extends AbstractDevCmd {
|
||||
|
||||
public AddBuildingCmd() {
|
||||
super("addbuilding");
|
||||
// super("addbuilding", MBServerStatics.ACCESS_GROUP_DESIGNER_UP, 0, false, true);
|
||||
this.addCmdString("building");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
|
||||
// Arg Count Check
|
||||
if (words.length != 2) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
|
||||
int ID;
|
||||
int rank;
|
||||
Blueprint blueprint;
|
||||
|
||||
try {
|
||||
ID = Integer.parseInt(words[0]);
|
||||
rank = Integer.parseInt(words[1]);
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc, "Invalid addBuilding Command. Need Building ID and rank.");
|
||||
return; // NaN
|
||||
}
|
||||
if (ID < 1) {
|
||||
throwbackError(pc,
|
||||
"Invalid addBuilding Command. Invalid Building ID.");
|
||||
return;
|
||||
}
|
||||
Vector3f rot = new Vector3f(0.0f, 0.0f, 0.0f);
|
||||
float w = 1f;
|
||||
Zone zone = ZoneManager.findSmallestZone(pc.getLoc());
|
||||
|
||||
if (zone == null) {
|
||||
throwbackError(pc, "Failed to find zone to place building in.");
|
||||
return;
|
||||
}
|
||||
|
||||
blueprint = Blueprint.getBlueprint(ID);
|
||||
|
||||
if ((blueprint != null) && (rank > blueprint.getMaxRank())) {
|
||||
throwbackError(pc, rank + " is not a valid rank for this building");
|
||||
return;
|
||||
}
|
||||
|
||||
Building likeBuilding = DbManager.BuildingQueries.GET_BUILDING_BY_MESH(ID);
|
||||
|
||||
if (likeBuilding != null) {
|
||||
rot = likeBuilding.getRot();
|
||||
w = likeBuilding.getw();
|
||||
}
|
||||
|
||||
String buildingName = "";
|
||||
int blueprintUUID = 0;
|
||||
|
||||
Vector3fImmutable localLoc = ZoneManager.worldToLocal(pc.getLoc(), zone);
|
||||
|
||||
if (localLoc == null)
|
||||
return;
|
||||
|
||||
if (blueprint != null) {
|
||||
buildingName = blueprint.getName();
|
||||
blueprintUUID = blueprint.getBlueprintUUID();
|
||||
}
|
||||
|
||||
Building building = DbManager.BuildingQueries.
|
||||
CREATE_BUILDING(
|
||||
zone.getObjectUUID(), 0, buildingName, ID,
|
||||
localLoc, 1.0f, 0, ProtectionState.PROTECTED, 0, rank,
|
||||
null, blueprintUUID, w, rot.y);
|
||||
|
||||
|
||||
if (building == null) {
|
||||
throwbackError(pc, "Failed to add building.");
|
||||
return;
|
||||
}
|
||||
|
||||
building.setRot(rot);
|
||||
building.setw(w);
|
||||
|
||||
building.setObjectTypeMask(MBServerStatics.MASK_BUILDING);
|
||||
WorldGrid.addObject(building, pc);
|
||||
ChatManager.chatSayInfo(pc,
|
||||
"Building with ID " + building.getObjectUUID() + " added");
|
||||
|
||||
this.setResult(String.valueOf(building.getObjectUUID()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Creates a building of type 'buildingID' at the location your character is standing.";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /addbuilding buildingID rank' || ' /building buildingID rank'";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.Item;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/**
|
||||
* @author Eighty
|
||||
*/
|
||||
public class AddGoldCmd extends AbstractDevCmd {
|
||||
|
||||
public AddGoldCmd() {
|
||||
super("addgold");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
if (words.length != 1) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
|
||||
Item gold = pc.getCharItemManager().getGoldInventory();
|
||||
int curAmt;
|
||||
if (gold == null)
|
||||
curAmt = 0;
|
||||
else
|
||||
curAmt = gold.getNumOfItems();
|
||||
|
||||
int amt;
|
||||
try {
|
||||
amt = Integer.parseInt(words[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
throwbackError(pc, "Quantity must be a number, " + words[0] + " is invalid");
|
||||
return;
|
||||
}
|
||||
if (amt < 1 || amt > 10000000) {
|
||||
throwbackError(pc, "Quantity must be between 1 and 10000000 (10 million)");
|
||||
return;
|
||||
} else if ((curAmt + amt) > 10000000) {
|
||||
throwbackError(pc, "This would place your inventory over 10,000,000 gold.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pc.getCharItemManager().addGoldToInventory(amt, true)) {
|
||||
throwbackError(pc, "Failed to add gold to inventory");
|
||||
return;
|
||||
}
|
||||
|
||||
ChatManager.chatSayInfo(pc, amt + " gold added to inventory");
|
||||
pc.getCharItemManager().updateInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "adds gold to inventory";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /addGold quantity'";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
/**
|
||||
* @author Eighty
|
||||
*/
|
||||
public class AddMobCmd extends AbstractDevCmd {
|
||||
|
||||
public AddMobCmd() {
|
||||
super("mob");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
if (words.length != 1) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
|
||||
Zone zone = ZoneManager.findSmallestZone(pc.getLoc());
|
||||
|
||||
if (words[0].equals("all")) {
|
||||
|
||||
for (AbstractGameObject mobbaseAGO : DbManager.getList(GameObjectType.MobBase)) {
|
||||
MobBase mb = (MobBase) mobbaseAGO;
|
||||
int loadID = mb.getObjectUUID();
|
||||
Mob mob = Mob.createMob(loadID, Vector3fImmutable.getRandomPointInCircle(pc.getLoc(), 100),
|
||||
null, true, zone, null, 0, "", 1);
|
||||
if (mob != null) {
|
||||
mob.updateDatabase();
|
||||
this.setResult(String.valueOf(mob.getDBID()));
|
||||
} else {
|
||||
throwbackError(pc, "Failed to create mob of type " + loadID);
|
||||
Logger.error("Failed to create mob of type "
|
||||
+ loadID);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int loadID;
|
||||
try {
|
||||
loadID = Integer.parseInt(words[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
throwbackError(pc, "Supplied type " + words[0]
|
||||
+ " failed to parse to an Integer");
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
throwbackError(pc,
|
||||
"An unknown exception occurred when trying to use mob command for type "
|
||||
+ words[0]);
|
||||
return; // NaN
|
||||
}
|
||||
|
||||
|
||||
if (zone == null) {
|
||||
throwbackError(pc, "Failed to find zone to place mob in.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (zone.isPlayerCity()) {
|
||||
throwbackError(pc, "Cannot use ./mob on Player cities. Try ./servermob instead.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Mob mob = Mob.createMob(loadID, pc.getLoc(),
|
||||
null, true, zone, null, 0, "", 1);
|
||||
if (mob != null) {
|
||||
mob.updateDatabase();
|
||||
ChatManager.chatSayInfo(pc,
|
||||
"Mob with ID " + mob.getDBID() + " added");
|
||||
this.setResult(String.valueOf(mob.getDBID()));
|
||||
} else {
|
||||
throwbackError(pc, "Failed to create mob of type " + loadID);
|
||||
Logger.error("Failed to create mob of type "
|
||||
+ loadID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Creates a Mob of type 'mobID' at the location your character is standing";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /mob mobID'";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.*;
|
||||
import engine.objects.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
/**
|
||||
* @author Eighty
|
||||
*/
|
||||
public class AddNPCCmd extends AbstractDevCmd {
|
||||
|
||||
public AddNPCCmd() {
|
||||
super("npc");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
int contractID;
|
||||
String name = "";
|
||||
int level = 0;
|
||||
|
||||
if (words.length < 2) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
contractID = Integer.parseInt(words[0]);
|
||||
level = Integer.parseInt(words[1]);
|
||||
|
||||
for (int i = 2; i < words.length; i++) {
|
||||
name += words[i];
|
||||
if (i + 1 < words.length)
|
||||
name += "";
|
||||
}
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
throwbackError(pc,
|
||||
"Failed to parse supplied contractID or level to an Integer.");
|
||||
return; // NaN
|
||||
}
|
||||
|
||||
Contract contract = DbManager.ContractQueries.GET_CONTRACT(contractID);
|
||||
|
||||
if (contract == null || level < 1 || level > 75) {
|
||||
throwbackError(pc,
|
||||
"Invalid addNPC Command. Need contract ID, and level");
|
||||
return; // NaN
|
||||
}
|
||||
|
||||
// Pick a random name
|
||||
if (name.isEmpty())
|
||||
name = NPCManager.getPirateName(contract.getMobbaseID());
|
||||
|
||||
Zone zone = ZoneManager.findSmallestZone(pc.getLoc());
|
||||
|
||||
if (zone == null) {
|
||||
throwbackError(pc, "Failed to find zone to place npc in.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (target != null)
|
||||
if (target.getObjectType() == GameObjectType.Building) {
|
||||
Building parentBuilding = (Building) target;
|
||||
BuildingManager.addHirelingForWorld(parentBuilding, pc, parentBuilding.getLoc(), parentBuilding.getParentZone(), contract, level);
|
||||
return;
|
||||
}
|
||||
|
||||
NPC npc = NPC.createNPC(name, contractID,
|
||||
pc.getLoc(), null, zone, (short) level, null);
|
||||
|
||||
if (npc != null) {
|
||||
WorldGrid.addObject(npc, pc);
|
||||
ChatManager.chatSayInfo(pc,
|
||||
"NPC with ID " + npc.getDBID() + " added");
|
||||
this.setResult(String.valueOf(npc.getDBID()));
|
||||
} else {
|
||||
throwbackError(pc, "Failed to create npc of contract type "
|
||||
+ contractID);
|
||||
Logger.error(
|
||||
"Failed to create npc of contract type " + contractID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Creates an NPC of type 'npcID' at the location your character is standing";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /npc npcID level name'";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.Enum.PowerActionType;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.PowersManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.powers.ActionsBase;
|
||||
import engine.powers.PowersBase;
|
||||
import engine.powers.effectmodifiers.AbstractEffectModifier;
|
||||
import engine.util.ThreadUtils;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ApplyBonusCmd extends AbstractDevCmd {
|
||||
|
||||
public ApplyBonusCmd() {
|
||||
super("applybonus");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pcSender, String[] words,
|
||||
AbstractGameObject target) {
|
||||
|
||||
String action = words[0];
|
||||
|
||||
PowerActionType actionType = null;
|
||||
|
||||
HashMap<String, HashSet<String>> appliedMods = new HashMap<>();
|
||||
|
||||
try {
|
||||
|
||||
if (action.equals("all") == false)
|
||||
for (PowerActionType powerActionType : PowerActionType.values()) {
|
||||
if (powerActionType.name().equalsIgnoreCase(action) == false)
|
||||
continue;
|
||||
actionType = powerActionType;
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
this.throwbackError(pcSender, "Invalid power Action type for " + action);
|
||||
this.throwbackInfo(pcSender, "Valid Types : " + this.getActionTypes());
|
||||
return;
|
||||
}
|
||||
if (action.equals("all") == false)
|
||||
if (actionType == null) {
|
||||
this.throwbackError(pcSender, "Invalid power Action type for " + action);
|
||||
this.throwbackInfo(pcSender, "Valid Types : " + this.getActionTypes());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (PowersBase pb : PowersManager.powersBaseByIDString.values()) {
|
||||
if (pb.getActions() == null || pb.getActions().isEmpty())
|
||||
continue;
|
||||
|
||||
for (ActionsBase ab : pb.getActions()) {
|
||||
if (ab.getPowerAction() == null)
|
||||
continue;
|
||||
if (action.equals("all") == false)
|
||||
if (ab.getPowerAction().getType().equalsIgnoreCase(action) == false)
|
||||
continue;
|
||||
String effect1 = "";
|
||||
String effect2 = "";
|
||||
ChatManager.chatSystemInfo(pcSender, "Applying Power " + pb.getName() + " : " + pb.getDescription());
|
||||
if (ab.getPowerAction().getEffectsBase() == null) {
|
||||
|
||||
try {
|
||||
PowersManager.runPowerAction(pcSender, pcSender, pcSender.getLoc(), ab, 1, pb);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (ab.getPowerAction().getEffectsBase().getModifiers() == null || ab.getPowerAction().getEffectsBase().getModifiers().isEmpty()) {
|
||||
try {
|
||||
PowersManager.runPowerAction(pcSender, pcSender, pcSender.getLoc(), ab, 1, pb);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean run = true;
|
||||
for (AbstractEffectModifier mod : ab.getPowerAction().getEffectsBase().getModifiers()) {
|
||||
if (appliedMods.containsKey(mod.modType.name()) == false) {
|
||||
appliedMods.put(mod.modType.name(), new HashSet<>());
|
||||
}
|
||||
|
||||
// if (appliedMods.get(mod.modType.name()).contains(mod.sourceType.name())){
|
||||
// continue;
|
||||
// }
|
||||
|
||||
appliedMods.get(mod.modType.name()).add(mod.sourceType.name());
|
||||
try {
|
||||
try {
|
||||
PowersManager.runPowerAction(pcSender, pcSender, pcSender.getLoc(), ab, 1, pb);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /bounds'";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Audits all the mobs in a zone.";
|
||||
|
||||
}
|
||||
|
||||
private String getActionTypes() {
|
||||
String output = "";
|
||||
|
||||
for (PowerActionType actionType : PowerActionType.values()) {
|
||||
output += actionType.name() + " | ";
|
||||
|
||||
}
|
||||
|
||||
return output.substring(0, output.length() - 3);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.PowersManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.AbstractCharacter;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.powers.PowersBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Eighty
|
||||
*/
|
||||
public class ApplyStatModCmd extends AbstractDevCmd {
|
||||
|
||||
private static int cnt = 0;
|
||||
|
||||
public ApplyStatModCmd() {
|
||||
super("applystatmod");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pcSender, String[] args,
|
||||
AbstractGameObject target) {
|
||||
if (args.length < 1) {
|
||||
// if(args.length < 2) {
|
||||
this.sendUsage(pcSender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(target instanceof AbstractCharacter)) {
|
||||
this.sendHelp(pcSender);
|
||||
return;
|
||||
}
|
||||
|
||||
this.setTarget(pcSender); //for logging
|
||||
|
||||
int spellID;
|
||||
int powerAction = 0;
|
||||
if (args[0].toLowerCase().contains("all")) {
|
||||
|
||||
int amount = 0;
|
||||
if (args.length == 1) {
|
||||
amount = ApplyStatModCmd.cnt;
|
||||
ApplyStatModCmd.cnt++;
|
||||
} else {
|
||||
amount = Integer.valueOf(args[1]);
|
||||
ApplyStatModCmd.cnt = amount + 1;
|
||||
}
|
||||
|
||||
|
||||
ArrayList<PowersBase> pbList = new ArrayList<>();
|
||||
pbList.add(PowersManager.getPowerByToken(429047968));
|
||||
pbList.add(PowersManager.getPowerByToken(429768864));
|
||||
pbList.add(PowersManager.getPowerByToken(428458144));
|
||||
pbList.add(PowersManager.getPowerByToken(428677994));
|
||||
pbList.add(PowersManager.getPowerByToken(431874079));
|
||||
pbList.add(PowersManager.getPowerByToken(431081336));
|
||||
|
||||
|
||||
for (PowersBase pb : pbList) {
|
||||
if (amount <= 0) {
|
||||
if (pb.getToken() == 428677994)
|
||||
powerAction = 1;
|
||||
PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false);
|
||||
continue;
|
||||
} else if (amount > 9999 || amount < 21) {
|
||||
ChatManager.chatSystemInfo(pcSender, "Amount must be between 21 and 9999 inclusive.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pb.getToken() == 428677994) {
|
||||
PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false);
|
||||
PowersManager.runPowerAction(pcSender, pcSender, Vector3fImmutable.ZERO, pb.getActions().get(powerAction), amount - 20, pb);
|
||||
}
|
||||
if (pb.getToken() == 428677994)
|
||||
powerAction = 1;
|
||||
PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false);
|
||||
PowersManager.runPowerAction(pcSender, pcSender, Vector3fImmutable.ZERO, pb.getActions().get(powerAction), amount - 20, pb);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (args[0].toLowerCase().contains("con")) {
|
||||
spellID = 429047968; //Blessing of Health
|
||||
} else if (args[0].toLowerCase().contains("str")) {
|
||||
spellID = 429768864; //Blessing of Might
|
||||
} else if (args[0].toLowerCase().contains("dex")) {
|
||||
spellID = 428458144; //Blessing of Dexterity
|
||||
} else if (args[0].toLowerCase().contains("int")) {
|
||||
spellID = 428677994; //Bard Spi - TODO
|
||||
powerAction = 1;
|
||||
} else if (args[0].toLowerCase().contains("spi")) {
|
||||
spellID = 428677994; //Bard Spi
|
||||
} else {
|
||||
ChatManager.chatSystemInfo(pcSender, "No valid stat found.");
|
||||
return;
|
||||
}
|
||||
|
||||
PowersBase pb = PowersManager.getPowerByToken(spellID);
|
||||
|
||||
int amount = 0;
|
||||
if (args.length == 1) {
|
||||
amount = ApplyStatModCmd.cnt;
|
||||
ApplyStatModCmd.cnt++;
|
||||
} else {
|
||||
amount = Integer.valueOf(args[1]);
|
||||
ApplyStatModCmd.cnt = amount + 1;
|
||||
}
|
||||
// int amount = Integer.valueOf(args[1]);
|
||||
if (amount <= 0) {
|
||||
PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false);
|
||||
return;
|
||||
} else if (amount > 9999 || amount < 21) {
|
||||
ChatManager.chatSystemInfo(pcSender, "Amount must be between 21 and 9999 inclusive.");
|
||||
return;
|
||||
}
|
||||
|
||||
PowersManager.removeEffect(pcSender, pb.getActions().get(powerAction), false, false);
|
||||
PowersManager.runPowerAction(pcSender, pcSender, Vector3fImmutable.ZERO, pb.getActions().get(powerAction), amount - 20, pb);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /applystatmod <stat> [trains]'";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "You must be targeting a player!";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.Enum.ModType;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.PowersManager;
|
||||
import engine.net.ItemProductionManager;
|
||||
import engine.objects.*;
|
||||
import engine.powers.effectmodifiers.AbstractEffectModifier;
|
||||
import engine.powers.poweractions.AbstractPowerAction;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
public class AuditFailedItemsCmd extends AbstractDevCmd {
|
||||
|
||||
public AuditFailedItemsCmd() {
|
||||
super("faileditems");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pcSender, String[] words,
|
||||
AbstractGameObject target) {
|
||||
|
||||
|
||||
if (ItemProductionManager.FailedItems.isEmpty())
|
||||
return;
|
||||
|
||||
Logger.info("Auditing Item production Failed Items");
|
||||
|
||||
String newLine = "\r\n";
|
||||
String auditFailedItem = "Failed Item Name | Prefix | Suffix | NPC | Contract | Player | ";
|
||||
|
||||
for (ProducedItem failedItem : ItemProductionManager.FailedItems) {
|
||||
|
||||
String npcName = "";
|
||||
String playerName = "";
|
||||
String contractName = "";
|
||||
|
||||
String prefix = "";
|
||||
String suffix = "";
|
||||
String itemName = "";
|
||||
NPC npc = NPC.getFromCache(failedItem.getNpcUID());
|
||||
|
||||
if (npc == null) {
|
||||
npcName = "null";
|
||||
contractName = "null";
|
||||
} else {
|
||||
npcName = npc.getName();
|
||||
if (npc.getContract() != null)
|
||||
contractName = npc.getContract().getName();
|
||||
}
|
||||
|
||||
PlayerCharacter roller = PlayerCharacter.getFromCache(failedItem.getPlayerID());
|
||||
|
||||
if (roller == null)
|
||||
playerName = "null";
|
||||
else
|
||||
playerName = roller.getName();
|
||||
|
||||
ItemBase ib = ItemBase.getItemBase(failedItem.getItemBaseID());
|
||||
|
||||
if (ib != null) {
|
||||
itemName = ib.getName();
|
||||
}
|
||||
|
||||
if (failedItem.isRandom() == false) {
|
||||
if (failedItem.getPrefix().isEmpty() == false) {
|
||||
AbstractPowerAction pa = PowersManager.getPowerActionByIDString(failedItem.getPrefix());
|
||||
if (pa != null) {
|
||||
for (AbstractEffectModifier aem : pa.getEffectsBase().getModifiers()) {
|
||||
if (aem.modType.equals(ModType.ItemName)) {
|
||||
prefix = aem.getString1();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (failedItem.getSuffix().isEmpty() == false) {
|
||||
AbstractPowerAction pa = PowersManager.getPowerActionByIDString(failedItem.getSuffix());
|
||||
if (pa != null) {
|
||||
for (AbstractEffectModifier aem : pa.getEffectsBase().getModifiers()) {
|
||||
if (aem.modType.equals(ModType.ItemName)) {
|
||||
suffix = aem.getString1();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
prefix = "random";
|
||||
}
|
||||
|
||||
|
||||
auditFailedItem += newLine;
|
||||
auditFailedItem += itemName + " | " + prefix + " | " + suffix + " | " + failedItem.getNpcUID() + ":" + npcName + " | " + contractName + " | " + failedItem.getPlayerID() + ":" + playerName;
|
||||
|
||||
}
|
||||
Logger.info(auditFailedItem);
|
||||
ItemProductionManager.FailedItems.clear();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /bounds'";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Audits all the mobs in a zone.";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.InterestManagement.HeightMap;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.math.Vector2f;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.Zone;
|
||||
|
||||
public class AuditHeightMapCmd extends AbstractDevCmd {
|
||||
|
||||
public AuditHeightMapCmd() {
|
||||
super("auditheightmap");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pcSender, String[] words,
|
||||
AbstractGameObject target) {
|
||||
|
||||
int count = Integer.parseInt(words[0]);
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
||||
|
||||
Zone currentZone = ZoneManager.findSmallestZone(pcSender.getLoc());
|
||||
|
||||
|
||||
Vector3fImmutable currentLoc = Vector3fImmutable.getRandomPointInCircle(currentZone.getLoc(), currentZone.getBounds().getHalfExtents().x < currentZone.getBounds().getHalfExtents().y ? currentZone.getBounds().getHalfExtents().x : currentZone.getBounds().getHalfExtents().y);
|
||||
|
||||
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(currentLoc, currentZone);
|
||||
|
||||
if (currentZone != null && currentZone.getHeightMap() != null) {
|
||||
float altitude = currentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
|
||||
float outsetAltitude = HeightMap.getOutsetHeight(altitude, currentZone, pcSender.getLoc());
|
||||
}
|
||||
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
long delta = end - start;
|
||||
|
||||
this.throwbackInfo(pcSender, "Audit Heightmap took " + delta + " ms to run " + count + " times!");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /auditmobs [zone.UUID]'";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Audits all the mobs in a zone.";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.Zone;
|
||||
|
||||
public class AuditMobsCmd extends AbstractDevCmd {
|
||||
|
||||
public AuditMobsCmd() {
|
||||
super("auditmobs");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pcSender, String[] words,
|
||||
AbstractGameObject target) {
|
||||
if (pcSender == null)
|
||||
return;
|
||||
|
||||
//get Zone to check mobs against
|
||||
|
||||
Zone zone;
|
||||
|
||||
if (words.length == 2) {
|
||||
if (words[0].equals("all")) {
|
||||
int plusplus = 0;
|
||||
int count = Integer.parseInt(words[1]);
|
||||
for (Zone zoneMicro : ZoneManager.getAllZones()) {
|
||||
int size = zoneMicro.zoneMobSet.size();
|
||||
|
||||
if (size >= count) {
|
||||
plusplus++;
|
||||
throwbackInfo(pcSender, zoneMicro.getName() + " at location " + zoneMicro.getLoc().toString() + " has " + size + " mobs. ");
|
||||
System.out.println(zoneMicro.getName() + " at location " + zoneMicro.getLoc().toString() + " has " + size + " mobs. ");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
throwbackInfo(pcSender, " there are " + plusplus + " zones with at least " + count + " mobs in each.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (words.length > 1) {
|
||||
this.sendUsage(pcSender);
|
||||
return;
|
||||
} else if (words.length == 1) {
|
||||
int uuid;
|
||||
try {
|
||||
uuid = Integer.parseInt(words[0]);
|
||||
zone = ZoneManager.getZoneByUUID(uuid);
|
||||
} catch (NumberFormatException e) {
|
||||
zone = ZoneManager.findSmallestZone(pcSender.getLoc());
|
||||
}
|
||||
} else
|
||||
zone = ZoneManager.findSmallestZone(pcSender.getLoc());
|
||||
|
||||
if (zone == null) {
|
||||
throwbackError(pcSender, "Unable to find the zone");
|
||||
return;
|
||||
}
|
||||
|
||||
//get list of mobs for zone
|
||||
|
||||
if (zone.zoneMobSet.isEmpty()) {
|
||||
throwbackError(pcSender, "No mobs found for this zone.");
|
||||
return;
|
||||
}
|
||||
|
||||
// ConcurrentHashMap<Integer, Mob> spawnMap = Mob.getSpawnMap();
|
||||
//ConcurrentHashMap<Mob, Long> respawnMap = Mob.getRespawnMap();
|
||||
// ConcurrentHashMap<Mob, Long> despawnMap = Mob.getDespawnMap();
|
||||
|
||||
throwbackInfo(pcSender, zone.getName() + ", numMobs: " + zone.zoneMobSet.size());
|
||||
throwbackInfo(pcSender, "UUID, dbID, inRespawnMap, isAlive, activeAI, Loc");
|
||||
|
||||
|
||||
//mob not found in spawn map, check respawn
|
||||
boolean inRespawn = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /auditmobs [zone.UUID]'";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Audits all the mobs in a zone.";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class BoundsCmd extends AbstractDevCmd {
|
||||
|
||||
public BoundsCmd() {
|
||||
super("bounds");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pcSender, String[] words,
|
||||
AbstractGameObject target) {
|
||||
if (target == null || !target.getObjectType().equals(GameObjectType.Building)) {
|
||||
this.throwbackError(pcSender, "No Building Selected");
|
||||
return;
|
||||
}
|
||||
|
||||
Building building = (Building) target;
|
||||
|
||||
if (building.getBounds() == null) {
|
||||
this.throwbackInfo(pcSender, "No valid Bounds for building UUID " + building.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
float topLeftX = building.getLoc().x - building.getBounds().getHalfExtents().x;
|
||||
float topLeftY = building.getLoc().z - building.getBounds().getHalfExtents().y;
|
||||
|
||||
float topRightX = building.getLoc().x + building.getBounds().getHalfExtents().x;
|
||||
float topRightY = building.getLoc().z - building.getBounds().getHalfExtents().y;
|
||||
|
||||
float bottomLeftX = building.getLoc().x - building.getBounds().getHalfExtents().x;
|
||||
float bottomLeftY = building.getLoc().z + building.getBounds().getHalfExtents().y;
|
||||
|
||||
float bottomRightX = building.getLoc().x + building.getBounds().getHalfExtents().x;
|
||||
float bottomRightY = building.getLoc().z + building.getBounds().getHalfExtents().y;
|
||||
|
||||
String newLine = "\r\n ";
|
||||
|
||||
String output = "Bounds Information for Building UUID " + building.getObjectUUID();
|
||||
output += newLine;
|
||||
|
||||
output += "Top Left : " + topLeftX + " , " + topLeftY + newLine;
|
||||
output += "Top Right : " + topRightX + " , " + topRightY + newLine;
|
||||
output += "Bottom Left : " + bottomLeftX + " , " + bottomLeftY + newLine;
|
||||
output += "Bottom Right : " + bottomRightX + " , " + bottomRightY + newLine;
|
||||
|
||||
this.throwbackInfo(pcSender, output);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /bounds'";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Audits all the mobs in a zone.";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.util.MiscUtils;
|
||||
|
||||
public class ChangeNameCmd extends AbstractDevCmd {
|
||||
|
||||
public ChangeNameCmd() {
|
||||
super("changename");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
Vector3fImmutable loc = null;
|
||||
|
||||
// Arg Count Check
|
||||
if (words.length < 2) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
|
||||
String oldFirst = words[0];
|
||||
String newFirst = words[1];
|
||||
String newLast = "";
|
||||
if (words.length > 2) {
|
||||
newLast = words[2];
|
||||
for (int i = 3; i < words.length; i++)
|
||||
newLast += ' ' + words[i];
|
||||
}
|
||||
|
||||
//verify new name length
|
||||
if (newFirst.length() < 3) {
|
||||
this.throwbackError(pc, "Error: First name is incorrect length. Must be between 3 and 15 characters");
|
||||
return;
|
||||
}
|
||||
|
||||
//verify old name length
|
||||
if (newLast.length() > 50) {
|
||||
this.throwbackError(pc, "Error: Last name is incorrect length. Must be no more than 50 characters");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if firstname is valid
|
||||
if (MiscUtils.checkIfFirstNameInvalid(newFirst)) {
|
||||
this.throwbackError(pc, "Error: First name is not allowed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//get the world ID we're modifying for
|
||||
|
||||
//test if first name is unique, unless new and old first name are equal.
|
||||
if (!(oldFirst.equals(newFirst))) {
|
||||
if (!DbManager.PlayerCharacterQueries.IS_CHARACTER_NAME_UNIQUE(newFirst)) {
|
||||
this.throwbackError(pc, "Error: First name is not unique.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//tests passed, update name in database
|
||||
if (!DbManager.PlayerCharacterQueries.UPDATE_NAME(oldFirst, newFirst, newLast)) {
|
||||
this.throwbackError(pc, "Error: Database failed to update the name.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Finally update player ingame
|
||||
PlayerCharacter pcTar = null;
|
||||
try {
|
||||
pcTar = SessionManager
|
||||
.getPlayerCharacterByLowerCaseName(words[0]);
|
||||
pcTar.setFirstName(newFirst);
|
||||
pcTar.setLastName(newLast);
|
||||
this.setTarget(pcTar); //for logging
|
||||
|
||||
//specify if last name is ascii characters only
|
||||
String lastAscii = newLast.replaceAll("[^\\p{ASCII}]", "");
|
||||
pcTar.setAsciiLastName(lastAscii.equals(newLast));
|
||||
} catch (Exception e) {
|
||||
this.throwbackError(pc, "Database was updated but ingame character failed to update.");
|
||||
return;
|
||||
}
|
||||
|
||||
String out = oldFirst + " was changed to " + newFirst + (newLast.isEmpty() ? "." : (' ' + newLast + '.'));
|
||||
this.throwbackInfo(pc, out);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Changes the name of a player";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "'./changename oldFirstName newFirstName newLastName'";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.net.client.msg.TargetedActionMsg;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/**
|
||||
* @author Eighty
|
||||
*/
|
||||
public class CombatMessageCmd extends AbstractDevCmd {
|
||||
|
||||
public CombatMessageCmd() {
|
||||
super("cm");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pcSender, String[] args,
|
||||
AbstractGameObject target) {
|
||||
if (pcSender == null)
|
||||
return;
|
||||
if (args.length != 1) {
|
||||
this.sendUsage(pcSender);
|
||||
return;
|
||||
}
|
||||
int num = 0;
|
||||
try {
|
||||
num = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
throwbackError(pcSender, "Supplied message number " + args[0] + " failed to parse to an Integer");
|
||||
return;
|
||||
}
|
||||
TargetedActionMsg.un2cnt = num;
|
||||
throwbackInfo(pcSender, "CombatMessage set to " + num);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /cm [cmNumber]'";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Sets the combat message to the supplied integer value";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.ItemBase;
|
||||
import engine.objects.ItemFactory;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/**
|
||||
* @author Eighty
|
||||
*/
|
||||
public class CreateItemCmd extends AbstractDevCmd {
|
||||
|
||||
public CreateItemCmd() {
|
||||
super("createitem");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
if (words.length < 2) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
int id;
|
||||
id = ItemBase.getIDByName(words[0]);
|
||||
|
||||
if (id == 0)
|
||||
id = Integer.parseInt(words[0]);
|
||||
if (id == 7) {
|
||||
this.throwbackInfo(pc, "use /addgold to add gold.....");
|
||||
return;
|
||||
}
|
||||
|
||||
int size = 1;
|
||||
|
||||
if (words.length < 3) {
|
||||
size = Integer.parseInt(words[1]);
|
||||
}
|
||||
|
||||
ItemFactory.fillInventory(pc, id, size);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Fill your inventory with items";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /createitem <ItembaseID> <quantity>'";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.jobs.DebugTimerJob;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class DebugCmd extends AbstractDevCmd {
|
||||
|
||||
|
||||
public DebugCmd() {
|
||||
super("debug");
|
||||
// super("debug", MBServerStatics.ACCESS_GROUP_ALL_TEAM, 0, false, false);
|
||||
}
|
||||
|
||||
private static void toggleDebugTimer(PlayerCharacter pc, String name, int num, int duration, boolean toggle) {
|
||||
if (toggle) {
|
||||
DebugTimerJob dtj = new DebugTimerJob(pc, name, num, duration);
|
||||
pc.renewTimer(name, dtj, duration);
|
||||
} else
|
||||
pc.cancelTimer(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
if (words.length < 2) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pc == null)
|
||||
return;
|
||||
|
||||
//pc.setDebug must use bit sizes: 1, 2, 4, 8, 16, 32
|
||||
|
||||
String command = words[0].toLowerCase();
|
||||
boolean toggle = (words[1].toLowerCase().equals("on")) ? true : false;
|
||||
|
||||
switch (command) {
|
||||
case "magictrek":
|
||||
pc.RUN_MAGICTREK = toggle;
|
||||
|
||||
break;
|
||||
case "combat":
|
||||
pc.setDebug(64, toggle);
|
||||
|
||||
break;
|
||||
case "health":
|
||||
toggleDebugTimer(pc, "Debug_Health", 1, 1000, toggle);
|
||||
|
||||
break;
|
||||
case "mana":
|
||||
toggleDebugTimer(pc, "Debug_Mana", 2, 1000, toggle);
|
||||
|
||||
break;
|
||||
case "stamina":
|
||||
toggleDebugTimer(pc, "Debug_Stamina", 3, 500, toggle);
|
||||
|
||||
break;
|
||||
case "spells":
|
||||
pc.setDebug(16, toggle);
|
||||
|
||||
break;
|
||||
case "damageabsorber":
|
||||
pc.setDebug(2, toggle);
|
||||
|
||||
break;
|
||||
case "recast":
|
||||
case "recycle":
|
||||
pc.setDebug(4, toggle);
|
||||
|
||||
break;
|
||||
case "seeinvis":
|
||||
pc.setDebug(8, toggle);
|
||||
|
||||
break;
|
||||
case "movement":
|
||||
pc.setDebug(1, toggle);
|
||||
|
||||
break;
|
||||
case "noaggro":
|
||||
pc.setDebug(32, toggle);
|
||||
|
||||
break;
|
||||
// case "loot":
|
||||
// MBServerStatics.debugLoot = toggle;
|
||||
// break;
|
||||
|
||||
default:
|
||||
String output = "Debug for " + command + " not found.";
|
||||
throwbackError(pc, output);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
setTarget(pc); //for logging
|
||||
|
||||
String output = "Debug for " + command + " turned " + ((toggle) ? "on." : "off.");
|
||||
throwbackInfo(pc, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Runs debug commands";
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "'./Debug command on/off'";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class DebugMeleeSyncCmd extends AbstractDevCmd {
|
||||
|
||||
public DebugMeleeSyncCmd() {
|
||||
super("debugmeleesync");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
// Arg Count Check
|
||||
if (words.length != 1) {
|
||||
this.sendUsage(pc);
|
||||
return;
|
||||
}
|
||||
|
||||
String s = words[0].toLowerCase();
|
||||
|
||||
if (s.equals("on")) {
|
||||
pc.setDebug(64, true);
|
||||
ChatManager.chatSayInfo(pc, "Melee Sync Debug ON");
|
||||
} else if (s.equals("off")) {
|
||||
pc.setDebug(64, false);
|
||||
ChatManager.chatSayInfo(pc, "Melee Sync Debug OFF");
|
||||
} else {
|
||||
this.sendUsage(pc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Turns on/off melee sync debugging.";
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "'./debugmeleesync on|off'";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DecachePlayerCmd extends AbstractDevCmd {
|
||||
|
||||
public DecachePlayerCmd() {
|
||||
super("decacheplayer");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
if (words.length < 1) {
|
||||
this.sendUsage(pc);
|
||||
}
|
||||
|
||||
int objectUUID = Integer.parseInt(words[0]);
|
||||
|
||||
if (DbManager.inCache(Enum.GameObjectType.PlayerCharacter, objectUUID)) {
|
||||
this.setTarget(PlayerCharacter.getFromCache(objectUUID)); //for logging
|
||||
PlayerCharacter.getFromCache(objectUUID).removeFromCache();
|
||||
} else {
|
||||
this.sendHelp(pc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "No player found. Please make sure the table ID is correct.";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /decacheplayer <UUID>'";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.devcmd.cmds;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.devcmd.AbstractDevCmd;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.Mob;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class DespawnCmd extends AbstractDevCmd {
|
||||
|
||||
public DespawnCmd() {
|
||||
super("debugmob");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _doCmd(PlayerCharacter pc, String[] words,
|
||||
AbstractGameObject target) {
|
||||
|
||||
|
||||
if (pc == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Mob mob = null;
|
||||
|
||||
if (target != null && target.getObjectType().equals(GameObjectType.Mob))
|
||||
mob = (Mob) target;
|
||||
|
||||
if (mob == null)
|
||||
mob = Mob.getFromCache(Integer.parseInt(words[1]));
|
||||
|
||||
if (mob == null)
|
||||
return;
|
||||
|
||||
if (words[0].equalsIgnoreCase("respawn")) {
|
||||
mob.respawn();
|
||||
this.throwbackInfo(pc, "Mob with ID " + mob.getObjectUUID() + " Respawned");
|
||||
} else if (words[0].equalsIgnoreCase("despawn")) {
|
||||
mob.despawn();
|
||||
this.throwbackInfo(pc, "Mob with ID " + mob.getObjectUUID() + " Despawned");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getHelpString() {
|
||||
return "Gets distance from a target.";
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String _getUsageString() {
|
||||
return "' /distance'";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user