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; if (!newPermissions.HasFlag(permission) || permission == ClientPermissions.None) continue;
System.Reflection.FieldInfo fi = typeof(ClientPermissions).GetField(permission.ToString()); System.Reflection.FieldInfo fi = typeof(ClientPermissions).GetField(permission.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
msg += " - " + attributes[0].Description+"\n"; msg += " - " + attributes[0].Description + "\n";
} }
} }
permissions = newPermissions; permissions = newPermissions;
new GUIMessageBox("Permissions changed", msg).UserData = "permissions"; 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); endRoundButton.Visible = HasPermission(ClientPermissions.EndRound);
} }
@@ -1326,6 +1329,51 @@ namespace Barotrauma.Networking
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered); 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() public void RequestRoundEnd()
{ {
NetOutgoingMessage msg = client.CreateMessage(); NetOutgoingMessage msg = client.CreateMessage();
@@ -14,7 +14,8 @@ namespace Barotrauma
{ {
if (value == allowSubVoting) return; if (value == allowSubVoting) return;
allowSubVoting = value; 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; GameMain.NetLobbyScreen.InfoFrame.FindChild("subvotes", true).Visible = value;
if (GameMain.Server != null) if (GameMain.Server != null)
@@ -36,7 +37,10 @@ namespace Barotrauma
{ {
if (value == allowModeVoting) return; if (value == allowModeVoting) return;
allowModeVoting = value; 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; GameMain.NetLobbyScreen.InfoFrame.FindChild("modevotes", true).Visible = value;
//gray out modes that can't be voted //gray out modes that can't be voted
@@ -112,6 +112,7 @@ namespace Barotrauma
public Submarine SelectedSub public Submarine SelectedSub
{ {
get { return subList.SelectedData as Submarine; } get { return subList.SelectedData as Submarine; }
set { subList.Select(value); }
} }
public Submarine SelectedShuttle public Submarine SelectedShuttle
@@ -384,10 +385,14 @@ namespace Barotrauma
Character.Controlled = null; Character.Controlled = null;
//GameMain.GameScreen.Cam.TargetPos = Vector2.Zero; //GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
subList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowSubVoting; subList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowSubVoting ||
(GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectSub));
shuttleList.Enabled = subList.Enabled; shuttleList.Enabled = subList.Enabled;
//playerList.Enabled = GameMain.Server != null;
modeList.Enabled = GameMain.Server != null || GameMain.NetworkMember.Voting.AllowModeVoting; modeList.Enabled =
GameMain.Server != null || GameMain.NetworkMember.Voting.AllowModeVoting ||
(GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.SelectMode));
seedBox.Enabled = GameMain.Server != null; seedBox.Enabled = GameMain.Server != null;
serverMessage.Enabled = GameMain.Server != null; serverMessage.Enabled = GameMain.Server != null;
autoRestartBox.Enabled = GameMain.Server != null; autoRestartBox.Enabled = GameMain.Server != null;
@@ -549,7 +554,6 @@ namespace Barotrauma
jobList = new GUIListBox(new Rectangle(0, 150, 0, 0), "", myPlayerFrame); jobList = new GUIListBox(new Rectangle(0, 150, 0, 0), "", myPlayerFrame);
jobList.Enabled = false; jobList.Enabled = false;
int i = 1; int i = 1;
foreach (string jobName in GameMain.Config.JobNamePreferences) foreach (string jobName in GameMain.Config.JobNamePreferences)
{ {
@@ -757,13 +761,29 @@ namespace Barotrauma
VoteType voteType; VoteType voteType;
if (component.Parent == GameMain.NetLobbyScreen.SubList) if (component.Parent == GameMain.NetLobbyScreen.SubList)
{ {
if (!GameMain.Client.Voting.AllowSubVoting) return false; if (!GameMain.Client.Voting.AllowSubVoting)
{
if (GameMain.Client.HasPermission(ClientPermissions.SelectSub))
{
GameMain.Client.RequestSelectSub(component.Parent.children.IndexOf(component));
return true;
}
return false;
}
voteType = VoteType.Sub; voteType = VoteType.Sub;
} }
else if (component.Parent == GameMain.NetLobbyScreen.ModeList) else if (component.Parent == GameMain.NetLobbyScreen.ModeList)
{ {
if (!GameMain.Client.Voting.AllowModeVoting) return false;
if (!((GameModePreset)userData).Votable) return false; if (!((GameModePreset)userData).Votable) return false;
if (!GameMain.Client.Voting.AllowModeVoting)
{
if (GameMain.Client.HasPermission(ClientPermissions.SelectMode))
{
GameMain.Client.RequestSelectMode(component.Parent.children.IndexOf(component));
return true;
}
return false;
}
voteType = VoteType.Mode; voteType = VoteType.Mode;
} }
@@ -843,7 +863,7 @@ namespace Barotrauma
new GUITextBlock(new Rectangle(0, 25, 150, 15), selectedClient.Connection.RemoteEndPoint.Address.ToString(), "", playerFrameInner); new GUITextBlock(new Rectangle(0, 25, 150, 15), selectedClient.Connection.RemoteEndPoint.Address.ToString(), "", playerFrameInner);
var permissionsBox = new GUIFrame(new Rectangle(0, 60, 0, 90), "", playerFrameInner); var permissionsBox = new GUIFrame(new Rectangle(0, 60, 0, 90), null, playerFrameInner);
permissionsBox.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); permissionsBox.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
permissionsBox.UserData = selectedClient; permissionsBox.UserData = selectedClient;
@@ -858,7 +878,7 @@ namespace Barotrauma
string permissionStr = attributes.Length > 0 ? attributes[0].Description : permission.ToString(); string permissionStr = attributes.Length > 0 ? attributes[0].Description : permission.ToString();
var permissionTick = new GUITickBox(new Rectangle(x, y + 20, 15, 15), permissionStr, Alignment.TopLeft, GUI.SmallFont, permissionsBox); var permissionTick = new GUITickBox(new Rectangle(x, y + 25, 15, 15), permissionStr, Alignment.TopLeft, GUI.SmallFont, permissionsBox);
permissionTick.UserData = permission; permissionTick.UserData = permission;
permissionTick.Selected = selectedClient.HasPermission(permission); permissionTick.Selected = selectedClient.HasPermission(permission);
@@ -16,8 +16,12 @@ namespace Barotrauma.Networking
Kick = 2, Kick = 2,
[Description("Ban")] [Description("Ban")]
Ban = 4, Ban = 4,
[Description("Select submarine")]
SelectSub = 8,
[Description("Select game mode")]
SelectMode = 16,
[Description("Manage campaign")] [Description("Manage campaign")]
ManageCampaign = 8 ManageCampaign = 32
} }
class Client class Client
@@ -770,6 +770,22 @@ namespace Barotrauma.Networking
EndGame(); EndGame();
} }
break; break;
case ClientPermissions.SelectSub:
UInt16 subIndex = inc.ReadUInt16();
var subList = GameMain.NetLobbyScreen.GetSubList();
if (subIndex >= subList.Count)
{
DebugConsole.NewMessage("Client \"" + sender.name + "\" attempted to select a sub, index out of bounds (" + subIndex + ")", Color.Red);
}
else
{
GameMain.NetLobbyScreen.SelectedSub = subList[subIndex];
}
break;
case ClientPermissions.SelectMode:
UInt16 modeIndex = inc.ReadUInt16();
var modeList = GameMain.NetLobbyScreen.SelectedModeIndex = modeIndex;
break;
case ClientPermissions.ManageCampaign: case ClientPermissions.ManageCampaign:
MultiplayerCampaign campaign = GameMain.GameSession.GameMode as MultiplayerCampaign; MultiplayerCampaign campaign = GameMain.GameSession.GameMode as MultiplayerCampaign;
if (campaign != null) if (campaign != null)