edited the LobbyLogic to include a spectator toggle in the server admin dropdown.

This commit is contained in:
Matthew Uzzell
2014-02-15 21:07:41 +00:00
parent 4075742d19
commit 88121b272d
8 changed files with 839 additions and 747 deletions

View File

@@ -127,6 +127,7 @@ namespace OpenRA.Network
public int RandomSeed = 0;
public bool FragileAlliances = false; // Allow diplomatic stance changes after game start.
public bool AllowCheats = false;
public bool AllowSpectate = true;
public bool Dedicated;
public string Difficulty;
public bool Crates = true;

View File

@@ -276,6 +276,13 @@ namespace OpenRA.Server
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)
SyncClientToPlayerReference(client, Map.Players[client.Slot]);
else

View File

@@ -132,14 +132,32 @@ namespace OpenRA.Mods.RA.Server
return true;
}},
{ "allow_spectate",
s =>
{
s = s.Trim();
if(s.Equals("True") || s.Equals("False")){
bool.TryParse(s, out server.LobbyInfo.GlobalSettings.AllowSpectate);
server.SyncLobbyInfo();
return true;
}else{
server.SendOrderTo(conn, "Message", "Malformed allow_spectate command");
return true;
}
}},
{ "spectate",
s =>
{
if(server.LobbyInfo.GlobalSettings.AllowSpectate){
client.Slot = null;
client.SpawnPoint = 0;
client.Color = HSLColor.FromRGB(255, 255, 255);
server.SyncLobbyInfo();
return true;
}else{
return false;
}
}},
{ "slot_close",
s =>

View File

@@ -75,7 +75,8 @@ namespace OpenRA.Mods.RA.Server
numBots,
"{0}@{1}".F(mod.Id, mod.Version),
server.LobbyInfo.GlobalSettings.Map,
server.Map.PlayerCount));
server.Map.PlayerCount,
server.LobbyInfo.GlobalSettings.AllowSpectate));
if (isInitialPing)
{

View File

@@ -173,6 +173,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
};
}
var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON");
if (slotsButton != null)
{
@@ -613,6 +614,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
idx++;
}
// Add spectators
foreach (var client in orderManager.LobbyInfo.Clients.Where(client => client.Slot == null))
{
@@ -656,15 +658,35 @@ namespace OpenRA.Mods.RA.Widgets.Logic
// Spectate button
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 block = spec.Get<ButtonWidget>("BLOCK_SPECTATE");
block.OnClick = () =>
{
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)
@@ -675,6 +697,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
idx++;
}
while (Players.Children.Count > idx)
Players.RemoveChild(Players.Children[idx]);
}

View File

@@ -307,10 +307,24 @@ ScrollPanel@LOBBY_PLAYER_BIN:
Height:25
Visible:false
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:
Text:Spectate
Font:Regular
Width:453
Width:257
Height:25
X:15
X:210
Y:0

View File

@@ -298,6 +298,20 @@ ScrollPanel@LOBBY_PLAYER_BIN:
Height:25
Visible:false
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:
Text:Spectate
Font:Regular

View File

@@ -298,6 +298,20 @@ ScrollPanel@LOBBY_PLAYER_BIN:
Height:25
Visible:false
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:
Text:Spectate
Font:Regular