Completely destroyed game

Looks like a lot more than just netcode is getting rewritten. Removing coroutines because there are better ways of handling asynchronous tasks, removing filestream because that's to be reimplemented later
This commit is contained in:
juanjp600
2016-08-30 19:59:14 -03:00
parent 37ffd64490
commit 9416eb64d7
31 changed files with 72 additions and 1437 deletions

View File

@@ -351,8 +351,6 @@ namespace Barotrauma.Networking
foreach (Client c in connectedClients)
{
if (c.FileStreamSender != null) UpdateFileTransfer(c, deltaTime);
//c.ReliableChannel.Update(deltaTime);
//slowly reset spam timers
@@ -365,7 +363,7 @@ namespace Barotrauma.Networking
{
try
{
ReadMessage(inc);
}
catch (Exception e)
{
@@ -382,7 +380,6 @@ namespace Barotrauma.Networking
{
if (gameStarted)
{
if (myCharacter != null && !myCharacter.IsDead) new NetworkEvent(NetworkEventType.EntityUpdate, myCharacter.ID, false);
float ignoreDistance = FarseerPhysics.ConvertUnits.ToDisplayUnits(NetConfig.CharacterIgnoreDistance);
@@ -394,7 +391,7 @@ namespace Barotrauma.Networking
c2 => c2.IsNetworkPlayer &&
Vector2.Distance(c2.WorldPosition, c.WorldPosition) < ignoreDistance))
{
new NetworkEvent(NetworkEventType.EntityUpdate, c.ID, false);
}
//todo: take multiple subs into account
@@ -407,8 +404,7 @@ namespace Barotrauma.Networking
if (server.ConnectionsCount > 0)
{
if (sparseUpdateTimer < DateTime.Now) SparseUpdate();
SendNetworkEvents();
}
updateTimer = DateTime.Now + updateInterval;
@@ -444,557 +440,12 @@ namespace Barotrauma.Networking
//if (FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) > NetConfig.CharacterIgnoreDistance) continue;
}
new NetworkEvent(NetworkEventType.ImportantEntityUpdate, c.ID, false);
}
sparseUpdateTimer = DateTime.Now + sparseUpdateInterval;
}
private void ReadMessage(NetIncomingMessage inc)
{
Client sender = connectedClients.Find(x => x.Connection == inc.SenderConnection);
switch (inc.MessageType)
{
case NetIncomingMessageType.ConnectionApproval:
HandleConnectionApproval(inc);
break;
case NetIncomingMessageType.StatusChanged:
Debug.WriteLine(inc.SenderConnection + " status changed. " + (NetConnectionStatus)inc.SenderConnection.Status);
if (inc.SenderConnection.Status == NetConnectionStatus.Disconnected)
{
var connectedClient = connectedClients.Find(c => c.Connection == inc.SenderConnection);
if (connectedClient != null && !disconnectedClients.Contains(connectedClient))
{
connectedClient.deleteDisconnectedTimer = NetConfig.DeleteDisconnectedTime;
disconnectedClients.Add(connectedClient);
}
DisconnectClient(inc.SenderConnection,
connectedClient != null ? connectedClient.name + " has disconnected" : "");
}
break;
case NetIncomingMessageType.Data:
byte packetType = inc.ReadByte();
if (sender == null)
{
var authUser = unauthenticatedClients.Find(c => c.Connection == inc.SenderConnection);
if (authUser == null)
{
unauthenticatedClients.Remove(authUser);
inc.SenderConnection.Disconnect("Disconnected");
}
else
{
CheckAuthentication(inc);
}
return;
}
switch (packetType)
{
case (byte)PacketTypes.NetworkEvent:
if (!gameStarted) break;
NetworkEvent.ReadMessage(inc, true);
break;
case (byte)PacketTypes.Chatmessage:
ReadChatMessage(inc);
break;
case (byte)PacketTypes.PlayerLeft:
DisconnectClient(inc.SenderConnection);
break;
case (byte)PacketTypes.StartGame:
sender.ReadyToStart = true;
break;
case (byte)PacketTypes.EndGame:
if (!sender.HasPermission(ClientPermissions.EndRound))
{
Log(sender.name+" attempted to end the round (insufficient permissions)", Color.Red);
}
else
{
Log("Round ended by " + sender.name, Color.Red);
EndGame();
}
break;
case (byte)PacketTypes.KickPlayer:
bool ban = inc.ReadBoolean();
string kickedName = inc.ReadString();
var kickedClient = connectedClients.Find(c => c.name.ToLowerInvariant() == kickedName.ToLowerInvariant());
if (kickedClient == null || kickedClient == sender) return;
if (ban && !sender.HasPermission(ClientPermissions.Ban))
{
Log(sender.name + " attempted to ban " + kickedClient.name + " (insufficient permissions)", Color.Red);
}
else if (!sender.HasPermission(ClientPermissions.Kick))
{
Log(sender.name + " attempted to kick " + kickedClient.name + " (insufficient permissions)", Color.Red);
}
else
{
KickClient(kickedClient, ban);
}
break;
case (byte)PacketTypes.CharacterInfo:
ReadCharacterData(inc);
break;
case (byte)PacketTypes.RequestFile:
if (!AllowFileTransfers)
{
SendCancelTransferMessage(sender, "File transfers have been disabled by the server.");
break;
}
byte fileType = inc.ReadByte();
string fileName = fileType == (byte)FileTransferMessageType.Cancel ? "" : inc.ReadString();
switch (fileType)
{
case (byte)FileTransferMessageType.Submarine:
var requestedSubmarine = Submarine.SavedSubmarines.Find(s => s.Name == fileName);
if (requestedSubmarine==null)
{
//todo: ei voi ladata
}
else
{
if (sender.FileStreamSender != null) sender.FileStreamSender.CancelTransfer();
var fileStreamSender = FileStreamSender.Create(sender.Connection, requestedSubmarine.FilePath, FileTransferMessageType.Submarine);
if (fileStreamSender != null) sender.FileStreamSender = fileStreamSender;
}
break;
case (byte)FileTransferMessageType.Cancel:
if (sender.FileStreamSender != null)
{
sender.FileStreamSender.CancelTransfer();
}
break;
default:
DebugConsole.ThrowError("Unknown file type was requested ("+fileType+")");
break;
}
break;
case (byte)PacketTypes.ResendRequest:
break;
case (byte)PacketTypes.LatestMessageID:
break;
case (byte)PacketTypes.Vote:
Voting.RegisterVote(inc, connectedClients);
if (Voting.AllowEndVoting && EndVoteMax > 0 &&
((float)EndVoteCount / (float)EndVoteMax) >= EndVoteRequiredRatio)
{
Log("Ending round by votes (" + EndVoteCount + "/" + (EndVoteMax - EndVoteCount) + ")", Color.Cyan);
EndGame();
}
break;
case (byte)PacketTypes.RequestNetLobbyUpdate:
UpdateNetLobby(null, null);
UpdateVoteStatus();
break;
case (byte)PacketTypes.SpectateRequest:
if (gameStarted && AllowSpectating)
{
var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
server.SendMessage(startMessage, inc.SenderConnection, NetDeliveryMethod.ReliableOrdered);
CoroutineManager.StartCoroutine(SyncSpectator(sender));
}
break;
}
break;
case NetIncomingMessageType.WarningMessage:
Debug.WriteLine(inc.ReadString());
break;
}
}
private void SendMessage(NetOutgoingMessage msg, NetDeliveryMethod deliveryMethod, NetConnection excludedConnection = null)
{
List<NetConnection> recipients = new List<NetConnection>();
foreach (Client client in connectedClients)
{
if (client.Connection != excludedConnection) recipients.Add(client.Connection);
}
if (recipients.Count == 0) return;
SendMessage(msg, deliveryMethod, recipients);
}
private void SendMessage(NetOutgoingMessage msg, NetDeliveryMethod deliveryMethod, List<NetConnection> recipients)
{
if (recipients == null) recipients = connectedClients.Select(c => c.Connection).ToList();
if (recipients.Count == 0) return;
server.SendMessage(msg, recipients, deliveryMethod, 0);
}
private void SendNetworkEvents(List<Client> recipients = null)
{
if (NetworkEvent.Events.Count == 0) return;
if (recipients == null)
{
recipients = connectedClients.FindAll(c => c.inGame);
}
if (recipients.Count == 0) return;
foreach (Client c in recipients)
{
var message = ComposeNetworkEventMessage(NetworkEventDeliveryMethod.ReliableLidgren, c.Connection);
if (message!=null)
{
server.SendMessage(message, c.Connection, NetDeliveryMethod.ReliableUnordered);
}
message = ComposeNetworkEventMessage(NetworkEventDeliveryMethod.Unreliable, c.Connection);
if (message != null)
{
server.SendMessage(message, c.Connection, NetDeliveryMethod.Unreliable, 0);
}
}
NetworkEvent.Events.Clear();
}
private IEnumerable<object> SyncSpectator(Client sender)
{
yield return new WaitForSeconds(3.0f);
foreach (Item item in Item.Remover.removedItems)
{
Item.Spawner.spawnItems.Remove(item);
}
SendItemRemoveMessage(Item.Remover.removedItems, new List<NetConnection>() { sender.Connection });
SendItemSpawnMessage(Item.Spawner.spawnItems, new List<NetConnection>() { sender.Connection });
yield return new WaitForSeconds(1.0f);
//save all the current events to a list and clear them
var existingEvents = new List<NetworkEvent>(NetworkEvent.Events);
NetworkEvent.Events.Clear();
foreach (Hull hull in Hull.hullList)
{
if (!hull.FireSources.Any() && hull.Volume < 0.01f) continue;
new NetworkEvent(NetworkEventType.ImportantEntityUpdate, hull.ID, false);
}
foreach (Character c in Character.CharacterList)
{
new NetworkEvent(NetworkEventType.EntityUpdate, c.ID, false);
if (c.Inventory != null) new NetworkEvent(NetworkEventType.InventoryUpdate, c.ID, false);
if (c.IsDead) new NetworkEvent(NetworkEventType.KillCharacter, c.ID, false);
}
foreach (Structure wall in Structure.WallList)
{
bool takenDamage = false;
for (int i = 0; i<wall.SectionCount; i++)
{
if (wall.SectionDamage(i) < wall.Health)
{
takenDamage = true;
break;
}
}
if (takenDamage) new NetworkEvent(NetworkEventType.ImportantEntityUpdate, wall.ID, false);
}
foreach (Item item in Item.ItemList)
{
for (int i = 0; i < item.components.Count; i++)
{
if (!item.components[i].NetworkUpdateSent) continue;
item.NewComponentEvent(item.components[i], false, true);
}
if (item.body == null || !item.body.Enabled || item.ParentInventory!=null) continue;
new NetworkEvent(NetworkEventType.DropItem, item.ID, false);
}
List<NetworkEvent> syncMessages = new List<NetworkEvent>(NetworkEvent.Events);
while (syncMessages.Any())
{
//put 5 events in the message and send them to the spectator
NetworkEvent.Events = syncMessages.GetRange(0, Math.Min(syncMessages.Count, 5));
SendNetworkEvents(new List<Client>() { sender });
syncMessages.RemoveRange(0, Math.Min(syncMessages.Count, 5));
//restore "normal" events
NetworkEvent.Events = existingEvents;
yield return new WaitForSeconds(0.1f);
//save "normal" events again
existingEvents = new List<NetworkEvent>(NetworkEvent.Events);
}
yield return new WaitForSeconds(0.1f);
SendRespawnManagerMsg(null, null, new List<NetConnection>() { sender.Connection });
yield return new WaitForSeconds(0.1f);
sender.inGame = true;
yield return CoroutineStatus.Success;
}
public bool StartGameClicked(GUIButton button, object obj)
{
Submarine selectedSub = null;
Submarine selectedShuttle = GameMain.NetLobbyScreen.SelectedShuttle;
if (Voting.AllowSubVoting)
{
selectedSub = Voting.HighestVoted<Submarine>(VoteType.Sub, connectedClients);
if (selectedSub == null) selectedSub = GameMain.NetLobbyScreen.SelectedSub;
}
else
{
selectedSub = GameMain.NetLobbyScreen.SelectedSub;
}
if (selectedSub == null)
{
GameMain.NetLobbyScreen.SubList.Flash();
return false;
}
if (selectedShuttle == null)
{
GameMain.NetLobbyScreen.ShuttleList.Flash();
return false;
}
GameModePreset selectedMode = Voting.HighestVoted<GameModePreset>(VoteType.Mode, connectedClients);
if (selectedMode == null) selectedMode = GameMain.NetLobbyScreen.SelectedMode;
if (selectedMode==null)
{
GameMain.NetLobbyScreen.ModeList.Flash();
return false;
}
CoroutineManager.StartCoroutine(WaitForPlayersReady(selectedSub, selectedShuttle, selectedMode), "WaitForPlayersReady");
return true;
}
private IEnumerable<object> WaitForPlayersReady(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode)
{
GameMain.NetLobbyScreen.StartButton.Enabled = false;
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.CanStartGame);
msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(selectedShuttle.Name);
msg.Write(selectedShuttle.MD5Hash.Hash);
SendMessage(msg, NetDeliveryMethod.ReliableUnordered);
connectedClients.ForEach(c => c.ReadyToStart = false);
float waitForResponseTimer = 5.0f;
while (connectedClients.Any(c => !c.ReadyToStart) && waitForResponseTimer > 0.0f)
{
waitForResponseTimer -= CoroutineManager.UnscaledDeltaTime;
yield return CoroutineStatus.Running;
}
float fileTransferTimeOut = 60.0f;
while (connectedClients.Any(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath) && fileTransferTimeOut>0.0f)
{
fileTransferTimeOut -= CoroutineManager.UnscaledDeltaTime;
if (GUIMessageBox.MessageBoxes.Count==0)
{
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);
messageBox.Buttons[0].UserData = connectedClients.Find(c => c.FileStreamSender != null && c.FileStreamSender.FilePath == selectedSub.FilePath);
messageBox.Buttons[0].OnClicked = (button, obj) =>
{
(button.UserData as Client).CancelTransfer();
return true;
};
}
}
GameMain.ShowLoading(StartGame(selectedSub, selectedShuttle, selectedMode), false);
yield return CoroutineStatus.Success;
}
private IEnumerable<object> StartGame(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode)
{
Item.Spawner.Clear();
Item.Remover.Clear();
GameMain.NetLobbyScreen.StartButton.Enabled = false;
GUIMessageBox.CloseAll();
AssignJobs(connectedClients);
roundStartSeed = DateTime.Now.Millisecond;
Rand.SetSyncedSeed(roundStartSeed);
GameMain.GameSession = new GameSession(selectedSub, "", selectedMode, Mission.MissionTypes[GameMain.NetLobbyScreen.MissionTypeIndex]);
GameMain.GameSession.StartShift(GameMain.NetLobbyScreen.LevelSeed);
GameServer.Log("Starting a new round...", Color.Cyan);
GameServer.Log("Submarine: " + selectedSub.Name, Color.Cyan);
GameServer.Log("Game mode: " + selectedMode.Name, Color.Cyan);
GameServer.Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, Color.Cyan);
if (AllowRespawn) respawnManager = new RespawnManager(this, selectedShuttle);
yield return CoroutineStatus.Running;
List<CharacterInfo> characterInfos = new List<CharacterInfo>();
foreach (Client client in connectedClients)
{
client.inGame = true;
if (client.characterInfo == null)
{
client.characterInfo = new CharacterInfo(Character.HumanConfigFile, client.name);
}
characterInfos.Add(client.characterInfo);
client.characterInfo.Job = new Job(client.assignedJob);
}
if (characterInfo != null)
{
characterInfo.Job = new Job(GameMain.NetLobbyScreen.JobPreferences[0]);
characterInfos.Add(characterInfo);
}
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSub);
for (int i = 0; i < connectedClients.Count; i++)
{
connectedClients[i].Character = Character.Create(
connectedClients[i].characterInfo, assignedWayPoints[i].WorldPosition, true, false);
connectedClients[i].Character.GiveJobItems(assignedWayPoints[i]);
GameMain.GameSession.CrewManager.characters.Add(connectedClients[i].Character);
}
if (characterInfo != null)
{
myCharacter = Character.Create(characterInfo, assignedWayPoints[assignedWayPoints.Length - 1].WorldPosition, false, false);
Character.Controlled = myCharacter;
myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]);
GameMain.GameSession.CrewManager.characters.Add(myCharacter);
}
var startMessage = CreateStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.gameMode.Preset);
SendMessage(startMessage, NetDeliveryMethod.ReliableOrdered);
//SendItemSpawnMessage(allItems, inventories);
yield return CoroutineStatus.Running;
UpdateCrewFrame();
if (TraitorsEnabled == YesNoMaybe.Yes ||
(TraitorsEnabled == YesNoMaybe.Maybe && Rand.Range(0.0f, 1.0f) < 0.5f))
{
TraitorManager = new TraitorManager(this);
}
else
{
TraitorManager = null;
}
//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();
if (myCharacter == null)
{
AddChatMessage("Press TAB to chat. Use ''d;'' to talk to dead players and spectators, "
+ "and ''player name;'' to only send the message to a specific player.", ChatMessageType.Server);
}
else
{
AddChatMessage("Press TAB to chat. Use ''r;'' to talk through the radio.", ChatMessageType.Server);
}
GameMain.NetLobbyScreen.StartButton.Enabled = true;
yield return CoroutineStatus.Success;
}
private NetOutgoingMessage CreateStartMessage(int seed, Submarine selectedSub, GameModePreset selectedMode)
{
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.StartGame);
msg.Write(seed);
msg.Write(GameMain.NetLobbyScreen.LevelSeed);
msg.Write((byte)GameMain.NetLobbyScreen.MissionTypeIndex);
msg.Write(selectedSub.Name);
msg.Write(selectedSub.MD5Hash.Hash);
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.Name);
msg.Write(GameMain.NetLobbyScreen.SelectedShuttle.MD5Hash.Hash);
msg.Write(selectedMode.Name);
msg.Write(AllowRespawn);
//msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes);
var characters = Character.CharacterList.FindAll(c => !(c is AICharacter) || c.SpawnedMidRound);
msg.Write((byte)characters.Count);
foreach (Character c in characters)
{
WriteCharacterData(msg, c.Name, c);
}
return msg;
}
public void EndGame()
{
if (!gameStarted) return;
@@ -1029,114 +480,14 @@ namespace Barotrauma.Networking
if (connectedClients.Count > 0)
{
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.EndGame);
msg.Write(endMessage);
if (server.ConnectionsCount > 0)
{
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableOrdered, 0);
}
foreach (Client client in connectedClients)
{
client.Character = null;
client.inGame = false;
}
}
CoroutineManager.StartCoroutine(EndCinematic());
}
public IEnumerable<object> EndCinematic()
{
float endPreviewLength = 10.0f;
var cinematic = new TransitionCinematic(Submarine.MainSub, GameMain.GameScreen.Cam, endPreviewLength);
float secondsLeft = endPreviewLength;
do
{
secondsLeft -= CoroutineManager.UnscaledDeltaTime;
yield return CoroutineStatus.Running;
} while (secondsLeft > 0.0f);
Submarine.Unload();
GameMain.NetLobbyScreen.Select();
yield return CoroutineStatus.Success;
}
public void SendRespawnManagerMsg(List<Character> spawnedCharacters = null, List<Item> spawnedItems = null, List<NetConnection> recipients = null)
{
if (respawnManager == null) return;
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.Respawn);
respawnManager.WriteNetworkEvent(msg, spawnedCharacters, spawnedItems);
SendMessage(msg, NetDeliveryMethod.ReliableUnordered, recipients);
}
private void DisconnectClient(NetConnection senderConnection, string msg = "", string targetmsg = "")
{
Client client = connectedClients.Find(x => x.Connection == senderConnection);
if (client == null) return;
DisconnectClient(client, msg, targetmsg);
}
private void DisconnectClient(Client client, string msg = "", string targetmsg = "")
{
if (client == null) return;
if (gameStarted && client.Character != null)
{
client.Character.ClearInputs();
client.Character.Kill(CauseOfDeath.Disconnected, true);
}
client.Character = null;
client.inGame = false;
if (string.IsNullOrWhiteSpace(msg)) msg = client.name + " has left the server";
if (string.IsNullOrWhiteSpace(targetmsg)) targetmsg = "You have left the server";
Log(msg, ChatMessage.MessageColor[(int)ChatMessageType.Server]);
client.Connection.Disconnect(targetmsg);
//notify other players about the disconnected client
NetOutgoingMessage outmsg = server.CreateMessage();
outmsg.Write((byte)PacketTypes.PlayerLeft);
outmsg.Write(client.ID);
outmsg.Write(msg);
GameMain.NetLobbyScreen.RemovePlayer(client.name);
if (server.Connections.Count > 0)
{
server.SendMessage(outmsg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0);
}
connectedClients.Remove(client);
if (client.FileStreamSender != null)
{
client.FileStreamSender.Dispose();
client.FileStreamSender = null;
}
AddChatMessage(msg, ChatMessageType.Server);
UpdateCrewFrame();
refreshMasterTimer = DateTime.Now;
}
private void UpdateCrewFrame()
{
List<Character> crew = new List<Character>();
@@ -1152,92 +503,7 @@ namespace Barotrauma.Networking
//if (GameMain.GameSession!=null) GameMain.GameSession.CrewManager.CreateCrewFrame(crew);
}
public override void KickPlayer(string playerName, bool ban)
{
playerName = playerName.ToLowerInvariant();
Client client = connectedClients.Find(c =>
c.name.ToLowerInvariant() == playerName ||
(c.Character != null && c.Character.Name.ToLowerInvariant() == playerName));
KickClient(client, ban);
}
public void KickClient(Client client, bool ban = false)
{
if (client == null) return;
if (ban)
{
DisconnectClient(client, client.name + " has been banned from the server", "You have been banned from the server");
banList.BanPlayer(client.name, client.Connection.RemoteEndPoint.Address.ToString());
}
else
{
DisconnectClient(client, client.name + " has been kicked from the server", "You have been kicked from the server");
}
}
private void UpdateFileTransfer(Client client, float deltaTime)
{
if (client.FileStreamSender == null) return;
var clientNameBox = GameMain.NetLobbyScreen.PlayerList.FindChild(client.name);
var clientInfo = clientNameBox.FindChild(client.FileStreamSender);
if (clientInfo == null)
{
clientNameBox.ClearChildren();
clientInfo = new GUIFrame(new Rectangle(0, 0, 180, 0), Color.Transparent, Alignment.TopRight, null, clientNameBox);
clientInfo.UserData = client.FileStreamSender;
new GUIProgressBar(new Rectangle(0, 4, 160, clientInfo.Rect.Height - 8), Color.Green, GUI.Style, 0.0f, Alignment.Left, clientInfo).IsHorizontal = true;
new GUITextBlock(new Rectangle(0, 2, 160, 0), "", GUI.Style, Alignment.TopLeft, Alignment.Left | Alignment.CenterY, clientInfo, true, GUI.SmallFont);
var cancelButton = new GUIButton(new Rectangle(20, 0, 14, 0), "X", Alignment.Right, GUI.Style, clientInfo);
cancelButton.OnClicked = (GUIButton button, object userdata) =>
{
(cancelButton.Parent.UserData as FileStreamSender).CancelTransfer();
return true;
};
}
else
{
var progressBar = clientInfo.GetChild<GUIProgressBar>();
progressBar.BarSize = client.FileStreamSender.Progress;
var progressText = clientInfo.GetChild<GUITextBlock>();
progressText.Text = client.FileStreamSender.FileName + " " +
MathUtils.GetBytesReadable(client.FileStreamSender.Sent) + " / " + MathUtils.GetBytesReadable(client.FileStreamSender.FileSize);
}
client.FileStreamSender.Update(deltaTime);
if (client.FileStreamSender.Status != FileTransferStatus.Sending &&
client.FileStreamSender.Status != FileTransferStatus.NotStarted)
{
if (client.FileStreamSender.Status == FileTransferStatus.Canceled)
{
SendCancelTransferMessage(client, "File transfer was canceled by the server.");
}
clientNameBox.RemoveChild(clientInfo);
client.FileStreamSender.Dispose();
client.FileStreamSender = null;
}
}
private void SendCancelTransferMessage(Client client, string message)
{
var outmsg = server.CreateMessage();
outmsg.Write((byte)PacketTypes.RequestFile);
outmsg.Write(false);
outmsg.Write(message);
server.SendMessage(outmsg, client.Connection, NetDeliveryMethod.ReliableUnordered);
}
public void NewTraitor(Character traitor, Character target)
{
Log(traitor.Name + " is the traitor and the target is " + target.Name, Color.Cyan);
@@ -1249,14 +515,7 @@ namespace Barotrauma.Networking
traitorClient = c;
break;
}
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.Traitor);
msg.Write(target.Info.Name);
if (server.Connections.Count > 0)
{
server.SendMessage(msg, traitorClient.Connection, NetDeliveryMethod.ReliableUnordered, 0);
}
}
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)