Made game compilable

Networking functionality is fully disabled now.

I think it's time to start rewriting everything. OH BOY
This commit is contained in:
juanjp600
2016-08-30 21:13:36 -03:00
parent 4157e5aab2
commit 7bdcc51bae
11 changed files with 80 additions and 291 deletions

View File

@@ -66,9 +66,6 @@ namespace Barotrauma
public virtual void Update(float deltaTime) { }
//protected Structure lastStructurePicked;
public virtual void FillNetworkData(NetBuffer message) { }
public virtual void ReadNetworkData(NetIncomingMessage message) { }
}
}

View File

@@ -291,7 +291,6 @@ namespace Barotrauma
if (spawnedCharacter != null && GameMain.Server != null)
{
spawnedCharacter.SpawnedMidRound = true;
GameMain.Server.SendCharacterSpawnMessage(spawnedCharacter);
}
break;
@@ -321,7 +320,7 @@ namespace Barotrauma
}
else
{
GameMain.Server.KickClient(client, true);
//GameMain.Server.KickClient(client, true);
}
break;
case "startclient":

View File

@@ -351,7 +351,14 @@ namespace Barotrauma
}
static bool waitForKeyHit = true;
public static CoroutineHandle ShowLoading(IEnumerable<object> loader, bool waitKeyHit = true)
{
waitForKeyHit = waitKeyHit;
titleScreenOpen = true;
TitleScreen.LoadState = null;
return CoroutineManager.StartCoroutine(TitleScreen.DoLoading(loader));
}
protected override void OnExiting(object sender, EventArgs args)
{
if (NetworkMember != null) NetworkMember.Disconnect();

View File

@@ -235,8 +235,8 @@ namespace Barotrauma
Items[index] = null;
//swapping the items failed -> move them back to where they were
TryPutItem(item, currentIndex, false, false);
TryPutItem(existingItem, index, false, false);
TryPutItem(item, currentIndex, false);
TryPutItem(existingItem, index, false);
}
}
@@ -287,7 +287,7 @@ namespace Barotrauma
{
if (doubleClickedItem.ParentInventory != this)
{
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true);
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots);
}
else
{
@@ -296,24 +296,24 @@ namespace Barotrauma
var selectedContainer = character.SelectedConstruction.GetComponent<ItemContainer>();
if (selectedContainer != null && selectedContainer.Inventory != null)
{
selectedContainer.Inventory.TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true);
selectedContainer.Inventory.TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots);
}
}
else if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
{
character.SelectedCharacter.Inventory.TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true);
character.SelectedCharacter.Inventory.TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots);
}
else //doubleclicked and no other inventory is selected
{
//not equipped -> attempt to equip
if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any))
{
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any), true);
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any));
}
//equipped -> attempt to unequip
else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any))
{
TryPutItem(doubleClickedItem, new List<InvSlotType>() { InvSlotType.Any }, true);
TryPutItem(doubleClickedItem, new List<InvSlotType>() { InvSlotType.Any });
}
}
}

View File

@@ -122,7 +122,7 @@ namespace Barotrauma
if (removeItem)
{
item.Drop(null, false);
item.Drop(null);
if (item.ParentInventory != null) item.ParentInventory.RemoveItem(item);
}
@@ -156,7 +156,7 @@ namespace Barotrauma
protected virtual void DropItem(Item item)
{
item.Drop(null, false);
item.Drop(null);
return;
}
//public void DropItem(int i)
@@ -276,7 +276,7 @@ namespace Barotrauma
}
//selectedSlot = slotIndex;
TryPutItem(draggingItem, slotIndex, true, true);
TryPutItem(draggingItem, slotIndex, true);
draggingItem = null;
}

View File

@@ -80,8 +80,7 @@ namespace Barotrauma
//inventories.Add(inventory);
}
}
if (GameMain.Server != null) GameMain.Server.SendItemSpawnMessage(items);
}
public void AddToSpawnedList(Item item)
@@ -133,8 +132,7 @@ namespace Barotrauma
items.Add(item);
}
if (GameMain.Server != null) GameMain.Server.SendItemRemoveMessage(items);
}
public void Clear()

