forked from j62/ctbrec
Revert MFC websocket message parsing change
This commit is contained in:
parent
5c0d841474
commit
792a6c10c8
|
@ -482,8 +482,8 @@ public class MyFreeCamsClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Message parseMessage(StringBuilder msgBuffer) throws UnsupportedEncodingException {
|
private Message parseMessage(StringBuilder msgBuffer) throws UnsupportedEncodingException {
|
||||||
int packetLengthBytes = parsePacketLengthBytes(msgBuffer);
|
int packetLengthBytes = 6;
|
||||||
if (packetLengthBytes < 0) {
|
if (msgBuffer.length() < packetLengthBytes) {
|
||||||
// packet size not transmitted completely
|
// packet size not transmitted completely
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
@ -522,10 +522,6 @@ public class MyFreeCamsClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int parsePacketLengthBytes(StringBuilder msgBuffer) {
|
|
||||||
return msgBuffer.indexOf(" ") - 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int parseNextInt(StringBuilder s) {
|
private int parseNextInt(StringBuilder s) {
|
||||||
int nextSpace = s.indexOf(" ");
|
int nextSpace = s.indexOf(" ");
|
||||||
int i = Integer.parseInt(s.substring(0, nextSpace));
|
int i = Integer.parseInt(s.substring(0, nextSpace));
|
||||||
|
|
|
@ -11,28 +11,26 @@ import ctbrec.ReflectionUtil;
|
||||||
|
|
||||||
public class MyFreeCamsClientTest {
|
public class MyFreeCamsClientTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMessageParsing() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testMessageParsing() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
MyFreeCamsClient client = MyFreeCamsClient.getInstance();
|
MyFreeCamsClient client = MyFreeCamsClient.getInstance();
|
||||||
StringBuilder input = new StringBuilder("082720 418550763 419337943 0 37761695 %7B%22lv%22%3A4%2C%22nm%22%3A%22AliceArras%22%2C%22pid%22%3A1%2C%22sid%22%3A418550763%2C%22uid%22%3A37761695%2C%22vs%22%3A0%2C%22u%22%3A%7B%22age%22%3A19%2C%22avatar%22%3A1%2C%22blurb%22%3A%22Open%20minded%2C%20willing%20to%20try%20new%20horny%20things%20all%20the%20time!%22%2C%22camserv%22%3A1205%2C%22chat_font%22%3A0%2C%22chat_opt%22%3A1%2C%22city%22%3A%22Tallinn%22%2C%22country%22%3A%22Estonia%22%2C%22creation%22%3A1596715285%2C%22ethnic%22%3A%22Caucasian%22%2C%22photos%22%3A1%2C%22profile%22%3A1%2C%22status%22%3A%22%22%7D%2C%22m%22%3A%7B%22camscore%22%3A629.800%2C%22continent%22%3A%22EU%22%2C%22flags%22%3A3104%2C%22kbit%22%3A0%2C%22lastnews%22%3A0%2C%22mg%22%3A0%2C%22missmfc%22%3A0%2C%22new_model%22%3A1%2C%22rank%22%3A0%2C%22rc%22%3A4%2C%22sfw%22%3A0%2C%22topic%22%3A%22%22%7D%7D");
|
StringBuilder input = new StringBuilder("00001933 0 439895060 1 0 00001933 0 439895060 1 0 0000208 0 439895060 0 112 00038...");
|
||||||
Message msg = ReflectionUtil.call(client, "parseMessage", input);
|
Message msg = ReflectionUtil.call(client, "parseMessage", input);
|
||||||
|
assertEquals(33, msg.getType());
|
||||||
|
assertEquals(0, msg.getSender());
|
||||||
|
assertEquals(439895060, msg.getReceiver());
|
||||||
|
assertEquals(1, msg.getArg1());
|
||||||
|
assertEquals(0, msg.getArg2());
|
||||||
|
assertTrue(msg.getMessage().isBlank());
|
||||||
|
|
||||||
|
input = new StringBuilder("00207820 439461784 439895060 12 507930 %7B%22lv%22%3A4%2C%22nm%22%3A%22Nivea%22%2C%22pid%22%3A1%2C%22sid%22%3A439461784%2C%22uid%22%3A507930%2C%22vs%22%3A12%2C%22u%22%3A%7B%22age%22%3A33%2C%22avatar%22%3A1%2C%22blurb%22%3A%22I%20love%20when%20my%20nose%20touch%20your%20belly%20when%20I%20do%20you%20a%20blowjob!%20When%20I%20look%20into%20your%20horny%20eyes%20when%22%2C%22camserv%22%3A1367%2C%22chat_color%22%3A%22FF0000%22%2C%22chat_font%22%3A0%2C%22chat_opt%22%3A1%2C%22ethnic%22%3A%22Caucasian%22%2C%22photos%22%3A74%2C%22profile%22%3A1%2C%22status%22%3A%22%22%7D%2C%22m%22%3A%7B%22camscore%22%3A7505.700%2C%22continent%22%3A%22EU%22%2C%22flags%22%3A605224%2C%22hidecs%22%3Atrue%2C%22kbit%22%3A0%2C%22lastnews%22%3A0%2C%22mg%22%3A0%2C%22missmfc%22%3A2%2C%22new_model%22%3A0%2C%22rank%22%3A0%2C%22rc%22%3A20%2C%22sfw%22%3A0%2C%22topic%22%3A%22hi%253A)%255Bnone%255D-Topless%252C500-snap4life%252C50-spanks%252C180-flash%252C700-10%2520mins%2520of%2520Nora%2520fun%252C666-shot%252C27%252C270%2520%253C3%22%7D%2C%22x%22%3A%7B%22fcext%22%3A%7B%22sm%22%3A%22%22%2C%22sfw%22%3A0%7D%2C%22share%22%3A%7B%22follows%22%3A11%2C%22albums%22%3A0%2C%22clubs%22%3A0%2C%22tm_album%22%3A0%2C%22collections%22%3A0%2C%22stores%22%3A0%2C%22goals%22%3A0%2C%22polls%22%3A0%2C%22things%22%3A0%2C%22recent_album_tm%22%3A0%2C%22recent_club_tm%22%3A0%2C%22recent_collection_tm%22%3A0%2C%22recent_goal_tm%22%3A0%2C%22recent_item_tm%22%3A0%2C%22recent_poll_tm%22%3A0%2C%22recent_story_tm%22%3A0%2C%22recent_album_thumb%22%3A%22%22%2C%22recent_club_thumb%22%3A%22%22%2C%22recent_collection_thumb%22%3A%22%22%2C%22recent_goal_thumb%22%3A%22%22%2C%22recent_item_thumb%22%3A%22%22%2C%22recent_poll_thumb%22%3A%22%22%2C%22recent_story_thumb%22%3A%22%22%2C%22recent_album_title%22%3A%22%22%2C%22recent_club_title%22%3A%22%22%2C%22recent_collection_title%22%3A%22%22%2C%22recent_goal_title%22%3A%22%22%2C%22recent_item_title%22%3A%22%22%2C%22recent_poll_title%22%3A%22%22%2C%22recent_story_title%22%3A%22%22%2C%22recent_album_slug%22%3A%22%22%2C%22recent_collection_slug%22%3A%22%22%2C%22tipmenus%22%3A0%7D%7D%7D");
|
||||||
|
msg = ReflectionUtil.call(client, "parseMessage", input);
|
||||||
assertEquals(20, msg.getType());
|
assertEquals(20, msg.getType());
|
||||||
assertEquals(418550763, msg.getSender());
|
assertEquals(439461784, msg.getSender());
|
||||||
assertEquals(419337943, msg.getReceiver());
|
assertEquals(439895060, msg.getReceiver());
|
||||||
assertEquals(0, msg.getArg1());
|
assertEquals(12, msg.getArg1());
|
||||||
assertEquals(37761695, msg.getArg2());
|
assertEquals(507930, msg.getArg2());
|
||||||
assertEquals(JSONObject.class, new JSONObject(msg.getMessage()).getClass());
|
assertEquals(JSONObject.class, new JSONObject(msg.getMessage()).getClass()); // make sure we have a parsable JSON message
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMessageLengthParsing() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
||||||
MyFreeCamsClient client = MyFreeCamsClient.getInstance();
|
|
||||||
StringBuilder input = new StringBuilder("082720 418550763 419337943 0 37761695");
|
|
||||||
int packetBytesLenth = ReflectionUtil.call(client, "parsePacketLengthBytes", input);
|
|
||||||
assertEquals(4, packetBytesLenth);
|
|
||||||
|
|
||||||
input = new StringBuilder("82720 418550763 419337943 0 37761695");
|
|
||||||
packetBytesLenth = ReflectionUtil.call(client, "parsePacketLengthBytes", input);
|
|
||||||
assertEquals(3, packetBytesLenth);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue