| 869 | { |
| 870 | return &identity; |
| 871 | } |
| 872 | } |
| 873 | return nullptr; |
| 874 | } |
| 875 | |
| 876 | PlayerIdentity* NetworkComponent::FindIdentity(int dpnid) |
| 877 | { |
| 878 | for (int i = 0; i < _identities.Size(); i++) |
| 879 | { |
| 880 | PlayerIdentity& identity = _identities[i]; |
| 881 | if (identity.dpnid == dpnid) |
| 882 | { |
| 883 | return &identity; |
| 884 | } |
| 885 | } |
| 886 | return nullptr; |
| 887 | } |
| 888 | |
| 889 | int NetworkComponent::ReceiveFileSegment(TransferFileMessage& msg) |
| 890 | { |
| 891 | if (Poseidon::IsSafeNetworkTransferredAssetPath(msg.path)) |
| 892 | { |
| 893 | msg.path = Poseidon::GetUserDirectory() + msg.path; |
| 894 | } |
| 895 | |
| 896 | // The declared geometry is wire-controlled. Reject it before any allocation or |
| 897 | // write so a malformed header can neither drive a giant Resize nor index/copy |
| 898 | // outside the buffers. |
| 899 | static const int kMaxTransferBytes = 256 * 1024 * 1024; |
| 900 | static const int kMaxTransferSegments = 1024 * 1024; |
| 901 | if (!WireBounds::SegmentInBounds(msg.totSize, msg.totSegments, msg.curSegment, msg.offset, msg.data.Size()) || |
| 902 | !WireBounds::ValidLength(msg.totSize, kMaxTransferBytes) || |
| 903 | !WireBounds::ValidCount(msg.totSegments, kMaxTransferSegments)) |
| 904 | { |
| 905 | return -1; |
| 906 | } |
| 907 | |
| 908 | // find file in list |
| 909 | int index = -1; |
| 910 | for (int i = 0; i < _files.Size(); i++) |
| 911 | { |
| 912 | if (_files[i].fileName == msg.path) |
| 913 | { |
| 914 | index = i; |
| 915 | break; |
| 916 | } |
| 917 | } |
| 918 | if (index < 0) |
| 919 | { |
| 920 | // new file |
| 921 | index = _files.Add(); |
| 922 | ReceivingFile& file = _files[index]; |
| 923 | file.fileName = msg.path; |
| 924 | file.fileSegments.Resize(msg.totSegments); |
| 925 | for (int i = 0; i < file.fileSegments.Size(); i++) |
| 926 | { |
| 927 | file.fileSegments[i] = false; |
| 928 | } |
nothing calls this directly
no test coverage detected