private void SendMovement() { if (m_NetworkWriter.StartWritting()) { PlayerManager me = playersList[0]; if (me == null) { return; } m_NetworkWriter.WritePacketID((byte)Packets_ID.ID_MOVEMENT); // step 9 : Instead of sending x,y,w ..... , send the server version instead (x,y,w,velocity, angular velocity) m_NetworkWriter.Write(me.position.x); m_NetworkWriter.Write(me.position.y); m_NetworkWriter.Write(me.position.z); m_NetworkWriter.Write(me.pRotation.x); m_NetworkWriter.Write(me.pRotation.y); m_NetworkWriter.Write(me.pRotation.z); m_NetworkWriter.Write(me.velocity.x); m_NetworkWriter.Write(me.velocity.y); m_NetworkWriter.Write(me.velocity.z); m_NetworkWriter.Send(serveruid, Peer.Priority.Immediate, Peer.Reliability.Reliable, 0); } }
/// <summary> /// Parsing packet /// </summary> /// <param name="packet_id">PACKET ID - SEE Packets_ID.cs</param> private void OnReceivedPacket(byte packet_id) { bool IsInternalNetworkPackets = packet_id <= 134; if (IsInternalNetworkPackets) { if (packet_id == (byte)Peer.RakNet_Packets_ID.CONNECTION_REQUEST_ACCEPTED) { OnConnected(peer.incomingAddress); } if (packet_id == (byte)Peer.RakNet_Packets_ID.CONNECTION_ATTEMPT_FAILED) { OnDisconnected("Connection attempt failed"); } if (packet_id == (byte)Peer.RakNet_Packets_ID.INCOMPATIBLE_PROTOCOL_VERSION) { OnDisconnected("Incompatible protocol version"); } if (packet_id == (byte)Peer.RakNet_Packets_ID.CONNECTION_LOST) { OnDisconnected("Time out"); } if (packet_id == (byte)Peer.RakNet_Packets_ID.NO_FREE_INCOMING_CONNECTIONS) { OnDisconnected("Server is full."); } if (packet_id == (byte)Peer.RakNet_Packets_ID.DISCONNECTION_NOTIFICATION && !tmp_Banned && !tmp_Fake) { OnDisconnected("You are kicked!"); } } else { if (packet_id == (byte)Packets_ID.CL_INFO) { if (m_NetworkWriter.StartWritting()) { m_NetworkWriter.WritePacketID((byte)Packets_ID.CL_INFO); m_NetworkWriter.Write(m_ClientNetInfo.name); m_NetworkWriter.WritePackedUInt64(m_ClientNetInfo.local_id); m_NetworkWriter.Write(m_ClientNetInfo.client_hwid); m_NetworkWriter.Write(m_ClientNetInfo.client_version); m_NetworkWriter.Send(peer.incomingGUID, Peer.Priority.Immediate, Peer.Reliability.Reliable, 0);//sending } } if (packet_id == (byte)Packets_ID.CL_ACCEPTED) { m_ClientNetInfo.net_id = m_NetworkReader.ReadPackedUInt64(); Debug.Log("[Client] Accepted connection by server... [ID: " + m_ClientNetInfo.net_id + "]"); } if (packet_id == (byte)Packets_ID.CL_BANNED) { tmp_Banned = true; OnDisconnected("You are banned on this server!"); } if (packet_id == (byte)Packets_ID.CL_FAKE) { tmp_Fake = true; OnDisconnected("Fake client! Please wait few seconds..."); } } }