completed switch to UDP featuring ingame chat support again
This commit is contained in:
parent
91bb936ebb
commit
4cc380a1ff
@ -105,34 +105,6 @@ public class DataMapper {
|
||||
return hlStatsMessages;
|
||||
}
|
||||
|
||||
public static String check_autismo_mysql() {
|
||||
String target = "";
|
||||
try (Connection l_cCon = DBCPDataSourceAutismo.getConnection()) {
|
||||
String l_sSQL = "SELECT chatmessage FROM unloze_css_autism_bot.chatting c WHERE c.responsemessage = '' LIMIT 1";
|
||||
try (PreparedStatement l_pStatement = l_cCon.prepareStatement(l_sSQL)) {
|
||||
try (ResultSet l_rsSearch = l_pStatement.executeQuery()) {
|
||||
while (l_rsSearch.next()) {
|
||||
target = l_rsSearch.getString(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
public static void update_autismo_mysql(String responseMsg, String update_string) {
|
||||
try (Connection l_cCon = DBCPDataSourceAutismo.getConnection()) {
|
||||
String l_sSQL = "UPDATE unloze_css_autism_bot.`chatting` SET `responsemessage` = '" + responseMsg + "' WHERE `chatmessage` = '" + update_string + "'";
|
||||
try (PreparedStatement l_pStatement = l_cCon.prepareStatement(l_sSQL)) {
|
||||
l_pStatement.execute();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CloseConnections(PreparedStatement ps, ResultSet rs, Connection con) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
|
@ -21,7 +21,12 @@ import edu.stanford.nlp.tagger.maxent.MaxentTagger;
|
||||
import edu.stanford.nlp.trees.GrammaticalStructureFactory;
|
||||
import edu.stanford.nlp.trees.TreebankLanguagePack;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import static java.lang.Math.random;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
@ -790,15 +795,30 @@ public class Datahandler {
|
||||
return stringCache.values().size() - (stringCache.values().size() / 10);
|
||||
}
|
||||
|
||||
public void update_autismo_mysql() {
|
||||
String update_string = DataMapper.check_autismo_mysql();
|
||||
if (!update_string.isEmpty()) {
|
||||
try {
|
||||
String getResponseMsg = getResponseMsg(update_string);
|
||||
DataMapper.update_autismo_mysql(getResponseMsg, update_string);
|
||||
public void update_autismo_socket_msg() {
|
||||
try {
|
||||
try (DatagramSocket serverSocket = new DatagramSocket(48477)) {
|
||||
byte[] receiveData = new byte[4096];
|
||||
InetAddress IPAddress = InetAddress.getByName("151.80.230.149");
|
||||
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
|
||||
while (true) {
|
||||
serverSocket.receive(receivePacket);
|
||||
String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength());
|
||||
sentence = sentence.replace("clientmessage:", "");
|
||||
String getResponseMsg = getResponseMsg(sentence);
|
||||
byte[] sendData = getResponseMsg.getBytes("UTF-8");
|
||||
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 48477);
|
||||
serverSocket.send(sendPacket);
|
||||
}
|
||||
} catch (CustomError ex) {
|
||||
Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
} catch (SocketException ex) {
|
||||
Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,17 +31,11 @@ import org.javacord.api.DiscordApiBuilder;
|
||||
* @author install1
|
||||
*/
|
||||
public class DiscordHandler {
|
||||
public static class update_autismo_ingame_msgs extends TimerTask {
|
||||
@Override
|
||||
public void run() {
|
||||
Datahandler.instance.update_autismo_mysql();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "15");
|
||||
try {
|
||||
Datahandler.instance.initiateMYSQL();
|
||||
//nohup screen -d -m -S nonroot java -Xmx6900M -jar /home/javatests/ArtificialAutism-1.0.jar
|
||||
//uncomment db fetch when ready, just keep the comment for future reference
|
||||
System.out.println("finished initiating MYSQL");
|
||||
} catch (SQLException | IOException ex) {
|
||||
@ -56,13 +50,13 @@ public class DiscordHandler {
|
||||
Datahandler.instance.updateStringCache();
|
||||
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||
Timer timer = new Timer();
|
||||
timer.scheduleAtFixedRate(new update_autismo_ingame_msgs(), 700, 700);
|
||||
new Thread(() -> {
|
||||
Datahandler.instance.update_autismo_socket_msg();
|
||||
}).start();
|
||||
api.addMessageCreateListener(event -> {
|
||||
if (!FunctionLayer.DoStuff.isOccupied()) {
|
||||
FunctionLayer.DoStuff.doStuff(event, api);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user