// Packet event handler private void RecieveConnection(RecievedPacket packet) { if (peerManager != null) { // Get the request to connect if (packet.type == PacketType.connectToNetwork && packet.value == PacketValue.addUpdate) { if (InLobby) { // Get the connecting peer and assign it a new Id peerManager.RecievePeer(peerManager.GetPeerDataFromBytes(packet.data), packet.GetTimeDifference()); SendCurrentNetwork(); } } // Get the change in the network else if (packet.type == PacketType.returnNetwork && packet.value == PacketValue.completeList) { peerManager.RetrievePeersFromBytes(packet); if (!InLobby) { JoinLobby(false); } UpdateLobbyMenu(); } // Get the request to disconnect else if (packet.type == PacketType.disconnectNetwork && packet.value != PacketValue.confirmation) { InvokeDisconnect(packet.data[0]); } } }
// Convert bytes to the list and callback what to do with the object info public void GetListFromBytes(RecievedPacket packet, Action <List <object>, float> callback) { int curI = 0; while (curI < packet.data.Count) { byte length = packet.data[curI]; curI++; callback.Invoke(DataConverter.ConvertByteToObject <T>(packet.data.GetRange(curI, length)), packet.GetTimeDifference()); curI += length; } }