Skip to content

Commit

Permalink
Accurate packet structure
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-dev committed Aug 5, 2024
1 parent 9ab164a commit 9ba6e1a
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.aionemu.gameserver.network.aion.serverpackets;

import java.util.Collections;
import java.util.List;

import com.aionemu.gameserver.model.team.legion.Legion;
import com.aionemu.gameserver.network.aion.AionConnection;
import com.aionemu.gameserver.network.aion.AionServerPacket;
Expand Down Expand Up @@ -32,8 +35,21 @@ protected void writeImpl(AionConnection con) {
writeD(legion.getOccupiedLegionDominion());
writeD(legion.getLastLegionDominion());
writeD(legion.getCurrentLegionDominion());
Legion.Announcement announcement = legion.getAnnouncement();
writeS(announcement == null ? null : announcement.message());
writeD(announcement == null ? 0 : (int) (announcement.time().getTime() / 1000));
writeAnnouncements();
}

/**
* The game client expects up to 7 announcements, but it only shows the first one, so only one is sent. The code could be simplified with just one
* announcement, but this implementation is more accurate and future-proof.
*/
private void writeAnnouncements() {
List<Legion.Announcement> announcements = Collections.singletonList(legion.getAnnouncement());
for (int i = 0; i < 7; i++) {
Legion.Announcement announcement = i < announcements.size() ? announcements.get(i) : null;
writeS(announcement == null ? "" : announcement.message());
if (announcement == null || announcement.message().isEmpty()) // empty string is a stop marker
break;
writeD((int) (announcement.time().getTime() / 1000));
}
}
}

0 comments on commit 9ba6e1a

Please sign in to comment.