View File

@@ -112,49 +112,5 @@ namespace Barotrauma.Networking
return sb.ToString();
}
public void WriteNetworkMessage(NetOutgoingMessage msg)
{
msg.WriteRangedInteger(0, Enum.GetValues(typeof(ChatMessageType)).Length, (byte)Type);
if (GameMain.Server != null)
{
msg.Write(Sender == null ? (ushort)0 : Sender.ID);
msg.Write(SenderName);
}
msg.Write(Text);
}
public static ChatMessage ReadNetworkMessage(NetBuffer msg)
{
ChatMessageType type = (ChatMessageType)msg.ReadRangedInteger(0, Enum.GetValues(typeof(ChatMessageType)).Length);
string senderName="";
Character character = null;
if (GameMain.Server == null)
{
ushort senderId = msg.ReadUInt16();
character = Entity.FindEntityByID(senderId) as Character;
senderName = msg.ReadString();
}
else
{
NetIncomingMessage inc = msg as NetIncomingMessage;
if (inc == null) return null;
Client sender = GameMain.Server.ConnectedClients.Find(x => x.Connection == inc.SenderConnection);
if (sender == null) return null;
character = sender.Character;
if (character != null)
{
senderName = character.Name;
}
else
{
senderName = sender.name;
}
}
string text = msg.ReadString();
return new ChatMessage(senderName, text, type, character);
}
}
}

View File

