Jump to content

[DMPServer Plugin] DMPExtendedPlugins


dsonbill

Recommended Posts

WARNING: This can be incredibly dangerous; don't do something stupid with this - always think carefully about what you are putting in the shell folder, especially on Linux!

DMPExtendedPlugins is a plugin for DarkMultiPlayer server. It adds scripted admin commands to DMPServer via batch (windows), shell/bash/whatever (linux, hopefully - untested. someone take a look at the code and tell me if it's going to work, or just try it), and IronPython (Python 2.7, included binaries).

IronPython is licensed under the Apache License, Version 2.0 http://opensource.org/licenses/apache2.0.php

The source for IronPython can be found at http://ironpython.net/

DMPScriptedCommands is released under CC0 1.0 https://creativecommons.org/publicdomain/zero/1.0/

The source for DMPScriptedCommands can be found at http://pastebin.com/B6vJyK62

Installation & Download

1. Download DMPExtendedPlugins, bundled with IronPython: https://mega.co.nz/#!i9VkgTRY!0CwvSsONNhkrblyb2fJp7zvim9yK2h6_ZUCxX1Qg9Mc

2. Extract all contents to DMPServer directory

3. Run DMPServer, it will make the necessary directories in Plugins

4. Put batch/shell scripts in Plugins/shell

5. Put python scripts in Plugins/py

List of Available DMP Python Functions/Methods/Whathaveyou

  • DarkLog.Normal(str)
  • DarkLog.Debug(srt)
  • DarkLog.Error(srt)
  • DarkLog.Fatal(str)
  • MessageReader/Writer
  • Clients # Clients is ClientHandler
  • DarkMultiPlayerCommon # Must instantiate Common class, and probably enums too
  • OnRegister function # See Example in Plugins/py
  • Execute function # See Example in Plugins/py
  • Ability to register script or just execute when loaded, leading to whatever possibility you can think of using it for
  • Basic DMPPlugin interface functions; can't register it's own message types yet, because this is still "server-side only"
  • Will soon have other fancy functions to make your modding/scripting life easier with DMP :)

Want another function delegated to scripts? Ask in the thread!

Basic Example Python Script


description = "A simple test script"
#register_command = False #Default is True. If set to False, Execute will be called as soon as the script is read.
call_onregister = True #Default is False. If set to True, runs OnRegister once upon registering command.
call_onmessagereceived = True #Default is False.
#call_onclientconnect = True #Default is False.
#call_onclientdisconnect = True #Default is False.
#call_onclientauthenticated = True #Default is False.
#call_onupdate = True #Default is False.


#OnRegister is ignored if register_command is set to False
#OnRegister must take a string arg, because I'm very hacky
def OnRegister(compliance):
# OnRegister Test
DarkLog.Debug("Called OnRegister!") #Do heavy initialization here for commands.


def Execute(args):
# Logging Test
DarkLog.Normal("Logging from Python! [args] is " + args)
DarkLog.Normal("Messaging Testing")
DarkLog.Error("Messaging Testing")
DarkLog.Debug("Messaging Testing")
DarkLog.Fatal("Messaging Testing")

# Common Access Test
comn = Common()
DarkLog.Debug("Python Common Access Test: DMP " + comn.PROGRAM_VERSION)

# Clients Access Test
clients = Clients()
DarkLog.Debug("Python ClientHandler Access Test: Active Clients: " + str(clients.GetActiveClientCount()))



#DMP Plugin Interface
def OnUpdate():
pass


def OnClientConnect(client):
DarkLog.Debug("[ExamplePluginTest] " + client.playerName + " connected with the server")


def OnClientAuthenticated(client):
DarkLog.Debug("[ExamplePluginTest] " + client.playerName + " authenticated with the server")


def OnClientDisconnect(client):
DarkLog.Debug("[ExamplePluginTest] " + client.playerName + " disconnected from the server")


def OnMessageReceived(client, message):
DarkLog.Debug("[ExamplePluginTest] " + "Got a " + str(message.type) + " message from " + client.playerName)

DMPServer Example Output:


