Skip to content

Commit 7450ab6

Browse files
committed
added gc command, now ignoring miror version, the BufferOverflowException is now fixed
1 parent 21cabb9 commit 7450ab6

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

mod.hjson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CLaJ (Copy Link and Join) allow you to play with your friends just by creating a
1010

1111
Please check this link for Mindustry v8 compatibility: https://github.com/xpdustry/claj#mindustry-v8-note
1212
'''
13-
version: "2.3"
13+
version: "2.3.1"
1414
minGameVersion: "146"
1515
java: true
1616
hidden: true

server/src/com/xpdustry/claj/server/ClajControl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ void registerCommands(ClajRelay server) {
6262
"&fr - &lw" + c.description));
6363
});
6464

65+
register("gc", "Trigger a garbage collection.", arg -> {
66+
int pre = (int)((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024);
67+
System.gc();
68+
int post = (int)((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024);
69+
Log.info("@ MB collected. Memory usage now at @ MB.", pre - post, post);
70+
});
71+
6572
register("exit", "Stop the server.", args -> {
6673
Log.info("Shutting down CLaJ server.");
6774
server.stop();

server/src/com/xpdustry/claj/server/ClajRelay.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void received(Connection connection, Object object) {
118118
connection.sendTCP("[scarlet][[CLaJ Server]:[] Your CLaJ version is obsolete! Please update it by "
119119
+ "installing the 'claj' mod, in the mod browser.");
120120
connection.close(DcReason.error);
121-
Log.warn("Rejected connection @ for incompatible version.", Strings.conIDToString(connection));
121+
Log.warn("Rejected room creation of connection @ for incompatible version.", Strings.conIDToString(connection));
122122

123123
} else if (object instanceof ClajPackets.RoomJoinPacket) {
124124
// Disconnect from a potential another room.
@@ -138,12 +138,14 @@ public void received(Connection connection, Object object) {
138138
} else if (object instanceof ClajPackets.RoomCreateRequestPacket) {
139139
// Check the version of client
140140
String version = ((ClajPackets.RoomCreateRequestPacket)object).version;
141-
if (version == null || Strings.isVersionAtLeast(version, Main.serverVersion)) {
141+
// Ignore the last part of version, the minor part. (versioning format: 2.major.minor)
142+
// The minor part is used when no changes have been made to the client version.
143+
if (version == null || Strings.isVersionAtLeast(version, Main.serverVersion, 2)) {
142144
ClajPackets.ClajMessagePacket p = new ClajPackets.ClajMessagePacket();
143145
p.message = "Your CLaJ version is outdated, please update it by reinstalling the 'claj' mod.";
144146
connection.sendTCP(p);
145147
connection.close(DcReason.error);
146-
Log.warn("Rejected connection @ for outdated version.", Strings.conIDToString(connection));
148+
Log.warn("Rejected room creation of connection @ for outdated version.", Strings.conIDToString(connection));
147149
return;
148150
}
149151

server/src/com/xpdustry/claj/server/ClajRoom.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ public void close() {
141141
closed = true; // close before kicking connections, to avoid receiving events
142142

143143
host.close(DcReason.closed);
144-
clients.values().forEach(c -> {
145-
c.setIdleThreshold(-1f);//try to avoid getting idle events
146-
c.close(DcReason.closed);
147-
});
144+
clients.values().forEach(c -> c.close(DcReason.closed));
148145
clients.clear();
149146
}
150147

server/src/com/xpdustry/claj/server/util/Strings.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,29 @@
1212

1313

1414
public class Strings extends arc.util.Strings {
15+
16+
public static boolean isVersionAtLeast(String currentVersion, String newVersion) {
17+
return isVersionAtLeast(currentVersion, newVersion, 0);
18+
}
1519
/**
16-
* @return whether {@code newVersion} is greater than {@code currentVersion}, e.g. "v146" > "124.1"
17-
* @apiNote can handle multiple dots in the version, and it's very fast because it only does one iteration.
20+
* Compare if the {@code newVersion} is greater than the {@code currentVersion}, e.g. "v146" > "124.1". <br>
21+
* {@code maxDepth} limits the number of comparisons of version segments, allowing sub-versions to be ignored.
22+
* (default is 0)
23+
*
24+
* @apiNote can handle multiple dots in the version and the 'v' prefix,
25+
* and it's very fast because it only does one iteration.
1826
*/
19-
public static boolean isVersionAtLeast(String currentVersion, String newVersion) {
27+
public static boolean isVersionAtLeast(String currentVersion, String newVersion, int maxDepth) {
28+
if (maxDepth < 1) maxDepth = Integer.MAX_VALUE;
29+
2030
int last1 = currentVersion.startsWith("v") ? 1 : 0,
2131
last2 = newVersion.startsWith("v") ? 1 : 0,
2232
len1 = currentVersion.length(),
2333
len2 = newVersion.length(),
2434
dot1 = 0, dot2 = 0,
2535
p1 = 0, p2 = 0;
2636

27-
while ((dot1 != -1 && dot2 != -1) && (last1 < len1 && last2 < len2)) {
37+
while ((dot1 != -1 && dot2 != -1) && (last1 < len1 && last2 < len2) && maxDepth-- > 0) {
2838
dot1 = currentVersion.indexOf('.', last1);
2939
dot2 = newVersion.indexOf('.', last2);
3040
if (dot1 == -1) dot1 = len1;
@@ -37,6 +47,7 @@ public static boolean isVersionAtLeast(String currentVersion, String newVersion)
3747

3848
if (p1 != p2) return p2 > p1;
3949
}
50+
if (maxDepth <= 0) return p2 > p1;
4051

4152
// Continue iteration on newVersion to see if it's just leading zeros.
4253
while (dot2 != -1 && last2 < len2) {

0 commit comments

Comments
 (0)