Banning players, networkevent refactoring, wire syncing bugfixes, wrenches can be used as a melee weapon, proper error message for invalid IPs, drawing held items in correct position, fixed client crashing if sending a chatmessage while connection is lost
This commit is contained in:
@@ -98,6 +98,7 @@
|
|||||||
<Compile Include="Source\Map\Lights\LightSource.cs" />
|
<Compile Include="Source\Map\Lights\LightSource.cs" />
|
||||||
<Compile Include="Source\Map\LocationType.cs" />
|
<Compile Include="Source\Map\LocationType.cs" />
|
||||||
<Compile Include="Source\Map\SubmarineHull.cs" />
|
<Compile Include="Source\Map\SubmarineHull.cs" />
|
||||||
|
<Compile Include="Source\Networking\BanList.cs" />
|
||||||
<Compile Include="Source\Networking\NetConfig.cs" />
|
<Compile Include="Source\Networking\NetConfig.cs" />
|
||||||
<Compile Include="Source\Networking\NetStats.cs" />
|
<Compile Include="Source\Networking\NetStats.cs" />
|
||||||
<Compile Include="Source\Networking\ReliableSender.cs" />
|
<Compile Include="Source\Networking\ReliableSender.cs" />
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
<Body width="39" height="18" density="5"/>
|
<Body width="39" height="18" density="5"/>
|
||||||
|
|
||||||
<Holdable slots="Any,RightHand,LeftHand"
|
<Holdable slots="Any,BothHands"
|
||||||
aimpos="50,0" handle1="-12,4"/>
|
aimpos="50,0" handle1="-12,4"/>
|
||||||
|
|
||||||
<RepairTool structurefixamount="-2.0" limbfixamount="-0.5" range="100" barrelpos="19,8" particles="plasma">
|
<RepairTool structurefixamount="-2.0" limbfixamount="-0.5" range="100" barrelpos="19,8" particles="plasma">
|
||||||
@@ -110,7 +110,7 @@
|
|||||||
<Body width="30" height="8" density="20"/>
|
<Body width="30" height="8" density="20"/>
|
||||||
|
|
||||||
<Holdable slots="Any,RightHand,LeftHand"
|
<Holdable slots="Any,RightHand,LeftHand"
|
||||||
holdangle="30" handle1="0,0"/>
|
holdangle="30" handle1="-5,0"/>
|
||||||
|
|
||||||
</Item>
|
</Item>
|
||||||
|
|
||||||
@@ -124,8 +124,10 @@
|
|||||||
|
|
||||||
<Body width="30" height="8" density="20"/>
|
<Body width="30" height="8" density="20"/>
|
||||||
|
|
||||||
<Holdable slots="Any,RightHand,LeftHand"
|
<MeleeWeapon slots="Any,RightHand,LeftHand"
|
||||||
holdangle="30" handle1="0,0"/>
|
aimpos="50,0" handle1="0,0" holdangle="30" reload="1.0">
|
||||||
|
<Attack damage="5" stun="0.2" damagetype="Blunt" sound="Content/Items/Weapons/smack.ogg"/>
|
||||||
|
</MeleeWeapon>
|
||||||
|
|
||||||
</Item>
|
</Item>
|
||||||
|
|
||||||
|
|||||||
@@ -405,7 +405,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (Info.PickedItemIDs.Any())
|
if (Info.PickedItemIDs.Any())
|
||||||
{
|
{
|
||||||
foreach (int id in Info.PickedItemIDs)
|
foreach (ushort id in Info.PickedItemIDs)
|
||||||
{
|
{
|
||||||
Item item = FindEntityByID(id) as Item;
|
Item item = FindEntityByID(id) as Item;
|
||||||
if (item == null) continue;
|
if (item == null) continue;
|
||||||
@@ -627,7 +627,7 @@ namespace Barotrauma
|
|||||||
selectedCharacter = null;
|
selectedCharacter = null;
|
||||||
|
|
||||||
if (createNetworkEvent)
|
if (createNetworkEvent)
|
||||||
new NetworkEvent(NetworkEventType.SelectCharacter, ID, true, -1);
|
new NetworkEvent(NetworkEventType.SelectCharacter, ID, true, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1075,7 +1075,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (GameMain.Server != null)
|
if (GameMain.Server != null)
|
||||||
{
|
{
|
||||||
new NetworkEvent(NetworkEventType.KillCharacter, ID, false);
|
new NetworkEvent(NetworkEventType.KillCharacter, ID, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameMain.GameSession != null)
|
if (GameMain.GameSession != null)
|
||||||
@@ -1088,12 +1088,12 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (type == NetworkEventType.PickItem)
|
if (type == NetworkEventType.PickItem)
|
||||||
{
|
{
|
||||||
message.Write((int)data);
|
message.Write((ushort)data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (type== NetworkEventType.SelectCharacter)
|
else if (type== NetworkEventType.SelectCharacter)
|
||||||
{
|
{
|
||||||
message.Write((int)data);
|
message.Write((ushort)data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (type == NetworkEventType.KillCharacter)
|
else if (type == NetworkEventType.KillCharacter)
|
||||||
@@ -1115,10 +1115,10 @@ namespace Barotrauma
|
|||||||
GetInputState(InputType.SecondaryHeld)) || LargeUpdateTimer <= 0;
|
GetInputState(InputType.SecondaryHeld)) || LargeUpdateTimer <= 0;
|
||||||
|
|
||||||
message.Write(hasInputs);
|
message.Write(hasInputs);
|
||||||
|
message.Write((float)NetTime.Now);
|
||||||
|
|
||||||
if (!hasInputs) return true;
|
if (!hasInputs) return true;
|
||||||
|
|
||||||
message.Write((float)NetTime.Now);
|
|
||||||
|
|
||||||
// Write byte = move direction
|
// Write byte = move direction
|
||||||
//message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -10.0f, 10.0f), -10.0f, 10.0f, 8);
|
//message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -10.0f, 10.0f), -10.0f, 10.0f, 8);
|
||||||
@@ -1168,7 +1168,7 @@ namespace Barotrauma
|
|||||||
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer,0.0f,60.0f), 0.0f, 60.0f, 8);
|
message.WriteRangedSingle(MathHelper.Clamp(AnimController.StunTimer,0.0f,60.0f), 0.0f, 60.0f, 8);
|
||||||
message.Write((byte)((health/maxHealth)*255.0f));
|
message.Write((byte)((health/maxHealth)*255.0f));
|
||||||
|
|
||||||
LargeUpdateTimer = 50;
|
LargeUpdateTimer = 30;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1189,16 +1189,9 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine("**************** PickItem networkevent received");
|
System.Diagnostics.Debug.WriteLine("**************** PickItem networkevent received");
|
||||||
|
|
||||||
int itemId = -1;
|
ushort itemId = 0;
|
||||||
|
|
||||||
try
|
itemId = message.ReadUInt16();
|
||||||
{
|
|
||||||
itemId = message.ReadInt32();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine("item id: "+itemId);
|
System.Diagnostics.Debug.WriteLine("item id: "+itemId);
|
||||||
|
|
||||||
@@ -1212,8 +1205,8 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
else if (type == NetworkEventType.SelectCharacter)
|
else if (type == NetworkEventType.SelectCharacter)
|
||||||
{
|
{
|
||||||
int characterId = message.ReadInt32();
|
ushort characterId = message.ReadUInt16();
|
||||||
if (characterId==-1)
|
if (characterId==0)
|
||||||
{
|
{
|
||||||
DeselectCharacter(false);
|
DeselectCharacter(false);
|
||||||
}
|
}
|
||||||
@@ -1254,14 +1247,14 @@ namespace Barotrauma
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
bool hasInputs = message.ReadBoolean();
|
bool hasInputs = message.ReadBoolean();
|
||||||
if (!hasInputs)
|
sendingTime = message.ReadFloat();
|
||||||
|
|
||||||
|
if (!hasInputs && sendingTime > LastNetworkUpdate)
|
||||||
{
|
{
|
||||||
ClearInputs();
|
ClearInputs();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendingTime = message.ReadFloat();
|
|
||||||
|
|
||||||
actionKeyState = message.ReadBoolean();
|
actionKeyState = message.ReadBoolean();
|
||||||
secondaryKeyState = message.ReadBoolean();
|
secondaryKeyState = message.ReadBoolean();
|
||||||
|
|
||||||
@@ -1321,7 +1314,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cursorPos = Position + new Vector2(1000.0f, 0.0f) * dir;
|
cursorPosition = Position + new Vector2(1000.0f, 0.0f) * dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLargeUpdate)
|
if (isLargeUpdate)
|
||||||
@@ -1383,9 +1376,7 @@ namespace Barotrauma
|
|||||||
catch { return; }
|
catch { return; }
|
||||||
|
|
||||||
|
|
||||||
Limb torso = AnimController.GetLimb(LimbType.Torso);
|
AnimController.RefLimb.body.TargetPosition = pos;
|
||||||
if (torso == null) torso = AnimController.GetLimb(LimbType.Head);
|
|
||||||
torso.body.TargetPosition = pos;
|
|
||||||
|
|
||||||
LargeUpdateTimer = 0;
|
LargeUpdateTimer = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -865,7 +865,13 @@ namespace Barotrauma
|
|||||||
Vector2 bodyVelocity = torso.body.LinearVelocity / 60.0f;
|
Vector2 bodyVelocity = torso.body.LinearVelocity / 60.0f;
|
||||||
|
|
||||||
item.body.ResetDynamics();
|
item.body.ResetDynamics();
|
||||||
item.SetTransform(MathUtils.SmoothStep(item.body.SimPosition, transformedHoldPos + bodyVelocity, 0.5f), itemAngle);
|
|
||||||
|
Vector2 currItemPos = (character.SelectedItems[0]==item) ?
|
||||||
|
rightHand.pullJoint.WorldAnchorA - transformedHandlePos[0] :
|
||||||
|
leftHand.pullJoint.WorldAnchorA - transformedHandlePos[1];
|
||||||
|
item.SetTransform(currItemPos, itemAngle);
|
||||||
|
|
||||||
|
//item.SetTransform(MathUtils.SmoothStep(item.body.SimPosition, transformedHoldPos + bodyVelocity, 0.5f), itemAngle);
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -219,7 +219,6 @@ namespace Barotrauma
|
|||||||
MainMenuScreen = new MainMenuScreen(this);
|
MainMenuScreen = new MainMenuScreen(this);
|
||||||
LobbyScreen = new LobbyScreen();
|
LobbyScreen = new LobbyScreen();
|
||||||
|
|
||||||
NetLobbyScreen = new NetLobbyScreen();
|
|
||||||
ServerListScreen = new ServerListScreen();
|
ServerListScreen = new ServerListScreen();
|
||||||
|
|
||||||
EditMapScreen = new EditMapScreen();
|
EditMapScreen = new EditMapScreen();
|
||||||
|
|||||||
@@ -161,9 +161,9 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
//PutItem(items[i], i, false, false);
|
//PutItem(items[i], i, false, false);
|
||||||
Inventory otherInventory = items[i].inventory;
|
Inventory otherInventory = items[i].inventory;
|
||||||
if (otherInventory!=null)
|
if (otherInventory!=null && createNetworkEvent)
|
||||||
{
|
{
|
||||||
new Networking.NetworkEvent(Networking.NetworkEventType.InventoryUpdate, otherInventory.Owner.ID, true);
|
new Networking.NetworkEvent(Networking.NetworkEventType.InventoryUpdate, otherInventory.Owner.ID, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
combined = true;
|
combined = true;
|
||||||
@@ -269,11 +269,71 @@ namespace Barotrauma
|
|||||||
slotRect.X = (int)slotPositions[i].X;
|
slotRect.X = (int)slotPositions[i].X;
|
||||||
slotRect.Y = (int)slotPositions[i].Y;
|
slotRect.Y = (int)slotPositions[i].Y;
|
||||||
|
|
||||||
|
bool multiSlot = false;
|
||||||
|
//skip if the item is in multiple slots
|
||||||
|
if (items[i]!=null)
|
||||||
|
{
|
||||||
|
for (int n = 0; n < capacity; n++ )
|
||||||
|
{
|
||||||
|
if (i==n || items[n] != items[i]) continue;
|
||||||
|
multiSlot = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (multiSlot) continue;
|
||||||
|
|
||||||
|
UpdateSlot(spriteBatch, slotRect, i, items[i], i > 4);
|
||||||
|
|
||||||
UpdateSlot(spriteBatch, slotRect, i, items[i], i>4);
|
|
||||||
if (draggingItem!=null && draggingItem == items[i]) draggingItemSlot = slotRect;
|
if (draggingItem!=null && draggingItem == items[i]) draggingItemSlot = slotRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < capacity; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Rectangle multiSlotRect = Rectangle.Empty;
|
||||||
|
bool multiSlot = false;
|
||||||
|
|
||||||
|
//check if the item is in multiple slots
|
||||||
|
if (items[i] != null)
|
||||||
|
{
|
||||||
|
slotRect.X = (int)slotPositions[i].X;
|
||||||
|
slotRect.Y = (int)slotPositions[i].Y;
|
||||||
|
slotRect.Width = 40;
|
||||||
|
slotRect.Height = 40;
|
||||||
|
|
||||||
|
for (int n = 0; n < capacity; n++)
|
||||||
|
{
|
||||||
|
if (items[n] != items[i]) continue;
|
||||||
|
|
||||||
|
if (!multiSlot && i > n) break;
|
||||||
|
|
||||||
|
if (i!=n)
|
||||||
|
{
|
||||||
|
multiSlot = true;
|
||||||
|
slotRect = Rectangle.Union(
|
||||||
|
new Rectangle((int)slotPositions[n].X, (int)slotPositions[n].Y, rectWidth, rectHeight), slotRect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!multiSlot) continue;
|
||||||
|
|
||||||
|
UpdateSlot(spriteBatch, slotRect, i, items[i], i > 4);
|
||||||
|
|
||||||
|
//if (multiSlot && i == first)
|
||||||
|
//{
|
||||||
|
// multiSlotPos = multiSlotPos / count;
|
||||||
|
// items[i].Sprite.Draw(spriteBatch, new Vector2(multiSlotPos.X + rectWidth / 2, multiSlotPos.Y + rectHeight / 2), items[i].Color);
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
slotRect.Width = rectWidth;
|
||||||
|
slotRect.Height = rectHeight;
|
||||||
|
|
||||||
|
|
||||||
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition))
|
if (draggingItem != null && !draggingItemSlot.Contains(PlayerInput.MousePosition))
|
||||||
{
|
{
|
||||||
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
|
if (PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed)
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
attached = true;
|
attached = true;
|
||||||
|
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ac.HoldItem(deltaTime, item, handlePos, new Vector2(hitPos, 0.0f), aimPos, false, 0.0f);
|
ac.HoldItem(deltaTime, item, handlePos, new Vector2(hitPos, 0.0f), aimPos, false, holdAngle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -93,10 +93,18 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
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 + 30, 40, 40), "+", true)) targetForce += 1.0f;
|
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 30, 40, 40), "+", true))
|
||||||
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 80, 40, 40), "-", true)) targetForce -= 1.0f;
|
{
|
||||||
|
targetForce += 1.0f;
|
||||||
|
item.NewComponentEvent(this, true, false);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
item.NewComponentEvent(this, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdateBroken(float deltaTime, Camera cam)
|
public override void UpdateBroken(float deltaTime, Camera cam)
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ namespace Barotrauma.Items.Components
|
|||||||
targetLevel = null;
|
targetLevel = null;
|
||||||
IsActive = !IsActive;
|
IsActive = !IsActive;
|
||||||
if (!IsActive) currPowerConsumption = 0.0f;
|
if (!IsActive) currPowerConsumption = 0.0f;
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
spriteBatch.DrawString(GUI.Font, "Pumping speed: " + (int)flowPercentage + " %", new Vector2(x + 20, y + 80), Color.White);
|
spriteBatch.DrawString(GUI.Font, "Pumping speed: " + (int)flowPercentage + " %", new Vector2(x + 20, y + 80), Color.White);
|
||||||
@@ -125,12 +125,12 @@ namespace Barotrauma.Items.Components
|
|||||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "OUT", false))
|
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 70, 40, 40), "OUT", false))
|
||||||
{
|
{
|
||||||
FlowPercentage -= 10.0f;
|
FlowPercentage -= 10.0f;
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, false);
|
||||||
}
|
}
|
||||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "IN", false))
|
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 70, 40, 40), "IN", false))
|
||||||
{
|
{
|
||||||
FlowPercentage += 10.0f;
|
FlowPercentage += 10.0f;
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ namespace Barotrauma.Items.Components
|
|||||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 20, y + 20, 200, 30), "Activate Radar"))
|
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 20, y + 20, 200, 30), "Activate Radar"))
|
||||||
{
|
{
|
||||||
IsActive = !IsActive;
|
IsActive = !IsActive;
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int radius = GuiFrame.Rect.Height / 2 - 10;
|
int radius = GuiFrame.Rect.Height / 2 - 10;
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
if (valueChanged)
|
if (valueChanged)
|
||||||
{
|
{
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, false);
|
||||||
valueChanged = false;
|
valueChanged = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ namespace Barotrauma.Items.Components
|
|||||||
networkUpdateTimer -= deltaTime;
|
networkUpdateTimer -= deltaTime;
|
||||||
if (networkUpdateTimer<=0.0f)
|
if (networkUpdateTimer<=0.0f)
|
||||||
{
|
{
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, false);
|
||||||
networkUpdateTimer = 1.0f;
|
networkUpdateTimer = 1.0f;
|
||||||
valueChanged = false;
|
valueChanged = false;
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
AutoPilot = !AutoPilot;
|
AutoPilot = !AutoPilot;
|
||||||
|
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI.DrawLine(spriteBatch,
|
GUI.DrawLine(spriteBatch,
|
||||||
|
|||||||
@@ -186,13 +186,13 @@ namespace Barotrauma.Items.Components
|
|||||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 90, 40, 40), "+"))
|
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 200, y + 90, 40, 40), "+"))
|
||||||
{
|
{
|
||||||
rechargeSpeed = Math.Min(rechargeSpeed + maxRechargeSpeed*0.1f, maxRechargeSpeed);
|
rechargeSpeed = Math.Min(rechargeSpeed + maxRechargeSpeed*0.1f, maxRechargeSpeed);
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 90, 40, 40), "-"))
|
if (GUI.DrawButton(spriteBatch, new Rectangle(x + 250, y + 90, 40, 40), "-"))
|
||||||
{
|
{
|
||||||
rechargeSpeed = Math.Max(rechargeSpeed - maxRechargeSpeed * 0.1f, 0.0f);
|
rechargeSpeed = Math.Max(rechargeSpeed - maxRechargeSpeed * 0.1f, 0.0f);
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -280,7 +280,7 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
if (!PlayerInput.LeftButtonDown())
|
if (!PlayerInput.LeftButtonDown())
|
||||||
{
|
{
|
||||||
panel.Item.NewComponentEvent(panel, true);
|
panel.Item.NewComponentEvent(panel, true, true);
|
||||||
draggingConnected = null;
|
draggingConnected = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,10 +125,9 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
Wire[] wires = Array.FindAll(c.Wires, w => w != null);
|
Wire[] wires = Array.FindAll(c.Wires, w => w != null);
|
||||||
message.Write((byte)wires.Length);
|
message.Write((byte)wires.Length);
|
||||||
for (int i = 0 ; i < c.Wires.Length; i++)
|
for (int i = 0 ; i < wires.Length; i++)
|
||||||
{
|
{
|
||||||
if (c.Wires[i] == null) continue;
|
message.Write(wires[i].Item.ID);
|
||||||
message.Write(c.Wires[i].Item.ID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,26 +139,22 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
//int wireCount = c.Wires.Length;
|
//int wireCount = c.Wires.Length;
|
||||||
c.ClearConnections();
|
c.ClearConnections();
|
||||||
try
|
|
||||||
|
byte wireCount = message.ReadByte();
|
||||||
|
|
||||||
|
for (int i = 0; i < wireCount; i++)
|
||||||
{
|
{
|
||||||
byte wireCount = message.ReadByte();
|
ushort wireId = message.ReadUInt16();
|
||||||
|
|
||||||
for (int i = 0; i < wireCount; i++)
|
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
|
||||||
{
|
if (wireItem == null) continue;
|
||||||
ushort wireId = message.ReadUInt16();
|
|
||||||
|
|
||||||
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
|
Wire wireComponent = wireItem.GetComponent<Wire>();
|
||||||
if (wireItem == null) continue;
|
if (wireComponent == null) continue;
|
||||||
|
|
||||||
Wire wireComponent = wireItem.GetComponent<Wire>();
|
c.Wires[i] = wireComponent;
|
||||||
if (wireComponent == null) continue;
|
wireComponent.Connect(c, false);
|
||||||
|
|
||||||
c.Wires[i] = wireComponent;
|
|
||||||
wireComponent.Connect(c, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ namespace Barotrauma.Items.Components
|
|||||||
CleanNodes();
|
CleanNodes();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loading) Item.NewComponentEvent(this, true);
|
if (!loading) Item.NewComponentEvent(this, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Equip(Character character)
|
public override void Equip(Character character)
|
||||||
@@ -200,7 +200,7 @@ namespace Barotrauma.Items.Components
|
|||||||
if (Nodes.Count > 1)
|
if (Nodes.Count > 1)
|
||||||
{
|
{
|
||||||
Nodes.RemoveAt(Nodes.Count - 1);
|
Nodes.RemoveAt(Nodes.Count - 1);
|
||||||
item.NewComponentEvent(this, true);
|
item.NewComponentEvent(this, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,8 +409,8 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
|
public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message)
|
||||||
{
|
{
|
||||||
message.Write(Nodes.Count);
|
message.Write((byte)Math.Min(Nodes.Count, 10));
|
||||||
for (int i = 0; i < Nodes.Count; i++)
|
for (int i = 0; i < Math.Min(Nodes.Count,10); i++)
|
||||||
{
|
{
|
||||||
message.Write(Nodes[i].X);
|
message.Write(Nodes[i].X);
|
||||||
message.Write(Nodes[i].Y);
|
message.Write(Nodes[i].Y);
|
||||||
@@ -420,8 +420,8 @@ namespace Barotrauma.Items.Components
|
|||||||
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
|
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message)
|
||||||
{
|
{
|
||||||
Nodes.Clear();
|
Nodes.Clear();
|
||||||
int nodeCount = message.ReadInt32();
|
int nodeCount = message.ReadByte();
|
||||||
for (int i = 0; i < nodeCount; i++)
|
for (int i = 0; i<nodeCount; i++)
|
||||||
{
|
{
|
||||||
Nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat()));
|
Nodes.Add(new Vector2(message.ReadFloat(), message.ReadFloat()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ namespace Barotrauma
|
|||||||
item.body.Enabled = false;
|
item.body.Enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createNetworkEvent) new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true);
|
if (createNetworkEvent) new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveItem(Item item)
|
public void RemoveItem(Item item)
|
||||||
@@ -203,11 +203,11 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void UpdateSlot(SpriteBatch spriteBatch, Rectangle rect, int slotIndex, Item item, bool isSubSlot)
|
protected void UpdateSlot(SpriteBatch spriteBatch, Rectangle rect, int slotIndex, Item item, bool isSubSlot, bool drawItem=true)
|
||||||
{
|
{
|
||||||
bool mouseOn = rect.Contains(PlayerInput.MousePosition);
|
bool mouseOn = rect.Contains(PlayerInput.MousePosition);
|
||||||
|
|
||||||
DrawSlot(spriteBatch, rect, (draggingItem == item && !mouseOn) ? null : item, mouseOn, isSubSlot);
|
DrawSlot(spriteBatch, rect, (draggingItem == item && !mouseOn) ? null : item, mouseOn, isSubSlot, drawItem);
|
||||||
|
|
||||||
if (mouseOn)
|
if (mouseOn)
|
||||||
{
|
{
|
||||||
@@ -267,12 +267,12 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DrawSlot(SpriteBatch spriteBatch, Rectangle rect, Item item, bool isHighLighted, bool isSubSlot)
|
protected void DrawSlot(SpriteBatch spriteBatch, Rectangle rect, Item item, bool isHighLighted, bool isSubSlot, bool drawItem=true)
|
||||||
{
|
{
|
||||||
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * ((isSubSlot) ? 0.1f : 0.3f), true);
|
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * ((isSubSlot) ? 0.1f : 0.3f), true);
|
||||||
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * ((isSubSlot) ? 0.2f : 0.4f), false);
|
GUI.DrawRectangle(spriteBatch, rect, (isHighLighted ? Color.Red : Color.White) * ((isSubSlot) ? 0.2f : 0.4f), false);
|
||||||
|
|
||||||
if (item == null) return;
|
if (item == null || !drawItem) return;
|
||||||
|
|
||||||
item.Sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color);
|
item.Sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color);
|
||||||
|
|
||||||
|
|||||||
@@ -593,7 +593,25 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
else if (body.Enabled)
|
else if (body.Enabled)
|
||||||
{
|
{
|
||||||
body.Draw(spriteBatch, prefab.sprite, color);
|
var holdable = GetComponent<Holdable>();
|
||||||
|
if (holdable!=null && holdable.Picker !=null)
|
||||||
|
{
|
||||||
|
float depth = Sprite.Depth;
|
||||||
|
if (holdable.Picker.SelectedItems[0]==this)
|
||||||
|
{
|
||||||
|
depth = holdable.Picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.000001f;
|
||||||
|
}
|
||||||
|
else if (holdable.Picker.SelectedItems[1] == this)
|
||||||
|
{
|
||||||
|
depth = holdable.Picker.AnimController.GetLimb(LimbType.LeftArm).sprite.Depth - 0.000001f;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.Draw(spriteBatch, prefab.sprite, color, depth);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
body.Draw(spriteBatch, prefab.sprite, color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1149,11 +1167,12 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void NewComponentEvent(ItemComponent ic, bool isClient)
|
public void NewComponentEvent(ItemComponent ic, bool isClient, bool isImportant)
|
||||||
{
|
{
|
||||||
int index = components.IndexOf(ic);
|
int index = components.IndexOf(ic);
|
||||||
|
|
||||||
new NetworkEvent(NetworkEventType.UpdateComponent, ID, isClient, index);
|
new NetworkEvent(isImportant ?
|
||||||
|
NetworkEventType.ImportantComponentUpdate : NetworkEventType.ComponentUpdate, ID, isClient, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool FillNetworkData(NetworkEventType type, NetOutgoingMessage message, object data)
|
public override bool FillNetworkData(NetworkEventType type, NetOutgoingMessage message, object data)
|
||||||
@@ -1173,7 +1192,8 @@ namespace Barotrauma
|
|||||||
var itemContainer = GetComponent<ItemContainer>();
|
var itemContainer = GetComponent<ItemContainer>();
|
||||||
if (itemContainer == null || itemContainer.inventory == null) return false;
|
if (itemContainer == null || itemContainer.inventory == null) return false;
|
||||||
return itemContainer.inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
return itemContainer.inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data);
|
||||||
case NetworkEventType.UpdateComponent:
|
case NetworkEventType.ComponentUpdate:
|
||||||
|
case NetworkEventType.ImportantComponentUpdate:
|
||||||
|
|
||||||
int componentIndex = (int)data;
|
int componentIndex = (int)data;
|
||||||
if (componentIndex < 0 || componentIndex >= components.Count) return false;
|
if (componentIndex < 0 || componentIndex >= components.Count) return false;
|
||||||
@@ -1230,10 +1250,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
case NetworkEventType.DropItem:
|
case NetworkEventType.DropItem:
|
||||||
Vector2 newSimPos = Vector2.Zero;
|
Vector2 newSimPos = Vector2.Zero;
|
||||||
if (body != null)
|
newSimPos = new Vector2(message.ReadFloat(), message.ReadFloat());
|
||||||
{
|
|
||||||
newSimPos = new Vector2(message.ReadFloat(), message.ReadFloat());
|
|
||||||
}
|
|
||||||
SetTransform(newSimPos, body.Rotation);
|
SetTransform(newSimPos, body.Rotation);
|
||||||
Drop(null, false);
|
Drop(null, false);
|
||||||
break;
|
break;
|
||||||
@@ -1242,7 +1259,8 @@ namespace Barotrauma
|
|||||||
if (itemContainer == null || itemContainer.inventory == null) return;
|
if (itemContainer == null || itemContainer.inventory == null) return;
|
||||||
itemContainer.inventory.ReadNetworkData(NetworkEventType.DropItem, message);
|
itemContainer.inventory.ReadNetworkData(NetworkEventType.DropItem, message);
|
||||||
break;
|
break;
|
||||||
case NetworkEventType.UpdateComponent:
|
case NetworkEventType.ComponentUpdate:
|
||||||
|
case NetworkEventType.ImportantComponentUpdate:
|
||||||
int componentIndex = message.ReadByte();
|
int componentIndex = message.ReadByte();
|
||||||
if (componentIndex < 0 || componentIndex > components.Count - 1) return;
|
if (componentIndex < 0 || componentIndex > components.Count - 1) return;
|
||||||
components[componentIndex].ReadNetworkData(type, message);
|
components[componentIndex].ReadNetworkData(type, message);
|
||||||
|
|||||||
@@ -0,0 +1,144 @@
|
|||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Barotrauma.Networking
|
||||||
|
{
|
||||||
|
class BanList
|
||||||
|
{
|
||||||
|
const string SavePath = "Data/bannedplayers.xml";
|
||||||
|
|
||||||
|
private List<BannedPlayer> bannedPlayers;
|
||||||
|
|
||||||
|
private GUIFrame banFrame;
|
||||||
|
|
||||||
|
public GUIFrame BanFrame
|
||||||
|
{
|
||||||
|
get { return banFrame; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public BanList()
|
||||||
|
{
|
||||||
|
bannedPlayers = new List<BannedPlayer>();
|
||||||
|
|
||||||
|
if (File.Exists(SavePath))
|
||||||
|
{
|
||||||
|
string[] lines;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
lines = File.ReadAllLines(SavePath);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Failed to open the list of banned players in "+SavePath, e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
string[] separatedLine = line.Split(',');
|
||||||
|
if (separatedLine.Length != 2) continue;
|
||||||
|
|
||||||
|
bannedPlayers.Add(new BannedPlayer(separatedLine[0],separatedLine[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BanPlayer(string name, string ip)
|
||||||
|
{
|
||||||
|
if (bannedPlayers.FirstOrDefault(bp => bp.IP == ip)!=null) return;
|
||||||
|
|
||||||
|
bannedPlayers.Add(new BannedPlayer(name,ip));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsBanned(string IP)
|
||||||
|
{
|
||||||
|
return bannedPlayers.FirstOrDefault(bp => bp.IP == IP)!=null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GUIFrame CreateBanFrame()
|
||||||
|
{
|
||||||
|
banFrame = new GUIFrame(new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsHeight), Color.Black*0.3f);
|
||||||
|
|
||||||
|
GUIFrame innerFrame = new GUIFrame(new Rectangle(0,0,300,300), null, Alignment.Center, GUI.Style, banFrame);
|
||||||
|
|
||||||
|
new GUITextBlock(new Rectangle(0, 0, 0, 30), "Banned IPs:", GUI.Style, Alignment.Left, Alignment.Left, innerFrame, false, GUI.LargeFont);
|
||||||
|
var banList = new GUIListBox(new Rectangle(0, 30, 200, 0), GUI.Style, innerFrame);
|
||||||
|
|
||||||
|
foreach (BannedPlayer bannedPlayer in bannedPlayers)
|
||||||
|
{
|
||||||
|
GUITextBlock textBlock = new GUITextBlock(
|
||||||
|
new Rectangle(0, 0, 0, 25),
|
||||||
|
bannedPlayer.IP+" ("+bannedPlayer.Name+")",
|
||||||
|
GUI.Style,
|
||||||
|
Alignment.Left, Alignment.Left, banList);
|
||||||
|
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
textBlock.UserData = banList;
|
||||||
|
|
||||||
|
var removeButton = new GUIButton(new Rectangle(0,0,100,20), "Remove", Alignment.Right, GUI.Style, textBlock);
|
||||||
|
removeButton.UserData = bannedPlayer;
|
||||||
|
removeButton.OnClicked = RemoveBan;
|
||||||
|
}
|
||||||
|
|
||||||
|
var closeButton = new GUIButton(new Rectangle(0,0,100,20), "Close", Alignment.BottomRight, GUI.Style, innerFrame);
|
||||||
|
closeButton.OnClicked = CloseFrame;
|
||||||
|
|
||||||
|
|
||||||
|
return banFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool RemoveBan(GUIButton button, object obj)
|
||||||
|
{
|
||||||
|
BannedPlayer banned = obj as BannedPlayer;
|
||||||
|
if (banned == null) return false;
|
||||||
|
|
||||||
|
bannedPlayers.Remove(banned);
|
||||||
|
|
||||||
|
CreateBanFrame();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CloseFrame(GUIButton button, object obj)
|
||||||
|
{
|
||||||
|
banFrame = null;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
List<string> lines = new List<string>();
|
||||||
|
|
||||||
|
foreach (BannedPlayer banned in bannedPlayers)
|
||||||
|
{
|
||||||
|
lines.Add(banned.Name + "," + banned.IP);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllLines(SavePath, lines);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Saving the list of banned players to "+SavePath+" failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class BannedPlayer
|
||||||
|
{
|
||||||
|
public string Name;
|
||||||
|
public string IP;
|
||||||
|
|
||||||
|
public BannedPlayer(string name, string ip)
|
||||||
|
{
|
||||||
|
this.Name = name;
|
||||||
|
this.IP = ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,7 +37,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
otherClients = new List<Client>();
|
otherClients = new List<Client>();
|
||||||
|
|
||||||
|
GameMain.NetLobbyScreen = new NetLobbyScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ConnectToServer(string hostIP, string password = "")
|
public void ConnectToServer(string hostIP, string password = "")
|
||||||
@@ -94,7 +94,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
IPEndPoint = new System.Net.IPEndPoint(NetUtility.Resolve(serverIP), Port);
|
IPEndPoint = new System.Net.IPEndPoint(NetUtility.Resolve(serverIP), Port);
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
new GUIMessageBox("Could not connect to server", "Failed to resolve address ''"+serverIP+":"+Port+"''. Please make sure you have entered a valid IP address.");
|
new GUIMessageBox("Could not connect to server", "Failed to resolve address ''"+serverIP+":"+Port+"''. Please make sure you have entered a valid IP address.");
|
||||||
return;
|
return;
|
||||||
@@ -111,7 +111,7 @@ namespace Barotrauma.Networking
|
|||||||
DebugConsole.ThrowError("Couldn't connect to "+hostIP+". Error message: "+e.Message);
|
DebugConsole.ThrowError("Couldn't connect to "+hostIP+". Error message: "+e.Message);
|
||||||
Disconnect();
|
Disconnect();
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.Select();
|
GameMain.ServerListScreen.Select();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +291,11 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Screen.Selected != GameMain.GameScreen) GameMain.NetLobbyScreen.Select();
|
if (Screen.Selected != GameMain.GameScreen)
|
||||||
|
{
|
||||||
|
GameMain.NetLobbyScreen = new NetLobbyScreen();
|
||||||
|
GameMain.NetLobbyScreen.Select();
|
||||||
|
}
|
||||||
connected = true;
|
connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,7 +351,7 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
else if (gameStarted)
|
else if (gameStarted)
|
||||||
{
|
{
|
||||||
myCharacter.SendNetworkEvent(true);
|
new NetworkEvent(myCharacter.ID, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,21 +378,12 @@ namespace Barotrauma.Networking
|
|||||||
client.SendMessage(message, NetDeliveryMethod.Unreliable);
|
client.SendMessage(message, NetDeliveryMethod.Unreliable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkEvent.events.Clear();
|
NetworkEvent.events.Clear();
|
||||||
|
|
||||||
if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.B))
|
|
||||||
{
|
|
||||||
SendChatMessage("asdfsdaf");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update current time
|
// Update current time
|
||||||
updateTimer = DateTime.Now + updateInterval;
|
updateTimer = DateTime.Now + updateInterval;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -441,12 +436,23 @@ namespace Barotrauma.Networking
|
|||||||
Client disconnectedClient = otherClients.Find(c => c.ID == leavingID);
|
Client disconnectedClient = otherClients.Find(c => c.ID == leavingID);
|
||||||
if (disconnectedClient != null) GameMain.NetLobbyScreen.RemovePlayer(disconnectedClient.name);
|
if (disconnectedClient != null) GameMain.NetLobbyScreen.RemovePlayer(disconnectedClient.name);
|
||||||
|
|
||||||
|
if (!gameStarted) return;
|
||||||
|
|
||||||
|
List<Character> crew = new List<Character>();
|
||||||
|
foreach (Character c in Character.CharacterList)
|
||||||
|
{
|
||||||
|
if (!c.IsNetworkPlayer || !c.IsHumanoid || c.Info==null) continue;
|
||||||
|
crew.Add(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateCrewFrame(crew);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (byte)PacketTypes.KickedOut:
|
case (byte)PacketTypes.KickedOut:
|
||||||
string msg = inc.ReadString();
|
string msg = inc.ReadString();
|
||||||
|
|
||||||
new GUIMessageBox("You have been kicked out from the server", msg);
|
new GUIMessageBox("Disconnected from server", msg);
|
||||||
|
|
||||||
Disconnect();
|
Disconnect();
|
||||||
GameMain.MainMenuScreen.Select();
|
GameMain.MainMenuScreen.Select();
|
||||||
@@ -588,6 +594,10 @@ namespace Barotrauma.Networking
|
|||||||
if (GameMain.GameSession!=null) GameMain.GameSession.EndShift("");
|
if (GameMain.GameSession!=null) GameMain.GameSession.EndShift("");
|
||||||
|
|
||||||
myCharacter = null;
|
myCharacter = null;
|
||||||
|
foreach (Client c in otherClients)
|
||||||
|
{
|
||||||
|
c.character = null;
|
||||||
|
}
|
||||||
|
|
||||||
yield return CoroutineStatus.Success;
|
yield return CoroutineStatus.Success;
|
||||||
|
|
||||||
@@ -698,6 +708,8 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
//AddChatMessage(message);
|
//AddChatMessage(message);
|
||||||
|
|
||||||
|
if (client.ServerConnection == null) return;
|
||||||
|
|
||||||
type = (gameStarted && myCharacter != null && myCharacter.IsDead) ? ChatMessageType.Dead : ChatMessageType.Default;
|
type = (gameStarted && myCharacter != null && myCharacter.IsDead) ? ChatMessageType.Dead : ChatMessageType.Default;
|
||||||
|
|
||||||
ReliableMessage msg = reliableChannel.CreateMessage();
|
ReliableMessage msg = reliableChannel.CreateMessage();
|
||||||
@@ -729,7 +741,7 @@ namespace Barotrauma.Networking
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
msg.Write((byte)PacketTypes.NetworkEvent);
|
msg.Write((byte)PacketTypes.NetworkEvent);
|
||||||
msg.Write((byte)NetworkEventType.UpdateComponent);
|
msg.Write((byte)NetworkEventType.ComponentUpdate);
|
||||||
msg.Write((int)Item.itemList[Rand.Int(Item.itemList.Count)].ID);
|
msg.Write((int)Item.itemList[Rand.Int(Item.itemList.Count)].ID);
|
||||||
msg.Write(Rand.Int(8));
|
msg.Write(Rand.Int(8));
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ namespace Barotrauma.Networking
|
|||||||
private TimeSpan refreshMasterInterval = new TimeSpan(0, 0, 40);
|
private TimeSpan refreshMasterInterval = new TimeSpan(0, 0, 40);
|
||||||
private DateTime refreshMasterTimer;
|
private DateTime refreshMasterTimer;
|
||||||
|
|
||||||
|
private BanList banList;
|
||||||
|
|
||||||
private bool masterServerResponded;
|
private bool masterServerResponded;
|
||||||
|
|
||||||
private bool registeredToMaster;
|
private bool registeredToMaster;
|
||||||
@@ -54,9 +56,11 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public GameServer(string name, int port, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10)
|
public GameServer(string name, int port, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10)
|
||||||
{
|
{
|
||||||
var endRoundButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 290, 20, 150, 25), "End round", Alignment.TopLeft, GUI.Style, inGameHUD);
|
var endRoundButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 170, 20, 150, 25), "End round", Alignment.TopLeft, GUI.Style, inGameHUD);
|
||||||
endRoundButton.OnClicked = EndButtonHit;
|
endRoundButton.OnClicked = EndButtonHit;
|
||||||
|
|
||||||
|
banList = new BanList();
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
|
|
||||||
@@ -297,7 +301,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
if (gameStarted)
|
if (gameStarted)
|
||||||
{
|
{
|
||||||
if (myCharacter != null) myCharacter.SendNetworkEvent(true);
|
if (myCharacter != null) new NetworkEvent(myCharacter.ID, true);
|
||||||
|
|
||||||
foreach (Character c in Character.CharacterList)
|
foreach (Character c in Character.CharacterList)
|
||||||
{
|
{
|
||||||
@@ -305,7 +309,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (c.SimPosition == Vector2.Zero || c.SimPosition.Length() < 100.0f)
|
if (c.SimPosition == Vector2.Zero || c.SimPosition.Length() < 100.0f)
|
||||||
{
|
{
|
||||||
c.SendNetworkEvent(false);
|
new NetworkEvent(c.ID, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -458,14 +462,6 @@ namespace Barotrauma.Networking
|
|||||||
List<Client> recipients = connectedClients.FindAll(c => c.Connection != inc.SenderConnection && c.inGame);
|
List<Client> recipients = connectedClients.FindAll(c => c.Connection != inc.SenderConnection && c.inGame);
|
||||||
if (recipients.Count == 0) break;
|
if (recipients.Count == 0) break;
|
||||||
|
|
||||||
//foreach (Client client in connectedClients)
|
|
||||||
//{
|
|
||||||
// if (client.Connection == inc.SenderConnection) continue;
|
|
||||||
// if (!client.inGame) continue;
|
|
||||||
|
|
||||||
// recipients.Add(client.Connection);
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (isReliable)
|
if (isReliable)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("receiver reliable networkevent");
|
Debug.WriteLine("receiver reliable networkevent");
|
||||||
@@ -525,6 +521,13 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
DebugConsole.NewMessage("New player has joined the server", Color.White);
|
DebugConsole.NewMessage("New player has joined the server", Color.White);
|
||||||
|
|
||||||
|
if (banList.IsBanned(inc.SenderEndPoint.Address.ToString()))
|
||||||
|
{
|
||||||
|
inc.SenderConnection.Deny("You have been banned from the server");
|
||||||
|
DebugConsole.NewMessage("Banned player tried to join the server", Color.Red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (connectedClients.Find(c => c.Connection == inc.SenderConnection)!=null)
|
if (connectedClients.Find(c => c.Connection == inc.SenderConnection)!=null)
|
||||||
{
|
{
|
||||||
inc.SenderConnection.Deny("Connection error - already joined");
|
inc.SenderConnection.Deny("Connection error - already joined");
|
||||||
@@ -595,6 +598,8 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
disconnectedClients.Remove(existingClient);
|
disconnectedClients.Remove(existingClient);
|
||||||
connectedClients.Add(existingClient);
|
connectedClients.Add(existingClient);
|
||||||
|
|
||||||
|
UpdateCrewFrame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (existingClient != null)
|
if (existingClient != null)
|
||||||
@@ -617,6 +622,8 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
connectedClients.Add(newClient);
|
connectedClients.Add(newClient);
|
||||||
|
|
||||||
|
UpdateCrewFrame();
|
||||||
|
|
||||||
inc.SenderConnection.Approve();
|
inc.SenderConnection.Approve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -737,7 +744,6 @@ namespace Barotrauma.Networking
|
|||||||
characterInfos.Add(characterInfo);
|
characterInfos.Add(characterInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Character> crew = new List<Character>();
|
|
||||||
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos);
|
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos);
|
||||||
|
|
||||||
for (int i = 0; i < connectedClients.Count; i++)
|
for (int i = 0; i < connectedClients.Count; i++)
|
||||||
@@ -745,8 +751,6 @@ namespace Barotrauma.Networking
|
|||||||
connectedClients[i].character = new Character(
|
connectedClients[i].character = new Character(
|
||||||
connectedClients[i].characterInfo, assignedWayPoints[i], true);
|
connectedClients[i].characterInfo, assignedWayPoints[i], true);
|
||||||
connectedClients[i].character.GiveJobItems(assignedWayPoints[i]);
|
connectedClients[i].character.GiveJobItems(assignedWayPoints[i]);
|
||||||
|
|
||||||
crew.Add(connectedClients[i].character);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (characterInfo != null)
|
if (characterInfo != null)
|
||||||
@@ -755,8 +759,6 @@ namespace Barotrauma.Networking
|
|||||||
Character.Controlled = myCharacter;
|
Character.Controlled = myCharacter;
|
||||||
|
|
||||||
myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]);
|
myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]);
|
||||||
|
|
||||||
crew.Add(myCharacter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return CoroutineStatus.Running;
|
yield return CoroutineStatus.Running;
|
||||||
@@ -790,7 +792,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
SendMessage(msg, NetDeliveryMethod.ReliableUnordered, null);
|
SendMessage(msg, NetDeliveryMethod.ReliableUnordered, null);
|
||||||
|
|
||||||
CreateCrewFrame(crew);
|
UpdateCrewFrame();
|
||||||
|
|
||||||
//give some time for the clients to load the map
|
//give some time for the clients to load the map
|
||||||
yield return new WaitForSeconds(2.0f);
|
yield return new WaitForSeconds(2.0f);
|
||||||
@@ -907,23 +909,51 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddChatMessage(msg, ChatMessageType.Server);
|
AddChatMessage(msg, ChatMessageType.Server);
|
||||||
|
|
||||||
|
UpdateCrewFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void KickPlayer(string playerName)
|
private void UpdateCrewFrame()
|
||||||
{
|
{
|
||||||
playerName = playerName.ToLower();
|
List<Character> crew = new List<Character>();
|
||||||
|
|
||||||
foreach (Client c in connectedClients)
|
foreach (Client c in connectedClients)
|
||||||
{
|
{
|
||||||
if (c.name.ToLower() == playerName) KickClient(c);
|
if (c.character == null || !c.inGame) continue;
|
||||||
break;
|
|
||||||
|
crew.Add(c.character);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (myCharacter != null) crew.Add(myCharacter);
|
||||||
|
|
||||||
|
CreateCrewFrame(crew);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void KickClient(Client client)
|
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));
|
||||||
|
|
||||||
|
if (client == null) return;
|
||||||
|
|
||||||
|
KickClient(client, ban);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void KickClient(Client client, bool ban = false)
|
||||||
{
|
{
|
||||||
if (client == null) return;
|
if (client == null) return;
|
||||||
|
|
||||||
DisconnectClient(client, client.name + " has been kicked from the server", "You have been kicked from the server");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NewTraitor(Client traitor, Client target)
|
public void NewTraitor(Client traitor, Client target)
|
||||||
@@ -999,6 +1029,32 @@ namespace Barotrauma.Networking
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool SelectCrewCharacter(GUIComponent component, object obj)
|
||||||
|
{
|
||||||
|
base.SelectCrewCharacter(component, obj);
|
||||||
|
|
||||||
|
var characterFrame = crewFrame.FindChild("selectedcharacter");
|
||||||
|
|
||||||
|
Character character = obj as Character;
|
||||||
|
if (obj == null) return false;
|
||||||
|
|
||||||
|
if (character != myCharacter)
|
||||||
|
{
|
||||||
|
var kickButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Kick", Alignment.BottomLeft, GUI.Style, characterFrame);
|
||||||
|
kickButton.UserData = character.Name;
|
||||||
|
kickButton.OnClicked += GameMain.NetLobbyScreen.KickPlayer;
|
||||||
|
|
||||||
|
var banButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Ban", Alignment.BottomRight, GUI.Style, characterFrame);
|
||||||
|
banButton.UserData = character.Name;
|
||||||
|
banButton.OnClicked += GameMain.NetLobbyScreen.BanPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public override void SendChatMessage(string message, ChatMessageType type = ChatMessageType.Server)
|
public override void SendChatMessage(string message, ChatMessageType type = ChatMessageType.Server)
|
||||||
{
|
{
|
||||||
AddChatMessage(message, type);
|
AddChatMessage(message, type);
|
||||||
@@ -1201,7 +1257,7 @@ namespace Barotrauma.Networking
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
msg.Write((byte)PacketTypes.NetworkEvent);
|
msg.Write((byte)PacketTypes.NetworkEvent);
|
||||||
msg.Write((byte)NetworkEventType.UpdateComponent);
|
msg.Write((byte)NetworkEventType.ComponentUpdate);
|
||||||
msg.Write((int)Item.itemList[Rand.Int(Item.itemList.Count)].ID);
|
msg.Write((int)Item.itemList[Rand.Int(Item.itemList.Count)].ID);
|
||||||
msg.Write(Rand.Int(8));
|
msg.Write(Rand.Int(8));
|
||||||
break;
|
break;
|
||||||
@@ -1224,6 +1280,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public override void Disconnect()
|
public override void Disconnect()
|
||||||
{
|
{
|
||||||
|
banList.Save();
|
||||||
server.Shutdown("The server has shut down");
|
server.Shutdown("The server has shut down");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,12 +73,12 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
spriteBatch.DrawString(GUI.SmallFont,
|
spriteBatch.DrawString(GUI.SmallFont,
|
||||||
"Peak received: "+graphs[(int)NetStatType.ReceivedBytes].LargestValue()+" bytes/s " +
|
"Peak received: "+graphs[(int)NetStatType.ReceivedBytes].LargestValue()+" bytes/s " +
|
||||||
"Avg received: " + graphs[(int)NetStatType.ReceivedBytes].LargestValue()/Graph.ArraySize + " bytes/s",
|
"Avg received: " + graphs[(int)NetStatType.ReceivedBytes].Average() + " bytes/s",
|
||||||
new Vector2(rect.X + 10, rect.Y+10), Color.Cyan);
|
new Vector2(rect.X + 10, rect.Y+10), Color.Cyan);
|
||||||
|
|
||||||
|
|
||||||
spriteBatch.DrawString(GUI.SmallFont, "Peak sent: " + graphs[(int)NetStatType.SentBytes].LargestValue() + " bytes/s " +
|
spriteBatch.DrawString(GUI.SmallFont, "Peak sent: " + graphs[(int)NetStatType.SentBytes].LargestValue() + " bytes/s " +
|
||||||
"Avg sent: " + graphs[(int)NetStatType.SentBytes].LargestValue()/Graph.ArraySize + " bytes/s",
|
"Avg sent: " + graphs[(int)NetStatType.SentBytes].Average() + " bytes/s",
|
||||||
new Vector2(rect.X + 10, rect.Y + 30), Color.Orange);
|
new Vector2(rect.X + 10, rect.Y + 30), Color.Orange);
|
||||||
|
|
||||||
spriteBatch.DrawString(GUI.SmallFont, "Peak resent: " + graphs[(int)NetStatType.ResentMessages].LargestValue() + " messages/s",
|
spriteBatch.DrawString(GUI.SmallFont, "Peak resent: " + graphs[(int)NetStatType.ResentMessages].LargestValue() + " messages/s",
|
||||||
@@ -107,6 +107,11 @@ namespace Barotrauma.Networking
|
|||||||
return maxValue;
|
return maxValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float Average()
|
||||||
|
{
|
||||||
|
return values.Average();
|
||||||
|
}
|
||||||
|
|
||||||
public void Update(float newValue)
|
public void Update(float newValue)
|
||||||
{
|
{
|
||||||
for (int i = values.Length-1; i > 0; i--)
|
for (int i = values.Length-1; i > 0; i--)
|
||||||
|
|||||||
@@ -7,24 +7,58 @@ namespace Barotrauma.Networking
|
|||||||
enum NetworkEventType
|
enum NetworkEventType
|
||||||
{
|
{
|
||||||
EntityUpdate = 0,
|
EntityUpdate = 0,
|
||||||
KillCharacter = 1,
|
ImportantEntityUpdate = 1,
|
||||||
UpdateComponent = 2,
|
|
||||||
DropItem = 3,
|
KillCharacter = 2,
|
||||||
InventoryUpdate = 4,
|
SelectCharacter = 3,
|
||||||
PickItem = 5,
|
|
||||||
UpdateProperty = 6,
|
ComponentUpdate = 4,
|
||||||
WallDamage = 7,
|
ImportantComponentUpdate = 5,
|
||||||
|
|
||||||
|
PickItem = 6,
|
||||||
|
DropItem = 7,
|
||||||
|
InventoryUpdate = 8,
|
||||||
|
|
||||||
|
|
||||||
|
UpdateProperty = 9,
|
||||||
|
WallDamage = 10,
|
||||||
|
|
||||||
|
|
||||||
SelectCharacter = 8,
|
|
||||||
EntityUpdateLarge = 9
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class NetworkEvent
|
class NetworkEvent
|
||||||
{
|
{
|
||||||
public static List<NetworkEvent> events = new List<NetworkEvent>();
|
public static List<NetworkEvent> events = new List<NetworkEvent>();
|
||||||
|
|
||||||
private static bool[] isImportant = { false, true, false, true, true, true, true, true, true, false };
|
private static bool[] isImportant;
|
||||||
private static bool[] overridePrevious = { true, false, true, false, false, false, true, true, true, true };
|
private static bool[] overridePrevious;
|
||||||
|
|
||||||
|
static NetworkEvent()
|
||||||
|
{
|
||||||
|
isImportant = new bool[11];
|
||||||
|
isImportant[(int)NetworkEventType.ImportantEntityUpdate] = true;
|
||||||
|
isImportant[(int)NetworkEventType.ImportantComponentUpdate] = true;
|
||||||
|
isImportant[(int)NetworkEventType.KillCharacter] = true;
|
||||||
|
isImportant[(int)NetworkEventType.SelectCharacter] = true;
|
||||||
|
|
||||||
|
isImportant[(int)NetworkEventType.ImportantComponentUpdate] = true;
|
||||||
|
isImportant[(int)NetworkEventType.PickItem] = true;
|
||||||
|
isImportant[(int)NetworkEventType.DropItem] = true;
|
||||||
|
isImportant[(int)NetworkEventType.InventoryUpdate] = true;
|
||||||
|
|
||||||
|
isImportant[(int)NetworkEventType.UpdateProperty] = true;
|
||||||
|
isImportant[(int)NetworkEventType.WallDamage] = true;
|
||||||
|
|
||||||
|
overridePrevious = new bool[11];
|
||||||
|
for (int i = 0; i < 11; i++ )
|
||||||
|
{
|
||||||
|
overridePrevious[i] = true;
|
||||||
|
}
|
||||||
|
overridePrevious[(int)NetworkEventType.KillCharacter] = false;
|
||||||
|
|
||||||
|
overridePrevious[(int)NetworkEventType.PickItem] = false;
|
||||||
|
overridePrevious[(int)NetworkEventType.DropItem] = false;
|
||||||
|
}
|
||||||
|
|
||||||
private ushort id;
|
private ushort id;
|
||||||
|
|
||||||
@@ -103,6 +137,10 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
DebugConsole.ThrowError("Failed to write network message for entity "+e.ToString());
|
||||||
|
#endif
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +159,9 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
DebugConsole.ThrowError("Received invalid network message");
|
DebugConsole.ThrowError("Received invalid network message");
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private bool crewFrameOpen;
|
private bool crewFrameOpen;
|
||||||
private GUIButton crewButton;
|
private GUIButton crewButton;
|
||||||
private GUIFrame crewFrame;
|
protected GUIFrame crewFrame;
|
||||||
|
|
||||||
protected bool gameStarted;
|
protected bool gameStarted;
|
||||||
|
|
||||||
@@ -117,20 +117,21 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
protected void CreateCrewFrame(List<Character> crew)
|
protected void CreateCrewFrame(List<Character> crew)
|
||||||
{
|
{
|
||||||
int width = 500, height = 400;
|
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 = 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);
|
crewFrame.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||||
|
|
||||||
GUIListBox crewList = new GUIListBox(new Rectangle(0, 0, 300, 300), Color.White * 0.7f, GUI.Style, crewFrame);
|
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.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
|
||||||
crewList.OnSelected = SelectCharacter;
|
crewList.OnSelected = SelectCrewCharacter;
|
||||||
|
|
||||||
foreach (Character character in crew)
|
foreach (Character character in crew)
|
||||||
{
|
{
|
||||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, crewList);
|
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, crewList);
|
||||||
frame.UserData = character;
|
frame.UserData = character;
|
||||||
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
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.HoverColor = Color.LightGray * 0.5f;
|
||||||
frame.SelectedColor = Color.Gold * 0.5f;
|
frame.SelectedColor = Color.Gold * 0.5f;
|
||||||
|
|
||||||
@@ -142,14 +143,14 @@ namespace Barotrauma.Networking
|
|||||||
null, frame);
|
null, frame);
|
||||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||||
|
|
||||||
new GUIImage(new Rectangle(-10, -10, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, frame);
|
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);
|
var closeButton = new GUIButton(new Rectangle(0,0, 80, 20), "Close", Alignment.BottomCenter, GUI.Style, crewFrame);
|
||||||
closeButton.OnClicked = ToggleCrewFrame;
|
closeButton.OnClicked = ToggleCrewFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SelectCharacter(GUIComponent component, object obj)
|
protected virtual bool SelectCrewCharacter(GUIComponent component, object obj)
|
||||||
{
|
{
|
||||||
Character character = obj as Character;
|
Character character = obj as Character;
|
||||||
if (obj == null) return false;
|
if (obj == null) return false;
|
||||||
@@ -174,6 +175,17 @@ namespace Barotrauma.Networking
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//protected void UpdateCrewFrame(List<Client> connectedClients)
|
||||||
|
//{
|
||||||
|
// List<Character> characterList = new List<Character>();
|
||||||
|
// foreach (Client c in connectedClients)
|
||||||
|
// {
|
||||||
|
// if (c.character != null && c.inGame) characterList.Add(c.character);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// CreateCrewFrame(characterList);
|
||||||
|
//}
|
||||||
|
|
||||||
public bool EnterChatMessage(GUITextBox textBox, string message)
|
public bool EnterChatMessage(GUITextBox textBox, string message)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(message)) return false;
|
if (string.IsNullOrWhiteSpace(message)) return false;
|
||||||
|
|||||||
@@ -243,6 +243,8 @@ namespace Barotrauma
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameMain.NetLobbyScreen = new NetLobbyScreen();
|
||||||
|
|
||||||
GameMain.NetworkMember = new GameServer(name, port, isPublicBox.Selected, passwordBox.Text, useUpnpBox.Selected, int.Parse(maxPlayersBox.Text));
|
GameMain.NetworkMember = new GameServer(name, port, isPublicBox.Selected, passwordBox.Text, useUpnpBox.Selected, int.Parse(maxPlayersBox.Text));
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.IsServer = true;
|
GameMain.NetLobbyScreen.IsServer = true;
|
||||||
|
|||||||
@@ -467,11 +467,16 @@ namespace Barotrauma
|
|||||||
GUI.Style, Alignment.TopLeft, Alignment.TopLeft,
|
GUI.Style, Alignment.TopLeft, Alignment.TopLeft,
|
||||||
playerFrameInner, false, GUI.LargeFont);
|
playerFrameInner, false, GUI.LargeFont);
|
||||||
|
|
||||||
var kickButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Kick", Alignment.BottomLeft, GUI.Style, playerFrameInner);
|
var kickButton = new GUIButton(new Rectangle(0, -30, 100, 20), "Kick", Alignment.BottomLeft, GUI.Style, playerFrameInner);
|
||||||
kickButton.UserData = obj;
|
kickButton.UserData = obj;
|
||||||
kickButton.OnClicked += KickPlayer;
|
kickButton.OnClicked += KickPlayer;
|
||||||
kickButton.OnClicked += ClosePlayerFrame;
|
kickButton.OnClicked += ClosePlayerFrame;
|
||||||
|
|
||||||
|
var banButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Ban", Alignment.BottomLeft, GUI.Style, playerFrameInner);
|
||||||
|
banButton.UserData = obj;
|
||||||
|
banButton.OnClicked += BanPlayer;
|
||||||
|
banButton.OnClicked += ClosePlayerFrame;
|
||||||
|
|
||||||
var closeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Close", Alignment.BottomRight, GUI.Style, playerFrameInner);
|
var closeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Close", Alignment.BottomRight, GUI.Style, playerFrameInner);
|
||||||
closeButton.OnClicked = ClosePlayerFrame;
|
closeButton.OnClicked = ClosePlayerFrame;
|
||||||
|
|
||||||
@@ -485,7 +490,7 @@ namespace Barotrauma
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool KickPlayer(GUIButton button, object userData)
|
public bool KickPlayer(GUIButton button, object userData)
|
||||||
{
|
{
|
||||||
if (GameMain.Server == null || userData == null) return false;
|
if (GameMain.Server == null || userData == null) return false;
|
||||||
|
|
||||||
@@ -494,6 +499,15 @@ namespace Barotrauma
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool BanPlayer(GUIButton button, object userData)
|
||||||
|
{
|
||||||
|
if (GameMain.Server == null || userData == null) return false;
|
||||||
|
|
||||||
|
GameMain.Server.KickPlayer(userData.ToString(), true);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void ClearPlayers()
|
public void ClearPlayers()
|
||||||
{
|
{
|
||||||
for (int i = 1; i<playerList.CountChildren; i++)
|
for (int i = 1; i<playerList.CountChildren; i++)
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user