217 changes: 80 additions & 137 deletions src/game/editor/io.cpp
Expand Up @@ -305,16 +305,18 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
if(pImg->m_Format == CImageInfo::FORMAT_RGB)
{
// Convert to RGBA
unsigned char *pData = (unsigned char*) mem_alloc(Item.m_Width*Item.m_Height*4, 1);
unsigned char *pDataRGBA = (unsigned char *)mem_alloc(Item.m_Width*Item.m_Height*4, 1);
unsigned char *pDataRGB = (unsigned char *)pImg->m_pData;
for(int i = 0; i < Item.m_Width*Item.m_Height; i++)
{
pData[i*4] = ((unsigned char*)(pImg->m_pData))[i*3];
pData[i*4+1] = ((unsigned char*)(pImg->m_pData))[i*3+1];
pData[i*4+2] = ((unsigned char*)(pImg->m_pData))[i*3+2];
pData[i*4+3] = 255;

pDataRGBA[i*4] = pDataRGB[i*3];
pDataRGBA[i*4+1] = pDataRGB[i*3+1];
pDataRGBA[i*4+2] = pDataRGB[i*3+2];
pDataRGBA[i*4+3] = 255;
}
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*4, pData);
mem_free(pData);
Item.m_ImageData = df.AddData(Item.m_Width*Item.m_Height*4, pDataRGBA);
mem_free(pDataRGBA);
}
else
{
Expand Down Expand Up @@ -413,48 +415,27 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
Item.m_Flags = pLayer->m_Game ? TILESLAYERFLAG_GAME : 0;

Item.m_Image = pLayer->m_Image;
if(pLayer->m_Tele)
{
CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height];
mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles);
Item.m_Tele = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTeleTile), ((CLayerTele *)pLayer)->m_pTeleTile);
delete[] Tiles;
}
else if(pLayer->m_Speedup)
{
CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height];
mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles);
Item.m_Speedup = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CSpeedupTile), ((CLayerSpeedup *)pLayer)->m_pSpeedupTile);
delete[] Tiles;
}
else if(pLayer->m_Front)
{
CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height];
mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles);
Item.m_Front = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles);
delete[] Tiles;
}
else if(pLayer->m_Switch)
{
CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height];
mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles);
Item.m_Switch = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CSwitchTile), ((CLayerSwitch *)pLayer)->m_pSwitchTile);
delete[] Tiles;
}
else if(pLayer->m_Tune)

if (Item.m_Flags && !(pLayer->m_Game))
{
CTile *Tiles = new CTile[pLayer->m_Width*pLayer->m_Height];
mem_zero(Tiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), Tiles);
Item.m_Tune = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTuneTile), ((CLayerTune *)pLayer)->m_pTuneTile);
delete[] Tiles;
CTile *pEmptyTiles = (CTile*)mem_alloc(sizeof(CTile)*pLayer->m_Width*pLayer->m_Height, 1);
mem_zero(pEmptyTiles, pLayer->m_Width*pLayer->m_Height*sizeof(CTile));
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pEmptyTiles);
mem_free(pEmptyTiles);

if(pLayer->m_Tele)
Item.m_Tele = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTeleTile), ((CLayerTele *)pLayer)->m_pTeleTile);
else if(pLayer->m_Speedup)
Item.m_Speedup = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CSpeedupTile), ((CLayerSpeedup *)pLayer)->m_pSpeedupTile);
else if(pLayer->m_Front)
Item.m_Front = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles);
else if(pLayer->m_Switch)
Item.m_Switch = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CSwitchTile), ((CLayerSwitch *)pLayer)->m_pSwitchTile);
else if(pLayer->m_Tune)
Item.m_Tune = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTuneTile), ((CLayerTune *)pLayer)->m_pTuneTile);
}
else
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles);
Item.m_Data = df.AddData(pLayer->m_Width*pLayer->m_Height*sizeof(CTile), pLayer->m_pTiles);

// save layer name
StrToInts(Item.m_aName, sizeof(Item.m_aName)/sizeof(int), pLayer->m_aName);
Expand Down Expand Up @@ -652,7 +633,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
if(!(pItem->m_Settings > -1))
break;

int Size = DataFile.GetUncompressedDataSize(pItem->m_Settings);
const unsigned Size = DataFile.GetUncompressedDataSize(pItem->m_Settings);
char *pSettings = (char *)DataFile.GetData(pItem->m_Settings);
char *pNext = pSettings;
while(pNext < pSettings + Size)
Expand Down Expand Up @@ -900,30 +881,27 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
unsigned int Size = DataFile.GetUncompressedDataSize(pTilemapItem->m_Tele);
if (Size >= pTiles->m_Width*pTiles->m_Height*sizeof(CTeleTile))
{
mem_copy(((CLayerTele*)pTiles)->m_pTeleTile, pTeleData, pTiles->m_Width*pTiles->m_Height*sizeof(CTeleTile));
static const int s_aTilesRep[] = {
TILE_TELEIN,
TILE_TELEINEVIL,
TILE_TELEOUT,
TILE_TELECHECK,
TILE_TELECHECKIN,
TILE_TELECHECKINEVIL,
TILE_TELECHECKOUT,
TILE_TELEINWEAPON,
TILE_TELEINHOOK
};
mem_copy(((CLayerTele *)pTiles)->m_pTeleTile, pTeleData, pTiles->m_Width*pTiles->m_Height*sizeof(CTeleTile));

for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
{
if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELEIN)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEIN;
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELEINEVIL)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEINEVIL;
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELEOUT)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEOUT;
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELECHECK)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELECHECK;
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELECHECKIN)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELECHECKIN;
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELECHECKINEVIL)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELECHECKINEVIL;
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELECHECKOUT)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELECHECKOUT;
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELEINWEAPON)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEINWEAPON;
else if(((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_TELEINHOOK)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEINHOOK;
else
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = 0;
pTiles->m_pTiles[i].m_Index = 0;
for (unsigned e = 0; e < sizeof(s_aTilesRep) / sizeof(s_aTilesRep[0]); e++)
{
if (((CLayerTele *)pTiles)->m_pTeleTile[i].m_Type == s_aTilesRep[e])
pTiles->m_pTiles[i].m_Index = s_aTilesRep[e];
}
}
}
DataFile.UnloadData(pTilemapItem->m_Tele);
Expand All @@ -940,9 +918,9 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
{
if(((CLayerSpeedup*)pTiles)->m_pSpeedupTile[i].m_Force > 0)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_BOOST;
pTiles->m_pTiles[i].m_Index = TILE_BOOST;
else
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = 0;
pTiles->m_pTiles[i].m_Index = 0;
}
}

Expand All @@ -963,76 +941,40 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
unsigned int Size = DataFile.GetUncompressedDataSize(pTilemapItem->m_Switch);
if (Size >= pTiles->m_Width*pTiles->m_Height*sizeof(CSwitchTile))
{
mem_copy(((CLayerSwitch*)pTiles)->m_pSwitchTile, pSwitchData, pTiles->m_Width*pTiles->m_Height*sizeof(CSwitchTile));
const int s_aTilesComp[] = {
TILE_SWITCHTIMEDOPEN,
TILE_SWITCHTIMEDCLOSE,
TILE_SWITCHOPEN,
TILE_FREEZE,
TILE_DFREEZE,
TILE_DUNFREEZE,
TILE_HIT_START,
TILE_HIT_END,
TILE_JUMP,
TILE_PENALTY,
TILE_BONUS
};
CSwitchTile *pLayerSwitchTiles = ((CLayerSwitch *)pTiles)->m_pSwitchTile;
mem_copy(((CLayerSwitch *)pTiles)->m_pSwitchTile, pSwitchData, pTiles->m_Width*pTiles->m_Height*sizeof(CSwitchTile));

for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
{
if(((((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type > (ENTITY_CRAZY_SHOTGUN + ENTITY_OFFSET) && ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type < (ENTITY_DRAGGER_WEAK + ENTITY_OFFSET)) || ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == (ENTITY_LASER_O_FAST + 1 + ENTITY_OFFSET)))
if(((pLayerSwitchTiles[i].m_Type > (ENTITY_CRAZY_SHOTGUN + ENTITY_OFFSET) && ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type < (ENTITY_DRAGGER_WEAK + ENTITY_OFFSET)) || ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == (ENTITY_LASER_O_FAST + 1 + ENTITY_OFFSET)))
continue;
if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_SWITCHTIMEDOPEN)
else if(pLayerSwitchTiles[i].m_Type >= (ENTITY_ARMOR_1 + ENTITY_OFFSET) && pLayerSwitchTiles[i].m_Type <= (ENTITY_DOOR + ENTITY_OFFSET))
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_SWITCHTIMEDOPEN;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_SWITCHTIMEDCLOSE)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_SWITCHTIMEDCLOSE;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_SWITCHOPEN)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_SWITCHOPEN;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_SWITCHCLOSE)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_SWITCHCLOSE;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_FREEZE)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_FREEZE;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_DFREEZE)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_DFREEZE;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_DUNFREEZE)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_DUNFREEZE;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type >= (ENTITY_ARMOR_1 + ENTITY_OFFSET) && ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type <= (ENTITY_DOOR + ENTITY_OFFSET))
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_HIT_START)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_HIT_START;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_HIT_END)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_HIT_END;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_JUMP)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_JUMP;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_PENALTY)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_PENALTY;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
pTiles->m_pTiles[i].m_Index = pLayerSwitchTiles[i].m_Type;
pTiles->m_pTiles[i].m_Flags = pLayerSwitchTiles[i].m_Flags;
continue;
}
else if(((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Type == TILE_BONUS)

for (unsigned e = 0; e < sizeof(s_aTilesComp) / sizeof(s_aTilesComp[0]); e++)
{
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_BONUS;
((CLayerTiles*)pTiles)->m_pTiles[i].m_Flags = ((CLayerSwitch*)pTiles)->m_pSwitchTile[i].m_Flags;
if(pLayerSwitchTiles[i].m_Type == s_aTilesComp[e])
{
pTiles->m_pTiles[i].m_Index = s_aTilesComp[e];
pTiles->m_pTiles[i].m_Flags = pLayerSwitchTiles[i].m_Flags;
}
}
}
}
Expand All @@ -1044,14 +986,15 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
unsigned int Size = DataFile.GetUncompressedDataSize(pTilemapItem->m_Tune);
if (Size >= pTiles->m_Width*pTiles->m_Height*sizeof(CTuneTile))
{
mem_copy(((CLayerTune*)pTiles)->m_pTuneTile, pTuneData, pTiles->m_Width*pTiles->m_Height*sizeof(CTuneTile));
CTuneTile *pLayerTuneTiles = ((CLayerTune *)pTiles)->m_pTuneTile;
mem_copy(((CLayerTune *)pTiles)->m_pTuneTile, pTuneData, pTiles->m_Width*pTiles->m_Height*sizeof(CTuneTile));

for(int i = 0; i < pTiles->m_Width*pTiles->m_Height; i++)
{
if(((CLayerTune*)pTiles)->m_pTuneTile[i].m_Type == TILE_TUNE1)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TUNE1;
if(pLayerTuneTiles[i].m_Type == TILE_TUNE1)
pTiles->m_pTiles[i].m_Index = TILE_TUNE1;
else
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = 0;
pTiles->m_pTiles[i].m_Index = 0;
}
}
DataFile.UnloadData(pTilemapItem->m_Tune);
Expand Down
10 changes: 5 additions & 5 deletions src/game/editor/layer_quads.cpp
Expand Up @@ -150,15 +150,15 @@ void CLayerQuads::BrushPlace(CLayer *pBrush, float wx, float wy)

