Compare commits

...

5 Commits
1.2.0 ... 1.2.1

Author SHA1 Message Date
Govindass
7849efd866 Little questionable improvements (shouldn't hurt anything anyway) 2020-10-24 17:59:48 +03:00
Govindass
f80d9b36e7 Make on redis message a synchronous event for thread-safety 2020-10-24 15:19:10 +03:00
Govindass
0c20becfa1 Merge branch 'master' of https://github.com/Limework/RediSkript 2020-10-24 14:33:12 +03:00
Govindass
089fdfd1f3 Update pom.xml 2020-10-24 14:32:55 +03:00
Govindas
c4426a692e Update README.md 2020-10-24 14:32:48 +03:00
5 changed files with 79 additions and 18 deletions

View File

@@ -1 +1,57 @@
**To-do List**
1. Fix memory leak of /reloadredis (Not yet known how to fix it, it can be easily noticed by changing IP addresses and using NetworkInterceptor plugin, it'll show connections still being done to old IP address, aswell as the new one, even if it doesn't use old IP address for anything.
RediSkript allows you to communicate between your servers with use of Redis, it's very fast and easy to use.
You can transfer any data in the form of text between your servers, you can program it to execute a set of instructions on the server depending on the redis message, etc. This can be used for making scripts that sync data between all servers and much more!
It is originally developed by the team of Govindas Limework developers and is now maintained only by Govindas.
Example:
```
on redis message:
if redis channel is "world":
broadcast "%redis message% %redis channel% %redis message date%"
command /sendredis <text> <text>:
usage: /sendredis <message> <channel>
trigger:
send redis message arg 1 to channel arg 2
send redis message "hello world!" to channel "world"
```
and that's all there is to this addon! You only need to have matching configuration in every server for communication and a Redis server to connect to. I recommend using VPS for hosting redis server, I personally use VPS from humbleservers.com.
Configuration:
```
Redis:
#a secure password that cannot be cracked, please change it!
#it is also recommended to firewall your redis server with iptables so it can only be accessed by specific IP addresses
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL9XMU"
Host: "127.0.0.1"
#must be 2 or higher, if you set to lower, the addon will automatically use 2 as a minimum
MaxConnections: 2
#the default Redis port
Port: 6379
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
#90000 = 90 seconds
TimeOut: 90000
#also known as SSL, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
#it encrypts your traffic and makes data exchange between distant servers completely secure
useTLS: false
#may be useful if you cannot use TLS due to use of older version of Redis
#however this will not encrypt the initial authentication password, only the messages sent
#it uses AES-128 SIV encryption which is secure enough for this
EncryptMessages: true
EncryptionKey: "16CHARACTERS KEY"
MacKey: "16CHARACTERS KEY"
#the channels from which this server can receive messages
#you can always send messages to all channels!
#you can add as many channels as you wish!
Channels:
- "Channel1"
- "Channel2"
- "Channel3"
```

View File

@@ -6,7 +6,7 @@
<groupId>net.limework.core</groupId> <groupId>net.limework.core</groupId>
<artifactId>RediSkript</artifactId> <artifactId>RediSkript</artifactId>
<version>1.1.2</version> <version>1.2.0</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>

View File

@@ -12,7 +12,7 @@ public class RedisMessageEvent extends Event {
private long date; private long date;
public RedisMessageEvent(String channelName , String message, long date) { public RedisMessageEvent(String channelName , String message, long date) {
super(true); super(false);
this.channelName = channelName; this.channelName = channelName;
this.message = message; this.message = message;
this.date = date; this.date = date;

View File

@@ -130,8 +130,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
JSONObject j = new JSONObject(receivedMessage); JSONObject j = new JSONObject(receivedMessage);
//System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString()); //System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString());
RedisMessageEvent event = new RedisMessageEvent(channelString, j.getString("Message"), j.getLong("Date")); RedisMessageEvent event = new RedisMessageEvent(channelString, j.getString("Message"), j.getLong("Date"));
Bukkit.getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(event));
plugin.getServer().getPluginManager().callEvent(event);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -146,6 +145,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
if (this.subscribeJedis != null) { if (this.subscribeJedis != null) {
this.unsubscribe(); this.unsubscribe();
this.subscribeJedis.close(); this.subscribeJedis.close();
this.subscribeJedis.getClient().close();
this.jedisPool.getResource().close(); this.jedisPool.getResource().close();
} }
this.RedisService.shutdown(); this.RedisService.shutdown();

View File

@@ -12,6 +12,7 @@ import org.bukkit.ChatColor;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.json.JSONObject; import org.json.JSONObject;
import redis.clients.jedis.BinaryJedis; import redis.clients.jedis.BinaryJedis;
import redis.clients.jedis.exceptions.JedisConnectionException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -42,33 +43,37 @@ public class EffSendMessage extends Effect {
return; return;
} }
assert plugin != null; assert plugin != null;
JSONObject json = new JSONObject();
json.put("Message", message);
json.put("Type", "Skript");
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
byte[] msg;
RedisManager manager = plugin.getRm(); RedisManager manager = plugin.getRm();
//manager.getRedisService().execute(() -> {
if (manager.getEncryption().isEncryptionEnabled()) {
msg = manager.getEncryption().encrypt(json.toString());
} else {
msg = json.toString().getBytes(StandardCharsets.UTF_8);
}
try {
BinaryJedis j = manager.getJedisPool().getResource(); BinaryJedis j = manager.getJedisPool().getResource();
JSONObject json = new JSONObject();
json.put("Message", message);
json.put("Type", "Skript");
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
byte[] msg;
if (manager.getEncryption().isEncryptionEnabled()) {
msg = manager.getEncryption().encrypt(json.toString());
} else {
msg = json.toString().getBytes(StandardCharsets.UTF_8);
}
j.publish(channel.getBytes(StandardCharsets.UTF_8), msg); j.publish(channel.getBytes(StandardCharsets.UTF_8), msg);
j.close(); j.close();
//}); } catch (JedisConnectionException exception) {
exception.printStackTrace();
}
} }
@Override @Override
public String toString(Event event, boolean b) { public String toString(Event event, boolean debug) {
return "send redis message " + message.getSingle(event) + " to channel " + channel.getSingle(event); return "send redis message " + message.getSingle(event) + " to channel " + channel.getSingle(event);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) { public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parser) {
this.message = (Expression<String>) expressions[0]; this.message = (Expression<String>) expressions[0];
this.channel = (Expression<String>) expressions[1]; this.channel = (Expression<String>) expressions[1];
return true; return true;