private bool GetPackets() { SendFound = false; lock (link.SendData_Lock) { if (link.SendDataPortalArrayOUTPUT[0] == null) { return(true); } for (int x = 0; x < link.SendDataPortalArrayOUTPUT.Length; x++) { if (link.SendDataPortalArrayOUTPUT[x].Count > 0) { byteData = link.SendDataPortalArrayOUTPUT[x].Dequeue(); SendFound = true; if (byteData._CallEmpybuffer) { _CallEmptyBuffer = true; } break; } } if (!SendFound) { IsInSendQueue = false; //Debug.WriteLine("no data"); //if _CallEmptyBuffer is set, trigger an event to get more data if (_CallEmptyBuffer) { _CallEmptyBuffer = false; LinkEventArgs args = new LinkEventArgs() { lnk = link }; lock (_CallOnEmptyBuffer_Lock) { _CallOnEmptyBufferQueue.Enqueue(args); } QueueOnEmptyBuffer(); } return(true); } } return(false); }
/// <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 Packet_Send PackContainer(BinaryWriter bwpc, MemoryStream mspc) { _SendPacket = new Packet_Send(null, false); //write direct into Portalstream _bw = bwpc; _ms = mspc; foreach (racefield field in _FieldList) { field.wd(field.FI); } // set to null, saftey first _bw = null; _ms = null; return(_SendPacket); }
/// <summary> /// Send data packets to the client. /// </summary> /// <param name="lnk">the link to the client</param> /// <param name="con">the container you want to send. can be null.</param> /// <param name="ContainerID">manually set</param> /// <param name="ObjectID">manually set</param> /// <param name="CallEmptyBufferEvent">if true raise an event</param> public void SendContainer(Link lnk, Container con, ushort ContainerID, uint ObjectID, bool CallEmptyBufferEvent = false) { //Operating threadsave lock (SendContainer_lock) { if (lnk.IsConnected == false || _sendBW == null) { return; } // write databody counter = 0; if (con != null) { _sendMS.Position = PacketHeadSize + 4; Packet_Send spacket = con.PackContainer(_sendBW, _sendMS); //big datapacket dedected /*if (_sendMS.Position >= Options.MaximumPacketSize + 4) * { * return; * } * else * {*/ counter = (ushort)_sendMS.Position - 4; //} //write header _sendMS.Position = 0; _sendBW.Write(counter); _sendBW.Write(this._PID); _sendBW.Write(ObjectID); _sendBW.Write(ContainerID); //Operating threadsave lock (lnk.SendData_Lock) { if (lnk.SendDataPortalArray[_PID] != null) { spacket._SendData = _sendMS.ToArray(); spacket._CallEmpybuffer = CallEmptyBufferEvent; lnk.SendDataPortalArray[_PID].Enqueue(spacket); lnk.Connect.QueueSend(); } } } else { counter += PacketHeadSize; //write header _sendMS.Position = 0; _sendBW.Write(counter); _sendBW.Write(this._PID); _sendBW.Write(ObjectID); _sendBW.Write(ContainerID); //Operating threadsave lock (lnk.SendData_Lock) { if (lnk.SendDataPortalArray[_PID] != null) { Packet_Send spacket = new Packet_Send(_sendMS.ToArray(), CallEmptyBufferEvent); lnk.SendDataPortalArray[_PID].Enqueue(spacket); lnk.Connect.QueueSend(); } } } //reset _sendMS.SetLength(0); //_sendMS.Flush(); } }