void Swap(CPoint& a, CPoint& b)
{
CPoint tmp;
tmp.x = a.x;
tmp.y = a.y;
CPoint Tmp;
Tmp.x = a.x;
Tmp.y = a.y;

a.x = b.x;
a.y = b.y;

b.x = tmp.x;
b.y = tmp.y;
b.x = Tmp.x;
b.y = Tmp.y;
}

void CLayerQuads::BrushFlipX()
Expand Down
12 changes: 6 additions & 6 deletions src/game/gamecore.cpp
Expand Up @@ -4,7 +4,7 @@

#include <engine/shared/config.h>
#include <engine/server/server.h>
const char *CTuningParams::m_apNames[] =
const char *CTuningParams::ms_apNames[] =
{
#define MACRO_TUNING_PARAM(Name,ScriptName,Value,Description) #ScriptName,
#include "tuning.h"
Expand All @@ -31,15 +31,15 @@ bool CTuningParams::Get(int Index, float *pValue)
bool CTuningParams::Set(const char *pName, float Value)
{
for(int i = 0; i < Num(); i++)
if(str_comp_nocase(pName, m_apNames[i]) == 0)
if(str_comp_nocase(pName, ms_apNames[i]) == 0)
return Set(i, Value);
return false;
}

bool CTuningParams::Get(const char *pName, float *pValue)
{
for(int i = 0; i < Num(); i++)
if(str_comp_nocase(pName, m_apNames[i]) == 0)
if(str_comp_nocase(pName, ms_apNames[i]) == 0)
return Get(i, pValue);

return false;
Expand All @@ -57,7 +57,7 @@ float VelocityRamp(float Value, float Start, float Range, float Curvature)
return 1.0f/powf(Curvature, (Value-Start)/Range);
}

void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore* pTeams)
void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams)
{
m_pWorld = pWorld;
m_pCollision = pCollision;
Expand All @@ -71,7 +71,7 @@ void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore
m_Jumps = 2;
}

void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore* pTeams, std::map<int, std::vector<vec2> > *pTeleOuts)
void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams, std::map<int, std::vector<vec2> > *pTeleOuts)
{
m_pWorld = pWorld;
m_pCollision = pCollision;
Expand Down Expand Up @@ -773,7 +773,7 @@ void SnapshotRemoveExtraInfo(unsigned char *pData)
CSnapshotItem *pItem = pSnap->GetItem(Index);
if(pItem->Type() == NETOBJTYPE_PROJECTILE)
{
CNetObj_Projectile* pProj = (CNetObj_Projectile*) ((void*)pItem->Data());
CNetObj_Projectile *pProj = (CNetObj_Projectile*) ((void*)pItem->Data());
if(UseExtraInfo(pProj))
{
vec2 Pos;
Expand Down
8 changes: 4 additions & 4 deletions src/game/gamecore.h
Expand Up @@ -40,7 +40,7 @@ class CTuningParams
#undef MACRO_TUNING_PARAM
}

static const char *m_apNames[];
static const char *ms_apNames[];

#define MACRO_TUNING_PARAM(Name,ScriptName,Value,Description) CTuneParam m_##Name;
#include "tuning.h"
Expand Down Expand Up @@ -211,8 +211,8 @@ class CCharacterCore

int m_TriggeredEvents;

void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore* pTeams);
void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore* pTeams, std::map<int, std::vector<vec2> > *pTeleOuts);
void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams);
void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams, std::map<int, std::vector<vec2> > *pTeleOuts);
void Reset();
void Tick(bool UseInput, bool IsClient);
void Move();
Expand All @@ -236,7 +236,7 @@ class CCharacterCore

private:

