99 // ------------------------------------------------------------------------------------------------- |
99 // ------------------------------------------------------------------------------------------------- |
100 // |
100 // |
101 METHOD |
101 METHOD |
102 RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) -> void |
102 RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) -> void |
103 { |
103 { |
104 print ("Processing packet of %1 bytes\n", packet.written_length()); |
|
105 |
|
106 try |
104 try |
107 { |
105 { |
108 while (packet.bytes_left() > 0) |
106 while (packet.bytes_left() > 0) |
109 { |
107 { |
110 int header = packet.read_byte(); |
108 int header = packet.read_byte(); |
111 print ("Recieved packet with header %1\n", header); |
|
112 |
109 |
113 switch (ServerResponse (header)) |
110 switch (ServerResponse (header)) |
114 { |
111 { |
115 case SVRC_OLDPROTOCOL: |
112 case SVRC_OLDPROTOCOL: |
116 print ("wrong version\n"); |
113 print ("wrong version\n"); |
139 case SVRC_MESSAGE: |
136 case SVRC_MESSAGE: |
140 { |
137 { |
141 String message = packet.read_string(); |
138 String message = packet.read_string(); |
142 if (message.ends_with ("\n")) |
139 if (message.ends_with ("\n")) |
143 message.remove_from_end (1); |
140 message.remove_from_end (1); |
144 print ("message: %1\n", message); |
141 print ("%1\n", message); |
145 } |
142 } |
146 break; |
143 break; |
147 |
144 |
148 case SVRC_LOGGEDIN: |
145 case SVRC_LOGGEDIN: |
149 print ("login successful\n"); |
146 print ("Login successful!\n"); |
150 m_serverProtocol = packet.read_byte(); |
147 m_serverProtocol = packet.read_byte(); |
151 m_hostname = packet.read_string(); |
148 m_hostname = packet.read_string(); |
152 m_state = RCON_CONNECTED; |
149 m_state = RCON_CONNECTED; |
153 |
150 |
154 for (int i = packet.read_byte(); i > 0; --i) |
151 for (int i = packet.read_byte(); i > 0; --i) |
155 process_server_updates (packet); |
152 process_server_updates (packet); |
156 |
153 |
|
154 print ("Previous messages:\n"); |
157 for (int i = packet.read_byte(); i > 0; --i) |
155 for (int i = packet.read_byte(); i > 0; --i) |
158 { |
156 { |
159 String message = packet.read_string(); |
157 String message = packet.read_string(); |
160 message.normalize(); |
158 message.normalize(); |
161 print ("--- %1\n", message); |
159 print ("--- %1\n", message); |
162 } |
160 } |
|
161 print ("End of previous messages.\n"); |
163 break; |
162 break; |
164 |
163 |
165 case SVRC_UPDATE: |
164 case SVRC_UPDATE: |
166 process_server_updates (packet); |
165 process_server_updates (packet); |
167 break; |
166 break; |
182 case SVRCU_PLAYERDATA: |
181 case SVRCU_PLAYERDATA: |
183 { |
182 { |
184 Vector<String> players; |
183 Vector<String> players; |
185 for (int i = packet.read_byte(); i > 0; --i) |
184 for (int i = packet.read_byte(); i > 0; --i) |
186 players << packet.read_string(); |
185 players << packet.read_string(); |
187 print ("players: %1\n", players); |
186 print ("Players: %1\n", players); |
188 } |
187 } |
189 break; |
188 break; |
190 |
189 |
191 case SVRCU_ADMINCOUNT: |
190 case SVRCU_ADMINCOUNT: |
192 print ("num admins: %d1\n", packet.read_byte()); |
191 print ("Admin count: %d1\n", packet.read_byte()); |
193 break; |
192 break; |
194 |
193 |
195 case SVRCU_MAP: |
194 case SVRCU_MAP: |
196 print ("new map: %1\n", packet.read_string()); |
195 print ("New level: %1\n", packet.read_string()); |
197 break; |
196 break; |
198 } |
197 } |
199 } |
198 } |
200 |
199 |
201 // ------------------------------------------------------------------------------------------------- |
200 // ------------------------------------------------------------------------------------------------- |
209 // ------------------------------------------------------------------------------------------------- |
208 // ------------------------------------------------------------------------------------------------- |
210 // |
209 // |
211 METHOD |
210 METHOD |
212 RCONSession::send_hello() -> void |
211 RCONSession::send_hello() -> void |
213 { |
212 { |
214 print ("connecting to %1...\n", m_address.to_string (IP_WITH_PORT)); |
213 print ("Connecting to %1...\n", m_address.to_string (IP_WITH_PORT)); |
215 Bytestream packet; |
214 Bytestream packet; |
216 packet.write_byte (CLRC_BEGINCONNECTION); |
215 packet.write_byte (CLRC_BEGINCONNECTION); |
217 packet.write_byte (RCON_PROTOCOL_VERSION); |
216 packet.write_byte (RCON_PROTOCOL_VERSION); |
218 send (packet); |
217 send (packet); |
219 bump_last_ping(); |
218 bump_last_ping(); |
222 // ------------------------------------------------------------------------------------------------- |
221 // ------------------------------------------------------------------------------------------------- |
223 // |
222 // |
224 METHOD |
223 METHOD |
225 RCONSession::send_password() -> void |
224 RCONSession::send_password() -> void |
226 { |
225 { |
227 print ("sending password...\n"); |
226 print ("Authenticating...\n"); |
228 Bytestream packet; |
227 Bytestream packet; |
229 packet.write_byte (CLRC_PASSWORD); |
228 packet.write_byte (CLRC_PASSWORD); |
230 print ("password: %1\nsalt: %2\nhashed password: %3\n", m_password, m_salt, (m_salt + m_password).md5()); |
|
231 packet.write_string ((m_salt + m_password).md5()); |
229 packet.write_string ((m_salt + m_password).md5()); |
232 send (packet); |
230 send (packet); |
233 bump_last_ping(); |
231 bump_last_ping(); |
234 } |
232 } |
235 |
233 |