Traitormode won't choose the first client as the target, admin can be traitor/target, banlist & removing IPs, environment dust particles, clients are responsible for the KillCharacter message of their own character, moar backgroundfish, syncing item FixRequirement states, longer gameserver tickrate
This commit is contained in:
@@ -59,14 +59,21 @@ namespace Barotrauma.Networking
|
||||
return bannedPlayers.FirstOrDefault(bp => bp.IP == IP)!=null;
|
||||
}
|
||||
|
||||
public bool ToggleBanFrame(GUIButton button, object obj)
|
||||
{
|
||||
banFrame = CreateBanFrame();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private GUIFrame CreateBanFrame()
|
||||
{
|
||||
banFrame = new GUIFrame(new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsHeight), Color.Black*0.3f);
|
||||
banFrame = new GUIFrame(new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsHeight), Color.Black*0.5f);
|
||||
|
||||
GUIFrame innerFrame = new GUIFrame(new Rectangle(0,0,300,300), null, Alignment.Center, GUI.Style, banFrame);
|
||||
GUIFrame innerFrame = new GUIFrame(new Rectangle(0,0,400,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);
|
||||
new GUITextBlock(new Rectangle(0, -10, 0, 30), "Banned IPs:", GUI.Style, Alignment.Left, Alignment.Left, innerFrame, false, GUI.LargeFont);
|
||||
var banList = new GUIListBox(new Rectangle(0, 30, 0, 0), GUI.Style, innerFrame);
|
||||
|
||||
foreach (BannedPlayer bannedPlayer in bannedPlayers)
|
||||
{
|
||||
@@ -78,12 +85,12 @@ namespace Barotrauma.Networking
|
||||
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);
|
||||
var removeButton = new GUIButton(new Rectangle(0,00,100,20), "Remove", Alignment.Right | Alignment.CenterY, 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);
|
||||
var closeButton = new GUIButton(new Rectangle(0,30,100,20), "Close", Alignment.BottomRight, GUI.Style, innerFrame);
|
||||
closeButton.OnClicked = CloseFrame;
|
||||
|
||||
|
||||
|
||||
@@ -484,8 +484,8 @@ namespace Barotrauma.Networking
|
||||
case (byte)PacketTypes.ResendRequest:
|
||||
reliableChannel.HandleResendRequest(inc);
|
||||
break;
|
||||
case (byte)PacketTypes.Ack:
|
||||
reliableChannel.HandleAckMessage(inc);
|
||||
case (byte)PacketTypes.LatestMessageID:
|
||||
reliableChannel.HandleLatestMessageID(inc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,11 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
public float AutoRestartTimer;
|
||||
|
||||
public BanList BanList
|
||||
{
|
||||
get { return banList; }
|
||||
}
|
||||
|
||||
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 - 170, 20, 150, 25), "End round", Alignment.TopLeft, GUI.Style, inGameHUD);
|
||||
@@ -86,7 +91,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
config.DisableMessageType(NetIncomingMessageType.DebugMessage |
|
||||
NetIncomingMessageType.WarningMessage | NetIncomingMessageType.Receipt |
|
||||
NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error);
|
||||
NetIncomingMessageType.ErrorMessage | NetIncomingMessageType.Error |
|
||||
NetIncomingMessageType.UnconnectedData);
|
||||
|
||||
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
|
||||
|
||||
@@ -137,7 +143,7 @@ namespace Barotrauma.Networking
|
||||
RegisterToMasterServer();
|
||||
}
|
||||
|
||||
updateInterval = new TimeSpan(0, 0, 0, 0, 60);
|
||||
updateInterval = new TimeSpan(0, 0, 0, 0, 150);
|
||||
|
||||
DebugConsole.NewMessage("Server started", Color.Green);
|
||||
|
||||
@@ -504,8 +510,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
dataSender.ReliableChannel.HandleResendRequest(inc);
|
||||
break;
|
||||
case (byte)PacketTypes.Ack:
|
||||
dataSender.ReliableChannel.HandleAckMessage(inc);
|
||||
case (byte)PacketTypes.LatestMessageID:
|
||||
dataSender.ReliableChannel.HandleLatestMessageID(inc);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -884,7 +890,19 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (client == null) return;
|
||||
|
||||
if (gameStarted && client.character != null) client.character.ClearInputs();
|
||||
if (gameStarted && client.character != null)
|
||||
{
|
||||
if (GameMain.GameSession!=null && GameMain.GameSession.gameMode!=null)
|
||||
{
|
||||
TraitorMode traitorMode = GameMain.GameSession.gameMode as TraitorMode;
|
||||
if (traitorMode!=null)
|
||||
{
|
||||
traitorMode.CharacterLeft(client.character);
|
||||
}
|
||||
}
|
||||
|
||||
client.character.ClearInputs();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(msg)) msg = client.name + " has left the server";
|
||||
if (string.IsNullOrWhiteSpace(targetmsg)) targetmsg = "You have left the server";
|
||||
@@ -956,23 +974,66 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
}
|
||||
|
||||
public void NewTraitor(Client traitor, Client target)
|
||||
public void NewTraitor(out Character traitor, out Character target)
|
||||
{
|
||||
//new GUIMessageBox("New traitor", traitor.name + " is the traitor and the target is " + target.name+".");
|
||||
List<Character> characters = new List<Character>();
|
||||
foreach (Client client in connectedClients)
|
||||
{
|
||||
if (!client.inGame || client.character==null) continue;
|
||||
characters.Add(client.character);
|
||||
}
|
||||
if (myCharacter!= null) characters.Add(myCharacter);
|
||||
|
||||
if (characters.Count < 2)
|
||||
{
|
||||
traitor = null;
|
||||
target = null;
|
||||
return;
|
||||
}
|
||||
|
||||
int traitorIndex = Rand.Range(0, characters.Count);
|
||||
|
||||
int targetIndex = Rand.Range(0, characters.Count);
|
||||
while (targetIndex==traitorIndex)
|
||||
{
|
||||
targetIndex = Rand.Range(0, characters.Count);
|
||||
}
|
||||
|
||||
|
||||
traitor = characters[traitorIndex];
|
||||
target = characters[targetIndex];
|
||||
|
||||
if (myCharacter==null)
|
||||
{
|
||||
new GUIMessageBox("New traitor", traitor.Info.Name + " is the traitor and the target is " + target.Info.Name+".");
|
||||
}
|
||||
else if (myCharacter == traitor)
|
||||
{
|
||||
new GUIMessageBox("You are the traitor!", "Your task is to assassinate " + target.Info.Name+".");
|
||||
return;
|
||||
}
|
||||
|
||||
Client traitorClient = null;
|
||||
foreach (Client c in connectedClients)
|
||||
{
|
||||
if (c.character != traitor) continue;
|
||||
traitorClient = c;
|
||||
break;
|
||||
}
|
||||
|
||||
NetOutgoingMessage msg = server.CreateMessage();
|
||||
msg.Write((byte)PacketTypes.Traitor);
|
||||
msg.Write(target.name);
|
||||
msg.Write(target.Info.Name);
|
||||
if (server.Connections.Count > 0)
|
||||
{
|
||||
server.SendMessage(msg, traitor.Connection, NetDeliveryMethod.ReliableUnordered, 0);
|
||||
server.SendMessage(msg, traitorClient.Connection, NetDeliveryMethod.ReliableUnordered, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
|
||||
{
|
||||
base.Draw(spriteBatch);
|
||||
|
||||
|
||||
if (!ShowNetStats) return;
|
||||
|
||||
int width = 200, height = 300;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public const float DeleteDisconnectedTime = 10.0f;
|
||||
|
||||
public const float AckInterval = 0.2f;
|
||||
public const float IdSendInterval = 0.2f;
|
||||
public const float RerequestInterval = 0.2f;
|
||||
|
||||
public const int ResendAttempts = 8;
|
||||
|
||||
@@ -18,9 +18,10 @@ namespace Barotrauma.Networking
|
||||
PickItem = 6,
|
||||
DropItem = 7,
|
||||
InventoryUpdate = 8,
|
||||
ItemFixed = 9,
|
||||
|
||||
UpdateProperty = 9,
|
||||
WallDamage = 10,
|
||||
UpdateProperty = 10,
|
||||
WallDamage = 11,
|
||||
|
||||
|
||||
}
|
||||
@@ -34,7 +35,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
static NetworkEvent()
|
||||
{
|
||||
isImportant = new bool[11];
|
||||
isImportant = new bool[Enum.GetNames(typeof(NetworkEventType)).Length];
|
||||
isImportant[(int)NetworkEventType.ImportantEntityUpdate] = true;
|
||||
isImportant[(int)NetworkEventType.ImportantComponentUpdate] = true;
|
||||
isImportant[(int)NetworkEventType.KillCharacter] = true;
|
||||
@@ -44,12 +45,13 @@ namespace Barotrauma.Networking
|
||||
isImportant[(int)NetworkEventType.PickItem] = true;
|
||||
isImportant[(int)NetworkEventType.DropItem] = true;
|
||||
isImportant[(int)NetworkEventType.InventoryUpdate] = true;
|
||||
isImportant[(int)NetworkEventType.ItemFixed] = true;
|
||||
|
||||
isImportant[(int)NetworkEventType.UpdateProperty] = true;
|
||||
isImportant[(int)NetworkEventType.WallDamage] = true;
|
||||
|
||||
overridePrevious = new bool[11];
|
||||
for (int i = 0; i < 11; i++ )
|
||||
overridePrevious = new bool[isImportant.Length];
|
||||
for (int i = 0; i < overridePrevious.Length; i++ )
|
||||
{
|
||||
overridePrevious[i] = true;
|
||||
}
|
||||
@@ -57,6 +59,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
overridePrevious[(int)NetworkEventType.PickItem] = false;
|
||||
overridePrevious[(int)NetworkEventType.DropItem] = false;
|
||||
overridePrevious[(int)NetworkEventType.ItemFixed] = false;
|
||||
}
|
||||
|
||||
private ushort id;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
ResendRequest,
|
||||
ReliableMessage,
|
||||
Ack
|
||||
LatestMessageID
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -43,10 +43,10 @@ namespace Barotrauma.Networking.ReliableMessages
|
||||
sender.HandleResendRequest(inc);
|
||||
}
|
||||
|
||||
public void HandleAckMessage(NetIncomingMessage inc)
|
||||
public void HandleLatestMessageID(NetIncomingMessage inc)
|
||||
{
|
||||
//make sure we've received what's been sent to us, if not, rerequest
|
||||
receiver.HandleAckMessage(inc);
|
||||
receiver.HandleLatestMessageID(inc);
|
||||
}
|
||||
|
||||
public bool CheckMessage(NetIncomingMessage inc)
|
||||
@@ -73,9 +73,9 @@ namespace Barotrauma.Networking.ReliableMessages
|
||||
|
||||
private NetConnection recipient;
|
||||
|
||||
private float ackTimer;
|
||||
private float idSendTimer;
|
||||
|
||||
private float ackInterval;
|
||||
private float idSendInterval;
|
||||
|
||||
public ReliableSender(NetPeer sender)
|
||||
{
|
||||
@@ -134,8 +134,8 @@ namespace Barotrauma.Networking.ReliableMessages
|
||||
|
||||
public void SendMessage(ReliableMessage message, NetConnection connection)
|
||||
{
|
||||
ackInterval = 0.0f;
|
||||
ackTimer = connection.AverageRoundtripTime;
|
||||
idSendInterval = 0.0f;
|
||||
idSendTimer = connection.AverageRoundtripTime;
|
||||
|
||||
messageBuffer.Add(message.ID, message);
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace Barotrauma.Networking.ReliableMessages
|
||||
NetOutgoingMessage resendMessage = sender.CreateMessage();
|
||||
message.RestoreInnerMessage(resendMessage);
|
||||
|
||||
ackTimer = connection.AverageRoundtripTime;
|
||||
idSendTimer = connection.AverageRoundtripTime;
|
||||
|
||||
sender.SendMessage(resendMessage, connection, NetDeliveryMethod.Unreliable);
|
||||
}
|
||||
@@ -177,20 +177,20 @@ namespace Barotrauma.Networking.ReliableMessages
|
||||
{
|
||||
if (recipient == null) return;
|
||||
|
||||
ackTimer -= deltaTime;
|
||||
idSendTimer -= deltaTime;
|
||||
|
||||
if (ackTimer > 0.0f) return;
|
||||
if (idSendTimer > 0.0f) return;
|
||||
|
||||
//Debug.WriteLine("Sending ack message: "+messageCount);
|
||||
|
||||
NetOutgoingMessage message = sender.CreateMessage();
|
||||
message.Write((byte)PacketTypes.Ack);
|
||||
message.Write((byte)PacketTypes.LatestMessageID);
|
||||
message.Write(messageCount);
|
||||
|
||||
sender.SendMessage(message, recipient, NetDeliveryMethod.Unreliable);
|
||||
|
||||
ackTimer = Math.Max(recipient.AverageRoundtripTime, NetConfig.AckInterval+ackInterval);
|
||||
ackInterval += 0.1f;
|
||||
idSendTimer = Math.Max(recipient.AverageRoundtripTime, NetConfig.IdSendInterval+idSendInterval);
|
||||
idSendInterval += 0.1f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ namespace Barotrauma.Networking.ReliableMessages
|
||||
missingMessages.Remove(id);
|
||||
}
|
||||
|
||||
public void HandleAckMessage(NetIncomingMessage inc)
|
||||
public void HandleLatestMessageID(NetIncomingMessage inc)
|
||||
{
|
||||
ushort messageId = inc.ReadUInt16();
|
||||
|
||||
@@ -357,7 +357,7 @@ namespace Barotrauma.Networking.ReliableMessages
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.WriteLine("Received ack message: " + messageId + ", need to rerequest messages (last id: "+lastMessageID+")");
|
||||
Debug.WriteLine("Received id update message: " + messageId + ", need to rerequest messages (last id: "+lastMessageID+")");
|
||||
|
||||
if (lastMessageID > ushort.MaxValue / 2 && messageId < short.MaxValue / 2)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user