CTeamsCore* m_pTeams;
CTeamsCore *m_pTeams;
int m_TileIndex;
int m_TileFlags;
int m_TileFIndex;
Expand Down
197 changes: 122 additions & 75 deletions src/game/server/ddracechat.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/game/server/ddracechat.h
Expand Up @@ -31,6 +31,7 @@ CHAT_COMMAND("rank", "?r[playername]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConRank, thi
CHAT_COMMAND("rules", "", CFGFLAG_CHAT|CFGFLAG_SERVER, ConRules, this, "Shows the server rules")
CHAT_COMMAND("team", "?i[id]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConJoinTeam, this, "Lets you join team i (shows your team if left blank)")
CHAT_COMMAND("lock", "?i['0'|'1']", CFGFLAG_CHAT|CFGFLAG_SERVER, ConLockTeam, this, "Lock team so no-one else can join it")
CHAT_COMMAND("invite", "r[player name]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConInviteTeam, this, "Invite a person to a locked team")
CHAT_COMMAND("top5team", "?i[rank to start with]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTeamTop5, this, "Shows five team ranks of the ladder beginning with rank i (1 by default)")
CHAT_COMMAND("teamtop5", "?i[rank to start with]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTeamTop5, this, "Shows five team ranks of the ladder beginning with rank i (1 by default)")
CHAT_COMMAND("top5", "?i[rank to start with]", CFGFLAG_CHAT|CFGFLAG_SERVER, ConTop5, this, "Shows five ranks of the ladder beginning with rank i (1 by default)")
Expand Down
15 changes: 6 additions & 9 deletions src/game/server/ddracecommands.cpp
Expand Up @@ -302,16 +302,13 @@ void CGameContext::ConTeleport(IConsole::IResult *pResult, void *pUserData)
if (pResult->NumArguments() > 0)
Tele = pResult->GetVictim();

if (pSelf->m_apPlayers[TeleTo])
CCharacter* pChr = pSelf->GetPlayerChar(Tele);
if (pChr && pSelf->GetPlayerChar(TeleTo))
{
CCharacter* pChr = pSelf->GetPlayerChar(Tele);
if (pChr && pSelf->GetPlayerChar(TeleTo))
{
pChr->Core()->m_Pos = pSelf->m_apPlayers[TeleTo]->m_ViewPos;
pChr->m_Pos = pSelf->m_apPlayers[TeleTo]->m_ViewPos;
pChr->m_PrevPos = pSelf->m_apPlayers[TeleTo]->m_ViewPos;
pChr->m_DDRaceState = DDRACE_CHEAT;
}
pChr->Core()->m_Pos = pSelf->m_apPlayers[TeleTo]->m_ViewPos;
pChr->m_Pos = pSelf->m_apPlayers[TeleTo]->m_ViewPos;
pChr->m_PrevPos = pSelf->m_apPlayers[TeleTo]->m_ViewPos;
pChr->m_DDRaceState = DDRACE_CHEAT;
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/game/server/entities/door.cpp
Expand Up @@ -76,8 +76,8 @@ void CDoor::Snap(int SnappingClient)
if (!pObj)
return;

pObj->m_X = (int) m_Pos.x;
pObj->m_Y = (int) m_Pos.y;
pObj->m_X = (int)m_Pos.x;
pObj->m_Y = (int)m_Pos.y;

CCharacter * Char = GameServer()->GetPlayerChar(SnappingClient);
int Tick = (Server()->Tick() % Server()->TickSpeed()) % 11;
Expand All @@ -97,19 +97,19 @@ void CDoor::Snap(int SnappingClient)

if (Char->Team() == TEAM_SUPER)
{
pObj->m_FromX = (int) m_Pos.x;
pObj->m_FromY = (int) m_Pos.y;
pObj->m_FromX = (int)m_Pos.x;
pObj->m_FromY = (int)m_Pos.y;
}
else if (Char->IsAlive() && GameServer()->Collision()->m_NumSwitchers > 0
&& GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()])
{
pObj->m_FromX = (int) m_To.x;
pObj->m_FromY = (int) m_To.y;
pObj->m_FromX = (int)m_To.x;
pObj->m_FromY = (int)m_To.y;
}
else
{
pObj->m_FromX = (int) m_Pos.x;
pObj->m_FromY = (int) m_Pos.y;
pObj->m_FromX = (int)m_Pos.x;
pObj->m_FromY = (int)m_Pos.y;
}
pObj->m_StartTick = Server()->Tick();
}
12 changes: 6 additions & 6 deletions src/game/server/entities/dragger.cpp
Expand Up @@ -365,17 +365,17 @@ void CDragger::Snap(int SnappingClient)

if (!obj)
continue;
obj->m_X = (int) m_Pos.x;
obj->m_Y = (int) m_Pos.y;
obj->m_X = (int)m_Pos.x;
obj->m_Y = (int)m_Pos.y;
if (Target)
{
obj->m_FromX = (int) Target->m_Pos.x;
obj->m_FromY = (int) Target->m_Pos.y;
obj->m_FromX = (int)Target->m_Pos.x;
obj->m_FromY = (int)Target->m_Pos.y;
}
else
{
obj->m_FromX = (int) m_Pos.x;
obj->m_FromY = (int) m_Pos.y;
obj->m_FromX = (int)m_Pos.x;
obj->m_FromY = (int)m_Pos.y;
}

int StartTick = m_EvalTick;
Expand Down
20 changes: 10 additions & 10 deletions src/game/server/entities/light.cpp
Expand Up @@ -129,29 +129,29 @@ void CLight::Snap(int SnappingClient)
if (!pObj)
return;

pObj->m_X = (int) m_Pos.x;
pObj->m_Y = (int) m_Pos.y;
pObj->m_X = (int)m_Pos.x;
pObj->m_Y = (int)m_Pos.y;

if (Char && Char->Team() == TEAM_SUPER)
{
pObj->m_FromX = (int) m_Pos.x;
pObj->m_FromY = (int) m_Pos.y;
pObj->m_FromX = (int)m_Pos.x;
pObj->m_FromY = (int)m_Pos.y;
}
else if (Char && m_Layer == LAYER_SWITCH
&& GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()])
{
pObj->m_FromX = (int) m_To.x;
pObj->m_FromY = (int) m_To.y;
pObj->m_FromX = (int)m_To.x;
pObj->m_FromY = (int)m_To.y;
}
else if (m_Layer != LAYER_SWITCH)
{
pObj->m_FromX = (int) m_To.x;
pObj->m_FromY = (int) m_To.y;
pObj->m_FromX = (int)m_To.x;
pObj->m_FromY = (int)m_To.y;
}
else
{
pObj->m_FromX = (int) m_Pos.x;
pObj->m_FromY = (int) m_Pos.y;
pObj->m_FromX = (int)m_Pos.x;
pObj->m_FromY = (int)m_Pos.y;
}

int StartTick = m_EvalTick;
Expand Down
6 changes: 3 additions & 3 deletions src/game/server/entities/pickup.cpp
Expand Up @@ -54,7 +54,7 @@ void CPickup::Tick()
if(pChr && pChr->IsAlive())
{
if(m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[pChr->Team()]) continue;
bool sound = false;
bool Sound = false;
// player picked us up, is someone was hooking us, let them go
switch (m_Type)
{
Expand All @@ -72,14 +72,14 @@ void CPickup::Tick()
{
pChr->SetWeaponGot(i, false);
pChr->SetWeaponAmmo(i, 0);
sound = true;
Sound = true;
}
}
}
pChr->SetNinjaActivationDir(vec2(0,0));
pChr->SetNinjaActivationTick(-500);
pChr->SetNinjaCurrentMoveTime(0);
if (sound)
if (Sound)
{
pChr->SetLastWeapon(WEAPON_GUN);
GameServer()->CreateSound(m_Pos, SOUND_PICKUP_ARMOR, pChr->Teams()->TeamMask(pChr->Team()));
Expand Down
8 changes: 4 additions & 4 deletions src/game/server/entities/plasma.cpp
Expand Up @@ -119,9 +119,9 @@ void CPlasma::Snap(int SnappingClient)
if(!pObj)
return;

pObj->m_X = (int) m_Pos.x;
pObj->m_Y = (int) m_Pos.y;
pObj->m_FromX = (int) m_Pos.x;
pObj->m_FromY = (int) m_Pos.y;
pObj->m_X = (int)m_Pos.x;
pObj->m_Y = (int)m_Pos.y;
pObj->m_FromX = (int)m_Pos.x;
pObj->m_FromY = (int)m_Pos.y;
pObj->m_StartTick = m_EvalTick;
}
6 changes: 3 additions & 3 deletions src/game/server/entities/projectile.cpp
Expand Up @@ -126,7 +126,7 @@ void CProjectile::Tick()
m_LifeSpan--;

int64_t TeamMask = -1LL;
bool isWeaponCollide = false;
bool IsWeaponCollide = false;
if
(
pOwnerChar &&
Expand All @@ -136,7 +136,7 @@ void CProjectile::Tick()
!pTargetChr->CanCollide(m_Owner)
)
{
isWeaponCollide = true;
IsWeaponCollide = true;
//TeamMask = OwnerChar->Teams()->TeamMask( OwnerChar->Team());
}
if (pOwnerChar && pOwnerChar->IsAlive())
Expand All @@ -148,7 +148,7 @@ void CProjectile::Tick()
GameServer()->m_World.DestroyEntity(this);
}

if( ((pTargetChr && (pOwnerChar ? !(pOwnerChar->m_Hit&CCharacter::DISABLE_HIT_GRENADE) : g_Config.m_SvHit || m_Owner == -1 || pTargetChr == pOwnerChar)) || Collide || GameLayerClipped(CurPos)) && !isWeaponCollide)
if( ((pTargetChr && (pOwnerChar ? !(pOwnerChar->m_Hit&CCharacter::DISABLE_HIT_GRENADE) : g_Config.m_SvHit || m_Owner == -1 || pTargetChr == pOwnerChar)) || Collide || GameLayerClipped(CurPos)) && !IsWeaponCollide)
{
if(m_Explosive/*??*/ && (!pTargetChr || (pTargetChr && (!m_Freeze || (m_Weapon == WEAPON_SHOTGUN && Collide)))))
{
Expand Down
60 changes: 30 additions & 30 deletions src/game/server/gamecontext.cpp
Expand Up @@ -1503,7 +1503,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
}*/

//Kill Protection
CCharacter* pChr = pPlayer->GetCharacter();
CCharacter *pChr = pPlayer->GetCharacter();
if(pChr)
{
int CurrTime = (Server()->Tick() - pChr->m_StartTime) / Server()->TickSpeed();
Expand Down Expand Up @@ -1682,7 +1682,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
pPlayer->m_LastEmote = Server()->Tick();

SendEmoticon(ClientID, pMsg->m_Emoticon);
CCharacter* pChr = pPlayer->GetCharacter();
CCharacter *pChr = pPlayer->GetCharacter();
if(pChr && g_Config.m_SvEmotionalTees && pPlayer->m_EyeEmote)
{
switch(pMsg->m_Emoticon)
Expand Down Expand Up @@ -1732,7 +1732,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
if(pPlayer->m_Paused)
return;

CCharacter* pChr = pPlayer->GetCharacter();
CCharacter *pChr = pPlayer->GetCharacter();
if(!pChr)
return;

Expand Down Expand Up @@ -1829,7 +1829,7 @@ void CGameContext::ConTuneDump(IConsole::IResult *pResult, void *pUserData)
{
float v;
pSelf->Tuning()->Get(i, &v);
str_format(aBuf, sizeof(aBuf), "%s %.2f", pSelf->Tuning()->m_apNames[i], v);
str_format(aBuf, sizeof(aBuf), "%s %.2f", pSelf->Tuning()->ms_apNames[i], v);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf);
}
}
Expand Down Expand Up @@ -1866,7 +1866,7 @@ void CGameContext::ConTuneDumpZone(IConsole::IResult *pResult, void *pUserData)
{
float v;
pSelf->TuningList()[List].Get(i, &v);
str_format(aBuf, sizeof(aBuf), "zone %d: %s %.2f", List, pSelf->TuningList()[List].m_apNames[i], v);
str_format(aBuf, sizeof(aBuf), "zone %d: %s %.2f", List, pSelf->TuningList()[List].ms_apNames[i], v);
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "tuning", aBuf);
}
}
Expand Down Expand Up @@ -2946,7 +2946,7 @@ float CGameContext::PlayerJetpack()

void CGameContext::OnSetAuthed(int ClientID, int Level)
{
CServer* pServ = (CServer*)Server();
CServer *pServ = (CServer*)Server();
if(m_apPlayers[ClientID])
{
m_apPlayers[ClientID]->m_Authed = Level;
Expand Down Expand Up @@ -3008,7 +3008,7 @@ int CGameContext::ProcessSpamProtection(int ClientID)

int CGameContext::GetDDRaceTeam(int ClientID)
{
CGameControllerDDRace* pController = (CGameControllerDDRace*)m_pController;
CGameControllerDDRace *pController = (CGameControllerDDRace*)m_pController;
return pController->m_Teams.m_Core.Team(ClientID);
}

Expand Down Expand Up @@ -3198,43 +3198,43 @@ void CGameContext::Converse(int ClientID, char *pStr)
}
}

void CGameContext::List(int ClientID, const char* filter)
void CGameContext::List(int ClientID, const char *pFilter)
{
int total = 0;
char buf[256];
int bufcnt = 0;
if (filter[0])
str_format(buf, sizeof(buf), "Listing players with \"%s\" in name:", filter);
int Total = 0;
char aBuf[256];
int Bufcnt = 0;
if (pFilter[0])
str_format(aBuf, sizeof(aBuf), "Listing players with \"%s\" in name:", pFilter);
else
str_format(buf, sizeof(buf), "Listing all players:", filter);
SendChatTarget(ClientID, buf);
str_format(aBuf, sizeof(aBuf), "Listing all players:", pFilter);
SendChatTarget(ClientID, aBuf);
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(m_apPlayers[i])
{
total++;
const char* name = Server()->ClientName(i);
if (str_find_nocase(name, filter) == NULL)
Total++;
const char *pName = Server()->ClientName(i);
if (str_find_nocase(pName, pFilter) == NULL)
continue;
if (bufcnt + str_length(name) + 4 > 256)
if (Bufcnt + str_length(pName) + 4 > 256)
{
SendChatTarget(ClientID, buf);
bufcnt = 0;
SendChatTarget(ClientID, aBuf);
Bufcnt = 0;
}
if (bufcnt != 0)
if (Bufcnt != 0)
{
str_format(&buf[bufcnt], sizeof(buf) - bufcnt, ", %s", name);
bufcnt += 2 + str_length(name);
str_format(&aBuf[Bufcnt], sizeof(aBuf) - Bufcnt, ", %s", pName);
Bufcnt += 2 + str_length(pName);
}
else
{
str_format(&buf[bufcnt], sizeof(buf) - bufcnt, "%s", name);
bufcnt += str_length(name);
str_format(&aBuf[Bufcnt], sizeof(aBuf) - Bufcnt, "%s", pName);
Bufcnt += str_length(pName);
}
}
}
if (bufcnt != 0)
SendChatTarget(ClientID, buf);
str_format(buf, sizeof(buf), "%d players online", total);
SendChatTarget(ClientID, buf);
if (Bufcnt != 0)
SendChatTarget(ClientID, aBuf);
str_format(aBuf, sizeof(aBuf), "%d players online", Total);
SendChatTarget(ClientID, aBuf);
}
1 change: 1 addition & 0 deletions src/game/server/gamecontext.h
Expand Up @@ -298,6 +298,7 @@ class CGameContext : public IGameServer
static void ConBroadTime(IConsole::IResult *pResult, void *pUserData);
static void ConJoinTeam(IConsole::IResult *pResult, void *pUserData);
static void ConLockTeam(IConsole::IResult *pResult, void *pUserData);
static void ConInviteTeam(IConsole::IResult *pResult, void *pUserData);
static void ConMe(IConsole::IResult *pResult, void *pUserData);
static void ConWhisper(IConsole::IResult *pResult, void *pUserData);
static void ConConverse(IConsole::IResult *pResult, void *pUserData);
Expand Down
50 changes: 25 additions & 25 deletions src/game/server/gameworld.cpp
Expand Up @@ -159,25 +159,25 @@ void CGameWorld::UpdatePlayerMaps()
{
if (Server()->Tick() % g_Config.m_SvMapUpdateRate != 0) return;

std::pair<float,int> dist[MAX_CLIENTS];
std::pair<float,int> Dist[MAX_CLIENTS];
for (int i = 0; i < MAX_CLIENTS; i++)
{
if (!Server()->ClientIngame(i)) continue;
int* map = Server()->GetIdMap(i);
int *pMap = Server()->GetIdMap(i);

// compute distances
for (int j = 0; j < MAX_CLIENTS; j++)
{
dist[j].second = j;
Dist[j].second = j;
if (!Server()->ClientIngame(j) || !GameServer()->m_apPlayers[j])
{
dist[j].first = 1e10;
Dist[j].first = 1e10;
continue;
}
CCharacter* ch = GameServer()->m_apPlayers[j]->GetCharacter();
if (!ch)
{
dist[j].first = 1e9;
Dist[j].first = 1e9;
continue;
}
// copypasted chunk from character.cpp Snap() follows
Expand All @@ -192,15 +192,15 @@ void CGameWorld::UpdatePlayerMaps()
)
)
)
dist[j].first = 1e8;
Dist[j].first = 1e8;
else
dist[j].first = 0;
Dist[j].first = 0;

