public static ClientPacketType Register(String name, ushort typeID, ClientPacketHandlerDelegate handler) { if (stTypeNames.ContainsKey(name)) { throw new Exception("Can not register new packet type:" + "packet type already registered with the name \"" + name + "\""); } ClientPacketType type = new ClientPacketType(typeID, name, handler); while (stTypeIDs.Count < typeID) { stTypeIDs.Add(null); } if (stTypeIDs.Count == typeID) { stTypeIDs.Add(type); } else { stTypeIDs[typeID] = type; } stTypeNames.Add(name, type); stNextID = (ushort)Math.Max(stNextID, typeID + 1); return(type); }
public static bool HandlePacket(ClientBase sender, Stream stream) { UInt16 id = BitConverter.ToUInt16(stream.ReadBytes(2), 0); if (stNextID <= id) { throw new Exception("Unknown packet type recieved"); } ClientPacketType type = stTypeIDs[id]; return(type.PacketHandler(sender, type, stream)); }
public static ClientPacketType Register( String name, ushort typeID, ClientPacketHandlerDelegate handler) { if ( stTypeNames.ContainsKey( name ) ) throw new Exception( "Can not register new packet type:" + "packet type already registered with the name \"" + name + "\"" ); ClientPacketType type = new ClientPacketType( typeID, name, handler ); while ( stTypeIDs.Count < typeID ) stTypeIDs.Add( null ); if ( stTypeIDs.Count == typeID ) stTypeIDs.Add( type ); else stTypeIDs[ typeID ] = type; stTypeNames.Add( name, type ); stNextID = (ushort) Math.Max( stNextID, typeID + 1 ); return type; }