Core: Added trait 'SurrenderOnDisconnect' and the core changes required to make this work
This commit is contained in:
@@ -34,7 +34,8 @@ namespace OpenRA.Network
|
||||
public enum ClientState
|
||||
{
|
||||
NotReady,
|
||||
Ready
|
||||
Ready,
|
||||
Disconnected = 1000
|
||||
}
|
||||
|
||||
public class Client
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace OpenRA.Network
|
||||
if (Game.IsHost && Game.Settings.Server.Extension != null && !Game.Settings.Server.Extension.OnIngameChat(client, order.TargetString, false))
|
||||
break;
|
||||
|
||||
|
||||
if (client != null)
|
||||
{
|
||||
var player = world != null ? world.FindPlayerByClient(client) : null;
|
||||
@@ -53,6 +54,16 @@ namespace OpenRA.Network
|
||||
Game.AddChatLine(Color.White, "(player {0})".F(clientId), order.TargetString);
|
||||
break;
|
||||
}
|
||||
|
||||
case "Disconnected": /* reports that the target player disconnected */
|
||||
{
|
||||
var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
|
||||
if (client != null)
|
||||
{
|
||||
client.State = Session.ClientState.Disconnected;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "TeamChat":
|
||||
{
|
||||
var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
|
||||
@@ -72,12 +83,16 @@ namespace OpenRA.Network
|
||||
{
|
||||
var player = world.FindPlayerByClient(client);
|
||||
var display = player != null
|
||||
&& (world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally
|
||||
&&
|
||||
(world.LocalPlayer != null &&
|
||||
player.Stances[world.LocalPlayer] == Stance.Ally
|
||||
|| player.WinState == WinState.Lost);
|
||||
|
||||
if (display)
|
||||
{
|
||||
var suffix = (player != null && player.WinState == WinState.Lost) ? " (Dead)" : " (Team)";
|
||||
var suffix = (player != null && player.WinState == WinState.Lost)
|
||||
? " (Dead)"
|
||||
: " (Team)";
|
||||
Game.AddChatLine(client.Color1, client.Name + suffix, order.TargetString);
|
||||
}
|
||||
}
|
||||
@@ -98,15 +113,15 @@ namespace OpenRA.Network
|
||||
&& !orderManager.GameStarted)
|
||||
{
|
||||
orderManager.FramesAhead = orderManager.LobbyInfo.GlobalSettings.OrderLatency;
|
||||
Game.Debug( "Order lag is now {0} frames.".F( orderManager.LobbyInfo.GlobalSettings.OrderLatency ) );
|
||||
Game.Debug(
|
||||
"Order lag is now {0} frames.".F(orderManager.LobbyInfo.GlobalSettings.OrderLatency));
|
||||
}
|
||||
|
||||
Game.SyncLobbyInfo();
|
||||
break;
|
||||
}
|
||||
|
||||
case "SetStance":
|
||||
{
|
||||
|
||||
var targetPlayer = order.Player.World.players[order.TargetLocation.X];
|
||||
var newStance = (Stance)order.TargetLocation.Y;
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace OpenRA
|
||||
Color = client.Color1;
|
||||
Color2 = client.Color2;
|
||||
PlayerName = client.Name;
|
||||
|
||||
InternalName = pr.Name;
|
||||
Country = world.GetCountries()
|
||||
.FirstOrDefault(c => client != null && client.Country == c.Race)
|
||||
|
||||
@@ -661,6 +661,11 @@ namespace OpenRA.Server
|
||||
DispatchOrders(asConn, 0, new ServerOrder("Chat", text).Serialize());
|
||||
}
|
||||
|
||||
static void SendDisconnected(Connection asConn)
|
||||
{
|
||||
DispatchOrders(asConn, 0, new ServerOrder("Disconnected", "").Serialize());
|
||||
}
|
||||
|
||||
static void InterpretServerOrder(Connection conn, ServerOrder so)
|
||||
{
|
||||
switch (so.Name)
|
||||
@@ -681,6 +686,7 @@ namespace OpenRA.Server
|
||||
|
||||
case "Chat":
|
||||
case "TeamChat":
|
||||
case "Disconnected":
|
||||
if (E(e => e.OnChat(conn, so.Data, so.Name == "TeamChat")))
|
||||
foreach (var c in conns.Except(conn).ToArray())
|
||||
DispatchOrdersToClient(c, GetClient(conn).Index, 0, so.Serialize());
|
||||
@@ -698,6 +704,9 @@ namespace OpenRA.Server
|
||||
conns.Remove(toDrop);
|
||||
SendChat(toDrop, "Connection Dropped");
|
||||
|
||||
if (GameStarted)
|
||||
SendDisconnected(toDrop); /* Report disconnection */
|
||||
|
||||
lobbyInfo.Clients.RemoveAll(c => c.Index == toDrop.PlayerIndex);
|
||||
|
||||
DispatchOrders( toDrop, toDrop.MostRecentFrame, new byte[] { 0xbf } );
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
<Compile Include="AttackMove.cs" />
|
||||
<Compile Include="Buildable.cs" />
|
||||
<Compile Include="Combat.cs" />
|
||||
<Compile Include="Player\SurrenderOnDisconnect.cs" />
|
||||
<Compile Include="Crates\CloakCrateAction.cs" />
|
||||
<Compile Include="Crates\GiveMcvCrateAction.cs" />
|
||||
<Compile Include="Crates\GiveUnitCrateAction.cs" />
|
||||
|
||||
44
OpenRA.Mods.RA/Player/SurrenderOnDisconnect.cs
Normal file
44
OpenRA.Mods.RA/Player/SurrenderOnDisconnect.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class SurrenderOnDisconnectInfo : TraitInfo<SurrenderOnDisconnect>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class SurrenderOnDisconnect : ITick
|
||||
{
|
||||
private bool Disconnected = false;
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (Disconnected) return;
|
||||
|
||||
var p = self.Owner;
|
||||
|
||||
if (p.WinState == WinState.Lost || p.WinState == WinState.Won) return; /* already won or lost */
|
||||
|
||||
var client = p.World.LobbyInfo.ClientWithIndex(p.ClientIndex);
|
||||
if (client == null)
|
||||
return;
|
||||
|
||||
if (client.State == Session.ClientState.Disconnected)
|
||||
{
|
||||
Disconnected = true; /* dont call this multiple times! */
|
||||
self.World.IssueOrder(new Order("Surrender", self));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ Player:
|
||||
PlayerColorPalette:
|
||||
BasePalette: terrain
|
||||
PaletteFormat: cnc
|
||||
|
||||
SurrenderOnDisconnect:
|
||||
World:
|
||||
OpenWidgetAtGameStart:
|
||||
Widget: INGAME_ROOT
|
||||
|
||||
@@ -124,6 +124,7 @@ Player:
|
||||
3tnk: 0%
|
||||
PlayerColorPalette:
|
||||
BasePalette: terrain
|
||||
SurrenderOnDisconnect:
|
||||
|
||||
World:
|
||||
OpenWidgetAtGameStart:
|
||||
|
||||
Reference in New Issue
Block a user