sources/network/rconsession.cpp

Tue, 16 Dec 2014 02:30:31 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 16 Dec 2014 02:30:31 +0200
changeset 57
a2f41245e387
parent 47
35b968619b0c
child 58
d175243ad169
permissions
-rw-r--r--

- restructured rconsession constructor a bit

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
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
4 RCONSession* g_rconSession = nullptr;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
5
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 RCONSession::RCONSession() :
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 m_state (RCON_DISCONNECTED),
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
10 m_lastPing (0),
57
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
11 m_numAdmins (0) {}
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
12
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
13 // -------------------------------------------------------------------------------------------------
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
14 //
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
15 STATIC METHOD
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
16 RCONSession::new_session() -> RCONSession*
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 {
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
18 if (g_rconSession != NULL)
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
19 {
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
20 g_rconSession->disconnect();
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
21 delete g_rconSession;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
22 }
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
23
57
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
24 g_rconSession = new RCONSession;
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
25
57
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
26 if (not g_rconSession->socket()->set_blocking (false))
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 {
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
28 print ("unable to set socket as non-blocking: %s\n",
57
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
29 g_rconSession->socket()->error_string().chars());
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
30 delete g_rconSession;
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
31 return nullptr;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 }
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
33
57
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
34 return g_rconSession;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 //
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
39 RCONSession::~RCONSession()
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
40 {
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
41 disconnect();
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
42
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
43 if (g_rconSession == this)
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
44 g_rconSession = nullptr;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
45 }
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 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 RCONSession::connect (IPAddress address) -> void
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 m_address = address;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 m_state = RCON_CONNECTING;
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
54 Interface::update_statusbar();
57
a2f41245e387 - restructured rconsession constructor a bit
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
55 send_hello();
10
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 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 RCONSession::disconnect() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 {
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
63 if (m_state > RCON_CONNECTING)
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 // Say goodbye to remote
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 packet.write_byte (CLRC_DISCONNECT);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 this->send (packet);
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
69 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
70 Interface::update_statusbar();
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 m_state = RCON_DISCONNECTED;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 RCONSession::send (const Bytestream& packet) -> void
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 m_socket.send (m_address, packet);
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
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 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 RCONSession::tick() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 {
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
89 if (m_state == RCON_DISCONNECTED)
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
90 return;
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
91
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 time_t now;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 time (&now);
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 if (m_lastPing < now)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 if (m_state == RCON_CONNECTING)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 send_hello();
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 else if (m_state == RCON_AUTHENTICATING)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 send_password();
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 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
106 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 packet.write_byte (CLRC_PONG);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 send (packet);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 bump_last_ping();
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 for (Datagram datagram; m_socket.read (datagram);)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 handle_packet (datagram.data, datagram.from);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 {
29
e534f2f78196 - handle the 'from' argument in RCONSession::handle_packet to filter out packets from foreign hosts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
123 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
124 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
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 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
127 {
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 while (packet.bytes_left() > 0)
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 {
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
130 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
131
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 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
133 {
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
134 case SVRC_OLDPROTOCOL:
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
135 print ("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
136 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
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_BANNED:
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
140 print ("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
141 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
142 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
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 case SVRC_SALT:
32
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
145 m_salt = packet.read_string();
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
146 m_state = RCON_AUTHENTICATING;
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
147 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
148 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149
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
150 case SVRC_INVALIDPASSWORD:
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
151 print ("Password incorrect.\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
152 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
153 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154
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 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
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 String message = packet.read_string();
32
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
158 message.normalize();
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
159 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
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 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162
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 case SVRC_LOGGEDIN:
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
164 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
165 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
166 m_hostname = packet.read_string();
23
f7221183a994 - the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
167 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
168 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
169
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
170 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
171 process_server_updates (packet);
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
172
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
173 print ("Previous messages:\n");
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
174
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
175 for (int i = packet.read_byte(); i > 0; --i)
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
176 {
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
177 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
178 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
179 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
180 }
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
181
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
182 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
183 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
184
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
185 case SVRC_UPDATE:
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
186 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
187 break;
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
188 }
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 }
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
190 }
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
191 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
192 {
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
193 print ("error while reading packet: %1\n", e.what());
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
194 }
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
195 }
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
196
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
197 METHOD
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
198 RCONSession::process_server_updates (Bytestream& packet) -> void
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 switch (RCONUpdateType (packet.read_byte()))
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 case SVRCU_PLAYERDATA:
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
203 {
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
204 StringList players;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
205
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
206 for (int i = packet.read_byte(); i > 0; --i)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
207 players << packet.read_string();
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
208
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
209 Interface::set_player_names (players);
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 break;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
212
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
213 case SVRCU_ADMINCOUNT:
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
214 m_numAdmins = packet.read_byte();
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
215 Interface::update_statusbar();
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
216 break;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
217
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
218 case SVRCU_MAP:
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
219 m_level = packet.read_string();
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
220 Interface::update_statusbar();
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
221 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
222 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 RCONSession::socket() -> UDPSocket*
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 return &m_socket;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 }
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 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 RCONSession::send_hello() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 {
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
238 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
239 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 packet.write_byte (CLRC_BEGINCONNECTION);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 packet.write_byte (RCON_PROTOCOL_VERSION);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 send (packet);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 bump_last_ping();
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_password() -> 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 ("Authenticating...\n");
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_PASSWORD);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 packet.write_string ((m_salt + m_password).md5());
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::set_password (const String& password) -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 m_password = password;
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 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 RCONSession::bump_last_ping() -> void
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 time_t now;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 time (&now);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 m_lastPing = now;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 }
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
276
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
277 // -------------------------------------------------------------------------------------------------
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
278 //
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
279 STATIC METHOD
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
280 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
281 {
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
282 if (g_rconSession == nullptr)
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
283 new_session();
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
284
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
285 return g_rconSession;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
286 }
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
287
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
288 // -------------------------------------------------------------------------------------------------
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
289 //
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
290 METHOD
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
291 RCONSession::is_active() const -> bool
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
292 {
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
293 return state() != RCON_DISCONNECTED;
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
294 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
295
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
296 // -------------------------------------------------------------------------------------------------
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
297 // Returns true if the message was successfully sent.
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 METHOD
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
300 RCONSession::send_command (const String& message) -> bool
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
301 {
22
77d02446edf0 - don't send empty messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
302 if (m_state != RCON_CONNECTED or message.is_empty())
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
303 return false;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
304
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
305 Bytestream packet;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
306 packet.write_byte (CLRC_COMMAND);
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
307 packet.write_string (message);
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
308 send (packet);
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
309 bump_last_ping();
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
310 return true;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
311 }
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
312
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
313 // -------------------------------------------------------------------------------------------------
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
314 //
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
315 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
316 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
317 {
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
318 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
319 }
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
320
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
321 // -------------------------------------------------------------------------------------------------
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 METHOD
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
324 RCONSession::address() const -> const IPAddress&
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 return m_address;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
327 }
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
328
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 //
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
331 METHOD
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
332 RCONSession::num_admins() const -> int
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 return m_numAdmins;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
335 }
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 // -------------------------------------------------------------------------------------------------
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 METHOD
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
340 RCONSession::level() const -> const String&
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 return m_level;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
343 }

mercurial