Skip to content

Commit

Permalink
Fix callback
Browse files Browse the repository at this point in the history
  • Loading branch information
zidonuke committed Dec 29, 2013
1 parent a0f3627 commit b48b014
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions StarryboundServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ static void Main(string[] args)
serverState = ServerState.Running;

//Keep this last!
runCallback();
if (config.enableCallback)
runCallback();
}

public static void crashMonitor()
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b48b014

Please sign in to comment.