From b48b014121d6d9f26a71ce5e67b6cfa5d8df6f94 Mon Sep 17 00:00:00 2001 From: Zidonuke Ghost Date: Sat, 28 Dec 2013 23:35:56 -0500 Subject: [PATCH] Fix callback --- StarryboundServer.cs | 50 ++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/StarryboundServer.cs b/StarryboundServer.cs index 32c059f..da9b945 100644 --- a/StarryboundServer.cs +++ b/StarryboundServer.cs @@ -193,7 +193,8 @@ static void Main(string[] args) serverState = ServerState.Running; //Keep this last! - runCallback(); + if (config.enableCallback) + runCallback(); } public static void crashMonitor() @@ -394,33 +395,28 @@ public static void runCallback() { while (true) { - if (config.enableCallback) + logInfo("Sending callback data to master server."); + try { - logInfo("Sending callback data to master server."); - - try - { - var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://callback.avilance.com/"); - httpWebRequest.ContentType = "application/x-www-form-urlencoded"; - httpWebRequest.Method = "POST"; - - using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) - { - string json = "json={\"version\":\"" + VersionNum + "\"," + - "\"protocol\":\"" + ProtocolVersion + "\"," + - "\"mono\":\"" + IsMono + "\"," + - "\"proxyPort\":\"" + config.proxyPort + "\"," + - "\"maxSlots\":\"" + config.maxClients + "\"," + - "\"clientCount\":\"" + clientCount + "\"}"; - - streamWriter.Write(json); - streamWriter.Flush(); - } - } - catch(Exception e) - { - logDebug("Callback", e.ToString()); - } + string json = "json={\"version\":\"" + VersionNum + "\"," + + "\"protocol\":\"" + ProtocolVersion + "\"," + + "\"mono\":\"" + IsMono + "\"," + + "\"proxyPort\":\"" + config.proxyPort + "\"," + + "\"maxSlots\":\"" + config.maxClients + "\"," + + "\"clientCount\":\"" + clientCount + "\"}"; + byte[] buffer = Encoding.UTF8.GetBytes(json); + + WebRequest request = WebRequest.Create("http://callback.avilance.com/"); + request.ContentType = "application/x-www-form-urlencoded"; + request.Method = "POST"; + request.ContentLength = buffer.Length; + Stream streamWriter = request.GetRequestStream(); + streamWriter.Write(buffer, 0, buffer.Length); + streamWriter.Close(); + } + catch (Exception e) + { + logDebug("Callback", e.ToString()); } Thread.Sleep(1000 * 60 * 15); }