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

Merge Integration->Main #186

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c56659a
Add loser picks balance algo
jauggy Sep 27, 2024
51bd1c0
Merge pull request #179 from jauggy/jauggy/add-loser-picks-2
DeviousNull Sep 28, 2024
75a9c12
Fix missing `!help` entries for several BarManager commands.
DeviousNull Oct 1, 2024
acdc155
Merge pull request #181 from DeviousNull/fix-missing-help-entries
DeviousNull Oct 1, 2024
c6ff3b3
Make `getNumUsersInMyBattle()` return 0 if the battle is not open
DeviousNull Oct 3, 2024
9e020aa
Don't attempt to send battle updates when the battle is closed
DeviousNull Oct 3, 2024
a34db4b
Clarify an error message in various lobby command handlers
DeviousNull Oct 3, 2024
6b6ac41
Add lobby handlers in 'onLobbyLogin', not 'onLobbyConnected'
DeviousNull Oct 3, 2024
7285387
Merge pull request #182 from DeviousNull/misc-cleanups-fixes
DeviousNull Oct 3, 2024
fc4a0e0
Add `selfFileHash`, and print it in `!barmanagerprintstate`
DeviousNull Oct 3, 2024
38aee6a
Merge branch 'integration' into add-self-hash
DeviousNull Oct 3, 2024
19ca3c6
Merge pull request #183 from DeviousNull/add-self-hash
DeviousNull Oct 5, 2024
40fba52
Disable `!boss` command (without parameters).
DeviousNull Sep 19, 2024
b91ba79
Fix `!unboss` silently failing for usernames containing symbols
DeviousNull Oct 13, 2024
d5e2fa0
Automatic update of maps from maps-metadata
github-actions[bot] Oct 1, 2024
200f442
Automatic update of maps from maps-metadata
github-actions[bot] Oct 5, 2024
f917d10
Automatic update of maps from maps-metadata
github-actions[bot] Oct 5, 2024
fa9d61a
Add respect_avoids balance algo
jauggy Oct 17, 2024
ddbdb4b
Merge branch 'main' of github.com:beyond-all-reason/spads_config_bar …
DeviousNull Oct 19, 2024
de31baa
Make `!joinas` require approval from its target player.
DeviousNull Oct 13, 2024
d048755
Merge branch 'integration' into joinas-requires-target-approval
DeviousNull Oct 19, 2024
a71d652
Merge pull request #188 from DeviousNull/joinas-requires-target-approval
DeviousNull Oct 21, 2024
787085b
Revert "Make `!joinas` require approval from its target player."
DeviousNull Nov 1, 2024
25ee520
Merge pull request #191 from beyond-all-reason/revert-188-joinas-requ…
DeviousNull Nov 1, 2024
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
9 changes: 9 additions & 0 deletions etc/BarManagerCmd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,12 @@ battle:player,playing:|100:10
[balancealgorithm]
battle:player,playing:|100:10
::|100:100

[unboss](voteTime:60,majorityVoteMargin:25)
battle:player,playing:|100:0
battle:spec:|100:
::|130:

[setAllAiBonus]
battle,pv:player:stopped|100:10
::|100:
9 changes: 0 additions & 9 deletions etc/commands.conf
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ battle,pv,game:player,spec:|0:
[sendLobby]
::|130:

[setAllAiBonus]
battle,pv:player:stopped|100:10
::|100:

[smurfs]
::|110:

Expand Down Expand Up @@ -275,11 +271,6 @@ battle,pv,game:player,spec:|100:10
[unlockSpec]
pv::|0:

[unboss](voteTime:60,majorityVoteMargin:25)
battle:player,playing:|100:0
battle:spec:|100:
::|130:

[update]
::|130:

Expand Down
5 changes: 3 additions & 2 deletions var/plugins/BarManagerHelp.dat
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
[resetchevlevels]
!resetchevlevels - removes the minimum/maximum rank requirements

[resetratinglevels]
[setratinglevels]
!setratinglevels <min-rating> <max-rating> - Sets the minimum and maximum rating levels for players.

[rename]
Expand Down Expand Up @@ -57,7 +57,8 @@
!balancealgorithm <algorithm> - Sets the balance algorithm used to autobalance the teams.
"!balancealgorithm default"
"!balancealgorithm split_noobs"
"!balancealgorithm auto"
"!balancealgorithm respect_avoids"
"!balancealgorithm loser_picks"

