Esempio n. 1
0
        static public void Trade(RequestContext request)
        {
            int userstate = UserHandler.AuthUser(request);

            if (userstate == 1 || userstate == 2)
            {
                string tradeId = ExtractIdFromRessource(request.Ressource);
                User   user    = UserHandler.GetUserDataByToken(request);
                if (!TradingDatabaseHandler.CheckDealToUser(tradeId, user))
                {
                    string    offeredCardId = request.Message.Trim('"');
                    DummyCard dummyCard     = CardsUsersDatabaseHandler.GetDummyCard(user, offeredCardId);
                    if (dummyCard != null)
                    {
                        ICard card = DummyCardConverter.Convert(dummyCard);
                        if (TradingDatabaseHandler.Trade(tradeId, user, offeredCardId, card.type, card.damage))
                        {
                            TradingDatabaseHandler.DeleteTradingDeal(tradeId);
                            Output.WriteConsole(Output.TradeSuccess);
                            return;
                        }
                        Output.WriteConsole(Output.TradeConditionsNotMet);
                        return;
                    }
                    Output.WriteConsole(Output.TradeInvalidCard);
                    return;
                }
                Output.WriteConsole(Output.TradeSelfTrade);
                return;
            }
            Output.WriteConsole(Output.AuthError);
        }
Esempio n. 2
0
        static public void CreateDeal(RequestContext request)
        {
            int userstate = UserHandler.AuthUser(request);

            if (userstate == 1 || userstate == 2)
            {
                TradeItem item = JsonConvert.DeserializeObject <TradeItem>(request.Message);
                User      user = UserHandler.GetUserDataByToken(request);
                if (UserCardsHandler.CheckValidCardToUser(item.cardToTrade, user))
                {
                    try
                    {
                        TradingDatabaseHandler.CreateTradingDeal(user, item);
                        Output.WriteConsole(Output.TradeCreationSuccess);
                    }
                    catch (Exception e)
                    {
                        Output.WriteConsole(e.Message);
                    }
                    return;
                }
                Output.WriteConsole(Output.TradeCreationInvalidCard);
                return;
            }
            Output.WriteConsole(Output.AuthError);
        }
Esempio n. 3
0
        static public string ShowTradeDeals(RequestContext request)
        {
            int userstate = UserHandler.AuthUser(request);

            if (userstate == 1 || userstate == 2)
            {
                return(TradingDatabaseHandler.GetTradingDeals());
            }
            return(Output.AuthError);
        }
Esempio n. 4
0
        static public string DeleteDeal(RequestContext request)
        {
            int userstate = UserHandler.AuthUser(request);

            if (userstate == 1 || userstate == 2)
            {
                string id = ExtractIdFromRessource(request.Ressource);
                if (TradingDatabaseHandler.CheckDealToUser(id, UserHandler.GetUserDataByToken(request)))
                {
                    TradingDatabaseHandler.DeleteTradingDeal(id);
                    return(Output.TradeDeletionSuccess);
                }
                return(Output.TradeDeletionError);
            }
            return(Output.AuthError);
        }