@@ -323,8 +323,8 @@ namespace Barotrauma.Networking
updateTimer = DateTime.Now + updateInterval;
}
private CoroutineHandle startGameCoroutine;
private CoroutineHandle startGameCoroutine;
/// <summary>
/// Check for new incoming messages from server
/// </summary>
@@ -333,8 +333,8 @@ namespace Barotrauma.Networking
// Create new incoming message holder
NetIncomingMessage inc;
if (startGameCoroutine != null && CoroutineManager.IsCoroutineRunning(startGameCoroutine)) return;
if (startGameCoroutine != null && CoroutineManager.IsCoroutineRunning(startGameCoroutine)) return;
while ((inc = client.ReadMessage()) != null)
{
//TODO: read message data
@@ -469,29 +469,6 @@ namespace Barotrauma.Networking
{
base.Draw(spriteBatch);
if (fileStreamReceiver != null &&
(fileStreamReceiver.Status == FileTransferStatus.Receiving || fileStreamReceiver.Status == FileTransferStatus.NotStarted))
{
Vector2 pos = new Vector2(GameMain.GraphicsWidth / 2 - 130, GameMain.NetLobbyScreen.InfoFrame.Rect.Y / 2 - 15);
GUI.DrawString(spriteBatch,
pos,
"Downloading " + fileStreamReceiver.FileName,
Color.White, null, 0, GUI.SmallFont);
GUI.DrawProgressBar(spriteBatch, new Vector2(pos.X, -pos.Y - 12), new Vector2(200, 15), fileStreamReceiver.Progress, Color.Green);
GUI.DrawString(spriteBatch, pos + new Vector2(5,12),
MathUtils.GetBytesReadable((long)fileStreamReceiver.Received) + " / " + MathUtils.GetBytesReadable((long)fileStreamReceiver.FileSize),
Color.White, null, 0, GUI.SmallFont);
if (GUI.DrawButton(spriteBatch, new Rectangle((int)pos.X + 210, (int)pos.Y+12, 65, 15), "Cancel", new Color(0.47f, 0.13f, 0.15f, 0.08f)))
{
CancelFileTransfer();
}
}
if (!GameMain.DebugDraw) return;
int width = 200, height = 300;

View File

@@ -444,8 +444,49 @@ namespace Barotrauma.Networking
}
sparseUpdateTimer = DateTime.Now + sparseUpdateInterval;
}
public bool StartGameClicked(GUIButton button, object obj)
{
Submarine selectedSub = null;
Submarine selectedShuttle = GameMain.NetLobbyScreen.SelectedShuttle;
if (Voting.AllowSubVoting)
{
selectedSub = Voting.HighestVoted<Submarine>(VoteType.Sub, connectedClients);
if (selectedSub == null) selectedSub = GameMain.NetLobbyScreen.SelectedSub;
}
else
{
selectedSub = GameMain.NetLobbyScreen.SelectedSub;
}
if (selectedSub == null)
{
GameMain.NetLobbyScreen.SubList.Flash();
return false;
}
if (selectedShuttle == null)
{
GameMain.NetLobbyScreen.ShuttleList.Flash();
return false;
}
GameModePreset selectedMode = Voting.HighestVoted<GameModePreset>(VoteType.Mode, connectedClients);
if (selectedMode == null) selectedMode = GameMain.NetLobbyScreen.SelectedMode;
if (selectedMode == null)
{
GameMain.NetLobbyScreen.ModeList.Flash();
return false;
}
//CoroutineManager.StartCoroutine(WaitForPlayersReady(selectedSub, selectedShuttle, selectedMode), "WaitForPlayersReady");
return true;
}
public void EndGame()
{
if (!gameStarted) return;
@@ -622,23 +663,8 @@ namespace Barotrauma.Networking
if (server.Connections.Count == 0) return;
var clientsToKick = connectedClients.FindAll(c => c.KickVoteCount > connectedClients.Count * KickVoteRequiredRatio);
clientsToKick.ForEach(c => KickClient(c));
try
{
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.VoteStatus);
Voting.WriteData(msg, connectedClients);
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0);
}
catch (Exception e)
{
#if DEBUG
DebugConsole.ThrowError("Failed to update vote status", e);
#endif
}
//clientsToKick.ForEach(c => KickClient(c));
}
public bool UpdateNetLobby(object obj)
@@ -649,24 +675,13 @@ namespace Barotrauma.Networking
public bool UpdateNetLobby(GUIComponent component, object obj)
{
if (server.Connections.Count == 0) return true;
NetOutgoingMessage msg = server.CreateMessage();
msg.Write((byte)PacketTypes.UpdateNetLobby);
GameMain.NetLobbyScreen.WriteData(msg);
server.SendMessage(msg, server.Connections, NetDeliveryMethod.ReliableUnordered, 0);
return true;
}
public void UpdateClientPermissions(Client client)
{
var msg = server.CreateMessage();
msg.Write((byte)PacketTypes.Permissions);
msg.Write((int)client.Permissions);
server.SendMessage(msg, client.Connection, NetDeliveryMethod.ReliableUnordered);
clientPermissions.RemoveAll(cp => cp.IP == client.Connection.RemoteEndPoint.Address.ToString());
if (client.Permissions != ClientPermissions.None)
@@ -703,100 +718,6 @@ namespace Barotrauma.Networking
return true;
}
private void ReadChatMessage(NetIncomingMessage inc)
{
Client sender = connectedClients.Find(x => x.Connection == inc.SenderConnection);
ChatMessage message = ChatMessage.ReadNetworkMessage(inc);
if (message == null) return;
List<Client> recipients = new List<Client>();
foreach (Client c in connectedClients)
{
if (!sender.inGame && c.inGame) continue; //people in lobby can't talk to people ingame
switch (message.Type)
{
case ChatMessageType.Dead:
if (c.Character != null && !c.Character.IsDead) continue;
break;
case ChatMessageType.Default:
if (message.Sender != null && c.Character != null && message.Sender != c.Character)
{
if (Vector2.Distance(message.Sender.WorldPosition, c.Character.WorldPosition) > ChatMessage.SpeakRange) continue;
}
break;
case ChatMessageType.Radio:
if (message.Sender == null) return;
var radio = message.Sender.Inventory.Items.First(i => i != null && i.GetComponent<WifiComponent>() != null);
if (radio == null) message.Type = ChatMessageType.Default;
break;
}
recipients.Add(c);
}
//SPAM FILTER
if (sender.ChatSpamTimer > 0.0f)
{
//player has already been spamming, stop again
ChatMessage denyMsg = ChatMessage.Create("", "You have been blocked by the spam filter. Try again after 10 seconds.", ChatMessageType.Server, null);
sender.ChatSpamTimer = 10.0f;
SendChatMessage(denyMsg, sender);
return;
}
float similarity = 0;
similarity += sender.ChatSpamSpeed * 0.05f; //the faster messages are being sent, the faster the filter will block
for (int i = 0; i < sender.ChatMessages.Count; i++)
{
float closeFactor = 1.0f / (20.0f - i);
int levenshteinDist = ToolBox.LevenshteinDistance(message.Text, sender.ChatMessages[i]);
similarity += Math.Max((message.Text.Length - levenshteinDist) / message.Text.Length * closeFactor, 0.0f);
}
if (similarity > 5.0f)
{
sender.ChatSpamCount++;
if (sender.ChatSpamCount > 3)
{
//kick for spamming too much
KickClient(sender, false);
}
else
{
ChatMessage denyMsg = ChatMessage.Create("", "You have been blocked by the spam filter. Try again after 10 seconds.", ChatMessageType.Server, null);
sender.ChatSpamTimer = 10.0f;
SendChatMessage(denyMsg, sender);
}
return;
}
sender.ChatMessages.Add(message.Text);
if (sender.ChatMessages.Count > 20)
{
sender.ChatMessages.RemoveAt(0);
}
if (sender.inGame || (Screen.Selected == GameMain.NetLobbyScreen))
{
AddChatMessage(message);
}
else
{
GameServer.Log(message.TextWithSender, message.Color);
}
sender.ChatSpamSpeed += 5.0f;
foreach (Client c in recipients)
{
}
}
public override void SendChatMessage(string message, ChatMessageType? type = null)
{
List<Client> recipients = new List<Client>();
@@ -943,40 +864,7 @@ namespace Barotrauma.Networking
}
}
public void SendCharacterSpawnMessage(Character character, List<NetConnection> recipients = null)
{
if (recipients != null && !recipients.Any()) return;
NetOutgoingMessage message = server.CreateMessage();
message.Write((byte)PacketTypes.NewCharacter);
WriteCharacterData(message, character.Name, character);
SendMessage(message, NetDeliveryMethod.ReliableUnordered, recipients);
}
public void SendItemSpawnMessage(List<Item> items, List<NetConnection> recipients = null)
{
if (items == null || !items.Any()) return;
NetOutgoingMessage message = server.CreateMessage();
message.Write((byte)PacketTypes.NewItem);
SendMessage(message, NetDeliveryMethod.ReliableOrdered, recipients);
}
public void SendItemRemoveMessage(List<Item> items, List<NetConnection> recipients = null)
{
if (items == null || !items.Any()) return;
NetOutgoingMessage message = server.CreateMessage();
message.Write((byte)PacketTypes.RemoveItem);
SendMessage(message, NetDeliveryMethod.ReliableOrdered, recipients);
}
public void AssignJobs(List<Client> unassigned)
{
unassigned = new List<Client>(unassigned);
@@ -1088,35 +976,7 @@ namespace Barotrauma.Networking
/// </summary>
public void SendRandomData()
{
NetOutgoingMessage msg = server.CreateMessage();
switch (Rand.Int(5))
{
case 0:
msg.Write((byte)PacketTypes.NetworkEvent);
msg.Write((byte)Rand.Int(Enum.GetNames(typeof(NetworkEventType)).Length));
msg.Write((ushort)Rand.Int(MapEntity.mapEntityList.Count));
break;
case 1:
msg.Write((byte)PacketTypes.NetworkEvent);
msg.Write((byte)NetworkEventType.ComponentUpdate);
msg.Write((int)Item.ItemList[Rand.Int(Item.ItemList.Count)].ID);
msg.Write(Rand.Int(8));
break;
case 2:
msg.Write((byte)Enum.GetNames(typeof(PacketTypes)).Length);
break;
case 3:
msg.Write((byte)PacketTypes.UpdateNetLobby);
break;
}
int bitCount = Rand.Int(100);
for (int i = 0; i < bitCount; i++)
{
msg.Write(Rand.Int(2) == 0);
}
SendMessage(msg, (Rand.Int(2) == 0) ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.Unreliable);
//NO DON'T DO THIS WHY
}
public override void Disconnect()
@@ -1137,12 +997,7 @@ namespace Barotrauma.Networking
Log("Shutting down server...", Color.Cyan);
log.Save();
}
foreach (Client client in connectedClients)
{
if (client.FileStreamSender != null) client.FileStreamSender.Dispose();
}
server.Shutdown("The server has been shut down");
}
}

