This commit is contained in:
NetRiceCake
2025-12-11 02:53:24 +09:00
parent 1462a086ba
commit 629ac88c69
57 changed files with 747 additions and 443 deletions

File diff suppressed because one or more lines are too long

View File

@@ -4,9 +4,9 @@ import com.github.netricecake.kakao.exception.BadCredentialsException;
import com.github.netricecake.kakao.exception.InvalidDeviceNameException;
import com.github.netricecake.kakao.exception.InvalidDeviceUUIDException;
import com.github.netricecake.kakao.exception.UnregisteredDeviceException;
import com.github.netricecake.loco.packet.inbound.login.GetConfIn;
import com.github.netricecake.loco.packet.outbound.login.GetConfOut;
import com.github.netricecake.loco.util.ByteUtil;
import com.github.netricecake.kakao.packet.inbound.login.GetConfIn;
import com.github.netricecake.kakao.packet.outbound.login.GetConfOut;
import com.github.netricecake.kakao.util.ByteUtil;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

View File

@@ -1,21 +1,15 @@
package com.github.netricecake.kakao;
import com.github.netricecake.kakao.packet.inbound.member.*;
import com.github.netricecake.kakao.structs.ChatRoom;
import com.github.netricecake.kakao.structs.Member;
import com.github.netricecake.kakao.structs.MemberType;
import com.github.netricecake.kakao.structs.Message;
import com.github.netricecake.loco.LocoPacket;
import com.github.netricecake.loco.LocoSocketHandler;
import com.github.netricecake.loco.packet.inbound.member.*;
import com.github.netricecake.loco.packet.inbound.message.MessageIn;
import com.github.netricecake.loco.packet.inbound.room.ChatInfoIn;
import com.github.netricecake.loco.packet.inbound.room.InfoLinkIn;
import com.github.netricecake.loco.packet.outbound.member.MemberOut;
import com.github.netricecake.loco.packet.outbound.room.ChatInfoOut;
import com.github.netricecake.loco.packet.outbound.member.GetMemberOut;
import com.github.netricecake.loco.packet.outbound.room.InfoLinkOut;
import com.github.netricecake.loco.packet.outbound.message.MessageOut;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.github.netricecake.kakao.loco.LocoPacket;
import com.github.netricecake.kakao.loco.LocoSocketHandler;
import com.github.netricecake.kakao.packet.inbound.message.MessageIn;
import com.github.netricecake.kakao.packet.outbound.member.MemberOut;
import com.github.netricecake.kakao.packet.outbound.message.MessageOut;
public class LocoSocketHandlerImpl extends LocoSocketHandler {
@@ -30,100 +24,42 @@ public class LocoSocketHandlerImpl extends LocoSocketHandler {
if (packet.getMethod().equals("MSG")) {
client.getSocket().write(new LocoPacket(packet.getPacketId(), "MSG", new MessageOut().toBson()));
MessageIn in = new MessageIn();
in.fromBson(packet.getBody());
checkRoom(in.getChatId());
checkMember(in.getChatId(), in.getAuthorId());
MessageIn in = new MessageIn(packet.getBody());
ChatRoom chatRoom = client.getChatRoom(in.getChatId());
if (chatRoom == null) return;
Member member = chatRoom.getMembers().get(in.getAuthorId());
ChatRoom room = client.getChatRooms().get(in.getChatId());
Member member = room.getMembers().get(in.getAuthorId());
Message msg = new Message(in.getLogId(), room, member, in.getType(), in.getMessage(), in.getAttachment());
Message msg = new Message(client, chatRoom, in.getLogId(), member, in.getType(), in.getSendAt(), in.getMessage(), in.getAttachment());
Thread.ofVirtual().start(() -> {
client.getTalkHandler().onMessage(msg);
});
} else if (packet.getMethod().equals("NEWMEM")) {
NewMemIn in = new NewMemIn();
in.fromBson(packet.getBody());
checkRoom(in.getChatId());
checkMember(in.getChatId(), in.getUserId());
NewMemIn res = new NewMemIn(packet.getBody());
ChatRoom chatRoom = client.getChatRoom(res.getChatId());
if (chatRoom == null) return;
MemberOut mo = new MemberOut(res.getChatId(), res.getUserId());
MemberIn mi = new MemberIn(client.getSocket().writeAndRead(new LocoPacket("MEMBER", mo.toBson())).getBody());
chatRoom.getMembers().put(res.getUserId(), new Member(client, chatRoom, res.getUserId(), mi.getType(), mi.getNickName(), mi.getProfileImageUrl(), mi.getFullProfileImageUrl(), mi.getOriginalProfileImageUrl(), mi.getProfileLinkId(), mi.getMemberType(), mi.getProfileType()));
ChatRoom room = client.getChatRooms().get(in.getChatId());
if (!room.getType().equals("OM")) return;
Thread.ofVirtual().start(() -> {
client.getTalkHandler().onNewMember(room, room.getMembers().get(in.getUserId()));
client.getTalkHandler().onNewMember(chatRoom, chatRoom.getMembers().get(res.getUserId()));
});
} else if (packet.getMethod().equals("DELMEM")) {
DelMemIn in = new DelMemIn();
in.fromBson(packet.getBody());
checkRoom(in.getChatId());
DelMemIn in = new DelMemIn(packet.getBody());
ChatRoom chatRoom = client.getChatRoom(in.getChatId());
if (chatRoom == null) return;
chatRoom.getMembers().remove(in.getUserId());
ChatRoom room = client.getChatRooms().get(in.getChatId());
if (!room.getType().equals("OM")) return;
Thread.ofVirtual().start(() -> {
client.getTalkHandler().onDelMember(room, new Member(in.getUserId(), in.getNickname(), 2));
client.getTalkHandler().onDelMember(chatRoom, in.getUserId(), in.getNickname());
});
room.getMembers().remove(in.getUserId());
} else if (packet.getMethod().equals("SYNCLINKPF")) {
SyncLinkPfIn si = new SyncLinkPfIn();
si.fromBson(packet.getBody());
ChatRoom room = client.getChatRooms().get(si.getChatId());
room.getMembers().remove(si.getUserId());
Member member = new Member(si.getUserId(), si.getNickName(), 2);
room.getMembers().put(si.getUserId(), member);
}
}
private void checkRoom(long chatId) {
if (!client.getChatRooms().containsKey(chatId)) {
ChatInfoOut co = new ChatInfoOut(chatId);
ChatInfoIn ci = new ChatInfoIn();
ci.fromBson(client.getSocket().writeAndRead(new LocoPacket("CHATINFO", co.toBson())).getBody());
ChatRoom room = new ChatRoom();
room.setChatId(chatId);
room.setType(ci.getType());
room.setLinkId(ci.getLinkId());
GetMemberOut gmo = new GetMemberOut(chatId);
GetMemberIn gmi = new GetMemberIn();
gmi.fromBson(client.getSocket().writeAndRead(new LocoPacket("GETMEM", gmo.toBson())).getBody());
for (int i = 0; i < gmi.getMembers().size(); i++) {
JsonObject json = gmi.getMembers().get(i).getAsJsonObject();
int type = json.get("mt") != null ? json.get("mt").getAsInt() : 2;
Member member = new Member(json.get("userId").getAsLong(), json.get("nickName").getAsString(), type);
room.getMembers().put(member.getId(), member);
}
if (ci.getType().equals("OM")) {
InfoLinkOut lo = new InfoLinkOut(ci.getLinkId());
InfoLinkIn li = new InfoLinkIn();
li.fromBson(client.getSocket().writeAndRead(new LocoPacket("INFOLINK", lo.toBson())).getBody());
room.setName(li.getName());
} else if (ci.getType().equals("MultiChat")) {
if (!ci.getChatMetas().isEmpty()) {
JsonArray chatMetas = ci.getChatMetas();
room.setName(chatMetas.get(0).getAsJsonObject().get("content").getAsString());
} else {
JsonArray displayMembers = ci.getDisplayMembers();
String name = "";
for (int i = 0; i < displayMembers.size(); i++) {
name += displayMembers.get(i).getAsJsonObject().get("nickName").getAsString() + ", ";
}
room.setName(name);
}
} else if (ci.getType().equals("DirectChat")) {
room.setName(ci.getDisplayMembers().get(0).getAsJsonObject().get("nickName").getAsString());
}
client.getChatRooms().put(chatId, room);
}
}
private void checkMember(long chatId, long memberId) {
ChatRoom room = client.getChatRooms().get(chatId);
if (!room.getMembers().containsKey(memberId)) {
MemberOut mo = new MemberOut(chatId, memberId);
MemberIn mi = new MemberIn();
mi.fromBson(client.getSocket().writeAndRead(new LocoPacket("MEMBER", mo.toBson())).getBody());
room.getMembers().put(memberId, new Member(memberId, mi.getNickName(), mi.getMemberType()));
SyncLinkPfIn res = new SyncLinkPfIn(packet.getBody());
ChatRoom chatRoom = client.getChatRoom(res.getChatId());
if (chatRoom == null) return;
chatRoom.getMembers().remove(res.getUserId());
Member member = new Member(client, chatRoom, res.getUserId(), 1000, res.getNickName(), res.getProfileImageUrl(), res.getFullProfileImageUrl(), res.getOriginalProfileImageUrl(), res.getProfileLinkId(), MemberType.MEMBER, res.getProfileType());
chatRoom.getMembers().put(res.getUserId(), member);
}
}

View File

@@ -1,25 +1,34 @@
package com.github.netricecake.kakao;
import com.github.netricecake.kakao.exception.*;
import com.github.netricecake.kakao.structs.ChatRoom;
import com.github.netricecake.loco.LocoPacket;
import com.github.netricecake.loco.LocoSocketHandler;
import com.github.netricecake.loco.LocoSocket;
import com.github.netricecake.loco.packet.inbound.login.CheckInIn;
import com.github.netricecake.loco.packet.inbound.login.GetConfIn;
import com.github.netricecake.loco.packet.inbound.login.LoginListIn;
import com.github.netricecake.loco.packet.inbound.message.PostIn;
import com.github.netricecake.loco.packet.inbound.message.ShipIn;
import com.github.netricecake.loco.packet.inbound.message.WriteIn;
import com.github.netricecake.loco.packet.outbound.login.CheckInOut;
import com.github.netricecake.loco.packet.outbound.login.LoginListOut;
import com.github.netricecake.loco.packet.outbound.etc.PingOut;
import com.github.netricecake.loco.packet.outbound.message.PostOut;
import com.github.netricecake.loco.packet.outbound.message.ShipOut;
import com.github.netricecake.loco.packet.outbound.message.WriteOut;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.loco.util.ByteUtil;
import com.github.netricecake.kakao.packet.inbound.member.GetMemberIn;
import com.github.netricecake.kakao.packet.inbound.message.PostIn;
import com.github.netricecake.kakao.packet.inbound.message.ShipIn;
import com.github.netricecake.kakao.packet.inbound.room.ChatInfoIn;
import com.github.netricecake.kakao.packet.inbound.room.InfoLinkIn;
import com.github.netricecake.kakao.packet.outbound.member.GetMemberOut;
import com.github.netricecake.kakao.packet.outbound.message.PostOut;
import com.github.netricecake.kakao.packet.outbound.message.ShipOut;
import com.github.netricecake.kakao.packet.outbound.room.ChatInfoOut;
import com.github.netricecake.kakao.packet.outbound.room.InfoLinkOut;
import com.github.netricecake.kakao.structs.*;
import com.github.netricecake.kakao.loco.LocoPacket;
import com.github.netricecake.kakao.loco.LocoSocketHandler;
import com.github.netricecake.kakao.loco.LocoSocket;
import com.github.netricecake.kakao.packet.inbound.login.CheckInIn;
import com.github.netricecake.kakao.packet.inbound.login.GetConfIn;
import com.github.netricecake.kakao.packet.inbound.login.LoginListIn;
import com.github.netricecake.kakao.packet.inbound.message.WriteIn;
import com.github.netricecake.kakao.packet.outbound.login.CheckInOut;
import com.github.netricecake.kakao.packet.outbound.login.LoginListOut;
import com.github.netricecake.kakao.packet.outbound.etc.PingOut;
import com.github.netricecake.kakao.packet.outbound.member.KickMemberOut;
import com.github.netricecake.kakao.packet.outbound.message.WriteOut;
import com.github.netricecake.kakao.util.BsonUtil;
import com.github.netricecake.kakao.util.ByteUtil;
import com.github.netricecake.kakao.util.ImageUtil;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.Getter;
@@ -42,7 +51,6 @@ public class TalkClient {
private final String deviceUuid;
private final String sessionDir;
@Getter
private final Map<Long, ChatRoom> chatRooms = new HashMap<>();
@Getter
@@ -148,22 +156,75 @@ public class TalkClient {
});
}
public boolean sendMessage(long chatId, int type, String message, String extra) {
WriteOut wo = new WriteOut();
wo.setChatId(chatId);
wo.setType(type);
wo.setMessage(message);
wo.setExtra(extra);
WriteIn wi = new WriteIn();
wi.fromBson(socket.writeAndRead(new LocoPacket("WRITE", wo.toBson())).getBody());
return wi.getStatus() == 0;
public ChatRoom getChatRoom(long chatId) {
if (chatRooms.containsKey(chatId)) return chatRooms.get(chatId);
ChatInfoOut req = new ChatInfoOut(chatId);
ChatInfoIn res = new ChatInfoIn(socket.writeAndRead(new LocoPacket("CHATINFO", req.toBson())).getBody());
if (res.getStatus() != 0) return null;
GetMemberOut memberReq = new GetMemberOut(chatId);
GetMemberIn memberRes = new GetMemberIn(socket.writeAndRead(new LocoPacket("GETMEM", memberReq.toBson())).getBody());
ChatRoom chatRoom = null;
if (res.getType().equals(ChatRoomType.OPEN_CHAT) || res.getType().equals(ChatRoomType.OPEN_DIRECT)) {
InfoLinkOut linkReq = new InfoLinkOut(res.getLinkId());
InfoLinkIn linkRes = new InfoLinkIn(socket.writeAndRead(new LocoPacket("INFOLINK", linkReq.toBson())).getBody());
chatRoom = new ChatRoom(this, chatId, res.getType(), linkRes.getName(), res.getLinkId());
for (int i = 0; i < memberRes.getMembers().size(); i++) {
JsonObject json = memberRes.getMembers().get(i).getAsJsonObject();
Member member = new Member(this, chatRoom, json.get("userId").getAsLong(), json.get("type").getAsInt(), json.get("nickName").getAsString(), json.get("pi").getAsString(), json.get("fpi").getAsString(), json.get("opi").getAsString(), json.get("ptp").getAsInt() == 16 ? json.get("pli").getAsLong() : 0, json.get("mt").getAsInt(), json.get("ptp").getAsInt());
chatRoom.getMembers().put(member.getUserId(), member);
}
} else if (res.getType().equals(ChatRoomType.DIRECT_CHAT)) {
chatRoom = new ChatRoom(this, chatId, res.getType(), res.getDisplayMembers().get(0).getAsJsonObject().get("nickName").getAsString(), 0);
for (int i = 0; i < memberRes.getMembers().size(); i++) {
JsonObject json = memberRes.getMembers().get(i).getAsJsonObject();
Member member = new Member(this, chatRoom, json.get("userId").getAsLong(), json.get("type").getAsInt(), json.get("nickName").getAsString(), json.get("profileImageUrl").getAsString(), json.get("fullProfileImageUrl").getAsString(), json.get("originalProfileImageUrl").getAsString(), 0, MemberType.MEMBER, 0);
chatRoom.getMembers().put(member.getUserId(), member);
}
} else if (res.getType().equals(ChatRoomType.GROUP_CHAT)) {
if (!res.getChatMetas().isEmpty()) {
JsonArray chatMetas = res.getChatMetas();
chatRoom = new ChatRoom(this, chatId, res.getType(), chatMetas.get(0).getAsJsonObject().get("content").getAsString(), 0);
} else {
JsonArray displayMembers = res.getDisplayMembers();
String name = "";
for (int i = 0; i < displayMembers.size(); i++) {
name += displayMembers.get(i).getAsJsonObject().get("nickName").getAsString() + ", ";
}
chatRoom = new ChatRoom(this, chatId, res.getType(), name, 0);
}
for (int i = 0; i < memberRes.getMembers().size(); i++) {
JsonObject json = memberRes.getMembers().get(i).getAsJsonObject();
Member member = new Member(this, chatRoom, json.get("userId").getAsLong(), json.get("type").getAsInt(), json.get("nickName").getAsString(), json.get("profileImageUrl").getAsString(), json.get("fullProfileImageUrl").getAsString(), json.get("originalProfileImageUrl").getAsString(), 0, MemberType.MEMBER, 0);
chatRoom.getMembers().put(member.getUserId(), member);
}
}
return chatRoom;
}
public boolean sendMessage(long chatId, String message, String extra) {
WriteOut req = new WriteOut();
req.setChatId(chatId);
req.setType(MessageType.TEXT);
req.setMessage(message);
req.setExtra(extra);
WriteIn res = new WriteIn(socket.writeAndRead(new LocoPacket("WRITE", req.toBson())).getBody());
return res.getStatus() == 0;
}
public boolean sendMessage(long chatId, String message) {
return sendMessage(chatId, 1, message, "{}");
return sendMessage(chatId, message, "{}");
}
public boolean sendJpg(long chatId, byte[] image, String format, int width, int height) {
public boolean sendJpg(long chatId, byte[] image) {
ImageUtil.ImageMeta meta = ImageUtil.getImageMeta(image);
if (!meta.isValidJpeg()) return false;
LocoSocket postSocket = null;
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
@@ -171,8 +232,7 @@ public class TalkClient {
so.setChatId(chatId);
so.setSize(image.length);
so.setCheckSum(ByteUtil.byteArrayToHexString(md.digest(image)));
ShipIn si = new ShipIn();
si.fromBson(socket.writeAndRead(new LocoPacket("SHIP", so.toBson())).getBody());
ShipIn si = new ShipIn(socket.writeAndRead(new LocoPacket("SHIP", so.toBson())).getBody());
if (si.getStatus() != 0) return false;
final CompletableFuture<Integer> future = new CompletableFuture<>();
@@ -191,11 +251,10 @@ public class TalkClient {
po.setKey(si.getKey());
po.setSize(image.length);
po.setChatId(chatId);
po.setWidth(width);
po.setHeight(height);
po.setWidth(meta.getWidth());
po.setHeight(meta.getHeight());
PostIn pi = new PostIn();
pi.fromBson(postSocket.writeAndRead(new LocoPacket("POST", po.toBson())).getBody());
PostIn pi = new PostIn(postSocket.writeAndRead(new LocoPacket("POST", po.toBson())).getBody());
if (pi.getStatus() != 0) {
postSocket.close();
return false;
@@ -214,7 +273,33 @@ public class TalkClient {
return false;
}
public long getUserId() {
public boolean reply(Message target, String message) {
JsonObject extraObject = new JsonObject();
extraObject.addProperty("src_logId", target.getLogId());
extraObject.addProperty("src_userId", target.getAuthor().getUserId());
extraObject.addProperty("src_message", target.getMessage());
extraObject.addProperty("src_type", target.getType());
extraObject.addProperty("src_linkId", target.getChatRoom().getLinkId());
WriteOut req = new WriteOut();
req.setChatId(target.getChatRoom().getChatId());
req.setMessage(message);
req.setType(MessageType.REPLY);
req.setExtra(extraObject.toString());
JsonObject res = socket.writeAndRead(new LocoPacket("WRITE", req.toBson())).getBodyJson();
return res.get("status").getAsInt() == 0;
}
public boolean kickMember(long chatId, long linkId, long memberId) {
KickMemberOut req = new KickMemberOut(chatId, linkId, memberId);
JsonObject res = socket.writeAndRead(new LocoPacket("KICKMEM", req.toBson())).getBodyJson();
// 채팅 로그 저장할거면 이거도 처리
return res.get("status").getAsInt() == 0;
}
public long getMyUserId() {
return loginData.userId;
}

View File

@@ -12,6 +12,14 @@ public class TalkHandler {
@Setter
private TalkClient talkClient;
public void onConnect() {
}
public void onDisconnect() {
}
public void onMessage(Message message) {
}
@@ -20,7 +28,7 @@ public class TalkHandler {
}
public void onDelMember(ChatRoom chatRoom, Member member) {
public void onDelMember(ChatRoom chatRoom, long userId, String nickName) {
}

View File

@@ -1,5 +1,7 @@
package com.github.netricecake.loco;
package com.github.netricecake.kakao.loco;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.Setter;
@@ -38,4 +40,16 @@ public class LocoPacket {
this(-1, method, body);
}
public LocoPacket(int packetId, String method, JsonObject body) {
this(packetId, method, BsonUtil.jsonObjectToBson(body));
}
public LocoPacket(String method, JsonObject body) {
this(-1, method, BsonUtil.jsonObjectToBson(body));
}
public JsonObject getBodyJson() {
return BsonUtil.bsonToJsonObject(body);
}
}

View File

@@ -1,8 +1,8 @@
package com.github.netricecake.loco;
package com.github.netricecake.kakao.loco;
import com.github.netricecake.loco.crypto.CryptoManager;
import com.github.netricecake.loco.codec.LocoCodec;
import com.github.netricecake.loco.codec.SecureLayerCodec;
import com.github.netricecake.kakao.loco.crypto.CryptoManager;
import com.github.netricecake.kakao.loco.codec.LocoCodec;
import com.github.netricecake.kakao.loco.codec.SecureLayerCodec;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioIoHandler;

View File

@@ -1,4 +1,4 @@
package com.github.netricecake.loco;
package com.github.netricecake.kakao.loco;
public class LocoSocketHandler {

View File

@@ -1,9 +1,9 @@
package com.github.netricecake.loco.codec;
package com.github.netricecake.kakao.loco.codec;
import com.github.netricecake.loco.LocoPacket;
import com.github.netricecake.loco.LocoSocketHandler;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.loco.util.ByteUtil;
import com.github.netricecake.kakao.loco.LocoPacket;
import com.github.netricecake.kakao.loco.LocoSocketHandler;
import com.github.netricecake.kakao.util.BsonUtil;
import com.github.netricecake.kakao.util.ByteUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.codec;
package com.github.netricecake.kakao.loco.codec;
import com.github.netricecake.loco.crypto.CryptoManager;
import com.github.netricecake.loco.util.ByteUtil;
import com.github.netricecake.kakao.loco.crypto.CryptoManager;
import com.github.netricecake.kakao.util.ByteUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageCodec;

View File

@@ -1,6 +1,6 @@
package com.github.netricecake.loco.crypto;
package com.github.netricecake.kakao.loco.crypto;
import com.github.netricecake.loco.util.ByteUtil;
import com.github.netricecake.kakao.util.ByteUtil;
import lombok.Getter;
import javax.crypto.Cipher;

View File

@@ -1,4 +1,4 @@
package com.github.netricecake.loco.packet;
package com.github.netricecake.kakao.packet;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

View File

@@ -0,0 +1,6 @@
package com.github.netricecake.kakao.packet.inbound.etc;
import com.github.netricecake.kakao.packet.InboundPacket;
public class PingIn extends InboundPacket {
}

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.inbound.login;
package com.github.netricecake.kakao.packet.inbound.login;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.inbound.login;
package com.github.netricecake.kakao.packet.inbound.login;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.inbound.login;
package com.github.netricecake.kakao.packet.inbound.login;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Getter;

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.inbound.member;
package com.github.netricecake.kakao.packet.inbound.member;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.Getter;
@@ -15,7 +15,7 @@ public class DelMemIn extends InboundPacket {
private String nickname;
public void fromBson(byte[] bson) {
public DelMemIn(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson).get("chatLog").getAsJsonObject();
chatId = jsonObject.get("chatId").getAsLong();
userId = jsonObject.get("authorId").getAsLong();

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.inbound.member;
package com.github.netricecake.kakao.packet.inbound.member;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Getter;
@@ -13,7 +13,7 @@ public class GetMemberIn extends InboundPacket {
private JsonArray members;
public void fromBson(byte[] bson) {
public GetMemberIn(byte[] bson) {
JsonObject json = BsonUtil.bsonToJsonObject(bson);
status = json.get("status").getAsInt();
if (status == 0) members = json.get("members").getAsJsonArray();

View File

@@ -0,0 +1,45 @@
package com.github.netricecake.kakao.packet.inbound.member;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.github.netricecake.kakao.structs.MemberType;
import com.google.gson.JsonObject;
import lombok.Getter;
@Getter
public class MemberIn extends InboundPacket {
private long userId;
private int type;
private String nickName;
private String profileImageUrl;
private String fullProfileImageUrl;
private String originalProfileImageUrl;
private long profileLinkId;
private int memberType = MemberType.MEMBER;
private int profileType;
public MemberIn(byte[] bson) {
JsonObject json = BsonUtil.bsonToJsonObject(bson).get("members").getAsJsonArray().get(0).getAsJsonObject();
userId = json.get("userId").getAsLong();
type = json.get("type").getAsInt();
nickName = json.get("nickName").getAsString();
profileImageUrl = json.get("pi").getAsString();
fullProfileImageUrl = json.get("fpi").getAsString();
originalProfileImageUrl = json.get("opi").getAsString();
if (type == 1000) {
memberType = json.get("mt").getAsInt();
profileType = json.get("ptp").getAsInt();
profileLinkId = profileType == 16 ? json.get("pli").getAsLong() : 0;
}
}
}

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.inbound.member;
package com.github.netricecake.kakao.packet.inbound.member;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.Getter;
@@ -15,7 +15,7 @@ public class NewMemIn extends InboundPacket {
private String nickname;
public void fromBson(byte[] bson) {
public NewMemIn(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson).get("chatLog").getAsJsonObject();
chatId = jsonObject.get("chatId").getAsLong();
userId = jsonObject.get("authorId").getAsLong();

View File

@@ -0,0 +1,43 @@
package com.github.netricecake.kakao.packet.inbound.member;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
@Getter
public class SyncLinkPfIn extends InboundPacket {
private long chatId;
private long linkId;
private long userId;
private int profileType;
private String nickName;
private String profileImageUrl;
private String fullProfileImageUrl;
private String originalProfileImageUrl;
private long profileLinkId;
public SyncLinkPfIn(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
chatId = jsonObject.get("c").getAsLong();
linkId = jsonObject.get("li").getAsLong();
JsonObject olu = jsonObject.get("olu").getAsJsonObject();
userId = olu.get("userId").getAsLong();
profileType = olu.get("ptp").getAsInt();
nickName = olu.get("nn").getAsString();
profileImageUrl = olu.get("pi").getAsString();
fullProfileImageUrl = olu.get("fpi").getAsString();
originalProfileImageUrl = olu.get("opi").getAsString();
profileLinkId = profileType == 16 ? olu.get("pli").getAsLong() : 0;
}
}

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.inbound.message;
package com.github.netricecake.kakao.packet.inbound.message;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
@@ -18,11 +18,13 @@ public class MessageIn extends InboundPacket {
private int type;
private long sendAt;
private String message;
private String attachment;
public void fromBson(byte[] bson) {
public MessageIn(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
chatId = jsonObject.get("chatId").getAsLong();
logId = jsonObject.get("logId").getAsLong();
@@ -31,6 +33,7 @@ public class MessageIn extends InboundPacket {
authorNickname = jsonObject.get("authorNickname").getAsString(); // 옵챗 아니면 이필드가 없음;;
} catch (Exception e) {}
type = jsonObject.get("chatLog").getAsJsonObject().get("type").getAsInt();
sendAt = jsonObject.get("chatLog").getAsJsonObject().get("sendAt").getAsLong();
message = jsonObject.get("chatLog").getAsJsonObject().get("message").getAsString();
try {
attachment = jsonObject.get("chatLog").getAsJsonObject().get("attachment").getAsString();

View File

@@ -1,6 +1,6 @@
package com.github.netricecake.loco.packet.inbound.message;
package com.github.netricecake.kakao.packet.inbound.message;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
@@ -11,7 +11,7 @@ public class PostIn {
private long o;
public void fromBson(byte[] bson) {
public PostIn(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
this.status = jsonObject.get("status").getAsInt();
this.o = jsonObject.get("o").getAsLong();

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.inbound.message;
package com.github.netricecake.kakao.packet.inbound.message;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
@@ -18,7 +18,7 @@ public class ShipIn extends InboundPacket {
private int port;
public void fromBson(byte[] bson) {
public ShipIn(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
status = jsonObject.get("status").getAsInt();
if (status != 0) return;

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.inbound.message;
package com.github.netricecake.kakao.packet.inbound.message;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
@@ -10,7 +10,7 @@ public class WriteIn extends InboundPacket {
private int status;
public void fromBson(byte[] bson) {
public WriteIn(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
status = jsonObject.get("status").getAsInt();
}

View File

@@ -0,0 +1,36 @@
package com.github.netricecake.kakao.packet.inbound.room;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.github.netricecake.kakao.structs.ChatRoomType;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Getter;
@Getter
public class ChatInfoIn extends InboundPacket {
private int status;
private String type;
private JsonArray chatMetas;
private JsonArray displayMembers;
private long linkId = 0;
public ChatInfoIn(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
status = jsonObject.get("status").getAsInt();
if (status == 0) {
type = jsonObject.get("chatInfo").getAsJsonObject().get("type").getAsString();
chatMetas = jsonObject.get("chatInfo").getAsJsonObject().get("chatMetas").getAsJsonArray();
displayMembers = jsonObject.get("chatInfo").getAsJsonObject().get("displayMembers").getAsJsonArray();
if (type.equals(ChatRoomType.OPEN_CHAT) || type.equals(ChatRoomType.OPEN_DIRECT)) {
linkId = jsonObject.get("chatInfo").getAsJsonObject().get("li").getAsLong();
}
}
}
}

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.inbound.room;
package com.github.netricecake.kakao.packet.inbound.room;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.packet.InboundPacket;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
@@ -10,7 +10,7 @@ public class InfoLinkIn extends InboundPacket {
private String name;
public void fromBson(byte[] bson) {
public InfoLinkIn(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
name = jsonObject.get("ols").getAsJsonArray().get(0).getAsJsonObject().get("ln").getAsString();
}

View File

@@ -0,0 +1,11 @@
package com.github.netricecake.kakao.packet.outbound.etc;
import com.github.netricecake.kakao.util.BsonUtil;
public class PingOut {
public byte[] toBson() {
return BsonUtil.jsonToBson("{}");
}
}

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.outbound.login;
package com.github.netricecake.kakao.packet.outbound.login;
import com.github.netricecake.kakao.KakaoApi;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.Setter;

View File

@@ -1,6 +1,6 @@
package com.github.netricecake.loco.packet.outbound.login;
package com.github.netricecake.kakao.packet.outbound.login;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
public class GetConfOut {

View File

@@ -1,8 +1,8 @@
package com.github.netricecake.loco.packet.outbound.login;
package com.github.netricecake.kakao.packet.outbound.login;
import com.github.netricecake.kakao.KakaoApi;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.loco.util.ByteUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.github.netricecake.kakao.util.ByteUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Getter;
@@ -38,16 +38,12 @@ public class LoginListOut {
private long lbk = 0;
private byte[] rp; // 이거 뭐임
private byte[] rp = ByteUtil.hexStringToByteArray("0000ffff0000");; // 이거 뭐임
private boolean bg = true;
private String oauthToken;
public LoginListOut() {
rp = ByteUtil.hexStringToByteArray("0000ffff0000");
}
public byte[] toBson() {
JsonObject rpObject = new JsonObject();
JsonObject binary = new JsonObject();

View File

@@ -1,6 +1,6 @@
package com.github.netricecake.loco.packet.outbound.member;
package com.github.netricecake.kakao.packet.outbound.member;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
public class GetMemberOut {

View File

@@ -0,0 +1,32 @@
package com.github.netricecake.kakao.packet.outbound.member;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class KickMemberOut {
private long chatId;
private long linkId;
private long memberId;
public KickMemberOut(long chatId, long linkId, long memberId) {
this.chatId = chatId;
this.linkId = linkId;
this.memberId = memberId;
}
public byte[] toBson() {
JsonObject json = new JsonObject();
json.addProperty("li", linkId);
json.addProperty("c", chatId);
json.addProperty("mid", memberId);
json.addProperty("r", false);
return BsonUtil.jsonObjectToBson(json);
}
}

View File

@@ -1,6 +1,6 @@
package com.github.netricecake.loco.packet.outbound.member;
package com.github.netricecake.kakao.packet.outbound.member;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Getter;

View File

@@ -0,0 +1,26 @@
package com.github.netricecake.kakao.packet.outbound.member;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class PardonMemberOut {
private long chatId;
private long linkId;
private long memberId;
public byte[] toBson() {
JsonObject json = new JsonObject();
json.addProperty("li", linkId);
json.addProperty("c", chatId);
json.addProperty("mid", memberId);
return BsonUtil.jsonObjectToBson(json);
}
}

View File

@@ -1,6 +1,6 @@
package com.github.netricecake.loco.packet.outbound.message;
package com.github.netricecake.kakao.packet.outbound.message;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
public class MessageOut {

View File

@@ -1,7 +1,7 @@
package com.github.netricecake.loco.packet.outbound.message;
package com.github.netricecake.kakao.packet.outbound.message;
import com.github.netricecake.kakao.KakaoApi;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.Setter;

View File

@@ -1,6 +1,6 @@
package com.github.netricecake.loco.packet.outbound.message;
package com.github.netricecake.kakao.packet.outbound.message;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.Setter;

View File

@@ -1,6 +1,7 @@
package com.github.netricecake.loco.packet.outbound.message;
package com.github.netricecake.kakao.packet.outbound.message;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.github.netricecake.kakao.structs.MessageType;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.Setter;
@@ -12,11 +13,17 @@ import java.security.SecureRandom;
public class WriteOut {
private long chatId;
private long msgId = new SecureRandom().nextLong();
private String message;
private int type = 1;
private int type = MessageType.TEXT;
private boolean noSeen = false;
private String extra = "{}";
private int scope = 1;
public byte[] toBson() {

View File

@@ -1,6 +1,6 @@
package com.github.netricecake.loco.packet.outbound.room;
package com.github.netricecake.kakao.packet.outbound.room;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonObject;
public class ChatInfoOut {

View File

@@ -1,6 +1,6 @@
package com.github.netricecake.loco.packet.outbound.room;
package com.github.netricecake.kakao.packet.outbound.room;
import com.github.netricecake.loco.util.BsonUtil;
import com.github.netricecake.kakao.util.BsonUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

View File

@@ -1,24 +1,39 @@
package com.github.netricecake.kakao.structs;
import com.github.netricecake.kakao.TalkClient;
import com.github.netricecake.kakao.util.ImageUtil;
import lombok.Getter;
import lombok.Setter;
import java.util.HashMap;
import java.util.Map;
@Getter
@Setter
public class ChatRoom {
private long chatId;
@Getter
private final TalkClient client;
private String type;
@Getter
private final long chatId;
private String name;
@Getter
private final String type;
private long linkId;
@Getter
private final String name;
private Map<Long, Member> members = new HashMap<>();
@Getter
private final long linkId;
@Getter
private final Map<Long, Member> members = new HashMap<>();
public ChatRoom(TalkClient client, long chatId, String type, String name, long linkId) {
this.client = client;
this.chatId = chatId;
this.type = type;
this.name = name;
this.linkId = linkId;
}
public int getMemberCount() {
return members.size();
@@ -28,4 +43,34 @@ public class ChatRoom {
return members.get(id);
}
public boolean kickMember(long userId) {
if (!(type.equals(ChatRoomType.OPEN_CHAT) || type.equals(ChatRoomType.OPEN_DIRECT))) return false;
if (!(getMember(client.getMyUserId()).getMemberType() == MemberType.OWNER || getMember(client.getMyUserId()).getMemberType() == MemberType.ADMIN)) return false;
return client.kickMember(chatId, linkId, userId);
}
public boolean kickMember(Member member) {
return kickMember(member.getUserId());
}
public boolean sendMessage(String message) {
return client.sendMessage(chatId, message);
}
public boolean sendMessage(String message, String extra) {
return client.sendMessage(chatId, message, extra);
}
public boolean sendJpg(byte[] image) {
return client.sendJpg(chatId, image); //client.sendImage(chatId, image, extension);
}
public boolean sendVideo(String extension, byte[] video) {
return false;
}
public boolean sendFile(String extension, byte[] file) {
return false;
}
}

View File

@@ -0,0 +1,11 @@
package com.github.netricecake.kakao.structs;
public class ChatRoomType {
public final static String DIRECT_CHAT = "DirectChat";
public final static String GROUP_CHAT = "MultiChat";
public final static String OPEN_CHAT = "OM";
public final static String OPEN_DIRECT = "OD";
}

View File

@@ -1,20 +1,48 @@
package com.github.netricecake.kakao.structs;
import com.github.netricecake.kakao.TalkClient;
import lombok.Getter;
@Getter
public class Member {
private long id;
private final TalkClient client;
private String name;
private final ChatRoom chatRoom;
private int memberType;
private final long userId;
public Member(long id, String name, int memberType) {
this.id = id;
this.name = name;
private final int type;
private final String nickName;
private final String profileImageUrl;
private final String fullProfileImageUrl;
private final String originalProfileImageUrl;
private final long profileLinkId;
private final int memberType;
private final int profileType; // 1 실제 프로필, 2 카카오 프로필, 16 오픈 프로필
public Member(TalkClient client, ChatRoom chatRoom, long userId, int type, String nickName, String profileImageUrl, String fullProfileImageUrl, String originalProfileImageUrl, long profileLinkId, int memberType, int profileType) {
this.client = client;
this.chatRoom = chatRoom;
this.userId = userId;
this.type = type;
this.nickName = nickName;
this.profileImageUrl = profileImageUrl;
this.fullProfileImageUrl = fullProfileImageUrl;
this.originalProfileImageUrl = originalProfileImageUrl;
this.profileLinkId = profileLinkId;
this.memberType = memberType;
this.profileType = profileType;
}
public boolean kick() {
return chatRoom.kickMember(this);
}
}

View File

@@ -0,0 +1,10 @@
package com.github.netricecake.kakao.structs;
public class MemberType {
public final static int OWNER = 1;
public final static int MEMBER = 2;
public final static int ADMIN = 4;
public final static int BOT = 8;
}

View File

@@ -1,29 +1,48 @@
package com.github.netricecake.kakao.structs;
import com.github.netricecake.kakao.TalkClient;
import com.github.netricecake.kakao.loco.LocoPacket;
import com.github.netricecake.kakao.packet.inbound.message.WriteIn;
import com.github.netricecake.kakao.packet.outbound.message.WriteOut;
import com.google.gson.JsonObject;
import lombok.Getter;
@Getter
public class Message {
private long logId;
private final TalkClient client;
private ChatRoom chatRoom;
private final ChatRoom chatRoom;
private Member author;
private final long logId;
private int type;
private final Member author;
private String message;
private final int type;
private String attachment;
private final long sendTime;
public Message(long logId, ChatRoom chatRoom, Member author, int type, String message, String attachment) {
private final String message;
private final String attachment;
public Message(TalkClient client, ChatRoom chatRoom, long logId, Member author, int type, long sendTime, String message, String attachment) {
this.client = client;
this.logId = logId;
this.chatRoom = chatRoom;
this.author = author;
this.type = type;
this.sendTime = sendTime;
this.message = message;
this.attachment = attachment;
}
public boolean reply(String message) {
return client.reply(this, message);
}
public boolean blind() {
return false;
}
}

View File

@@ -0,0 +1,14 @@
package com.github.netricecake.kakao.structs;
public class MessageType {
private MessageType() {};
public final static int TEXT = 1;
public final static int IMAGE = 2;
public final static int VIDEO = 3;
public final static int FILE = 4;
public final static int REPLY = 26;
}

View File

@@ -1,4 +1,4 @@
package com.github.netricecake.loco.util;
package com.github.netricecake.kakao.util;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

View File

@@ -1,4 +1,4 @@
package com.github.netricecake.loco.util;
package com.github.netricecake.kakao.util;
public class ByteUtil {

View File

@@ -0,0 +1,63 @@
package com.github.netricecake.kakao.util;
import lombok.Getter;
public class ImageUtil {
@Getter
public static class ImageMeta {
private boolean isValidJpeg;
private int width;
private int height;
public ImageMeta(boolean isValidJpeg, int width, int height) {
this.isValidJpeg = isValidJpeg;
this.width = width;
this.height = height;
}
}
public static ImageMeta getImageMeta(byte[] data) {
if (data == null || data.length < 4) {
return new ImageMeta(false, 0, 0);
}
int i = 0;
if ((data[i] & 0xFF) != 0xFF || (data[i + 1] & 0xFF) != 0xD8) {
return new ImageMeta(false, 0, 0);
}
i += 2;
while (i < data.length) {
int marker;
while ((marker = (data[i] & 0xFF)) != 0xFF) {
i++;
if (i >= data.length) return new ImageMeta(false, 0, 0);
}
do {
marker = data[++i] & 0xFF;
} while (marker == 0xFF);
i++;
if (isSOFMarker(marker)) {
int height = ((data[i + 3] & 0xFF) << 8) | (data[i + 4] & 0xFF);
int width = ((data[i + 5] & 0xFF) << 8) | (data[i + 6] & 0xFF);
return new ImageMeta(true, width, height);
}
int length = ((data[i] & 0xFF) << 8) | (data[i + 1] & 0xFF);
i += length;
}
return new ImageMeta(false, 0, 0);
}
private static boolean isSOFMarker(int marker) {
return marker >= 0xC0 && marker <= 0xCF
&& marker != 0xC4 && marker != 0xC8 && marker != 0xCC;
}
}

View File

@@ -1,6 +0,0 @@
package com.github.netricecake.loco.packet.inbound.etc;
import com.github.netricecake.loco.packet.InboundPacket;
public class PingIn extends InboundPacket {
}

View File

@@ -1,26 +0,0 @@
package com.github.netricecake.loco.packet.inbound.member;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.google.gson.JsonObject;
import lombok.Getter;
@Getter
public class MemberIn extends InboundPacket {
private long userId;
private String nickName;
private int memberType = 2;
public void fromBson(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
userId = jsonObject.get("members").getAsJsonArray().get(0).getAsJsonObject().get("userId").getAsLong();
this.nickName = jsonObject.get("members").getAsJsonArray().get(0).getAsJsonObject().get("nickName").getAsString();
try {
memberType = jsonObject.get("members").getAsJsonArray().get(0).getAsJsonObject().get("mt").getAsInt();
} catch (Exception e) {}
}
}

View File

@@ -1,29 +0,0 @@
package com.github.netricecake.loco.packet.inbound.member;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.Getter;
@Getter
public class SyncLinkPfIn extends InboundPacket {
private long chatId;
private long linkId;
private long userId;
private String nickName;
public void fromBson(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
chatId = jsonObject.get("c").getAsLong();
linkId = jsonObject.get("li").getAsLong();
JsonObject olu = jsonObject.get("olu").getAsJsonObject();
userId = olu.get("userId").getAsLong();
nickName = olu.get("nn").getAsString();
}
}

View File

@@ -1,32 +0,0 @@
package com.github.netricecake.loco.packet.inbound.room;
import com.github.netricecake.loco.packet.InboundPacket;
import com.github.netricecake.loco.util.BsonUtil;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Getter;
@Getter
public class ChatInfoIn extends InboundPacket {
private String type;
private JsonArray chatMetas;
private JsonArray displayMembers;
private long linkId = 0;
public void fromBson(byte[] bson) {
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
type = jsonObject.get("chatInfo").getAsJsonObject().get("type").getAsString();
try {
linkId = jsonObject.get("chatInfo").getAsJsonObject().get("li").getAsLong();
} catch (Exception e) {}
try {
chatMetas = jsonObject.get("chatInfo").getAsJsonObject().get("chatMetas").getAsJsonArray();
displayMembers = jsonObject.get("chatInfo").getAsJsonObject().get("displayMembers").getAsJsonArray();
} catch (Exception e) {}
}
}

View File

@@ -1,11 +0,0 @@
package com.github.netricecake.loco.packet.outbound.etc;
import com.github.netricecake.loco.util.BsonUtil;
public class PingOut {
public byte[] toBson() {
return BsonUtil.jsonToBson("{}");
}
}