ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/deliantra/dclient/src/backend/communicator/command_parser.cpp
Revision: 1.5
Committed: Mon Oct 25 12:06:56 2010 UTC (15 years, 11 months ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +4 -0 lines
Log Message:
be more strict about the protocol

File Contents

# Content
1 #include "deliantra/command_parser.h"
2
3 #include "adt/reverse.h"
4
5 #include <cassert>
6 #include <sstream>
7 #include <stdexcept>
8
9 void
10 command_parser::receive (std::string const &cmd, std::string const &args)
11 {
12 std::istringstream argstream (args);
13 if (false) ;
14 else if (cmd == "addme_success") on_addme_success (argstream);
15 else if (cmd == "addspell" ) on_addspell (argstream);
16 else if (cmd == "anim" ) on_anim (argstream);
17 else if (cmd == "delinv" ) on_delinv (argstream);
18 else if (cmd == "delitem" ) on_delitem (argstream);
19 else if (cmd == "drawinfo" ) on_drawinfo (argstream);
20 else if (cmd == "ext" ) on_ext (argstream);
21 else if (cmd == "fx" ) on_fx (argstream);
22 else if (cmd == "item2" ) on_item2 (argstream);
23 else if (cmd == "map1a" ) on_map1a (argstream);
24 else if (cmd == "mapinfo" ) on_mapinfo (argstream);
25 else if (cmd == "map_scroll" ) on_map_scroll (argstream);
26 else if (cmd == "msg" ) on_msg (argstream);
27 else if (cmd == "newmap" ) on_newmap (argstream);
28 else if (cmd == "player" ) on_player (argstream);
29 else if (cmd == "query" ) on_query (argstream);
30 else if (cmd == "replyinfo" ) on_replyinfo (argstream);
31 else if (cmd == "setup" ) on_setup (argstream);
32 else if (cmd == "stats" ) on_stats (argstream);
33 else if (cmd == "upditem" ) on_upditem (argstream);
34 else if (cmd == "updspell" ) on_updspell (argstream);
35 else if (cmd == "version" ) on_version (argstream);
36 else
37 {
38 LOG () << "unhandled command: " << cmd << " " << args << "\n";
39 throw std::runtime_error ("unknown command: `" + cmd + "' args:" + args);
40 }
41 }
42
43 void
44 command_parser::add_command_handler (interface::command_handler &handler)
45 {
46 handlers.push_back (&handler);
47 }
48
49
50 #include "deliantra/netio.h"
51
52 static std::pair<std::string, std::string>
53 split2 (std::string const &s, char ch)
54 {
55 size_t pos = s.find_first_of (ch);
56 return { s.substr (0, pos), s.substr (pos + 1) };
57 }
58
59 #define PARSE_END \
60 return_unless (args); \
61 return_unless (args.peek () == EOF)
62
63 #define emit foreach (interface::command_handler *handler, reverse (handlers)) handler->
64
65 #include "command_parser/addme_success.h"
66 #include "command_parser/addspell.h"
67 #include "command_parser/anim.h"
68 #include "command_parser/delinv.h"
69 #include "command_parser/delitem.h"
70 #include "command_parser/drawinfo.h"
71 #include "command_parser/ext.h"
72 #include "command_parser/fx.h"
73 #include "command_parser/item2.h"
74 #include "command_parser/map1a.h"
75 #include "command_parser/mapinfo.h"
76 #include "command_parser/map_scroll.h"
77 #include "command_parser/msg.h"
78 #include "command_parser/newmap.h"
79 #include "command_parser/player.h"
80 #include "command_parser/query.h"
81 #include "command_parser/replyinfo.h"
82 #include "command_parser/setup.h"
83 #include "command_parser/stats.h"
84 #include "command_parser/upditem.h"
85 #include "command_parser/updspell.h"
86 #include "command_parser/version.h"