Пример #1
0
 public void WriteTo(RawData package)
 {
     package.WriteByte((byte)Type);
     package.WriteShort((short)SubType);
     package.WriteShort(Value);
 }
Пример #2
0
        public void WriteTo(RawData data)
        {
            if (_configType == ConfigStringType.Bad)
                return;

            data.WriteByte((byte)Type);
            data.WriteShort((short) ((short)ConfigType + SubCode));
            data.WriteString(Message);
        }
Пример #3
0
        void ParseClientData(IProxy sender, MessageEventArgs e)
        {
            var outcomingData = new RawData(e.Data);
            int sequence = outcomingData.ReadInt();
            int outId =  sequence & ~(1 << 31);

            if (sequence == -1)
            {
                string cmd = outcomingData.ReadString(' ');
                if (cmd == "connect")
                    Protocol = (ServerData.ServerProtocol)int.Parse(outcomingData.ReadString(' '));
                return;
            }

            if (outId <= _lastSentMessageId)
                return;
            int ack = outcomingData.ReadInt();

            short qPort;
            if (Protocol == ServerData.ServerProtocol.R1Q2)
                qPort = outcomingData.ReadByte();
            else
                qPort = outcomingData.ReadShort();

            _lastSentMessageId = outId;

            Package<IClientCommand> package = outcomingData.ReadClientPackage();
            Package<IClientCommand> okPackage = new Package<IClientCommand>();

            lock (_fakeClientCommands)
            {
                while (_fakeClientCommands.Count > 0)
                    okPackage.Commands.Enqueue(_fakeClientCommands.Dequeue());
            }

            if (OnClientPackage.Check(this, package))
            {
                foreach (IClientCommand cmd in package.Commands)
                {
                    switch (cmd.Type)
                    {
                        case ClientCommand.StringCmd:
                            if (OnClientStringCmd.Check(this, (StringCmd)cmd) &&
                                OnClientStringPackage.Check(this, (IClientStringPackage)cmd))
                                okPackage.Commands.Enqueue(cmd);
                            break;
                        case ClientCommand.UserInfo:
                            if (OnClientUserInfo.Check(this, (UserInfo)cmd) &&
                                OnClientStringPackage.Check(this, (IClientStringPackage)cmd))
                                okPackage.Commands.Enqueue(cmd);
                            break;
                        case ClientCommand.Setting:
                            if (OnClientSetting.Check(this, (Setting)cmd))
                                okPackage.Commands.Enqueue(cmd);
                            break;
                        default:
                            okPackage.Commands.Enqueue(cmd);
                            break;
                    }
                }
            }

            okPackage.RemainingData = package.RemainingData;

            var finalPackage = new RawData(8 + (Protocol == ServerData.ServerProtocol.R1Q2 ? 1 : 2) + okPackage.Size());
            finalPackage.WriteInt(sequence);
            finalPackage.WriteInt(ack);

            if (Protocol == ServerData.ServerProtocol.R1Q2)
                finalPackage.WriteByte((byte)qPort);
            else
                finalPackage.WriteShort(qPort);

            okPackage.WriteTo(finalPackage);

            e.Data = finalPackage.Data;
        }