288 changes: 0 additions & 288 deletions src/engine/external/libwebsockets/extension-deflate-frame.c

This file was deleted.

25 changes: 0 additions & 25 deletions src/engine/external/libwebsockets/extension-deflate-frame.h

This file was deleted.

166 changes: 0 additions & 166 deletions src/engine/external/libwebsockets/extension-deflate-stream.c

This file was deleted.

20 changes: 0 additions & 20 deletions src/engine/external/libwebsockets/extension-deflate-stream.h

This file was deleted.

208 changes: 0 additions & 208 deletions src/engine/external/libwebsockets/extension.c

This file was deleted.

76 changes: 0 additions & 76 deletions src/engine/external/libwebsockets/getifaddrs.h

This file was deleted.

232 changes: 0 additions & 232 deletions src/engine/external/libwebsockets/handshake.c

This file was deleted.

530 changes: 0 additions & 530 deletions src/engine/external/libwebsockets/huftable.h

This file was deleted.

86 changes: 0 additions & 86 deletions src/engine/external/libwebsockets/lextable-strings.h

This file was deleted.

745 changes: 0 additions & 745 deletions src/engine/external/libwebsockets/lextable.h

This file was deleted.

850 changes: 0 additions & 850 deletions src/engine/external/libwebsockets/libwebsockets.c

This file was deleted.

1,371 changes: 0 additions & 1,371 deletions src/engine/external/libwebsockets/libwebsockets.h

This file was deleted.

442 changes: 0 additions & 442 deletions src/engine/external/libwebsockets/lws-plat-unix.c

This file was deleted.

606 changes: 0 additions & 606 deletions src/engine/external/libwebsockets/output.c

This file was deleted.

1,015 changes: 0 additions & 1,015 deletions src/engine/external/libwebsockets/parsers.c

This file was deleted.

293 changes: 0 additions & 293 deletions src/engine/external/libwebsockets/pollfd.c

This file was deleted.

1,211 changes: 0 additions & 1,211 deletions src/engine/external/libwebsockets/private-libwebsockets.h

This file was deleted.

274 changes: 0 additions & 274 deletions src/engine/external/libwebsockets/server-handshake.c

This file was deleted.

1,162 changes: 0 additions & 1,162 deletions src/engine/external/libwebsockets/server.c

This file was deleted.

636 changes: 0 additions & 636 deletions src/engine/external/libwebsockets/service.c

This file was deleted.

301 changes: 0 additions & 301 deletions src/engine/external/libwebsockets/sha-1.c

This file was deleted.

110 changes: 101 additions & 9 deletions src/engine/graphics.h
Expand Up @@ -5,6 +5,38 @@

#include "kernel.h"

#include <vector>
#define GRAPHICS_TYPE_UNSIGNED_BYTE 0x1401
#define GRAPHICS_TYPE_UNSIGNED_SHORT 0x1403
#define GRAPHICS_TYPE_INT 0x1404
#define GRAPHICS_TYPE_UNSIGNED_INT 0x1405
#define GRAPHICS_TYPE_FLOAT 0x1406
struct SBufferContainerInfo
{
int m_Stride;

// the attributes of the container
struct SAttribute
{
int m_DataTypeCount;
unsigned int m_Type;
bool m_Normalized;
void* m_pOffset;

//0: float, 1:integer
unsigned int m_FuncType;

int m_VertBufferBindingIndex;
};
std::vector<SAttribute> m_Attributes;
};

struct SQuadRenderInfo
{
float m_aColor[4];
float m_aOffsets[2];
float m_Rotation;
};

class CImageInfo
{
Expand Down Expand Up @@ -44,6 +76,22 @@ class CVideoMode
int m_Red, m_Green, m_Blue;
};

struct GL_SPoint { float x, y; };
struct GL_STexCoord { float u, v; };
struct GL_SColorf { float r, g, b, a; };

//use normalized color values
struct GL_SColor { unsigned char r, g, b, a; };

struct GL_SVertex
{
GL_SPoint m_Pos;
GL_STexCoord m_Tex;
GL_SColor m_Color;
};

typedef void(*WINDOW_RESIZE_FUNC)(void *pUser);

class IGraphics : public IInterface
{
MACRO_INTERFACE("graphics", 0)
Expand Down Expand Up @@ -72,6 +120,7 @@ class IGraphics : public IInterface
virtual bool SetVSync(bool State) = 0;
virtual int GetWindowScreen() = 0;
virtual void Resize(int w, int h) = 0;
virtual void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) = 0;

virtual void Clear(float r, float g, float b) = 0;

Expand All @@ -95,14 +144,30 @@ class IGraphics : public IInterface
virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags) = 0;
virtual int LoadTextureRawSub(int TextureID, int x, int y, int Width, int Height, int Format, const void *pData) = 0;
virtual void TextureSet(int TextureID) = 0;

virtual void FlushVertices(bool KeepVertices = false) = 0;
virtual void FlushTextVertices(int TextureSize, int TextTextureIndex, int TextOutlineTextureIndex, float* pOutlineTextColor) = 0;

// specific render functions
virtual void RenderTileLayer(int BufferContainerIndex, float* pColor, char** pOffsets, unsigned int* IndicedVertexDrawNum, size_t NumIndicesOffet) = 0;
virtual void RenderBorderTiles(int BufferContainerIndex, float* pColor, char* pOffset, float* Offset, float* Dir, int JumpIndex, unsigned int DrawNum) = 0;
virtual void RenderBorderTileLines(int BufferContainerIndex, float* pColor, char* pOffset, float* Dir, unsigned int IndexDrawNum, unsigned int RedrawNum) = 0;
virtual void RenderQuadLayer(int BufferContainerIndex, SQuadRenderInfo* pQuadInfo, int QuadNum) = 0;
virtual void RenderText(int BufferContainerIndex, int TextQuadNum, int TextureSize, int TextureTextIndex, int TextureTextOutlineIndex, float* pTextColor, float* pTextoutlineColor) = 0;

//upload/draw of VBO and IBO
virtual void DrawVisualObject(int VisualObjectIDX, float* pColor, char** pOffsets, unsigned int* IndicedVertexDrawNum, size_t NumIndicesOffet) = 0;
virtual void DrawBorderTile(int VisualObjectIDX, float* pColor, char* pOffset, float* Offset, float* Dir, int JumpIndex, unsigned int DrawNum) = 0;
virtual void DrawBorderTileLine(int VisualObjectIDX, float* pColor, char* pOffset, float* Dir, unsigned int IndexDrawNum, unsigned int RedrawNum) = 0;
virtual void DestroyVisual(int VisualObjectIDX) = 0;
virtual int CreateVisualObjects(float* pVertices, unsigned char* pTexCoords, int NumTiles, unsigned int NumIndicesRequired) = 0;
virtual void AppendAllVertices(float* pVertices, unsigned char* pTexCoords, int NumTiles, int VisualObjectIDX) = 0;
// opengl 3.3 functions
virtual int CreateBufferObject(size_t UploadDataSize, void* pUploadData) = 0;
virtual void RecreateBufferObject(int BufferIndex, size_t UploadDataSize, void* pUploadData) = 0;
virtual void UpdateBufferObject(int BufferIndex, size_t UploadDataSize, void* pUploadData, void* pOffset) = 0;
virtual void CopyBufferObject(int WriteBufferIndex, int ReadBufferIndex, size_t WriteOffset, size_t ReadOffset, size_t CopyDataSize) = 0;
virtual void DeleteBufferObject(int BufferIndex) = 0;