[setAllAiBonus]
!setAllAiBonus <bonus> - Sets the economic bonus for each AI in the battle. The bonus must be between 0-100.
Expand Down
49 changes: 38 additions & 11 deletions var/plugins/barmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import time
import re
import hashlib

from datetime import datetime, timezone
# from https://blog.miguelgrinberg.com/post/it-s-time-for-a-change-datetime-utcnow-is-now-deprecated
Expand All @@ -22,10 +23,11 @@ def naive_utcfromtimestamp(timestamp):
spads = perl.BarManager

# ------------------ Instance global "constants" -------------

BMP = "BarManager|"
DBGLEVEL = 3
pluginParams = {}
selfFileHash = ""

# ---------------- Battleroom Variables to Track --------------
AiProfiles = {} # dict of BotName : {username : Owner, profile: Defensive} dunno the format yet, should support script tags to set AI profiles
isBattleLocked = False
Expand Down Expand Up @@ -108,6 +110,9 @@ def jsonBase64(toencode):
return base64.urlsafe_b64encode(json.dumps(toencode).encode("utf-8")).decode()

def getNumUsersInMyBattle():
if spads.getLobbyState() < 6: # 6 -> BATTLE OPENED
return 0 # We don't have a battle, so we don't have users in it.

lobbyLogin = spads.getSpadsConf()['lobbyLogin']
users = spads.getLobbyInterface().getBattle()['users']

Expand Down Expand Up @@ -238,6 +243,9 @@ def sendTachyonBattle():
global timerTachyonBattle, TachyonBattle
try:
timerTachyonBattle = False
if spads.getLobbyState() < 6: # 6 -> BATTLE OPENED
return

bsjson = json.dumps(TachyonBattle)
spads.slog("Trying to update tachyonbattlestatus " + bsjson, DBGLEVEL)
spads.queueLobbyCommand(["c.battle.update_host", bsjson])
Expand Down Expand Up @@ -412,7 +420,7 @@ def addLobbyCommandHandlers(self):

# This is our constructor, called when the plugin is loaded by SPADS (mandatory callback)
def __init__(self, context):
global DBGLEVEL, voteHistoryMax
global DBGLEVEL, voteHistoryMax, selfFileHash
# We declare our new command and the associated handler
spads.addSpadsCommandHandler({'aiProfile': hAiProfile})
spads.addSpadsCommandHandler({'setAllAiBonus': hSetAllAiBonus})
Expand All @@ -436,7 +444,7 @@ def __init__(self, context):
spads.addSpadsCommandHandler({'meme': getTeiserverStringCommandHandler("meme",
re.compile("^(undo|ticks|rich|poor|crazy|deathmatch)$"))})
spads.addSpadsCommandHandler({'balancealgorithm': getTeiserverStringCommandHandler("balancealgorithm",
re.compile("^(default|split_noobs|auto)$"))})
re.compile("^(default|split_noobs|respect_avoids|loser_picks)$"))})
spads.addSpadsCommandHandler({'unboss': hUnboss})

# We need to add the lobby command handlers before we are fully connected, or we dont get the JOINEDBATTLE stuff
Expand Down Expand Up @@ -478,11 +486,24 @@ def __init__(self, context):
spads.slog("Unhandled exception: " + str(sys.exc_info()
[0]) + "\n" + str(traceback.format_exc()), 0)

def onLobbyConnected(self, lobbyInterface):
try:
with open(__file__, 'rb') as f:
sha256 = hashlib.sha256()
data = f.read(32768)
while data:
sha256.update(data)
data = f.read(32768)
selfFileHash = "{0}".format(sha256.hexdigest()[:6])
spads.slog("Calculated source file's hash: " + selfFileHash, 3)
except Exception as e:
spads.slog("Unhandled exception: " + str(sys.exc_info()
[0]) + "\n" + str(traceback.format_exc()), 0)

def onLobbyLogin(self, lobbyInterface):
try:
# spads lobby command handlers are unloaded when connection is lost.
# Thus we need to readd them according to
# https://springrts.com/wiki/SPADS_plugin_development_(Python)#Writing_plugin_code_2
# https://github.com/Yaribz/SPADS/wiki/SPADS-plugin-development-(Python)#user-content-Writing_plugin_code-2
self.addLobbyCommandHandlers()

except Exception as e:
Expand Down Expand Up @@ -842,6 +863,10 @@ def preSpadsCommand(self, command, source, user, params):
spads.slog("preSpadsCommand: " + ','.join(map(str,
[command, source, user, params])), DBGLEVEL)

