sources/network/rconsession.cpp

Mon, 15 Dec 2014 03:09:26 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 15 Dec 2014 03:09:26 +0200
changeset 31
b5b5a6a96d91
parent 29
e534f2f78196
child 32
ee770597a281
permissions
-rw-r--r--

- added input history (use up/down to navigate)
- rcon sessions are never null anymore

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),
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
11 m_numAdmins (0)
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 {
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
13 if (g_rconSession != NULL)
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
14 {
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
15 g_rconSession->disconnect();
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
16 delete g_rconSession;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
17 }
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
18
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
19 g_rconSession = this;
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
20 }
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
21
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
22 // -------------------------------------------------------------------------------------------------
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
23 //
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
24 STATIC 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
25 RCONSession::new_session() -> RCONSession*
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
26 {
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
27 RCONSession* session = new RCONSession;
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
28
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
29 if (not session->socket()->set_blocking (false))
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 {
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
31 print ("unable to set socket as non-blocking: %s\n",
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
32 session->socket()->error_string().chars());
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 delete session;
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
34 return nullptr;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 }
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
36
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
37 return session;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 //
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
42 RCONSession::~RCONSession()
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
43 {
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
44 disconnect();
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
45
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
46 if (g_rconSession == this)
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
47 g_rconSession = nullptr;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
48 }
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 RCONSession::connect (IPAddress address) -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 m_address = address;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 m_state = RCON_CONNECTING;
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
57 Interface::update_statusbar();
10
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::disconnect() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 {
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
65 if (m_state > RCON_CONNECTING)
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 // Say goodbye to remote
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 packet.write_byte (CLRC_DISCONNECT);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 this->send (packet);
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
71 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
72 Interface::update_statusbar();
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 m_state = RCON_DISCONNECTED;
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 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 RCONSession::send (const Bytestream& packet) -> void
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 m_socket.send (m_address, packet);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 RCONSession::tick() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 {
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
91 if (m_state == RCON_DISCONNECTED)
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
92 return;
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
93
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 time_t now;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 time (&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_lastPing < now)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 if (m_state == RCON_CONNECTING)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 send_hello();
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 else if (m_state == RCON_AUTHENTICATING)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 send_password();
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 else if (m_state == RCON_CONNECTED and m_lastPing + 5 < now)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 packet.write_byte (CLRC_PONG);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 send (packet);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 bump_last_ping();
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 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 for (Datagram datagram; m_socket.read (datagram);)
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 handle_packet (datagram.data, datagram.from);
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 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 {
29
e534f2f78196 - handle the 'from' argument in RCONSession::handle_packet to filter out packets from foreign hosts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
125 if (from != m_address)
e534f2f78196 - handle the 'from' argument in RCONSession::handle_packet to filter out packets from foreign hosts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
126 return;
e534f2f78196 - handle the 'from' argument in RCONSession::handle_packet to filter out packets from foreign hosts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
127
13
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
128 try
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
129 {
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
130 while (packet.bytes_left() > 0)
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 {
13
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
132 int header = packet.read_byte();
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
133
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
134 switch (ServerResponse (header))
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
135 {
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
136 case SVRC_OLDPROTOCOL:
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
137 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
138 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
139 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140
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 case SVRC_BANNED:
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
142 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
143 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
144 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
13
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
146 case SVRC_SALT:
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 {
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 String salt = 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
149 m_salt = salt;
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 m_state = RCON_AUTHENTICATING;
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 send_password();
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 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_INVALIDPASSWORD:
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
156 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
157 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
158 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159
13
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
160 case SVRC_MESSAGE:
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
161 {
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
162 String message = packet.read_string();
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 if (message.ends_with ("\n"))
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
164 message.remove_from_end (1);
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
165
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
166 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
167 }
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 break;
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169
13
09dcaeaa216b - to hell with that 'ok' field. now throws an exception if attempts to read past the end
Teemu Piippo <crimsondusk64@gmail.com>
parents: 12
diff changeset
170 case SVRC_LOGGEDIN:
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
171 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
172 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
173 m_hostname = packet.read_string();
23
f7221183a994 - the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents: 22
diff changeset
174 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
175 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
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 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
178 process_server_updates (packet);
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
179
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
180 print ("Previous messages:\n");
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
181
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
182 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
183 {
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 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
185 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
186 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
187 }
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
188
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
189 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
190 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
191
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 case SVRC_UPDATE:
12
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
193 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
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 {
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
200 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
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 {
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
207 switch (RCONUpdateType (packet.read_byte()))
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
208 {
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
209 case SVRCU_PLAYERDATA:
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 Vector<String> players;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
212 for (int i = packet.read_byte(); i > 0; --i)
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
213 players << packet.read_string();
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
214 }
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
215 break;
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
216
8d0d1b368de0 - rcon session now works! woo!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
217 case SVRCU_ADMINCOUNT:
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
218 m_numAdmins = packet.read_byte();
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
219 Interface::update_statusbar();
12
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_MAP:
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
223 m_level = packet.read_string();
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;
10
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 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228
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 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 RCONSession::socket() -> UDPSocket*
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 return &m_socket;
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 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 RCONSession::send_hello() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 {
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
242 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
243 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 packet.write_byte (CLRC_BEGINCONNECTION);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 packet.write_byte (RCON_PROTOCOL_VERSION);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 send (packet);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 bump_last_ping();
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 RCONSession::send_password() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 {
21
12e4ff8bb471 - cleaned up rcon session messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
255 print ("Authenticating...\n");
10
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 Bytestream packet;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 packet.write_byte (CLRC_PASSWORD);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 packet.write_string ((m_salt + m_password).md5());
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259 send (packet);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 bump_last_ping();
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 // -------------------------------------------------------------------------------------------------
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 //
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
265 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 RCONSession::set_password (const String& password) -> void
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 m_password = password;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 }
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270
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 METHOD
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 RCONSession::bump_last_ping() -> void
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 {
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 time_t now;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 time (&now);
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 m_lastPing = now;
3874575d924d - begin work on rcon sessions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 }
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
280
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
281 // -------------------------------------------------------------------------------------------------
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
282 //
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
283 STATIC METHOD
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
284 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
285 {
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
286 if (g_rconSession == nullptr)
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
287 new_session();
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
288
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
289 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
290 }
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
291
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
292 // -------------------------------------------------------------------------------------------------
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
293 //
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
294 METHOD
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
295 RCONSession::is_active() const -> bool
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
296 {
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
297 return state() != RCON_DISCONNECTED;
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
298 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
299
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
300 // -------------------------------------------------------------------------------------------------
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
301 // Returns true if the message was successfully sent.
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
302 //
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
303 METHOD
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
304 RCONSession::send_command (const String& message) -> bool
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
305 {
22
77d02446edf0 - don't send empty messages
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
306 if (m_state != RCON_CONNECTED or message.is_empty())
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
307 return false;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
308
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
309 Bytestream packet;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
310 packet.write_byte (CLRC_COMMAND);
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
311 packet.write_string (message);
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
312 send (packet);
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
313 bump_last_ping();
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
314 return true;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
315 }
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
316
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 //
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 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
320 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
321 {
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
322 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
323 }
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
324
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
325 // -------------------------------------------------------------------------------------------------
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
326 //
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
327 METHOD
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
328 RCONSession::address() const -> const IPAddress&
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
329 {
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
330 return m_address;
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 //
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
335 METHOD
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
336 RCONSession::num_admins() const -> int
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 return m_numAdmins;
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 //
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
343 METHOD
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
344 RCONSession::level() const -> const String&
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
345 {
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
346 return m_level;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
347 }

mercurial