ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/client/main.cpp
Revision: 1.5
Committed: Sun Oct 24 20:31:52 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.4: +13 -47 lines
Log Message:
use EV and plain sockets instead of asio

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