dist[j].first += distance(GameServer()->m_apPlayers[i]->m_ViewPos, GameServer()->m_apPlayers[j]->GetCharacter()->m_Pos);
Dist[j].first += distance(GameServer()->m_apPlayers[i]->m_ViewPos, GameServer()->m_apPlayers[j]->GetCharacter()->m_Pos);
}

// always send the player himself
dist[i].first = 0;
Dist[i].first = 0;

// compute reverse map
int rMap[MAX_CLIENTS];
Expand All @@ -210,32 +210,32 @@ void CGameWorld::UpdatePlayerMaps()
}
for (int j = 0; j < VANILLA_MAX_CLIENTS; j++)
{
if (map[j] == -1) continue;
if (dist[map[j]].first > 5e9) map[j] = -1;
else rMap[map[j]] = j;
if (pMap[j] == -1) continue;
if (Dist[pMap[j]].first > 5e9) pMap[j] = -1;
else rMap[pMap[j]] = j;
}

std::nth_element(&dist[0], &dist[VANILLA_MAX_CLIENTS - 1], &dist[MAX_CLIENTS], distCompare);
std::nth_element(&Dist[0], &Dist[VANILLA_MAX_CLIENTS - 1], &Dist[MAX_CLIENTS], distCompare);

int mapc = 0;
int demand = 0;
int Mapc = 0;
int Demand = 0;
for (int j = 0; j < VANILLA_MAX_CLIENTS - 1; j++)
{
int k = dist[j].second;
if (rMap[k] != -1 || dist[j].first > 5e9) continue;
while (mapc < VANILLA_MAX_CLIENTS && map[mapc] != -1) mapc++;
if (mapc < VANILLA_MAX_CLIENTS - 1)
map[mapc] = k;
int k = Dist[j].second;
if (rMap[k] != -1 || Dist[j].first > 5e9) continue;
while (Mapc < VANILLA_MAX_CLIENTS && pMap[Mapc] != -1) Mapc++;
if (Mapc < VANILLA_MAX_CLIENTS - 1)
pMap[Mapc] = k;
else
demand++;
Demand++;
}
for (int j = MAX_CLIENTS - 1; j > VANILLA_MAX_CLIENTS - 2; j--)
{
int k = dist[j].second;
if (rMap[k] != -1 && demand-- > 0)
map[rMap[k]] = -1;
int k = Dist[j].second;
if (rMap[k] != -1 && Demand-- > 0)
pMap[rMap[k]] = -1;
}
map[VANILLA_MAX_CLIENTS - 1] = -1; // player with empty name to say chat msgs
pMap[VANILLA_MAX_CLIENTS - 1] = -1; // player with empty name to say chat msgs
}
}

Expand Down
209 changes: 104 additions & 105 deletions src/game/server/save.cpp
Expand Up @@ -17,157 +17,156 @@ CSaveTee::~CSaveTee()
;
}