[19:53:36][DEBUG] : Loading settings...
[19:53:36][DEBUG] : System.IO compression works: True, test time: 6 ms.
[19:53:36][DEBUG] : Loading plugins!
[19:53:36][DEBUG] : Loaded C:\Users\Lance\Desktop\DMPServer\Plugins\DMPScriptedC
ommands.dll
[19:53:36][DEBUG] : Loading plugin: DMPScriptedCommands.ShellCommands
[19:53:36][INFO] : [ScriptedCommands|ShellCommands] Registered Command: test
[19:53:36][INFO] : [ScriptedCommands|ShellCommands] Registered Command: test1
[19:53:36][INFO] : [ScriptedCommands|ShellCommands] Registered Command: test2
[19:53:36][INFO] : [ScriptedCommands|ShellCommands] Registered Command: test3
[19:53:36][DEBUG] : Loaded plugin: DMPScriptedCommands.ShellCommands
[19:53:36][DEBUG] : Loading plugin: DMPScriptedCommands.PyCommands
[19:53:37][INFO] : [ScriptedCommands|PyCommands] Registered Command: pytest
[19:53:37][INFO] : [ScriptedCommands|PyCommands] Registered Command: pytest2
[19:53:37][DEBUG] : Loaded plugin: DMPScriptedCommands.PyCommands
[19:53:37][DEBUG] : Done!
[19:53:37][INFO] : Starting DMPServer v0.2.1.2, protocol 37
[19:53:37][INFO] : Loading universe...
[19:53:37][INFO] : Starting SUBSPACE server on port 6703...
[19:53:37][INFO] : Removed 0 debris
[19:53:38][INFO] : Ready!
/pytest2
[19:54:02][INFO] : Command input: /pytest2
[19:54:02][INFO] : Logging from Python! [args] is
[19:54:02][INFO] : Messaging Testing
[19:54:02][ERROR] : Messaging Testing
[19:54:02][DEBUG] : Messaging Testing
[19:54:02][FATAL] : Messaging Testing
[19:54:02][ERROR] : [PYTHON COMMAND ERROR] index out of range: 0
/pytest2 arg1 asd;lajk
[19:54:09][INFO] : Command input: /pytest2 arg1 asd;lajk
[19:54:09][INFO] : Logging from Python! [args] is arg1 asd;lajk
[19:54:09][INFO] : Messaging Testing
[19:54:09][ERROR] : Messaging Testing
[19:54:09][DEBUG] : Messaging Testing
[19:54:09][FATAL] : Messaging Testing
[19:54:09][INFO] : Arg 1: arg1 Arg 2: asd;lajk
/test
[19:54:38][INFO] : Command input: /test
/reloadPython
[19:54:42][INFO] : Command input: /reloadPython
[19:54:42][INFO] : [ScriptedCommands|PyCommands] Registered Command: pytest
[19:54:42][INFO] : [ScriptedCommands|PyCommands] Registered Command: pytest2
[19:54:43][INFO] : [Shell Output]========================[Shell Output]
Super epic results!
And here's the second line!


Waiting for 5 seconds, press a key to continue ..0
Output after sleeping 5 seconds!


/pytest2 arg1 asd;laj
[19:54:55][INFO] : Command input: /pytest2 arg1 asd;laj
[19:54:55][INFO] : Logging from Python! [args] is arg1 asd;laj
[19:54:55][INFO] : Messaging Testing
[19:54:55][ERROR] : Messaging Testing
[19:54:55][DEBUG] : Messaging Testing
[19:54:55][FATAL] : Messaging Testing
[19:54:55][INFO] : Arg 1: arg1 Arg 2: asd;laj
[19:54:55][INFO] : File Changed
/help
[19:55:06][INFO] : Command input: /help
[19:55:06][INFO] : exit - Shuts down the server
[19:55:06][INFO] : quit - Shuts down the server
[19:55:06][INFO] : shutdown - Shuts down the server
[19:55:06][INFO] : restart - Restarts the server
[19:55:06][INFO] : kick - Kicks a player from the server
[19:55:06][INFO] : ban - Bans a player from the server
[19:55:06][INFO] : banip - Bans an IP Address from the server
[19:55:06][INFO] : bankey - Bans a Guid from the server
[19:55:06][INFO] : pm - Sends a message to a player
[19:55:06][INFO] : admin - Sets a player as admin/removes admin from t
he player
[19:55:06][INFO] : whitelist - Change the server whitelist
[19:55:06][INFO] : test - Shell Command
[19:55:06][INFO] : test1 - Shell Command
[19:55:06][INFO] : test2 - Shell Command
[19:55:06][INFO] : test3 - Shell Command
[19:55:06][INFO] : reloadShell - Reloads the shell commands from scom
[19:55:06][INFO] : pytest - Python Command
[19:55:06][INFO] : pytest2 - A simple test script
[19:55:06][INFO] : reloadPython - Reloads the python commands from pycom
[19:55:06][INFO] : help - Displays this help
[19:55:06][INFO] : say - Broadcasts a message to clients
[19:55:06][INFO] : dekessler - Clears out debris from the server
[19:55:06][INFO] : nukeksc - Clears ALL vessels from KSC and the Runway
[19:55:06][INFO] : listclients - Lists connected clients
[19:55:06][INFO] : countclients - Counts connected clients
[19:55:06][INFO] : connectionstats - Displays network traffic usage


#Contents of Plugins/scom/test.cmd
@echo off
echo Super epic results!
echo And here's the second line!
timeout 5
echo Output after sleeping 5 seconds!


#Contents of Plugins/pycom/pytest.py
description = "A simple test script"


def Execute(args):
# Logging Test
DarkLog.Normal("Logging from Python! [args] is " + args)
DarkLog.Normal("Messaging Testing")
DarkLog.Error("Messaging Testing")
DarkLog.Debug("Messaging Testing")
DarkLog.Fatal("Messaging Testing")


# Args test
arg_list = args.split()


DarkLog.Normal("Arg 1: " + arg_list[0] + " Arg 2: " + arg_list[1])
DarkLog.Normal("File Changed")

Changelog

-----------------

The scripts can now be run automatically as part of plugin load, so you can write complete plugins in Python as long as what you need is there.

Since the scripts run in their own threads, you can just run indefinitely - just be careful about what you do, obviously. I believe the scripts need access to more functions.

Changed name to DMPExtendedPlugins, as per above functionality.

Added quite a few functions/data stuffs.

Changed pycom and scom to py and shell, respectively, to reflect the more general nature of the scripts.

Added the basic DMPPlugin Interface.

Prevent everything from dying upon failed scriptstuffs.

Edited by dsonbill
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...