add sending image method
This commit is contained in:
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
@@ -1,8 +0,0 @@
|
||||
# 디폴트 무시된 파일
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 에디터 기반 HTTP 클라이언트 요청
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
7
.idea/encodings.xml
generated
7
.idea/encodings.xml
generated
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
14
.idea/misc.xml
generated
14
.idea/misc.xml
generated
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="ms-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
BIN
ex.png
BIN
ex.png
Binary file not shown.
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 58 KiB |
File diff suppressed because one or more lines are too long
@@ -4,8 +4,8 @@ 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.GetConfIn;
|
||||
import com.github.netricecake.loco.packet.outbound.GetConfOut;
|
||||
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.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -17,7 +17,6 @@ import javax.net.ssl.SSLSocketFactory;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -5,10 +5,18 @@ import com.github.netricecake.kakao.structs.Member;
|
||||
import com.github.netricecake.kakao.structs.Message;
|
||||
import com.github.netricecake.loco.LocoPacket;
|
||||
import com.github.netricecake.loco.LocoSocektHandler;
|
||||
import com.github.netricecake.loco.packet.inbound.*;
|
||||
import com.github.netricecake.loco.packet.outbound.ChatInfoOut;
|
||||
import com.github.netricecake.loco.packet.outbound.InfoLinkOut;
|
||||
import com.github.netricecake.loco.packet.outbound.MessageOut;
|
||||
import com.github.netricecake.loco.packet.inbound.member.DelMemIn;
|
||||
import com.github.netricecake.loco.packet.inbound.member.MemberIn;
|
||||
import com.github.netricecake.loco.packet.inbound.member.NewMemIn;
|
||||
import com.github.netricecake.loco.packet.inbound.member.SyncLinkPfIn;
|
||||
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.room.InfoLinkOut;
|
||||
import com.github.netricecake.loco.packet.outbound.message.MessageOut;
|
||||
import com.google.gson.JsonArray;
|
||||
import lombok.Getter;
|
||||
|
||||
public class LocoSocketHandlerImpl extends LocoSocektHandler {
|
||||
@@ -28,19 +36,22 @@ public class LocoSocketHandlerImpl extends LocoSocektHandler {
|
||||
MessageIn in = new MessageIn();
|
||||
in.fromBson(packet.getBody());
|
||||
checkRoom(in.getChatId());
|
||||
checkMember(in.getChatId(), in.getAuthorId());
|
||||
|
||||
ChatRoom room = client.getChatRooms().get(in.getChatId());
|
||||
if (!room.getType().equals("OM")) return;
|
||||
Message msg = new Message(in.getLogId(), room, new Member(in.getAuthorId(), in.getAuthorNickname()), in.getType(), in.getMessage(), in.getAttachment());
|
||||
Member member = room.getMembers().get(in.getAuthorId());
|
||||
|
||||
Message msg = new Message(in.getLogId(), room, member, in.getType(), in.getMessage(), in.getAttachment());
|
||||
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());
|
||||
|
||||
ChatRoom room = client.getChatRooms().get(in.getChatId());
|
||||
if (!room.getType().equals("OM")) return;
|
||||
client.getTalkHandler().onNewMember(room, new Member(in.getUserId(), in.getNickname()));
|
||||
client.getTalkHandler().onNewMember(room, room.getMembers().get(in.getUserId()));
|
||||
} else if (packet.getMethod().equals("DELMEM")) {
|
||||
DelMemIn in = new DelMemIn();
|
||||
in.fromBson(packet.getBody());
|
||||
@@ -49,6 +60,14 @@ public class LocoSocketHandlerImpl extends LocoSocektHandler {
|
||||
ChatRoom room = client.getChatRooms().get(in.getChatId());
|
||||
if (!room.getType().equals("OM")) return;
|
||||
client.getTalkHandler().onDelMember(room, new Member(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());
|
||||
room.getMembers().put(si.getUserId(), member);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,25 +85,48 @@ public class LocoSocketHandlerImpl extends LocoSocektHandler {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnect() {
|
||||
|
||||
System.out.println("연결 성공");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect() {
|
||||
client.connected = false;
|
||||
System.out.println("연결 끊어짐");
|
||||
System.out.println("연결 끊김");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,29 +5,36 @@ import com.github.netricecake.kakao.structs.ChatRoom;
|
||||
import com.github.netricecake.loco.LocoPacket;
|
||||
import com.github.netricecake.loco.LocoSocektHandler;
|
||||
import com.github.netricecake.loco.LocoSocket;
|
||||
import com.github.netricecake.loco.packet.inbound.CheckInIn;
|
||||
import com.github.netricecake.loco.packet.inbound.GetConfIn;
|
||||
import com.github.netricecake.loco.packet.inbound.LoginListIn;
|
||||
import com.github.netricecake.loco.packet.inbound.WriteIn;
|
||||
import com.github.netricecake.loco.packet.outbound.CheckInOut;
|
||||
import com.github.netricecake.loco.packet.outbound.LoginListOut;
|
||||
import com.github.netricecake.loco.packet.outbound.PingOut;
|
||||
import com.github.netricecake.loco.packet.outbound.WriteOut;
|
||||
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.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.awt.print.Book;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class TalkClient {
|
||||
|
||||
@@ -136,7 +143,7 @@ public class TalkClient {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
while (socket.isAlive()) {
|
||||
Thread.sleep(10 * 60 * 1000);
|
||||
Thread.sleep(5 * 60 * 1000);
|
||||
PingOut pingOut = new PingOut();
|
||||
LocoPacket pingPacket = new LocoPacket("PING", pingOut.toBson());
|
||||
socket.write(pingPacket);
|
||||
@@ -147,9 +154,9 @@ public class TalkClient {
|
||||
});
|
||||
}
|
||||
|
||||
public boolean sendMessage(ChatRoom room, int type, String message, String extra) {
|
||||
public boolean sendMessage(long chatId, int type, String message, String extra) {
|
||||
WriteOut wo = new WriteOut();
|
||||
wo.setChatId(room.getChatId());
|
||||
wo.setChatId(chatId);
|
||||
wo.setType(type);
|
||||
wo.setMessage(message);
|
||||
wo.setExtra(extra);
|
||||
@@ -158,8 +165,59 @@ public class TalkClient {
|
||||
return wi.getStatus() == 0;
|
||||
}
|
||||
|
||||
public boolean sendMessage(ChatRoom room, String message) {
|
||||
return sendMessage(room, 1, message, "{}");
|
||||
public boolean sendMessage(long chatId, String message) {
|
||||
return sendMessage(chatId, 1, message, "{}");
|
||||
}
|
||||
|
||||
public boolean sendJpg(long chatId, byte[] image, String format, int width, int height) {
|
||||
LocoSocket postSocket = null;
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||
ShipOut so = new ShipOut();
|
||||
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());
|
||||
if (si.getStatus() != 0) return false;
|
||||
|
||||
final CompletableFuture<Integer> future = new CompletableFuture<>();
|
||||
postSocket = new LocoSocket(si.getVhost(), si.getPort(), new LocoSocektHandler() {
|
||||
@Override
|
||||
public void onPacket(LocoPacket packet) {
|
||||
JsonObject jsonObject = BsonUtil.bsonToJsonObject(packet.getBody());
|
||||
int status = jsonObject.get("status").getAsInt();
|
||||
future.complete(status);
|
||||
}
|
||||
}, Executors.newFixedThreadPool(1));
|
||||
postSocket.connect();
|
||||
|
||||
PostOut po = new PostOut();
|
||||
po.setUserId(loginData.userId);
|
||||
po.setKey(si.getKey());
|
||||
po.setSize(image.length);
|
||||
po.setChatId(chatId);
|
||||
po.setWidth(width);
|
||||
po.setHeight(height);
|
||||
|
||||
PostIn pi = new PostIn();
|
||||
pi.fromBson(postSocket.writeAndRead(new LocoPacket("POST", po.toBson())).getBody());
|
||||
if (pi.getStatus() != 0) {
|
||||
postSocket.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
LocoPacket packet = new LocoPacket("", image);
|
||||
packet.setRaw(true);
|
||||
postSocket.write(packet);
|
||||
int status = future.get();
|
||||
postSocket.close();
|
||||
return status == 0;
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
//if (postSocket != null) postSocket.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.github.netricecake.kakao.structs;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ChatRoom {
|
||||
@@ -15,6 +18,6 @@ public class ChatRoom {
|
||||
|
||||
private long linkId;
|
||||
|
||||
//private Map<Long, Member> members = new HashMap<>();
|
||||
private Map<Long, Member> members = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import lombok.Setter;
|
||||
@Setter
|
||||
public class LocoPacket {
|
||||
|
||||
private boolean raw = false;
|
||||
|
||||
private int packetId;
|
||||
|
||||
private short statusCode;
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.netty.handler.codec.bytes.ByteArrayDecoder;
|
||||
import io.netty.handler.codec.bytes.ByteArrayEncoder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -51,7 +52,7 @@ public class LocoSocket {
|
||||
cryptoManager = new CryptoManager();
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
public void connect() throws IOException {
|
||||
try {
|
||||
byte[] handshakePacket = cryptoManager.generateHandshakeMessage();
|
||||
eventLoopGroup = new MultiThreadIoEventLoopGroup(1, NioIoHandler.newFactory());
|
||||
@@ -92,7 +93,7 @@ public class LocoSocket {
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
} catch (Exception e) {
|
||||
} catch (InterruptedException e) {
|
||||
handlerPool.execute(() -> {
|
||||
locoSocektHandler.onError(e);
|
||||
});
|
||||
@@ -128,11 +129,12 @@ public class LocoSocket {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (!alive) return;
|
||||
handlerPool.execute(() -> {
|
||||
locoSocektHandler.onDisconnect();
|
||||
});
|
||||
channel.close();
|
||||
eventLoopGroup.shutdownGracefully();
|
||||
channel.close();
|
||||
alive = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,18 @@ public class LocoCodec extends MessageToMessageCodec<byte[], LocoPacket> {
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext channelHandlerContext, LocoPacket packet, List<Object> list) throws Exception {
|
||||
byte[] packetId = ByteUtil.intToByteArrayLE(packet.getPacketId());
|
||||
byte[] statusCode = ByteUtil.shortToByteArrayLE(packet.getStatusCode());
|
||||
byte[] method = new byte[11];
|
||||
System.arraycopy(packet.getMethod().getBytes(), 0, method, 0, packet.getMethod().length());
|
||||
byte[] bodyType = { packet.getBodyType() };
|
||||
byte[] body = packet.getBody();
|
||||
byte[] bodyLength = ByteUtil.intToByteArrayLE(body.length);
|
||||
list.add(ByteUtil.concatBytes(packetId, statusCode, method, bodyType, bodyLength, body));
|
||||
if (packet.isRaw()) {
|
||||
list.add(packet.getBody());
|
||||
} else {
|
||||
byte[] packetId = ByteUtil.intToByteArrayLE(packet.getPacketId());
|
||||
byte[] statusCode = ByteUtil.shortToByteArrayLE(packet.getStatusCode());
|
||||
byte[] method = new byte[11];
|
||||
System.arraycopy(packet.getMethod().getBytes(), 0, method, 0, packet.getMethod().length());
|
||||
byte[] bodyType = {packet.getBodyType()};
|
||||
byte[] body = packet.getBody();
|
||||
byte[] bodyLength = ByteUtil.intToByteArrayLE(body.length);
|
||||
list.add(ByteUtil.concatBytes(packetId, statusCode, method, bodyType, bodyLength, body));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.inbound;
|
||||
package com.github.netricecake.loco.packet.inbound.etc;
|
||||
|
||||
import com.github.netricecake.loco.packet.InboundPacket;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.github.netricecake.loco.packet.inbound;
|
||||
package com.github.netricecake.loco.packet.inbound.login;
|
||||
|
||||
import com.github.netricecake.loco.packet.InboundPacket;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public class CheckInIn extends InboundPacket {
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.github.netricecake.loco.packet.inbound;
|
||||
package com.github.netricecake.loco.packet.inbound.login;
|
||||
|
||||
import com.github.netricecake.loco.packet.InboundPacket;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public class GetConfIn extends InboundPacket {
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.inbound;
|
||||
package com.github.netricecake.loco.packet.inbound.login;
|
||||
|
||||
import com.github.netricecake.loco.packet.InboundPacket;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
@@ -15,7 +15,7 @@ public class LoginListIn extends InboundPacket {
|
||||
|
||||
private long userId;
|
||||
|
||||
private int revision;
|
||||
private long revision;
|
||||
|
||||
private String revisionInfo;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class LoginListIn extends InboundPacket {
|
||||
|
||||
private long minLogId;
|
||||
|
||||
private int sb;
|
||||
private long sb;
|
||||
|
||||
private JsonArray chatDatas;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class LoginListIn extends InboundPacket {
|
||||
|
||||
private JsonArray kc;
|
||||
|
||||
private int mcmRevision;
|
||||
private long mcmRevision;
|
||||
|
||||
private long lastTokenId;
|
||||
|
||||
@@ -46,23 +46,24 @@ public class LoginListIn extends InboundPacket {
|
||||
public void fromBson(byte[] bson) {
|
||||
JsonObject json = BsonUtil.bsonToJsonObject(bson);
|
||||
status = json.get("status").getAsInt();
|
||||
try {
|
||||
userId = json.get("userId").getAsLong();
|
||||
revision = json.get("revision").getAsInt();
|
||||
revisionInfo = json.get("revisionInfo").getAsString();
|
||||
userId = getLongOrNull(json, "userId");
|
||||
revision = getLongOrNull(json, "revision");
|
||||
revisionInfo = getStringOrNull(json, "revisionInfo");
|
||||
minLogId = getLongOrNull(json, "minLogId");
|
||||
sb = getLongOrNull(json, "sb");
|
||||
mcmRevision = getLongOrNull(json, "mcmRevision");
|
||||
lastTokenId = getLongOrNull(json, "lastTokenId");
|
||||
lastChatId = getLongOrNull(json, "lastChatId");
|
||||
ltk = getLongOrNull(json, "ltk");
|
||||
lbk = getLongOrNull(json, "lbk");
|
||||
eof = getBoolOrNull(json, "eof");
|
||||
|
||||
if (status == 0) {
|
||||
rp = Base64.getDecoder().decode(json.get("rp").getAsJsonObject().get("$binary").getAsJsonObject().get("base64").getAsString());
|
||||
minLogId = json.get("minLogId").getAsLong();
|
||||
sb = json.get("sb").getAsInt();
|
||||
chatDatas = json.get("chatDatas").getAsJsonArray();
|
||||
delChatIds = json.get("delChatIds").getAsJsonArray();
|
||||
kc = json.get("kc").getAsJsonArray();
|
||||
mcmRevision = json.get("mcmRevision").getAsInt();
|
||||
lastTokenId = json.get("lastTokenId").getAsLong();
|
||||
lastChatId = json.get("lastChatId").getAsLong();
|
||||
ltk = json.get("ltk").getAsLong();
|
||||
lbk = json.get("lbk").getAsLong();
|
||||
eof = json.get("eof").getAsBoolean();
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.inbound;
|
||||
package com.github.netricecake.loco.packet.inbound.member;
|
||||
|
||||
import com.github.netricecake.loco.packet.InboundPacket;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
@@ -0,0 +1,18 @@
|
||||
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 String nickName;
|
||||
|
||||
public void fromBson(byte[] bson) {
|
||||
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
|
||||
this.nickName = jsonObject.get("members").getAsJsonArray().get(0).getAsJsonObject().get("nickName").getAsString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.inbound;
|
||||
package com.github.netricecake.loco.packet.inbound.member;
|
||||
|
||||
import com.github.netricecake.loco.packet.InboundPacket;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
@@ -0,0 +1,29 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.inbound;
|
||||
package com.github.netricecake.loco.packet.inbound.message;
|
||||
|
||||
import com.github.netricecake.loco.packet.InboundPacket;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.github.netricecake.loco.packet.inbound.message;
|
||||
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class PostIn {
|
||||
|
||||
private int status;
|
||||
|
||||
private long o;
|
||||
|
||||
public void fromBson(byte[] bson) {
|
||||
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
|
||||
this.status = jsonObject.get("status").getAsInt();
|
||||
this.o = jsonObject.get("o").getAsLong();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.github.netricecake.loco.packet.inbound.message;
|
||||
|
||||
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 ShipIn extends InboundPacket {
|
||||
|
||||
private int status;
|
||||
|
||||
private String key;
|
||||
|
||||
private String vhost;
|
||||
|
||||
private String vhost6;
|
||||
|
||||
private int port;
|
||||
|
||||
public void fromBson(byte[] bson) {
|
||||
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
|
||||
status = jsonObject.get("status").getAsInt();
|
||||
if (status != 0) return;
|
||||
key = jsonObject.get("k").getAsString();
|
||||
vhost = jsonObject.get("vh").getAsString();
|
||||
vhost6 = jsonObject.get("vh6").getAsString();
|
||||
port = jsonObject.get("p").getAsInt();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.inbound;
|
||||
package com.github.netricecake.loco.packet.inbound.message;
|
||||
|
||||
import com.github.netricecake.loco.packet.InboundPacket;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.github.netricecake.loco.packet.inbound;
|
||||
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;
|
||||
|
||||
@@ -10,7 +11,11 @@ public class ChatInfoIn extends InboundPacket {
|
||||
|
||||
private String type;
|
||||
|
||||
private long linkId;
|
||||
private JsonArray chatMetas;
|
||||
|
||||
private JsonArray displayMembers;
|
||||
|
||||
private long linkId = 0;
|
||||
|
||||
public void fromBson(byte[] bson) {
|
||||
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
|
||||
@@ -18,6 +23,10 @@ public class ChatInfoIn extends InboundPacket {
|
||||
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) {}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.inbound;
|
||||
package com.github.netricecake.loco.packet.inbound.room;
|
||||
|
||||
import com.github.netricecake.loco.packet.InboundPacket;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.outbound;
|
||||
package com.github.netricecake.loco.packet.outbound.etc;
|
||||
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.outbound;
|
||||
package com.github.netricecake.loco.packet.outbound.login;
|
||||
|
||||
import com.github.netricecake.kakao.KakaoApi;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.outbound;
|
||||
package com.github.netricecake.loco.packet.outbound.login;
|
||||
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.outbound;
|
||||
package com.github.netricecake.loco.packet.outbound.login;
|
||||
|
||||
import com.github.netricecake.kakao.KakaoApi;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.github.netricecake.loco.packet.outbound.member;
|
||||
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class MemberOut {
|
||||
|
||||
private long chatId;
|
||||
|
||||
private long memberId;
|
||||
|
||||
public MemberOut(long chatId, long memberId) {
|
||||
this.chatId = chatId;
|
||||
this.memberId = memberId;
|
||||
}
|
||||
|
||||
public byte[] toBson() {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("chatId", chatId);
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
jsonArray.add(memberId);
|
||||
jsonObject.add("memberIds", jsonArray);
|
||||
return BsonUtil.jsonObjectToBson(jsonObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.outbound;
|
||||
package com.github.netricecake.loco.packet.outbound.message;
|
||||
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.github.netricecake.loco.packet.outbound.message;
|
||||
|
||||
import com.github.netricecake.kakao.KakaoApi;
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PostOut {
|
||||
|
||||
private long userId;
|
||||
|
||||
private String key;
|
||||
|
||||
private int type = 2;
|
||||
|
||||
private long size;
|
||||
|
||||
private long chatId;
|
||||
|
||||
private long msgId = new SecureRandom().nextLong();
|
||||
|
||||
private long width;
|
||||
|
||||
private long height;
|
||||
|
||||
private String MCCMNC = KakaoApi.MCCMNC;
|
||||
|
||||
private int nType = KakaoApi.NETWORK_TYPE;
|
||||
|
||||
private String os = KakaoApi.AGENT;
|
||||
|
||||
private String version = KakaoApi.VERSION;
|
||||
|
||||
private String ex = "{\"cmt\":\"\"}";
|
||||
|
||||
private boolean ns = false;
|
||||
|
||||
private long dt = 4;
|
||||
|
||||
private long scp = 1;
|
||||
|
||||
public byte[] toBson() {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("u", userId);
|
||||
jsonObject.addProperty("k", key);
|
||||
jsonObject.addProperty("t", type);
|
||||
jsonObject.addProperty("s", size);
|
||||
jsonObject.addProperty("c", chatId);
|
||||
jsonObject.addProperty("mid", msgId);
|
||||
jsonObject.addProperty("w", width);
|
||||
jsonObject.addProperty("h", height);
|
||||
jsonObject.addProperty("mm", MCCMNC);
|
||||
jsonObject.addProperty("nt", nType);
|
||||
jsonObject.addProperty("os", os);
|
||||
jsonObject.addProperty("av", version);
|
||||
jsonObject.addProperty("ex", ex);
|
||||
jsonObject.add("f", null);
|
||||
jsonObject.add("sp", null);
|
||||
jsonObject.addProperty("ns", ns);
|
||||
jsonObject.addProperty("dt", dt);
|
||||
jsonObject.addProperty("scp", scp);
|
||||
|
||||
return BsonUtil.jsonObjectToBson(jsonObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.github.netricecake.loco.packet.outbound.message;
|
||||
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ShipOut {
|
||||
|
||||
private long chatId;
|
||||
|
||||
private long size;
|
||||
|
||||
private int type = 2;
|
||||
|
||||
private String checkSum;
|
||||
|
||||
private String extension = "jpg";
|
||||
|
||||
private String extensions = "{}";
|
||||
|
||||
public byte[] toBson() {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("c", chatId);
|
||||
jsonObject.addProperty("s", size);
|
||||
jsonObject.addProperty("t", type);
|
||||
jsonObject.addProperty("cs", checkSum);
|
||||
jsonObject.addProperty("e", extension);
|
||||
jsonObject.addProperty("ex", extensions);
|
||||
return BsonUtil.jsonObjectToBson(jsonObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.outbound;
|
||||
package com.github.netricecake.loco.packet.outbound.message;
|
||||
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.outbound;
|
||||
package com.github.netricecake.loco.packet.outbound.room;
|
||||
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.netricecake.loco.packet.outbound;
|
||||
package com.github.netricecake.loco.packet.outbound.room;
|
||||
|
||||
import com.github.netricecake.loco.util.BsonUtil;
|
||||
import com.google.gson.JsonArray;
|
||||
Reference in New Issue
Block a user