public StreamBuffer(StreamBuffer source) { ReadBytes = 0; WrittenBytes = 0; Capacity(source.WrittenBytes); Write(source.Buffer, 0, source.WrittenBytes); }
public StreamBuffer(StreamBuffer source, int index, int size) { ReadBytes = 0; WrittenBytes = 0; Capacity(size); Write(source.Buffer, index, size); }
public void Add(MessageType type, StreamBuffer buffer, int size, Action actionOnComplete = null) { lock (_queue) { MessageData data = new MessageData(); data.Type = type; data.Buffer = buffer; data.Size = size; data.ActionOnComplete = actionOnComplete; _queue.Add(data); Monitor.Pulse(_queue); } }
public void AddFirst(MessageType type, StreamBuffer buffer, int size) { lock (_queue) { MessageData data = new MessageData(); data.Type = type; data.Buffer = buffer; data.Size = size; _queue.Insert(0, data); Monitor.Pulse(_queue); } }
public Connector(AegisClient parent) { _aegisClient = parent; _receivedBuffer = new StreamBuffer(); }
public bool SendPacket(StreamBuffer source) { try { _socket.Send(source.Buffer, 0, source.WrittenBytes, SocketFlags.None); return true; } catch (Exception e) { Debug.WriteLine(e.ToString()); } return false; }
internal bool IsValidPacket(StreamBuffer buffer, out int packetSize) { packetSize = 0; if (PacketValidator == null) return false; return PacketValidator(this, buffer, out packetSize); }
public void SendPacket(StreamBuffer buffer, Action actionOnSent = null) { MQ.Add(MessageType.Send, buffer, buffer.WrittenBytes, actionOnSent); }
/// <summary> /// StreamBuffer의 데이터를 복사하여 패킷을 생성합니다. /// </summary> /// <param name="source">복사할 데이터가 담긴 StreamBuffer 객체</param> public Packet(StreamBuffer source) { Write(source.Buffer, 0, source.WrittenBytes); }
internal Response_IMC_Message(SecurePacket packet) : base(packet) { if (ResultCodeNo != ResultCode.Ok) return; SenderUserNo = packet.GetInt32(); Message = new StreamBuffer(packet.Buffer, packet.ReadBytes, packet.ReadableSize); }
private void OnReceive(AegisClient ac, StreamBuffer buffer) { SecurePacket packet = new SecurePacket(buffer); packet.Decrypt(AESIV, AESKey); packet.SkipHeader(); if (PacketPreprocessing != null && PacketPreprocessing(packet) == false) { _callbackQueue.AddPacket(packet); } }
private bool IsValidPacket(AegisClient ac, StreamBuffer buffer, out Int32 packetSize) { if (buffer.WrittenBytes < 8) { packetSize = 0; return false; } packetSize = buffer.GetUInt16(); return (packetSize > 0 && buffer.WrittenBytes >= packetSize); }
/// <summary> /// StreamBuffer의 데이터를 복사하여 패킷을 생성합니다. /// </summary> /// <param name="source">복사할 데이터가 담긴 StreamBuffer 객체</param> public Packet(StreamBuffer source) { Write(source.Buffer, 0, source.WrittenBytes); }
/// <summary> /// 패킷 버퍼를 초기화하고 source 데이터를 저장합니다. Packet Header의 Size는 source 버퍼의 헤더값이 사용됩니다. /// </summary> /// <param name="source">저장할 데이터</param> public void Clear(StreamBuffer source) { if (source.BufferSize < 4) throw new AegisException("The source size must be at lest 4 bytes."); base.Clear(); Write(source.Buffer, 0, source.WrittenBytes); Size = GetUInt16(0); }
private void OnSocket_Read(IAsyncResult ar) { if (_socket == null) return; try { // transBytes가 0이면 원격지 혹은 네트워크에 의해 연결이 끊긴 상태 int transBytes = _socket.EndReceive(ar); if (transBytes == 0) { _aegisClient.MQ.Add(MessageType.Disconnect, null, 0); return; } _receivedBuffer.Write(transBytes); while (_receivedBuffer.ReadableSize > 0) { // 패킷 하나가 정상적으로 수신되었는지 확인 int packetSize = 0; _receivedBuffer.ResetReadIndex(); if (_aegisClient.IsValidPacket(_receivedBuffer, out packetSize) == false) break; // 수신처리 try { StreamBuffer dispatchBuffer = new StreamBuffer(_receivedBuffer.Buffer, 0, packetSize); _aegisClient.MQ.Add(MessageType.Receive, dispatchBuffer, dispatchBuffer.WrittenBytes); _receivedBuffer.ResetReadIndex(); _receivedBuffer.Read(packetSize); } catch (Exception e) { Debug.WriteLine(e.ToString()); } // 처리된 패킷을 버퍼에서 제거 _receivedBuffer.PopReadBuffer(); } // ReceiveBuffer의 안정적인 처리를 위해 OnReceive 작업이 끝난 후에 다시 수신대기 WaitForReceive(); } catch (SocketException) { _aegisClient.MQ.Add(MessageType.Close, null, 0); } catch (Exception e) { Debug.WriteLine(e.ToString()); } }
public static void IMC_SendMessage(int targetUserNo, StreamBuffer data, APICallbackHandler<ResponseBase> callback) { SecurePacket reqPacket = new SecurePacket(Protocol.GetID("CS_IMC_SendMessage_Req")); reqPacket.PutInt32(_userNo); reqPacket.PutInt32(targetUserNo); reqPacket.Write(data.Buffer); _request.SendPacket(reqPacket, (resPacket) => { callback(new ResponseBase(resPacket)); }); }
public void SendPacket(StreamBuffer buffer, Action actionOnSent = null) { MQ.Add(MessageType.Send, buffer, buffer.WrittenBytes, actionOnSent); }