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