public string DownloadString(Uri u) { var w = new StringBuilder(); try { var url = new java.net.URL(u.ToString()); var i = new java.io.InputStreamReader(url.openStream(), "UTF-8"); var reader = new java.io.BufferedReader(i); // can't we just read to the end? var line = reader.readLine(); while (line != null) { w.AppendLine(line); line = reader.readLine(); } reader.close(); } catch { // oops } return(w.ToString()); }
public override void run() { try { string s = NetLoginHandler.getServerId(loginHandler); var url = new URL( (new StringBuilder()).append("http://www.minecraft.net/game/checkserver.jsp?user="******"&serverId=").append(s).toString()); var bufferedreader = new BufferedReader(new InputStreamReader(url.openStream())); string s1 = bufferedreader.readLine(); bufferedreader.close(); if (s1.Equals("YES")) { NetLoginHandler.setLoginPacket(loginHandler, loginPacket); } else { loginHandler.kickUser("Failed to verify username!"); } } catch (Exception exception) { exception.printStackTrace(); } }
public static string ToWebString(this Uri u) { var w = new StringBuilder(); try { var url = new URL(u.ToString()); var i = new InputStreamReader(url.openStream()); var reader = new BufferedReader(i); var line = reader.readLine(); while (line != null) { w.AppendLine(line); line = reader.readLine(); } reader.close(); } catch { // oops } return w.ToString(); }
public string UploadString(Uri u, string method, string data) { var w = new StringBuilder(); HttpURLConnection conn = null; try { var url = new java.net.URL(u.ToString()); conn = (HttpURLConnection)url.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); conn.setInstanceFollowRedirects(false); conn.setRequestMethod(method); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("charset", "utf-8"); conn.setRequestProperty("content-length", "" + data.Length); conn.setUseCaches(false); try { if (Headers != null) { foreach (string key in Headers.AllKeys) { conn.addRequestProperty(key, Headers[key]); } } } catch (Exception e) { //System.Console.WriteLine("ERROR: Failed to write headers. Exception was:" + e.Message); } DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(data); wr.flush(); wr.close(); //var i = new java.io.InputStreamReader(url.openStream(), "UTF-8"); var i = new java.io.InputStreamReader(conn.getInputStream(), "UTF-8"); var reader = new java.io.BufferedReader(i); // can't we just read to the end? var line = reader.readLine(); while (line != null) { w.AppendLine(line); line = reader.readLine(); } reader.close(); } catch { // oops } if (conn != null) { conn.disconnect(); } return(w.ToString()); }
public string UploadString(Uri u, string method, string data) { // http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/tip/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java // fails on openJDK why? Console.WriteLine("enter UploadString " + new { u, method }); var w = new StringBuilder(); HttpURLConnection xHttpURLConnection = null; try { #region NSA is that you? intercept? we can only trust pinned off device certs var trustAllCerts = new[] { new localX509TrustManager { } }; SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(new localHostnameVerifier { }); #endregion //UploadString getOutputStream //enter checkServerTrusted //enter getAcceptedIssuers //UploadString writeBytes var url = new java.net.URL(u.ToString()); xHttpURLConnection = (HttpURLConnection)url.openConnection(); var https = xHttpURLConnection as HttpsURLConnection; if (https != null) { //Console.WriteLine(new { https }); } //conn.setHostnameVerifier(new localHostnameVerifier { }); xHttpURLConnection.setDoOutput(true); xHttpURLConnection.setDoInput(true); xHttpURLConnection.setInstanceFollowRedirects(false); //conn.setInstanceFollowRedirects(true); xHttpURLConnection.setRequestMethod(method); var xContentType = default(string); try { if (Headers != null) { foreach (string key in Headers.AllKeys) { if (key == "Content-Type") { xContentType = Headers[key]; } xHttpURLConnection.addRequestProperty(key, Headers[key]); } } } catch (Exception e) { //System.Console.WriteLine("ERROR: Failed to write headers. Exception was:" + e.Message); } if (xContentType == null) { xHttpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); xHttpURLConnection.setRequestProperty("charset", "utf-8"); } //conn.setRequestProperty("content-length", "" + data.Length); xHttpURLConnection.setRequestProperty("Content-Length", "" + data.Length); xHttpURLConnection.setUseCaches(false); //Console.WriteLine("UploadString getOutputStream"); var o = xHttpURLConnection.getOutputStream(); //Console.WriteLine("UploadString writeBytes"); // DataOutputStream wr = new DataOutputStream(o); wr.writeBytes(data); //Console.WriteLine("UploadString flush"); wr.flush(); //Console.WriteLine("UploadString close"); wr.close(); //Console.WriteLine("UploadString readLine"); //var i = new java.io.InputStreamReader(url.openStream(), "UTF-8"); var i = new java.io.InputStreamReader(xHttpURLConnection.getInputStream(), "UTF-8"); var reader = new java.io.BufferedReader(i); // can't we just read to the end? var line = reader.readLine(); while (line != null) { w.AppendLine(line); line = reader.readLine(); } reader.close(); } catch (Exception err) { // 500 ? // = java.net.ProtocolException: Invalid HTTP method: // oops Console.WriteLine("UploadString " + new { err }); } //Console.WriteLine("exit UploadString " + new { conn }); if (xHttpURLConnection != null) { xHttpURLConnection.disconnect(); } return(w.ToString()); }
public string UploadString(Uri u, string method, string data) { // http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/tip/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java // fails on openJDK why? Console.WriteLine("enter UploadString " + new { u, method }); var w = new StringBuilder(); HttpURLConnection xHttpURLConnection = null; try { #region NSA is that you? intercept? we can only trust pinned off device certs var trustAllCerts = new[] { new localX509TrustManager{} }; SSLContext sc = SSLContext.getInstance("SSL"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(new localHostnameVerifier { }); #endregion //UploadString getOutputStream //enter checkServerTrusted //enter getAcceptedIssuers //UploadString writeBytes var url = new java.net.URL(u.ToString()); xHttpURLConnection = (HttpURLConnection)url.openConnection(); var https = xHttpURLConnection as HttpsURLConnection; if (https != null) { //Console.WriteLine(new { https }); } //conn.setHostnameVerifier(new localHostnameVerifier { }); xHttpURLConnection.setDoOutput(true); xHttpURLConnection.setDoInput(true); xHttpURLConnection.setInstanceFollowRedirects(false); //conn.setInstanceFollowRedirects(true); xHttpURLConnection.setRequestMethod(method); var xContentType = default(string); try { if (Headers != null) { foreach (string key in Headers.AllKeys) { if (key == "Content-Type") { xContentType = Headers[key]; } xHttpURLConnection.addRequestProperty(key, Headers[key]); } } } catch (Exception e) { //System.Console.WriteLine("ERROR: Failed to write headers. Exception was:" + e.Message); } if (xContentType == null) { xHttpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); xHttpURLConnection.setRequestProperty("charset", "utf-8"); } //conn.setRequestProperty("content-length", "" + data.Length); xHttpURLConnection.setRequestProperty("Content-Length", "" + data.Length); xHttpURLConnection.setUseCaches(false); //Console.WriteLine("UploadString getOutputStream"); var o = xHttpURLConnection.getOutputStream(); //Console.WriteLine("UploadString writeBytes"); // DataOutputStream wr = new DataOutputStream(o); wr.writeBytes(data); //Console.WriteLine("UploadString flush"); wr.flush(); //Console.WriteLine("UploadString close"); wr.close(); //Console.WriteLine("UploadString readLine"); //var i = new java.io.InputStreamReader(url.openStream(), "UTF-8"); var i = new java.io.InputStreamReader(xHttpURLConnection.getInputStream(), "UTF-8"); var reader = new java.io.BufferedReader(i); // can't we just read to the end? var line = reader.readLine(); while (line != null) { w.AppendLine(line); line = reader.readLine(); } reader.close(); } catch (Exception err) { // 500 ? // = java.net.ProtocolException: Invalid HTTP method: // oops Console.WriteLine("UploadString " + new { err }); } //Console.WriteLine("exit UploadString " + new { conn }); if (xHttpURLConnection != null) xHttpURLConnection.disconnect(); return w.ToString(); }
public string DownloadString(Uri u) { var w = new StringBuilder(); try { var url = new java.net.URL(u.ToString()); var i = new java.io.InputStreamReader(url.openStream(), "UTF-8"); var reader = new java.io.BufferedReader(i); // can't we just read to the end? var line = reader.readLine(); while (line != null) { w.AppendLine(line); line = reader.readLine(); } reader.close(); } catch { // oops } return w.ToString(); }
private void readBannedPlayers() { try { bannedPlayers.clear(); var bufferedreader = new BufferedReader(new FileReader(bannedPlayersFile)); for (string s = ""; (s = bufferedreader.readLine()) != null;) { bannedPlayers.add(s.Trim().ToLower()); } bufferedreader.close(); } catch (Exception exception) { logger.warning((new StringBuilder()).append("Failed to load ban list: ").append(exception).toString()); } }
private void loadWhiteList() { try { whiteListedIPs.clear(); var bufferedreader = new BufferedReader(new FileReader(whitelistPlayersFile)); for (string s = ""; (s = bufferedreader.readLine()) != null;) { whiteListedIPs.add(s.Trim().ToLower()); } bufferedreader.close(); } catch (Exception exception) { logger.warning((new StringBuilder()).append("Failed to load white-list: ").append(exception).toString()); } }
protected override void onCreate(Bundle savedInstanceState) { base.onCreate(savedInstanceState); height = getWindowManager().getDefaultDisplay().getHeight(); width = getWindowManager().getDefaultDisplay().getWidth(); this.ToFullscreen(); if (width > height) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // http://stackoverflow.com/questions/8469112/hide-ics-back-home-task-switcher-buttons // http://developer.android.com/reference/android/view/View.OnSystemUiVisibilityChangeListener.html // http://stackoverflow.com/questions/9131790/android-lights-out-mode-not-working // http://baroqueworksdev.blogspot.com/2012/02/request-that-visibility-of.html } var r = new System.Random(); var port = r.Next(1024, 32000); uri = "http://" + getLocalIpAddress(); uri += ":"; uri += ((object)(port)).ToString(); this.setTitle(uri); ServerSocket serversocket = null; bool isRunning = true; #region openFileFromAssets Func<string, InputStream> openFileFromAssets = (string spath) => { InputStream value = null; try { value = this.getResources().getAssets().open(spath); } catch { } return value; }; #endregion #region getStringFromInput Func<BufferedReader, string> getStringFromInput = (BufferedReader input) => { StringBuilder sb = new StringBuilder(); string sTemp; try { sTemp = input.readLine(); while (!(sTemp == "")) { sb.append(sTemp + "\n"); sTemp = input.readLine(); } } catch { sb = new StringBuilder(); } return sb.ToString(); }; #endregion #region AtConnection Action<Socket> AtConnection = (clientsocket) => { BufferedReader input = null; OutputStream output = null; try { input = new BufferedReader(new InputStreamReader(clientsocket.getInputStream(), "ISO-8859-2")); output = clientsocket.getOutputStream(); } catch { } #region send_text Action<string> send_text = (s) => { string header = "HTTP/1.1 200 OK\n" + "Connection: close\n" + "Content-type: text/html; charset=utf-8\n"; //"Content-Length: " + s.Length + "\n" + header += "\n"; var w = new OutputStreamWriter(output); try { w.write(header + s); w.flush(); } catch { } }; #endregion #region send_stream Action<InputStream, string> send_stream = (fis, contenttype) => { string header = "HTTP/1.1 200 OK\n"; header += "Expires: Sun, 17 Jan 2038 19:14:07 GMT\n"; header += "Content-type: "; header += contenttype; header += "\n"; //header += "Content-Length: " + fis.available() + "\n" + header += "\n"; try { var w = new OutputStreamWriter(output); w.write(header); w.flush(); sbyte[] buffer = new sbyte[0x10000]; int bytes = 0; bytes = fis.read(buffer); while (bytes != -1) { output.write(buffer, 0, bytes); bytes = fis.read(buffer); } } catch { } }; #endregion new System.Threading.Thread( delegate() { try { string sAll = getStringFromInput(input); var i0 = sAll.IndexOf(" ", 0); var i1 = sAll.IndexOf(" ", i0 + 1); var path = sAll.Substring(i0, i1 - i0); path = path.Replace("%20", " "); if (path.Length > 0) path = path.Substring(2); if (path.Length > 1) { var last = path.Substring(path.Length - 1); if (last == "/") { path = path.Substring(0, path.Length - 1); } } if (this.width > this.height) if (path == "") path = this.ApplicationFile; var asset = openFileFromAssets(path); if (asset != null) { var _get = path; _get += " size: "; _get += ((object)asset.available()).ToString(); Log.i("jsc get", _get); if (path.EndsWith(".gif")) send_stream(asset, "image/gif"); if (path.EndsWith(".htm")) send_stream(asset, "text/html"); else send_stream(asset, "application/octet-stream"); } else { string firstpage = "<body style='padding: 0; margin: 0;'>"; #region AttachQRToElement Action<string, string> AttachQRToElement = (itemuri, Container) => { firstpage += "<script>"; firstpage += "\n"; firstpage += "var i = document.getElementById('"; firstpage += Container; firstpage += "').appendChild( qr.image("; firstpage += "\n"; firstpage += "{value:'"; firstpage += itemuri; firstpage += "'}"; firstpage += "\n"; firstpage += "));"; firstpage += "\n"; firstpage += "</script>"; }; #endregion #region firstpage firstpage += "<script src='/qr.js'></script>"; firstpage += "<center>"; firstpage += "<div style='background-color: black; color: white; padding: 2em;'>"; firstpage += "« Rotate your device to left to <b>launch</b>"; firstpage += "</div>"; firstpage += "<h1>"; firstpage += path; firstpage += "</h1>"; firstpage += "<div id='newdevice'>"; firstpage += "</div>"; AttachQRToElement(this.uri, "newdevice"); firstpage += "<br />"; var ApplicationFileLink = this.uri; ApplicationFileLink += "/"; ApplicationFileLink += this.ApplicationFile; firstpage += "<a"; firstpage += " href='"; firstpage += ApplicationFileLink; firstpage += "' id='ApplicationFile"; firstpage += "'"; firstpage += ">"; firstpage += "<div>"; firstpage += "Connect any other device on the same network to"; firstpage += "</div>"; firstpage += "\n"; firstpage += "<div>"; firstpage += "<code>"; firstpage += this.uri; firstpage += "</code>"; firstpage += "</div>"; firstpage += "</a>"; firstpage += "\n"; firstpage += "<div style='padding: 1em; margin: 0; overflow: hidden;'>"; //ScriptCoreLib.JavaScript.DOM.IStyle.OverflowEnum.hidden var assets = this.getResources().getAssets(); var collection = assets.list(path); var index = 0; #region AtItem Action<string> AtItem = item => { index++; if (!item.Contains(".")) { item += "/"; } firstpage += "<div style='border-top: 0.3em solid black; padding: 1em; '>"; firstpage += "<a"; firstpage += " href='"; firstpage += item; firstpage += "' id='item"; firstpage += ((object)index).ToString(); firstpage += "'"; firstpage += ">"; var path_preview = "assets.preview/"; path_preview += item; path_preview += ".png"; var asset_preview = openFileFromAssets(path_preview); if (asset_preview != null) { firstpage += "<div>"; firstpage += "<img src='"; firstpage += path_preview; firstpage += "' />"; firstpage += "</div>"; } firstpage += "<div>"; firstpage += item; firstpage += "</div>"; firstpage += "\n"; #region WithImage var WithImage = item.EndsWith(".gif"); WithImage |= item.EndsWith(".png"); if (WithImage) { firstpage += "<div>"; firstpage += "<img src='"; firstpage += item; firstpage += "' />"; firstpage += "</div>"; } #endregion firstpage += "</a>"; firstpage += "</div>"; #region WithQR var WithQR = item.EndsWith( ".apk"); if (WithQR) { var ContainerID = "item"; ContainerID += ((object)index).ToString(); var itemuri = this.uri + "/"; itemuri += item; AttachQRToElement(itemuri, ContainerID); } #endregion firstpage += "\n"; }; #endregion foreach (var xitem in collection) { AtItem(xitem); } firstpage += "</center>"; firstpage += "<pre>"; firstpage += sAll; firstpage += "</pre>"; firstpage += "</div>"; firstpage += "</body>"; send_text(firstpage); #endregion } input.close(); output.close(); } catch { } } ).Start(); }; #endregion #region serverThread var serverThread = new System.Threading.Thread( delegate() { try { serversocket = new ServerSocket(port); serversocket.setReuseAddress(true); while (isRunning) { var clientsocket = serversocket.accept(); AtConnection(clientsocket); } } catch { } } ); serverThread.Start(); #endregion #region AtDestroy AtDestroy = delegate { try { if (serversocket != null) serversocket.close(); } catch { } }; #endregion // http://stackoverflow.com/questions/8955228/webview-with-an-iframe-android // http://www.chrisdanielson.com/tag/webviewclient/ this.alertDialog = new AlertDialog.Builder(this).create(); this.progressBar = ProgressDialog.show(this, "Get ready!", "Almost there..." ); #region webview this.webview = new WebView(this); setContentView(webview); webview.getSettings().setBuiltInZoomControls(true); webview.getSettings().setSupportZoom(true); webview.getSettings().setLoadsImagesAutomatically(true); webview.getSettings().setJavaScriptEnabled(true); webview.setInitialScale(ApplicationScale); webview.setWebViewClient(new MyWebViewClient { __this = this }); webview.getSettings().setSupportZoom(false); webview.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY); //webview.getSettings().setJavaScriptEnabled(true); // no flash in emulator? // works on my phone! // no Flash since android 4.1.0!!! //webview.getSettings().setPluginsEnabled(true); //webview.getSettings().setPluginState(android.webkit.WebSettings.PluginState.ON); // OR, you can also load from an HTML string: //var summary = "<html><body>You scored <b>192</b> points.</body></html>"; //webview.loadData(summary, "text/html", null); //Log.i(TAG, "loadUrl"); webview.loadUrl(uri); #endregion }
public void run() { try { serversocket = new ServerSocket(port); serversocket.setReuseAddress(true); while (isRunning) { clientsocket = serversocket.accept(); input = new BufferedReader(new InputStreamReader(clientsocket.getInputStream(), "ISO-8859-2")); output = clientsocket.getOutputStream(); string sAll = getStringFromInput(input); var i0 = sAll.IndexOf(" ", 0); var i1 = sAll.IndexOf(" ", i0 + 1); var path = ((java.lang.String)(object)sAll).substring(i0, i1); if (path.Length > 0) path = ((java.lang.String)(object)path).substring(2, path.Length); var asset = openFileFromAssets(path, mycontext); if (asset != null) { send(asset); } else { #region firstpage string firstpage = "<body>"; firstpage += "<link rel=\"stylesheet\" type=\"text/css\" "; firstpage += "href=\"/foo.css\" />"; firstpage += "<h1>"; firstpage += path; firstpage += "</h1>"; firstpage += "<pre>"; firstpage += sAll; firstpage += "</pre>"; firstpage += "First page! jsc! <a href='/foo.htm'>Next</a>"; firstpage += "Other page! jsc! <a href='/bar.htm'>Other</a>"; var assets = mycontext.getResources().getAssets(); var collection = assets.list(path); foreach (var item in collection) { firstpage += "<pre>"; firstpage += item; firstpage += "</pre>"; firstpage += "<hr />"; } firstpage += "</body>"; send(firstpage); #endregion } input.close(); output.close(); } } catch { } }