RemoteAdmin:RemoteAdmin Implement new command/de

From OpenSimulator

Revision as of 03:16, 31 August 2017 by Manni (Talk | contribs)

Jump to: navigation, search


So implementieren Sie neue Befehle an Remote Admin

Bei der Implementierung eines neuen RemoteAdmin-Befehls müssen Sie die Datei /OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs bearbeiten

Bitte beachten Sie die RemoteAdmin Standards für das vorgeschlagene Namensschema.


Nehmen wir an, wir wollen einen Befehl erstellen, der eine Zeile in der Konsole ausgibt, die eine Nachricht und die Region uuid einer Region enthält, die wir wählen.

Schritt 1 - Hinzufügen eines neuen Befehls

Zuerst müssen wir unseren neuen Befehl definieren und zur Verfügung stellen. In der Funktion public void Initialise(OpenSimBase openSim) inden Sie eine Liste aller implementierten Befehle. Die verfügbaren Befehle beginnen mit availableMethods.... Dort fügen wir unseren neuen Befehl hinzu, nennen wir admin_output_message.

Wir werden nun eine neue availableMethods zu den bereits aufgeführten hinzufügen, waren admin_output_message ist unser Befehl und XmlRpcOutputMessage ist die Funktion, in der unser Befehl die Arbeit wehn aufgerufen hat (Schritt 2).

public void Initialise(OpenSimBase openSim)
        {
        ...
                    //Unser neuer Befehl
                    availableMethods["admin_output_message"] = (req, ep) => InvokeXmlRpcMethod(req, ep, XmlRpcOutputMessage);
        ...
        }

Schritt 2 - Codierung unseres neuen Kommandos

In Step 1 we added a new command which calls the function XmlRpcOutputMessage. So our next step is to create our new function and include all the goddies our command will execute.

private void XmlRpcOutputMessage(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
        {
            //List with all parameters that will be returned
            Hashtable responseData = (Hashtable)response.Value;
            //List with all parameters received
            Hashtable requestData = (Hashtable)request.Params[0];
 
            //Check if the parameter message was received
            CheckStringParameters(requestData, responseData, new string[] { "message" });
 
            Scene scene = null;
            string error_message = String.Empty;
            responseData["success"] = false;
 
            //Check if a region with parameter region_id or region_name exist
            CheckRegionParamsInScene(requestData, out scene, out error_message);
 
            if (scene == null)
            {
                //The region is not known, so we send a error message
                responseData["error"] = error_message;
                throw new Exception(error_message);
            }
 
            // here we do all work when a region is found
            string message = (string) requestData["message"];
 
            m_log.InfoFormat("[RADMIN]: {0}: {1} {2}", message, scene.RegionInfo.RegionName, scene.RegionInfo.RegionID);
 
            // We have finished our work, lets send back some information
            responseData["success"] = true;
            responseData["region_name"] = scene.RegionInfo.RegionName;
        }
  • Our new function always starts of with creating the Hashtable responseData and requestData. In the requestData list we have all parameters we are recieving from our external application while responseData is the list of data we are sending back...
  • If we have parameters that are needed and may not be empty, then one check these parameters using CheckStringParameters and CheckIntegerParams. If any of the specified paramaters, in our case the string "message" is not given, then a error with exeption will be given and the rest of our code will not be executed.
  • As we want to send region data of a given region_id or region_name we use CheckRegionParamsInScene. This will output us the scene of the region if it exists. Both region_id and region_name are checked. If no region is found then scene = null and a error_mesage is returned. The error message can be used to send back as responseData["error"]
  • As a response we always send responseData["success"] as true or false were true only is returned if no errors occured.
  • If errors occure, we send the error message to our application as responseData["error"]

RemoteAdmin

Personal tools
General
About This Wiki