public bool ClientInit(byte[] verificationCode, NetworkfConnection applyTo) { Logger.WriteLine("waiting server requirement..."); lock (mtx) { while (!_hasReceivedServerVerificationRequirement) { Monitor.Wait(mtx); } } Logger.WriteLine("server requirement received"); var verifyMsg = new ClientVerifyMessage(); verifyMsg.verificationCode = verificationCode; _service.SendMessage(verifyMsg); Logger.WriteLine("waiting verification result..."); lock (mtx) { while (!_hasReceivedServerVerificationResult) { Monitor.Wait(mtx); } } Logger.WriteLine("verification result received"); if (_verificationResult) { _service.parseMessage = null; _service.OnMessageReceived -= OnRawMessageReceived; applyTo.ApplyService(_service); return(true); } else { return(false); } }
public void ServerApplyConnection(NetworkfConnection applyTo) { if (applyTo != null) { _service.parseMessage = null; _service.OnMessageReceived -= OnRawMessageReceived; applyTo.ApplyService(_service); var serMsg = new ServerVerifyResultMessage(); serMsg.result = true; _service.SendMessage(serMsg); Logger.WriteLine("verification result has sent"); } else { var serMsg = new ServerVerifyResultMessage(); serMsg.result = true; _service.SendMessage(serMsg); Logger.WriteLine("verification result has sent"); _service.parseMessage = null; _service.OnMessageReceived -= OnRawMessageReceived; _service.TeardownService(); } }