| 1798 | } |
| 1799 | |
| 1800 | bool NetworkBase::ProcessConnection(Connection& connection) |
| 1801 | { |
| 1802 | ReadPacket packetStatus; |
| 1803 | |
| 1804 | uint32_t countProcessed = 0; |
| 1805 | do |
| 1806 | { |
| 1807 | countProcessed++; |
| 1808 | packetStatus = connection.readPacket(); |
| 1809 | switch (packetStatus) |
| 1810 | { |
| 1811 | case ReadPacket::disconnected: |
| 1812 | // closed connection or network error |
| 1813 | if (!connection.getLastDisconnectReason()) |
| 1814 | { |
| 1815 | connection.setLastDisconnectReason(STR_MULTIPLAYER_CONNECTION_CLOSED); |
| 1816 | } |
| 1817 | return false; |
| 1818 | case ReadPacket::success: |
| 1819 | // done reading in packet |
| 1820 | reportPacketProgress(*this, connection); |
| 1821 | ProcessPacket(connection, connection.inboundPacket); |
| 1822 | if (!connection.isValid()) |
| 1823 | { |
| 1824 | return false; |
| 1825 | } |
| 1826 | break; |
| 1827 | case ReadPacket::moreData: |
| 1828 | // more data required to be read |
| 1829 | reportPacketProgress(*this, connection); |
| 1830 | break; |
| 1831 | case ReadPacket::noData: |
| 1832 | // could not read anything from socket |
| 1833 | break; |
| 1834 | } |
| 1835 | } while (packetStatus == ReadPacket::success && countProcessed < kMaxPacketsPerTick); |
| 1836 | |
| 1837 | if (!connection.receivedDataRecently()) |
| 1838 | { |
| 1839 | LOG_INFO( |
| 1840 | "No data received recently from connection %s, disconnecting connection.", |
| 1841 | connection.socket->GetIpAddress().c_str()); |
| 1842 | |
| 1843 | if (!connection.getLastDisconnectReason()) |
| 1844 | { |
| 1845 | connection.setLastDisconnectReason(STR_MULTIPLAYER_NO_DATA); |
| 1846 | } |
| 1847 | return false; |
| 1848 | } |
| 1849 | |
| 1850 | return true; |
| 1851 | } |
| 1852 | |
| 1853 | void NetworkBase::ProcessPacket(Connection& connection, Packet& packet) |
| 1854 | { |
nothing calls this directly
no test coverage detected