Merge chr name + id wrappers into new CharacterIdentity record

This commit is contained in:
P0nk
2023-08-06 20:35:26 +02:00
parent 5b5888cf65
commit bbee8d7caa
7 changed files with 99 additions and 137 deletions

View File

@@ -21,6 +21,7 @@
*/
package client;
import model.CharacterIdentity;
import net.packet.Packet;
import net.server.PlayerStorage;
import tools.DatabaseConnection;
@@ -43,7 +44,7 @@ public class BuddyList {
private final Map<Integer, BuddylistEntry> buddies = new LinkedHashMap<>();
private int capacity;
private final Deque<CharacterNameAndId> pendingRequests = new LinkedList<>();
private final Deque<CharacterIdentity> pendingRequests = new LinkedList<>();
public BuddyList(int capacity) {
this.capacity = capacity;
@@ -145,7 +146,7 @@ public class BuddyList {
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
if (rs.getInt("pending") == 1) {
pendingRequests.push(new CharacterNameAndId(rs.getInt("buddyid"), rs.getString("buddyname")));
pendingRequests.push(new CharacterIdentity(rs.getString("buddyname"), rs.getInt("buddyid")));
} else {
put(new BuddylistEntry(rs.getString("buddyname"), rs.getString("group"), rs.getInt("buddyid"), (byte) -1, true));
}
@@ -162,7 +163,7 @@ public class BuddyList {
}
}
public CharacterNameAndId pollPendingRequest() {
public CharacterIdentity pollPendingRequest() {
return pendingRequests.pollLast();
}
@@ -171,7 +172,7 @@ public class BuddyList {
if (pendingRequests.isEmpty()) {
c.sendPacket(PacketCreator.requestBuddylistAdd(cidFrom, c.getPlayer().getId(), nameFrom));
} else {
pendingRequests.push(new CharacterNameAndId(cidFrom, nameFrom));
pendingRequests.push(new CharacterIdentity(nameFrom, cidFrom));
}
}
}

View File

@@ -41,6 +41,7 @@ import constants.id.MapId;
import constants.id.MobId;
import constants.inventory.ItemConstants;
import constants.skills.*;
import model.CharacterIdentity;
import net.packet.Packet;
import net.server.PlayerBuffValueHolder;
import net.server.PlayerCoolDownValueHolder;
@@ -2115,9 +2116,9 @@ public class Character extends AbstractCharacterObject {
}
private void nextPendingRequest(Client c) {
CharacterNameAndId pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest();
CharacterIdentity pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest();
if (pendingBuddyRequest != null) {
c.sendPacket(PacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), c.getPlayer().getId(), pendingBuddyRequest.getName()));
c.sendPacket(PacketCreator.requestBuddylistAdd(pendingBuddyRequest.id(), c.getPlayer().getId(), pendingBuddyRequest.name()));
}
}

View File

@@ -1,41 +0,0 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client;
public class CharacterNameAndId {
private final int id;
private final String name;
public CharacterNameAndId(int id, String name) {
super();
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}

View File

@@ -27,6 +27,7 @@ import constants.id.MapId;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;
import model.CharacterIdentity;
import net.PacketHandler;
import net.PacketProcessor;
import net.netty.DisconnectException;
@@ -308,8 +309,8 @@ public class Client extends ChannelInboundHandlerAdapter {
public List<Character> loadCharacters(int serverId) {
List<Character> chars = new ArrayList<>(15);
try {
for (CharNameAndId cni : loadCharactersInternal(serverId)) {
chars.add(Character.loadCharFromDB(cni.id, this, false));
for (CharacterIdentity cni : loadCharactersInternal(serverId)) {
chars.add(Character.loadCharFromDB(cni.id(), this, false));
}
} catch (Exception e) {
e.printStackTrace();
@@ -317,8 +318,8 @@ public class Client extends ChannelInboundHandlerAdapter {
return chars;
}
private List<CharNameAndId> loadCharactersInternal(int worldId) {
List<CharNameAndId> chars = new ArrayList<>(15);
private List<CharacterIdentity> loadCharactersInternal(int worldId) {
List<CharacterIdentity> chars = new ArrayList<>(15);
try (Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT id, name FROM characters WHERE accountid = ? AND world = ?")) {
ps.setInt(1, this.getAccID());
@@ -326,7 +327,7 @@ public class Client extends ChannelInboundHandlerAdapter {
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
chars.add(new CharNameAndId(rs.getString("name"), rs.getInt("id")));
chars.add(new CharacterIdentity(rs.getString("name"), rs.getInt("id")));
}
}
} catch (SQLException e) {
@@ -1160,18 +1161,6 @@ public class Client extends ChannelInboundHandlerAdapter {
actionsSemaphore.release();
}
private static class CharNameAndId {
public String name;
public int id;
public CharNameAndId(String name, int id) {
super();
this.name = name;
this.id = id;
}
}
private static boolean checkHash(String hash, String type, String password) {
try {
MessageDigest digester = MessageDigest.getInstance(type);