virtual int CreateBufferContainer(struct SBufferContainerInfo *pContainerInfo) = 0;
// destroying all buffer objects means, that all referenced VBOs are destroyed automatically, so the user does not need to save references to them
virtual void DeleteBufferContainer(int ContainerIndex, bool DestroyAllBO = true) = 0;
virtual void UpdateBufferContainer(int ContainerIndex, struct SBufferContainerInfo *pContainerInfo) = 0;
virtual void IndicesNumRequiredNotify(unsigned int RequiredIndicesCount) = 0;

virtual bool IsBufferingEnabled() = 0;

struct CLineItem
Expand All @@ -117,15 +182,20 @@ class IGraphics : public IInterface

virtual void QuadsBegin() = 0;
virtual void QuadsEnd() = 0;
virtual void TextQuadsBegin() = 0;
virtual void TextQuadsEnd(int TextureSize, int TextTextureIndex, int TextOutlineTextureIndex, float* pOutlineTextColor) = 0;
virtual void QuadsEndKeepVertices() = 0;
virtual void QuadsDrawCurrentVertices(bool KeepVertices = true) = 0;
virtual void QuadsSetRotation(float Angle) = 0;
virtual void QuadsSetSubset(float TopLeftU, float TopLeftV, float BottomRightU, float BottomRightV) = 0;
virtual void QuadsSetSubsetFree(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) = 0;

struct CQuadItem
{
float m_X, m_Y, m_Width, m_Height;
CQuadItem() {}
CQuadItem(float x, float y, float w, float h) : m_X(x), m_Y(y), m_Width(w), m_Height(h) {}
void Set(float x, float y, float w, float h) { m_X = x; m_Y = y; m_Width = w; m_Height = h; }
};
virtual void QuadsDraw(CQuadItem *pArray, int Num) = 0;
virtual void QuadsDrawTL(const CQuadItem *pArray, int Num) = 0;
Expand All @@ -137,6 +207,26 @@ class IGraphics : public IInterface
CFreeformItem(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)
: m_X0(x0), m_Y0(y0), m_X1(x1), m_Y1(y1), m_X2(x2), m_Y2(y2), m_X3(x3), m_Y3(y3) {}
};

virtual int CreateQuadContainer() = 0;
virtual void QuadContainerUpload(int ContainerIndex) = 0;
virtual void QuadContainerAddQuads(int ContainerIndex, CQuadItem *pArray, int Num) = 0;
virtual void QuadContainerAddQuads(int ContainerIndex, CFreeformItem *pArray, int Num) = 0;
virtual void QuadContainerReset(int ContainerIndex) = 0;
virtual void DeleteQuadContainer(int ContainerIndex) = 0;
virtual void RenderQuadContainer(int ContainerIndex, int QuadDrawNum) = 0;
virtual void RenderQuadContainer(int ContainerIndex, int QuadOffset, int QuadDrawNum) = 0;
virtual void RenderQuadContainerAsSprite(int ContainerIndex, int QuadOffset, float X, float Y, float ScaleX = 1.f, float ScaleY = 1.f) = 0;

struct SRenderSpriteInfo
{
float m_Pos[2];
float m_Scale;
float m_Rotation;
};

virtual void RenderQuadContainerAsSpriteMultiple(int ContainerIndex, int QuadOffset, int DrawCount, SRenderSpriteInfo *pRenderInfo) = 0;

virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0;
virtual void QuadsText(float x, float y, float Size, const char *pText) = 0;

Expand All @@ -149,6 +239,8 @@ class IGraphics : public IInterface
};
virtual void SetColorVertex(const CColorVertex *pArray, int Num) = 0;
virtual void SetColor(float r, float g, float b, float a) = 0;
virtual void ChangeColorOfCurrentQuadVertices(float r, float g, float b, float a) = 0;
virtual void ChangeColorOfQuadVertices(int QuadOffset, unsigned char r, unsigned char g, unsigned char b, unsigned char a) = 0;

virtual void TakeScreenshot(const char *pFilename) = 0;
virtual void TakeCustomScreenshot(const char *pFilename) = 0;
Expand All @@ -157,7 +249,7 @@ class IGraphics : public IInterface
virtual void Swap() = 0;
virtual int GetNumScreens() const = 0;

// syncronization
// synchronization
virtual void InsertSignal(class semaphore *pSemaphore) = 0;
virtual bool IsIdle() = 0;
virtual void WaitForIdle() = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/engine/server.h
Expand Up @@ -33,6 +33,7 @@ class IServer : public IInterface
virtual const char *ClientClan(int ClientID) = 0;
virtual int ClientCountry(int ClientID) = 0;
virtual bool ClientIngame(int ClientID) = 0;
virtual bool ClientAuthed(int ClientID) = 0;
virtual int GetClientInfo(int ClientID, CClientInfo *pInfo) = 0;
virtual void GetClientAddr(int ClientID, char *pAddrStr, int Size) = 0;
virtual void RestrictRconOutput(int ClientID) = 0;
Expand Down Expand Up @@ -213,6 +214,7 @@ class IGameServer : public IInterface
virtual bool IsClientReady(int ClientID) = 0;
virtual bool IsClientPlayer(int ClientID) = 0;

virtual CUuid GameUuid() = 0;
virtual const char *GameType() = 0;
virtual const char *Version() = 0;
virtual const char *NetVersion() = 0;
Expand Down
24 changes: 24 additions & 0 deletions src/engine/server/name_ban.cpp
@@ -0,0 +1,24 @@
#include "name_ban.h"

CNameBan *IsNameBanned(const char *pName, CNameBan *pNameBans, int NumNameBans)
{
char aTrimmed[MAX_NAME_LENGTH];
str_copy(aTrimmed, str_utf8_skip_whitespaces(pName), sizeof(aTrimmed));
str_utf8_trim_right(aTrimmed);

int aSkeleton[MAX_NAME_SKELETON_LENGTH];
int SkeletonLength = str_utf8_to_skeleton(aTrimmed, aSkeleton, sizeof(aSkeleton) / sizeof(aSkeleton[0]));
int aBuffer[MAX_NAME_SKELETON_LENGTH * 2 + 2];

CNameBan *pResult = 0;
for(int i = 0; i < NumNameBans; i++)
{
CNameBan *pBan = &pNameBans[i];
int Distance = str_utf32_dist_buffer(aSkeleton, SkeletonLength, pBan->m_aSkeleton, pBan->m_SkeletonLength, aBuffer, sizeof(aBuffer) / sizeof(aBuffer[0]));
if(Distance <= pBan->m_Distance)
{
pResult = pBan;
}
}
return pResult;
}
33 changes: 33 additions & 0 deletions src/engine/server/name_ban.h
@@ -0,0 +1,33 @@
#ifndef ENGINE_SERVER_NAME_BANS_H
#define ENGINE_SERVER_NAME_BANS_H

