How can I implement an ip whitelist to protect my server?

view story

http://serverfault.com – I'm going to start running a gameserver soon and I want a way to reduce the the damage of a denial of service attack. I want to make it so when someone joins the game their ip adress is added to a textfile (can already do this) and In the event of an attack I can simply use the text file as a whitelist and only allow connections to the server from the IPS that have joined the game in the past. Therefore allowing any user that has played before to join during an attack. The server is running centOS. Is there anyway I can create a script that I can execute during and after an attack to enable/ (HowTos)