Forums Archived

This forum has been archived. No new posts can be made and no new users can sign up. It remains here for reference only.

Find the new forums here

How to Start / Stop server over plugin? NOT SOLVED ! MISSCLICK

  • 157 Views
  • Last Post 31 January 2022
  • Topic Is Solved
tbS_ posted this 29 January 2022

Hello again :)

Im trying to write a plugin, that need to stop the server, then do something and after that start the server. im already found that i can do over api: /API/ADSModule/Servers/SERVERIDHERE/Core/Login SERVERIDHERE i replace with InstanceID from my server.

const todo = { username: "admin", password: "123", token: "", rememberMe: "false" };

fetch('/API/ADSModule/Servers/4fb97e39-b5fe-44d7-8662-938abbd86f4b/Core/Login', { method: 'POST', body: JSON.stringify(todo), headers: { 'Content-type': 'application/json', 'accept': 'application/json', } }) .then(response => response.json()) .then(json => { console.log(json); });

but i cant login i only get error. VM26534:1 Uncaught (in promise) SyntaxError: Unexpected end of JSON input at :16:32

I try more methods for it. All work if i use /API/Core/Login but if i try to login in specific Instance not working.

So is it the right way for the plugin to login etc ? or are better ways avaible?

something like: AMPDataLoaded: function ()... that i can get there all information to stop and start the server where i am(at the server instance) ?

Order By: Standard | Newest | Votes
Mike posted this 29 January 2022

Is this an AMP plugin? If so, you you can do that from the AMP side. IApplicationWrapper has stop and start methods on it.

tbS_ posted this 29 January 2022

oh shit marked as answer sorry.

ahm yes it a amp plugin. anywhere i found more over IApplicationWrapper? I know about java, javascript, css, php etc but never before work with c#.

The plugin need to stop and start the server. because he need access to the files. He need to create a zip from the files and copy it to my webspace. (Valheim Mods :P)

tbS_ posted this 29 January 2022

In my PluginMain i think you mean this :

    public Task StopServer()
    {
        application.Stop();
        return Task.CompletedTask;
    }

but now.. how i do i call it at my Plugin.JS ?

Mike posted this 29 January 2022

Why are you wanting to stop it from JS? For that you just do API.Core.Start()

tbS_ posted this 29 January 2022

The plugin give me a tab where i loaded it. There is a textarea and a button for start create the modpack. When the button got clicked. he need to stop, create a zip and start the gameserver again. When i try per api. i only get error like first post. because i need to go over /API/ADSModule/Servers/SERVERIDHERE/Core/Login.. because i go over remotelogin (port 8080 main instance) so i cant use direct /API/Core/Stop or /Start etc. so u write then:

Is this an AMP plugin? If so, you you can do that from the AMP side. IApplicationWrapper has stop and start methods on it..

So i try to call this function that im created with Application.Stop(); in my Plugin.js where i call a Function on button Click. if u have an better idea i will be Thankful. First time with c# and i try and google much. but somtimes i didnt get it convert for amp.

This is the Plugin.js https://pastebin.com/qXhu1waa u see i call the function sync on button click.

and this is my PluginMain.cs https://pastebin.com/7E3zHwnE at the end i have StopServer.

So its an ampplugin and i need to only Stop the server and not the instance. but it need to work, without go direct to the instance ip:port.

Here is how i try it before complete per Javascript and the API. I write down comments behind every function

https://pastebin.com/nSwK4TKi

the other way i try over JS: https://pastebin.com/1BU6xquT

Mike posted this 30 January 2022

You're trying to use PHP for your frontend tab which isn't going to work. Plugin tabs must be HTML only. You shouldn't be trying to use Fetch at all - from your Javascript you use AMPs API object: API.ModuleName.MethodName()

tbS_ posted this 30 January 2022

i changed to html and in my javascript i delte my fetch. i try like you write. API.ValheimSyncPlugin.HelloPerson() and try this in console log to get the string out. i delete the params from helloperson. so i only get string back but get only undefinded. if i try fetch i get the string back after login.

tbS_ posted this 31 January 2022

Can u give me point that i can google to find? I only find with fetch etc. Nothing with api.modulename.methodname..

Close