コード例 #1
0
        /// <summary>
        /// IDatabase.Authenticate implementation for MySQL driver
        /// </summary>
        public Task <Plugin.AuthenticationInformation> Authenticate(Plugin.IDatabaseConnection clientImpl, string username, string password)
        {
            VirtualConnection connection = clientImpl as VirtualConnection;

            var tableResult = connection
                              .Command("SELECT acc.id, acc.username, acc.email, acc.balance, subs.subscriptionType, subs.paidDate FROM `accounts` AS acc JOIN `subscriptions` AS subs ON acc.id = subs.accountId WHERE acc.username = @username AND acc.password = MD5(CONCAT(@password, acc.salt)) AND subs.paid = TRUE ORDER BY subs.paidDate DESC LIMIT 0,1;")
                              .SetParameter("@username", username)
                              .SetParameter("@password", password)
                              .ReadTable();

            connection.IsBusy = false;

            // return default authentication information (success = false)
            if (tableResult.Rows.Count == 0)
            {
                return(Task.FromResult(new Plugin.AuthenticationInformation(false)));
            }
            else
            {
                var    row = tableResult.Rows[0];
                string subscriptionTypeName = row["subscriptionType"] as string;
                subscriptionTypeName = subscriptionTypeName[0].ToString().ToUpper() + subscriptionTypeName.Substring(1);
                return(Task.FromResult(
                           new Plugin.AuthenticationInformation(
                               (long)(int)row["id"],
                               row["username"] as string,
                               row["email"] as string,
                               double.Parse(row["balance"].ToString(), System.Globalization.CultureInfo.GetCultureInfo("en-US")),
                               (Plugin.SubscriptionType)Enum.Parse(typeof(Plugin.SubscriptionType), subscriptionTypeName),
                               ((DateTime)row["paidDate"]).AddDays(30)
                               )
                           ));
            }
        }
コード例 #2
0
        /// <summary>
        /// IDatabase.CommitStats implementation for MySQL driver
        /// </summary>
        public Task <object> CommitStats(Plugin.IDatabaseConnection clientImpl, long accountId, long newTx, long newRx)
        {
            VirtualConnection connection = clientImpl as VirtualConnection;

            connection
            .Command("UPDATE `accounts` AS acc SET acc.totalTx = acc.totalTx + @newTx, acc.totalRx = acc.totalRx + @newRx WHERE acc.id = @accountId;")
            .SetParameter("@newTx", newTx)
            .SetParameter("@newRx", newRx)
            .SetParameter("@accountId", accountId)
            .Execute();

            connection.IsBusy = false;
            return(Task.FromResult <object>(null));
        }
コード例 #3
0
        /// <summary>
        /// IDatabase.CommitConnection implementation for MySQL driver
        /// </summary>
        public Task <object> CommitCommand(Plugin.IDatabaseConnection clientImpl, long accountId, Socks.Constants.Command command, System.Net.IPEndPoint clientEndPoint, System.Net.IPEndPoint proxyEndPoint, long wiredTx, long wiredRx, DateTime commandTime, bool success)
        {
            VirtualConnection connection = clientImpl as VirtualConnection;

            uint sourceAddr = BitConverter.ToUInt32(clientEndPoint.Address.GetAddressBytes(), 0);
            uint targetAddr = BitConverter.ToUInt32(proxyEndPoint.Address.GetAddressBytes(), 0);

            connection
            .Command("INSERT INTO `commands` (`accountId`, `commandType`, `sourceAddr`, `sourcePort`, `targetAddr`, `targetPort`, `wiredTx`, `wiredRx`, `timestamp`, `success`) VALUES (@accountId, @command, @sourceAddr, @sourcePort, @targetAddr, @targetPort, @wiredTx, @wiredRx, @commandTime, @success);")
            .SetParameter("@accountId", accountId)
            .SetParameter("@command", command.ToString())
            .SetParameter("@sourceAddr", sourceAddr)
            .SetParameter("@sourcePort", clientEndPoint.Port)
            .SetParameter("@targetAddr", targetAddr)
            .SetParameter("@targetPort", proxyEndPoint.Port)
            .SetParameter("@wiredTx", wiredTx)
            .SetParameter("@wiredRx", wiredRx)
            .SetParameter("@commandTime", commandTime)
            .SetParameter("@success", success)
            .Execute();

            connection.IsBusy = false;
            return(Task.FromResult <object>(null));
        }
コード例 #4
0
 /// <summary>
 /// Command wrapper to easily query over database
 /// </summary>
 public CommandWrapper(VirtualConnection owner, string query)
 {
     this.Owner      = owner;
     this.Query      = query;
     this.Parameters = new Dictionary <string, object>();
 }