RemoteAdmin:RemoteAdmin Implement new command

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (Robot: Cosmetic changes)
m (How to implement new commands to Remote Admin: Fixing a typo)
 
Line 71: Line 71:
 
* 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.
 
* 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 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 responce we always send ''responseData["success"]'' as true or false were true only is returned if no errors occured.
+
* 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"]''
 
* If errors occure, we send the error message to our application as ''responseData["error"]''
  
 
[[RemoteAdmin]]
 
[[RemoteAdmin]]

Latest revision as of 18:32, 27 July 2014


[edit] How to implement new commands to Remote Admin

When implementing a new RemoteAdmin command you need to edit /OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs

Please see RemoteAdmin Standards for proposed naming schema


Lets assume we want to create a command that outputs a line in the console containing a message and the region uuid of a region we choose.

[edit] Step 1 - Adding a new Command

First we need to define our new command and make it available. In the function public void Initialise(OpenSimBase openSim) you will find a list of all implemented commands. The available commands start with availableMethods.... There we add our new command, lets call it admin_output_message.

We will now add a new availableMethods to those already listed, were admin_output_message is our command and XmlRpcOutputMessage will be the function in which our command does the work wehn called (step 2).

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

[edit] Step 2 - Coding our new command

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

General
About This Wiki