Skip to content

Commit

Permalink
v1.19
Browse files Browse the repository at this point in the history
 - updated GSON version
 - added JSON parsing support for native clients
  • Loading branch information
matsfunk committed Nov 29, 2020
1 parent c4cefb0 commit b732fb4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion server/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="libs/javaosc-core-0.3.jar"/>
<classpathentry kind="lib" path="libs/gson-2.8.2.jar"/>
<classpathentry kind="lib" path="libs/gson-2.8.6.jar"/>
<classpathentry kind="lib" path="libs/EvalEx/EvalEx-2.1.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/oocsi-client"/>
<classpathentry kind="output" path="bin"/>
Expand Down
2 changes: 1 addition & 1 deletion server/build/makejar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</manifest>
<fileset dir="${dir.workspace}/Making/iddi/oocsi/server/bin"/>
<zipfileset excludes="META-INF/*.SF" src="${dir.workspace}/Making/iddi/oocsi/server/libs/javaosc-core-0.3.jar"/>
<zipfileset excludes="META-INF/*.SF" src="${dir.workspace}/Making/iddi/oocsi/server/libs/gson-2.8.2.jar"/>
<zipfileset excludes="META-INF/*.SF" src="${dir.workspace}/Making/iddi/oocsi/server/libs/gson-2.8.6.jar"/>
<zipfileset excludes="META-INF/*.SF" src="${dir.workspace}/Making/iddi/oocsi/server/libs/EvalEx/EvalEx-2.1.jar"/>
<fileset dir="${dir.workspace}/Making/iddi/oocsi/client/bin"/>
</jar>
Expand Down
Binary file modified server/dist/OOCSI_server.jar
Binary file not shown.
Binary file removed server/libs/gson-2.8.2.jar
Binary file not shown.
Binary file added server/libs/gson-2.8.6.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion server/src/nl/tue/id/oocsi/server/OOCSIServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class OOCSIServer extends Server {

// constants
public static final String VERSION = "1.18";
public static final String VERSION = "1.19";

// defaults for different services
private int maxClients = 100;
Expand Down
52 changes: 35 additions & 17 deletions server/src/nl/tue/id/oocsi/server/protocol/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -110,8 +109,35 @@ else if (inputLine.startsWith("send")) {

Channel c = server.getChannel(recipient);
if (message.length() > 0) {
try {
Map<String, Object> map = parseJavaMessage(message);
Map<String, Object> map = null;
if (message.startsWith("{")) {
map = parseJSONMessage(message);
} else {
try {
map = parseJavaMessage(message);
if (c != null && c.accept(recipient)) {
c.send(new Message(sender.getName(), recipient, new Date(), map));
} else {
// log if not private message
if (!Channel.isPrivate(recipient)) {
OOCSIServer.logEvent(sender.getName(), recipient, "?", map, new Date());
}
}
} catch (IOException e) {
OOCSIServer.log("[MsgParser] I/O problem: " + e.getMessage() + "\n\nSender:\n"
+ sender.getName() + "\nRecipient:\n" + recipient + "\nData:\n" + message);
} catch (IllegalArgumentException e) {
OOCSIServer.log("[MsgParser] Base64 encoder problem: " + e.getMessage());
} catch (ClassNotFoundException e) {
OOCSIServer.log("[MsgParser] Unknown class: " + e.getMessage());
} catch (Exception e) {
// just in case
OOCSIServer.log("[MsgParser] Unknown problem: " + e.getMessage());
}
}

// only send if there is useful data
if (map != null) {
if (c != null && c.accept(recipient)) {
c.send(new Message(sender.getName(), recipient, new Date(), map));
} else {
Expand All @@ -120,19 +146,10 @@ else if (inputLine.startsWith("send")) {
OOCSIServer.logEvent(sender.getName(), recipient, "?", map, new Date());
}
}
} catch (IOException e) {
OOCSIServer.log("[MsgParser] I/O problem: " + e.getMessage() + "\n\nSender:\n"
+ sender.getName() + "\nRecipient:\n" + recipient + "\nData:\n" + message);
} catch (IllegalArgumentException e) {
OOCSIServer.log("[MsgParser] Base64 encoder problem: " + e.getMessage());
} catch (ClassNotFoundException e) {
OOCSIServer.log("[MsgParser] Unknown class: " + e.getMessage());
} catch (Exception e) {
// just in case
OOCSIServer.log("[MsgParser] Unknown problem: " + e.getMessage());
}
}
}
}
// respond to ping
else if (inputLine.equals("ping")) {
server.getChangeListener().refresh(sender, sender);
Expand Down Expand Up @@ -162,8 +179,7 @@ public static Map<String, Object> parseJSONMessage(String message) {

// try to parse input as JSON
try {
Gson serializer = new Gson();
JsonElement je = new JsonParser().parse(message);
JsonElement je = JsonParser.parseString(message);
if (je.isJsonObject()) {
JsonObject jo = je.getAsJsonObject();
for (Map.Entry<String, JsonElement> element : jo.entrySet()) {
Expand Down Expand Up @@ -213,8 +229,10 @@ else if (asJsonArray.get(0).getAsJsonPrimitive().isString()) {
}
map.put(element.getKey(), array);
}
} else if (!value.isJsonNull()) {
map.put(element.getKey(), serializer.toJson(value));
}
// no primitives included on first level, so we include the JSON array directly
else if (!value.isJsonNull()) {
map.put(element.getKey(), value/* serializer.toJson(value) */);
}
}
}
Expand Down

0 comments on commit b732fb4

Please sign in to comment.