mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-23 10:44:36 +01:00
Implement friend list
This commit is contained in:
@@ -18,6 +18,7 @@ public class GameConstants {
|
||||
public static final int MAX_STAMINA = 240;
|
||||
public static final int MAX_STAMINA_RESERVE = 2400;
|
||||
public static final int MAX_AVATARS_IN_TEAM = 4;
|
||||
public static final int MAX_FRIENDSHIPS = 100;
|
||||
public static final int DEFAULT_TEAMS = 6;
|
||||
public static final int MAX_MP = 5; // Client doesnt like more than 5
|
||||
|
||||
|
||||
248
src/main/java/emu/lunarcore/game/friends/FriendList.java
Normal file
248
src/main/java/emu/lunarcore/game/friends/FriendList.java
Normal file
@@ -0,0 +1,248 @@
|
||||
package emu.lunarcore.game.friends;
|
||||
|
||||
import emu.lunarcore.GameConstants;
|
||||
import emu.lunarcore.LunarCore;
|
||||
import emu.lunarcore.game.player.BasePlayerManager;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.send.*;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
public class FriendList extends BasePlayerManager {
|
||||
@Getter(AccessLevel.PUBLIC)
|
||||
private final Int2ObjectMap<Friendship> friends;
|
||||
@Getter(AccessLevel.PUBLIC)
|
||||
private final Int2ObjectMap<Friendship> pendingFriends;
|
||||
|
||||
private long friendListCooldown = 0;
|
||||
private long applyFriendListCooldown = 0;
|
||||
private BasePacket friendListPacket;
|
||||
private BasePacket applyFriendListPacket;
|
||||
|
||||
public FriendList(Player player) {
|
||||
super(player);
|
||||
this.friends = new Int2ObjectOpenHashMap<Friendship>();
|
||||
this.pendingFriends = new Int2ObjectOpenHashMap<Friendship>();
|
||||
}
|
||||
|
||||
private synchronized Friendship getFriendById(int id) {
|
||||
if (this.getPlayer().isOnline()) {
|
||||
return this.getFriends().get(id);
|
||||
} else {
|
||||
return LunarCore.getGameDatabase().getObjectByUid(Friendship.class, Friendship.generateUniqueKey(getPlayer().getUid(), id));
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized Friendship getPendingFriendById(int id) {
|
||||
if (this.getPlayer().isOnline()) {
|
||||
return this.getPendingFriends().get(id);
|
||||
} else {
|
||||
return LunarCore.getGameDatabase().getObjectByUid(Friendship.class, Friendship.generateUniqueKey(getPlayer().getUid(), id));
|
||||
}
|
||||
}
|
||||
|
||||
private void addFriendship(Friendship friendship) {
|
||||
getFriends().put(friendship.getFriendUid(), friendship);
|
||||
this.friendListCooldown = 0;
|
||||
}
|
||||
|
||||
private void addPendingFriendship(Friendship friendship) {
|
||||
getPendingFriends().put(friendship.getFriendUid(), friendship);
|
||||
this.applyFriendListCooldown = 0;
|
||||
}
|
||||
|
||||
private void removeFriendship(int uid) {
|
||||
getFriends().remove(uid);
|
||||
this.friendListCooldown = 0;
|
||||
}
|
||||
|
||||
private void removePendingFriendship(int uid) {
|
||||
getPendingFriends().remove(uid);
|
||||
this.applyFriendListCooldown = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets total amount of potential friends
|
||||
*/
|
||||
public int getFullFriendCount() {
|
||||
return this.getPendingFriends().size() + this.getFriends().size();
|
||||
}
|
||||
|
||||
public synchronized void handleFriendRequest(int targetUid, boolean action) {
|
||||
// Make sure we have enough room
|
||||
if (this.getFriends().size() >= GameConstants.MAX_FRIENDSHIPS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if player has sent friend request
|
||||
Friendship myFriendship = this.getPendingFriendById(targetUid);
|
||||
if (myFriendship == null) return;
|
||||
|
||||
// Make sure this player is not the asker
|
||||
if (myFriendship.getAskerUid() == this.getPlayer().getUid()) return;
|
||||
|
||||
// Get target player
|
||||
Player target = getServer().getPlayerByUid(targetUid, true);
|
||||
if (target == null) return;
|
||||
|
||||
// Get target player's friendship
|
||||
Friendship theirFriendship = target.getFriendList().getPendingFriendById(getPlayer().getUid());
|
||||
|
||||
if (theirFriendship == null) {
|
||||
// They dont have us on their friends list anymore, rip
|
||||
this.removePendingFriendship(myFriendship.getOwnerUid());
|
||||
myFriendship.delete();
|
||||
getPlayer().sendPacket(new PacketHandleFriendScRsp(target, false));
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle action
|
||||
if (action) {
|
||||
// Request accepted
|
||||
myFriendship.setFriend(true);
|
||||
theirFriendship.setFriend(true);
|
||||
|
||||
this.removePendingFriendship(myFriendship.getOwnerUid());
|
||||
this.addFriendship(myFriendship);
|
||||
|
||||
if (target.isOnline()) {
|
||||
target.getFriendList().removePendingFriendship(this.getPlayer().getUid());
|
||||
target.getFriendList().addFriendship(theirFriendship);
|
||||
target.sendPacket(new PacketSyncHandleFriendScNotify(getPlayer(), action));
|
||||
}
|
||||
|
||||
// Save friendships to the database
|
||||
myFriendship.save();
|
||||
theirFriendship.save();
|
||||
} else {
|
||||
// Request declined - Delete from my pending friends
|
||||
this.removePendingFriendship(myFriendship.getOwnerUid());
|
||||
|
||||
if (target.isOnline()) {
|
||||
target.getFriendList().removePendingFriendship(getPlayer().getUid());
|
||||
target.sendPacket(new PacketSyncHandleFriendScNotify(getPlayer(), action));
|
||||
}
|
||||
|
||||
// Delete friendships from the database
|
||||
myFriendship.delete();
|
||||
theirFriendship.delete();
|
||||
}
|
||||
|
||||
// Send packet
|
||||
getPlayer().sendPacket(new PacketHandleFriendScRsp(target, action));
|
||||
}
|
||||
|
||||
public synchronized void sendFriendRequest(int targetUid) {
|
||||
// Get target and sanity check
|
||||
Player target = getPlayer().getServer().getPlayerByUid(targetUid, true);
|
||||
if (target == null || target == this.getPlayer()) return;
|
||||
|
||||
// Check if friend already exists
|
||||
if (getPendingFriends().containsKey(targetUid) || getFriends().containsKey(targetUid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create friendships
|
||||
Friendship myFriendship = new Friendship(getPlayer(), target, getPlayer());
|
||||
Friendship theirFriendship = new Friendship(target, getPlayer(), getPlayer());
|
||||
|
||||
// Add to our pending friendship list
|
||||
this.addPendingFriendship(myFriendship);
|
||||
|
||||
if (target.isOnline()) {
|
||||
target.getFriendList().addPendingFriendship(theirFriendship);
|
||||
target.sendPacket(new PacketSyncApplyFriendScNotify(this.getPlayer()));
|
||||
}
|
||||
|
||||
// Save friendships to the database
|
||||
myFriendship.save();
|
||||
theirFriendship.save();
|
||||
}
|
||||
|
||||
public synchronized void deleteFriend(int targetUid) {
|
||||
// Get friendship
|
||||
Friendship myFriendship = this.getFriendById(targetUid);
|
||||
if (myFriendship == null) return;
|
||||
|
||||
// Remove from friends list
|
||||
this.removeFriendship(targetUid);
|
||||
myFriendship.delete();
|
||||
|
||||
// Delete from friend's friend list
|
||||
Player friend = getServer().getPlayerByUid(targetUid, true);
|
||||
|
||||
if (friend != null) {
|
||||
// Friend online
|
||||
Friendship theirFriendship = friend.getFriendList().getFriendById(this.getPlayer().getUid());
|
||||
|
||||
if (theirFriendship != null) {
|
||||
// Delete friendship on friends side
|
||||
theirFriendship.delete();
|
||||
|
||||
if (friend.isOnline()) {
|
||||
// Remove from online friend's friend list
|
||||
friend.getFriendList().removeFriendship(theirFriendship.getFriendUid());
|
||||
|
||||
// Send packet to friend
|
||||
getPlayer().sendPacket(new PacketSyncDeleteFriendScNotify(getPlayer().getUid()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send packet
|
||||
getPlayer().sendPacket(new PacketSyncDeleteFriendScNotify(targetUid));
|
||||
}
|
||||
|
||||
// Database
|
||||
|
||||
public synchronized void loadFromDatabase() {
|
||||
var friendships = LunarCore.getGameDatabase().getObjects(Friendship.class, "ownerUid", this.getPlayer().getUid());
|
||||
|
||||
friendships.forEach(friendship -> {
|
||||
// Set ownership first
|
||||
friendship.setOwner(getPlayer());
|
||||
|
||||
// Finally, load to our friends list
|
||||
if (friendship.isFriend()) {
|
||||
getFriends().put(friendship.getFriendUid(), friendship);
|
||||
} else {
|
||||
getPendingFriends().put(friendship.getFriendUid(), friendship);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Protobuf serialization
|
||||
|
||||
public synchronized int[] toFriendUidArray() {
|
||||
IntArrayList list = new IntArrayList();
|
||||
|
||||
list.add(GameConstants.SERVER_CONSOLE_UID);
|
||||
|
||||
for (var friendship : this.getFriends().values()) {
|
||||
list.add(friendship.getFriendUid());
|
||||
}
|
||||
|
||||
return list.toIntArray();
|
||||
}
|
||||
|
||||
public synchronized BasePacket getFriendListPacket() {
|
||||
if (this.friendListPacket == null || System.currentTimeMillis() >= this.friendListCooldown) {
|
||||
this.friendListPacket = new PacketGetFriendListInfoScRsp(this);
|
||||
this.friendListCooldown = System.currentTimeMillis() + 60000;
|
||||
}
|
||||
return this.friendListPacket;
|
||||
}
|
||||
|
||||
public synchronized BasePacket getApplyFriendListPacket() {
|
||||
if (this.applyFriendListPacket == null || System.currentTimeMillis() >= this.applyFriendListCooldown) {
|
||||
this.applyFriendListPacket = new PacketGetFriendApplyListInfoScRsp(this);
|
||||
this.applyFriendListCooldown = System.currentTimeMillis() + 60000;
|
||||
}
|
||||
return this.applyFriendListPacket;
|
||||
}
|
||||
}
|
||||
55
src/main/java/emu/lunarcore/game/friends/Friendship.java
Normal file
55
src/main/java/emu/lunarcore/game/friends/Friendship.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package emu.lunarcore.game.friends;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import dev.morphia.annotations.Indexed;
|
||||
import emu.lunarcore.LunarCore;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.SimpleInfoOuterClass.SimpleInfo;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Entity(value = "friendships", useDiscriminator = false)
|
||||
public class Friendship {
|
||||
@Id private long id;
|
||||
|
||||
@Indexed private int ownerUid;
|
||||
@Indexed private int friendUid;
|
||||
|
||||
@Setter private boolean isFriend;
|
||||
private int askerUid;
|
||||
|
||||
@Setter private transient Player owner;
|
||||
@Setter private transient SimpleInfo simpleInfo;
|
||||
|
||||
@Deprecated // Morphia use only
|
||||
public Friendship() { }
|
||||
|
||||
public Friendship(Player owner, Player friend, Player asker) {
|
||||
this.owner = owner;
|
||||
this.id = Friendship.generateUniqueKey(owner.getUid(), this.getFriendUid());
|
||||
this.ownerUid = owner.getUid();
|
||||
this.friendUid = friend.getUid();
|
||||
this.askerUid = asker.getUid();
|
||||
}
|
||||
|
||||
// Database functions
|
||||
|
||||
public void save() {
|
||||
LunarCore.getGameDatabase().save(this);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
LunarCore.getGameDatabase().delete(this);
|
||||
}
|
||||
|
||||
// Extra
|
||||
|
||||
/**
|
||||
* Creates an unique key for a friendship object using 2 player uids
|
||||
*/
|
||||
public static long generateUniqueKey(int ownerUid, int targetUid) {
|
||||
return ((long) ownerUid << 32) + targetUid;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package emu.lunarcore.game.player;
|
||||
|
||||
import emu.lunarcore.server.game.GameServer;
|
||||
|
||||
public abstract class BasePlayerManager {
|
||||
private transient Player player;
|
||||
|
||||
@@ -10,4 +12,8 @@ public abstract class BasePlayerManager {
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public GameServer getServer() {
|
||||
return player.getServer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import emu.lunarcore.game.chat.ChatManager;
|
||||
import emu.lunarcore.game.chat.ChatMessage;
|
||||
import emu.lunarcore.game.enums.PlaneType;
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.friends.FriendList;
|
||||
import emu.lunarcore.game.gacha.PlayerGachaInfo;
|
||||
import emu.lunarcore.game.inventory.GameItem;
|
||||
import emu.lunarcore.game.inventory.Inventory;
|
||||
@@ -45,16 +46,21 @@ import emu.lunarcore.game.scene.entity.EntityProp;
|
||||
import emu.lunarcore.game.scene.entity.GameEntity;
|
||||
import emu.lunarcore.game.scene.triggers.PropTriggerType;
|
||||
import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync;
|
||||
import emu.lunarcore.proto.FriendOnlineStatusOuterClass.FriendOnlineStatus;
|
||||
import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon;
|
||||
import emu.lunarcore.proto.PlatformTypeOuterClass.PlatformType;
|
||||
import emu.lunarcore.proto.PlayerBasicInfoOuterClass.PlayerBasicInfo;
|
||||
import emu.lunarcore.proto.PlayerDetailInfoOuterClass.PlayerDetailInfo;
|
||||
import emu.lunarcore.proto.RogueVirtualItemInfoOuterClass.RogueVirtualItemInfo;
|
||||
import emu.lunarcore.proto.SimpleAvatarInfoOuterClass.SimpleAvatarInfo;
|
||||
import emu.lunarcore.proto.SimpleInfoOuterClass.SimpleInfo;
|
||||
import emu.lunarcore.server.game.GameServer;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.SessionState;
|
||||
import emu.lunarcore.server.packet.send.*;
|
||||
import emu.lunarcore.util.Position;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import lombok.Getter;
|
||||
@@ -99,6 +105,7 @@ public class Player {
|
||||
private transient final AvatarStorage avatars;
|
||||
private transient final Inventory inventory;
|
||||
private transient final ChatManager chatManager;
|
||||
private transient final FriendList friendList;
|
||||
private transient final Mailbox mailbox;
|
||||
private transient final ChallengeManager challengeManager;
|
||||
private transient final RogueManager rogueManager;
|
||||
@@ -112,6 +119,7 @@ public class Player {
|
||||
@Setter private transient RogueInstance rogueInstance;
|
||||
|
||||
// Etc
|
||||
private transient boolean loggedIn;
|
||||
private transient boolean inAnchorRange;
|
||||
private transient int nextBattleId;
|
||||
|
||||
@@ -124,6 +132,7 @@ public class Player {
|
||||
this.avatars = new AvatarStorage(this);
|
||||
this.inventory = new Inventory(this);
|
||||
this.chatManager = new ChatManager(this);
|
||||
this.friendList = new FriendList(this);
|
||||
this.mailbox = new Mailbox(this);
|
||||
this.challengeManager = new ChallengeManager(this);
|
||||
this.rogueManager = new RogueManager(this);
|
||||
@@ -167,6 +176,10 @@ public class Player {
|
||||
public Account getAccount() {
|
||||
return session.getAccount();
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return this.getSession() != null && this.loggedIn;
|
||||
}
|
||||
|
||||
public void setSession(GameSession session) {
|
||||
if (this.session == null) {
|
||||
@@ -238,7 +251,7 @@ public class Player {
|
||||
}
|
||||
|
||||
public void resetPosition() {
|
||||
if (this.hasLoggedIn()) {
|
||||
if (this.isOnline()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -249,10 +262,6 @@ public class Player {
|
||||
this.entryId = GameConstants.START_ENTRY_ID;
|
||||
}
|
||||
|
||||
public boolean hasLoggedIn() {
|
||||
return this.getSession() != null && this.getSession().getState() != SessionState.WAITING_FOR_TOKEN;
|
||||
}
|
||||
|
||||
public boolean addAvatar(GameAvatar avatar) {
|
||||
boolean success = getAvatars().addAvatar(avatar);
|
||||
if (success) {
|
||||
@@ -430,7 +439,7 @@ public class Player {
|
||||
}
|
||||
|
||||
// Send packet
|
||||
if (hasChanged && this.hasLoggedIn()) {
|
||||
if (hasChanged && this.isOnline()) {
|
||||
this.getSession().send(new PacketStaminaInfoScNotify(this));
|
||||
}
|
||||
}
|
||||
@@ -601,7 +610,7 @@ public class Player {
|
||||
}
|
||||
|
||||
public void sendPacket(BasePacket packet) {
|
||||
if (this.hasLoggedIn()) {
|
||||
if (this.isOnline()) {
|
||||
this.getSession().send(packet);
|
||||
}
|
||||
}
|
||||
@@ -618,6 +627,7 @@ public class Player {
|
||||
this.getAvatars().loadFromDatabase();
|
||||
this.getInventory().loadFromDatabase();
|
||||
this.getLineupManager().loadFromDatabase();
|
||||
this.getFriendList().loadFromDatabase();
|
||||
this.getMailbox().loadFromDatabase();
|
||||
this.getChallengeManager().loadFromDatabase();
|
||||
this.getRogueManager().loadFromDatabase();
|
||||
@@ -638,8 +648,10 @@ public class Player {
|
||||
if (this.getScene() == null) {
|
||||
this.enterScene(GameConstants.START_ENTRY_ID, 0, false);
|
||||
}
|
||||
|
||||
// Set flag
|
||||
this.loggedIn = true;
|
||||
}
|
||||
|
||||
|
||||
// Database
|
||||
|
||||
@@ -692,6 +704,34 @@ public class Player {
|
||||
return proto;
|
||||
}
|
||||
|
||||
public PlayerDetailInfo toDetailInfo() {
|
||||
var proto = PlayerDetailInfo.newInstance()
|
||||
.setUid(this.getUid())
|
||||
.setNickname(this.getName())
|
||||
.setSignature(this.getSignature())
|
||||
.setLevel(this.getLevel())
|
||||
.setWorldLevel(this.getWorldLevel())
|
||||
.setPlatformType(PlatformType.PC)
|
||||
.setRecordInfo("")
|
||||
.setHeadIcon(this.getHeadIcon());
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
public SimpleInfo toSimpleInfo() {
|
||||
var proto = SimpleInfo.newInstance()
|
||||
.setUid(this.getUid())
|
||||
.setNickname(this.getName())
|
||||
.setSignature(this.getSignature())
|
||||
.setLevel(this.getLevel())
|
||||
.setOnlineStatus(this.isOnline() ? FriendOnlineStatus.FRIEND_ONLINE_STATUS_ONLINE : FriendOnlineStatus.FRIEND_ONLINE_STATUS_OFFLINE)
|
||||
.setPlatformType(PlatformType.PC)
|
||||
.setSimpleAvatarInfo(SimpleAvatarInfo.newInstance().setAvatarId(GameConstants.TRAILBLAZER_AVATAR_ID).setLevel(1)) // TODO
|
||||
.setHeadIcon(this.getHeadIcon());
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
public BoardDataSync toBoardData() {
|
||||
var proto = BoardDataSync.newInstance()
|
||||
.setSignature(this.getSignature());
|
||||
|
||||
@@ -86,11 +86,25 @@ public class GameServer extends KcpServer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Player getPlayerByUid(int uid, boolean allowOffline) {
|
||||
Player target = null;
|
||||
|
||||
// Get player if online
|
||||
synchronized (this.players) {
|
||||
target = this.players.get(uid);
|
||||
}
|
||||
|
||||
// Player is not online, but we arent requesting an online one
|
||||
if (target == null && allowOffline) {
|
||||
target = LunarCore.getGameDatabase().getObjectByUid(Player.class, uid);
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
public Player getOnlinePlayerByUid(int uid) {
|
||||
synchronized (this.players) {
|
||||
return this.players.get(uid);
|
||||
}
|
||||
return this.getPlayerByUid(uid, false);
|
||||
}
|
||||
|
||||
public Player getOnlinePlayerByAccountId(String accountUid) {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.proto.ApplyFriendCsReqOuterClass.ApplyFriendCsReq;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
|
||||
@Opcodes(CmdId.ApplyFriendCsReq)
|
||||
public class HandlerApplyFriendCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
var req = ApplyFriendCsReq.parseFrom(data);
|
||||
|
||||
session.getPlayer().getFriendList().sendFriendRequest(req.getUid());
|
||||
session.send(CmdId.ApplyFriendScRsp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.proto.DeleteFriendCsReqOuterClass.DeleteFriendCsReq;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
|
||||
@Opcodes(CmdId.DeleteFriendCsReq)
|
||||
public class HandlerDeleteFriendCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
var req = DeleteFriendCsReq.parseFrom(data);
|
||||
|
||||
session.getPlayer().getFriendList().deleteFriend(req.getUid());
|
||||
session.send(CmdId.DeleteFriendScRsp);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public class HandlerGetFriendApplyListInfoCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
session.send(CmdId.GetFriendApplyListInfoScRsp);
|
||||
session.send(session.getPlayer().getFriendList().getApplyFriendListPacket());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@ import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
import emu.lunarcore.server.packet.send.PacketGetFriendListInfoScRsp;
|
||||
|
||||
@Opcodes(CmdId.GetFriendListInfoCsReq)
|
||||
public class HandlerGetFriendListInfoCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
session.send(new PacketGetFriendListInfoScRsp());
|
||||
session.send(session.getPlayer().getFriendList().getFriendListPacket());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
import emu.lunarcore.server.packet.send.PacketGetFriendLoginInfoScRsp;
|
||||
|
||||
@Opcodes(CmdId.GetFriendLoginInfoCsReq)
|
||||
public class HandlerGetFriendLoginInfoCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
session.send(CmdId.GetFriendLoginInfoScRsp);
|
||||
session.send(new PacketGetFriendLoginInfoScRsp(session.getPlayer()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.GetPlayerDetailInfoCsReqOuterClass.GetPlayerDetailInfoCsReq;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
@@ -14,8 +15,9 @@ public class HandlerGetPlayerDetailInfoCsReq extends PacketHandler {
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
var req = GetPlayerDetailInfoCsReq.parseFrom(data);
|
||||
|
||||
session.send(new PacketGetPlayerDetailInfoScRsp());
|
||||
|
||||
Player player = session.getServer().getPlayerByUid(req.getUid(), true);
|
||||
session.send(new PacketGetPlayerDetailInfoScRsp(player));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.proto.HandleFriendCsReqOuterClass.HandleFriendCsReq;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
|
||||
@Opcodes(CmdId.HandleFriendCsReq)
|
||||
public class HandlerHandleFriendCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
var req = HandleFriendCsReq.parseFrom(data);
|
||||
|
||||
session.getPlayer().getFriendList().handleFriendRequest(req.getUid(), req.getHandleResult());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.SearchPlayerCsReqOuterClass.SearchPlayerCsReq;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.Opcodes;
|
||||
import emu.lunarcore.server.packet.PacketHandler;
|
||||
import emu.lunarcore.server.packet.send.PacketSearchPlayerScRsp;
|
||||
|
||||
@Opcodes(CmdId.SearchPlayerCsReq)
|
||||
public class HandlerSearchPlayerCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] data) throws Exception {
|
||||
var req = SearchPlayerCsReq.parseFrom(data);
|
||||
|
||||
List<Player> results = new ArrayList<>();
|
||||
|
||||
for (int uid : req.getSearchUidList()) {
|
||||
Player target = session.getServer().getPlayerByUid(uid, true);
|
||||
|
||||
if (target != null) {
|
||||
results.add(target);
|
||||
}
|
||||
}
|
||||
|
||||
session.send(new PacketSearchPlayerScRsp(results));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.friends.FriendList;
|
||||
import emu.lunarcore.proto.FriendApplyListInfoOuterClass.FriendApplyListInfo;
|
||||
import emu.lunarcore.proto.GetFriendApplyListInfoScRspOuterClass.GetFriendApplyListInfoScRsp;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketGetFriendApplyListInfoScRsp extends BasePacket {
|
||||
|
||||
public PacketGetFriendApplyListInfoScRsp(FriendList friendList) {
|
||||
super(CmdId.GetFriendApplyListInfoScRsp);
|
||||
|
||||
var data = GetFriendApplyListInfoScRsp.newInstance();
|
||||
|
||||
for (var friendship : friendList.getPendingFriends().values()) {
|
||||
// Skip if we are the asker
|
||||
if (friendship.getAskerUid() == friendList.getPlayer().getUid()) continue;
|
||||
|
||||
// Get friend info from the server
|
||||
var friend = friendList.getServer().getPlayerByUid(friendship.getFriendUid(), true);
|
||||
if (friend == null) continue;
|
||||
|
||||
var friendInfo = FriendApplyListInfo.newInstance()
|
||||
.setSimpleInfo(friend.toSimpleInfo());
|
||||
|
||||
data.addFriendApplyList(friendInfo);
|
||||
}
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,43 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.GameConstants;
|
||||
import emu.lunarcore.proto.FriendAvatarInfoOuterClass.FriendAvatarInfo;
|
||||
import emu.lunarcore.game.friends.FriendList;
|
||||
import emu.lunarcore.proto.FriendListInfoOuterClass.FriendListInfo;
|
||||
import emu.lunarcore.proto.FriendOnlineStatusOuterClass.FriendOnlineStatus;
|
||||
import emu.lunarcore.proto.GetFriendListInfoScRspOuterClass.GetFriendListInfoScRsp;
|
||||
import emu.lunarcore.proto.PlatformTypeOuterClass.PlatformType;
|
||||
import emu.lunarcore.proto.SimpleAvatarInfoOuterClass.SimpleAvatarInfo;
|
||||
import emu.lunarcore.proto.SimpleInfoOuterClass.SimpleInfo;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketGetFriendListInfoScRsp extends BasePacket {
|
||||
|
||||
public PacketGetFriendListInfoScRsp() {
|
||||
public PacketGetFriendListInfoScRsp(FriendList friendList) {
|
||||
super(CmdId.GetFriendListInfoScRsp);
|
||||
|
||||
// Inject server console as friend
|
||||
var consoleFriend = SimpleInfo.newInstance()
|
||||
.setUid(GameConstants.SERVER_CONSOLE_UID)
|
||||
.setNickname("Server")
|
||||
.setLevel(1)
|
||||
.setUid(GameConstants.SERVER_CONSOLE_UID)
|
||||
.setOnlineStatus(FriendOnlineStatus.FRIEND_ONLINE_STATUS_ONLINE)
|
||||
.setPlatformType(PlatformType.PC)
|
||||
.setFriendAvatarInfo(FriendAvatarInfo.newInstance().setAvatarId(1001).setLevel(1))
|
||||
.setProfilePicture(201001);
|
||||
.setSimpleAvatarInfo(SimpleAvatarInfo.newInstance().setAvatarId(1001).setLevel(1))
|
||||
.setHeadIcon(201001);
|
||||
|
||||
var data = GetFriendListInfoScRsp.newInstance()
|
||||
.addFriendList(FriendListInfo.newInstance().setSimpleInfo(consoleFriend));
|
||||
|
||||
for (var friendship : friendList.getFriends().values()) {
|
||||
var friend = friendList.getServer().getPlayerByUid(friendship.getFriendUid(), true);
|
||||
if (friend == null) continue;
|
||||
|
||||
var friendInfo = FriendListInfo.newInstance()
|
||||
.setSimpleInfo(friend.toSimpleInfo());
|
||||
|
||||
data.addFriendList(friendInfo);
|
||||
}
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.GetFriendLoginInfoScRspOuterClass.GetFriendLoginInfoScRsp;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketGetFriendLoginInfoScRsp extends BasePacket {
|
||||
|
||||
public PacketGetFriendLoginInfoScRsp(Player player) {
|
||||
super(CmdId.GetFriendLoginInfoScRsp);
|
||||
|
||||
var data = GetFriendLoginInfoScRsp.newInstance()
|
||||
.addAllFriendUidList(player.getFriendList().toFriendUidArray());
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,22 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.GetPlayerDetailInfoScRspOuterClass.GetPlayerDetailInfoScRsp;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketGetPlayerDetailInfoScRsp extends BasePacket {
|
||||
|
||||
public PacketGetPlayerDetailInfoScRsp() {
|
||||
public PacketGetPlayerDetailInfoScRsp(Player player) {
|
||||
super(CmdId.GetPlayerDetailInfoScRsp);
|
||||
|
||||
// TODO handle properly
|
||||
var data = GetPlayerDetailInfoScRsp.newInstance()
|
||||
.setRetcode(1);
|
||||
var data = GetPlayerDetailInfoScRsp.newInstance();
|
||||
|
||||
if (player != null) {
|
||||
data.setPlayerDetailInfo(player.toDetailInfo());
|
||||
} else {
|
||||
data.setRetcode(1);
|
||||
}
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.FriendListInfoOuterClass.FriendListInfo;
|
||||
import emu.lunarcore.proto.HandleFriendScRspOuterClass.HandleFriendScRsp;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketHandleFriendScRsp extends BasePacket {
|
||||
|
||||
public PacketHandleFriendScRsp(Player friend, boolean result) {
|
||||
super(CmdId.HandleFriendScRsp);
|
||||
|
||||
var data = HandleFriendScRsp.newInstance()
|
||||
.setUid(friend.getUid())
|
||||
.setHandleResult(result);
|
||||
|
||||
if (result) {
|
||||
data.setHandleFriendInfo(FriendListInfo.newInstance().setSimpleInfo(friend.toSimpleInfo()));
|
||||
}
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.SearchPlayerScRspOuterClass.SearchPlayerScRsp;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketSearchPlayerScRsp extends BasePacket {
|
||||
|
||||
public PacketSearchPlayerScRsp(Collection<Player> players) {
|
||||
super(CmdId.SearchPlayerScRsp);
|
||||
|
||||
var data = SearchPlayerScRsp.newInstance();
|
||||
|
||||
if (players != null && players.size() > 0) {
|
||||
for (Player player : players) {
|
||||
data.addSearchResultList(player.toSimpleInfo());
|
||||
}
|
||||
} else {
|
||||
data.setRetcode(3612);
|
||||
}
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.FriendApplyListInfoOuterClass.FriendApplyListInfo;
|
||||
import emu.lunarcore.proto.SyncApplyFriendScNotifyOuterClass.SyncApplyFriendScNotify;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketSyncApplyFriendScNotify extends BasePacket {
|
||||
|
||||
public PacketSyncApplyFriendScNotify(Player friend) {
|
||||
super(CmdId.SyncApplyFriendScNotify);
|
||||
|
||||
var data = SyncApplyFriendScNotify.newInstance()
|
||||
.setFriendApplyInfo(FriendApplyListInfo.newInstance().setSimpleInfo(friend.toSimpleInfo()));
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.proto.SyncDeleteFriendScNotifyOuterClass.SyncDeleteFriendScNotify;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketSyncDeleteFriendScNotify extends BasePacket {
|
||||
|
||||
public PacketSyncDeleteFriendScNotify(int uid) {
|
||||
super(CmdId.SyncDeleteFriendScNotify);
|
||||
|
||||
var data = SyncDeleteFriendScNotify.newInstance()
|
||||
.setUid(uid);
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.FriendListInfoOuterClass.FriendListInfo;
|
||||
import emu.lunarcore.proto.SyncHandleFriendScNotifyOuterClass.SyncHandleFriendScNotify;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketSyncHandleFriendScNotify extends BasePacket {
|
||||
|
||||
public PacketSyncHandleFriendScNotify(Player friend, boolean result) {
|
||||
super(CmdId.SyncHandleFriendScNotify);
|
||||
|
||||
var data = SyncHandleFriendScNotify.newInstance()
|
||||
.setUid(friend.getUid())
|
||||
.setHandleResult(result);
|
||||
|
||||
if (result) {
|
||||
data.setHandleFriendInfo(FriendListInfo.newInstance().setSimpleInfo(friend.toSimpleInfo()));
|
||||
}
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user