sources/network/rconsession.h

Fri, 05 Feb 2021 11:36:38 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 05 Feb 2021 11:36:38 +0200
changeset 200
3fb775db4829
parent 191
2e6cbacafdc7
permissions
-rw-r--r--

refactor

10
3874575d924d - begin work on rcon sessions
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
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. Neither the name of the copyright holder nor the names of its
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 contributors may be used to endorse or promote products derived from
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 this software without specific prior written permission.
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
156
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
23 EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
156
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 */
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #pragma once
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "ipaddress.h"
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 #include "udpsocket.h"
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 #include "bytestream.h"
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
35 BEGIN_ZFC_NAMESPACE
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 enum
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 {
132
8a4690db252e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 109
diff changeset
41 RCON_PROTOCOL_VERSION = 5
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 };
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 enum ServerResponse
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 SVRC_OLDPROTOCOL = 32,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 SVRC_BANNED,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 SVRC_SALT,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 SVRC_LOGGEDIN,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 SVRC_INVALIDPASSWORD,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 SVRC_MESSAGE,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 SVRC_UPDATE,
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
55 SVRC_TABCOMPLETE,
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
56 SVRC_TOOMANYTABCOMPLETES,
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 };
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 enum ClientRequest
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 CLRC_BEGINCONNECTION = 52,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 CLRC_PASSWORD,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 CLRC_COMMAND,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 CLRC_PONG,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 CLRC_DISCONNECT,
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
68 CLRC_TABCOMPLETE,
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 };
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 enum RCONUpdateType
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 SVRCU_PLAYERDATA,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 SVRCU_ADMINCOUNT,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 SVRCU_MAP,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 };
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 enum RCONSessionState
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 RCON_DISCONNECTED,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 RCON_CONNECTING,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 RCON_AUTHENTICATING,
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 RCON_CONNECTED
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 };
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 class RCONSession
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 public:
92
39947c46ed17 Suppress more MSVC warnings
Teemu Piippo <tsapii@utu.fi>
parents: 88
diff changeset
95 RCONSession();
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 ~RCONSession();
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97
186
9330b93d9946 cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
98 const net::ip_address& address() const;
156
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
99 void bumpLastPing();
186
9330b93d9946 cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
100 void connect(net::ip_address address);
156
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
101 void disconnect();
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
102 int getAdminCount() const;
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 168
diff changeset
103 const std::string& getLevel() const;
189
248d0b85cbda various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
104 net::UDPSocket* getSocket();
156
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
105 RCONSessionState getState() const;
191
2e6cbacafdc7 various little touchups
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
106 void handlePacket(std::vector<unsigned char>& message);
156
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
107 bool isActive() const;
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
108 void processServerUpdates(Bytestream& packet);
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 168
diff changeset
109 void requestTabCompletion(const std::string& part);
191
2e6cbacafdc7 various little touchups
Teemu Piippo <teemu@hecknology.net>
parents: 190
diff changeset
110 bool send(const std::vector<unsigned char>& packet);
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 168
diff changeset
111 bool sendCommand(const std::string& commandString);
156
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
112 void sendHello();
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
113 void sendPassword();
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
114 void setInterface(class Interface* interface);
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 168
diff changeset
115 void setPassword(const std::string& password);
156
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
116 void tick();
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
117
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 private:
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 RCONSessionState m_state;
186
9330b93d9946 cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents: 183
diff changeset
120 net::ip_address m_address;
189
248d0b85cbda various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents: 186
diff changeset
121 net::UDPSocket m_socket;
200
3fb775db4829 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 191
diff changeset
122 std::time_t m_lastPing;
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 168
diff changeset
123 std::string m_password;
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 168
diff changeset
124 std::string m_salt;
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
125 int m_serverProtocol;
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 168
diff changeset
126 std::string m_hostname;
156
ce66d7e374bf Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents: 154
diff changeset
127 int m_adminCount;
183
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 168
diff changeset
128 std::string m_level;
9b6a0daedfc0 renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents: 168
diff changeset
129 std::string m_lastTabComplete;
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
130 class Interface* m_interface;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 };
88
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
132
08ccaf26cffd Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents: 73
diff changeset
133 END_ZFC_NAMESPACE

mercurial