Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
nosoop committed Dec 5, 2020
0 parents commit 9eed381
Showing 5 changed files with 315 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore compiled SourceMod plugins

*.smx
231 changes: 231 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Defer Server Command

[:coffee: fund my caffeine addiction :coffee:](https://buymeacoff.ee/nosoop)

A small utility to defer execution of a command until after all configs have been buffered.
Created in response to [nosoop/SM-YetAnotherMapConfigPlugin#1][issue].

[issue]: https://github.com/nosoop/SM-YetAnotherMapConfigPlugin/issues/1

## Example

In a configuration file:

```
defer echo "Hello from defer!";
echo "Hello from config!";
```

"Hello from config!" will be printed out as the configuration file is being executed, and
"Hello from defer!" will be printed after all configuration files have been buffered.
44 changes: 44 additions & 0 deletions scripting/defer.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Internal server command `defer`.
*/
#pragma semicolon 1
#include <sourcemod>

#pragma newdecls required

#define PLUGIN_VERSION "1.0.0"
public Plugin myinfo = {
name = "Defer Server Utility",
author = "nosoop",
description = "Defers execution of commands until after configs have been executed",
version = PLUGIN_VERSION,
url = "https://github.com/nosoop"
}

#define MAX_COMMAND_LENGTH 1024

ArrayList g_DeferredCommands;

public void OnPluginStart() {
g_DeferredCommands = new ArrayList(ByteCountToCells(MAX_COMMAND_LENGTH));

RegServerCmd("defer", DeferCmd);
}

Action DeferCmd(int args) {
char buffer[MAX_COMMAND_LENGTH];
GetCmdArgString(buffer, sizeof(buffer));

g_DeferredCommands.PushString(buffer);
}

public void OnConfigsExecuted() {
while (g_DeferredCommands.Length) {
char buffer[MAX_COMMAND_LENGTH];

g_DeferredCommands.GetString(0, buffer, sizeof(buffer));
g_DeferredCommands.Erase(0);

ServerCommand("%s", buffer);
}
}

0 comments on commit 9eed381

Please sign in to comment.