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 (15 years, 11 months 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

# User Rev Content
1 sf-pippijn 1.1 #include "deliantra/data/fx.h"
2     #include "deliantra/data/glyph.h"
3    
4 sf-pippijn 1.3 static bool
5     read_glyph_part (char const *&data, size_t &length, data::glyph::part &part)
6 sf-pippijn 1.2 {
7 sf-pippijn 1.3 return_val_unless (length > 2, false);
8    
9 sf-pippijn 1.4 part.fg = *data++; length--;
10     part.bg = *data++; length--;
11 sf-pippijn 1.3
12     int len;
13 sf-pippijn 1.4 return_val_unless ((len = mbtowc (&part.text, data, length)) != -1, false);
14 sf-pippijn 1.3
15 sf-pippijn 1.4 data += len;
16     length -= len;
17 sf-pippijn 1.3
18     return true;
19 sf-pippijn 1.2 }
20    
21 sf-pippijn 1.4 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 sf-pippijn 1.1 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 sf-pippijn 1.4 read_glyph (facenum, name);
50 sf-pippijn 1.3 faces.emplace_back (data::fx { type, facenum, std::move (name) });
51 sf-pippijn 1.1 }
52     else if (name.length () == 1)
53     type = name[0];
54     }
55 sf-pippijn 1.5 PARSE_END;
56 sf-pippijn 1.1
57     emit fx (faces);
58     }