Support for master game ID.

This commit is contained in:
Matthew Bowra-Dean
2010-05-28 23:22:08 +12:00
parent 1839655eb5
commit fd014e15a5
9 changed files with 31 additions and 10 deletions

View File

@@ -175,12 +175,13 @@ namespace OpenRA
internal static string CurrentHost = ""; internal static string CurrentHost = "";
internal static int CurrentPort = 0; internal static int CurrentPort = 0;
internal static void JoinServer(string host, int port) internal static void JoinServer(int id, string host, int port)
{ {
if (orderManager != null) orderManager.Dispose(); if (orderManager != null) orderManager.Dispose();
CurrentHost = host; CurrentHost = host;
CurrentPort = port; CurrentPort = port;
MasterGameID = id;
orderManager = new OrderManager(new NetworkConnection(host, port), ChooseReplayFilename()); orderManager = new OrderManager(new NetworkConnection(host, port), ChooseReplayFilename());
} }

View File

@@ -48,6 +48,7 @@ namespace OpenRA.Server
class GameServer class GameServer
{ {
public readonly int Id = 0;
public readonly string Name = null; public readonly string Name = null;
public readonly string Address = null; public readonly string Address = null;
public readonly int State = 0; public readonly int State = 0;

View File

@@ -28,6 +28,7 @@ using System.Net.Sockets;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Threading; using System.Threading;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using System.Text;
namespace OpenRA.Server namespace OpenRA.Server
{ {
@@ -540,11 +541,14 @@ namespace OpenRA.Server
if (wc.IsBusy || !isInternetServer) return; if (wc.IsBusy || !isInternetServer) return;
var url = "ping.php?port={0}&name={1}&state={2}&players={3}&mods={4}&map={5}"; var url = "ping.php?port={0}&name={1}&state={2}&players={3}&mods={4}&map={5}";
wc.DownloadDataCompleted += PingMasterServerResponse;
if (isInitialPing) if (isInitialPing)
{ {
url += "&new=1"; url += "&new=1";
isInitialPing = false; isInitialPing = false;
} }
else
wc.DownloadDataCompleted -= PingMasterServerResponse;
wc.DownloadDataAsync(new Uri( wc.DownloadDataAsync(new Uri(
masterServerUrl + url.F( masterServerUrl + url.F(
@@ -556,5 +560,11 @@ namespace OpenRA.Server
lastPing = Environment.TickCount; lastPing = Environment.TickCount;
} }
static void PingMasterServerResponse(object sender, DownloadDataCompletedEventArgs e)
{
string s = Encoding.UTF8.GetString(e.Result);
int.TryParse(s.Trim(), out Game.MasterGameID);
}
} }
} }

View File

@@ -49,12 +49,12 @@ namespace OpenRA
catch( Exception e ) catch( Exception e )
{ {
Log.Write( "{0}", e.ToString() ); Log.Write( "{0}", e.ToString() );
UploadLog(); UploadLog(Game.MasterGameID);
throw; throw;
} }
} }
static void UploadLog() static void UploadLog(int gameId)
{ {
Log.Close(); Log.Close();
var logfile = File.OpenRead(Log.Filename); var logfile = File.OpenRead(Log.Filename);
@@ -71,11 +71,13 @@ namespace OpenRA
request.ContentType = "application/x-gzip"; request.ContentType = "application/x-gzip";
request.ContentLength = buffer.Length; request.ContentLength = buffer.Length;
request.Method = "POST"; request.Method = "POST";
request.Headers.Add("Game-ID", gameId.ToString());
using (var requestStream = request.GetRequestStream()) using (var requestStream = request.GetRequestStream())
requestStream.Write(buffer, 0, buffer.Length); requestStream.Write(buffer, 0, buffer.Length);
var response = (HttpWebResponse)request.GetResponse(); var response = (HttpWebResponse)request.GetResponse();
MessageBox.Show(response.GetResponseStream().ReadAllText());
} }
static void Run( string[] args ) static void Run( string[] args )

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Widgets.Delegates
return true; return true;
}; };
r.GetWidget("CONNECTION_BUTTON_RETRY").OnMouseUp = mi => { r.GetWidget("CONNECTION_BUTTON_RETRY").OnMouseUp = mi => {
Game.JoinServer(Game.CurrentHost, Game.CurrentPort); Game.JoinServer(Game.MasterGameID, Game.CurrentHost, Game.CurrentPort);
return true; return true;
}; };

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Widgets.Delegates
Game.Settings.ExternalPort, mods, map); Game.Settings.ExternalPort, mods, map);
Log.Write("Joining server"); Log.Write("Joining server");
Game.JoinServer(IPAddress.Loopback.ToString(), Game.Settings.ListenPort); Game.JoinServer(0, IPAddress.Loopback.ToString(), Game.Settings.ListenPort);
return true; return true;
}; };

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Widgets.Delegates
OnMouseUp = nmi => OnMouseUp = nmi =>
{ {
r.GetWidget("JOINSERVER_BG").Visible = false; r.GetWidget("JOINSERVER_BG").Visible = false;
Game.JoinServer(g.Address.Split(':')[0], int.Parse(g.Address.Split(':')[1])); Game.JoinServer(g.Id, g.Address.Split(':')[0], int.Parse(g.Address.Split(':')[1]));
return true; return true;
}, },
}; };
@@ -128,7 +128,7 @@ namespace OpenRA.Widgets.Delegates
r.GetWidget("JOINSERVER_BUTTON_DIRECTCONNECT").OnMouseUp = mi => r.GetWidget("JOINSERVER_BUTTON_DIRECTCONNECT").OnMouseUp = mi =>
{ /* rude hack. kill this as soon as we can do a direct connect via the commandline */ { /* rude hack. kill this as soon as we can do a direct connect via the commandline */
r.CloseWindow(); r.CloseWindow();
Game.JoinServer(Game.Settings.NetworkHost, Game.Settings.NetworkPort); Game.JoinServer(0, Game.Settings.NetworkHost, Game.Settings.NetworkPort);
return true; return true;
}; };
} }

