diff --git a/CHANGELOG.md b/CHANGELOG.md index a9cd96f8..9a433825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added `/uploadssc [player]` which allows someone to upload SSC data for [player] and store it on the server. Adds `tshock.ssc.upload` and `tshock.ssc.upload.others` permission nodes to match (@DogooFalchion). * Added hardened stone to the whitelist of tiles editable by players (@DogooFalchion). * Added conversion system to send convert old MOTD format into smart text, while preserving initial line starting values to keep byte optimization for background colors Thanks to (@WhiteXZ, @Simon311, and especially @DogooFalchion) for the hard work on this issue. +* Fixed server-sided inventory issues caused by bank3 (@ProfessorXZ) ## TShock 4.3.20 * Security improvement: The auth system is now automatically disabled if a superadmin exists in the database (@Enerdy). diff --git a/TShock.sln b/TShock.sln index 2f54cde7..af79472c 100644 --- a/TShock.sln +++ b/TShock.sln @@ -1,21 +1,27 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{755F5B05-0924-47E9-9563-26EB20FE3F67}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockAPI", "TShockAPI\TShockAPI.csproj", "{49606449-072B-4CF5-8088-AA49DA586694}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerrariaServer", "TerrariaServerAPI\TerrariaServer.csproj", "{6877506E-ADC6-4142-98A6-79E4FA02855A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerrariaServerAPI", "TerrariaServerAPI\TerrariaServerAPI\TerrariaServerAPI.csproj", "{6877506E-ADC6-4142-98A6-79E4FA02855A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Mono|Any CPU = Mono|Any CPU + Mono|Mixed Platforms = Mono|Mixed Platforms + Mono|x64 = Mono|x64 + Mono|x86 = Mono|x86 Release|Any CPU = Release|Any CPU Release|Mixed Platforms = Release|Mixed Platforms + Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution @@ -23,20 +29,43 @@ Global {49606449-072B-4CF5-8088-AA49DA586694}.Debug|Any CPU.Build.0 = Debug|Any CPU {49606449-072B-4CF5-8088-AA49DA586694}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {49606449-072B-4CF5-8088-AA49DA586694}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Debug|x64.ActiveCfg = Debug|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Debug|x64.Build.0 = Debug|Any CPU {49606449-072B-4CF5-8088-AA49DA586694}.Debug|x86.ActiveCfg = Debug|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Mono|Any CPU.ActiveCfg = Release|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Mono|Any CPU.Build.0 = Release|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Mono|Mixed Platforms.ActiveCfg = Release|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Mono|Mixed Platforms.Build.0 = Release|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Mono|x64.ActiveCfg = Release|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Mono|x64.Build.0 = Release|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Mono|x86.ActiveCfg = Release|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Mono|x86.Build.0 = Release|Any CPU {49606449-072B-4CF5-8088-AA49DA586694}.Release|Any CPU.ActiveCfg = Release|Any CPU {49606449-072B-4CF5-8088-AA49DA586694}.Release|Any CPU.Build.0 = Release|Any CPU {49606449-072B-4CF5-8088-AA49DA586694}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {49606449-072B-4CF5-8088-AA49DA586694}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Release|x64.ActiveCfg = Release|Any CPU + {49606449-072B-4CF5-8088-AA49DA586694}.Release|x64.Build.0 = Release|Any CPU {49606449-072B-4CF5-8088-AA49DA586694}.Release|x86.ActiveCfg = Release|Any CPU {6877506E-ADC6-4142-98A6-79E4FA02855A}.Debug|Any CPU.ActiveCfg = Debug|x86 {6877506E-ADC6-4142-98A6-79E4FA02855A}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 {6877506E-ADC6-4142-98A6-79E4FA02855A}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Debug|x64.ActiveCfg = Debug|x64 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Debug|x64.Build.0 = Debug|x64 {6877506E-ADC6-4142-98A6-79E4FA02855A}.Debug|x86.ActiveCfg = Debug|x86 {6877506E-ADC6-4142-98A6-79E4FA02855A}.Debug|x86.Build.0 = Debug|x86 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Mono|Any CPU.ActiveCfg = Mono|x86 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Mono|Mixed Platforms.ActiveCfg = Mono|x86 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Mono|Mixed Platforms.Build.0 = Mono|x86 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Mono|x64.ActiveCfg = Mono|x64 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Mono|x64.Build.0 = Mono|x64 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Mono|x86.ActiveCfg = Mono|x86 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Mono|x86.Build.0 = Mono|x86 {6877506E-ADC6-4142-98A6-79E4FA02855A}.Release|Any CPU.ActiveCfg = Release|x86 {6877506E-ADC6-4142-98A6-79E4FA02855A}.Release|Mixed Platforms.ActiveCfg = Release|x86 {6877506E-ADC6-4142-98A6-79E4FA02855A}.Release|Mixed Platforms.Build.0 = Release|x86 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Release|x64.ActiveCfg = Release|x64 + {6877506E-ADC6-4142-98A6-79E4FA02855A}.Release|x64.Build.0 = Release|x64 {6877506E-ADC6-4142-98A6-79E4FA02855A}.Release|x86.ActiveCfg = Release|x86 {6877506E-ADC6-4142-98A6-79E4FA02855A}.Release|x86.Build.0 = Release|x86 EndGlobalSection diff --git a/TShockAPI/BackupManager.cs b/TShockAPI/BackupManager.cs index 58b544f4..b5bf734d 100644 --- a/TShockAPI/BackupManager.cs +++ b/TShockAPI/BackupManager.cs @@ -62,7 +62,7 @@ namespace TShockAPI string worldname = Main.worldPathName; string name = Path.GetFileName(worldname); - Main.worldPathName = Path.Combine(BackupPath, string.Format("{0}.{1:dd.MM.yy-HH.mm.ss}.bak", name, DateTime.UtcNow)); + Main.ActiveWorldFileData._path = Path.Combine(BackupPath, string.Format("{0}.{1:dd.MM.yy-HH.mm.ss}.bak", name, DateTime.UtcNow)); string worldpath = Path.GetDirectoryName(Main.worldPathName); if (worldpath != null && !Directory.Exists(worldpath)) @@ -80,7 +80,7 @@ namespace TShockAPI Console.ForegroundColor = ConsoleColor.Gray; TShock.Log.Info(string.Format("World backed up ({0}).", Main.worldPathName)); - Main.worldPathName = worldname; + Main.ActiveWorldFileData._path = worldname; } catch (Exception ex) { diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs old mode 100755 new mode 100644 index 754d6fab..f1a07d67 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -31,6 +31,8 @@ using TShockAPI.DB; using TerrariaApi.Server; using TShockAPI.Hooks; using Terraria.GameContent.Events; +using Microsoft.Xna.Framework; +using OTAPI.Tile; namespace TShockAPI { @@ -2116,7 +2118,7 @@ namespace TShockAPI else { Main.anglerWhoFinishedToday.Clear(); - NetMessage.SendAnglerQuest(); + NetMessage.SendAnglerQuest(-1); args.Player.SendSuccessMessage("Cleared all users from the angler quest completion list for today."); } } @@ -4437,7 +4439,7 @@ namespace TShockAPI // Could be improved by sending raw tile data to the client instead but not really // worth the effort as chances are very low that overwriting the wire for a few // nanoseconds will cause much trouble. - Tile tile = Main.tile[boundaryPoint.X, boundaryPoint.Y]; + ITile tile = Main.tile[boundaryPoint.X, boundaryPoint.Y]; bool oldWireState = tile.wire(); tile.wire(true); @@ -5177,7 +5179,7 @@ namespace TShockAPI else { var plr = players[0]; - plr.DamagePlayer(999999); + plr.KillPlayer(); args.Player.SendSuccessMessage(string.Format("You just killed {0}!", plr.Name)); plr.SendErrorMessage("{0} just killed you!", args.Player.Name); } diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/DB/BanManager.cs b/TShockAPI/DB/BanManager.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/DB/CharacterManager.cs b/TShockAPI/DB/CharacterManager.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/DB/ItemManager.cs b/TShockAPI/DB/ItemManager.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/DB/ProjectileManager.cs b/TShockAPI/DB/ProjectileManager.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/DB/RegionManager.cs b/TShockAPI/DB/RegionManager.cs old mode 100755 new mode 100644 index 47fb4843..1e1ed74e --- a/TShockAPI/DB/RegionManager.cs +++ b/TShockAPI/DB/RegionManager.cs @@ -22,6 +22,7 @@ using System.Data; using System.Linq; using MySql.Data.MySqlClient; using Terraria; +using Microsoft.Xna.Framework; namespace TShockAPI.DB { diff --git a/TShockAPI/DB/RememberedPosManager.cs b/TShockAPI/DB/RememberedPosManager.cs old mode 100755 new mode 100644 index 44b21a5d..cb1735ad --- a/TShockAPI/DB/RememberedPosManager.cs +++ b/TShockAPI/DB/RememberedPosManager.cs @@ -20,6 +20,7 @@ using System; using System.Data; using MySql.Data.MySqlClient; using Terraria; +using Microsoft.Xna.Framework; namespace TShockAPI.DB { diff --git a/TShockAPI/DB/SqlTable.cs b/TShockAPI/DB/SqlTable.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/DB/TileManager.cs b/TShockAPI/DB/TileManager.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/DB/WarpsManager.cs b/TShockAPI/DB/WarpsManager.cs old mode 100755 new mode 100644 index f06003f6..9ea67600 --- a/TShockAPI/DB/WarpsManager.cs +++ b/TShockAPI/DB/WarpsManager.cs @@ -23,6 +23,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using MySql.Data.MySqlClient; using Terraria; +using Microsoft.Xna.Framework; namespace TShockAPI.DB { diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs old mode 100755 new mode 100644 index 82db3096..cead709a --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -32,6 +32,8 @@ using Terraria; using Terraria.ObjectData; using Terraria.DataStructures; using Terraria.GameContent.Tile_Entities; +using Microsoft.Xna.Framework; +using OTAPI.Tile; namespace TShockAPI { @@ -2053,7 +2055,7 @@ namespace TShockAPI Item selectedItem = args.Player.SelectedItem; int lastKilledProj = args.Player.LastKilledProjectile; - Tile tile = Main.tile[tileX, tileY]; + ITile tile = Main.tile[tileX, tileY]; if (action == EditAction.PlaceTile) { diff --git a/TShockAPI/Hooks/AccountHooks.cs b/TShockAPI/Hooks/AccountHooks.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/NetItem.cs b/TShockAPI/NetItem.cs index 8ae60e62..8d6b4e2a 100644 --- a/TShockAPI/NetItem.cs +++ b/TShockAPI/NetItem.cs @@ -76,6 +76,15 @@ namespace TShockAPI /// public static readonly int MaxInventory = InventorySlots + ArmorSlots + DyeSlots + MiscEquipSlots + MiscDyeSlots + PiggySlots + SafeSlots + ForgeSlots + 1; + public static readonly Tuple InventoryIndex = new Tuple(0, InventorySlots); + public static readonly Tuple ArmorIndex = new Tuple(InventoryIndex.Item2, InventoryIndex.Item2 + ArmorSlots); + public static readonly Tuple DyeIndex = new Tuple(ArmorIndex.Item2, ArmorIndex.Item2 + DyeSlots); + public static readonly Tuple MiscEquipIndex = new Tuple(DyeIndex.Item2, DyeIndex.Item2 + MiscEquipSlots); + public static readonly Tuple MiscDyeIndex = new Tuple(MiscEquipIndex.Item2, MiscEquipIndex.Item2 + MiscDyeSlots); + public static readonly Tuple PiggyIndex = new Tuple(MiscDyeIndex.Item2, MiscDyeIndex.Item2 + PiggySlots); + public static readonly Tuple SafeIndex = new Tuple(PiggyIndex.Item2, PiggyIndex.Item2 + SafeSlots); + public static readonly Tuple ForgeIndex = new Tuple(SafeIndex.Item2, SafeIndex.Item2 + ForgeSlots); + [JsonProperty("netID")] private int _netId; [JsonProperty("prefix")] diff --git a/TShockAPI/PaginationTools.cs b/TShockAPI/PaginationTools.cs index 3bc6de89..55526040 100644 --- a/TShockAPI/PaginationTools.cs +++ b/TShockAPI/PaginationTools.cs @@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +using Microsoft.Xna.Framework; using System; using System.Collections; using System.Collections.Generic; diff --git a/TShockAPI/PlayerData.cs b/TShockAPI/PlayerData.cs index 7422bc80..9cd7c97b 100644 --- a/TShockAPI/PlayerData.cs +++ b/TShockAPI/PlayerData.cs @@ -16,7 +16,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -using Terraria; +using Microsoft.Xna.Framework; +using Terraria; using TShockAPI; namespace TShockAPI @@ -122,64 +123,51 @@ namespace TShockAPI for (int i = 0; i < NetItem.MaxInventory; i++) { - if (i < NetItem.InventorySlots) + if (i < NetItem.InventoryIndex.Item2) { //0-58 this.inventory[i] = (NetItem)inventory[i]; } - else if (i < NetItem.InventorySlots + NetItem.ArmorSlots) + else if (i < NetItem.ArmorIndex.Item2) { //59-78 - var index = i - NetItem.InventorySlots; + var index = i - NetItem.ArmorIndex.Item1; this.inventory[i] = (NetItem)armor[index]; } - else if (i < NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots) + else if (i < NetItem.DyeIndex.Item2) { //79-88 - var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots); + var index = i - NetItem.DyeIndex.Item1; this.inventory[i] = (NetItem)dye[index]; } - else if (i < - NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots) + else if (i < NetItem.MiscEquipIndex.Item2) { //89-93 - var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots); + var index = i - NetItem.MiscEquipIndex.Item1; this.inventory[i] = (NetItem)miscEqups[index]; } - else if (i < - NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots - + NetItem.MiscDyeSlots) + else if (i < NetItem.MiscDyeIndex.Item2) { //93-98 - var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots - + NetItem.MiscEquipSlots); + var index = i - NetItem.MiscDyeIndex.Item1; this.inventory[i] = (NetItem)miscDyes[index]; } - else if (i < - NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + - NetItem.MiscDyeSlots + NetItem.PiggySlots) + else if (i < NetItem.PiggyIndex.Item2) { //98-138 - var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots - + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots); + var index = i - NetItem.PiggyIndex.Item1; this.inventory[i] = (NetItem)piggy[index]; } - else if (i < - NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + - NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.SafeSlots) + else if (i < NetItem.SafeIndex.Item2) { //138-178 - var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots - + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots); + var index = i - NetItem.SafeIndex.Item1; this.inventory[i] = (NetItem)safe[index]; } - else if (i < - NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + - NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.SafeSlots + NetItem.ForgeSlots) + else if (i < NetItem.ForgeIndex.Item2) { //179-219 - var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots - + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.ForgeSlots); + var index = i - NetItem.ForgeIndex.Item1; this.inventory[i] = (NetItem)forge[index]; } else @@ -463,4 +451,4 @@ namespace TShockAPI NetMessage.SendData(39, player.Index, -1, "", 400); } } -} \ No newline at end of file +} diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs old mode 100755 new mode 100644 diff --git a/TShockAPI/Rest/SecureRest.cs b/TShockAPI/Rest/SecureRest.cs index cf3a9fd2..da74099b 100644 --- a/TShockAPI/Rest/SecureRest.cs +++ b/TShockAPI/Rest/SecureRest.cs @@ -23,6 +23,7 @@ using System.Net; using HttpServer; using TShockAPI; using TShockAPI.DB; +using Microsoft.Xna.Framework; namespace Rests { diff --git a/TShockAPI/SaveManager.cs b/TShockAPI/SaveManager.cs index 9ff98287..52166b2a 100644 --- a/TShockAPI/SaveManager.cs +++ b/TShockAPI/SaveManager.cs @@ -15,6 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ +using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Threading; diff --git a/TShockAPI/Sockets/LinuxTcpSocket.cs b/TShockAPI/Sockets/LinuxTcpSocket.cs new file mode 100644 index 00000000..72e8e9d3 --- /dev/null +++ b/TShockAPI/Sockets/LinuxTcpSocket.cs @@ -0,0 +1,178 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using Terraria; +using Terraria.Localization; +using Terraria.Net; +using Terraria.Net.Sockets; + +namespace TShockAPI.Sockets +{ + public class LinuxTcpSocket : ISocket + { + private byte[] _packetBuffer = new byte[1024]; + + private int _packetBufferLength; + + private List _callbackBuffer = new List(); + + private int _messagesInQueue; + + private TcpClient _connection; + + private TcpListener _listener; + + private SocketConnectionAccepted _listenerCallback; + + private RemoteAddress _remoteAddress; + + private bool _isListening; + + public int MessagesInQueue + { + get + { + return this._messagesInQueue; + } + } + + public LinuxTcpSocket() + { + this._connection = new TcpClient(); + this._connection.NoDelay = true; + } + + public LinuxTcpSocket(TcpClient tcpClient) + { + this._connection = tcpClient; + this._connection.NoDelay = true; + IPEndPoint iPEndPoint = (IPEndPoint)tcpClient.Client.RemoteEndPoint; + this._remoteAddress = new TcpAddress(iPEndPoint.Address, iPEndPoint.Port); + } + + void ISocket.Close() + { + this._remoteAddress = null; + this._connection.Close(); + } + + bool ISocket.IsConnected() + { + return this._connection != null && this._connection.Client != null && this._connection.Connected; + } + + void ISocket.Connect(RemoteAddress address) + { + TcpAddress tcpAddress = (TcpAddress)address; + this._connection.Connect(tcpAddress.Address, tcpAddress.Port); + this._remoteAddress = address; + } + + private void ReadCallback(IAsyncResult result) + { + Tuple tuple = (Tuple)result.AsyncState; + tuple.Item1(tuple.Item2, this._connection.GetStream().EndRead(result)); + } + + private void SendCallback(IAsyncResult result) + { + object[] expr_0B = (object[])result.AsyncState; + LegacyNetBufferPool.ReturnBuffer((byte[])expr_0B[1]); + Tuple tuple = (Tuple)expr_0B[0]; + try + { + this._connection.GetStream().EndWrite(result); + tuple.Item1(tuple.Item2); + } + catch (Exception) + { + ((ISocket)this).Close(); + } + } + + void ISocket.SendQueuedPackets() + { + } + + void ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state) + { + byte[] array = LegacyNetBufferPool.RequestBuffer(data, offset, size); + this._connection.GetStream().BeginWrite(array, 0, size, new AsyncCallback(this.SendCallback), new object[] + { + new Tuple(callback, state), + array + }); + } + + void ISocket.AsyncReceive(byte[] data, int offset, int size, SocketReceiveCallback callback, object state) + { + this._connection.GetStream().BeginRead(data, offset, size, new AsyncCallback(this.ReadCallback), new Tuple(callback, state)); + } + + bool ISocket.IsDataAvailable() + { + return this._connection.GetStream().DataAvailable; + } + + RemoteAddress ISocket.GetRemoteAddress() + { + return this._remoteAddress; + } + + bool ISocket.StartListening(SocketConnectionAccepted callback) + { + IPAddress any = IPAddress.Any; + string ipString; + if (Program.LaunchParameters.TryGetValue("-ip", out ipString) && !IPAddress.TryParse(ipString, out any)) + { + any = IPAddress.Any; + } + this._isListening = true; + this._listenerCallback = callback; + if (this._listener == null) + { + this._listener = new TcpListener(any, Netplay.ListenPort); + } + try + { + this._listener.Start(); + } + catch (Exception) + { + return false; + } + ThreadPool.QueueUserWorkItem(new WaitCallback(this.ListenLoop)); + return true; + } + + void ISocket.StopListening() + { + this._isListening = false; + } + + private void ListenLoop(object unused) + { + while (this._isListening && !Netplay.disconnect) + { + try + { + ISocket socket = new LinuxTcpSocket(this._listener.AcceptTcpClient()); + Console.WriteLine(Language.GetTextValue("Net.ClientConnecting", socket.GetRemoteAddress())); + this._listenerCallback(socket); + } + catch (Exception) + { + } + } + this._listener.Stop(); + + // currently vanilla will stop listening when the slots are full, however it appears that this Netplay.IsListening + // flag is still set, making the server loop beleive it's still listening when it's actually not. + // clearing this flag when we actually have stopped will allow the ServerLoop to start listening again when + // there are enough slots available. + Netplay.IsListening = false; + } + } +} diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs old mode 100755 new mode 100644 index 96ba95af..cd64547f --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +using Microsoft.Xna.Framework; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -24,6 +25,7 @@ using System.IO; using System.Text; using System.Threading; using System.Timers; +using OTAPI.Tile; using Terraria; using Terraria.DataStructures; using Terraria.ID; @@ -121,12 +123,12 @@ namespace TShockAPI /// /// A queue of tiles destroyed by the player for reverting. /// - public Dictionary TilesDestroyed { get; protected set; } + public Dictionary TilesDestroyed { get; protected set; } /// /// A queue of tiles placed by the player for reverting. /// - public Dictionary TilesCreated { get; protected set; } + public Dictionary TilesCreated { get; protected set; } /// /// The player's group. @@ -641,8 +643,8 @@ namespace TShockAPI /// The player's index in the. public TSPlayer(int index) { - TilesDestroyed = new Dictionary(); - TilesCreated = new Dictionary(); + TilesDestroyed = new Dictionary(); + TilesCreated = new Dictionary(); Index = index; Group = Group.DefaultGroup; IceTiles = new List(); @@ -655,8 +657,8 @@ namespace TShockAPI /// The player's name. protected TSPlayer(String playerName) { - TilesDestroyed = new Dictionary(); - TilesCreated = new Dictionary(); + TilesDestroyed = new Dictionary(); + TilesCreated = new Dictionary(); Index = -1; FakePlayer = new Player {name = playerName, whoAmI = -1}; Group = Group.DefaultGroup; @@ -1022,6 +1024,14 @@ namespace TShockAPI NetMessage.SendPlayerHurt(Index, PlayerDeathReason.LegacyDefault(), damage, (new Random()).Next(-1, 1), false, false, 0, -1, -1); } + /// + /// Kills the player. + /// + public virtual void KillPlayer() + { + NetMessage.SendPlayerDeath(Index, PlayerDeathReason.LegacyDefault(), 99999, (new Random()).Next(-1, 1), false, -1, -1); + } + /// /// Sets the player's team. /// diff --git a/TShockAPI/TSServerPlayer.cs b/TShockAPI/TSServerPlayer.cs index 72517a52..94036b96 100644 --- a/TShockAPI/TSServerPlayer.cs +++ b/TShockAPI/TSServerPlayer.cs @@ -16,6 +16,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +using Microsoft.Xna.Framework; +using OTAPI.Tile; using System; using System.Collections.Generic; using Terraria; @@ -165,10 +167,10 @@ namespace TShockAPI NetMessage.SendData((int)PacketTypes.NpcStrike, -1, -1, "", npcid, damage, knockBack, hitDirection); } - public void RevertTiles(Dictionary tiles) + public void RevertTiles(Dictionary tiles) { // Update Main.Tile first so that when tile sqaure is sent it is correct - foreach (KeyValuePair entry in tiles) + foreach (KeyValuePair entry in tiles) { Main.tile[(int)entry.Key.X, (int)entry.Key.Y] = entry.Value; } diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs old mode 100755 new mode 100644 index 88766e8d..493ec01a --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -39,6 +39,8 @@ using TShockAPI.DB; using TShockAPI.Hooks; using TShockAPI.ServerSideCharacters; using Terraria.Utilities; +using Microsoft.Xna.Framework; +using TShockAPI.Sockets; namespace TShockAPI { @@ -46,13 +48,13 @@ namespace TShockAPI /// This is the TShock main class. TShock is a plugin on the TerrariaServerAPI, so it extends the base TerrariaPlugin. /// TShock also complies with the API versioning system, and defines its required API version here. /// - [ApiVersion(1, 26)] + [ApiVersion(2, 0)] public class TShock : TerrariaPlugin { /// VersionNum - The version number the TerrariaAPI will return back to the API. We just use the Assembly info. public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version; /// VersionCodename - The version codename is displayed when the server starts. Inspired by software codenames conventions. - public static readonly string VersionCodename = "Yoraiz0r R0cks"; + public static readonly string VersionCodename = "Mintaka"; /// SavePath - This is the path TShock saves its data in. This path is relative to the TerrariaServer.exe (not in ServerPlugins). public static string SavePath = "tshock"; @@ -183,7 +185,20 @@ namespace TShockAPI string logFilename; string logPathSetupWarning; - TerrariaApi.Reporting.CrashReporter.HeapshotRequesting += CrashReporter_HeapshotRequesting; + OTAPI.Hooks.Net.Socket.Create = () => + { + //Console.WriteLine($"Creating socket {nameof(LinuxTcpSocket)}"); + return new LinuxTcpSocket(); + //return new OTAPI.Sockets.PoolSocket(); + //return new Terraria.Net.Sockets.TcpSocket(); + }; + OTAPI.Hooks.Player.Announce = (int playerId) => + { + //TShock handles this + return OTAPI.HookResult.Cancel; + }; + + TerrariaApi.Reporting.CrashReporter.HeapshotRequesting += CrashReporter_HeapshotRequesting; try { @@ -197,6 +212,10 @@ namespace TShockAPI Main.ServerSideCharacter = ServerSideCharacterConfig.Enabled; + //TSAPI previously would do this automatically, but the vanilla server wont + if (Netplay.ServerIP == null) + Netplay.ServerIP = IPAddress.Any; + DateTime now = DateTime.Now; // Log path was not already set by the command line parameter? if (LogPath == LogPathDefault) @@ -578,7 +597,7 @@ namespace TShockAPI { if (Main.worldPathName != null && Config.SaveWorldOnCrash) { - Main.worldPathName += ".crash"; + Main.ActiveWorldFileData._path += ".crash"; SaveManager.Instance.SaveWorld(); } } @@ -685,7 +704,7 @@ namespace TShockAPI } case "-autoshutdown": { - Main.instance.autoShut(); + Main.instance.EnableAutoShutdown(); break; } case "-autocreate": @@ -715,9 +734,11 @@ namespace TShockAPI int limit; if (int.TryParse(parms[++i], out limit)) { + /* Todo - Requires an OTAPI modification Netplay.MaxConnections = limit; ServerApi.LogWriter.PluginWriteLine(this, string.Format( - "Connections per IP have been limited to {0} connections.", limit), TraceLevel.Verbose); + "Connections per IP have been limited to {0} connections.", limit), TraceLevel.Verbose);*/ + ServerApi.LogWriter.PluginWriteLine(this, "\"-connperip\" is not supported in this version of TShock.", TraceLevel.Verbose); } else ServerApi.LogWriter.PluginWriteLine(this, "Invalid value given for command line argument \"-connperip\".", TraceLevel.Warning); @@ -1190,7 +1211,7 @@ namespace TShockAPI { if (args.Handled) return; - + if (!Config.AllowCrimsonCreep && (args.Type == TileID.Dirt || args.Type == TileID.FleshWeeds || TileID.Sets.Crimson[args.Type])) { @@ -1694,7 +1715,10 @@ namespace TShockAPI invasionSize = 100 + (Config.InvasionMultiplier * Utils.ActivePlayers()); } - Main.StartInvasion(type, invasionSize); + // Note: This is a workaround to previously providing the size as a parameter in StartInvasion + Main.invasionSize = invasionSize; + + Main.StartInvasion(type); } /// CheckProjectilePermission - Checks if a projectile is banned. diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index c6c65341..2b91163b 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -68,10 +68,14 @@ ..\packages\MySql.Data.6.9.8\lib\net45\MySql.Data.dll True - - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True + + False + ..\TerrariaServerAPI\TerrariaServerAPI\bin\Debug\OTAPI.dll + @@ -88,6 +92,7 @@ + @@ -178,9 +183,9 @@ - - {6877506E-ADC6-4142-98A6-79E4FA02855A} - TerrariaServer + + {6877506e-adc6-4142-98a6-79e4fa02855a} + TerrariaServerAPI @@ -194,7 +199,7 @@ - +