Readded voting (submarine, mode, end round & kick)
This commit is contained in:
@@ -169,7 +169,7 @@
|
|||||||
<Compile Include="Source\Particles\ParticleEmitter.cs" />
|
<Compile Include="Source\Particles\ParticleEmitter.cs" />
|
||||||
<Compile Include="Source\Networking\GameServerSettings.cs" />
|
<Compile Include="Source\Networking\GameServerSettings.cs" />
|
||||||
<Compile Include="Source\Screens\BlurEffect.cs" />
|
<Compile Include="Source\Screens\BlurEffect.cs" />
|
||||||
<Compile Include="Source\Screens\NetLobbyVoting.cs" />
|
<Compile Include="Source\Networking\Voting.cs" />
|
||||||
<Compile Include="Source\Screens\ServerListScreen.cs" />
|
<Compile Include="Source\Screens\ServerListScreen.cs" />
|
||||||
<Compile Include="Source\Timing.cs" />
|
<Compile Include="Source\Timing.cs" />
|
||||||
<Compile Include="Source\Utils\MTRandom.cs" />
|
<Compile Include="Source\Utils\MTRandom.cs" />
|
||||||
|
|||||||
@@ -2486,7 +2486,6 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (GameMain.Server != null) return null;
|
if (GameMain.Server != null) return null;
|
||||||
|
|
||||||
|
|
||||||
bool noInfo = inc.ReadBoolean();
|
bool noInfo = inc.ReadBoolean();
|
||||||
ushort id = inc.ReadUInt16();
|
ushort id = inc.ReadUInt16();
|
||||||
string configPath = inc.ReadString();
|
string configPath = inc.ReadString();
|
||||||
@@ -2540,6 +2539,14 @@ namespace Barotrauma
|
|||||||
character.memPos.Clear();
|
character.memPos.Clear();
|
||||||
character.memLocalPos.Clear();
|
character.memLocalPos.Clear();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var ownerClient = GameMain.Client.ConnectedClients.Find(c => c.ID == ownerId);
|
||||||
|
if (ownerClient != null)
|
||||||
|
{
|
||||||
|
ownerClient.Character = character;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (configPath == Character.HumanConfigFile)
|
if (configPath == Character.HumanConfigFile)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -239,14 +239,7 @@ namespace Barotrauma
|
|||||||
child.State = ComponentState.Hover;
|
child.State = ComponentState.Hover;
|
||||||
if (PlayerInput.LeftButtonClicked())
|
if (PlayerInput.LeftButtonClicked())
|
||||||
{
|
{
|
||||||
Debug.WriteLine("clicked");
|
|
||||||
Select(i);
|
Select(i);
|
||||||
//selected = child;
|
|
||||||
//if (OnSelected != null)
|
|
||||||
//{
|
|
||||||
// if (!OnSelected(selected, child.UserData)) selected = null;
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (selected.Contains(child))
|
else if (selected.Contains(child))
|
||||||
@@ -301,8 +294,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
bool wasSelected = true;
|
bool wasSelected = true;
|
||||||
if (OnSelected != null) wasSelected = OnSelected(children[childIndex], children[childIndex].UserData) || force;
|
if (OnSelected != null) wasSelected = OnSelected(children[childIndex], children[childIndex].UserData) || force;
|
||||||
|
|
||||||
|
|
||||||
if (!wasSelected) return;
|
if (!wasSelected) return;
|
||||||
|
|
||||||
if (SelectMultiple)
|
if (SelectMultiple)
|
||||||
|
|||||||
@@ -465,6 +465,8 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (gameStarted && Screen.Selected == GameMain.GameScreen)
|
if (gameStarted && Screen.Selected == GameMain.GameScreen)
|
||||||
{
|
{
|
||||||
|
endVoteTickBox.Visible = Voting.AllowEndVoting && myCharacter != null;
|
||||||
|
|
||||||
if (respawnManager != null)
|
if (respawnManager != null)
|
||||||
{
|
{
|
||||||
respawnManager.Update(deltaTime);
|
respawnManager.Update(deltaTime);
|
||||||
@@ -632,8 +634,6 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
gameStarted = true;
|
gameStarted = true;
|
||||||
|
|
||||||
endVoteTickBox.Visible = Voting.AllowEndVoting && myCharacter != null;
|
|
||||||
|
|
||||||
GameMain.GameScreen.Select();
|
GameMain.GameScreen.Select();
|
||||||
|
|
||||||
yield return CoroutineStatus.Success;
|
yield return CoroutineStatus.Success;
|
||||||
@@ -744,6 +744,9 @@ namespace Barotrauma.Networking
|
|||||||
string selectShuttleName = inc.ReadString();
|
string selectShuttleName = inc.ReadString();
|
||||||
string selectShuttleHash = inc.ReadString();
|
string selectShuttleHash = inc.ReadString();
|
||||||
|
|
||||||
|
bool allowSubVoting = inc.ReadBoolean();
|
||||||
|
bool allowModeVoting = inc.ReadBoolean();
|
||||||
|
|
||||||
YesNoMaybe traitorsEnabled = (YesNoMaybe)inc.ReadRangedInteger(0, 2);
|
YesNoMaybe traitorsEnabled = (YesNoMaybe)inc.ReadRangedInteger(0, 2);
|
||||||
int missionTypeIndex = inc.ReadRangedInteger(0, Mission.MissionTypes.Count - 1);
|
int missionTypeIndex = inc.ReadRangedInteger(0, Mission.MissionTypes.Count - 1);
|
||||||
int modeIndex = inc.ReadByte();
|
int modeIndex = inc.ReadByte();
|
||||||
@@ -754,10 +757,14 @@ namespace Barotrauma.Networking
|
|||||||
float autoRestartTimer = autoRestartEnabled ? inc.ReadFloat() : 0.0f;
|
float autoRestartTimer = autoRestartEnabled ? inc.ReadFloat() : 0.0f;
|
||||||
|
|
||||||
int clientCount = inc.ReadByte();
|
int clientCount = inc.ReadByte();
|
||||||
List<string> clientNames = new List<string>();
|
List<string> clientNames = new List<string>();
|
||||||
|
List<byte> clientIDs = new List<byte>();
|
||||||
|
List<ushort> characterIDs = new List<ushort>();
|
||||||
for (int i = 0; i < clientCount; i++)
|
for (int i = 0; i < clientCount; i++)
|
||||||
{
|
{
|
||||||
|
clientIDs.Add(inc.ReadByte());
|
||||||
clientNames.Add(inc.ReadString());
|
clientNames.Add(inc.ReadString());
|
||||||
|
characterIDs.Add(inc.ReadUInt16());
|
||||||
}
|
}
|
||||||
|
|
||||||
//ignore the message if we already a more up-to-date one
|
//ignore the message if we already a more up-to-date one
|
||||||
@@ -768,22 +775,40 @@ namespace Barotrauma.Networking
|
|||||||
GameMain.NetLobbyScreen.ServerName = serverName;
|
GameMain.NetLobbyScreen.ServerName = serverName;
|
||||||
GameMain.NetLobbyScreen.ServerMessage.Text = serverText;
|
GameMain.NetLobbyScreen.ServerMessage.Text = serverText;
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList);
|
if (!allowSubVoting)
|
||||||
|
{
|
||||||
|
GameMain.NetLobbyScreen.TrySelectSub(selectSubName, selectSubHash, GameMain.NetLobbyScreen.SubList);
|
||||||
|
}
|
||||||
GameMain.NetLobbyScreen.TrySelectSub(selectShuttleName, selectShuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox);
|
GameMain.NetLobbyScreen.TrySelectSub(selectShuttleName, selectShuttleHash, GameMain.NetLobbyScreen.ShuttleList.ListBox);
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);
|
GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);
|
||||||
GameMain.NetLobbyScreen.SetMissionType(missionTypeIndex);
|
GameMain.NetLobbyScreen.SetMissionType(missionTypeIndex);
|
||||||
GameMain.NetLobbyScreen.SelectMode(modeIndex);
|
|
||||||
|
if (!allowModeVoting)
|
||||||
|
{
|
||||||
|
GameMain.NetLobbyScreen.SelectMode(modeIndex);
|
||||||
|
}
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.LevelSeed = levelSeed;
|
GameMain.NetLobbyScreen.LevelSeed = levelSeed;
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.SetAutoRestart(autoRestartEnabled, autoRestartTimer);
|
GameMain.NetLobbyScreen.SetAutoRestart(autoRestartEnabled, autoRestartTimer);
|
||||||
|
|
||||||
|
ConnectedClients.Clear();
|
||||||
GameMain.NetLobbyScreen.ClearPlayers();
|
GameMain.NetLobbyScreen.ClearPlayers();
|
||||||
foreach (string clientName in clientNames)
|
for (int i = 0; i < clientNames.Count; i++)
|
||||||
{
|
{
|
||||||
GameMain.NetLobbyScreen.AddPlayer(clientName);
|
var newClient = new Client(clientNames[i], clientIDs[i]);
|
||||||
|
if (characterIDs[i] > 0)
|
||||||
|
{
|
||||||
|
newClient.Character = Entity.FindEntityByID(characterIDs[i]) as Character;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectedClients.Add(newClient);
|
||||||
|
GameMain.NetLobbyScreen.AddPlayer(newClient.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Voting.AllowSubVoting = allowSubVoting;
|
||||||
|
Voting.AllowModeVoting = allowModeVoting;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastSentChatMsgID = inc.ReadUInt32();
|
lastSentChatMsgID = inc.ReadUInt32();
|
||||||
@@ -791,6 +816,9 @@ namespace Barotrauma.Networking
|
|||||||
case ServerNetObject.CHAT_MESSAGE:
|
case ServerNetObject.CHAT_MESSAGE:
|
||||||
ChatMessage.ClientRead(inc);
|
ChatMessage.ClientRead(inc);
|
||||||
break;
|
break;
|
||||||
|
case ServerNetObject.VOTE:
|
||||||
|
Voting.ClientRead(inc);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1018,6 +1046,17 @@ namespace Barotrauma.Networking
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Vote(VoteType voteType, object data)
|
||||||
|
{
|
||||||
|
NetOutgoingMessage msg = client.CreateMessage();
|
||||||
|
msg.Write((byte)ClientPacketHeader.UPDATE_LOBBY);
|
||||||
|
msg.Write((byte)ClientNetObject.VOTE);
|
||||||
|
Voting.ClientWrite(msg, voteType, data);
|
||||||
|
msg.Write((byte)ServerNetObject.END_OF_MESSAGE);
|
||||||
|
|
||||||
|
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
||||||
|
}
|
||||||
|
|
||||||
public bool VoteForKick(GUIButton button, object userdata)
|
public bool VoteForKick(GUIButton button, object userdata)
|
||||||
{
|
{
|
||||||
var votedClient = otherClients.Find(c => c.Character == userdata);
|
var votedClient = otherClients.Find(c => c.Character == userdata);
|
||||||
@@ -1027,7 +1066,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (votedClient == null) return false;
|
if (votedClient == null) return false;
|
||||||
|
|
||||||
//Vote(VoteType.Kick, votedClient);
|
Vote(VoteType.Kick, votedClient);
|
||||||
|
|
||||||
button.Enabled = false;
|
button.Enabled = false;
|
||||||
|
|
||||||
@@ -1062,7 +1101,7 @@ namespace Barotrauma.Networking
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Vote(VoteType.EndRound, tickBox.Selected);
|
Vote(VoteType.EndRound, tickBox.Selected);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,8 +370,7 @@ namespace Barotrauma.Networking
|
|||||||
Log("Ending round (submarine reached the end of the level)", Color.Cyan);
|
Log("Ending round (submarine reached the end of the level)", Color.Cyan);
|
||||||
}
|
}
|
||||||
|
|
||||||
EndGame();
|
EndGame();
|
||||||
UpdateNetLobby(null,null);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -629,6 +628,9 @@ namespace Barotrauma.Networking
|
|||||||
case ClientNetObject.CHAT_MESSAGE:
|
case ClientNetObject.CHAT_MESSAGE:
|
||||||
ChatMessage.ServerRead(inc, c);
|
ChatMessage.ServerRead(inc, c);
|
||||||
break;
|
break;
|
||||||
|
case ClientNetObject.VOTE:
|
||||||
|
Voting.ServerRead(inc, c);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
//break;
|
//break;
|
||||||
@@ -694,7 +696,7 @@ namespace Barotrauma.Networking
|
|||||||
entityEventManager.Read(inc, c);
|
entityEventManager.Read(inc, c);
|
||||||
break;
|
break;
|
||||||
case ClientNetObject.VOTE:
|
case ClientNetObject.VOTE:
|
||||||
Voting.RegisterVote(inc, c);
|
Voting.ServerRead(inc, c);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@@ -815,6 +817,9 @@ namespace Barotrauma.Networking
|
|||||||
outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).Name);
|
outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).Name);
|
||||||
outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).MD5Hash.ToString());
|
outmsg.Write((GameMain.NetLobbyScreen.ShuttleList.SelectedData as Submarine).MD5Hash.ToString());
|
||||||
|
|
||||||
|
outmsg.Write(Voting.AllowSubVoting);
|
||||||
|
outmsg.Write(Voting.AllowModeVoting);
|
||||||
|
|
||||||
outmsg.WriteRangedInteger(0, 2, (int)TraitorsEnabled);
|
outmsg.WriteRangedInteger(0, 2, (int)TraitorsEnabled);
|
||||||
|
|
||||||
outmsg.WriteRangedInteger(0, Mission.MissionTypes.Count - 1, (GameMain.NetLobbyScreen.MissionTypeIndex));
|
outmsg.WriteRangedInteger(0, Mission.MissionTypes.Count - 1, (GameMain.NetLobbyScreen.MissionTypeIndex));
|
||||||
@@ -831,7 +836,9 @@ namespace Barotrauma.Networking
|
|||||||
outmsg.Write((byte)connectedClients.Count);
|
outmsg.Write((byte)connectedClients.Count);
|
||||||
foreach (Client client in connectedClients)
|
foreach (Client client in connectedClients)
|
||||||
{
|
{
|
||||||
|
outmsg.Write(client.ID);
|
||||||
outmsg.Write(client.name);
|
outmsg.Write(client.name);
|
||||||
|
outmsg.Write(client.Character == null || !gameStarted ? (ushort)0 : client.Character.ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -965,8 +972,7 @@ namespace Barotrauma.Networking
|
|||||||
//try again in >5 seconds
|
//try again in >5 seconds
|
||||||
if (autoRestart) AutoRestartTimer = Math.Max(AutoRestartInterval, 5.0f);
|
if (autoRestart) AutoRestartTimer = Math.Max(AutoRestartInterval, 5.0f);
|
||||||
GameMain.NetLobbyScreen.StartButton.Enabled = true;
|
GameMain.NetLobbyScreen.StartButton.Enabled = true;
|
||||||
|
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||||
UpdateNetLobby(null, null);
|
|
||||||
|
|
||||||
couldNotStart = true;
|
couldNotStart = true;
|
||||||
}
|
}
|
||||||
@@ -1294,6 +1300,8 @@ namespace Barotrauma.Networking
|
|||||||
GameMain.NetLobbyScreen.RemovePlayer(client.name);
|
GameMain.NetLobbyScreen.RemovePlayer(client.name);
|
||||||
connectedClients.Remove(client);
|
connectedClients.Remove(client);
|
||||||
|
|
||||||
|
UpdateVoteStatus();
|
||||||
|
|
||||||
AddChatMessage(msg, ChatMessageType.Server);
|
AddChatMessage(msg, ChatMessageType.Server);
|
||||||
|
|
||||||
UpdateCrewFrame();
|
UpdateCrewFrame();
|
||||||
@@ -1457,6 +1465,11 @@ namespace Barotrauma.Networking
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type == ChatMessageType.Server)
|
||||||
|
{
|
||||||
|
senderName = null;
|
||||||
|
}
|
||||||
|
|
||||||
var chatMsg = ChatMessage.Create(
|
var chatMsg = ChatMessage.Create(
|
||||||
senderName,
|
senderName,
|
||||||
modifiedMessage,
|
modifiedMessage,
|
||||||
@@ -1598,21 +1611,29 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
if (server.Connections.Count == 0) return;
|
if (server.Connections.Count == 0) return;
|
||||||
|
|
||||||
var clientsToKick = connectedClients.FindAll(c => c.KickVoteCount > connectedClients.Count * KickVoteRequiredRatio);
|
var clientsToKick = connectedClients.FindAll(c => c.KickVoteCount >= connectedClients.Count * KickVoteRequiredRatio);
|
||||||
//clientsToKick.ForEach(c => KickClient(c));
|
foreach (Client c in clientsToKick)
|
||||||
|
{
|
||||||
}
|
SendChatMessage(c.name+" has been kicked from the server.", ChatMessageType.Server, null);
|
||||||
|
KickClient(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||||
|
|
||||||
public bool UpdateNetLobby(object obj)
|
NetOutgoingMessage msg = server.CreateMessage();
|
||||||
{
|
msg.Write((byte)ServerPacketHeader.UPDATE_LOBBY);
|
||||||
return UpdateNetLobby(null, obj);
|
msg.Write((byte)ServerNetObject.VOTE);
|
||||||
}
|
Voting.ServerWrite(msg);
|
||||||
|
msg.Write((byte)ServerNetObject.END_OF_MESSAGE);
|
||||||
|
|
||||||
public bool UpdateNetLobby(GUIComponent component, object obj)
|
server.SendMessage(msg, connectedClients.Select(c => c.Connection).ToList(), NetDeliveryMethod.ReliableUnordered, 0);
|
||||||
{
|
|
||||||
if (server.Connections.Count == 0) return true;
|
if (Voting.AllowEndVoting && EndVoteMax > 0 &&
|
||||||
|
((float)EndVoteCount / (float)EndVoteMax) >= EndVoteRequiredRatio)
|
||||||
return true;
|
{
|
||||||
|
Log("Ending round by votes (" + EndVoteCount + "/" + (EndVoteMax - EndVoteCount) + ")", Color.Cyan);
|
||||||
|
EndGame();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateClientPermissions(Client client)
|
public void UpdateClientPermissions(Client client)
|
||||||
@@ -1757,8 +1778,6 @@ namespace Barotrauma.Networking
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateNetLobby(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Client FindClientWithJobPreference(List<Client> clients, JobPrefab job, bool forceAssign = false)
|
private Client FindClientWithJobPreference(List<Client> clients, JobPrefab job, bool forceAssign = false)
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
GameMain.NetLobbyScreen.AddPlayer(newClient.name);
|
GameMain.NetLobbyScreen.AddPlayer(newClient.name);
|
||||||
|
|
||||||
AddChatMessage(clName+" has joined the server.", ChatMessageType.Server);
|
GameMain.Server.SendChatMessage(clName + " has joined the server.", ChatMessageType.Server, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -774,7 +774,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;
|
Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;
|
||||||
|
|
||||||
if (subSelectionMode==SelectionMode.Random)
|
if (subSelectionMode == SelectionMode.Random)
|
||||||
{
|
{
|
||||||
GameMain.NetLobbyScreen.SubList.Select(Rand.Range(0, GameMain.NetLobbyScreen.SubList.CountChildren));
|
GameMain.NetLobbyScreen.SubList.Select(Rand.Range(0, GameMain.NetLobbyScreen.SubList.CountChildren));
|
||||||
}
|
}
|
||||||
|
|||||||
+175
-61
@@ -58,66 +58,6 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterVote(NetIncomingMessage inc, List<Client> connectedClients)
|
|
||||||
{
|
|
||||||
/*byte voteTypeByte = inc.ReadByte();
|
|
||||||
VoteType voteType = VoteType.Unknown;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
voteType = (VoteType)voteTypeByte;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
DebugConsole.ThrowError("Failed to cast vote type \""+voteTypeByte+"\"", e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Client sender = connectedClients.Find(x => x.Connection == inc.SenderConnection);
|
|
||||||
switch (voteType)
|
|
||||||
{
|
|
||||||
case VoteType.Sub:
|
|
||||||
string subName = inc.ReadString();
|
|
||||||
Submarine sub = Submarine.SavedSubmarines.Find(s => s.Name == subName);
|
|
||||||
sender.SetVote(voteType, sub);
|
|
||||||
UpdateVoteTexts(connectedClients, voteType);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VoteType.Mode:
|
|
||||||
string modeName = inc.ReadString();
|
|
||||||
GameModePreset mode = GameModePreset.list.Find(gm => gm.Name == modeName);
|
|
||||||
sender.SetVote(voteType, mode);
|
|
||||||
UpdateVoteTexts(connectedClients, voteType);
|
|
||||||
break;
|
|
||||||
case VoteType.EndRound:
|
|
||||||
if (sender.Character == null) return;
|
|
||||||
sender.SetVote(voteType, inc.ReadBoolean());
|
|
||||||
|
|
||||||
GameMain.NetworkMember.EndVoteCount = connectedClients.Count(c => c.Character != null && c.GetVote<bool>(VoteType.EndRound));
|
|
||||||
GameMain.NetworkMember.EndVoteMax = connectedClients.Count(c => c.Character != null);
|
|
||||||
|
|
||||||
break;
|
|
||||||
case VoteType.Kick:
|
|
||||||
|
|
||||||
byte kickedClientID = inc.ReadByte();
|
|
||||||
|
|
||||||
Client kicked = connectedClients.Find(x => x.ID == kickedClientID);
|
|
||||||
if (kicked == null) return;
|
|
||||||
|
|
||||||
kicked.AddKickVote(sender);
|
|
||||||
|
|
||||||
if (GameMain.Server != null)
|
|
||||||
{
|
|
||||||
GameMain.Server.SendChatMessage(
|
|
||||||
ChatMessage.Create("", sender.name + " has voted to kick " + kicked.name, ChatMessageType.Server, null),
|
|
||||||
GameMain.Server.ConnectedClients);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameMain.Server.UpdateVoteStatus();*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateVoteTexts(List<Client> clients, VoteType voteType)
|
public void UpdateVoteTexts(List<Client> clients, VoteType voteType)
|
||||||
{
|
{
|
||||||
GUIListBox listBox = (voteType == VoteType.Sub) ?
|
GUIListBox listBox = (voteType == VoteType.Sub) ?
|
||||||
@@ -162,7 +102,7 @@ namespace Barotrauma
|
|||||||
object vote = voter.GetVote<object>(voteType);
|
object vote = voter.GetVote<object>(voteType);
|
||||||
if (vote == null) continue;
|
if (vote == null) continue;
|
||||||
|
|
||||||
var existingVotable = voteList.Find(v => v.First == vote);
|
var existingVotable = voteList.Find(v => v.First == vote || v.First.Equals(vote));
|
||||||
if (existingVotable == null)
|
if (existingVotable == null)
|
||||||
{
|
{
|
||||||
voteList.Add(Pair<object, int>.Create(vote, 1));
|
voteList.Add(Pair<object, int>.Create(vote, 1));
|
||||||
@@ -209,6 +149,180 @@ namespace Barotrauma
|
|||||||
UpdateVoteTexts(connectedClients, VoteType.Mode);
|
UpdateVoteTexts(connectedClients, VoteType.Mode);
|
||||||
UpdateVoteTexts(connectedClients, VoteType.Sub);
|
UpdateVoteTexts(connectedClients, VoteType.Sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClientWrite(NetBuffer msg, VoteType voteType, object data)
|
||||||
|
{
|
||||||
|
if (GameMain.Server != null) return;
|
||||||
|
|
||||||
|
msg.Write((byte)voteType);
|
||||||
|
|
||||||
|
switch (voteType)
|
||||||
|
{
|
||||||
|
case VoteType.Sub:
|
||||||
|
Submarine sub = data as Submarine;
|
||||||
|
if (sub == null) return;
|
||||||
|
|
||||||
|
msg.Write(sub.Name);
|
||||||
|
break;
|
||||||
|
case VoteType.Mode:
|
||||||
|
GameModePreset gameMode = data as GameModePreset;
|
||||||
|
if (gameMode == null) return;
|
||||||
|
|
||||||
|
msg.Write(gameMode.Name);
|
||||||
|
break;
|
||||||
|
case VoteType.EndRound:
|
||||||
|
if (!(data is bool)) return;
|
||||||
|
|
||||||
|
msg.Write((bool)data);
|
||||||
|
break;
|
||||||
|
case VoteType.Kick:
|
||||||
|
Client votedClient = data as Client;
|
||||||
|
if (votedClient == null) return;
|
||||||
|
|
||||||
|
msg.Write(votedClient.ID);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.WritePadBits();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ServerRead(NetIncomingMessage inc, Client sender)
|
||||||
|
{
|
||||||
|
if (GameMain.Server == null || sender == null) return;
|
||||||
|
|
||||||
|
byte voteTypeByte = inc.ReadByte();
|
||||||
|
VoteType voteType = VoteType.Unknown;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
voteType = (VoteType)voteTypeByte;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Failed to cast vote type \"" + voteTypeByte + "\"", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (voteType)
|
||||||
|
{
|
||||||
|
case VoteType.Sub:
|
||||||
|
string subName = inc.ReadString();
|
||||||
|
Submarine sub = Submarine.SavedSubmarines.Find(s => s.Name == subName);
|
||||||
|
sender.SetVote(voteType, sub);
|
||||||
|
UpdateVoteTexts(GameMain.Server.ConnectedClients, voteType);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VoteType.Mode:
|
||||||
|
string modeName = inc.ReadString();
|
||||||
|
GameModePreset mode = GameModePreset.list.Find(gm => gm.Name == modeName);
|
||||||
|
sender.SetVote(voteType, mode);
|
||||||
|
UpdateVoteTexts(GameMain.Server.ConnectedClients, voteType);
|
||||||
|
break;
|
||||||
|
case VoteType.EndRound:
|
||||||
|
if (sender.Character == null) return;
|
||||||
|
sender.SetVote(voteType, inc.ReadBoolean());
|
||||||
|
|
||||||
|
GameMain.NetworkMember.EndVoteCount = GameMain.Server.ConnectedClients.Count(c => c.Character != null && c.GetVote<bool>(VoteType.EndRound));
|
||||||
|
GameMain.NetworkMember.EndVoteMax = GameMain.Server.ConnectedClients.Count(c => c.Character != null);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case VoteType.Kick:
|
||||||
|
byte kickedClientID = inc.ReadByte();
|
||||||
|
|
||||||
|
Client kicked = GameMain.Server.ConnectedClients.Find(c => c.ID == kickedClientID);
|
||||||
|
if (kicked == null) return;
|
||||||
|
|
||||||
|
kicked.AddKickVote(sender);
|
||||||
|
|
||||||
|
GameMain.Server.SendChatMessage(sender.name + " has voted to kick " + kicked.name, ChatMessageType.Server, null);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
inc.ReadPadBits();
|
||||||
|
|
||||||
|
GameMain.Server.UpdateVoteStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ServerWrite(NetBuffer msg)
|
||||||
|
{
|
||||||
|
if (GameMain.Server == null) return;
|
||||||
|
|
||||||
|
msg.Write(allowSubVoting);
|
||||||
|
if (allowSubVoting)
|
||||||
|
{
|
||||||
|
List<Pair<object, int>> voteList = GetVoteList(VoteType.Sub, GameMain.Server.ConnectedClients);
|
||||||
|
msg.Write((byte)voteList.Count);
|
||||||
|
foreach (Pair<object, int> vote in voteList)
|
||||||
|
{
|
||||||
|
msg.Write((byte)vote.Second);
|
||||||
|
msg.Write(((Submarine)vote.First).Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msg.Write(AllowModeVoting);
|
||||||
|
if (allowModeVoting)
|
||||||
|
{
|
||||||
|
List<Pair<object, int>> voteList = GetVoteList(VoteType.Mode, GameMain.Server.ConnectedClients);
|
||||||
|
msg.Write((byte)voteList.Count);
|
||||||
|
foreach (Pair<object, int> vote in voteList)
|
||||||
|
{
|
||||||
|
msg.Write((byte)vote.Second);
|
||||||
|
msg.Write(((GameModePreset)vote.First).Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msg.Write(AllowEndVoting);
|
||||||
|
if (AllowEndVoting)
|
||||||
|
{
|
||||||
|
msg.Write((byte)GameMain.Server.ConnectedClients.Count(v => v.GetVote<bool>(VoteType.EndRound)));
|
||||||
|
msg.Write((byte)GameMain.Server.ConnectedClients.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.Write(AllowVoteKick);
|
||||||
|
|
||||||
|
msg.WritePadBits();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClientRead(NetIncomingMessage inc)
|
||||||
|
{
|
||||||
|
if (GameMain.Server != null) return;
|
||||||
|
|
||||||
|
AllowSubVoting = inc.ReadBoolean();
|
||||||
|
if (allowSubVoting)
|
||||||
|
{
|
||||||
|
foreach (Submarine sub in Submarine.SavedSubmarines)
|
||||||
|
{
|
||||||
|
SetVoteText(GameMain.NetLobbyScreen.SubList, sub, 0);
|
||||||
|
}
|
||||||
|
int votableCount = inc.ReadByte();
|
||||||
|
for (int i = 0; i < votableCount; i++)
|
||||||
|
{
|
||||||
|
int votes = inc.ReadByte();
|
||||||
|
string subName = inc.ReadString();
|
||||||
|
Submarine sub = Submarine.SavedSubmarines.Find(sm => sm.Name == subName);
|
||||||
|
SetVoteText(GameMain.NetLobbyScreen.SubList, sub, votes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AllowModeVoting = inc.ReadBoolean();
|
||||||
|
if (allowModeVoting)
|
||||||
|
{
|
||||||
|
int votableCount = inc.ReadByte();
|
||||||
|
for (int i = 0; i < votableCount; i++)
|
||||||
|
{
|
||||||
|
int votes = inc.ReadByte();
|
||||||
|
string modeName = inc.ReadString();
|
||||||
|
GameModePreset mode = GameModePreset.list.Find(m => m.Name == modeName);
|
||||||
|
SetVoteText(GameMain.NetLobbyScreen.ModeList, mode, votes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AllowEndVoting = inc.ReadBoolean();
|
||||||
|
if (AllowEndVoting)
|
||||||
|
{
|
||||||
|
GameMain.NetworkMember.EndVoteCount = inc.ReadByte();
|
||||||
|
GameMain.NetworkMember.EndVoteMax = inc.ReadByte();
|
||||||
|
}
|
||||||
|
AllowVoteKick = inc.ReadBoolean();
|
||||||
|
|
||||||
|
inc.ReadPadBits();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -382,8 +382,8 @@ namespace Barotrauma
|
|||||||
missionTypeButtons[0].Enabled = GameMain.Server != null;
|
missionTypeButtons[0].Enabled = GameMain.Server != null;
|
||||||
missionTypeButtons[1].Enabled = GameMain.Server != null;
|
missionTypeButtons[1].Enabled = GameMain.Server != null;
|
||||||
|
|
||||||
ServerName = (GameMain.Server==null) ? "Server" : GameMain.Server.Name;
|
ServerName = (GameMain.Server == null) ? "Server" : GameMain.Server.Name;
|
||||||
|
|
||||||
infoFrame.RemoveChild(StartButton);
|
infoFrame.RemoveChild(StartButton);
|
||||||
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "settingsButton"));
|
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "settingsButton"));
|
||||||
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "spectateButton"));
|
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "spectateButton"));
|
||||||
@@ -732,7 +732,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (GameMain.Client == null) return false;
|
if (GameMain.Client == null) return false;
|
||||||
|
|
||||||
VoteType voteType = VoteType.Unknown;
|
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) return false;
|
||||||
@@ -748,7 +748,7 @@ namespace Barotrauma
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//GameMain.Client.Vote(voteType, userData);
|
GameMain.Client.Vote(voteType, userData);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1195,7 +1195,9 @@ namespace Barotrauma
|
|||||||
var matchingListSub = subList.children.Find(c => c.UserData != null && (c.UserData as Submarine).Name == subName) as GUITextBlock;
|
var matchingListSub = subList.children.Find(c => c.UserData != null && (c.UserData as Submarine).Name == subName) as GUITextBlock;
|
||||||
if (matchingListSub != null)
|
if (matchingListSub != null)
|
||||||
{
|
{
|
||||||
|
subList.OnSelected -= VotableClicked;
|
||||||
subList.Select(subList.children.IndexOf(matchingListSub), true);
|
subList.Select(subList.children.IndexOf(matchingListSub), true);
|
||||||
|
subList.OnSelected += VotableClicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
Submarine sub = Submarine.SavedSubmarines.Find(m => m.Name == subName);
|
Submarine sub = Submarine.SavedSubmarines.Find(m => m.Name == subName);
|
||||||
|
|||||||
Reference in New Issue
Block a user