Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation of the oxide core hooks #4

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
14585bb
Code modification to use both files docs.json and docs_core.json
Lorenzo-oo Oct 1, 2024
04907ef
Documention of the oxide core hooks
Lorenzo-oo Oct 1, 2024
acbb51b
Merge branch 'OxideMod:main' into main
Lorenzo-oo Oct 3, 2024
f5ee857
More flexible Docs json file to support multiple .JSON files
Lorenzo-oo Oct 9, 2024
7c177e2
Merge branch 'OxideMod:main' into main
Lorenzo-oo Oct 9, 2024
0a854f9
-
Lorenzo-oo Oct 9, 2024
e71a543
Merge branch 'main' of https://github.com/Lorenzo-oo/Oxide.Docs
Lorenzo-oo Oct 9, 2024
482abeb
-
Lorenzo-oo Oct 9, 2024
388d4d9
Add hook ReturnType
Lorenzo-oo Oct 16, 2024
308413a
Add Hook ReturnType
Lorenzo-oo Oct 16, 2024
ce58048
Add Hook ReturnType
Lorenzo-oo Oct 16, 2024
b632d10
Merge branch 'OxideMod:main' into main
Lorenzo-oo Dec 29, 2024
be3e7da
missing return line in sample code, when return value is not void
Lorenzo-oo Dec 29, 2024
a14a886
Merge branch 'main' of https://github.com/Lorenzo-oo/Oxide.Docs
Lorenzo-oo Dec 29, 2024
54cde9e
Add documentation for Attributes and Timers
Lorenzo-oo Jan 10, 2025
d368fed
Merge branch 'OxideMod:main' into main
Lorenzo-oo Jan 10, 2025
83950b4
Add Permissions.md, Database.md, WebRequest.md
Lorenzo-oo Jan 10, 2025
54e40dd
Merge branch 'main' of https://github.com/Lorenzo-oo/Oxide.Docs
Lorenzo-oo Jan 10, 2025
9042ec1
fix typo
Lorenzo-oo Jan 12, 2025
989b8b6
missing HookMethod (was not sure if available to plugins)
Lorenzo-oo Jan 16, 2025
c5ba718
Merge branch 'OxideMod:main' into main
Lorenzo-oo Feb 5, 2025
a63ea24
Merge branch 'OxideMod:main' into main
Lorenzo-oo Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions docs/guides/developers/Attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
title: Attributes
after: WebRequests
---
# Attributes
## Commands

Custom commands are easily implemented with minimal boilerplate for both in-game chat interfaces and conventional command-line interfaces.
## Chat commands
Chat commands are in-game commands entered via the game client's chat, prefixed by a forward slash (/).

when using covalence
```csharp
[Command("test")]
private void TestCommand(IPlayer player, string command, string[] args)
{
player.Reply("Test successful!");
}
```
when using Rustplugin
```csharp
[ChatCommand("test")]
void cmdTest (BasePlayer player, string command, string [] args)
{
Puts("Test successful!");
}
```
## Console commands
Console commands may be executed from the server console and in-game interfaces F1 (where applicable).

when using covalence
```csharp
[Command("test")]
private void TestCommand(IPlayer player, string command, string[] args)
{
player.Reply("Test successful!");
}
```
when using Rustplugin
```csharp
[ConsoleCommand("test")]
private void cmdTest((ConsoleSystem.Arg arg))
{
Puts("Test successful!");
}
```
## Command permissions
Easily restrict command usage to players who have a permission assigned to them.
```csharp
[Command("test"), Permission("epicstuff.use")]
private void TestCommand(IPlayer player, string command, string[] args)
{
player.Reply("Test successful!");
}
```
## Info
Information about the plugin. plugin name (with spaces between words), Developper or maintainer name, and a 3 digit version number.
```csharp
[Info("Plugin name", "Developper/Maintainer", "1.0.0")]
```
## Description
A short description of what the plugin does
```csharp
[Description("A short description of the plugin")]
```
## PluginReference
Reference to other plugin, when this plugin need to use functions from other plugins.

