don't crash on in-game connection loss either

This commit is contained in:
Chris Forbes
2010-01-18 18:32:03 +13:00
parent 893dc15d81
commit 1b0187b089
3 changed files with 32 additions and 14 deletions

View File

@@ -217,6 +217,9 @@ namespace OpenRa
var r = new Rectangle((Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h); var r = new Rectangle((Game.viewport.Width - w) / 2, (Game.viewport.Height - h) / 2, w, h);
DrawDialogBackground(r, optionsSprites, true); DrawDialogBackground(r, optionsSprites, true);
DrawCentered(text, new int2(Game.viewport.Width / 2, Game.viewport.Height / 2 - 8), Color.White); DrawCentered(text, new int2(Game.viewport.Width / 2, Game.viewport.Height / 2 - 8), Color.White);
// don't allow clicks through the dialog
AddButton(r, _ => { });
} }
public void DrawLobby() public void DrawLobby()
@@ -260,6 +263,9 @@ namespace OpenRa
DrawDialogBackground(chatBox, panelSprites, false); DrawDialogBackground(chatBox, panelSprites, false);
DrawChat(typingBox, chatBox); DrawChat(typingBox, chatBox);
// block clicks `through` the dialog
AddButton(r, _ => { });
} }
public void TickRadarAnimation() public void TickRadarAnimation()

View File

@@ -53,6 +53,10 @@ namespace OpenRa.Graphics
{ {
Game.world.WorldRenderer.Draw(); Game.world.WorldRenderer.Draw();
Game.chrome.Draw(); Game.chrome.Draw();
if (Game.orderManager.IsNetplay &&
Game.orderManager.Sources.OfType<NetworkOrderSource>().First().State == ConnectionState.NotConnected)
Game.chrome.DrawDialog("Connection lost.");
} }
else else
{ {
@@ -64,7 +68,7 @@ namespace OpenRa.Graphics
switch (nos.State) switch (nos.State)
{ {
case ConnectionState.Connecting: case ConnectionState.Connecting:
Game.chrome.DrawDialog("Connecting to {0}:{1}".F( Game.Settings.NetworkHost, Game.Settings.NetworkPort )); Game.chrome.DrawDialog("Connecting to {0}:{1}...".F( Game.Settings.NetworkHost, Game.Settings.NetworkPort ));
break; break;
case ConnectionState.NotConnected: case ConnectionState.NotConnected:
Game.chrome.DrawDialog("Connection failed."); Game.chrome.DrawDialog("Connection failed.");

View File

@@ -42,26 +42,34 @@ namespace OpenRa.Orders
{ {
var reader = new BinaryReader(socket.GetStream()); var reader = new BinaryReader(socket.GetStream());
for (; ; ) try
{ {
var len = reader.ReadInt32(); for (; ; )
var frame = reader.ReadInt32();
var buf = reader.ReadBytes(len - 4);
lock (orderBuffers)
{ {
if (len == 5 && buf[0] == 0xef) /* got everything marker */ var len = reader.ReadInt32();
gotEverything[frame] = true; var frame = reader.ReadInt32();
else var buf = reader.ReadBytes(len - 4);
lock (orderBuffers)
{ {
/* accumulate this chunk */ if (len == 5 && buf[0] == 0xef) /* got everything marker */
if (!orderBuffers.ContainsKey(frame)) gotEverything[frame] = true;
orderBuffers[frame] = new List<byte[]> { buf };
else else
orderBuffers[frame].Add(buf); {
/* accumulate this chunk */
if (!orderBuffers.ContainsKey(frame))
orderBuffers[frame] = new List<byte[]> { buf };
else
orderBuffers[frame].Add(buf);
}
} }
} }
} }
catch (IOException e)
{
State = ConnectionState.NotConnected;
}
}) { IsBackground = true }.Start(); }) { IsBackground = true }.Start();
} }
catch catch