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

# Content
1 #include "tinput_handler.h"
2
3 #include "trenderer.h"
4
5 #include "deliantra/exception.h"
6
7 #include "adt/string.h"
8
9 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
27 if (len < 0)
28 throw "read error (stdin): " + std::string (strerror (errno));
29 if (len == 0)
30 throw exit_success ("EOF from stdin");
31
32 return_unless (buf[len - 1] == '\n');
33 buf[len - 1] = '\0';
34
35 if (buf[0] == '/')
36 send (buf + 1, size_t (len) - 2);
37 else if (buf[0] == '!')
38 {
39 if (false) ;
40 else if (!strncmp (buf, "!dump-map")) rend->draw_map ();
41 }
42 else
43 send ("command", std::string (buf, len - 1));
44 }