Mon, 15 Dec 2014 22:36:14 +0200
- cleanup, fixed red text not rendering
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | Copyright 2014 Teemu Piippo |
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, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
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 |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
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" |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
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 | enum |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | RCON_PROTOCOL_VERSION = 3 |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | }; |
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 | enum ServerResponse |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | SVRC_OLDPROTOCOL = 32, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | SVRC_BANNED, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | SVRC_SALT, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | SVRC_LOGGEDIN, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | SVRC_INVALIDPASSWORD, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | SVRC_MESSAGE, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | SVRC_UPDATE, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | }; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | // ------------------------------------------------------------------------------------------------- |
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 | enum ClientRequest |
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 | CLRC_BEGINCONNECTION = 52, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | CLRC_PASSWORD, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | CLRC_COMMAND, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | CLRC_PONG, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | CLRC_DISCONNECT, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | }; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | // |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | enum RCONUpdateType |
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 | SVRCU_PLAYERDATA, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | SVRCU_ADMINCOUNT, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | SVRCU_MAP, |
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 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | // |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | enum RCONSessionState |
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 | RCON_DISCONNECTED, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | RCON_CONNECTING, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | RCON_AUTHENTICATING, |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | RCON_CONNECTED |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | }; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | // |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | class RCONSession |
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 | public: |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | ~RCONSession(); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
93 | METHOD address() const -> const IPAddress&; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | METHOD connect (IPAddress address) -> void; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | METHOD disconnect() -> void; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | METHOD handle_packet (Bytestream& packet, const IPAddress& from) -> void; |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
97 | METHOD process_server_updates (Bytestream& packet) -> void; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
98 | METHOD num_admins() const -> int; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | METHOD send (const Bytestream& packet) -> void; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | METHOD send_hello() -> void; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | METHOD send_password() -> void; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | METHOD set_password (const String& password) -> void; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | METHOD socket() -> UDPSocket*; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | METHOD tick() -> void; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | METHOD bump_last_ping() -> void; |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
106 | METHOD send_command (const String& message) -> bool; |
24
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
107 | METHOD state() const -> RCONSessionState; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
108 | METHOD level() const -> const String&; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
109 | METHOD is_active() const -> bool; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | |
24
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
111 | static METHOD new_session() -> RCONSession*; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
112 | static METHOD get_session() -> RCONSession*; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
113 | |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | private: |
24
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
115 | RCONSession(); |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
116 | |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | RCONSessionState m_state; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | IPAddress m_address; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | UDPSocket m_socket; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | time_t m_lastPing; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | String m_password; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | String m_salt; |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
123 | int m_serverProtocol; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
124 | String m_hostname; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
125 | int m_numAdmins; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
126 | String m_level; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | }; |