Created
May 24, 2012 06:48
-
-
Save md-5/2779868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.raphfrk.craftproxylitest; | |
import com.google.gson.Gson; | |
import static com.raphfrk.craftproxylitest.LogManager.$; | |
import java.io.InputStreamReader; | |
import java.io.OutputStreamWriter; | |
import java.io.Reader; | |
import java.io.Writer; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import java.net.URLEncoder; | |
import lombok.Data; | |
public class MCBansLookup { | |
private static final Gson gson = new Gson(); | |
public static String exec(String username, String IP) { | |
String resp = null; | |
try { | |
Ban ban = request("player=" + URLEncoder.encode(username, "UTF-8") | |
+ "&playerip=" + URLEncoder.encode(IP, "UTF-8") + "&exec=playerConnect"); | |
switch (ConnectStatus.valueOf(ban.getBanStatus().toUpperCase())) { | |
case G: | |
case L: | |
case S: | |
case I: | |
case T: | |
resp = ban.getBanReason(); | |
break; | |
case B: | |
float rep = Float.parseFloat(ban.getPlayerRep()); | |
if (rep <= 0) { | |
resp = ban.getBanReason(); | |
} else if (rep < Globals.minRep) { | |
resp = "Your reputation is below this servers threshold!"; | |
} | |
break; | |
} | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
} | |
if (resp != null) { | |
$().info(username + " is banned and cannot connect!"); | |
} | |
return resp; | |
} | |
public static Ban request(String data) throws Exception { | |
URLConnection conn = new URL("http://72.10.39.172/v2/" + Globals.mcbansKey).openConnection(); | |
conn.setConnectTimeout(5000); | |
conn.setReadTimeout(5000); | |
conn.setDoOutput(true); | |
Writer wr = new OutputStreamWriter(conn.getOutputStream()); | |
wr.write(data); | |
wr.flush(); | |
wr.close(); | |
Reader rd = new InputStreamReader(conn.getInputStream()); | |
Ban ban = gson.fromJson(rd, Ban.class); | |
rd.close(); | |
return ban; | |
} | |
private enum ConnectStatus { | |
N, G, S, T, L, B, I | |
} | |
@Data | |
public class Ban { | |
private String banStatus; | |
private String playerRep; | |
private String altList; | |
private String banReason; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment