Spectating, fire, damaged limb sprites, water detector, engineer jumpsuit, new signal comp sprites, resharper cleanup (god knows what else, commit more often)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
@@ -207,7 +206,7 @@ namespace Barotrauma.Networking
|
||||
if (packetType == (byte)PacketTypes.LoggedIn)
|
||||
{
|
||||
myID = inc.ReadInt32();
|
||||
bool gameStarted= inc.ReadBoolean();
|
||||
gameStarted = inc.ReadBoolean();
|
||||
if (gameStarted && Screen.Selected != GameMain.GameScreen)
|
||||
{
|
||||
new GUIMessageBox("Please wait", "A round is already running. You will have to wait for a new round to start.");
|
||||
@@ -219,7 +218,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
GameMain.NetLobbyScreen.Select();
|
||||
|
||||
new GUIMessageBox("Connection timed out", "You were disconnected for too long and your character was deleted. Please wait for another round to start.");
|
||||
new GUIMessageBox("Connection timed out", "You were disconnected for too long and your Character was deleted. Please wait for another round to start.");
|
||||
}
|
||||
|
||||
GameMain.NetLobbyScreen.ClearPlayers();
|
||||
@@ -428,7 +427,7 @@ namespace Barotrauma.Networking
|
||||
switch (packetType)
|
||||
{
|
||||
case (byte)PacketTypes.StartGame:
|
||||
if (gameStarted) continue;
|
||||
if (Screen.Selected == GameMain.GameScreen) continue;
|
||||
|
||||
GameMain.ShowLoading(StartGame(inc), false);
|
||||
|
||||
@@ -467,8 +466,8 @@ namespace Barotrauma.Networking
|
||||
if (!c.IsNetworkPlayer || !c.IsHumanoid || c.Info==null) continue;
|
||||
crew.Add(c);
|
||||
}
|
||||
|
||||
CreateCrewFrame(crew);
|
||||
|
||||
GameMain.GameSession.CrewManager.CreateCrewFrame(crew);
|
||||
|
||||
break;
|
||||
|
||||
@@ -532,7 +531,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (gameMode == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Game mode ''"+gameMode+"'' not found!");
|
||||
DebugConsole.ThrowError("Game mode ''" + modeName + "'' not found!");
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
@@ -576,7 +575,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
AddChatMessage("Press TAB to chat", ChatMessageType.Server);
|
||||
|
||||
CreateCrewFrame(crew);
|
||||
GameMain.GameSession.CrewManager.CreateCrewFrame(crew);
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
@@ -624,7 +623,7 @@ namespace Barotrauma.Networking
|
||||
myCharacter = null;
|
||||
foreach (Client c in otherClients)
|
||||
{
|
||||
c.character = null;
|
||||
c.Character = null;
|
||||
}
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
@@ -680,6 +679,16 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
public bool SpectateClicked(GUIButton button, object userData)
|
||||
{
|
||||
NetOutgoingMessage msg = client.CreateMessage();
|
||||
msg.Write((byte)PacketTypes.Spectate);
|
||||
|
||||
client.SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SendCharacterData()
|
||||
{
|
||||
if (characterInfo == null) return;
|
||||
@@ -800,7 +809,7 @@ namespace Barotrauma.Networking
|
||||
int bitCount = Rand.Int(100);
|
||||
for (int i = 0; i<bitCount; i++)
|
||||
{
|
||||
msg.Write((Rand.Int(2)==0) ? true : false);
|
||||
msg.Write(Rand.Int(2)==0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using RestSharp;
|
||||
@@ -11,15 +12,17 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
partial class GameServer : NetworkMember
|
||||
{
|
||||
public List<Client> connectedClients = new List<Client>();
|
||||
public List<Client> ConnectedClients = new List<Client>();
|
||||
|
||||
//for keeping track of disconnected clients in case the reconnect shortly after
|
||||
private List<Client> disconnectedClients = new List<Client>();
|
||||
|
||||
private NetStats netStats;
|
||||
|
||||
private int roundStartSeed;
|
||||
|
||||
//is the server running
|
||||
bool started;
|
||||
private bool started;
|
||||
|
||||
private NetServer server;
|
||||
private NetPeerConfiguration config;
|
||||
@@ -131,7 +134,7 @@ namespace Barotrauma.Networking
|
||||
request.AddParameter("action", "addserver");
|
||||
request.AddParameter("servername", name);
|
||||
request.AddParameter("serverport", Port);
|
||||
request.AddParameter("playercount", PlayerCountToByte(connectedClients.Count, config.MaximumConnections));
|
||||
request.AddParameter("playercount", PlayerCountToByte(ConnectedClients.Count, config.MaximumConnections));
|
||||
request.AddParameter("password", string.IsNullOrWhiteSpace(password) ? 0 : 1);
|
||||
|
||||
// execute the request
|
||||
@@ -143,7 +146,7 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
if (response!=null && !string.IsNullOrWhiteSpace(response.Content))
|
||||
if (response != null && !string.IsNullOrWhiteSpace(response.Content))
|
||||
{
|
||||
DebugConsole.ThrowError("Error while connecting to master server (" +response.Content+")");
|
||||
return;
|
||||
@@ -160,7 +163,7 @@ namespace Barotrauma.Networking
|
||||
var request = new RestRequest("masterserver.php", Method.GET);
|
||||
request.AddParameter("action", "refreshserver");
|
||||
request.AddParameter("gamestarted", gameStarted ? 1 : 0);
|
||||
request.AddParameter("playercount", PlayerCountToByte(connectedClients.Count, config.MaximumConnections));
|
||||
request.AddParameter("playercount", PlayerCountToByte(ConnectedClients.Count, config.MaximumConnections));
|
||||
|
||||
System.Diagnostics.Debug.WriteLine("refreshing master");
|
||||
|
||||
@@ -221,7 +224,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
//if all characters dead
|
||||
if (AutoRestart &&
|
||||
connectedClients.Find(c => c.character != null && !c.character.IsDead)==null &&
|
||||
ConnectedClients.Find(c => c.Character != null && !c.Character.IsDead)==null &&
|
||||
(myCharacter == null || myCharacter.IsDead))
|
||||
{
|
||||
EndButtonHit(null, null);
|
||||
@@ -229,7 +232,7 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && connectedClients.Count>0)
|
||||
else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && ConnectedClients.Count>0)
|
||||
{
|
||||
AutoRestartTimer -= deltaTime;
|
||||
if (AutoRestartTimer < 0.0f)
|
||||
@@ -243,16 +246,16 @@ namespace Barotrauma.Networking
|
||||
disconnectedClients[i].deleteDisconnectedTimer -= deltaTime;
|
||||
if (disconnectedClients[i].deleteDisconnectedTimer > 0.0f) continue;
|
||||
|
||||
if (gameStarted && disconnectedClients[i].character!=null)
|
||||
if (gameStarted && disconnectedClients[i].Character!=null)
|
||||
{
|
||||
disconnectedClients[i].character.Remove();
|
||||
disconnectedClients[i].character = null;
|
||||
disconnectedClients[i].Character.Remove();
|
||||
disconnectedClients[i].Character = null;
|
||||
}
|
||||
|
||||
disconnectedClients.RemoveAt(i);
|
||||
}
|
||||
|
||||
foreach (Client c in connectedClients)
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
c.ReliableChannel.Update(deltaTime);
|
||||
}
|
||||
@@ -283,7 +286,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
foreach (Character c in Character.CharacterList)
|
||||
{
|
||||
if (c as AICharacter == null || c.IsDead) continue;
|
||||
if (!(c is AICharacter) || c.IsDead) continue;
|
||||
|
||||
if (c.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) continue;
|
||||
|
||||
@@ -301,12 +304,10 @@ namespace Barotrauma.Networking
|
||||
updateTimer = DateTime.Now + updateInterval;
|
||||
}
|
||||
|
||||
if (registeredToMaster && refreshMasterTimer < DateTime.Now)
|
||||
{
|
||||
CoroutineManager.StartCoroutine(RefreshMaster());
|
||||
if (!registeredToMaster || refreshMasterTimer >= DateTime.Now) return;
|
||||
|
||||
refreshMasterTimer = DateTime.Now + refreshMasterInterval;
|
||||
}
|
||||
CoroutineManager.StartCoroutine(RefreshMaster());
|
||||
refreshMasterTimer = DateTime.Now + refreshMasterInterval;
|
||||
}
|
||||
|
||||
private void SparseUpdate()
|
||||
@@ -315,7 +316,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
foreach (Character c in Character.CharacterList)
|
||||
{
|
||||
if (c as AICharacter != null || c.IsDead) continue;
|
||||
if (c is AICharacter || c.IsDead) continue;
|
||||
|
||||
new NetworkEvent(NetworkEventType.ImportantEntityUpdate, c.ID, false);
|
||||
}
|
||||
@@ -325,8 +326,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
private void ReadMessage(NetIncomingMessage inc)
|
||||
{
|
||||
NetOutgoingMessage outmsg;
|
||||
|
||||
switch (inc.MessageType)
|
||||
{
|
||||
case NetIncomingMessageType.ConnectionApproval:
|
||||
@@ -336,7 +335,7 @@ namespace Barotrauma.Networking
|
||||
Debug.WriteLine(inc.SenderConnection + " status changed. " + (NetConnectionStatus)inc.SenderConnection.Status);
|
||||
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;
|
||||
|
||||
@@ -345,7 +344,7 @@ namespace Barotrauma.Networking
|
||||
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 + ")");
|
||||
}
|
||||
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)",
|
||||
"The name ''"+sender.name+"'' is already in use. Please choose another name.");
|
||||
@@ -357,19 +356,16 @@ namespace Barotrauma.Networking
|
||||
GameMain.NetLobbyScreen.AddPlayer(sender.name);
|
||||
|
||||
// Notify the client that they have logged in
|
||||
outmsg = server.CreateMessage();
|
||||
var outmsg = server.CreateMessage();
|
||||
|
||||
outmsg.Write((byte)PacketTypes.LoggedIn);
|
||||
|
||||
outmsg.Write(sender.ID);
|
||||
|
||||
outmsg.Write(gameStarted);
|
||||
|
||||
outmsg.Write(gameStarted && sender.character!=null);
|
||||
outmsg.Write(gameStarted && sender.Character!=null);
|
||||
|
||||
//notify the client about other clients already logged in
|
||||
outmsg.Write((characterInfo == null) ? connectedClients.Count - 1 : connectedClients.Count);
|
||||
foreach (Client c in connectedClients)
|
||||
outmsg.Write((characterInfo == null) ? ConnectedClients.Count - 1 : ConnectedClients.Count);
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
if (c.Connection == inc.SenderConnection) continue;
|
||||
outmsg.Write(c.name);
|
||||
@@ -401,7 +397,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
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))
|
||||
{
|
||||
connectedClient.deleteDisconnectedTimer = NetConfig.DeleteDisconnectedTime;
|
||||
@@ -415,7 +411,7 @@ namespace Barotrauma.Networking
|
||||
break;
|
||||
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;
|
||||
|
||||
byte packetType = 0;
|
||||
@@ -428,13 +424,10 @@ namespace Barotrauma.Networking
|
||||
return;
|
||||
}
|
||||
|
||||
bool isReliable = false;
|
||||
if (packetType == (byte)PacketTypes.ReliableMessage)
|
||||
{
|
||||
if (!dataSender.ReliableChannel.CheckMessage(inc)) return;
|
||||
packetType = inc.ReadByte();
|
||||
|
||||
isReliable = true;
|
||||
}
|
||||
|
||||
switch (packetType)
|
||||
@@ -443,33 +436,6 @@ namespace Barotrauma.Networking
|
||||
if (!gameStarted) break;
|
||||
NetworkEvent.ReadMessage(inc, true);
|
||||
|
||||
//List<Client> recipients = connectedClients.FindAll(c => c.Connection != inc.SenderConnection && c.inGame);
|
||||
//if (recipients.Count == 0) break;
|
||||
|
||||
//if (isReliable)
|
||||
//{
|
||||
// Debug.WriteLine("receiver reliable networkevent");
|
||||
// foreach (Client c in recipients)
|
||||
// {
|
||||
// var reliableMessage = c.ReliableChannel.CreateMessage();
|
||||
// inc.Position = 8+16;
|
||||
// byte[] messageBytes = inc.ReadBytes(inc.LengthBytes-3);
|
||||
// reliableMessage.InnerMessage.Write(messageBytes);
|
||||
|
||||
// c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// outmsg = server.CreateMessage();
|
||||
// outmsg.Write(inc);
|
||||
|
||||
// List<NetConnection> recipientConnections = new List<NetConnection>();
|
||||
// foreach (Client c in recipients) recipientConnections.Add(c.Connection);
|
||||
|
||||
// server.SendMessage(outmsg, recipientConnections, inc.DeliveryMethod, 0);
|
||||
//}
|
||||
|
||||
break;
|
||||
case (byte)PacketTypes.Chatmessage:
|
||||
ChatMessageType messageType = (ChatMessageType)inc.ReadByte();
|
||||
@@ -492,7 +458,14 @@ namespace Barotrauma.Networking
|
||||
dataSender.ReliableChannel.HandleLatestMessageID(inc);
|
||||
break;
|
||||
case (byte)PacketTypes.Vote:
|
||||
Voting.RegisterVote(inc, connectedClients);
|
||||
Voting.RegisterVote(inc, ConnectedClients);
|
||||
break;
|
||||
case (byte)PacketTypes.Spectate:
|
||||
if (gameStarted)
|
||||
{
|
||||
var startMessage = CreateStartMessage(roundStartSeed, Submarine.Loaded, GameMain.GameSession.gameMode.Preset);
|
||||
server.SendMessage(startMessage, inc.SenderConnection, NetDeliveryMethod.ReliableUnordered);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -515,7 +488,7 @@ namespace Barotrauma.Networking
|
||||
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");
|
||||
return;
|
||||
@@ -565,7 +538,7 @@ namespace Barotrauma.Networking
|
||||
DebugConsole.NewMessage(name + " couldn't join the server (wrong content package hash)", Color.Red);
|
||||
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.");
|
||||
DebugConsole.NewMessage(name + " couldn't join the server (name already in use)", Color.Red);
|
||||
@@ -577,14 +550,14 @@ namespace Barotrauma.Networking
|
||||
//existing user re-joining
|
||||
if (userID > 0)
|
||||
{
|
||||
Client existingClient = connectedClients.Find(c => c.ID == userID);
|
||||
Client existingClient = ConnectedClients.Find(c => c.ID == userID);
|
||||
if (existingClient == null)
|
||||
{
|
||||
existingClient = disconnectedClients.Find(c => c.ID == userID);
|
||||
if (existingClient != null)
|
||||
{
|
||||
disconnectedClients.Remove(existingClient);
|
||||
connectedClients.Add(existingClient);
|
||||
ConnectedClients.Add(existingClient);
|
||||
|
||||
UpdateCrewFrame();
|
||||
}
|
||||
@@ -598,7 +571,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
userID = Rand.Range(1, 1000000);
|
||||
while (connectedClients.Find(c => c.ID == userID) != null)
|
||||
while (ConnectedClients.Find(c => c.ID == userID) != null)
|
||||
{
|
||||
userID++;
|
||||
}
|
||||
@@ -607,7 +580,7 @@ namespace Barotrauma.Networking
|
||||
newClient.Connection = inc.SenderConnection;
|
||||
newClient.version = version;
|
||||
|
||||
connectedClients.Add(newClient);
|
||||
ConnectedClients.Add(newClient);
|
||||
|
||||
UpdateCrewFrame();
|
||||
|
||||
@@ -615,11 +588,11 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
|
||||
private void SendMessage(NetOutgoingMessage msg, NetDeliveryMethod deliveryMethod, NetConnection excludedConnection)
|
||||
private void SendMessage(NetOutgoingMessage msg, NetDeliveryMethod deliveryMethod, NetConnection excludedConnection = null)
|
||||
{
|
||||
List<NetConnection> recipients = new List<NetConnection>();
|
||||
|
||||
foreach (Client client in connectedClients)
|
||||
foreach (Client client in ConnectedClients)
|
||||
{
|
||||
if (client.Connection != excludedConnection) recipients.Add(client.Connection);
|
||||
}
|
||||
@@ -634,78 +607,10 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (NetworkEvent.Events.Count == 0) return;
|
||||
|
||||
List<Client> recipients = connectedClients.FindAll(c => c.character != null);
|
||||
|
||||
List<NetConnection> recipientConnections = new List<NetConnection>();
|
||||
foreach (Client c in recipients)
|
||||
{
|
||||
recipientConnections.Add(c.Connection);
|
||||
}
|
||||
List<Client> recipients = ConnectedClients.FindAll(c => c.Character != null);
|
||||
|
||||
if (recipients.Count == 0) return;
|
||||
|
||||
//foreach (Client c in recipients)
|
||||
//{
|
||||
|
||||
// for (int i = 0; i < 2; i++)
|
||||
// {
|
||||
// bool important = i == 0;
|
||||
|
||||
// var events = NetworkEvent.Events.FindAll(e => e.IsImportant == important && e.SenderConnection != c.Connection);
|
||||
// if (events.Count == 0) continue;
|
||||
|
||||
// List<byte[]> msgBytes = new List<byte[]>();
|
||||
|
||||
// int totalLength = 1;
|
||||
|
||||
// foreach (NetworkEvent unreliableEvent in events)
|
||||
// {
|
||||
// NetBuffer tempMessage = new NetBuffer();// server.CreateMessage();
|
||||
// if (!unreliableEvent.FillData(tempMessage)) continue;
|
||||
// tempMessage.WritePadBits();
|
||||
|
||||
// tempMessage.Position = 0;
|
||||
// msgBytes.Add(tempMessage.ReadBytes(tempMessage.LengthBytes));
|
||||
|
||||
// //one extra byte for writing the length
|
||||
// totalLength += 1 + tempMessage.LengthBytes;
|
||||
// }
|
||||
|
||||
// //NetOutgoingMessage combinedMessage = null;
|
||||
// //reliableMessage = null;
|
||||
// if (important)
|
||||
// {
|
||||
// ReliableMessage reliableMessage = c.ReliableChannel.CreateMessage();
|
||||
|
||||
// reliableMessage.InnerMessage.Write((byte)msgBytes.Count);
|
||||
// foreach (byte[] msgData in msgBytes)
|
||||
// {
|
||||
// if (msgData.Length > 255) DebugConsole.ThrowError("too large networkevent (" + msgData.Length + " bytes)");
|
||||
|
||||
// reliableMessage.InnerMessage.Write((byte)msgData.Length);
|
||||
// reliableMessage.InnerMessage.Write(msgData);
|
||||
// }
|
||||
|
||||
// c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var combinedMessage = server.CreateMessage(totalLength);
|
||||
|
||||
// combinedMessage.Write((byte)msgBytes.Count);
|
||||
// foreach (byte[] msgData in msgBytes)
|
||||
// {
|
||||
// if (msgData.Length > 255) DebugConsole.ThrowError("too large networkevent (" + msgData.Length + " bytes)");
|
||||
|
||||
// combinedMessage.Write((byte)msgData.Length);
|
||||
// combinedMessage.Write(msgData);
|
||||
// }
|
||||
|
||||
// server.SendMessage(combinedMessage, c.Connection, NetDeliveryMethod.Unreliable, 0);
|
||||
// }
|
||||
|
||||
// }
|
||||
//}
|
||||
foreach (Client c in recipients)
|
||||
{
|
||||
var message = ComposeNetworkEventMessage(true, c.Connection);
|
||||
@@ -725,39 +630,6 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//foreach (NetworkEvent networkEvent in NetworkEvent.events)
|
||||
//{
|
||||
// if (!networkEvent.IsImportant) co
|
||||
// //if (!networkEvent.IsClient) continue;
|
||||
|
||||
// if (!networkEvent.FillData(message))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// //Entity e = Entity.FindEntityByID(networkEvent.ID);
|
||||
// //if (e == null) continue;
|
||||
// if (networkEvent.IsImportant)
|
||||
// {
|
||||
// foreach (Client c in recipients)
|
||||
// {
|
||||
// ReliableMessage reliableMessage = c.ReliableChannel.CreateMessage();
|
||||
// message.Position = 0;
|
||||
// reliableMessage.InnerMessage.Write(message.ReadBytes(message.LengthBytes));
|
||||
|
||||
// c.ReliableChannel.SendMessage(reliableMessage, c.Connection);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (server.ConnectionsCount>0)
|
||||
// {
|
||||
// server.SendMessage(message, recipientConnections, NetDeliveryMethod.Unreliable, 0);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
NetworkEvent.Events.Clear();
|
||||
}
|
||||
|
||||
@@ -768,7 +640,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (Voting.AllowSubVoting)
|
||||
{
|
||||
Voting.HighestVoted<Submarine>(VoteType.Sub, connectedClients);
|
||||
selectedSub = Voting.HighestVoted<Submarine>(VoteType.Sub, ConnectedClients);
|
||||
if (selectedSub == null) selectedSub = GameMain.NetLobbyScreen.SelectedSub;
|
||||
}
|
||||
else
|
||||
@@ -793,22 +665,23 @@ namespace Barotrauma.Networking
|
||||
|
||||
AssignJobs();
|
||||
|
||||
//selectedMap.Load();
|
||||
roundStartSeed = DateTime.Now.Millisecond;
|
||||
Rand.SetSyncedSeed(roundStartSeed);
|
||||
|
||||
int seed = DateTime.Now.Millisecond;
|
||||
Rand.SetSyncedSeed(seed);
|
||||
|
||||
GameModePreset selectedMode = Voting.HighestVoted<GameModePreset>(VoteType.Mode, connectedClients);
|
||||
GameModePreset selectedMode = Voting.HighestVoted<GameModePreset>(VoteType.Mode, ConnectedClients);
|
||||
if (selectedMode==null) selectedMode=GameMain.NetLobbyScreen.SelectedMode;
|
||||
|
||||
GameMain.GameSession = new GameSession(selectedSub, "", selectedMode);
|
||||
GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed);
|
||||
|
||||
var startMessage = CreateStartMessage(roundStartSeed, Submarine.Loaded, GameMain.GameSession.gameMode.Preset);
|
||||
SendMessage(startMessage, NetDeliveryMethod.ReliableUnordered);
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
|
||||
|
||||
foreach (Client client in connectedClients)
|
||||
foreach (Client client in ConnectedClients)
|
||||
{
|
||||
client.inGame = true;
|
||||
|
||||
@@ -829,11 +702,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos);
|
||||
|
||||
for (int i = 0; i < connectedClients.Count; i++)
|
||||
for (int i = 0; i < ConnectedClients.Count; i++)
|
||||
{
|
||||
connectedClients[i].character = new Character(
|
||||
connectedClients[i].characterInfo, assignedWayPoints[i], true);
|
||||
connectedClients[i].character.GiveJobItems(assignedWayPoints[i]);
|
||||
ConnectedClients[i].Character = new Character(
|
||||
ConnectedClients[i].characterInfo, assignedWayPoints[i], true);
|
||||
ConnectedClients[i].Character.GiveJobItems(assignedWayPoints[i]);
|
||||
}
|
||||
|
||||
if (characterInfo != null)
|
||||
@@ -845,7 +718,23 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
UpdateCrewFrame();
|
||||
|
||||
//give some time for the clients to load the map
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
|
||||
gameStarted = true;
|
||||
|
||||
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
|
||||
|
||||
GameMain.GameScreen.Select();
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
}
|
||||
|
||||
private NetOutgoingMessage CreateStartMessage(int seed, Submarine selectedSub, GameModePreset selectedMode)
|
||||
{
|
||||
NetOutgoingMessage msg = server.CreateMessage();
|
||||
msg.Write((byte)PacketTypes.StartGame);
|
||||
|
||||
@@ -860,11 +749,13 @@ namespace Barotrauma.Networking
|
||||
|
||||
//msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes);
|
||||
|
||||
msg.Write((myCharacter == null) ? (byte)connectedClients.Count : (byte)(connectedClients.Count + 1));
|
||||
foreach (Client client in connectedClients)
|
||||
List<Client> playingClients = ConnectedClients.FindAll(c => c.Character != null);
|
||||
|
||||
msg.Write((myCharacter == null) ? (byte)playingClients.Count : (byte)(playingClients.Count + 1));
|
||||
foreach (Client client in playingClients)
|
||||
{
|
||||
msg.Write(client.ID);
|
||||
WriteCharacterData(msg, client.character.Name, client.character);
|
||||
WriteCharacterData(msg, client.Character.Name, client.Character);
|
||||
}
|
||||
|
||||
if (myCharacter != null)
|
||||
@@ -873,21 +764,7 @@ namespace Barotrauma.Networking
|
||||
WriteCharacterData(msg, myCharacter.Info.Name, Character.Controlled);
|
||||
}
|
||||
|
||||
SendMessage(msg, NetDeliveryMethod.ReliableUnordered, null);
|
||||
|
||||
UpdateCrewFrame();
|
||||
|
||||
//give some time for the clients to load the map
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
|
||||
gameStarted = true;
|
||||
|
||||
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
|
||||
|
||||
GameMain.GameScreen.Select();
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
private bool EndButtonHit(GUIButton button, object obj)
|
||||
@@ -909,7 +786,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
gameStarted = false;
|
||||
|
||||
if (connectedClients.Count > 0)
|
||||
if (ConnectedClients.Count > 0)
|
||||
{
|
||||
NetOutgoingMessage msg = server.CreateMessage();
|
||||
msg.Write((byte)PacketTypes.EndGame);
|
||||
@@ -920,9 +797,9 @@ namespace Barotrauma.Networking
|
||||
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableOrdered, 0);
|
||||
}
|
||||
|
||||
foreach (Client client in connectedClients)
|
||||
foreach (Client client in ConnectedClients)
|
||||
{
|
||||
client.character = null;
|
||||
client.Character = null;
|
||||
client.inGame = false;
|
||||
}
|
||||
}
|
||||
@@ -961,7 +838,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
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) DisconnectClient(client, msg, targetmsg);
|
||||
}
|
||||
|
||||
@@ -969,18 +846,18 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (client == null) return;
|
||||
|
||||
if (gameStarted && client.character != null)
|
||||
if (gameStarted && client.Character != null)
|
||||
{
|
||||
if (GameMain.GameSession!=null && GameMain.GameSession.gameMode!=null)
|
||||
{
|
||||
TraitorMode traitorMode = GameMain.GameSession.gameMode as TraitorMode;
|
||||
if (traitorMode!=null)
|
||||
{
|
||||
traitorMode.CharacterLeft(client.character);
|
||||
traitorMode.CharacterLeft(client.Character);
|
||||
}
|
||||
}
|
||||
|
||||
client.character.ClearInputs();
|
||||
client.Character.ClearInputs();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(msg)) msg = client.name + " has left the server";
|
||||
@@ -991,7 +868,7 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write(targetmsg);
|
||||
server.SendMessage(outmsg, client.Connection, NetDeliveryMethod.ReliableUnordered, 0);
|
||||
|
||||
connectedClients.Remove(client);
|
||||
ConnectedClients.Remove(client);
|
||||
|
||||
outmsg = server.CreateMessage();
|
||||
outmsg.Write((byte)PacketTypes.PlayerLeft);
|
||||
@@ -1014,24 +891,24 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
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;
|
||||
|
||||
crew.Add(c.character);
|
||||
crew.Add(c.Character);
|
||||
}
|
||||
|
||||
if (myCharacter != null) crew.Add(myCharacter);
|
||||
|
||||
CreateCrewFrame(crew);
|
||||
if (GameMain.GameSession!=null) GameMain.GameSession.CrewManager.CreateCrewFrame(crew);
|
||||
}
|
||||
|
||||
public void KickPlayer(string playerName, bool ban = false)
|
||||
{
|
||||
playerName = playerName.ToLower();
|
||||
|
||||
Client client = connectedClients.Find( c => c.name.ToLower() == playerName ||
|
||||
(c.character != null && c.character.Name.ToLower() == playerName));
|
||||
Client client = ConnectedClients.Find( c => c.name.ToLower() == playerName ||
|
||||
(c.Character != null && c.Character.Name.ToLower() == playerName));
|
||||
|
||||
if (client == null) return;
|
||||
|
||||
@@ -1056,10 +933,10 @@ namespace Barotrauma.Networking
|
||||
public void NewTraitor(out Character traitor, out Character target)
|
||||
{
|
||||
List<Character> characters = new List<Character>();
|
||||
foreach (Client client in connectedClients)
|
||||
foreach (Client client in ConnectedClients)
|
||||
{
|
||||
if (!client.inGame || client.character==null) continue;
|
||||
characters.Add(client.character);
|
||||
if (!client.inGame || client.Character==null) continue;
|
||||
characters.Add(client.Character);
|
||||
}
|
||||
if (myCharacter!= null) characters.Add(myCharacter);
|
||||
|
||||
@@ -1093,9 +970,9 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
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;
|
||||
break;
|
||||
}
|
||||
@@ -1133,7 +1010,7 @@ namespace Barotrauma.Networking
|
||||
int resentMessages = 0;
|
||||
|
||||
y += 110;
|
||||
foreach (Client c in connectedClients)
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
spriteBatch.DrawString(GUI.SmallFont, c.name + ":", new Vector2(x + 10, y), Color.White);
|
||||
spriteBatch.DrawString(GUI.SmallFont, "- avg roundtrip " + c.Connection.AverageRoundtripTime+" s", new Vector2(x + 20, y + 15), Color.White);
|
||||
@@ -1160,7 +1037,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
NetOutgoingMessage msg = server.CreateMessage();
|
||||
msg.Write((byte)PacketTypes.VoteStatus);
|
||||
Voting.WriteData(msg, connectedClients);
|
||||
Voting.WriteData(msg, ConnectedClients);
|
||||
|
||||
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0);
|
||||
}
|
||||
@@ -1191,14 +1068,12 @@ namespace Barotrauma.Networking
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool SelectCrewCharacter(GUIComponent component, object obj)
|
||||
public override bool SelectCrewCharacter(GUIComponent component, object obj)
|
||||
{
|
||||
base.SelectCrewCharacter(component, obj);
|
||||
|
||||
var characterFrame = crewFrame.FindChild("selectedcharacter");
|
||||
var characterFrame = component.Parent.Parent.FindChild("selectedcharacter");
|
||||
|
||||
Character character = obj as Character;
|
||||
if (obj == null) return false;
|
||||
if (character == null) return false;
|
||||
|
||||
if (character != myCharacter)
|
||||
{
|
||||
@@ -1225,9 +1100,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
List<Client> recipients = new List<Client>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
foreach (Client c in recipients)
|
||||
@@ -1271,7 +1146,7 @@ namespace Barotrauma.Networking
|
||||
if (jobPrefab != null) jobPreferences.Add(jobPrefab);
|
||||
}
|
||||
|
||||
foreach (Client c in connectedClients)
|
||||
foreach (Client c in ConnectedClients)
|
||||
{
|
||||
if (c.Connection != message.SenderConnection) continue;
|
||||
|
||||
@@ -1298,7 +1173,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
private void AssignJobs()
|
||||
{
|
||||
List<Client> unassigned = new List<Client>(connectedClients);
|
||||
List<Client> unassigned = new List<Client>(ConnectedClients);
|
||||
|
||||
int[] assignedClientCount = new int[JobPrefab.List.Count];
|
||||
|
||||
@@ -1424,7 +1299,7 @@ namespace Barotrauma.Networking
|
||||
int bitCount = Rand.Int(100);
|
||||
for (int i = 0; i < bitCount; i++)
|
||||
{
|
||||
msg.Write((Rand.Int(2) == 0) ? true : false);
|
||||
msg.Write(Rand.Int(2) == 0);
|
||||
}
|
||||
SendMessage(msg, (Rand.Int(2) == 0) ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.Unreliable, null);
|
||||
|
||||
@@ -1442,7 +1317,7 @@ namespace Barotrauma.Networking
|
||||
public string name;
|
||||
public int ID;
|
||||
|
||||
public Character character;
|
||||
public Character Character;
|
||||
public CharacterInfo characterInfo;
|
||||
public NetConnection Connection { get; set; }
|
||||
public string version;
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public bool AutoRestart
|
||||
{
|
||||
get { return (connectedClients.Count == 0) ? false : autoRestart; }
|
||||
get { return (ConnectedClients.Count == 0) ? false : autoRestart; }
|
||||
set
|
||||
{
|
||||
autoRestart = value;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public static string MasterServerUrl = GameMain.Config.MasterServerUrl;
|
||||
|
||||
//if a character is further than this from the sub, the server will ignore it
|
||||
//if a Character is further than this from the sub, the server will ignore it
|
||||
//(in sim units)
|
||||
public const float CharacterIgnoreDistance = 100.0f;
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@ namespace Barotrauma.Networking
|
||||
|
||||
Vote, VoteStatus,
|
||||
|
||||
ResendRequest, ReliableMessage, LatestMessageID
|
||||
ResendRequest, ReliableMessage, LatestMessageID,
|
||||
|
||||
Spectate
|
||||
}
|
||||
|
||||
enum VoteType
|
||||
@@ -56,10 +58,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
public int Port;
|
||||
|
||||
private bool crewFrameOpen;
|
||||
private GUIButton crewButton;
|
||||
protected GUIFrame crewFrame;
|
||||
|
||||
protected bool gameStarted;
|
||||
|
||||
protected Character myCharacter;
|
||||
@@ -117,8 +115,6 @@ namespace Barotrauma.Networking
|
||||
chatMsgBox.Font = GUI.SmallFont;
|
||||
chatMsgBox.OnEnterPressed = EnterChatMessage;
|
||||
|
||||
crewButton = new GUIButton(new Rectangle(chatBox.Rect.Right-80, chatBox.Rect.Y-30, 80, 20), "Crew", GUI.Style, inGameHUD);
|
||||
crewButton.OnClicked = ToggleCrewFrame;
|
||||
|
||||
Voting = new Voting();
|
||||
}
|
||||
@@ -159,66 +155,6 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
protected void CreateCrewFrame(List<Character> crew)
|
||||
{
|
||||
int width = 600, height = 400;
|
||||
|
||||
crewFrame = new GUIFrame(new Rectangle(GameMain.GraphicsWidth / 2 - width / 2, GameMain.GraphicsHeight / 2 - height / 2, width, height), GUI.Style);
|
||||
crewFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
|
||||
GUIListBox crewList = new GUIListBox(new Rectangle(0, 0, 280, 300), Color.White * 0.7f, GUI.Style, crewFrame);
|
||||
crewList.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||
crewList.OnSelected = SelectCrewCharacter;
|
||||
|
||||
foreach (Character character in crew)
|
||||
{
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, crewList);
|
||||
frame.UserData = character;
|
||||
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
frame.Color = (myCharacter == character) ? Color.Gold * 0.2f : Color.Transparent;
|
||||
frame.HoverColor = Color.LightGray * 0.5f;
|
||||
frame.SelectedColor = Color.Gold * 0.5f;
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(40, 0, 0, 25),
|
||||
character.Info.Name + " ("+character.Info.Job.Name+")",
|
||||
Color.Transparent, Color.White,
|
||||
Alignment.Left, Alignment.Left,
|
||||
null, frame);
|
||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||
|
||||
new GUIImage(new Rectangle(-10, 0, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame);
|
||||
}
|
||||
|
||||
var closeButton = new GUIButton(new Rectangle(0,0, 80, 20), "Close", Alignment.BottomCenter, GUI.Style, crewFrame);
|
||||
closeButton.OnClicked = ToggleCrewFrame;
|
||||
}
|
||||
|
||||
protected virtual bool SelectCrewCharacter(GUIComponent component, object obj)
|
||||
{
|
||||
Character character = obj as Character;
|
||||
if (obj == null) return false;
|
||||
|
||||
GUIComponent existingFrame = crewFrame.FindChild("selectedcharacter");
|
||||
if (existingFrame != null) crewFrame.RemoveChild(existingFrame);
|
||||
|
||||
var previewPlayer = new GUIFrame(
|
||||
new Rectangle(0,0, 230, 300),
|
||||
new Color(0.0f, 0.0f, 0.0f, 0.8f), Alignment.TopRight, GUI.Style, crewFrame);
|
||||
previewPlayer.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
previewPlayer.UserData = "selectedcharacter";
|
||||
|
||||
var infoFrame = character.Info.CreateInfoFrame(previewPlayer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ToggleCrewFrame(GUIButton button, object obj)
|
||||
{
|
||||
crewFrameOpen = !crewFrameOpen;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool EnterChatMessage(GUITextBox textBox, string message)
|
||||
@@ -251,7 +187,6 @@ namespace Barotrauma.Networking
|
||||
//float prevScroll = chatBox.BarScroll;
|
||||
|
||||
float prevSize = chatBox.BarSize;
|
||||
float oldScroll = chatBox.BarScroll;
|
||||
|
||||
msg.Padding = new Vector4(20, 0, 0, 0);
|
||||
chatBox.AddChild(msg);
|
||||
@@ -265,13 +200,13 @@ namespace Barotrauma.Networking
|
||||
|
||||
public virtual void Update(float deltaTime)
|
||||
{
|
||||
if (gameStarted)
|
||||
if (gameStarted && Screen.Selected == GameMain.GameScreen)
|
||||
{
|
||||
inGameHUD.Update(deltaTime);
|
||||
|
||||
if (crewFrameOpen) crewFrame.Update(deltaTime);
|
||||
//if (crewFrameOpen) crewFrame.Update(deltaTime);
|
||||
|
||||
if (Character.Controlled != null && Character.Controlled.IsDead)
|
||||
if (Character.Controlled == null || Character.Controlled.IsDead)
|
||||
{
|
||||
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
|
||||
GameMain.LightManager.LosEnabled = false;
|
||||
@@ -294,11 +229,14 @@ namespace Barotrauma.Networking
|
||||
|
||||
public virtual void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
{
|
||||
if (!gameStarted) return;
|
||||
if (!gameStarted && Screen.Selected != GameMain.GameScreen) return;
|
||||
|
||||
inGameHUD.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
if (crewFrameOpen) crewFrame.Draw(spriteBatch);
|
||||
public virtual bool SelectCrewCharacter(GUIComponent component, object obj)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void Disconnect() { }
|
||||
|
||||
Reference in New Issue
Block a user