Skip to content

Commit 3e6151d

Browse files
committed
Updated some deprecated functions
1 parent 2f8e1c0 commit 3e6151d

10 files changed

Lines changed: 141 additions & 119 deletions

File tree

SphereSvr.vcxproj

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup Label="ProjectConfigurations">
44
<ProjectConfiguration Include="Debug|x64">
55
<Configuration>Debug</Configuration>
@@ -15,21 +15,10 @@
1515
</ProjectConfiguration>
1616
</ItemGroup>
1717
<PropertyGroup Label="Globals">
18-
<TargetName>SphereSvr</TargetName>
19-
<ProjectName>0.56d</ProjectName>
2018
<ProjectGuid>{40CA07B5-BCC7-A9C8-A6E6-DEFC536EE8CB}</ProjectGuid>
2119
<PlatformToolset>v143</PlatformToolset>
2220
</PropertyGroup>
2321
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
24-
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
25-
<LinkIncremental>true</LinkIncremental>
26-
</PropertyGroup>
27-
<PropertyGroup Condition="'$(Configuration)'=='Nightly'">
28-
<LinkIncremental>false</LinkIncremental>
29-
</PropertyGroup>
30-
<PropertyGroup Condition="'$(Configuration)'=='Release'">
31-
<LinkIncremental>false</LinkIncremental>
32-
</PropertyGroup>
3322
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
3423
<ItemDefinitionGroup>
3524
<ClCompile>
@@ -40,7 +29,7 @@
4029
</ClCompile>
4130
<Link>
4231
<AdditionalDependencies>libmysql.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
43-
<AdditionalLibraryDirectories>src\common\mysql\lib</AdditionalLibraryDirectories>
32+
<AdditionalLibraryDirectories>$(ProjectDir)src\common\mysql\lib</AdditionalLibraryDirectories>
4433
<LanguageStandard>stdcpp20</LanguageStandard>
4534
<SubSystem>Windows</SubSystem>
4635
</Link>
@@ -63,7 +52,7 @@ git rev-parse --is-inside-work-tree &gt;nul 2&gt;&amp;1 &amp;&amp; (
6352
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
6453
<EnableCOMDATFolding>false</EnableCOMDATFolding>
6554
<Optimization>Disabled</Optimization>
66-
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
55+
<PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
6756
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
6857
<RuntimeTypeInfo>true</RuntimeTypeInfo>
6958
</ClCompile>
@@ -78,7 +67,7 @@ git rev-parse --is-inside-work-tree &gt;nul 2&gt;&amp;1 &amp;&amp; (
7867
<ClCompile>
7968
<EnableCOMDATFolding>true</EnableCOMDATFolding>
8069
<Optimization>MaxSpeed</Optimization>
81-
<PreprocessorDefinitions>_NIGHTLYBUILD;_THREAD_TRACK_CALLSTACK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
70+
<PreprocessorDefinitions>_NIGHTLYBUILD;_THREAD_TRACK_CALLSTACK;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
8271
<WholeProgramOptimization>true</WholeProgramOptimization>
8372
</ClCompile>
8473
<ResourceCompile>
@@ -93,7 +82,7 @@ git rev-parse --is-inside-work-tree &gt;nul 2&gt;&amp;1 &amp;&amp; (
9382
<ClCompile>
9483
<EnableCOMDATFolding>true</EnableCOMDATFolding>
9584
<Optimization>MaxSpeed</Optimization>
96-
<PreprocessorDefinitions>_THREAD_TRACK_CALLSTACK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
85+
<PreprocessorDefinitions>_THREAD_TRACK_CALLSTACK;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
9786
<WholeProgramOptimization>true</WholeProgramOptimization>
9887
</ClCompile>
9988
<ResourceCompile>

src/common/CSocket.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "../graysvr/graysvr.h"
2+
#include <thread>
23
#ifdef __FreeBSD__
34
#include <errno.h>
45
#endif
@@ -16,9 +17,20 @@ void CSocketAddressIP::SetHostStr(LPCTSTR pszHostName)
1617
return SetAddrStr(pszHostName);
1718

1819
// Try to resolve hostname
19-
struct hostent *pHost = gethostbyname(pszHostName);
20-
if ( pHost && pHost->h_addr )
21-
SetAddrIP(*reinterpret_cast<DWORD *>(pHost->h_addr));
20+
struct addrinfo hints = {};
21+
hints.ai_family = AF_INET;
22+
hints.ai_socktype = SOCK_STREAM;
23+
struct addrinfo *pResult = NULL;
24+
25+
if ( getaddrinfo(pszHostName, NULL, &hints, &pResult) == 0 )
26+
{
27+
if ( pResult )
28+
{
29+
struct sockaddr_in *pSockAddrIn = reinterpret_cast<struct sockaddr_in *>(pResult->ai_addr);
30+
SetAddrIP(pSockAddrIn->sin_addr.s_addr);
31+
freeaddrinfo(pResult);
32+
}
33+
}
2234
}
2335

2436
///////////////////////////////////////////////////////////
@@ -67,13 +79,12 @@ void CSocketAddress::SetHostPortStr(LPCTSTR pszIP)
6779
///////////////////////////////////////////////////////////
6880
// CGSocket
6981

70-
int CGSocket::GetLastError(bool fUseErrno)
82+
int CGSocket::GetLastError()
7183
{
7284
#ifdef _WIN32
73-
UNREFERENCED_PARAMETER(fUseErrno);
7485
return WSAGetLastError();
7586
#else
76-
return fUseErrno ? errno : h_errno;
87+
return errno;
7788
#endif
7889
}
7990

@@ -228,6 +239,6 @@ void CGSocket::ClearAsync()
228239
{
229240
// TO BE CALLED IN CClient destructor !!!
230241
CancelIo(reinterpret_cast<HANDLE>(m_hSocket));
231-
SleepEx(1, TRUE);
242+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
232243
}
233244
#endif

src/common/CSocket.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,32 @@ struct CSocketAddressIP : public in_addr
3434
{
3535
s_addr = dwIP;
3636
}
37-
explicit CSocketAddressIP(const char *ip)
37+
explicit CSocketAddressIP(LPCTSTR pszIP)
3838
{
39-
s_addr = inet_addr(ip);
39+
SetAddrStr(pszIP);
4040
}
4141

4242
public:
4343
void SetHostStr(LPCTSTR pszHostName);
4444

4545
LPCTSTR GetAddrStr() const
4646
{
47-
return inet_ntoa(*this);
47+
static thread_local TCHAR szIP[INET_ADDRSTRLEN];
48+
if ( inet_ntop(AF_INET, const_cast<struct in_addr *>(static_cast<const struct in_addr *>(this)), szIP, sizeof(szIP)) )
49+
return szIP;
50+
51+
return "0.0.0.0";
4852
}
4953
void SetAddrStr(LPCTSTR pszIP)
5054
{
5155
// IP must be in IPv4 format (x.x.x.x)
52-
s_addr = inet_addr(pszIP);
56+
s_addr = INADDR_BROADCAST;
57+
if ( pszIP )
58+
{
59+
struct in_addr addr;
60+
if ( inet_pton(AF_INET, pszIP, &addr) == 1 )
61+
s_addr = addr.s_addr;
62+
}
5363
}
5464

5565
DWORD GetAddrIP() const
@@ -177,7 +187,7 @@ class CGSocket
177187
}
178188

179189
public:
180-
static int GetLastError(bool fUseErrno = false);
190+
static int GetLastError();
181191
bool IsOpen() const
182192
{
183193
return (m_hSocket != INVALID_SOCKET);

src/common/os_unix.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#pragma once
44

55
#ifndef _WIN32
6+
#include <cctype>
7+
#include <climits>
8+
#include <cstdarg>
69
#include <cstdint>
7-
#include <stdio.h>
8-
#include <stdarg.h>
9-
#include <string.h>
10-
#include <limits.h>
10+
#include <cstdio>
11+
#include <cstring>
1112
#include <pthread.h>
12-
#include <unistd.h>
1313
#include <sys/wait.h>
14-
#include <cctype>
14+
#include <unistd.h>
1515

1616
// Port some Windows stuff to Linux
1717
typedef unsigned char BYTE; // 8 bits
@@ -50,8 +50,6 @@ typedef int BOOL;
5050
#define _cdecl
5151
#define __cdecl
5252
#define _vsnprintf vsnprintf
53-
#define Sleep(mSec) usleep(mSec * 1000) // arg is microseconds = 1/1000000
54-
#define SleepEx(mSec, unused) usleep(mSec * 1000) // arg is microseconds = 1/1000000
5553

5654
#ifndef _MAX_PATH
5755
#define _MAX_PATH 260
@@ -71,16 +69,24 @@ typedef int BOOL;
7169
#define UNREFERENCED_PARAMETER(P) (void)(P)
7270
#endif
7371

74-
inline void _strupr(TCHAR *pszStr)
72+
inline TCHAR* _strupr(TCHAR *pszStr)
7573
{
76-
for ( ; *pszStr != '\0'; ++pszStr )
77-
*pszStr = toupper(*pszStr);
74+
if ( pszStr )
75+
{
76+
for ( ; *pszStr != '\0'; ++pszStr )
77+
*pszStr = static_cast<TCHAR>(toupper(static_cast<unsigned char>(*pszStr)));
78+
}
79+
return pszStr;
7880
}
7981

80-
inline void _strlwr(TCHAR *pszStr)
82+
inline TCHAR* _strlwr(TCHAR *pszStr)
8183
{
82-
for ( ; *pszStr != '\0'; ++pszStr )
83-
*pszStr = tolower(*pszStr);
84+
if ( pszStr )
85+
{
86+
for ( ; *pszStr != '\0'; ++pszStr )
87+
*pszStr = static_cast<TCHAR>(tolower(static_cast<unsigned char>(*pszStr)));
88+
}
89+
return pszStr;
8490
}
8591

8692
#endif // _WIN32

src/common/os_windows.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
#pragma once
44

55
#ifdef _WIN32
6-
#ifndef _CRT_SECURE_NO_WARNINGS
7-
#define _CRT_SECURE_NO_WARNINGS
8-
#endif
9-
#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
10-
#define _WINSOCK_DEPRECATED_NO_WARNINGS
11-
#endif
126
#undef FD_SETSIZE
137
#define FD_SETSIZE 1024 // for max of n users ! default = 64
148

src/graysvr/CClientMsg.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,18 +2629,18 @@ void CClient::addAOSTooltip(const CObjBase *pObj, bool fRequested, bool fShop)
26292629
if ( iMaxWeight > 0 )
26302630
{
26312631
m_TooltipData.Add(t = new CClientTooltip(1072241)); // Contents: ~1_COUNT~/~2_MAXCOUNT~ items, ~3_WEIGHT~/~4_MAXWEIGHT~ stones
2632-
t->FormatArgs("%" FMTSIZE_T "\t%d\t%d\t%d", pContainer->GetCount(), MAX_ITEMS_CONT, pContainer->GetTotalWeight() / WEIGHT_UNITS, iMaxWeight / WEIGHT_UNITS);
2632+
t->FormatArgs("%zu\t%d\t%d\t%d", pContainer->GetCount(), MAX_ITEMS_CONT, pContainer->GetTotalWeight() / WEIGHT_UNITS, iMaxWeight / WEIGHT_UNITS);
26332633
}
26342634
else
26352635
{
26362636
m_TooltipData.Add(t = new CClientTooltip(1073841)); // Contents: ~1_COUNT~/~2_MAXCOUNT~ items, ~3_WEIGHT~ stones
2637-
t->FormatArgs("%" FMTSIZE_T "\t%d\t%d", pContainer->GetCount(), MAX_ITEMS_CONT, pContainer->GetTotalWeight() / WEIGHT_UNITS);
2637+
t->FormatArgs("%zu\t%d\t%d", pContainer->GetCount(), MAX_ITEMS_CONT, pContainer->GetTotalWeight() / WEIGHT_UNITS);
26382638
}
26392639
}
26402640
else
26412641
{
26422642
m_TooltipData.Add(t = new CClientTooltip(1050044)); // ~1_COUNT~ items, ~2_WEIGHT~ stones
2643-
t->FormatArgs("%" FMTSIZE_T "\t%d", pContainer->GetCount(), pContainer->GetTotalWeight() / WEIGHT_UNITS);
2643+
t->FormatArgs("%zu\t%d", pContainer->GetCount(), pContainer->GetTotalWeight() / WEIGHT_UNITS);
26442644
}
26452645

26462646
if ( pItem->m_WeightReduction != 0 )
@@ -2651,7 +2651,7 @@ void CClient::addAOSTooltip(const CObjBase *pObj, bool fRequested, bool fShop)
26512651
}
26522652
}
26532653

