private void ProcessPacket(Packet packet)
        {
            switch (packet.Method)
            {
            case PacketType.SCZero:
                break;

            case PacketType.SCReturnValue:
                _replyes.Enqueue(packet);
                break;

            case PacketType.SCScriptDLLTerminate:
                new Task(OnTerminateRecieve).Start();
                break;

            case PacketType.SCPauseResumeScript:
                new Task(OnStartStopRevieve).Start();
                break;

            case PacketType.SCExecEventProc:
                var eventType = (EventTypes)packet.Data[0];


                ArrayList parameters = new ArrayList();
                using (var stream = new MemoryStream(packet.Data, 2, packet.DataLength - 2))
                    using (var reader = new BinaryReader(stream))
                    {
                        while (stream.Position < stream.Length - 1)
                        {
                            var type = reader.ReadByte();
                            var size = reader.ReadUInt16();
                            switch ((DataType)type)
                            {
                            case DataType.parUnicodeString:
                                parameters.Add(Encoding.Unicode.GetString(reader.ReadBytes(size)));
                                break;

                            case DataType.parInteger:
                                parameters.Add(reader.ReadInt32());
                                break;

                            case DataType.parCardinal:
                                parameters.Add(reader.ReadUInt32());
                                break;

                            case DataType.parBoolean:
                                parameters.Add(reader.ReadBoolean());
                                break;

                            case DataType.parWord:
                                parameters.Add(reader.ReadUInt16());
                                break;

                            case DataType.parByte:
                                parameters.Add(reader.ReadByte());
                                break;
                            }
                        }
                    }


                ExecEventProcData data = new ExecEventProcData(eventType, parameters);
                new Task(() => OnServerEventRecieve(data)).Start();
                break;

            default:
                throw new Exception("Recieve unknown packet. ID: " + (ushort)packet.Method);
            }
        }
 private void OnServerEventRecieve(ExecEventProcData data)
 {
     ServerEventRecieve?.Invoke(this, new ServerEventArgs(data));
 }
Exemple #3
0
 public ServerEventArgs(ExecEventProcData data)
 {
     Data = data;
 }