Skip to content

Commit

Permalink
Merge pull request #182 from congcoi123/develop
Browse files Browse the repository at this point in the history
Develop 0.6.0
  • Loading branch information
congcoi123 authored Oct 10, 2024
2 parents 2de408b + e3237c3 commit 766ab47
Show file tree
Hide file tree
Showing 51 changed files with 812 additions and 512 deletions.
4 changes: 0 additions & 4 deletions examples/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions examples/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions examples/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@
- Removed redundant constant, enum values
- Fixed test cases' issues
- Bugs fixed

## 0.6.0 2024-10-09 Feature release
- Upgraded dependencies
- Enhanced performances and addressed the issue related to "100% CPU"
- Reworked on MsgPack classes and methods
- Bugs fixed
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This project contains a collection of examples that show you how to manipulate t
## Dependencies
```txt
- tenio-core 0.6.0
- tenio-engine 0.5.0
- tenio-engine 0.6.0
```

## Requirements
Expand Down
2 changes: 1 addition & 1 deletion examples/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20230903.0.5.1
20241009.0.6.0
4 changes: 2 additions & 2 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<jdk.vendor>oracle</jdk.vendor>

<io.github.congcoi123.tenio.core.version>0.6.0</io.github.congcoi123.tenio.core.version>
<io.github.congcoi123.tenio.engine.version>0.5.0</io.github.congcoi123.tenio.engine.version>
<org.apache.commons.version>3.12.0</org.apache.commons.version>
<io.github.congcoi123.tenio.engine.version>0.6.0</io.github.congcoi123.tenio.engine.version>
<org.apache.commons.version>3.17.0</org.apache.commons.version>