View File

@@ -630,7 +630,7 @@ namespace Barotrauma
var item = new Item(screwdriverPrefab, Vector2.Zero, null);
dummyCharacter.Inventory.TryPutItem(item, new List<InvSlotType>() {InvSlotType.RightHand}, false);
dummyCharacter.Inventory.TryPutItem(item, new List<InvSlotType>() {InvSlotType.RightHand});
wiringToolPanel = CreateWiringPanel();
}
@@ -720,7 +720,7 @@ namespace Barotrauma
existingWire.Remove();
}
dummyCharacter.Inventory.TryPutItem(wire, slotIndex, false, false);
dummyCharacter.Inventory.TryPutItem(wire, slotIndex, false);
return true;

View File

@@ -1144,7 +1144,7 @@ namespace Barotrauma
public bool TrySelectSub(string subName, string md5Hash, GUIListBox subList)
{
//already downloading the selected sub file
if (GameMain.Client.ActiveFileTransferName == subName+".sub") return false;
//if (GameMain.Client.ActiveFileTransferName == subName+".sub") return false;
var matchingListSub = subList.children.Find(c => c.UserData != null && (c.UserData as Submarine).Name == subName) as GUITextBlock;
if (matchingListSub != null)
@@ -1173,9 +1173,9 @@ namespace Barotrauma
+ "Server's MD5 hash: " + md5Hash + ". ";
}
string downloadMsg = string.IsNullOrEmpty(GameMain.Client.ActiveFileTransferName) ?
/*string downloadMsg = string.IsNullOrEmpty(GameMain.Client.ActiveFileTransferName) ?
"Do you want to download the file from the server host?" :
"Do you want to download the file and cancel downloading ''" + GameMain.Client.ActiveFileTransferName + "''?";
"Do you want to download the file and cancel downloading ''" + GameMain.Client.ActiveFileTransferName + "''?";*/
if (GUIMessageBox.MessageBoxes.Count>0)
{
@@ -1186,7 +1186,7 @@ namespace Barotrauma
}
}
var requestFileBox = new GUIMessageBox("Submarine not found!", errorMsg+downloadMsg, new string[] { "Yes", "No" }, 400, 300);
/*var requestFileBox = new GUIMessageBox("Submarine not found!", errorMsg+downloadMsg, new string[] { "Yes", "No" }, 400, 300);
requestFileBox.Buttons[0].UserData = subName;
requestFileBox.Buttons[0].OnClicked += requestFileBox.Close;
requestFileBox.Buttons[0].OnClicked += (GUIButton button, object userdata) =>
@@ -1194,7 +1194,7 @@ namespace Barotrauma
GameMain.Client.RequestFile(userdata.ToString(), FileTransferMessageType.Submarine);
return true;
};
requestFileBox.Buttons[1].OnClicked += requestFileBox.Close;
requestFileBox.Buttons[1].OnClicked += requestFileBox.Close;*/
return false;
}