Esempio n. 1
0
        protected Hashtable HandleBuyPointChange(string rawBpId, Hashtable request)
        {
            JObject json = GetJsonFromPost(request);

            string name         = (string)json.SelectToken("Name");
            bool   changingName = name != null;

            string rawDevelopmentRightsBuyerId = (string)json.SelectToken("DevelopmentRightsOwner.Uuid.Guid");
            bool   buyingDevelopmentRights     = rawDevelopmentRightsBuyerId != null;

            string rawWaterRightsBuyerId = (string)json.SelectToken("WaterRightsOwner.Uuid.Guid");
            bool   buyingWaterRights     = rawWaterRightsBuyerId != null;

            int?developmentRightsPrice = (int?)json.SelectToken("DevelopmentRightsPrice");
            int?waterRightsPrice       = (int?)json.SelectToken("WaterRightsPrice");
            int?combinedRightsPrice    = (int?)json.SelectToken("CombinedPrice");

//            m_log.InfoFormat(
//                "rawBpId [{0}], buyingDevelopmentRights [{1}], buyingWaterRights [{2}]",
//                rawBpId, buyingDevelopmentRights, buyingWaterRights);

            UUID     bpId = WaterWarsUtils.ParseRawId(rawBpId);
            BuyPoint bp   = null;

            m_controller.Game.BuyPoints.TryGetValue(bpId, out bp);

            if (changingName)
            {
                return(HandleChangeName(bp, name));
            }
            else if (buyingDevelopmentRights || buyingWaterRights)
            {
                return(HandleBuyRights(
                           bp, buyingDevelopmentRights, buyingWaterRights,
                           rawDevelopmentRightsBuyerId, rawWaterRightsBuyerId,
                           developmentRightsPrice, waterRightsPrice, combinedRightsPrice, request));
            }

            // TODO: Deal with error situations: uuid not valid, no such buy point, not enough money, etc.

            Hashtable reply = new Hashtable();

            reply["int_response_code"]   = 200; // 200 OK
            reply["str_response_string"] = "hoorah";
            reply["content_type"]        = "text/plain";

            return(reply);
        }
Esempio n. 2
0
        protected Hashtable HandleLogin(UUID playerId, Hashtable request)
        {
            Hashtable reply = new Hashtable();

            // We have to give some response string otherwise the return code crashes
            reply["str_response_string"] = "";

            UUID loginToken = UUID.Zero;

            lock (m_loginTokens)
                m_loginTokens.TryGetValue(playerId, out loginToken);

            bool passed = false;

            if (!WaterWarsConstants.IS_WEBSERVICE_SECURITY_ON)
            {
                passed = true;
            }
            else
            {
                UUID submittedLoginToken = WaterWarsUtils.ParseRawId((string)request["loginToken"]);

                if (loginToken == submittedLoginToken)
                {
                    passed = true;
                }
            }

            if (passed)
            {
                reply["int_response_code"] = 200;

                lock (m_loginTokens)
                    m_loginTokens.Remove(playerId);

                // TODO: Establish the second authorization token
            }
            else
            {
                reply["int_response_code"] = 401;
            }

            return(reply);
        }
Esempio n. 3
0
        protected Hashtable HandleBuyRights(
            BuyPoint bp, bool buyingDevelopmentRights, bool buyingWaterRights,
            string rawDevelopmentRightsBuyerId, string rawWaterRightsBuyerId,
            int?developmentRightsPrice, int?waterRightsPrice, int?combinedRightsPrice, Hashtable request)
        {
            if (bp.DevelopmentRightsOwner == Player.None)
            {
                m_controller.Resolver.BuyLandRights(bp.Uuid.ToString(), rawDevelopmentRightsBuyerId);
            }
            else
            {
                UUID developmentRightsBuyerId = UUID.Zero;
                if (rawDevelopmentRightsBuyerId != null)
                {
                    developmentRightsBuyerId = WaterWarsUtils.ParseRawId(rawDevelopmentRightsBuyerId);
                }

                UUID waterRightsBuyerId = UUID.Zero;
                if (rawWaterRightsBuyerId != null)
                {
                    waterRightsBuyerId = WaterWarsUtils.ParseRawId(rawWaterRightsBuyerId);
                }

                // TODO: Do player ownership checks later when we have access to this via security

                if (buyingDevelopmentRights && buyingWaterRights)
                {
                    if (null == combinedRightsPrice)
                    {
                        throw new Exception(
                                  string.Format("No combined rights price specified for sale of {0} rights", bp));
                    }

                    m_controller.Resolver.SellRights(
                        bp, developmentRightsBuyerId, RightsType.Combined, (int)combinedRightsPrice);
                }
                else if (buyingDevelopmentRights)
                {
                    if (null == developmentRightsPrice)
                    {
                        throw new Exception(
                                  string.Format("No development rights price specified for sale of {0} rights", bp));
                    }

                    m_controller.Resolver.SellRights(
                        bp, developmentRightsBuyerId, RightsType.Development, (int)developmentRightsPrice);
                }
                else if (buyingWaterRights)
                {
                    if (null == waterRightsPrice)
                    {
                        throw new Exception(
                                  string.Format("No water rights price specified for sale of {0} rights", bp));
                    }

                    m_controller.Resolver.SellRights(
                        bp, waterRightsBuyerId, RightsType.Water, (int)waterRightsPrice);
                }
            }

            // TODO: Deal with error situations: uuid not valid, no such buy point, not enough money, etc.

            Hashtable reply = new Hashtable();

            reply["int_response_code"]   = 200; // 200 OK
            reply["str_response_string"] = "hoorah";
            reply["content_type"]        = "text/plain";

            return(reply);
        }