public void OnReceivePacket(IPEndPoint ipEndpoint, PacketType packetType, Stream stream) { switch (packetType) { case PacketType.ConnectionRequest: ConnectionRequestPacket connectionRequestPacket = new ConnectionRequestPacket(); connectionRequestPacket.Deserialize(stream); CheckAndSendChallengeRequest(ipEndpoint, connectionRequestPacket.payload); break; case PacketType.ChallengeRequest: ChallengeRequestPacket challengeRequestPacket = new ChallengeRequestPacket(); challengeRequestPacket.Deserialize(stream); CheckAndSendChallengeResponse(ipEndpoint, challengeRequestPacket.payload); break; case PacketType.ChallengeResponse: ChallengeResponsePacket challengeResponsePacket = new ChallengeResponsePacket(); challengeResponsePacket.Deserialize(stream); CheckResult(ipEndpoint, challengeResponsePacket.payload); break; case PacketType.Connected: if (!isServer && currentState == State.RespondingChallenge) { currentState = State.Connected; } break; } }
public void OnReceivePacket(IPEndPoint ipEndpoint, PacketType packetType, Stream stream) { switch (packetType) { case PacketType.ConnectionRequest: { ConnectionRequestPacket connectionRequestPacket = new ConnectionRequestPacket(); connectionRequestPacket.Deserialize(stream); CheckAndSendChallengeRequest(ipEndpoint, connectionRequestPacket.payload); } break; case PacketType.ChallengeRequest: { ChallengeRequestPacket challengeRequestPacket = new ChallengeRequestPacket(); challengeRequestPacket.Deserialize(stream); CheckAndSendChallengeResponse(ipEndpoint, challengeRequestPacket.payload); } break; case PacketType.ChallengeResponse: { ChallengeResponsePacket challengeResponsePacket = new ChallengeResponsePacket(); challengeResponsePacket.Deserialize(stream); CheckResult(ipEndpoint, challengeResponsePacket.payload); } break; case PacketType.Connected: { FinishHandShake(); } break; } }
void SendChallengeRequest(IPEndPoint ip, BitArray serverDirt) { Debug.Log("Enviando ChallengeRequest"); ChallengeRequestPacket packet = new ChallengeRequestPacket(); packet.payload = serverDirt; PacketsManager.Instance.SendPacket(packet, ip, objectId); }
private void OnChallengeRequest(IPEndPoint iPEndPoint, Stream stream) { Debug.Log("OnChallengeRequest"); ChallengeRequestPacket challengeRequestPacket = new ChallengeRequestPacket(); challengeRequestPacket.Deserialize(stream); StoreClientAndServerSalt(challengeRequestPacket.payload); SetClientConnectionStateTo(ClientConnectionState.OnChallengeResponse); }
private void SendChallengeRequest(Client client) { ChallengeRequestPacket packet = new ChallengeRequestPacket(); packet.payload.clientID = client.id; packet.payload.clientSalt = client.clientSalt; packet.payload.serverSalt = client.serverSalt; SendToClient(packet, client.ipEndPoint); }
private void SendChallengeRequest(Client client) { ChallengeRequestPacket request = new ChallengeRequestPacket(); request.payload.clientId = client.id; request.payload.clientSalt = client.clientSalt; request.payload.serverSalt = client.serverSalt; SendToClient(request, client.ipEndPoint); }
private void SendChallengeRequest(ConnectionRequestInformation data, int cId, long cSalt, long sSalt, IPEndPoint iPEnd) { ChallengeRequestPacket requestPacket = new ChallengeRequestPacket(); requestPacket.payload.clientId = cId; requestPacket.payload.clientSalt = cSalt; requestPacket.payload.serverSalt = sSalt; SendToClient(requestPacket, iPEnd); }
void SendChallengeRequest(uint clientId, long clientSalt, long serverSalt, IPEndPoint ipEndPoint) { ChallengeRequestPacket packet = new ChallengeRequestPacket(); packet.payload.clientId = clientId; packet.payload.clientSalt = clientSalt; packet.payload.serverSalt = serverSalt; PacketManager.Instance.SendPacketToClient(packet, ipEndPoint); }
void SendChallengeRequest(UdpPendingClientData udpPendingClientData) { ChallengeRequestPacket challengeRequestPacket = new ChallengeRequestPacket(); ChallengeRequestData challengeRequestData; challengeRequestData.serverSalt = udpPendingClientData.serverSalt; challengeRequestPacket.Payload = challengeRequestData; PacketsManager.Instance.SendPacket(challengeRequestPacket, udpPendingClientData.ipEndPoint); }
public void ReceivingChallengeRequest(Stream stream, IPEndPoint iPEnd) { if (!NetworkManager.Instance.isServer) { state = ConnectionState.ChallengeComplying; ChallengeRequestPacket challengePacket = new ChallengeRequestPacket(); challengePacket.Deserialize(stream); NetworkManager.Instance.clientId = challengePacket.payload.clientId; serverSalt = challengePacket.payload.serverSalt; SendChallengeResponse(challengePacket.payload.clientSalt, challengePacket.payload.serverSalt); } }
void OnChallenge(Stream stream, IPEndPoint iPEndPoint) { if (!NetworkManager.Instance.isServer) { state = State.AnsweringChallenge; ChallengeRequestPacket packet = new ChallengeRequestPacket(); packet.Deserialize(stream); clientId = packet.payload.clientId; serverSalt = packet.payload.serverSalt; SendChallengeResponse(packet.payload.clientSalt, serverSalt); } }
void OnRecieve(ushort type, Stream stream, IPEndPoint ip) { switch (type) { case (ushort)PacketType.ConnectionRequest: { ConnectionRequestPacket packet = new ConnectionRequestPacket(); packet.Deserialize(stream); AddNewClient(ip, packet.payload); break; } case (ushort)PacketType.ChallengeRequest: { onConectionRequest = false; ChallengeRequestPacket packet = new ChallengeRequestPacket(); packet.Deserialize(stream); serverDirt = packet.payload; DoChallenge(); break; } case (ushort)PacketType.ChallengeResponse: { ChallengeResponsePacket packet = new ChallengeResponsePacket(); packet.Deserialize(stream); CheckChallengeRecieved(ip, packet.payload); break; } case (ushort)PacketType.Conected: OnConected(); break; } }
void ReceiveConnectionData(ushort packetTypeIndex, IPEndPoint ipEndPoint, Stream stream) { switch ((PacketType)packetTypeIndex) { case PacketType.ChallengeRequest: if (!UdpNetworkManager.Instance.IsServer && clientConnectionState == ClientConnectionState.RequestingConnection) { ChallengeRequestPacket challengeRequestPacket = new ChallengeRequestPacket(); challengeRequestPacket.Deserialize(stream); challengeResultGeneratedByClient = saltGeneratedByClient ^ challengeRequestPacket.Payload.serverSalt; clientConnectionState = ClientConnectionState.SendingChallengeResponse; } break; case PacketType.ConnectionAccepted: if (!UdpNetworkManager.Instance.IsServer && clientConnectionState == ClientConnectionState.SendingChallengeResponse) { ConnectionAcceptedPacket connectionAcceptedPacket = new ConnectionAcceptedPacket(); connectionAcceptedPacket.Deserialize(stream); UdpNetworkManager.Instance.SetClientID(connectionAcceptedPacket.Payload.clientID); onClientConnectedCallback?.Invoke(connectionAcceptedPacket.Payload.clientsInSession); onClientConnectedCallback = null; clientConnectionState = ClientConnectionState.Connected; } break; case PacketType.ClientJoined: if (!UdpNetworkManager.Instance.IsServer && clientConnectionState == ClientConnectionState.Connected) { ClientJoinedPacket clientJoinedPacket = new ClientJoinedPacket(); clientJoinedPacket.Deserialize(stream); OnOtherClientJoined.Invoke(clientJoinedPacket.Payload.clientID); } break; case PacketType.ConnectionRequest: if (UdpNetworkManager.Instance.IsServer && !udpClientsIDs.ContainsKey(ipEndPoint)) { if (!udpPendingClientsData.ContainsKey(ipEndPoint)) { ConnectionRequestPacket connectionRequestPacket = new ConnectionRequestPacket(); connectionRequestPacket.Deserialize(stream); AddPendingClient(ipEndPoint, connectionRequestPacket.Payload.clientSalt); } UdpPendingClientData udpPendingClientData = udpPendingClientsData[ipEndPoint]; SendChallengeRequest(udpPendingClientData); } break; case PacketType.ChallengeResponse: if (UdpNetworkManager.Instance.IsServer) { if (udpPendingClientsData.ContainsKey(ipEndPoint)) { ChallengeResponsePacket challengeResponsePacket = new ChallengeResponsePacket(); UdpPendingClientData udpPendingClientData = udpPendingClientsData[ipEndPoint]; challengeResponsePacket.Deserialize(stream); long serverResult = udpPendingClientData.clientSalt ^ udpPendingClientData.serverSalt; if (challengeResponsePacket.Payload.result == serverResult) { ClientJoinedPacket clientJoinedPacket = new ClientJoinedPacket(); ClientJoinedData clientJoinedData; clientJoinedData.clientID = ClientID; clientJoinedPacket.Payload = clientJoinedData; PacketsManager.Instance.SendPacket(clientJoinedPacket, null, 0, 0, reliable: true); AddClient(ipEndPoint); RemovePendingClient(ipEndPoint); OnClientAddedByServer?.Invoke(udpClientsIDs[ipEndPoint]); } } if (udpClientsIDs.ContainsKey(ipEndPoint)) { SendConnectionAccepted(udpClientsData[udpClientsIDs[ipEndPoint]]); } } break; } }