Esempio n. 1
0
 public ServerEventArgs(ExecEventProcData data)
 {
     Data = data;
 }
Esempio n. 2
0
        private void ProcessPacket(Packet packet)
        {
            switch (packet.Method)
            {
            case PacketType.SCZero:
                break;

            case PacketType.SCReturnValue:
                packet.ReturnId = BinaryPrimitives.ReadUInt16LittleEndian(packet.Data.AsSpan());
                _replyes.Enqueue(packet);
                break;

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

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

            case PacketType.SCExecEventProc:
                var span       = packet.Data.AsSpan();
                var eventType  = (EventTypes)span[0];
                var paramCount = span[1];
                span = span.Slice(2);
                ArrayList parameters = new ArrayList(paramCount);
                int       pos        = 0;
                for (int i = 0; i < paramCount; i++)
                {
                    var type = (DataType)span[pos++];
                    switch (type)
                    {
                    case DataType.parUnicodeString:
                        var size = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(pos));
                        pos += 4;
                        parameters.Add(Encoding.Unicode.GetString(span.Slice(pos, size * 2).ToArray()));
                        pos += size * 2;
                        break;

                    case DataType.parInteger:
                        parameters.Add(BinaryPrimitives.ReadInt32LittleEndian(span.Slice(pos)));
                        pos += 4;
                        break;

                    case DataType.parCardinal:
                        parameters.Add(BinaryPrimitives.ReadUInt16LittleEndian(span.Slice(pos)));
                        pos += 2;
                        break;

                    case DataType.parBoolean:
                        parameters.Add(span[pos++] > 0);
                        break;

                    case DataType.parWord:
                        parameters.Add(BinaryPrimitives.ReadInt16LittleEndian(span.Slice(pos)));
                        pos += 2;
                        break;

                    case DataType.parByte:
                        parameters.Add(span[pos++]);
                        break;
                    }
                }

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

            default:
                throw new Exception("Recieve unknown packet. ID: " + (ushort)packet.Method);
            }
        }
Esempio n. 3
0
 private void OnServerEventRecieve(ExecEventProcData data)
 {
     ServerEventRecieve?.Invoke(this, new ServerEventArgs(data));
 }
Esempio n. 4
0
        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];
                var paramCount = packet.Data[1];

                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();
                            switch ((DataType)type)
                            {
                            case DataType.parUnicodeString:
                                var size = (int)reader.ReadUInt32();
                                parameters.Add(Encoding.Unicode.GetString(reader.ReadBytes(size * 2)));
                                break;

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

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

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

                            case DataType.parWord:
                                parameters.Add(reader.ReadInt16());
                                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);
            }
        }