sources/main.cpp

Thu, 28 Jan 2021 11:39:48 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 28 Jan 2021 11:39:48 +0200
branch
protocol5
changeset 199
927f4b8ef6f7
parent 192
94c67ae846fc
permissions
-rw-r--r--

merged with default

1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
190
90bf9049e5eb updated copyright year
Teemu Piippo <teemu@hecknology.net>
parents: 189
diff changeset
2 Copyright 2014 - 2021 Teemu Piippo
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. Neither the name of the copyright holder nor the names of its
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 contributors may be used to endorse or promote products derived from
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 this software without specific prior written permission.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 */
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
81
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
31 #ifndef _WIN32
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
32 # include <sys/select.h>
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
33 #else
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
34 # include <winsock2.h>
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
35 #endif
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
36
93
1ea012a6e1ec Fix min/max name clashing
Teemu Piippo <tsapii@utu.fi>
parents: 89
diff changeset
37 #include "main.h"
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
38 #include "network/rconsession.h"
76
6de6d9a64ebd - moved huffman from sources/ to top level because it's external
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
39 #include "huffman.h"
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
40 #include "interface.h"
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
41
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
42 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
43 //
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 81
diff changeset
44 int main (int argc, char* argv[])
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 {
81
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
46 #ifdef _WIN32
89
777b2a10b835 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
47 # ifdef HAVE_PDCURSES_WIN32A
777b2a10b835 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
48 // PDCurses-win32a uses a GUI window of its own so we need to destroy the console window.
81
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
49 FreeConsole();
89
777b2a10b835 Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
50 # endif
81
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
51
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
52 WSADATA wsaData;
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
53 int result = WSAStartup (MAKEWORD (2, 2), &wsaData);
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
54
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
55 if (result != 0)
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
56 {
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
57 fprintf (stderr, "WSAStartup failed: %d\n", result);
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
58 return 1;
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
59 }
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
60 #endif
a18aaf460648 Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents: 76
diff changeset
61
8
8b697d30c49f - added huffman lib, now capable of initializing an rcon connection!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
62 HUFFMAN_Construct();
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
63
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
64 if (argc != 1 and argc != 3)
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
65 {
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
66 fprintf (stderr, "usage: %s\nusage: %s <address> <password>\n", argv[0], argv[0]);
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
67 return EXIT_FAILURE;
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
68 }
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
69
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 81
diff changeset
70 zfc::Interface iface;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
71
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
72 if (argc == 3)
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
73 iface.connect (argv[1], argv[2]);
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
74
192
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
75 for (;;)
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
76 {
192
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
77 fd_set fdset;
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
78 timeval timeout;
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
79 timeout.tv_sec = 0;
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
80 timeout.tv_usec = 250000; // 0.25 seconds
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
81 FD_ZERO(&fdset);
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
82 FD_SET(0, &fdset);
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
83 const int fd = iface.getSession()->getSocket()->file_descriptor;
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
84 FD_SET(fd, &fdset);
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
85 ::select(fd + 1, &fdset, nullptr, nullptr, &timeout);
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
86 bool shouldquit = false;
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
87 if (FD_ISSET(0, &fdset))
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
88 {
192
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
89 // stdin is ready, what's incoming?
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
90 iface.handleInput(&shouldquit);
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
91 }
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
92 if (shouldquit)
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
93 {
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
94 break;
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
95 }
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
96 else
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
97 {
138
c909c38ca886 Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents: 109
diff changeset
98 iface.getSession()->tick();
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 59
diff changeset
99 iface.render();
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
100 }
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
101 }
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
102
138
c909c38ca886 Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents: 109
diff changeset
103 iface.getSession()->disconnect();
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 return EXIT_SUCCESS;
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 }

mercurial