#include <base/system.h>
#include <engine/shared/protocol.h>

enum
{
MAX_NAME_SKELETON_LENGTH=MAX_NAME_LENGTH*4,
MAX_NAMEBAN_REASON_LENGTH=64
};

class CNameBan
{
public:
CNameBan() {}
CNameBan(const char *pName, int Distance, const char *pReason = "") :
m_Distance(Distance)
{
str_copy(m_aName, pName, sizeof(m_aName));
m_SkeletonLength = str_utf8_to_skeleton(m_aName, m_aSkeleton, sizeof(m_aSkeleton) / sizeof(m_aSkeleton[0]));
str_copy(m_aReason, pReason, sizeof(m_aReason));
}
char m_aName[MAX_NAME_LENGTH];
char m_aReason[MAX_NAMEBAN_REASON_LENGTH];
int m_aSkeleton[MAX_NAME_SKELETON_LENGTH];
int m_SkeletonLength;
int m_Distance;
};

CNameBan *IsNameBanned(const char *pName, CNameBan *pNameBans, int NumNameBans);

#endif // ENGINE_SERVER_NAME_BANS_H
176 changes: 115 additions & 61 deletions src/engine/server/server.cpp
Expand Up @@ -44,43 +44,6 @@
#include <windows.h>
#endif

static const char *StrLtrim(const char *pStr)
{
while(*pStr)
{
const char *pStrOld = pStr;
int Code = str_utf8_decode(&pStr);

// check if unicode is not empty
if(str_utf8_isspace(Code))
{
return pStrOld;
}
}
return pStr;
}

static void StrRtrim(char *pStr)
{
const char *p = pStr;
const char *pEnd = 0;
while(*p)
{
const char *pStrOld = p;
int Code = str_utf8_decode(&p);

// check if unicode is not empty
if(str_utf8_isspace(Code))
{
pEnd = 0;
}
else if(pEnd == 0)
pEnd = pStrOld;
}
if(pEnd != 0)
*(const_cast<char *>(pEnd)) = 0;
}


CSnapIDPool::CSnapIDPool()
{
Expand Down Expand Up @@ -343,14 +306,13 @@ CServer::CServer()
Init();
}


int CServer::TrySetClientName(int ClientID, const char *pName)
{
char aTrimmedName[64];

// trim the name
str_copy(aTrimmedName, StrLtrim(pName), sizeof(aTrimmedName));
StrRtrim(aTrimmedName);
str_copy(aTrimmedName, str_utf8_skip_whitespaces(pName), sizeof(aTrimmedName));
str_utf8_trim_right(aTrimmedName);

// check for empty names
if(!aTrimmedName[0])
Expand Down Expand Up @@ -381,8 +343,6 @@ int CServer::TrySetClientName(int ClientID, const char *pName)
return 0;
}



void CServer::SetClientName(int ClientID, const char *pName)
{
if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State < CClient::STATE_READY)
Expand All @@ -391,6 +351,25 @@ void CServer::SetClientName(int ClientID, const char *pName)
if(!pName)
return;

CNameBan *pBanned = IsNameBanned(pName, m_aNameBans.base_ptr(), m_aNameBans.size());
if(pBanned)
{
if(m_aClients[ClientID].m_State == CClient::STATE_READY)
{
char aBuf[256];
if(pBanned->m_aReason[0])
{
str_format(aBuf, sizeof(aBuf), "Kicked (your name is banned: %s)", pBanned->m_aReason);
}
else
{
str_copy(aBuf, "Kicked (your name is banned)", sizeof(aBuf));
}
Kick(ClientID, aBuf);
}
return;
}

char aNameTry[MAX_NAME_LENGTH];
str_copy(aNameTry, pName, sizeof(aNameTry));
if(TrySetClientName(ClientID, aNameTry))
Expand Down Expand Up @@ -564,6 +543,11 @@ bool CServer::ClientIngame(int ClientID)
return ClientID >= 0 && ClientID < MAX_CLIENTS && m_aClients[ClientID].m_State == CServer::CClient::STATE_INGAME;
}

bool CServer::ClientAuthed(int ClientID)
{
return ClientID >= 0 && ClientID < MAX_CLIENTS && m_aClients[ClientID].m_Authed;
}

int CServer::MaxClients() const
{
return m_NetServer.MaxClients();
Expand Down Expand Up @@ -1721,9 +1705,8 @@ int CServer::LoadMap(const char *pMapName)
{
IOHANDLE File = Storage()->OpenFile(aBuf, IOFLAG_READ, IStorage::TYPE_ALL);
m_CurrentMapSize = (unsigned int)io_length(File);
if(m_pCurrentMapData)
mem_free(m_pCurrentMapData);
m_pCurrentMapData = (unsigned char *)mem_alloc(m_CurrentMapSize, 1);
free(m_pCurrentMapData);
m_pCurrentMapData = (unsigned char *)malloc(m_CurrentMapSize);
io_read(File, m_pCurrentMapData, m_CurrentMapSize);
io_close(File);
}
Expand Down Expand Up @@ -1815,12 +1798,6 @@ int CServer::Run()
m_Lastheartbeat = 0;
m_GameStartTime = time_get();

if(g_Config.m_Debug)
{
str_format(aBuf, sizeof(aBuf), "baseline memory usage %dk", mem_stats()->allocated/1024);
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "server", aBuf);
}

while(m_RunServer)
{
if(NonActive)
Expand Down Expand Up @@ -2020,8 +1997,7 @@ int CServer::Run()
GameServer()->OnShutdown(true);
m_pMap->Unload();

if(m_pCurrentMapData)
mem_free(m_pCurrentMapData);
free(m_pCurrentMapData);

#if defined (CONF_SQL)
for (int i = 0; i < MAX_SQLSERVERS; i++)
Expand Down Expand Up @@ -2328,6 +2304,75 @@ void CServer::ConAuthList(IConsole::IResult *pResult, void *pUser)
pManager->ListKeys(ListKeysCallback, pThis);
}

