예제 #1
0
    void ServerRenew()
    {
        ServerRentParams prm = new ServerRentParams(web);

        // hourly rent, check if user can donate (there is required delay after account creation)
        if (prm.rentID >= HOURLY_RENTID_START)
        {
            int HoursLeft = ServerGetHoursLeftForDonate();
            if (HoursLeft > 0)
            {
                Response.Write("WO_4");
                Response.Write(string.Format("{0}", HoursLeft));
                return;
            }
        }

        // verify that client price is correct!
        ReadPricesFromDB(false);
        int price = calcServerRentPrice(prm);

        if (price != prm.client_price)
        {
            Response.Write("WO_3");
            Response.Write(string.Format("price calc desync {0} vs {1}", price, prm.client_price));
            return;
        }
        if (price <= 0)
        {
            throw new ApiExitException("no price");
        }

        // calc hours for rent
        int RentHours = calcRentHours(prm.rentID);

        SqlCommand sqcmd = new SqlCommand();

        sqcmd.CommandType = CommandType.StoredProcedure;
        sqcmd.CommandText = "WZ_ServerRenew";
        sqcmd.Parameters.AddWithValue("@in_CustomerID", web.CustomerID());
        sqcmd.Parameters.AddWithValue("@in_GameServerID", web.Param("GSID"));
        sqcmd.Parameters.AddWithValue("@in_PriceGP", price);
        sqcmd.Parameters.AddWithValue("@in_RentHours", RentHours);

        if (!CallWOApi(sqcmd))
        {
            return;
        }

        reader.Read();
        int ServerID = getInt("ServerID");

        Response.Write("WO_0");
        Response.Write(string.Format("{0}", ServerID));
    }
예제 #2
0
    void ServerRent()
    {
        ServerRentParams prm = new ServerRentParams(web);

        prm.name = prm.name.Trim();
        if (prm.name.Length == 0)
        {
            throw new ApiExitException("empty server name");
        }
        if (prm.rentID >= HOURLY_RENTID_START)
        {
            throw new ApiExitException("no hourly rent");
        }

        // verify that client price is correct!
        ReadPricesFromDB(true);
        int price = calcServerRentPrice(prm);

        if (price != prm.client_price)
        {
            Response.Write("WO_3");
            Response.Write(string.Format("price calc desync {0} vs {1}", price, prm.client_price));
            return;
        }
        if (price <= 0)
        {
            throw new ApiExitException("no price");
        }

        // get server slots number based on slot index
        int[] GameworldSlots  = { 10, 30, 50, 70, 100 };
        int[] StrongholdSlots = { 10, 20, 30, 40, 50 };
        int   ServerSlots     = (prm.isGameServer > 0) ? GameworldSlots[prm.slotID] : StrongholdSlots[prm.slotID];

        if (ServerSlots < 0)
        {
            throw new ApiExitException("bad slotID");
        }

        // create server flags. SYNC with client
        int SFLAGS_Passworded = 1 << 0; // passworded server
        int SFLAGS_PVE        = 1 << 1;
        int SFLAGS_Nameplates = 1 << 2;
        int SFLAGS_CrossHair  = 1 << 3;
        int SFLAGS_Tracers    = 1 << 4;
        int ServerFlags       = 0;

        if (prm.password.Length > 0)
        {
            ServerFlags |= SFLAGS_Passworded;
        }
        if (prm.pveID > 0)
        {
            ServerFlags |= SFLAGS_PVE;
        }
        if (prm.nameplates > 0)
        {
            ServerFlags |= SFLAGS_Nameplates;
        }
        if (prm.crosshair > 0)
        {
            ServerFlags |= SFLAGS_CrossHair;
        }
        if (prm.tracers > 0)
        {
            ServerFlags |= SFLAGS_Tracers;
        }

        // calc hours for rent
        int RentHours = calcRentHours(prm.rentID);

        SqlCommand sqcmd = new SqlCommand();

        sqcmd.CommandType = CommandType.StoredProcedure;
        sqcmd.CommandText = "WZ_ServerRent";
        sqcmd.Parameters.AddWithValue("@in_CustomerID", web.CustomerID());
        sqcmd.Parameters.AddWithValue("@in_PriceGP", price);
        sqcmd.Parameters.AddWithValue("@in_ServerRegion", prm.regionID);
        sqcmd.Parameters.AddWithValue("@in_ServerType", prm.isGameServer);
        sqcmd.Parameters.AddWithValue("@in_ServerFlags", ServerFlags);
        sqcmd.Parameters.AddWithValue("@in_ServerMap", prm.mapID);
        sqcmd.Parameters.AddWithValue("@in_ServerSlots", ServerSlots);
        sqcmd.Parameters.AddWithValue("@in_ServerName", prm.name);
        sqcmd.Parameters.AddWithValue("@in_ServerPwd", prm.password);
        sqcmd.Parameters.AddWithValue("@in_RentHours", RentHours);

        if (!CallWOApi(sqcmd))
        {
            return;
        }

        reader.Read();
        int ServerID = getInt("ServerID");

        Response.Write("WO_0");
        Response.Write(string.Format("{0}", ServerID));
    }
예제 #3
0
    //
    // WARNING: this code must be in sync with client code
    //
    int calcServerRentPrice(ServerRentParams prm)
    {
        PriceOptions opt = prm.isGameServer > 0 ? OptGameServer : OptStronghold;

        // calc base
        int server_base = 0;

        switch (prm.regionID)
        {
        case 1:  server_base = opt.BasePrice[0]; break;

        case 10: server_base = opt.BasePrice[1]; break;

        case 20: server_base = opt.BasePrice[2]; break;

        case 30: server_base = opt.BasePrice[3]; break;

        default: throw new ApiExitException("bad regionID");
        }
        if (server_base == 0)
        {
            return(0);
        }

        // calc all other options
        int price = server_base;

        //[TH] price is set for slot, not by percents
        switch (prm.slotID)
        {
        case 0: price = opt.Slot1; break;

        case 1: price = opt.Slot2; break;

        case 2: price = opt.Slot3; break;

        case 3: price = opt.Slot4; break;

        case 4: price = opt.Slot5; break;

        default: throw new ApiExitException("bad slotID");
        }

        if (prm.password.Length > 0)
        {
            price += getServerRentOptionPrice(server_base, opt.Passworded);
        }

        if (prm.pveID > 0)
        {
            price += getServerRentOptionPrice(server_base, opt.PVE);
        }
        else
        {
            price += getServerRentOptionPrice(server_base, opt.PVP);
        }

        if (prm.nameplates > 0)
        {
            price += getServerRentOptionPrice(server_base, opt.OptNameplates);
        }
        if (prm.crosshair > 0)
        {
            price += getServerRentOptionPrice(server_base, opt.OptCrosshair);
        }
        if (prm.tracers > 0)
        {
            price += getServerRentOptionPrice(server_base, opt.OptTracers);
        }

        // hourly rent, hours is after 100
        if (prm.rentID >= HOURLY_RENTID_START)
        {
            // 10% add for hourly rent
            price += price / 10;
            price  = (int)Math.Ceiling((float)price / 24.0f / 31.0f);
            price  = (prm.rentID - HOURLY_RENTID_START) * price;
            return(price);
        }

        // [TH] adjust per day coeff
        switch (prm.rentID)
        {
        case 0: price *= 3; break;

        case 1: price *= 7; break;

        case 2: price *= 15; break;

        case 3: price *= 30; break;

        case 4: price *= 60; break;

        default: throw new ApiExitException("bad rentid");
        }

        return(price);
    }