Files
LuaCsForBarotraumaEP/Barotrauma/BarotraumaServer/Source/Networking/Voting.cs
T
Joonas Rikkonen cc9ae260a3 58005a8...01f115d
commit 01f115d32d768c76d01bc5fad5cfe2e3f88333cc
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Thu Mar 21 13:09:32 2019 +0200

    MidRoundSyncing changes (could potentially fix #1281 and #1323):
    - Don't mark events as "sent to all" if there's a midround syncing client who'll need those events once the midround sync is done.
    - Don't keep updating midround syncing clients' unreceived event count as new unique events are created during midround sync, but instead just send the clients the unique events they were missing at the time of joining. Because the new events created during the midround syncing aren't removed anymore, the joining client will be able to receive them when they switch to normal sync. The old behaviour might've lead to cases where the client can't "catch up" with the new events while midround syncing, causing them to time out.

commit 915aeb4e322ad04968556484aea74cf8b0070c3e
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Thu Mar 21 12:16:57 2019 +0200

    Fixed end round vote count overlapping with the server log button, display the votes as votes/max instead of y/n.

commit 62e3b272bb0235553562578493bf638a047235ab
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Wed Mar 20 23:36:03 2019 +0200

    Updated handheld sonar UI graphics & moved it to the bottom left corner of the screen

commit b93c7312c6bf4b560c8259e79650dbf1444072c9
Author: Joonas Rikkonen <poe.regalis@gmail.com>
Date:   Wed Mar 20 23:10:08 2019 +0200

    Hide the start button from the campaign UI if the client doesn't have the permission to manage the campaign or rounds.
2019-03-21 14:52:00 +02:00

136 lines
5.0 KiB
C#

using Barotrauma.Networking;
using Lidgren.Network;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
partial class Voting
{
public bool AllowSubVoting
{
get { return allowSubVoting; }
set { allowSubVoting = value; }
}
public bool AllowModeVoting
{
get { return allowModeVoting; }
set { allowModeVoting = value; }
}
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.FirstOrDefault(s => s.Name == subName);
sender.SetVote(voteType, sub);
break;
case VoteType.Mode:
string modeIdentifier = inc.ReadString();
GameModePreset mode = GameModePreset.List.Find(gm => gm.Identifier == modeIdentifier);
if (!mode.Votable) break;
sender.SetVote(voteType, mode);
break;
case VoteType.EndRound:
if (!sender.HasSpawned) return;
sender.SetVote(voteType, inc.ReadBoolean());
GameMain.NetworkMember.EndVoteCount = GameMain.Server.ConnectedClients.Count(c => c.HasSpawned && c.GetVote<bool>(VoteType.EndRound));
GameMain.NetworkMember.EndVoteMax = GameMain.Server.ConnectedClients.Count(c => c.HasSpawned);
break;
case VoteType.Kick:
byte kickedClientID = inc.ReadByte();
Client kicked = GameMain.Server.ConnectedClients.Find(c => c.ID == kickedClientID);
if (kicked != null && !kicked.HasKickVoteFrom(sender))
{
kicked.AddKickVote(sender);
Client.UpdateKickVotes(GameMain.Server.ConnectedClients);
GameMain.Server.SendChatMessage($"ServerMessage.HasVotedToKick~[initiator]={sender.Name}~[target]={kicked.Name}", ChatMessageType.Server, null);
}
break;
case VoteType.StartRound:
bool ready = inc.ReadBoolean();
if (ready != sender.GetVote<bool>(VoteType.StartRound))
{
sender.SetVote(VoteType.StartRound, ready);
GameServer.Log(sender.Name + (ready ? " is ready to start the game." : " is not ready to start the game."), ServerLog.MessageType.ServerMessage);
}
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).Identifier);
}
}
msg.Write(AllowEndVoting);
if (AllowEndVoting)
{
msg.Write((byte)GameMain.Server.ConnectedClients.Count(c => c.HasSpawned && c.GetVote<bool>(VoteType.EndRound)));
msg.Write((byte)GameMain.Server.ConnectedClients.Count(c => c.HasSpawned));
}
msg.Write(AllowVoteKick);
var readyClients = GameMain.Server.ConnectedClients.FindAll(c => c.GetVote<bool>(VoteType.StartRound));
msg.Write((byte)readyClients.Count);
foreach (Client c in readyClients)
{
msg.Write(c.ID);
}
msg.WritePadBits();
}
}
}