sources/interface.h

Thu, 28 Jan 2021 11:37:36 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 28 Jan 2021 11:37:36 +0200
branch
protocol5
changeset 197
819fdef70d68
parent 195
be953e1621d9
permissions
-rw-r--r--

merged with default

14
33b8f428bacb - begin work on interface - input line works for the most part :)
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
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. Neither the name of the copyright holder nor the names of its
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 contributors may be used to endorse or promote products derived from
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 this software without specific prior written permission.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 */
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #pragma once
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "main.h"
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
33 #include "network/ipaddress.h"
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
34 #include "coloredline.h"
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
35 #include "network/rconsession.h"
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
36 #include "coloredline.h"
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
37
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
38 BEGIN_ZFC_NAMESPACE
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
40 class Interface
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
42 public:
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
43 enum InputState
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
44 {
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
45 INPUTSTATE_NORMAL,
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
46 INPUTSTATE_ADDRESS,
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
47 INPUTSTATE_PASSWORD,
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
48 INPUTSTATE_CONFIRM_DISCONNECTION,
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
49 };
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
50
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
51 Interface();
192
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
52 virtual ~Interface();
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
53 void connect(std::string address, std::string password);
138
c909c38ca886 Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents: 132
diff changeset
54 void disconnected();
c909c38ca886 Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents: 132
diff changeset
55 RCONSession* getSession() { return &m_session; }
192
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
56 void handleCommand(const std::string& input, bool *shouldquit);
94c67ae846fc handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
57 void handleInput(bool *shouldquit);
138
c909c38ca886 Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents: 132
diff changeset
58 void needRefresh();
189
248d0b85cbda various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
59 void __cdecl print(const char* fmtstr, ...) GNUATTRIBUTE((format(printf, 2, 3)));
248d0b85cbda various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
60 void __cdecl printWarning(const char* fmtstr, ...) GNUATTRIBUTE((format(printf, 2, 3)));
248d0b85cbda various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
61 void __cdecl printError(const char* fmtstr, ...) GNUATTRIBUTE((format(printf, 2, 3)));
248d0b85cbda various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
62 void __cdecl printText(const char* fmtstr, ...) GNUATTRIBUTE((format(printf, 2, 3)));
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
63 void render();
138
c909c38ca886 Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents: 132
diff changeset
64 void renderFull();
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
65 void setPlayerNames(const std::vector<std::string>& names);
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
66 void setTitle(const std::string& message);
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
67 void tabComplete(const std::string& part, std::string complete);
138
c909c38ca886 Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents: 132
diff changeset
68 void updateStatusBar();
c909c38ca886 Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents: 132
diff changeset
69 void vprint(const char* fmtstr, va_list args);
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
70
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
71 private:
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
72 std::vector<std::string> m_inputHistory;
127
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
73 int m_inputCursor;
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
74 int m_cursorPosition;
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
75 int m_inputPanning;
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
76 bool m_needRefresh;
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
77 bool m_needStatusBarRender;
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
78 bool m_needInputRender;
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
79 bool m_needOutputRender;
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
80 bool m_needNicklistRender;
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
81 struct { char ch; int x; } m_cursorCharacter;
191
2e6cbacafdc7 various little touchups
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
82 std::vector<ColoredLine> m_outputLines;
127
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
83 int m_outputScroll;
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
84 std::string m_title;
127
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
85 InputState m_inputState;
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
86 std::function<void(bool)> m_disconnectCallback;
186
9330b93d9946 cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
87 net::ip_address m_remoteAddress;
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
88 std::string m_statusBarText;
179
7fc34735178e start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents: 139
diff changeset
89 std::vector<ColoredLine> m_playerNames;
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
90 std::string m_pasteBuffer;
127
6610b8b29848 Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents: 116
diff changeset
91 RCONSession m_session;
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
92
139
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
93 void detachInput();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
94 int findNextWord();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
95 int findPreviousWord();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
96 void flushInput();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
97 chtype getColorPair(Color fg, Color bg);
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
98 const std::string& getCurrentInput();
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
99 std::string& getEditableInput();
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
100 std::string getPromptString();
139
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
101 void moveInputCursor(int delta);
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
102 int nicklistWidth();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
103 void positionCursor();
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 179
diff changeset
104 void printToConsole(std::string message);
139
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
105 int renderColorline(int y, int x0, int width, const ColoredLine& line, bool allowWrap);
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
106 void renderInput();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
107 void renderNicklist();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
108 void renderOutput();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
109 void renderStatusBar();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
110 void renderTitlebar();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
111 void resetTitle();
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
112 void safeDisconnect(std::function<void(bool)> afterwards);
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
113 void setInputState(InputState newstate);
da7d5a8e608f Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents: 138
diff changeset
114 void yank(int a, int b);
186
9330b93d9946 cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
115 bool tryResolveAddress(const std::string& address_string, net::ip_address *target);
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 };
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
117
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 83
diff changeset
118 END_ZFC_NAMESPACE

mercurial