Esempio n. 1
0
 public HttpManager(HttpManagerConfiguration config, ScriptManager scriptManager, ServerPlugin serverPlugin)
 {
     _config        = config;
     _scriptManager = scriptManager;
     _serverPlugin  = serverPlugin;
     if (_config.enabled)
     {
         _httpRouter   = new UriRouter();
         _httplistener = new HttpListener();
         _httplistener.Prefixes.Add("http://*:" + _config.port + "/");
         if (_config.authentication)
         {
             _httplistener.AuthenticationSchemes = AuthenticationSchemes.Basic;
         }
         else
         {
             _httplistener.AuthenticationSchemes = AuthenticationSchemes.None;
         }
         _httpRouter.DefineRoute("/script/execute/:script", (req, res, parameters) =>
         {
             LogMessage("Running Script " + parameters["script"]);
             if (_scriptManager.ExecuteScript(parameters["script"]))
             {
                 res.StatusCode        = 200;
                 res.StatusDescription = "OK";
             }
             else
             {
                 res.StatusCode        = 404;
                 res.StatusDescription = "NOT FOUND";
             }
         });
         _httpRouter.DefineRoute("/script/trigger/:trigger", (req, res, parameters) =>
         {
             string trigger = parameters["trigger"];
             IDictionary <string, string> queryParams = new Dictionary <string, string>();
             foreach (var k in req.QueryString.AllKeys)
             {
                 queryParams.Add(k, req.QueryString[k]);
             }
             LogMessage("Triggering Function '" + trigger + "' with " + ToString(queryParams));
             if (_scriptManager.ExecuteTrigger(trigger, queryParams))
             {
                 res.StatusCode        = 200;
                 res.StatusDescription = "OK";
             }
             else
             {
                 res.StatusCode        = 404;
                 res.StatusDescription = "NOT FOUND";
             }
         });
     }
 }
 public ScriptManager(ScriptManagerConfiguration config, ServerPlugin serverPlugin, ModGameAPI modGameApi)
 {
     _config        = config;
     _serverPlugin  = serverPlugin;
     _modGameApi    = modGameApi;
     _pythonApi     = new EmpyrionAPI(this);
     _sqlConnection = new Connection(_config.databaseFile);
     _engine        = Python.CreateEngine();
     _engine.SetSearchPaths(new string[] {
         "Content/Python",
         "Content/Scripts"
     });
     _handles = new Dictionary <ushort, Handle>();
     _scope   = _engine.CreateScope();
     _scope.ImportModule("clr");
     _scope.SetVariable("settings", settings   = new Dictionary <string, string>());
     _scope.SetVariable("empyrion", _pythonApi = new EmpyrionAPI(this));
     _scope.SetVariable("sql", _sqlConnection  = new Connection(_config.databaseFile));
     _triggeredCallbacks = new Dictionary <string, TriggeredCallback>();
     _factionCache       = new Dictionary <int, FactionInfo>();
     _playerCache        = new Dictionary <int, PlayerInfo>();
     LogMessage("PythonAPI Version " + typeof(ServerPlugin).Assembly.GetName().Version);
     LogMessage("IronPython Version " + typeof(Python).Assembly.GetName().Version);
 }