move LobbyInfo onto OrderManager
This commit is contained in:
@@ -21,8 +21,10 @@ namespace OpenRA.Network
|
||||
readonly SyncReport syncReport = new SyncReport();
|
||||
readonly FrameData frameData = new FrameData();
|
||||
|
||||
public int FrameNumber { get; private set; }
|
||||
public Session LobbyInfo = new Session( Game.Settings.Game.Mods );
|
||||
public Session.Client LocalClient { get { return LobbyInfo.ClientWithIndex( Connection.LocalClientId ); } }
|
||||
|
||||
public int FrameNumber { get; private set; }
|
||||
public int FramesAhead = 0;
|
||||
|
||||
public bool GameStarted { get { return FrameNumber != 0; } }
|
||||
@@ -82,7 +84,7 @@ namespace OpenRA.Network
|
||||
|
||||
foreach( var p in immediatePackets )
|
||||
foreach( var o in p.Second.ToOrderList( world ) )
|
||||
UnitOrders.ProcessOrder( world, p.First, o );
|
||||
UnitOrders.ProcessOrder( this, world, p.First, o );
|
||||
}
|
||||
|
||||
Dictionary<int, byte[]> syncForFrame = new Dictionary<int, byte[]>();
|
||||
@@ -152,7 +154,7 @@ namespace OpenRA.Network
|
||||
|
||||
foreach( var order in frameData.OrdersForFrame( world, FrameNumber) )
|
||||
{
|
||||
UnitOrders.ProcessOrder( world, order.Client, order.Order );
|
||||
UnitOrders.ProcessOrder( this, world, order.Client, order.Order );
|
||||
sync.Add( world.SyncHash() );
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Network
|
||||
@@ -20,6 +21,16 @@ namespace OpenRA.Network
|
||||
public List<Slot> Slots = new List<Slot>();
|
||||
public Global GlobalSettings = new Global();
|
||||
|
||||
public Client ClientWithIndex( int clientID )
|
||||
{
|
||||
return Clients.Single( c => c.Index == clientID );
|
||||
}
|
||||
|
||||
public Client ClientInSlot( Slot slot )
|
||||
{
|
||||
return Clients.SingleOrDefault( c => c.Slot == slot.Index );
|
||||
}
|
||||
|
||||
public enum ClientState
|
||||
{
|
||||
NotReady,
|
||||
@@ -59,6 +70,11 @@ namespace OpenRA.Network
|
||||
public bool AllowCheats = false;
|
||||
}
|
||||
|
||||
public Session( string[] mods )
|
||||
{
|
||||
this.GlobalSettings.Mods = mods.ToArray();
|
||||
}
|
||||
|
||||
public string Serialize()
|
||||
{
|
||||
var clientData = new List<MiniYamlNode>();
|
||||
@@ -76,8 +92,7 @@ namespace OpenRA.Network
|
||||
|
||||
public static Session Deserialize(string data)
|
||||
{
|
||||
var session = new Session();
|
||||
session.GlobalSettings.Mods = Game.Settings.Game.Mods;
|
||||
var session = new Session( Game.Settings.Game.Mods );
|
||||
|
||||
var ys = MiniYaml.FromString(data);
|
||||
foreach (var y in ys)
|
||||
|
||||
@@ -16,18 +16,13 @@ namespace OpenRA.Network
|
||||
{
|
||||
static class UnitOrders
|
||||
{
|
||||
static Session.Client FindClientById(int id)
|
||||
{
|
||||
return Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == id);
|
||||
}
|
||||
|
||||
static Player FindPlayerByClientId( this World world, int id)
|
||||
{
|
||||
/* todo: find the interactive player. */
|
||||
return world.players.Values.FirstOrDefault(p => p.ClientIndex == id);
|
||||
}
|
||||
|
||||
public static void ProcessOrder( World world, int clientId, Order order )
|
||||
public static void ProcessOrder( OrderManager orderManager, World world, int clientId, Order order )
|
||||
{
|
||||
// Drop exploiting orders
|
||||
if (order.Subject != null && order.Subject.Owner.ClientIndex != clientId)
|
||||
@@ -40,7 +35,7 @@ namespace OpenRA.Network
|
||||
{
|
||||
case "Chat":
|
||||
{
|
||||
var client = FindClientById(clientId);
|
||||
var client = orderManager.LobbyInfo.ClientWithIndex( clientId );
|
||||
if (client != null)
|
||||
{
|
||||
var player = world.FindPlayerByClientId(clientId);
|
||||
@@ -53,14 +48,14 @@ namespace OpenRA.Network
|
||||
}
|
||||
case "TeamChat":
|
||||
{
|
||||
var client = FindClientById(clientId);
|
||||
var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
|
||||
if (client != null)
|
||||
{
|
||||
var player = world.FindPlayerByClientId(clientId);
|
||||
var display = (world.GameHasStarted) ?
|
||||
player != null && (world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally
|
||||
|| player.WinState == WinState.Lost) :
|
||||
client == Game.LocalClient || (client.Team == Game.LocalClient.Team && client.Team != 0);
|
||||
client == orderManager.LocalClient || (client.Team == orderManager.LocalClient.Team && client.Team != 0);
|
||||
|
||||
if (display)
|
||||
{
|
||||
@@ -73,12 +68,27 @@ namespace OpenRA.Network
|
||||
case "StartGame":
|
||||
{
|
||||
Game.AddChatLine(Color.White, "Server", "The game has started.");
|
||||
Game.StartGame(Game.LobbyInfo.GlobalSettings.Map);
|
||||
Game.StartGame(orderManager.LobbyInfo.GlobalSettings.Map);
|
||||
break;
|
||||
}
|
||||
case "SyncInfo":
|
||||
{
|
||||
Game.SyncLobbyInfo( order.TargetString);
|
||||
orderManager.LobbyInfo = Session.Deserialize( order.TargetString );
|
||||
|
||||
//if( !world.GameHasStarted )
|
||||
// world.SharedRandom = new XRandom( LobbyInfo.GlobalSettings.RandomSeed );
|
||||
|
||||
//if (orderManager.Connection.ConnectionState == ConnectionState.Connected)
|
||||
// world.SetLocalPlayer(orderManager.Connection.LocalClientId);
|
||||
|
||||
if( orderManager.FramesAhead != orderManager.LobbyInfo.GlobalSettings.OrderLatency
|
||||
&& !orderManager.GameStarted )
|
||||
{
|
||||
orderManager.FramesAhead = orderManager.LobbyInfo.GlobalSettings.OrderLatency;
|
||||
Game.Debug( "Order lag is now {0} frames.".F( orderManager.LobbyInfo.GlobalSettings.OrderLatency ) );
|
||||
}
|
||||
|
||||
Game.SyncLobbyInfo();
|
||||
break;
|
||||
}
|
||||
case "SetStance":
|
||||
|
||||
Reference in New Issue
Block a user