<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
<maven.compiler.target>17</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ of this software and associated documentation files (the "Software"), to deal
import com.tenio.common.data.DataUtility;
import com.tenio.common.data.msgpack.element.MsgPackMap;
import com.tenio.core.network.entity.session.Session;
import com.tenio.core.network.statistic.NetworkWriterStatistic;
import com.tenio.examples.client.ClientUtility;
import com.tenio.examples.client.DatagramListener;
import com.tenio.examples.client.SocketListener;
Expand All @@ -50,23 +49,17 @@ of this software and associated documentation files (the "Software"), to deal
public final class TestClientMsgPackEcho implements SocketListener, DatagramListener {

private static final int SOCKET_PORT = 8032;
private final TCP tcp;
private final Session session;
private final String playerName;
private final NetworkWriterStatistic networkWriterStatistic;
private UDP udp;

public TestClientMsgPackEcho() {
playerName = ClientUtility.generateRandomString(5);

// create a new TCP object and listen for this port
tcp = new TCP(SOCKET_PORT);
TCP tcp = new TCP(SOCKET_PORT);
tcp.receive(this);
session = tcp.getSession();
Session session = tcp.getSession();
session.setName(playerName);

networkWriterStatistic = NetworkWriterStatistic.newInstance();

// send a login request
var request =
DataUtility.newMsgMap().putString(SharedEventKey.KEY_PLAYER_LOGIN, playerName);
Expand All @@ -87,15 +80,15 @@ public void onReceivedTCP(byte[] binaries) {
var parcel = (MsgPackMap) DataUtility.binaryToCollection(DataType.MSG_PACK, binaries);

System.err.println("[RECV FROM SERVER TCP] -> " + parcel);
var pack = parcel.getMsgPackArray(SharedEventKey.KEY_ALLOW_TO_ACCESS_UDP_CHANNEL);
var pack = parcel.getIntegerArray(SharedEventKey.KEY_ALLOW_TO_ACCESS_UDP_CHANNEL);

switch (pack.getInteger(0)) {
switch (pack[0]) {
case DatagramEstablishedState.ALLOW_TO_ACCESS -> {
// now you can send request for UDP connection request
var request =
DataUtility.newMsgMap().putString(SharedEventKey.KEY_PLAYER_LOGIN, playerName);
// create a new UDP object and listen for this port
udp = new UDP(pack.getInteger(1));
UDP udp = new UDP(pack[1]);
udp.receive(this);
udp.send(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public final class AccessDatagramChannelRequestValidationResultHandler extends A
@Override
public void handle(Optional<Player> player, int udpConv, AccessDatagramChannelResult result) {
if (result == AccessDatagramChannelResult.SUCCESS) {
var parcel = msgmap().putMsgPackArray(SharedEventKey.KEY_ALLOW_TO_ACCESS_UDP_CHANNEL,
msgarray().addInteger(DatagramEstablishedState.ESTABLISHED));
var parcel = msgmap().putIntegerArray(SharedEventKey.KEY_ALLOW_TO_ACCESS_UDP_CHANNEL,
new int[] { DatagramEstablishedState.ESTABLISHED });

response().setContent(parcel.toBinary()).setRecipientPlayer(player.get()).write();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ public final class PlayerLoggedInHandler extends AbstractHandler
public void handle(Player player, PlayerLoggedInResult result) {
if (result == PlayerLoggedInResult.SUCCESS) {
var parcel =
msgmap().putMsgPackArray(SharedEventKey.KEY_ALLOW_TO_ACCESS_UDP_CHANNEL,
msgarray().addInteger(DatagramEstablishedState.ALLOW_TO_ACCESS)
.addInteger(api().getCurrentAvailableUdpPort()));
msgmap().putIntegerArray(SharedEventKey.KEY_ALLOW_TO_ACCESS_UDP_CHANNEL,
new int[] { DatagramEstablishedState.ALLOW_TO_ACCESS, api().getCurrentAvailableUdpPort() });

response().setContent(parcel.toBinary()).setRecipientPlayer(player).write();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,25 @@ public void handle(Player player, Room room, PlayerJoinedRoomResult result) {
var players = room.getReadonlyPlayersList();
var iterator = players.iterator();

var pack = msgarray();
var users = new String[players.size()];
var positionXs = new int[players.size()];
var positionYs = new int[players.size()];
int index = 0;
while (iterator.hasNext()) {
var rplayer = iterator.next();

var parray = msgarray();
parray.addString(rplayer.getName());
parray.addInteger((int) rplayer.getProperty(Example7Constant.PLAYER_POSITION_X));
parray.addInteger((int) rplayer.getProperty(Example7Constant.PLAYER_POSITION_Y));
users[index] = rplayer.getName();
positionXs[index] = (int) rplayer.getProperty(Example7Constant.PLAYER_POSITION_X);
positionYs[index] = (int) rplayer.getProperty(Example7Constant.PLAYER_POSITION_Y);

pack.addMsgPackArray(parray);
index++;
}

var parcel = msgmap().putString(SharedEventKey.KEY_COMMAND, "i")
.putMsgPackArray(SharedEventKey.KEY_DATA, pack);
var parcel = msgmap()
.putString(SharedEventKey.KEY_COMMAND, "i")
.putStringArray(SharedEventKey.KEY_USER, users)
.putIntegerArray(SharedEventKey.KEY_DATA_1, positionXs)
.putIntegerArray(SharedEventKey.KEY_DATA_2, positionYs);

response().setRecipientPlayers(players).setContent(parcel.toBinary()).write();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,18 @@ public final class ReceivedMessageFromPlayerHandler extends AbstractHandler

@Override
public void handle(Player player, DataCollection message) {
var position =
((MsgPackMap) message).getMsgPackArray(SharedEventKey.KEY_DATA).toArray();
var msgpackMap = (MsgPackMap) message;
var positions = msgpackMap.getIntegerArray(SharedEventKey.KEY_DATA);

player.setProperty(Example7Constant.PLAYER_POSITION_X, position[0]);
player.setProperty(Example7Constant.PLAYER_POSITION_Y, position[1]);
player.setProperty(Example7Constant.PLAYER_POSITION_X, positions[0]);
player.setProperty(Example7Constant.PLAYER_POSITION_Y, positions[1]);

var players = player.getCurrentRoom().get().getReadonlyPlayersList();

var pack = msgarray();
pack.addString(player.getName());
pack.addInteger((int) position[0]);
pack.addInteger((int) position[1]);

var parcel = msgmap().putString(SharedEventKey.KEY_COMMAND, "m")
.putMsgPackArray(SharedEventKey.KEY_DATA, pack);
var parcel = msgmap()
.putString(SharedEventKey.KEY_COMMAND, "m")
.putString(SharedEventKey.KEY_USER, player.getName())
.putIntegerArray(SharedEventKey.KEY_DATA, new int[] { positions[0], positions[1] });

response().setRecipientPlayers(players).setContent(parcel.toBinary()).write();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ of this software and associated documentation files (the "Software"), to deal
public final class TestClientRestful {

public TestClientRestful() {
System.out.println(executeRequest("http://localhost:9999/ping", "param=test", "GET"));
System.err.println(executeRequest("http://localhost:9999/ping/another", "param=test", "POST"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ of this software and associated documentation files (the "Software"), to deal

package com.tenio.examples.example9;

import com.backblaze.erasure.FecAdapt;
import com.tenio.common.data.DataType;
import com.tenio.common.data.DataUtility;
import com.tenio.common.data.zero.ZeroArray;
Expand Down Expand Up @@ -101,7 +100,6 @@ public void onReceivedTCP(byte[] binaries) {
channelConfig.setMtu(512);
channelConfig.setAckNoDelay(true);
channelConfig.setConv(55);
channelConfig.setFecAdapt(new FecAdapt(3, 1));
channelConfig.setCrc32Check(true);
KcpClient kcpClient = new KcpClient();
kcpClient.init(channelConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public final class SharedEventKey {
public static final String KEY_PLAYER_REQUEST_NEIGHBOURS = "r";
public static final String KEY_PLAYER_GET_RESPONSE = "rr";
public static final String KEY_COMMAND = "c";
public static final String KEY_USER = "ku";
public static final String KEY_DATA = "kd";
public static final String KEY_DATA_1 = "kd1";
public static final String KEY_DATA_2 = "kd2";
public static final String KEY_UDP_CONVEY_ID = "u";
public static final String KEY_UDP_MESSAGE_DATA = "d";

Expand Down
5 changes: 5 additions & 0 deletions framework/common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@
- Changed some methods' names
- Fixed test cases' issues
- Bugs fixed

## 0.6.0 2024-10-09 Feature release
- Upgraded dependencies
- Reworked MsgPack data (Removed MsgPackArray and added new array types)
- Bugs fixed
2 changes: 1 addition & 1 deletion framework/common/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20230830.0.5.0
20241009.0.6.0
16 changes: 8 additions & 8 deletions framework/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.congcoi123</groupId>
<artifactId>tenio-common</artifactId>
<version>0.5.0</version>
<version>0.6.0</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down Expand Up @@ -39,24 +39,24 @@
</scm>

<properties>
<google.guava.version>33.1.0-jre</google.guava.version>
<org.msgpack.version>0.6.12</org.msgpack.version>
<google.guava.version>33.3.1-jre</google.guava.version>
<org.msgpack.version>0.9.8</org.msgpack.version>
<logging.log4j.version>2.20.0</logging.log4j.version>
<org.reflections.version>0.10.2</org.reflections.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<org.junit.jupiter.version>5.9.2</org.junit.jupiter.version>
<org.junit.platform.version>1.9.2</org.junit.platform.version>
<org.mockito.core.version>5.2.0</org.mockito.core.version>
<org.junit.jupiter.version>5.11.2</org.junit.jupiter.version>
<org.junit.platform.version>1.11.2</org.junit.platform.version>
<org.mockito.core.version>5.14.1</org.mockito.core.version>

<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
<jdk.release>17</jdk.release>
<jdk.vendor>oracle</jdk.vendor>

<maven.checkstyle.version>3.1.2</maven.checkstyle.version>
<maven.source.plugin.version>3.2.0</maven.source.plugin.version>
<maven.javadoc.plugin.version>3.6.3</maven.javadoc.plugin.version>
<maven.javadoc.plugin.version>3.10.1</maven.javadoc.plugin.version>
<maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>
<jacoco.maven.plugin.version>0.8.7</jacoco.maven.plugin.version>
<coveralls.maven.plugin.version>4.3.0</coveralls.maven.plugin.version>
Expand All @@ -73,7 +73,7 @@
</dependency>
<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack</artifactId>
<artifactId>msgpack-core</artifactId>
<version>${org.msgpack.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ of this software and associated documentation files (the "Software"), to deal
package com.tenio.common.data;

import com.tenio.common.data.msgpack.MsgPackUtility;
import com.tenio.common.data.msgpack.element.MsgPackArray;
import com.tenio.common.data.msgpack.element.MsgPackMap;
import com.tenio.common.data.zero.ZeroArray;
import com.tenio.common.data.zero.ZeroMap;
Expand Down Expand Up @@ -60,15 +59,6 @@ public static ZeroMap newZeroMap() {
return new ZeroMapImpl();
}

/**
* Creates a new instance of {@link MsgPackArray} class.
*
* @return new instance of msgpack array
*/
public static MsgPackArray newMsgArray() {
return MsgPackArray.newInstance();
}

/**
* Creates a new instance of {@link MsgPackMap} class.
*
Expand Down
Loading

0 comments on commit 766ab47

Please sign in to comment.