Fixed propulsion applying force to _every limb except_ the ones it's supposed to, fixed pressure building up in enclosed rooms that are full of water, fixed netlobby displaying multiple votes for clients, progress on file transfer

This commit is contained in:
Regalis
2016-02-26 22:21:00 +02:00
parent 77d3d22810
commit 9f8f4e290e
19 changed files with 330 additions and 133 deletions
@@ -558,27 +558,12 @@ namespace Barotrauma
bool wallAttack = (wallAttackPos != Vector2.Zero && state == AiState.Attack); bool wallAttack = (wallAttackPos != Vector2.Zero && state == AiState.Attack);
message.Write(wallAttack); //message.Write(wallAttack);
//if (wallAttack)
//{
// Vector2 relativeWallAttackPos = wallAttackPos - Submarine.Loaded.SimPosition;
// message.WriteRangedSingle(MathHelper.Clamp(relativeWallAttackPos.X, -50.0f, 50.0f), -50.0f, 50.0f, 10);
// message.WriteRangedSingle(MathHelper.Clamp(relativeWallAttackPos.Y, -50.0f, 50.0f), -50.0f, 50.0f, 10);
//}
//message.Write(Velocity.X);
//message.Write(Velocity.Y);
//message.Write(Character.AnimController.RefLimb.SimPosition.X);
//message.Write(Character.AnimController.RefLimb.SimPosition.Y);
message.Write(MathUtils.AngleToByte(steeringManager.WanderAngle)); message.Write(MathUtils.AngleToByte(steeringManager.WanderAngle));
//message.WriteRangedSingle(MathHelper.Clamp(updateTargetsTimer,0.0f, UpdateTargetsInterval), 0.0f, UpdateTargetsInterval, 8);
//message.WriteRangedSingle(MathHelper.Clamp(raycastTimer, 0.0f, RaycastInterval), 0.0f, RaycastInterval, 8); coolDownTimer = MathHelper.Clamp(coolDownTimer, 0.0f, 30.0f);
//message.WriteRangedSingle(MathHelper.Clamp(coolDownTimer, 0.0f, attackCoolDown * 2.0f), 0.0f, attackCoolDown * 2.0f, 8); message.WriteRangedSingle(coolDownTimer, 0.0f, 30.0f, 8);
message.Write(targetEntity==null ? (ushort)0 : (targetEntity as Entity).ID); message.Write(targetEntity==null ? (ushort)0 : (targetEntity as Entity).ID);
} }
@@ -612,9 +597,8 @@ namespace Barotrauma
//targetPosition = new Vector2(message.ReadFloat(), message.ReadFloat()); //targetPosition = new Vector2(message.ReadFloat(), message.ReadFloat());
wanderAngle = MathUtils.ByteToAngle(message.ReadByte()); wanderAngle = MathUtils.ByteToAngle(message.ReadByte());
//updateTargetsTimer = message.ReadRangedSingle(0.0f, UpdateTargetsInterval, 8);
//raycastTimer = message.ReadRangedSingle(0.0f, RaycastInterval, 8); coolDownTimer = message.ReadRangedSingle(0.0f, 30.0f, 8);
//coolDownTimer = message.ReadRangedSingle(0.0f, attackCoolDown*2.0f, 8);
targetID = message.ReadUInt16(); targetID = message.ReadUInt16();
} }
@@ -629,14 +613,10 @@ namespace Barotrauma
return; return;
} }
//wallAttackPos = newWallAttackPos;
steeringManager.WanderAngle = wanderAngle; steeringManager.WanderAngle = wanderAngle;
//this.updateTargetsTimer = updateTargetsTimer;
//this.raycastTimer = raycastTimer;
//this.coolDownTimer = coolDownTimer;
if (targetID > 0) targetEntity = Entity.FindEntityByID(targetID) as IDamageable; if (targetID > 0) targetEntity = Entity.FindEntityByID(targetID) as IDamageable;
updateTargetsTimer = UpdateTargetsInterval;
} }
} }
@@ -647,14 +627,8 @@ namespace Barotrauma
//and if the target attacks the Character, the priority increases) //and if the target attacks the Character, the priority increases)
class AITargetMemory class AITargetMemory
{ {
//private AITarget target;
private float priority; private float priority;
//public AITarget Target
//{
// get { return target; }
//}
public float Priority public float Priority
{ {
get { return priority; } get { return priority; }
+2 -2
View File
@@ -10,9 +10,9 @@ namespace Barotrauma
class StatusEffect class StatusEffect
{ {
[Flags] [Flags]
public enum TargetType public enum TargetType
{ {
This = 1, Parent = 2, Character = 4, Contained = 8, Nearby = 16, UseTarget=32 This = 1, Parent = 2, Character = 4, Contained = 8, Nearby = 16, UseTarget = 32, Hull = 64
} }
private TargetType targetTypes; private TargetType targetTypes;
+17 -7
View File
@@ -304,24 +304,34 @@ namespace Barotrauma
return texture; return texture;
} }
public static bool DrawButton(SpriteBatch sb, Rectangle rect, string text, bool isHoldable = false) public static bool DrawButton(SpriteBatch sb, Rectangle rect, string text, Color color, bool isHoldable = false)
{ {
Color color = new Color(200, 200, 200);
bool clicked = false; bool clicked = false;
if (rect.Contains(PlayerInput.MousePosition)) if (rect.Contains(PlayerInput.MousePosition))
{ {
clicked = PlayerInput.LeftButtonHeld(); clicked = PlayerInput.LeftButtonHeld();
color = clicked ? new Color(100, 100, 100) : new Color(250, 250, 250); color = clicked ?
new Color((int)(color.R * 0.8f), (int)(color.G * 0.8f), (int)(color.B * 0.8f), color.A) :
new Color((int)(color.R * 1.2f), (int)(color.G * 1.2f), (int)(color.B * 1.2f), color.A);
if (!isHoldable) if (!isHoldable) clicked = PlayerInput.LeftButtonClicked();
clicked = PlayerInput.LeftButtonClicked();
} }
DrawRectangle(sb, rect, color, true); DrawRectangle(sb, rect, color, true);
sb.DrawString(Font, text, new Vector2(rect.X + 10, rect.Y + 10), Color.White);
Vector2 origin;
try
{
origin = Font.MeasureString(text)/2;
}
catch
{
origin = Vector2.Zero;
}
sb.DrawString(Font, text, new Vector2(rect.Center.X, rect.Center.Y) , Color.White, 0.0f, origin, 1.0f, SpriteEffects.None, 0.0f);
return clicked; return clicked;
} }
@@ -76,7 +76,7 @@ namespace Barotrauma.Items.Components
{ {
foreach (Limb limb in character.AnimController.Limbs) foreach (Limb limb in character.AnimController.Limbs)
{ {
if (limb.WearingItems.Find(w => w.WearableComponent.Item != this.item)==null) continue; if (limb.WearingItems.Find(w => w.WearableComponent.Item == this.item)==null) continue;
limb.body.ApplyForce(propulsion); limb.body.ApplyForce(propulsion);
} }
@@ -48,6 +48,24 @@ namespace Barotrauma.Items.Components
: base(item, element) : base(item, element)
{ {
IsActive = true; IsActive = true;
var button = new GUIButton(new Rectangle(160, 50, 30, 30), "-", GUI.Style, GuiFrame);
button.OnClicked = (GUIButton btn, object obj) =>
{
targetForce -= 1.0f;
item.NewComponentEvent(this, true, false);
return true;
};
button = new GUIButton(new Rectangle(200, 50, 30, 30), "+", GUI.Style, GuiFrame);
button.OnClicked = (GUIButton btn, object obj) =>
{
targetForce += 1.0f;
item.NewComponentEvent(this, true, false);
return true;
};
} }
public float CurrentVolume public float CurrentVolume
@@ -80,7 +98,7 @@ namespace Barotrauma.Items.Components
voltage = 0.0f; voltage = 0.0f;
} }
public override void DrawHUD(SpriteBatch spriteBatch, Character character) public override void DrawHUD(SpriteBatch spriteBatch, Character character)
{ {
//isActive = true; //isActive = true;
@@ -93,18 +111,7 @@ namespace Barotrauma.Items.Components
//GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true); //GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
spriteBatch.DrawString(GUI.Font, "Force: " + (int)(targetForce) + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White); spriteBatch.DrawString(GUI.Font, "Force: " + (int)(targetForce) + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 80, 40, 40), "-", true))
{
targetForce -= 1.0f;
item.NewComponentEvent(this, true, false);
}
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 30, 40, 40), "+", true))
{
targetForce += 1.0f;
item.NewComponentEvent(this, true, false);
}
} }
public override void UpdateBroken(float deltaTime, Camera cam) public override void UpdateBroken(float deltaTime, Camera cam)
+42 -5
View File
@@ -154,9 +154,12 @@ namespace Barotrauma
if (GameMain.DebugDraw) if (GameMain.DebugDraw)
{ {
Vector2 center = new Vector2(WorldRect.X + rect.Width / 2.0f, -(WorldRect.Y - rect.Height/ 2.0f)); Vector2 center = new Vector2(WorldRect.X + rect.Width / 2.0f, -(WorldRect.Y - rect.Height/ 2.0f));
GUI.DrawLine(sb, center, center + flowForce/10.0f, Color.Red);
GUI.DrawLine(sb, center + Vector2.One * 5.0f, center + lerpedFlowForce / 10.0f + Vector2.One * 5.0f, Color.Orange);
GUI.DrawLine(sb, center, center + new Vector2(flowForce.X, -flowForce.Y)/10.0f, Color.Red);
GUI.DrawLine(sb, center + Vector2.One * 5.0f, center + new Vector2(lerpedFlowForce.X, -lerpedFlowForce.Y) / 10.0f + Vector2.One * 5.0f, Color.Orange);
} }
if (!editing || !ShowGaps) return; if (!editing || !ShowGaps) return;
@@ -288,6 +291,25 @@ namespace Barotrauma
} }
} }
if (flowTargetHull != null && lerpedFlowForce != Vector2.Zero)
{
foreach (Character character in Character.CharacterList)
{
if (character.AnimController.CurrentHull != flowTargetHull) continue;
foreach (Limb limb in character.AnimController.Limbs)
{
if (!limb.inWater) continue;
float dist = Vector2.Distance(limb.WorldPosition, WorldPosition);
if (dist > lerpedFlowForce.Length()) continue;
limb.body.ApplyForce(lerpedFlowForce / dist/10.0f);
}
}
}
} }
@@ -444,7 +466,7 @@ namespace Barotrauma
if (open > 0.0f) if (open > 0.0f)
{ {
if (hull1.Volume>hull1.FullVolume && hull2.Volume>hull2.FullVolume) if (hull1.Volume > hull1.FullVolume - Hull.MaxCompress && hull2.Volume > hull2.FullVolume - Hull.MaxCompress)
{ {
float avgLethality = (hull1.LethalPressure + hull2.LethalPressure) / 2.0f; float avgLethality = (hull1.LethalPressure + hull2.LethalPressure) / 2.0f;
hull1.LethalPressure = avgLethality; hull1.LethalPressure = avgLethality;
@@ -497,21 +519,31 @@ namespace Barotrauma
lowerSurface = rect.Y; lowerSurface = rect.Y;
if (hull1.Volume < hull1.FullVolume - Hull.MaxCompress && if (hull1.Volume < hull1.FullVolume - Hull.MaxCompress &&
hull1.Surface > -rect.Y) hull1.Surface < rect.Y)
{ {
float vel = (rect.Y + hull1.Surface) * 0.03f;
if (rect.X > hull1.Rect.X + hull1.Rect.Width / 2.0f) if (rect.X > hull1.Rect.X + hull1.Rect.Width / 2.0f)
{ {
float vel = ((rect.Y - rect.Height / 2) - (hull1.Surface + hull1.WaveY[hull1.WaveY.Length - 1])) * 0.1f;
hull1.WaveVel[hull1.WaveY.Length - 1] += vel; hull1.WaveVel[hull1.WaveY.Length - 1] += vel;
hull1.WaveVel[hull1.WaveY.Length - 2] += vel; hull1.WaveVel[hull1.WaveY.Length - 2] += vel;
} }
else else
{ {
float vel = ((rect.Y - rect.Height / 2) - (hull1.Surface + hull1.WaveY[0])) * 0.1f;
hull1.WaveVel[0] += vel; hull1.WaveVel[0] += vel;
hull1.WaveVel[1] += vel; hull1.WaveVel[1] += vel;
} }
} }
else
{
hull1.LethalPressure += (Submarine.Loaded != null && Submarine.Loaded.AtDamageDepth) ? 100.0f * deltaTime : 10.0f * deltaTime;
}
} }
else else
{ {
@@ -523,7 +555,12 @@ namespace Barotrauma
{ {
flowForce = new Vector2(0.0f, delta); flowForce = new Vector2(0.0f, delta);
} }
if (hull1.Volume >= hull1.FullVolume - Hull.MaxCompress)
{
hull1.LethalPressure += (Submarine.Loaded != null && Submarine.Loaded.AtDamageDepth) ? 100.0f * deltaTime : 10.0f * deltaTime;
}
} }
} }
private void UpdateOxygen() private void UpdateOxygen()
-5
View File
@@ -433,11 +433,6 @@ namespace Barotrauma
update = false; update = false;
} }
} }
else
{
LethalPressure += ( Submarine.Loaded!=null && Submarine.Loaded.AtDamageDepth) ? 100.0f*deltaTime : 10.0f * deltaTime;
}
} }
public void Extinquish(float deltaTime, float amount, Vector2 position) public void Extinquish(float deltaTime, float amount, Vector2 position)
+3 -1
View File
@@ -590,7 +590,7 @@ namespace Barotrauma
{ {
try try
{ {
filePaths.AddRange(Directory.GetDirectories(subDirectory)); filePaths.AddRange(Directory.GetFiles(subDirectory).ToList());
} }
catch (Exception e) catch (Exception e)
{ {
@@ -604,6 +604,8 @@ namespace Barotrauma
//Map savedMap = new Map(mapPath); //Map savedMap = new Map(mapPath);
SavedSubmarines.Add(new Submarine(path)); SavedSubmarines.Add(new Submarine(path));
} }
if (GameMain.NetLobbyScreen!=null) GameMain.NetLobbyScreen.UpdateSubList();
} }
private XDocument OpenDoc(string file) private XDocument OpenDoc(string file)
@@ -1,11 +1,14 @@
using Lidgren.Network; using Lidgren.Network;
using System; using System;
using System.IO; using System.IO;
using System.Text.RegularExpressions;
namespace Barotrauma.Networking namespace Barotrauma.Networking
{ {
class FileStreamReceiver : IDisposable class FileStreamReceiver : IDisposable
{ {
const int MaxFileSize = 1000000;
public delegate void OnFinished(FileStreamReceiver fileStreamReceiver); public delegate void OnFinished(FileStreamReceiver fileStreamReceiver);
private OnFinished onFinished; private OnFinished onFinished;
@@ -18,12 +21,17 @@ namespace Barotrauma.Networking
private string filePath; private string filePath;
private FileTransferType fileType; private FileTransferType fileType;
public string FileName public string FileName
{ {
get; get;
private set; private set;
} }
public string FilePath
{
get { return filePath; }
}
public ulong FileSize public ulong FileSize
{ {
@@ -35,12 +43,23 @@ namespace Barotrauma.Networking
get { return received; } get { return received; }
} }
public FileTransferType FileType
{
get { return fileType; }
}
public FileTransferStatus Status public FileTransferStatus Status
{ {
get; get;
private set; private set;
} }
public string ErrorMessage
{
get;
private set;
}
public float BytesPerSecond public float BytesPerSecond
{ {
get; get;
@@ -49,13 +68,13 @@ namespace Barotrauma.Networking
public float Progress public float Progress
{ {
get { return length / (float)received; } get { return (float)received / (float)length; }
} }
public FileStreamReceiver(NetClient client, string filePath, FileTransferType fileType, OnFinished onFinished) public FileStreamReceiver(NetClient client, string filePath, FileTransferType fileType, OnFinished onFinished)
{ {
client = client; this.client = client;
this.filePath = filePath; this.filePath = filePath;
this.fileType = fileType; this.fileType = fileType;
@@ -78,8 +97,75 @@ namespace Barotrauma.Networking
} }
} }
private bool ValidateInitialData(byte type, string fileName, ulong fileSize)
{
if (fileSize > MaxFileSize)
{
ErrorMessage = "File too large (" + MathUtils.GetBytesReadable((long)fileSize) + ")";
Status = FileTransferStatus.Error;
return false;
}
if (type != (byte)fileType)
{
ErrorMessage = "Unexpected file type ''"+type+"'' (expected "+fileType+")";
Status = FileTransferStatus.Error;
return false;
}
if (!Regex.Match(fileName, @"^[\w\- ]+[\w\-. ]*$").Success)
{
ErrorMessage = "Illegal characters in file name ''"+fileName+"''";
Status = FileTransferStatus.Error;
return false;
}
switch (type)
{
case (byte)FileTransferType.Submarine:
if (Path.GetExtension(fileName) != ".sub")
{
ErrorMessage = "Wrong file extension ''" + Path.GetExtension(fileName)+"''! (Expected .sub)";
Status = FileTransferStatus.Error;
return false;
}
break;
}
return true;
}
public void DeleteFile()
{
string file = Path.Combine(filePath, FileName);
writeStream.Flush();
writeStream.Close();
writeStream.Dispose();
writeStream = null;
Status = FileTransferStatus.Canceled;
if (File.Exists(file))
{
try
{
File.Delete(file);
}
catch (Exception e)
{
DebugConsole.ThrowError("Couldn't delete file ''" + file + "''!", e);
}
}
}
private void TryReadMessage(NetIncomingMessage inc) private void TryReadMessage(NetIncomingMessage inc)
{ {
if (Status == FileTransferStatus.Error ||
Status == FileTransferStatus.Finished ||
Status == FileTransferStatus.Canceled) return;
//int chunkLen = inc.LengthBytes; //int chunkLen = inc.LengthBytes;
if (length == 0) if (length == 0)
{ {
@@ -90,14 +176,17 @@ namespace Barotrauma.Networking
} }
byte fileTypeByte = inc.ReadByte(); byte fileTypeByte = inc.ReadByte();
if (fileTypeByte != (byte)fileType)
{
Status = FileTransferStatus.Error;
return;
}
length = inc.ReadUInt64(); length = inc.ReadUInt64();
FileName = inc.ReadString(); FileName = inc.ReadString();
if (!ValidateInitialData(fileTypeByte, FileName, length))
{
Status = FileTransferStatus.Error;
if (onFinished != null) onFinished(this);
return;
}
writeStream = new FileStream(Path.Combine(filePath, FileName), FileMode.Create, FileAccess.Write, FileShare.None); writeStream = new FileStream(Path.Combine(filePath, FileName), FileMode.Create, FileAccess.Write, FileShare.None);
timeStarted = Environment.TickCount; timeStarted = Environment.TickCount;
@@ -106,6 +195,15 @@ namespace Barotrauma.Networking
return; return;
} }
if (received + (ulong)inc.LengthBytes > length*1.1f)
{
ErrorMessage = "Receiving more data than expected (> " + MathUtils.GetBytesReadable((long)(received + (ulong)inc.LengthBytes)) + ")";
Status = FileTransferStatus.Error;
if (onFinished != null) onFinished(this);
return;
}
byte[] all = inc.ReadBytes(inc.LengthBytes - inc.PositionInBytes); byte[] all = inc.ReadBytes(inc.LengthBytes - inc.PositionInBytes);
received += (ulong)all.Length; received += (ulong)all.Length;
writeStream.Write(all, 0, all.Length); writeStream.Write(all, 0, all.Length);
@@ -117,6 +215,7 @@ namespace Barotrauma.Networking
Status = FileTransferStatus.Receiving; Status = FileTransferStatus.Receiving;
if (received >= length) if (received >= length)
{ {
Status = FileTransferStatus.Finished; Status = FileTransferStatus.Finished;
@@ -133,9 +232,12 @@ namespace Barotrauma.Networking
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
writeStream.Flush(); if (writeStream != null)
writeStream.Close(); {
writeStream.Dispose(); writeStream.Flush();
writeStream.Close();
writeStream.Dispose();
}
} }
} }
@@ -6,7 +6,7 @@ namespace Barotrauma.Networking
{ {
enum FileTransferStatus enum FileTransferStatus
{ {
NotStarted, Sending, Receiving, Finished, Error NotStarted, Sending, Receiving, Finished, Error, Canceled
} }
enum FileTransferType enum FileTransferType
@@ -22,6 +22,8 @@ namespace Barotrauma.Networking
private byte[] tempBuffer; private byte[] tempBuffer;
private NetConnection connection; private NetConnection connection;
float waitTimer;
private FileTransferType fileType; private FileTransferType fileType;
@@ -56,7 +58,7 @@ namespace Barotrauma.Networking
chunkLen = connection.Peer.Configuration.MaximumTransmissionUnit - 100; chunkLen = connection.Peer.Configuration.MaximumTransmissionUnit - 100;
tempBuffer = new byte[chunkLen]; tempBuffer = new byte[chunkLen];
sentOffset = 0; sentOffset = 0;
FileName = fileName; FileName = fileName;
this.fileType = fileType; this.fileType = fileType;
@@ -64,10 +66,13 @@ namespace Barotrauma.Networking
Status = FileTransferStatus.NotStarted; Status = FileTransferStatus.NotStarted;
} }
public void Update() public void Update(float deltaTime)
{ {
if (inputStream == null) return; if (inputStream == null) return;
waitTimer -= deltaTime;
if (waitTimer > 0.0f) return;
if (!connection.CanSendImmediately(NetDeliveryMethod.ReliableOrdered, 1)) return; if (!connection.CanSendImmediately(NetDeliveryMethod.ReliableOrdered, 1)) return;
// send another part of the file! // send another part of the file!
@@ -98,6 +103,8 @@ namespace Barotrauma.Networking
connection.SendMessage(message, NetDeliveryMethod.ReliableOrdered, 1); connection.SendMessage(message, NetDeliveryMethod.ReliableOrdered, 1);
sentOffset += sendBytes; sentOffset += sendBytes;
waitTimer = connection.AverageRoundtripTime + 0.05f;
//Program.Output("Sent " + m_sentOffset + "/" + m_inputStream.Length + " bytes to " + m_connection); //Program.Output("Sent " + m_sentOffset + "/" + m_inputStream.Length + " bytes to " + m_connection);
if (remaining - sendBytes <= 0) if (remaining - sendBytes <= 0)
+29 -9
View File
@@ -697,6 +697,25 @@ namespace Barotrauma.Networking
{ {
base.Draw(spriteBatch); base.Draw(spriteBatch);
if (fileStreamReceiver != null &&
(fileStreamReceiver.Status == FileTransferStatus.Receiving || fileStreamReceiver.Status == FileTransferStatus.NotStarted))
{
Vector2 pos = Screen.Selected == GameMain.NetLobbyScreen ?
new Vector2(GameMain.NetLobbyScreen.SubList.Rect.X, GameMain.NetLobbyScreen.SubList.Rect.Bottom+5) : new Vector2(GameMain.GraphicsWidth / 2 - 200, 10);
GUI.DrawString(spriteBatch, pos, "Downloading " + fileStreamReceiver.FileName, Color.White);
GUI.DrawString(spriteBatch, pos + Vector2.UnitX*300,
MathUtils.GetBytesReadable((long)fileStreamReceiver.Received) + " / " + MathUtils.GetBytesReadable((long)fileStreamReceiver.FileSize), Color.White);
GUI.DrawProgressBar(spriteBatch, new Vector2(pos.X, -pos.Y - 20), new Vector2(300, 15), fileStreamReceiver.Progress, Color.Green);
if (GUI.DrawButton(spriteBatch, new Rectangle((int)pos.X + 310, (int)pos.Y + 20, 100, 15), "Cancel", new Color(0.88f, 0.25f, 0.15f, 0.8f)))
{
fileStreamReceiver.DeleteFile();
fileStreamReceiver.Dispose();
fileStreamReceiver = null;
}
}
if (!GameMain.DebugDraw) return; if (!GameMain.DebugDraw) return;
int width = 200, height = 300; int width = 200, height = 300;
@@ -711,27 +730,28 @@ namespace Barotrauma.Networking
spriteBatch.DrawString(GUI.SmallFont, "Sent bytes: " + client.Statistics.SentBytes, new Vector2(x + 10, y + 75), Color.White); spriteBatch.DrawString(GUI.SmallFont, "Sent bytes: " + client.Statistics.SentBytes, new Vector2(x + 10, y + 75), Color.White);
spriteBatch.DrawString(GUI.SmallFont, "Sent packets: " + client.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White); spriteBatch.DrawString(GUI.SmallFont, "Sent packets: " + client.Statistics.SentPackets, new Vector2(x + 10, y + 90), Color.White);
if (fileStreamReceiver!=null)
{
GUI.DrawString(spriteBatch, new Vector2(GameMain.GraphicsWidth / 2 - 100, 20), "Downloading "+fileStreamReceiver.FileName, Color.White);
GUI.DrawString(spriteBatch, new Vector2(GameMain.GraphicsWidth / 2 - 100, 20),
MathUtils.GetBytesReadable((long)fileStreamReceiver.Received)+" / "+MathUtils.GetBytesReadable((long)fileStreamReceiver.FileSize), Color.White);
GUI.DrawProgressBar(spriteBatch, new Vector2(GameMain.GraphicsWidth / 2 - 100, 20), new Vector2(200, 15), fileStreamReceiver.Progress, Color.Green);
}
} }
private void OnFileReceived(FileStreamReceiver receiver) private void OnFileReceived(FileStreamReceiver receiver)
{ {
if (receiver.Status == FileTransferStatus.Error) if (receiver.Status == FileTransferStatus.Error)
{ {
new GUIMessageBox("Error while receiving file from server", receiver.ErrorMessage);
receiver.DeleteFile();
} }
else if (receiver.Status == FileTransferStatus.Finished) else if (receiver.Status == FileTransferStatus.Finished)
{ {
new GUIMessageBox("Download finished", "File ''"+receiver.FileName+"'' was downloaded succesfully."); new GUIMessageBox("Download finished", "File ''"+receiver.FileName+"'' was downloaded succesfully.");
switch (receiver.FileType)
{
case FileTransferType.Submarine:
Submarine.Preload();
break;
}
} }
receiver.Dispose();
fileStreamReceiver = null; fileStreamReceiver = null;
} }
+15 -6
View File
@@ -312,9 +312,9 @@ namespace Barotrauma.Networking
foreach (Client c in ConnectedClients) foreach (Client c in ConnectedClients)
{ {
if (c.FileStreamSender!=null) if (c.FileStreamSender!=null && Rand.Range(0.0f, 1.0f)<0.01f)
{ {
c.FileStreamSender.Update(); c.FileStreamSender.Update(deltaTime);
if (c.FileStreamSender.Status == FileTransferStatus.Finished || if (c.FileStreamSender.Status == FileTransferStatus.Finished ||
c.FileStreamSender.Status == FileTransferStatus.Error) c.FileStreamSender.Status == FileTransferStatus.Error)
@@ -516,8 +516,17 @@ namespace Barotrauma.Networking
ReadCharacterData(inc); ReadCharacterData(inc);
break; break;
case (byte)PacketTypes.RequestFile: case (byte)PacketTypes.RequestFile:
string fileName = inc.ReadString();
if (!allowFileTransfers)
{
var outmsg = server.CreateMessage();
outmsg.Write((byte)PacketTypes.RequestFile);
outmsg.Write(false);
break;
}
byte fileType = inc.ReadByte(); byte fileType = inc.ReadByte();
string fileName = inc.ReadString();
switch (fileType) switch (fileType)
{ {
@@ -552,11 +561,11 @@ namespace Barotrauma.Networking
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)
{ {
Log("Ending round by votes ("+EndVoteCount+"/"+(EndVoteMax-EndVoteCount)+")", Color.Cyan); Log("Ending round by votes (" + EndVoteCount + "/" + (EndVoteMax - EndVoteCount) + ")", Color.Cyan);
EndButtonHit(null,null); EndButtonHit(null, null);
} }
break; break;
case (byte)PacketTypes.RequestNetLobbyUpdate: case (byte)PacketTypes.RequestNetLobbyUpdate:
@@ -45,6 +45,8 @@ namespace Barotrauma.Networking
private bool saveServerLogs = true; private bool saveServerLogs = true;
private bool allowFileTransfers = true;
public bool AutoRestart public bool AutoRestart
{ {
get { return (ConnectedClients.Count == 0) ? false : autoRestart; } get { return (ConnectedClients.Count == 0) ? false : autoRestart; }
+1 -1
View File
@@ -9,7 +9,7 @@ namespace Barotrauma.Networking
{ {
class ServerLog class ServerLog
{ {
const int LinesPerFile = 300; const int LinesPerFile = 800;
public const string SavePath = "ServerLogs"; public const string SavePath = "ServerLogs";
+16 -8
View File
@@ -207,6 +207,11 @@ namespace Barotrauma
return dictionary; return dictionary;
} }
public static Dictionary<string, ObjectProperty> InitProperties(object obj)
{
return InitProperties(obj, null);
}
public static Dictionary<string, ObjectProperty> InitProperties(object obj, XElement element) public static Dictionary<string, ObjectProperty> InitProperties(object obj, XElement element)
{ {
var properties = TypeDescriptor.GetProperties(obj.GetType()).Cast<PropertyDescriptor>(); var properties = TypeDescriptor.GetProperties(obj.GetType()).Cast<PropertyDescriptor>();
@@ -226,16 +231,19 @@ namespace Barotrauma
} }
} }
//go through all the attributes in the xml element if (element!=null)
//and set the value of the matching property if it is initializable
foreach (XAttribute attribute in element.Attributes())
{ {
ObjectProperty property = null; //go through all the attributes in the xml element
if (!dictionary.TryGetValue(attribute.Name.ToString().ToLower(), out property)) continue; //and set the value of the matching property if it is initializable
if (!property.Attributes.OfType<HasDefaultValue>().Any()) continue; foreach (XAttribute attribute in element.Attributes())
property.TrySetValue(attribute.Value); {
ObjectProperty property = null;
if (!dictionary.TryGetValue(attribute.Name.ToString().ToLower(), out property)) continue;
if (!property.Attributes.OfType<HasDefaultValue>().Any()) continue;
property.TrySetValue(attribute.Value);
}
} }
return dictionary; return dictionary;
} }
+42 -23
View File
@@ -187,24 +187,7 @@ namespace Barotrauma
voteText.UserData = "subvotes"; voteText.UserData = "subvotes";
voteText.Visible = false; voteText.Visible = false;
if (Submarine.SavedSubmarines.Count > 0) UpdateSubList();
{
foreach (Submarine sub in Submarine.SavedSubmarines)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
sub.Name, GUI.Style,
Alignment.Left, Alignment.Left,
subList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = sub;
}
}
else
{
DebugConsole.ThrowError("No saved submarines found!");
return;
}
columnX += columnWidth + 20; columnX += columnWidth + 20;
@@ -213,8 +196,7 @@ namespace Barotrauma
new GUITextBlock(new Rectangle(columnX, 120, 0, 30), "Game mode: ", GUI.Style, infoFrame); new GUITextBlock(new Rectangle(columnX, 120, 0, 30), "Game mode: ", GUI.Style, infoFrame);
modeList = new GUIListBox(new Rectangle(columnX, 150, columnWidth, infoFrame.Rect.Height - 150 - 80), GUI.Style, infoFrame); modeList = new GUIListBox(new Rectangle(columnX, 150, columnWidth, infoFrame.Rect.Height - 150 - 80), GUI.Style, infoFrame);
modeList.OnSelected = VotableClicked; modeList.OnSelected = VotableClicked;
voteText = new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 30), "Votes: ", GUI.Style, Alignment.TopLeft, Alignment.TopRight, infoFrame); voteText = new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 30), "Votes: ", GUI.Style, Alignment.TopLeft, Alignment.TopRight, infoFrame);
voteText.UserData = "modevotes"; voteText.UserData = "modevotes";
voteText.Visible = false; voteText.Visible = false;
@@ -533,6 +515,33 @@ namespace Barotrauma
return true; return true;
} }
public void UpdateSubList()
{
if (subList == null) return;
subList.ClearChildren();
if (Submarine.SavedSubmarines.Count > 0)
{
foreach (Submarine sub in Submarine.SavedSubmarines)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
sub.Name, GUI.Style,
Alignment.Left, Alignment.Left,
subList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = sub;
}
}
else
{
DebugConsole.ThrowError("No saved submarines found!");
return;
}
}
public bool VotableClicked(GUIComponent component, object userData) public bool VotableClicked(GUIComponent component, object userData)
{ {
if (GameMain.Client == null) return false; if (GameMain.Client == null) return false;
@@ -921,7 +930,7 @@ namespace Barotrauma
if (sub == null) if (sub == null)
{ {
var requestFileBox = new GUIMessageBox("Submarine not found!", "The submarine ''" + subName + "'' has been selected by the server. " var requestFileBox = new GUIMessageBox("Submarine not found!", "The submarine ''" + subName + "'' has been selected by the server. "
+"Matching file not found in your map folder. Do you want to download the file from the server host?", new string[] { "Yes", "No" }); +"Matching file not found in your map folder. Do you want to download the file from the server host?", new string[] { "Yes", "No" }, 400, 300);
requestFileBox.Buttons[0].UserData = subName; requestFileBox.Buttons[0].UserData = subName;
requestFileBox.Buttons[0].OnClicked += requestFileBox.Close; requestFileBox.Buttons[0].OnClicked += requestFileBox.Close;
requestFileBox.Buttons[0].OnClicked += (GUIButton button, object userdata) => requestFileBox.Buttons[0].OnClicked += (GUIButton button, object userdata) =>
@@ -938,10 +947,20 @@ namespace Barotrauma
{ {
if (sub.MD5Hash.Hash != md5Hash) if (sub.MD5Hash.Hash != md5Hash)
{ {
new GUIMessageBox("Submarine not found!", var requestFileBox = new GUIMessageBox("Submarine not found!",
"Your version of the map file ''" + sub.Name + "'' doesn't match the server's version!" "Your version of the map file ''" + sub.Name + "'' doesn't match the server's version!"
+"\nYour file: " + sub.Name + "(MD5 hash : " + sub.MD5Hash.Hash + ")" +"\nYour file: " + sub.Name + "(MD5 hash : " + sub.MD5Hash.Hash + ")"
+"\nServer's file: " + subName + "(MD5 hash : " + md5Hash + ")"); +"\nServer's file: " + subName + "(MD5 hash : " + md5Hash + ")\n"
+"Do you want to download the file from the server host?", new string[] { "Yes", "No" }, 400, 300);
requestFileBox.Buttons[0].UserData = subName;
requestFileBox.Buttons[0].OnClicked += requestFileBox.Close;
requestFileBox.Buttons[0].OnClicked += (GUIButton button, object userdata) =>
{
GameMain.Client.RequestFile(userdata.ToString(), FileTransferType.Submarine);
return true;
};
requestFileBox.Buttons[1].OnClicked += requestFileBox.Close;
return false; return false;
} }
else else
+7 -2
View File
@@ -128,7 +128,7 @@ namespace Barotrauma
voteText.UserData = "votes"; voteText.UserData = "votes";
} }
voteText.Text = votes.ToString(); voteText.Text = votes == 0 ? "" : votes.ToString();
} }
} }
@@ -233,6 +233,11 @@ namespace Barotrauma
AllowSubVoting = msg.ReadBoolean(); AllowSubVoting = msg.ReadBoolean();
if (allowSubVoting) if (allowSubVoting)
{ {
foreach (Submarine sub in Submarine.SavedSubmarines)
{
SetVoteText(GameMain.NetLobbyScreen.SubList, sub, 0);
}
int votableCount = msg.ReadByte(); int votableCount = msg.ReadByte();
for (int i = 0; i < votableCount; i++) for (int i = 0; i < votableCount; i++)
{ {
@@ -252,7 +257,7 @@ namespace Barotrauma
int votes = msg.ReadByte(); int votes = msg.ReadByte();
string modeName = msg.ReadString(); string modeName = msg.ReadString();
GameModePreset mode = GameModePreset.list.Find(m => m.Name == modeName); GameModePreset mode = GameModePreset.list.Find(m => m.Name == modeName);
SetVoteText(GameMain.NetLobbyScreen.SubList, mode, votes); SetVoteText(GameMain.NetLobbyScreen.ModeList, mode, votes);
} }
} }
@@ -169,7 +169,7 @@ namespace Barotrauma
string maxPlayersStr = (arguments.Length > 5) ? arguments[5] : ""; string maxPlayersStr = (arguments.Length > 5) ? arguments[5] : "";
string hasPassWordStr = (arguments.Length > 5) ? arguments[5] : ""; string hasPassWordStr = (arguments.Length > 6) ? arguments[6] : "";
var serverFrame = new GUIFrame(new Rectangle(0, 0, 0, 20), (i % 2 == 0) ? Color.Transparent : Color.White * 0.2f, null, serverList); var serverFrame = new GUIFrame(new Rectangle(0, 0, 0, 20), (i % 2 == 0) ? Color.Transparent : Color.White * 0.2f, null, serverList);
serverFrame.UserData = IP + ":" + port; serverFrame.UserData = IP + ":" + port;
Binary file not shown.