示例#1
0
        protected void PrintWarning(string format, params object[] args)
        {
            OxideMod oxide = Interface.Oxide;

            object[] title = new object[] { base.Title, null };
            title[1] = (args.Length != 0 ? string.Format(format, args) : format);
            oxide.LogWarning("[{0}] {1}", title);
        }
示例#2
0
 void OnDestroy()
 {
     if (oxideMod.IsShuttingDown)
     {
         return;
     }
     oxideMod.LogWarning("The Oxide Unity Script was destroyed (creating a new instance)");
     oxideMod.NextTick(Create);
 }
示例#3
0
        public Connection OpenDb(string conStr, Plugin plugin, bool persistent = false)
        {
            Dictionary <string, Connection> strs;
            Connection connection;
            object     name;
            object     connectionString;
            object     obj;
            Dictionary <string, Dictionary <string, Connection> > strs1 = this._connections;

            if (plugin != null)
            {
                name = plugin.get_Name();
            }
            else
            {
                name = null;
            }
            if (name == null)
            {
                name = "null";
            }
            if (!strs1.TryGetValue((string)name, out strs))
            {
                Dictionary <string, Dictionary <string, Connection> > strs2 = this._connections;
                if (plugin != null)
                {
                    obj = plugin.get_Name();
                }
                else
                {
                    obj = null;
                }
                if (obj == null)
                {
                    obj = "null";
                }
                Dictionary <string, Connection> strs3 = new Dictionary <string, Connection>();
                strs = strs3;
                strs2[(string)obj] = strs3;
            }
            if (!strs.TryGetValue(conStr, out connection))
            {
                Connection connection1 = new Connection(conStr, persistent);
                connection1.set_Plugin(plugin);
                connection1.set_Con(new MySqlConnection(conStr));
                connection   = connection1;
                strs[conStr] = connection;
            }
            else
            {
                OxideMod     oxide    = Interface.get_Oxide();
                object[]     objArray = new object[1];
                DbConnection con      = connection.get_Con();
                if (con != null)
                {
                    connectionString = con.ConnectionString;
                }
                else
                {
                    connectionString = null;
                }
                objArray[0] = connectionString;
                oxide.LogWarning("Already open connection ({0}), using existing instead...", objArray);
            }
            if (plugin != null && !this._pluginRemovedFromManager.ContainsKey(plugin))
            {
                this._pluginRemovedFromManager[plugin] = plugin.OnRemovedFromManager.Add(new Action <Plugin, PluginManager>(this.OnRemovedFromManager));
            }
            return(connection);
        }
示例#4
0
        private void OnRemovedFromManager(Plugin sender, PluginManager manager)
        {
            Event.Callback <Plugin, PluginManager> callback;
            bool          state;
            object        name;
            List <string> strs = new List <string>();

            foreach (KeyValuePair <string, Connection> _connection in this._connections)
            {
                if ((object)_connection.Value.get_Plugin() != (object)sender)
                {
                    continue;
                }
                DbConnection con = _connection.Value.get_Con();
                if (con != null)
                {
                    state = con.State != ConnectionState.Closed;
                }
                else
                {
                    state = true;
                }
                if (state)
                {
                    OxideMod oxide            = Interface.get_Oxide();
                    object[] connectionString = new object[] { _connection.Value.get_ConnectionString(), null };
                    Plugin   plugin           = _connection.Value.get_Plugin();
                    if (plugin != null)
                    {
                        name = plugin.get_Name();
                    }
                    else
                    {
                        name = null;
                    }
                    if (name == null)
                    {
                        name = "null";
                    }
                    connectionString[1] = name;
                    oxide.LogWarning("Unclosed sqlite connection ({0}), by plugin '{1}', closing...", connectionString);
                }
                DbConnection dbConnection = _connection.Value.get_Con();
                if (dbConnection != null)
                {
                    dbConnection.Close();
                }
                else
                {
                }
                _connection.Value.set_Plugin(null);
                strs.Add(_connection.Key);
            }
            foreach (string str in strs)
            {
                this._connections.Remove(str);
            }
            if (this._pluginRemovedFromManager.TryGetValue(sender, out callback))
            {
                callback.Remove();
                this._pluginRemovedFromManager.Remove(sender);
            }
        }
示例#5
0
        private void OnRemovedFromManager(Plugin sender, PluginManager manager)
        {
            Dictionary <string, Connection> strs;

            Event.Callback <Plugin, PluginManager> callback;
            bool   state;
            object connectionString;
            object name;

            if (this._connections.TryGetValue(sender.get_Name(), out strs))
            {
                foreach (KeyValuePair <string, Connection> keyValuePair in strs)
                {
                    if ((object)keyValuePair.Value.get_Plugin() != (object)sender)
                    {
                        continue;
                    }
                    DbConnection con = keyValuePair.Value.get_Con();
                    if (con != null)
                    {
                        state = con.State != ConnectionState.Closed;
                    }
                    else
                    {
                        state = true;
                    }
                    if (state)
                    {
                        OxideMod     oxide        = Interface.get_Oxide();
                        object[]     objArray     = new object[2];
                        DbConnection dbConnection = keyValuePair.Value.get_Con();
                        if (dbConnection != null)
                        {
                            connectionString = dbConnection.ConnectionString;
                        }
                        else
                        {
                            connectionString = null;
                        }
                        objArray[0] = connectionString;
                        Plugin plugin = keyValuePair.Value.get_Plugin();
                        if (plugin != null)
                        {
                            name = plugin.get_Name();
                        }
                        else
                        {
                            name = null;
                        }
                        if (name == null)
                        {
                            name = "null";
                        }
                        objArray[1] = name;
                        oxide.LogWarning("Unclosed mysql connection ({0}), by plugin '{1}', closing...", objArray);
                    }
                    DbConnection con1 = keyValuePair.Value.get_Con();
                    if (con1 != null)
                    {
                        con1.Close();
                    }
                    else
                    {
                    }
                    keyValuePair.Value.set_Plugin(null);
                }
                this._connections.Remove(sender.get_Name());
            }
            if (this._pluginRemovedFromManager.TryGetValue(sender, out callback))
            {
                callback.Remove();
                this._pluginRemovedFromManager.Remove(sender);
            }
        }