Browse Source

Refactor WOO change timer mechanics to use the same system as the mine claims. Moved both resets to the hourly job.

master
MagicBot 2 years ago
parent
commit
6a1b461735
  1. 7
      src/engine/db/handlers/dbGuildHandler.java
  2. 16
      src/engine/net/client/handlers/MineWindowChangeHandler.java
  3. 228
      src/engine/objects/Guild.java
  4. 2
      src/engine/server/MBServerStatics.java
  5. 66
      src/engine/workthreads/HourlyJobThread.java

7
src/engine/db/handlers/dbGuildHandler.java

@ -115,13 +115,6 @@ public class dbGuildHandler extends dbHandlerBase { @@ -115,13 +115,6 @@ public class dbGuildHandler extends dbHandlerBase {
return outputStr;
}
public boolean SET_LAST_WOO_UPDATE(Guild guild, LocalDateTime lastEditTime) {
prepareCallable("UPDATE `obj_guild` SET `lastWooEditTime`=? WHERE `UID`=?");
setLocalDateTime(1, lastEditTime);
setLong(2, (long) guild.getObjectUUID());
return (executeUpdate() > 0);
}
public ArrayList<Guild> GET_GUILD_ALLIES(final int id) {
prepareCallable("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
+ "WHERE l.isAlliance = 1 && l.OtherGuildID = g.UID && l.GuildID=?");

16
src/engine/net/client/handlers/MineWindowChangeHandler.java

@ -81,10 +81,10 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { @@ -81,10 +81,10 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler {
if (newMineTime == 24)
newMineTime = 0;
// Enforce 15hr restriction between WOO edits
// Enforce time restriction between WOO edits
if (LocalDateTime.now().isBefore(mineGuild.lastWooEditTime.plusHours(14))) {
ErrorPopupMsg.sendErrorMsg(playerCharacter, "You must wait 15 hours between WOO changes.");
if (mineGuild.wooWasModified) {
ErrorPopupMsg.sendErrorMsg(playerCharacter, "You can only modify your WOO once per day.");
return true;
}
@ -110,15 +110,7 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { @@ -110,15 +110,7 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler {
}
mineGuild.setMineTime(newMineTime);
mineGuild.lastWooEditTime = LocalDateTime.now();
// Update guild WOO timer for reboot persistence
if (!DbManager.GuildQueries.SET_LAST_WOO_UPDATE(mineGuild, mineGuild.lastWooEditTime)) {
Logger.error("MineWindowChange", "Failed to update woo timer for guild " + mineGuild.getObjectUUID());
ChatManager.chatGuildError(playerCharacter, "A Serious error has for to occurred.");
return true;
}
mineGuild.wooWasModified = true;
ChatManager.chatGuildInfo(playerCharacter, "Mine time updated.");

228
src/engine/objects/Guild.java

@ -7,9 +7,6 @@ @@ -7,9 +7,6 @@
// www.magicbane.com
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
@ -43,7 +40,6 @@ import java.sql.SQLException; @@ -43,7 +40,6 @@ import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
@ -77,15 +73,15 @@ public class Guild extends AbstractWorldObject { @@ -77,15 +73,15 @@ public class Guild extends AbstractWorldObject {
private ArrayList<Guild> subGuildList;
private int nationUUID = 0;
private GuildState guildState = GuildState.Errant;
private ConcurrentHashMap<Integer,Condemned> guildCondemned = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Integer, Condemned> guildCondemned = new ConcurrentHashMap<>();
private String hash;
private boolean ownerIsNPC;
private static Guild errantGuild;
private static Guild errantNation;
public LocalDateTime lastWooEditTime;
public HashMap<Integer,GuildAlliances> guildAlliances = new HashMap<>();
public boolean wooWasModified;
public HashMap<Integer, GuildAlliances> guildAlliances = new HashMap<>();
/**
* No Id Constructor
@ -121,7 +117,7 @@ public class Guild extends AbstractWorldObject { @@ -121,7 +117,7 @@ public class Guild extends AbstractWorldObject {
/**
* Normal Constructor
*/
public Guild( String name, Guild nat, int charter,
public Guild(String name, Guild nat, int charter,
String leadershipType, GuildTag gt, int newUUID) {
super(newUUID);
this.name = name;
@ -182,11 +178,7 @@ public class Guild extends AbstractWorldObject { @@ -182,11 +178,7 @@ public class Guild extends AbstractWorldObject {
this.teleportMax = rs.getInt("teleportMax");
this.mineTime = rs.getInt("mineTime");
Timestamp lastWooRequest = rs.getTimestamp("lastWooEditTime");
if (lastWooRequest != null)
this.lastWooEditTime = lastWooRequest.toLocalDateTime();
this.wooWasModified = false;
this.hash = rs.getString("hash");
}
@ -333,9 +325,9 @@ public class Guild extends AbstractWorldObject { @@ -333,9 +325,9 @@ public class Guild extends AbstractWorldObject {
if (this.isErrant())
return false;
if (!DbManager.GuildQueries.SET_GUILD_LEADER(ac.getObjectUUID(), this.getObjectUUID())){
if (!DbManager.GuildQueries.SET_GUILD_LEADER(ac.getObjectUUID(), this.getObjectUUID())) {
if (ac.getObjectType().equals(GameObjectType.PlayerCharacter))
ChatManager.chatGuildError((PlayerCharacter)ac, "Failed to change guild leader!");
ChatManager.chatGuildError((PlayerCharacter) ac, "Failed to change guild leader!");
return false;
}
@ -346,7 +338,7 @@ public class Guild extends AbstractWorldObject { @@ -346,7 +338,7 @@ public class Guild extends AbstractWorldObject {
oldGuildLeader.setGuildLeader(false);
if (ac.getObjectType().equals(GameObjectType.PlayerCharacter))
((PlayerCharacter)ac).setGuildLeader(true);
((PlayerCharacter) ac).setGuildLeader(true);
this.guildLeaderUUID = ac.getObjectUUID();
return true;
@ -360,7 +352,7 @@ public class Guild extends AbstractWorldObject { @@ -360,7 +352,7 @@ public class Guild extends AbstractWorldObject {
return false;
if (ac.getObjectType().equals(GameObjectType.PlayerCharacter))
((PlayerCharacter)ac).setGuildLeader(true);
((PlayerCharacter) ac).setGuildLeader(true);
this.guildLeaderUUID = ac.getObjectUUID();
return true;
@ -411,9 +403,8 @@ public class Guild extends AbstractWorldObject { @@ -411,9 +403,8 @@ public class Guild extends AbstractWorldObject {
public boolean isErrant() {
return this.getObjectUUID() == Guild.errantGuild.getObjectUUID();
}
}
public static boolean sameGuild(Guild a, Guild b) {
if (a == null || b == null)
@ -475,14 +466,14 @@ public class Guild extends AbstractWorldObject { @@ -475,14 +466,14 @@ public class Guild extends AbstractWorldObject {
public void removePlayer(PlayerCharacter pc, GuildHistoryType historyType) {
if (this.isErrant()) {
Logger.warn( "Attempted to remove a PlayerCharacter (" + pc.getObjectUUID() + ") from an errant guild.");
Logger.warn("Attempted to remove a PlayerCharacter (" + pc.getObjectUUID() + ") from an errant guild.");
return;
}
//Add to Guild History
if (pc.getGuild() != null){
if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(pc.getGuildUUID(), pc, DateTime.now(), historyType)){
GuildHistory guildHistory = new GuildHistory(pc.getGuildUUID(), pc.getGuild().name,DateTime.now(), historyType) ;
if (pc.getGuild() != null) {
if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(pc.getGuildUUID(), pc, DateTime.now(), historyType)) {
GuildHistory guildHistory = new GuildHistory(pc.getGuildUUID(), pc.getGuild().name, DateTime.now(), historyType);
pc.getGuildHistory().add(guildHistory);
}
}
@ -496,12 +487,12 @@ public class Guild extends AbstractWorldObject { @@ -496,12 +487,12 @@ public class Guild extends AbstractWorldObject {
}
public void upgradeGuildState(boolean nation){
if (nation){
public void upgradeGuildState(boolean nation) {
if (nation) {
this.guildState = GuildState.Nation;
return;
}
switch(this.guildState){
switch (this.guildState) {
case Errant:
this.guildState = GuildState.Petitioner;
@ -528,9 +519,9 @@ public class Guild extends AbstractWorldObject { @@ -528,9 +519,9 @@ public class Guild extends AbstractWorldObject {
}
public void downgradeGuildState(){
public void downgradeGuildState() {
switch(this.guildState){
switch (this.guildState) {
case Errant:
break;
case Sworn:
@ -555,13 +546,13 @@ public class Guild extends AbstractWorldObject { @@ -555,13 +546,13 @@ public class Guild extends AbstractWorldObject {
}
public boolean canSubAGuild(Guild toSub){
public boolean canSubAGuild(Guild toSub) {
boolean canSub;
if (this.equals(toSub))
return false;
switch(this.guildState) {
switch (this.guildState) {
case Nation:
case Sovereign:
canSub = true;
@ -570,7 +561,7 @@ public class Guild extends AbstractWorldObject { @@ -570,7 +561,7 @@ public class Guild extends AbstractWorldObject {
canSub = false;
}
switch(toSub.guildState){
switch (toSub.guildState) {
case Errant:
case Sovereign:
canSub = true;
@ -585,11 +576,11 @@ public class Guild extends AbstractWorldObject { @@ -585,11 +576,11 @@ public class Guild extends AbstractWorldObject {
return canSub;
}
public static boolean canSwearIn(Guild toSub){
public static boolean canSwearIn(Guild toSub) {
boolean canSwear = false;
switch(toSub.guildState){
switch (toSub.guildState) {
case Protectorate:
case Petitioner:
@ -607,7 +598,7 @@ public class Guild extends AbstractWorldObject { @@ -607,7 +598,7 @@ public class Guild extends AbstractWorldObject {
*/
public static void _serializeForClientMsg(Guild guild, ByteBufferWriter writer) {
Guild.serializeForClientMsg(guild,writer, null, false);
Guild.serializeForClientMsg(guild, writer, null, false);
}
public static void serializeForClientMsg(Guild guild, ByteBufferWriter writer, PlayerCharacter pc, boolean reshowGuild) {
@ -635,24 +626,24 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -635,24 +626,24 @@ Guild.serializeForClientMsg(guild,writer, null, false);
City ownedCity = guild.getOwnedCity();
if (ownedCity != null){
if (ownedCity != null) {
Realm realm = guild.getOwnedCity().getRealm();
if (realm != null && realm.getRulingCity() != null){
if (realm.getRulingCity().equals(ownedCity)){
if (realm != null && realm.getRulingCity() != null) {
if (realm.getRulingCity().equals(ownedCity)) {
writer.putInt(realm.getCharterType());
}else
} else
writer.putInt(0);
}else{
} else {
writer.putInt(0);
}
}else
} else
writer.putInt(0);
writer.putFloat(200);
writer.putFloat(200); // Pad
GuildTag._serializeForDisplay(guild.guildTag,writer);
GuildTag._serializeForDisplay(guild.nation.guildTag,writer);
GuildTag._serializeForDisplay(guild.guildTag, writer);
GuildTag._serializeForDisplay(guild.nation.guildTag, writer);
if (reshowGuild) {
writer.putInt(1);
writer.putInt(guild.getObjectType().ordinal());
@ -662,10 +653,10 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -662,10 +653,10 @@ Guild.serializeForClientMsg(guild,writer, null, false);
writer.putInt(0); // Pad
}
public static void serializeForTrack(Guild guild,ByteBufferWriter writer) {
Guild.serializeGuildForTrack(guild,writer);
public static void serializeForTrack(Guild guild, ByteBufferWriter writer) {
Guild.serializeGuildForTrack(guild, writer);
if (guild.nation != null)
Guild.serializeGuildForTrack(guild.nation,writer);
Guild.serializeGuildForTrack(guild.nation, writer);
else
Guild.addErrantForTrack(writer);
}
@ -674,7 +665,7 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -674,7 +665,7 @@ Guild.serializeForClientMsg(guild,writer, null, false);
writer.putInt(guild.getObjectType().ordinal());
writer.putInt(guild.getObjectUUID());
writer.put((byte) 1);
GuildTag._serializeForDisplay(guild.guildTag,writer);
GuildTag._serializeForDisplay(guild.guildTag, writer);
}
public static void serializeErrantForTrack(ByteBufferWriter writer) {
@ -682,9 +673,9 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -682,9 +673,9 @@ Guild.serializeForClientMsg(guild,writer, null, false);
addErrantForTrack(writer); //Nation
}
public int getRealmsOwnedFlag(){
public int getRealmsOwnedFlag() {
int flag = 0;
switch(realmsOwned){
switch (realmsOwned) {
case 0:
flag = 0;
case 1:
@ -727,7 +718,7 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -727,7 +718,7 @@ Guild.serializeForClientMsg(guild,writer, null, false);
public static Guild getErrantGuild() {
if (Guild.errantGuild == null)
Guild.errantGuild = new Guild( "None", Guild.getErrantNation(), 0,
Guild.errantGuild = new Guild("None", Guild.getErrantNation(), 0,
"Anarchy", GuildTag.ERRANT, 0);
return Guild.errantGuild;
@ -793,13 +784,13 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -793,13 +784,13 @@ Guild.serializeForClientMsg(guild,writer, null, false);
//LOad Owners in Cache so we do not have to continuely look in the db for owner.
if (this.ownerIsNPC){
if (this.ownerIsNPC) {
if (NPC.getNPC(this.guildLeaderUUID) == null)
Logger.info( "Guild UID " + this.getObjectUUID() + " Failed to Load NPC Owner with ID " + this.guildLeaderUUID);
Logger.info("Guild UID " + this.getObjectUUID() + " Failed to Load NPC Owner with ID " + this.guildLeaderUUID);
}else if (this.guildLeaderUUID != 0){
} else if (this.guildLeaderUUID != 0) {
if (PlayerCharacter.getPlayerCharacter(this.guildLeaderUUID) == null)
Logger.info( "Guild UID " + this.getObjectUUID() + " Failed to Load Player Owner with ID " + this.guildLeaderUUID);
Logger.info("Guild UID " + this.getObjectUUID() + " Failed to Load Player Owner with ID " + this.guildLeaderUUID);
}
// If loading this guild for the first time write it's character record to disk
@ -829,10 +820,10 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -829,10 +820,10 @@ Guild.serializeForClientMsg(guild,writer, null, false);
//Get guild states.
try {
this.subGuildList = DbManager.GuildQueries.GET_SUB_GUILDS(this.getObjectUUID());
}catch(Exception e){
} catch (Exception e) {
this.subGuildList = new ArrayList<>();
Logger.error( "FAILED TO LOAD SUB GUILDS FOR UUID " + this.getObjectUUID());
Logger.error("FAILED TO LOAD SUB GUILDS FOR UUID " + this.getObjectUUID());
}
if (this.nation == this && subGuildList.size() > 0)
@ -861,7 +852,7 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -861,7 +852,7 @@ Guild.serializeForClientMsg(guild,writer, null, false);
}
}
if (ConfigManager.serverType.equals(ServerType.WORLDSERVER)){
if (ConfigManager.serverType.equals(ServerType.WORLDSERVER)) {
//add alliance list, clear all lists as there seems to be a bug where alliances are doubled, need to find where.
//possible runAfterLoad being called twice?!?!
@ -873,25 +864,25 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -873,25 +864,25 @@ Guild.serializeForClientMsg(guild,writer, null, false);
this.enemyList.clear();
this.recommendList.clear();
try{
try {
DbManager.GuildQueries.LOAD_ALL_ALLIANCES_FOR_GUILD(this);
for (GuildAlliances guildAlliance:this.guildAlliances.values()){
if (guildAlliance.isRecommended()){
for (GuildAlliances guildAlliance : this.guildAlliances.values()) {
if (guildAlliance.isRecommended()) {
Guild recommendedGuild = Guild.getGuild(guildAlliance.getAllianceGuild());
if (recommendedGuild != null)
this.recommendList.add(recommendedGuild);
}else if (guildAlliance.isAlly()){
} else if (guildAlliance.isAlly()) {
Guild alliedGuild = Guild.getGuild(guildAlliance.getAllianceGuild());
if (alliedGuild != null)
this.allyList.add(alliedGuild);
}else{
} else {
Guild enemyGuild = Guild.getGuild(guildAlliance.getAllianceGuild());
if (enemyGuild != null)
this.enemyList.add(enemyGuild);
}
}
}catch(Exception e){
} catch (Exception e) {
Logger.error(this.getObjectUUID() + e.getMessage());
}
}
@ -937,8 +928,7 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -937,8 +928,7 @@ Guild.serializeForClientMsg(guild,writer, null, false);
if (subGuild.getOwnedCity() == null) {
subGuild.nation = null;
}
else {
} else {
subGuild.nation = subGuild;
}
@ -959,7 +949,7 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -959,7 +949,7 @@ Guild.serializeForClientMsg(guild,writer, null, false);
this.mineTime = mineTime;
}
public ConcurrentHashMap<Integer,Condemned> getGuildCondemned() {
public ConcurrentHashMap<Integer, Condemned> getGuildCondemned() {
return guildCondemned;
}
@ -974,10 +964,10 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -974,10 +964,10 @@ Guild.serializeForClientMsg(guild,writer, null, false);
DataWarehouse.writeHash(Enum.DataRecordType.GUILD, this.getObjectUUID());
}
public Enum.GuildType getGuildType(){
try{
public Enum.GuildType getGuildType() {
try {
return Enum.GuildType.values()[this.charter];
}catch(Exception e){
} catch (Exception e) {
Logger.error(e);
return Enum.GuildType.NONE;
}
@ -992,7 +982,7 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -992,7 +982,7 @@ Guild.serializeForClientMsg(guild,writer, null, false);
this.recommendList = recommendList;
}
public synchronized boolean addGuildToAlliance(AllianceChangeMsg msg, final AllianceType allianceType, Guild toGuild, PlayerCharacter player){
public synchronized boolean addGuildToAlliance(AllianceChangeMsg msg, final AllianceType allianceType, Guild toGuild, PlayerCharacter player) {
Dispatch dispatch;
@ -1002,7 +992,7 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1002,7 +992,7 @@ Guild.serializeForClientMsg(guild,writer, null, false);
if (toGuild == null)
return false;
if (!Guild.sameGuild(player.getGuild(), this)){
if (!Guild.sameGuild(player.getGuild(), this)) {
msg.setMsgType(AllianceChangeMsg.ERROR_NOT_SAME_GUILD);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
@ -1010,15 +1000,15 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1010,15 +1000,15 @@ Guild.serializeForClientMsg(guild,writer, null, false);
}
if (allianceType == AllianceType.Ally || allianceType == AllianceType.Enemy)
if (!GuildStatusController.isInnerCouncil(player.getGuildStatus()) && !GuildStatusController.isGuildLeader(player.getGuildStatus())){
if (!GuildStatusController.isInnerCouncil(player.getGuildStatus()) && !GuildStatusController.isGuildLeader(player.getGuildStatus())) {
msg.setMsgType(AllianceChangeMsg.ERROR_NOT_AUTHORIZED);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
if (allianceType == AllianceType.RecommendedAlly || allianceType == AllianceType.RecommendedEnemy){
if (!GuildStatusController.isFullMember(player.getGuildStatus())){
if (allianceType == AllianceType.RecommendedAlly || allianceType == AllianceType.RecommendedEnemy) {
if (!GuildStatusController.isFullMember(player.getGuildStatus())) {
msg.setMsgType(AllianceChangeMsg.ERROR_NOT_AUTHORIZED);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
@ -1034,29 +1024,25 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1034,29 +1024,25 @@ Guild.serializeForClientMsg(guild,writer, null, false);
// }
switch(allianceType){
switch (allianceType) {
case RecommendedAlly:
if (recommendList.size() == 10){
if (recommendList.size() == 10) {
msg.setMsgType(AllianceChangeMsg.ERROR_TOO_MANY);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
if (recommendList.contains(toGuild)){
if (recommendList.contains(toGuild)) {
ErrorPopupMsg.sendErrorMsg(player, "This guild is already recommonded!");
msg.setMsgType((byte)15);
msg.setMsgType((byte) 15);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
if (!DbManager.GuildQueries.ADD_TO_ALLIANCE_LIST(this.getObjectUUID(), toGuild.getObjectUUID(), true, true, player.getFirstName())){
msg.setMsgType((byte)15);
if (!DbManager.GuildQueries.ADD_TO_ALLIANCE_LIST(this.getObjectUUID(), toGuild.getObjectUUID(), true, true, player.getFirstName())) {
msg.setMsgType((byte) 15);
dispatch = Dispatch.borrow(player, msg);
return false;
}
@ -1068,27 +1054,26 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1068,27 +1054,26 @@ Guild.serializeForClientMsg(guild,writer, null, false);
this.recommendList.add(toGuild);
return true;
case RecommendedEnemy:
if (recommendList.size() == 10){
if (recommendList.size() == 10) {
msg.setMsgType(AllianceChangeMsg.ERROR_TOO_MANY);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
if (recommendList.contains(toGuild)){
if (recommendList.contains(toGuild)) {
ErrorPopupMsg.sendErrorMsg(player, "This guild is already recommonded!");
msg.setMsgType((byte)15);
msg.setMsgType((byte) 15);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
if (!DbManager.GuildQueries.ADD_TO_ALLIANCE_LIST(this.getObjectUUID(), toGuild.getObjectUUID(), true, false, player.getFirstName())){
msg.setMsgType((byte)15);
if (!DbManager.GuildQueries.ADD_TO_ALLIANCE_LIST(this.getObjectUUID(), toGuild.getObjectUUID(), true, false, player.getFirstName())) {
msg.setMsgType((byte) 15);
dispatch = Dispatch.borrow(player, msg);
return false;
}
@ -1102,35 +1087,35 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1102,35 +1087,35 @@ Guild.serializeForClientMsg(guild,writer, null, false);
return true;
case Ally:
if (allyList.size() == 10){
if (allyList.size() == 10) {
msg.setMsgType(AllianceChangeMsg.ERROR_TOO_MANY);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
if (allyList.contains(toGuild)){
if (allyList.contains(toGuild)) {
ErrorPopupMsg.sendErrorMsg(player, "This guild is already an Ally!");
msg.setMsgType((byte)15);
msg.setMsgType((byte) 15);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
if (!this.guildAlliances.containsKey(toGuild.getObjectUUID())){
if (!this.guildAlliances.containsKey(toGuild.getObjectUUID())) {
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has Occured. Please contact CCR!");
Logger.error(this.getObjectUUID() + " Could not find alliance Guild");
msg.setMsgType((byte)15);
msg.setMsgType((byte) 15);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
GuildAlliances ally = this.guildAlliances.get(toGuild.getObjectUUID());
if (!ally.UpdateAlliance(AllianceType.Ally, this.recommendList.contains(toGuild))){
if (!ally.UpdateAlliance(AllianceType.Ally, this.recommendList.contains(toGuild))) {
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has Occured. Please contact CCR!");
Logger.error( this.getObjectUUID() + " failed to update alliance Database");
msg.setMsgType((byte)15);
Logger.error(this.getObjectUUID() + " failed to update alliance Database");
msg.setMsgType((byte) 15);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
@ -1146,35 +1131,35 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1146,35 +1131,35 @@ Guild.serializeForClientMsg(guild,writer, null, false);
break;
case Enemy:
if (enemyList.size() == 10){
if (enemyList.size() == 10) {
msg.setMsgType(AllianceChangeMsg.ERROR_TOO_MANY);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
if (enemyList.contains(toGuild)){
if (enemyList.contains(toGuild)) {
ErrorPopupMsg.sendErrorMsg(player, "This guild is already an Enemy!");
msg.setMsgType((byte)15);
msg.setMsgType((byte) 15);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
if (!this.guildAlliances.containsKey(toGuild.getObjectUUID())){
if (!this.guildAlliances.containsKey(toGuild.getObjectUUID())) {
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has Occured. Please contact CCR!");
Logger.error( this.getObjectUUID() + " Could not find alliance Guild");
msg.setMsgType((byte)15);
Logger.error(this.getObjectUUID() + " Could not find alliance Guild");
msg.setMsgType((byte) 15);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
}
GuildAlliances enemy = this.guildAlliances.get(toGuild.getObjectUUID());
if (!enemy.UpdateAlliance(AllianceType.Enemy, this.recommendList.contains(toGuild))){
if (!enemy.UpdateAlliance(AllianceType.Enemy, this.recommendList.contains(toGuild))) {
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has Occured. Please contact CCR!");
Logger.error(this.getObjectUUID() + " failed to update alliance Database");
msg.setMsgType((byte)15);
msg.setMsgType((byte) 15);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
return false;
@ -1198,28 +1183,24 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1198,28 +1183,24 @@ Guild.serializeForClientMsg(guild,writer, null, false);
return true;
}
public synchronized boolean removeGuildFromAlliance(Guild toRemove){
if (this.allyList.contains(toRemove)){
public synchronized boolean removeGuildFromAlliance(Guild toRemove) {
this.allyList.remove(toRemove);
}
return true;
}
public synchronized boolean removeGuildFromEnemy(Guild toRemove){
if (this.enemyList.contains(toRemove)){
public synchronized boolean removeGuildFromEnemy(Guild toRemove) {
this.enemyList.remove(toRemove);
}
return true;
}
public synchronized boolean removeGuildFromRecommended(Guild toRemove){
if (this.recommendList.contains(toRemove)){
public synchronized boolean removeGuildFromRecommended(Guild toRemove) {
this.recommendList.remove(toRemove);
}
return true;
}
public synchronized boolean removeGuildFromAllAlliances(Guild toRemove){
public synchronized boolean removeGuildFromAllAlliances(Guild toRemove) {
if (!this.guildAlliances.containsKey(toRemove.getObjectUUID())){
if (!this.guildAlliances.containsKey(toRemove.getObjectUUID())) {
return false;
}
@ -1227,7 +1208,6 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1227,7 +1208,6 @@ Guild.serializeForClientMsg(guild,writer, null, false);
return false;
this.guildAlliances.remove(toRemove.getObjectUUID());
this.removeGuildFromAlliance(toRemove);
@ -1241,14 +1221,13 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1241,14 +1221,13 @@ Guild.serializeForClientMsg(guild,writer, null, false);
}
public static void UpdateClientAlliances(Guild toUpdate){
public static void UpdateClientAlliances(Guild toUpdate) {
UpdateClientAlliancesMsg ucam = new UpdateClientAlliancesMsg(toUpdate);
for (PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()) {
if (Guild.sameGuild(player.getGuild(), toUpdate)){
if (Guild.sameGuild(player.getGuild(), toUpdate)) {
Dispatch dispatch = Dispatch.borrow(player, ucam);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
}
@ -1257,7 +1236,7 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1257,7 +1236,7 @@ Guild.serializeForClientMsg(guild,writer, null, false);
}
}
public static void UpdateClientAlliancesForPlayer(PlayerCharacter toUpdate){
public static void UpdateClientAlliancesForPlayer(PlayerCharacter toUpdate) {
UpdateClientAlliancesMsg ucam = new UpdateClientAlliancesMsg(toUpdate.getGuild());
Dispatch dispatch = Dispatch.borrow(toUpdate, ucam);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
@ -1269,7 +1248,7 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1269,7 +1248,7 @@ Guild.serializeForClientMsg(guild,writer, null, false);
return (Guild) DbManager.getFromCache(GameObjectType.Guild, id);
}
public static ArrayList<PlayerCharacter> GuildRoster(Guild guild){
public static ArrayList<PlayerCharacter> GuildRoster(Guild guild) {
ArrayList<PlayerCharacter> roster = new ArrayList<>();
if (guild == null)
return roster;
@ -1279,8 +1258,8 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1279,8 +1258,8 @@ Guild.serializeForClientMsg(guild,writer, null, false);
if (DbManager.getList(GameObjectType.PlayerCharacter) == null)
return roster;
for (AbstractGameObject ago : DbManager.getList(GameObjectType.PlayerCharacter)){
PlayerCharacter toAdd = (PlayerCharacter)ago;
for (AbstractGameObject ago : DbManager.getList(GameObjectType.PlayerCharacter)) {
PlayerCharacter toAdd = (PlayerCharacter) ago;
if (!toAdd.getGuild().equals(guild))
continue;
@ -1295,5 +1274,4 @@ Guild.serializeForClientMsg(guild,writer, null, false); @@ -1295,5 +1274,4 @@ Guild.serializeForClientMsg(guild,writer, null, false);
}
}

2
src/engine/server/MBServerStatics.java

@ -793,7 +793,7 @@ public class MBServerStatics { @@ -793,7 +793,7 @@ public class MBServerStatics {
public static final int MAX_PLAYER_LOAD_SIZE = 1000;
// Mine related
public static final int MINE_EARLY_WINDOW = 16; // 3pm
public static final int MINE_EARLY_WINDOW = 16; // 4pm
public static final int MINE_LATE_WINDOW = 0; // Midnight
// Race

66
src/engine/workthreads/HourlyJobThread.java

@ -22,9 +22,11 @@ import java.time.LocalDateTime; @@ -22,9 +22,11 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import static engine.server.MBServerStatics.MINE_LATE_WINDOW;
public class HourlyJobThread implements Runnable {
private static int hotzoneCount = 0;
private static final int hotzoneCount = 0;
public HourlyJobThread() {
@ -42,20 +44,22 @@ public class HourlyJobThread implements Runnable { @@ -42,20 +44,22 @@ public class HourlyJobThread implements Runnable {
Zone hotzone = ZoneManager.getHotZone();
if (hotzone == null) {
Logger.error( "Null hotzone returned from mapmanager");
Logger.error("Null hotzone returned from mapmanager");
} else {
Logger.info( "new hotzone: " + hotzone.getName());
Logger.info("new hotzone: " + hotzone.getName());
WorldServer.setLastHZChange(System.currentTimeMillis());
}
} catch (Exception e) {
Logger.error( e.toString());
Logger.error(e.toString());
}
// Open or Close mines for the current mine window.
processMineWindow();
// Deposit mine resources to Guilds
for (Mine mine : Mine.getMines()) {
try {
@ -65,6 +69,33 @@ public class HourlyJobThread implements Runnable { @@ -65,6 +69,33 @@ public class HourlyJobThread implements Runnable {
}
}
// Reset time-gated access to WOO slider.
// *** Do this after the mines open/close!
if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) {
Guild guild;
for (AbstractGameObject dbObject : DbManager.getList(Enum.GameObjectType.Guild)) {
guild = (Guild) dbObject;
if (guild != null)
guild.wooWasModified = false;
}
}
// Mines can only be claimed once per cycle.
// This will reset at 1am after the last mine
// window closes.
if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW + 1) {
for (Mine mine : Mine.getMines()) {
if (mine.wasClaimed == true)
mine.wasClaimed = false;
}
}
// Update city population values
@ -72,9 +103,9 @@ public class HourlyJobThread implements Runnable { @@ -72,9 +103,9 @@ public class HourlyJobThread implements Runnable {
if (map != null) {
for (AbstractGameObject ago : map.values()){
for (AbstractGameObject ago : map.values()) {
City city = (City)ago;
City city = (City) ago;
if (city != null)
if (city.getGuild() != null) {
@ -88,9 +119,9 @@ public class HourlyJobThread implements Runnable { @@ -88,9 +119,9 @@ public class HourlyJobThread implements Runnable {
}
// Log metrics to console
Logger.info( WorldServer.getUptimeString());
Logger.info( SimulationManager.getPopulationString());
Logger.info( MessageDispatcher.getNetstatString());
Logger.info(WorldServer.getUptimeString());
Logger.info(SimulationManager.getPopulationString());
Logger.info(MessageDispatcher.getNetstatString());
Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted");
}
@ -101,19 +132,8 @@ public class HourlyJobThread implements Runnable { @@ -101,19 +132,8 @@ public class HourlyJobThread implements Runnable {
ArrayList<Mine> mines = Mine.getMines();
for (Mine mine : mines) {
try {
// Mines can only be claimed once a cycle.
// The cycle resets at 01:00hrs after the
// Last mine window closes.
if (mine.wasClaimed == true) {
if (LocalDateTime.now().getHour() == 01)
mine.wasClaimed = false;
continue;
}
try {
// Open Errant Mines
@ -138,11 +158,11 @@ public class HourlyJobThread implements Runnable { @@ -138,11 +158,11 @@ public class HourlyJobThread implements Runnable {
Mine.setLastChange(System.currentTimeMillis());
} catch (Exception e) {
Logger.error ("mineID: " + mine.getObjectUUID(), e.toString());
Logger.error("mineID: " + mine.getObjectUUID(), e.toString());
}
}
} catch (Exception e) {
Logger.error( e.toString());
Logger.error(e.toString());
}
}
}

Loading…
Cancel
Save