initial commit, lordsawar source, slightly modified
[lordsawar] / src / pbm-game-client.cpp
1 // Copyright (C) 2008 Ole Laursen
2 // Copyright (C) 2008 Ben Asselstine
3 //
4 //  This program is free software; you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation; either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU Library General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
17 //  02110-1301, USA.
18
19 #include <iostream>
20 #include <fstream>
21
22 #include "pbm-game-client.h"
23
24 #include "File.h"
25 #include "action.h"
26 #include "network-action.h"
27 #include "network-history.h"
28 #include "playerlist.h"
29 #include "network_player.h"
30 #include "xmlhelper.h"
31
32
33
34 PbmGameClient * PbmGameClient::s_instance = 0;
35
36
37 PbmGameClient* PbmGameClient::getInstance()
38 {
39     if (s_instance == 0)
40         s_instance = new PbmGameClient();
41
42     return s_instance;
43 }
44
45 void PbmGameClient::deleteInstance()
46 {
47     if (s_instance)
48         delete s_instance;
49
50     s_instance = 0;
51 }
52
53
54 PbmGameClient::PbmGameClient()
55 {
56 }
57
58 PbmGameClient::~PbmGameClient()
59 {
60 }
61
62 bool PbmGameClient::loadWithHelper(XML_Helper &helper, Player *p)
63 {
64   ActionLoader actionloader;
65   HistoryLoader historyloader;
66   bool broken = false;
67   helper.registerTag(NetworkAction::d_tag, sigc::mem_fun(actionloader, &ActionLoader::loadAction));
68   helper.registerTag(Action::d_tag, sigc::mem_fun(actionloader, &ActionLoader::loadAction));
69   helper.registerTag(NetworkHistory::d_tag, sigc::mem_fun(historyloader, &HistoryLoader::loadHistory));
70   helper.registerTag(History::d_tag, sigc::mem_fun(historyloader, &HistoryLoader::loadHistory));
71   if (!helper.parse())
72     broken = true;
73
74   int num = decodeActions(actionloader.actions, p);
75   printf ("decoded %d actions\n", num);
76   num = decodeHistories(historyloader.histories);
77   printf ("decoded %d histories\n", num);
78   return broken;
79 }