```csharp
[PluginReference] private Plugin Vanish, Backpacks;
```
Note: when a plugin is required by this plugin, this line should appear at the top.
```csharp
//Requires: Backpacks
```
If required plugin is absent from plugin folder, this plugin will not start

## OnlinePlayers
Auto manage an Hashtable of online players.

see Bank and Trade plugin for usage example
```csharp
class OnlinePlayer
{
public BasePlayer Player;
public OnlinePlayer (BasePlayer player)
{
}
}

[OnlinePlayers]
Hash<BasePlayer, OnlinePlayer> onlinePlayers = new Hash<BasePlayer, OnlinePlayer> ();
```
## HookMethod
Indicates that the specified method should be a handler for a hook
```csharp
[HookMethod("OnPlayerConnected")]
private void base_OnPlayerConnected(BasePlayer player) => AddOnlinePlayer(player);
```

## AutoPatch
Used with HarmonyPatch to automatically install harmony patch when plugin start, and uninstall when plugin terminate
```csharp
[AutoPatch]
[HarmonyPatch(typeof(Planner), "DoPlace")]
static class DoPlace_Process
{
[HarmonyPrefix]
private static bool Prefix()
{
UnityEngine.Debug.Log($"[Harmony] Planner DoPlace ");
return true;
}
}
```
Note: see harmony documentation for info about harmony patches
103 changes: 103 additions & 0 deletions docs/guides/developers/Database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
title: Database
after: Permissions
---
# Database

The Oxide database extensions implement a generalized database abstraction layer for both MySQL and SQLite.
## Open a connection

Create a new connection to a database by providing the database file location or an address (URI and port), a database name, and authentication credentials.
```csharp
Core.MySql.Libraries.MySql sqlLibrary = Interface.Oxide.GetLibrary<Core.MySql.Libraries.MySql>();
Connection sqlConnection = sqlLibrary.OpenDb("localhost", 3306, "umod", "username", "password", this);
```
## Close the connection

Close an existing connection to the database.
```csharp
sqlLibrary.CloseDb(sqlConnection);
```
## Query the database

Retrieve data from the database, typically using a SELECT statement.
```csharp
string sqlQuery = "SELECT `id`, `field1`, `field2` FROM example_table";
Sql selectCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery);

sqlLibrary.Query(selectCommand, sqlConnection, list =>
{
if (list == null)
{
return; // Empty result or no records found
}

StringBuilder newString = new StringBuilder();
newString.AppendLine(" id\tfield1\tfield2");

// Iterate through resulting records
foreach (Dictionary<string, object> entry in list)
{
newString.AppendFormat(" {0}\t{1}\t{2}\n", entry["id"], entry["field1"], entry["field2"]);
}

Puts(newString.ToString());
});
```
## Insert query

Insert records into the database using an INSERT statement.
```csharp
string sqlQuery = "INSERT INTO example_table (`field1`, `field2`) VALUES (@0, @1);";
Sql insertCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, "field1 value", "field2 value");

sqlLibrary.Insert(insertCommand, sqlConnection, rowsAffected =>
{
if (rowsAffected > 0)
{
Puts("New record inserted with ID: {0}", sqlConnection.LastInsertRowId);
}
});
```
## Update query

Update existing records in the database using an UPDATE statement.
```csharp
int exampleId = 2;
string sqlQuery = "UPDATE example_table SET `field1` = @0, `field2` = @1 WHERE `id` = @2;";
Sql updateCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, "field1 value", "field2 value", exampleId);

sqlLibrary.Update(updateCommand, sqlConnection, rowsAffected =>
{
if (rowsAffected > 0)
{
Puts("Record successfully updated!");
}
});
```
## Delete query

