YAPOG  0.0.1
Yet Another Pokemon Online Game
ChatManager.cpp
Go to the documentation of this file.
3 
4 namespace yap
5 {
6  bool CheckBoolTab (String str)
7  {
8  if (str.length () != NBCHAN)
9  return false;
10  for (size_t i = 0; i < str.length (); i++)
11  if (!(str[i] == '0' || str[i] == '1'))
12  return false;
13  return true;
14  }
15 
16  bool* StrToBoolTab (String str)
17  {
18  bool* tabbool = new bool[NBCHAN];
19 
20  for (size_t i = 0; i < str.length (); i++)
21  tabbool[i] = (str[i] == '0' ? 0 : 1);
22 
23  return tabbool;
24  }
25 
27  : Local (false)
28  , ChanNb (DEFAULTCHAN)
29  , Request ()
30  , TabNb (DEFAULTTAB)
31  , Count (4)
32  , Cd ()
33  {
34  String file =
35  boost::filesystem::current_path ().string () + "/chat.conf";
36  boost::filesystem::path path (file);
37  if (!boost::filesystem::exists (path))
38  {
39  Cd.Add (new ChatDisplayer ("System", StringHelper::Parse<UInt32> ("0")));
40  Cd.Add (new ChatDisplayer ("Global", StringHelper::Parse<UInt32> ("1")));
41  Cd.Add (new ChatDisplayer ("Group", StringHelper::Parse<UInt32> ("2")));
42  Cd.Add (new ChatDisplayer ("Business", StringHelper::Parse<UInt32> ("3")));
43  }
44  else
45  {
46  std::ifstream f;
47  String line = "";
48  bool parse = false;
49  f.open (path.string ());
50  while (f.good ())
51  {
52  std::getline (f, line);
53  if (line.compare ("</chat>") == 0)
54  parse = false;
55  if (parse)
56  {
57  BufferType bt;
58  StringHelper::Split (line, " ", bt);
59  if (bt.Count () != 2 || !CheckBoolTab (bt[1]))
60  continue;
61  bool *tabtoadd = StrToBoolTab (bt[1]);
62  Cd.Add (new ChatDisplayer (bt[0], tabtoadd));
63  }
64  if (line.compare ("<chat>") == 0)
65  parse = true;
66  }
67  f.close ();
68  }
69  }
70 
72  {
75 
76  for (; it < ite; it++)
77  {
78  delete (*it);
79  *it = nullptr;
80  }
81  }
82 
83 } // namespace yap