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 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);
        }