void CServer::ConNameBan(IConsole::IResult *pResult, void *pUser)
{
CServer *pThis = (CServer *)pUser;
char aBuf[64];
const char *pName = pResult->GetString(0);
const char *pReason = "";
int Distance;

if(pResult->NumArguments() > 1)
{
Distance = pResult->GetInteger(1);
if(pResult->NumArguments() > 2)
{
pReason = pResult->GetString(2);
}
}
else
{
Distance = str_length(pName) / 3;
}

for(int i = 0; i < pThis->m_aNameBans.size(); i++)
{
CNameBan *pBan = &pThis->m_aNameBans[i];
if(str_comp(pBan->m_aName, pName) == 0)
{
str_format(aBuf, sizeof(aBuf), "changed name='%s' distance=%d old_distance=%d reason='%s' old_reason='%s'", pName, Distance, pBan->m_Distance, pReason, pBan->m_aReason);
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "name_ban", aBuf);
pBan->m_Distance = Distance;
return;
}
}

pThis->m_aNameBans.add(CNameBan(pName, Distance, pReason));
str_format(aBuf, sizeof(aBuf), "added name='%s' distance=%d reason='%s'", pName, Distance, pReason);
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "name_ban", aBuf);
}

void CServer::ConNameUnban(IConsole::IResult *pResult, void *pUser)
{
CServer *pThis = (CServer *)pUser;
const char *pName = pResult->GetString(0);

for(int i = 0; i < pThis->m_aNameBans.size(); i++)
{
CNameBan *pBan = &pThis->m_aNameBans[i];
if(str_comp(pBan->m_aName, pName) == 0)
{
char aBuf[64];
str_format(aBuf, sizeof(aBuf), "removed name='%s' distance=%d reason='%s'", pBan->m_aName, pBan->m_Distance, pBan->m_aReason);
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "name_ban", aBuf);
pThis->m_aNameBans.remove_index(i);
}
}
}

void CServer::ConNameBans(IConsole::IResult *pResult, void *pUser)
{
CServer *pThis = (CServer *)pUser;

for(int i = 0; i < pThis->m_aNameBans.size(); i++)
{
CNameBan *pBan = &pThis->m_aNameBans[i];
char aBuf[64];
str_format(aBuf, sizeof(aBuf), "name='%s' distance=%d reason='%s'", pBan->m_aName, pBan->m_Distance, pBan->m_aReason);
pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "name_ban", aBuf);
}
}

void CServer::ConShutdown(IConsole::IResult *pResult, void *pUser)
{
((CServer *)pUser)->m_RunServer = 0;
Expand Down Expand Up @@ -2610,25 +2655,30 @@ void CServer::LogoutKey(int Key, const char *pReason)
LogoutClient(i, pReason);
}

void CServer::ConchainRconPasswordChangeGeneric(int Level, IConsole::IResult *pResult)
void CServer::ConchainRconPasswordChangeGeneric(int Level, const char *pCurrent, IConsole::IResult *pResult)
{
if(pResult->NumArguments() == 1)
{
int KeySlot = m_AuthManager.DefaultKey(Level);
if(KeySlot == -1 && pResult->GetString(0)[0])
const char *pNew = pResult->GetString(0);
if(str_comp(pCurrent, pNew) == 0)
{
m_AuthManager.AddDefaultKey(Level, pResult->GetString(0));
return;
}
if(KeySlot == -1 && pNew[0])
{
m_AuthManager.AddDefaultKey(Level, pNew);
}
else if(KeySlot >= 0)
{
if(!pResult->GetString(0)[0])
if(!pNew[0])
{
AuthRemoveKey(KeySlot);
// Already logs users out.
}
else
{
m_AuthManager.UpdateKey(KeySlot, pResult->GetString(0), Level);
m_AuthManager.UpdateKey(KeySlot, pNew, Level);
LogoutKey(KeySlot, "key update");
}
}
Expand All @@ -2637,20 +2687,20 @@ void CServer::ConchainRconPasswordChangeGeneric(int Level, IConsole::IResult *pR

void CServer::ConchainRconPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
((CServer *)pUserData)->ConchainRconPasswordChangeGeneric(AUTHED_ADMIN, g_Config.m_SvRconPassword, pResult);
pfnCallback(pResult, pCallbackUserData);
((CServer *)pUserData)->ConchainRconPasswordChangeGeneric(AUTHED_ADMIN, pResult);
}

void CServer::ConchainRconModPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
((CServer *)pUserData)->ConchainRconPasswordChangeGeneric(AUTHED_MOD, g_Config.m_SvRconModPassword, pResult);
pfnCallback(pResult, pCallbackUserData);
((CServer *)pUserData)->ConchainRconPasswordChangeGeneric(AUTHED_MOD, pResult);
}

void CServer::ConchainRconHelperPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
((CServer *)pUserData)->ConchainRconPasswordChangeGeneric(AUTHED_HELPER, g_Config.m_SvRconHelperPassword, pResult);
pfnCallback(pResult, pCallbackUserData);
((CServer *)pUserData)->ConchainRconPasswordChangeGeneric(AUTHED_HELPER, pResult);
}

#if defined(CONF_FAMILY_UNIX)
Expand Down Expand Up @@ -2713,6 +2763,10 @@ void CServer::RegisterCommands()
Console()->Register("auth_remove", "s[ident]", CFGFLAG_SERVER|CFGFLAG_NONTEEHISTORIC, ConAuthRemove, this, "Remove a rcon key");
Console()->Register("auth_list", "", CFGFLAG_SERVER, ConAuthList, this, "List all rcon keys");

Console()->Register("name_ban", "s[name] ?i[distance] ?r[reason]", CFGFLAG_SERVER, ConNameBan, this, "Ban a certain nick name");
Console()->Register("name_unban", "s[name]", CFGFLAG_SERVER, ConNameUnban, this, "Unban a certain nick name");
Console()->Register("name_bans", "", CFGFLAG_SERVER, ConNameBans, this, "List all name bans");

Console()->Chain("sv_name", ConchainSpecialInfoupdate, this);
Console()->Chain("password", ConchainSpecialInfoupdate, this);

Expand Down
12 changes: 11 additions & 1 deletion src/engine/server/server.h
Expand Up @@ -19,7 +19,10 @@
#include <engine/shared/netban.h>
#include <engine/shared/uuid_manager.h>

#include <base/tl/array.h>

#include "authmanager.h"
#include "name_ban.h"

#if defined (CONF_SQL)
#include "sql_connector.h"
Expand Down Expand Up @@ -217,6 +220,8 @@ class CServer : public IServer

char m_aErrorShutdownReason[128];

array<CNameBan> m_aNameBans;

CServer();

int TrySetClientName(int ClientID, const char *pName);
Expand Down Expand Up @@ -247,6 +252,7 @@ class CServer : public IServer
const char *ClientClan(int ClientID);
int ClientCountry(int ClientID);
bool ClientIngame(int ClientID);
bool ClientAuthed(int ClientID);
int MaxClients() const;

virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID);
Expand Down Expand Up @@ -308,6 +314,10 @@ class CServer : public IServer
static void ConAuthRemove(IConsole::IResult *pResult, void *pUser);
static void ConAuthList(IConsole::IResult *pResult, void *pUser);

