From e7854fee608fdad3cb56ef12602cfbff2b7c792c Mon Sep 17 00:00:00 2001 From: kola2451 Date: Sat, 30 Nov 2024 22:32:14 +0300 Subject: [PATCH] Fix crash on default server creation --- src/xrGame/ui/UIMapList.cpp | 67 +++++++++++++++++++++++++++++-------- src/xrGame/ui/UIMapList.h | 2 ++ 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/xrGame/ui/UIMapList.cpp b/src/xrGame/ui/UIMapList.cpp index fb6cb8730c..b37dd5308b 100644 --- a/src/xrGame/ui/UIMapList.cpp +++ b/src/xrGame/ui/UIMapList.cpp @@ -77,7 +77,7 @@ void CUIMapList::StartDedicatedServer() xr_strcat (g_sLaunchOnExit_app, "xrServer.exe\""); xr_strcat (g_sLaunchOnExit_params, " -i -fsltx fsgame.ltx -ltx -nosound -"); - xr_strcat (g_sLaunchOnExit_params, GetCommandLine("")); //GetCommandLine default playername = User + xr_strcat (g_sLaunchOnExit_params, GetCommandLine("")); Msg ("Going to quit before starting dedicated server"); Msg ("Working folder is:%s", g_sLaunchWorkingFolder); @@ -198,8 +198,9 @@ EGameIDs CUIMapList::GetCurGameType() #endif } -const char* CUIMapList::GetCommandLine(LPCSTR player_name){ - +//Функция для создания обычного сервера через игру +const char* CUIMapList::GetCommandLine(LPCSTR player_name) +{ CUIListBoxItem* itm = m_pList2->GetItemByIDX(0); if (!itm) return nullptr; @@ -207,6 +208,38 @@ const char* CUIMapList::GetCommandLine(LPCSTR player_name){ u32 _idx = (u32)(__int64)(itm->GetData()); const SGameTypeMaps::SMapItm& M = GetMapNameInt (GetCurGameType(), _idx); + m_command.clear(); + m_command = "start server("; + m_command += M.map_name.c_str(); + m_command += "/"; + m_command += GameTypeToString(GetCurGameType(), true); + m_command += m_srv_params; + m_command += "/ver="; + m_command += M.map_ver.c_str(); + m_command += "/estime="; + + u32 id = m_pWeatherSelector->m_list_box.GetSelectedItem()->GetTAG(); + + m_command += m_mapWeather[id].weather_time.c_str(); + m_command += ")"; + + m_command += " client(localhost/name="; + m_command += GetPlayerName(player_name); + m_command += ")"; + + return m_command.c_str(); +} + +//функция для создания выделенного сервера из игры +const char* CUIMapList::GetCommandLineDedicated(LPCSTR player_name) +{ + CUIListBoxItem* itm = m_pList2->GetItemByIDX(0); + if (!itm) + return nullptr; + + u32 _idx = (u32)(__int64)(itm->GetData()); + const SGameTypeMaps::SMapItm& M = GetMapNameInt(GetCurGameType(), _idx); + m_command.clear(); m_command = "start server \""; m_command += M.map_name.c_str(); @@ -223,27 +256,33 @@ const char* CUIMapList::GetCommandLine(LPCSTR player_name){ m_command += "\""; m_command += " client \"localhost/name="; - if (player_name == nullptr || 0 == xr_strlen(player_name)) - { + m_command += GetPlayerName(player_name); + m_command += "\""; + + return m_command.c_str(); +} + +const char* CUIMapList::GetPlayerName(const LPCSTR player_name) { + static string256 final_name; + if (player_name == nullptr || 0 == xr_strlen(player_name)) { string64 player_name2; GetPlayerName_FromRegistry(player_name2, sizeof(player_name2)); - if (xr_strlen(player_name2) == 0) - { + if (xr_strlen(player_name2) == 0) { xr_strcpy(player_name2, xr_strlen(Core.UserName) ? Core.UserName : Core.CompName); } - VERIFY(xr_strlen(player_name2)); - m_command += player_name2; + VERIFY(xr_strlen(player_name2)); + + xr_strcpy(final_name, player_name2); } - else - { - m_command += player_name; + else { + xr_strcpy(final_name, player_name); } - m_command += "\""; - return m_command.c_str(); + return final_name; } + #include "../UIGameCustom.h" void CUIMapList::LoadMapList() { diff --git a/src/xrGame/ui/UIMapList.h b/src/xrGame/ui/UIMapList.h index db33f98786..c5dcbca510 100644 --- a/src/xrGame/ui/UIMapList.h +++ b/src/xrGame/ui/UIMapList.h @@ -35,6 +35,8 @@ class CUIMapList : public CUIWindow { void LoadMapList(); void SaveMapList(); const char* GetCommandLine(LPCSTR player_name); + const char* GetCommandLineDedicated(LPCSTR player_name); + const char* GetPlayerName(const LPCSTR player_name); EGameIDs GetCurGameType(); void StartDedicatedServer(); void ClearList();