/// <summary> /// Sends the specified message. /// </summary> /// <param name="Message">The message.</param> public void SendMessage(Message Message) { if (this.Device.Token.IsConnected) { if (Message.IsServerToClientMessage == false) { Message.Encode(); byte[] Decrypted = Message.Stream.ToArray(); byte[] Encrypted = null; if (this.SendEncrypter != null) { Encrypted = this.SendEncrypter.Encrypt(Decrypted); } else { if (this.PepperInit.State > 0) { if (this.PepperInit.State == 2) { this.PepperInit.ServerPublicKey = PepperFactory.PublicKey; Encrypted = PepperCrypto.SendPepperLogin(ref this.PepperInit, Decrypted); } } else { Encrypted = PepperCrypto.SendPepperAuthentification(ref this.PepperInit, Decrypted); } } Message.Stream.SetByteArray(Encrypted); NetworkTcp.Send(Message.ToBytes, this.Device.Token); } else { Logging.Warning(this.GetType(), "ClientToServer != false at SendMessage(Message " + Message.Type + ")."); } } // else { // Logging.Warning(this.GetType(), "[" + this.Device.BotId + "] IsConnected != true at SendMessage(Message " + Message.Type + ")."); } }
/// <summary> /// Sends the specified message. /// </summary> /// <param name="Message">The message.</param> public void SendMessage(Message Message) { Logging.Info(typeof(NetworkTcp), "Sending " + Message.GetType().Name + "."); if (this.Device.Token.IsConnected) { if (Message.IsServerToClientMessage) { Message.Encode(); byte[] Bytes = Message.Stream.ToArray(); if (this.SendEncrypter == null) { if (this.PepperInit.State > 0) { if (this.PepperInit.State == 1) { Bytes = PepperCrypto.SendPepperAuthentificationResponse(ref this.PepperInit, Bytes); } else { if (this.PepperInit.State == 3) { Bytes = PepperCrypto.SendPepperLoginResponse(ref this.PepperInit, out this.SendEncrypter, out this.ReceiveEncrypter, Bytes); } } } } else { Bytes = this.SendEncrypter.Encrypt(Bytes); } Message.Stream.SetByteArray(Bytes); NetworkTcp.Send(this.WriteHeader(Message), this.Device.Token); HandlerFactory.MessageHandle(this.Device, Message); // TODO : Probably call Task.Wait(). } else { Logging.Error(this.GetType(), "Message.IsServerToClientMessage != true at SendMessage(Message " + Message.Type + ")."); } } }
/// <summary> /// Sends the specified message. /// </summary> /// <param name="Message">The message.</param> public void SendMessage(Message Message) { Logging.Info(typeof(NetworkTcp), "Sending " + Message.GetType().Name + " to " + this.Device.Token.Socket.RemoteEndPoint + "."); if (this.Device.Token.IsConnected) { // Message.Encode(); byte[] Bytes = Message.Stream.ToArray(); if (this.SendEncrypter == null) { if (this.PepperInit.State > 0) { if (this.PepperInit.State == 1) { Bytes = PepperCrypto.SendPepperAuthentificationResponse(ref this.PepperInit, Bytes); } else { if (this.PepperInit.State == 3) { Bytes = PepperCrypto.SendPepperLoginResponse(ref this.PepperInit, out this.SendEncrypter, out this.ReceiveEncrypter, Bytes); } } } } else { Bytes = this.SendEncrypter.Encrypt(Bytes); } Message.Stream.SetByteArray(Bytes); Logging.Info(this.GetType(), BitConverter.ToString(Message.ToBytes)); NetworkTcp.Send(Message.ToBytes, this.Device.Token); HandlerFactory.MessageHandle(this.Device, Message).Wait(); } }