void CSaveTee::save(CCharacter* pchr)
void CSaveTee::save(CCharacter *pChr)
{
str_copy(m_name, pchr->m_pPlayer->Server()->ClientName(pchr->m_pPlayer->GetCID()), sizeof(m_name));
str_copy(m_name, pChr->m_pPlayer->Server()->ClientName(pChr->m_pPlayer->GetCID()), sizeof(m_name));

m_Alive = pchr->m_Alive;
m_Paused = pchr->m_pPlayer->m_Paused;
m_NeededFaketuning = pchr->m_NeededFaketuning;
m_Alive = pChr->m_Alive;
m_Paused = pChr->m_pPlayer->m_Paused;
m_NeededFaketuning = pChr->m_NeededFaketuning;

m_TeeFinished = pchr->Teams()->TeeFinished(pchr->m_pPlayer->GetCID());
m_IsSolo = pchr->Teams()->m_Core.GetSolo(pchr->m_pPlayer->GetCID());
m_TeeFinished = pChr->Teams()->TeeFinished(pChr->m_pPlayer->GetCID());
m_IsSolo = pChr->Teams()->m_Core.GetSolo(pChr->m_pPlayer->GetCID());

for(int i = 0; i< NUM_WEAPONS; i++)
{
m_aWeapons[i].m_AmmoRegenStart = pchr->m_aWeapons[i].m_AmmoRegenStart;
m_aWeapons[i].m_Ammo = pchr->m_aWeapons[i].m_Ammo;
m_aWeapons[i].m_Ammocost = pchr->m_aWeapons[i].m_Ammocost;
m_aWeapons[i].m_Got = pchr->m_aWeapons[i].m_Got;
m_aWeapons[i].m_AmmoRegenStart = pChr->m_aWeapons[i].m_AmmoRegenStart;
m_aWeapons[i].m_Ammo = pChr->m_aWeapons[i].m_Ammo;
m_aWeapons[i].m_Ammocost = pChr->m_aWeapons[i].m_Ammocost;
m_aWeapons[i].m_Got = pChr->m_aWeapons[i].m_Got;
}

m_LastWeapon = pchr->m_LastWeapon;
m_QueuedWeapon = pchr->m_QueuedWeapon;
m_LastWeapon = pChr->m_LastWeapon;
m_QueuedWeapon = pChr->m_QueuedWeapon;

m_SuperJump = pchr->m_SuperJump;
m_Jetpack = pchr->m_Jetpack;
m_NinjaJetpack = pchr->m_NinjaJetpack;
m_FreezeTime = pchr->m_FreezeTime;
m_FreezeTick = pchr->Server()->Tick() - pchr->m_FreezeTick;
m_SuperJump = pChr->m_SuperJump;
m_Jetpack = pChr->m_Jetpack;
m_NinjaJetpack = pChr->m_NinjaJetpack;
m_FreezeTime = pChr->m_FreezeTime;
m_FreezeTick = pChr->Server()->Tick() - pChr->m_FreezeTick;

m_DeepFreeze = pchr->m_DeepFreeze;
m_EndlessHook = pchr->m_EndlessHook;
m_DDRaceState = pchr->m_DDRaceState;
m_DeepFreeze = pChr->m_DeepFreeze;
m_EndlessHook = pChr->m_EndlessHook;
m_DDRaceState = pChr->m_DDRaceState;

m_Hit = pchr->m_Hit;
m_TuneZone = pchr->m_TuneZone;
m_TuneZoneOld = pchr->m_TuneZoneOld;
m_Hit = pChr->m_Hit;
m_TuneZone = pChr->m_TuneZone;
m_TuneZoneOld = pChr->m_TuneZoneOld;

if(pchr->m_StartTime)
m_Time = pchr->Server()->Tick() - pchr->m_StartTime + 60 * pchr->Server()->TickSpeed();
if(pChr->m_StartTime)
m_Time = pChr->Server()->Tick() - pChr->m_StartTime + 60 * pChr->Server()->TickSpeed();

m_Pos = pchr->m_Pos;
m_PrevPos = pchr->m_PrevPos;
m_TeleCheckpoint = pchr->m_TeleCheckpoint;
m_LastPenalty = pchr->m_LastPenalty;
m_Pos = pChr->m_Pos;
m_PrevPos = pChr->m_PrevPos;
m_TeleCheckpoint = pChr->m_TeleCheckpoint;
m_LastPenalty = pChr->m_LastPenalty;

if(pchr->m_CpTick)
m_CpTime = pchr->Server()->Tick() - pchr->m_CpTick;
if(pChr->m_CpTick)
m_CpTime = pChr->Server()->Tick() - pChr->m_CpTick;

m_CpActive = pchr->m_CpActive;
m_CpLastBroadcast = pchr->m_CpLastBroadcast;
m_CpActive = pChr->m_CpActive;
m_CpLastBroadcast = pChr->m_CpLastBroadcast;

for(int i = 0; i < 25; i++)
m_CpCurrent[i] = pchr->m_CpCurrent[i];
m_CpCurrent[i] = pChr->m_CpCurrent[i];

// Core
m_CorePos = pchr->m_Core.m_Pos;
m_Vel = pchr->m_Core.m_Vel;
m_Hook = pchr->m_Core.m_Hook;
m_Collision = pchr->m_Core.m_Collision;
m_ActiveWeapon = pchr->m_Core.m_ActiveWeapon;
m_Jumped = pchr->m_Core.m_Jumped;
m_JumpedTotal = pchr->m_Core.m_JumpedTotal;
m_Jumps = pchr->m_Core.m_Jumps;
m_HookPos = pchr->m_Core.m_HookPos;
m_HookDir = pchr->m_Core.m_HookDir;
m_HookTeleBase = pchr->m_Core.m_HookTeleBase;

m_HookTick = pchr->m_Core.m_HookTick;

m_HookState = pchr->m_Core.m_HookState;
m_CorePos = pChr->m_Core.m_Pos;
m_Vel = pChr->m_Core.m_Vel;
m_Hook = pChr->m_Core.m_Hook;
m_Collision = pChr->m_Core.m_Collision;
m_ActiveWeapon = pChr->m_Core.m_ActiveWeapon;
m_Jumped = pChr->m_Core.m_Jumped;
m_JumpedTotal = pChr->m_Core.m_JumpedTotal;
m_Jumps = pChr->m_Core.m_Jumps;
m_HookPos = pChr->m_Core.m_HookPos;
m_HookDir = pChr->m_Core.m_HookDir;
m_HookTeleBase = pChr->m_Core.m_HookTeleBase;

m_HookTick = pChr->m_Core.m_HookTick;

m_HookState = pChr->m_Core.m_HookState;
}

void CSaveTee::load(CCharacter* pchr, int Team)
void CSaveTee::load(CCharacter *pChr, int Team)
{
pchr->m_pPlayer->m_Paused = m_Paused;
pchr->m_pPlayer->ProcessPause();
pChr->m_pPlayer->m_Paused = m_Paused;
pChr->m_pPlayer->ProcessPause();

pchr->m_Alive = m_Alive;
pchr->m_NeededFaketuning = m_NeededFaketuning;
pChr->m_Alive = m_Alive;
pChr->m_NeededFaketuning = m_NeededFaketuning;

pchr->Teams()->SetForceCharacterTeam(pchr->m_pPlayer->GetCID(), Team);
pchr->Teams()->m_Core.SetSolo(pchr->m_pPlayer->GetCID(), m_IsSolo);
pchr->Teams()->SetFinished(pchr->m_pPlayer->GetCID(), m_TeeFinished);
pChr->Teams()->SetForceCharacterTeam(pChr->m_pPlayer->GetCID(), Team);
pChr->Teams()->m_Core.SetSolo(pChr->m_pPlayer->GetCID(), m_IsSolo);
pChr->Teams()->SetFinished(pChr->m_pPlayer->GetCID(), m_TeeFinished);

for(int i = 0; i< NUM_WEAPONS; i++)
{
pchr->m_aWeapons[i].m_AmmoRegenStart = m_aWeapons[i].m_AmmoRegenStart;
pchr->m_aWeapons[i].m_Ammo = m_aWeapons[i].m_Ammo;
pchr->m_aWeapons[i].m_Ammocost = m_aWeapons[i].m_Ammocost;
pchr->m_aWeapons[i].m_Got = m_aWeapons[i].m_Got;
pChr->m_aWeapons[i].m_AmmoRegenStart = m_aWeapons[i].m_AmmoRegenStart;
pChr->m_aWeapons[i].m_Ammo = m_aWeapons[i].m_Ammo;
pChr->m_aWeapons[i].m_Ammocost = m_aWeapons[i].m_Ammocost;
pChr->m_aWeapons[i].m_Got = m_aWeapons[i].m_Got;
}

pchr->m_LastWeapon = m_LastWeapon;
pchr->m_QueuedWeapon = m_QueuedWeapon;
pChr->m_LastWeapon = m_LastWeapon;
pChr->m_QueuedWeapon = m_QueuedWeapon;

pchr->m_SuperJump = m_SuperJump;
pchr->m_Jetpack = m_Jetpack;
pchr->m_NinjaJetpack = m_NinjaJetpack;
pchr->m_FreezeTime = m_FreezeTime;
pchr->m_FreezeTick = pchr->Server()->Tick() - m_FreezeTick;
pChr->m_SuperJump = m_SuperJump;
pChr->m_Jetpack = m_Jetpack;
pChr->m_NinjaJetpack = m_NinjaJetpack;
pChr->m_FreezeTime = m_FreezeTime;
pChr->m_FreezeTick = pChr->Server()->Tick() - m_FreezeTick;

pchr->m_DeepFreeze = m_DeepFreeze;
pchr->m_EndlessHook = m_EndlessHook;
pchr->m_DDRaceState = m_DDRaceState;
pChr->m_DeepFreeze = m_DeepFreeze;
pChr->m_EndlessHook = m_EndlessHook;
pChr->m_DDRaceState = m_DDRaceState;

pchr->m_Hit = m_Hit;
pchr->m_TuneZone = m_TuneZone;
pchr->m_TuneZoneOld = m_TuneZoneOld;
pChr->m_Hit = m_Hit;
pChr->m_TuneZone = m_TuneZone;
pChr->m_TuneZoneOld = m_TuneZoneOld;

if(m_Time)
pchr->m_StartTime = pchr->Server()->Tick() - m_Time;
pChr->m_StartTime = pChr->Server()->Tick() - m_Time;

pchr->m_Pos = m_Pos;
pchr->m_PrevPos = m_PrevPos;
pchr->m_TeleCheckpoint = m_TeleCheckpoint;
pchr->m_LastPenalty = m_LastPenalty;
pChr->m_Pos = m_Pos;
pChr->m_PrevPos = m_PrevPos;
pChr->m_TeleCheckpoint = m_TeleCheckpoint;
pChr->m_LastPenalty = m_LastPenalty;

if(m_CpTime)
pchr->m_CpTick = pchr->Server()->Tick() - m_CpTime;
pChr->m_CpTick = pChr->Server()->Tick() - m_CpTime;

pchr->m_CpActive = m_CpActive;
pchr->m_CpLastBroadcast = m_CpLastBroadcast;
pChr->m_CpActive = m_CpActive;
pChr->m_CpLastBroadcast = m_CpLastBroadcast;

for(int i = 0; i < 25; i++)
pchr->m_CpCurrent[i] = m_CpCurrent[i];
pChr->m_CpCurrent[i] = m_CpCurrent[i];

// Core
pchr->m_Core.m_Pos = m_CorePos;
pchr->m_Core.m_Vel = m_Vel;
pchr->m_Core.m_Hook = m_Hook;
pchr->m_Core.m_Collision = m_Collision;
pchr->m_Core.m_ActiveWeapon = m_ActiveWeapon;
pchr->m_Core.m_Jumped = m_Jumped;
pchr->m_Core.m_JumpedTotal = m_JumpedTotal;
pchr->m_Core.m_Jumps = m_Jumps;
pchr->m_Core.m_HookPos = m_HookPos;
pchr->m_Core.m_HookDir = m_HookDir;
pchr->m_Core.m_HookTeleBase = m_HookTeleBase;

pchr->m_Core.m_HookTick = m_HookTick;
pChr->m_Core.m_Pos = m_CorePos;
pChr->m_Core.m_Vel = m_Vel;
pChr->m_Core.m_Hook = m_Hook;
pChr->m_Core.m_Collision = m_Collision;
pChr->m_Core.m_ActiveWeapon = m_ActiveWeapon;
pChr->m_Core.m_JumpedTotal = m_JumpedTotal;
pChr->m_Core.m_Jumps = m_Jumps;
pChr->m_Core.m_HookPos = m_HookPos;
pChr->m_Core.m_HookDir = m_HookDir;
pChr->m_Core.m_HookTeleBase = m_HookTeleBase;

pChr->m_Core.m_HookTick = m_HookTick;

if(m_HookState == HOOK_GRABBED)
{
pchr->m_Core.m_HookState = HOOK_FLYING;
pchr->m_Core.m_HookedPlayer = -1;
pChr->m_Core.m_HookState = HOOK_FLYING;
pChr->m_Core.m_HookedPlayer = -1;
}
else
{
pchr->m_Core.m_HookState = m_HookState;
pChr->m_Core.m_HookState = m_HookState;
}

pchr->GameServer()->SendTuningParams(pchr->m_pPlayer->GetCID(), m_TuneZone);
pChr->GameServer()->SendTuningParams(pChr->m_pPlayer->GetCID(), m_TuneZone);
}

