nosoop / rcbot2

A Metamod:Source plugin that provides customizable bot players.
http://rcbot.bots-united.com
GNU Affero General Public License v3.0
5 stars 0 forks source link

Prevent bot joinclass / weapon use command spamming #3

Closed nosoop closed 5 years ago

nosoop commented 5 years ago

This issue, combined with a low sv_quota_stringcmdspersecond value, kicks RCBots when they aren't expecting to be kicked, causing a crash.

Bots keep trying to select a class on every think tick when they're dead.

#0  CBotFortress::selectClass (this=0xe7cd620) at rcbot2/utils/RCBot2_meta/bot_fortress.cpp:1531
#1  0xaa40355f in CBotFortress::startGame (this=0xe7cd620) at rcbot2/utils/RCBot2_meta/bot_fortress.cpp:337
#2  0xaa3c35f1 in CBot::think (this=0xe7cd620) at rcbot2/utils/RCBot2_meta/bot.cpp:826
#3  0xaa3c4329 in CBots::botThink () at rcbot2/utils/RCBot2_meta/bot.cpp:3417
#4  0xaa48dd3b in RCBotPluginMeta::Hook_GameFrame (this=0xaac3c240 <g_RCBotPluginMeta>, simulating=true) at rcbot2/utils/RCBot2_meta/bot_plugin_meta.cpp:994

Pretty sure CBotTF2::handleWeapons is also problematic as Snipers always switch between their primary and secondary weapons; still need to figure out why though.

nosoop commented 5 years ago

Fixed one case with commit 72d93eb — it only attempts to change class if the server's expected desired class doesn't match.

One verified situation that a bot will spam weapon switches is if they can't switch weapons at the moment (e.g., if they are revved up on a minigun). This should probably be properly handled by a call to the game's weapon switch function, but I'm not sure what the best way of setting that up would be (depending on if the SDK provides it or if we have to get a game config for it).

nosoop commented 5 years ago

Second issue lies within CBotTF2::select_CWeapon() and CBotTF2::selectBotWeapon(), which uses command dispatch to switch weapons.

m_pController->SetActiveWeapon() is a no-go — it instantiates new instances of weapons. Handling it via usercmd seems like the way to go, but determining available weapons from the game doesn't seem trivial from what the SDK offers; a lot easier with sendprop support from SM.