FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixed a crash on servers with a colon in its path (thanks to Hedgehog) · Necavi/Source.Python@4415513 · GitHub

Repository navigation

Commit 4415513

Browse files
committed
Fixed a crash on servers with a colon in its path (thanks to Hedgehog)
1 parent ca09a20 commit 4415513

4 files changed

Lines changed: 97 additions & 0 deletions

File tree

‎src/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Set(SOURCEPYTHON_LOADER_FILES
3030
# ------------------------------------------------------------------
3131
Set(SOURCEPYTHON_UTIL_HEADERS
3232
core/utility/sp_util.h
33+
core/utility/shared_utils.h
3334
core/utility/call_python.h
3435
core/utility/wrap_macros.h
3536
core/utility/ipythongenerator.h

‎src/core/core/sp_gamedir.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "eiface.h"
3333
#include "strtools.h"
3434

35+
#include "utility/shared_utils.h"
36+
3537
//---------------------------------------------------------------------------------
3638
// External variables we need.
3739
//---------------------------------------------------------------------------------
@@ -53,6 +55,7 @@ bool CGamePaths::Initialize( void )
5355
}
5456

5557
engine->GetGameDir(m_szGameDir, MAX_GAME_PATH);
58+
GenerateSymlink(m_szGameDir);
5659
V_snprintf(m_szSPDir, MAX_GAME_PATH, "%s%s", m_szGameDir, sp_ADDON_BASE);
5760

5861
// Fix slashes

‎src/core/utility/shared_utils.h‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* =============================================================================
3+
* Source Python
4+
* Copyright (C) 2015 Source Python Development Team. All rights reserved.
5+
* =============================================================================
6+
*
7+
* This program is free software; you can redistribute it and/or modify it under
8+
* the terms of the GNU General Public License, version 3.0, as published by the
9+
* Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* As a special exception, the Source Python Team gives you permission
20+
* to link the code of this program (as well as its derivative works) to
21+
* "Half-Life 2," the "Source Engine," and any Game MODs that run on software
22+
* by the Valve Corporation. You must obey the GNU General Public License in
23+
* all respects for all other code used. Additionally, the Source.Python
24+
* Development Team grants this exception to all derivative works.
25+
*/
26+
#ifndef _SHARED_UTILS_H
27+
#define _SHARED_UTILS_H
28+
29+
//-----------------------------------------------------------------------------
30+
// Includes
31+
//-----------------------------------------------------------------------------
32+
#include "strtools.h"
33+
34+
35+
//-----------------------------------------------------------------------------
36+
// Generates a symlink without the colon symbol (":").
37+
//
38+
// Thanks to Hedgehog for this!
39+
// http://forums.sourcepython.com/showthread.php?581-Server-crash-on-SP-loading&p=2967&viewfull=1#post2967
40+
//-----------------------------------------------------------------------------
41+
inline void _GenerateSymlink(char* path)
42+
{
43+
#if __linux__
44+
int pathLen = V_strlen(path) + 1;
45+
char symlinkOrigin[pathLen];
46+
char symlinkPath[pathLen];
47+
48+
V_strncpy(symlinkOrigin, path, pathLen);
49+
V_strncpy(symlinkPath, path, pathLen);
50+
51+
int i = 0;
52+
bool flag = false;
53+
54+
for (i = 0; i < pathLen; i++)
55+
{
56+
if (path[i] == ':')
57+
{
58+
path[i] = '-';
59+
symlinkPath[i] = '-';
60+
flag = true;
61+
}
62+
if (flag && path[i] == '/')
63+
{
64+
break;
65+
}
66+
}
67+
symlinkOrigin[i] = '\0';
68+
symlinkPath[i] = '\0';
69+
70+
if (symlink(symlinkOrigin, symlinkPath) != 0 && (errno != EEXIST))
71+
{
72+
DevMsg(0, MSG_PREFIX "Unable to create a symbolic link (%s).\n", strerror(errno));
73+
DevMsg(0, MSG_PREFIX "Original path: %s\n", symlinkOrigin);
74+
DevMsg(0, MSG_PREFIX "Symbolic link: %s\n", symlinkPath);
75+
}
76+
#endif
77+
}
78+
79+
inline void GenerateSymlink(char* path)
80+
{
81+
#if __linux__
82+
while (strchr(path, ':') != NULL)
83+
{
84+
_GenerateSymlink(path);
85+
}
86+
#endif
87+
}
88+
89+
#endif // _SHARED_UTILS_H

‎src/loader/loader_main.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
# include <windows.h>
3636
#endif
3737

38+
#include "../core/utility/shared_utils.h"
39+
3840
//---------------------------------------------------------------------------------
3941
// Disable warnings.
4042
//---------------------------------------------------------------------------------
@@ -81,6 +83,7 @@ void* SPLoadLibrary( IVEngineServer* engine, const char* libraryPath )
8183
V_strncpy(szError, "[SP-LOADER] - No error found\n", 1024);
8284

8385
engine->GetGameDir(szGamePath, 1024);
86+
GenerateSymlink(szGamePath);
8487

8588
V_snprintf(szFullPath, sizeof(szFullPath), "%s/addons/source-python/%s",
8689
szGamePath, libraryPath);
@@ -172,6 +175,7 @@ bool CSourcePython::Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn
172175
// Get the game directory.
173176
// ------------------------------------------------------------------
174177
engine->GetGameDir(szGameDir, 1024);
178+
GenerateSymlink(szGameDir);
175179

176180
// ------------------------------------------------------------------
177181
// Load windows dependencies.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL