/// <summary>
        /// This login uses a flat file system, data/users/{0}.user - the users name is the file.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="client"></param>
        /// <returns></returns>
        public bool Login(byte[] data, Client client)
        {
            try
            {
                BinaryBuffer buff = new BinaryBuffer(data, true);

                client.Username = buff.ReadString(buff.ReadInt()); // Username
                client.Password = buff.ReadString(buff.ReadInt()); // Password

                buff.EndRead();

                buff = new BinaryBuffer(File.ReadAllBytes(string.Format(@"data/users/{0}.svpref", client.Username)), true);

                LoadClientArguments(ref buff, ref client);
                // does pass equal?

                string arg;
                client.GetArgument("Password", out arg);
                if (arg != client.Password)
                    return false;

                buff.EndRead();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
 /// <summary>
 /// This function will run not matter if it errors...
 /// </summary>
 /// <param name="data"></param>
 /// <param name="client"></param>
 public void LoadClientArguments(ref BinaryBuffer data, ref Client client)
 {
     //how many arguments do we have stored?
     try
     {
         int Total = data.ReadInt();
         for (int i = 0; i < Total; i++)
             client.Arguments.Add(new ClientArgument(data.ReadString(data.ReadInt()), data.ReadByte(), data.ReadByteArray(data.ReadInt())));
     }
     catch (Exception)
     {
         // If the file is out of order, they lose there data.
         // because if they can login then the file has been changed manually.
     }
 }
示例#3
0
        /// <summary>
        /// This will be called before a client Interface gets called.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public bool ProessRequest(NetworkStream stream)
        {
            try
            {
                BinaryBuffer buff = new BinaryBuffer(Database.ReadBuffer(stream));

                buff.BeginRead();

                int count = buff.ReadInt();

                BinaryBuffer writeBuff = new BinaryBuffer();

                writeBuff.BeginWrite();

                for (int i = 0; i < count; i++)
                {
                    IClientRequest Request = CurrentServer.GetRequest(buff.ReadByte());
                    // if a IClientRequest to close. we need to handle by not reading and writing back!
                    if (!this.TcpConnection.Connected)
                    {
                        return(false);
                    }

                    byte[] data = buff.ReadByteArray(buff.ReadInt());
                    if (Request != null)
                    {
                        data = Request.Process(new BinaryBuffer(data), this);
                        writeBuff.Write(data.Length);
                        writeBuff.Write(data);
                    }
                    else
                    {
                        writeBuff.Write(0); // length;
                    }
                }

                writeBuff.EndWrite();

                Database.WriteBuffer(writeBuff.ByteBuffer, stream);

                return(true);
            }
            catch (Exception)
            { }
            return(false);
        }
示例#4
0
        /// <summary>
        /// This will be called before a client Interface gets called.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public bool ProessRequest(NetworkStream stream)
        {
            try
            {
                BinaryBuffer buff = new BinaryBuffer(Database.ReadBuffer(stream));

                buff.BeginRead();

                int count = buff.ReadInt();

                BinaryBuffer writeBuff = new BinaryBuffer();

                writeBuff.BeginWrite();

                for (int i = 0; i < count;i++)
                {
                    IClientRequest Request = CurrentServer.GetRequest(buff.ReadByte());
                    // if a IClientRequest to close. we need to handle by not reading and writing back!
                    if (!this.TcpConnection.Connected)
                        return false;

                    byte[] data = buff.ReadByteArray(buff.ReadInt());
                    if(Request != null)
                    {
                        data = Request.Process(new BinaryBuffer(data), this);
                        writeBuff.Write(data.Length);
                        writeBuff.Write(data);
                    }
                    else
                    {
                        writeBuff.Write(0); // length;
                    }
                }

                writeBuff.EndWrite();

                Database.WriteBuffer(writeBuff.ByteBuffer, stream);

                return true;
            }
            catch (Exception)
            { }
            return false;
        }
示例#5
0
        public static DataTable ConvertBlobToDataTable(ref byte[] data)
        {
            DataTable dt = null;

            if (data == null || data.Length == 0)
            {
                return(dt);
            }

            BinaryBuffer buff = new BinaryBuffer(data);

            buff.BeginRead();

            buff.ReadInt();

            int ColumnCount = buff.ReadInt();

            if (ColumnCount > 0)
            {
                dt = new DataTable();
                TypeCode[] types = new TypeCode[ColumnCount];
                for (int i = 0; i < ColumnCount; i++)
                {
                    string   colName = buff.ReadString(buff.ReadInt());
                    TypeCode type    = (TypeCode)buff.ReadByte();
                    types[i] = type;

                    switch (type)
                    {
                    case TypeCode.Boolean:
                        dt.Columns.Add(colName, typeof(Boolean));
                        break;

                    case TypeCode.Byte:
                        dt.Columns.Add(colName, typeof(byte));
                        break;

                    case TypeCode.Char:
                        dt.Columns.Add(colName, typeof(char));
                        break;

                    case TypeCode.DateTime:
                        dt.Columns.Add(colName, typeof(DateTime));
                        break;

                    case TypeCode.DBNull:
                        dt.Columns.Add(colName);
                        break;

                    case TypeCode.Decimal:
                        dt.Columns.Add(colName, typeof(decimal));
                        break;

                    case TypeCode.Double:
                        dt.Columns.Add(colName, typeof(double));
                        break;

                    case TypeCode.Empty:
                        dt.Columns.Add(colName);
                        break;

                    case TypeCode.Int16:
                        dt.Columns.Add(colName, typeof(short));
                        break;

                    case TypeCode.Int32:
                        dt.Columns.Add(colName, typeof(int));
                        break;

                    case TypeCode.Int64:
                        dt.Columns.Add(colName, typeof(long));
                        break;

                    case TypeCode.Single:
                        dt.Columns.Add(colName, typeof(float));
                        break;

                    case TypeCode.String:
                        dt.Columns.Add(colName, typeof(string));
                        break;

                    default:
                        dt.Columns.Add(colName);
                        break;
                    }
                }

                int RowCount = buff.ReadInt();

                dt.BeginLoadData();

                for (int i = 0; i < RowCount; i++)
                {
                    //DataRow dr = dt.NewRow();
                    object[] obj = new object[ColumnCount];
                    for (int y = 0; y < ColumnCount; y++)
                    {
                        TypeCode type = (TypeCode)buff.ReadByte();

                        switch (type)
                        {
                        case TypeCode.Byte:
                        case TypeCode.Boolean:
                            obj[y] = buff.ReadByte();
                            break;

                        case TypeCode.String:
                            obj[y] = buff.ReadString(buff.ReadInt());
                            break;

                        case TypeCode.Int16:
                            obj[y] = BitConverter.ToInt16(buff.ReadByteArray(2), 0);
                            break;

                        case TypeCode.Int32:
                            obj[y] = buff.ReadInt();
                            break;

                        case TypeCode.Int64:
                            obj[y] = buff.ReadLong();
                            break;

                        case TypeCode.Single:
                            obj[y] = buff.ReadFloat();
                            break;

                        case TypeCode.Double:
                            obj[y] = BitConverter.ToDouble(buff.ReadByteArray(8), 0);
                            break;

                        case TypeCode.Decimal:
                            obj[y] = buff.ReadDecimal();
                            break;

                        case TypeCode.DBNull:
                            obj[y] = DBNull.Value;
                            break;

                        case TypeCode.DateTime:
                            obj[y] = DateTime.FromBinary(buff.ReadLong());
                            break;

                        default:
                            obj[y] = null;
                            break;
                        }
                    }
                    dt.Rows.Add(obj);
                }

                dt.EndLoadData();

                if (RowCount > 0)
                {
                    dt.AcceptChanges();
                }
            }

            return(dt);
        }
示例#6
0
        public static DataTable ConvertBlobToDataTable(ref byte[] data)
        {
            DataTable dt = null;

            if (data == null || data.Length == 0)
                return dt;

            BinaryBuffer buff = new BinaryBuffer(data);

            buff.BeginRead();

            buff.ReadInt();

            int ColumnCount = buff.ReadInt();

            if (ColumnCount > 0)
            {
                dt = new DataTable();
                TypeCode[] types = new TypeCode[ColumnCount];
                for (int i = 0; i < ColumnCount; i++)
                {
                    string colName = buff.ReadString(buff.ReadInt());
                    TypeCode type = (TypeCode)buff.ReadByte();
                    types[i] = type;

                    switch (type)
                    {
                        case TypeCode.Boolean:
                            dt.Columns.Add(colName, typeof(Boolean));
                            break;
                        case TypeCode.Byte:
                            dt.Columns.Add(colName, typeof(byte));
                            break;
                        case TypeCode.Char:
                            dt.Columns.Add(colName, typeof(char));
                            break;
                        case TypeCode.DateTime:
                            dt.Columns.Add(colName, typeof(DateTime));
                            break;
                        case TypeCode.DBNull:
                            dt.Columns.Add(colName);
                            break;
                        case TypeCode.Decimal:
                            dt.Columns.Add(colName, typeof(decimal));
                            break;
                        case TypeCode.Double:
                            dt.Columns.Add(colName, typeof(double));
                            break;
                        case TypeCode.Empty:
                            dt.Columns.Add(colName);
                            break;
                        case TypeCode.Int16:
                            dt.Columns.Add(colName, typeof(short));
                            break;
                        case TypeCode.Int32:
                            dt.Columns.Add(colName, typeof(int));
                            break;
                        case TypeCode.Int64:
                            dt.Columns.Add(colName, typeof(long));
                            break;
                        case TypeCode.Single:
                            dt.Columns.Add(colName, typeof(float));
                            break;
                        case TypeCode.String:
                            dt.Columns.Add(colName, typeof(string));
                            break;
                        default:
                            dt.Columns.Add(colName);
                            break;
                    }
                }

                int RowCount = buff.ReadInt();

                dt.BeginLoadData();

                for (int i = 0; i < RowCount; i++)
                {
                    //DataRow dr = dt.NewRow();
                    object[] obj = new object[ColumnCount];
                    for (int y = 0; y < ColumnCount; y++)
                    {
                        TypeCode type = (TypeCode)buff.ReadByte();

                        switch (type)
                        {
                            case TypeCode.Byte:
                            case TypeCode.Boolean:
                                obj[y] = buff.ReadByte();
                                break;
                            case TypeCode.String:
                                obj[y] = buff.ReadString(buff.ReadInt());
                                break;
                            case TypeCode.Int16:
                                obj[y] = BitConverter.ToInt16(buff.ReadByteArray(2), 0);
                                break;
                            case TypeCode.Int32:
                                obj[y] = buff.ReadInt();
                                break;
                            case TypeCode.Int64:
                                obj[y] = buff.ReadLong();
                                break;
                            case TypeCode.Single:
                                obj[y] = buff.ReadFloat();
                                break;
                            case TypeCode.Double:
                                obj[y] = BitConverter.ToDouble(buff.ReadByteArray(8), 0);
                                break;
                            case TypeCode.Decimal:
                                obj[y] = buff.ReadDecimal();
                                break;
                            case TypeCode.DBNull:
                                obj[y] = DBNull.Value;
                                break;
                            case TypeCode.DateTime:
                                obj[y] = DateTime.FromBinary(buff.ReadLong());
                                break;
                            default:
                                obj[y] = null;
                                break;
                        }
                    }
                    dt.Rows.Add(obj);
                }

                dt.EndLoadData();

                if (RowCount > 0)
                    dt.AcceptChanges();
            }

            return dt;
        }