View File

@@ -1,6 +1,6 @@
<?php <?php
$post_file = fopen("php://input", "rb"); $post_file = fopen('php://input', 'rb');
$log_file = fopen("log.".time().".gz", "wb"); $log_file = fopen('log.'.time().'.gz', 'wb');
$post_data = ''; $post_data = '';
while (!feof($post_file)) { while (!feof($post_file)) {
@@ -11,4 +11,9 @@ fwrite($log_file, $post_data);
fclose($post_file); fclose($post_file);
fclose($log_file); fclose($log_file);
foreach ($_SERVER as $key=>$value)
{
echo $key.': '.$value.'\n';
}
?> ?>

View File

@@ -6,9 +6,11 @@
$db = new PDO('sqlite:openra.db'); $db = new PDO('sqlite:openra.db');
$stale = 60 * 5; $stale = 60 * 5;
$result = $db->query('SELECT * FROM servers WHERE (' . time() . ' - ts < ' . $stale . ')'); $result = $db->query('SELECT * FROM servers WHERE (' . time() . ' - ts < ' . $stale . ')');
$n = 0;
foreach ( $result as $row ) foreach ( $result as $row )
{ {
echo "Game@" . $row['id'] . ":\n"; echo "Game@" . $n++ . ":\n";
echo "\tId: " . $row['id'] . "\n";
echo "\tName: " . $row['name'] . "\n"; echo "\tName: " . $row['name'] . "\n";
echo "\tAddress: " . $row['address'] . "\n"; echo "\tAddress: " . $row['address'] . "\n";
echo "\tState: " . $row['state'] . "\n"; echo "\tState: " . $row['state'] . "\n";