//internal BinaryWriter _DecodeMSWriter = null; /// <summary> /// Unpacks a Packet_Recv data packet. /// </summary> /// <param name="pak">the packet</param> /// <returns>Is true if the unpacking was successful.</returns> public bool UnpackContainer(Packet_Recv pak) { try { if (pak.Data == null) { return(false); } _DecodeMS.SetLength(0); _DecodeMS.Write(pak.Data, 0, pak.Data.Length); _DecodeMS.Position = 0; _ReadCounter = 0; _ReadSize = pak.Data.Length; foreach (racefield Rfield in _FieldList) { Rfield.rd(Rfield.FI); } return(true); } catch (Exception e) { Debug.WriteLine("Vaser packet decode error: ClassID> " + pak.ClassID + " ContainerID> " + pak.ContainerID + " ObjectID> " + pak.ObjectID + " Packetsize> " + pak.Data.Length + " MEM L> " + _DecodeMS.Length + " P> " + _DecodeMS.Position + " ERROR> " + e.ToString()); return(false); } }
internal void GivePacketToClass(Packet_Recv pak) { Portal clas = PortalArray[pak.ClassID]; if (clas != null) { clas.AddPacket(pak); } else { Debug.WriteLine("Vaser.Portal> Portal not found."); pak.link.Dispose(); } }
/// <summary> /// Forward a packet unread further to another client or server. /// </summary> /// <param name="lnk">The target link.</param> /// <param name="packet">The unread packet.</param> public void DispatchContainer(Link lnk, Packet_Recv packet) { //Operating threadsave lock (SendContainer_lock) { if (lnk.IsConnected == false || _sendBW == null) { return; } _sendMS.Position = 0; if (_sendBW != null) { if (packet.Data == null) { _sendBW.Write(PacketHeadSize); _sendBW.Write(this._PID); _sendBW.Write(packet.ObjectID); _sendBW.Write(packet.ContainerID); } else { _sendBW.Write(packet.Data.Length + PacketHeadSize); _sendBW.Write(this._PID); _sendBW.Write(packet.ObjectID); _sendBW.Write(packet.ContainerID); _sendBW.Write(packet.Data); } } //Operating threadsave lock (lnk.SendData_Lock) { if (lnk.SendDataPortalArray[_PID] != null) { Packet_Send spacket = new Packet_Send(_sendMS.ToArray(), false); lnk.SendDataPortalArray[_PID].Enqueue(spacket); lnk.Connect.QueueSend(); } } //reset _sendMS.SetLength(0); //_sendMS.Flush(); } }
internal void AddPacket(Packet_Recv pak) { //operating Threadsafe lock (_AddPacket_lock) { packetList1.Add(pak); //PacketQueue.Enqueue(pak); if (!QueueLock) { QueueLock = true; ThreadPool.QueueUserWorkItem(EventWorker); } } }
internal void AddPacket(Packet_Recv pak) { //operating Threadsafe lock (_AddPacket_lock) { packetList1.Add(pak); //PacketQueue.Enqueue(pak); if (!QueueLock) { QueueLock = true; IAsyncAction asyncAction = Windows.System.Threading.ThreadPool.RunAsync(EventWorker); } } }
private void WritePackets() { //Debug.WriteLine("Write in _rms2 " + bytesRead + " _rms2.Position " + _rms2.Position); _rms2.Write(_buff, 0, bytesRead); //Debug.WriteLine("New _rms2.Position " + _rms2.Position); _rms2.Position = 0; action2 = true; while (action2) { action2 = false; switch (mode) { case 0: // get the packetsize if ((_rms2.Length - _rms2.Position) >= 4) { size = _rbr2.ReadInt32(); mode = 1; action2 = true; // Receive Heartbeat packet if (size == -1) { mode = 0; action2 = true; } else { //Debug.WriteLine("size " + size ); // if the Packetsize is beond the limits, terminate the connection. maybe a Hacking attempt? if (size > MaximumPacketSize || size < PacketHeadSize) { //Debug.WriteLine("The Size was: " + size + " > the Packetsize is beond the limits, terminate the connection. maybe a Hacking attempt?"); this.Stop(); mode = 100; break; } } } break; case 1: // recive the packet und give it to the class if ((_rms2.Length - _rms2.Position) >= size) { if (size == PacketHeadSize) { inlist.Add(new Packet_Recv(link, _rbr2)); //_PCollection.GivePacketToClass(new Packet_Recv(link, _rbr2)); } else { Packet_Recv Recv = new Packet_Recv(link, _rbr2) { Data = _rbr2.ReadBytes(size - PacketHeadSize) }; //_PCollection.GivePacketToClass(Recv); inlist.Add(Recv); } mode = 0; action2 = true; } break; } } _PCollection.GivePacketToClass(inlist); inlist.Clear(); //Debug.WriteLine("last _rms2.Length " + _rms2.Length+ " _rms2.Position " + _rms2.Position); if (_rms2.Length == _rms2.Position) { _rms2.SetLength(0); //_rms2.Flush(); _rms2.Position = 0; } else { byte[] lastbytes = new byte[(int)(_rms2.Length - _rms2.Position)]; //byte[] lastbytes = _rbr2.ReadBytes((int)(_rms2.Length - _rms2.Position)); _rms2.Read(lastbytes, 0, (int)(_rms2.Length - _rms2.Position)); _rms2.SetLength(0); //_rms2.Flush(); _rms2.Position = 0; _rms2.Write(lastbytes, 0, lastbytes.Length); _rms2.Position = lastbytes.Length; } }