char* CSaveTee::GetString()
Expand Down Expand Up @@ -271,7 +270,7 @@ int CSaveTeam::load(int Team)
Teams->ChangeTeamState(Team, m_TeamState);
Teams->SetTeamLock(Team, m_TeamLocked);

CCharacter* pchr;
CCharacter *pChr;

for (int i = 0; i<m_MembersCount; i++)
{
Expand All @@ -288,10 +287,10 @@ int CSaveTeam::load(int Team)

for (int i = 0; i<m_MembersCount; i++)
{
pchr = MatchCharacter(SavedTees[i].GetName(), i);
if(pchr)
pChr = MatchCharacter(SavedTees[i].GetName(), i);
if(pChr)
{
SavedTees[i].load(pchr, Team);
SavedTees[i].load(pChr, Team);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/game/server/score.h
Expand Up @@ -52,19 +52,19 @@ class IScore
virtual void SaveTeamScore(int* ClientIDs, unsigned int Size, float Time) = 0;

virtual void ShowTop5(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut=1) = 0;
virtual void ShowRank(int ClientID, const char* pName, bool Search=false) = 0;
virtual void ShowRank(int ClientID, const char *pName, bool Search=false) = 0;

virtual void ShowTeamTop5(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut=1) = 0;
virtual void ShowTeamRank(int ClientID, const char* pName, bool Search=false) = 0;
virtual void ShowTeamRank(int ClientID, const char *pName, bool Search=false) = 0;

virtual void ShowTopPoints(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut=1) = 0;
virtual void ShowPoints(int ClientID, const char* pName, bool Search=false) = 0;
virtual void ShowPoints(int ClientID, const char *pName, bool Search=false) = 0;

virtual void RandomMap(int ClientID, int stars) = 0;
virtual void RandomUnfinishedMap(int ClientID, int stars) = 0;

virtual void SaveTeam(int Team, const char* Code, int ClientID, const char* Server) = 0;
virtual void LoadTeam(const char* Code, int ClientID) = 0;
virtual void SaveTeam(int Team, const char *pCode, int ClientID, const char *pServer) = 0;
virtual void LoadTeam(const char *pCode, int ClientID) = 0;

// called when the server is shut down but not on mapchange/reload
virtual void OnShutdown() = 0;
Expand Down
12 changes: 6 additions & 6 deletions src/game/server/score/file_score.cpp
Expand Up @@ -248,8 +248,8 @@ void CFileScore::ShowTop5(IConsole::IResult *pResult, int ClientID,
CPlayerScore *r = &m_Top[i + Debut - 1];
str_format(aBuf, sizeof(aBuf),
"%d. %s Time: %d minute(s) %5.2f second(s)", i + Debut,
r->m_aName, (int) r->m_Score / 60,
r->m_Score - ((int) r->m_Score / 60 * 60));
r->m_aName, (int)r->m_Score / 60,
r->m_Score - ((int)r->m_Score / 60 * 60));
pSelf->SendChatTarget(ClientID, aBuf);
}
pSelf->SendChatTarget(ClientID, "------------------------------");
Expand All @@ -274,13 +274,13 @@ void CFileScore::ShowRank(int ClientID, const char* pName, bool Search)
Server()->ClientName(ClientID));
if (g_Config.m_SvHideScore)
str_format(aBuf, sizeof(aBuf),
"Your time: %d minute(s) %5.2f second(s)", (int) Time / 60,
Time - ((int) Time / 60 * 60));
"Your time: %d minute(s) %5.2f second(s)", (int)Time / 60,
Time - ((int)Time / 60 * 60));
else
str_format(aBuf, sizeof(aBuf),
"%d. %s Time: %d minute(s) %5.2f second(s), requested by (%s)", Pos,
pScore->m_aName, (int) Time / 60,
Time - ((int) Time / 60 * 60), aClientName);
pScore->m_aName, (int)Time / 60,
Time - ((int)Time / 60 * 60), aClientName);
if (!Search)
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, ClientID);
else
Expand Down
61 changes: 35 additions & 26 deletions src/game/server/score/sql_score.cpp
Expand Up @@ -23,7 +23,7 @@ const char* CSqlData::ms_pMap = 0;
bool CSqlData::ms_GameContextAvailable = false;
int CSqlData::ms_Instance = 0;

int CSqlExecData::ms_InstanceCount = 0;
volatile int CSqlExecData::ms_InstanceCount = 0;

LOCK CSqlScore::ms_FailureFileLock = lock_create();

