(965c31410a) Unstable v0.10.4.0
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
public enum ChatMessageType
|
||||
{
|
||||
Default, Error, Dead, Server, Radio, Private, Console, MessageBox, Order, ServerLog, ServerMessageBox
|
||||
Default, Error, Dead, Server, Radio, Private, Console, MessageBox, Order, ServerLog, ServerMessageBox, ServerMessageBoxInGame
|
||||
}
|
||||
|
||||
public enum PlayerConnectionChangeType { None = 0, Joined = 1, Kicked = 2, Disconnected = 3, Banned = 4 }
|
||||
@@ -61,6 +61,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public ChatMessageType Type;
|
||||
public PlayerConnectionChangeType ChangeType;
|
||||
public string IconStyle;
|
||||
|
||||
public readonly Character Sender;
|
||||
public readonly Client SenderClient;
|
||||
@@ -107,7 +108,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public static ChatMessage Create(string senderName, string text, ChatMessageType type, Character sender, Client client = null, PlayerConnectionChangeType changeType = PlayerConnectionChangeType.None)
|
||||
{
|
||||
return new ChatMessage(senderName, text, type, sender, client ?? GameMain.NetworkMember?.ConnectedClients?.Find(c => c.Character == sender), changeType);
|
||||
return new ChatMessage(senderName, text, type, sender, client ?? GameMain.NetworkMember?.ConnectedClients?.Find(c => c.Character != null && c.Character == sender), changeType);
|
||||
}
|
||||
|
||||
public static string GetChatMessageCommand(string message, out string messageWithoutCommand)
|
||||
@@ -151,7 +152,11 @@ namespace Barotrauma.Networking
|
||||
Hull sourceHull = sender == null ? null : Hull.FindHull(sender.WorldPosition);
|
||||
if (sourceHull != listenerHull)
|
||||
{
|
||||
if (Submarine.CheckVisibility(listener.SimPosition, sender.SimPosition) != null) dist = (dist + 100f) * obstructionmult;
|
||||
if ((sourceHull == null || !sourceHull.GetConnectedHulls(includingThis: false, searchDepth: 2, ignoreClosedGaps: true).Contains(listenerHull)) &&
|
||||
Submarine.CheckVisibility(listener.SimPosition, sender.SimPosition) != null)
|
||||
{
|
||||
dist = (dist + 100f) * obstructionmult;
|
||||
}
|
||||
}
|
||||
if (dist > range) { return 1.0f; }
|
||||
|
||||
@@ -188,14 +193,16 @@ namespace Barotrauma.Networking
|
||||
|
||||
public static string ApplyDistanceEffect(string message, ChatMessageType type, Character sender, Character receiver)
|
||||
{
|
||||
if (sender == null) return "";
|
||||
if (sender == null) { return ""; }
|
||||
|
||||
string spokenMsg = ApplyDistanceEffect(receiver, sender, message, SpeakRange * (1.0f - sender.SpeechImpediment / 100.0f), 3.0f);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ChatMessageType.Default:
|
||||
if (receiver != null && !receiver.IsDead)
|
||||
{
|
||||
return ApplyDistanceEffect(receiver, sender, message, SpeakRange * (1.0f - sender.SpeechImpediment / 100.0f), 3.0f);
|
||||
return spokenMsg;
|
||||
}
|
||||
break;
|
||||
case ChatMessageType.Radio:
|
||||
@@ -204,15 +211,15 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
var receiverItem = receiver.Inventory?.Items.FirstOrDefault(i => i?.GetComponent<WifiComponent>() != null);
|
||||
//character doesn't have a radio -> don't send
|
||||
if (receiverItem == null || !receiver.HasEquippedItem(receiverItem)) return "";
|
||||
if (receiverItem == null || !receiver.HasEquippedItem(receiverItem)) { return spokenMsg; }
|
||||
|
||||
var senderItem = sender.Inventory?.Items.FirstOrDefault(i => i?.GetComponent<WifiComponent>() != null);
|
||||
if (senderItem == null || !sender.HasEquippedItem(senderItem)) return "";
|
||||
if (senderItem == null || !sender.HasEquippedItem(senderItem)) { return spokenMsg; }
|
||||
|
||||
var receiverRadio = receiverItem.GetComponent<WifiComponent>();
|
||||
var senderRadio = senderItem.GetComponent<WifiComponent>();
|
||||
|
||||
if (!receiverRadio.CanReceive(senderRadio)) return "";
|
||||
if (!receiverRadio.CanReceive(senderRadio)) { return spokenMsg; }
|
||||
|
||||
string msg = ApplyDistanceEffect(receiverItem, senderItem, message, senderRadio.Range);
|
||||
if (sender.SpeechImpediment > 0.0f)
|
||||
@@ -222,7 +229,6 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
partial class Client : IDisposable
|
||||
{
|
||||
public const int MaxNameLength = 20;
|
||||
public const int MaxNameLength = 32;
|
||||
|
||||
public string Name; public UInt16 NameID;
|
||||
public byte ID;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Barotrauma.Networking;
|
||||
using Barotrauma.Items.Components;
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -58,10 +59,13 @@ namespace Barotrauma
|
||||
return null;
|
||||
}
|
||||
Item spawnedItem;
|
||||
if (Inventory != null)
|
||||
if (Inventory?.Owner != null)
|
||||
{
|
||||
spawnedItem = new Item(Prefab, Vector2.Zero, null);
|
||||
Inventory.TryPutItem(spawnedItem, null, spawnedItem.AllowedSlots);
|
||||
if (!Inventory.Owner.Removed && !Inventory.TryPutItem(spawnedItem, null, spawnedItem.AllowedSlots))
|
||||
{
|
||||
spawnedItem.SetTransform(FarseerPhysics.ConvertUnits.ToSimUnits(Inventory.Owner?.WorldPosition ?? Vector2.Zero), spawnedItem.body?.Rotation ?? 0.0f, findNewHull: false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -127,6 +131,8 @@ namespace Barotrauma
|
||||
|
||||
public readonly UInt16 OriginalID, OriginalInventoryID;
|
||||
|
||||
public readonly byte OriginalItemContainerIndex;
|
||||
|
||||
public readonly bool Remove = false;
|
||||
|
||||
public SpawnOrRemove(Entity entity, bool remove)
|
||||
@@ -136,6 +142,20 @@ namespace Barotrauma
|
||||
if (entity is Item item && item.ParentInventory?.Owner != null)
|
||||
{
|
||||
OriginalInventoryID = item.ParentInventory.Owner.ID;
|
||||
//find the index of the ItemContainer this item is inside to get the item to
|
||||
//spawn in the correct inventory in multi-inventory items like fabricators
|
||||
if (item.Container != null)
|
||||
{
|
||||
foreach (ItemComponent component in item.Container.Components)
|
||||
{
|
||||
if (component is ItemContainer container &&
|
||||
container.Inventory == item.ParentInventory)
|
||||
{
|
||||
OriginalItemContainerIndex = (byte)item.Container.GetComponentIndex(component);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Remove = remove;
|
||||
}
|
||||
|
||||
+3
-1
@@ -16,7 +16,9 @@ namespace Barotrauma.Networking
|
||||
Control,
|
||||
UpdateSkills,
|
||||
Combine,
|
||||
ExecuteAttack
|
||||
ExecuteAttack,
|
||||
Upgrade,
|
||||
AssignCampaignInteraction
|
||||
}
|
||||
|
||||
public readonly Entity Entity;
|
||||
|
||||
@@ -22,6 +22,12 @@ namespace Barotrauma.Networking
|
||||
(id2 > id1) && (id2 - id1 > ushort.MaxValue / 2);
|
||||
}
|
||||
|
||||
public static ushort Difference(ushort id1, ushort id2)
|
||||
{
|
||||
int diff = id2 > id1 ? id2 - id1 : id1 - id2;
|
||||
return (ushort)(diff > ushort.MaxValue / 2 ? ushort.MaxValue - diff : diff);
|
||||
}
|
||||
|
||||
public static ushort Clamp(ushort id, ushort min, ushort max)
|
||||
{
|
||||
if (IdMoreRecent(min, max))
|
||||
@@ -72,8 +78,13 @@ namespace Barotrauma.Networking
|
||||
Debug.Assert(IsValidId((ushort)1, (ushort)(ushort.MaxValue - 5), (ushort)10));
|
||||
Debug.Assert(!IsValidId((ushort)(ushort.MaxValue - 6), (ushort)(ushort.MaxValue - 5), (ushort)10));
|
||||
|
||||
Debug.Assert(IsValidId((ushort)0, (ushort)ushort.MaxValue - 100, (ushort)ushort.MaxValue));
|
||||
Debug.Assert(!IsValidId((ushort)(ushort.MaxValue - 101), (ushort)ushort.MaxValue - 100, (ushort)ushort.MaxValue));
|
||||
Debug.Assert(IsValidId((ushort)0, (ushort)(ushort.MaxValue - 100), (ushort)5));
|
||||
Debug.Assert(!IsValidId((ushort)(ushort.MaxValue - 101), (ushort)(ushort.MaxValue - 100), (ushort)ushort.MaxValue));
|
||||
|
||||
Debug.Assert(Difference((ushort)0, (ushort)56) == 56);
|
||||
Debug.Assert(Difference((ushort)56, (ushort)0) == 56);
|
||||
Debug.Assert(Difference((ushort)5, (ushort)(ushort.MaxValue - 101)) == 106);
|
||||
Debug.Assert(Difference((ushort)(ushort.MaxValue - 101), (ushort)5) == 106);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -24,9 +24,13 @@ namespace Barotrauma.Networking
|
||||
RESPONSE_STARTGAME, //tell the server whether you're ready to start
|
||||
SERVER_COMMAND, //tell the server to end a round or kick/ban someone (special permissions required)
|
||||
|
||||
EVENTMANAGER_RESPONSE,
|
||||
|
||||
REQUEST_STARTGAMEFINALIZE, //tell the server you're ready to finalize round initialization
|
||||
|
||||
ERROR //tell the server that an error occurred
|
||||
ERROR, //tell the server that an error occurred
|
||||
CREW
|
||||
|
||||
}
|
||||
enum ClientNetObject
|
||||
{
|
||||
@@ -71,7 +75,10 @@ namespace Barotrauma.Networking
|
||||
ENDGAME,
|
||||
|
||||
TRAITOR_MESSAGE,
|
||||
MISSION
|
||||
MISSION,
|
||||
EVENTACTION,
|
||||
RESET_UPGRADES, //inform the clients that the upgrades on the submarine have been reset
|
||||
CREW //anything related to managing bots in multiplayer
|
||||
}
|
||||
enum ServerNetObject
|
||||
{
|
||||
@@ -82,7 +89,7 @@ namespace Barotrauma.Networking
|
||||
CLIENT_LIST,
|
||||
ENTITY_POSITION,
|
||||
ENTITY_EVENT,
|
||||
ENTITY_EVENT_INITIAL,
|
||||
ENTITY_EVENT_INITIAL
|
||||
}
|
||||
|
||||
enum TraitorMessageType
|
||||
@@ -100,7 +107,10 @@ namespace Barotrauma.Networking
|
||||
Mode,
|
||||
EndRound,
|
||||
Kick,
|
||||
StartRound
|
||||
StartRound,
|
||||
PurchaseAndSwitchSub,
|
||||
PurchaseSub,
|
||||
SwitchSub
|
||||
}
|
||||
|
||||
enum DisconnectReason
|
||||
@@ -157,7 +167,7 @@ namespace Barotrauma.Networking
|
||||
protected TimeSpan updateInterval;
|
||||
protected DateTime updateTimer;
|
||||
|
||||
public int EndVoteCount, EndVoteMax;
|
||||
public int EndVoteCount, EndVoteMax, SubmarineVoteYesCount, SubmarineVoteNoCount, SubmarineVoteMax;
|
||||
|
||||
protected bool gameStarted;
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
//restore other items to full condition and recharge batteries
|
||||
item.Condition = item.Prefab.Health;
|
||||
item.Condition = item.MaxCondition;
|
||||
item.GetComponent<Repairable>()?.ResetDeterioration();
|
||||
var powerContainer = item.GetComponent<PowerContainer>();
|
||||
if (powerContainer != null)
|
||||
|
||||
@@ -642,6 +642,20 @@ namespace Barotrauma.Networking
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(false, true)]
|
||||
public bool DestructibleOutposts
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(true, true)]
|
||||
public bool KillableNPCs
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(true, true)]
|
||||
public bool BanAfterWrongPassword
|
||||
{
|
||||
@@ -669,6 +683,13 @@ namespace Barotrauma.Networking
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize("", true)]
|
||||
public string CampaignSubmarines
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
private YesNoMaybe traitorsEnabled;
|
||||
[Serialize(YesNoMaybe.No, true)]
|
||||
public YesNoMaybe TraitorsEnabled
|
||||
@@ -752,6 +773,20 @@ namespace Barotrauma.Networking
|
||||
private set;
|
||||
}
|
||||
|
||||
[Serialize(0.6f, true)]
|
||||
public float SubmarineVoteRequiredRatio
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Serialize(30f, true)]
|
||||
public float SubmarineVoteTimeout
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
[Serialize(0.6f, true)]
|
||||
public float KickVoteRequiredRatio
|
||||
{
|
||||
|
||||
@@ -11,6 +11,10 @@ namespace Barotrauma
|
||||
|
||||
public bool AllowEndVoting = true;
|
||||
|
||||
public bool VoteRunning = false;
|
||||
|
||||
public enum VoteState { None = 0, Started = 1, Running = 2, Passed = 3, Failed = 4 };
|
||||
|
||||
private List<Pair<object, int>> GetVoteList(VoteType voteType, List<Client> voters)
|
||||
{
|
||||
List<Pair<object, int>> voteList = new List<Pair<object, int>>();
|
||||
|
||||
Reference in New Issue
Block a user