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?
I would just create a struct
that groups information about the user with the socket.
It's something I do with a User
or Player
class when writing in C#, no reason you can't translate that to C.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.