Sun, 17 May 2015 22:07:48 +0300
Added support for SVRC_YOUREDISCONNECTED
73
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
1 | /* |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
2 | Copyright 2014, 2015 Teemu Piippo |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
3 | All rights reserved. |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
4 | |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
7 | are met: |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
8 | |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
14 | 3. Neither the name of the copyright holder nor the names of its |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
15 | contributors may be used to endorse or promote products derived from |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
16 | this software without specific prior written permission. |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
17 | |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
20 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
21 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
22 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
23 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
24 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
25 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
26 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
27 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
29 | */ |
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
30 | |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | #include "rconsession.h" |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
32 | #include "../interface.h" |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | // |
72 | 36 | RCONSession::RCONSession (Interface* iface) : |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | m_state (RCON_DISCONNECTED), |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
38 | m_lastPing (0), |
72 | 39 | m_numAdmins (0), |
40 | m_interface (iface) | |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | { |
58
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
42 | if (not m_socket.set_blocking (false)) |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
43 | { |
58
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
44 | print_to (stderr, "unable to set socket as non-blocking: %s\n", |
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
45 | m_socket.error_string().chars()); |
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
46 | exit (EXIT_FAILURE); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
47 | } |
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:
23
diff
changeset
|
48 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
49 | |
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:
23
diff
changeset
|
50 | // ------------------------------------------------------------------------------------------------- |
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:
23
diff
changeset
|
51 | // |
58
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
52 | RCONSession::~RCONSession() {} |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | |
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 | // |
72 | 56 | void RCONSession::connect (IPAddress address) |
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 | m_address = address; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | m_state = RCON_CONNECTING; |
72 | 60 | m_interface->update_statusbar(); |
57
a2f41245e387
- restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
47
diff
changeset
|
61 | send_hello(); |
10
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 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | // |
72 | 66 | void RCONSession::disconnect() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
68 | if (m_state > RCON_CONNECTING) |
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 | // Say goodbye to remote |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | Bytestream packet; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | packet.write_byte (CLRC_DISCONNECT); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | this->send (packet); |
72 | 74 | m_interface->print ("Disconnected from %1\n", m_address.to_string (IP_WITH_PORT)); |
75 | m_interface->update_statusbar(); | |
10
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 | m_state = RCON_DISCONNECTED; |
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 | // |
72 | 83 | void RCONSession::send (const Bytestream& packet) |
10
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 | m_socket.send (m_address, packet); |
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 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | // |
72 | 90 | void RCONSession::tick() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
92 | if (m_state == RCON_DISCONNECTED) |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
93 | return; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
94 | |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | time_t now; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | time (&now); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | if (m_lastPing < now) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | if (m_state == RCON_CONNECTING) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | send_hello(); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | else if (m_state == RCON_AUTHENTICATING) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | send_password(); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | else if (m_state == RCON_CONNECTED and m_lastPing + 5 < now) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | Bytestream packet; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | packet.write_byte (CLRC_PONG); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | send (packet); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | bump_last_ping(); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | for (Datagram datagram; m_socket.read (datagram);) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | handle_packet (datagram.data, datagram.from); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | // |
72 | 123 | void RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | { |
29
e534f2f78196
- handle the 'from' argument in RCONSession::handle_packet to filter out packets from foreign hosts
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
125 | if (from != m_address) |
e534f2f78196
- handle the 'from' argument in RCONSession::handle_packet to filter out packets from foreign hosts
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
126 | return; |
e534f2f78196
- handle the 'from' argument in RCONSession::handle_packet to filter out packets from foreign hosts
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
127 | |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
128 | try |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
129 | { |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
130 | while (packet.bytes_left() > 0) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | { |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
132 | int header = packet.read_byte(); |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
133 | |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
134 | switch (ServerResponse (header)) |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
135 | { |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
136 | case SVRC_OLDPROTOCOL: |
72 | 137 | m_interface->print_error ("Your RCON client is using outdated protocol.\n"); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
138 | m_state = RCON_DISCONNECTED; |
80
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
139 | m_interface->disconnected(); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
140 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
142 | case SVRC_BANNED: |
72 | 143 | m_interface->print_error ("You have been banned from the server.\n"); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
144 | m_state = RCON_DISCONNECTED; |
80
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
145 | m_interface->disconnected(); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
146 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
148 | case SVRC_SALT: |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
149 | m_salt = packet.read_string(); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
150 | m_state = RCON_AUTHENTICATING; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
151 | send_password(); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
152 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
154 | case SVRC_INVALIDPASSWORD: |
72 | 155 | m_interface->print_error ("Login failed.\n"); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
156 | m_state = RCON_DISCONNECTED; |
80
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
157 | m_interface->disconnected(); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
158 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
160 | case SVRC_MESSAGE: |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
161 | { |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
162 | String message = packet.read_string(); |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
163 | message.normalize(); |
72 | 164 | m_interface->print ("%1\n", message); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
165 | } |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
166 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
168 | case SVRC_LOGGEDIN: |
72 | 169 | m_interface->print ("Login successful!\n"); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
170 | m_serverProtocol = packet.read_byte(); |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
171 | m_hostname = packet.read_string(); |
72 | 172 | m_interface->set_title (m_hostname); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
173 | m_state = RCON_CONNECTED; |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
174 | |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
175 | for (int i = packet.read_byte(); i > 0; --i) |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
176 | process_server_updates (packet); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
177 | |
72 | 178 | m_interface->print ("Previous messages:\n"); |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
179 | |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
180 | for (int i = packet.read_byte(); i > 0; --i) |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
181 | { |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
182 | String message = packet.read_string(); |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
183 | message.normalize(); |
72 | 184 | m_interface->print ("--- %1\n", message); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
185 | } |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
186 | |
72 | 187 | m_interface->print ("End of previous messages.\n"); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
188 | break; |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
189 | |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
190 | case SVRC_UPDATE: |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
191 | process_server_updates (packet); |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
192 | break; |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
193 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
194 | case SVRC_TOOMANYTABCOMPLETES: |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
195 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
196 | unsigned int numCompletions = packet.read_short(); |
72 | 197 | m_interface->print ("%1 completions for '%2'.\n", |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
198 | int (numCompletions), m_lastTabComplete); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
199 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
200 | break; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
201 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
202 | case SVRC_TABCOMPLETE: |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
203 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
204 | StringList completes; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
205 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
206 | for (signed int i = packet.read_byte(); i > 0; --i) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
207 | completes << packet.read_string(); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
208 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
209 | if (completes.size() == 1) |
72 | 210 | { |
211 | m_interface->tab_complete (m_lastTabComplete, completes[0]); | |
212 | } | |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
213 | else if (not completes.is_empty()) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
214 | { |
72 | 215 | m_interface->print ("Completions for '%1':\n", m_lastTabComplete); |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
216 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
217 | for (int i = 0; i < completes.size(); i += 8) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
218 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
219 | Range<int> spliceRange (i, min (i + 8, completes.size() - 1)); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
220 | StringList splice (completes.splice (spliceRange)); |
72 | 221 | m_interface->print ("- %1\n", splice.join (", ")); |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
222 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
223 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
224 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
225 | break; |
79
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
226 | |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
227 | case SVRC_WATCHINGCVAR: |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
228 | m_interface->print ("Server acknowledges watch on %1\n", packet.read_string()); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
229 | m_interface->print ("Its current value is %1\n", packet.read_string()); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
230 | break; |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
231 | |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
232 | case SVRC_ALREADYWATCHINGCVAR: |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
233 | m_interface->print ("Server says you are already watching %1\n", packet.read_string()); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
234 | break; |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
235 | |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
236 | case SVRC_WATCHCVARNOTFOUND: |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
237 | m_interface->print ("No such cvar %1\n", packet.read_string()); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
238 | break; |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
239 | |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
240 | case SVRC_CVARCHANGED: |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
241 | { |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
242 | String name = packet.read_string(); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
243 | String value = packet.read_string(); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
244 | m_interface->print ("New value of %1: %2\n", name, value); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
245 | } |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
246 | break; |
80
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
247 | |
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
248 | case SVRC_YOUREDISCONNECTED: |
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
249 | { |
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
250 | String message = packet.read_string(); |
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
251 | m_interface->print_error ("Connection error: %1\n", message); |
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
252 | m_state = RCON_DISCONNECTED; |
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
253 | m_interface->disconnected(); |
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
254 | } |
f992b027374b
Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents:
79
diff
changeset
|
255 | break; |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
256 | } |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | } |
13
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
258 | } |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
259 | catch (std::exception& e) |
09dcaeaa216b
- to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents:
12
diff
changeset
|
260 | { |
72 | 261 | m_interface->print_warning ("Couldn't process packet: %1\n", e.what()); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
262 | } |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
263 | } |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
264 | |
72 | 265 | void RCONSession::process_server_updates (Bytestream& packet) |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
266 | { |
70 | 267 | int header = packet.read_byte(); |
268 | ||
269 | switch (RCONUpdateType (header)) | |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
270 | { |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
271 | case SVRCU_PLAYERDATA: |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
272 | { |
47 | 273 | StringList players; |
274 | ||
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
275 | for (int i = packet.read_byte(); i > 0; --i) |
70 | 276 | players.append (packet.read_string()); |
47 | 277 | |
72 | 278 | m_interface->set_player_names (players); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
279 | } |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
280 | break; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
281 | |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
282 | case SVRCU_ADMINCOUNT: |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
283 | m_numAdmins = packet.read_byte(); |
72 | 284 | m_interface->update_statusbar(); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
285 | break; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
286 | |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
287 | case SVRCU_MAP: |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
288 | m_level = packet.read_string(); |
72 | 289 | m_interface->update_statusbar(); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
290 | break; |
70 | 291 | |
292 | default: | |
72 | 293 | m_interface->print_warning ("Unknown server update type: %d\n", header); |
70 | 294 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | // |
72 | 300 | UDPSocket* RCONSession::socket() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | return &m_socket; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
304 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
305 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | // |
72 | 307 | void RCONSession::send_hello() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | { |
72 | 309 | m_interface->print ("Connecting to %1...\n", m_address.to_string (IP_WITH_PORT)); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
310 | Bytestream packet; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | packet.write_byte (CLRC_BEGINCONNECTION); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
312 | packet.write_byte (RCON_PROTOCOL_VERSION); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
313 | send (packet); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
314 | bump_last_ping(); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
317 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
318 | // |
72 | 319 | void RCONSession::send_password() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
320 | { |
72 | 321 | m_interface->print ("Authenticating...\n"); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | Bytestream packet; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
323 | packet.write_byte (CLRC_PASSWORD); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
324 | packet.write_string ((m_salt + m_password).md5()); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
325 | send (packet); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
326 | bump_last_ping(); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
327 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
328 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
329 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
330 | // |
72 | 331 | void RCONSession::set_password (const String& password) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
332 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
333 | m_password = password; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
335 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
336 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | // |
72 | 338 | void RCONSession::bump_last_ping() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
339 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
340 | time_t now; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
341 | time (&now); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | m_lastPing = now; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
343 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
344 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
345 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
346 | // |
72 | 347 | bool RCONSession::is_active() const |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
348 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
349 | return state() != RCON_DISCONNECTED; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
350 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
351 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
352 | // ------------------------------------------------------------------------------------------------- |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
353 | // Returns true if the message was successfully sent. |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
354 | // |
72 | 355 | bool RCONSession::send_command (const String& message) |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
356 | { |
22
77d02446edf0
- don't send empty messages
Teemu Piippo <crimsondusk64@gmail.com>
parents:
21
diff
changeset
|
357 | if (m_state != RCON_CONNECTED or message.is_empty()) |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
358 | return false; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
359 | |
79
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
360 | if (message.starts_with ("/watch ")) |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
361 | { |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
362 | String cvarnamelist = message.mid (String ("/watch ").length(), -1); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
363 | cvarnamelist.normalize(); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
364 | |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
365 | Bytestream packet; |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
366 | packet.write_byte (CLRC_WATCHCVAR); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
367 | |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
368 | for (String cvarname : cvarnamelist.split (' ')) |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
369 | { |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
370 | m_interface->print (TEXTCOLOR_Green "Requesting watch on %1...\n", cvarname); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
371 | packet.write_string (cvarname); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
372 | } |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
373 | send (packet); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
374 | bump_last_ping(); |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
375 | return true; |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
376 | } |
62cfb7b97fc0
Added rudimentary support for CVar watch (only as a debug command for now)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
377 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
378 | Bytestream packet; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
379 | packet.write_byte (CLRC_COMMAND); |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
380 | packet.write_string (message); |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
381 | send (packet); |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
382 | bump_last_ping(); |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
383 | return true; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
384 | } |
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:
23
diff
changeset
|
385 | |
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:
23
diff
changeset
|
386 | // ------------------------------------------------------------------------------------------------- |
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:
23
diff
changeset
|
387 | // |
72 | 388 | RCONSessionState RCONSession::state() const |
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:
23
diff
changeset
|
389 | { |
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:
23
diff
changeset
|
390 | return m_state; |
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:
23
diff
changeset
|
391 | } |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
392 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
393 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
394 | // |
72 | 395 | const IPAddress& RCONSession::address() const |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
396 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
397 | return m_address; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
398 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
399 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
400 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
401 | // |
72 | 402 | int RCONSession::num_admins() const |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
403 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
404 | return m_numAdmins; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
405 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
406 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
407 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
408 | // |
72 | 409 | const String& RCONSession::level() const |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
410 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
411 | return m_level; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
412 | } |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
413 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
414 | // ------------------------------------------------------------------------------------------------- |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
415 | // |
72 | 416 | void RCONSession::request_tab_complete (const String& part) |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
417 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
418 | if (m_serverProtocol >= 4) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
419 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
420 | Bytestream packet; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
421 | packet.write_byte (CLRC_TABCOMPLETE); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
422 | packet.write_string (part); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
423 | send (packet); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
424 | bump_last_ping(); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
425 | m_lastTabComplete = part; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
426 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
427 | else |
72 | 428 | m_interface->print ("Server protocol is %1, cannot tab-complete\n", m_serverProtocol); |
78
c1d43ade656e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
429 | } |