ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/dclient/src/backend/communicator/command_parser/msg.h
Revision: 1.2
Committed: Mon Oct 18 14:11:46 2010 UTC (16 years ago) by sf-pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +28 -7 lines
Log Message:
check and log but do not die when ncurses stuff fails

File Contents

# User Rev Content
1 sf-pippijn 1.1 #include <json/json.h>
2    
3     void
4     command_parser::on_msg (std::istream &args)
5     {
6 sf-pippijn 1.2 if (args.peek () == '[')
7     {
8     Json::Reader reader;
9     Json::Value msg;
10     if (!reader.parse (args, msg, false))
11     throw std::runtime_error ("error parsing input: " + reader.getFormatedErrorMessages ());
12 sf-pippijn 1.1
13 sf-pippijn 1.2 assert (msg.type () == Json::arrayValue);
14     emit msg (msg[0u].asUInt (), msg[1u].asString (), msg[2u].asString ());
15     }
16     else
17     {
18     int n;
19     std::string channel;
20     std::string msg;
21    
22     args >> n >> channel;
23     while (args.peek () == ' ')
24     args.ignore ();
25     std::getline (args, channel);
26    
27     if (msg.empty ())
28     {
29     msg = channel;
30     channel = "log";
31     }
32    
33     emit msg (n, channel, msg);
34     }
35 sf-pippijn 1.1 }