Exemplo n.º 1
0
        /*Получаем пакет в виде массива байтов*/
        public DataSet(Byte[] pack, int length)
        {
            this.package = new MemoryStream();
            this.package.Write(pack, 0, length);
            /*Устанавливаем позицию в 0 для чтения*/
            this.package.Position = 0;
            /*Читаем команду*/
            byte[] cmdByte = new byte[5];
            this.package.Read(cmdByte, 0, 5);
            this.command = ToCommand(cmdByte);
            /*В зависимости от полученной команды читаем значения переменных*/
            switch (command)
            {
            case ConnectionCommands.INIT:
            case ConnectionCommands.CHATMESSAGE:
                FromString(Encoding.ASCII.GetString(pack, 0, length));
                break;

            case ConnectionCommands.PASSWORD:
                int passLength = length - 5;
                cmdByte = new byte[passLength];
                this.package.Read(cmdByte, 0, passLength);
                Add(Encoding.ASCII.GetString(cmdByte, 0, passLength));
                break;

            case ConnectionCommands.SCREEN:
                int numLength = 2;
                cmdByte = new Byte[numLength];
                this.package.Read(cmdByte, 0, numLength);
                Add(BitConverter.ToInt16(cmdByte, 0));
                break;
            }
        }
Exemplo n.º 2
0
 /*Получаем команду для инициализации пакета*/
 public DataSet(ConnectionCommands command)
 {
     this.command = command;
     byte[] cmd = Encoding.UTF8.GetBytes(ToString(command));
     package = new MemoryStream();
     package.Write(cmd, 0, cmd.Length);
 }
Exemplo n.º 3
0
        /*Преобразует команду в строку*/
        private String ToString(ConnectionCommands command)
        {
            switch (command)
            {
            case ConnectionCommands.HELLO:
                return("0x01\\");

            case ConnectionCommands.INIT:
                return("0x02\\");

            case ConnectionCommands.PASSWORD:
                return("0x03\\");

            case ConnectionCommands.CONNECT:
                return("0x04\\");

            case ConnectionCommands.DECLINE:
                return("0x05\\");

            case ConnectionCommands.EXIT:
                return("0x06\\");

            case ConnectionCommands.ERROR:
                return("0x07\\");

            case ConnectionCommands.SCREEN:
                return("0x08\\");

            case ConnectionCommands.SCREENINFO:
                return("0x09\\");

            case ConnectionCommands.CHATMESSAGE:
                return("0x10\\");

            case ConnectionCommands.SOUND:
                return("0x11\\");

            default:
                return("0x00\\");
            }
        }
Exemplo n.º 4
0
 public DataSet()
 {
     this.command = ConnectionCommands.NONE;
     this.package = new MemoryStream();
 }
 public string Select(int index) => Multi(ConnectionCommands.Select(index));
 public Task <string> SelectAsync(int index) => MultiAsync(ConnectionCommands.Select(index));
 public string Quit() => Multi(ConnectionCommands.Quit());
 public Task <string> QuitAsync() => MultiAsync(ConnectionCommands.Quit());
 public Task <string> PingAsync() => MultiAsync(ConnectionCommands.Ping());
 public string Ping() => Multi(ConnectionCommands.Ping());
 public Task <string> EchoAsync(string message) => MultiAsync(ConnectionCommands.Echo(message));
 public string Echo(string message) => Multi(ConnectionCommands.Echo(message));
Exemplo n.º 13
0
 /// <summary>
 /// 利用密码进行授权
 /// </summary>
 /// <param name="password">密码</param>
 /// <returns>状态消息</returns>
 public string Auth(string password)
 {
     return(Write(ConnectionCommands.Auth(password)));
 }