Skip to content

Instantly share code, notes, and snippets.

@jasonmcleod
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save jasonmcleod/8963969 to your computer and use it in GitHub Desktop.

Select an option

Save jasonmcleod/8963969 to your computer and use it in GitHub Desktop.
PLUGIN.Title = "PlayersWebService"
PLUGIN.Description = "Publishes player list to a website"
local alternate = true
function PLUGIN:Init()
oxmin_mod = cs.findplugin("oxmin")
oxmin_mod:AddExternalOxminChatCommand(self, "online", {}, cmdList)
end
function cmdList()
local pclist = rust.GetAllNetUsers()
local count = 0
local names = ""
for key,value in pairs(pclist) do
count = count + 1
end
for i=1, count do
names = names .. "," .. util.QuoteSafe(pclist[i].displayName)
end
webrequest.Send("http://YOUR_WEBSITE/online.php?key=SOME_FANCY_KEY&list=" .. names, function(code, content) if(code == 200) then print(content) end end)
end
function PLUGIN:OnUserDisconnect()
timer.Once(3,cmdList);
end
function PLUGIN:OnUserConnect()
cmdList();
end
@jasonmcleod
Copy link
Author

You'll need to post this php script on your own web server. Of course you could write this in any language, just have it accept the list and some token.

<?
    if(isset($_GET['key']) && $_GET['key']=='SOME_FANCY_KEY' && isset($_GET['list'])) {
        $list = $_GET['list'];
        $players = explode(',',$list);
        array_shift($players);
        file_put_contents('online.json', json_encode($players));    
    }
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment