/// <summary>
        /// 添加客户到客户组
        /// </summary>
        /// <param name="account">客户id</param>
        /// <param name="LoginId">登陆标示</param>
        /// <returns></returns>
        public ErrType AddUserToUserGroups(string account, string Groupid, String LoginId, ref ClientAccount CAccount)
        {
            try
            {
                TradeUser user = new TradeUser();
                ResultDesc result = ManagerService.AddUserToUserGroups(account, Groupid, LoginId, ref user);
                CAccount = MyConverter.ToClientAccount(user);

                if (!result.Result)
                    return new ErrType(ERR.SERVICE, result.Desc);
                return GeneralErr.Success;
            }
            catch (TimeoutException te)
            {
                FileLog.WriteLog("", Assembly.GetExecutingAssembly().GetName().Name, this.GetType().Name, new StackTrace().GetFrame(0).GetMethod().Name, te.Message);
                return new ErrType(ERR.EXEPTION, ErrorText.TimeoutException);
            }
            catch (Exception ex)
            {
                FileLog.WriteLog("", Assembly.GetExecutingAssembly().GetName().Name, this.GetType().Name,
              new StackTrace().GetFrame(0).GetMethod().Name, ex.Message);
                return new ErrType(ERR.EXEPTION, ErrorText.OperationError);
            }
        }
 public WTradeUserInfo()
 {
     WUser = new Base_WUser();
     TdUser = new TradeUser();
 }
        //Todo:金通网待处理,登陆方法弃用
        #region MyRegion
        //internal static LoginResult ToLoginResult(ReAgentAuth dealerResult)
        //{
        //    if (dealerResult.LoginID == "-1")
        //    {
        //        return new LoginResult("登陆失败,账号或密码失败");
        //    }
        //    else
        //    {
        //        DealerAuthority dealerAuthority = ToDealerAuthority(dealerResult.AtAuth);
        //        return new LoginResult(dealerResult.LoginID, dealerResult.QuotesAddressIP, dealerResult.QuotesPort, new ManagerAuthority(dealerAuthority));
        //    }
        //} 
        #endregion

        //Todo:金通网待处理,登陆方法弃用
        #region MyRegion
        //internal static LoginResult ToLoginResult(ReClerkAuth reClerkAuth)
        //{
        //    if (reClerkAuth.LoginID == "-1")
        //    {
        //        return new LoginResult("登陆失败,账号或密码失败");
        //    }
        //    else
        //    {
        //        //Todo:权限待处理,登陆方法弃用
        //        DealerAuthority clerkAuthority = ToDealerAuthority(reClerkAuth.AtAuth);
        //        LoginResult result = new LoginResult(reClerkAuth.LoginID, reClerkAuth.QuotesAddressIP, reClerkAuth.QuotesPort, new ManagerAuthority(clerkAuthority));
        //        result.ClerkAgentId = reClerkAuth.AgentId;
        //        return result;
        //    }
        //} 
        #endregion

        #region TradeUser与 ClientAccount之间的转换

        internal static ClientAccount ToClientAccount(TradeUser user)
        {
            return new ClientAccount
            {
                AccInfo =
                {
                    UserID = user.UserID,
                    OrgId = user.OrgId,
                    AccountName = user.Account,
                    AccountPassword = user.LoginPwd,
                    Address = user.LinkAdress,
                    CellPhoneNumber = user.PhoneNum,
                    CeritificateEnum = ToCertificateEnum(user.CardType),//
                    CertificateNumber = user.CardNum,
                    Contact = user.LinkMan,
                    Email = user.Email,
                    FundsPassword = user.CashPwd,
                    TelephoneNumber = user.TelNum,
                    LastLoginTime = user.LastLoginTime,
                    LastUpdateTime = user.LastUpdateTime,
                    LastUpdateManager = user.LastUpdateID,
                    Legal = user.CorporationName,
                    LoginIP = user.Ip,
                    LoginMAC = user.Mac,
                    IsAccountEnabled = ToBoolean(user.Status),
                    IsOnline = user.Online,
                    OpeningMan = user.OpenMan,
                    OpenAccountTime = user.OpenTime,
                    OrderPhoneNumber = user.OrderPhone,
                    Sex = ToSexEnum(user.Sex),
                    UserName = user.UserName,
                    OrgName = user.OrgName,
                    BindAccount = user.BindAccount,
                    IsEnable = user.IsEnable == 1 ? "激活" : "未激活",
                    Reperson = user.Reperson,
                    Telephone = user.Telephone,
                    IsBroker = user.IsBroker,
                    PAccount = user.PAccount,
                    PUserId = user.PUserId,
                    PUserName = user.PUserName
                },
                FundsInfo =
                {
                    BankAccountName = user.AccountName,
                    BankCardNumber = user.BankCard,
                    BankNumber = user.BankAccount,
                    banktype = user.ConBankType,
                    //ContractStatus = (CONTRACT_STATUS)Enum.Parse(typeof(CONTRACT_STATUS), user.BankState),
                    ContractStatus = string.IsNullOrEmpty(user.BankState) ? CONTRACT_STATUS.Unbound : (CONTRACT_STATUS)Enum.Parse(typeof(CONTRACT_STATUS), user.BankState),//当为管理员账户时无签约状态
                    CurrentBalance = user.Money,
                    FrozenDeposit = user.FrozenMoney,
                    FundsAccount = user.Account,
                    OccupiedDeposit = user.OccMoney,
                    OpenBank = user.OpenBank,
                    SubAccount = user.SubUser,
                    TanAccount = user.TanUser,
                    DongJieMoney = user.DongJieMoney,
                },
                TransactionSettings =
                {
                    MinTrade = user.MinTrade,
                    OrderUnit = user.OrderUnit,
                    MaxTrade = user.MaxTrade,
                    AllowRecharge = user.PermitRcash,
                    AllowEncashment = user.PermitCcash,
                    AllowChargeback = user.PermitDelOrder,
                    AllowOrder = user.PermitDhuo,
                    AllowRecovery = user.PermitHshou,
                    AllowWarehousing = user.PermitRstore,
                },
            };
        }
