Clients can be given a permission to select the sub or the game mode

This commit is contained in:
Joonas Rikkonen
2017-09-24 17:11:10 +03:00
parent 04b0c63f30
commit 5eb1544f1e
5 changed files with 104 additions and 12 deletions
@@ -620,12 +620,15 @@ namespace Barotrauma.Networking
if (!newPermissions.HasFlag(permission) || permission == ClientPermissions.None) continue;
System.Reflection.FieldInfo fi = typeof(ClientPermissions).GetField(permission.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
msg += " - " + attributes[0].Description+"\n";
msg += " - " + attributes[0].Description + "\n";
}
}
permissions = newPermissions;
new GUIMessageBox("Permissions changed", msg).UserData = "permissions";
GameMain.NetLobbyScreen.SubList.Enabled = Voting.AllowSubVoting || HasPermission(ClientPermissions.SelectSub);
GameMain.NetLobbyScreen.ModeList.Enabled = Voting.AllowModeVoting || HasPermission(ClientPermissions.SelectMode);
endRoundButton.Visible = HasPermission(ClientPermissions.EndRound);
}
@@ -1326,6 +1329,51 @@ namespace Barotrauma.Networking
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
}
/// <summary>
/// Tell the server to select a submarine (permission required)
/// </summary>
public void RequestSelectSub(int subIndex)
{
if (!HasPermission(ClientPermissions.SelectSub)) return;
if (subIndex < 0 || subIndex >= GameMain.NetLobbyScreen.SubList.CountChildren)
{
DebugConsole.ThrowError("Submarine index out of bounds (" + subIndex + ")\n" + Environment.StackTrace);
return;
}
NetOutgoingMessage msg = client.CreateMessage();
msg.Write((byte)ClientPacketHeader.SERVER_COMMAND);
msg.Write((byte)ClientPermissions.SelectSub);
msg.Write((UInt16)subIndex);
msg.Write((byte)ServerNetObject.END_OF_MESSAGE);
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
}
/// <summary>
/// Tell the server to select a submarine (permission required)
/// </summary>
public void RequestSelectMode(int modeIndex)
{
if (!HasPermission(ClientPermissions.SelectMode)) return;
if (modeIndex < 0 || modeIndex >= GameMain.NetLobbyScreen.ModeList.CountChildren)
{
DebugConsole.ThrowError("Gamemode index out of bounds (" + modeIndex + ")\n" + Environment.StackTrace);
return;
}
NetOutgoingMessage msg = client.CreateMessage();
msg.Write((byte)ClientPacketHeader.SERVER_COMMAND);
msg.Write((byte)ClientPermissions.SelectMode);
msg.Write((UInt16)modeIndex);
msg.Write((byte)ServerNetObject.END_OF_MESSAGE);
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
}
/// <summary>
/// Tell the server to end the round (permission required)
/// </summary>
public void RequestRoundEnd()
{
NetOutgoingMessage msg = client.CreateMessage();
@@ -14,7 +14,8 @@ namespace Barotrauma
{
if (value == allowSubVoting) return;
allowSubVoting = value;
GameMain.NetLobbyScreen.SubList.Enabled = value || GameMain.Server != null;
GameMain.NetLobbyScreen.SubList.Enabled = value || GameMain.Server != null ||
(GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectSub));
GameMain.NetLobbyScreen.InfoFrame.FindChild("subvotes", true).Visible = value;
if (GameMain.Server != null)
@@ -36,7 +37,10 @@ namespace Barotrauma
{
if (value == allowModeVoting) return;
allowModeVoting = value;
GameMain.NetLobbyScreen.ModeList.Enabled = value || GameMain.Server != null;
GameMain.NetLobbyScreen.ModeList.Enabled =
value || GameMain.Server != null ||
(GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectMode));
GameMain.NetLobbyScreen.InfoFrame.FindChild("modevotes", true).Visible = value;
//gray out modes that can't be voted