Skip to content

Commit

Permalink
Load TerrariaAPI 1.18
Browse files Browse the repository at this point in the history
Some interesting facts about this port:

1. UUIDs are no longer included in Terraria's server code; we need
to do that ourselves.
2. Some things from serverSock have been changed to RemoteClient;
many of which are not the same as they used to be

	E.g. ServerSock.kill is now RemoteClient.PendingTermination
  • Loading branch information
hakusaro committed Jul 3, 2015
1 parent 4f5ebc2 commit 68df888
Show file tree
Hide file tree
Showing 9 changed files with 419 additions and 311 deletions.
504 changes: 260 additions & 244 deletions Terraria/Main.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Terraria/Netplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Terraria
{
public class Netplay
{
public const int MaxConnections = 256;
public static int MaxConnections = 256;

This comment has been minimized.

Copy link
@SteelPhase

SteelPhase Jul 8, 2015

Converting this value to static allows this value to be changed by '-connperip', but It looks like nothing is actually reading this value.

public const int NetBufferSize = 1024;
public static string BanFilePath = "banlist.txt";
public static string ServerPassword = "";
Expand Down
33 changes: 14 additions & 19 deletions Terraria/ProgramServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Terraria.Social;
using TerrariaApi.Server;

namespace Terraria
{
Expand Down Expand Up @@ -208,32 +209,26 @@ private static void InnerStart(string[] args)
{
ProgramServer.Game.SetWorld(str, flag);
}
ProgramServer.Game.DedServ();
}
catch (Exception exception1)
{
Exception exception = exception1;
try
{
using (StreamWriter streamWriter = new StreamWriter("crashlog.txt", true))
{
streamWriter.WriteLine(DateTime.Now);
streamWriter.WriteLine(exception);
streamWriter.WriteLine("");
}
Console.WriteLine(string.Concat("Server crash: ", DateTime.Now));
Console.WriteLine(exception);
Console.WriteLine("");
Console.WriteLine("Please send crashlog.txt to support@terraria.org");
Console.WriteLine("TerrariaAPI Version: " + ServerApi.ApiVersion + " (Protocol {0} ({1}))", Terraria.Main.versionNumber2, Terraria.Main.curRelease);
ServerApi.Initialize(args, Game);
}
catch (Exception ex)
{
#if DEBUG
Console.WriteLine(ex);
System.Diagnostics.Debugger.Break();
ServerApi.LogWriter.ServerWriteLine(
"Startup aborted due to an exception in the Server API initialization:\n" + ex, TraceLevel.Error);

#endif
Console.ReadLine();
return;
}
ProgramServer.Game.DedServ();
ServerApi.DeInitialize();

}
catch (Exception exception1)
{
ServerApi.LogWriter.ServerWriteLine("Server crashed due to an unhandled exception:\n" + exception1, TraceLevel.Error);
}
}

Expand Down
68 changes: 34 additions & 34 deletions Terraria/ServerSock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,40 +90,40 @@ public void SpamClear()
this.spamDelBlock = 0f;
this.spamWater = 0f;
}
public static void CheckSection(int who, Vector2 position)
{
int sectionX = Netplay.GetSectionX((int)(position.X / 16f));
int sectionY = Netplay.GetSectionY((int)(position.Y / 16f));
int num = 0;
for (int i = sectionX - 1; i < sectionX + 2; i++)
{
for (int j = sectionY - 1; j < sectionY + 2; j++)
{
if (i >= 0 && i < Main.maxSectionsX && j >= 0 && j < Main.maxSectionsY && !Netplay.serverSock[who].tileSection[i, j])
{
num++;
}
}
}
if (num > 0)
{
int num2 = num;
NetMessage.SendData(9, who, -1, Lang.inter[44], num2, 0f, 0f, 0f, 0);
Netplay.serverSock[who].statusText2 = "is receiving tile data";
Netplay.serverSock[who].statusMax += num2;
for (int k = sectionX - 1; k < sectionX + 2; k++)
{
for (int l = sectionY - 1; l < sectionY + 2; l++)
{
if (k >= 0 && k < Main.maxSectionsX && l >= 0 && l < Main.maxSectionsY && !Netplay.serverSock[who].tileSection[k, l])
{
NetMessage.SendSection(who, k, l, false);
NetMessage.SendData(11, who, -1, "", k, (float)l, (float)k, (float)l, 0);
}
}
}
}
}
// public static void CheckSection(int who, Vector2 position)
// {
// int sectionX = Netplay.GetSectionX((int)(position.X / 16f));
// int sectionY = Netplay.GetSectionY((int)(position.Y / 16f));
// int num = 0;
// for (int i = sectionX - 1; i < sectionX + 2; i++)
// {
// for (int j = sectionY - 1; j < sectionY + 2; j++)
// {
// if (i >= 0 && i < Main.maxSectionsX && j >= 0 && j < Main.maxSectionsY && !Netplay.serverSock[who].tileSection[i, j])
// {
// num++;
// }
// }
// }
// if (num > 0)
// {
// int num2 = num;
// NetMessage.SendData(9, who, -1, Lang.inter[44], num2, 0f, 0f, 0f, 0);
// Netplay.serverSock[who].statusText2 = "is receiving tile data";
// Netplay.serverSock[who].statusMax += num2;
// for (int k = sectionX - 1; k < sectionX + 2; k++)
// {
// for (int l = sectionY - 1; l < sectionY + 2; l++)
// {
// if (k >= 0 && k < Main.maxSectionsX && l >= 0 && l < Main.maxSectionsY && !Netplay.serverSock[who].tileSection[k, l])
// {
// NetMessage.SendSection(who, k, l, false);
// NetMessage.SendData(11, who, -1, "", k, (float)l, (float)k, (float)l, 0);
// }
// }
// }
// }
// }
public bool SectionRange(int size, int firstX, int firstY)
{
for (int i = 0; i < 4; i++)
Expand Down
2 changes: 1 addition & 1 deletion TerrariaApi.Server/EventArgs/SendBytesEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TerrariaApi.Server
{
public class SendBytesEventArgs: HandledEventArgs
{
public ServerSock Socket
public RemoteClient Socket
{
get;
internal set;
Expand Down
2 changes: 1 addition & 1 deletion TerrariaApi.Server/EventArgs/SocketResetEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TerrariaApi.Server
{
public class SocketResetEventArgs : EventArgs
{
public ServerSock Socket
public RemoteClient Socket
{
get;
internal set;
Expand Down
10 changes: 5 additions & 5 deletions TerrariaApi.Server/HookManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ internal bool InvokeNetGetData(ref byte msgId, MessageBuffer buffer, ref int ind
case PacketTypes.ConnectRequest:
if (this.InvokeServerConnect(buffer.whoAmI))
{
Netplay.serverSock[buffer.whoAmI].kill = true;
Netplay.Clients[buffer.whoAmI].PendingTermination = true;
return true;
}

break;
case PacketTypes.ContinueConnecting2:
if (this.InvokeServerJoin(buffer.whoAmI))
{
Netplay.serverSock[buffer.whoAmI].kill = true;
Netplay.Clients[buffer.whoAmI].PendingTermination = true;
return true;
}

Expand Down Expand Up @@ -414,7 +414,7 @@ internal bool InvokeNetGetData(ref byte msgId, MessageBuffer buffer, ref int ind
Buffer.BlockCopy(buffer.readBuffer, index + 4, uuid, 0, length - 5);
SHA512 shaM = new SHA512Managed();
var result = shaM.ComputeHash(uuid);
Netplay.serverSock[buffer.whoAmI].clientUUID = result.Aggregate("", (s, b) => s + b.ToString("X2"));;
// Netplay.serverSock[buffer.whoAmI].clientUUID = result.Aggregate("", (s, b) => s + b.ToString("X2"));;
return true;

break;
Expand Down Expand Up @@ -469,7 +469,7 @@ public HandlerCollection<SendBytesEventArgs> NetSendBytes
get { return this.netSendBytes; }
}

internal bool InvokeNetSendBytes(ServerSock socket, byte[] buffer, int offset, int count)
internal bool InvokeNetSendBytes(RemoteClient socket, byte[] buffer, int offset, int count)
{
SendBytesEventArgs args = new SendBytesEventArgs
{
Expand Down Expand Up @@ -937,7 +937,7 @@ public HandlerCollection<SocketResetEventArgs> ServerSocketReset
get { return this.serverSocketReset; }
}

internal void InvokeServerSocketReset(ServerSock socket)
internal void InvokeServerSocketReset(RemoteClient socket)
{
SocketResetEventArgs args = new SocketResetEventArgs
{
Expand Down
13 changes: 7 additions & 6 deletions TerrariaApi.Server/ServerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class ServerApi
{
public const string PluginsPath = "ServerPlugins";

public static readonly Version ApiVersion = new Version(1, 17, 0, 0);
public static readonly Version ApiVersion = new Version(1, 18, 0, 0);
private static Main game;
private static readonly Dictionary<string, Assembly> loadedAssemblies = new Dictionary<string, Assembly>();
private static readonly List<PluginContainer> plugins = new List<PluginContainer>();
Expand Down Expand Up @@ -139,7 +139,7 @@ internal static void HandleCommandLine(string[] commandLineArgs)
int serverPort;
if (int.TryParse(commandLineArgs[++i], out serverPort))
{
Netplay.serverPort = serverPort;
Netplay.ListenPort = serverPort;
LogWriter.ServerWriteLine(string.Format("Listening on port {0}.", serverPort), TraceLevel.Verbose);
}
else
Expand All @@ -153,7 +153,7 @@ internal static void HandleCommandLine(string[] commandLineArgs)
case "-world":
{
string worldPath = commandLineArgs[++i];
game.SetWorld(worldPath);
game.SetWorld(worldPath, false);
LogWriter.ServerWriteLine(string.Format("World set for auto loading: {0}", worldPath), TraceLevel.Verbose);

break;
Expand Down Expand Up @@ -182,7 +182,7 @@ internal static void HandleCommandLine(string[] commandLineArgs)
IPAddress ip;
if (IPAddress.TryParse(commandLineArgs[++i], out ip))
{
Netplay.serverListenIP = ip;
Netplay.ServerIP = ip;
LogWriter.ServerWriteLine(string.Format("Listening on IP {0}.", ip), TraceLevel.Verbose);
}
else
Expand All @@ -198,7 +198,7 @@ internal static void HandleCommandLine(string[] commandLineArgs)
int limit;
if (int.TryParse(commandLineArgs[++i], out limit))
{
Netplay.connectionLimit = limit;
Netplay.MaxConnections = limit;
LogWriter.ServerWriteLine(string.Format(
"Connections per IP have been limited to {0} connections.", limit), TraceLevel.Verbose);
}
Expand All @@ -209,7 +209,8 @@ internal static void HandleCommandLine(string[] commandLineArgs)
}
case "-killinactivesocket":
{
Netplay.killInactive = true;
// Netplay.killInactive = true;
LogWriter.ServerWriteLine("The argument -killinactivesocket is no longer present in Terraria.", TraceLevel.Warning);
break;
}
case "-lang":
Expand Down
96 changes: 96 additions & 0 deletions TerrariaServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
<AssemblyName>TerrariaServer</AssemblyName>
<OutputType>Exe</OutputType>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputPath>bin\Debug\</OutputPath>
Expand All @@ -29,6 +44,7 @@
<DebugType>pdbonly</DebugType>
<ErrorReport>prompt</ErrorReport>
<PlatformTarget>x86</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -77,9 +93,57 @@
<AutoGen>false</AutoGen>
<DesignTimeSharedInput>false</DesignTimeSharedInput>
</Compile>
<Compile Include="TerrariaApi.Server\ApiVersionAttribute.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\ChatEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\ChatReceivedEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\ChristmasCheckEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\CommandEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\ConnectEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\GetDataEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\GreetPlayerEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\HalloweenCheckEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\HardmodeTileUpdateEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\JoinEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\LeaveEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\MeteorDropEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\NameCollisionEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\NpcLootDropEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\NpcSpawnEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\NpcStrikeEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\NpcTransformationEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\ProjectileAiUpdateEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\SendBytesEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\SendDataEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\ServerChatEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\SetDefaultsEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\SocketResetEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\StatueSpawnEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\TriggerPressurePlateEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\UpdatePhysicsEventArgs.cs" />
<Compile Include="TerrariaApi.Server\EventArgs\WorldSaveEventArgs.cs" />
<Compile Include="TerrariaApi.Server\HandlerCollection.cs" />
<Compile Include="TerrariaApi.Server\HandlerRegistration.cs" />
<Compile Include="TerrariaApi.Server\HookManager.cs" />
<Compile Include="TerrariaApi.Server\ILogWriter.cs" />
<Compile Include="TerrariaApi.Server\IProfiler.cs" />
<Compile Include="TerrariaApi.Server\LogWriterManager.cs" />
<Compile Include="TerrariaApi.Server\Networking\IPacket.cs" />
<Compile Include="TerrariaApi.Server\Networking\PacketFactory.cs" />
<Compile Include="TerrariaApi.Server\Networking\PacketId.cs" />
<Compile Include="TerrariaApi.Server\Networking\PacketIdAttribute.cs" />
<Compile Include="TerrariaApi.Server\Networking\TerrariaPackets\VersionPacket.cs" />
<Compile Include="TerrariaApi.Server\PacketTypes.cs" />
<Compile Include="TerrariaApi.Server\PluginContainer.cs" />
<Compile Include="TerrariaApi.Server\ProfilerManager.cs" />
<Compile Include="TerrariaApi.Server\ServerApi.cs" />
<Compile Include="TerrariaApi.Server\ServerLogWriter.cs" />
<Compile Include="TerrariaApi.Server\TaskExt.cs" />
<Compile Include="TerrariaApi.Server\TerrariaPlugin.cs" />
<Compile Include="Terraria\IStaticPortMapping.cs" />
<Compile Include="Terraria\IStaticPortMappingCollection.cs" />
<Compile Include="Terraria\IUPnPNAT.cs" />
<Compile Include="Terraria\StreamExt.cs" />
<Compile Include="Terraria\StreamGenericExt.cs" />
<Compile Include="Terraria\UPnPNAT.cs" />
<Compile Include="Terraria\World.Generation\GenerationProgress.cs">
<AutoGen>false</AutoGen>
Expand Down Expand Up @@ -1349,8 +1413,40 @@
<AutoGen>false</AutoGen>
<DesignTimeSharedInput>false</DesignTimeSharedInput>
</Compile>
<Compile Include="XNA\Color.cs" />
<Compile Include="XNA\IPackedVector.cs" />
<Compile Include="XNA\MathHelper.cs" />
<Compile Include="XNA\Matrix.cs" />
<Compile Include="XNA\PackUtils.cs" />
<Compile Include="XNA\Point.cs" />
<Compile Include="XNA\Rectangle.cs" />
<Compile Include="XNA\Vector2.cs" />
<Compile Include="XNA\Vector3.cs" />
<Compile Include="XNA\Vector4.cs" />
<EmbeddedResource Include="Terraria.Libraries.Steamworks.NET.Steamworks.NET.dll" />
<EmbeddedResource Include="Terraria.Libraries.JSON.NET.Net40.Newtonsoft.Json.dll" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.4.5">
<Visible>False</Visible>
<ProductName>Windows Installer 4.5</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit 68df888

Please sign in to comment.