@ -296,127 +296,218 @@ public class dbGuildHandler extends dbHandlerBase {
public boolean IS_CREST_UNIQUE ( final GuildTag gt ) {
public boolean IS_CREST_UNIQUE ( final GuildTag gt ) {
boolean valid = false ;
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`=?;" ;
if ( gt . backgroundColor01 = = gt . backgroundColor02 ) {
//both background colors the same, ignore backgroundDesign
prepareCallable ( "SELECT `name` FROM `obj_guild` WHERE `backgroundColor01`=? && `backgroundColor02`=? && `symbolColor`=? && `symbol`=?;" ) ;
setInt ( 1 , gt . backgroundColor01 ) ;
setInt ( 2 , gt . backgroundColor02 ) ;
setInt ( 3 , gt . symbolColor ) ;
setInt ( 4 , gt . 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 {
} else {
prepareCallable ( "SELECT `name` FROM `obj_guild` WHERE `backgroundColor01`=? && `backgroundColor02`=? && `symbolColor`=? && `backgroundDesign`=? && `symbol`=?;" ) ;
preparedStatement . setInt ( 1 , gt . backgroundColor01 ) ;
setInt ( 1 , gt . backgroundColor01 ) ;
preparedStatement . setInt ( 2 , gt . backgroundColor02 ) ;
setInt ( 2 , gt . backgroundColor02 ) ;
preparedStatement . setInt ( 3 , gt . symbolColor ) ;
setInt ( 3 , gt . symbolColor ) ;
preparedStatement . setInt ( 4 , gt . backgroundDesign ) ;
setInt ( 4 , gt . backgroundDesign ) ;
preparedStatement . setInt ( 5 , gt . symbol ) ;
setInt ( 5 , gt . symbol ) ;
}
}
try {
ResultSet rs = executeQuery ( ) ;
ResultSet rs = preparedStatement . executeQuery ( ) ;
if ( ! rs . next ( ) )
if ( ! rs . next ( ) )
valid = true ;
valid = true ;
rs . close ( ) ;
} catch ( SQLException e ) {
} catch ( SQLException e ) {
Logger . error ( e . getMessage ( ) ) ;
Logger . error ( e ) ;
}
}
return valid ;
return valid ;
}
}
public boolean SET_GUILD_OWNED_CITY ( int guildID , int cityID ) {
public boolean SET_GUILD_OWNED_CITY ( int guildID , int cityID ) {
prepareCallable ( "UPDATE `obj_guild` SET `ownedCity`=? WHERE `UID`=?" ) ;
setLong ( 1 , ( long ) cityID ) ;
try ( Connection connection = DbManager . getConnection ( ) ;
setLong ( 2 , ( long ) guildID ) ;
PreparedStatement preparedStatement = connection . prepareStatement ( "UPDATE `obj_guild` SET `ownedCity`=? WHERE `UID`=?" ) ) {
return ( executeUpdate ( ) > 0 ) ;
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 ) {
public boolean SET_GUILD_LEADER ( int objectUUID , int guildID ) {
prepareCallable ( "UPDATE `obj_guild` SET `leaderUID`=? WHERE `UID`=?" ) ;
setLong ( 1 , ( long ) objectUUID ) ;
try ( Connection connection = DbManager . getConnection ( ) ;
setLong ( 2 , ( long ) guildID ) ;
PreparedStatement preparedStatement = connection . prepareStatement ( "UPDATE `obj_guild` SET `leaderUID`=? WHERE `UID`=?" ) ) {
return ( executeUpdate ( ) > 0 ) ;
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 ) {
public boolean IS_NAME_UNIQUE ( final String name ) {
boolean valid = false ;
boolean valid = false ;
prepareCallable ( "SELECT `name` FROM `obj_guild` WHERE `name`=?;" ) ;
setString ( 1 , name ) ;
try ( Connection connection = DbManager . getConnection ( ) ;
try {
PreparedStatement preparedStatement = connection . prepareStatement ( "SELECT `name` FROM `obj_guild` WHERE `name`=?;" ) ) {
ResultSet rs = executeQuery ( ) ;
preparedStatement . setString ( 1 , name ) ;
ResultSet rs = preparedStatement . executeQuery ( ) ;
if ( ! rs . next ( ) )
if ( ! rs . next ( ) )
valid = true ;
valid = true ;
rs . close ( ) ;
} catch ( SQLException e ) {
} catch ( SQLException e ) {
Logger . warn ( e . getMessage ( ) ) ;
Logger . error ( e ) ;
return false ;
}
}
return valid ;
return valid ;
}
}
public Guild SAVE_TO_DATABASE ( Guild g ) {
public Guild SAVE_TO_DATABASE ( Guild g ) {
prepareCallable ( "CALL `guild_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ) ;
GuildTag gt = g . getGuildTag ( ) ;
Guild guild = null ;
if ( gt = = null )
GuildTag guildTag = g . getGuildTag ( ) ;
if ( guildTag = = null )
return null ;
return null ;
setLong ( 1 , MBServerStatics . worldUUID ) ;
setLong ( 2 , g . getGuildLeaderUUID ( ) ) ;
try ( Connection connection = DbManager . getConnection ( ) ;
setString ( 3 , g . getName ( ) ) ;
PreparedStatement preparedStatement = connection . prepareStatement ( "CALL `guild_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ) ) {
setInt ( 4 , gt . backgroundColor01 ) ;
setInt ( 5 , gt . backgroundColor02 ) ;
preparedStatement . setLong ( 1 , MBServerStatics . worldUUID ) ;
setInt ( 6 , gt . symbolColor ) ;
preparedStatement . setLong ( 2 , g . getGuildLeaderUUID ( ) ) ;
setInt ( 7 , gt . backgroundDesign ) ;
preparedStatement . setString ( 3 , g . getName ( ) ) ;
setInt ( 8 , gt . symbol ) ;
preparedStatement . setInt ( 4 , guildTag . backgroundColor01 ) ;
setInt ( 9 , g . getCharter ( ) ) ;
preparedStatement . setInt ( 5 , guildTag . backgroundColor02 ) ;
setString ( 10 , g . getLeadershipType ( ) ) ;
preparedStatement . setInt ( 6 , guildTag . symbolColor ) ;
setString ( 11 , g . getMotto ( ) ) ;
preparedStatement . setInt ( 7 , guildTag . backgroundDesign ) ;
preparedStatement . setInt ( 8 , guildTag . symbol ) ;
int objectUUID = ( int ) getUUID ( ) ;
preparedStatement . setInt ( 9 , g . getCharter ( ) ) ;
preparedStatement . setString ( 10 , g . getLeadershipType ( ) ) ;
preparedStatement . setString ( 11 , g . getMotto ( ) ) ;
ResultSet rs = preparedStatement . executeQuery ( ) ;
int objectUUID = ( int ) rs . getLong ( "UID" ) ;
if ( objectUUID > 0 )
if ( objectUUID > 0 )
return GET_GUILD ( objectUUID ) ;
guild = GET_GUILD ( objectUUID ) ;
return null ;
} catch ( SQLException e ) {
Logger . error ( e ) ;
}
return guild ;
}
}
public boolean UPDATE_GUILD_RANK_OFFLINE ( int target , int newRank , int guildId ) {
public boolean UPDATE_GUILD_RANK_OFFLINE ( int target , int newRank , int guildId ) {
prepareCallable ( "UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=? && `guildUID`=?" ) ;
setInt ( 1 , newRank ) ;
try ( Connection connection = DbManager . getConnection ( ) ;
setInt ( 2 , target ) ;
PreparedStatement preparedStatement = connection . prepareStatement ( "UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=? && `guildUID`=?" ) ) {
setInt ( 3 , guildId ) ;
return ( executeUpdate ( ) > 0 ) ;
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 ) {
public boolean UPDATE_PARENT ( int guildUID , int parentUID ) {
prepareCallable ( "UPDATE `object` SET `parent`=? WHERE `UID`=?" ) ;
setInt ( 1 , parentUID ) ;
try ( Connection connection = DbManager . getConnection ( ) ;
setInt ( 2 , guildUID ) ;
PreparedStatement preparedStatement = connection . prepareStatement ( "UPDATE `object` SET `parent`=? WHERE `UID`=?" ) ) {
return ( executeUpdate ( ) > 0 ) ;
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 ) {
public int DELETE_GUILD ( final Guild guild ) {
prepareCallable ( "DELETE FROM `object` WHERE `UID` = ?" ) ;
setLong ( 1 , ( long ) guild . getObjectUUID ( ) ) ;
int row_count = 0 ;
return executeUpdate ( ) ;
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 ) {
public boolean UPDATE_MINETIME ( int guildUID , int mineTime ) {
prepareCallable ( "UPDATE `obj_guild` SET `mineTime`=? WHERE `UID`=?" ) ;
setInt ( 1 , mineTime ) ;
try ( Connection connection = DbManager . getConnection ( ) ;
setInt ( 2 , guildUID ) ;
PreparedStatement preparedStatement = connection . prepareStatement ( "UPDATE `obj_guild` SET `mineTime`=? WHERE `UID`=?" ) ) {
return ( executeUpdate ( ) > 0 ) ;
preparedStatement . setInt ( 1 , mineTime ) ;
preparedStatement . setInt ( 2 , guildUID ) ;
return ( preparedStatement . executeUpdate ( ) > 0 ) ;
} catch ( SQLException e ) {
Logger . error ( e ) ;
return false ;
}
}
}
public int UPDATE_GUILD_STATUS_OFFLINE ( int target , boolean isInnerCouncil , boolean isRecruiter , boolean isTaxCollector , int guildId ) {
public int UPDATE_GUILD_STATUS_OFFLINE ( int target , boolean isInnerCouncil , boolean isRecruiter , boolean isTaxCollector , int guildId ) {
int updateMask = 0 ;
int updateMask = 0 ;
prepareCallable ( "SELECT `guild_isInnerCouncil`, `guild_isTaxCollector`, `guild_isRecruiter` FROM `obj_character` WHERE `UID`=? && `guildUID`=?" ) ;
int row_count = 0 ;
setLong ( 1 , ( long ) target ) ;
setLong ( 2 , ( long ) guildId ) ;
try ( Connection connection = DbManager . getConnection ( ) ;
try {
PreparedStatement preparedStatement = connection . prepareStatement ( "SELECT `guild_isInnerCouncil`, `guild_isTaxCollector`, `guild_isRecruiter` FROM `obj_character` WHERE `UID`=? && `guildUID`=?" ) ) {
ResultSet rs = executeQuery ( ) ;
preparedStatement . setLong ( 1 , target ) ;
preparedStatement . setLong ( 2 , guildId ) ;
ResultSet rs = preparedStatement . executeQuery ( ) ;
//If the first query had no results, neither will the second
//If the first query had no results, neither will the second
if ( rs . first ( ) ) {
//Determine what is different
//Determine what is different
if ( rs . first ( ) ) {
if ( rs . getBoolean ( "guild_isInnerCouncil" ) ! = isInnerCouncil )
if ( rs . getBoolean ( "guild_isInnerCouncil" ) ! = isInnerCouncil )
updateMask | = 4 ;
updateMask | = 4 ;
if ( rs . getBoolean ( "guild_isRecruiter" ) ! = isRecruiter )
if ( rs . getBoolean ( "guild_isRecruiter" ) ! = isRecruiter )
@ -424,19 +515,26 @@ public class dbGuildHandler extends dbHandlerBase {
if ( rs . getBoolean ( "guild_isTaxCollector" ) ! = isTaxCollector )
if ( rs . getBoolean ( "guild_isTaxCollector" ) ! = isTaxCollector )
updateMask | = 1 ;
updateMask | = 1 ;
}
}
rs . close ( ) ;
} catch ( SQLException e ) {
} catch ( SQLException e ) {
Logger . error ( e . toString ( ) ) ;
Logger . error ( e ) ;
}
}
prepareCallable ( "UPDATE `obj_character` SET `guild_isInnerCouncil`=?, `guild_isTaxCollector`=?, `guild_isRecruiter`=?, `guild_isFullMember`=? WHERE `UID`=? && `guildUID`=?" ) ;
setBoolean ( 1 , isInnerCouncil ) ;
setBoolean ( 2 , isRecruiter ) ;
setBoolean ( 3 , isTaxCollector ) ;
setBoolean ( 4 , ( ( updateMask > 0 ) ) ) ; //If you are becoming an officer, or where an officer, your a full member...
setLong ( 5 , ( long ) target ) ;
setLong ( 6 , ( long ) guildId ) ;
return executeUpdate ( ) ;
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 ;
}
}