static void ConNameBan(IConsole::IResult *pResult, void *pUser);
static void ConNameUnban(IConsole::IResult *pResult, void *pUser);
static void ConNameBans(IConsole::IResult *pResult, void *pUser);

static void StatusImpl(IConsole::IResult *pResult, void *pUser, bool DnsblBlacklistedOnly);

#if defined (CONF_SQL)
Expand All @@ -326,7 +336,7 @@ class CServer : public IServer
void LogoutClient(int ClientID, const char *pReason);
void LogoutKey(int Key, const char *pReason);

void ConchainRconPasswordChangeGeneric(int Level, IConsole::IResult *pResult);
void ConchainRconPasswordChangeGeneric(int Level, const char *pCurrent, IConsole::IResult *pResult);
static void ConchainRconPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainRconModPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainRconHelperPasswordChange(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
Expand Down
4 changes: 2 additions & 2 deletions src/engine/server/sql_server.cpp
Expand Up @@ -170,10 +170,10 @@ void CSqlServer::CreateTables()
char aBuf[1024];

// create tables
str_format(aBuf, sizeof(aBuf), "CREATE TABLE IF NOT EXISTS %s_race (Map VARCHAR(128) BINARY NOT NULL, Name VARCHAR(%d) BINARY NOT NULL, Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , Time FLOAT DEFAULT 0, Server CHAR(4), cp1 FLOAT DEFAULT 0, cp2 FLOAT DEFAULT 0, cp3 FLOAT DEFAULT 0, cp4 FLOAT DEFAULT 0, cp5 FLOAT DEFAULT 0, cp6 FLOAT DEFAULT 0, cp7 FLOAT DEFAULT 0, cp8 FLOAT DEFAULT 0, cp9 FLOAT DEFAULT 0, cp10 FLOAT DEFAULT 0, cp11 FLOAT DEFAULT 0, cp12 FLOAT DEFAULT 0, cp13 FLOAT DEFAULT 0, cp14 FLOAT DEFAULT 0, cp15 FLOAT DEFAULT 0, cp16 FLOAT DEFAULT 0, cp17 FLOAT DEFAULT 0, cp18 FLOAT DEFAULT 0, cp19 FLOAT DEFAULT 0, cp20 FLOAT DEFAULT 0, cp21 FLOAT DEFAULT 0, cp22 FLOAT DEFAULT 0, cp23 FLOAT DEFAULT 0, cp24 FLOAT DEFAULT 0, cp25 FLOAT DEFAULT 0, KEY (Map, Name)) CHARACTER SET utf8mb4;", m_aPrefix, MAX_NAME_LENGTH);
str_format(aBuf, sizeof(aBuf), "CREATE TABLE IF NOT EXISTS %s_race (Map VARCHAR(128) BINARY NOT NULL, Name VARCHAR(%d) BINARY NOT NULL, Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , Time FLOAT DEFAULT 0, Server CHAR(4), cp1 FLOAT DEFAULT 0, cp2 FLOAT DEFAULT 0, cp3 FLOAT DEFAULT 0, cp4 FLOAT DEFAULT 0, cp5 FLOAT DEFAULT 0, cp6 FLOAT DEFAULT 0, cp7 FLOAT DEFAULT 0, cp8 FLOAT DEFAULT 0, cp9 FLOAT DEFAULT 0, cp10 FLOAT DEFAULT 0, cp11 FLOAT DEFAULT 0, cp12 FLOAT DEFAULT 0, cp13 FLOAT DEFAULT 0, cp14 FLOAT DEFAULT 0, cp15 FLOAT DEFAULT 0, cp16 FLOAT DEFAULT 0, cp17 FLOAT DEFAULT 0, cp18 FLOAT DEFAULT 0, cp19 FLOAT DEFAULT 0, cp20 FLOAT DEFAULT 0, cp21 FLOAT DEFAULT 0, cp22 FLOAT DEFAULT 0, cp23 FLOAT DEFAULT 0, cp24 FLOAT DEFAULT 0, cp25 FLOAT DEFAULT 0, GameID VARCHAR(64), KEY (Map, Name)) CHARACTER SET utf8mb4;", m_aPrefix, MAX_NAME_LENGTH);
executeSql(aBuf);

str_format(aBuf, sizeof(aBuf), "CREATE TABLE IF NOT EXISTS %s_teamrace (Map VARCHAR(128) BINARY NOT NULL, Name VARCHAR(%d) BINARY NOT NULL, Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, Time FLOAT DEFAULT 0, ID VARBINARY(16) NOT NULL, KEY Map (Map)) CHARACTER SET utf8mb4;", m_aPrefix, MAX_NAME_LENGTH);
str_format(aBuf, sizeof(aBuf), "CREATE TABLE IF NOT EXISTS %s_teamrace (Map VARCHAR(128) BINARY NOT NULL, Name VARCHAR(%d) BINARY NOT NULL, Timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, Time FLOAT DEFAULT 0, ID VARBINARY(16) NOT NULL, GameID VARCHAR(64), KEY Map (Map)) CHARACTER SET utf8mb4;", m_aPrefix, MAX_NAME_LENGTH);
executeSql(aBuf);

str_format(aBuf, sizeof(aBuf), "CREATE TABLE IF NOT EXISTS %s_maps (Map VARCHAR(128) BINARY NOT NULL, Server VARCHAR(32) BINARY NOT NULL, Mapper VARCHAR(128) BINARY NOT NULL, Points INT DEFAULT 0, Stars INT DEFAULT 0, Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY Map (Map)) CHARACTER SET utf8mb4;", m_aPrefix);
Expand Down
32 changes: 26 additions & 6 deletions src/engine/shared/config.cpp
Expand Up @@ -11,6 +11,7 @@ class CConfig : public IConfig
{
IStorage *m_pStorage;
IOHANDLE m_ConfigFile;
bool m_Failed;

struct CCallback
{
Expand All @@ -37,6 +38,7 @@ class CConfig : public IConfig
{
m_ConfigFile = 0;
m_NumCallbacks = 0;
m_Failed = false;
}

virtual void Init()
Expand All @@ -60,11 +62,14 @@ class CConfig : public IConfig
{
if(!m_pStorage || !g_Config.m_ClSaveSettings)
return;
m_ConfigFile = m_pStorage->OpenFile(CONFIG_FILE, IOFLAG_WRITE, IStorage::TYPE_SAVE);

m_ConfigFile = m_pStorage->OpenFile(CONFIG_FILE_TMP, IOFLAG_WRITE, IStorage::TYPE_SAVE);

if(!m_ConfigFile)
return;

m_Failed = false;

char aLineBuf[1024*2];
char aEscapeBuf[1024*2];

Expand All @@ -79,8 +84,19 @@ class CConfig : public IConfig
for(int i = 0; i < m_NumCallbacks; i++)
m_aCallbacks[i].m_pfnFunc(this, m_aCallbacks[i].m_pUserData);

io_close(m_ConfigFile);
if(io_close(m_ConfigFile) != 0)
m_Failed = true;

m_ConfigFile = 0;

if(m_Failed)
{
dbg_msg("config", "ERROR: writing to " CONFIG_FILE_TMP " failed");
return;
}

if(!m_pStorage->RenameFile(CONFIG_FILE_TMP, CONFIG_FILE, IStorage::TYPE_SAVE))
dbg_msg("config", "ERROR: renaming " CONFIG_FILE_TMP " to " CONFIG_FILE " failed");
}

virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData)
Expand All @@ -93,10 +109,14 @@ class CConfig : public IConfig

virtual void WriteLine(const char *pLine)
{
if(!m_ConfigFile)
return;
io_write(m_ConfigFile, pLine, str_length(pLine));
io_write_newline(m_ConfigFile);
if(!m_ConfigFile ||
io_write(m_ConfigFile, pLine, str_length(pLine)) != static_cast<unsigned>(str_length(pLine)) ||
#if defined(CONF_FAMILY_WINDOWS)
io_write_newline(m_ConfigFile) != 2)
#else
io_write_newline(m_ConfigFile) != 1)
#endif
m_Failed = true;
}
};

