fix: yb_shoots_thru_walls bounds was incorrect.

fix: save, load, upload, download graph files always in lowercase.
refactor: menu display / hide refactored to reduce network traffic. (use string chunks instead of sending menu with writeChar (), and do not reset menu display, if no menu is displayed to client).
This commit is contained in:
ds 2020-10-11 14:01:19 +03:00
commit 3b0f06bb09
4 changed files with 90 additions and 76 deletions

View file

@ -137,6 +137,8 @@ public:
bool executeMenus (); bool executeMenus ();
void showMenu (int id); void showMenu (int id);
void closeMenu ();
void kickBotByMenu (int page); void kickBotByMenu (int page);
void assignAdminRights (edict_t *ent, char *infobuffer); void assignAdminRights (edict_t *ent, char *infobuffer);
void maintainAdminRights (); void maintainAdminRights ();

View file

@ -15,7 +15,7 @@
#include <yapb.h> #include <yapb.h>
ConVar cv_shoots_thru_walls ("yb_shoots_thru_walls", "2", "Specifies whether bots able to fire at enemies behind the wall, if they hearing or suspecting them.", true, 0.0f, 3.0f); ConVar cv_shoots_thru_walls ("yb_shoots_thru_walls", "2", "Specifies whether bots able to fire at enemies behind the wall, if they hearing or suspecting them.", true, 0.0f, 2.0f);
ConVar cv_ignore_enemies ("yb_ignore_enemies", "0", "Enables or disables searching world for enemies."); ConVar cv_ignore_enemies ("yb_ignore_enemies", "0", "Enables or disables searching world for enemies.");
ConVar cv_check_enemy_rendering ("yb_check_enemy_rendering", "0", "Enables or disables checking enemy rendering flags. Useful for some mods."); ConVar cv_check_enemy_rendering ("yb_check_enemy_rendering", "0", "Enables or disables checking enemy rendering flags. Useful for some mods.");
ConVar cv_stab_close_enemies ("yb_stab_close_enemies", "1", "Enables or disables bot ability to stab the enemy with knife if bot is in good condition."); ConVar cv_stab_close_enemies ("yb_stab_close_enemies", "1", "Enables or disables bot ability to stab the enemy with knife if bot is in good condition.");

View file

