Firstly, you'd have to store a registered user's IP address. Then, you'd need to watch for both:
- When the user is logged in
- AND when the user is "active". By active, it means the user's IP address made a page hit within a specified amount of time.
If the user was "active" in the last, say, 15 minutes, you could show that they're online. If there is no activity by that user in the last 15 minutes, you could display his status as "offline".
You'd need to make a plugin to do this. Not hard.
The method described above is exactly how this SMF forum tracks user's online/offline status.