sources/network/rconsession.cpp

changeset 152
6be21be4bea1
parent 145
d0aedc9be448
child 153
82aac80a2f1d
child 156
ce66d7e374bf
equal deleted inserted replaced
149:7643c21d546b 152:6be21be4bea1
114 bump_last_ping(); 114 bump_last_ping();
115 } 115 }
116 } 116 }
117 117
118 for (Datagram datagram; m_socket.read (datagram);) 118 for (Datagram datagram; m_socket.read (datagram);)
119 handle_packet (datagram.data, datagram.from); 119 handle_packet (datagram);
120 } 120 }
121 121
122 // ------------------------------------------------------------------------------------------------- 122 // -------------------------------------------------------------------------------------------------
123 // 123 //
124 void RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) 124 void RCONSession::handle_packet (Datagram& datagram)
125 { 125 {
126 if (from != m_address) 126 if (datagram.address != m_address)
127 return; 127 return;
128 128
129 try 129 try
130 { 130 {
131 while (packet.bytes_left() > 0) 131 while (datagram.message.bytes_left() > 0)
132 { 132 {
133 int header = packet.read_byte(); 133 int header = datagram.message.read_byte();
134 134
135 switch (ServerResponse (header)) 135 switch (ServerResponse (header))
136 { 136 {
137 case SVRC_OLDPROTOCOL: 137 case SVRC_OLDPROTOCOL:
138 m_interface->printError ("Your RCON client is using outdated protocol.\n"); 138 m_interface->printError ("Your RCON client is using outdated protocol.\n");
143 m_interface->printError ("You have been banned from the server.\n"); 143 m_interface->printError ("You have been banned from the server.\n");
144 m_state = RCON_DISCONNECTED; 144 m_state = RCON_DISCONNECTED;
145 break; 145 break;
146 146
147 case SVRC_SALT: 147 case SVRC_SALT:
148 m_salt = packet.read_string(); 148 m_salt = datagram.message.read_string();
149 m_state = RCON_AUTHENTICATING; 149 m_state = RCON_AUTHENTICATING;
150 send_password(); 150 send_password();
151 break; 151 break;
152 152
153 case SVRC_INVALIDPASSWORD: 153 case SVRC_INVALIDPASSWORD:
155 m_state = RCON_DISCONNECTED; 155 m_state = RCON_DISCONNECTED;
156 break; 156 break;
157 157
158 case SVRC_MESSAGE: 158 case SVRC_MESSAGE:
159 { 159 {
160 String message = packet.read_string(); 160 String message = datagram.message.read_string();
161 message.normalize(); 161 message.normalize();
162 m_interface->printText ("%s\n", message.chars()); 162 m_interface->printText ("%s\n", message.chars());
163 } 163 }
164 break; 164 break;
165 165
166 case SVRC_LOGGEDIN: 166 case SVRC_LOGGEDIN:
167 m_interface->print ("Login successful!\n"); 167 m_interface->print ("Login successful!\n");
168 m_serverProtocol = packet.read_byte(); 168 m_serverProtocol = datagram.message.read_byte();
169 m_hostname = packet.read_string(); 169 m_hostname = datagram.message.read_string();
170 m_interface->setTitle (m_hostname); 170 m_interface->setTitle (m_hostname);
171 m_state = RCON_CONNECTED; 171 m_state = RCON_CONNECTED;
172 172
173 for (int i = packet.read_byte(); i > 0; --i) 173 for (int i = datagram.message.read_byte(); i > 0; --i)
174 process_server_updates (packet); 174 process_server_updates (datagram.message);
175 175
176 m_interface->print ("Previous messages:\n"); 176 m_interface->print ("Previous messages:\n");
177 177
178 for (int i = packet.read_byte(); i > 0; --i) 178 for (int i = datagram.message.read_byte(); i > 0; --i)
179 { 179 {
180 String message = packet.read_string(); 180 String message = datagram.message.read_string();
181 message.normalize(); 181 message.normalize();
182 m_interface->printText ("--- %s\n", message.chars()); 182 m_interface->printText ("--- %s\n", message.chars());
183 } 183 }
184 184
185 m_interface->print ("End of previous messages.\n"); 185 m_interface->print ("End of previous messages.\n");
186 break; 186 break;
187 187
188 case SVRC_UPDATE: 188 case SVRC_UPDATE:
189 process_server_updates (packet); 189 process_server_updates (datagram.message);
190 break; 190 break;
191 191
192 case SVRC_TOOMANYTABCOMPLETES: 192 case SVRC_TOOMANYTABCOMPLETES:
193 { 193 {
194 unsigned int numCompletions = packet.read_short(); 194 unsigned int numCompletions = datagram.message.read_short();
195 m_interface->print ("%d completions for '%s'.\n", 195 m_interface->print ("%d completions for '%s'.\n",
196 int (numCompletions), m_lastTabComplete.chars()); 196 int (numCompletions), m_lastTabComplete.chars());
197 } 197 }
198 break; 198 break;
199 199
200 case SVRC_TABCOMPLETE: 200 case SVRC_TABCOMPLETE:
201 { 201 {
202 StringList completes; 202 StringList completes;
203 completes.resize(packet.read_byte()); 203 completes.resize(datagram.message.read_byte());
204 204
205 for (String& completion : completes) 205 for (String& completion : completes)
206 completion = packet.read_string(); 206 completion = datagram.message.read_string();
207 207
208 if (completes.size() == 1) 208 if (completes.size() == 1)
209 { 209 {
210 m_interface->tabComplete (m_lastTabComplete, completes[0]); 210 m_interface->tabComplete (m_lastTabComplete, completes[0]);
211 } 211 }

mercurial