/// <summary> /// Encode process. /// </summary> /// <returns></returns> public byte[] Encode() { byte[] res = new byte[_message.Length]; foreach (var item in ReadByChunk().Select((chunk, i) => new { i, chunk })) { Array.Copy(_cipher.Encode(_message, _subKeys), 0, res, item.i, item.chunk.Length); } return(res); }
/// <summary> /// Encode process. /// </summary> /// <returns></returns> public byte[] Encode() { var res = new byte[_message.Length]; var i = -1; foreach (var item in ReadByChunk()) { Array.Copy(_cipher.Encode(item, _subKeys), 0, res, i + 1, item.Length); i += item.Length; } return(res); }
/// <summary> /// Sends a packet via TCP /// </summary> /// <param name="buf">Buffer containing the data to be sent</param> public void SendTCP(byte[] buf) { //Check if client is connected if (m_socket.Connected) { //Globals.Log.Debug(Marshal.ToHexDump( /*string.Format("{0} <=== <{3}> Packet 0x{1:X2} ({2}) length: {4}", m_config.PacketOutText, Marshal.ConvertToInt16(buf, 4), * Marshal.ConvertToInt16(buf, 4), TcpEndpoint, Marshal.ConvertToInt32(buf, 0), * buf.Length), * buf));*/ try { if (buf.Length > 4092) { // we need to split this up byte[] nb1 = new byte[4092]; int nl = buf.Length - 4092; byte[] nb2 = new byte[nl]; Buffer.BlockCopy(buf, 0, nb1, 0, 4092); Buffer.BlockCopy(buf, 4092, nb2, 0, nl); SendTCPOF(nb1); SendTCPOF(nb2); return; } lock (m_tcpQueue) { if (m_sendingTcp) { m_tcpQueue.Enqueue(buf); return; } m_sendingTcp = true; } Buffer.BlockCopy(m_encoding.Encode(buf), 0, m_writeEventArgs.Buffer, 0, buf.Length); int start = Environment.TickCount; m_writeEventArgs.SetBuffer(0, buf.Length); m_socket.SendAsync(m_writeEventArgs); int took = Environment.TickCount - start; //if (took > 100) //Globals.Log.Warning("SendTCP.SendAsync took {0}ms! (TCP to client: {1})", took, this.ToString()); } catch (Exception ex) { // assure that no exception is thrown into the upper layers and interrupt game loops! Disconnect(); Console.WriteLine("Exception: {0}", ex.ToString()); /* * log.Warning("It seems <" + ((m_client.Account != null) ? m_client.Account.Name : "???") + * "> went linkdead. Closing connection. (SendTCP, " + e.GetType() + ": " + e.Message + ")"); * GameServer.Instance.Disconnect(m_client); */ } } }