All packet creating methods now create Packet instead of byte[]

This commit got way too big...
- Remove deprecated methods for sending packets
- Favor OutPacket & Packet over MaplePacketLittleEndianWriter, LittleEndianWriter, and byte array
- Split up some packet creating methods into separate classes
This commit is contained in:
P0nk
2021-08-21 01:36:51 +02:00
parent b5cd6887ae
commit 8f6860d7d7
231 changed files with 6403 additions and 6927 deletions

View File

@@ -0,0 +1,543 @@
package net.server.guild;
import client.MapleCharacter;
import client.MapleClient;
import net.opcodes.SendOpcode;
import net.packet.OutPacket;
import net.packet.Packet;
import net.server.Server;
import tools.PacketCreator;
import tools.Pair;
import tools.StringUtil;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
public class GuildPackets {
public static Packet showGuildInfo(MapleCharacter chr) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x1A); //signature for showing guild info
if (chr == null) { //show empty guild (used for leaving, expelled)
p.writeByte(0);
return p;
}
MapleGuild g = chr.getClient().getWorldServer().getGuild(chr.getMGC());
if (g == null) { //failed to read from DB - don't show a guild
p.writeByte(0);
return p;
}
p.writeByte(1); //bInGuild
p.writeInt(g.getId());
p.writeString(g.getName());
for (int i = 1; i <= 5; i++) {
p.writeString(g.getRankTitle(i));
}
Collection<MapleGuildCharacter> members = g.getMembers();
p.writeByte(members.size()); //then it is the size of all the members
for (MapleGuildCharacter mgc : members) {//and each of their character ids o_O
p.writeInt(mgc.getId());
}
for (MapleGuildCharacter mgc : members) {
p.writeFixedString(StringUtil.getRightPaddedStr(mgc.getName(), '\0', 13));
p.writeInt(mgc.getJobId());
p.writeInt(mgc.getLevel());
p.writeInt(mgc.getGuildRank());
p.writeInt(mgc.isOnline() ? 1 : 0);
p.writeInt(g.getSignature());
p.writeInt(mgc.getAllianceRank());
}
p.writeInt(g.getCapacity());
p.writeShort(g.getLogoBG());
p.writeByte(g.getLogoBGColor());
p.writeShort(g.getLogo());
p.writeByte(g.getLogoColor());
p.writeString(g.getNotice());
p.writeInt(g.getGP());
p.writeInt(g.getAllianceId());
return p;
}
public static Packet guildMemberOnline(int guildId, int chrId, boolean bOnline) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x3d);
p.writeInt(guildId);
p.writeInt(chrId);
p.writeBool(bOnline);
return p;
}
public static Packet guildInvite(int guildId, String charName) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x05);
p.writeInt(guildId);
p.writeString(charName);
return p;
}
public static Packet createGuildMessage(String masterName, String guildName) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x3);
p.writeInt(0);
p.writeString(masterName);
p.writeString(guildName);
return p;
}
/**
* Gets a Heracle/guild message packet.
* <p>
* Possible values for <code>code</code>:<br> 28: guild name already in use<br>
* 31: problem in locating players during agreement<br> 33/40: already joined a guild<br>
* 35: Cannot make guild<br> 36: problem in player agreement<br> 38: problem during forming guild<br>
* 41: max number of players in joining guild<br> 42: character can't be found this channel<br>
* 45/48: character not in guild<br> 52: problem in disbanding guild<br> 56: admin cannot make guild<br>
* 57: problem in increasing guild size<br>
*
* @param code The response code.
* @return The guild message packet.
*/
public static Packet genericGuildMessage(byte code) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(code);
return p;
}
/**
* Gets a guild message packet appended with target name.
* <p>
* 53: player not accepting guild invites<br>
* 54: player already managing an invite<br> 55: player denied an invite<br>
*
* @param code The response code.
* @param targetName The initial player target of the invitation.
* @return The guild message packet.
*/
public static Packet responseGuildMessage(byte code, String targetName) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(code);
p.writeString(targetName);
return p;
}
public static Packet newGuildMember(MapleGuildCharacter mgc) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x27);
p.writeInt(mgc.getGuildId());
p.writeInt(mgc.getId());
p.writeFixedString(StringUtil.getRightPaddedStr(mgc.getName(), '\0', 13));
p.writeInt(mgc.getJobId());
p.writeInt(mgc.getLevel());
p.writeInt(mgc.getGuildRank()); //should be always 5 but whatevs
p.writeInt(mgc.isOnline() ? 1 : 0); //should always be 1 too
p.writeInt(1); //? could be guild signature, but doesn't seem to matter
p.writeInt(3);
return p;
}
//someone leaving, mode == 0x2c for leaving, 0x2f for expelled
public static Packet memberLeft(MapleGuildCharacter mgc, boolean bExpelled) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(bExpelled ? 0x2f : 0x2c);
p.writeInt(mgc.getGuildId());
p.writeInt(mgc.getId());
p.writeString(mgc.getName());
return p;
}
//rank change
public static Packet changeRank(MapleGuildCharacter mgc) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x40);
p.writeInt(mgc.getGuildId());
p.writeInt(mgc.getId());
p.writeByte(mgc.getGuildRank());
return p;
}
public static Packet guildNotice(int guildId, String notice) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x44);
p.writeInt(guildId);
p.writeString(notice);
return p;
}
public static Packet guildMemberLevelJobUpdate(MapleGuildCharacter mgc) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x3C);
p.writeInt(mgc.getGuildId());
p.writeInt(mgc.getId());
p.writeInt(mgc.getLevel());
p.writeInt(mgc.getJobId());
return p;
}
public static Packet rankTitleChange(int guildId, String[] ranks) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x3E);
p.writeInt(guildId);
for (int i = 0; i < 5; i++) {
p.writeString(ranks[i]);
}
return p;
}
public static Packet guildDisband(int guildId) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x32);
p.writeInt(guildId);
p.writeByte(1);
return p;
}
public static Packet guildQuestWaitingNotice(byte channel, int waitingPos) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x4C);
p.writeByte(channel - 1);
p.writeByte(waitingPos);
return p;
}
public static Packet guildEmblemChange(int guildId, short bg, byte bgcolor, short logo, byte logoColor) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x42);
p.writeInt(guildId);
p.writeShort(bg);
p.writeByte(bgcolor);
p.writeShort(logo);
p.writeByte(logoColor);
return p;
}
public static Packet guildCapacityChange(int guildId, int capacity) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x3A);
p.writeInt(guildId);
p.writeByte(capacity);
return p;
}
public static void addThread(final OutPacket p, ResultSet rs) throws SQLException {
p.writeInt(rs.getInt("localthreadid"));
p.writeInt(rs.getInt("postercid"));
p.writeString(rs.getString("name"));
p.writeLong(PacketCreator.getTime(rs.getLong("timestamp")));
p.writeInt(rs.getInt("icon"));
p.writeInt(rs.getInt("replycount"));
}
public static Packet BBSThreadList(ResultSet rs, int start) throws SQLException {
OutPacket p = OutPacket.create(SendOpcode.GUILD_BBS_PACKET);
p.writeByte(0x06);
if (!rs.last()) {
p.writeByte(0);
p.writeInt(0);
p.writeInt(0);
return p;
}
int threadCount = rs.getRow();
if (rs.getInt("localthreadid") == 0) { //has a notice
p.writeByte(1);
addThread(p, rs);
threadCount--; //one thread didn't count (because it's a notice)
} else {
p.writeByte(0);
}
if (!rs.absolute(start + 1)) { //seek to the thread before where we start
rs.first(); //uh, we're trying to start at a place past possible
start = 0;
}
p.writeInt(threadCount);
p.writeInt(Math.min(10, threadCount - start));
for (int i = 0; i < Math.min(10, threadCount - start); i++) {
addThread(p, rs);
rs.next();
}
return p;
}
public static Packet showThread(int localthreadid, ResultSet threadRS, ResultSet repliesRS) throws SQLException, RuntimeException {
OutPacket p = OutPacket.create(SendOpcode.GUILD_BBS_PACKET);
p.writeByte(0x07);
p.writeInt(localthreadid);
p.writeInt(threadRS.getInt("postercid"));
p.writeLong(PacketCreator.getTime(threadRS.getLong("timestamp")));
p.writeString(threadRS.getString("name"));
p.writeString(threadRS.getString("startpost"));
p.writeInt(threadRS.getInt("icon"));
if (repliesRS != null) {
int replyCount = threadRS.getInt("replycount");
p.writeInt(replyCount);
int i;
for (i = 0; i < replyCount && repliesRS.next(); i++) {
p.writeInt(repliesRS.getInt("replyid"));
p.writeInt(repliesRS.getInt("postercid"));
p.writeLong(PacketCreator.getTime(repliesRS.getLong("timestamp")));
p.writeString(repliesRS.getString("content"));
}
if (i != replyCount || repliesRS.next()) {
throw new RuntimeException(String.valueOf(threadRS.getInt("threadid")));
}
} else {
p.writeInt(0);
}
return p;
}
public static Packet showGuildRanks(int npcid, ResultSet rs) throws SQLException {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x49);
p.writeInt(npcid);
if (!rs.last()) { //no guilds o.o
p.writeInt(0);
return p;
}
p.writeInt(rs.getRow()); //number of entries
rs.beforeFirst();
while (rs.next()) {
p.writeString(rs.getString("name"));
p.writeInt(rs.getInt("GP"));
p.writeInt(rs.getInt("logo"));
p.writeInt(rs.getInt("logoColor"));
p.writeInt(rs.getInt("logoBG"));
p.writeInt(rs.getInt("logoBGColor"));
}
return p;
}
public static Packet showPlayerRanks(int npcid, List<Pair<String, Integer>> worldRanking) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x49);
p.writeInt(npcid);
if (worldRanking.isEmpty()) {
p.writeInt(0);
return p;
}
p.writeInt(worldRanking.size());
for (Pair<String, Integer> wr : worldRanking) {
p.writeString(wr.getLeft());
p.writeInt(wr.getRight());
p.writeInt(0);
p.writeInt(0);
p.writeInt(0);
p.writeInt(0);
}
return p;
}
public static Packet updateGP(int guildId, int GP) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_OPERATION);
p.writeByte(0x48);
p.writeInt(guildId);
p.writeInt(GP);
return p;
}
public static void getGuildInfo(OutPacket p, MapleGuild guild) {
p.writeInt(guild.getId());
p.writeString(guild.getName());
for (int i = 1; i <= 5; i++) {
p.writeString(guild.getRankTitle(i));
}
Collection<MapleGuildCharacter> members = guild.getMembers();
p.writeByte(members.size());
for (MapleGuildCharacter mgc : members) {
p.writeInt(mgc.getId());
}
for (MapleGuildCharacter mgc : members) {
p.writeFixedString(StringUtil.getRightPaddedStr(mgc.getName(), '\0', 13));
p.writeInt(mgc.getJobId());
p.writeInt(mgc.getLevel());
p.writeInt(mgc.getGuildRank());
p.writeInt(mgc.isOnline() ? 1 : 0);
p.writeInt(guild.getSignature());
p.writeInt(mgc.getAllianceRank());
}
p.writeInt(guild.getCapacity());
p.writeShort(guild.getLogoBG());
p.writeByte(guild.getLogoBGColor());
p.writeShort(guild.getLogo());
p.writeByte(guild.getLogoColor());
p.writeString(guild.getNotice());
p.writeInt(guild.getGP());
p.writeInt(guild.getAllianceId());
}
public static Packet getAllianceInfo(MapleAlliance alliance) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x0C);
p.writeByte(1);
p.writeInt(alliance.getId());
p.writeString(alliance.getName());
for (int i = 1; i <= 5; i++) {
p.writeString(alliance.getRankTitle(i));
}
p.writeByte(alliance.getGuilds().size());
p.writeInt(alliance.getCapacity()); // probably capacity
for (Integer guild : alliance.getGuilds()) {
p.writeInt(guild);
}
p.writeString(alliance.getNotice());
return p;
}
public static Packet updateAllianceInfo(MapleAlliance alliance, int world) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x0F);
p.writeInt(alliance.getId());
p.writeString(alliance.getName());
for (int i = 1; i <= 5; i++) {
p.writeString(alliance.getRankTitle(i));
}
p.writeByte(alliance.getGuilds().size());
for (Integer guild : alliance.getGuilds()) {
p.writeInt(guild);
}
p.writeInt(alliance.getCapacity()); // probably capacity
p.writeShort(0);
for (Integer guildid : alliance.getGuilds()) {
getGuildInfo(p, Server.getInstance().getGuild(guildid, world));
}
return p;
}
public static Packet getGuildAlliances(MapleAlliance alliance, int worldId) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x0D);
p.writeInt(alliance.getGuilds().size());
for (Integer guild : alliance.getGuilds()) {
getGuildInfo(p, Server.getInstance().getGuild(guild, worldId));
}
return p;
}
public static Packet addGuildToAlliance(MapleAlliance alliance, int newGuild, MapleClient c) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x12);
p.writeInt(alliance.getId());
p.writeString(alliance.getName());
for (int i = 1; i <= 5; i++) {
p.writeString(alliance.getRankTitle(i));
}
p.writeByte(alliance.getGuilds().size());
for (Integer guild : alliance.getGuilds()) {
p.writeInt(guild);
}
p.writeInt(alliance.getCapacity());
p.writeString(alliance.getNotice());
p.writeInt(newGuild);
getGuildInfo(p, Server.getInstance().getGuild(newGuild, c.getWorld(), null));
return p;
}
public static Packet allianceMemberOnline(MapleCharacter mc, boolean online) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x0E);
p.writeInt(mc.getGuild().getAllianceId());
p.writeInt(mc.getGuildId());
p.writeInt(mc.getId());
p.writeBool(online);
return p;
}
public static Packet allianceNotice(int id, String notice) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x1C);
p.writeInt(id);
p.writeString(notice);
return p;
}
public static Packet changeAllianceRankTitle(int alliance, String[] ranks) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x1A);
p.writeInt(alliance);
for (int i = 0; i < 5; i++) {
p.writeString(ranks[i]);
}
return p;
}
public static Packet updateAllianceJobLevel(MapleCharacter mc) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x18);
p.writeInt(mc.getGuild().getAllianceId());
p.writeInt(mc.getGuildId());
p.writeInt(mc.getId());
p.writeInt(mc.getLevel());
p.writeInt(mc.getJob().getId());
return p;
}
public static Packet removeGuildFromAlliance(MapleAlliance alliance, int expelledGuild, int worldId) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x10);
p.writeInt(alliance.getId());
p.writeString(alliance.getName());
for (int i = 1; i <= 5; i++) {
p.writeString(alliance.getRankTitle(i));
}
p.writeByte(alliance.getGuilds().size());
for (Integer guild : alliance.getGuilds()) {
p.writeInt(guild);
}
p.writeInt(alliance.getCapacity());
p.writeString(alliance.getNotice());
p.writeInt(expelledGuild);
getGuildInfo(p, Server.getInstance().getGuild(expelledGuild, worldId, null));
p.writeByte(0x01);
return p;
}
public static Packet disbandAlliance(int alliance) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x1D);
p.writeInt(alliance);
return p;
}
public static Packet allianceInvite(int allianceid, MapleCharacter chr) {
OutPacket p = OutPacket.create(SendOpcode.ALLIANCE_OPERATION);
p.writeByte(0x03);
p.writeInt(allianceid);
p.writeString(chr.getName());
p.writeShort(0);
return p;
}
public static Packet GuildBoss_HealerMove(short nY) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_BOSS_HEALER_MOVE);
p.writeShort(nY); //New Y Position
return p;
}
public static Packet GuildBoss_PulleyStateChange(byte nState) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_BOSS_PULLEY_STATE_CHANGE);
p.writeByte(nState);
return p;
}
/**
* Guild Name & Mark update packet, thanks to Arnah (Vertisy)
*
* @param guildName The Guild name, blank for nothing.
*/
public static Packet guildNameChanged(int chrid, String guildName) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_NAME_CHANGED);
p.writeInt(chrid);
p.writeString(guildName);
return p;
}
public static Packet guildMarkChanged(int chrId, MapleGuild guild) {
OutPacket p = OutPacket.create(SendOpcode.GUILD_MARK_CHANGED);
p.writeInt(chrId);
p.writeShort(guild.getLogoBG());
p.writeByte(guild.getLogoBGColor());
p.writeShort(guild.getLogo());
p.writeByte(guild.getLogoColor());
return p;
}
}