if (command == "boss" and len(params) == 0) or (command == "callvote" and len(params) == 1 and params[0] == "boss"):
spads.answer(user + ", you must specify a user to boss. (Use '!unboss <USERNAME>' or '!unboss *' to remove bosses)")
return 0

# We check "len(params) > 1" here so that only commands like "callvote boss UserName"
# are considered, and commands like "callvote boss" are allowed.
if command == "callvote" and len(params) > 1 and params[0] == "boss" and myBattlePassword == "*":
Expand Down Expand Up @@ -1019,12 +1044,14 @@ def hbarmanagerprintstate(source, user, params, checkOnly):
spads.slog("TachyonBattle: " + str(TachyonBattle), 3)
spads.slog("myBattleTeaser: " + str(myBattleTeaser), 3)
spads.slog("hwInfoIngame: " + str(hwInfoIngame), 3)
spads.slog("selfFileHash: " + str(selfFileHash), 3)

spads.sayPrivate(user, "DBGLEVEL: " + str(DBGLEVEL))
spads.sayPrivate(user, "myBattleID: " + str(myBattleID))
spads.sayPrivate(user, "ChobbyState: " + str(ChobbyState))
spads.sayPrivate(user, "TachyonBattle: " + str(TachyonBattle))
spads.sayPrivate(user, "myBattleTeaser: " + str(myBattleTeaser))
spads.sayPrivate(user, "selfFileHash: " + str(selfFileHash))
# Also say these in private to caller

except Exception as e:
Expand Down Expand Up @@ -1191,7 +1218,7 @@ def hUnboss(source, user, params, checkOnly):
if params[0] == '*':
callPerlFunction("hBoss", "battle", user, [], False) # Just use the SPADS handler
else:
perl.eval("delete $::bosses{" + params[0] + "};")
perl.eval("delete $::bosses{'" + params[0] + "'};")
spads.broadcastMsg("Boss mode disabled for %s (by %s)" % (params[0], user))

newBosses = "" + ','.join(spads.getBosses())
Expand Down Expand Up @@ -1453,7 +1480,7 @@ def hLEFT_pre(command, chanName, userName, reason=""):
if userName in knownUsers:
return
else:
spads.slog("hLEFT_pre cannot be exectuted" +
spads.slog("hLEFT_pre was called for an unknown user, skipping " +
str([command, chanName, userName, reason, userName in knownUsers]), 2)
# spads.sayPrivate('AutohostMonitor', 'broken_connection ' + userName)
# return "DROP"
Expand All @@ -1469,7 +1496,7 @@ def hLEFTBATTLE_pre(command, battleID, userName):
if userName in knownUsers:
return
else:
spads.slog("hLEFTBATTLE_pre cannot be exectuted" +
spads.slog("hLEFTBATTLE_pre was called for an unknown user, skipping " +
str([command, battleID, userName, userName in knownUsers]), 2)
# spads.sayPrivate('AutohostMonitor', 'broken_connection ' + userName)
# return "DROP"
Expand All @@ -1486,7 +1513,7 @@ def hREMOVEUSER_pre(command, userName):
del knownUsers[userName]
return
else:
spads.slog("hREMOVEUSER_pre cannot be exectuted" +
spads.slog("hREMOVEUSER_pre was called for an unknown user, skipping " +
str([command, userName, userName in knownUsers]), 2)
# spads.sayPrivate('AutohostMonitor', 'broken_connection ' + userName)
# return "DROP"
Expand All @@ -1502,7 +1529,7 @@ def hCLIENTSTATUS_pre(command, userName, status):
if userName in knownUsers:
return
else:
spads.slog("hCLIENTSTATUS_pre cannot be exectuted" +
spads.slog("hCLIENTSTATUS_pre was called for an unknown user, skipping " +
str([command, userName, status, userName in knownUsers]), 2)
# spads.sayPrivate('AutohostMonitor', 'broken_connection ' + userName)
# return "DROP"
Expand All @@ -1518,7 +1545,7 @@ def hJOINEDBATTLE_pre(command, battleID, userName, scriptPassword=""):
if userName in knownUsers:
return
else:
spads.slog("hJOINEDBATTLE_pre cannot be exectuted" + str(
spads.slog("hJOINEDBATTLE_pre was called for an unknown user, skipping " + str(
[command, battleID, userName, scriptPassword, userName in knownUsers]), 2)
# spads.sayPrivate('AutohostMonitor', 'broken_connection ' + userName)
# return "DROP"
Expand Down