MsgVoteCanCall.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Lidgren.Network;
  2. using Robust.Shared.Network;
  3. using Robust.Shared.Serialization;
  4. namespace Content.Shared.Voting
  5. {
  6. /// <summary>
  7. /// Used to tell clients whether they are able to currently call votes.
  8. /// </summary>
  9. public sealed class MsgVoteCanCall : NetMessage
  10. {
  11. public override MsgGroups MsgGroup => MsgGroups.Command;
  12. // If true, we can currently call votes.
  13. public bool CanCall;
  14. // When we can call votes again in server RealTime.
  15. // Can be null if the reason is something not timeout related.
  16. public TimeSpan WhenCanCallVote;
  17. // Which standard votes are currently unavailable, and when will they become available.
  18. // The whenAvailable can be null if the reason is something not timeout related.
  19. public (StandardVoteType type, TimeSpan whenAvailable)[] VotesUnavailable = default!;
  20. // It's possible to be able to call votes but all standard votes to be timed out.
  21. // In this case you can open the interface and see the timeout listed there, I suppose.
  22. public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer)
  23. {
  24. CanCall = buffer.ReadBoolean();
  25. buffer.ReadPadBits();
  26. WhenCanCallVote = TimeSpan.FromTicks(buffer.ReadInt64());
  27. var lenVotes = buffer.ReadByte();
  28. VotesUnavailable = new (StandardVoteType type, TimeSpan whenAvailable)[lenVotes];
  29. for (var i = 0; i < lenVotes; i++)
  30. {
  31. var type = (StandardVoteType) buffer.ReadByte();
  32. var timeOut = TimeSpan.FromTicks(buffer.ReadInt64());
  33. VotesUnavailable[i] = (type, timeOut);
  34. }
  35. }
  36. public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serializer)
  37. {
  38. buffer.Write(CanCall);
  39. buffer.WritePadBits();
  40. buffer.Write(WhenCanCallVote.Ticks);
  41. buffer.Write((byte) VotesUnavailable.Length);
  42. foreach (var (type, timeout) in VotesUnavailable)
  43. {
  44. buffer.Write((byte) type);
  45. buffer.Write(timeout.Ticks);
  46. }
  47. }
  48. }
  49. }