You can stretch the definition of legal and head the abandonware route, some companies even provide windows 2k/xp updates for these and some companies even donate/support it.
Likewise a lot of the old doom and slightly more recent era FPS titles had their source released although normally not with any level/graphic data meaning 3rd party is normally necessary (even then it is a bit sketchy).
A lot of companies give the full multiplayer component or a client (i.e. you can not host) of the game of their game (normally FPS titles but occasionally some others).
The odd MMO title also does free stuff but look carefully.
Various agreements also preside over emulation (normally stuff where a developer licensed and published a game through a company and said company gained the rights before giving them away to the community).
A lot is out there if you know where and how to look.
Edit: if you are after gaming on the cheap I strongly urge you to also consider those $/£5 shelves in game/electronic/supermarket type places as the games they offer tend to be good, require a modest PC to run (by todays standards anyhow) which also means network games, are fully patched and stable most of the time and last and most certainly not least frequently have devoted modding sites/communities.
iD gives anyone access to the source code of their games after some time.. the source for the engines of Doom, Quake, Quake 2 and Quake 3 are free for anyone who wants to use them..
3d realms made the same thing with Duke Nukem 3D..
I find this even cooler then just giving the game.. gives students the opportunity to see how the game is done.