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:
144
Subsurface/Source/Networking/BanList.cs
Normal file
144
Subsurface/Source/Networking/BanList.cs
Normal file
@@ -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>();
|
||||
|
||||
|
||||
GameMain.NetLobbyScreen = new NetLobbyScreen();
|
||||
}
|
||||
|
||||
public void ConnectToServer(string hostIP, string password = "")
|
||||
@@ -94,7 +94,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
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.");
|
||||
return;
|
||||
@@ -111,7 +111,7 @@ namespace Barotrauma.Networking
|
||||
DebugConsole.ThrowError("Couldn't connect to "+hostIP+". Error message: "+e.Message);
|
||||
Disconnect();
|
||||
|
||||
GameMain.NetLobbyScreen.Select();
|
||||
GameMain.ServerListScreen.Select();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -291,7 +291,11 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Screen.Selected != GameMain.GameScreen) GameMain.NetLobbyScreen.Select();
|
||||
if (Screen.Selected != GameMain.GameScreen)
|
||||
{
|
||||
GameMain.NetLobbyScreen = new NetLobbyScreen();
|
||||
GameMain.NetLobbyScreen.Select();
|
||||
}
|
||||
connected = true;
|
||||
}
|
||||
|
||||
@@ -347,7 +351,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else if (gameStarted)
|
||||
{
|
||||
myCharacter.SendNetworkEvent(true);
|
||||
new NetworkEvent(myCharacter.ID, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,21 +378,12 @@ namespace Barotrauma.Networking
|
||||
client.SendMessage(message, NetDeliveryMethod.Unreliable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
NetworkEvent.events.Clear();
|
||||
|
||||
if (PlayerInput.KeyDown(Microsoft.Xna.Framework.Input.Keys.B))
|
||||
{
|
||||
SendChatMessage("asdfsdaf");
|
||||
}
|
||||
|
||||
|
||||
// Update current time
|
||||
updateTimer = DateTime.Now + updateInterval;
|
||||
|
||||
|
||||
updateTimer = DateTime.Now + updateInterval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -440,13 +435,24 @@ namespace Barotrauma.Networking
|
||||
AddChatMessage(inc.ReadString(), ChatMessageType.Server);
|
||||
Client disconnectedClient = otherClients.Find(c => c.ID == leavingID);
|
||||
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;
|
||||
|
||||
case (byte)PacketTypes.KickedOut:
|
||||
string msg = inc.ReadString();
|
||||
|
||||
new GUIMessageBox("You have been kicked out from the server", msg);
|
||||
new GUIMessageBox("Disconnected from server", msg);
|
||||
|
||||
Disconnect();
|
||||
GameMain.MainMenuScreen.Select();
|
||||
@@ -588,6 +594,10 @@ namespace Barotrauma.Networking
|
||||
if (GameMain.GameSession!=null) GameMain.GameSession.EndShift("");
|
||||
|
||||
myCharacter = null;
|
||||
foreach (Client c in otherClients)
|
||||
{
|
||||
c.character = null;
|
||||
}
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
|
||||
@@ -698,6 +708,8 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
//AddChatMessage(message);
|
||||
|
||||
if (client.ServerConnection == null) return;
|
||||
|
||||
type = (gameStarted && myCharacter != null && myCharacter.IsDead) ? ChatMessageType.Dead : ChatMessageType.Default;
|
||||
|
||||
ReliableMessage msg = reliableChannel.CreateMessage();
|
||||
@@ -729,7 +741,7 @@ namespace Barotrauma.Networking
|
||||
break;
|
||||
case 2:
|
||||
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(Rand.Int(8));
|
||||
break;
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
private TimeSpan refreshMasterInterval = new TimeSpan(0, 0, 40);
|
||||
private DateTime refreshMasterTimer;
|
||||
|
||||
private BanList banList;
|
||||
|
||||
private bool masterServerResponded;
|
||||
|
||||
@@ -54,9 +56,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
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;
|
||||
|
||||
banList = new BanList();
|
||||
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
|
||||
@@ -297,7 +301,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (gameStarted)
|
||||
{
|
||||
if (myCharacter != null) myCharacter.SendNetworkEvent(true);
|
||||
if (myCharacter != null) new NetworkEvent(myCharacter.ID, true);
|
||||
|
||||
foreach (Character c in Character.CharacterList)
|
||||
{
|
||||
@@ -305,7 +309,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
if (c.SimPosition == Vector2.Zero || c.SimPosition.Length() < 100.0f)
|
||||
{
|
||||
c.SendNetworkEvent(false);
|
||||
new NetworkEvent(c.ID, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -457,14 +461,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
List<Client> recipients = connectedClients.FindAll(c => c.Connection != inc.SenderConnection && c.inGame);
|
||||
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)
|
||||
{
|
||||
@@ -524,6 +520,13 @@ namespace Barotrauma.Networking
|
||||
if (inc.ReadByte() != (byte)PacketTypes.Login) return;
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -595,6 +598,8 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
disconnectedClients.Remove(existingClient);
|
||||
connectedClients.Add(existingClient);
|
||||
|
||||
UpdateCrewFrame();
|
||||
}
|
||||
}
|
||||
if (existingClient != null)
|
||||
@@ -617,6 +622,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
connectedClients.Add(newClient);
|
||||
|
||||
UpdateCrewFrame();
|
||||
|
||||
inc.SenderConnection.Approve();
|
||||
}
|
||||
|
||||
@@ -737,7 +744,6 @@ namespace Barotrauma.Networking
|
||||
characterInfos.Add(characterInfo);
|
||||
}
|
||||
|
||||
List<Character> crew = new List<Character>();
|
||||
WayPoint[] assignedWayPoints = WayPoint.SelectCrewSpawnPoints(characterInfos);
|
||||
|
||||
for (int i = 0; i < connectedClients.Count; i++)
|
||||
@@ -745,8 +751,6 @@ namespace Barotrauma.Networking
|
||||
connectedClients[i].character = new Character(
|
||||
connectedClients[i].characterInfo, assignedWayPoints[i], true);
|
||||
connectedClients[i].character.GiveJobItems(assignedWayPoints[i]);
|
||||
|
||||
crew.Add(connectedClients[i].character);
|
||||
}
|
||||
|
||||
if (characterInfo != null)
|
||||
@@ -755,8 +759,6 @@ namespace Barotrauma.Networking
|
||||
Character.Controlled = myCharacter;
|
||||
|
||||
myCharacter.GiveJobItems(assignedWayPoints[assignedWayPoints.Length - 1]);
|
||||
|
||||
crew.Add(myCharacter);
|
||||
}
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
@@ -789,8 +791,8 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
SendMessage(msg, NetDeliveryMethod.ReliableUnordered, null);
|
||||
|
||||
CreateCrewFrame(crew);
|
||||
|
||||
UpdateCrewFrame();
|
||||
|
||||
//give some time for the clients to load the map
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
@@ -907,23 +909,51 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (c.name.ToLower() == playerName) KickClient(c);
|
||||
break;
|
||||
if (c.character == null || !c.inGame) continue;
|
||||
|
||||
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;
|
||||
|
||||
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)
|
||||
@@ -999,6 +1029,32 @@ namespace Barotrauma.Networking
|
||||
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)
|
||||
{
|
||||
AddChatMessage(message, type);
|
||||
@@ -1081,7 +1137,7 @@ namespace Barotrauma.Networking
|
||||
private void AssignJobs()
|
||||
{
|
||||
List<Client> unassigned = new List<Client>(connectedClients);
|
||||
|
||||
|
||||
int[] assignedClientCount = new int[JobPrefab.List.Count];
|
||||
|
||||
if (characterInfo!=null)
|
||||
@@ -1201,7 +1257,7 @@ namespace Barotrauma.Networking
|
||||
break;
|
||||
case 1:
|
||||
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(Rand.Int(8));
|
||||
break;
|
||||
@@ -1224,6 +1280,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
public override void Disconnect()
|
||||
{
|
||||
banList.Save();
|
||||
server.Shutdown("The server has shut down");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,12 +73,12 @@ namespace Barotrauma.Networking
|
||||
|
||||
spriteBatch.DrawString(GUI.SmallFont,
|
||||
"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);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
spriteBatch.DrawString(GUI.SmallFont, "Peak resent: " + graphs[(int)NetStatType.ResentMessages].LargestValue() + " messages/s",
|
||||
@@ -107,6 +107,11 @@ namespace Barotrauma.Networking
|
||||
return maxValue;
|
||||
}
|
||||
|
||||
public float Average()
|
||||
{
|
||||
return values.Average();
|
||||
}
|
||||
|
||||
public void Update(float newValue)
|
||||
{
|
||||
for (int i = values.Length-1; i > 0; i--)
|
||||
|
||||
@@ -7,24 +7,58 @@ namespace Barotrauma.Networking
|
||||
enum NetworkEventType
|
||||
{
|
||||
EntityUpdate = 0,
|
||||
KillCharacter = 1,
|
||||
UpdateComponent = 2,
|
||||
DropItem = 3,
|
||||
InventoryUpdate = 4,
|
||||
PickItem = 5,
|
||||
UpdateProperty = 6,
|
||||
WallDamage = 7,
|
||||
ImportantEntityUpdate = 1,
|
||||
|
||||
KillCharacter = 2,
|
||||
SelectCharacter = 3,
|
||||
|
||||
ComponentUpdate = 4,
|
||||
ImportantComponentUpdate = 5,
|
||||
|
||||
PickItem = 6,
|
||||
DropItem = 7,
|
||||
InventoryUpdate = 8,
|
||||
|
||||
|
||||
UpdateProperty = 9,
|
||||
WallDamage = 10,
|
||||
|
||||
|
||||
SelectCharacter = 8,
|
||||
EntityUpdateLarge = 9
|
||||
}
|
||||
|
||||
class 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[] overridePrevious = { true, false, true, false, false, false, true, true, true, true };
|
||||
private static bool[] isImportant;
|
||||
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;
|
||||
|
||||
@@ -103,6 +137,10 @@ namespace Barotrauma.Networking
|
||||
|
||||
catch
|
||||
{
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("Failed to write network message for entity "+e.ToString());
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -121,7 +159,9 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
catch
|
||||
{
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("Received invalid network message");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Barotrauma.Networking
|
||||
|
||||
private bool crewFrameOpen;
|
||||
private GUIButton crewButton;
|
||||
private GUIFrame crewFrame;
|
||||
protected GUIFrame crewFrame;
|
||||
|
||||
protected bool gameStarted;
|
||||
|
||||
@@ -117,20 +117,21 @@ namespace Barotrauma.Networking
|
||||
|
||||
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.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.OnSelected = SelectCharacter;
|
||||
crewList.OnSelected = SelectCrewCharacter;
|
||||
|
||||
foreach (Character character in crew)
|
||||
{
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, crewList);
|
||||
frame.UserData = character;
|
||||
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.SelectedColor = Color.Gold * 0.5f;
|
||||
|
||||
@@ -142,14 +143,14 @@ namespace Barotrauma.Networking
|
||||
null, frame);
|
||||
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);
|
||||
closeButton.OnClicked = ToggleCrewFrame;
|
||||
}
|
||||
|
||||
private bool SelectCharacter(GUIComponent component, object obj)
|
||||
protected virtual bool SelectCrewCharacter(GUIComponent component, object obj)
|
||||
{
|
||||
Character character = obj as Character;
|
||||
if (obj == null) return false;
|
||||
@@ -174,6 +175,17 @@ namespace Barotrauma.Networking
|
||||
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)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message)) return false;
|
||||
|
||||
Reference in New Issue
Block a user