Giter Site home page Giter Site logo

terrariaapi-server's Introduction

Terraria Server API

This is the Terraria Server API, the API that TShock for Terraria runs on.

Features

  • Hooks for the most used events & calls used by Terraria.
  • Runs plugins from the ServerPlugins folder.
  • Direct access to all methods inside Terraria Server itself.

terrariaapi-server's People

Contributors

axiskriel avatar cheahjs avatar codercow avatar hakusaro avatar marioe avatar olink avatar simon311 avatar stealownz avatar stevenh avatar zidonuke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terrariaapi-server's Issues

Allow headless servers

Currently if you start a server without a input stream/the input stream EOFs (/dev/null for example), the server will create a .crash file which leads to an "unsaveable" world.

This is because there's no null check on text here.

Sorry there's no PR attached, but it was already pretty messy to get a build system and to get to the cause of that crash.

-ip is missing

The -ip startup flag is missing from the API. It was implemented here originally.

API version

We never released 1,13 so I am assuming we are planning to release 1,13 when weve updated to the newest Terraria version.

The fancy api is ticked to 1,14 assuming we would release 1,13 prior to integrating so this issue is here to determine where we go.

plugins fail to load

seems to be an issue with how assemblies are loaded and whatnot. I will investigate it tomorrow sometime, but if someone else has any ideas...

Missing code??

I have look up the code and i think the worldgen.cs is missing this one?

public static void paintEffect(int x, int y, byte color, byte oldColor)
{
int color2 = (int)(color ?? oldColor); <------ I am not sure how to fix this
Color newColor = WorldGen.paintColor(color2);
for (int i = 0; i < 10; i++)
{
int num = Dust.NewDust(new Vector2((float)(x * 16), (float)(y * 16)), 16, 16, 143, 0f, 0f, 50, newColor, 1f);
if (Main.rand.Next(2) == 0)
{
Main.dust[num].noGravity = true;
Main.dust[num].scale *= 1.2f;
}
else
{
Main.dust[num].scale *= 0.5f;
}
}
}

Server API Revamp

Because 1.2 will probably force pretty much any plugin to upgrade, this would be a good opportunity to do have some major upgrades of the server api.

I would like to suggest a revamp of the current hook system, I think the best way to express my thoughts is by showing you a prototype implementation of it.
(Imagine all hooks to be defined by the HookManager class in the same way as the NetGetData is implemented. Could also use partial classes if this becomes too messy.)

This is how a plugin would then register a handler:
PluginAPI.Hooks.NetGetData.Register(this, this.Net_GetData, 10);

This implementation would have the following advantages:

  • Improves stablity because unhandled exceptions are catched for each handler, and if exceptions occur, the handler list invocation will not be aborted (thus one plugin wouldn't prevent other plugins from handling a given hook).
  • Lets plugins register each handler with a priority.
  • Gives the server more control over the plugin handlers which opens new possibilities in the future. (e.g. invoking of handlers with timeouts to detect deadlocks, deregister handlers and thus disable a plugin automatically if it is malfunctioning etc.)
  • Allows a plugin to register a profiler implementation which would easily allow to keep track of the server's performance and especially to detect malfunctioning / bad implemented plugins more easily.
  • Allows the server to have a proper log implementation where it can write informative messages to, where this log writer can be overridden by plugins. The server would of course implement a very basic log writer itself, which would then probably be overridden by a TShock log writer implementation once the plugin is loaded.

The only downside I see of this implementation is that the invoking of hooks eats a bit more performance than the old system, considering my (very vague) performance testing on this maybe a few nanosecs more per hook invoke within an average system.

Quick question

We have a hook for StrinkeNPC but it is never invoked, nor was it in 1.1.2. I am quite confused. Is there a reason why we dont use it?

PriorityClass mono incompatibility

The merge with 1.2.4 broke the boot process under mono. Seems that Terraria / ProgramServer.cs is setting the process priority immediately now on line 13, which is a root-only function call under mono. Commenting out lines 12 and 13 solve this problem and at least get the server booting.

Tiles still don't load up on the client, but that's beyond the scope of this issue (good luck with that!)

NPC Spawn Event not returning position.

I am making a TShock plugin and I am using the NPCSpawn hook. I can correctly get the NPC, but it's position (x,y) is always (0,0). Is this a bug or intended?

https://github.com/Deathmax/TerrariaAPI-Server/blob/d446a8288a5d7984f4298a507a64249865259472/TerrariaApi.Server/HookManager.cs#L632

public override void Initialize()
{
.....
ServerApi.Hooks.NpcSpawn.Register(this, OnNpcSpawn, 5);
....
}
....
public void OnNpcSpawn(NpcSpawnEventArgs args)
{
NPC npc= args.Npc;
Log.ConsoleInfo("NPC " + npc.type + " Spawned at " + npc.position.X + ", " + npc.position.Y);
}

NPC 61 Spawned at 0, 0
NPC 69 Spawned at 0, 0

syncJoin exception

[Server API] Error System.AggregateException
---> System.ObjectDisposedException
   at System.IO.__Error.StreamIsClosed()
   at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.BinaryWriter.Write(Int16 value)
   at Terraria.NetMessage.SendData(Int32 msgType, Int32 remoteClient, Int32 ignoreClient, String text, Int32 number, Single number2, Single number3, Single number4, Int32 number5)
   at Terraria.NetMessage.syncJoin(Int32 plr)
   at Terraria.MessageBuffer.<GetData>m__17()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
---> (Internal Exception #0) System.ObjectDisposedException
   at System.IO.__Error.StreamIsClosed()
   at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.BinaryWriter.Write(Int16 value)
   at Terraria.NetMessage.SendData(Int32 msgType, Int32 remoteClient, Int32 ignoreClient, String text, Int32 number, Single number2, Single number3, Single number4, Int32 number5)
   at Terraria.NetMessage.syncJoin(Int32 plr)
   at Terraria.MessageBuffer.<GetData>m__17()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()<---

Contribute

Hey everyone. Awesome project, but one question.. can I contribute?

Just saw some messy code and want to know if I could fix it up in my spare time.

Switch to async sockets on Mono

Regular socket BeginRead/Write does not work properly on Mono for Terraria. As a result, synchronous methods are used and gameplay is jerky.

Blue Flare

New item in last update, the changes in Lang.cs are missing, something like tshock can't find the item.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.