Skip to content

Commit

Permalink
Fix crash on default server creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kola24511 committed Nov 30, 2024
1 parent dd49a10 commit e7854fe
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
67 changes: 53 additions & 14 deletions src/xrGame/ui/UIMapList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -198,15 +198,48 @@ 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;

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();
Expand All @@ -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()
{
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/ui/UIMapList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e7854fe

Please sign in to comment.