Skip to content

Commit 8d4e45e

Browse files
committed
Initial Commit
0 parents  commit 8d4e45e

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

GameStateHook.lua

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- Game hook mod injector
2+
function listener()
3+
local playerTurns = ""
4+
for i,a in pairs(Players) do
5+
if a:IsEverAlive() and a:IsHuman() then
6+
playerTurns = playerTurns .. "{" ..
7+
'"id" : ' .. tostring(a:GetID()) .. "," ..
8+
'"nickName" : ' .. '"' .. a:GetNickName() .. '"' .. "," ..
9+
'"isTurnComplete" : ' .. tostring(a:HasReceivedNetTurnComplete()) .. "," ..
10+
'"isOnline" : ' .. tostring(Network.IsPlayerConnected(a:GetID())) .. "," ..
11+
'"isAlive" : ' .. tostring(a:IsAlive()) ..
12+
"},"
13+
end
14+
end
15+
16+
print("----JSON----{" ..
17+
'"gameTurn" : ' .. tostring(Game.GetGameTurn()) .."," ..
18+
'"players" : [' .. playerTurns:sub(1, -2) .. "]" ..
19+
"}----JSON----")
20+
end
21+
22+
print("----GameHook: GameHook listener initialized.")
23+
24+
Events.RemotePlayerTurnEnd.Add(listener)
25+
Events.RemotePlayerTurnStart.Add(listener)
26+
Events.ActivePlayerTurnStart.Add(listener)
27+
Events.ActivePlayerTurnEnd.Add(listener)
28+
Events.MultiplayerGamePlayerDisconnected.Add(listener)
29+
Events.MultiplayerGamePlayerUpdated.Add(listener)
30+
Events.MultiplayerHotJoinCompleted.Add(listener)

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Civ5 Pitboss WebHook
2+
Adds webhooks to Sid Meier's Civilization 5 games. Install this on your pitboss server to be notified anytime a player starts/ends their turn or connects/disconnects.
3+
4+
## How to use
5+
1. Edit `steamapps/common/Sid Meier's Civilization V/Assets/DLC/Expansion2/UI/InGame/TopPanel.lua` and append the content of `GameStateHook.lua`. This injects the game hook logic, which logs the game state to the game console. Other files can be used, (i.e. if you do not have BNW), but this file works. If you choose to inject into another file, make sure that it is being loaded when hosting a game.
6+
7+
2. Edit `Documents/My Games/Sid Meier's Civilization 5/config.ini` and enable logging.
8+
```
9+
;Update these two properties
10+
MessageLog = 1
11+
LoggingEnabled = 1
12+
```
13+
14+
3. Copy `WatchLog.ps1` to `Documents/My Games/Sid Meier's Civilization 5/Logs`. Change `https://my-endpoint.com` to be whatever endpoint you want.
15+
16+
4. Make sure that powershell scripts are enabled on your system. (https:/go.microsoft.com/fwlink/?LinkID=135170)[https:/go.microsoft.com/fwlink/?LinkID=135170]
17+
18+
5. Start the game.
19+
20+
6. Run the `Watchlog.ps1` script. Note that you may need to manually open a powershell console, `cd` to the logs directory, and then run the script. Windows does not seem able to automatically open a powershell console in a folder which contains an apostrophe `'`, which is the case with the default game directory.
21+
22+
## Troubleshooting
23+
24+
### The powershell script shows red text and immediately stops!
25+
- Make sure that the game is running before running the script. Make sure that powershell scripts are enabled. (Step 4.)

WatchLog.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Get-Content .\Lua.log -Wait | select-string "JSON" | % {[Regex]::Matches($_, '----JSON----(.+)----JSON----').Groups[1]} | Select -ExpandProperty Value | % {Invoke-WebRequest -Uri https://my-endpoint.com -Method POST -Headers @{'Content-Type' = 'application/json'} -UseBasicParsing -Body $_}

0 commit comments

Comments
 (0)