internal void Launch(float xSpeed, float rotationSpeed) { state = PacketState.Flying; this.xSpeed = xSpeed; this.rotationSpeed = rotationSpeed; //this.rotationSpeed = 0; }
private bool ReadBody(ref bool readFromNetwork) { if ((this.writeIndex == this.headerIndex) && this.lastPacket) { this.packetState = PacketState.Complete; return(true); } if (this.readIndex < this.headerIndex) { if ((this.writeIndex < this.headerIndex) && (this.writeIndex < this.buffer.Length)) { readFromNetwork = true; } else if (this.readIndex < this.buffer.Length) { return(true); } } else { this.packetState = PacketState.Header; } return(false); }
public Packet(byte[] buffer) { this.state = PacketState.Read; this.memoryStream = new MemoryStream(buffer, 0, buffer.Length); this.memoryReader = new BinaryReader(this.memoryStream); }
public byte[] Compile(out int length) { if (mCompiledBuffer == null) { if ((mState & PacketState.Accessed) == 0) { mState |= PacketState.Accessed; } else { if ((mState & PacketState.Warned) == 0) { mState |= PacketState.Warned; try { using (StreamWriter op = new StreamWriter("net_opt.log", true)) { op.WriteLine("Redundant compile for packet {0}, use Acquire() and Release()", this.GetType()); op.WriteLine(new System.Diagnostics.StackTrace()); } } catch { } } mCompiledBuffer = new byte[0]; mCompiledLength = 0; length = mCompiledLength; return(mCompiledBuffer); } InternalCompile(); } length = mCompiledLength; return(mCompiledBuffer); }
private void ReadHeader(ref bool readFromNetwork) { if (this.writeIndex >= (this.headerIndex + TcpHeaderLength)) { int packetLength = Utilities.ToInt32BigEndian(this.buffer.AsSpan(this.headerIndex, TcpHeaderLength)); if (packetLength < 0) { this.lastPacket = true; packetLength &= 0x0fffffff; } if (((packetLength % 4) != 0) || (packetLength == 0)) { throw new RpcException("This is not an XDR stream."); } this.packetState = PacketState.Body; this.bodyIndex = this.headerIndex + TcpHeaderLength; this.headerIndex = this.bodyIndex + packetLength; this.readIndex = this.bodyIndex; } else { readFromNetwork = true; } }
private void Update() { // Ale gunwo, popraw to. if (state == PacketState.Flying) { transform.Translate(Vector3.right * xSpeed * Time.deltaTime, Space.World); transform.Rotate(Vector3.forward * rotationSpeed); } if (state == PacketState.MovingToCollectedDestination) { //gameObject.transform.position = Vector2.MoveTowards(transform.position, destinationPosition, Time.deltaTime * 5f); transform.position = Vector2.Lerp(transform.position, destinationPosition, Time.deltaTime * 4f); transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.identity, Time.deltaTime * 10f); if (Vector2.Distance(transform.position, destinationPosition) < 0.1) { print("reached destination " + name); transform.position = destinationPosition; FindObjectOfType <RoundManager>().RewindPacketIfCollectedOnPosition(col, row); state = PacketState.Collected; } } }
// Respones functions #region HelloGame ^^ private void ParseTicket(string packet) { var date = packet.Split('|')[0]; var ip = packet.Split('|')[1]; if (DateTime.ParseExact(date, "MM/dd/yyyy HH:mm:ss", null).AddSeconds(Constant.TicketTimeExpiredInterval) < DateTime.ParseExact(DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), "MM/dd/yyyy HH:mm:ss", null)) { _client.SendPackets(Packet.TicketExpired); _client.OnSocketClosed(); } else if (ip.Equals(_client.Socket.IP)) { _client.SendPackets(Packet.InvalidIp); _client.OnSocketClosed(); } else { var account = packet.Split('|')[2].Split(','); try { _client.Account = new Account { Id = int.Parse(account[0]), Username = account[1], Password = account[2], Pseudo = account[3], Question = account[4], Reponse = account[5], GmLevel = int.Parse(account[7]), BannedUntil = account[8] == "" ? (DateTime?)null : DateTime.Parse(account[8].ToString(CultureInfo.InvariantCulture)), Subscription = account[9] == "" ? (DateTime?)null : DateTime.Parse(account[9].ToString(CultureInfo.InvariantCulture)), }; _packetState = PacketState.CharactersInfos; AccountRepository.UpdateAccount(_client.Account.Id); AccountRepository.UpdateCharactersList(_client.Account.Id); _packetState = PacketState.CharactersInfos; _client.SendPackets(Packet.TicketAccepted); } catch (Exception e) { SilverConsole.WriteLine(e.Message, ConsoleColor.Red); Logs.LogWritter(Constant.ErrorsFolder, string.Format("Impossible de charger le compte {0}", account[1])); } } }
public void SetState(PacketState state) { if (state == _state) { return; } _state = state; }
public Packet() { this.state = PacketState.Write; this.memoryStream = new MemoryStream(); this.memoryWriter = new BinaryWriter(this.memoryStream); this.Write(0); // packet size }
public HandshakePacket(int protocolVersion, string serverAddress, ushort serverPort, PacketState nextState) : base(PacketType.ToServer.Handshake .handshake) { this.protocolVersion = protocolVersion; this.serverAddress = serverAddress; this.serverPort = serverPort; this.nextState = nextState; }
public void Init(SplittedImage parentSplittedImage, int col, int row, Sprite sprite, PacketType packetType) { this.parentSplittedImage = parentSplittedImage; this.packetType = packetType; this.col = col; this.row = row; GetComponent <SpriteRenderer>().sprite = sprite; state = PacketState.ReadyToLaunch; name = sprite.name; }
internal void OnCollected() { state = PacketState.MovingToCollectedDestination; destinationPosition = GameObject.Find("GoodImageResult").transform.position; SpriteRenderer sr = GetComponent <SpriteRenderer>(); float w = sr.sprite.bounds.size.x; float h = sr.sprite.bounds.size.y; destinationPosition.x += col * w + w * 0.5f; destinationPosition.y -= row * h + h * 0.5f; }
public void ReadPacketTest(byte[] rawData, PacketState state) { using var stream = new MemoryStream(rawData); using var archive = new Unreal.Core.BinaryReader(stream); var reader = new MockReplayReader(); var result = reader.ReadPacket(archive); Assert.True(archive.AtEnd()); Assert.False(archive.IsError); Assert.Equal(state, result.State); }
public override bool Equals(object obj) { if ((obj == null) || (!(obj is PacketState))) { return(false); } PacketState source = (PacketState)obj; return((PacketNumber == source.PacketNumber) && (Gamepad.Equals(source.Gamepad))); }
public NetworkReadResult BeginReading() { this.readIndex = 0; this.writeIndex = 0; this.lastPacket = false; this.headerIndex = 0; this.bodyIndex = 0; this.packetState = PacketState.Header; return(this.FillBuffer()); }
public void OnData(byte[] data, int offset, int length) { try { this._readStream.Write(data, offset, length); while (this._readStream.Length >= this._needLenth) { if (this._packetState == PacketState.ReadHead) { if (this._readStream.Length >= this._needLenth) //头部读取完毕 { long originPos = this._readStream.Position; this._readStream.Position = 0; this._readStream.Read(this.headBytes, 0, this.headBytes.Length); //从头部取出内容长度 int tmpIndex = 0; this._bodyLength = BitConverterNoAlloc.ToInt32(this.headBytes, ref tmpIndex); this._needLenth = this._bodyLength + this.headBytes.Length; //头部仍然在流中,所以加上头部的长度 this._packetState = PacketState.ReadBody; this._readStream.Position = originPos; //恢复流位置 } } if (this._packetState == PacketState.ReadBody) { if (this._readStream.Length >= this._needLenth) //内容读取完毕 { ArraySegment <byte> buffer; if (!this._readStream.TryGetBuffer(out buffer)) { throw new Exception("Get Buffer From Stream Error"); } //先将剩余部分写在交换流中 int remainLength = (int)(this._readStream.Length - this._needLenth); this._packetSwapStream.Write(buffer.Array, this._needLenth, remainLength); //定位到内容部分并调用回调 this._readStream.SetLength(this._needLenth); this._readStream.Position = this.headBytes.Length; this._onPacket(this._readStream); //重置包接收流并将剩余部分写入包接收流 this._readStream.Position = 0; this._readStream.SetLength(0); this._packetSwapStream.WriteTo(this._readStream); //重置交换流 this._packetSwapStream.Position = 0; this._packetSwapStream.SetLength(0); ResetPacket(); } } } } catch (Exception e) { this._onError(e); } }
private void Free() { if (mCompiledBuffer == null) { return; } if ((mState & PacketState.Buffered) != 0) { mBuffers.ReleaseBuffer(mCompiledBuffer); } mState &= ~(PacketState.Static | PacketState.Acquired | PacketState.Buffered); mCompiledBuffer = null; }
private void SendCharacterInfos(string data) { var character = DatabaseProvider.Characters.Find(x => x.Id == int.Parse(data)); if (character == null) { return; } _client.Character = character; _client.SendPackets(string.Format("{0}|{1}", Packet.CharacterSelectedResponse, character.InfosWheneSelectedCharacter())); _packetState = PacketState.GameCreate; }
public Packet(Stream stream) { // Это бесполезно конвертировать в фабрику, // в которой можно использовать асинхронщину для // чтения из стрима, потому что в общей библиотеке имеем 3.5 // фреймворк, поэтому будет некоторая копипаста на сервере. byte[] sizeBytes = new byte[sizeof(long)]; stream.Read(sizeBytes, 0, sizeBytes.Length); long size = BitConverter.ToInt64(sizeBytes, 0); var formatter = new BinaryFormatter(); if (size == 0) { return; } long readSize = 0; using (var memStream = new MemoryStream()) { while (readSize < size) { long readBufferSize = 1024; if (size - readSize < readBufferSize) { readBufferSize = size - readSize; } var readBuffer = new byte[readBufferSize]; int currentRead = stream.Read(readBuffer, 0, readBuffer.Length); memStream.Write(readBuffer, 0, currentRead); readSize += currentRead; } memStream.Position = 0; state = (PacketState)formatter.Deserialize(memStream); } }
//void PacketReceived(IAsyncResult ar) //{ // // End async and get data from socket // PacketState state = (PacketState)ar.AsyncState; // int bytesReceived = socket.EndReceiveFrom(ar, ref state.Sender); // PacketReceived(state, bytesReceived); //} void PacketReceived(PacketState state) { if (state.BytesReceived == 0) { return; } IPEndPoint sender = (IPEndPoint)state.Sender; if (ignoredConnections.Count > 0 && ignoredConnections.ContainsKey(sender)) { return; } byte[] data = new byte[state.BytesReceived]; Buffer.BlockCopy(state.Buffer, 0, data, 0, state.BytesReceived); // Handle packet PacketReceived(data, sender); }
public void ReadPacketTest(byte[] rawData, PacketState state) { using var stream = new MemoryStream(rawData); using var archive = new Unreal.Core.BinaryReader(stream); var reader = new MockReplayReader(); reader.SetReplay(new MockReplay { Header = new ReplayHeader { EngineNetworkVersion = EngineNetworkVersionHistory.HISTORY_OPTIONALLY_QUANTIZE_SPAWN_INFO, NetworkVersion = NetworkVersionHistory.HISTORY_CHARACTER_MOVEMENT_NOINTERP, Flags = ReplayHeaderFlags.HasStreamingFixes } }); var result = reader.ReadPacket(archive); Assert.True(archive.AtEnd()); Assert.False(archive.IsError); Assert.Equal(state, result); }
private void SendCharacterGameInfos() { if (_client.Character == null) { return; } _client.SendPackets(string.Format("{0}|1|{1}", Packet.GameCreatedResponse, _client.Character.Name)); SendItemSetsBonnus(); RefreshCharacterStats(); _client.SendPackets(Packet.Restriction); _client.SendPackets(string.Format("{0}{1}", Packet.Message, Packet.WelcomeToDofus)); _client.SendPackets(string.Format("{0}+{1}", Packet.SubscribeChannel, string.Join("", _client.Character.Channels))); LoadMap(); _packetState = PacketState.InGame; }
private void SendCharacterGameInfos() { if (_client.Character == null) return; _client.SendPackets(string.Format("{0}|1|{1}", Packet.GameCreatedResponse, _client.Character.Name)); SendItemSetsBonnus(); RefreshCharacterStats(); _client.SendPackets(Packet.Restriction); _client.SendPackets(string.Format("{0}{1}", Packet.Message, Packet.WelcomeToDofus)); _client.SendPackets(string.Format("{0}+{1}", Packet.SubscribeChannel, string.Join("", _client.Character.Channels))); LoadMap(); _packetState = PacketState.InGame; }
public void Copy(PacketState source) { PacketNumber = source.PacketNumber; Gamepad.Copy(source.Gamepad); }
public PacketEventArgs(PacketState state) { _State = state; _Cancel = false; }
public void switchState(PacketState state) { GD.Print("Changing state to " + state); currentState = state; }
public void Setup(byte[] src, int offset, int size, uint sequence, uint index, TimeSpan rto_interval, PacketState state) { if (src != null) { Data[1] = (byte)(sequence >> 24); Data[2] = (byte)(sequence >> 16); Data[3] = (byte)(sequence >> 8); Data[4] = (byte)(sequence); Data[5] = (byte)(size >> 8); Data[6] = (byte)(size); Buffer.BlockCopy (src, offset, Data, HeaderSize, size); Filled = HeaderSize + size; } else { Filled = 0; } Sequence = sequence; Index = index; RetransmitIndex = index; RTO = DateTime.Now + rto_interval; RTO_Interval = rto_interval; Retries = 0; State = state; Start = DateTime.Now; }
void ResetPacket() { this._needLenth = headBytes.Length; this._packetState = PacketState.ReadHead; }
// this function knows about the boundaries of the packets and receives complete packets, // sending ACK / NAK as needed. protected override void OnRxChar(byte ch) { bool prevDle = gotDle; gotDle = (ch == 0x10); uint uch = (uint)ch; /* if(gotDle || prevDle) { log("-- ch: " + ((byte)ch) + " gotDle=" + gotDle + " prevDle=" + prevDle + " p=" + rxPacket.RxBufferP + " state=" + packetState); } else { log("ch: " + ((byte)ch)); } */ switch(packetState) { case PacketState.resync: //logError("resync -- ch: " + ((byte)ch)); resyncLostCount++; if(prevDle && ch == 0x3) // wait for opening DLE { logError("resync --> outside, lost " + resyncLostCount + " chars"); packetState = PacketState.outside; resyncLostCount = 0; } else if(gotDle && prevCh == 0x3) { logError("resync --> pid, lost " + resyncLostCount + " chars"); packetState = PacketState.pid; resyncLostCount = 0; } break; case PacketState.outside: if(gotDle) // wait for opening DLE { packetState = PacketState.pid; } else { if(ch != 0x3) { //logError("-- inbetween: " + ((byte)ch)); } else { //log("-- inbetween: " + ((byte)ch)); } } break; case PacketState.pid: if(gotDle || ch == 0x3) { // two DLE's is a wrong place ro resync, go on syncing: packetState = PacketState.resync; logError("-- two DLE's or 0x3 in pid"); break; } arxPacket = new RxPacket(); arxPacket.RxPacketId = ch; //log("-- pid -- RxPacketId: " + arxPacket.RxPacketId); packetState = PacketState.datalength; break; case PacketState.datalength: // first DLE in sequence of two is ignored: if(gotDle && prevDle || !gotDle) // DLE stuffing { if(prevDle && !gotDle) // single DLE not allowed - resync { logError("-- datalength ch: " + ((byte)ch) + " after single DLE caused resync"); packetState = PacketState.resync; break; } arxPacket.RxDatalength = (int)uch; //log("-- datalength -- RxDatalength: " + arxPacket.RxDatalength); packetState = PacketState.data; arxPacket.RxBufferP = 0; gotDle = false; // so that prevDle won't be influenced by two legit DLE's } break; case PacketState.data: // first DLE in sequence of two is ignored: if(gotDle && prevDle || !gotDle) // DLE stuffing { if(prevDle && !gotDle) // single DLE not allowed - resync { logError("-- data ch: " + ((byte)ch) + " after single DLE caused resync"); packetState = PacketState.resync; break; } arxPacket.RxBuffer[arxPacket.RxBufferP++] = ch; if(arxPacket.RxBufferP >= arxPacket.RxDatalength) { packetState = PacketState.chksum; } gotDle = false; // so that prevDle won't be influenced by two legit DLE's } break; case PacketState.chksum: // first DLE in sequence of two is ignored: if(gotDle && prevDle || !gotDle) // DLE stuffing { if(prevDle && !gotDle) // single DLE not allowed - resync { logError("-- chksum ch: " + ((byte)ch) + " after single DLE caused resync"); packetState = PacketState.resync; break; } arxPacket.RxBuffer[arxPacket.RxBufferP] = ch; packetState = PacketState.trailer; gotDle = false; // so that prevDle won't be influenced by two legit DLE's } break; case PacketState.trailer: logIncoming(arxPacket); if(arxPacket.RxPacketId != (byte)BasicPids.Pid_Ack_Byte && arxPacket.RxPacketId != (byte)BasicPids.Pid_Nak_Byte) { // some devices respond with two-byte ACK/NAK and do not understand standard // one-byte ACK/NAK. Match our response with whatever they have sent us before: byte[] rspBody = useTwoByteAck ? new byte[] { 0x0, 0x2, 0x0, 0x0 } : new byte[] { 0x0, 0x1, 0x0 }; // incoming ACK/NAK are not responded to, others are: byte cs = RxChecksum(arxPacket); if(ch != 0x10 || cs != arxPacket.RxBuffer[arxPacket.RxBufferP]) { logError("bad packet received (sending NAK) - ch=" + ((byte)ch) + " RxPacketId=" + arxPacket.RxPacketId + " cs=" + cs + " rec_cs=" + arxPacket.RxBuffer[arxPacket.RxBufferP]); arxPacket.RxBufferP = 0; // buffer data no good // prepare to send NAK: rspBody[0] = (byte)BasicPids.Pid_Nak_Byte; arxPacket.RxBadPacket = true; // signal bad packet has been received and NAK'ed rspBody[2] = arxPacket.RxPacketId; Send(rspBody); // send NAK } else { //log("good packet received (sending ACK) - ch=" + ((byte)ch) + " RxPacketId=" + arxPacket.RxPacketId + " cs=" + cs); // prepare to send ACK: rspBody[0] = (byte)BasicPids.Pid_Ack_Byte; arxPacket.RxBadPacket = false; rspBody[2] = arxPacket.RxPacketId; Send(rspBody); // send ACK } } else { // incoming ACK / NAK are not responded to arxPacket.RxBadPacket = false; // ACK / NAK considered good no matter what. useTwoByteAck = (arxPacket.RxDatalength == 2); // make sure we match their ACK size } rxPacket = arxPacket; arxPacket = null; gotDle = false; // trailer is a real DLE and doesn't participate in DLE stuffing resyncLostCount = 0; /* if (TransFlag.WaitOne(0,false)) // Transact/Receive waiting for result? { // we are not in Transact, let async OnRxPacket() work: if(!RxBadPacket) { byte[] packetBody; lock(RxBuffer) { packetBody = new Byte[RxBufferP - 1]; Array.Copy(RxBuffer, packetBody, (int)RxBufferP - 1); RxBufferP = 0; } OnRxPacket(RxPacketId, packetBody); // good unsolicited packet - call the callback function // knowing that ACK or NAK has been already sent } else { RxBufferP = 0; OnRxPacket(RxPacketId, null); // bad unsolicited packet - call the callback function // knowing that ACK or NAK has been already sent } } else */ { TransFlag.Set(); // we are in Transact or Receive, let it pick the result, good or bad, // knowing that ACK or NAK has been already sent } packetState = PacketState.outside; // 0x3 will be ignored in search for 0x10 break; } prevCh = ch; }
public static extern int XInputGetState ( int dwUserIndex, // [in] Index of the gamer associated with the device ref PacketState pState // [out] Receives the current state );
public void Acquire() { mState |= PacketState.Acquired; }
// this function knows about the boundaries of the packets and receives complete packets, // sending ACK / NAK as needed. protected override void OnRxChar(byte ch) { bool prevDle = gotDle; gotDle = (ch == 0x10); uint uch = (uint)ch; /* * if(gotDle || prevDle) * { * log("-- ch: " + ((byte)ch) + " gotDle=" + gotDle + " prevDle=" + prevDle + " p=" + rxPacket.RxBufferP + " state=" + packetState); * } * else * { * log("ch: " + ((byte)ch)); * } */ switch (packetState) { case PacketState.resync: //logError("resync -- ch: " + ((byte)ch)); resyncLostCount++; if (prevDle && ch == 0x3) // wait for opening DLE { logError("resync --> outside, lost " + resyncLostCount + " chars"); packetState = PacketState.outside; resyncLostCount = 0; } else if (gotDle && prevCh == 0x3) { logError("resync --> pid, lost " + resyncLostCount + " chars"); packetState = PacketState.pid; resyncLostCount = 0; } break; case PacketState.outside: if (gotDle) // wait for opening DLE { packetState = PacketState.pid; } else { if (ch != 0x3) { //logError("-- inbetween: " + ((byte)ch)); } else { //log("-- inbetween: " + ((byte)ch)); } } break; case PacketState.pid: if (gotDle || ch == 0x3) { // two DLE's is a wrong place ro resync, go on syncing: packetState = PacketState.resync; logError("-- two DLE's or 0x3 in pid"); break; } arxPacket = new RxPacket(); arxPacket.RxPacketId = ch; //log("-- pid -- RxPacketId: " + arxPacket.RxPacketId); packetState = PacketState.datalength; break; case PacketState.datalength: // first DLE in sequence of two is ignored: if (gotDle && prevDle || !gotDle) // DLE stuffing { if (prevDle && !gotDle) // single DLE not allowed - resync { logError("-- datalength ch: " + ((byte)ch) + " after single DLE caused resync"); packetState = PacketState.resync; break; } arxPacket.RxDatalength = (int)uch; //log("-- datalength -- RxDatalength: " + arxPacket.RxDatalength); packetState = PacketState.data; arxPacket.RxBufferP = 0; gotDle = false; // so that prevDle won't be influenced by two legit DLE's } break; case PacketState.data: // first DLE in sequence of two is ignored: if (gotDle && prevDle || !gotDle) // DLE stuffing { if (prevDle && !gotDle) // single DLE not allowed - resync { logError("-- data ch: " + ((byte)ch) + " after single DLE caused resync"); packetState = PacketState.resync; break; } arxPacket.RxBuffer[arxPacket.RxBufferP++] = ch; if (arxPacket.RxBufferP >= arxPacket.RxDatalength) { packetState = PacketState.chksum; } gotDle = false; // so that prevDle won't be influenced by two legit DLE's } break; case PacketState.chksum: // first DLE in sequence of two is ignored: if (gotDle && prevDle || !gotDle) // DLE stuffing { if (prevDle && !gotDle) // single DLE not allowed - resync { logError("-- chksum ch: " + ((byte)ch) + " after single DLE caused resync"); packetState = PacketState.resync; break; } arxPacket.RxBuffer[arxPacket.RxBufferP] = ch; packetState = PacketState.trailer; gotDle = false; // so that prevDle won't be influenced by two legit DLE's } break; case PacketState.trailer: logIncoming(arxPacket); if (arxPacket.RxPacketId != (byte)BasicPids.Pid_Ack_Byte && arxPacket.RxPacketId != (byte)BasicPids.Pid_Nak_Byte) { // some devices respond with two-byte ACK/NAK and do not understand standard // one-byte ACK/NAK. Match our response with whatever they have sent us before: byte[] rspBody = useTwoByteAck ? new byte[] { 0x0, 0x2, 0x0, 0x0 } : new byte[] { 0x0, 0x1, 0x0 }; // incoming ACK/NAK are not responded to, others are: byte cs = RxChecksum(arxPacket); if (ch != 0x10 || cs != arxPacket.RxBuffer[arxPacket.RxBufferP]) { logError("bad packet received (sending NAK) - ch=" + ((byte)ch) + " RxPacketId=" + arxPacket.RxPacketId + " cs=" + cs + " rec_cs=" + arxPacket.RxBuffer[arxPacket.RxBufferP]); arxPacket.RxBufferP = 0; // buffer data no good // prepare to send NAK: rspBody[0] = (byte)BasicPids.Pid_Nak_Byte; arxPacket.RxBadPacket = true; // signal bad packet has been received and NAK'ed rspBody[2] = arxPacket.RxPacketId; Send(rspBody); // send NAK } else { //log("good packet received (sending ACK) - ch=" + ((byte)ch) + " RxPacketId=" + arxPacket.RxPacketId + " cs=" + cs); // prepare to send ACK: rspBody[0] = (byte)BasicPids.Pid_Ack_Byte; arxPacket.RxBadPacket = false; rspBody[2] = arxPacket.RxPacketId; Send(rspBody); // send ACK } } else { // incoming ACK / NAK are not responded to arxPacket.RxBadPacket = false; // ACK / NAK considered good no matter what. useTwoByteAck = (arxPacket.RxDatalength == 2); // make sure we match their ACK size } rxPacket = arxPacket; arxPacket = null; gotDle = false; // trailer is a real DLE and doesn't participate in DLE stuffing resyncLostCount = 0; /* * if (TransFlag.WaitOne(0,false)) // Transact/Receive waiting for result? * { * // we are not in Transact, let async OnRxPacket() work: * if(!RxBadPacket) * { * byte[] packetBody; * lock(RxBuffer) * { * packetBody = new Byte[RxBufferP - 1]; * Array.Copy(RxBuffer, packetBody, (int)RxBufferP - 1); * RxBufferP = 0; * } * OnRxPacket(RxPacketId, packetBody); // good unsolicited packet - call the callback function * // knowing that ACK or NAK has been already sent * } * else * { * RxBufferP = 0; * OnRxPacket(RxPacketId, null); // bad unsolicited packet - call the callback function * // knowing that ACK or NAK has been already sent * } * } * else */ { TransFlag.Set(); // we are in Transact or Receive, let it pick the result, good or bad, // knowing that ACK or NAK has been already sent } packetState = PacketState.outside; // 0x3 will be ignored in search for 0x10 break; } prevCh = ch; }
private void ParseTicket(string packet) { var date = packet.Split('|')[0]; var ip = packet.Split('|')[1]; if (DateTime.ParseExact(date, "MM/dd/yyyy HH:mm:ss", null).AddSeconds(Constant.TicketTimeExpiredInterval) < DateTime.ParseExact(DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), "MM/dd/yyyy HH:mm:ss", null)) { _client.SendPackets(Packet.TicketExpired); _client.OnSocketClosed(); } else if (ip.Equals(_client.Socket.IP)) { _client.SendPackets(Packet.InvalidIp); _client.OnSocketClosed(); } else { var account = packet.Split('|')[2].Split(','); try { _client.Account = new Account { Id = int.Parse(account[0]), Username = account[1], Password = account[2], Pseudo = account[3], Question = account[4], Reponse = account[5], GmLevel = int.Parse(account[7]), BannedUntil = account[8] == "" ? (DateTime?) null : DateTime.Parse(account[8].ToString(CultureInfo.InvariantCulture)), Subscription = account[9] == "" ? (DateTime?) null : DateTime.Parse(account[9].ToString(CultureInfo.InvariantCulture)), }; _packetState = PacketState.CharactersInfos; AccountRepository.UpdateAccount(_client.Account.Id); AccountRepository.UpdateCharactersList(_client.Account.Id); _packetState = PacketState.CharactersInfos; _client.SendPackets(Packet.TicketAccepted); } catch (Exception e) { SilverConsole.WriteLine(e.Message, ConsoleColor.Red); Logs.LogWritter(Constant.ErrorsFolder, string.Format("Impossible de charger le compte {0}", account[1])); } } }
public void SetStatic() { mState |= PacketState.Static | PacketState.Acquired; }
private void Free() { if( mCompiledBuffer == null ) return; if( ( mState & PacketState.Buffered ) != 0 ) mBuffers.ReleaseBuffer( mCompiledBuffer ); mState &= ~( PacketState.Static | PacketState.Acquired | PacketState.Buffered ); mCompiledBuffer = null; }
private void SendCharacterInfos(string data) { var character = DatabaseProvider.Characters.Find(x => x.Id == int.Parse(data)); if (character == null) return; _client.Character = character; _client.SendPackets(string.Format("{0}|{1}", Packet.CharacterSelectedResponse, character.InfosWheneSelectedCharacter())); _packetState = PacketState.GameCreate; }
public void HandleReceivedData(byte[] buffer, int offset, int bytesRead) { List <byte> receivedData = new List <byte>(); byte b; for (int i = offset; i < bytesRead; i++) { b = buffer[i]; switch (currentPacketState) { case PacketState.NORMAL: if (b == Constants.SWITCH) { currentReceiveState = ReceiveState.SWITCH; currentPacketState = PacketState.READING_ID; } else if (b == Constants.END) { currentReceiveState = ReceiveState.END; currentPacketState = PacketState.READING_ID; } else if (b == Constants.ESC) { currentPacketState = PacketState.IN_ESC; } else { if (!in_packet) { throw new Exception("Received data before receiving packet Id"); } receivedData.Add(b); } break; case PacketState.IN_ESC: receivedData.Add(b); currentPacketState = PacketState.NORMAL; break; case PacketState.READING_ID: idBuffer[idBufferCounter++] = b; if (idBufferCounter >= 4) { idBufferCounter = 0; currentId = System.Net.IPAddress.HostToNetworkOrder(BitConverter.ToInt32(idBuffer, 0)); currentPacketState = PacketState.NORMAL; if (currentReceiveState == ReceiveState.SWITCH) { //New packet in_packet = true; } else if (currentReceiveState == ReceiveState.END) { //End packet if (DataReceived != null) { DataReceived(this, new DataReceivedEventArgs() { Id = currentId, Data = receivedData.Count > 0 ? receivedData.ToArray() : null, isEnd = true }); } prevId = currentId; currentId = 0; in_packet = false; receivedData.Clear(); } } break; } } if (in_packet && receivedData.Count != 0 && DataReceived != null) { DataReceived(this, new DataReceivedEventArgs() { Id = currentId, Data = receivedData.ToArray(), isEnd = false }); } }
protected void SetState(PacketState nState) { this.mState = nState; }
internal void SetState(PacketState newState) { state = newState; }
public byte[] Compile( out int length ) { if( mCompiledBuffer == null ) { if( ( mState & PacketState.Accessed ) == 0 ) { mState |= PacketState.Accessed; } else { if( ( mState & PacketState.Warned ) == 0 ) { mState |= PacketState.Warned; try { using( StreamWriter op = new StreamWriter( "net_opt.log", true ) ) { op.WriteLine( "Redundant compile for packet {0}, use Acquire() and Release()", this.GetType() ); op.WriteLine( new System.Diagnostics.StackTrace() ); } } catch { } } mCompiledBuffer = new byte[ 0 ]; mCompiledLength = 0; length = mCompiledLength; return mCompiledBuffer; } InternalCompile(); } length = mCompiledLength; return mCompiledBuffer; }