Commit 2dab37c616cd9abef6f1103b725d8f75dbcd59a7
1 parent
aecc5dcf
new log upload functionality to upload to liteloader.com
Showing
4 changed files
with
150 additions
and
29 deletions
java/client/com/mumfrey/liteloader/client/gui/GuiPanelLiteLoaderLog.java
... | ... | @@ -3,26 +3,19 @@ package com.mumfrey.liteloader.client.gui; |
3 | 3 | import static org.lwjgl.opengl.GL11.*; |
4 | 4 | |
5 | 5 | import java.net.URI; |
6 | -import java.text.DateFormat; | |
7 | 6 | import java.util.ArrayList; |
8 | -import java.util.Date; | |
9 | 7 | import java.util.List; |
10 | 8 | |
11 | -import org.lwjgl.input.Keyboard; | |
12 | - | |
13 | - | |
14 | - | |
15 | - | |
16 | - | |
17 | - | |
18 | - | |
19 | 9 | import net.minecraft.client.Minecraft; |
20 | 10 | import net.minecraft.client.gui.GuiButton; |
21 | 11 | import net.minecraft.client.gui.ScaledResolution; |
22 | 12 | import net.minecraft.client.resources.I18n; |
13 | +import net.minecraft.util.Session; | |
14 | + | |
15 | +import org.lwjgl.input.Keyboard; | |
23 | 16 | |
24 | 17 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
25 | -import com.mumfrey.liteloader.util.net.PastebinUpload; | |
18 | +import com.mumfrey.liteloader.util.net.LiteLoaderLogUpload; | |
26 | 19 | |
27 | 20 | /** |
28 | 21 | * |
... | ... | @@ -47,9 +40,9 @@ class GuiPanelLiteLoaderLog extends GuiPanel implements ScrollPanelContent |
47 | 40 | |
48 | 41 | private GuiButton btnUpload; |
49 | 42 | |
50 | - private PastebinUpload logUpload; | |
43 | + private LiteLoaderLogUpload logUpload; | |
51 | 44 | |
52 | - private String pasteBinURL; | |
45 | + private String logURL; | |
53 | 46 | |
54 | 47 | private int throb; |
55 | 48 | |
... | ... | @@ -140,19 +133,19 @@ class GuiPanelLiteLoaderLog extends GuiPanel implements ScrollPanelContent |
140 | 133 | |
141 | 134 | if (this.logUpload != null && this.logUpload.isCompleted()) |
142 | 135 | { |
143 | - this.pasteBinURL = this.logUpload.getPasteUrl().trim(); | |
136 | + this.logURL = this.logUpload.getLogUrl().trim(); | |
144 | 137 | this.logUpload = null; |
145 | 138 | |
146 | 139 | int xMid = this.width / 2; |
147 | - if (this.pasteBinURL.startsWith("http:")) | |
140 | + if (this.logURL.startsWith("http:")) | |
148 | 141 | { |
149 | - LiteLoaderLogger.info("Log file upload succeeded, url is %s", this.pasteBinURL); | |
150 | - int urlWidth = this.mc.fontRendererObj.getStringWidth(this.pasteBinURL); | |
151 | - this.controls.add(new GuiHoverLabel(3, xMid - (urlWidth / 2), this.height / 2, this.mc.fontRendererObj, "\247n" + this.pasteBinURL, this.parent.getBrandColour())); | |
142 | + LiteLoaderLogger.info("Log file upload succeeded, url is %s", this.logURL); | |
143 | + int urlWidth = this.mc.fontRendererObj.getStringWidth(this.logURL); | |
144 | + this.controls.add(new GuiHoverLabel(3, xMid - (urlWidth / 2), this.height / 2, this.mc.fontRendererObj, "\247n" + this.logURL, this.parent.getBrandColour())); | |
152 | 145 | } |
153 | 146 | else |
154 | 147 | { |
155 | - LiteLoaderLogger.info("Log file upload failed, reason is %s", this.pasteBinURL); | |
148 | + LiteLoaderLogger.info("Log file upload failed, reason is %s", this.logURL); | |
156 | 149 | } |
157 | 150 | |
158 | 151 | this.controls.add(new GuiButton(4, xMid - 40, this.height - BOTTOM - MARGIN - 24, 80, 20, I18n.format("gui.log.closedialog"))); |
... | ... | @@ -161,7 +154,7 @@ class GuiPanelLiteLoaderLog extends GuiPanel implements ScrollPanelContent |
161 | 154 | if (this.closeDialog) |
162 | 155 | { |
163 | 156 | this.closeDialog = false; |
164 | - this.pasteBinURL = null; | |
157 | + this.logURL = null; | |
165 | 158 | this.setSize(this.width, this.height); |
166 | 159 | } |
167 | 160 | } |
... | ... | @@ -188,7 +181,7 @@ class GuiPanelLiteLoaderLog extends GuiPanel implements ScrollPanelContent |
188 | 181 | int xMid = this.width / 2; |
189 | 182 | int yMid = this.height / 2; |
190 | 183 | |
191 | - if (this.logUpload != null || this.pasteBinURL != null) | |
184 | + if (this.logUpload != null || this.logURL != null) | |
192 | 185 | { |
193 | 186 | drawRect(MARGIN + MARGIN, TOP + MARGIN, this.width - MARGIN - MARGIN, this.height - BOTTOM - MARGIN, 0xC0000000); |
194 | 187 | |
... | ... | @@ -199,7 +192,7 @@ class GuiPanelLiteLoaderLog extends GuiPanel implements ScrollPanelContent |
199 | 192 | } |
200 | 193 | else |
201 | 194 | { |
202 | - if (this.pasteBinURL.startsWith("http:")) | |
195 | + if (this.logURL.startsWith("http:")) | |
203 | 196 | { |
204 | 197 | this.drawCenteredString(this.mc.fontRendererObj, I18n.format("gui.log.uploadsuccess"), xMid, yMid - 14, 0xFF55FF55); |
205 | 198 | } |
... | ... | @@ -286,9 +279,9 @@ class GuiPanelLiteLoaderLog extends GuiPanel implements ScrollPanelContent |
286 | 279 | this.updateLog(); |
287 | 280 | } |
288 | 281 | |
289 | - if (control.id == 3 && this.pasteBinURL != null) | |
282 | + if (control.id == 3 && this.logURL != null) | |
290 | 283 | { |
291 | - this.openURI(URI.create(this.pasteBinURL)); | |
284 | + this.openURI(URI.create(this.logURL)); | |
292 | 285 | } |
293 | 286 | |
294 | 287 | if (control.id == 4) |
... | ... | @@ -368,9 +361,9 @@ class GuiPanelLiteLoaderLog extends GuiPanel implements ScrollPanelContent |
368 | 361 | completeLog.append(logLine).append("\r\n"); |
369 | 362 | } |
370 | 363 | |
371 | - String pasteName = "LiteLoaderLog-" + DateFormat.getDateTimeInstance().format(new Date()); | |
372 | - LiteLoaderLogger.info("Uploading log file %s to pastebin...", pasteName); | |
373 | - this.logUpload = new PastebinUpload("LiteLoader", pasteName, completeLog.toString(), PastebinUpload.UNLISTED); | |
364 | + LiteLoaderLogger.info("Uploading log file to liteloader..."); | |
365 | + Session session = this.mc.getSession(); | |
366 | + this.logUpload = new LiteLoaderLogUpload(session.getUsername(), session.getPlayerID(), completeLog.toString()); | |
374 | 367 | this.logUpload.start(); |
375 | 368 | } |
376 | 369 | ... | ... |
java/common/com/mumfrey/liteloader/util/log/LiteLoaderLogger.java
... | ... | @@ -6,6 +6,7 @@ import java.io.StringWriter; |
6 | 6 | import java.util.ArrayList; |
7 | 7 | import java.util.LinkedList; |
8 | 8 | import java.util.List; |
9 | +import java.util.MissingFormatArgumentException; | |
9 | 10 | |
10 | 11 | import org.apache.logging.log4j.Level; |
11 | 12 | import org.apache.logging.log4j.LogManager; |
... | ... | @@ -130,7 +131,14 @@ public class LiteLoaderLogger extends AbstractAppender |
130 | 131 | |
131 | 132 | private static void log(Level level, String format, Object... data) |
132 | 133 | { |
133 | - LiteLoaderLogger.logger.log(level, String.format(format, data)); | |
134 | + try | |
135 | + { | |
136 | + LiteLoaderLogger.logger.log(level, String.format(format, data)); | |
137 | + } | |
138 | + catch (MissingFormatArgumentException ex) | |
139 | + { | |
140 | + LiteLoaderLogger.logger.log(level, format.replace('%', '@')); | |
141 | + } | |
134 | 142 | } |
135 | 143 | |
136 | 144 | private static void log(Level level, Throwable th, String format, Object... data) | ... | ... |
java/common/com/mumfrey/liteloader/util/net/LiteLoaderLogUpload.java
0 โ 100644
1 | +package com.mumfrey.liteloader.util.net; | |
2 | + | |
3 | +import java.io.BufferedReader; | |
4 | +import java.io.DataOutputStream; | |
5 | +import java.io.IOException; | |
6 | +import java.io.InputStream; | |
7 | +import java.io.InputStreamReader; | |
8 | +import java.io.UnsupportedEncodingException; | |
9 | +import java.net.HttpURLConnection; | |
10 | +import java.net.URL; | |
11 | +import java.net.URLEncoder; | |
12 | +import java.util.HashMap; | |
13 | +import java.util.Map; | |
14 | +import java.util.Map.Entry; | |
15 | + | |
16 | +import com.mumfrey.liteloader.util.log.LiteLoaderLogger; | |
17 | + | |
18 | +/** | |
19 | + * Upload manager for posting logs to liteloader.com | |
20 | + * | |
21 | + * @author Adam Mummery-Smith | |
22 | + */ | |
23 | +public class LiteLoaderLogUpload extends Thread | |
24 | +{ | |
25 | + private static final String POST_URL = "http://logs.liteloader.com/post"; | |
26 | + | |
27 | + private static final String LITELOADER_KEY = "liteloader0cea4593b6a51e7c"; | |
28 | + | |
29 | + private final String encodedData; | |
30 | + | |
31 | + private volatile boolean completed; | |
32 | + | |
33 | + private String response = "Unknown Error"; | |
34 | + | |
35 | + public LiteLoaderLogUpload(String nick, String uuid, String content) | |
36 | + { | |
37 | + Map<String, String> data = new HashMap<String, String>(); | |
38 | + | |
39 | + data.put("nick", nick); | |
40 | + data.put("uuid", uuid); | |
41 | + data.put("token", LITELOADER_KEY); | |
42 | + data.put("log", content); | |
43 | + | |
44 | + StringBuilder sb = new StringBuilder(); | |
45 | + | |
46 | + try | |
47 | + { | |
48 | + String separator = ""; | |
49 | + for (Entry<String, String> postValue : data.entrySet()) | |
50 | + { | |
51 | + sb.append(separator).append(postValue.getKey()).append("=").append(URLEncoder.encode(postValue.getValue(), "UTF-8")); | |
52 | + separator = "&"; | |
53 | + } | |
54 | + } | |
55 | + catch (UnsupportedEncodingException ex) | |
56 | + { | |
57 | + ex.printStackTrace(); | |
58 | + } | |
59 | + | |
60 | + this.encodedData = sb.toString(); | |
61 | + } | |
62 | + | |
63 | + public boolean isCompleted() | |
64 | + { | |
65 | + return this.completed; | |
66 | + } | |
67 | + | |
68 | + public String getLogUrl() | |
69 | + { | |
70 | + return this.response; | |
71 | + } | |
72 | + | |
73 | + @Override | |
74 | + public void run() | |
75 | + { | |
76 | + try | |
77 | + { | |
78 | + URL url = new URL(POST_URL); | |
79 | + HttpURLConnection httpClient = (HttpURLConnection)url.openConnection(); | |
80 | + httpClient.setConnectTimeout(5000); | |
81 | + httpClient.setReadTimeout(10000); | |
82 | + httpClient.addRequestProperty("Content-type", "application/x-www-form-urlencoded"); | |
83 | + httpClient.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); // For not fail++ | |
84 | + httpClient.setRequestMethod("POST"); | |
85 | + httpClient.setDoOutput(true); | |
86 | + | |
87 | + DataOutputStream outputStream = new DataOutputStream(httpClient.getOutputStream()); | |
88 | + outputStream.writeBytes(this.encodedData); | |
89 | + outputStream.flush(); | |
90 | + | |
91 | + InputStream httpStream = httpClient.getInputStream(); | |
92 | + | |
93 | + try | |
94 | + { | |
95 | + StringBuilder readString = new StringBuilder(); | |
96 | + BufferedReader reader = new BufferedReader(new InputStreamReader(httpStream)); | |
97 | + | |
98 | + String readLine; | |
99 | + while ((readLine = reader.readLine()) != null) | |
100 | + { | |
101 | + readString.append(readLine).append("\n"); | |
102 | + } | |
103 | + | |
104 | + reader.close(); | |
105 | + this.response = readString.toString(); | |
106 | + } | |
107 | + catch (IOException ex) { ex.printStackTrace(); } | |
108 | + | |
109 | + httpStream.close(); | |
110 | + outputStream.close(); | |
111 | + } | |
112 | + catch (Exception ex) | |
113 | + { | |
114 | + this.response = ex.getMessage(); | |
115 | + LiteLoaderLogger.warning("Error posting log to liteloader.com: %s: %s", ex.getClass(), ex.getMessage()); | |
116 | + } | |
117 | + | |
118 | + this.completed = true; | |
119 | + } | |
120 | +} | |
0 | 121 | \ No newline at end of file | ... | ... |
resources/assets/liteloader/lang/en_US.lang
... | ... | @@ -63,7 +63,7 @@ gui.log.button=LiteLoader Log |
63 | 63 | gui.log.title=LiteLoader Log Viewer |
64 | 64 | gui.log.scalecheckbox=Use native resolution |
65 | 65 | gui.log.postlog=Upload Log |
66 | -gui.log.uploading=Uploading log to pastebin... | |
66 | +gui.log.uploading=Uploading log please wait... | |
67 | 67 | gui.log.uploadfailed=Upload failed |
68 | 68 | gui.log.uploadsuccess=Upload succeeded, log available at |
69 | 69 | gui.log.closedialog=Close | ... | ... |