Untitled
unknown
plain_text
3 years ago
4.2 kB
9
Indexable
package ballistickemu.Lobby;
import ballistickemu.Tools.StickPacketMaker;
import ballistickemu.Types.StickClient;
import ballistickemu.Types.StickClientRegistry;
import ballistickemu.Types.StickPacket;
import ballistickemu.Types.StickRoomRegistry;
import ballistickemu.Types.StickShop;
import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
public class LobbyServer
{
private StickClientRegistry ClientRegistry;
private StickRoomRegistry RoomRegistry;
private StickShop StickShop;
public LobbyServer()
{
this.ClientRegistry = new StickClientRegistry(Boolean.valueOf(true));
this.RoomRegistry = new StickRoomRegistry();
this.StickShop = new StickShop();
}
public StickClientRegistry getClientRegistry()
{
return this.ClientRegistry;
}
public StickRoomRegistry getRoomRegistry()
{
return this.RoomRegistry;
}
public StickShop getShop()
{
return this.StickShop;
}
public void BroadcastPacket(StickPacket packet, Boolean ExcludeChar, String client_UID)
{
this.ClientRegistry.ClientsLock.readLock().lock();
ArrayList<StickClient> ToDC = new ArrayList();
try
{
for (StickClient c : this.ClientRegistry.getAllClients())
{
try
{
if ((c.getLobbyStatus().booleanValue()) && ((!ExcludeChar.booleanValue()) || (!c.getUID().equalsIgnoreCase(client_UID)))) {
c.write(packet);
}
}
catch (Exception e) {
if (c.getIoSession() != null)
e.printStackTrace();
ToDC.add(c);
}
}
} finally {
this.ClientRegistry.ClientsLock.readLock().unlock();
}
for (StickClient c : ToDC)
{
this.ClientRegistry.deregisterClient(c);
}
ToDC.removeAll(ToDC);
}
public void BroadcastPacket(StickPacket packet)
{
this.ClientRegistry.ClientsLock.readLock().lock();
ArrayList<StickClient> ToDC = new ArrayList();
try
{
for (StickClient c : this.ClientRegistry.getAllClients())
{
try
{
if (c.getLobbyStatus().booleanValue()) {
c.write(packet);
}
}
catch (Exception e) {
if (c.getIoSession() != null)
e.printStackTrace();
ToDC.add(c);
}
}
} finally {
this.ClientRegistry.ClientsLock.readLock().unlock();
}
for (StickClient c : ToDC)
{
this.ClientRegistry.deregisterClient(c);
}
ToDC.removeAll(ToDC);
}
public void BroadcastAnnouncement(String Announcement)
{
this.ClientRegistry.ClientsLock.readLock().lock();
ArrayList<StickClient> ToDC = new ArrayList();
try
{
for (StickClient c : this.ClientRegistry.getAllClients())
{
try
{
c.writeCallbackMessage("Announcement: " + Announcement);
}
catch (Exception e)
{
ToDC.add(c);
}
}
} finally {
this.ClientRegistry.ClientsLock.readLock().unlock();
}
for (StickClient c : ToDC)
{
this.ClientRegistry.deregisterClient(c);
}
ToDC.removeAll(ToDC);
}
public void BroadcastAnnouncement2(String Announcement)
{
this.ClientRegistry.ClientsLock.readLock().lock();
ArrayList<StickClient> ToDC = new ArrayList();
try
{
for (StickClient c : this.ClientRegistry.getAllClients())
{
try
{
c.write(StickPacketMaker.getAnnouncePacket(Announcement));
}
catch (Exception e)
{
ToDC.add(c);
}
}
} finally {
this.ClientRegistry.ClientsLock.readLock().unlock();
}
for (StickClient c : ToDC)
{
this.ClientRegistry.deregisterClient(c);
}
ToDC.removeAll(ToDC);
}
public void sendToUID(String ToUID, StickPacket packet)
{
if (this.ClientRegistry.UIDExists(ToUID).booleanValue()) {
this.ClientRegistry.getClientfromUID(ToUID).write(packet);
}
}
}Editor is loading...