ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/communicator/command_parser/fx.h
Revision: 1.5
Committed: Mon Oct 25 12:06:57 2010 UTC (16 years ago) by sf-pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +1 -0 lines
Log Message:
be more strict about the protocol

File Contents

# Content
1 #include "deliantra/data/fx.h"
2 #include "deliantra/data/glyph.h"
3
4 static bool
5 read_glyph_part (char const *&data, size_t &length, data::glyph::part &part)
6 {
7 return_val_unless (length > 2, false);
8
9 part.fg = *data++; length--;
10 part.bg = *data++; length--;
11
12 int len;
13 return_val_unless ((len = mbtowc (&part.text, data, length)) != -1, false);
14
15 data += len;
16 length -= len;
17
18 return true;
19 }
20
21 static void
22 read_glyph (u32 facenum, std::string name)
23 {
24 data::glyph glyph;
25 if (!name.empty ())
26 {
27 char const *data = name.data ();
28 size_t length = name.length ();
29 return_unless (read_glyph_part (data, length, glyph[0]));
30 return_unless (read_glyph_part (data, length, glyph[1]));
31 return_unless (length == 0);
32 }
33 data::register_glyph (facenum, glyph);
34 }
35
36 void
37 command_parser::on_fx (std::istream &args)
38 {
39 std::vector<data::fx> faces;
40
41 u32 type = 0;
42 while (args.peek () != EOF)
43 {
44 u32 facenum = read_ber32 (args);
45 std::string name = read_string08 (args);
46
47 if (facenum)
48 {
49 read_glyph (facenum, name);
50 faces.emplace_back (data::fx { type, facenum, std::move (name) });
51 }
52 else if (name.length () == 1)
53 type = name[0];
54 }
55 PARSE_END;
56
57 emit fx (faces);
58 }