Fri, 22 Jul 2016 17:50:00 +0300
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
73
07dda51a7a8e
Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
1 | /* |
109 | 2 | Copyright 2014 - 2016 Teemu Piippo |
73
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 | |
81
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
31 | #include <time.h> |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include "rconsession.h" |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
33 | #include "../interface.h" |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
83
diff
changeset
|
34 | BEGIN_ZFC_NAMESPACE |
10
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 | // |
92 | 38 | RCONSession::RCONSession() : |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
39 | m_state(RCON_DISCONNECTED), |
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
40 | m_lastPing(0), |
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
41 | m_adminCount(0), |
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
42 | m_interface(nullptr) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
44 | 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
|
45 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
46 | fprintf(stderr, "unable to set socket as non-blocking: %s\n", |
58
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
47 | m_socket.error_string().chars()); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
48 | exit(EXIT_FAILURE); |
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 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
51 | |
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
|
52 | // ------------------------------------------------------------------------------------------------- |
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
|
53 | // |
58
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
54 | RCONSession::~RCONSession() {} |
10
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 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
58 | void RCONSession::connect(IPAddress address) |
10
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 | m_address = address; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | m_state = RCON_CONNECTING; |
138
c909c38ca886
Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
62 | m_interface->updateStatusBar(); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
63 | sendHello(); |
10
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 | |
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 | // |
72 | 68 | void RCONSession::disconnect() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
70 | if (m_state > RCON_CONNECTING) |
10
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 | // Say goodbye to remote |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
73 | send({CLRC_DISCONNECT}); |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
74 | m_interface->disconnected(); |
10
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 | m_state = RCON_DISCONNECTED; |
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 | // |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
82 | void RCONSession::send(const Vector<unsigned char>& packet) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
84 | m_socket.send(m_address, packet); |
10
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 | // |
72 | 89 | void RCONSession::tick() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
91 | if (m_state == RCON_DISCONNECTED) |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
92 | return; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
93 | |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | time_t now; |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
95 | time(&now); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | if (m_lastPing < now) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | if (m_state == RCON_CONNECTING) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
101 | sendHello(); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | else if (m_state == RCON_AUTHENTICATING) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
105 | sendPassword(); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | 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
|
108 | { |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
109 | send({CLRC_PONG}); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
110 | bumpLastPing(); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
114 | for (Datagram datagram; m_socket.read(datagram);) |
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
115 | handlePacket(datagram); |
10
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 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
120 | void RCONSession::handlePacket(Datagram& datagram) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | { |
152
6be21be4bea1
Renamed Datagram members, RCONSession::handle_packet now takes the datagram as the parameter.
Teemu Piippo <teemu@compsta2.com>
parents:
145
diff
changeset
|
122 | if (datagram.address != m_address) |
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
|
123 | 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
|
124 | |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
125 | Bytestream stream(datagram.message); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
126 | |
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
|
127 | 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
|
128 | { |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
129 | while (stream.bytesLeft() > 0) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | { |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
131 | int header = stream.readByte(); |
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 | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
133 | switch (ServerResponse(header)) |
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
|
134 | { |
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 | case SVRC_OLDPROTOCOL: |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
136 | m_interface->printError("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
|
137 | m_state = RCON_DISCONNECTED; |
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 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | |
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 | case SVRC_BANNED: |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
141 | m_interface->printError("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
|
142 | m_state = RCON_DISCONNECTED; |
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
|
143 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | |
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
|
145 | case SVRC_SALT: |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
146 | m_salt = stream.readString(); |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
147 | m_state = RCON_AUTHENTICATING; |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
148 | sendPassword(); |
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
|
149 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | |
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
|
151 | case SVRC_INVALIDPASSWORD: |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
152 | m_interface->printError("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
|
153 | m_state = RCON_DISCONNECTED; |
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 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | |
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 | 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
|
157 | { |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
158 | String message = stream.readString(); |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
159 | message.normalize(); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
160 | m_interface->printText("%s\n", message.chars()); |
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
|
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 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | |
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
|
164 | case SVRC_LOGGEDIN: |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
165 | m_interface->print("Login successful!\n"); |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
166 | m_serverProtocol = stream.readByte(); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
167 | m_hostname = stream.readString(); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
168 | m_interface->setTitle(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
|
169 | 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
|
170 | |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
171 | for (int i = stream.readByte(); i > 0; --i) |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
172 | processServerUpdates(stream); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
173 | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
174 | 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
|
175 | |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
176 | for (int i = stream.readByte(); i > 0; --i) |
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
|
177 | { |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
178 | String message = stream.readString(); |
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
|
179 | message.normalize(); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
180 | m_interface->printText("--- %s\n", message.chars()); |
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
|
181 | } |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
182 | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
183 | 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
|
184 | 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
|
185 | |
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
|
186 | case SVRC_UPDATE: |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
187 | processServerUpdates(stream); |
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; |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
189 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
190 | case SVRC_TOOMANYTABCOMPLETES: |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
191 | { |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
192 | unsigned int numCompletions = stream.readShort(); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
193 | m_interface->print("%d completions for '%s'.\n", |
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
194 | int(numCompletions), m_lastTabComplete.chars()); |
41
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 | break; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
197 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
198 | case SVRC_TABCOMPLETE: |
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 | StringList completes; |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
201 | completes.resize(stream.readByte()); |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
202 | |
137
485cb6d6b98c
Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents:
115
diff
changeset
|
203 | for (String& completion : completes) |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
204 | completion = stream.readString(); |
41
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 | if (completes.size() == 1) |
72 | 207 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
208 | m_interface->tabComplete(m_lastTabComplete, completes[0]); |
72 | 209 | } |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
210 | else if (not completes.is_empty()) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
211 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
212 | m_interface->print("Completions for '%s':\n", m_lastTabComplete.chars()); |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
213 | |
137
485cb6d6b98c
Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents:
115
diff
changeset
|
214 | for (int i : range(0, completes.size(), 8)) |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
215 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
216 | Range<int> spliceRange(i, min(i + 8, completes.size())); |
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
217 | StringList splice(completes.splice(spliceRange)); |
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
218 | m_interface->print("- %s\n", splice.join(", ").chars()); |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
219 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
220 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
221 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
222 | break; |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
223 | } |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | } |
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
|
225 | } |
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
|
226 | 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
|
227 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
228 | m_interface->printWarning("Couldn't process packet: %s\n", e.what()); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
229 | } |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
230 | } |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
231 | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
232 | void RCONSession::processServerUpdates(Bytestream& packet) |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
233 | { |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
234 | int header = packet.readByte(); |
70 | 235 | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
236 | switch (RCONUpdateType(header)) |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
237 | { |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
238 | case SVRCU_PLAYERDATA: |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
239 | { |
47 | 240 | StringList players; |
241 | ||
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
242 | for (int i = packet.readByte(); i > 0; --i) |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
243 | players.append(packet.readString()); |
47 | 244 | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
245 | m_interface->setPlayerNames(players); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
246 | } |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
247 | break; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
248 | |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
249 | case SVRCU_ADMINCOUNT: |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
250 | m_adminCount = packet.readByte(); |
138
c909c38ca886
Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
251 | m_interface->updateStatusBar(); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
252 | break; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
253 | |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
254 | case SVRCU_MAP: |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
255 | m_level = packet.readString(); |
138
c909c38ca886
Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
256 | m_interface->updateStatusBar(); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
257 | break; |
70 | 258 | |
259 | default: | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
260 | m_interface->printWarning("Unknown server update type: %d\n", header); |
70 | 261 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
265 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
267 | UDPSocket* RCONSession::getSocket() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | return &m_socket; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
271 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
273 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
274 | void RCONSession::sendHello() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
276 | m_interface->print("Connecting to %s...\n", m_address.to_string(IPAddress::WITH_PORT).chars()); |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
277 | send({CLRC_BEGINCONNECTION, RCON_PROTOCOL_VERSION}); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
278 | bumpLastPing(); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
282 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
283 | void RCONSession::sendPassword() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
284 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
285 | m_interface->print("Authenticating...\n"); |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
286 | Vector<unsigned char> message; |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
287 | Bytestream stream(message); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
288 | stream.writeByte(CLRC_PASSWORD); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
289 | stream.writeString((m_salt + m_password).md5()); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
290 | send(message); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
291 | bumpLastPing(); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
296 | void RCONSession::setPassword(const String& password) |
10
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 | m_password = password; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | |
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 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
303 | void RCONSession::bumpLastPing() |
10
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 | time_t now; |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
306 | time(&now); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | m_lastPing = now; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
309 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
310 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
311 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
312 | bool RCONSession::isActive() const |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
313 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
314 | return getState() != RCON_DISCONNECTED; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
315 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
316 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
317 | // ------------------------------------------------------------------------------------------------- |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
318 | // Returns true if the message was successfully sent. |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
319 | // |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
320 | bool RCONSession::sendCommand(const String& commandString) |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
321 | { |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
322 | if (m_state != RCON_CONNECTED or commandString.isEmpty()) |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
323 | return false; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
324 | |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
325 | Vector<unsigned char> message; |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
326 | Bytestream stream(message); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
327 | stream.writeByte(CLRC_COMMAND); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
328 | stream.writeString(commandString); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
329 | send(message); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
330 | bumpLastPing(); |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
331 | return true; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
332 | } |
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
|
333 | |
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
|
334 | // ------------------------------------------------------------------------------------------------- |
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
|
335 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
336 | RCONSessionState RCONSession::getState() 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
|
337 | { |
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
|
338 | 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
|
339 | } |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
340 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
341 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
342 | // |
72 | 343 | const IPAddress& RCONSession::address() const |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
344 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
345 | return m_address; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
346 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
347 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
348 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
349 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
350 | int RCONSession::getAdminCount() const |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
351 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
352 | return m_adminCount; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
353 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
354 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
355 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
356 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
357 | const String& RCONSession::getLevel() const |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
358 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
359 | return m_level; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
360 | } |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
361 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
362 | // ------------------------------------------------------------------------------------------------- |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
363 | // |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
364 | void RCONSession::requestTabCompletion(const String& part) |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
365 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
366 | if (m_serverProtocol >= 4) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
367 | { |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
368 | Vector<unsigned char> message; |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
369 | Bytestream stream(message); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
370 | stream.writeByte(CLRC_TABCOMPLETE); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
371 | stream.writeString(part); |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
156
diff
changeset
|
372 | send(message); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
373 | bumpLastPing(); |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
374 | m_lastTabComplete = part; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
375 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
376 | else |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
81
diff
changeset
|
377 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
378 | m_interface->print("This server does not support tab-completion\n", m_serverProtocol); |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
81
diff
changeset
|
379 | } |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
83
diff
changeset
|
380 | } |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
83
diff
changeset
|
381 | |
92 | 382 | // ------------------------------------------------------------------------------------------------- |
383 | // | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
384 | void RCONSession::setInterface(Interface* interface) |
92 | 385 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
152
diff
changeset
|
386 | m_interface = interface; |
92 | 387 | } |
388 | ||
105
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
96
diff
changeset
|
389 | END_ZFC_NAMESPACE |