1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
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 void Awake()
{
VoteBanSystem.Instance = this;
}
// RpcVote
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 enum RpcCalls
{
AddVote
}
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();
}
}
}
}
|