ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/client/main.cpp
Revision: 1.9
Committed: Mon Oct 25 00:51:06 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.8: +2 -1 lines
Log Message:
fixed map widget

File Contents

# User Rev Content
1 sf-pippijn 1.1 #include "autoconf.h"
2    
3     #include "dclient/input_handler.h"
4     #include "dclient/query_handler.h"
5     #include "dclient/renderer.h"
6     #include "dclient/widgets.h"
7 sf-pippijn 1.2 #include "dclient/widgets/inventory.h"
8 sf-pippijn 1.1
9 sf-pippijn 1.8 #include "deliantra/client.h"
10 sf-pippijn 1.1 #include "deliantra/command_parser.h"
11 sf-pippijn 1.5 #include "deliantra/communicator.h"
12 sf-pippijn 1.1 #include "deliantra/handshake_handler.h"
13 sf-pippijn 1.2 #include "deliantra/inventory_manager.h"
14 sf-pippijn 1.1 #include "deliantra/message_logger.h"
15    
16     #include "deliantra/data/item.h"
17    
18     #include "adt/bind.h"
19    
20 sf-pippijn 1.5 #include <ndk/application.hh>
21 sf-pippijn 1.1
22 sf-pippijn 1.3 #include <csignal>
23 sf-pippijn 1.1 #include <cstring>
24     #include <iomanip>
25     #include <memory>
26    
27     static void
28     start_game ( std::string const &server
29     , std::string const &port
30     , std::string const &user
31     , std::string const &pass
32     )
33     {
34 sf-pippijn 1.6 if (!ev_default_loop (EVBACKEND_SELECT))
35     throw "unable to initialise event loop";
36 sf-pippijn 1.5
37 sf-pippijn 1.1 // ncurses
38 sf-pippijn 1.4 std::auto_ptr<ndk::application> app (ndk::app = new ndk::application);
39     app->init_palette ();
40 sf-pippijn 1.1
41     // deliantra
42 sf-pippijn 1.5 communicator comm (server, port);
43 sf-pippijn 1.1 command_parser cmdp;
44 sf-pippijn 1.8 client cli (comm, cmdp);
45 sf-pippijn 1.1 handshake_handler hh (comm);
46     message_logger logger;
47 sf-pippijn 1.2 inventory_manager invman;
48 sf-pippijn 1.1
49 sf-pippijn 1.8 cmdp.add_command_handler (hh);
50     cmdp.add_command_handler (invman);
51     cmdp.add_command_handler (logger);
52    
53     // link deliantra stuff together
54     comm.set_packet_handler (cli);
55    
56 sf-pippijn 1.1 // dclient
57     widgets ui;
58     renderer rend (ui);
59 sf-pippijn 1.5 input_handler input (comm, ui);
60 sf-pippijn 1.1 query_handler qh (comm, ui, user, pass);
61    
62 sf-pippijn 1.8 // link dclient stuff together
63 sf-pippijn 1.2 invman.set_inventory_view (*ui.inventory);
64     invman.set_container_view (*ui.container);
65 sf-pippijn 1.1 cmdp.add_command_handler (qh);
66     cmdp.add_command_handler (rend);
67    
68     // run the event loop
69 sf-pippijn 1.7 ev_run (EV_DEFAULT_UC_ 0);
70 sf-pippijn 1.1 }
71    
72    
73     int
74     main (int argc, char *argv[])
75     try
76     {
77 sf-pippijn 1.9 setlocale (LC_ALL, "");
78    
79 sf-pippijn 1.1 if (argc == 2 && !strcmp (argv[1], "--version"))
80     {
81     printf ("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
82     return EXIT_SUCCESS;
83     }
84    
85     if (argc < 3 || !strcmp (argv[1], "--help"))
86     {
87     printf ("Usage: %s <host> <port> [user] [password]\n", PACKAGE);
88     return EXIT_SUCCESS;
89     }
90    
91     std::string server, port, user, pass;
92    
93     server = argv[1];
94     port = argv[2];
95     if (argc == 5)
96     {
97     user = argv[3];
98     pass = argv[4];
99     }
100    
101     start_game (server, port, user, pass);
102    
103     return EXIT_SUCCESS;
104     }
105     catch (std::exception const &e)
106     {
107 sf-pippijn 1.3 LOG ("exception") << e.what () << "\n";
108 sf-pippijn 1.1 printf ("exception caught: %s\n", e.what ());
109 sf-pippijn 1.3 return EXIT_FAILURE;
110 sf-pippijn 1.1 }
111     catch (int i)
112     {
113 sf-pippijn 1.3 LOG ("exception") << '0' << std::oct << std::setfill ('0') << std::setw (3) << i << "\n";
114 sf-pippijn 1.1 printf ("exception caught: 0%03o\n", i);
115 sf-pippijn 1.3 return EXIT_FAILURE;
116 sf-pippijn 1.1 }
117 sf-pippijn 1.5 catch (std::string const &s)
118     {
119     LOG ("exception") << s << "\n";
120     printf ("exception caught: %s\n", s.c_str ());
121     return EXIT_FAILURE;
122     }
123 sf-pippijn 1.1 catch (char const *s)
124     {
125 sf-pippijn 1.3 LOG ("exception") << s << "\n";
126 sf-pippijn 1.1 printf ("exception caught: %s\n", s);
127 sf-pippijn 1.3 return EXIT_FAILURE;
128 sf-pippijn 1.1 }
129     catch (...)
130     {
131 sf-pippijn 1.3 LOG ("exception");
132 sf-pippijn 1.1 puts ("exception caught");
133 sf-pippijn 1.3 return EXIT_FAILURE;
134 sf-pippijn 1.1 }