public override bool NetRead(NetRead read) { base.NetRead(read); var count = read.Read <int>(); _internalDictionary = new Dictionary <TKey, TValue>(count); for (int i = 0; i < count; i++) { var key = default(TKey); var keyType = typeof(TKey); // Get key if (keyType == typeof(string)) { if (read.ReadClass <string>(null, null) is TKey str) { key = str; } } else if (keyType.IsSubclassOf(typeof(Entity))) { if (read.ReadClass <Entity>(null, null) is TKey ent) { key = ent; } } else if (keyType.IsSubclassOf(typeof(NetworkClass))) { if (read.ReadClass <NetworkClass>(null, null) is TKey nc) { key = nc; } } else if (typeof(INetIdentifiable).IsAssignableFrom(keyType)) { if (read.ReadClass <INetIdentifiable>(null, null) is TKey ni) { key = ni; } } else { throw new NotSupportedException("You can only network NetworkClass, Entity, string or INetIdentifiable. Use a struct with NetworkedValueDictionary<T> for other types."); } // Get value var value = read.Read <TValue>(); _internalDictionary.Add(key !, value); } return(true); }
public NetworkReader(NetRead Reader) { this.Reader = Reader; TotalByteCount = Reader.Remaining; CurrentBytePosition = 0; if (Reader.Remaining > 0) { CurrentByte = Reader.Read <byte>(); } }
public override bool NetRead(NetRead read) { base.NetRead(read); var count = read.Read <int>(); _internalDictionary = new Dictionary <TKey, TValue>(count); for (int i = 0; i < count; i++) { var key = read.Read <TKey>(); var value = read.Read <TValue>(); _internalDictionary.Add(key, value); } return(true); }
public bool OnUnconnectedMessage(int type, NetRead read, uint ip, int port) { if (this.useQueryPort) { return(false); } if (type != 255) { return(false); } if (this.queriesPerSeconTimer.Elapsed.TotalSeconds > 1) { this.queriesPerSeconTimer.Reset(); this.queriesPerSeconTimer.Start(); this.NumQueriesLastSecond = 0; } if (this.NumQueriesLastSecond > ConVar.Server.queriesPerSecond) { return(false); } if (read.UInt8() != 255) { return(false); } if (read.UInt8() != 255) { return(false); } if (read.UInt8() != 255) { return(false); } if (this.queryTimer.Elapsed.TotalSeconds > 60) { this.queryTimer.Reset(); this.queryTimer.Start(); this.unconnectedQueries.Clear(); } if (!this.unconnectedQueries.ContainsKey(ip)) { this.unconnectedQueries.Add(ip, 0); } int item = this.unconnectedQueries[ip] + 1; this.unconnectedQueries[ip] = item; if (item > ConVar.Server.ipQueriesPerMin) { return(true); } this.NumQueriesLastSecond++; read.Position = (long)0; int unread = read.Unread; if (unread > 4096) { return(true); } if (this.queryBuffer.Capacity < unread) { this.queryBuffer.Capacity = unread; } int num = read.Read(this.queryBuffer.GetBuffer(), 0, unread); SteamServer.HandleIncomingPacket(this.queryBuffer.GetBuffer(), num, ip, (ushort)port); return(true); }