ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/client/main.cpp
Revision: 1.6
Committed: Sun Oct 24 21:48:00 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.5: +3 -2 lines
Log Message:
support disabled ev-multiplicity and disable ev3 compat

File Contents

# User Rev Content
1 sf-pippijn 1.1 #include "autoconf.h"
2    
3     #include "dclient/client.h"
4     #include "dclient/input_handler.h"
5     #include "dclient/query_handler.h"
6     #include "dclient/renderer.h"
7     #include "dclient/widgets.h"
8 sf-pippijn 1.2 #include "dclient/widgets/inventory.h"
9 sf-pippijn 1.1
10     #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 setlocale (LC_ALL, "");
39     std::auto_ptr<ndk::application> app (ndk::app = new ndk::application);
40     app->init_palette ();
41 sf-pippijn 1.1
42     // deliantra
43 sf-pippijn 1.5 communicator comm (server, port);
44 sf-pippijn 1.1 command_parser cmdp;
45     handshake_handler hh (comm);
46     message_logger logger;
47 sf-pippijn 1.2 inventory_manager invman;
48 sf-pippijn 1.1
49     // dclient
50     client cli (comm, cmdp);
51     widgets ui;
52     renderer rend (ui);
53 sf-pippijn 1.5 input_handler input (comm, ui);
54 sf-pippijn 1.1 query_handler qh (comm, ui, user, pass);
55    
56     // link them all together
57 sf-pippijn 1.2 invman.set_inventory_view (*ui.inventory);
58     invman.set_container_view (*ui.container);
59 sf-pippijn 1.1 comm.set_packet_handler (cli);
60     cmdp.add_command_handler (hh);
61     cmdp.add_command_handler (qh);
62 sf-pippijn 1.2 cmdp.add_command_handler (invman);
63 sf-pippijn 1.1 cmdp.add_command_handler (rend);
64     cmdp.add_command_handler (logger);
65    
66     // run the event loop
67 sf-pippijn 1.6 ev_run (EV_DEFAULT_ 0);
68 sf-pippijn 1.1 }
69    
70    
71     int
72     main (int argc, char *argv[])
73     try
74     {
75     if (argc == 2 && !strcmp (argv[1], "--version"))
76     {
77     printf ("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
78     return EXIT_SUCCESS;
79     }
80    
81     if (argc < 3 || !strcmp (argv[1], "--help"))
82     {
83     printf ("Usage: %s <host> <port> [user] [password]\n", PACKAGE);
84     return EXIT_SUCCESS;
85     }
86    
87     std::string server, port, user, pass;
88    
89     server = argv[1];
90     port = argv[2];
91     if (argc == 5)
92     {
93     user = argv[3];
94     pass = argv[4];
95     }
96    
97     start_game (server, port, user, pass);
98    
99     return EXIT_SUCCESS;
100     }
101     catch (std::exception const &e)
102     {
103 sf-pippijn 1.3 LOG ("exception") << e.what () << "\n";
104 sf-pippijn 1.1 printf ("exception caught: %s\n", e.what ());
105 sf-pippijn 1.3 return EXIT_FAILURE;
106 sf-pippijn 1.1 }
107     catch (int i)
108     {
109 sf-pippijn 1.3 LOG ("exception") << '0' << std::oct << std::setfill ('0') << std::setw (3) << i << "\n";
110 sf-pippijn 1.1 printf ("exception caught: 0%03o\n", i);
111 sf-pippijn 1.3 return EXIT_FAILURE;
112 sf-pippijn 1.1 }
113 sf-pippijn 1.5 catch (std::string const &s)
114     {
115     LOG ("exception") << s << "\n";
116     printf ("exception caught: %s\n", s.c_str ());
117     return EXIT_FAILURE;
118     }
119 sf-pippijn 1.1 catch (char const *s)
120     {
121 sf-pippijn 1.3 LOG ("exception") << s << "\n";
122 sf-pippijn 1.1 printf ("exception caught: %s\n", s);
123 sf-pippijn 1.3 return EXIT_FAILURE;
124 sf-pippijn 1.1 }
125     catch (...)
126     {
127 sf-pippijn 1.3 LOG ("exception");
128 sf-pippijn 1.1 puts ("exception caught");
129 sf-pippijn 1.3 return EXIT_FAILURE;
130 sf-pippijn 1.1 }