Expand Down
1 change: 1 addition & 0 deletions src/engine/shared/config.h
Expand Up @@ -4,6 +4,7 @@
#define ENGINE_SHARED_CONFIG_H

#define CONFIG_FILE "settings_ddnet.cfg"
#define CONFIG_FILE_TMP CONFIG_FILE ".tmp"
#define AUTOEXEC_FILE "autoexec.cfg"
#define AUTOEXEC_CLIENT_FILE "autoexec_client.cfg"
#define AUTOEXEC_SERVER_FILE "autoexec_server.cfg"
Expand Down
12 changes: 3 additions & 9 deletions src/engine/shared/config_variables.h
Expand Up @@ -36,12 +36,6 @@ MACRO_CONFIG_INT(ClFriendsIgnoreClan, cl_friends_ignore_clan, 0, 0, 1, CFGFLAG_C

MACRO_CONFIG_INT(ClEventthread, cl_eventthread, 0, 0, 1, CFGFLAG_CLIENT, "Enables the usage of a thread to pump the events")

#if !defined(CONF_PLATFORM_MACOSX)
MACRO_CONFIG_INT(InpGrab, inp_grab, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use forceful input grabbing method")
#else
MACRO_CONFIG_INT(InpGrab, inp_grab, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use forceful input grabbing method")
#endif

MACRO_CONFIG_STR(BrFilterString, br_filter_string, 25, "Novice", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Server browser filtering string")
MACRO_CONFIG_STR(BrExcludeString, br_exclude_string, 25, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Server browser exclusion string")
MACRO_CONFIG_INT(BrFilterFull, br_filter_full, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out full server in browser")
Expand Down Expand Up @@ -118,7 +112,7 @@ MACRO_CONFIG_INT(GfxHighDetail, gfx_high_detail, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_C
MACRO_CONFIG_INT(GfxTextureQuality, gfx_texture_quality, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
#endif
MACRO_CONFIG_INT(GfxFsaaSamples, gfx_fsaa_samples, 0, 0, 16, CFGFLAG_SAVE|CFGFLAG_CLIENT, "FSAA Samples")
MACRO_CONFIG_INT(GfxRefreshRate, gfx_refresh_rate, 0, 0, 1000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen refresh rate")
MACRO_CONFIG_INT(GfxRefreshRate, gfx_refresh_rate, 0, 0, 10000, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen refresh rate")
MACRO_CONFIG_INT(GfxFinish, gfx_finish, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(GfxBackgroundRender, gfx_backgroundrender, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Render graphics when window is in background")
MACRO_CONFIG_INT(GfxTextOverlay, gfx_text_overlay, 10, 1, 100, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Stop rendering textoverlay in editor or with entities: high value = less details = more speed")
Expand Down Expand Up @@ -358,8 +352,8 @@ MACRO_CONFIG_INT(SvSpamMuteDuration, sv_spam_mute_duration, 60, 0, 3600 , CFGFLA

MACRO_CONFIG_INT(SvEvents, sv_events, 1, 0, 1, CFGFLAG_SERVER, "Enable triggering of server events, like the happy eyeemotes on some holidays.")
MACRO_CONFIG_INT(SvRankCheats, sv_rank_cheats, 0, 0, 1, CFGFLAG_SERVER, "Enable ranks after cheats have been used (file based server only)")
MACRO_CONFIG_INT(SvShutdownWhenEmpty, sv_shutdown_when_empty, 0, 0, 1, CFGFLAG_SERVER, "Shutdown server as soon as noone is on it anymore")
MACRO_CONFIG_INT(SvReloadWhenEmpty, sv_reload_when_empty, 0, 0, 2, CFGFLAG_SERVER, "Reload map when server is empty (1 = reload once, 2 = reload everytime server gets empty)")
MACRO_CONFIG_INT(SvShutdownWhenEmpty, sv_shutdown_when_empty, 0, 0, 1, CFGFLAG_SERVER, "Shutdown server as soon as no one is on it anymore")
MACRO_CONFIG_INT(SvReloadWhenEmpty, sv_reload_when_empty, 0, 0, 2, CFGFLAG_SERVER, "Reload map when server is empty (1 = reload once, 2 = reload every time server gets empty)")
MACRO_CONFIG_INT(SvKillProtection, sv_kill_protection, 20, 0, 9999, CFGFLAG_SERVER, "0 - Disable, 1-9999 minutes")
MACRO_CONFIG_INT(SvSoloServer, sv_solo_server, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Set server to solo mode (no player interactions, has to be set before loading the map)")
MACRO_CONFIG_STR(SvClientSuggestion, sv_client_suggestion, 128, "Get DDNet client from DDNet.tw to use all features on DDNet!", CFGFLAG_SERVER, "Broadcast to display to players without DDNet client")
Expand Down
4 changes: 2 additions & 2 deletions src/engine/shared/console.cpp
Expand Up @@ -863,7 +863,7 @@ CConsole::~CConsole()
{
CCommand *pNext = pCommand->m_pNext;
if(pCommand->m_pfnCallback == Con_Chain)
mem_free(static_cast<CChain *>(pCommand->m_pUserData));
delete static_cast<CChain *>(pCommand->m_pUserData);
delete pCommand;
pCommand = pNext;
}
Expand Down Expand Up @@ -1048,7 +1048,7 @@ void CConsole::Chain(const char *pName, FChainCommandCallback pfnChainFunc, void
return;
}

CChain *pChainInfo = (CChain *)mem_alloc(sizeof(CChain), sizeof(void*));
CChain *pChainInfo = new CChain();

// store info
pChainInfo->m_pfnChainCallback = pfnChainFunc;
Expand Down
52 changes: 26 additions & 26 deletions src/engine/shared/datafile.cpp
Expand Up @@ -130,17 +130,17 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
Size += Header.m_NumItemTypes*sizeof(CDatafileItemType);
Size += (Header.m_NumItems+Header.m_NumRawData)*sizeof(int);
if(Header.m_Version == 4)
Size += Header.m_NumRawData*sizeof(int); // v4 has uncompressed data sizes aswell
Size += Header.m_NumRawData*sizeof(int); // v4 has uncompressed data sizes as well
Size += Header.m_ItemSize;

unsigned AllocSize = Size;
AllocSize += sizeof(CDatafile); // add space for info structure
AllocSize += Header.m_NumRawData*sizeof(void*); // add space for data pointers

CDatafile *pTmpDataFile = (CDatafile*)mem_alloc(AllocSize, 1);
CDatafile *pTmpDataFile = (CDatafile *)malloc(AllocSize);
pTmpDataFile->m_Header = Header;
pTmpDataFile->m_DataStartOffset = sizeof(CDatafileHeader) + Size;
pTmpDataFile->m_ppDataPtrs = (char**)(pTmpDataFile+1);
pTmpDataFile->m_ppDataPtrs = (char **)(pTmpDataFile+1);
pTmpDataFile->m_pData = (char *)(pTmpDataFile+1)+Header.m_NumRawData*sizeof(char *);
pTmpDataFile->m_File = File;
pTmpDataFile->m_Crc = Crc;
Expand All @@ -153,7 +153,7 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
if(ReadSize != Size)
{
io_close(pTmpDataFile->m_File);
mem_free(pTmpDataFile);
free(pTmpDataFile);
pTmpDataFile = 0;
dbg_msg("datafile", "couldn't load the whole thing, wanted=%d got=%d", Size, ReadSize);
return false;
Expand Down Expand Up @@ -295,12 +295,12 @@ void *CDataFileReader::GetDataImpl(int Index, int Swap)
if(m_pDataFile->m_Header.m_Version == 4)
{
// v4 has compressed data
void *pTemp = (char *)mem_alloc(DataSize, 1);
void *pTemp = malloc(DataSize);
unsigned long UncompressedSize = m_pDataFile->m_Info.m_pDataSizes[Index];
unsigned long s;

dbg_msg("datafile", "loading data index=%d size=%d uncompressed=%lu", Index, DataSize, UncompressedSize);
m_pDataFile->m_ppDataPtrs[Index] = (char *)mem_alloc(UncompressedSize, 1);
m_pDataFile->m_ppDataPtrs[Index] = (char *)malloc(UncompressedSize);

// read the compressed data
io_seek(m_pDataFile->m_File, m_pDataFile->m_DataStartOffset+m_pDataFile->m_Info.m_pDataOffsets[Index], IOSEEK_START);
Expand All @@ -314,13 +314,13 @@ void *CDataFileReader::GetDataImpl(int Index, int Swap)
#endif

// clean up the temporary buffers
mem_free(pTemp);
free(pTemp);
}
else
{
// load the data
dbg_msg("datafile", "loading data index=%d size=%d", Index, DataSize);
m_pDataFile->m_ppDataPtrs[Index] = (char *)mem_alloc(DataSize, 1);
m_pDataFile->m_ppDataPtrs[Index] = (char *)malloc(DataSize);
io_seek(m_pDataFile->m_File, m_pDataFile->m_DataStartOffset+m_pDataFile->m_Info.m_pDataOffsets[Index], IOSEEK_START);
io_read(m_pDataFile->m_File, m_pDataFile->m_ppDataPtrs[Index], DataSize);
}
Expand Down Expand Up @@ -350,7 +350,7 @@ void CDataFileReader::UnloadData(int Index)
return;

//
mem_free(m_pDataFile->m_ppDataPtrs[Index]);
free(m_pDataFile->m_ppDataPtrs[Index]);
m_pDataFile->m_ppDataPtrs[Index] = 0x0;
}

Expand All @@ -369,7 +369,7 @@ void *CDataFileReader::GetItem(int Index, int *pType, int *pID)

CDatafileItem *i = (CDatafileItem *)(m_pDataFile->m_Info.m_pItemStart+m_pDataFile->m_Info.m_pItemOffsets[Index]);
if(pType)
*pType = (i->m_TypeAndID>>16)&0xffff; // remove sign extention
*pType = (i->m_TypeAndID>>16)&0xffff; // remove sign extension
if(pID)
*pID = i->m_TypeAndID&0xffff;
return (void *)(i+1);
Expand Down Expand Up @@ -424,10 +424,10 @@ bool CDataFileReader::Close()
// free the data that is loaded
int i;
for(i = 0; i < m_pDataFile->m_Header.m_NumRawData; i++)
mem_free(m_pDataFile->m_ppDataPtrs[i]);
free(m_pDataFile->m_ppDataPtrs[i]);

io_close(m_pDataFile->m_File);
mem_free(m_pDataFile);
free(m_pDataFile);
m_pDataFile = 0;
return true;
}
Expand All @@ -454,18 +454,18 @@ IOHANDLE CDataFileReader::File()
CDataFileWriter::CDataFileWriter()
{
m_File = 0;
m_pItemTypes = static_cast<CItemTypeInfo *>(mem_alloc(sizeof(CItemTypeInfo) * MAX_ITEM_TYPES, 1));
m_pItems = static_cast<CItemInfo *>(mem_alloc(sizeof(CItemInfo) * MAX_ITEMS, 1));
m_pDatas = static_cast<CDataInfo *>(mem_alloc(sizeof(CDataInfo) * MAX_DATAS, 1));
m_pItemTypes = static_cast<CItemTypeInfo *>(calloc(MAX_ITEM_TYPES, sizeof(CItemTypeInfo)));
m_pItems = static_cast<CItemInfo *>(calloc(MAX_ITEMS, sizeof(CItemInfo)));
m_pDatas = static_cast<CDataInfo *>(calloc(MAX_DATAS, sizeof(CDataInfo)));
}

CDataFileWriter::~CDataFileWriter()
{
mem_free(m_pItemTypes);
free(m_pItemTypes);
m_pItemTypes = 0;
mem_free(m_pItems);
free(m_pItems);
m_pItems = 0;
mem_free(m_pDatas);
free(m_pDatas);
m_pDatas = 0;
}

Expand Down Expand Up @@ -508,7 +508,7 @@ int CDataFileWriter::AddItem(int Type, int ID, int Size, void *pData)
m_pItems[m_NumItems].m_Size = Size;

// copy data
m_pItems[m_NumItems].m_pData = mem_alloc(Size, 1);
m_pItems[m_NumItems].m_pData = malloc(Size);
mem_copy(m_pItems[m_NumItems].m_pData, pData, Size);

if(!m_pItemTypes[Type].m_Num) // count item types
Expand Down Expand Up @@ -537,7 +537,7 @@ int CDataFileWriter::AddData(int Size, void *pData)

CDataInfo *pInfo = &m_pDatas[m_NumDatas];
unsigned long s = compressBound(Size);
void *pCompData = mem_alloc(s, 1); // temporary buffer that we use during compression
void *pCompData = malloc(s); // temporary buffer that we use during compression

int Result = compress((Bytef*)pCompData, &s, (Bytef*)pData, Size); // ignore_convention
if(Result != Z_OK)
Expand All @@ -548,9 +548,9 @@ int CDataFileWriter::AddData(int Size, void *pData)

pInfo->m_UncompressedSize = Size;
pInfo->m_CompressedSize = (int)s;
pInfo->m_pCompressedData = mem_alloc(pInfo->m_CompressedSize, 1);
pInfo->m_pCompressedData = malloc(pInfo->m_CompressedSize);
mem_copy(pInfo->m_pCompressedData, pCompData, pInfo->m_CompressedSize);
mem_free(pCompData);
free(pCompData);

m_NumDatas++;
return m_NumDatas-1;
Expand All @@ -561,11 +561,11 @@ int CDataFileWriter::AddDataSwapped(int Size, void *pData)
dbg_assert(Size%sizeof(int) == 0, "incorrect boundary");

#if defined(CONF_ARCH_ENDIAN_BIG)
void *pSwapped = mem_alloc(Size, 1); // temporary buffer that we use during compression
void *pSwapped = malloc(Size); // temporary buffer that we use during compression
mem_copy(pSwapped, pData, Size);
swap_endian(pSwapped, sizeof(int), Size/sizeof(int));
int Index = AddData(Size, pSwapped);
mem_free(pSwapped);
free(pSwapped);
return Index;
#else
return AddData(Size, pData);
Expand Down Expand Up @@ -741,9 +741,9 @@ int CDataFileWriter::Finish()

// free data
for(int i = 0; i < m_NumItems; i++)
mem_free(m_pItems[i].m_pData);
free(m_pItems[i].m_pData);
for(int i = 0; i < m_NumDatas; ++i)
mem_free(m_pDatas[i].m_pCompressedData);
free(m_pDatas[i].m_pCompressedData);

io_close(m_File);
m_File = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/engine/shared/demo.cpp
Expand Up @@ -497,7 +497,7 @@ void CDemoPlayer::ScanFile()
}

// copy all the frames to an array instead for fast access
m_pKeyFrames = (CKeyFrame*)mem_alloc(m_Info.m_SeekablePoints*sizeof(CKeyFrame), 1);
m_pKeyFrames = (CKeyFrame *)calloc(m_Info.m_SeekablePoints, sizeof(CKeyFrame));
for(pCurrentKey = pFirstKey, i = 0; pCurrentKey; pCurrentKey = pCurrentKey->m_pNext, i++)
m_pKeyFrames[i] = pCurrentKey->m_Frame;

Expand Down Expand Up @@ -715,7 +715,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
else if(MapSize > 0)
{
// get map data
unsigned char *pMapData = (unsigned char *)mem_alloc(MapSize, 1);
unsigned char *pMapData = (unsigned char *)malloc(MapSize);
io_read(m_File, pMapData, MapSize);

// save map
Expand All @@ -724,7 +724,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
io_close(MapFile);

// free data
mem_free(pMapData);
free(pMapData);
}

// store map inforation
Expand Down Expand Up @@ -891,7 +891,7 @@ int CDemoPlayer::Stop()
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", "Stopped playback");
io_close(m_File);
m_File = 0;
mem_free(m_pKeyFrames);
free(m_pKeyFrames);
m_pKeyFrames = 0;
str_copy(m_aFilename, "", sizeof(m_aFilename));
return 0;
Expand Down
11 changes: 0 additions & 11 deletions src/engine/shared/engine.cpp
Expand Up @@ -32,16 +32,6 @@ class CEngine : public IEngine
IStorage *m_pStorage;
bool m_Logging;

static void Con_DbgDumpmem(IConsole::IResult *pResult, void *pUserData)
{
CEngine *pEngine = static_cast<CEngine *>(pUserData);
char aBuf[32];
str_timestamp(aBuf, sizeof(aBuf));
char aFilename[128];
str_format(aFilename, sizeof(aFilename), "dumps/memory_%s.txt", aBuf);
mem_debug_dump(pEngine->m_pStorage->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE));
}

static void Con_DbgLognetwork(IConsole::IResult *pResult, void *pUserData)
{
CEngine *pEngine = static_cast<CEngine *>(pUserData);
Expand Down Expand Up @@ -97,7 +87,6 @@ class CEngine : public IEngine
if(!m_pConsole || !m_pStorage)
return;

m_pConsole->Register("dbg_dumpmem", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_DbgDumpmem, this, "Dump the memory");
m_pConsole->Register("dbg_lognetwork", "", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_DbgLognetwork, this, "Log the network");
}

Expand Down
6 changes: 3 additions & 3 deletions src/engine/shared/memheap.cpp
Expand Up @@ -10,11 +10,11 @@ void CHeap::NewChunk()
char *pMem;

// allocate memory
pMem = (char*)mem_alloc(sizeof(CChunk)+CHUNK_SIZE, 1);
pMem = (char *)malloc(sizeof(CChunk) + CHUNK_SIZE);
if(!pMem)
return;

// the chunk structure is located in the begining of the chunk
// the chunk structure is located in the beginning of the chunk
// init it and return the chunk
pChunk = (CChunk*)pMem;
pChunk->m_pMemory = (char*)(pChunk+1);
Expand Down Expand Up @@ -68,7 +68,7 @@ void CHeap::Clear()
while(pChunk)
{
pNext = pChunk->m_pNext;
mem_free(pChunk);
free(pChunk);
pChunk = pNext;
}

Expand Down
4 changes: 2 additions & 2 deletions src/engine/shared/network_conn.cpp
Expand Up @@ -128,7 +128,7 @@ int CNetConnection::QueueChunkEx(int Flags, int DataSize, const void *pData, int
m_Construct.m_NumChunks++;
m_Construct.m_DataSize = (int)(pChunkData-m_Construct.m_aChunkData);

// set packet flags aswell
// set packet flags as well

if(Flags&NET_CHUNKFLAG_VITAL && !(Flags&NET_CHUNKFLAG_RESEND))
{
Expand Down Expand Up @@ -443,7 +443,7 @@ int CNetConnection::Update()
}
}

// send keep alives if nothing has happend for 250ms
// send keep alives if nothing has happened for 250ms
if(State() == NET_CONNSTATE_ONLINE)
{
if(time_get()-m_LastSendTime > time_freq()/2) // flush connection after 500ms if needed
Expand Down
2 changes: 1 addition & 1 deletion src/engine/shared/protocol.h
Expand Up @@ -16,7 +16,7 @@
Client -> READY -> Server
The client has loaded the map and is ready to go,
but the mod needs to send it's information aswell.
but the mod needs to send it's information as well.
modc_connected is called on the client and
mods_connected is called on the server.
The client should call client_entergame when the
Expand Down