sources/network/rconsession.cpp

branch
protocol5
changeset 170
40d8d7231a36
parent 169
febc3ed5435c
child 171
d0fba0d7ad03
equal deleted inserted replaced
169:febc3ed5435c 170:40d8d7231a36
119 } 119 }
120 120
121 // Check for new packets in our socket 121 // Check for new packets in our socket
122 for (Datagram datagram; m_socket.read(datagram);) 122 for (Datagram datagram; m_socket.read(datagram);)
123 { 123 {
124 // Packet came from the wrong address, ignore 124 // Only process packets that originate from the game server.
125 if (datagram.address != m_address) 125 if (datagram.address == m_address)
126 continue; 126 {
127 127 // Parse and cut off the header.
128 // Parse and cut off the header. 128 PacketHeader header;
129 PacketHeader header; 129 {
130 { 130 // Read the header, and find the sequence number
131 // Read the header, and find the sequence number 131 Bytestream stream(datagram.message);
132 Bytestream stream(datagram.message); 132 header.header = stream.readLong();
133 header.header = stream.readLong(); 133 header.sequenceNumber = (header.header != 0) ? stream.readLong() : -1;
134 header.sequenceNumber = (header.header != 0) ? stream.readLong() : -1; 134 datagram.message = datagram.message.splice(stream.position(), datagram.message.size());
135 datagram.message = datagram.message.splice(stream.position(), datagram.message.size()); 135 }
136 } 136
137 137 // Try to store this packet into the queue. However, do not try to store packets without a sequence number.
138 // Try to store this packet into the queue. However, do not try to store packets without a sequence number. 138 bool stored = false;
139 bool stored = false; 139
140 140 if (header.sequenceNumber != -1)
141 if (header.sequenceNumber != -1) 141 stored = m_packetQueue.addPacket(header.sequenceNumber, datagram.message);
142 stored = m_packetQueue.addPacket(header.sequenceNumber, datagram.message); 142
143 143 // If the packet was not stored, we are to just process it right away.
144 // If the packet was not stored, we are to just process it right away. 144 if (stored == false)
145 if (stored == false) 145 handlePacket(datagram.message);
146 handlePacket(datagram.message); 146 }
147 } 147 }
148 148
149 // Check if we can now also process some packets from the queue. 149 // Check if we can now also process some packets from the queue.
150 if (m_packetQueue.hasPacketsToPop()) 150 if (m_packetQueue.hasPacketsToPop())
151 { 151 {

mercurial