Finish encapsulating all userconnection fields

This commit is contained in:
md_5 2013-04-28 11:36:36 +10:00
parent ff32764f9a
commit 50f8bd2eb0
4 changed files with 63 additions and 31 deletions

View File

@ -12,6 +12,7 @@ import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.ServerConnectedEvent;
import net.md_5.bungee.api.event.ServerKickEvent;
import net.md_5.bungee.api.scoreboard.Objective;
import net.md_5.bungee.api.scoreboard.Scoreboard;
import net.md_5.bungee.api.scoreboard.Team;
import net.md_5.bungee.connection.CancelSendSignal;
import net.md_5.bungee.connection.DownstreamBridge;
@ -59,6 +60,12 @@ public class ServerConnector extends PacketHandler
channel.write( PacketCDClientStatus.CLIENT_LOGIN );
}
@Override
public void disconnected(ChannelWrapper channel) throws Exception
{
user.getPendingConnects().remove( target );
}
@Override
public void handle(Packet1Login login) throws Exception
{
@ -76,9 +83,9 @@ public class ServerConnector extends PacketHandler
{
ch.write( packetQueue.poll() );
}
if ( user.settings != null )
if ( user.getSettings() != null )
{
ch.write( user.settings );
ch.write( user.getSettings() );
}
synchronized ( user.getSwitchMutex() )
@ -86,8 +93,8 @@ public class ServerConnector extends PacketHandler
if ( user.getServer() == null )
{
// Once again, first connection
user.clientEntityId = login.entityId;
user.serverEntityId = login.entityId;
user.setClientEntityId( login.entityId );
user.setServerEntityId( login.entityId );
// Set tab list size
Packet1Login modLogin = new Packet1Login(
login.entityId,
@ -102,20 +109,21 @@ public class ServerConnector extends PacketHandler
{
bungee.getTabListHandler().onServerChange( user );
for ( Objective objective : user.serverSentScoreboard.getObjectives() )
Scoreboard serverScoreboard = user.getServerSentScoreboard();
for ( Objective objective : serverScoreboard.getObjectives() )
{
user.sendPacket( new PacketCEScoreboardObjective( objective.getName(), objective.getValue(), (byte) 1 ) );
}
for ( Team team : user.serverSentScoreboard.getTeams() )
for ( Team team : serverScoreboard.getTeams() )
{
user.sendPacket( PacketD1Team.destroy( team.getName() ) );
}
user.serverSentScoreboard.clear();
serverScoreboard.clear();
user.sendPacket( Packet9Respawn.DIM1_SWITCH );
user.sendPacket( Packet9Respawn.DIM2_SWITCH );
user.serverEntityId = login.entityId;
user.setServerEntityId( login.entityId );
user.sendPacket( new Packet9Respawn( login.dimension, login.difficulty, login.gameMode, (short) 256, login.levelType ) );
// Remove from old servers
@ -135,7 +143,7 @@ public class ServerConnector extends PacketHandler
// Add to new server
// TODO: Move this to the connected() method of DownstreamBridge
target.addPlayer( user );
user.pendingConnects.remove( target );
user.getPendingConnects().remove( target );
user.setServer( server );
ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user, server ) );

View File

@ -16,6 +16,7 @@ import java.util.Objects;
import java.util.logging.Level;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.md_5.bungee.api.ChatColor;
@ -41,21 +42,24 @@ public final class UserConnection implements ProxiedPlayer
{
/*========================================================================*/
@NonNull
private final ProxyServer bungee;
@NonNull
private final ChannelWrapper ch;
@Getter
@NonNull
private final String name;
@Getter
@NonNull
private final InitialHandler pendingConnection;
/*========================================================================*/
@Getter
@Setter(AccessLevel.PACKAGE)
@Setter
private ServerConnection server;
// reconnect stuff
public int clientEntityId;
public int serverEntityId;
@Getter
private String displayName;
private final Object switchMutex = new Object();
@Getter
private final Collection<ServerInfo> pendingConnects = new HashSet<>();
/*========================================================================*/
@Getter
@Setter
@ -71,10 +75,19 @@ public final class UserConnection implements ProxiedPlayer
private final Collection<String> permissions = new HashSet<>();
/*========================================================================*/
@Getter
private final Object switchMutex = new Object();
public PacketCCSettings settings;
public final Scoreboard serverSentScoreboard = new Scoreboard();
public final Collection<ServerInfo> pendingConnects = new HashSet<>();
private int clientEntityId;
@Getter
@Setter
private int serverEntityId;
@Getter
@Setter
private PacketCCSettings settings;
@Getter
private final Scoreboard serverSentScoreboard = new Scoreboard();
/*========================================================================*/
@Getter
private String displayName;
/*========================================================================*/
public void init()
{
@ -295,4 +308,10 @@ public final class UserConnection implements ProxiedPlayer
{
return name;
}
public void setClientEntityId(int clientEntityId)
{
Preconditions.checkState( this.clientEntityId == 0, "Client entityId already set!" );
this.clientEntityId = clientEntityId;
}
}

View File

@ -20,6 +20,7 @@ import net.md_5.bungee.api.event.ServerKickEvent;
import net.md_5.bungee.api.scoreboard.Objective;
import net.md_5.bungee.api.scoreboard.Position;
import net.md_5.bungee.api.scoreboard.Score;
import net.md_5.bungee.api.scoreboard.Scoreboard;
import net.md_5.bungee.api.scoreboard.Team;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.packet.Packet0KeepAlive;
@ -71,7 +72,7 @@ public class DownstreamBridge extends PacketHandler
@Override
public void handle(byte[] buf) throws Exception
{
EntityMap.rewrite( buf, con.serverEntityId, con.clientEntityId );
EntityMap.rewrite( buf, con.getServerEntityId(), con.getClientEntityId() );
con.sendPacket( buf );
}
@ -107,13 +108,14 @@ public class DownstreamBridge extends PacketHandler
@Override
public void handle(PacketCEScoreboardObjective objective) throws Exception
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
switch ( objective.action )
{
case 0:
con.serverSentScoreboard.addObjective( new Objective( objective.name, objective.text ) );
serverScoreboard.addObjective( new Objective( objective.name, objective.text ) );
break;
case 1:
con.serverSentScoreboard.removeObjective( objective.name );
serverScoreboard.removeObjective( objective.name );
break;
}
}
@ -121,15 +123,16 @@ public class DownstreamBridge extends PacketHandler
@Override
public void handle(PacketCFScoreboardScore score) throws Exception
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
switch ( score.action )
{
case 0:
Score s = new Score( score.itemName, score.scoreName, score.value );
con.serverSentScoreboard.removeScore( score.itemName );
con.serverSentScoreboard.addScore( s );
serverScoreboard.removeScore( score.itemName );
serverScoreboard.addScore( s );
break;
case 1:
con.serverSentScoreboard.removeScore( score.itemName );
serverScoreboard.removeScore( score.itemName );
break;
}
}
@ -137,17 +140,19 @@ public class DownstreamBridge extends PacketHandler
@Override
public void handle(PacketD0DisplayScoreboard displayScoreboard) throws Exception
{
con.serverSentScoreboard.setName( displayScoreboard.name );
con.serverSentScoreboard.setPosition( Position.values()[displayScoreboard.position] );
Scoreboard serverScoreboard = con.getServerSentScoreboard();
serverScoreboard.setName( displayScoreboard.name );
serverScoreboard.setPosition( Position.values()[displayScoreboard.position] );
}
@Override
public void handle(PacketD1Team team) throws Exception
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
// Remove team and move on
if ( team.mode == 1 )
{
con.serverSentScoreboard.removeTeam( team.name );
serverScoreboard.removeTeam( team.name );
return;
}
@ -156,10 +161,10 @@ public class DownstreamBridge extends PacketHandler
if ( team.mode == 0 )
{
t = new Team( team.name );
con.serverSentScoreboard.addTeam( t );
serverScoreboard.addTeam( t );
} else
{
t = con.serverSentScoreboard.getTeam( team.name );
t = serverScoreboard.getTeam( team.name );
}
if ( t != null )

View File

@ -64,7 +64,7 @@ public class UpstreamBridge extends PacketHandler
@Override
public void handle(byte[] buf) throws Exception
{
EntityMap.rewrite( buf, con.clientEntityId, con.serverEntityId );
EntityMap.rewrite( buf, con.getClientEntityId(), con.getServerEntityId() );
if ( con.getServer() != null )
{
con.getServer().getCh().write( buf );
@ -102,7 +102,7 @@ public class UpstreamBridge extends PacketHandler
@Override
public void handle(PacketCCSettings settings) throws Exception
{
con.settings = settings;
con.setSettings( settings );
}
@Override