netplay readying cleanup
This commit is contained in:
@@ -16,7 +16,6 @@ namespace OpenRA.Server
|
||||
public int Frame = 0;
|
||||
|
||||
/* client data */
|
||||
public bool IsReady;
|
||||
public int PlayerIndex;
|
||||
|
||||
public byte[] PopBytes(int n)
|
||||
@@ -25,6 +24,11 @@ namespace OpenRA.Server
|
||||
data.RemoveRange(0, n);
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/* file server state */
|
||||
public int NextChunk = 0;
|
||||
public int NumChunks = 0;
|
||||
public Stream Stream = null;
|
||||
}
|
||||
|
||||
enum ReceiveState { Header, Data };
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace OpenRA.Server
|
||||
static Dictionary<int, List<Connection>> inFlightFrames
|
||||
= new Dictionary<int, List<Connection>>();
|
||||
static Session lobbyInfo = new Session();
|
||||
static bool GameStarted = false;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
@@ -223,7 +224,7 @@ namespace OpenRA.Server
|
||||
{ "race",
|
||||
s =>
|
||||
{
|
||||
if (conn.IsReady)
|
||||
if (GameStarted)
|
||||
{
|
||||
DispatchOrdersToClient(conn, 0,
|
||||
new ServerOrder( conn.PlayerIndex, "Chat",
|
||||
@@ -245,7 +246,7 @@ namespace OpenRA.Server
|
||||
{ "pal",
|
||||
s =>
|
||||
{
|
||||
if (conn.IsReady)
|
||||
if (GameStarted)
|
||||
{
|
||||
DispatchOrdersToClient(conn, 0,
|
||||
new ServerOrder( conn.PlayerIndex, "Chat",
|
||||
@@ -275,7 +276,7 @@ namespace OpenRA.Server
|
||||
return true;
|
||||
}
|
||||
|
||||
if (conn.IsReady)
|
||||
if (GameStarted)
|
||||
{
|
||||
DispatchOrdersToClient(conn, 0,
|
||||
new ServerOrder( conn.PlayerIndex, "Chat",
|
||||
@@ -309,15 +310,22 @@ namespace OpenRA.Server
|
||||
switch (so.Name)
|
||||
{
|
||||
case "ToggleReady":
|
||||
conn.IsReady ^= true;
|
||||
// if we're downloading, we can't ready up.
|
||||
|
||||
Console.WriteLine("Player @{0} is {1}",
|
||||
conn.socket.RemoteEndPoint, conn.IsReady ? "ready" : "not ready");
|
||||
var client = lobbyInfo.Clients[conn.PlayerIndex];
|
||||
if (client.State == Session.ClientState.NotReady)
|
||||
client.State = Session.ClientState.Ready;
|
||||
else if (client.State == Session.ClientState.Ready)
|
||||
client.State = Session.ClientState.NotReady;
|
||||
|
||||
Console.WriteLine("Player @{0} is {1}",
|
||||
conn.socket.RemoteEndPoint, client.State);
|
||||
|
||||
// start the game if everyone is ready.
|
||||
if (conns.All(c => c.IsReady))
|
||||
if (conns.All(c => lobbyInfo.Clients[c.PlayerIndex].State == Session.ClientState.Ready))
|
||||
{
|
||||
Console.WriteLine("All players are ready. Starting the game!");
|
||||
GameStarted = true;
|
||||
DispatchOrders(null, 0,
|
||||
new ServerOrder(0, "StartGame", "").Serialize());
|
||||
}
|
||||
@@ -336,6 +344,11 @@ namespace OpenRA.Server
|
||||
foreach (var c in conns.Except(conn).ToArray())
|
||||
DispatchOrdersToClient(c, 0, so.Serialize());
|
||||
break;
|
||||
|
||||
case "RequestFile":
|
||||
Console.WriteLine("** Requesting file: `{0}`", so.Data);
|
||||
// todo: start serving!
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,6 +387,7 @@ namespace OpenRA.Server
|
||||
Console.WriteLine("Server emptied out; doing a bit of housekeeping to prepare for next game..");
|
||||
inFlightFrames.Clear();
|
||||
lobbyInfo = new Session();
|
||||
GameStarted = false;
|
||||
}
|
||||
|
||||
static void SyncLobbyInfo()
|
||||
|
||||
@@ -160,13 +160,12 @@ namespace OpenRa.Game
|
||||
buttons.Clear();
|
||||
|
||||
renderer.Device.DisableScissor();
|
||||
renderer.DrawText("RenderFrame {0} ({2:F1} ms)\nTick {1} ({3:F1} ms)\nReady: {4} (F8 to toggle)".F(
|
||||
renderer.DrawText("RenderFrame {0} ({2:F1} ms)\nTick {1} ({3:F1} ms)\n".F(
|
||||
Game.RenderFrame,
|
||||
Game.orderManager.FrameNumber,
|
||||
PerfHistory.items["render"].LastValue,
|
||||
PerfHistory.items["tick_time"].LastValue,
|
||||
Game.LocalPlayer.IsReady ? "Yes" : "No"
|
||||
), new int2(140, 15), Color.White);
|
||||
PerfHistory.items["tick_time"].LastValue),
|
||||
new int2(140, 15), Color.White);
|
||||
|
||||
if (Game.Settings.PerfGraph)
|
||||
PerfHistory.Render(renderer, Game.worldRenderer.lineRenderer);
|
||||
|
||||
@@ -146,10 +146,8 @@ namespace OpenRa.Game
|
||||
/* hack hack hack */
|
||||
if (e.KeyCode == Keys.F8 && !Game.orderManager.GameStarted)
|
||||
{
|
||||
Game.LocalPlayer.IsReady ^= true;
|
||||
Game.controller.AddOrder(
|
||||
new Order( "ToggleReady", Game.LocalPlayer.PlayerActor, null, int2.Zero,
|
||||
Game.LocalPlayer.IsReady ? "ready" : "not ready") { IsImmediate = true });
|
||||
new Order( "ToggleReady", Game.LocalPlayer.PlayerActor, null, int2.Zero, "") { IsImmediate = true });
|
||||
}
|
||||
|
||||
/* temporary hack: DO NOT LEAVE IN */
|
||||
|
||||
@@ -26,8 +26,6 @@ namespace OpenRa.Game
|
||||
public int PowerProvided = 0;
|
||||
public int PowerDrained = 0;
|
||||
|
||||
public bool IsReady;
|
||||
|
||||
public Shroud Shroud = new Shroud();
|
||||
public Dictionary<string, SupportPower> SupportPowers;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user