Skip to content
Snippets Groups Projects
Commit 6202fc07 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Problème éclairci et suppresion du champs ip.

parent 692abb22
Branches
Tags
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>PAPER</platformType>
<platformType>ADVENTURE</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
</module>
\ No newline at end of file
...@@ -3,7 +3,6 @@ package com.slprojects.slcraftplugin.tachesParalleles; ...@@ -3,7 +3,6 @@ package com.slprojects.slcraftplugin.tachesParalleles;
import com.slprojects.slcraftplugin.Main; import com.slprojects.slcraftplugin.Main;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
...@@ -27,13 +26,15 @@ public class internalWebServer { ...@@ -27,13 +26,15 @@ public class internalWebServer {
while (true) { while (true) {
Socket client = serverSocket.accept(); Socket client = serverSocket.accept();
//plugin.getServer().getConsoleSender().sendMessage("Nouvelle connexion sur le port " + ChatColor.GOLD + serverPort);
// Get input and output streams to talk to the client // Get input and output streams to talk to the client
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
PrintWriter out = new PrintWriter(client.getOutputStream()); PrintWriter out = new PrintWriter(client.getOutputStream());
// Start sending our reply, using the HTTP 1.1 protocol // Start sending our reply, using the HTTP 1.1 protocol
out.print("HTTP/1.1 200 \r\n"); // Version & status code out.print("HTTP/1.1 200 \r\n"); // Version & status code
out.print("Content-Type: text/plain\r\n"); // The type of data out.print("Content-Type: application/json\r\n"); // The type of data
out.print("Connection: close\r\n"); // Will close stream out.print("Connection: close\r\n"); // Will close stream
out.print("\r\n"); // End of headers out.print("\r\n"); // End of headers
...@@ -64,6 +65,7 @@ public class internalWebServer { ...@@ -64,6 +65,7 @@ public class internalWebServer {
// On récupère le nom de la commande // On récupère le nom de la commande
String commandName = split2[1]; String commandName = split2[1];
JSONObject answer = new JSONObject();
switch (commandName) { switch (commandName) {
case "discordMsg": case "discordMsg":
JSONObject json = (JSONObject) new JSONParser().parse(URLDecoder.decode(split2[2], "UTF-8")); JSONObject json = (JSONObject) new JSONParser().parse(URLDecoder.decode(split2[2], "UTF-8"));
...@@ -75,20 +77,33 @@ public class internalWebServer { ...@@ -75,20 +77,33 @@ public class internalWebServer {
p.sendMessage(ChatColor.DARK_PURPLE + playerName + ChatColor.WHITE + ": " + message); p.sendMessage(ChatColor.DARK_PURPLE + playerName + ChatColor.WHITE + ": " + message);
} }
plugin.getServer().getConsoleSender().sendMessage(ChatColor.DARK_PURPLE + playerName + ": " + message); plugin.getServer().getConsoleSender().sendMessage(ChatColor.DARK_PURPLE + playerName + ": " + message);
out.print("Message envoyé !"); answer.put("status", "ok");
out.print(answer.toJSONString());
break; break;
case "getPlayers": case "getPlayers":
plugin.getServer().getConsoleSender().sendMessage("getPlayers");
// On renvoie la liste des joueurs // On renvoie la liste des joueurs
JSONObject listToReturn = new JSONObject(); JSONObject listToReturn = new JSONObject();
JSONArray players = new JSONArray(); JSONObject players = new JSONObject();
// On vérifie qu'il y a des joueurs -> pas vraiment utile vu que le timeout ne viens pas d'ici
//TODO: Corriger le timeout et supprimer la condition
if( plugin.getServer().getOnlinePlayers().size() > 0 ) {
for (Player p : plugin.getServer().getOnlinePlayers()) { for (Player p : plugin.getServer().getOnlinePlayers()) {
players.add(p.getName()); JSONObject playerInfos = new JSONObject();
playerInfos.put("username", p.getName());
playerInfos.put("uuid", p.getUniqueId().toString());
players.put(p.getName(), playerInfos);
}
} }
listToReturn.put("players", players); listToReturn.put("players", players);
out.print(listToReturn.toJSONString()); out.print(listToReturn.toJSONString());
break; break;
default: default:
out.print("La commande \"" + commandName + "\" n'est pas reconnue.\r\n"); answer.put("status", "error");
answer.put("message", "Commande "+commandName+" inconnue");
out.print(answer.toJSONString());
break; break;
} }
} }
......
#Generated by Maven #Generated by Maven
#Thu Apr 07 19:00:13 CEST 2022 #Mon May 02 23:05:52 CEST 2022
artifactId=SLCraftPlugin
groupId=com.slprojects groupId=com.slprojects
artifactId=SLCraftPlugin
version=1.6.0 version=1.6.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment