Merge branch 'master' of ssh://184.154.0.242:7999/min/mineplex
This commit is contained in:
commit
b6904f2ae1
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import mineplex.serverdata.MinecraftServer;
|
||||
@ -25,9 +26,7 @@ public class LobbyBalancer implements Listener, Runnable
|
||||
private List<MinecraftServer> _sortedLobbies = new ArrayList<MinecraftServer>();
|
||||
private static Object _serverLock = new Object();
|
||||
|
||||
private int _bestServerIndex = 0;
|
||||
private int _playersSentToBestServer = 0;
|
||||
private int _maxPlayersToSendToBestServer = 1;
|
||||
private Random _random = new Random();
|
||||
|
||||
public LobbyBalancer(Plugin plugin)
|
||||
{
|
||||
@ -39,7 +38,7 @@ public class LobbyBalancer implements Listener, Runnable
|
||||
loadLobbyServers();
|
||||
|
||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 200L, 200L, TimeUnit.MILLISECONDS);
|
||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 150L, 150L, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -47,45 +46,15 @@ public class LobbyBalancer implements Listener, Runnable
|
||||
{
|
||||
if (!event.getTarget().getName().equalsIgnoreCase("Lobby"))
|
||||
return;
|
||||
|
||||
int bungeeBufferNumber = 20;
|
||||
|
||||
|
||||
synchronized (_serverLock)
|
||||
{
|
||||
if (_playersSentToBestServer >= _maxPlayersToSendToBestServer)
|
||||
{
|
||||
_playersSentToBestServer = 0;
|
||||
|
||||
while (_bestServerIndex < _sortedLobbies.size())
|
||||
{
|
||||
_maxPlayersToSendToBestServer = (_sortedLobbies.get(_bestServerIndex).getMaxPlayerCount() - _sortedLobbies.get(_bestServerIndex).getPlayerCount()) / bungeeBufferNumber;
|
||||
|
||||
if (_maxPlayersToSendToBestServer > 0)
|
||||
break;
|
||||
|
||||
_bestServerIndex++;
|
||||
}
|
||||
|
||||
if (_maxPlayersToSendToBestServer == 0)
|
||||
{
|
||||
_bestServerIndex = 0;
|
||||
_maxPlayersToSendToBestServer = 1;
|
||||
|
||||
// Since we had to enter our dangerzone, decrease buffer so we try to hit another server
|
||||
bungeeBufferNumber -= 2;
|
||||
|
||||
if (bungeeBufferNumber <= 0)
|
||||
bungeeBufferNumber = 0;
|
||||
}
|
||||
}
|
||||
Collections.sort(_sortedLobbies, new LobbySorter());
|
||||
|
||||
if (_bestServerIndex < _sortedLobbies.size())
|
||||
{
|
||||
event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(_bestServerIndex).getName()));
|
||||
System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(_bestServerIndex).getName() + "(" + _sortedLobbies.get(_bestServerIndex).getPublicAddress() + ")");
|
||||
}
|
||||
|
||||
_playersSentToBestServer++;
|
||||
int lobbyIndex = _random.nextInt(Math.min(10, _sortedLobbies.size()));
|
||||
event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(lobbyIndex).getName()));
|
||||
_sortedLobbies.get(lobbyIndex).incrementPlayerCount(1);
|
||||
System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(lobbyIndex).getName() + "(" + _sortedLobbies.get(lobbyIndex).getPublicAddress() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,12 +91,6 @@ public class LobbyBalancer implements Listener, Runnable
|
||||
|
||||
Collections.sort(_sortedLobbies, new LobbySorter());
|
||||
|
||||
_playersSentToBestServer = 0;
|
||||
_bestServerIndex = 0;
|
||||
|
||||
if (_sortedLobbies.size() > 0)
|
||||
_maxPlayersToSendToBestServer = (_sortedLobbies.get(_bestServerIndex).getMaxPlayerCount() - _sortedLobbies.get(_bestServerIndex).getPlayerCount());
|
||||
|
||||
long timeSpentInLock = System.currentTimeMillis() - startTime;
|
||||
|
||||
if (timeSpentInLock > 50)
|
||||
|
@ -104,7 +104,7 @@ public class ServerStatusManager extends MiniPlugin
|
||||
@EventHandler
|
||||
public void saveServerStatus(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
if (event.getType() != UpdateType.FASTER)
|
||||
return;
|
||||
|
||||
if (!_enabled)
|
||||
|
@ -39,6 +39,8 @@ public class ServerMonitor
|
||||
private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
||||
private static Logger _logger = Logger.getLogger("ServerMonitor");
|
||||
|
||||
private static int _totalPlayers = 0;
|
||||
|
||||
public static void main (String args[])
|
||||
{
|
||||
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
|
||||
@ -74,6 +76,7 @@ public class ServerMonitor
|
||||
|
||||
while (true)
|
||||
{
|
||||
_totalPlayers = 0;
|
||||
Collection<ServerGroup> serverGroups = _repository.getServerGroups(true);
|
||||
Collection<MinecraftServer> serverStatuses = _repository.getServerStatuses();
|
||||
|
||||
@ -88,7 +91,10 @@ public class ServerMonitor
|
||||
for (ServerGroup serverGroup : serverGroups)
|
||||
{
|
||||
serverGroupMap.put(serverGroup.getName(), serverGroup);
|
||||
_totalPlayers += serverGroup.getPlayerCount();
|
||||
}
|
||||
|
||||
System.out.println("Total Players : " + _totalPlayers);
|
||||
|
||||
for (MinecraftServer minecraftServer : serverStatuses)
|
||||
{
|
||||
@ -277,16 +283,26 @@ public class ServerMonitor
|
||||
serversToAdd = 0;
|
||||
}
|
||||
}
|
||||
else if (serverGroup.getName().equalsIgnoreCase("UltraHardcore"))
|
||||
{
|
||||
int maxUHC = Math.max(1, _totalPlayers / 6000);
|
||||
|
||||
if (serversToAdd > 0)
|
||||
serversToAdd = maxUHC - joinableServers;
|
||||
|
||||
if (joinableServers > maxUHC)
|
||||
serversToKill = maxUHC - joinableServers;
|
||||
}
|
||||
|
||||
while (serversToAdd > 0)
|
||||
{
|
||||
serverNum = serverGroup.generateUniqueId(serverNum + 1);
|
||||
Collections.sort(dedicatedServers, new DedicatedServerSorter());
|
||||
DedicatedServer bestServer = getBestDedicatedServer(dedicatedServers, serverGroup);
|
||||
|
||||
|
||||
if (bestServer == null)
|
||||
{
|
||||
System.out.println("No best dynamic server available for group " + serverGroup.getName());
|
||||
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!! NO DEDICATED SERVER AVAILABLE FOR GROUP " + serverGroup.getName() + " !!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -398,8 +414,7 @@ public class ServerMonitor
|
||||
if (serverData.getAvailableRam() > serverGroup.getRequiredRam()
|
||||
&& serverData.getAvailableCpu() > serverGroup.getRequiredCpu())
|
||||
{
|
||||
if (bestServer == null
|
||||
|| serverData.getServerCount(serverGroup) < bestServer.getServerCount(serverGroup))
|
||||
if (bestServer == null || serverData.getServerCount(serverGroup) < bestServer.getServerCount(serverGroup))
|
||||
{
|
||||
bestServer = serverData;
|
||||
}
|
||||
@ -427,9 +442,9 @@ public class ServerMonitor
|
||||
public void run(Boolean error)
|
||||
{
|
||||
if (error)
|
||||
log("[" + serverName + ":" + serverAddress + "] Errored " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")");
|
||||
log("[" + serverName + ":" + serverAddress + " Free Resources; CPU " + serverSpace.getAvailableCpu() + " RAM " + serverSpace.getAvailableRam() + "MB] Errored " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")");
|
||||
else
|
||||
log("[" + serverName + ":" + serverAddress + "] Added " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")");
|
||||
log("[" + serverName + ":" + serverAddress + " Free Resources; CPU " + serverSpace.getAvailableCpu() + " RAM " + serverSpace.getAvailableRam() + "MB] Added " + serverName + "(" + groupPrefix+ "-" + serverNum + (free ? "-FREE" : "") + ")");
|
||||
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user