121 |
121 |
122 // ------------------------------------------------------------------------------------------------- |
122 // ------------------------------------------------------------------------------------------------- |
123 // |
123 // |
124 void RCONSession::handle_packet (Datagram& datagram) |
124 void RCONSession::handle_packet (Datagram& datagram) |
125 { |
125 { |
126 if (datagram.from != m_address) |
126 if (datagram.address != m_address) |
127 return; |
127 return; |
128 |
128 |
129 try |
129 try |
130 { |
130 { |
131 Bytestream& packet = datagram.data; |
131 int32_t header = datagram.message.read_long(); |
132 int32_t header = packet.read_long(); |
132 int32_t sequenceNumber = (header != 0) ? datagram.message.read_long() : 0; |
133 int32_t sequenceNumber = (header != 0) ? packet.read_long() : 0; |
|
134 m_interface->print("Recieved packet with header 0x%x and sequence number #%d\n", header, sequenceNumber); |
133 m_interface->print("Recieved packet with header 0x%x and sequence number #%d\n", header, sequenceNumber); |
135 |
134 |
136 while (packet.bytes_left() > 0) |
135 while (datagram.message.bytes_left() > 0) |
137 { |
136 { |
138 int header = packet.read_byte(); |
137 int header = datagram.message.read_byte(); |
139 |
138 |
140 switch (ServerResponse (header)) |
139 switch (ServerResponse (header)) |
141 { |
140 { |
142 case SVRC_OLDPROTOCOL: |
141 case SVRC_OLDPROTOCOL: |
143 m_interface->printError ("Your RCON client is using outdated protocol.\n"); |
142 m_interface->printError ("Your RCON client is using outdated protocol.\n"); |
148 m_interface->printError ("You have been banned from the server.\n"); |
147 m_interface->printError ("You have been banned from the server.\n"); |
149 m_state = RCON_DISCONNECTED; |
148 m_state = RCON_DISCONNECTED; |
150 break; |
149 break; |
151 |
150 |
152 case SVRC_SALT: |
151 case SVRC_SALT: |
153 m_salt = packet.read_string(); |
152 m_salt = datagram.message.read_string(); |
154 m_state = RCON_AUTHENTICATING; |
153 m_state = RCON_AUTHENTICATING; |
155 send_password(); |
154 send_password(); |
156 break; |
155 break; |
157 |
156 |
158 case SVRC_INVALIDPASSWORD: |
157 case SVRC_INVALIDPASSWORD: |
160 m_state = RCON_DISCONNECTED; |
159 m_state = RCON_DISCONNECTED; |
161 break; |
160 break; |
162 |
161 |
163 case SVRC_MESSAGE: |
162 case SVRC_MESSAGE: |
164 { |
163 { |
165 String message = packet.read_string(); |
164 String message = datagram.message.read_string(); |
166 message.normalize(); |
165 message.normalize(); |
167 m_interface->printText ("%s\n", message.chars()); |
166 m_interface->printText ("%s\n", message.chars()); |
168 } |
167 } |
169 break; |
168 break; |
170 |
169 |
171 case SVRC_LOGGEDIN: |
170 case SVRC_LOGGEDIN: |
172 m_interface->print ("Login successful!\n"); |
171 m_interface->print ("Login successful!\n"); |
173 m_serverProtocol = packet.read_byte(); |
172 m_serverProtocol = datagram.message.read_byte(); |
174 m_hostname = packet.read_string(); |
173 m_hostname = datagram.message.read_string(); |
175 m_interface->setTitle (m_hostname); |
174 m_interface->setTitle (m_hostname); |
176 m_state = RCON_CONNECTED; |
175 m_state = RCON_CONNECTED; |
177 |
176 |
178 for (int i = packet.read_byte(); i > 0; --i) |
177 for (int i = datagram.message.read_byte(); i > 0; --i) |
179 process_server_updates (packet); |
178 process_server_updates (datagram.message); |
180 |
179 |
181 m_interface->print ("Previous messages:\n"); |
180 m_interface->print ("Previous messages:\n"); |
182 |
181 |
183 for (int i = packet.read_byte(); i > 0; --i) |
182 for (int i = datagram.message.read_byte(); i > 0; --i) |
184 { |
183 { |
185 String message = packet.read_string(); |
184 String message = datagram.message.read_string(); |
186 message.normalize(); |
185 message.normalize(); |
187 m_interface->printText ("--- %s\n", message.chars()); |
186 m_interface->printText ("--- %s\n", message.chars()); |
188 } |
187 } |
189 |
188 |
190 m_interface->print ("End of previous messages.\n"); |
189 m_interface->print ("End of previous messages.\n"); |
193 request_watch("sv_hostname"); |
192 request_watch("sv_hostname"); |
194 m_interface->print ("Watch requested.\n"); |
193 m_interface->print ("Watch requested.\n"); |
195 break; |
194 break; |
196 |
195 |
197 case SVRC_UPDATE: |
196 case SVRC_UPDATE: |
198 process_server_updates (packet); |
197 process_server_updates (datagram.message); |
199 break; |
198 break; |
200 |
199 |
201 case SVRC_TOOMANYTABCOMPLETES: |
200 case SVRC_TOOMANYTABCOMPLETES: |
202 { |
201 { |
203 unsigned int numCompletions = packet.read_short(); |
202 unsigned int numCompletions = datagram.message.read_short(); |
204 m_interface->print ("%d completions for '%s'.\n", |
203 m_interface->print ("%d completions for '%s'.\n", |
205 int (numCompletions), m_lastTabComplete.chars()); |
204 int (numCompletions), m_lastTabComplete.chars()); |
206 } |
205 } |
207 break; |
206 break; |
208 |
207 |
209 case SVRC_TABCOMPLETE: |
208 case SVRC_TABCOMPLETE: |
210 { |
209 { |
211 StringList completes; |
210 StringList completes; |
212 completes.resize(packet.read_byte()); |
211 completes.resize(datagram.message.read_byte()); |
213 |
212 |
214 for (String& completion : completes) |
213 for (String& completion : completes) |
215 completion = packet.read_string(); |
214 completion = datagram.message.read_string(); |
216 |
215 |
217 if (completes.size() == 1) |
216 if (completes.size() == 1) |
218 { |
217 { |
219 m_interface->tabComplete (m_lastTabComplete, completes[0]); |
218 m_interface->tabComplete (m_lastTabComplete, completes[0]); |
220 } |
219 } |
231 } |
230 } |
232 } |
231 } |
233 break; |
232 break; |
234 |
233 |
235 case SVRC_WATCHINGCVAR: |
234 case SVRC_WATCHINGCVAR: |
236 m_interface->print ("You are now watching %s\n", packet.read_string().chars()); |
235 m_interface->print ("You are now watching %s\n", datagram.message.read_string().chars()); |
237 m_interface->print ("Its value is: %s\n", packet.read_string().chars()); |
236 m_interface->print ("Its value is: %s\n", datagram.message.read_string().chars()); |
238 break; |
237 break; |
239 |
238 |
240 case SVRC_ALREADYWATCHINGCVAR: |
239 case SVRC_ALREADYWATCHINGCVAR: |
241 m_interface->print ("You are already watching %s\n", packet.read_string().chars()); |
240 m_interface->print ("You are already watching %s\n", datagram.message.read_string().chars()); |
242 break; |
241 break; |
243 |
242 |
244 case SVRC_WATCHCVARNOTFOUND: |
243 case SVRC_WATCHCVARNOTFOUND: |
245 m_interface->print ("CVar %s not found\n", packet.read_string().chars()); |
244 m_interface->print ("CVar %s not found\n", datagram.message.read_string().chars()); |
246 break; |
245 break; |
247 |
246 |
248 case SVRC_CVARCHANGED: |
247 case SVRC_CVARCHANGED: |
249 { |
248 { |
250 String name = packet.read_string(); |
249 String name = datagram.message.read_string(); |
251 String value = packet.read_string(); |
250 String value = datagram.message.read_string(); |
252 m_interface->print ("The value of CVar %s", name.chars()); |
251 m_interface->print ("The value of CVar %s", name.chars()); |
253 m_interface->print (" is now %s\n", value.chars()); |
252 m_interface->print (" is now %s\n", value.chars()); |
254 |
253 |
255 // If sv_hostname changes, update the titlebar |
254 // If sv_hostname changes, update the titlebar |
256 if (name == "sv_hostname") |
255 if (name == "sv_hostname") |