View File

@@ -23,6 +23,7 @@ package net.server.guild;
import client.MapleCharacter;
import client.MapleClient;
import net.packet.Packet;
import net.server.Server;
import net.server.coordinator.world.MapleInviteCoordinator;
import net.server.coordinator.world.MapleInviteCoordinator.InviteType;
@@ -30,7 +31,6 @@ import net.server.coordinator.world.MapleInviteCoordinator.MapleInviteResult;
import net.server.world.MapleParty;
import net.server.world.MaplePartyCharacter;
import tools.DatabaseConnection;
import tools.PacketCreator;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -141,8 +141,8 @@ public class MapleAlliance {
Server.getInstance().addAlliance(id, alliance);
int worldid = guildMasters.get(0).getWorld();
Server.getInstance().allianceMessage(id, PacketCreator.updateAllianceInfo(alliance, worldid), -1, -1);
Server.getInstance().allianceMessage(id, PacketCreator.getGuildAlliances(alliance, worldid), -1, -1); // thanks Vcoc for noticing guilds from other alliances being visually stacked here due to this not being updated
Server.getInstance().allianceMessage(id, GuildPackets.updateAllianceInfo(alliance, worldid), -1, -1);
Server.getInstance().allianceMessage(id, GuildPackets.getGuildAlliances(alliance, worldid), -1, -1); // thanks Vcoc for noticing guilds from other alliances being visually stacked here due to this not being updated
} catch (Exception e) {
e.printStackTrace();
return null;
@@ -273,7 +273,7 @@ public class MapleAlliance {
ps.executeUpdate();
}
Server.getInstance().allianceMessage(allianceId, PacketCreator.disbandAlliance(allianceId), -1, -1);
Server.getInstance().allianceMessage(allianceId, GuildPackets.disbandAlliance(allianceId), -1, -1);
Server.getInstance().disbandAlliance(allianceId);
} catch (SQLException sqle) {
sqle.printStackTrace();
@@ -298,13 +298,13 @@ public class MapleAlliance {
return false;
}
srv.allianceMessage(alliance.getId(), PacketCreator.removeGuildFromAlliance(alliance, guildId, worldId), -1, -1);
srv.allianceMessage(alliance.getId(), GuildPackets.removeGuildFromAlliance(alliance, guildId, worldId), -1, -1);
srv.removeGuildFromAlliance(alliance.getId(), guildId);
removeGuildFromAllianceOnDb(guildId);
srv.allianceMessage(alliance.getId(), PacketCreator.getGuildAlliances(alliance, worldId), -1, -1);
srv.allianceMessage(alliance.getId(), PacketCreator.allianceNotice(alliance.getId(), alliance.getNotice()), -1, -1);
srv.guildMessage(guildId, PacketCreator.disbandAlliance(alliance.getId()));
srv.allianceMessage(alliance.getId(), GuildPackets.getGuildAlliances(alliance, worldId), -1, -1);
srv.allianceMessage(alliance.getId(), GuildPackets.allianceNotice(alliance.getId(), alliance.getNotice()), -1, -1);
srv.guildMessage(guildId, GuildPackets.disbandAlliance(alliance.getId()));
alliance.dropMessage("[" + srv.getGuild(guildId, worldId).getName() + "] guild has left the union.");
return true;
@@ -312,8 +312,8 @@ public class MapleAlliance {
public void updateAlliancePackets(MapleCharacter chr) {
if (allianceId > 0) {
this.broadcastMessage(PacketCreator.updateAllianceInfo(this, chr.getWorld()));
this.broadcastMessage(PacketCreator.allianceNotice(this.getId(), this.getNotice()));
this.broadcastMessage(GuildPackets.updateAllianceInfo(this, chr.getWorld()));
this.broadcastMessage(GuildPackets.allianceNotice(this.getId(), this.getNotice()));
}
}
@@ -431,7 +431,7 @@ public class MapleAlliance {
}
}
public void broadcastMessage(byte[] packet) {
public void broadcastMessage(Packet packet) {
Server.getInstance().allianceMessage(allianceId, packet, -1, -1);
}
@@ -448,7 +448,7 @@ public class MapleAlliance {
c.getPlayer().dropMessage(5, "The master of the guild that you offered an invitation is currently not online.");
} else {
if (MapleInviteCoordinator.createInvite(InviteType.ALLIANCE, c.getPlayer(), allianceId, victim.getId())) {
victim.getClient().announce(PacketCreator.allianceInvite(allianceId, c.getPlayer()));
victim.sendPacket(GuildPackets.allianceInvite(allianceId, c.getPlayer()));
} else {
c.getPlayer().dropMessage(5, "The master of the guild that you offered an invitation is currently managing another invite.");
}

View File

@@ -24,6 +24,7 @@ package net.server.guild;
import client.MapleCharacter;
import client.MapleClient;
import config.YamlConfig;
import net.packet.Packet;
import net.server.PlayerStorage;
import net.server.Server;
import net.server.audit.locks.MonitoredLockType;
@@ -184,7 +185,7 @@ public class MapleGuild {
membersLock.lock();
try {
this.broadcast(PacketCreator.guildDisband(this.id));
this.broadcast(GuildPackets.guildDisband(this.id));
} finally {
membersLock.unlock();
}
@@ -279,8 +280,8 @@ public class MapleGuild {
continue;
}
byte[] packet = PacketCreator.guildNameChanged(chr.getId(), this.getName());
chr.getMap().broadcastMessage(chr, packet);
Packet packet = GuildPackets.guildNameChanged(chr.getId(), this.getName());
chr.getMap().broadcastPacket(chr, packet);
}
}
@@ -293,8 +294,8 @@ public class MapleGuild {
continue;
}
byte[] packet = PacketCreator.guildMarkChanged(chr.getId(), this);
chr.getMap().broadcastMessage(chr, packet);
Packet packet = GuildPackets.guildMarkChanged(chr.getId(), this);
chr.getMap().broadcastPacket(chr, packet);
}
}
@@ -307,20 +308,19 @@ public class MapleGuild {
continue;
}
byte[] packet = PacketCreator.showGuildInfo(chr);
chr.announce(packet);
chr.sendPacket(GuildPackets.showGuildInfo(chr));
}
}
public void broadcast(final byte[] packet) {
public void broadcast(Packet packet) {
broadcast(packet, -1, BCOp.NONE);
}
public void broadcast(final byte[] packet, int exception) {
public void broadcast(Packet packet, int exception) {
broadcast(packet, exception, BCOp.NONE);
}
public void broadcast(final byte[] packet, int exceptionId, BCOp bcop) {
public void broadcast(Packet packet, int exceptionId, BCOp bcop) {
membersLock.lock(); // membersLock awareness thanks to ProjectNano dev team
try {
synchronized (notifications) {
@@ -349,13 +349,13 @@ public class MapleGuild {
}
}
public void guildMessage(final byte[] serverNotice) {
public void guildMessage(Packet serverNotice) {
membersLock.lock();
try {
for (MapleGuildCharacter mgc : members) {
for (Channel cs : Server.getInstance().getChannelsFromWorld(world)) {
if (cs.getPlayerStorage().getCharacterById(mgc.getId()) != null) {
cs.getPlayerStorage().getCharacterById(mgc.getId()).getClient().announce(serverNotice);
cs.getPlayerStorage().getCharacterById(mgc.getId()).sendPacket(serverNotice);
break;
}
}
@@ -382,7 +382,7 @@ public class MapleGuild {
}
}
public void broadcastMessage(byte[] packet) {
public void broadcastMessage(Packet packet) {
Server.getInstance().guildMessage(id, packet);
}
@@ -401,7 +401,7 @@ public class MapleGuild {
}
}
if (bBroadcast) {
this.broadcast(PacketCreator.guildMemberOnline(id, cid, online), cid);
this.broadcast(GuildPackets.guildMemberOnline(id, cid, online), cid);
}
bDirty = true;
} finally {
@@ -479,7 +479,7 @@ public class MapleGuild {
}
}
this.broadcast(PacketCreator.newGuildMember(mgc));
this.broadcast(GuildPackets.newGuildMember(mgc));
return 1;
} finally {
membersLock.unlock();
@@ -489,7 +489,7 @@ public class MapleGuild {
public void leaveGuild(MapleGuildCharacter mgc) {
membersLock.lock();
try {
this.broadcast(PacketCreator.memberLeft(mgc, false));
this.broadcast(GuildPackets.memberLeft(mgc, false));
members.remove(mgc);
bDirty = true;
} finally {
@@ -505,7 +505,7 @@ public class MapleGuild {
while (itr.hasNext()) {
mgc = itr.next();
if (mgc.getId() == cid && initiator.getGuildRank() < mgc.getGuildRank()) {
this.broadcast(PacketCreator.memberLeft(mgc, true));
this.broadcast(GuildPackets.memberLeft(mgc, true));
itr.remove();
bDirty = true;
try {
@@ -568,7 +568,7 @@ public class MapleGuild {
membersLock.lock();
try {
this.broadcast(PacketCreator.changeRank(mgc));
this.broadcast(GuildPackets.changeRank(mgc));
} finally {
membersLock.unlock();
}
@@ -580,7 +580,7 @@ public class MapleGuild {
membersLock.lock();
try {
this.broadcast(PacketCreator.guildNotice(this.id, notice));
this.broadcast(GuildPackets.guildNotice(this.id, notice));
} finally {
membersLock.unlock();
}
@@ -593,7 +593,7 @@ public class MapleGuild {
if (mgc.equals(member)) {
member.setJobId(mgc.getJobId());
member.setLevel(mgc.getLevel());
this.broadcast(PacketCreator.guildMemberLevelJobUpdate(mgc));
this.broadcast(GuildPackets.guildMemberLevelJobUpdate(mgc));
break;
}
}
@@ -624,7 +624,7 @@ public class MapleGuild {
membersLock.lock();
try {
this.broadcast(PacketCreator.rankTitleChange(this.id, ranks));
this.broadcast(GuildPackets.rankTitleChange(this.id, ranks));
} finally {
membersLock.unlock();
}
@@ -686,7 +686,7 @@ public class MapleGuild {
membersLock.lock();
try {
this.broadcast(PacketCreator.guildCapacityChange(this.id, this.capacity));
this.broadcast(GuildPackets.guildCapacityChange(this.id, this.capacity));
} finally {
membersLock.unlock();
}
@@ -697,14 +697,14 @@ public class MapleGuild {
public void gainGP(int amount) {
this.gp += amount;
this.writeToDB(false);
this.guildMessage(PacketCreator.updateGP(this.id, this.gp));
this.guildMessage(GuildPackets.updateGP(this.id, this.gp));
this.guildMessage(PacketCreator.getGPMessage(amount));
}
public void removeGP(int amount) {
this.gp -= amount;
this.writeToDB(false);
this.guildMessage(PacketCreator.updateGP(this.id, this.gp));
this.guildMessage(GuildPackets.updateGP(this.id, this.gp));
}
public static MapleGuildResponse sendInvitation(MapleClient c, String targetName) {
@@ -718,7 +718,7 @@ public class MapleGuild {
MapleCharacter sender = c.getPlayer();
if (MapleInviteCoordinator.createInvite(InviteType.GUILD, sender, sender.getGuildId(), mc.getId())) {
mc.getClient().announce(PacketCreator.guildInvite(sender.getGuildId(), sender.getName()));
mc.sendPacket(GuildPackets.guildInvite(sender.getGuildId(), sender.getName()));
return null;
} else {
return MapleGuildResponse.MANAGING_INVITE;
@@ -743,7 +743,7 @@ public class MapleGuild {
}
if (mgr != null && sender != null) {
sender.announce(mgr.getPacket(targetName));
sender.sendPacket(mgr.getPacket(targetName));
}
return false;
}
@@ -766,7 +766,7 @@ public class MapleGuild {
try (Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT `name`, `GP`, `logoBG`, `logoBGColor`, `logo`, `logoColor` FROM guilds ORDER BY `GP` DESC LIMIT 50", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = ps.executeQuery()) {
c.announce(PacketCreator.showGuildRanks(npcid, rs));
c.sendPacket(GuildPackets.showGuildRanks(npcid, rs));
} catch (SQLException e) {
e.printStackTrace();
System.out.println("failed to display guild ranks. " + e);

View File

@@ -21,7 +21,7 @@
*/
package net.server.guild;
import tools.PacketCreator;
import net.packet.Packet;
public enum MapleGuildResponse {
NOT_IN_CHANNEL(0x2a),
@@ -31,17 +31,17 @@ public enum MapleGuildResponse {
MANAGING_INVITE(0x36),
DENIED_INVITE(0x37);
private int value;
private final int value;
private MapleGuildResponse(int val) {
MapleGuildResponse(int val) {
value = val;
}
public final byte[] getPacket(String targetName) {
public final Packet getPacket(String targetName) {
if (value >= MANAGING_INVITE.value) {
return PacketCreator.responseGuildMessage((byte) value, targetName);
return GuildPackets.responseGuildMessage((byte) value, targetName);
} else {
return PacketCreator.genericGuildMessage((byte) value);
return GuildPackets.genericGuildMessage((byte) value);
}
}
}