Progress on tutorial, gap tweaking (water flows faster from room to room), UPnP error messages, input keys in array, underwater aiming tweaking, tons of misc stuff commit more often ffs
This commit is contained in:
@@ -10,9 +10,6 @@ namespace Subsurface.Networking
|
||||
{
|
||||
private NetClient client;
|
||||
|
||||
private Character myCharacter;
|
||||
private CharacterInfo characterInfo;
|
||||
|
||||
private GUIMessageBox reconnectBox;
|
||||
|
||||
private bool connected;
|
||||
@@ -23,17 +20,6 @@ namespace Subsurface.Networking
|
||||
|
||||
private string serverIP;
|
||||
|
||||
public Character Character
|
||||
{
|
||||
get { return myCharacter; }
|
||||
set { myCharacter = value; }
|
||||
}
|
||||
|
||||
public CharacterInfo CharacterInfo
|
||||
{
|
||||
get { return characterInfo; }
|
||||
}
|
||||
|
||||
public int ID
|
||||
{
|
||||
get { return myID; }
|
||||
@@ -56,7 +42,7 @@ namespace Subsurface.Networking
|
||||
if (address.Length==1)
|
||||
{
|
||||
serverIP = hostIP;
|
||||
Port = DefaultPort;
|
||||
Port = NetConfig.DefaultPort;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -65,7 +51,7 @@ namespace Subsurface.Networking
|
||||
if (!int.TryParse(address[1], out Port))
|
||||
{
|
||||
DebugConsole.ThrowError("Invalid port: "+address[1]+"!");
|
||||
Port = DefaultPort;
|
||||
Port = NetConfig.DefaultPort;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,10 +137,10 @@ namespace Subsurface.Networking
|
||||
|
||||
DateTime timeOut = DateTime.Now + new TimeSpan(0,0,15);
|
||||
|
||||
// Loop untill we are approved
|
||||
// Loop until we are approved
|
||||
while (!CanStart)
|
||||
{
|
||||
yield return Status.Running;
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
if (DateTime.Now > timeOut) break;
|
||||
|
||||
@@ -171,7 +157,7 @@ namespace Subsurface.Networking
|
||||
if (packetType == (byte)PacketTypes.LoggedIn)
|
||||
{
|
||||
myID = inc.ReadInt32();
|
||||
if (inc.ReadBoolean())
|
||||
if (inc.ReadBoolean() && Screen.Selected != Game1.GameScreen)
|
||||
{
|
||||
new GUIMessageBox("Please wait", "A round is already running. You will have to wait for a new round to start.");
|
||||
}
|
||||
@@ -234,11 +220,11 @@ namespace Subsurface.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Screen.Selected == Game1.MainMenuScreen) Game1.NetLobbyScreen.Select();
|
||||
if (Screen.Selected != Game1.GameScreen) Game1.NetLobbyScreen.Select();
|
||||
connected = true;
|
||||
}
|
||||
|
||||
yield return Status.Success;
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
@@ -274,17 +260,7 @@ namespace Subsurface.Networking
|
||||
}
|
||||
else if (gameStarted)
|
||||
{
|
||||
Vector2 charMovement = myCharacter.AnimController.TargetMovement;
|
||||
if ((charMovement==Vector2.Zero || charMovement.Length()<0.001f) &&
|
||||
!myCharacter.ActionKeyDown.State && !myCharacter.SecondaryKeyDown.State)
|
||||
{
|
||||
new NetworkEvent(NetworkEventType.NotMoving, myCharacter.ID, true);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
new NetworkEvent(myCharacter.ID, true);
|
||||
}
|
||||
new NetworkEvent(myCharacter.ID, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,7 +311,7 @@ namespace Subsurface.Networking
|
||||
if (this.Character != null) Character.Remove();
|
||||
|
||||
int seed = inc.ReadInt32();
|
||||
Rand.SetSyncedSeed(seed);
|
||||
|
||||
|
||||
string levelSeed = inc.ReadString();
|
||||
|
||||
@@ -347,7 +323,7 @@ namespace Subsurface.Networking
|
||||
double durationMinutes = inc.ReadDouble();
|
||||
|
||||
TimeSpan duration = new TimeSpan(0,(int)durationMinutes,0);
|
||||
|
||||
Rand.SetSyncedSeed(seed);
|
||||
//int gameModeIndex = inc.ReadInt32();
|
||||
Game1.GameSession = new GameSession(Submarine.Loaded, "", Game1.NetLobbyScreen.SelectedMode);
|
||||
Game1.GameSession.StartShift(duration, levelSeed);
|
||||
@@ -456,7 +432,7 @@ namespace Subsurface.Networking
|
||||
//Game1.GameScreen.Cam.MoveCamera((float)deltaTime);
|
||||
|
||||
messageBox.Text = endMessage + "\nReturning to lobby in " + (int)secondsLeft + " s";
|
||||
yield return Status.Running;
|
||||
yield return CoroutineStatus.Running;
|
||||
} while (secondsLeft > 0.0f);
|
||||
|
||||
messageBox.Text = endMessage;
|
||||
@@ -469,7 +445,7 @@ namespace Subsurface.Networking
|
||||
|
||||
myCharacter = null;
|
||||
|
||||
yield return Status.Success;
|
||||
yield return CoroutineStatus.Success;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,12 @@ namespace Subsurface.Networking
|
||||
|
||||
public List<Client> connectedClients = new List<Client>();
|
||||
|
||||
bool started;
|
||||
|
||||
private NetServer server;
|
||||
private NetPeerConfiguration config;
|
||||
|
||||
private TimeSpan SparseUpdateInterval = new TimeSpan(0, 0, 0, 1);
|
||||
private TimeSpan SparseUpdateInterval = new TimeSpan(0, 0, 0, 3);
|
||||
private DateTime sparseUpdateTimer;
|
||||
|
||||
private TimeSpan refreshMasterInterval = new TimeSpan(0, 0, 40);
|
||||
@@ -36,7 +38,6 @@ namespace Subsurface.Networking
|
||||
endRoundButton.OnClicked = EndButtonHit;
|
||||
|
||||
this.name = name;
|
||||
|
||||
this.password = password;
|
||||
|
||||
config = new NetPeerConfiguration("subsurface");
|
||||
@@ -45,7 +46,6 @@ namespace Subsurface.Networking
|
||||
config.SimulatedLoss = 0.2f;
|
||||
config.SimulatedMinimumLatency = 0.3f;
|
||||
#endif
|
||||
|
||||
config.Port = port;
|
||||
Port = port;
|
||||
|
||||
@@ -56,25 +56,52 @@ namespace Subsurface.Networking
|
||||
|
||||
config.MaximumConnections = maxPlayers;
|
||||
|
||||
config.DisableMessageType(NetIncomingMessageType.DebugMessage | NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt
|
||||
| NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error);
|
||||
config.DisableMessageType(NetIncomingMessageType.DebugMessage |
|
||||
NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt |
|
||||
NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error);
|
||||
|
||||
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
|
||||
|
||||
|
||||
CoroutineManager.StartCoroutine(StartServer(isPublic));
|
||||
}
|
||||
|
||||
private IEnumerable<object> StartServer(bool isPublic)
|
||||
{
|
||||
try
|
||||
{
|
||||
server = new NetServer(config);
|
||||
server = new NetServer(config);
|
||||
server.Start();
|
||||
|
||||
if (attemptUPnP)
|
||||
{
|
||||
server.UPnP.ForwardPort(port, "subsurface");
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Couldn't start the server", e);
|
||||
DebugConsole.ThrowError("Couldn't start the server", e);
|
||||
}
|
||||
|
||||
|
||||
if (config.EnableUPnP)
|
||||
{
|
||||
server.UPnP.ForwardPort(config.Port, "subsurface");
|
||||
|
||||
GUIMessageBox upnpBox = new GUIMessageBox("Please wait...", "Attempting UPnP port forwarding", new string[] {"Cancel"} );
|
||||
upnpBox.Buttons[0].OnClicked = upnpBox.Close;
|
||||
|
||||
DateTime upnpTimeout = DateTime.Now + new TimeSpan(0,0,5);
|
||||
while (server.UPnP.Status == UPnPStatus.Discovering
|
||||
&& GUIMessageBox.VisibleBox == upnpBox)// && upnpTimeout>DateTime.Now)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
upnpBox.Close(null,null);
|
||||
|
||||
if (server.UPnP.Status == UPnPStatus.NotAvailable)
|
||||
{
|
||||
new GUIMessageBox("Error", "UPnP not available");
|
||||
}
|
||||
else if (server.UPnP.Status == UPnPStatus.Discovering)
|
||||
{
|
||||
new GUIMessageBox("Error", "UPnP discovery timed out");
|
||||
}
|
||||
}
|
||||
|
||||
if (isPublic)
|
||||
@@ -86,11 +113,15 @@ namespace Subsurface.Networking
|
||||
updateInterval = new TimeSpan(0, 0, 0, 0, 30);
|
||||
|
||||
DebugConsole.NewMessage("Server started", Color.Green);
|
||||
|
||||
Game1.NetLobbyScreen.Select();
|
||||
started = true;
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
private void RegisterToMasterServer()
|
||||
{
|
||||
var client = new RestClient(NetworkMember.MasterServerUrl);
|
||||
var client = new RestClient(NetConfig.MasterServerUrl);
|
||||
|
||||
var request = new RestRequest("masterserver.php", Method.GET);
|
||||
request.AddParameter("action", "addserver");
|
||||
@@ -120,7 +151,7 @@ namespace Subsurface.Networking
|
||||
|
||||
private IEnumerable<object> RefreshMaster()
|
||||
{
|
||||
var client = new RestClient(NetworkMember.MasterServerUrl);
|
||||
var client = new RestClient(NetConfig.MasterServerUrl);
|
||||
|
||||
var request = new RestRequest("masterserver.php", Method.GET);
|
||||
request.AddParameter("action", "refreshserver");
|
||||
@@ -146,10 +177,10 @@ namespace Subsurface.Networking
|
||||
}
|
||||
System.Diagnostics.Debug.WriteLine("took "+sw.ElapsedMilliseconds+" ms");
|
||||
|
||||
yield return Status.Running;
|
||||
yield return CoroutineStatus.Running;
|
||||
}
|
||||
|
||||
yield return Status.Success;
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
private void MasterServerCallBack(IRestResponse response)
|
||||
@@ -173,6 +204,8 @@ namespace Subsurface.Networking
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
if (!started) return;
|
||||
|
||||
base.Update(deltaTime);
|
||||
|
||||
if (gameStarted) inGameHUD.Update((float)Physics.step);
|
||||
@@ -298,7 +331,7 @@ namespace Subsurface.Networking
|
||||
}
|
||||
|
||||
int id = 1;
|
||||
while (connectedClients.Find(c=>c.ID==id)!=null)
|
||||
while (connectedClients.Find(c => c.ID==id)!=null)
|
||||
{
|
||||
id++;
|
||||
}
|
||||
@@ -458,26 +491,17 @@ namespace Subsurface.Networking
|
||||
|
||||
List<NetConnection> recipients = new List<NetConnection>();
|
||||
|
||||
if (!networkEvent.IsImportant)
|
||||
{
|
||||
Entity e = Entity.FindEntityByID(networkEvent.ID);
|
||||
foreach (Client c in connectedClients)
|
||||
{
|
||||
if (c.character==null) continue;
|
||||
if (Vector2.Distance(e.SimPosition, c.character.SimPosition) > 2000.0f) continue;
|
||||
|
||||
recipients.Add(c.Connection);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Client c in connectedClients)
|
||||
{
|
||||
if (c.character == null) continue;
|
||||
//if (networkEvent.Type == NetworkEventType.UpdateEntity &&
|
||||
// Vector2.Distance(e.SimPosition, c.character.SimPosition) > NetConfig.UpdateEntityDistance) continue;
|
||||
|
||||
recipients.Add(c.Connection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (recipients.Count == 0) return;
|
||||
|
||||
@@ -510,13 +534,14 @@ namespace Subsurface.Networking
|
||||
return false;
|
||||
}
|
||||
|
||||
int seed = DateTime.Now.Millisecond;
|
||||
Rand.SetSyncedSeed(seed);
|
||||
|
||||
|
||||
AssignJobs();
|
||||
|
||||
//selectedMap.Load();
|
||||
|
||||
int seed = DateTime.Now.Millisecond;
|
||||
Rand.SetSyncedSeed(seed);
|
||||
Game1.GameSession = new GameSession(selectedMap, "", Game1.NetLobbyScreen.SelectedMode);
|
||||
Game1.GameSession.StartShift(Game1.NetLobbyScreen.GameDuration, Game1.NetLobbyScreen.LevelSeed);
|
||||
//EventManager.SelectEvent(Game1.netLobbyScreen.SelectedEvent);
|
||||
@@ -570,7 +595,7 @@ namespace Subsurface.Networking
|
||||
msg.Write(Game1.NetLobbyScreen.LevelSeed);
|
||||
|
||||
msg.Write(Game1.NetLobbyScreen.SelectedMap.Name);
|
||||
msg.Write(Game1.NetLobbyScreen.SelectedMap.Hash.Hash);
|
||||
msg.Write(Game1.NetLobbyScreen.SelectedMap.MD5Hash.Hash);
|
||||
|
||||
msg.Write(Game1.NetLobbyScreen.GameDuration.TotalMinutes);
|
||||
|
||||
@@ -651,7 +676,7 @@ namespace Subsurface.Networking
|
||||
Game1.GameScreen.Cam.TargetPos = offset * 0.8f;
|
||||
//Game1.GameScreen.Cam.MoveCamera((float)deltaTime);
|
||||
|
||||
yield return Status.Running;
|
||||
yield return CoroutineStatus.Running;
|
||||
} while (secondsLeft > 0.0f);
|
||||
|
||||
Submarine.Unload();
|
||||
@@ -660,7 +685,7 @@ namespace Subsurface.Networking
|
||||
|
||||
DebugConsole.ThrowError(endMessage);
|
||||
|
||||
yield return Status.Success;
|
||||
yield return CoroutineStatus.Success;
|
||||
|
||||
}
|
||||
|
||||
@@ -674,7 +699,7 @@ namespace Subsurface.Networking
|
||||
{
|
||||
if (client == null) return;
|
||||
|
||||
if (gameStarted && client.character != null) client.character.Kill(true);
|
||||
if (gameStarted && client.character != null) client.character.ClearInputs();
|
||||
|
||||
if (msg == "") msg = client.name + " has left the server";
|
||||
if (targetmsg == "") targetmsg = "You have left the server";
|
||||
@@ -742,7 +767,7 @@ namespace Subsurface.Networking
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, new Rectangle(x,y,width,height), Color.Black*0.7f, true);
|
||||
spriteBatch.DrawString(GUI.Font, "Network statistics:", new Vector2(x+10, y+10), Color.White);
|
||||
|
||||
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Connections: "+server.ConnectionsCount, new Vector2(x + 10, y + 30), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Received bytes: " + server.Statistics.ReceivedBytes, new Vector2(x + 10, y + 45), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Received packets: " + server.Statistics.ReceivedPackets, new Vector2(x + 10, y + 60), Color.White);
|
||||
|
||||
24
Subsurface/Source/Networking/NetConfig.cs
Normal file
24
Subsurface/Source/Networking/NetConfig.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Subsurface.Networking
|
||||
{
|
||||
static class NetConfig
|
||||
{
|
||||
public const int DefaultPort = 14242;
|
||||
|
||||
//UpdateEntity networkevents aren't sent to clients if they're further than this from the entity
|
||||
public const float UpdateEntityDistance = 2500.0f;
|
||||
|
||||
public static string MasterServerUrl = Game1.Config.MasterServerUrl;
|
||||
|
||||
//if a ragdoll is further than this from the correct position, teleport it there
|
||||
//(in sim units)
|
||||
public const float ResetRagdollDistance = 2.0f;
|
||||
|
||||
//if the ragdoll is closer than this, don't try to correct its position
|
||||
public const float AllowedRagdollDistance = 0.1f;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,7 @@ namespace Subsurface.Networking
|
||||
DropItem = 3,
|
||||
InventoryUpdate = 4,
|
||||
PickItem = 5,
|
||||
UpdateProperty = 6,
|
||||
NotMoving = 7
|
||||
UpdateProperty = 6
|
||||
}
|
||||
|
||||
class NetworkEvent
|
||||
@@ -46,6 +45,11 @@ namespace Subsurface.Networking
|
||||
get { return isImportant[(int)eventType]; }
|
||||
}
|
||||
|
||||
public NetworkEventType Type
|
||||
{
|
||||
get { return eventType; }
|
||||
}
|
||||
|
||||
public NetworkEvent(int id, bool isClient)
|
||||
: this(NetworkEventType.UpdateEntity, id, isClient)
|
||||
{
|
||||
@@ -64,9 +68,9 @@ namespace Subsurface.Networking
|
||||
|
||||
eventType = type;
|
||||
|
||||
foreach (NetworkEvent e in events)
|
||||
if (!isImportant[(int)type])
|
||||
{
|
||||
if (!isImportant[(int)type] && e.id == id && e.eventType == type) return;
|
||||
if (events.Find(e => e.id == id && e.eventType == type) != null) return;
|
||||
}
|
||||
|
||||
this.id = id;
|
||||
|
||||
@@ -31,9 +31,6 @@ namespace Subsurface.Networking
|
||||
|
||||
class NetworkMember
|
||||
{
|
||||
public const int DefaultPort = 14242;
|
||||
|
||||
public static string MasterServerUrl = Game1.Config.MasterServerUrl;
|
||||
|
||||
protected static Color[] messageColor = { Color.White, Color.Red, Color.LightBlue, Color.LightGreen };
|
||||
|
||||
@@ -54,6 +51,21 @@ namespace Subsurface.Networking
|
||||
|
||||
protected bool gameStarted;
|
||||
|
||||
protected Character myCharacter;
|
||||
protected CharacterInfo characterInfo;
|
||||
|
||||
public Character Character
|
||||
{
|
||||
get { return myCharacter; }
|
||||
set { myCharacter = value; }
|
||||
}
|
||||
|
||||
public CharacterInfo CharacterInfo
|
||||
{
|
||||
get { return characterInfo; }
|
||||
set { characterInfo = value; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return name; }
|
||||
|
||||
Reference in New Issue
Block a user