I’m writing a server that needs to know if you are logged in or not. To log in, the user sends his username and password as a packet through a socket. Based on that socket, how can I tell if the user has been logged in?
Should I be associating login information with the socket – at that low a level?
Better yet, is there a simple solution to this problem that I’m missing?
All you need to do is keep a structure (array, hash, map, whatever; array is simple, hash would more efficient, but hardly available in C), where you store your sockets ids (in C each socket has an int identifier like file), along with all the other information, you would like to have about every single connection/user.
Each time the package comes you have to lookup the data in the structure.