This commit is contained in:
Regalis
2015-08-18 22:29:21 +03:00
parent 00c64f0b20
commit e19ac600ff
13 changed files with 161 additions and 58 deletions

View File

@@ -74,8 +74,8 @@ namespace Subsurface.Networking
// Create new instance of configs. Parameter is "application Id". It has to be same on client and server.
NetPeerConfiguration Config = new NetPeerConfiguration("subsurface");
Config.SimulatedLoss = 0.2f;
Config.SimulatedMinimumLatency = 0.5f;
//Config.SimulatedLoss = 0.2f;
//Config.SimulatedMinimumLatency = 0.5f;
// Create new client, with previously created configs
client = new NetClient(Config);
@@ -111,8 +111,11 @@ namespace Subsurface.Networking
//update.Elapsed += new System.Timers.ElapsedEventHandler(Update);
// Funtion that waits for connection approval info from server
if (reconnectBox==null)
{
reconnectBox = new GUIMessageBox("CONNECTING", "Connecting to " + serverIP, new string[0]);
}
reconnectBox = new GUIMessageBox("CONNECTING", "Connecting to " + serverIP, new string[0]);
CoroutineManager.StartCoroutine(WaitForStartingInfo());
// Start the timer
@@ -239,14 +242,19 @@ namespace Subsurface.Networking
if (!connected || updateTimer > DateTime.Now) return;
if (client.ConnectionStatus == NetConnectionStatus.Disconnected && reconnectBox==null)
if (client.ConnectionStatus == NetConnectionStatus.Disconnected)
{
reconnectBox = new GUIMessageBox("CONNECTION LOST", "You have been disconnected from the server. Reconnecting...", new string[0]);
connected = false;
ConnectToServer(serverIP);
if (reconnectBox==null)
{
reconnectBox = new GUIMessageBox("CONNECTION LOST", "You have been disconnected from the server. Reconnecting...", new string[0]);
connected = false;
ConnectToServer(serverIP);
}
return;
}
else if (reconnectBox!=null)
if (reconnectBox!=null)
{
reconnectBox.Close(null,null);
reconnectBox = null;

View File

@@ -30,7 +30,7 @@ namespace Subsurface.Networking
private Client myClient;
public GameServer(string name, int port, bool isPublic = false, string password="")
public GameServer(string name, int port, bool isPublic = false, string password="", bool attemptUPnP = false, int maxPlayers = 10)
{
var endRoundButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 290, 20, 150, 25), "End round", Alignment.TopLeft, GUI.style, inGameHUD);
endRoundButton.OnClicked = EndButtonHit;
@@ -41,26 +41,30 @@ namespace Subsurface.Networking
config = new NetPeerConfiguration("subsurface");
config.SimulatedLoss = 0.2f;
config.SimulatedMinimumLatency = 0.5f;
//config.SimulatedLoss = 0.2f;
//config.SimulatedMinimumLatency = 0.5f;
config.Port = port;
Port = port;
config.EnableUPnP = true;
if (attemptUPnP)
{
config.EnableUPnP = true;
}
config.MaximumConnections = 10;
config.MaximumConnections = maxPlayers;
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
try
{
server = new NetServer(config);
server.Start();
// attempt to forward port
server.UPnP.ForwardPort(port, "subsurface");
if (attemptUPnP)
{
server.UPnP.ForwardPort(port, "subsurface");
}
}
catch (Exception e)
@@ -126,7 +130,7 @@ namespace Subsurface.Networking
masterServerResponded = false;
var restRequestHandle = client.ExecuteAsync(request, response => MasterServerCallBack(response));
DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 10);
DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 15);
while (!masterServerResponded)
{
if (DateTime.Now > timeOut)
@@ -220,9 +224,9 @@ namespace Subsurface.Networking
break;
}
if (!isClient)
if (!isClient && (c.SimPosition==Vector2.Zero || c.SimPosition.Length() < 300.0f))
{
//c.LargeUpdateTimer = 0;
c.LargeUpdateTimer -= 2;
new NetworkEvent(c.ID, false);
}
}