The client finds LAN servers by transmitting a UDP broadcast packet (a packet addressed to 255.255.255.255) on ports 28000, 28050, and 28051. Any LAN servers are listening on their local network for such broadcast packets, and upon receiving them send a reply packet, and the client lists the server in the LAN servers menu. This is one way - the
right way - of handling LAN game servers.
The
wrong way goes something like this. A game starts a LAN server, and then begins spamming its local network with broadcast packets, telling everyone "HAY I R HOESTIN' GAEM LEOEL." This adds to network clutter, and in extremely unlucky cases, can lead to the server replying to itself over and over and
over and over and over and OVER AND OVER. Clients are unable to refresh the list of servers in real-time, network administrators have to slog through
hundreds of unimportant packets, and there are also clients who try to join servers which have since shut down, since again, they have no way of manually refreshing their list.
...oh, you meant how it works on the scripting level. I have no idea. Isn't that deliciously backwards?