summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-01 22:57:08 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-11-01 22:57:08 +0100
commitb5b920dedaa62302795b0b8f3db84a0650d236e0 (patch)
treef46d1ec70d6519fff2a75f45c08fe37bf4b5538c /source
parentforogt to update all of cPlayer.cpp for player based gamemode. (diff)
downloadcuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.gz
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.bz2
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.lz
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.xz
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.tar.zst
cuberite-b5b920dedaa62302795b0b8f3db84a0650d236e0.zip
Diffstat (limited to '')
-rw-r--r--source/Bindings.cpp263
-rw-r--r--source/Bindings.h2
-rw-r--r--source/cChunkMap.cpp20
-rw-r--r--source/cClientHandle.cpp95
-rw-r--r--source/cClientHandle.h1
-rw-r--r--source/cEntity.cpp2
-rw-r--r--source/cFileFormatUpdater.cpp2
-rw-r--r--source/cPickup.cpp2
-rw-r--r--source/cPlayer.cpp38
-rw-r--r--source/cPlayer.h2
-rw-r--r--source/cRoot.cpp82
-rw-r--r--source/cRoot.h13
-rw-r--r--source/cServer.cpp38
-rw-r--r--source/cWorld.cpp68
-rw-r--r--source/cWorld.h11
-rw-r--r--source/main.cpp2
16 files changed, 476 insertions, 165 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 690d7af7f..330582dea 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 10/31/11 01:51:08.
+** Generated automatically by tolua++-1.0.92 on 11/01/11 22:50:07.
*/
#ifndef __cplusplus
@@ -161,6 +161,7 @@ static void tolua_reg_types (lua_State* tolua_S)
tolua_usertype(tolua_S,"TakeDamageInfo");
tolua_usertype(tolua_S,"cPlugin");
tolua_usertype(tolua_S,"cStringMap");
+ tolua_usertype(tolua_S,"Json::Value");
tolua_usertype(tolua_S,"cServer");
tolua_usertype(tolua_S,"cRoot");
tolua_usertype(tolua_S,"cPlugin::CommandStruct");
@@ -187,16 +188,16 @@ static void tolua_reg_types (lua_State* tolua_S)
tolua_usertype(tolua_S,"cWebAdmin");
tolua_usertype(tolua_S,"Vector3i");
tolua_usertype(tolua_S,"cBlockEntity");
- tolua_usertype(tolua_S,"cWorld");
+ tolua_usertype(tolua_S,"cWebPlugin");
tolua_usertype(tolua_S,"Lua__cTCPLink");
tolua_usertype(tolua_S,"Lua__cPlugin");
tolua_usertype(tolua_S,"cTCPLink");
tolua_usertype(tolua_S,"cPacket_BlockPlace");
tolua_usertype(tolua_S,"cLadder");
tolua_usertype(tolua_S,"cGroupManager");
- tolua_usertype(tolua_S,"cPluginManager");
+ tolua_usertype(tolua_S,"cWorld");
tolua_usertype(tolua_S,"cIniFile");
- tolua_usertype(tolua_S,"cWebPlugin");
+ tolua_usertype(tolua_S,"cPluginManager");
tolua_usertype(tolua_S,"HTTPRequest");
tolua_usertype(tolua_S,"cPawn");
tolua_usertype(tolua_S,"cPlayer");
@@ -4827,6 +4828,39 @@ static int tolua_AllToLua_Lua__cPawn_cPawn__KilledBy00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: Initialize of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_Initialize00
+static int tolua_AllToLua_cPlayer_Initialize00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cWorld",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
+ cWorld* a_World = ((cWorld*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Initialize'", NULL);
+#endif
+ {
+ self->Initialize(a_World);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Initialize'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: GetEyeHeight of class cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_GetEyeHeight00
static int tolua_AllToLua_cPlayer_GetEyeHeight00(lua_State* tolua_S)
@@ -5629,6 +5663,14 @@ static int tolua_AllToLua_cPlayer_IsVisible00(lua_State* tolua_S)
class Lua__cPlayer : public cPlayer, public ToluaBase {
public:
+ void Initialize( cWorld* a_World) {
+ if (push_method("Initialize", tolua_AllToLua_cPlayer_Initialize00)) {
+ tolua_pushusertype(lua_state, (void*)a_World, "cWorld");
+ ToluaBase::dbcall(lua_state, 2, 0);
+ } else {
+ return ( void ) cPlayer:: Initialize(a_World);
+ };
+ };
void TeleportTo( cEntity* a_Entity) {
if (push_method("TeleportTo", tolua_AllToLua_cPlayer_TeleportTo00)) {
tolua_pushusertype(lua_state, (void*)a_Entity, "cEntity");
@@ -5672,14 +5714,6 @@ public:
return ( void ) cPlayer:: KilledBy(a_Killer);
};
};
- void Initialize( cWorld* a_World) {
- if (push_method("Initialize", tolua_AllToLua_cEntity_Initialize00)) {
- tolua_pushusertype(lua_state, (void*)a_World, "cWorld");
- ToluaBase::dbcall(lua_state, 2, 0);
- } else {
- return ( void ) cPlayer:: Initialize(a_World);
- };
- };
unsigned int GetEntityType( void ) {
if (push_method("GetEntityType", tolua_AllToLua_cEntity_GetEntityType00)) {
ToluaBase::dbcall(lua_state, 1, 1);
@@ -5740,6 +5774,9 @@ public:
};
};
+ void cPlayer__Initialize( cWorld* a_World) {
+ return ( void )cPlayer::Initialize(a_World);
+ };
void cPlayer__TeleportTo( cEntity* a_Entity) {
return ( void )cPlayer::TeleportTo(a_Entity);
};
@@ -5755,9 +5792,6 @@ public:
void cPlayer__KilledBy( cEntity* a_Killer) {
return ( void )cPlayer::KilledBy(a_Killer);
};
- void cPlayer__Initialize( cWorld* a_World) {
- return ( void )cPlayer::Initialize(a_World);
- };
unsigned int cPlayer__GetEntityType( void ) {
return (unsigned int )cPlayer::GetEntityType();
};
@@ -5802,6 +5836,39 @@ static int tolua_AllToLua_Lua__cPlayer_tolua__set_instance00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: cPlayer__Initialize of class Lua__cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlayer_cPlayer__Initialize00
+static int tolua_AllToLua_Lua__cPlayer_cPlayer__Initialize00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cWorld",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlayer* self = (Lua__cPlayer*) tolua_tousertype(tolua_S,1,0);
+ cWorld* a_World = ((cWorld*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlayer__Initialize'", NULL);
+#endif
+ {
+ self->cPlayer__Initialize(a_World);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlayer__Initialize'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: cPlayer__TeleportTo of class Lua__cPlayer */
#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo00
static int tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo00(lua_State* tolua_S)
@@ -8583,6 +8650,38 @@ static int tolua_AllToLua_cWorld_GetWorldSeed00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: GetName of class cWorld */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cWorld_GetName00
+static int tolua_AllToLua_cWorld_GetName00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetName'", NULL);
+#endif
+ {
+ const char* tolua_ret = (const char*) self->GetName();
+ tolua_pushstring(tolua_S,(const char*)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetName'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: Clear of class cInventory */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cInventory_Clear00
static int tolua_AllToLua_cInventory_Clear00(lua_State* tolua_S)
@@ -9014,6 +9113,72 @@ static int tolua_AllToLua_cItem_Equals00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: GetJson of class cItem */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_GetJson00
+static int tolua_AllToLua_cItem_GetJson00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cItem",0,&tolua_err) ||
+ (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"Json::Value",0,&tolua_err)) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cItem* self = (cItem*) tolua_tousertype(tolua_S,1,0);
+ Json::Value* a_OutValue = ((Json::Value*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetJson'", NULL);
+#endif
+ {
+ self->GetJson(*a_OutValue);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetJson'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: FromJson of class cItem */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_FromJson00
+static int tolua_AllToLua_cItem_FromJson00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cItem",0,&tolua_err) ||
+ (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const Json::Value",0,&tolua_err)) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cItem* self = (cItem*) tolua_tousertype(tolua_S,1,0);
+ const Json::Value* a_Value = ((const Json::Value*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'FromJson'", NULL);
+#endif
+ {
+ self->FromJson(*a_Value);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'FromJson'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* get function: m_ItemID of class cItem */
#ifndef TOLUA_DISABLE_tolua_get_cItem_m_ItemID
static int tolua_get_cItem_m_ItemID(lua_State* tolua_S)
@@ -10219,6 +10384,67 @@ static int tolua_AllToLua_cRoot_GetWorld00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: GetDefaultWorld of class cRoot */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cRoot_GetDefaultWorld00
+static int tolua_AllToLua_cRoot_GetDefaultWorld00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cRoot",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cRoot* self = (cRoot*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetDefaultWorld'", NULL);
+#endif
+ {
+ cWorld* tolua_ret = (cWorld*) self->GetDefaultWorld();
+ tolua_pushusertype(tolua_S,(void*)tolua_ret,"cWorld");
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetDefaultWorld'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: GetWorld of class cRoot */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cRoot_GetWorld01
+static int tolua_AllToLua_cRoot_GetWorld01(lua_State* tolua_S)
+{
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cRoot",0,&tolua_err) ||
+ !tolua_isstring(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+ {
+ cRoot* self = (cRoot*) tolua_tousertype(tolua_S,1,0);
+ const char* a_WorldName = ((const char*) tolua_tostring(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetWorld'", NULL);
+#endif
+ {
+ cWorld* tolua_ret = (cWorld*) self->GetWorld(a_WorldName);
+ tolua_pushusertype(tolua_S,(void*)tolua_ret,"cWorld");
+ }
+ }
+ return 1;
+tolua_lerror:
+ return tolua_AllToLua_cRoot_GetWorld00(tolua_S);
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: GetGroupManager of class cRoot */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cRoot_GetGroupManager00
static int tolua_AllToLua_cRoot_GetGroupManager00(lua_State* tolua_S)
@@ -15146,6 +15372,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cPlayer","cPlayer","cPawn",NULL);
tolua_beginmodule(tolua_S,"cPlayer");
+ tolua_function(tolua_S,"Initialize",tolua_AllToLua_cPlayer_Initialize00);
tolua_function(tolua_S,"GetEyeHeight",tolua_AllToLua_cPlayer_GetEyeHeight00);
tolua_function(tolua_S,"GetEyePosition",tolua_AllToLua_cPlayer_GetEyePosition00);
tolua_function(tolua_S,"GetFlying",tolua_AllToLua_cPlayer_GetFlying00);
@@ -15174,6 +15401,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_cclass(tolua_S,"Lua__cPlayer","Lua__cPlayer","cPlayer",NULL);
tolua_beginmodule(tolua_S,"Lua__cPlayer");
tolua_function(tolua_S,"tolua__set_instance",tolua_AllToLua_Lua__cPlayer_tolua__set_instance00);
+ tolua_function(tolua_S,"cPlayer__Initialize",tolua_AllToLua_Lua__cPlayer_cPlayer__Initialize00);
tolua_function(tolua_S,"cPlayer__TeleportTo",tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo00);
tolua_function(tolua_S,"cPlayer__TeleportTo",tolua_AllToLua_Lua__cPlayer_cPlayer__TeleportTo01);
tolua_function(tolua_S,"cPlayer__MoveTo",tolua_AllToLua_Lua__cPlayer_cPlayer__MoveTo00);
@@ -15293,6 +15521,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"GetBlockEntity",tolua_AllToLua_cWorld_GetBlockEntity00);
tolua_function(tolua_S,"GrowTree",tolua_AllToLua_cWorld_GrowTree00);
tolua_function(tolua_S,"GetWorldSeed",tolua_AllToLua_cWorld_GetWorldSeed00);
+ tolua_function(tolua_S,"GetName",tolua_AllToLua_cWorld_GetName00);
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cInventory","cInventory","",NULL);
tolua_beginmodule(tolua_S,"cInventory");
@@ -15317,6 +15546,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"Empty",tolua_AllToLua_cItem_Empty00);
tolua_function(tolua_S,"IsEmpty",tolua_AllToLua_cItem_IsEmpty00);
tolua_function(tolua_S,"Equals",tolua_AllToLua_cItem_Equals00);
+ tolua_function(tolua_S,"GetJson",tolua_AllToLua_cItem_GetJson00);
+ tolua_function(tolua_S,"FromJson",tolua_AllToLua_cItem_FromJson00);
tolua_variable(tolua_S,"m_ItemID",tolua_get_cItem_m_ItemID,tolua_set_cItem_m_ItemID);
tolua_variable(tolua_S,"m_ItemCount",tolua_get_cItem_m_ItemCount,tolua_set_cItem_m_ItemCount);
tolua_variable(tolua_S,"m_ItemHealth",tolua_get_cItem_m_ItemHealth,tolua_set_cItem_m_ItemHealth);
@@ -15389,6 +15620,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"Get",tolua_AllToLua_cRoot_Get00);
tolua_function(tolua_S,"GetServer",tolua_AllToLua_cRoot_GetServer00);
tolua_function(tolua_S,"GetWorld",tolua_AllToLua_cRoot_GetWorld00);
+ tolua_function(tolua_S,"GetDefaultWorld",tolua_AllToLua_cRoot_GetDefaultWorld00);
+ tolua_function(tolua_S,"GetWorld",tolua_AllToLua_cRoot_GetWorld01);
tolua_function(tolua_S,"GetGroupManager",tolua_AllToLua_cRoot_GetGroupManager00);
tolua_function(tolua_S,"GetRecipeChecker",tolua_AllToLua_cRoot_GetRecipeChecker00);
tolua_function(tolua_S,"GetFurnaceRecipe",tolua_AllToLua_cRoot_GetFurnaceRecipe00);
diff --git a/source/Bindings.h b/source/Bindings.h
index d779e1f5b..8c6c7302d 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 10/31/11 01:51:08.
+** Generated automatically by tolua++-1.0.92 on 11/01/11 22:50:07.
*/
/* Exported function */
diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp
index 1cabcd593..855318159 100644
--- a/source/cChunkMap.cpp
+++ b/source/cChunkMap.cpp
@@ -10,6 +10,9 @@
#include <cstdlib> // abs
#include <math.h> // floorf
#include <stdio.h> // sprintf and stuff
+
+
+#define sprintf_s( dest, size, format, ... ) sprintf( dest, format, __VA_ARGS__ )
#endif
#include "zlib.h"
@@ -549,16 +552,12 @@ void cChunkMap::SaveAllChunks()
void cChunkMap::SaveLayer( cChunkLayer* a_Layer )
{
- cMakeDir::MakeDir("world");
+ std::string WorldName = m_World->GetName();
+ cMakeDir::MakeDir( WorldName.c_str() );
char SourceFile[128];
- #ifdef _WIN32
- sprintf_s(SourceFile, 128, "world/X%i_Z%i.pak", a_Layer->m_X, a_Layer->m_Z );
- #else
- sprintf(SourceFile, "world/X%i_Z%i.pak", a_Layer->m_X, a_Layer->m_Z );
- #endif
-
+ sprintf_s(SourceFile, 128, ( WorldName + "/X%i_Z%i.pak").c_str(), a_Layer->m_X, a_Layer->m_Z );
FILE* f = 0;
#ifdef _WIN32
@@ -635,13 +634,10 @@ void cChunkMap::SaveLayer( cChunkLayer* a_Layer )
cChunkMap::cChunkLayer* cChunkMap::LoadLayer(int a_LayerX, int a_LayerZ )
{
+ std::string WorldName = m_World->GetName();
char SourceFile[128];
- #ifdef _WIN32
- sprintf_s(SourceFile, 128, "world/X%i_Z%i.pak", a_LayerX, a_LayerZ );
- #else
- sprintf(SourceFile, "world/X%i_Z%i.pak", a_LayerX, a_LayerZ );
- #endif
+ sprintf_s(SourceFile, 128, (WorldName + "/X%i_Z%i.pak").c_str(), a_LayerX, a_LayerZ );
FILE* f = 0;
#ifdef _WIN32
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 18ba84d88..b4d74cc01 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -112,6 +112,7 @@ cClientHandle::cClientHandle(const cSocket & a_Socket)
, m_TimeLastPacket( cWorld::GetTime() )
, m_bLoggedIn( false )
, m_bKeepThreadGoing( true )
+ , m_bSendLoginResponse( false )
, m_pState( new sClientHandleState )
{
LOG("cClientHandle::cClientHandle");
@@ -234,17 +235,16 @@ void cClientHandle::StreamChunks()
{
if( !m_bLoggedIn )
return;
- int ChunkPosX = (int)m_Player->GetPosX() / 16;
- if( m_Player->GetPosX() < 0 ) ChunkPosX -= 1;
- int ChunkPosZ = (int)m_Player->GetPosZ() / 16;
- if( m_Player->GetPosZ() < 0 ) ChunkPosZ -= 1;
+
+ int ChunkPosX = (int)floor(m_Player->GetPosX() / 16);
+ int ChunkPosZ = (int)floor(m_Player->GetPosZ() / 16);
cChunk* NeededChunks[VIEWDISTANCE*VIEWDISTANCE];
for(int x = 0; x < VIEWDISTANCE; x++)
{
for(int z = 0; z < VIEWDISTANCE; z++)
{
- NeededChunks[x + z*VIEWDISTANCE] = cRoot::Get()->GetWorld()->GetChunk( x + ChunkPosX-(VIEWDISTANCE-1)/2, 0, z + ChunkPosZ-(VIEWDISTANCE-1)/2 );
+ NeededChunks[x + z*VIEWDISTANCE] = m_Player->GetWorld()->GetChunk( x + ChunkPosX-(VIEWDISTANCE-1)/2, 0, z + ChunkPosZ-(VIEWDISTANCE-1)/2 );
}
}
@@ -298,9 +298,9 @@ void cClientHandle::StreamChunks()
void cClientHandle::StreamChunksSmart( cChunk** a_Chunks, unsigned int a_NumChunks )
{
- int X = (int)m_Player->GetPosX() / 16;
- int Y = (int)m_Player->GetPosY() / 128;
- int Z = (int)m_Player->GetPosZ() / 16;
+ int X = (int)floor(m_Player->GetPosX() / 16);
+ int Y = (int)floor(m_Player->GetPosY() / 128);
+ int Z = (int)floor(m_Player->GetPosZ() / 16);
bool bAllDone = false;
while( !bAllDone )
@@ -432,7 +432,7 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
}
// Now initialize player (adds to entity list etc.)
- m_Player->Initialize( cRoot::Get()->GetWorld() ); // TODO - Get correct world for player
+ m_Player->Initialize( cRoot::Get()->GetDefaultWorld() ); // TODO - Get correct world for player
// Broadcasts to all but this ( this is actually handled in cChunk.cpp, after entity is added to the chunk )
//m_Player->SpawnOn( 0 );
@@ -537,7 +537,8 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
case 294 : itemhasdur = true; break;
case 359 : itemhasdur = true; break;
}
- if (itemhasdur) {
+ if (itemhasdur)
+ {
int maxhelditemdur = 1563;
switch(helditem)
{
@@ -570,9 +571,10 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
}
m_Player->GetInventory().GetEquippedItem().m_ItemHealth ++;
LOG("Health: %i", m_Player->GetInventory().GetEquippedItem().m_ItemHealth);
- if (m_Player->GetInventory().GetEquippedItem().m_ItemHealth >= maxhelditemdur) {
+ if (m_Player->GetInventory().GetEquippedItem().m_ItemHealth >= maxhelditemdur)
+ {
LOG("Player %s Broke ID: %i", GetUsername(), m_Player->GetInventory().GetEquippedItem().m_ItemID);
- m_Player->GetInventory().RemoveItem( m_Player->GetInventory().GetEquippedItem());
+ m_Player->GetInventory().RemoveItem( m_Player->GetInventory().GetEquippedItem());
}
}
}
@@ -914,42 +916,9 @@ void cClientHandle::AuthenticateThread( void* a_Param )
return;
}
- self->SendLoginResponse();
+ self->m_bSendLoginResponse = true;
}
-void cClientHandle::SendLoginResponse()
-{
- cWorld* World = cRoot::Get()->GetWorld(); // TODO - Get the correct world or better yet, move this to the main thread so we don't have to lock anything
- World->LockEntities();
- // Spawn player (only serversided, so data is loaded)
- m_Player = new cPlayer( this, GetUsername() ); // !!DO NOT INITIALIZE!! <- is done after receiving MoveLook Packet
-
- cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_PLAYER_SPAWN, 1, m_Player ); // TODO - this function is called from a seperate thread, which might be dangerous
-
- // Return a server login packet
- cPacket_Login LoginResponse;
- LoginResponse.m_ProtocolVersion = m_Player->GetUniqueID();
- //LoginResponse.m_Username = "";
- //m_Player->SetGameMode ( 0 );
- m_Player->SetGameMode ( cRoot::Get()->GetWorld()->GetGameMode() ); //set player's gamemode to server's gamemode at login.
- LoginResponse.m_ServerMode = m_Player->GetGameMode(); //set gamemode from player.
- LoginResponse.m_MapSeed = 0;
- LoginResponse.m_Dimension = 0;
- Send( LoginResponse );
-
- // Send position
- Send( cPacket_PlayerMoveLook( m_Player ) );
-
- // Send time
- Send( cPacket_TimeUpdate( (cRoot::Get()->GetWorld()->GetWorldTime() ) ) );
-
- // Send inventory
- m_Player->GetInventory().SendWholeInventory( this );
-
- // Send health
- Send( cPacket_UpdateHealth( (short)m_Player->GetHealth() ) );
- World->UnlockEntities();
-}
void cClientHandle::Tick(float a_Dt)
{
@@ -963,6 +932,40 @@ void cClientHandle::Tick(float a_Dt)
Destroy();
}
+
+ if( m_bSendLoginResponse )
+ {
+ m_bSendLoginResponse = false;
+
+ cWorld* World = cRoot::Get()->GetDefaultWorld(); // TODO - Get the correct world or better yet, move this to the main thread so we don't have to lock anything
+ World->LockEntities();
+ // Spawn player (only serversided, so data is loaded)
+ m_Player = new cPlayer( this, GetUsername() ); // !!DO NOT INITIALIZE!! <- is done after receiving MoveLook Packet
+
+ cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_PLAYER_SPAWN, 1, m_Player ); // TODO - this function is called from a seperate thread, which might be dangerous
+
+ // Return a server login packet
+ cPacket_Login LoginResponse;
+ LoginResponse.m_ProtocolVersion = m_Player->GetUniqueID();
+ //LoginResponse.m_Username = "";
+ LoginResponse.m_ServerMode = m_Player->GetGameMode(); //set gamemode from world.
+ LoginResponse.m_MapSeed = 0;
+ LoginResponse.m_Dimension = 0;
+ Send( LoginResponse );
+
+ // Send position
+ Send( cPacket_PlayerMoveLook( m_Player ) );
+
+ // Send time
+ Send( cPacket_TimeUpdate( World->GetWorldTime() ) );
+
+ // Send inventory
+ m_Player->GetInventory().SendWholeInventory( this );
+
+ // Send health
+ Send( cPacket_UpdateHealth( (short)m_Player->GetHealth() ) );
+ World->UnlockEntities();
+ }
}
void cClientHandle::Send( const cPacket & a_Packet, ENUM_PRIORITY a_Priority /* = E_PRIORITY_NORMAL */ )
diff --git a/source/cClientHandle.h b/source/cClientHandle.h
index 224ba46b3..318355773 100644
--- a/source/cClientHandle.h
+++ b/source/cClientHandle.h
@@ -65,6 +65,7 @@ private:
float m_TimeLastPacket;
bool m_bLoggedIn;
+ bool m_bSendLoginResponse;
bool m_bKeepThreadGoing;
}; // tolua_export
diff --git a/source/cEntity.cpp b/source/cEntity.cpp
index b8cc26199..c22be3def 100644
--- a/source/cEntity.cpp
+++ b/source/cEntity.cpp
@@ -75,6 +75,8 @@ void cEntity::WrapRotation()
void cEntity::MoveToCorrectChunk()
{
+ if( !m_World ) return; // Entity needs a world to move to a chunk
+
int ChunkX = 0, ChunkY = 0, ChunkZ = 0;
cWorld::BlockToChunk( (int)m_Pos->x, (int)m_Pos->y, (int)m_Pos->z, ChunkX, ChunkY, ChunkZ );
if( m_ChunkX != ChunkX || m_ChunkY != ChunkY || m_ChunkZ != ChunkZ )
diff --git a/source/cFileFormatUpdater.cpp b/source/cFileFormatUpdater.cpp
index 8516b5b40..733b0e0e4 100644
--- a/source/cFileFormatUpdater.cpp
+++ b/source/cFileFormatUpdater.cpp
@@ -52,7 +52,7 @@ void cFileFormatUpdater::PlayerBINtoJSON( const char* a_FileName )
{
Vector3d PlayerPos;
Vector3f PlayerRot;
- short PlayerHealth;
+ short PlayerHealth = 0;
const unsigned int NumInventorySlots = 45; // At this time the player inventory has/had 45 slots
cItem IventoryItems[ NumInventorySlots ];
diff --git a/source/cPickup.cpp b/source/cPickup.cpp
index ba36077e0..c712d9919 100644
--- a/source/cPickup.cpp
+++ b/source/cPickup.cpp
@@ -27,6 +27,7 @@ CLASS_DEFINITION( cPickup, cEntity )
cPickup::~cPickup()
{
delete m_Item;
+ delete m_Speed;
}
cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */)
@@ -60,6 +61,7 @@ cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX
cPickup::cPickup(cPacket_PickupSpawn* a_PickupSpawnPacket)
: cEntity( ((double)a_PickupSpawnPacket->m_PosX)/32, ((double)a_PickupSpawnPacket->m_PosY)/32, ((double)a_PickupSpawnPacket->m_PosZ)/32 )
+ , m_Speed( new Vector3f() )
, m_bOnGround( false )
, m_bReplicated( false )
, m_Timer( 0.f )
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index fe3f5a7d6..69e163629 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -15,6 +15,7 @@
#include "cItem.h"
#include "cTracer.h"
#include "cRoot.h"
+#include "cMakeDir.h"
#include "packets/cPacket_NamedEntitySpawn.h"
#include "packets/cPacket_EntityLook.h"
@@ -86,13 +87,16 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName)
if( !LoadFromDisk() )
{
m_Inventory->Clear();
- SetPosX( cRoot::Get()->GetWorld()->GetSpawnX() ); // TODO - Get from the correct world?
- SetPosY( cRoot::Get()->GetWorld()->GetSpawnY() );
- SetPosZ( cRoot::Get()->GetWorld()->GetSpawnZ() );
+ SetPosX( cRoot::Get()->GetDefaultWorld()->GetSpawnX() );
+ SetPosY( cRoot::Get()->GetDefaultWorld()->GetSpawnY() );
+ SetPosZ( cRoot::Get()->GetDefaultWorld()->GetSpawnZ() );
}
+}
- //MoveToCorrectChunk();
- cRoot::Get()->GetWorld()->AddPlayer( this ); // TODO - Add to correct world? Or get rid of this?
+void cPlayer::Initialize( cWorld* a_World )
+{
+ cPawn::Initialize( a_World );
+ GetWorld()->AddPlayer( this );
}
cPlayer::~cPlayer(void)
@@ -618,7 +622,7 @@ void cPlayer::TossItem( bool a_bDraggingItem, int a_Amount /* = 1 */ )
}
}
-bool cPlayer::LoadFromDisk()
+bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the correct world for this player
{
cIniFile IniFile("users.ini");
if( IniFile.ReadFile() )
@@ -653,7 +657,7 @@ bool cPlayer::LoadFromDisk()
}
char SourceFile[128];
- sprintf_s(SourceFile, 128, "world/player/%s.json", m_pState->PlayerName.c_str() );
+ sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() );
FILE* f;
#ifdef _WIN32
@@ -696,7 +700,7 @@ bool cPlayer::LoadFromDisk()
m_Rot->z = (float)JSON_PlayerRotation[(unsigned int)2].asDouble();
}
- m_Health = root.get("health", 0 ).asInt();
+ m_Health = (short)root.get("health", 0 ).asInt();
m_Inventory->LoadFromJson(root["inventory"]);
return true;
@@ -706,21 +710,7 @@ bool cPlayer::LoadFromDisk()
bool cPlayer::SaveToDisk()
{
- #ifdef _WIN32
- { // Make sure some folders exist
- SECURITY_ATTRIBUTES Attrib;
- Attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
- Attrib.lpSecurityDescriptor = NULL;
- Attrib.bInheritHandle = false;
- ::CreateDirectory("world", &Attrib);
- ::CreateDirectory("world/player", &Attrib);
- }
- #else
- {
- mkdir("world", S_IRWXU | S_IRWXG | S_IRWXO);
- mkdir("world/player", S_IRWXU | S_IRWXG | S_IRWXO);
- }
- #endif
+ cMakeDir::MakeDir("players");
// create the JSON data
Json::Value JSON_PlayerPosition;
@@ -746,7 +736,7 @@ bool cPlayer::SaveToDisk()
std::string JsonData = writer.write( root );
char SourceFile[128];
- sprintf_s(SourceFile, 128, "world/player/%s.json", m_pState->PlayerName.c_str() );
+ sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() );
FILE* f;
#ifdef _WIN32
diff --git a/source/cPlayer.h b/source/cPlayer.h
index 1bb349a40..4dedde727 100644
--- a/source/cPlayer.h
+++ b/source/cPlayer.h
@@ -16,6 +16,8 @@ public:
cPlayer(cClientHandle* a_Client, const char* a_PlayerName);
virtual ~cPlayer();
+ virtual void Initialize( cWorld* a_World ); //tolua_export
+
virtual void SpawnOn( cClientHandle* a_Target );
virtual void Tick(float a_Dt);
diff --git a/source/cRoot.cpp b/source/cRoot.cpp
index 55ee28576..518275088 100644
--- a/source/cRoot.cpp
+++ b/source/cRoot.cpp
@@ -24,9 +24,15 @@
cRoot* cRoot::s_Root = 0;
+typedef std::map< std::string, cWorld* > WorldMap;
+struct cRoot::sRootState
+{
+ cWorld* pDefaultWorld;
+ WorldMap WorldsByName;
+};
+
cRoot::cRoot()
: m_Server( 0 )
- , m_World( 0 )
, m_MonsterConfig( 0 )
, m_GroupManager( 0 )
, m_RecipeChecker( 0 )
@@ -37,6 +43,7 @@ cRoot::cRoot()
, m_bStop( false )
, m_bRestart( false )
, m_InputThread( 0 )
+ , m_pState( new sRootState )
{
s_Root = this;
}
@@ -44,6 +51,7 @@ cRoot::cRoot()
cRoot::~cRoot()
{
s_Root = 0;
+ delete m_pState;
}
void cRoot::InputThread(void* a_Params)
@@ -93,8 +101,7 @@ void cRoot::Start()
m_GroupManager = new cGroupManager();
m_RecipeChecker = new cRecipeChecker();
m_FurnaceRecipe = new cFurnaceRecipe();
- m_World = new cWorld();
- m_World->InitializeSpawn();
+ LoadWorlds();
m_PluginManager = new cPluginManager(); // This should be last
m_PluginManager->ReloadPluginsNow();
@@ -122,7 +129,7 @@ void cRoot::Start()
delete m_FurnaceRecipe; m_FurnaceRecipe = 0;
delete m_RecipeChecker; m_RecipeChecker = 0;
delete m_GroupManager; m_GroupManager = 0;
- delete m_World; m_World = 0;
+ UnloadWorlds();
//delete HeartBeat; HeartBeat = 0;
delete m_Server; m_Server = 0;
}
@@ -130,6 +137,73 @@ void cRoot::Start()
delete m_Log; m_Log = 0;
}
+void cRoot::LoadWorlds()
+{
+ cIniFile IniFile("settings.ini"); IniFile.ReadFile();
+
+ // First get the default world
+ std::string DefaultWorldName = IniFile.GetValue("Worlds", "DefaultWorld", "world");
+ m_pState->pDefaultWorld = new cWorld( DefaultWorldName.c_str() );
+ m_pState->pDefaultWorld->InitializeSpawn();
+ m_pState->WorldsByName[ DefaultWorldName ] = m_pState->pDefaultWorld;
+
+ // Then load the other worlds
+ unsigned int KeyNum = IniFile.FindKey("Worlds");
+ unsigned int NumWorlds = IniFile.GetNumValues( KeyNum );
+ if( NumWorlds > 0 )
+ {
+ for(unsigned int i = 0; i < NumWorlds; i++)
+ {
+ std::string ValueName = IniFile.GetValueName(KeyNum, i );
+ if( ValueName.compare("World") == 0 )
+ {
+ std::string WorldName = IniFile.GetValue(KeyNum, i );
+ if( WorldName.size() > 0 )
+ {
+ cWorld* NewWorld = new cWorld( WorldName.c_str() );
+ NewWorld->InitializeSpawn();
+ m_pState->WorldsByName[ WorldName ] = NewWorld;
+ }
+ }
+ }
+ }
+}
+
+void cRoot::UnloadWorlds()
+{
+ for( WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr )
+ {
+ delete itr->second;
+ }
+ m_pState->WorldsByName.clear();
+}
+
+cWorld* cRoot::GetWorld()
+{
+ return GetDefaultWorld();
+}
+
+cWorld* cRoot::GetDefaultWorld()
+{
+ return m_pState->pDefaultWorld;
+}
+
+cWorld* cRoot::GetWorld( const char* a_WorldName )
+{
+ WorldMap::iterator itr = m_pState->WorldsByName.find( a_WorldName );
+ if( itr != m_pState->WorldsByName.end() )
+ return itr->second;
+ return 0;
+}
+
+void cRoot::TickWorlds( float a_Dt )
+{
+ for( WorldMap::iterator itr = m_pState->WorldsByName.begin(); itr != m_pState->WorldsByName.end(); ++itr )
+ {
+ itr->second->Tick( a_Dt );
+ }
+}
+
void cRoot::ServerCommand( const char* a_Cmd )
{
//LOG("Command: %s", a_Cmd );
diff --git a/source/cRoot.h b/source/cRoot.h
index 95f2e236e..86b6ac28a 100644
--- a/source/cRoot.h
+++ b/source/cRoot.h
@@ -21,7 +21,9 @@ public:
void Start();
cServer* GetServer() { return m_Server; } //tolua_export
- cWorld* GetWorld() { return m_World; } //tolua_export
+ cWorld* GetWorld(); //tolua_export
+ cWorld* GetDefaultWorld(); //tolua_export
+ cWorld* GetWorld( const char* a_WorldName ); //tolua_export
cMonsterConfig *GetMonsterConfig() { return m_MonsterConfig;}
cGroupManager* GetGroupManager() { return m_GroupManager; } //tolua_export
@@ -31,9 +33,13 @@ public:
cPluginManager* GetPluginManager() { return m_PluginManager; } //tolua_export
void ServerCommand( const char* a_Cmd ); //tolua_export
+
+ void TickWorlds( float a_Dt );
private:
+ void LoadWorlds();
+ void UnloadWorlds();
+
cServer* m_Server;
- cWorld* m_World;
cMonsterConfig *m_MonsterConfig;
cGroupManager* m_GroupManager;
@@ -47,6 +53,9 @@ private:
bool m_bStop;
bool m_bRestart;
+ struct sRootState;
+ sRootState* m_pState;
+
cThread* m_InputThread;
static void InputThread(void* a_Params);
diff --git a/source/cServer.cpp b/source/cServer.cpp
index 8ea00a523..e6d475f46 100644
--- a/source/cServer.cpp
+++ b/source/cServer.cpp
@@ -48,6 +48,8 @@ extern "C" {
bool g_bWaterPhysics = false;
+typedef std::list< cClientHandle* > ClientList;
+
struct cServer::sServerState
{
sServerState()
@@ -61,6 +63,8 @@ struct cServer::sServerState
cThread* pListenThread; bool bStopListenThread;
cThread* pTickThread; bool bStopTickThread;
+ ClientList Clients;
+
cEvent RestartEvent;
std::string ServerID;
};
@@ -230,14 +234,11 @@ cServer::~cServer()
// TODO - Need to modify this or something, so it broadcasts to all worlds? And move this to cWorld?
void cServer::Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude /* = 0 */ )
{
- //m_World->LockClientHandle();
- cWorld* World = cRoot::Get()->GetWorld();
- for( cWorld::ClientList::iterator itr = World->GetClients().begin(); itr != World->GetClients().end(); ++itr)
+ for( ClientList::iterator itr = m_pState->Clients.begin(); itr != m_pState->Clients.end(); ++itr)
{
if( *itr == a_Exclude || !(*itr)->IsLoggedIn() ) continue;
(*itr)->Send( a_Packet );
}
- //m_World->UnlockClientHandle();
}
// TODO - Need to move this to cWorld I think
@@ -263,10 +264,7 @@ void cServer::StartListenClient()
LOG("%s connected!", ClientIP);
cClientHandle *NewHandle = new cClientHandle( SClient );
- cWorld* World = cRoot::Get()->GetWorld(); // TODO - I don't think the world cares for the client at this stage, besides for calling the tick function
- World->LockClientHandle();
- World->AddClient( NewHandle );
- World->UnlockClientHandle();
+ m_pState->Clients.push_back( NewHandle ); // TODO - lock list
}
}
@@ -284,11 +282,11 @@ bool cServer::Tick(float a_Dt)
m_Millisecondsf = m_Millisecondsf - (int)m_Millisecondsf;
}
- cWorld* World = cRoot::Get()->GetWorld(); // TODO - Iterate through all worlds, or give all worlds their own thread
- World->Tick(a_Dt);
- World->LockClientHandle();
- for( cWorld::ClientList::iterator itr = World->GetClients().begin(); itr != World->GetClients().end();)
+ cRoot::Get()->TickWorlds( a_Dt ); // TODO - Maybe give all worlds their own thread?
+
+ //World->LockClientHandle(); // TODO - Lock client list
+ for( ClientList::iterator itr = m_pState->Clients.begin(); itr != m_pState->Clients.end();)
{
(*itr)->HandlePendingPackets();
@@ -297,13 +295,14 @@ bool cServer::Tick(float a_Dt)
cClientHandle* RemoveMe = *itr;
++itr;
- cRoot::Get()->GetWorld()->RemoveClient( RemoveMe );
+ m_pState->Clients.remove( RemoveMe );
+ delete RemoveMe;
continue;
}
(*itr)->Tick(a_Dt);
++itr;
}
- World->UnlockClientHandle();
+ //World->UnlockClientHandle();
cRoot::Get()->GetPluginManager()->Tick( a_Dt );
@@ -506,13 +505,14 @@ void cServer::Shutdown()
cRoot::Get()->GetWorld()->SaveAllChunks();
- cWorld* World = cRoot::Get()->GetWorld();
- World->LockClientHandle();
- while( World->GetClients().begin() != World->GetClients().end() )
+ //cWorld* World = cRoot::Get()->GetWorld();
+ //World->LockClientHandle(); // TODO - Lock client list
+ for( ClientList::iterator itr = m_pState->Clients.begin(); itr != m_pState->Clients.end(); ++itr )
{
- World->RemoveClient( *World->GetClients().begin() );
+ delete *itr;
}
- World->UnlockClientHandle();
+ m_pState->Clients.clear();
+ //World->UnlockClientHandle();
}
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index 29115d15e..3d85fc0fb 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -30,6 +30,7 @@
#include "cGhast.h" //Ghast
#include "cZombiepigman.h" //Zombiepigman
#include "cGenSettings.h"
+#include "cMakeDir.h"
#include "packets/cPacket_TimeUpdate.h"
@@ -42,7 +43,7 @@
#ifndef _WIN32
#include <stdlib.h>
-#include <sys/stat.h> // for mkdir
+//#include <sys/stat.h> // for mkdir
#include <sys/types.h>
#endif
@@ -70,6 +71,8 @@ struct cWorld::sWorldState
std::vector< unsigned int > m_ChunkBuffer;
cWorld::ChunkList m_SpreadQueue;
+
+ std::string WorldName;
};
cWorld* cWorld::GetWorld()
@@ -100,25 +103,14 @@ cWorld::~cWorld()
delete m_pState;
}
-cWorld::cWorld()
+cWorld::cWorld( const char* a_WorldName )
: m_pState( new sWorldState )
, m_SpawnMonsterTime( 0.f )
{
- LOG("cWorld::cWorld()");
+ LOG("cWorld::cWorld(%s)", a_WorldName);
+ m_pState->WorldName = a_WorldName;
-#ifdef _WIN32
- {
- SECURITY_ATTRIBUTES Attrib;
- Attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
- Attrib.lpSecurityDescriptor = NULL;
- Attrib.bInheritHandle = false;
- ::CreateDirectory("world", &Attrib);
- }
-#else
- {
- mkdir("world", S_IRWXU | S_IRWXG | S_IRWXO);
- }
-#endif
+ cMakeDir::MakeDir(m_pState->WorldName.c_str());
srand( (unsigned int) time(0) );
m_SpawnX = (double)((rand()%10000)-5000);
@@ -126,7 +118,7 @@ cWorld::cWorld()
m_SpawnZ = (double)((rand()%10000)-5000);
m_WorldSeed = rand();
- cIniFile IniFile("world/world.ini");
+ cIniFile IniFile( m_pState->WorldName + "/world.ini");
if( IniFile.ReadFile() )
{
m_SpawnX = IniFile.GetValueF("SpawnPosition", "X", m_SpawnX );
@@ -142,7 +134,7 @@ cWorld::cWorld()
IniFile.SetValueI("Seed", "Seed", m_WorldSeed );
if( !IniFile.WriteFile() )
{
- LOG("WARNING: Could not write to world/world.ini");
+ LOG("WARNING: Could not write to %s/world.ini", a_WorldName);
}
}
LOGINFO("Seed: %i", m_WorldSeed );
@@ -184,7 +176,7 @@ cWorld::cWorld()
m_Time = 0;
m_WorldTimeFraction = 0.f;
m_WorldTime = 0;
- m_GameMode = 1;
+ m_GameMode = 0;
m_LastSave = 0;
m_LastUnload = 0;
m_ClientHandleCriticalSection = new cCriticalSection();
@@ -696,15 +688,15 @@ cEntity* cWorld::GetEntity( int a_UniqueID )
return 0;
}
-void cWorld::RemoveClient( cClientHandle* a_Client )
-{
- m_pState->m_Clients.remove( a_Client );
- if( a_Client )
- {
- delete a_Client;
- a_Client = 0;
- }
-}
+// void cWorld::RemoveClient( cClientHandle* a_Client )
+// {
+// m_pState->m_Clients.remove( a_Client );
+// if( a_Client )
+// {
+// delete a_Client;
+// a_Client = 0;
+// }
+// }
void cWorld::RemoveEntity( cEntity* a_Entity )
{
@@ -783,14 +775,14 @@ void cWorld::RemoveSpread( cChunk* a_Chunk )
/************************************************************************/
/* Get and set */
/************************************************************************/
-void cWorld::AddClient( cClientHandle* a_Client )
-{
- m_pState->m_Clients.push_back( a_Client );
-}
-cWorld::ClientList & cWorld::GetClients()
-{
- return m_pState->m_Clients;
-}
+// void cWorld::AddClient( cClientHandle* a_Client )
+// {
+// m_pState->m_Clients.push_back( a_Client );
+// }
+// cWorld::ClientList & cWorld::GetClients()
+// {
+// return m_pState->m_Clients;
+// }
cWorld::EntityList & cWorld::GetEntities()
{
return m_pState->m_AllEntities;
@@ -812,3 +804,7 @@ void cWorld::AddToRemoveEntityQueue( cEntity & a_Entity )
m_pState->m_AllEntities.remove( &a_Entity);
m_pState->m_RemoveEntityQueue.push_back( &a_Entity );
}
+const char* cWorld::GetName()
+{
+ return m_pState->WorldName.c_str();
+} \ No newline at end of file
diff --git a/source/cWorld.h b/source/cWorld.h
index 74f8ae8e8..383ffaec3 100644
--- a/source/cWorld.h
+++ b/source/cWorld.h
@@ -25,7 +25,7 @@ public:
typedef std::list< cChunk* > ChunkList;
typedef std::list< cPlayer* > PlayerList;
- static cWorld* GetWorld(); //tolua_export
+ static cWorld* GetWorld(); //tolua_export
// Return time in seconds
inline static float GetTime() //tolua_export
@@ -43,9 +43,9 @@ public:
cChunk* GetChunkOfBlock( int a_X, int a_Y, int a_Z );
char GetHeight( int a_X, int a_Z ); //tolua_export
- void AddClient( cClientHandle* a_Client );
- void RemoveClient( cClientHandle* a_Client );
- ClientList & GetClients();
+ //void AddClient( cClientHandle* a_Client );
+ //void RemoveClient( cClientHandle* a_Client );
+ //ClientList & GetClients();
void AddPlayer( cPlayer* a_Player );
void RemovePlayer( cPlayer* a_Player );
@@ -79,6 +79,7 @@ public:
void GrowTree( int a_X, int a_Y, int a_Z ); //tolua_export
unsigned int GetWorldSeed() { return m_WorldSeed; } //tolua_export
+ const char* GetName(); //tolua_export
inline static void AbsoluteToRelative( int & a_X, int & a_Y, int & a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ )
{
@@ -122,7 +123,7 @@ public:
void InitializeSpawn();
private:
friend class cRoot;
- cWorld();
+ cWorld( const char* a_WorldName );
~cWorld();
struct sWorldState;
diff --git a/source/main.cpp b/source/main.cpp
index 011a50f83..1868e30ca 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -26,7 +26,9 @@ int main( int argc, char **argv )
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
+#ifndef _DEBUG
std::signal(SIGSEGV, ShowCrashReport);
+#endif
try
{