Fri, 15 May 2015 20:03:35 +0300
Massive refactor
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | #include "rconsession.h" |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
22
diff
changeset
|
2 | #include "../interface.h" |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | // |
72 | 6 | RCONSession::RCONSession (Interface* iface) : |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | m_state (RCON_DISCONNECTED), |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
8 | m_lastPing (0), |
72 | 9 | m_numAdmins (0), |
10 | m_interface (iface) | |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | { |
58
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
12 | 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
|
13 | { |
58
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
14 | 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
|
15 | m_socket.error_string().chars()); |
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
16 | exit (EXIT_FAILURE); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
17 | } |
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
|
18 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
19 | |
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
|
20 | // ------------------------------------------------------------------------------------------------- |
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
|
21 | // |
58
d175243ad169
- rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents:
57
diff
changeset
|
22 | RCONSession::~RCONSession() {} |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | // |
72 | 26 | void RCONSession::connect (IPAddress address) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | m_address = address; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | m_state = RCON_CONNECTING; |
72 | 30 | m_interface->update_statusbar(); |
57
a2f41245e387
- restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
47
diff
changeset
|
31 | send_hello(); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | } |
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 | void RCONSession::disconnect() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
38 | if (m_state > RCON_CONNECTING) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | // Say goodbye to remote |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | Bytestream packet; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | packet.write_byte (CLRC_DISCONNECT); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | this->send (packet); |
72 | 44 | m_interface->print ("Disconnected from %1\n", m_address.to_string (IP_WITH_PORT)); |
45 | m_interface->update_statusbar(); | |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | m_state = RCON_DISCONNECTED; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | // |
72 | 53 | void RCONSession::send (const Bytestream& packet) |
10
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 | m_socket.send (m_address, packet); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | // |
72 | 60 | void RCONSession::tick() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
62 | if (m_state == RCON_DISCONNECTED) |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
63 | return; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
64 | |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | time_t now; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | time (&now); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | if (m_lastPing < now) |
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 | if (m_state == RCON_CONNECTING) |
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 | send_hello(); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | else if (m_state == RCON_AUTHENTICATING) |
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 | send_password(); |
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 | 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
|
79 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | Bytestream packet; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | packet.write_byte (CLRC_PONG); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | send (packet); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | bump_last_ping(); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | for (Datagram datagram; m_socket.read (datagram);) |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | handle_packet (datagram.data, datagram.from); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | // |
72 | 93 | void RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | { |
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
|
95 | 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
|
96 | 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
|
97 | |
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
|
98 | 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
|
99 | { |
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
|
100 | while (packet.bytes_left() > 0) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | { |
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
|
102 | 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
|
103 | |
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
|
104 | 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
|
105 | { |
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
|
106 | case SVRC_OLDPROTOCOL: |
72 | 107 | 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
|
108 | 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
|
109 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | |
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
|
111 | case SVRC_BANNED: |
72 | 112 | 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
|
113 | 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
|
114 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
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
|
116 | case SVRC_SALT: |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
117 | m_salt = packet.read_string(); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
118 | m_state = RCON_AUTHENTICATING; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
119 | 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
|
120 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | |
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
|
122 | case SVRC_INVALIDPASSWORD: |
72 | 123 | 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
|
124 | 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
|
125 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
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 | 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
|
128 | { |
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 | String message = packet.read_string(); |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
130 | message.normalize(); |
72 | 131 | 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
|
132 | } |
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 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | |
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
|
135 | case SVRC_LOGGEDIN: |
72 | 136 | 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
|
137 | 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
|
138 | m_hostname = packet.read_string(); |
72 | 139 | 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
|
140 | 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
|
141 | |
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 | 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
|
143 | process_server_updates (packet); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
144 | |
72 | 145 | 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
|
146 | |
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
|
147 | 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
|
148 | { |
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 | 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
|
150 | message.normalize(); |
72 | 151 | 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
|
152 | } |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
153 | |
72 | 154 | 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
|
155 | 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
|
156 | |
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 | case SVRC_UPDATE: |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
158 | 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
|
159 | break; |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
160 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
161 | case SVRC_TOOMANYTABCOMPLETES: |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
162 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
163 | unsigned int numCompletions = packet.read_short(); |
72 | 164 | m_interface->print ("%1 completions for '%2'.\n", |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
165 | int (numCompletions), m_lastTabComplete); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
166 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
167 | break; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
168 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
169 | case SVRC_TABCOMPLETE: |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
170 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
171 | StringList completes; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
172 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
173 | for (signed int i = packet.read_byte(); i > 0; --i) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
174 | completes << packet.read_string(); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
175 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
176 | if (completes.size() == 1) |
72 | 177 | { |
178 | m_interface->tab_complete (m_lastTabComplete, completes[0]); | |
179 | } | |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
180 | else if (not completes.is_empty()) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
181 | { |
72 | 182 | m_interface->print ("Completions for '%1':\n", m_lastTabComplete); |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
183 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
184 | for (int i = 0; i < completes.size(); i += 8) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
185 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
186 | Range<int> spliceRange (i, min (i + 8, completes.size() - 1)); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
187 | StringList splice (completes.splice (spliceRange)); |
72 | 188 | m_interface->print ("- %1\n", splice.join (", ")); |
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 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
191 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
192 | break; |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
193 | } |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | } |
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
|
195 | } |
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
|
196 | 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
|
197 | { |
72 | 198 | 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
|
199 | } |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
200 | } |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
201 | |
72 | 202 | void RCONSession::process_server_updates (Bytestream& packet) |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
203 | { |
70 | 204 | int header = packet.read_byte(); |
205 | ||
206 | switch (RCONUpdateType (header)) | |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
207 | { |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
208 | case SVRCU_PLAYERDATA: |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
209 | { |
47 | 210 | StringList players; |
211 | ||
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
212 | for (int i = packet.read_byte(); i > 0; --i) |
70 | 213 | players.append (packet.read_string()); |
47 | 214 | |
72 | 215 | m_interface->set_player_names (players); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
216 | } |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
217 | break; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
218 | |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
219 | case SVRCU_ADMINCOUNT: |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
220 | m_numAdmins = packet.read_byte(); |
72 | 221 | m_interface->update_statusbar(); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
222 | break; |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
223 | |
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
224 | case SVRCU_MAP: |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
225 | m_level = packet.read_string(); |
72 | 226 | m_interface->update_statusbar(); |
12
8d0d1b368de0
- rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
227 | break; |
70 | 228 | |
229 | default: | |
72 | 230 | m_interface->print_warning ("Unknown server update type: %d\n", header); |
70 | 231 | break; |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | // |
72 | 237 | UDPSocket* RCONSession::socket() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | return &m_socket; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | // |
72 | 244 | void RCONSession::send_hello() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | { |
72 | 246 | 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
|
247 | Bytestream packet; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | packet.write_byte (CLRC_BEGINCONNECTION); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | packet.write_byte (RCON_PROTOCOL_VERSION); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | send (packet); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | bump_last_ping(); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | } |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
253 | |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | // |
72 | 256 | void RCONSession::send_password() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | { |
72 | 258 | m_interface->print ("Authenticating...\n"); |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
259 | Bytestream packet; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | packet.write_byte (CLRC_PASSWORD); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | packet.write_string ((m_salt + m_password).md5()); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | send (packet); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | bump_last_ping(); |
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 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | // |
72 | 268 | void RCONSession::set_password (const String& password) |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | m_password = password; |
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 | // ------------------------------------------------------------------------------------------------- |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | // |
72 | 275 | void RCONSession::bump_last_ping() |
10
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | { |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
277 | time_t now; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | time (&now); |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | m_lastPing = now; |
3874575d924d
- begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
281 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
282 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
283 | // |
72 | 284 | bool RCONSession::is_active() const |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
285 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
286 | return state() != RCON_DISCONNECTED; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
287 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
288 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
289 | // ------------------------------------------------------------------------------------------------- |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
290 | // Returns true if the message was successfully sent. |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
291 | // |
72 | 292 | bool RCONSession::send_command (const String& message) |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
293 | { |
22
77d02446edf0
- don't send empty messages
Teemu Piippo <crimsondusk64@gmail.com>
parents:
21
diff
changeset
|
294 | if (m_state != RCON_CONNECTED or message.is_empty()) |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
295 | return false; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
296 | |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
297 | Bytestream packet; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
298 | packet.write_byte (CLRC_COMMAND); |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
299 | packet.write_string (message); |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
300 | send (packet); |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
301 | bump_last_ping(); |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
302 | return true; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
303 | } |
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
|
304 | |
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
|
305 | // ------------------------------------------------------------------------------------------------- |
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
|
306 | // |
72 | 307 | 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
|
308 | { |
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
|
309 | 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
|
310 | } |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
311 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
312 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
313 | // |
72 | 314 | const IPAddress& RCONSession::address() const |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
315 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
316 | return m_address; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
317 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
318 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
319 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
320 | // |
72 | 321 | int RCONSession::num_admins() const |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
322 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
323 | return m_numAdmins; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
324 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
325 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
326 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
327 | // |
72 | 328 | const String& RCONSession::level() const |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
329 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
330 | return m_level; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
331 | } |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
332 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
333 | // ------------------------------------------------------------------------------------------------- |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
334 | // |
72 | 335 | void RCONSession::request_tab_complete (const String& part) |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
336 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
337 | if (m_serverProtocol >= 4) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
338 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
339 | Bytestream packet; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
340 | packet.write_byte (CLRC_TABCOMPLETE); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
341 | packet.write_string (part); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
342 | send (packet); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
343 | bump_last_ping(); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
344 | m_lastTabComplete = part; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
345 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
346 | else |
72 | 347 | m_interface->print ("Server protocol is %1, cannot tab-complete\n", m_serverProtocol); |
348 | } |