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

View File

@@ -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();

View File

@@ -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

View File

@@ -112,6 +112,7 @@ namespace Barotrauma
public Submarine SelectedSub
{
get { return subList.SelectedData as Submarine; }
set { subList.Select(value); }
}
public Submarine SelectedShuttle
@@ -384,10 +385,14 @@ namespace Barotrauma
Character.Controlled = null;
//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;
//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;
serverMessage.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.Enabled = false;
int i = 1;
foreach (string jobName in GameMain.Config.JobNamePreferences)
{
@@ -757,13 +761,29 @@ namespace Barotrauma
VoteType voteType;
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;
}
else if (component.Parent == GameMain.NetLobbyScreen.ModeList)
{
if (!GameMain.Client.Voting.AllowModeVoting) 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;
}
@@ -843,7 +863,7 @@ namespace Barotrauma
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.UserData = selectedClient;
@@ -858,7 +878,7 @@ namespace Barotrauma
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.Selected = selectedClient.HasPermission(permission);

View File

@@ -16,8 +16,12 @@ namespace Barotrauma.Networking
Kick = 2,
[Description("Ban")]
Ban = 4,
[Description("Select submarine")]
SelectSub = 8,
[Description("Select game mode")]
SelectMode = 16,
[Description("Manage campaign")]
ManageCampaign = 8
ManageCampaign = 32
}
class Client

View File

@@ -770,6 +770,22 @@ namespace Barotrauma.Networking
EndGame();
}
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:
MultiplayerCampaign campaign = GameMain.GameSession.GameMode as MultiplayerCampaign;
if (campaign != null)