| 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 |
sf-pippijn |
1.3 |
cmdp.add_command_handler (invman); |
| 45 |
sf-pippijn |
1.1 |
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 |
sf-pippijn |
1.3 |
ih.rend = &rend; |
| 60 |
|
|
|
| 61 |
sf-pippijn |
1.1 |
// run the event loop |
| 62 |
|
|
ev_run (EV_DEFAULT_UC_ 0); |
| 63 |
|
|
} |
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
int |
| 67 |
|
|
main (int argc, char *argv[]) |
| 68 |
|
|
try |
| 69 |
|
|
{ |
| 70 |
sf-pippijn |
1.2 |
setlocale (LC_ALL, ""); |
| 71 |
|
|
|
| 72 |
sf-pippijn |
1.1 |
if (argc == 2 && !strcmp (argv[1], "--version")) |
| 73 |
|
|
{ |
| 74 |
|
|
printf ("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION); |
| 75 |
|
|
return EXIT_SUCCESS; |
| 76 |
|
|
} |
| 77 |
|
|
|
| 78 |
|
|
if (argc < 3 || !strcmp (argv[1], "--help")) |
| 79 |
|
|
{ |
| 80 |
|
|
printf ("Usage: %s <host> <port> [user] [password]\n", PACKAGE); |
| 81 |
|
|
return EXIT_SUCCESS; |
| 82 |
|
|
} |
| 83 |
|
|
|
| 84 |
|
|
std::string server, port, user, pass; |
| 85 |
|
|
|
| 86 |
|
|
server = argv[1]; |
| 87 |
|
|
port = argv[2]; |
| 88 |
|
|
if (argc == 5) |
| 89 |
|
|
{ |
| 90 |
|
|
user = argv[3]; |
| 91 |
|
|
pass = argv[4]; |
| 92 |
|
|
} |
| 93 |
|
|
|
| 94 |
|
|
start_game (server, port, user, pass); |
| 95 |
|
|
|
| 96 |
|
|
return EXIT_SUCCESS; |
| 97 |
|
|
} |
| 98 |
|
|
catch (std::exception const &e) |
| 99 |
|
|
{ |
| 100 |
|
|
LOG ("exception") << e.what () << "\n"; |
| 101 |
|
|
printf ("exception caught: %s\n", e.what ()); |
| 102 |
|
|
return EXIT_FAILURE; |
| 103 |
|
|
} |
| 104 |
|
|
catch (int i) |
| 105 |
|
|
{ |
| 106 |
|
|
LOG ("exception") << '0' << std::oct << std::setfill ('0') << std::setw (3) << i << "\n"; |
| 107 |
|
|
printf ("exception caught: 0%03o\n", i); |
| 108 |
|
|
return EXIT_FAILURE; |
| 109 |
|
|
} |
| 110 |
|
|
catch (std::string const &s) |
| 111 |
|
|
{ |
| 112 |
|
|
LOG ("exception") << s << "\n"; |
| 113 |
|
|
printf ("exception caught: %s\n", s.c_str ()); |
| 114 |
|
|
return EXIT_FAILURE; |
| 115 |
|
|
} |
| 116 |
|
|
catch (char const *s) |
| 117 |
|
|
{ |
| 118 |
|
|
LOG ("exception") << s << "\n"; |
| 119 |
|
|
printf ("exception caught: %s\n", s); |
| 120 |
|
|
return EXIT_FAILURE; |
| 121 |
|
|
} |
| 122 |
|
|
catch (...) |
| 123 |
|
|
{ |
| 124 |
|
|
LOG ("exception"); |
| 125 |
|
|
puts ("exception caught"); |
| 126 |
|
|
return EXIT_FAILURE; |
| 127 |
|
|
} |