// client_socket.h #ifndef HAVE_CLIENT_SOCKET_H #define HAVE_CLIENT_SOCKET_H #include "common/config.h" #include "common/string.h" #include "common/log.h" typedef enum { Closed = 0, LoginName, LoginPassword, Playing } ConnectionState; class ClientSocket { public: ClientSocket(); ~ClientSocket(); void set_fd(const INT set) { fd = set; } const INT get_fd() { return fd; } void set_conn_state(const ConnectionState cs) { conn_state = cs; } const ConnectionState get_conn_state() { return conn_state; } const STRING get_hostname() { return hostname; } void set_hostname(const STRING h) { hostname = h; } // driver calls this to (get input from/send output to) client BOOL read_socket(); BOOL write_socket(); void get_in_buffer(STRING &buffer) { buffer = in_buffer; } void append_in_buffer(const STRING stuff) { in_buffer += stuff; } // call this to send text to the connected user void to_client(const STRING text); // driver calls this to set text read from user socket void from_client(const STRING text); void clear_in_buffer() { in_buffer.clear(); } void clear_out_buffer() { out_buffer.clear(); } void clear_next_command() { next_command.clear(); } BOOL is_colorblind() { return colorblind; } // driver calls this after parsing in_buffer void set_next_command(const STRING cmd) { next_command = cmd; } const STRING get_next_command() { return next_command; } void set_prompt(BOOL newprompt) { prompt = newprompt; } BOOL need_prompt() { return prompt; } BOOL lock(); BOOL unlock(); // temporary accessor functions - to be replaced by the SIL-lib void set_name(const STRING n) { name = n; } const STRING get_name() { return name; } void set_password(const STRING p) { password = p; } BOOL hasPublicIP(); void set_logon_time(const time_t t) { logonTime = t; } const time_t get_logon_time() { return logonTime; } void set_last_command_time(const time_t t) { lastCommandTime = t; } const time_t get_last_command_time() { return lastCommandTime; } private: INT fd; BUFFER in_buffer; BUFFER out_buffer; STRING hostname; STRING next_command; ConnectionState conn_state; pthread_mutex_t busy; BOOL prompt; BOOL compress; BOOL colorblind; time_t logonTime; time_t lastCommandTime; // temporary stuff to test driver STRING name; STRING password; }; #endif // HAVE_CLIENT_SOCKET_H