Expand Down Expand Up @@ -70,6 +70,11 @@ void CSqlScore::OnShutdown()
int i = 0;
while (CSqlExecData::ms_InstanceCount != 0)
{
if (i > 600) {
dbg_msg("sql", "Waited 60 seconds for score-threads to complete, quitting anyway");
break;
}

// print a log about every two seconds
if (i % 20 == 0)
dbg_msg("sql", "Waiting for score-threads to complete (%d left)", CSqlExecData::ms_InstanceCount);
Expand All @@ -88,20 +93,24 @@ void CSqlScore::ExecSqlFunc(void *pUser)

bool Success = false;

// try to connect to a working databaseserver
while (!Success && !connector.MaxTriesReached(pData->m_ReadOnly) && connector.ConnectSqlServer(pData->m_ReadOnly))
{
if (pData->m_pFuncPtr(connector.SqlServer(), pData->m_pSqlData, false))
Success = true;
try {
// try to connect to a working databaseserver
while (!Success && !connector.MaxTriesReached(pData->m_ReadOnly) && connector.ConnectSqlServer(pData->m_ReadOnly))
{
if (pData->m_pFuncPtr(connector.SqlServer(), pData->m_pSqlData, false))
Success = true;

// disconnect from databaseserver
connector.SqlServer()->Disconnect();
}
// disconnect from databaseserver
connector.SqlServer()->Disconnect();
}

// handle failures
// eg write inserts to a file and print a nice error message
if (!Success)
pData->m_pFuncPtr(0, pData->m_pSqlData, true);
// handle failures
// eg write inserts to a file and print a nice error message
if (!Success)
pData->m_pFuncPtr(0, pData->m_pSqlData, true);
} catch (...) {
dbg_msg("sql", "Unexpected exception caught");
}

delete pData->m_pSqlData;
delete pData;
Expand Down Expand Up @@ -223,11 +232,11 @@ bool CSqlScore::LoadScoreThread(CSqlServer* pSqlServer, const CSqlData *pGameDat
if(pSqlServer->GetResults()->next())
{
// get the best time
float time = (float)pSqlServer->GetResults()->getDouble("Time");
pData->PlayerData(pData->m_ClientID)->m_BestTime = time;
pData->PlayerData(pData->m_ClientID)->m_CurrentTime = time;
float Time = (float)pSqlServer->GetResults()->getDouble("Time");
pData->PlayerData(pData->m_ClientID)->m_BestTime = Time;
pData->PlayerData(pData->m_ClientID)->m_CurrentTime = Time;
if(pData->GameServer()->m_apPlayers[pData->m_ClientID])
pData->GameServer()->m_apPlayers[pData->m_ClientID]->m_Score = -time;
pData->GameServer()->m_apPlayers[pData->m_ClientID]->m_Score = -Time;

char aColumn[8];
if(g_Config.m_SvCheckpointSave)
Expand Down Expand Up @@ -403,7 +412,7 @@ bool CSqlScore::MapInfoThread(CSqlServer* pSqlServer, const CSqlData *pGameData,
char pReleasedString[60] = "\0";
if(stamp != 0)
{
sqlstr::agoTimeToString(ago, pAgoString);
sqlstr::AgoTimeToString(ago, pAgoString);
str_format(pReleasedString, sizeof(pReleasedString), ", released %s ago", pAgoString);
}

Expand Down Expand Up @@ -476,7 +485,7 @@ bool CSqlScore::SaveScoreThread(CSqlServer* pSqlServer, const CSqlData *pGameDat
dbg_msg("sql", "ERROR: Could not save Score, writing insert to a file now...");

char aTimestamp [20];
sqlstr::getTimeStamp(aTimestamp, sizeof(aTimestamp));
sqlstr::GetTimeStamp(aTimestamp, sizeof(aTimestamp));

char aBuf[768];
str_format(aBuf, sizeof(aBuf), "INSERT IGNORE INTO %%s_race(Map, Name, Timestamp, Time, Server, cp1, cp2, cp3, cp4, cp5, cp6, cp7, cp8, cp9, cp10, cp11, cp12, cp13, cp14, cp15, cp16, cp17, cp18, cp19, cp20, cp21, cp22, cp23, cp24, cp25) VALUES ('%s', '%s', '%s', '%.2f', '%s', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f');", pData->m_Map.ClrStr(), pData->m_Name.ClrStr(), aTimestamp, pData->m_Time, g_Config.m_SvSqlServerName, pData->m_aCpCurrent[0], pData->m_aCpCurrent[1], pData->m_aCpCurrent[2], pData->m_aCpCurrent[3], pData->m_aCpCurrent[4], pData->m_aCpCurrent[5], pData->m_aCpCurrent[6], pData->m_aCpCurrent[7], pData->m_aCpCurrent[8], pData->m_aCpCurrent[9], pData->m_aCpCurrent[10], pData->m_aCpCurrent[11], pData->m_aCpCurrent[12], pData->m_aCpCurrent[13], pData->m_aCpCurrent[14], pData->m_aCpCurrent[15], pData->m_aCpCurrent[16], pData->m_aCpCurrent[17], pData->m_aCpCurrent[18], pData->m_aCpCurrent[19], pData->m_aCpCurrent[20], pData->m_aCpCurrent[21], pData->m_aCpCurrent[22], pData->m_aCpCurrent[23], pData->m_aCpCurrent[24]);
Expand Down Expand Up @@ -577,7 +586,7 @@ bool CSqlScore::SaveTeamScoreThread(CSqlServer* pSqlServer, const CSqlData *pGam
io_write_newline(File);

char aTimestamp [20];
sqlstr::getTimeStamp(aTimestamp, sizeof(aTimestamp));
sqlstr::GetTimeStamp(aTimestamp, sizeof(aTimestamp));

char aBuf[2300];
for(unsigned int i = 0; i < pData->m_Size; i++)
Expand Down Expand Up @@ -1049,9 +1058,9 @@ bool CSqlScore::ShowTimesThread(CSqlServer* pSqlServer, const CSqlData *pGameDat
char aBuf[512];

if(pData->m_Search) // last 5 times of a player
str_format(aBuf, sizeof(aBuf), "SELECT Time, UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(Timestamp) as Ago, UNIX_TIMESTAMP(Timestamp) as Stamp FROM %s_race WHERE Map = '%s' AND Name = '%s' ORDER BY Ago ASC LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pData->m_Name.ClrStr(), pData->m_Num-1);
str_format(aBuf, sizeof(aBuf), "SELECT Time, UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(Timestamp) as Ago, UNIX_TIMESTAMP(Timestamp) as Stamp FROM %s_race WHERE Map = '%s' AND Name = '%s' ORDER BY Timestamp DESC LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pData->m_Name.ClrStr(), pData->m_Num-1);
else// last 5 times of server
str_format(aBuf, sizeof(aBuf), "SELECT Name, Time, UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(Timestamp) as Ago, UNIX_TIMESTAMP(Timestamp) as Stamp FROM %s_race WHERE Map = '%s' ORDER BY Ago ASC LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pData->m_Num-1);
str_format(aBuf, sizeof(aBuf), "SELECT Name, Time, UNIX_TIMESTAMP(CURRENT_TIMESTAMP)-UNIX_TIMESTAMP(Timestamp) as Ago, UNIX_TIMESTAMP(Timestamp) as Stamp FROM %s_race WHERE Map = '%s' ORDER BY Timestamp DESC LIMIT %d, 5;", pSqlServer->GetPrefix(), pData->m_Map.ClrStr(), pData->m_Num-1);

pSqlServer->executeSqlQuery(aBuf);

Expand All @@ -1076,7 +1085,7 @@ bool CSqlScore::ShowTimesThread(CSqlServer* pSqlServer, const CSqlData *pGameDat
pStamp = (int)pSqlServer->GetResults()->getInt("Stamp");
pTime = (float)pSqlServer->GetResults()->getDouble("Time");

sqlstr::agoTimeToString(pSince,pAgoString);
sqlstr::AgoTimeToString(pSince,pAgoString);

if(pData->m_Search) // last 5 times of a player
{
Expand Down Expand Up @@ -1512,13 +1521,13 @@ bool CSqlScore::LoadTeamThread(CSqlServer* pSqlServer, const CSqlData *pGameData
else
{

bool found = false;
bool Found = false;
for (int i = 0; i < SavedTeam.GetMembersCount(); i++)
{
if(str_comp(SavedTeam.SavedTees[i].GetName(), pData->Server()->ClientName(pData->m_ClientID)) == 0)
{ found = true; break; }
{ Found = true; break; }
}
if (!found)
if (!Found)
pData->GameServer()->SendChatTarget(pData->m_ClientID, "You don't belong to this team");
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/server/score/sql_score.h
Expand Up @@ -74,7 +74,7 @@ struct CSqlExecData
bool m_ReadOnly;

// keeps track of score-threads
static int ms_InstanceCount;
volatile static int ms_InstanceCount;
};

struct CSqlPlayerData : CSqlData
Expand Down
88 changes: 56 additions & 32 deletions src/game/server/teams.cpp
Expand Up @@ -20,6 +20,7 @@ void CGameTeams::Reset()
m_LastChat[i] = 0;
m_TeamLocked[i] = false;
m_IsSaving[i] = false;
m_Invited[i] = 0;
}
}

Expand Down Expand Up @@ -414,9 +415,9 @@ float *CGameTeams::GetCpCurrent(CPlayer* Player)

void CGameTeams::OnTeamFinish(CPlayer** Players, unsigned int Size)
{
float time = (float) (Server()->Tick() - GetStartTime(Players[0]))
/ ((float) Server()->TickSpeed());
if (time < 0.000001f)
float Time = (float)(Server()->Tick() - GetStartTime(Players[0]))
/ ((float)Server()->TickSpeed());
if (Time < 0.000001f)
return;

bool CallSaveScore = false;
Expand All @@ -442,43 +443,43 @@ void CGameTeams::OnTeamFinish(CPlayer** Players, unsigned int Size)
}

if (CallSaveScore && Size >= 2)
GameServer()->Score()->SaveTeamScore(PlayerCIDs, Size, time);
GameServer()->Score()->SaveTeamScore(PlayerCIDs, Size, Time);
}

void CGameTeams::OnFinish(CPlayer* Player)
{
if (!Player || !Player->IsPlaying())
return;
//TODO:DDRace:btd: this ugly
float time = (float) (Server()->Tick() - GetStartTime(Player))
/ ((float) Server()->TickSpeed());
if (time < 0.000001f)
float Time = (float)(Server()->Tick() - GetStartTime(Player))
/ ((float)Server()->TickSpeed());
if (Time < 0.000001f)
return;
CPlayerData *pData = GameServer()->Score()->PlayerData(Player->GetCID());
char aBuf[128];
SetCpActive(Player, -2);
str_format(aBuf, sizeof(aBuf),
"%s finished in: %d minute(s) %5.2f second(s)",
Server()->ClientName(Player->GetCID()), (int) time / 60,
time - ((int) time / 60 * 60));
Server()->ClientName(Player->GetCID()), (int)Time / 60,
Time - ((int)Time / 60 * 60));
if (g_Config.m_SvHideScore || !g_Config.m_SvSaveWorseScores)
GameServer()->SendChatTarget(Player->GetCID(), aBuf);
else
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf);

float diff = fabs(time - pData->m_BestTime);
float Diff = fabs(Time - pData->m_BestTime);

if (time - pData->m_BestTime < 0)
if (Time - pData->m_BestTime < 0)
{
// new record \o/
Server()->SaveDemo(Player->GetCID(), time);
Server()->SaveDemo(Player->GetCID(), Time);

if (diff >= 60)
if (Diff >= 60)
str_format(aBuf, sizeof(aBuf), "New record: %d minute(s) %5.2f second(s) better.",
(int) diff / 60, diff - ((int) diff / 60 * 60));
(int)Diff / 60, Diff - ((int)Diff / 60 * 60));
else
str_format(aBuf, sizeof(aBuf), "New record: %5.2f second(s) better.",
diff);
Diff);
if (g_Config.m_SvHideScore || !g_Config.m_SvSaveWorseScores)
GameServer()->SendChatTarget(Player->GetCID(), aBuf);
else
Expand All @@ -488,66 +489,66 @@ void CGameTeams::OnFinish(CPlayer* Player)
{
Server()->StopRecord(Player->GetCID());

if (diff <= 0.005)
if (Diff <= 0.005)
{
GameServer()->SendChatTarget(Player->GetCID(),
"You finished with your best time.");
}
else
{
if (diff >= 60)
if (Diff >= 60)
str_format(aBuf, sizeof(aBuf), "%d minute(s) %5.2f second(s) worse, better luck next time.",
(int) diff / 60, diff - ((int) diff / 60 * 60));
(int)Diff / 60, Diff - ((int)Diff / 60 * 60));
else
str_format(aBuf, sizeof(aBuf),
"%5.2f second(s) worse, better luck next time.",
diff);
Diff);
GameServer()->SendChatTarget(Player->GetCID(), aBuf); //this is private, sent only to the tee
}
}
else
{
Server()->SaveDemo(Player->GetCID(), time);
Server()->SaveDemo(Player->GetCID(), Time);
}

bool CallSaveScore = false;
#if defined(CONF_SQL)
CallSaveScore = g_Config.m_SvUseSQL && g_Config.m_SvSaveWorseScores;
#endif

if (!pData->m_BestTime || time < pData->m_BestTime)
if (!pData->m_BestTime || Time < pData->m_BestTime)
{
// update the score
pData->Set(time, GetCpCurrent(Player));
pData->Set(Time, GetCpCurrent(Player));
CallSaveScore = true;
}

if (CallSaveScore)
if (g_Config.m_SvNamelessScore || str_comp_num(Server()->ClientName(Player->GetCID()), "nameless tee",
12) != 0)
GameServer()->Score()->SaveScore(Player->GetCID(), time,
GameServer()->Score()->SaveScore(Player->GetCID(), Time,
GetCpCurrent(Player));

bool NeedToSendNewRecord = false;
// update server best time
if (GameServer()->m_pController->m_CurrentRecord == 0
|| time < GameServer()->m_pController->m_CurrentRecord)
|| Time < GameServer()->m_pController->m_CurrentRecord)
{
// check for nameless
if (g_Config.m_SvNamelessScore || str_comp_num(Server()->ClientName(Player->GetCID()), "nameless tee",
12) != 0)
{
GameServer()->m_pController->m_CurrentRecord = time;
GameServer()->m_pController->m_CurrentRecord = Time;
//dbg_msg("character", "Finish");
NeedToSendNewRecord = true;
}
}

SetDDRaceState(Player, DDRACE_FINISHED);
// set player score
if (!pData->m_CurrentTime || pData->m_CurrentTime > time)
if (!pData->m_CurrentTime || pData->m_CurrentTime > Time)
{
pData->m_CurrentTime = time;
pData->m_CurrentTime = Time;
NeedToSendNewRecord = true;
for (int i = 0; i < MAX_CLIENTS; i++)
{
Expand All @@ -556,7 +557,7 @@ void CGameTeams::OnFinish(CPlayer* Player)
if (!g_Config.m_SvHideScore || i == Player->GetCID())
{
CNetMsg_Sv_PlayerTime Msg;
Msg.m_Time = time * 100.0;
Msg.m_Time = Time * 100.0;
Msg.m_ClientID = Player->GetCID();
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, i);
}
Expand All @@ -579,20 +580,20 @@ void CGameTeams::OnFinish(CPlayer* Player)
if (Player->m_ClientVersion >= VERSION_DDRACE)
{
CNetMsg_Sv_DDRaceTime Msg;
Msg.m_Time = (int) (time * 100.0f);
Msg.m_Time = (int)(Time * 100.0f);
Msg.m_Check = 0;
Msg.m_Finish = 1;

if (pData->m_BestTime)
{
float Diff = (time - pData->m_BestTime) * 100;
Msg.m_Check = (int) Diff;
float Diff = (Time - pData->m_BestTime) * 100;
Msg.m_Check = (int)Diff;
}

Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, Player->GetCID());
}

int TTime = 0 - (int) time;
int TTime = 0 - (int)Time;
if (Player->m_Score < TTime)
Player->m_Score = TTime;

Expand Down Expand Up @@ -646,7 +647,30 @@ void CGameTeams::OnCharacterDeath(int ClientID, int Weapon)
void CGameTeams::SetTeamLock(int Team, bool Lock)
{
if(Team > TEAM_FLOCK && Team < TEAM_SUPER)
{
if(!m_TeamLocked[Team] && Lock)
ResetInvited(Team);
m_TeamLocked[Team] = Lock;
}
}

void CGameTeams::ResetInvited(int Team)
{
m_Invited[Team] = 0;
for (int i = 0; i < MAX_CLIENTS; i++)
if(m_Core.Team(i) == Team && GameServer()->m_apPlayers[i])
m_Invited[Team] |= 1ULL << i;
}

void CGameTeams::SetClientInvited(int Team, int ClientID, bool Invited)
{
if(Team > TEAM_FLOCK && Team < TEAM_SUPER)
{
if(Invited)
m_Invited[Team] |= 1ULL << ClientID;
else
m_Invited[Team] &= ~(1ULL << ClientID);
}
}

void CGameTeams::KillSavedTeam(int Team)
Expand Down
8 changes: 8 additions & 0 deletions src/game/server/teams.h
Expand Up @@ -12,6 +12,7 @@ class CGameTeams
bool m_TeeFinished[MAX_CLIENTS];
bool m_TeamLocked[MAX_CLIENTS];
bool m_IsSaving[MAX_CLIENTS];
uint64_t m_Invited[MAX_CLIENTS];

class CGameContext * m_pGameContext;

Expand Down Expand Up @@ -69,6 +70,8 @@ class CGameTeams

void SendTeamsState(int Cid);
void SetTeamLock(int Team, bool Lock);
void ResetInvited(int Team);
void SetClientInvited(int Team, int ClientID, bool Invited);

int m_LastChat[MAX_CLIENTS];

Expand Down Expand Up @@ -101,6 +104,11 @@ class CGameTeams
return m_TeamLocked[Team];
}

bool IsInvited(int Team, int ClientID)
{
return m_Invited[Team] & 1LL << ClientID;
}

void SetFinished(int ClientID, bool finished)
{
m_TeeFinished[ClientID] = finished;
Expand Down
6 changes: 3 additions & 3 deletions src/game/version.h
Expand Up @@ -3,8 +3,8 @@
#ifndef GAME_VERSION_H
#define GAME_VERSION_H
#include "generated/nethash.cpp"
#define GAME_VERSION "0.6.3, 10.4.3"
#define GAME_VERSION "0.6.3, 10.5"
#define GAME_NETVERSION "0.6 626fce9a778df4d4"
static const char GAME_RELEASE_VERSION[8] = "10.4.3";
#define CLIENT_VERSIONNR 10043
static const char GAME_RELEASE_VERSION[8] = "10.5";
#define CLIENT_VERSIONNR 10050
#endif
16 changes: 14 additions & 2 deletions src/mastersrv/mastersrv.h
Expand Up @@ -28,8 +28,11 @@ static const unsigned char SERVERBROWSE_COUNT[] = {255, 255, 255, 255, 's', 'i',
static const unsigned char SERVERBROWSE_GETINFO[] = {255, 255, 255, 255, 'g', 'i', 'e', '3'};
static const unsigned char SERVERBROWSE_INFO[] = {255, 255, 255, 255, 'i', 'n', 'f', '3'};

static const unsigned char SERVERBROWSE_GETINFO64[] = {255, 255, 255, 255, 'f', 's', 't', 'd'};
static const unsigned char SERVERBROWSE_INFO64[] = {255, 255, 255, 255, 'd', 't', 's', 'f'};
static const unsigned char SERVERBROWSE_GETINFO_64_LEGACY[] = {255, 255, 255, 255, 'f', 's', 't', 'd'};
static const unsigned char SERVERBROWSE_INFO_64_LEGACY[] = {255, 255, 255, 255, 'd', 't', 's', 'f'};

static const unsigned char SERVERBROWSE_INFO_EXTENDED[] = {255, 255, 255, 255, 'i', 'e', 'x', 't'};
static const unsigned char SERVERBROWSE_INFO_EXTENDED_MORE[] = {255, 255, 255, 255, 'i', 'e', 'x', '+'};

static const unsigned char SERVERBROWSE_FWCHECK[] = {255, 255, 255, 255, 'f', 'w', '?', '?'};
static const unsigned char SERVERBROWSE_FWRESPONSE[] = {255, 255, 255, 255, 'f', 'w', '!', '!'};
Expand All @@ -52,4 +55,13 @@ static const unsigned char SERVERBROWSE_LIST_LEGACY[] = {255, 255, 255, 255, 'l'

static const unsigned char SERVERBROWSE_GETCOUNT_LEGACY[] = {255, 255, 255, 255, 'c', 'o', 'u', 'n'};
static const unsigned char SERVERBROWSE_COUNT_LEGACY[] = {255, 255, 255, 255, 's', 'i', 'z', 'e'};

enum
{
SERVERINFO_VANILLA=0,
SERVERINFO_64_LEGACY,
SERVERINFO_EXTENDED,
SERVERINFO_EXTENDED_MORE,
SERVERINFO_INGAME,
};
#endif
10 changes: 5 additions & 5 deletions src/tools/fake_server.cpp
Expand Up @@ -29,19 +29,19 @@ int aInfoMsgSize;

static void SendHeartBeats()
{
static unsigned char aData[sizeof(SERVERBROWSE_HEARTBEAT) + 2];
static unsigned char s_aData[sizeof(SERVERBROWSE_HEARTBEAT) + 2];
CNetChunk Packet;

mem_copy(aData, SERVERBROWSE_HEARTBEAT, sizeof(SERVERBROWSE_HEARTBEAT));
mem_copy(s_aData, SERVERBROWSE_HEARTBEAT, sizeof(SERVERBROWSE_HEARTBEAT));

Packet.m_ClientID = -1;
Packet.m_Flags = NETSENDFLAG_CONNLESS;
Packet.m_DataSize = sizeof(SERVERBROWSE_HEARTBEAT) + 2;
Packet.m_pData = &aData;
Packet.m_pData = &s_aData;

/* supply the set port that the master can use if it has problems */
aData[sizeof(SERVERBROWSE_HEARTBEAT)] = 0;
aData[sizeof(SERVERBROWSE_HEARTBEAT)+1] = 0;
s_aData[sizeof(SERVERBROWSE_HEARTBEAT)] = 0;
s_aData[sizeof(SERVERBROWSE_HEARTBEAT)+1] = 0;

for(int i = 0; i < NumMasters; i++)
{
Expand Down