2654-
const CChar *pCraftsman = static_cast<CGrayUID>(pItem->GetDefNum("CRAFTEDBY")).CharFind();
2654+
const CChar *pCraftsman = static_cast<CGrayUID>(static_cast<DWORD>(pItem->GetDefNum("CRAFTEDBY"))).CharFind();
26552655
if ( pCraftsman )
26562656
{
26572657
m_TooltipData.Add(t = new CClientTooltip(1050043)); // crafted by ~1_NAME~
@@ -3361,28 +3361,28 @@ void CClient::SendPacket(TCHAR *pszKey)
33613361
if ( packet->getLength() > SCRIPT_MAX_LINE_LEN - 4 )
33623362
{
33633363
// We won't get here because this lenght is enforced in all scripts
3364-
DEBUG_ERR(("SENDPACKET function exceeded max length allowed (%" FMTSIZE_T "/%d)\n", packet->getLength(), SCRIPT_MAX_LINE_LEN - 4));
3364+
DEBUG_ERR(("SENDPACKET function exceeded max length allowed (%zu/%d)\n", packet->getLength(), SCRIPT_MAX_LINE_LEN - 4));
33653365
delete packet;
33663366
return;
33673367
}
33683368

33693369
GETNONWHITESPACE(pszKey);
3370-
3371-
if ( toupper(*pszKey) == 'D' )
3372-
{
3373-
++pszKey;
3374-
packet->writeInt32(static_cast<DWORD>(Exp_GetLLVal(pszKey)));
3375-
}
3376-
else if ( toupper(*pszKey) == 'W' )
3377-
{
3378-
++pszKey;
3379-
packet->writeInt16(static_cast<WORD>(Exp_GetLLVal(pszKey)));
3380-
}
3381-
else
3370+
switch ( toupper(*pszKey) )
33823371
{
3383-
if ( toupper(*pszKey) == 'B' )
3372+
case 'D':
33843373
++pszKey;
3385-
packet->writeByte(static_cast<BYTE>(Exp_GetLLVal(pszKey)));
3374+
packet->writeInt32(static_cast<DWORD>(Exp_GetLLVal(pszKey)));
3375+
break;
3376+
case 'W':
3377+
++pszKey;
3378+
packet->writeInt16(static_cast<WORD>(Exp_GetLLVal(pszKey)));
3379+
break;
3380+
case 'B':
3381+
++pszKey;
3382+
// fall through
3383+
default:
3384+
packet->writeByte(static_cast<BYTE>(Exp_GetLLVal(pszKey)));
3385+
break;
33863386
}
33873387
}
33883388

0 commit comments

Comments
 (0)