mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-22 00:01:32 +01:00
Changed SQL phone-home to connection with PHP front-end application
This commit is contained in:
parent
f68521c691
commit
8c31fabadc
2
pom.xml
2
pom.xml
@ -65,7 +65,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.herocraftonline</groupId>
|
<groupId>com.herocraftonline</groupId>
|
||||||
<artifactId>Heroes</artifactId>
|
<artifactId>Heroes</artifactId>
|
||||||
<version>1.5.4-SNAPSHOT</version>
|
<version>1.5.5</version>
|
||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${project.basedir}/lib/Heroes.jar</systemPath>
|
<systemPath>${project.basedir}/lib/Heroes.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -2,10 +2,6 @@ package me.blackvein.quests;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -84,6 +80,12 @@ import com.herocraftonline.heroes.characters.classes.HeroClass;
|
|||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
public class Quests extends JavaPlugin implements ConversationAbandonedListener, ColorUtil {
|
public class Quests extends JavaPlugin implements ConversationAbandonedListener, ColorUtil {
|
||||||
|
|
||||||
@ -4716,30 +4718,74 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void snoop() {
|
public void snoop() {
|
||||||
|
|
||||||
|
String ip = getServer().getIp().trim();
|
||||||
|
if (ip.isEmpty() || ip.startsWith("192") || ip.startsWith("localhost") || ip.startsWith("127") || ip.startsWith("0.0"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
snoop_delete();
|
||||||
|
snoop_insert();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void snoop_insert() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.jdbc.Driver").newInstance();
|
|
||||||
String url = "jdbc:mysql://173.234.237.34:3306/bigal_quests";
|
Date date = new Date(System.currentTimeMillis());
|
||||||
Connection conn = DriverManager.getConnection(url, "bigal_snooper", "merv41");
|
|
||||||
Statement statement = conn.createStatement();
|
|
||||||
java.sql.Date date = new java.sql.Date(System.currentTimeMillis());
|
|
||||||
Timestamp stamp = new Timestamp(date.getTime());
|
Timestamp stamp = new Timestamp(date.getTime());
|
||||||
statement.executeUpdate("DELETE FROM entries WHERE server='" + getServer().getIp() + ":" + ((Integer) getServer().getPort()).toString() + "'");
|
String arguments = "arg1=" + getServer().getIp()
|
||||||
String cit = citizens != null ? "true" : "false";
|
+ "&arg2=" + ((Integer) getServer().getPort()).toString()
|
||||||
String name = getServer().getServerName().replaceAll("'", "''").replaceAll("\"", "''");
|
+ "&arg3=" + URLEncoder.encode(getServer().getServerName().replaceAll("'", "''").replaceAll("\"", "''"), "UTF-8")
|
||||||
String motd = getServer().getMotd().replaceAll("'", "''").replaceAll("\"", "''");
|
+ "&arg4=" + URLEncoder.encode(getServer().getMotd().replaceAll("'", "''").replaceAll("\"", "''"), "UTF-8")
|
||||||
String ip = getServer().getIp().trim();
|
+ "&arg5=" + quests.size()
|
||||||
if (ip.isEmpty() || ip.startsWith("192") || ip.startsWith("localhost") || ip.startsWith("127") || ip.startsWith("0.0"))
|
+ "&arg6=" + (citizens != null ? "true" : "false")
|
||||||
return;
|
+ "&arg7=" + URLEncoder.encode(stamp.toString(), "UTF-8");
|
||||||
String port = ((Integer) getServer().getPort()).toString();
|
System.out.println("Arguments");
|
||||||
|
System.out.println(arguments);
|
||||||
|
URL url = new URL("http://www.bcitdnd.net/php/quests.php?" + arguments);
|
||||||
|
URLConnection yc = url.openConnection();
|
||||||
|
BufferedReader in = new BufferedReader(
|
||||||
|
new InputStreamReader(
|
||||||
|
yc.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
|
||||||
statement.executeUpdate("INSERT INTO entries VALUES ('" + ip + ":" + port + "', '" + name + "', '" + motd + "', " + quests.size() + ", '" + cit + "', '" + stamp.toString() + "')");
|
while ((inputLine = in.readLine()) != null) {
|
||||||
} catch (ClassNotFoundException e) {
|
if(inputLine.equalsIgnoreCase("false"))
|
||||||
} catch (IllegalAccessException e) {
|
printWarning("[Quests] An error occurred inserting data into the snooper database!");
|
||||||
} catch (InstantiationException e) {
|
}
|
||||||
} catch (SQLException e) {
|
in.close();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
printWarning("[Quests] An error occurred inserting data into the snooper database!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void snoop_delete() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
String arguments = "arg1=" + getServer().getIp() + "&arg2=" + ((Integer) getServer().getPort()).toString();
|
||||||
|
URL url = new URL("http://www.bcitdnd.net/php/quests_del.php?" + arguments);
|
||||||
|
System.out.println("Delete arguments");
|
||||||
|
System.out.println(arguments);
|
||||||
|
URLConnection yc = url.openConnection();
|
||||||
|
BufferedReader in = new BufferedReader(
|
||||||
|
new InputStreamReader(
|
||||||
|
yc.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
if(inputLine.equalsIgnoreCase("false"))
|
||||||
|
printWarning("[Quests] An error occurred removing old data from the snooper database!");
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
printWarning("[Quests] An error occurred removing old data from the snooper database!");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasQuest(NPC npc, Quester quester) {
|
public boolean hasQuest(NPC npc, Quester quester) {
|
||||||
|
Loading…
Reference in New Issue
Block a user