sources/network/rconsession.cpp

Fri, 15 May 2015 18:36:22 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Fri, 15 May 2015 18:36:22 +0300
changeset 71
4f7c2c944637
parent 70
0e947b487b18
parent 41
9ab869656b9e
child 72
1b9c53e0c846
permissions
-rw-r--r--

Merge tab-complete

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 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 RCONSession::RCONSession() :
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),
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
9 m_numAdmins (0)
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 {
58
d175243ad169 - rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
11 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
12 {
58
d175243ad169 - rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
13 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
14 m_socket.error_string().chars());
d175243ad169 - rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
15 exit (EXIT_FAILURE);
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
16 }
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
17 }
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
18
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
19 // -------------------------------------------------------------------------------------------------
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 //
58
d175243ad169 - rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
21 RCONSession::~RCONSession() {}
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22
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 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 RCONSession::connect (IPAddress address) -> void
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;
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
30 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 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 RCONSession::disconnect() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 {
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
39 if (m_state > RCON_CONNECTING)
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 // Say goodbye to remote
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 packet.write_byte (CLRC_DISCONNECT);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 this->send (packet);
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
45 print ("Disconnected from %1\n", m_address.to_string (IP_WITH_PORT));
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
46 Interface::update_statusbar();
10
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
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 m_state = RCON_DISCONNECTED;
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 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 RCONSession::send (const Bytestream& packet) -> void
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 m_socket.send (m_address, packet);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 RCONSession::tick() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 {
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
65 if (m_state == RCON_DISCONNECTED)
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
66 return;
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
67
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 time_t now;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 time (&now);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 if (m_lastPing < now)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 if (m_state == RCON_CONNECTING)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 send_hello();
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 else if (m_state == RCON_AUTHENTICATING)
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 send_password();
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 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
82 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 packet.write_byte (CLRC_PONG);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 send (packet);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 bump_last_ping();
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 for (Datagram datagram; m_socket.read (datagram);)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 handle_packet (datagram.data, datagram.from);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 {
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
99 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
100 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
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 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
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 while (packet.bytes_left() > 0)
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 {
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
106 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
107
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 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
109 {
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
110 case SVRC_OLDPROTOCOL:
70
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
111 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
112 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
113 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114
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
115 case SVRC_BANNED:
70
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
116 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
117 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
118 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
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 case SVRC_SALT:
32
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
121 m_salt = packet.read_string();
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
122 m_state = RCON_AUTHENTICATING;
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
123 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
124 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125
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
126 case SVRC_INVALIDPASSWORD:
70
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
127 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
128 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
129 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
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
131 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
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 String message = packet.read_string();
32
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
134 message.normalize();
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
135 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
136 }
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 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138
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
139 case SVRC_LOGGEDIN:
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
140 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
141 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
142 m_hostname = packet.read_string();
23
f7221183a994 - the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
143 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
144 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
145
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
146 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
147 process_server_updates (packet);
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
148
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
149 print ("Previous messages:\n");
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
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 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
152 {
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 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
154 message.normalize();
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 print ("--- %1\n", 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
156 }
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
157
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
158 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
159 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
160
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 case SVRC_UPDATE:
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
162 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
163 break;
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
164
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
165 case SVRC_TOOMANYTABCOMPLETES:
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 unsigned int numCompletions = packet.read_short();
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
168 print ("%1 completions for '%2'.\n",
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
169 int (numCompletions), m_lastTabComplete);
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 break;
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 case SVRC_TABCOMPLETE:
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
174 {
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
175 StringList completes;
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
176
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
177 for (signed int i = packet.read_byte(); i > 0; --i)
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
178 completes << packet.read_string();
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
179
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
180 if (completes.size() == 1)
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
181 Interface::tab_complete (m_lastTabComplete, completes[0]);
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
182 else if (not completes.is_empty())
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 print ("Completions for '%1':\n", m_lastTabComplete);
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 for (int i = 0; i < completes.size(); i += 8)
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
187 {
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
188 Range<int> spliceRange (i, min (i + 8, completes.size() - 1));
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
189 StringList splice (completes.splice (spliceRange));
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
190 print ("- %1\n", splice.join (", "));
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 }
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
193 }
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
194 break;
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
195 }
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 }
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
197 }
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
198 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
199 {
70
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
200 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
201 }
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
202 }
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
203
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
204 METHOD
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
205 RCONSession::process_server_updates (Bytestream& packet) -> void
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
206 {
70
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
207 int header = packet.read_byte();
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
208
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
209 switch (RCONUpdateType (header))
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
210 {
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
211 case SVRCU_PLAYERDATA:
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
212 {
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
213 StringList players;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
214
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
215 for (int i = packet.read_byte(); i > 0; --i)
70
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
216 players.append (packet.read_string());
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
217
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
218 Interface::set_player_names (players);
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
219 }
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
220 break;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
221
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
222 case SVRCU_ADMINCOUNT:
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
223 m_numAdmins = packet.read_byte();
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
224 Interface::update_statusbar();
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
225 break;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
226
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
227 case SVRCU_MAP:
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
228 m_level = packet.read_string();
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
229 Interface::update_statusbar();
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
230 break;
70
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
231
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
232 default:
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
233 print_warning ("Unknown server update type: %d\n", header);
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
234 break;
10
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 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237
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 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 RCONSession::socket() -> UDPSocket*
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 return &m_socket;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 RCONSession::send_hello() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 {
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
251 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
252 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 packet.write_byte (CLRC_BEGINCONNECTION);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 packet.write_byte (RCON_PROTOCOL_VERSION);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 send (packet);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 bump_last_ping();
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 RCONSession::send_password() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 {
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
264 print ("Authenticating...\n");
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 packet.write_byte (CLRC_PASSWORD);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267 packet.write_string ((m_salt + m_password).md5());
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 send (packet);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 bump_last_ping();
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 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 RCONSession::set_password (const String& password) -> void
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 m_password = password;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 }
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 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 RCONSession::bump_last_ping() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 time_t now;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
286 time (&now);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 m_lastPing = now;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 }
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
289
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
290 // -------------------------------------------------------------------------------------------------
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
291 //
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
292 STATIC METHOD
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
293 RCONSession::get_session() -> RCONSession*
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
294 {
58
d175243ad169 - rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
295 static RCONSession session;
d175243ad169 - rcon sessions are no longer allocated on the heap
Teemu Piippo <crimsondusk64@gmail.com>
parents: 57
diff changeset
296 return &session;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
297 }
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
298
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
299 // -------------------------------------------------------------------------------------------------
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
300 //
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
301 METHOD
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
302 RCONSession::is_active() const -> bool
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
303 {
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
304 return state() != RCON_DISCONNECTED;
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
305 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
306
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
307 // -------------------------------------------------------------------------------------------------
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
308 // Returns true if the message was successfully sent.
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
309 //
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
310 METHOD
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
311 RCONSession::send_command (const String& message) -> bool
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
312 {
22
77d02446edf0 - don't send empty messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
313 if (m_state != RCON_CONNECTED or message.is_empty())
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
314 return false;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
315
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
316 Bytestream packet;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
317 packet.write_byte (CLRC_COMMAND);
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
318 packet.write_string (message);
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
319 send (packet);
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
320 bump_last_ping();
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
321 return true;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
322 }
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
323
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
324 // -------------------------------------------------------------------------------------------------
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
325 //
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
326 METHOD
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
327 RCONSession::state() const -> RCONSessionState
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
328 {
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
329 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
330 }
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
331
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
332 // -------------------------------------------------------------------------------------------------
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
333 //
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
334 METHOD
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
335 RCONSession::address() const -> const IPAddress&
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
336 {
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
337 return m_address;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
338 }
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
339
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 METHOD
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
343 RCONSession::num_admins() const -> int
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_numAdmins;
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 //
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
350 METHOD
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
351 RCONSession::level() const -> const String&
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
352 {
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
353 return m_level;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
354 }
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
355
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
356 // -------------------------------------------------------------------------------------------------
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
357 //
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
358 METHOD
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
359 RCONSession::request_tab_complete (const String& part) -> void
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
360 {
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
361 if (m_serverProtocol >= 4)
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 Bytestream packet;
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
364 packet.write_byte (CLRC_TABCOMPLETE);
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
365 packet.write_string (part);
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
366 send (packet);
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
367 bump_last_ping();
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
368 m_lastTabComplete = part;
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
369 }
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
370 else
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
371 print ("Server protocol is %1, cannot tab-complete\n", m_serverProtocol);
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
372 }

mercurial