- fixed clients failing to load submarines if they're not in the root Submarine folder
- some refactoring - temporarily disabled kicking by voting
This commit is contained in:
@@ -1631,7 +1631,7 @@ namespace Barotrauma
|
|||||||
case NetworkEventType.KillCharacter:
|
case NetworkEventType.KillCharacter:
|
||||||
if (GameMain.Server != null)
|
if (GameMain.Server != null)
|
||||||
{
|
{
|
||||||
Client sender =GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection);
|
Client sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection);
|
||||||
if (sender == null || sender.Character != this)
|
if (sender == null || sender.Character != this)
|
||||||
throw new Exception("Received a KillCharacter message from someone else than the client controlling the Character!");
|
throw new Exception("Received a KillCharacter message from someone else than the client controlling the Character!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,12 @@ namespace Barotrauma.Networking
|
|||||||
get { return myID; }
|
get { return myID; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Client> OtherClients
|
public override List<Client> ConnectedClients
|
||||||
{
|
{
|
||||||
get { return otherClients; }
|
get
|
||||||
|
{
|
||||||
|
return otherClients;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ActiveFileTransferName
|
public string ActiveFileTransferName
|
||||||
@@ -273,7 +276,14 @@ namespace Barotrauma.Networking
|
|||||||
string subName = inc.ReadString();
|
string subName = inc.ReadString();
|
||||||
string subHash = inc.ReadString();
|
string subHash = inc.ReadString();
|
||||||
|
|
||||||
submarines.Add(new Submarine(Path.Combine(Submarine.SavePath, subName), subHash, false));
|
string mySubPath = Path.Combine(Submarine.SavePath, subName);
|
||||||
|
var matchingSub = Submarine.SavedSubmarines.Find(s => s.Name == subName);
|
||||||
|
if (matchingSub != null)
|
||||||
|
{
|
||||||
|
mySubPath = matchingSub.FilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
submarines.Add(new Submarine(mySubPath, subHash, false));
|
||||||
}
|
}
|
||||||
GameMain.NetLobbyScreen.UpdateSubList(submarines);
|
GameMain.NetLobbyScreen.UpdateSubList(submarines);
|
||||||
|
|
||||||
@@ -679,7 +689,7 @@ namespace Barotrauma.Networking
|
|||||||
if (id != myID)
|
if (id != myID)
|
||||||
{
|
{
|
||||||
var characterOwner = otherClients.Find(c => c.ID == id);
|
var characterOwner = otherClients.Find(c => c.ID == id);
|
||||||
characterOwner.Character = newCharacter;
|
if (characterOwner != null) characterOwner.Character = newCharacter;
|
||||||
}
|
}
|
||||||
|
|
||||||
crew.Add(newCharacter);
|
crew.Add(newCharacter);
|
||||||
@@ -824,12 +834,24 @@ namespace Barotrauma.Networking
|
|||||||
Character character = obj as Character;
|
Character character = obj as Character;
|
||||||
if (character == null) return false;
|
if (character == null) return false;
|
||||||
|
|
||||||
if (character != myCharacter)
|
//if (character != myCharacter)
|
||||||
{
|
//{
|
||||||
var kickButton = new GUIButton(new Rectangle(0, 0, 130, 20), "Vote to Kick", Alignment.BottomLeft, GUI.Style, characterFrame);
|
// var kickButton = new GUIButton(new Rectangle(0, 0, 120, 20), "Vote to Kick", Alignment.BottomLeft, GUI.Style, characterFrame);
|
||||||
kickButton.UserData = character;
|
// kickButton.UserData = character;
|
||||||
kickButton.OnClicked += VoteForKick;
|
// kickButton.OnClicked += VoteForKick;
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
//if (GameMain.NetworkMember.ConnectedClients != null)
|
||||||
|
//{
|
||||||
|
// var client = GameMain.NetworkMember.ConnectedClients.Find(c => c.Character == character);
|
||||||
|
// if (client != null && client.KickVoteCount>0)
|
||||||
|
// {
|
||||||
|
// new GUITextBlock(
|
||||||
|
// new Rectangle(0, 0, 100, 20),
|
||||||
|
// client.KickVoteCount + "/" + GameMain.NetworkMember.ConnectedClients,
|
||||||
|
// GUI.Style, Alignment.BottomRight, Alignment.TopLeft, characterFrame);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
partial class GameServer : NetworkMember
|
partial class GameServer : NetworkMember
|
||||||
{
|
{
|
||||||
public List<Client> ConnectedClients = new List<Client>();
|
private List<Client> connectedClients = new List<Client>();
|
||||||
|
|
||||||
//for keeping track of disconnected clients in case the reconnect shortly after
|
//for keeping track of disconnected clients in case the reconnect shortly after
|
||||||
private List<Client> disconnectedClients = new List<Client>();
|
private List<Client> disconnectedClients = new List<Client>();
|
||||||
@@ -41,6 +41,14 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public TraitorManager TraitorManager;
|
public TraitorManager TraitorManager;
|
||||||
|
|
||||||
|
public override List<Client> ConnectedClients
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return connectedClients;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public GameServer(string name, int port, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10)
|
public GameServer(string name, int port, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10)
|
||||||
{
|
{
|
||||||
name = name.Replace(":", "");
|
name = name.Replace(":", "");
|
||||||
@@ -173,7 +181,7 @@ namespace Barotrauma.Networking
|
|||||||
request.AddParameter("action", "addserver");
|
request.AddParameter("action", "addserver");
|
||||||
request.AddParameter("servername", name);
|
request.AddParameter("servername", name);
|
||||||
request.AddParameter("serverport", Port);
|
request.AddParameter("serverport", Port);
|
||||||
request.AddParameter("currplayers", ConnectedClients.Count);
|
request.AddParameter("currplayers", connectedClients.Count);
|
||||||
request.AddParameter("maxplayers", config.MaximumConnections);
|
request.AddParameter("maxplayers", config.MaximumConnections);
|
||||||
request.AddParameter("password", string.IsNullOrWhiteSpace(password) ? 0 : 1);
|
request.AddParameter("password", string.IsNullOrWhiteSpace(password) ? 0 : 1);
|
||||||
|
|
||||||
@@ -206,7 +214,7 @@ namespace Barotrauma.Networking
|
|||||||
var request = new RestRequest("masterserver2.php", Method.GET);
|
var request = new RestRequest("masterserver2.php", Method.GET);
|
||||||
request.AddParameter("action", "refreshserver");
|
request.AddParameter("action", "refreshserver");
|
||||||
request.AddParameter("gamestarted", gameStarted ? 1 : 0);
|
request.AddParameter("gamestarted", gameStarted ? 1 : 0);
|
||||||
request.AddParameter("currplayers", ConnectedClients.Count);
|
request.AddParameter("currplayers", connectedClients.Count);
|
||||||
request.AddParameter("maxplayers", config.MaximumConnections);
|
request.AddParameter("maxplayers", config.MaximumConnections);
|
||||||
|
|
||||||
Log("Refreshing connection with master server...", Color.Cyan);
|
Log("Refreshing connection with master server...", Color.Cyan);
|
||||||
@@ -275,7 +283,7 @@ namespace Barotrauma.Networking
|
|||||||
inGameHUD.Update((float)Physics.step);
|
inGameHUD.Update((float)Physics.step);
|
||||||
|
|
||||||
bool isCrewDead =
|
bool isCrewDead =
|
||||||
ConnectedClients.Find(c => c.Character != null && !c.Character.IsDead)==null &&
|
connectedClients.Find(c => c.Character != null && !c.Character.IsDead)==null &&
|
||||||
(myCharacter == null || myCharacter.IsDead);
|
(myCharacter == null || myCharacter.IsDead);
|
||||||
|
|
||||||
//restart if all characters are dead or submarine is at the end of the level
|
//restart if all characters are dead or submarine is at the end of the level
|
||||||
@@ -297,7 +305,7 @@ namespace Barotrauma.Networking
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && ConnectedClients.Count>0)
|
else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && connectedClients.Count>0)
|
||||||
{
|
{
|
||||||
AutoRestartTimer -= deltaTime;
|
AutoRestartTimer -= deltaTime;
|
||||||
if (AutoRestartTimer < 0.0f && GameMain.NetLobbyScreen.StartButton.Enabled)
|
if (AutoRestartTimer < 0.0f && GameMain.NetLobbyScreen.StartButton.Enabled)
|
||||||
@@ -320,7 +328,7 @@ namespace Barotrauma.Networking
|
|||||||
disconnectedClients.RemoveAt(i);
|
disconnectedClients.RemoveAt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Client c in ConnectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
if (c.FileStreamSender != null) UpdateFileTransfer(c, deltaTime);
|
if (c.FileStreamSender != null) UpdateFileTransfer(c, deltaTime);
|
||||||
|
|
||||||
@@ -411,7 +419,7 @@ namespace Barotrauma.Networking
|
|||||||
Debug.WriteLine(inc.SenderConnection + " status changed. " + (NetConnectionStatus)inc.SenderConnection.Status);
|
Debug.WriteLine(inc.SenderConnection + " status changed. " + (NetConnectionStatus)inc.SenderConnection.Status);
|
||||||
if (inc.SenderConnection.Status == NetConnectionStatus.Connected)
|
if (inc.SenderConnection.Status == NetConnectionStatus.Connected)
|
||||||
{
|
{
|
||||||
Client sender = ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
|
Client sender = connectedClients.Find(x => x.Connection == inc.SenderConnection);
|
||||||
|
|
||||||
if (sender == null) break;
|
if (sender == null) break;
|
||||||
|
|
||||||
@@ -420,7 +428,7 @@ namespace Barotrauma.Networking
|
|||||||
DisconnectClient(sender, sender.name+" was unable to connect to the server (nonmatching game version)",
|
DisconnectClient(sender, sender.name+" was unable to connect to the server (nonmatching game version)",
|
||||||
"Version " + GameMain.Version + " required to connect to the server (Your version: " + sender.version + ")");
|
"Version " + GameMain.Version + " required to connect to the server (Your version: " + sender.version + ")");
|
||||||
}
|
}
|
||||||
else if (ConnectedClients.Find(x => x.name == sender.name && x != sender)!=null)
|
else if (connectedClients.Find(x => x.name == sender.name && x != sender)!=null)
|
||||||
{
|
{
|
||||||
DisconnectClient(sender, sender.name + " was unable to connect to the server (name already in use)",
|
DisconnectClient(sender, sender.name + " was unable to connect to the server (name already in use)",
|
||||||
"The name ''"+sender.name+"'' is already in use. Please choose another name.");
|
"The name ''"+sender.name+"'' is already in use. Please choose another name.");
|
||||||
@@ -441,8 +449,8 @@ namespace Barotrauma.Networking
|
|||||||
outmsg.Write(allowSpectating);
|
outmsg.Write(allowSpectating);
|
||||||
|
|
||||||
//notify the client about other clients already logged in
|
//notify the client about other clients already logged in
|
||||||
outmsg.Write((byte)((characterInfo == null) ? ConnectedClients.Count - 1 : ConnectedClients.Count));
|
outmsg.Write((byte)((characterInfo == null) ? connectedClients.Count - 1 : connectedClients.Count));
|
||||||
foreach (Client c in ConnectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
if (c.Connection == inc.SenderConnection) continue;
|
if (c.Connection == inc.SenderConnection) continue;
|
||||||
outmsg.Write(c.name);
|
outmsg.Write(c.name);
|
||||||
@@ -479,7 +487,7 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
else if (inc.SenderConnection.Status == NetConnectionStatus.Disconnected)
|
else if (inc.SenderConnection.Status == NetConnectionStatus.Disconnected)
|
||||||
{
|
{
|
||||||
var connectedClient = ConnectedClients.Find(c => c.Connection == inc.SenderConnection);
|
var connectedClient = connectedClients.Find(c => c.Connection == inc.SenderConnection);
|
||||||
if (connectedClient != null && !disconnectedClients.Contains(connectedClient))
|
if (connectedClient != null && !disconnectedClients.Contains(connectedClient))
|
||||||
{
|
{
|
||||||
connectedClient.deleteDisconnectedTimer = NetConfig.DeleteDisconnectedTime;
|
connectedClient.deleteDisconnectedTimer = NetConfig.DeleteDisconnectedTime;
|
||||||
@@ -493,7 +501,7 @@ namespace Barotrauma.Networking
|
|||||||
break;
|
break;
|
||||||
case NetIncomingMessageType.Data:
|
case NetIncomingMessageType.Data:
|
||||||
|
|
||||||
Client dataSender = ConnectedClients.Find(c => c.Connection == inc.SenderConnection);
|
Client dataSender = connectedClients.Find(c => c.Connection == inc.SenderConnection);
|
||||||
if (dataSender == null) return;
|
if (dataSender == null) return;
|
||||||
|
|
||||||
byte packetType = inc.ReadByte();
|
byte packetType = inc.ReadByte();
|
||||||
@@ -577,7 +585,7 @@ namespace Barotrauma.Networking
|
|||||||
dataSender.ReliableChannel.HandleLatestMessageID(inc);
|
dataSender.ReliableChannel.HandleLatestMessageID(inc);
|
||||||
break;
|
break;
|
||||||
case (byte)PacketTypes.Vote:
|
case (byte)PacketTypes.Vote:
|
||||||
Voting.RegisterVote(inc, ConnectedClients);
|
Voting.RegisterVote(inc, connectedClients);
|
||||||
|
|
||||||
if (Voting.AllowEndVoting && EndVoteMax > 0 &&
|
if (Voting.AllowEndVoting && EndVoteMax > 0 &&
|
||||||
((float)EndVoteCount / (float)EndVoteMax) >= EndVoteRequiredRatio)
|
((float)EndVoteCount / (float)EndVoteMax) >= EndVoteRequiredRatio)
|
||||||
@@ -621,7 +629,7 @@ namespace Barotrauma.Networking
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConnectedClients.Find(c => c.Connection == inc.SenderConnection)!=null)
|
if (connectedClients.Find(c => c.Connection == inc.SenderConnection)!=null)
|
||||||
{
|
{
|
||||||
inc.SenderConnection.Deny("Connection error - already joined");
|
inc.SenderConnection.Deny("Connection error - already joined");
|
||||||
return;
|
return;
|
||||||
@@ -676,7 +684,7 @@ namespace Barotrauma.Networking
|
|||||||
DebugConsole.NewMessage(name + " couldn't join the server (wrong content package hash)", Color.Red);
|
DebugConsole.NewMessage(name + " couldn't join the server (wrong content package hash)", Color.Red);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (ConnectedClients.Find(c => c.name.ToLower() == name.ToLower() && c.ID != userID) != null)
|
else if (connectedClients.Find(c => c.name.ToLower() == name.ToLower() && c.ID != userID) != null)
|
||||||
{
|
{
|
||||||
inc.SenderConnection.Deny("The name ''" + name + "'' is already in use. Please choose another name.");
|
inc.SenderConnection.Deny("The name ''" + name + "'' is already in use. Please choose another name.");
|
||||||
DebugConsole.NewMessage(name + " couldn't join the server (name already in use)", Color.Red);
|
DebugConsole.NewMessage(name + " couldn't join the server (name already in use)", Color.Red);
|
||||||
@@ -688,14 +696,14 @@ namespace Barotrauma.Networking
|
|||||||
//existing user re-joining
|
//existing user re-joining
|
||||||
if (userID > 0)
|
if (userID > 0)
|
||||||
{
|
{
|
||||||
Client existingClient = ConnectedClients.Find(c => c.ID == userID);
|
Client existingClient = connectedClients.Find(c => c.ID == userID);
|
||||||
if (existingClient == null)
|
if (existingClient == null)
|
||||||
{
|
{
|
||||||
existingClient = disconnectedClients.Find(c => c.ID == userID);
|
existingClient = disconnectedClients.Find(c => c.ID == userID);
|
||||||
if (existingClient != null)
|
if (existingClient != null)
|
||||||
{
|
{
|
||||||
disconnectedClients.Remove(existingClient);
|
disconnectedClients.Remove(existingClient);
|
||||||
ConnectedClients.Add(existingClient);
|
connectedClients.Add(existingClient);
|
||||||
|
|
||||||
UpdateCrewFrame();
|
UpdateCrewFrame();
|
||||||
}
|
}
|
||||||
@@ -709,8 +717,8 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userID = (byte)Rand.Range(1, 255);
|
userID = 1;
|
||||||
while (ConnectedClients.Find(c => c.ID == userID) != null)
|
while (connectedClients.Any(c => c.ID == userID))
|
||||||
{
|
{
|
||||||
userID++;
|
userID++;
|
||||||
}
|
}
|
||||||
@@ -719,7 +727,7 @@ namespace Barotrauma.Networking
|
|||||||
newClient.Connection = inc.SenderConnection;
|
newClient.Connection = inc.SenderConnection;
|
||||||
newClient.version = version;
|
newClient.version = version;
|
||||||
|
|
||||||
ConnectedClients.Add(newClient);
|
connectedClients.Add(newClient);
|
||||||
|
|
||||||
UpdateCrewFrame();
|
UpdateCrewFrame();
|
||||||
|
|
||||||
@@ -733,7 +741,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
List<NetConnection> recipients = new List<NetConnection>();
|
List<NetConnection> recipients = new List<NetConnection>();
|
||||||
|
|
||||||
foreach (Client client in ConnectedClients)
|
foreach (Client client in connectedClients)
|
||||||
{
|
{
|
||||||
if (client.Connection != excludedConnection) recipients.Add(client.Connection);
|
if (client.Connection != excludedConnection) recipients.Add(client.Connection);
|
||||||
}
|
}
|
||||||
@@ -750,7 +758,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (recipients == null)
|
if (recipients == null)
|
||||||
{
|
{
|
||||||
recipients = ConnectedClients.FindAll(c => c.Character != null || c.Spectating);
|
recipients = connectedClients.FindAll(c => c.Character != null || c.Spectating);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipients.Count == 0) return;
|
if (recipients.Count == 0) return;
|
||||||
@@ -843,7 +851,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (Voting.AllowSubVoting)
|
if (Voting.AllowSubVoting)
|
||||||
{
|
{
|
||||||
selectedSub = Voting.HighestVoted<Submarine>(VoteType.Sub, ConnectedClients);
|
selectedSub = Voting.HighestVoted<Submarine>(VoteType.Sub, connectedClients);
|
||||||
if (selectedSub == null) selectedSub = GameMain.NetLobbyScreen.SelectedSub;
|
if (selectedSub == null) selectedSub = GameMain.NetLobbyScreen.SelectedSub;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -857,7 +865,7 @@ namespace Barotrauma.Networking
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameModePreset selectedMode = Voting.HighestVoted<GameModePreset>(VoteType.Mode, ConnectedClients);
|
GameModePreset selectedMode = Voting.HighestVoted<GameModePreset>(VoteType.Mode, connectedClients);
|
||||||
if (selectedMode == null) selectedMode = GameMain.NetLobbyScreen.SelectedMode;
|
if (selectedMode == null) selectedMode = GameMain.NetLobbyScreen.SelectedMode;
|
||||||
|
|
||||||
if (selectedMode==null)
|
if (selectedMode==null)
|
||||||
@@ -882,17 +890,17 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
||||||
|
|
||||||
ConnectedClients.ForEach(c => c.ReadyToStart = false);
|
connectedClients.ForEach(c => c.ReadyToStart = false);
|
||||||
|
|
||||||
float waitForResponseTimer = 5.0f;
|
float waitForResponseTimer = 5.0f;
|
||||||
while (ConnectedClients.Any(c => !c.ReadyToStart) && waitForResponseTimer > 0.0f)
|
while (connectedClients.Any(c => !c.ReadyToStart) && waitForResponseTimer > 0.0f)
|
||||||
{
|
{
|
||||||
waitForResponseTimer -= CoroutineManager.UnscaledDeltaTime;
|
waitForResponseTimer -= CoroutineManager.UnscaledDeltaTime;
|
||||||
yield return CoroutineStatus.Running;
|
yield return CoroutineStatus.Running;
|
||||||
}
|
}
|
||||||
|
|
||||||
float fileTransferTimeOut = 60.0f;
|
float fileTransferTimeOut = 60.0f;
|
||||||
while (ConnectedClients.Any(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath) && fileTransferTimeOut>0.0f)
|
while (connectedClients.Any(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath) && fileTransferTimeOut>0.0f)
|
||||||
{
|
{
|
||||||
fileTransferTimeOut -= CoroutineManager.UnscaledDeltaTime;
|
fileTransferTimeOut -= CoroutineManager.UnscaledDeltaTime;
|
||||||
|
|
||||||
@@ -900,7 +908,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
var messageBox = new GUIMessageBox("File transfer in progress",
|
var messageBox = new GUIMessageBox("File transfer in progress",
|
||||||
"The round will be started after the submarine file has been sent to all players.", new string[] {"Cancel transfer"}, 400, 400);
|
"The round will be started after the submarine file has been sent to all players.", new string[] {"Cancel transfer"}, 400, 400);
|
||||||
messageBox.Buttons[0].UserData = ConnectedClients.Find(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath);
|
messageBox.Buttons[0].UserData = connectedClients.Find(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath);
|
||||||
messageBox.Buttons[0].OnClicked = (button, obj) =>
|
messageBox.Buttons[0].OnClicked = (button, obj) =>
|
||||||
{
|
{
|
||||||
(button.UserData as Client).CancelTransfer();
|
(button.UserData as Client).CancelTransfer();
|
||||||
@@ -937,7 +945,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
||||||
|
|
||||||
foreach (Client client in ConnectedClients)
|
foreach (Client client in connectedClients)
|
||||||
{
|
{
|
||||||
client.inGame = true;
|
client.inGame = true;
|
||||||
|
|
||||||
@@ -958,13 +966,13 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos);
|
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos);
|
||||||
|
|
||||||
for (int i = 0; i < ConnectedClients.Count; i++)
|
for (int i = 0; i < connectedClients.Count; i++)
|
||||||
{
|
{
|
||||||
ConnectedClients[i].Character = Character.Create(
|
connectedClients[i].Character = Character.Create(
|
||||||
ConnectedClients[i].characterInfo, assignedWayPoints[i].WorldPosition, true, false);
|
connectedClients[i].characterInfo, assignedWayPoints[i].WorldPosition, true, false);
|
||||||
ConnectedClients[i].Character.GiveJobItems(assignedWayPoints[i]);
|
connectedClients[i].Character.GiveJobItems(assignedWayPoints[i]);
|
||||||
|
|
||||||
GameMain.GameSession.CrewManager.characters.Add(ConnectedClients[i].Character);
|
GameMain.GameSession.CrewManager.characters.Add(connectedClients[i].Character);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (characterInfo != null)
|
if (characterInfo != null)
|
||||||
@@ -1037,7 +1045,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
//msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes);
|
//msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes);
|
||||||
|
|
||||||
List<Client> playingClients = ConnectedClients.FindAll(c => c.Character != null);
|
List<Client> playingClients = connectedClients.FindAll(c => c.Character != null);
|
||||||
|
|
||||||
msg.Write((myCharacter == null) ? (byte)playingClients.Count : (byte)(playingClients.Count + 1));
|
msg.Write((myCharacter == null) ? (byte)playingClients.Count : (byte)(playingClients.Count + 1));
|
||||||
foreach (Client client in playingClients)
|
foreach (Client client in playingClients)
|
||||||
@@ -1084,7 +1092,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
gameStarted = false;
|
gameStarted = false;
|
||||||
|
|
||||||
if (ConnectedClients.Count > 0)
|
if (connectedClients.Count > 0)
|
||||||
{
|
{
|
||||||
NetOutgoingMessage msg = server.CreateMessage();
|
NetOutgoingMessage msg = server.CreateMessage();
|
||||||
msg.Write((byte)PacketTypes.EndGame);
|
msg.Write((byte)PacketTypes.EndGame);
|
||||||
@@ -1095,7 +1103,7 @@ namespace Barotrauma.Networking
|
|||||||
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableOrdered, 0);
|
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableOrdered, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Client client in ConnectedClients)
|
foreach (Client client in connectedClients)
|
||||||
{
|
{
|
||||||
client.Spectating = false;
|
client.Spectating = false;
|
||||||
client.Character = null;
|
client.Character = null;
|
||||||
@@ -1126,7 +1134,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private void DisconnectClient(NetConnection senderConnection, string msg = "", string targetmsg = "")
|
private void DisconnectClient(NetConnection senderConnection, string msg = "", string targetmsg = "")
|
||||||
{
|
{
|
||||||
Client client = ConnectedClients.Find(x => x.Connection == senderConnection);
|
Client client = connectedClients.Find(x => x.Connection == senderConnection);
|
||||||
if (client == null) return;
|
if (client == null) return;
|
||||||
|
|
||||||
DisconnectClient(client, msg, targetmsg);
|
DisconnectClient(client, msg, targetmsg);
|
||||||
@@ -1151,7 +1159,7 @@ namespace Barotrauma.Networking
|
|||||||
outmsg.Write(targetmsg);
|
outmsg.Write(targetmsg);
|
||||||
server.SendMessage(outmsg, client.Connection, NetDeliveryMethod.ReliableUnordered, 0);
|
server.SendMessage(outmsg, client.Connection, NetDeliveryMethod.ReliableUnordered, 0);
|
||||||
|
|
||||||
ConnectedClients.Remove(client);
|
connectedClients.Remove(client);
|
||||||
|
|
||||||
outmsg = server.CreateMessage();
|
outmsg = server.CreateMessage();
|
||||||
outmsg.Write((byte)PacketTypes.PlayerLeft);
|
outmsg.Write((byte)PacketTypes.PlayerLeft);
|
||||||
@@ -1182,7 +1190,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
List<Character> crew = new List<Character>();
|
List<Character> crew = new List<Character>();
|
||||||
|
|
||||||
foreach (Client c in ConnectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
if (c.Character == null || !c.inGame) continue;
|
if (c.Character == null || !c.inGame) continue;
|
||||||
|
|
||||||
@@ -1198,7 +1206,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
playerName = playerName.ToLowerInvariant();
|
playerName = playerName.ToLowerInvariant();
|
||||||
|
|
||||||
Client client = ConnectedClients.Find(c => c.name.ToLowerInvariant() == playerName ||
|
Client client = connectedClients.Find(c => c.name.ToLowerInvariant() == playerName ||
|
||||||
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
|
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
|
||||||
|
|
||||||
if (client == null) return;
|
if (client == null) return;
|
||||||
@@ -1285,7 +1293,7 @@ namespace Barotrauma.Networking
|
|||||||
Log(traitor.Name + " is the traitor and the target is " + target.Name, Color.Cyan);
|
Log(traitor.Name + " is the traitor and the target is " + target.Name, Color.Cyan);
|
||||||
|
|
||||||
Client traitorClient = null;
|
Client traitorClient = null;
|
||||||
foreach (Client c in ConnectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
if (c.Character != traitor) continue;
|
if (c.Character != traitor) continue;
|
||||||
traitorClient = c;
|
traitorClient = c;
|
||||||
@@ -1338,7 +1346,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
int resentMessages = 0;
|
int resentMessages = 0;
|
||||||
|
|
||||||
int clientListHeight = ConnectedClients.Count() * 40;
|
int clientListHeight = connectedClients.Count() * 40;
|
||||||
float scrollBarHeight = (height - 110) / (float)Math.Max(clientListHeight, 110);
|
float scrollBarHeight = (height - 110) / (float)Math.Max(clientListHeight, 110);
|
||||||
|
|
||||||
if (clientListScrollBar.BarSize != scrollBarHeight)
|
if (clientListScrollBar.BarSize != scrollBarHeight)
|
||||||
@@ -1348,7 +1356,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
int startY = y + 110;
|
int startY = y + 110;
|
||||||
y = (startY - (int)(clientListScrollBar.BarScroll * (clientListHeight-(height - 110))));
|
y = (startY - (int)(clientListScrollBar.BarScroll * (clientListHeight-(height - 110))));
|
||||||
foreach (Client c in ConnectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
Color clientColor = c.Connection.AverageRoundtripTime > 0.3f ? Color.Red : Color.White;
|
Color clientColor = c.Connection.AverageRoundtripTime > 0.3f ? Color.Red : Color.White;
|
||||||
|
|
||||||
@@ -1379,14 +1387,14 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
if (server.Connections.Count == 0) return;
|
if (server.Connections.Count == 0) return;
|
||||||
|
|
||||||
var clientsToKick = ConnectedClients.FindAll(c => c.KickVoteCount > ConnectedClients.Count * KickVoteRequiredRatio);
|
var clientsToKick = connectedClients.FindAll(c => c.KickVoteCount > connectedClients.Count * KickVoteRequiredRatio);
|
||||||
clientsToKick.ForEach(c => KickClient(c));
|
clientsToKick.ForEach(c => KickClient(c));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NetOutgoingMessage msg = server.CreateMessage();
|
NetOutgoingMessage msg = server.CreateMessage();
|
||||||
msg.Write((byte)PacketTypes.VoteStatus);
|
msg.Write((byte)PacketTypes.VoteStatus);
|
||||||
Voting.WriteData(msg, ConnectedClients);
|
Voting.WriteData(msg, connectedClients);
|
||||||
|
|
||||||
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0);
|
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0);
|
||||||
}
|
}
|
||||||
@@ -1446,7 +1454,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
List<Client> recipients = new List<Client>();
|
List<Client> recipients = new List<Client>();
|
||||||
|
|
||||||
foreach (Client c in ConnectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
switch (message.Type)
|
switch (message.Type)
|
||||||
{
|
{
|
||||||
@@ -1503,7 +1511,7 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
else if (command != "")
|
else if (command != "")
|
||||||
{
|
{
|
||||||
targetClient = ConnectedClients.Find(c =>
|
targetClient = connectedClients.Find(c =>
|
||||||
command == c.name.ToLowerInvariant() ||
|
command == c.name.ToLowerInvariant() ||
|
||||||
(c.Character != null && command == c.Character.Name.ToLowerInvariant()));
|
(c.Character != null && command == c.Character.Name.ToLowerInvariant()));
|
||||||
|
|
||||||
@@ -1520,7 +1528,7 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (Client c in ConnectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
if (type != ChatMessageType.Dead || (c.Character == null || c.Character.IsDead)) recipients.Add(c);
|
if (type != ChatMessageType.Dead || (c.Character == null || c.Character.IsDead)) recipients.Add(c);
|
||||||
}
|
}
|
||||||
@@ -1577,7 +1585,7 @@ namespace Barotrauma.Networking
|
|||||||
if (jobPrefab != null) jobPreferences.Add(jobPrefab);
|
if (jobPrefab != null) jobPreferences.Add(jobPrefab);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Client c in ConnectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
if (c.Connection != message.SenderConnection) continue;
|
if (c.Connection != message.SenderConnection) continue;
|
||||||
|
|
||||||
@@ -1642,7 +1650,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private void AssignJobs()
|
private void AssignJobs()
|
||||||
{
|
{
|
||||||
List<Client> unassigned = new List<Client>(ConnectedClients);
|
List<Client> unassigned = new List<Client>(connectedClients);
|
||||||
|
|
||||||
int[] assignedClientCount = new int[JobPrefab.List.Count];
|
int[] assignedClientCount = new int[JobPrefab.List.Count];
|
||||||
|
|
||||||
@@ -1792,7 +1800,7 @@ namespace Barotrauma.Networking
|
|||||||
log.Save();
|
log.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Client client in ConnectedClients)
|
foreach (Client client in connectedClients)
|
||||||
{
|
{
|
||||||
if (client.FileStreamSender != null) client.FileStreamSender.Dispose();
|
if (client.FileStreamSender != null) client.FileStreamSender.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public bool AutoRestart
|
public bool AutoRestart
|
||||||
{
|
{
|
||||||
get { return (ConnectedClients.Count != 0) && autoRestart; }
|
get { return (connectedClients.Count != 0) && autoRestart; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
autoRestart = value;
|
autoRestart = value;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace Barotrauma.Networking
|
|||||||
Kick
|
Kick
|
||||||
}
|
}
|
||||||
|
|
||||||
class NetworkMember
|
abstract class NetworkMember
|
||||||
{
|
{
|
||||||
protected NetPeer netPeer;
|
protected NetPeer netPeer;
|
||||||
|
|
||||||
@@ -64,7 +64,6 @@ namespace Barotrauma.Networking
|
|||||||
protected GUIListBox chatBox;
|
protected GUIListBox chatBox;
|
||||||
protected GUITextBox chatMsgBox;
|
protected GUITextBox chatMsgBox;
|
||||||
|
|
||||||
|
|
||||||
public int EndVoteCount, EndVoteMax;
|
public int EndVoteCount, EndVoteMax;
|
||||||
//private GUITextBlock endVoteText;
|
//private GUITextBlock endVoteText;
|
||||||
|
|
||||||
@@ -109,6 +108,12 @@ namespace Barotrauma.Networking
|
|||||||
get { return inGameHUD; }
|
get { return inGameHUD; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public virtual List<Client> ConnectedClients
|
||||||
|
{
|
||||||
|
get { return null; }
|
||||||
|
}
|
||||||
|
|
||||||
public NetworkMember()
|
public NetworkMember()
|
||||||
{
|
{
|
||||||
inGameHUD = new GUIFrame(new Rectangle(0,0,0,0), null, null);
|
inGameHUD = new GUIFrame(new Rectangle(0,0,0,0), null, null);
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ namespace Barotrauma
|
|||||||
spectateButton.UserData = "spectateButton";
|
spectateButton.UserData = "spectateButton";
|
||||||
}
|
}
|
||||||
|
|
||||||
GameMain.Client.Voting.ResetVotes(GameMain.Client.OtherClients);
|
GameMain.Client.Voting.ResetVotes(GameMain.Client.ConnectedClients);
|
||||||
|
|
||||||
UpdatePlayerFrame(GameMain.Client.CharacterInfo);
|
UpdatePlayerFrame(GameMain.Client.CharacterInfo);
|
||||||
}
|
}
|
||||||
@@ -594,9 +594,13 @@ namespace Barotrauma
|
|||||||
(component as GUITextBlock).TextColor = Color.DarkRed * 0.8f;
|
(component as GUITextBlock).TextColor = Color.DarkRed * 0.8f;
|
||||||
component.CanBeFocused = false;
|
component.CanBeFocused = false;
|
||||||
|
|
||||||
|
StartButton.Enabled = false;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StartButton.Enabled = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1121,7 +1125,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void ReadData(NetIncomingMessage msg)
|
public void ReadData(NetIncomingMessage msg)
|
||||||
{
|
{
|
||||||
string mapName = "", md5Hash = "";
|
string subName = "", md5Hash = "";
|
||||||
|
|
||||||
int modeIndex = 0;
|
int modeIndex = 0;
|
||||||
//float durationScroll = 0.0f;
|
//float durationScroll = 0.0f;
|
||||||
@@ -1135,7 +1139,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mapName = msg.ReadString();
|
subName = msg.ReadString();
|
||||||
md5Hash = msg.ReadString();
|
md5Hash = msg.ReadString();
|
||||||
|
|
||||||
ServerName = msg.ReadString();
|
ServerName = msg.ReadString();
|
||||||
@@ -1167,7 +1171,7 @@ namespace Barotrauma
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(mapName) && !GameMain.NetworkMember.Voting.AllowSubVoting) TrySelectSub(mapName, md5Hash);
|
if (!string.IsNullOrWhiteSpace(subName) && !GameMain.NetworkMember.Voting.AllowSubVoting) TrySelectSub(subName, md5Hash);
|
||||||
|
|
||||||
if (!GameMain.NetworkMember.Voting.AllowModeVoting)
|
if (!GameMain.NetworkMember.Voting.AllowModeVoting)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user