chat no longer sets Order.Player (or Subject); clientId is used instead.

This commit is contained in:
Bob
2010-01-26 16:25:27 +13:00
parent f3f8fdef90
commit 99e59e8fb2
9 changed files with 19 additions and 15 deletions

View File

@@ -350,12 +350,12 @@ namespace OpenRA.Server
static void SendChatTo(Connection conn, string text)
{
DispatchOrdersToClient(conn, 0, 0,
new ServerOrder(conn.PlayerIndex, "Chat", text).Serialize());
new ServerOrder(-1, "Chat", text).Serialize());
}
static void SendChat(Connection asConn, string text)
{
DispatchOrders(null, 0, new ServerOrder(asConn.PlayerIndex, "Chat", text).Serialize());
DispatchOrders(null, 0, new ServerOrder(-1, "Chat", text).Serialize());
}
static void InterpretServerOrder(Connection conn, ServerOrder so)

View File

@@ -15,7 +15,7 @@ namespace OpenRa
public void Toggle()
{
if (isChatting && typing.Length > 0)
Game.orderManager.IssueOrder(Order.Chat(Game.world.LocalPlayer, typing));
Game.orderManager.IssueOrder(Order.Chat(typing));
typing = "";
isChatting ^= true;

View File

@@ -257,7 +257,7 @@ namespace OpenRa
_ =>
{
Game.orderManager.IssueOrder(
Order.Chat(Game.world.LocalPlayer, "/map " + currentMap));
Order.Chat("/map " + currentMap));
showMapChooser = false;
});

View File

@@ -47,7 +47,7 @@ namespace OpenRa
var ret = new MemoryStream();
var w = new BinaryWriter(ret);
w.Write((byte)0xfe);
w.Write((uint)Player.Index);
w.Write(Subject == null ? uint.MaxValue : (uint)Player.Index);
w.Write(OrderString);
w.Write(TargetString);
return ret.ToArray();
@@ -113,7 +113,9 @@ namespace OpenRa
var name = r.ReadString();
var data = r.ReadString();
return new Order( name, LookupPlayer( world, playerID ).PlayerActor, data ) { IsImmediate = true };
var player = (playerID == uint.MaxValue) ? null : LookupPlayer( world, playerID ).PlayerActor;
return new Order( name, player, data ) { IsImmediate = true };
}
default:
@@ -148,9 +150,9 @@ namespace OpenRa
// Named constructors for Orders.
// Now that Orders are resolved by individual Actors, these are weird; you unpack orders manually, but not pack them.
public static Order Chat(Player subject, string text)
public static Order Chat(string text)
{
return new Order("Chat", subject.PlayerActor, text) { IsImmediate = true };
return new Order("Chat", null, text) { IsImmediate = true };
}
public static Order StartProduction(Player subject, string item)

View File

@@ -79,7 +79,7 @@ namespace OpenRa.Network
foreach( var p in immediatePackets )
foreach( var o in p.Second.ToOrderList( world ) )
UnitOrders.ProcessOrder( p.First, o );
UnitOrders.ProcessOrder( world, p.First, o );
}
Dictionary<int, byte[]> syncForFrame = new Dictionary<int, byte[]>();
@@ -126,7 +126,7 @@ namespace OpenRa.Network
foreach( var order in frameData.OrderBy( p => p.Key ).SelectMany( o => o.Value.ToOrderList( world ).Select( a => new { Client = o.Key, Order = a } ) ) )
{
UnitOrders.ProcessOrder( order.Client, order.Order );
UnitOrders.ProcessOrder( world, order.Client, order.Order );
sync.Add( world.SyncHash() );
}

View File

@@ -1,4 +1,5 @@
using System.Drawing;
using System.Linq;
using OpenRa.FileFormats;
using OpenRa.GameRules;
using OpenRa.Graphics;
@@ -8,13 +9,14 @@ namespace OpenRa.Network
{
static class UnitOrders
{
public static void ProcessOrder( int clientId, Order order )
public static void ProcessOrder( World world, int clientId, Order order )
{
switch( order.OrderString )
{
case "Chat":
{
Game.chat.AddLine(order.Player, order.TargetString);
var player = world.players.Values.Where( p => p.Index == clientId ).Single();
Game.chat.AddLine(player, order.TargetString);
break;
}
case "StartGame":

View File

@@ -68,7 +68,7 @@ namespace OpenRa
Game.chat.AddLine(Color.White, "Debug", "Requesting package: {0}".F(currentPackage));
Game.orderManager.IssueOrder(
new Order("RequestFile", Game.world.LocalPlayer.PlayerActor, currentPackage) { IsImmediate = true });
new Order("RequestFile", null, currentPackage) { IsImmediate = true });
Fraction = 0f;
}

View File

@@ -62,7 +62,7 @@ namespace OpenRa.Traits
{
if (mi.Button == MouseButton.Left)
{
yield return new Order("NuclearMissile", Game.world.LocalPlayer.PlayerActor, xy);
yield return new Order("NuclearMissile", world.LocalPlayer.PlayerActor, xy);
}
yield break;

View File

@@ -68,7 +68,7 @@ namespace OpenRa.Traits
yield break;
}
yield return new Order("SpyPlane", Game.world.LocalPlayer.PlayerActor, xy);
yield return new Order("SpyPlane", world.LocalPlayer.PlayerActor, xy);
}
public void Tick(World world) {}