Added code to detect if players are cheating (creating multiple accounts or joining the same league from multiple accounts).

This commit is contained in:
marcins78@gmail.com
2012-08-23 22:32:35 +00:00
parent ab5815736f
commit cf9709a283
7 changed files with 32 additions and 12 deletions

View File

@@ -17,14 +17,15 @@ public class DbLeagueParticipationDAO implements LeagueParticipationDAO {
_dbAccess = dbAccess;
}
public void userJoinsLeague(String leagueId, Player player) {
public void userJoinsLeague(String leagueId, Player player, String remoteAddr) {
try {
Connection conn = _dbAccess.getDataSource().getConnection();
try {
PreparedStatement statement = conn.prepareStatement("insert into league_participation (league_type, player_name) values (?,?)");
PreparedStatement statement = conn.prepareStatement("insert into league_participation (league_type, player_name, join_ip) values (?,?,?)");
try {
statement.setString(1, leagueId);
statement.setString(2, player.getName());
statement.setString(3, remoteAddr);
statement.execute();
} finally {
statement.close();

View File

@@ -5,7 +5,7 @@ import com.gempukku.lotro.game.Player;
import java.util.Collection;
public interface LeagueParticipationDAO {
public void userJoinsLeague(String leagueId, Player player);
public void userJoinsLeague(String leagueId, Player player, String remoteAddr);
public Collection<String> getUsersParticipating(String leagueId);
}

View File

@@ -122,18 +122,19 @@ public class PlayerDAO {
}
}
public synchronized boolean registerUser(String login, String password) throws SQLException {
public synchronized boolean registerUser(String login, String password, String remoteAddr) throws SQLException {
boolean result = validateLogin(login);
if (!result)
return false;
Connection conn = _dbAccess.getDataSource().getConnection();
try {
PreparedStatement statement = conn.prepareStatement("insert into player (name, password, type) values (?, ?, ?)");
PreparedStatement statement = conn.prepareStatement("insert into player (name, password, type, create_ip) values (?, ?, ?, ?)");
try {
statement.setString(1, login);
statement.setString(2, encodePassword(password));
statement.setString(3, "u");
statement.setString(4, remoteAddr);
statement.execute();
return true;
} finally {
@@ -260,4 +261,20 @@ public class PlayerDAO {
conn.close();
}
}
public void updateLastLoginIp(String login, String remoteAddr) throws SQLException {
Connection conn = _dbAccess.getDataSource().getConnection();
try {
PreparedStatement statement = conn.prepareStatement("update player set last_ip=? where name=?");
try {
statement.setString(1, remoteAddr);
statement.setString(2, login);
statement.execute();
} finally {
statement.close();
}
} finally {
conn.close();
}
}
}

View File

@@ -23,11 +23,11 @@ public class CachedLeagueParticipationDAO implements LeagueParticipationDAO {
}
@Override
public void userJoinsLeague(String leagueId, Player player) {
public void userJoinsLeague(String leagueId, Player player, String remoteAddr) {
_readWriteLock.writeLock().lock();
try {
getLeagueParticipantsInWriteLock(leagueId).add(player.getName());
_leagueParticipationDAO.userJoinsLeague(leagueId, player);
_leagueParticipationDAO.userJoinsLeague(leagueId, player, remoteAddr);
} finally {
_readWriteLock.writeLock().unlock();
}

View File

@@ -90,12 +90,12 @@ public class LeagueService {
return _leagueParticipationDAO.getUsersParticipating(league.getType()).contains(player.getName());
}
public synchronized boolean playerJoinsLeague(League league, Player player) {
public synchronized boolean playerJoinsLeague(League league, Player player, String remoteAddr) {
if (isPlayerInLeague(league, player))
return false;
int cost = league.getCost();
if (_collectionsManager.removeCurrencyFromPlayerCollection(player, new CollectionType("permanent", "My cards"), cost)) {
_leagueParticipationDAO.userJoinsLeague(league.getType(), player);
_leagueParticipationDAO.userJoinsLeague(league.getType(), player, remoteAddr);
league.getLeagueData().joinLeague(_collectionsManager, player, DateUtils.getCurrentDate());
_leagueStandings.remove(LeagueMapKeys.getLeagueMapKey(league));

View File

@@ -44,7 +44,7 @@ public class LeagueResource extends AbstractResource {
if (league == null)
sendError(Response.Status.NOT_FOUND);
if (!_leagueService.playerJoinsLeague(league, resourceOwner))
if (!_leagueService.playerJoinsLeague(league, resourceOwner, request.getRemoteAddr()))
sendError(Response.Status.CONFLICT);
}

View File

@@ -22,6 +22,7 @@ import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -82,7 +83,7 @@ public class ServerResource extends AbstractResource {
@FormParam("login") String login,
@FormParam("password") String password,
@Context HttpServletRequest request) throws Exception {
if (_playerDao.registerUser(login, password)) {
if (_playerDao.registerUser(login, password, request.getRemoteAddr())) {
logUser(request, login);
return "<script>location.href='hall.html';</script>";
} else {
@@ -309,7 +310,8 @@ public class ServerResource extends AbstractResource {
}
}
private void logUser(HttpServletRequest request, String login) {
private void logUser(HttpServletRequest request, String login) throws SQLException {
_playerDao.updateLastLoginIp(login, request.getRemoteAddr());
request.getSession().setAttribute("logged", login);
}