}
} else {
/*
* Player is logged in, allow interaction with their player object
*/
PlayerChar p = (PlayerChar) session.getAttribute("player");
p.lastPacket = System.currentTimeMillis();
switch(message.charAt(0)) {
case 'U':
//Move up
p.queueMovement(Direction.Up);
break;
case 'D':
//Move down
p.queueMovement(Direction.Down);
break;
case 'L':
//Move left
p.queueMovement(Direction.Left);
break;
case 'R':
//Move right
p.queueMovement(Direction.Right);
break;
case 'P':
//Pokemon interaction
int pokemonIndex = 0;
String move;
switch(message.charAt(1)) {
case 'm':
//Player is allowing move to be learned
pokemonIndex = Integer.parseInt(String.valueOf(message.charAt(2)));
int moveIndex = Integer.parseInt(String.valueOf(message.charAt(3)));
move = message.substring(4);
if(move != null && !move.equalsIgnoreCase("") &&
p.getParty()[pokemonIndex] != null) {
if(p.getParty()[pokemonIndex].getMovesLearning().contains(move)) {
p.getParty()[pokemonIndex].learnMove(moveIndex, move);
p.updateClientPP(pokemonIndex, moveIndex);
}
}
break;
case 'M':
//Player is not allowing the move to be learned
pokemonIndex = Integer.parseInt(String.valueOf(message.charAt(2)));
move = message.substring(3);
if(p.getParty()[pokemonIndex] != null) {
if(p.getParty()[pokemonIndex].getMovesLearning().contains(move)) {
p.getParty()[pokemonIndex].getMovesLearning().remove(move);
}
}
break;
case 'e':
//Evolution response
pokemonIndex = Integer.parseInt(String.valueOf(message.charAt(3)));
if(p.getParty()[pokemonIndex] != null) {
switch(message.charAt(2)) {
case '0':
//Cancel evolution
p.getParty()[pokemonIndex].evolutionResponse(false, p);
break;
case '1':
//Allow evolution
p.getParty()[pokemonIndex].evolutionResponse(true, p);
break;
}
}
break;
}
break;
case 's':
//Party swapping
p.swapPokemon(Integer.parseInt(message.substring(1, message.indexOf(','))),
Integer.parseInt(message.substring(message.indexOf(',') + 1)));
break;
case 'S':
//Shop interaction
if(p.isShopping()) {
int item = -1;
switch(message.charAt(1)) {
case 'b':
//Buy items. Sent as SbITEMID,QUANTITY
item = Integer.parseInt(message.substring(2, message.indexOf(',')));
//int q = Integer.parseInt(message.substring(message.indexOf(',') + 1));
p.buyItem(item, 1);
break;
case 's':
//Sell items. Sent as SsITEMID,QUANTITY
item = Integer.parseInt(message.substring(2, message.indexOf(',')));
//int q = Integer.parseInt(message.substring(message.indexOf(',') + 1));
p.sellItem(item, 1);
break;
case 'f':
//Finished shopping
p.setShopping(false);
break;
}
} else if(p.isSpriting()) {
//Sprite changing
int sprite = Integer.parseInt(message.substring(1));
/* Ensure the user buys a visible sprite */
if(sprite > 0 && !GameServer.getServiceManager().
getSpriteList().getUnbuyableSprites().contains(sprite)) {
if(p.getMoney() >= 500) {
p.setMoney(p.getMoney() - 500);
p.updateClientMoney();
p.setSprite(sprite);
p.setSpriting(false);
}
}
}
break;
case 'r':
String player = message.substring(2);
//A request was sent
switch(message.charAt(1)) {
case 'b':
//Battle Request rbUSERNAME
if(m_players.containsKey(player)) {
TcpProtocolHandler.writeMessage(m_players.get(player).getTcpSession(),
new RequestMessage(RequestType.BATTLE, p.getName()));
p.addRequest(player, RequestType.BATTLE);
}
break;
case 't':
//Trade Request rtUSERNAME
if(m_players.containsKey(player)) {
TcpProtocolHandler.writeMessage(m_players.get(player).getTcpSession(),
new RequestMessage(RequestType.TRADE, p.getName()));
p.addRequest(player, RequestType.TRADE);
}
break;
case 'a':
//Request accepted raUSERNAME
if(m_players.containsKey(player)) {
m_players.get(player).requestAccepted(p.getName());
}
break;
case 'c':
//Request declined rcUSERNAME
if(m_players.containsKey(player)) {
m_players.get(player).removeRequest(p.getName());
}
break;
}
break;
case 'B':
//Box interaction
if(p.isBoxing()) {
switch(message.charAt(1)) {
case 'r':
//Requesting info for box number - e.g. Br0
int boxNum = Integer.parseInt(String.valueOf(message.charAt(2)));
if(boxNum >= 0 && boxNum < 9)
p.sendBoxInfo(boxNum);
break;
case 'R':
//Releasing a pokemon from storage - sent as BRBOXNUM,BOXSLOT
details = message.substring(2).split(",");
p.releasePokemon(Integer.parseInt(details[0]), Integer.parseInt(details[1]));
break;
case 's':
//Swap pokemon between box and party - sent as BsBOXNUM,BOXSLOT,PARTYSLOT, e.g.Bs0,1,0
details = message.substring(2).split(",");
p.swapFromBox(Integer.parseInt(details[0]),
Integer.parseInt(details[1]), Integer.parseInt(details[2]));
break;
case 'f':
//Finished with box interfaction
p.setBoxing(false);
break;
}
}
break;
case 'M':
//Moderation
if(message.charAt(1) == 'c') {
p.getTcpSession().write("Cl" + m_players.size() + " players online");
} else if(p.getAdminLevel() > 0) {
try {
switch(message.charAt(1)) {
case 'a':
//Server announcement
for (String s : m_players.keySet()){
m_players.get(s).getTcpSession().write("q" + message.substring(2));
}
break;
case 'l':
//Send an alert
if(p.getAdminLevel()>1)
for (String s : m_players.keySet()){
m_players.get(s).getTcpSession().write("!" + message.substring(2));
}
break;
case 'b':
//Ban player
if(m_players.containsKey(message.substring(2))) {
PlayerChar o = m_players.get(message.substring(2));
MySqlManager m = new MySqlManager();
if(m.connect(GameServer.getDatabaseHost(),
GameServer.getDatabaseUsername(),
GameServer.getDatabasePassword())) {
m.selectDatabase(GameServer.getDatabaseName());
m.query("INSERT INTO pn_bans (ip) VALUE ('" +
o.getIpAddress()
+ "')");
m.close();
}
}
break;
case 'B':
//Unban ip
MySqlManager m = new MySqlManager();
if(m.connect(GameServer.getDatabaseHost(),
GameServer.getDatabaseUsername(),
GameServer.getDatabasePassword())) {
m.selectDatabase(GameServer.getDatabaseName());
m.query("DELETE FROM pn_bans WHERE ip='" +
message.substring(2)
+ "'");
m.close();
}
break;
case 'W':
//Warp to player
if(m_players.containsKey(message.substring(2))) {
PlayerChar o = m_players.get(message.substring(2));
p.setX(o.getX());
p.setY(o.getY());
p.setMap(o.getMap(), null);
}
break;
case 'm':
//Mute player
if(m_players.containsKey(message.substring(2))) {
PlayerChar o = m_players.get(message.substring(2));
o.setMuted(true);
o.getTcpSession().write("!You have been muted.");
}
break;
case 'u':
//Unmute player
if(m_players.containsKey(message.substring(2))) {
PlayerChar o = m_players.get(message.substring(2));
o.setMuted(false);
o.getTcpSession().write("!You have been unmuted.");
}
break;
case 'k':
if(m_players.containsKey(message.substring(2))) {
PlayerChar o = m_players.get(message.substring(2));
o.getTcpSession().write("!You have been kicked from the server.");
o.getTcpSession().close(true);
}
break;
case 'w':
//Change weather on current map
switch(message.charAt(2)) {