mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-19 17:19:58 +02:00
Implement commissions
This commit is contained in:
@@ -2,6 +2,9 @@ package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.AgentApply.AgentApplyReq;
|
||||
import emu.nebula.proto.AgentApply.AgentApplyResp;
|
||||
import emu.nebula.proto.AgentApply.AgentRespInfo;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@@ -10,7 +13,36 @@ public class HandlerAgentApplyReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
return session.encodeMsg(NetMsgId.agent_apply_failed_ack);
|
||||
// Parse request
|
||||
var req = AgentApplyReq.parseFrom(message);
|
||||
|
||||
// Build response
|
||||
var rsp = AgentApplyResp.newInstance();
|
||||
|
||||
// Apply for commissions
|
||||
for (var apply : req.getApply()) {
|
||||
// Apply
|
||||
var agent = session.getPlayer().getAgentManager().apply(
|
||||
apply.getId(),
|
||||
apply.getProcessTime(),
|
||||
apply.getCharIds()
|
||||
);
|
||||
|
||||
// Serialize to proto
|
||||
var info = AgentRespInfo.newInstance()
|
||||
.setId(agent.getId())
|
||||
.setBeginTime(agent.getStart());
|
||||
|
||||
rsp.addInfos(info);
|
||||
}
|
||||
|
||||
// Save
|
||||
if (rsp.getInfos().length() > 0) {
|
||||
session.getPlayer().getAgentManager().save();
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.agent_apply_succeed_ack, rsp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user