mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-25 18:54:36 +01:00
Implement Heartlink
This commit is contained in:
@@ -2,6 +2,7 @@ package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.PhoneContactsInfo.PhoneContactsInfoResp;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@@ -10,7 +11,15 @@ public class HandlerPhoneContactsInfoReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
return session.encodeMsg(NetMsgId.phone_contacts_info_succeed_ack);
|
||||
// Build response
|
||||
var rsp = PhoneContactsInfoResp.newInstance();
|
||||
|
||||
for (var character : session.getPlayer().getCharacters().getCharacterCollection()) {
|
||||
rsp.addList(character.getContact().toProto());
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.phone_contacts_info_succeed_ack, rsp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.PhoneContactsReport.PhoneContactsReportReq;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.phone_contacts_report_req)
|
||||
public class HandlerPhoneContactsReportReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = PhoneContactsReportReq.parseFrom(message);
|
||||
|
||||
// Get chat data
|
||||
var data = GameData.getChatDataTable().get(req.getChatId());
|
||||
if (data == null) {
|
||||
return session.encodeMsg(NetMsgId.phone_contacts_report_failed_ack);
|
||||
}
|
||||
|
||||
// Get character
|
||||
var character = session.getPlayer().getCharacters().getCharacterById(data.getAddressBookId());
|
||||
if (character == null) {
|
||||
return session.encodeMsg(NetMsgId.phone_contacts_report_failed_ack);
|
||||
}
|
||||
|
||||
// Handle report
|
||||
var change = character.getContact().report(data, req.getProcess(), req.getOptions(), req.getEnd());
|
||||
|
||||
if (change == null) {
|
||||
return session.encodeMsg(NetMsgId.phone_contacts_report_failed_ack);
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.phone_contacts_report_succeed_ack, change.toProto());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.Public.UI32;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.phone_contacts_top_req)
|
||||
public class HandlerPhoneContactsTopReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Parse request
|
||||
var req = UI32.parseFrom(message);
|
||||
|
||||
// Get character
|
||||
var character = session.getPlayer().getCharacters().getCharacterById(req.getValue());
|
||||
if (character == null) {
|
||||
return session.encodeMsg(NetMsgId.phone_contacts_top_failed_ack);
|
||||
}
|
||||
|
||||
// Toggle chat status
|
||||
character.getContact().toggleTop();
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.phone_contacts_top_succeed_ack);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user