Only You Can Save Mankind by Terry Pratchett
This is the first book in the Johnny Maxwell trilogy. Johnny Maxwell is just an ordinary boy - not smart, popular or rich. But he does love video games.
And as his parents argue themselves out of a marriage, Johnny plays at becoming humanity's last hope, shooting invading aliens out of a pixelated sky. Then comes a message from the last remaining alien spaceship: We Wish to Talk. And suddenly Johnny is thrust into the very real world of the video game, and comes face to face with an alien race that needs his help.
Only Johnny can save them. And this isn't a game anymore . .