summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/VoteBanSystem.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/VoteBanSystem.cs')
-rw-r--r--Client/Assembly-CSharp/VoteBanSystem.cs111
1 files changed, 111 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/VoteBanSystem.cs b/Client/Assembly-CSharp/VoteBanSystem.cs
new file mode 100644
index 0000000..23d030f
--- /dev/null
+++ b/Client/Assembly-CSharp/VoteBanSystem.cs
@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+using Hazel;
+using InnerNet;
+
+public class VoteBanSystem : InnerNetObject
+{
+ public static VoteBanSystem Instance;
+
+ public Dictionary<int, int[]> Votes = new Dictionary<int, int[]>();
+
+ public enum RpcCalls
+ {
+ AddVote
+ }
+
+ public void Awake()
+ {
+ VoteBanSystem.Instance = this;
+ }
+
+ public void CmdAddVote(int clientId)
+ {
+ this.AddVote(AmongUsClient.Instance.ClientId, clientId);
+ MessageWriter messageWriter = AmongUsClient.Instance.StartRpc(this.NetId, 0, SendOption.Reliable);
+ messageWriter.Write(AmongUsClient.Instance.ClientId);
+ messageWriter.Write(clientId);
+ messageWriter.EndMessage();
+ }
+
+ private void AddVote(int srcClient, int clientId)
+ {
+ int[] array;
+ if (!this.Votes.TryGetValue(clientId, out array))
+ {
+ array = (this.Votes[clientId] = new int[3]);
+ }
+ int num = -1;
+ for (int i = 0; i < array.Length; i++)
+ {
+ int num2 = array[i];
+ if (num2 == srcClient)
+ {
+ break;
+ }
+ if (num2 == 0)
+ {
+ num = i;
+ break;
+ }
+ }
+ if (num != -1)
+ {
+ array[num] = srcClient;
+ base.SetDirtyBit(1U);
+ if (num == array.Length - 1)
+ {
+ AmongUsClient.Instance.KickPlayer(clientId, false);
+ }
+ }
+ }
+
+ public bool HasMyVote(int clientId)
+ {
+ int[] array;
+ return this.Votes.TryGetValue(clientId, out array) && Array.IndexOf<int>(array, AmongUsClient.Instance.ClientId) != -1;
+ }
+
+ public override void HandleRpc(byte callId, MessageReader reader)
+ {
+ if (callId == 0)
+ {
+ int srcClient = reader.ReadInt32();
+ int clientId = reader.ReadInt32();
+ this.AddVote(srcClient, clientId);
+ }
+ }
+
+ public override bool Serialize(MessageWriter writer, bool initialState)
+ {
+ writer.Write((byte)this.Votes.Count);
+ foreach (KeyValuePair<int, int[]> keyValuePair in this.Votes)
+ {
+ writer.Write(keyValuePair.Key);
+ for (int i = 0; i < 3; i++)
+ {
+ writer.WritePacked(keyValuePair.Value[i]);
+ }
+ }
+ this.DirtyBits = 0U;
+ return true;
+ }
+
+ public override void Deserialize(MessageReader reader, bool initialState)
+ {
+ int num = (int)reader.ReadByte();
+ for (int i = 0; i < num; i++)
+ {
+ int key = reader.ReadInt32();
+ int[] array;
+ if (!this.Votes.TryGetValue(key, out array))
+ {
+ array = (this.Votes[key] = new int[3]);
+ }
+ for (int j = 0; j < 3; j++)
+ {
+ array[j] = reader.ReadPackedInt32();
+ }
+ }
+ }
+}