edited the LobbyLogic to include a spectator toggle in the server admin dropdown.
This commit is contained in:
@@ -127,6 +127,7 @@ namespace OpenRA.Network
|
|||||||
public int RandomSeed = 0;
|
public int RandomSeed = 0;
|
||||||
public bool FragileAlliances = false; // Allow diplomatic stance changes after game start.
|
public bool FragileAlliances = false; // Allow diplomatic stance changes after game start.
|
||||||
public bool AllowCheats = false;
|
public bool AllowCheats = false;
|
||||||
|
public bool AllowSpectate = true;
|
||||||
public bool Dedicated;
|
public bool Dedicated;
|
||||||
public string Difficulty;
|
public string Difficulty;
|
||||||
public bool Crates = true;
|
public bool Crates = true;
|
||||||
|
|||||||
@@ -276,6 +276,13 @@ namespace OpenRA.Server
|
|||||||
IsAdmin = !LobbyInfo.Clients.Any(c1 => c1.IsAdmin)
|
IsAdmin = !LobbyInfo.Clients.Any(c1 => c1.IsAdmin)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (client.IsObserver && !LobbyInfo.GlobalSettings.AllowSpectate)
|
||||||
|
{
|
||||||
|
SendOrderTo(newConn, "ServerError", "The game is full");
|
||||||
|
DropClient(newConn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (client.Slot != null)
|
if (client.Slot != null)
|
||||||
SyncClientToPlayerReference(client, Map.Players[client.Slot]);
|
SyncClientToPlayerReference(client, Map.Players[client.Slot]);
|
||||||
else
|
else
|
||||||
@@ -317,7 +324,7 @@ namespace OpenRA.Server
|
|||||||
LobbyInfo.Clients.Add(client);
|
LobbyInfo.Clients.Add(client);
|
||||||
|
|
||||||
Log.Write("server", "Client {0}: Accepted connection from {1}.",
|
Log.Write("server", "Client {0}: Accepted connection from {1}.",
|
||||||
newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
|
newConn.PlayerIndex, newConn.socket.RemoteEndPoint);
|
||||||
|
|
||||||
foreach (var t in serverTraits.WithInterface<IClientJoined>())
|
foreach (var t in serverTraits.WithInterface<IClientJoined>())
|
||||||
t.ClientJoined(this, newConn);
|
t.ClientJoined(this, newConn);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -75,7 +75,8 @@ namespace OpenRA.Mods.RA.Server
|
|||||||
numBots,
|
numBots,
|
||||||
"{0}@{1}".F(mod.Id, mod.Version),
|
"{0}@{1}".F(mod.Id, mod.Version),
|
||||||
server.LobbyInfo.GlobalSettings.Map,
|
server.LobbyInfo.GlobalSettings.Map,
|
||||||
server.Map.PlayerCount));
|
server.Map.PlayerCount,
|
||||||
|
server.LobbyInfo.GlobalSettings.AllowSpectate));
|
||||||
|
|
||||||
if (isInitialPing)
|
if (isInitialPing)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON");
|
var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON");
|
||||||
if (slotsButton != null)
|
if (slotsButton != null)
|
||||||
{
|
{
|
||||||
@@ -613,6 +614,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add spectators
|
// Add spectators
|
||||||
foreach (var client in orderManager.LobbyInfo.Clients.Where(client => client.Slot == null))
|
foreach (var client in orderManager.LobbyInfo.Clients.Where(client => client.Slot == null))
|
||||||
{
|
{
|
||||||
@@ -653,27 +655,48 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spectate button
|
// Spectate button
|
||||||
if (orderManager.LocalClient.Slot != null)
|
if (orderManager.LocalClient.Slot != null)
|
||||||
{
|
{
|
||||||
Widget spec = null;
|
|
||||||
if (idx < Players.Children.Count)
|
|
||||||
spec = Players.Children[idx];
|
|
||||||
if (spec == null || spec.Id != NewSpectatorTemplate.Id)
|
|
||||||
spec = NewSpectatorTemplate.Clone();
|
|
||||||
|
|
||||||
var btn = spec.Get<ButtonWidget>("SPECTATE");
|
Widget spec = null;
|
||||||
btn.OnClick = () => orderManager.IssueOrder(Order.Command("spectate"));
|
if (idx < Players.Children.Count)
|
||||||
btn.IsDisabled = () => orderManager.LocalClient.IsReady;
|
spec = Players.Children[idx];
|
||||||
spec.IsVisible = () => true;
|
if (spec == null || spec.Id != NewSpectatorTemplate.Id)
|
||||||
|
spec = NewSpectatorTemplate.Clone();
|
||||||
|
|
||||||
if (idx >= Players.Children.Count)
|
var block = spec.Get<ButtonWidget>("BLOCK_SPECTATE");
|
||||||
Players.AddChild(spec);
|
block.OnClick = () =>
|
||||||
else if (Players.Children[idx].Id != spec.Id)
|
{
|
||||||
Players.ReplaceChild(Players.Children[idx], spec);
|
orderManager.IssueOrder(Order.Command("allow_spectate False"));
|
||||||
|
orderManager.IssueOrders(
|
||||||
|
orderManager.LobbyInfo.Clients.Where(
|
||||||
|
c => c.IsObserver && !c.IsAdmin).Select(
|
||||||
|
client => Order.Command(String.Format("kick {0} {1}", client.Index, client.Name
|
||||||
|
))).ToArray());
|
||||||
|
};
|
||||||
|
block.IsVisible = () => orderManager.LocalClient.IsAdmin && orderManager.LobbyInfo.GlobalSettings.AllowSpectate;
|
||||||
|
block.IsDisabled = () => !orderManager.LobbyInfo.GlobalSettings.AllowSpectate;
|
||||||
|
|
||||||
|
var allow = spec.Get<ButtonWidget>("ALLOW_SPECTATE");
|
||||||
|
allow.OnClick = () => orderManager.IssueOrder(Order.Command("allow_spectate True"));
|
||||||
|
allow.IsVisible = () => orderManager.LocalClient.IsAdmin && !orderManager.LobbyInfo.GlobalSettings.AllowSpectate;
|
||||||
|
allow.IsDisabled = () => orderManager.LobbyInfo.GlobalSettings.AllowSpectate;
|
||||||
|
|
||||||
|
var btn = spec.Get<ButtonWidget>("SPECTATE");
|
||||||
|
btn.OnClick = () => orderManager.IssueOrder(Order.Command("spectate"));
|
||||||
|
btn.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||||
|
btn.IsVisible = () => orderManager.LobbyInfo.GlobalSettings.AllowSpectate;
|
||||||
|
spec.IsVisible = () => true;
|
||||||
|
|
||||||
|
if (idx >= Players.Children.Count)
|
||||||
|
Players.AddChild(spec);
|
||||||
|
else if (Players.Children[idx].Id != spec.Id)
|
||||||
|
Players.ReplaceChild(Players.Children[idx], spec);
|
||||||
|
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (Players.Children.Count > idx)
|
while (Players.Children.Count > idx)
|
||||||
Players.RemoveChild(Players.Children[idx]);
|
Players.RemoveChild(Players.Children[idx]);
|
||||||
|
|||||||
@@ -307,10 +307,24 @@ ScrollPanel@LOBBY_PLAYER_BIN:
|
|||||||
Height:25
|
Height:25
|
||||||
Visible:false
|
Visible:false
|
||||||
Children:
|
Children:
|
||||||
|
Button@ALLOW_SPECTATE:
|
||||||
|
Text:Allow Spectators
|
||||||
|
Font:Regular
|
||||||
|
Width:190
|
||||||
|
Height:25
|
||||||
|
Y:0
|
||||||
|
X:15
|
||||||
|
Button@BLOCK_SPECTATE:
|
||||||
|
Text:Block Spectators
|
||||||
|
Font:Regular
|
||||||
|
Width:190
|
||||||
|
Height:25
|
||||||
|
Y:0
|
||||||
|
X:15
|
||||||
Button@SPECTATE:
|
Button@SPECTATE:
|
||||||
Text:Spectate
|
Text:Spectate
|
||||||
Font:Regular
|
Font:Regular
|
||||||
Width:453
|
Width:257
|
||||||
Height:25
|
Height:25
|
||||||
X:15
|
X:210
|
||||||
Y:0
|
Y:0
|
||||||
@@ -298,6 +298,20 @@ ScrollPanel@LOBBY_PLAYER_BIN:
|
|||||||
Height:25
|
Height:25
|
||||||
Visible:false
|
Visible:false
|
||||||
Children:
|
Children:
|
||||||
|
Button@ALLOW_SPECTATE:
|
||||||
|
Text:Allow Spectators
|
||||||
|
Font:Regular
|
||||||
|
Width:165
|
||||||
|
Height:25
|
||||||
|
X:15
|
||||||
|
Y:0
|
||||||
|
Button@BLOCK_SPECTATE:
|
||||||
|
Text:Block Spectators
|
||||||
|
Font:Regular
|
||||||
|
Width:165
|
||||||
|
Height:25
|
||||||
|
X:15
|
||||||
|
Y:0
|
||||||
Button@SPECTATE:
|
Button@SPECTATE:
|
||||||
Text:Spectate
|
Text:Spectate
|
||||||
Font:Regular
|
Font:Regular
|
||||||
|
|||||||
@@ -298,6 +298,20 @@ ScrollPanel@LOBBY_PLAYER_BIN:
|
|||||||
Height:25
|
Height:25
|
||||||
Visible:false
|
Visible:false
|
||||||
Children:
|
Children:
|
||||||
|
Button@ALLOW_SPECTATE:
|
||||||
|
Text:Allow Spectators
|
||||||
|
Font:Regular
|
||||||
|
Width:165
|
||||||
|
Height:25
|
||||||
|
X:15
|
||||||
|
Y:0
|
||||||
|
Button@BLOCK_SPECTATE:
|
||||||
|
Text:Block Spectators
|
||||||
|
Font:Regular
|
||||||
|
Width:165
|
||||||
|
Height:25
|
||||||
|
X:15
|
||||||
|
Y:0
|
||||||
Button@SPECTATE:
|
Button@SPECTATE:
|
||||||
Text:Spectate
|
Text:Spectate
|
||||||
Font:Regular
|
Font:Regular
|
||||||
|
|||||||
Reference in New Issue
Block a user