Changes to server, to reset collections.

This commit is contained in:
marcins78@gmail.com
2013-03-31 19:42:41 +00:00
parent 1deff453c0
commit 404faffdeb
11 changed files with 115 additions and 60 deletions

View File

@@ -23,6 +23,7 @@ import org.w3c.dom.Element;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.lang.reflect.Type;
import java.net.InetSocketAddress;
import java.text.DecimalFormat;
import java.util.Collection;
import java.util.List;
@@ -64,7 +65,7 @@ public class LeagueRequestHandler extends LotroServerRequestHandler implements U
if (league == null)
throw new HttpProcessingException(404);
if (!_leagueService.playerJoinsLeague(league, resourceOwner, e.getRemoteAddress().toString()))
if (!_leagueService.playerJoinsLeague(league, resourceOwner, ((InetSocketAddress) e.getRemoteAddress()).getHostName()))
throw new HttpProcessingException(409);
responseWriter.writeXmlResponse(null);

View File

@@ -25,7 +25,11 @@ public class LoginRequestHandler extends LotroServerRequestHandler implements Ur
Player player = _playerDao.loginUser(login, password);
if (player != null) {
if (player.getType().contains("u")) {
responseWriter.writeXmlResponse(null, logUserReturningHeaders(e, login));
if (player.getType().contains("a")) {
responseWriter.writeXmlResponse(null, logUserReturningHeaders(e, login));
} else {
responseWriter.writeError(503);
}
} else {
responseWriter.writeError(403);
}

View File

@@ -20,6 +20,7 @@ import org.jboss.netty.handler.codec.http.multipart.InterfaceHttpData;
import java.io.IOException;
import java.lang.reflect.Type;
import java.net.InetSocketAddress;
import java.sql.SQLException;
import java.util.Collections;
import java.util.LinkedList;
@@ -132,7 +133,7 @@ public class LotroServerRequestHandler {
}
protected Map<String, String> logUserReturningHeaders(MessageEvent e, String login) throws SQLException {
_playerDao.updateLastLoginIp(login, e.getChannel().getRemoteAddress().toString());
_playerDao.updateLastLoginIp(login, ((InetSocketAddress) e.getChannel().getRemoteAddress()).getHostName());
CookieEncoder cookieEncoder = new CookieEncoder(true);
for (Map.Entry<String, String> cookie : _loggedUserHolder.logUser(login).entrySet())

View File

@@ -1,12 +1,9 @@
package com.gempukku.lotro.async.handler;
import com.gempukku.lotro.async.HttpProcessingException;
import com.gempukku.lotro.async.ResponseWriter;
import com.gempukku.lotro.db.LoginInvalidException;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
import java.lang.reflect.Type;
import java.util.Map;
@@ -19,19 +16,21 @@ public class RegisterRequestHandler extends LotroServerRequestHandler implements
@Override
public void handleRequest(String uri, HttpRequest request, Map<Type, Object> context, ResponseWriter responseWriter, MessageEvent e) throws Exception {
if (uri.equals("") && request.getMethod() == HttpMethod.POST) {
HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request);
String login = getFormParameterSafely(postDecoder, "login");
String password = getFormParameterSafely(postDecoder, "password");
try {
if (_playerDao.registerUser(login, password, e.getRemoteAddress().toString())) {
responseWriter.writeXmlResponse(null, logUserReturningHeaders(e, login));
} else {
throw new HttpProcessingException(409);
}
} catch (LoginInvalidException exp) {
throw new HttpProcessingException(400);
}
responseWriter.writeError(503);
//
// HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(request);
// String login = getFormParameterSafely(postDecoder, "login");
// String password = getFormParameterSafely(postDecoder, "password");
// try {
// if (_playerDao.registerUser(login, password, e.getRemoteAddress().toString())) {
// responseWriter.writeXmlResponse(null, logUserReturningHeaders(e, login));
// } else {
// throw new HttpProcessingException(409);
// }
// } catch (LoginInvalidException exp) {
// throw new HttpProcessingException(400);
// }
//
} else {
responseWriter.writeError(404);
}

View File

@@ -70,21 +70,24 @@
$(".error").html("Password and Password repeated are different! Try again");
} else {
comm.register(login, password, function() {
location.href="/gemp-lotr/hall.html";
location.href = "/gemp-lotr/hall.html";
},
{
"0": function() {
alert("Unable to connect to server, either server is down or there is a problem" +
" with your internet connection");
},
"400":function() {
$(".error").html("Login is invalid. Login must be between 2-10 characters long, and contain only<br/>"+
" english letters, numbers or _ (underscore) and - (dash) characters.");
},
"409": function() {
$(".error").html("User with this login already exists in the system. Try a different one.");
}
});
{
"0": function() {
alert("Unable to connect to server, either server is down or there is a problem" +
" with your internet connection");
},
"400":function() {
$(".error").html("Login is invalid. Login must be between 2-10 characters long, and contain only<br/>" +
" english letters, numbers or _ (underscore) and - (dash) characters.");
},
"409": function() {
$(".error").html("User with this login already exists in the system. Try a different one.");
},
"503": function() {
$(".error").html("Server is down for maintenance. Please come at a later time.");
}
});
}
}
@@ -102,22 +105,25 @@
var login = $("#login").val();
var password = $("#password").val();
comm.login(login, password, function() {
location.href = "/gemp-lotr/hall.html";
},
{
"0": function() {
alert("Unable to connect to server, either server is down or there is a problem" +
" with your internet connection");
},
"401":function() {
$(".error").html("Invalid username or password. Try again.");
loginScreen();
},
"403": function() {
$(".error").html("You have been banned. If you think it was a mistake, please write an e-mail to <a href='mailto:marcins78@gmail.com>marcins78@gmail.com</a>");
$(".interaction").html("");
}
});
location.href = "/gemp-lotr/hall.html";
},
{
"0": function() {
alert("Unable to connect to server, either server is down or there is a problem" +
" with your internet connection");
},
"401":function() {
$(".error").html("Invalid username or password. Try again.");
loginScreen();
},
"403": function() {
$(".error").html("You have been banned. If you think it was a mistake, please write an e-mail to <a href='mailto:marcins78@gmail.com>marcins78@gmail.com</a>");
$(".interaction").html("");
},
"503": function() {
$(".error").html("Server is down for maintenance. Please come at a later time.");
}
});
}
function loginScreen() {

View File

@@ -37,7 +37,7 @@ public class MerchantService {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
setupDate = format.parse("2012-03-14 00:00:00");
setupDate = format.parse("2013-03-31 00:00:00");
} catch (ParseException exp) {
throw new RuntimeException("Unable to parse merchant setup date");
}

View File

@@ -93,7 +93,15 @@ public class StorageBasedMerchant implements Merchant {
if (normalPrice == null)
return null;
int price = Math.max(MIN_BUY_PRICE, (int) Math.floor(_profitMargin * normalPrice));
int priceWithProfit = (int) Math.floor(_profitMargin * normalPrice);
boolean outOfStock = (lastTransaction == null || lastTransaction.getStock() < OUT_OF_STOCK_MIN);
// If card is out of stock, adjust the buy price, as it might be over-inflated (due to over-selling)
if (outOfStock)
priceWithProfit = priceWithProfit / OUT_OF_STOCK_MULTIPLIER;
int price = Math.max(MIN_BUY_PRICE, priceWithProfit);
if (foil)
return FOIL_PRICE_MULTIPLIER * price;

View File

@@ -15,11 +15,11 @@ public class DailyTournamentPrizes implements TournamentPrizes {
public CardCollection getPrizeForTournament(PlayerStanding playerStanding, int playersCount) {
DefaultCardCollection tournamentPrize = new DefaultCardCollection();
if (playerStanding.getStanding() == 1) {
tournamentPrize.addItem("(S)Booster Choice", 8);
tournamentPrize.addItem("(S)Booster Choice", 10);
} else if (playerStanding.getStanding() == 2) {
tournamentPrize.addItem("(S)Booster Choice", 5);
tournamentPrize.addItem("(S)Booster Choice", 8);
} else if (playerStanding.getStanding() <=4) {
tournamentPrize.addItem("(S)Booster Choice", 4);
tournamentPrize.addItem("(S)Booster Choice", 5);
} else if (playerStanding.getStanding()<=8) {
tournamentPrize.addItem("(S)Booster Choice", 2);
}
@@ -36,6 +36,6 @@ public class DailyTournamentPrizes implements TournamentPrizes {
@Override
public String getPrizeDescription() {
return "<div class='prizeHint' value='1st place - 8 boosters, 2nd place - 5 boosters, 3rd and 4th place - 4 boosters, 5th-8th - 2 boosters each'>8-5-4-2</div>";
return "<div class='prizeHint' value='1st place - 10 boosters, 2nd place - 8 boosters, 3rd and 4th place - 5 boosters, 5th-8th - 2 boosters each'>10-8-5-2</div>";
}
}

View File

@@ -27,6 +27,7 @@ public class SingleEliminationOnDemandPrizes implements TournamentPrizes{
DefaultCardCollection tournamentPrize = new DefaultCardCollection();
if (playerStanding.getPoints() == 3) {
tournamentPrize.addItem("(S)Booster Choice", 2);
tournamentPrize.addItem(getRandom(_promos), 1);
} else if (playerStanding.getPoints() == 2) {
tournamentPrize.addItem("(S)Booster Choice", 1);
tournamentPrize.addItem(getRandom(_promos), 1);
@@ -50,6 +51,6 @@ public class SingleEliminationOnDemandPrizes implements TournamentPrizes{
@Override
public String getPrizeDescription() {
return "<div class='prizeHint' value='3 wins - 2 boosters, 2 wins - 1 booster and a random promo, 1 win - 1 booster'>2-(1+promo)-1-1</div>";
return "<div class='prizeHint' value='3 wins - 2 boosters and a random promo, 2 wins - 1 booster and a random promo, 1 win - 1 booster'>(2+promo)-(1+promo)-1-1</div>";
}
}

View File

@@ -29,4 +29,8 @@ public class MockMerchantDAO implements MerchantDAO {
return new Transaction(_dates.get(blueprintId), _prices.get(blueprintId), _transactionTypes.get(blueprintId), _stock.get(blueprintId));
return null;
}
public void setStock(String blueprintId, int count) {
_stock.put(blueprintId, count);
}
}

View File

@@ -3,24 +3,24 @@ package com.gempukku.lotro.merchant;
import com.gempukku.lotro.cards.CardSets;
import com.gempukku.lotro.db.MerchantDAO;
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import java.util.Date;
import static org.junit.Assert.*;
public class StorageBasedMerchantTest {
private StorageBasedMerchant _merchant;
private CardSets _cardSets = new CardSets();
private static final long DAY = 1000 * 60 * 60 * 24;
private MockMerchantDAO _merchantDao;
@Before
public void setup() {
Date setupDate = new Date(0);
MerchantDAO merchantDao = new MockMerchantDAO();
_merchantDao = new MockMerchantDAO();
_merchant = new StorageBasedMerchant(new LotroCardBlueprintLibrary(), merchantDao, setupDate, _cardSets);
_merchant = new StorageBasedMerchant(new LotroCardBlueprintLibrary(), _merchantDao, setupDate, _cardSets);
}
@Test
@@ -77,6 +77,37 @@ public class StorageBasedMerchantTest {
assertTrue(initialPrice > _merchant.getCardBuyPrice("1_1", new Date(DAY)));
}
@Test
public void buyAndSellLosesOnValue() {
_merchantDao.setStock("1_1", 2);
long time = 0;
// Buy 5 times the same card every 10 seconds, then sell the 5, also every 10 sec
int moneySpent = 0;
int moneyEarned = 0;
for (int i=0; i<5; i++) {
int sellPrice = _merchant.getCardSellPrice("1_1", new Date(time));
moneySpent+=sellPrice;
_merchant.cardSold("1_1", new Date(time), sellPrice);
System.out.println("Bought for: "+sellPrice);
time+=10*1000;
}
System.out.println("Selling for : "+_merchant.getCardSellPrice("1_1", new Date(time)));
System.out.println("Buying for: "+_merchant.getCardBuyPrice("1_1", new Date(time)));
for (int i=0; i<5; i++) {
int buyPrice = _merchant.getCardBuyPrice("1_1", new Date(time));
moneyEarned+=buyPrice;
_merchant.cardBought("1_1", new Date(time), buyPrice);
System.out.println("Sold for: "+buyPrice);
time+=10*1000;
}
System.out.println("Money spent: "+moneySpent);
System.out.println("Money earned: "+moneyEarned);
assertTrue(moneySpent>moneyEarned);
}
// @Test
public void plotPricesAfterTransactions() {
Date setupDate = new Date(-1000 * 60 * 60 * 24 * 50L);