Delete existing records from a database using a DELETE statement.
```csharp
int exampleId = 2;
string sqlQuery = "DELETE FROM example_table WHERE `id` = @0;";
Sql deleteCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, exampleId);

sqlLibrary.Delete(deleteCommand, sqlConnection, rowsAffected =>
{
if (rowsAffected > 0)
{
Puts("Record successfully deleted!");
}
});
```
## Non-query

By definition a non-query is a query which modifies data and does not retrieve data. Insert, Update, and Delete queries are all considered non-queries.
```csharp
int exampleId = 2;
string sqlQuery = "UPDATE example_table SET `field1` = @0, `field2` = @1 WHERE `id` = @3;";
Sql sqlCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery, "field1 value", "field2 value", exampleId);

sqlLibrary.ExecuteNonQuery(sqlCommand, sqlConnection);
```
126 changes: 126 additions & 0 deletions docs/guides/developers/Permissions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
title: Permissions
after: Attributes
---
# Permissions

Oxide offers a substantial API to control user access with permissions and groups
Basic usage

For a primer on how to use permissions as a server owner, please consult the Using the Oxide permissions system tutorial.

Most plugins can benefit from some permissions. Below is a basic example of how to register a permission and check if a player has that permission assigned to them.
```csharp
namespace Oxide.Plugins
{
[Info("Epic Stuff", "Unknown Author", "0.1.0")]
[Description("Makes epic stuff happen")]
class EpicStuff : CovalencePlugin
{
private void Init()
{
permission.RegisterPermission("epicstuff.use", this);
}

private void OnUserConnected(IPlayer player)
{
if (player.HasPermission("epicstuff.use"))
{
// Player has permission, do special stuff for them
}
}
}
}
```
# API
## Groups
Get all groups
```csharp
string[] groups = permission.GetGroups();
```
Check if group exists
```csharp
bool GroupExists = permission.GroupExists("GroupName");
```
Create a group
```csharp
bool GroupCreated = permission.CreateGroup("GroupName", "Group Title", 0);
```
Remove a group
```csharp
bool GroupRemoved = permission.RemoveGroup("GroupName");
```
Check if group has a permission
```csharp
bool GroupHasPermission = permission.GroupHasPermission("GroupName", "epicstuff.use");
```
Grant permission to a group
```csharp
permission.GrantGroupPermission("GroupName", "epicstuff.use", this);
```
Revoke permission from a group
```csharp
permission.RevokeGroupPermission("GroupName", "epicstuff.use");
```
Get the rank for a group
```csharp
int GroupRank = permission.GetGroupRank("GroupName");
```
Get the title for a group
```csharp
string GroupTitle = permission.GetGroupTitle("GroupName");
```
Get parent group for a group
```csharp
string GroupParent = permission.GetGroupParent("GroupName");
```
Get permissions for a group
```csharp
string[] permissions = permission.GetGroupPermissions("GroupName", false);
```
Migrate group
```csharp
permission.MigrateGroup("OldGroupName", "NewGroupName");
```
## Users
Get permissions granted to player
```csharp
string[] UserPermissions = permission.GetUserPermissions("playerID");
```
Check if player has a permission
```csharp
bool UserHasPermission = permission.UserHasPermission("playerID", "epicstuff.use");
```
Add player to a group
```csharp
permission.AddUserGroup("playerID", "GroupName");
```
Remove player from a group
```csharp
permission.RemoveUserGroup("playerID", "GroupName");
```
Check if player is in a group
```csharp
bool UserHasGroup = permission.UserHasGroup("playerID", "GroupName");
```
Grant permission to a player
```csharp
permission.GrantUserPermission("playerID", "epicstuff.use", this);
```
Revoke permission from a player
```csharp
permission.RevokeUserPermission("playerID", "epicstuff.use");
```
## Server
Get all registered permissions
```csharp
string[] permissions = permission.GetPermissions();
```
Check if a permission exists
```csharp
bool PermissionExists = permission.PermissionExists("epicstuff.use", this);
```
Register a permission
```csharp
permission.RegisterPermission("epicstuff.use", this);
```
Loading