ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/tclient/tinput_handler.cpp
Revision: 1.4
Committed: Mon Oct 25 02:07:51 2010 UTC (15 years, 11 months ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +7 -2 lines
Log Message:
factored out common client main

File Contents

# User Rev Content
1 sf-pippijn 1.1 #include "tinput_handler.h"
2    
3 sf-pippijn 1.3 #include "trenderer.h"
4    
5 sf-pippijn 1.4 #include "deliantra/exception.h"
6    
7 sf-pippijn 1.3 #include "adt/string.h"
8    
9 sf-pippijn 1.1 input_handler::input_handler (communicator &comm)
10     : sender (comm)
11     {
12     stdin_watcher.set (STDIN_FILENO, ev::READ);
13     stdin_watcher.set<input_handler, &input_handler::stdin_read_cb> (this);
14     stdin_watcher.start ();
15     }
16    
17     input_handler::~input_handler ()
18     {
19     }
20    
21     void
22     input_handler::stdin_read_cb (ev::io &w, int revents)
23     {
24     char buf[BUFSIZ];
25     ssize_t len = read (w.fd, buf, sizeof buf);
26 sf-pippijn 1.2
27 sf-pippijn 1.1 if (len < 0)
28     throw "read error (stdin): " + std::string (strerror (errno));
29     if (len == 0)
30 sf-pippijn 1.4 throw exit_success ("EOF from stdin");
31    
32     return_unless (buf[len - 1] == '\n');
33     buf[len - 1] = '\0';
34 sf-pippijn 1.2
35 sf-pippijn 1.1 if (buf[0] == '/')
36     send (buf + 1, size_t (len) - 2);
37 sf-pippijn 1.3 else if (buf[0] == '!')
38     {
39     if (false) ;
40 sf-pippijn 1.4 else if (!strncmp (buf, "!dump-map")) rend->draw_map ();
41 sf-pippijn 1.3 }
42 sf-pippijn 1.1 else
43     send ("command", std::string (buf, len - 1));
44     }