added protocol versioning. AssignPlayer order is dead.
This commit is contained in:
@@ -77,6 +77,7 @@ namespace OpenRA.Server
|
||||
|
||||
// assign the player number.
|
||||
newConn.PlayerIndex = ChooseFreePlayerIndex();
|
||||
newConn.socket.Send(BitConverter.GetBytes(ProtocolVersion.Version));
|
||||
newConn.socket.Send(BitConverter.GetBytes(newConn.PlayerIndex));
|
||||
conns.Add(newConn);
|
||||
|
||||
@@ -90,9 +91,6 @@ namespace OpenRA.Server
|
||||
State = Session.ClientState.NotReady
|
||||
});
|
||||
|
||||
DispatchOrdersToClient(newConn, 0, 0,
|
||||
new ServerOrder(newConn.PlayerIndex, "AssignPlayer", "").Serialize());
|
||||
|
||||
Console.WriteLine("Accepted connection from {0}.",
|
||||
newConn.socket.RemoteEndPoint);
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
<Compile Include="Palette.cs" />
|
||||
<Compile Include="PlayerColorRemap.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ProtocolVersion.cs" />
|
||||
<Compile Include="Session.cs" />
|
||||
<Compile Include="ShpReader.cs" />
|
||||
<Compile Include="ShroudPaletteRemap.cs" />
|
||||
|
||||
13
OpenRa.FileFormats/ProtocolVersion.cs
Normal file
13
OpenRa.FileFormats/ProtocolVersion.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenRa.FileFormats
|
||||
{
|
||||
public static class ProtocolVersion
|
||||
{
|
||||
// you *must* increment this whenever you make an incompatible protocol change
|
||||
public static readonly int Version = 1;
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,6 @@ namespace OpenRa
|
||||
|
||||
internal static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer, Controller controller)
|
||||
{
|
||||
//localPlayerIndex = localPlayer;
|
||||
Game.renderer = renderer;
|
||||
Game.clientSize = clientSize;
|
||||
|
||||
@@ -102,7 +101,6 @@ namespace OpenRa
|
||||
ChangeMap(mapName);
|
||||
|
||||
if (Settings.Replay != "")
|
||||
//orderManager = new OrderManager(new IOrderSource[] { new ReplayOrderSource(Settings.Replay) });
|
||||
throw new NotImplementedException();
|
||||
else
|
||||
{
|
||||
@@ -197,6 +195,9 @@ namespace OpenRa
|
||||
|
||||
LobbyInfo = session;
|
||||
|
||||
if (Game.orderManager.Connection.ConnectionState == ConnectionState.Connected)
|
||||
world.SetLocalPlayer(Game.orderManager.Connection.LocalClientId);
|
||||
|
||||
if (Game.orderManager.FramesAhead != LobbyInfo.GlobalSettings.OrderLatency
|
||||
&& !Game.orderManager.GameStarted)
|
||||
{
|
||||
@@ -277,14 +278,6 @@ namespace OpenRa
|
||||
new Order( "ToggleReady", Game.world.LocalPlayer.PlayerActor, "" ) { IsImmediate = true } );
|
||||
}
|
||||
|
||||
/* temporary hack: DO NOT LEAVE IN */
|
||||
if( e.KeyCode == Keys.F2 )
|
||||
Game.world.LocalPlayer = Game.world.players[ ( Game.world.LocalPlayer.Index + 1 ) % 4 ];
|
||||
if( e.KeyCode == Keys.F3 )
|
||||
Game.controller.orderGenerator = new SellOrderGenerator();
|
||||
if( e.KeyCode == Keys.F4 )
|
||||
Game.controller.orderGenerator = new RepairOrderGenerator();
|
||||
|
||||
if( !Game.chat.isChatting )
|
||||
if( e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 )
|
||||
Game.controller.DoControlGroup( world, (int)e.KeyCode - (int)Keys.D0, (Modifiers)(int)e.Modifiers );
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Text;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.IO;
|
||||
using OpenRa.FileFormats;
|
||||
|
||||
namespace OpenRa.Network
|
||||
{
|
||||
@@ -78,6 +79,13 @@ namespace OpenRa.Network
|
||||
{
|
||||
socket = new TcpClient( host, port );
|
||||
var reader = new BinaryReader( socket.GetStream() );
|
||||
var serverProtocol = reader.ReadInt32();
|
||||
|
||||
if (ProtocolVersion.Version != serverProtocol)
|
||||
throw new InvalidOperationException(
|
||||
"Protocol version mismatch. Server={0} Client={1}"
|
||||
.F(serverProtocol, ProtocolVersion.Version));
|
||||
|
||||
clientId = reader.ReadInt32();
|
||||
connectionState = ConnectionState.Connected;
|
||||
|
||||
|
||||
@@ -18,12 +18,6 @@ namespace OpenRa.Network
|
||||
Game.chat.AddLine(order.Player, order.TargetString);
|
||||
break;
|
||||
}
|
||||
case "AssignPlayer":
|
||||
{
|
||||
order.Player.World.LocalPlayer = order.Player;
|
||||
Game.chat.AddLine(order.Player, "is now YOU.");
|
||||
break;
|
||||
}
|
||||
case "StartGame":
|
||||
{
|
||||
Game.chat.AddLine(Color.White, "Server", "The game has started.");
|
||||
|
||||
@@ -21,10 +21,15 @@ namespace OpenRa
|
||||
public Player LocalPlayer
|
||||
{
|
||||
get { return players[localPlayerIndex]; }
|
||||
set
|
||||
}
|
||||
|
||||
public void SetLocalPlayer(int index)
|
||||
{
|
||||
localPlayerIndex = value.Index;
|
||||
Game.viewport.GoToStartLocation( value );
|
||||
if (index != localPlayerIndex)
|
||||
{
|
||||
localPlayerIndex = index;
|
||||
Game.viewport.GoToStartLocation(LocalPlayer);
|
||||
Game.chat.AddLine(LocalPlayer, "is now YOU");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user