示例#4
0
 public WUserInfo()
 {
     WUser  = new Base_WUser();
     TdUser = new TradeUser();
 }
示例#5
0
		private void checkForTrades()
		{
			string password = System.IO.File.ReadAllText(@"../cstrade_admin_password.txt");

			TradeList data;
			string getUrl = "http://skinbonanza.com/backend/get_items.php";
			var getRequest = (HttpWebRequest)WebRequest.Create (getUrl);

			string getData = "password="******"&bot_steam_id=" + Bot.SteamUser.SteamID.ConvertToUInt64();
			var getData_encoded = Encoding.ASCII.GetBytes (getData);

			getRequest.Method = "POST";
			getRequest.ContentType = "application/x-www-form-urlencoded";
			getRequest.ContentLength = getData_encoded.Length;

			using (var stream = getRequest.GetRequestStream ()) {
				stream.Write (getData_encoded, 0, getData_encoded.Length);
			}

			for(int attempts = 0;;attempts++)
			{
				try
				{
					var getResponse = (HttpWebResponse)getRequest.GetResponse (); //THIS LINE/AREA IS CAUSING A LOT OF ISSUES... TRY CATCH NEEDED
					string getString = new StreamReader (getResponse.GetResponseStream()).ReadToEnd();
					if (debug_output) {
						Log.Info(getString + "");
					}
					data = JsonConvert.DeserializeObject<TradeList> (getString);
					break;
				}
				catch (Exception e)
				{
					getRequest.Abort ();
					Log.Error (e.Message);
					if(attempts > 4)
						throw e;
				}
			}

			//Prevent valid trades from being cancelled because they dont exist in tradeStatuses yet
			foreach(TradeData trade in data.trades)
			{
				bool tradeValue;
				if(tradesDone.TryGetValue(trade.tradeid, out tradeValue))
				{
					//Log.Info("Trade " + trade.tradeid + " already made");
				}
				else if(trade.status == 2 || trade.status == 9 || trade.status == 11)
				{
					//Trade not in update list, bot must have restarted, add now
					Log.Info("Incomplete Trade Missing with tradeID: " + trade.tradeid);
					tradesDone[trade.tradeid] = true;
					tradeStatuses[trade.tradeid] = new TradeStatus(trade.user.steamid, trade.steamid, trade.tradeid, trade.type);						
				}
			}

			foreach(TradeData trade in data.trades)
			{
				bool tradeValue;
				if(tradesDone.TryGetValue(trade.tradeid, out tradeValue))
				{
					//Log.Info("Trade " + trade.tradeid + " already made");
				}
				else
				{
					Log.Info("Trade " + trade.tradeid + " not completed... Attempting");

					TradeUser user = trade.user;

					var tradeOffer = Bot.NewTradeOffer(new SteamID(user.steamid));
					int count = 0;
					foreach(long item in trade.items)
					{
						Log.Info("Adding Item with AssetID: " + item + " to Trade");
						if(trade.type.Equals("d", StringComparison.Ordinal) || 
						   trade.type.Equals("t", StringComparison.Ordinal))
						{
							tradeOffer.Items.AddTheirItem(730, 2, item);
						}
						else if(trade.type.Equals("w", StringComparison.Ordinal))
						{
							tradeOffer.Items.AddMyItem(730, 2, item);
						}
						count++;
					}
					if(trade.type.Equals("d", StringComparison.Ordinal) || 
					   trade.type.Equals("t", StringComparison.Ordinal))
					{
						Log.Info("Deposit/MultiTrade: " + count + " items being traded from user " + user.steamid);
					}
					else if(trade.type.Equals("w", StringComparison.Ordinal))
					{
						Log.Info("Withdrawal: " + count + " items being traded to user " + user.steamid);
					}


					if (tradeOffer.Items.NewVersion == null) {
						Log.Error ("TradeOffer is appearing as NULL, restarting the bot may fix?");
					}
					if (tradeOffer.Items.NewVersion)
					{
						string tradeID = "";
						string tradeError = "";
						bool sent = tradeOffer.SendWithToken(out tradeID, out tradeError, trade.user.token, "Secure Code: " + trade.code);

						if(sent)
						{
							Log.Success("New TradeID: " + tradeID);
							tradesDone[trade.tradeid] = true;
							//Add trade to list of trades to check status of (accepted, declined, etc)
							tradeStatuses[trade.tradeid] = new TradeStatus(user.steamid, tradeID, trade.tradeid, trade.type);

							string setTradeIDData = "password="******"&trade_id=" + trade.tradeid;
							setTradeIDData += "&trade_steam_id=" + tradeID;

							string url = "http://skinbonanza.com/backend/update_trade.php";
							var updaterequest = (HttpWebRequest)WebRequest.Create (url);

							var setTradeID_data = Encoding.ASCII.GetBytes (setTradeIDData);

							updaterequest.Method = "POST";
							updaterequest.ContentType = "application/x-www-form-urlencoded";
							updaterequest.ContentLength = setTradeID_data.Length;

							using (var stream = updaterequest.GetRequestStream ()) {
								stream.Write (setTradeID_data, 0, setTradeID_data.Length);
							}

							for(int attempts = 0;;attempts++)
							{
								try
								{
									var response = (HttpWebResponse)updaterequest.GetResponse ();
									var responseString = new StreamReader (response.GetResponseStream ()).ReadToEnd ();
									if(responseString.Contains("success"))
									{
										Log.Info("Steam TradeID set in update_trade.");
									}
									break;
								}
								catch (Exception e)
								{
									Log.Error (e.Message);
									if(attempts > 4)
										throw e;
								}
							}
						}
						else
						{
							int statusID = 12;
							if (!String.IsNullOrEmpty (tradeError)) {
								if (tradeError.Contains ("JSonException")) {
									Log.Error ("Trade may have been sent, but a JSON conversion error occurred");
									statusID = 14;
								} else if (tradeError.Contains ("ResponseEmpty")) {
									Log.Error ("The request was sent, but Steam returned an empty response");
									statusID = 15;
								} else if (tradeError.Contains ("(26)")) {
									Log.Error ("The trade contains an invalid trade item");
									statusID = 16;
								} else if (tradeError.Contains ("(15)")) {
									Log.Error ("The trade url for the user is invalid");
									statusID = 17;
								} else if (tradeError.Contains ("(50)")) {
									Log.Error ("Too many concurrent trade offers sent (5 max)");
									statusID = 18;
								} else {
									Log.Error ("Error: {0}", tradeError);
								}
							} else {
								Log.Error ("Trade not sent and trade error is null/empty!");
							}

							int knownActiveTradesCount = 0;
							foreach(KeyValuePair<int, TradeStatus> knowntrade in tradeStatuses)
							{
								if(knowntrade.Value.state == TradeOfferState.TradeOfferStateCanceled
									|| knowntrade.Value.state == TradeOfferState.TradeOfferStateCountered
									|| knowntrade.Value.state == TradeOfferState.TradeOfferStateDeclined
									|| knowntrade.Value.state == TradeOfferState.TradeOfferStateExpired
									|| knowntrade.Value.state == TradeOfferState.TradeOfferStateInvalid
									|| knowntrade.Value.state == TradeOfferState.TradeOfferStateInvalidItems
									|| knowntrade.Value.state == TradeOfferState.TradeOfferStateCanceledBySecondFactor
									|| knowntrade.Value.itemsPushed == true)
								{
								}
								else
								{
									knownActiveTradesCount++;
								}
							}

							OffersResponse offersresponse = Bot.tradeOfferManager.webApi.GetActiveTradeOffers(true, false, false);
							List<Offer> activeTrades = offersresponse.TradeOffersSent;
							bool unmatched = false;
							if(activeTrades.Count != knownActiveTradesCount)
							{
								foreach(Offer offer in activeTrades)
								{
									//GetActiveOffers still gets cancelled and declined trades
									//so check that the trade is actually active
									if(offer.TradeOfferState == TradeOfferState.TradeOfferStateActive
										|| offer.TradeOfferState == TradeOfferState.TradeOfferStateNeedsConfirmation
										|| offer.TradeOfferState == TradeOfferState.TradeOfferStateInEscrow)
									{
										foreach(KeyValuePair<int, TradeStatus> checkTrade in tradeStatuses)
										{
											if(checkTrade.Value.state == TradeOfferState.TradeOfferStateCanceled
												|| checkTrade.Value.state == TradeOfferState.TradeOfferStateCountered
												|| checkTrade.Value.state == TradeOfferState.TradeOfferStateDeclined
												|| checkTrade.Value.state == TradeOfferState.TradeOfferStateExpired
												|| checkTrade.Value.state == TradeOfferState.TradeOfferStateInvalid
												|| checkTrade.Value.state == TradeOfferState.TradeOfferStateInvalidItems
												|| checkTrade.Value.state == TradeOfferState.TradeOfferStateCanceledBySecondFactor
												|| checkTrade.Value.itemsPushed == true)
											{
											}
											else
											{
												if(checkTrade.Value.steam_trade_id == offer.TradeOfferId)
												{
													//matching trade found
													continue;
												}
											}
										}

										//no matching trade found
										//trade not being tracked
										unmatched = true;
										Log.Error("Untracked trade found {0}, cancelling it", offer.TradeOfferId);
										Bot.tradeOfferManager.session.Cancel(offer.TradeOfferId);
									}
								}
							}
							if(!unmatched)
								Log.Success("No non-tracked trades found.");

							string postData = "password="******"&trade_id=" + trade.tradeid;
							postData += "&trade_status=" + statusID;
							postData += "&user_steam_id=" + user.steamid;
							postData += "&bot_steam_id=" + Bot.SteamUser.SteamID.ConvertToUInt64();

							string url = "http://skinbonanza.com/backend/update_trade.php";
							var updaterequest = (HttpWebRequest)WebRequest.Create (url);

							var failedTrade_data = Encoding.ASCII.GetBytes (postData);

							updaterequest.Method = "POST";
							updaterequest.ContentType = "application/x-www-form-urlencoded";
							updaterequest.ContentLength = failedTrade_data.Length;

							using (var stream = updaterequest.GetRequestStream ()) {
								stream.Write (failedTrade_data, 0, failedTrade_data.Length);
							}

							for (int attempts = 0;; attempts++) 
							{
								try 
								{
									var response = (HttpWebResponse)updaterequest.GetResponse ();
									var responseString = new StreamReader (response.GetResponseStream ()).ReadToEnd ();
									if (responseString.Contains ("success")) {
										Log.Success ("Trade status updated.");
									}
									break;
								} catch (Exception e) {
									Log.Error (e.Message);
									if (attempts > 4)
										throw e;
								}
							}
						}
					}
					else
					{
						Log.Error("Old version of trade. Cancelling.");

						string postData = "password="******"&trade_id=" + trade.tradeid;
						postData += "&trade_status=" + 6;
						postData += "&user_steam_id=" + user.steamid;
						postData += "&bot_steam_id=" + Bot.SteamUser.SteamID.ConvertToUInt64();

						string url = "http://skinbonanza.com/backend/update_trade.php";
						var updaterequest = (HttpWebRequest)WebRequest.Create (url);

						var failedTrade_data = Encoding.ASCII.GetBytes (postData);

						updaterequest.Method = "POST";
						updaterequest.ContentType = "application/x-www-form-urlencoded";
						updaterequest.ContentLength = failedTrade_data.Length;

						using (var stream = updaterequest.GetRequestStream ()) {
							stream.Write (failedTrade_data, 0, failedTrade_data.Length);
						}

						for (int attempts = 0;; attempts++) 
						{
							try 
							{
								var response = (HttpWebResponse)updaterequest.GetResponse ();
								var responseString = new StreamReader (response.GetResponseStream ()).ReadToEnd ();
								if (responseString.Contains ("success")) {
									Log.Success ("Trade status updated.");
								}
								break;
							} catch (Exception e) {
								Log.Error (e.Message);
								if (attempts > 4)
									throw e;
							}
						}
					}
				}
			}
			//https://steamcommunity.com/tradeoffer/new/?partner=81920318&token=od9DZwUG
		}
 public TradeAcceptedComposer(TradeUser tradeUser)
 {
     this.tradeUser = tradeUser;
 }