[WIP] Added code

This commit is contained in:
Sven Heidemann 2023-12-12 16:54:53 +01:00
commit 8bad835c2e
7 changed files with 192 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
server/

13
install_server.sh Executable file
View File

@ -0,0 +1,13 @@
mkdir -p server/steam
cd server/steam
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
tar xfvz steamcmd_linux.tar.gz
rm steamcmd_linux.tar.gz
cd ..
./steam/steamcmd.sh +force_install_dir ../ +login anonymous +app_update 565060 validate +quit
cd ..
echo "done"

5
src/config.lua Normal file
View File

@ -0,0 +1,5 @@
local config = {
apiKey = "",
apiURL = ""
}
return config

6
src/modconfig.lua Normal file
View File

@ -0,0 +1,6 @@
modLocation = ""
forceEnabling = false
mods={
{path = "galaxy/galaxy/mods/sh_ontime_handler_avorion"}
}

View File

@ -0,0 +1,97 @@
local http = require('http')
local config = {}
function error(message, err)
print("Sh_ONTIME_HANDLER", "ERROR", message, err)
end
function info(message)
print("Sh_ONTIME_HANDLER", "INFO", message)
end
local function readFile(path)
local open = io.open
local file = open(path, "rb") -- r read mode and b binary mode
if not file then return nil end
local content = file:read "*a" -- *a or *all reads the whole file
file:close()
return content
end
function readConfig()
config = require(scriptPath():gsub("sh_ontime_handler_avorion/main.lua", "config"))
if config == nil or config.apiURL == nil or config.apiKey == nil then
error("Invalid config!")
exit()
end
info("Config loaded")
end
local function getUserJoinedMutation(id)
local json = require('json')
return json.encode({
query = "mutation { userJoinedGameServer { userJoined(input: { ident = \"" .. id .. "\" }) { id } } }"
})
end
local function getUserLeftMutation(id)
local json = require('json')
return json.encode({
query = "mutation { userJoinedGameServer { userLeft(input: { ident = \"" .. id .. "\" }) { id } } }"
})
end
function sendJoinedPlayer(id)
local client = http.client()
local request = http.request.new()
request.uri = config.ApiURL
request.method = "POST"
request.headers["Authorization"] = "API-Key " .. config.ApiKey
request.headers["Content-Type"] = "application/json"
request.body = getUserJoinedMutation(id)
local response = client:send(request)
local success, result = pcall(json.parse, response.body)
if success then
local joinId = tonumber(result.data.userJoinedGameServer.userJoined.id)
else
error("Cannot send player joined", "")
end
end
function sendLeftPlayer(id)
local client = http.client()
local request = http.request.new()
request.uri = config.ApiURL
request.method = "POST"
request.headers["Authorization"] = "API-Key " .. config.ApiKey
request.headers["Content-Type"] = "application/json"
request.body = getUserLeftMutation(id)
local response = client:send(request)
local success, result = pcall(json.parse, response.body)
if success then
local joinId = tonumber(result.data.userJoinedGameServer.userJoined.id)
else
error("Cannot send player left", "")
end
end
function initialize()
Server():registerCallback("onPlayerLogIn", "handlePlayerJoined")
Server():registerCallback("onPlayerLogOff", "handlePlayerLeft")
info("Loading")
readConfig()
info("Listening")
end
function handlePlayerJoined(playerIndex)
local player = Player(playerIndex)
info(string.format("Player %s connected", player.name))
sendJoinedPlayer(player.id)
end
function handlePlayerLeft(playerIndex)
local player = Player(playerIndex)
info(string.format("Player %s disconnected", player.name))
-- sendJoinedPlayer(data.networkid)
end

View File

@ -0,0 +1,61 @@
meta =
{
-- ID of your mod; Make sure this is unique!
-- Will be used for identifying the mod in dependency lists
-- Will be changed to workshop ID (ensuring uniqueness) when you upload the mod to the workshop
id = "sh_ontime_handler_avorion",
-- Name of your mod; You may want this to be unique, but it's not absolutely necessary.
-- This is an additional helper attribute for you to easily identify your mod in the Mods() list
name = "sh_ontime_handler_avorion",
-- Title of your mod that will be displayed to players
title = "Ontime handler for sh-edraft's discord bot",
-- Type of your mod, either "mod" or "factionpack"
type = "mod",
-- Description of your mod that will be displayed to players
description = "https://git.sh-edraft.de/sh-edraft.de/sh_ontime_handler_avorion",
-- Insert all authors into this list
authors = {"Sven 'edraft' Heidemann"},
-- Version of your mod, should be in format 1.0.0 (major.minor.patch) or 1.0 (major.minor)
-- This will be used to check for unmet dependencies or incompatibilities, and to check compatibility between clients and dedicated servers with mods.
-- If a client with an unmatching major or minor mod version wants to log into a server, login is prohibited.
-- Unmatching patch version still allows logging into a server. This works in both ways (server or client higher or lower version).
version = "1.0",
-- If your mod requires dependencies, enter them here. The game will check that all dependencies given here are met.
-- Possible attributes:
-- id: The ID of the other mod as stated in its modinfo.lua
-- min, max, exact: version strings that will determine minimum, maximum or exact version required (exact is only syntactic sugar for min == max)
-- optional: set to true if this mod is only an optional dependency (will only influence load order, not requirement checks)
-- incompatible: set to true if your mod is incompatible with the other one
-- Example:
-- dependencies = {
-- {id = "Avorion", min = "0.17", max = "0.21"}, -- we can only work with Avorion between versions 0.17 and 0.21
-- {id = "SomeModLoader", min = "1.0", max = "2.0"}, -- we require SomeModLoader, and we need its version to be between 1.0 and 2.0
-- {id = "AnotherMod", max = "2.0"}, -- we require AnotherMod, and we need its version to be 2.0 or lower
-- {id = "IncompatibleMod", incompatible = true}, -- we're incompatible with IncompatibleMod, regardless of its version
-- {id = "IncompatibleModB", exact = "2.0", incompatible = true}, -- we're incompatible with IncompatibleModB, but only exactly version 2.0
-- {id = "OptionalMod", min = "0.2", optional = true}, -- we support OptionalMod optionally, starting at version 0.2
-- },
dependencies = {
},
-- Set to true if the mod only has to run on the server. Clients will get notified that the mod is running on the server, but they won't download it to themselves
serverSideOnly = true,
-- Set to true if the mod only has to run on the client, such as UI mods
clientSideOnly = false,
-- Set to true if the mod changes the savegame in a potentially breaking way, as in it adds scripts or mechanics that get saved into database and no longer work once the mod gets disabled
-- logically, if a mod is client-side only, it can't alter savegames, but Avorion doesn't check for that at the moment
saveGameAltering = false,
-- Contact info for other users to reach you in case they have questions
contact = "sven.heidemann@sh-edraft.de",
}

9
start_server.sh Executable file
View File

@ -0,0 +1,9 @@
mkdir -p server/galaxy/galaxy/mods
cp src/modconfig.lua server/galaxy/galaxy/
cp -r src/sh_ontime_handler_avorion server/galaxy/galaxy/mods
cd server
./server.sh --galaxy-name galaxy --datapath ./galaxy
cd ..