01-14-2018, 12:18 PM
hello pls friend fix
[SRC="java"]package ru.pb.game.network.client.packets.client;
import java.util.ArrayList;
import java.util.LinkedList;
import ru.pb.game.controller.ChannelController;
import ru.pb.game.network.client.packets.ClientPacket;
import ru.pb.game.network.client.packets.server.SM_FRIEND_AD;
import ru.pb.game.network.client.packets.server.SM_FRIEND_UPDATE;
import ru.pb.game.network.client.packets.server.SM_SEND_NOTICE;
import ru.pb.global.dao.impl.FriendDaoImpl;
import ru.pb.global.models.Channel;
import ru.pb.global.models.FriendInfo;
import ru.pb.global.models.Player;
import ru.pb.global.models.Room;
import ru.pb.global.service.FriendDaoService;
public class CM_FRIEND_ADD extends ClientPacket {
private String friend_;
public CM_FRIEND_ADD(int opcode) {
super(opcode);
}
@Override
protected void readImpl() {
friend_ = readS(33);
}
@Override
protected void runImpl() {
Player player = getConnection().getPlayer();
Player friend = getPlayer(friend_.trim());
if(friend == null){ //Il giocatore offline
}else{ //Il giocatore online
FriendDaoImpl.getInstance().addFriend(friend.getId(), player.getId(), 1);
FriendDaoImpl.getInstance().addFriend(player.getId(), friend.getId(), 2);
player.friends.add(createNewFriend(friend, 1));
friend.friends.add(createNewFriend(player, 2));
int v1 = player.friends.indexOf(createNewFriend(friend, 1));
int v2 = friend.friends.indexOf(createNewFriend(player, 2));
sendPacket(new SM_FRIEND_UPDATE((byte)1, 32, player, v2));
sendPacket(new SM_FRIEND_UPDATE((byte)1, 16, friend, v1));
}
}
private FriendInfo createNewFriend(Player newFriend, int type){
FriendInfo f = new FriendInfo();
f.setStatus(type);
f.id = newFriend.getId();
f.setRank((int)newFriend.getRank());
f.setName(newFriend.getName());
return f;
}
private Player getPlayer(String name) {
for(Channel ch : ChannelController.getInstance().getChannels()) {
for(Player member : ch.getPlayers().values()) {
if(member.getName() == name) {
return member;
}
}
for(Room room : ch.getRooms().values()) {
for(Player member : room.getPlayers().values()) {
if(member.getName().equals(name)) {
return member;
}
}
}
}
return null;
}
}
[/SRC]
[SRC="java"]package ru.pb.game.network.client.packets.client;
import ru.pb.game.network.client.packets.ClientPacket;
import ru.pb.game.network.client.packets.server.SM_FRIEND_FIND;
public class CM_FRIEND_FIND extends ClientPacket
{
public CM_FRIEND_FIND(int opcode)
{
super(opcode);
}
protected void readImpl()
{
}
protected void runImpl()
{
sendPacket(new SM_FRIEND_FIND());
}
}
[/SRC]
pls fix
[SRC="java"]package ru.pb.game.network.client.packets.client;
import java.util.ArrayList;
import java.util.LinkedList;
import ru.pb.game.controller.ChannelController;
import ru.pb.game.network.client.packets.ClientPacket;
import ru.pb.game.network.client.packets.server.SM_FRIEND_AD;
import ru.pb.game.network.client.packets.server.SM_FRIEND_UPDATE;
import ru.pb.game.network.client.packets.server.SM_SEND_NOTICE;
import ru.pb.global.dao.impl.FriendDaoImpl;
import ru.pb.global.models.Channel;
import ru.pb.global.models.FriendInfo;
import ru.pb.global.models.Player;
import ru.pb.global.models.Room;
import ru.pb.global.service.FriendDaoService;
public class CM_FRIEND_ADD extends ClientPacket {
private String friend_;
public CM_FRIEND_ADD(int opcode) {
super(opcode);
}
@Override
protected void readImpl() {
friend_ = readS(33);
}
@Override
protected void runImpl() {
Player player = getConnection().getPlayer();
Player friend = getPlayer(friend_.trim());
if(friend == null){ //Il giocatore offline
}else{ //Il giocatore online
FriendDaoImpl.getInstance().addFriend(friend.getId(), player.getId(), 1);
FriendDaoImpl.getInstance().addFriend(player.getId(), friend.getId(), 2);
player.friends.add(createNewFriend(friend, 1));
friend.friends.add(createNewFriend(player, 2));
int v1 = player.friends.indexOf(createNewFriend(friend, 1));
int v2 = friend.friends.indexOf(createNewFriend(player, 2));
sendPacket(new SM_FRIEND_UPDATE((byte)1, 32, player, v2));
sendPacket(new SM_FRIEND_UPDATE((byte)1, 16, friend, v1));
}
}
private FriendInfo createNewFriend(Player newFriend, int type){
FriendInfo f = new FriendInfo();
f.setStatus(type);
f.id = newFriend.getId();
f.setRank((int)newFriend.getRank());
f.setName(newFriend.getName());
return f;
}
private Player getPlayer(String name) {
for(Channel ch : ChannelController.getInstance().getChannels()) {
for(Player member : ch.getPlayers().values()) {
if(member.getName() == name) {
return member;
}
}
for(Room room : ch.getRooms().values()) {
for(Player member : room.getPlayers().values()) {
if(member.getName().equals(name)) {
return member;
}
}
}
}
return null;
}
}
[/SRC]
[SRC="java"]package ru.pb.game.network.client.packets.client;
import ru.pb.game.network.client.packets.ClientPacket;
import ru.pb.game.network.client.packets.server.SM_FRIEND_FIND;
public class CM_FRIEND_FIND extends ClientPacket
{
public CM_FRIEND_FIND(int opcode)
{
super(opcode);
}
protected void readImpl()
{
}
protected void runImpl()
{
sendPacket(new SM_FRIEND_FIND());
}
}
[/SRC]
pls fix