ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/tclient/tmain.cpp
Revision: 1.1
Committed: Sun Oct 24 22:24:50 2010 UTC (15 years, 11 months ago) by sf-pippijn
Branch: MAIN
Log Message:
added a command line client (no curses)

File Contents

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