@ -176,7 +176,7 @@ int BotControl::cmdMenu () {
enum args { alias = 1, cmd }; enum args { alias = 1, cmd };
// reset the current menu // reset the current menu
showMenu (Menu::None); closeMenu ();
if (strValue (cmd) == "cmd" && util.isAlive (m_ent)) { if (strValue (cmd) == "cmd" && util.isAlive (m_ent)) {
showMenu (Menu::Commands); showMenu (Menu::Commands);
@ -754,8 +754,11 @@ int BotControl::cmdNodeUpload () {
msg ("you may notice the game freezes a bit during upload and issue request creation. Please, be patient."); msg ("you may notice the game freezes a bit during upload and issue request creation. Please, be patient.");
msg ("\n"); msg ("\n");
// upload everytime in lowercase
String mapName = game.getMapName ();
// try to upload the file // try to upload the file
if (http.uploadFile (strings.format ("http://%s/graph", product.download), strings.format ("%sgraph/%s.graph", graph.getDataDirectory (false), game.getMapName ()))) { if (http.uploadFile (strings.format ("http://%s/graph", product.download), strings.format ("%sgraph/%s.graph", graph.getDataDirectory (false), mapName.lowercase ()))) {
msg ("Graph file was successfully validated and uploaded to the YaPB Graph DB (%s).", product.download); msg ("Graph file was successfully validated and uploaded to the YaPB Graph DB (%s).", product.download);
msg ("It will be available for download for all YaPB users in a few minutes."); msg ("It will be available for download for all YaPB users in a few minutes.");
msg ("\n"); msg ("\n");
@ -853,7 +856,7 @@ int BotControl::cmdNodeShowStats () {
} }
int BotControl::menuMain (int item) { int BotControl::menuMain (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -875,7 +878,7 @@ int BotControl::menuMain (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
default: default:
@ -886,7 +889,7 @@ int BotControl::menuMain (int item) {
} }
int BotControl::menuFeatures (int item) { int BotControl::menuFeatures (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -913,20 +916,20 @@ int BotControl::menuFeatures (int item) {
showMenu (Menu::Commands); showMenu (Menu::Commands);
} }
else { else {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
msg ("You're dead, and have no access to this menu"); msg ("You're dead, and have no access to this menu");
} }
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
int BotControl::menuControl (int item) { int BotControl::menuControl (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -952,14 +955,14 @@ int BotControl::menuControl (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
int BotControl::menuWeaponMode (int item) { int BotControl::menuWeaponMode (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -974,7 +977,7 @@ int BotControl::menuWeaponMode (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
@ -982,7 +985,7 @@ int BotControl::menuWeaponMode (int item) {
int BotControl::menuPersonality (int item) { int BotControl::menuPersonality (int item) {
if (m_isMenuFillCommand) { if (m_isMenuFillCommand) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -990,16 +993,16 @@ int BotControl::menuPersonality (int item) {
case 3: case 3:
case 4: case 4:
bots.serverFill (m_menuServerFillTeam, item - 2, m_interMenuData[0]); bots.serverFill (m_menuServerFillTeam, item - 2, m_interMenuData[0]);
showMenu (Menu::None); closeMenu ();
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1011,14 +1014,14 @@ int BotControl::menuPersonality (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
int BotControl::menuDifficulty (int item) { int BotControl::menuDifficulty (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1042,7 +1045,7 @@ int BotControl::menuDifficulty (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
showMenu (Menu::Personality); showMenu (Menu::Personality);
@ -1052,7 +1055,7 @@ int BotControl::menuDifficulty (int item) {
int BotControl::menuTeamSelect (int item) { int BotControl::menuTeamSelect (int item) {
if (m_isMenuFillCommand) { if (m_isMenuFillCommand) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
if (item < 3) { if (item < 3) {
extern ConVar mp_limitteams, mp_autoteambalance; extern ConVar mp_limitteams, mp_autoteambalance;
@ -1071,12 +1074,12 @@ int BotControl::menuTeamSelect (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1094,14 +1097,14 @@ int BotControl::menuTeamSelect (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
int BotControl::menuClassSelect (int item) { int BotControl::menuClassSelect (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1114,14 +1117,14 @@ int BotControl::menuClassSelect (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
int BotControl::menuCommands (int item) { int BotControl::menuCommands (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
Bot *nearest = nullptr; Bot *nearest = nullptr;
switch (item) { switch (item) {
@ -1150,14 +1153,14 @@ int BotControl::menuCommands (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
int BotControl::menuGraphPage1 (int item) { int BotControl::menuGraphPage1 (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1222,14 +1225,14 @@ int BotControl::menuGraphPage1 (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
int BotControl::menuGraphPage2 (int item) { int BotControl::menuGraphPage2 (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1316,7 +1319,7 @@ int BotControl::menuGraphPage2 (int item) {
} }
int BotControl::menuGraphRadius (int item) { int BotControl::menuGraphRadius (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
graph.setEditFlag (GraphEdit::On); // turn graph on in case graph.setEditFlag (GraphEdit::On); // turn graph on in case
constexpr float radius[] = { 0.0f, 8.0f, 16.0f, 32.0f, 48.0f, 64.0f, 80.0f, 96.0f, 128.0f }; constexpr float radius[] = { 0.0f, 8.0f, 16.0f, 32.0f, 48.0f, 64.0f, 80.0f, 96.0f, 128.0f };
@ -1329,7 +1332,7 @@ int BotControl::menuGraphRadius (int item) {
} }
int BotControl::menuGraphType (int item) { int BotControl::menuGraphType (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1354,14 +1357,14 @@ int BotControl::menuGraphType (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
int BotControl::menuGraphFlag (int item) { int BotControl::menuGraphFlag (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1393,7 +1396,7 @@ int BotControl::menuGraphFlag (int item) {
} }
int BotControl::menuAutoPathDistance (int item) { int BotControl::menuAutoPathDistance (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
constexpr float distances[] = { 0.0f, 100.0f, 130.0f, 160.0f, 190.0f, 220.0f, 250.0f }; constexpr float distances[] = { 0.0f, 100.0f, 130.0f, 160.0f, 190.0f, 220.0f, 250.0f };
@ -1407,14 +1410,14 @@ int BotControl::menuAutoPathDistance (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
} }
int BotControl::menuKickPage1 (int item) { int BotControl::menuKickPage1 (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1441,7 +1444,7 @@ int BotControl::menuKickPage1 (int item) {
} }
int BotControl::menuKickPage2 (int item) { int BotControl::menuKickPage2 (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1468,7 +1471,7 @@ int BotControl::menuKickPage2 (int item) {
} }
int BotControl::menuKickPage3 (int item) { int BotControl::menuKickPage3 (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1495,7 +1498,7 @@ int BotControl::menuKickPage3 (int item) {
} }
int BotControl::menuKickPage4 (int item) { int BotControl::menuKickPage4 (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1518,7 +1521,7 @@ int BotControl::menuKickPage4 (int item) {
} }
int BotControl::menuGraphPath (int item) { int BotControl::menuGraphPath (int item) {
showMenu (Menu::None); // reset menu display closeMenu (); // reset menu display
switch (item) { switch (item) {
case 1: case 1:
@ -1537,7 +1540,7 @@ int BotControl::menuGraphPath (int item) {
break; break;
case 10: case 10:
showMenu (Menu::None); closeMenu ();
break; break;
} }
return BotCommandResult::Handled; return BotCommandResult::Handled;
@ -1674,10 +1677,10 @@ bool BotControl::executeMenus () {
} }
void BotControl::showMenu (int id) { void BotControl::showMenu (int id) {
static bool s_menusParsed = false; static bool menusParsed = false;
// make menus looks like we need only once // make menus looks like we need only once
if (!s_menusParsed) { if (!menusParsed) {
for (auto &parsed : m_menus) { for (auto &parsed : m_menus) {
StringRef translated = conf.translate (parsed.text); StringRef translated = conf.translate (parsed.text);
@ -1691,48 +1694,37 @@ void BotControl::showMenu (int id) {
} }
} }
} }
s_menusParsed = true; menusParsed = true;
} }
if (!util.isPlayer (m_ent)) { if (!util.isPlayer (m_ent)) {
return; return;
} }
Client &client = util.getClient (game.indexOfPlayer (m_ent)); auto &client = util.getClient (game.indexOfPlayer (m_ent));
constexpr size_t maxMenuSentLength = 140;
if (id == Menu::None) { for (const auto &display : m_menus) {
MessageWriter (MSG_ONE_UNRELIABLE, msgs.id (NetMsg::ShowMenu), nullptr, m_ent)
.writeShort (0)
.writeChar (0)
.writeByte (0)
.writeString ("");
client.menu = id;
return;
}
for (auto &display : m_menus) {
if (display.ident == id) { if (display.ident == id) {
auto text = (game.is (GameFlags::Xash3D | GameFlags::Mobility) && !cv_display_menu_text.bool_ ()) ? " " : display.text.chars (); StringRef text = (game.is (GameFlags::Xash3D | GameFlags::Mobility) && !cv_display_menu_text.bool_ ()) ? " " : display.text.chars ();
MessageWriter msg;
while (strlen (text) >= 64) { size_t sentLength = 0;
msg.start (MSG_ONE_UNRELIABLE, msgs.id (NetMsg::ShowMenu), nullptr, m_ent) size_t leftLength = text.length ();
String buffer = (leftLength > maxMenuSentLength) ? text.substr (0, maxMenuSentLength) : text;
do {
leftLength -= buffer.length ();
MessageWriter (MSG_ONE, msgs.id (NetMsg::ShowMenu), nullptr, m_ent)
.writeShort (display.slots) .writeShort (display.slots)
.writeChar (-1) .writeChar (-1)
.writeByte (1); .writeByte (leftLength > 0 ? HLTrue : HLFalse)
.writeString (buffer.chars ());
for (int i = 0; i < 64; ++i) { sentLength += buffer.length ();
msg.writeChar (text[i]); buffer = text.substr (sentLength, (leftLength > maxMenuSentLength) ? maxMenuSentLength : StringRef::InvalidIndex);
}
msg.end ();
text += 64;
}
MessageWriter (MSG_ONE_UNRELIABLE, msgs.id (NetMsg::ShowMenu), nullptr, m_ent) } while (leftLength > 0);
.writeShort (display.slots)
.writeChar (-1)
.writeByte (0)
.writeString (text);
client.menu = id; client.menu = id;
engfuncs.pfnClientCommand (m_ent, "speak \"player/geiger1\"\n"); // Stops others from hearing menu sounds.. engfuncs.pfnClientCommand (m_ent, "speak \"player/geiger1\"\n"); // Stops others from hearing menu sounds..
@ -1740,6 +1732,26 @@ void BotControl::showMenu (int id) {
} }
} }
void BotControl::closeMenu () {
if (!util.isPlayer (m_ent)) {
return;
}
auto &client = util.getClient (game.indexOfPlayer (m_ent));
// do not reset menu if already none
if (client.menu == Menu::None) {
return;
}
MessageWriter (MSG_ONE, msgs.id (NetMsg::ShowMenu), nullptr, m_ent)
.writeShort (0)
.writeChar (0)
.writeByte (0)
.writeString ("");
client.menu = Menu::None;
}
void BotControl::kickBotByMenu (int page) { void BotControl::kickBotByMenu (int page) {
if (page > 4 || page < 1) { if (page > 4 || page < 1) {
return; return;
@ -1771,7 +1783,7 @@ void BotControl::kickBotByMenu (int page) {
menus.appendf ("\n%s 0. %s", (page == 4) ? "" : strings.format (" 9. %s...\n", moreKey), backKey); menus.appendf ("\n%s 0. %s", (page == 4) ? "" : strings.format (" 9. %s...\n", moreKey), backKey);
// force to clear current menu // force to clear current menu
showMenu (Menu::None); closeMenu ();
auto id = Menu::KickPage1 - 1 + page; auto id = Menu::KickPage1 - 1 + page;

View file

@ -1559,7 +1559,7 @@ template <typename U> bool BotGraph::saveStorage (StringRef ext, StringRef name,
bool isGraph = !!(options & StorageOption::Graph); bool isGraph = !!(options & StorageOption::Graph);
String filename; String filename;
filename.assignf ("%s.%s", game.getMapName (), ext); filename.assignf ("%s.%s", game.getMapName (), ext).lowercase ();
if (data.empty ()) { if (data.empty ()) {
logger.error ("Unable to save %s file. Empty data. (filename: '%s').", name, filename); logger.error ("Unable to save %s file. Empty data. (filename: '%s').", name, filename);