From 4d2c810c64c38fd5530170d5c4d54956a5587fb2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Oct 2013 00:30:20 +0100 Subject: Pickups now have collection delay when vomited Implements FS#394. --- source/Entities/Pickup.cpp | 7 ++++--- source/Entities/Pickup.h | 7 ++++++- source/Entities/Player.cpp | 2 +- source/UI/SlotArea.cpp | 2 +- source/World.cpp | 8 ++++---- source/World.h | 4 ++-- source/WorldStorage/WSSAnvil.cpp | 2 +- 7 files changed, 19 insertions(+), 13 deletions(-) (limited to 'source') diff --git a/source/Entities/Pickup.cpp b/source/Entities/Pickup.cpp index 075f93449..50431f52e 100644 --- a/source/Entities/Pickup.cpp +++ b/source/Entities/Pickup.cpp @@ -24,11 +24,12 @@ -cPickup::cPickup(double a_X, double a_Y, double a_Z, const cItem & a_Item, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) +cPickup::cPickup(double a_X, double a_Y, double a_Z, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) : cEntity(etPickup, a_X, a_Y, a_Z, 0.2, 0.2) , m_Timer( 0.f ) , m_Item(a_Item) , m_bCollected( false ) + , m_bIsPlayerCreated( IsPlayerCreated ) { m_MaxHealth = 5; m_Health = 5; @@ -126,8 +127,8 @@ bool cPickup::CollectedBy(cPlayer * a_Dest) return false; // It's already collected! } - // 800 is to long - if (m_Timer < 500.f) + // Two seconds if player created the pickup (vomiting), half a second if anything else + if (m_Timer < (m_bIsPlayerCreated ? 2000.f : 500.f)) { // LOG("Pickup %d cannot be collected by \"%s\", because it is not old enough.", m_UniqueID, a_Dest->GetName().c_str()); return false; // Not old enough diff --git a/source/Entities/Pickup.h b/source/Entities/Pickup.h index 488f91fb2..e4154f1d4 100644 --- a/source/Entities/Pickup.h +++ b/source/Entities/Pickup.h @@ -24,7 +24,7 @@ class cPickup : public: CLASS_PROTODEF(cPickup); - cPickup(double a_X, double a_Y, double a_Z, const cItem & a_Item, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); // tolua_export + cPickup(double a_MicroPosX, double a_MicroPosY, double a_MicroPosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); // tolua_export cItem & GetItem(void) {return m_Item; } // tolua_export const cItem & GetItem(void) const {return m_Item; } @@ -40,6 +40,9 @@ public: /// Returns true if the pickup has already been collected bool IsCollected(void) const { return m_bCollected; } // tolua_export + + /// Returns true if created by player (i.e. vomiting), used for determining picking-up delay time + bool IsPlayerCreated(void) const { return m_bIsPlayerCreated; } // tolua_export private: Vector3d m_ResultingSpeed; //Can be used to modify the resulting speed for the current tick ;) @@ -52,6 +55,8 @@ private: cItem m_Item; bool m_bCollected; + + bool m_bIsPlayerCreated; }; // tolua_export diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index d93b45614..e06281998 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -1183,7 +1183,7 @@ void cPlayer::TossItem( double vX = 0, vY = 0, vZ = 0; EulerToVector(-GetRotation(), GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 3, vY * 3, vZ * 3); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player } diff --git a/source/UI/SlotArea.cpp b/source/UI/SlotArea.cpp index 0a37e82b0..463e56bce 100644 --- a/source/UI/SlotArea.cpp +++ b/source/UI/SlotArea.cpp @@ -793,7 +793,7 @@ void cSlotAreaTemporary::TossItems(cPlayer & a_Player, int a_Begin, int a_End) double vX = 0, vY = 0, vZ = 0; EulerToVector(-a_Player.GetRotation(), a_Player.GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; - a_Player.GetWorld()->SpawnItemPickups(Drops, a_Player.GetPosX(), a_Player.GetPosY() + 1.6f, a_Player.GetPosZ(), vX * 3, vY * 3, vZ * 3); + a_Player.GetWorld()->SpawnItemPickups(Drops, a_Player.GetPosX(), a_Player.GetPosY() + 1.6f, a_Player.GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because player created } diff --git a/source/World.cpp b/source/World.cpp index ef56e7fe9..28c73f591 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -1533,7 +1533,7 @@ bool cWorld::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlock -void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed) +void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed, bool IsPlayerCreated) { MTRand r1; a_FlyAwaySpeed /= 1000; // Pre-divide, so that we don't have to divide each time inside the loop @@ -1545,7 +1545,7 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double cPickup * Pickup = new cPickup( a_BlockX, a_BlockY, a_BlockZ, - *itr, SpeedX, SpeedY, SpeedZ + *itr, IsPlayerCreated, SpeedX, SpeedY, SpeedZ ); Pickup->Initialize(this); } @@ -1555,13 +1555,13 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double -void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ) +void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated) { for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) { cPickup * Pickup = new cPickup( a_BlockX, a_BlockY, a_BlockZ, - *itr, (float)a_SpeedX, (float)a_SpeedY, (float)a_SpeedZ + *itr, IsPlayerCreated, (float)a_SpeedX, (float)a_SpeedY, (float)a_SpeedZ ); Pickup->Initialize(this); } diff --git a/source/World.h b/source/World.h index 25bc0b338..633ce969e 100644 --- a/source/World.h +++ b/source/World.h @@ -347,10 +347,10 @@ public: // tolua_begin /// Spawns item pickups for each item in the list. May compress pickups if too many entities: - void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0); + void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed = 1.0, bool IsPlayerCreated = false); /// Spawns item pickups for each item in the list. May compress pickups if too many entities. All pickups get the speed specified: - void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ); + void SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ, bool IsPlayerCreated = false); /// Spawns a new primed TNT entity at the specified block coords and specified fuse duration. Initial velocity is given based on the relative coefficient provided void SpawnPrimedTNT(double a_X, double a_Y, double a_Z, double a_FuseTimeInSec, double a_InitialVelocityCoeff = 1); diff --git a/source/WorldStorage/WSSAnvil.cpp b/source/WorldStorage/WSSAnvil.cpp index 537e2f723..b2e104a78 100644 --- a/source/WorldStorage/WSSAnvil.cpp +++ b/source/WorldStorage/WSSAnvil.cpp @@ -1123,7 +1123,7 @@ void cWSSAnvil::LoadPickupFromNBT(cEntityList & a_Entities, const cParsedNBT & a { return; } - std::auto_ptr Pickup(new cPickup(0, 0, 0, Item)); + std::auto_ptr Pickup(new cPickup(0, 0, 0, Item, false)); // Pickup delay doesn't matter, just say false if (!LoadEntityBaseFromNBT(*Pickup.get(), a_NBT, a_TagIdx)) { return; -- cgit v1.2.3 From d359c5a2fe8a0e5af849916cbd225d31919f1826 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Oct 2013 11:05:43 +0200 Subject: Unified cPlayer's Heal() function with cEntity's. --- source/Entities/Player.cpp | 7 ++----- source/Entities/Player.h | 15 +++++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'source') diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index e06281998..f92d42556 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -349,11 +349,8 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) void cPlayer::Heal(int a_Health) { - if (m_Health < GetMaxHealth()) - { - m_Health = (short)std::min((int)a_Health + m_Health, (int)GetMaxHealth()); - SendHealth(); - } + super::Heal(a_Health); + SendHealth(); } diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 82ff48954..067a996e5 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -167,13 +167,15 @@ public: StringList GetResolvedPermissions(); // >> EXPORTED IN MANUALBINDINGS << bool IsInGroup( const AString & a_Group ); // tolua_export - AString GetColor(void) const; // tolua_export + // tolua_begin + + /// Returns the full color code to use for this player, based on their primary group or set in m_Color + AString GetColor(void) const; - void TossItem(bool a_bDraggingItem, char a_Amount = 1, short a_CreateType = 0, short a_CreateHealth = 0); // tolua_export + void TossItem(bool a_bDraggingItem, char a_Amount = 1, short a_CreateType = 0, short a_CreateHealth = 0); - void Heal( int a_Health ); // tolua_export - - // tolua_begin + /// Heals the player by the specified amount of HPs (positive only); sends health update + void Heal(int a_Health); int GetFoodLevel (void) const { return m_FoodLevel; } double GetFoodSaturationLevel (void) const { return m_FoodSaturationLevel; } @@ -181,7 +183,7 @@ public: double GetFoodExhaustionLevel (void) const { return m_FoodExhaustionLevel; } int GetFoodPoisonedTicksRemaining(void) const { return m_FoodPoisonedTicksRemaining; } - int GetAirLevel (void) const { return m_AirLevel; } + int GetAirLevel (void) const { return m_AirLevel; } /// Returns true if the player is satiated, i. e. their foodlevel is at the max and they cannot eat anymore bool IsSatiated(void) const { return (m_FoodLevel >= MAX_FOOD_LEVEL); } @@ -302,6 +304,7 @@ protected: /// Player's air level (for swimming) int m_AirLevel; + /// used to time ticks between damage taken via drowning/suffocation int m_AirTickTimer; -- cgit v1.2.3 From eca6955a2dc4c8c444ad9e11ad4a8aa926969918 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Oct 2013 12:18:54 +0200 Subject: Cleanup in cPlayer. --- source/Entities/Player.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/Entities/Player.h b/source/Entities/Player.h index 067a996e5..449a63231 100644 --- a/source/Entities/Player.h +++ b/source/Entities/Player.h @@ -128,8 +128,8 @@ public: // Sets the current gamemode, doesn't check validity, doesn't send update packets to client void LoginSetGameMode(eGameMode a_GameMode); - /// Tries to move to a new position, with collision checks and stuff - virtual void MoveTo( const Vector3d & a_NewPos ); // tolua_export + /// Tries to move to a new position, with attachment-related checks (y == -999) + void MoveTo(const Vector3d & a_NewPos); // tolua_export cWindow * GetWindow(void) { return m_CurrentWindow; } // tolua_export const cWindow * GetWindow(void) const { return m_CurrentWindow; } @@ -159,8 +159,10 @@ public: /// Adds a player to existing group or creates a new group when it doesn't exist void AddToGroup( const AString & a_GroupName ); // tolua_export + /// Removes a player from the group, resolves permissions and group inheritance (case sensitive) void RemoveFromGroup( const AString & a_GroupName ); // tolua_export + bool CanUseCommand( const AString & a_Command ); // tolua_export bool HasPermission( const AString & a_Permission ); // tolua_export const GroupList & GetGroups() { return m_Groups; } // >> EXPORTED IN MANUALBINDINGS << -- cgit v1.2.3 From 625c5f86deb0649403994ae4bbcc4a4cd07853d0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Oct 2013 15:05:23 +0200 Subject: Fixed cPickup's constructor's parameter naming. --- source/Entities/Pickup.cpp | 4 ++-- source/Entities/Pickup.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/Entities/Pickup.cpp b/source/Entities/Pickup.cpp index 50431f52e..bc8abd204 100644 --- a/source/Entities/Pickup.cpp +++ b/source/Entities/Pickup.cpp @@ -24,8 +24,8 @@ -cPickup::cPickup(double a_X, double a_Y, double a_Z, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) - : cEntity(etPickup, a_X, a_Y, a_Z, 0.2, 0.2) +cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) + : cEntity(etPickup, a_PosX, a_PosY, a_PosZ, 0.2, 0.2) , m_Timer( 0.f ) , m_Item(a_Item) , m_bCollected( false ) diff --git a/source/Entities/Pickup.h b/source/Entities/Pickup.h index e4154f1d4..cbd34a922 100644 --- a/source/Entities/Pickup.h +++ b/source/Entities/Pickup.h @@ -24,7 +24,7 @@ class cPickup : public: CLASS_PROTODEF(cPickup); - cPickup(double a_MicroPosX, double a_MicroPosY, double a_MicroPosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); // tolua_export + cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); // tolua_export cItem & GetItem(void) {return m_Item; } // tolua_export const cItem & GetItem(void) const {return m_Item; } -- cgit v1.2.3 From 99d369d83761e7ee27fa05061426cfdcd72f808b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Oct 2013 16:44:25 +0200 Subject: cPickup cleanup. --- source/Entities/Pickup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source') diff --git a/source/Entities/Pickup.h b/source/Entities/Pickup.h index cbd34a922..d39eda298 100644 --- a/source/Entities/Pickup.h +++ b/source/Entities/Pickup.h @@ -31,7 +31,7 @@ public: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - virtual bool CollectedBy(cPlayer * a_Dest); // tolua_export + bool CollectedBy(cPlayer * a_Dest); // tolua_export virtual void Tick(float a_Dt, cChunk & a_Chunk) override; -- cgit v1.2.3 From 5331555708ce3bfc4417b2f7c788fff98e81a858 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Oct 2013 16:45:13 +0200 Subject: Renamed cMonster::GetSpawnRate() to GetSpawnDelay(). --- source/Bindings.cpp | 99 ++++++++++++++++++++++++++++++++++--------------- source/Bindings.h | 2 +- source/Mobs/Monster.cpp | 2 +- source/Mobs/Monster.h | 4 +- source/World.cpp | 4 +- 5 files changed, 76 insertions(+), 35 deletions(-) (limited to 'source') diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 54a3e161b..998fab632 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/23/13 13:30:23. +** Generated automatically by tolua++-1.0.92 on 10/24/13 16:43:14. */ #ifndef __cplusplus @@ -10073,24 +10073,26 @@ static int tolua_AllToLua_cPickup_new00(lua_State* tolua_S) !tolua_isnumber(tolua_S,3,0,&tolua_err) || !tolua_isnumber(tolua_S,4,0,&tolua_err) || (tolua_isvaluenil(tolua_S,5,&tolua_err) || !tolua_isusertype(tolua_S,5,"const cItem",0,&tolua_err)) || - !tolua_isnumber(tolua_S,6,1,&tolua_err) || + !tolua_isboolean(tolua_S,6,0,&tolua_err) || !tolua_isnumber(tolua_S,7,1,&tolua_err) || !tolua_isnumber(tolua_S,8,1,&tolua_err) || - !tolua_isnoobj(tolua_S,9,&tolua_err) + !tolua_isnumber(tolua_S,9,1,&tolua_err) || + !tolua_isnoobj(tolua_S,10,&tolua_err) ) goto tolua_lerror; else #endif { - double a_X = ((double) tolua_tonumber(tolua_S,2,0)); - double a_Y = ((double) tolua_tonumber(tolua_S,3,0)); - double a_Z = ((double) tolua_tonumber(tolua_S,4,0)); + double a_PosX = ((double) tolua_tonumber(tolua_S,2,0)); + double a_PosY = ((double) tolua_tonumber(tolua_S,3,0)); + double a_PosZ = ((double) tolua_tonumber(tolua_S,4,0)); const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,5,0)); - float a_SpeedX = ((float) tolua_tonumber(tolua_S,6,0.f)); - float a_SpeedY = ((float) tolua_tonumber(tolua_S,7,0.f)); - float a_SpeedZ = ((float) tolua_tonumber(tolua_S,8,0.f)); + bool IsPlayerCreated = ((bool) tolua_toboolean(tolua_S,6,0)); + float a_SpeedX = ((float) tolua_tonumber(tolua_S,7,0.f)); + float a_SpeedY = ((float) tolua_tonumber(tolua_S,8,0.f)); + float a_SpeedZ = ((float) tolua_tonumber(tolua_S,9,0.f)); { - cPickup* tolua_ret = (cPickup*) Mtolua_new((cPickup)(a_X,a_Y,a_Z,*a_Item,a_SpeedX,a_SpeedY,a_SpeedZ)); + cPickup* tolua_ret = (cPickup*) Mtolua_new((cPickup)(a_PosX,a_PosY,a_PosZ,*a_Item,IsPlayerCreated,a_SpeedX,a_SpeedY,a_SpeedZ)); tolua_pushusertype(tolua_S,(void*)tolua_ret,"cPickup"); } } @@ -10115,24 +10117,26 @@ static int tolua_AllToLua_cPickup_new00_local(lua_State* tolua_S) !tolua_isnumber(tolua_S,3,0,&tolua_err) || !tolua_isnumber(tolua_S,4,0,&tolua_err) || (tolua_isvaluenil(tolua_S,5,&tolua_err) || !tolua_isusertype(tolua_S,5,"const cItem",0,&tolua_err)) || - !tolua_isnumber(tolua_S,6,1,&tolua_err) || + !tolua_isboolean(tolua_S,6,0,&tolua_err) || !tolua_isnumber(tolua_S,7,1,&tolua_err) || !tolua_isnumber(tolua_S,8,1,&tolua_err) || - !tolua_isnoobj(tolua_S,9,&tolua_err) + !tolua_isnumber(tolua_S,9,1,&tolua_err) || + !tolua_isnoobj(tolua_S,10,&tolua_err) ) goto tolua_lerror; else #endif { - double a_X = ((double) tolua_tonumber(tolua_S,2,0)); - double a_Y = ((double) tolua_tonumber(tolua_S,3,0)); - double a_Z = ((double) tolua_tonumber(tolua_S,4,0)); + double a_PosX = ((double) tolua_tonumber(tolua_S,2,0)); + double a_PosY = ((double) tolua_tonumber(tolua_S,3,0)); + double a_PosZ = ((double) tolua_tonumber(tolua_S,4,0)); const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,5,0)); - float a_SpeedX = ((float) tolua_tonumber(tolua_S,6,0.f)); - float a_SpeedY = ((float) tolua_tonumber(tolua_S,7,0.f)); - float a_SpeedZ = ((float) tolua_tonumber(tolua_S,8,0.f)); + bool IsPlayerCreated = ((bool) tolua_toboolean(tolua_S,6,0)); + float a_SpeedX = ((float) tolua_tonumber(tolua_S,7,0.f)); + float a_SpeedY = ((float) tolua_tonumber(tolua_S,8,0.f)); + float a_SpeedZ = ((float) tolua_tonumber(tolua_S,9,0.f)); { - cPickup* tolua_ret = (cPickup*) Mtolua_new((cPickup)(a_X,a_Y,a_Z,*a_Item,a_SpeedX,a_SpeedY,a_SpeedZ)); + cPickup* tolua_ret = (cPickup*) Mtolua_new((cPickup)(a_PosX,a_PosY,a_PosZ,*a_Item,IsPlayerCreated,a_SpeedX,a_SpeedY,a_SpeedZ)); tolua_pushusertype(tolua_S,(void*)tolua_ret,"cPickup"); tolua_register_gc(tolua_S,lua_gettop(tolua_S)); } @@ -10276,6 +10280,38 @@ static int tolua_AllToLua_cPickup_IsCollected00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: IsPlayerCreated of class cPickup */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cPickup_IsPlayerCreated00 +static int tolua_AllToLua_cPickup_IsPlayerCreated00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cPickup",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cPickup* self = (const cPickup*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'IsPlayerCreated'", NULL); +#endif + { + bool tolua_ret = (bool) self->IsPlayerCreated(); + tolua_pushboolean(tolua_S,(bool)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'IsPlayerCreated'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: GetProjectileKind of class cProjectileEntity */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cProjectileEntity_GetProjectileKind00 static int tolua_AllToLua_cProjectileEntity_GetProjectileKind00(lua_State* tolua_S) @@ -12541,7 +12577,8 @@ static int tolua_AllToLua_cWorld_SpawnItemPickups00(lua_State* tolua_S) !tolua_isnumber(tolua_S,4,0,&tolua_err) || !tolua_isnumber(tolua_S,5,0,&tolua_err) || !tolua_isnumber(tolua_S,6,1,&tolua_err) || - !tolua_isnoobj(tolua_S,7,&tolua_err) + !tolua_isboolean(tolua_S,7,1,&tolua_err) || + !tolua_isnoobj(tolua_S,8,&tolua_err) ) goto tolua_lerror; else @@ -12553,11 +12590,12 @@ static int tolua_AllToLua_cWorld_SpawnItemPickups00(lua_State* tolua_S) double a_BlockY = ((double) tolua_tonumber(tolua_S,4,0)); double a_BlockZ = ((double) tolua_tonumber(tolua_S,5,0)); double a_FlyAwaySpeed = ((double) tolua_tonumber(tolua_S,6,1.0)); + bool IsPlayerCreated = ((bool) tolua_toboolean(tolua_S,7,false)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SpawnItemPickups'", NULL); #endif { - self->SpawnItemPickups(*a_Pickups,a_BlockX,a_BlockY,a_BlockZ,a_FlyAwaySpeed); + self->SpawnItemPickups(*a_Pickups,a_BlockX,a_BlockY,a_BlockZ,a_FlyAwaySpeed,IsPlayerCreated); } } return 0; @@ -12583,7 +12621,8 @@ static int tolua_AllToLua_cWorld_SpawnItemPickups01(lua_State* tolua_S) !tolua_isnumber(tolua_S,6,0,&tolua_err) || !tolua_isnumber(tolua_S,7,0,&tolua_err) || !tolua_isnumber(tolua_S,8,0,&tolua_err) || - !tolua_isnoobj(tolua_S,9,&tolua_err) + !tolua_isboolean(tolua_S,9,1,&tolua_err) || + !tolua_isnoobj(tolua_S,10,&tolua_err) ) goto tolua_lerror; else @@ -12596,11 +12635,12 @@ static int tolua_AllToLua_cWorld_SpawnItemPickups01(lua_State* tolua_S) double a_SpeedX = ((double) tolua_tonumber(tolua_S,6,0)); double a_SpeedY = ((double) tolua_tonumber(tolua_S,7,0)); double a_SpeedZ = ((double) tolua_tonumber(tolua_S,8,0)); + bool IsPlayerCreated = ((bool) tolua_toboolean(tolua_S,9,false)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SpawnItemPickups'", NULL); #endif { - self->SpawnItemPickups(*a_Pickups,a_BlockX,a_BlockY,a_BlockZ,a_SpeedX,a_SpeedY,a_SpeedZ); + self->SpawnItemPickups(*a_Pickups,a_BlockX,a_BlockY,a_BlockZ,a_SpeedX,a_SpeedY,a_SpeedZ,IsPlayerCreated); } } return 0; @@ -29333,9 +29373,9 @@ static int tolua_AllToLua_cMonster_FamilyFromType00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: GetSpawnRate of class cMonster */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cMonster_GetSpawnRate00 -static int tolua_AllToLua_cMonster_GetSpawnRate00(lua_State* tolua_S) +/* method: GetSpawnDelay of class cMonster */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cMonster_GetSpawnDelay00 +static int tolua_AllToLua_cMonster_GetSpawnDelay00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -29350,14 +29390,14 @@ static int tolua_AllToLua_cMonster_GetSpawnRate00(lua_State* tolua_S) { cMonster::eFamily a_MobFamily = ((cMonster::eFamily) (int) tolua_tonumber(tolua_S,2,0)); { - int tolua_ret = (int) cMonster::GetSpawnRate(a_MobFamily); + int tolua_ret = (int) cMonster::GetSpawnDelay(a_MobFamily); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'GetSpawnRate'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'GetSpawnDelay'.",&tolua_err); return 0; #endif } @@ -30489,6 +30529,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"CollectedBy",tolua_AllToLua_cPickup_CollectedBy00); tolua_function(tolua_S,"GetAge",tolua_AllToLua_cPickup_GetAge00); tolua_function(tolua_S,"IsCollected",tolua_AllToLua_cPickup_IsCollected00); + tolua_function(tolua_S,"IsPlayerCreated",tolua_AllToLua_cPickup_IsPlayerCreated00); tolua_endmodule(tolua_S); tolua_cclass(tolua_S,"cProjectileEntity","cProjectileEntity","cEntity",NULL); tolua_beginmodule(tolua_S,"cProjectileEntity"); @@ -31467,7 +31508,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"MobTypeToString",tolua_AllToLua_cMonster_MobTypeToString00); tolua_function(tolua_S,"StringToMobType",tolua_AllToLua_cMonster_StringToMobType00); tolua_function(tolua_S,"FamilyFromType",tolua_AllToLua_cMonster_FamilyFromType00); - tolua_function(tolua_S,"GetSpawnRate",tolua_AllToLua_cMonster_GetSpawnRate00); + tolua_function(tolua_S,"GetSpawnDelay",tolua_AllToLua_cMonster_GetSpawnDelay00); tolua_endmodule(tolua_S); tolua_cclass(tolua_S,"cLineBlockTracer","cLineBlockTracer","",NULL); tolua_beginmodule(tolua_S,"cLineBlockTracer"); diff --git a/source/Bindings.h b/source/Bindings.h index 620dbea84..f123da881 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/23/13 13:30:24. +** Generated automatically by tolua++-1.0.92 on 10/24/13 16:43:15. */ /* Exported function */ diff --git a/source/Mobs/Monster.cpp b/source/Mobs/Monster.cpp index 7e35b97f1..9b1f2fc4c 100644 --- a/source/Mobs/Monster.cpp +++ b/source/Mobs/Monster.cpp @@ -605,7 +605,7 @@ cMonster::eFamily cMonster::FamilyFromType(eType a_Type) -int cMonster::GetSpawnRate(cMonster::eFamily a_MobFamily) +int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily) { switch (a_MobFamily) { diff --git a/source/Mobs/Monster.h b/source/Mobs/Monster.h index 14c72ed73..39fa716ed 100644 --- a/source/Mobs/Monster.h +++ b/source/Mobs/Monster.h @@ -146,8 +146,8 @@ public: /// Returns the mob family based on the type static eFamily FamilyFromType(eType a_MobType); - /// Returns the spawn rate (number of game ticks between spawn attempts) for the given mob family - static int GetSpawnRate(cMonster::eFamily a_MobFamily); + /// Returns the spawn delay (number of game ticks between spawn attempts) for the given mob family + static int GetSpawnDelay(cMonster::eFamily a_MobFamily); // tolua_end diff --git a/source/World.cpp b/source/World.cpp index e2db77666..e62794781 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -755,9 +755,9 @@ void cWorld::TickMobs(float a_Dt) for (int i = 0; i < ARRAYCOUNT(AllFamilies); i++) { cMonster::eFamily Family = AllFamilies[i]; - int spawnrate = cMonster::GetSpawnRate(Family); + int SpawnDelay = cMonster::GetSpawnDelay(Family); if ( - (m_LastSpawnMonster[Family] > m_WorldAge - spawnrate) || // Not reached the needed tiks before the next round + (m_LastSpawnMonster[Family] > m_WorldAge - SpawnDelay) || // Not reached the needed ticks before the next round MobCensus.IsCapped(Family) ) { -- cgit v1.2.3 From 86bec4c57c72bb2d58c6dd91a447987f45cc7b32 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 25 Oct 2013 10:41:19 +0200 Subject: cMonster: Improved doxycomments. --- source/Mobs/Monster.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/Mobs/Monster.h b/source/Mobs/Monster.h index 39fa716ed..a0002bf4f 100644 --- a/source/Mobs/Monster.h +++ b/source/Mobs/Monster.h @@ -137,10 +137,10 @@ public: // tolua_begin - /// Translates MobType enum to a string + /// Translates MobType enum to a string, empty string if unknown static AString MobTypeToString(eType a_MobType); - /// Translates MobType string to the enum + /// Translates MobType string to the enum, mtInvalidType if not recognized static eType StringToMobType(const AString & a_MobTypeName); /// Returns the mob family based on the type -- cgit v1.2.3 From 9e9198e0907d3d6fd353c683478007f418d86dd8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 25 Oct 2013 11:15:44 +0200 Subject: cIniFile doesn't store filename internally anymore. --- source/Authenticator.cpp | 6 +- source/Bindings.cpp | 178 +++-------------------------------- source/Bindings.h | 2 +- source/BlockID.cpp | 4 +- source/Entities/Player.cpp | 8 +- source/Generating/ChunkGenerator.cpp | 2 - source/GroupManager.cpp | 4 +- source/MonsterConfig.cpp | 4 +- source/PluginManager.cpp | 4 +- source/Root.cpp | 9 +- source/WebAdmin.cpp | 9 +- source/World.cpp | 6 +- 12 files changed, 43 insertions(+), 193 deletions(-) (limited to 'source') diff --git a/source/Authenticator.cpp b/source/Authenticator.cpp index a45617f93..d7e05b4c2 100644 --- a/source/Authenticator.cpp +++ b/source/Authenticator.cpp @@ -47,8 +47,8 @@ cAuthenticator::~cAuthenticator() /// Read custom values from INI void cAuthenticator::ReadINI(void) { - cIniFile IniFile("settings.ini"); - if (!IniFile.ReadFile()) + cIniFile IniFile; + if (!IniFile.ReadFile("settings.ini")) { return; } @@ -74,7 +74,7 @@ void cAuthenticator::ReadINI(void) if (bSave) { IniFile.SetValueB("Authentication", "Authenticate", m_ShouldAuthenticate); - IniFile.WriteFile(); + IniFile.WriteFile("settings.ini"); } } diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 998fab632..f32f796bd 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/24/13 16:43:14. +** Generated automatically by tolua++-1.0.92 on 10/25/13 10:38:50. */ #ifndef __cplusplus @@ -345,59 +345,6 @@ static int tolua_AllToLua_cIniFile_new00_local(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: new of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_new01 -static int tolua_AllToLua_cIniFile_new01(lua_State* tolua_S) -{ - tolua_Error tolua_err; - if ( - !tolua_isusertable(tolua_S,1,"cIniFile",0,&tolua_err) || - !tolua_iscppstring(tolua_S,2,0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) - ) - goto tolua_lerror; - else - { - const std::string a_Path = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - { - cIniFile* tolua_ret = (cIniFile*) Mtolua_new((cIniFile)(a_Path)); - tolua_pushusertype(tolua_S,(void*)tolua_ret,"cIniFile"); - tolua_pushcppstring(tolua_S,(const char*)a_Path); - } - } - return 2; -tolua_lerror: - return tolua_AllToLua_cIniFile_new00(tolua_S); -} -#endif //#ifndef TOLUA_DISABLE - -/* method: new_local of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_new01_local -static int tolua_AllToLua_cIniFile_new01_local(lua_State* tolua_S) -{ - tolua_Error tolua_err; - if ( - !tolua_isusertable(tolua_S,1,"cIniFile",0,&tolua_err) || - !tolua_iscppstring(tolua_S,2,0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) - ) - goto tolua_lerror; - else - { - const std::string a_Path = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - { - cIniFile* tolua_ret = (cIniFile*) Mtolua_new((cIniFile)(a_Path)); - tolua_pushusertype(tolua_S,(void*)tolua_ret,"cIniFile"); - tolua_register_gc(tolua_S,lua_gettop(tolua_S)); - tolua_pushcppstring(tolua_S,(const char*)a_Path); - } - } - return 2; -tolua_lerror: - return tolua_AllToLua_cIniFile_new00_local(tolua_S); -} -#endif //#ifndef TOLUA_DISABLE - /* method: CaseSensitive of class cIniFile */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_CaseSensitive00 static int tolua_AllToLua_cIniFile_CaseSensitive00(lua_State* tolua_S) @@ -460,101 +407,6 @@ static int tolua_AllToLua_cIniFile_CaseInsensitive00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: Path of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_Path00 -static int tolua_AllToLua_cIniFile_Path00(lua_State* tolua_S) -{ -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) || - !tolua_iscppstring(tolua_S,2,0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string newPath = ((const std::string) tolua_tocppstring(tolua_S,2,0)); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Path'", NULL); -#endif - { - self->Path(newPath); - tolua_pushcppstring(tolua_S,(const char*)newPath); - } - } - return 1; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'Path'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - -/* method: Path of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_Path01 -static int tolua_AllToLua_cIniFile_Path01(lua_State* tolua_S) -{ - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) || - !tolua_isnoobj(tolua_S,2,&tolua_err) - ) - goto tolua_lerror; - else - { - const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Path'", NULL); -#endif - { - const std::string tolua_ret = (const std::string) self->Path(); - tolua_pushcppstring(tolua_S,(const char*)tolua_ret); - } - } - return 1; -tolua_lerror: - return tolua_AllToLua_cIniFile_Path00(tolua_S); -} -#endif //#ifndef TOLUA_DISABLE - -/* method: SetPath of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_SetPath00 -static int tolua_AllToLua_cIniFile_SetPath00(lua_State* tolua_S) -{ -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) || - !tolua_iscppstring(tolua_S,2,0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string newPath = ((const std::string) tolua_tocppstring(tolua_S,2,0)); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetPath'", NULL); -#endif - { - self->SetPath(newPath); - tolua_pushcppstring(tolua_S,(const char*)newPath); - } - } - return 1; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'SetPath'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - /* method: ReadFile of class cIniFile */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_ReadFile00 static int tolua_AllToLua_cIniFile_ReadFile00(lua_State* tolua_S) @@ -563,24 +415,27 @@ static int tolua_AllToLua_cIniFile_ReadFile00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) || - !tolua_isboolean(tolua_S,2,1,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) + !tolua_iscppstring(tolua_S,2,0,&tolua_err) || + !tolua_isboolean(tolua_S,3,1,&tolua_err) || + !tolua_isnoobj(tolua_S,4,&tolua_err) ) goto tolua_lerror; else #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - bool a_AllowExampleRedirect = ((bool) tolua_toboolean(tolua_S,2,true)); + const AString a_FileName = ((const AString) tolua_tocppstring(tolua_S,2,0)); + bool a_AllowExampleRedirect = ((bool) tolua_toboolean(tolua_S,3,true)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ReadFile'", NULL); #endif { - bool tolua_ret = (bool) self->ReadFile(a_AllowExampleRedirect); + bool tolua_ret = (bool) self->ReadFile(a_FileName,a_AllowExampleRedirect); tolua_pushboolean(tolua_S,(bool)tolua_ret); + tolua_pushcppstring(tolua_S,(const char*)a_FileName); } } - return 1; + return 2; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'ReadFile'.",&tolua_err); @@ -597,22 +452,25 @@ static int tolua_AllToLua_cIniFile_WriteFile00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) || - !tolua_isnoobj(tolua_S,2,&tolua_err) + !tolua_iscppstring(tolua_S,2,0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else #endif { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); + const AString a_FileName = ((const AString) tolua_tocppstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'WriteFile'", NULL); #endif { - bool tolua_ret = (bool) self->WriteFile(); + bool tolua_ret = (bool) self->WriteFile(a_FileName); tolua_pushboolean(tolua_S,(bool)tolua_ret); + tolua_pushcppstring(tolua_S,(const char*)a_FileName); } } - return 1; + return 2; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'WriteFile'.",&tolua_err); @@ -29487,14 +29345,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"new",tolua_AllToLua_cIniFile_new00); tolua_function(tolua_S,"new_local",tolua_AllToLua_cIniFile_new00_local); tolua_function(tolua_S,".call",tolua_AllToLua_cIniFile_new00_local); - tolua_function(tolua_S,"new",tolua_AllToLua_cIniFile_new01); - tolua_function(tolua_S,"new_local",tolua_AllToLua_cIniFile_new01_local); - tolua_function(tolua_S,".call",tolua_AllToLua_cIniFile_new01_local); tolua_function(tolua_S,"CaseSensitive",tolua_AllToLua_cIniFile_CaseSensitive00); tolua_function(tolua_S,"CaseInsensitive",tolua_AllToLua_cIniFile_CaseInsensitive00); - tolua_function(tolua_S,"Path",tolua_AllToLua_cIniFile_Path00); - tolua_function(tolua_S,"Path",tolua_AllToLua_cIniFile_Path01); - tolua_function(tolua_S,"SetPath",tolua_AllToLua_cIniFile_SetPath00); tolua_function(tolua_S,"ReadFile",tolua_AllToLua_cIniFile_ReadFile00); tolua_function(tolua_S,"WriteFile",tolua_AllToLua_cIniFile_WriteFile00); tolua_function(tolua_S,"Clear",tolua_AllToLua_cIniFile_Clear00); diff --git a/source/Bindings.h b/source/Bindings.h index f123da881..58f6023c1 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/24/13 16:43:15. +** Generated automatically by tolua++-1.0.92 on 10/25/13 10:38:51. */ /* Exported function */ diff --git a/source/BlockID.cpp b/source/BlockID.cpp index 95e1a63bf..2e957593b 100644 --- a/source/BlockID.cpp +++ b/source/BlockID.cpp @@ -42,8 +42,8 @@ class cBlockIDMap public: cBlockIDMap(void) { - cIniFile Ini("items.ini"); - if (!Ini.ReadFile()) + cIniFile Ini; + if (!Ini.ReadFile("items.ini")) { return; } diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp index f92d42556..d94bc944c 100644 --- a/source/Entities/Player.cpp +++ b/source/Entities/Player.cpp @@ -1224,11 +1224,11 @@ void cPlayer::LoadPermissionsFromDisk() m_Groups.clear(); m_Permissions.clear(); - cIniFile IniFile("users.ini"); - if( IniFile.ReadFile() ) + cIniFile IniFile; + if (IniFile.ReadFile("users.ini")) { std::string Groups = IniFile.GetValue(m_PlayerName, "Groups", ""); - if( Groups.size() > 0 ) + if (!Groups.empty()) { AStringVector Split = StringSplit( Groups, "," ); for( unsigned int i = 0; i < Split.size(); i++ ) @@ -1245,7 +1245,7 @@ void cPlayer::LoadPermissionsFromDisk() } else { - LOGWARN("WARNING: Failed to read ini file users.ini"); + LOGWARN("Failed to read the users.ini file. The player will be added only to the Default group."); AddToGroup("Default"); } ResolvePermissions(); diff --git a/source/Generating/ChunkGenerator.cpp b/source/Generating/ChunkGenerator.cpp index d35b30460..59a00b540 100644 --- a/source/Generating/ChunkGenerator.cpp +++ b/source/Generating/ChunkGenerator.cpp @@ -75,8 +75,6 @@ bool cChunkGenerator::Start(cWorld * a_World, cIniFile & a_IniFile) m_Generator->Initialize(a_World, a_IniFile); - a_IniFile.WriteFile(); - return super::Start(); } diff --git a/source/GroupManager.cpp b/source/GroupManager.cpp index b79fde9dc..d7332fd0a 100644 --- a/source/GroupManager.cpp +++ b/source/GroupManager.cpp @@ -44,8 +44,8 @@ cGroupManager::cGroupManager() : m_pState( new sGroupManagerState ) { LOGD("-- Loading Groups --"); - cIniFile IniFile("groups.ini"); - if (!IniFile.ReadFile()) + cIniFile IniFile; + if (!IniFile.ReadFile("groups.ini")) { LOGWARNING("groups.ini inaccessible, no groups are defined"); return; diff --git a/source/MonsterConfig.cpp b/source/MonsterConfig.cpp index 37c7431b0..69d639bdb 100644 --- a/source/MonsterConfig.cpp +++ b/source/MonsterConfig.cpp @@ -55,9 +55,9 @@ cMonsterConfig::~cMonsterConfig() void cMonsterConfig::Initialize() { - cIniFile MonstersIniFile("monsters.ini"); + cIniFile MonstersIniFile; - if (!MonstersIniFile.ReadFile()) + if (!MonstersIniFile.ReadFile("monsters.ini")) { LOGWARNING("%s: Cannot read monsters.ini file, monster attributes not available", __FUNCTION__); return; diff --git a/source/PluginManager.cpp b/source/PluginManager.cpp index a557bdc03..5ae70d48d 100644 --- a/source/PluginManager.cpp +++ b/source/PluginManager.cpp @@ -103,8 +103,8 @@ void cPluginManager::ReloadPluginsNow(void) cServer::BindBuiltInConsoleCommands(); - cIniFile IniFile("settings.ini"); - if (!IniFile.ReadFile()) + cIniFile IniFile; + if (!IniFile.ReadFile("settings.ini")) { LOGWARNING("cPluginManager: Can't find settings.ini, so can't load any plugins."); } diff --git a/source/Root.cpp b/source/Root.cpp index 1f6437784..f47de972c 100644 --- a/source/Root.cpp +++ b/source/Root.cpp @@ -116,8 +116,8 @@ void cRoot::Start(void) m_Server = new cServer(); LOG("Reading server config..."); - cIniFile IniFile("settings.ini"); - if (!IniFile.ReadFile()) + cIniFile IniFile; + if (!IniFile.ReadFile("settings.ini")) { LOGWARNING("settings.ini inaccessible, all settings are reset to default values"); } @@ -138,7 +138,7 @@ void cRoot::Start(void) LOGERROR("Failure starting server, aborting..."); return; } - IniFile.WriteFile(); + IniFile.WriteFile("settings.ini"); m_WebAdmin = new cWebAdmin(); m_WebAdmin->Init(); @@ -247,7 +247,8 @@ void cRoot::LoadGlobalSettings() void cRoot::LoadWorlds(void) { - cIniFile IniFile("settings.ini"); IniFile.ReadFile(); + cIniFile IniFile; + IniFile.ReadFile("settings.ini"); // Doesn't matter if success or not // First get the default world AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world"); diff --git a/source/WebAdmin.cpp b/source/WebAdmin.cpp index 882969746..8c95e4e21 100644 --- a/source/WebAdmin.cpp +++ b/source/WebAdmin.cpp @@ -44,8 +44,7 @@ public: cWebAdmin::cWebAdmin(void) : m_IsInitialized(false), - m_TemplateScript(""), - m_IniFile("webadmin.ini") + m_TemplateScript("") { } @@ -86,19 +85,19 @@ void cWebAdmin::RemovePlugin( cWebPlugin * a_Plugin ) bool cWebAdmin::Init(void) { - if (!m_IniFile.ReadFile()) + if (!m_IniFile.ReadFile("webadmin.ini")) { return false; } - LOG("Initialising WebAdmin..."); - if (!m_IniFile.GetValueSetB("WebAdmin", "Enabled", true)) { // WebAdmin is disabled, bail out faking a success return true; } + LOG("Initialising WebAdmin..."); + AString PortsIPv4 = m_IniFile.GetValueSet("WebAdmin", "Port", "8080"); AString PortsIPv6 = m_IniFile.GetValueSet("WebAdmin", "PortsIPv6", ""); diff --git a/source/World.cpp b/source/World.cpp index e62794781..786d97a4d 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -444,8 +444,8 @@ void cWorld::Start(void) m_SpawnZ = (double)((m_TickRand.randInt() % 1000) - 500); m_GameMode = eGameMode_Creative; - cIniFile IniFile(m_IniFileName); - if (!IniFile.ReadFile()) + cIniFile IniFile; + if (!IniFile.ReadFile(m_IniFileName)) { LOGWARNING("Cannot read world settings from \"%s\", defaults will be used.", m_IniFileName.c_str()); } @@ -555,7 +555,7 @@ void cWorld::Start(void) // Save any changes that the defaults may have done to the ini file: - if (!IniFile.WriteFile()) + if (!IniFile.WriteFile(m_IniFileName)) { LOGWARNING("Could not write world config to %s", m_IniFileName.c_str()); } -- cgit v1.2.3 From 323ebf119f35dc2bb689715a05f182238d7088f8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 25 Oct 2013 11:38:14 +0200 Subject: cIniFile: Renamed functions to make meaning more explicit. For example KeyComment() -> GetKeyComment() / AddKeyComment() --- source/Bindings.cpp | 562 +++++++++++++---------------------------------- source/Bindings.h | 2 +- source/BlockID.cpp | 8 +- source/MonsterConfig.cpp | 4 +- 4 files changed, 159 insertions(+), 417 deletions(-) (limited to 'source') diff --git a/source/Bindings.cpp b/source/Bindings.cpp index f32f796bd..5de3a3b38 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/25/13 10:38:50. +** Generated automatically by tolua++-1.0.92 on 10/25/13 11:34:58. */ #ifndef __cplusplus @@ -230,7 +230,7 @@ static void tolua_reg_types (lua_State* tolua_S) tolua_usertype(tolua_S,"cRoot"); tolua_usertype(tolua_S,"std::vector"); tolua_usertype(tolua_S,"cPickup"); - tolua_usertype(tolua_S,"cItems"); + tolua_usertype(tolua_S,"sWebAdminPage"); tolua_usertype(tolua_S,"cFireChargeEntity"); tolua_usertype(tolua_S,"cWorld"); tolua_usertype(tolua_S,"cChunkDesc"); @@ -253,39 +253,39 @@ static void tolua_reg_types (lua_State* tolua_S) tolua_usertype(tolua_S,"cLuaWindow"); tolua_usertype(tolua_S,"cInventory"); tolua_usertype(tolua_S,"cHopperEntity"); + tolua_usertype(tolua_S,"std::vector"); tolua_usertype(tolua_S,"cBlockEntityWithItems"); tolua_usertype(tolua_S,"cWindow"); - tolua_usertype(tolua_S,"cGroup"); tolua_usertype(tolua_S,"HTTPFormData"); - tolua_usertype(tolua_S,"cCraftingGrid"); + tolua_usertype(tolua_S,"cGroup"); tolua_usertype(tolua_S,"cArrowEntity"); tolua_usertype(tolua_S,"cDropSpenserEntity"); + tolua_usertype(tolua_S,"cCraftingGrid"); + tolua_usertype(tolua_S,"cPlayer"); tolua_usertype(tolua_S,"cBlockArea"); tolua_usertype(tolua_S,"cTracer"); tolua_usertype(tolua_S,"cStringMap"); - tolua_usertype(tolua_S,"cBoundingBox"); - tolua_usertype(tolua_S,"cServer"); tolua_usertype(tolua_S,"cBlockEntity"); tolua_usertype(tolua_S,"cCriticalSection"); tolua_usertype(tolua_S,"HTTPTemplateRequest"); + tolua_usertype(tolua_S,"cBoundingBox"); + tolua_usertype(tolua_S,"cServer"); tolua_usertype(tolua_S,"Vector3i"); tolua_usertype(tolua_S,"cFile"); - tolua_usertype(tolua_S,"std::vector"); + tolua_usertype(tolua_S,"cItems"); tolua_usertype(tolua_S,"cClientHandle"); + tolua_usertype(tolua_S,"cIniFile"); tolua_usertype(tolua_S,"cChatColor"); tolua_usertype(tolua_S,"cWebPlugin"); - tolua_usertype(tolua_S,"cIniFile"); - tolua_usertype(tolua_S,"cWebAdmin"); - tolua_usertype(tolua_S,"sWebAdminPage"); tolua_usertype(tolua_S,"cPawn"); - tolua_usertype(tolua_S,"cPlayer"); + tolua_usertype(tolua_S,"cThrownEggEntity"); tolua_usertype(tolua_S,"cGroupManager"); + tolua_usertype(tolua_S,"cWebAdmin"); tolua_usertype(tolua_S,"cItem"); - tolua_usertype(tolua_S,"HTTPRequest"); tolua_usertype(tolua_S,"cProjectileEntity"); + tolua_usertype(tolua_S,"HTTPRequest"); tolua_usertype(tolua_S,"cItemGrid::cListener"); tolua_usertype(tolua_S,"cDropperEntity"); - tolua_usertype(tolua_S,"cThrownEggEntity"); } /* method: new of class cIniFile */ @@ -510,68 +510,6 @@ static int tolua_AllToLua_cIniFile_Clear00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: Reset of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_Reset00 -static int tolua_AllToLua_cIniFile_Reset00(lua_State* tolua_S) -{ -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) || - !tolua_isnoobj(tolua_S,2,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Reset'", NULL); -#endif - { - self->Reset(); - } - } - return 0; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'Reset'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - -/* method: Erase of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_Erase00 -static int tolua_AllToLua_cIniFile_Erase00(lua_State* tolua_S) -{ -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) || - !tolua_isnoobj(tolua_S,2,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Erase'", NULL); -#endif - { - self->Erase(); - } - } - return 0; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'Erase'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - /* method: FindKey of class cIniFile */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_FindKey00 static int tolua_AllToLua_cIniFile_FindKey00(lua_State* tolua_S) @@ -588,12 +526,12 @@ static int tolua_AllToLua_cIniFile_FindKey00(lua_State* tolua_S) #endif { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'FindKey'", NULL); #endif { - long tolua_ret = (long) self->FindKey(keyname); + int tolua_ret = (int) self->FindKey(keyname); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); tolua_pushcppstring(tolua_S,(const char*)keyname); } @@ -624,13 +562,13 @@ static int tolua_AllToLua_cIniFile_FindValue00(lua_State* tolua_S) #endif { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); - const std::string valuename = ((const std::string) tolua_tocppstring(tolua_S,3,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); + const AString valuename = ((const AString) tolua_tocppstring(tolua_S,3,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'FindValue'", NULL); #endif { - long tolua_ret = (long) self->FindValue(keyID,valuename); + int tolua_ret = (int) self->FindValue(keyID,valuename); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); tolua_pushcppstring(tolua_S,(const char*)valuename); } @@ -644,38 +582,6 @@ static int tolua_AllToLua_cIniFile_FindValue00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: NumKeys of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_NumKeys00 -static int tolua_AllToLua_cIniFile_NumKeys00(lua_State* tolua_S) -{ -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) || - !tolua_isnoobj(tolua_S,2,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NumKeys'", NULL); -#endif - { - unsigned tolua_ret = (unsigned) self->NumKeys(); - tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); - } - } - return 1; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'NumKeys'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - /* method: GetNumKeys of class cIniFile */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetNumKeys00 static int tolua_AllToLua_cIniFile_GetNumKeys00(lua_State* tolua_S) @@ -695,7 +601,7 @@ static int tolua_AllToLua_cIniFile_GetNumKeys00(lua_State* tolua_S) if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetNumKeys'", NULL); #endif { - unsigned tolua_ret = (unsigned) self->GetNumKeys(); + int tolua_ret = (int) self->GetNumKeys(); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } @@ -724,12 +630,12 @@ static int tolua_AllToLua_cIniFile_AddKeyName00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddKeyName'", NULL); #endif { - unsigned tolua_ret = (unsigned) self->AddKeyName(keyname); + int tolua_ret = (int) self->AddKeyName(keyname); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); tolua_pushcppstring(tolua_S,(const char*)keyname); } @@ -743,40 +649,6 @@ static int tolua_AllToLua_cIniFile_AddKeyName00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: KeyName of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_KeyName00 -static int tolua_AllToLua_cIniFile_KeyName00(lua_State* tolua_S) -{ -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) || - !tolua_isnumber(tolua_S,2,0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'KeyName'", NULL); -#endif - { - std::string tolua_ret = (std::string) self->KeyName(keyID); - tolua_pushcppstring(tolua_S,(const char*)tolua_ret); - } - } - return 1; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'KeyName'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - /* method: GetKeyName of class cIniFile */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetKeyName00 static int tolua_AllToLua_cIniFile_GetKeyName00(lua_State* tolua_S) @@ -793,12 +665,12 @@ static int tolua_AllToLua_cIniFile_GetKeyName00(lua_State* tolua_S) #endif { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetKeyName'", NULL); #endif { - std::string tolua_ret = (std::string) self->GetKeyName(keyID); + AString tolua_ret = (AString) self->GetKeyName(keyID); tolua_pushcppstring(tolua_S,(const char*)tolua_ret); } } @@ -811,41 +683,6 @@ static int tolua_AllToLua_cIniFile_GetKeyName00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: NumValues of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_NumValues00 -static int tolua_AllToLua_cIniFile_NumValues00(lua_State* tolua_S) -{ -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) || - !tolua_iscppstring(tolua_S,2,0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NumValues'", NULL); -#endif - { - unsigned tolua_ret = (unsigned) self->NumValues(keyname); - tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); - tolua_pushcppstring(tolua_S,(const char*)keyname); - } - } - return 2; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'NumValues'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - /* method: GetNumValues of class cIniFile */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetNumValues00 static int tolua_AllToLua_cIniFile_GetNumValues00(lua_State* tolua_S) @@ -853,7 +690,7 @@ static int tolua_AllToLua_cIniFile_GetNumValues00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) || !tolua_iscppstring(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) @@ -861,13 +698,13 @@ static int tolua_AllToLua_cIniFile_GetNumValues00(lua_State* tolua_S) else #endif { - cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); + const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetNumValues'", NULL); #endif { - unsigned tolua_ret = (unsigned) self->GetNumValues(keyname); + int tolua_ret = (int) self->GetNumValues(keyname); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); tolua_pushcppstring(tolua_S,(const char*)keyname); } @@ -881,55 +718,26 @@ static int tolua_AllToLua_cIniFile_GetNumValues00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: NumValues of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_NumValues01 -static int tolua_AllToLua_cIniFile_NumValues01(lua_State* tolua_S) -{ - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) || - !tolua_isnumber(tolua_S,2,0,&tolua_err) || - !tolua_isnoobj(tolua_S,3,&tolua_err) - ) - goto tolua_lerror; - else - { - cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NumValues'", NULL); -#endif - { - unsigned tolua_ret = (unsigned) self->NumValues(keyID); - tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); - } - } - return 1; -tolua_lerror: - return tolua_AllToLua_cIniFile_NumValues00(tolua_S); -} -#endif //#ifndef TOLUA_DISABLE - /* method: GetNumValues of class cIniFile */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetNumValues01 static int tolua_AllToLua_cIniFile_GetNumValues01(lua_State* tolua_S) { tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"cIniFile",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) || !tolua_isnumber(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else { - cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); + const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetNumValues'", NULL); #endif { - unsigned tolua_ret = (unsigned) self->GetNumValues(keyID); + int tolua_ret = (int) self->GetNumValues(keyID); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } @@ -939,43 +747,6 @@ tolua_lerror: } #endif //#ifndef TOLUA_DISABLE -/* method: ValueName of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_ValueName00 -static int tolua_AllToLua_cIniFile_ValueName00(lua_State* tolua_S) -{ -#ifndef TOLUA_RELEASE - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) || - !tolua_iscppstring(tolua_S,2,0,&tolua_err) || - !tolua_isnumber(tolua_S,3,0,&tolua_err) || - !tolua_isnoobj(tolua_S,4,&tolua_err) - ) - goto tolua_lerror; - else -#endif - { - const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const unsigned valueID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ValueName'", NULL); -#endif - { - std::string tolua_ret = (std::string) self->ValueName(keyname,valueID); - tolua_pushcppstring(tolua_S,(const char*)tolua_ret); - tolua_pushcppstring(tolua_S,(const char*)keyname); - } - } - return 2; -#ifndef TOLUA_RELEASE - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'ValueName'.",&tolua_err); - return 0; -#endif -} -#endif //#ifndef TOLUA_DISABLE - /* method: GetValueName of class cIniFile */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetValueName00 static int tolua_AllToLua_cIniFile_GetValueName00(lua_State* tolua_S) @@ -993,13 +764,13 @@ static int tolua_AllToLua_cIniFile_GetValueName00(lua_State* tolua_S) #endif { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const unsigned valueID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); + const int valueID = ((const int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetValueName'", NULL); #endif { - std::string tolua_ret = (std::string) self->GetValueName(keyname,valueID); + AString tolua_ret = (AString) self->GetValueName(keyname,valueID); tolua_pushcppstring(tolua_S,(const char*)tolua_ret); tolua_pushcppstring(tolua_S,(const char*)keyname); } @@ -1013,37 +784,6 @@ static int tolua_AllToLua_cIniFile_GetValueName00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: ValueName of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_ValueName01 -static int tolua_AllToLua_cIniFile_ValueName01(lua_State* tolua_S) -{ - tolua_Error tolua_err; - if ( - !tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) || - !tolua_isnumber(tolua_S,2,0,&tolua_err) || - !tolua_isnumber(tolua_S,3,0,&tolua_err) || - !tolua_isnoobj(tolua_S,4,&tolua_err) - ) - goto tolua_lerror; - else - { - const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); - const unsigned valueID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); -#ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ValueName'", NULL); -#endif - { - std::string tolua_ret = (std::string) self->ValueName(keyID,valueID); - tolua_pushcppstring(tolua_S,(const char*)tolua_ret); - } - } - return 1; -tolua_lerror: - return tolua_AllToLua_cIniFile_ValueName00(tolua_S); -} -#endif //#ifndef TOLUA_DISABLE - /* method: GetValueName of class cIniFile */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetValueName01 static int tolua_AllToLua_cIniFile_GetValueName01(lua_State* tolua_S) @@ -1059,13 +799,13 @@ static int tolua_AllToLua_cIniFile_GetValueName01(lua_State* tolua_S) else { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); - const unsigned valueID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); + const int valueID = ((const int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetValueName'", NULL); #endif { - std::string tolua_ret = (std::string) self->GetValueName(keyID,valueID); + AString tolua_ret = (AString) self->GetValueName(keyID,valueID); tolua_pushcppstring(tolua_S,(const char*)tolua_ret); } } @@ -1164,8 +904,8 @@ static int tolua_AllToLua_cIniFile_GetValue02(lua_State* tolua_S) else { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); - const unsigned valueID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); + const int valueID = ((const int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetValue'", NULL); #endif @@ -1196,8 +936,8 @@ static int tolua_AllToLua_cIniFile_GetValue03(lua_State* tolua_S) else { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); - const unsigned valueID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); + const int valueID = ((const int) tolua_tonumber(tolua_S,3,0)); const AString defValue = ((const AString) tolua_tocppstring(tolua_S,4,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetValue'", NULL); @@ -1546,9 +1286,9 @@ static int tolua_AllToLua_cIniFile_SetValue00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); - const unsigned valueID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); - const std::string value = ((const std::string) tolua_tocppstring(tolua_S,4,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); + const int valueID = ((const int) tolua_tonumber(tolua_S,3,0)); + const AString value = ((const AString) tolua_tocppstring(tolua_S,4,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetValue'", NULL); #endif @@ -1584,9 +1324,9 @@ static int tolua_AllToLua_cIniFile_SetValue01(lua_State* tolua_S) else { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const std::string valuename = ((const std::string) tolua_tocppstring(tolua_S,3,0)); - const std::string value = ((const std::string) tolua_tocppstring(tolua_S,4,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); + const AString valuename = ((const AString) tolua_tocppstring(tolua_S,3,0)); + const AString value = ((const AString) tolua_tocppstring(tolua_S,4,0)); const bool create = ((const bool) tolua_toboolean(tolua_S,5,true)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetValue'", NULL); @@ -1624,8 +1364,8 @@ static int tolua_AllToLua_cIniFile_SetValueI00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const std::string valuename = ((const std::string) tolua_tocppstring(tolua_S,3,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); + const AString valuename = ((const AString) tolua_tocppstring(tolua_S,3,0)); const int value = ((const int) tolua_tonumber(tolua_S,4,0)); const bool create = ((const bool) tolua_toboolean(tolua_S,5,true)); #ifndef TOLUA_RELEASE @@ -1666,8 +1406,8 @@ static int tolua_AllToLua_cIniFile_SetValueB00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const std::string valuename = ((const std::string) tolua_tocppstring(tolua_S,3,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); + const AString valuename = ((const AString) tolua_tocppstring(tolua_S,3,0)); const bool value = ((const bool) tolua_toboolean(tolua_S,4,0)); const bool create = ((const bool) tolua_toboolean(tolua_S,5,true)); #ifndef TOLUA_RELEASE @@ -1708,8 +1448,8 @@ static int tolua_AllToLua_cIniFile_SetValueF00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const std::string valuename = ((const std::string) tolua_tocppstring(tolua_S,3,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); + const AString valuename = ((const AString) tolua_tocppstring(tolua_S,3,0)); const double value = ((const double) tolua_tonumber(tolua_S,4,0)); const bool create = ((const bool) tolua_toboolean(tolua_S,5,true)); #ifndef TOLUA_RELEASE @@ -1748,8 +1488,8 @@ static int tolua_AllToLua_cIniFile_DeleteValueByID00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); - const unsigned valueID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); + const int valueID = ((const int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeleteValueByID'", NULL); #endif @@ -1784,8 +1524,8 @@ static int tolua_AllToLua_cIniFile_DeleteValue00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const std::string valuename = ((const std::string) tolua_tocppstring(tolua_S,3,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); + const AString valuename = ((const AString) tolua_tocppstring(tolua_S,3,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeleteValue'", NULL); #endif @@ -1821,7 +1561,7 @@ static int tolua_AllToLua_cIniFile_DeleteKey00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeleteKey'", NULL); #endif @@ -1840,9 +1580,9 @@ static int tolua_AllToLua_cIniFile_DeleteKey00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: NumHeaderComments of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_NumHeaderComments00 -static int tolua_AllToLua_cIniFile_NumHeaderComments00(lua_State* tolua_S) +/* method: GetNumHeaderComments of class cIniFile */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetNumHeaderComments00 +static int tolua_AllToLua_cIniFile_GetNumHeaderComments00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -1856,25 +1596,25 @@ static int tolua_AllToLua_cIniFile_NumHeaderComments00(lua_State* tolua_S) { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NumHeaderComments'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetNumHeaderComments'", NULL); #endif { - unsigned tolua_ret = (unsigned) self->NumHeaderComments(); + int tolua_ret = (int) self->GetNumHeaderComments(); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'NumHeaderComments'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'GetNumHeaderComments'.",&tolua_err); return 0; #endif } #endif //#ifndef TOLUA_DISABLE -/* method: HeaderComment of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_HeaderComment00 -static int tolua_AllToLua_cIniFile_HeaderComment00(lua_State* tolua_S) +/* method: AddHeaderComment of class cIniFile */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_AddHeaderComment00 +static int tolua_AllToLua_cIniFile_AddHeaderComment00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -1888,28 +1628,29 @@ static int tolua_AllToLua_cIniFile_HeaderComment00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string comment = ((const std::string) tolua_tocppstring(tolua_S,2,0)); + const AString comment = ((const AString) tolua_tocppstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HeaderComment'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddHeaderComment'", NULL); #endif { - self->HeaderComment(comment); + self->AddHeaderComment(comment); tolua_pushcppstring(tolua_S,(const char*)comment); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'HeaderComment'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'AddHeaderComment'.",&tolua_err); return 0; #endif } #endif //#ifndef TOLUA_DISABLE -/* method: HeaderComment of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_HeaderComment01 -static int tolua_AllToLua_cIniFile_HeaderComment01(lua_State* tolua_S) +/* method: GetHeaderComment of class cIniFile */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetHeaderComment00 +static int tolua_AllToLua_cIniFile_GetHeaderComment00(lua_State* tolua_S) { +#ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) || @@ -1918,20 +1659,24 @@ static int tolua_AllToLua_cIniFile_HeaderComment01(lua_State* tolua_S) ) goto tolua_lerror; else +#endif { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned commentID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); + const int commentID = ((const int) tolua_tonumber(tolua_S,2,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HeaderComment'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetHeaderComment'", NULL); #endif { - std::string tolua_ret = (std::string) self->HeaderComment(commentID); + AString tolua_ret = (AString) self->GetHeaderComment(commentID); tolua_pushcppstring(tolua_S,(const char*)tolua_ret); } } return 1; -tolua_lerror: - return tolua_AllToLua_cIniFile_HeaderComment00(tolua_S); +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetHeaderComment'.",&tolua_err); + return 0; +#endif } #endif //#ifndef TOLUA_DISABLE @@ -1951,7 +1696,7 @@ static int tolua_AllToLua_cIniFile_DeleteHeaderComment00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - unsigned commentID = ((unsigned) tolua_tonumber(tolua_S,2,0)); + int commentID = ((int) tolua_tonumber(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeleteHeaderComment'", NULL); #endif @@ -2000,9 +1745,9 @@ static int tolua_AllToLua_cIniFile_DeleteHeaderComments00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE -/* method: NumKeyComments of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_NumKeyComments00 -static int tolua_AllToLua_cIniFile_NumKeyComments00(lua_State* tolua_S) +/* method: GetNumKeyComments of class cIniFile */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetNumKeyComments00 +static int tolua_AllToLua_cIniFile_GetNumKeyComments00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -2016,27 +1761,27 @@ static int tolua_AllToLua_cIniFile_NumKeyComments00(lua_State* tolua_S) #endif { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NumKeyComments'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetNumKeyComments'", NULL); #endif { - unsigned tolua_ret = (unsigned) self->NumKeyComments(keyID); + int tolua_ret = (int) self->GetNumKeyComments(keyID); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'NumKeyComments'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'GetNumKeyComments'.",&tolua_err); return 0; #endif } #endif //#ifndef TOLUA_DISABLE -/* method: NumKeyComments of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_NumKeyComments01 -static int tolua_AllToLua_cIniFile_NumKeyComments01(lua_State* tolua_S) +/* method: GetNumKeyComments of class cIniFile */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetNumKeyComments01 +static int tolua_AllToLua_cIniFile_GetNumKeyComments01(lua_State* tolua_S) { tolua_Error tolua_err; if ( @@ -2048,25 +1793,25 @@ static int tolua_AllToLua_cIniFile_NumKeyComments01(lua_State* tolua_S) else { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'NumKeyComments'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetNumKeyComments'", NULL); #endif { - unsigned tolua_ret = (unsigned) self->NumKeyComments(keyname); + int tolua_ret = (int) self->GetNumKeyComments(keyname); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); tolua_pushcppstring(tolua_S,(const char*)keyname); } } return 2; tolua_lerror: - return tolua_AllToLua_cIniFile_NumKeyComments00(tolua_S); + return tolua_AllToLua_cIniFile_GetNumKeyComments00(tolua_S); } #endif //#ifndef TOLUA_DISABLE -/* method: KeyComment of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_KeyComment00 -static int tolua_AllToLua_cIniFile_KeyComment00(lua_State* tolua_S) +/* method: AddKeyComment of class cIniFile */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_AddKeyComment00 +static int tolua_AllToLua_cIniFile_AddKeyComment00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; @@ -2081,13 +1826,13 @@ static int tolua_AllToLua_cIniFile_KeyComment00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); - const std::string comment = ((const std::string) tolua_tocppstring(tolua_S,3,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); + const AString comment = ((const AString) tolua_tocppstring(tolua_S,3,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'KeyComment'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddKeyComment'", NULL); #endif { - bool tolua_ret = (bool) self->KeyComment(keyID,comment); + bool tolua_ret = (bool) self->AddKeyComment(keyID,comment); tolua_pushboolean(tolua_S,(bool)tolua_ret); tolua_pushcppstring(tolua_S,(const char*)comment); } @@ -2095,15 +1840,15 @@ static int tolua_AllToLua_cIniFile_KeyComment00(lua_State* tolua_S) return 2; #ifndef TOLUA_RELEASE tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'KeyComment'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'AddKeyComment'.",&tolua_err); return 0; #endif } #endif //#ifndef TOLUA_DISABLE -/* method: KeyComment of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_KeyComment01 -static int tolua_AllToLua_cIniFile_KeyComment01(lua_State* tolua_S) +/* method: AddKeyComment of class cIniFile */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_AddKeyComment01 +static int tolua_AllToLua_cIniFile_AddKeyComment01(lua_State* tolua_S) { tolua_Error tolua_err; if ( @@ -2116,13 +1861,13 @@ static int tolua_AllToLua_cIniFile_KeyComment01(lua_State* tolua_S) else { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const std::string comment = ((const std::string) tolua_tocppstring(tolua_S,3,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); + const AString comment = ((const AString) tolua_tocppstring(tolua_S,3,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'KeyComment'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddKeyComment'", NULL); #endif { - bool tolua_ret = (bool) self->KeyComment(keyname,comment); + bool tolua_ret = (bool) self->AddKeyComment(keyname,comment); tolua_pushboolean(tolua_S,(bool)tolua_ret); tolua_pushcppstring(tolua_S,(const char*)keyname); tolua_pushcppstring(tolua_S,(const char*)comment); @@ -2130,14 +1875,15 @@ static int tolua_AllToLua_cIniFile_KeyComment01(lua_State* tolua_S) } return 3; tolua_lerror: - return tolua_AllToLua_cIniFile_KeyComment00(tolua_S); + return tolua_AllToLua_cIniFile_AddKeyComment00(tolua_S); } #endif //#ifndef TOLUA_DISABLE -/* method: KeyComment of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_KeyComment02 -static int tolua_AllToLua_cIniFile_KeyComment02(lua_State* tolua_S) +/* method: GetKeyComment of class cIniFile */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetKeyComment00 +static int tolua_AllToLua_cIniFile_GetKeyComment00(lua_State* tolua_S) { +#ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"const cIniFile",0,&tolua_err) || @@ -2147,27 +1893,31 @@ static int tolua_AllToLua_cIniFile_KeyComment02(lua_State* tolua_S) ) goto tolua_lerror; else +#endif { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); - const unsigned commentID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); + const int commentID = ((const int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'KeyComment'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetKeyComment'", NULL); #endif { - std::string tolua_ret = (std::string) self->KeyComment(keyID,commentID); + AString tolua_ret = (AString) self->GetKeyComment(keyID,commentID); tolua_pushcppstring(tolua_S,(const char*)tolua_ret); } } return 1; -tolua_lerror: - return tolua_AllToLua_cIniFile_KeyComment01(tolua_S); +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetKeyComment'.",&tolua_err); + return 0; +#endif } #endif //#ifndef TOLUA_DISABLE -/* method: KeyComment of class cIniFile */ -#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_KeyComment03 -static int tolua_AllToLua_cIniFile_KeyComment03(lua_State* tolua_S) +/* method: GetKeyComment of class cIniFile */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cIniFile_GetKeyComment01 +static int tolua_AllToLua_cIniFile_GetKeyComment01(lua_State* tolua_S) { tolua_Error tolua_err; if ( @@ -2180,20 +1930,20 @@ static int tolua_AllToLua_cIniFile_KeyComment03(lua_State* tolua_S) else { const cIniFile* self = (const cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const unsigned commentID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); + const int commentID = ((const int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE - if (!self) tolua_error(tolua_S,"invalid 'self' in function 'KeyComment'", NULL); + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetKeyComment'", NULL); #endif { - std::string tolua_ret = (std::string) self->KeyComment(keyname,commentID); + AString tolua_ret = (AString) self->GetKeyComment(keyname,commentID); tolua_pushcppstring(tolua_S,(const char*)tolua_ret); tolua_pushcppstring(tolua_S,(const char*)keyname); } } return 2; tolua_lerror: - return tolua_AllToLua_cIniFile_KeyComment02(tolua_S); + return tolua_AllToLua_cIniFile_GetKeyComment00(tolua_S); } #endif //#ifndef TOLUA_DISABLE @@ -2214,8 +1964,8 @@ static int tolua_AllToLua_cIniFile_DeleteKeyComment00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); - const unsigned commentID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); + const int commentID = ((const int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeleteKeyComment'", NULL); #endif @@ -2248,8 +1998,8 @@ static int tolua_AllToLua_cIniFile_DeleteKeyComment01(lua_State* tolua_S) else { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); - const unsigned commentID = ((const unsigned) tolua_tonumber(tolua_S,3,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); + const int commentID = ((const int) tolua_tonumber(tolua_S,3,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeleteKeyComment'", NULL); #endif @@ -2281,7 +2031,7 @@ static int tolua_AllToLua_cIniFile_DeleteKeyComments00(lua_State* tolua_S) #endif { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const unsigned keyID = ((const unsigned) tolua_tonumber(tolua_S,2,0)); + const int keyID = ((const int) tolua_tonumber(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeleteKeyComments'", NULL); #endif @@ -2313,7 +2063,7 @@ static int tolua_AllToLua_cIniFile_DeleteKeyComments01(lua_State* tolua_S) else { cIniFile* self = (cIniFile*) tolua_tousertype(tolua_S,1,0); - const std::string keyname = ((const std::string) tolua_tocppstring(tolua_S,2,0)); + const AString keyname = ((const AString) tolua_tocppstring(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeleteKeyComments'", NULL); #endif @@ -29350,22 +29100,14 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"ReadFile",tolua_AllToLua_cIniFile_ReadFile00); tolua_function(tolua_S,"WriteFile",tolua_AllToLua_cIniFile_WriteFile00); tolua_function(tolua_S,"Clear",tolua_AllToLua_cIniFile_Clear00); - tolua_function(tolua_S,"Reset",tolua_AllToLua_cIniFile_Reset00); - tolua_function(tolua_S,"Erase",tolua_AllToLua_cIniFile_Erase00); tolua_function(tolua_S,"FindKey",tolua_AllToLua_cIniFile_FindKey00); tolua_function(tolua_S,"FindValue",tolua_AllToLua_cIniFile_FindValue00); - tolua_function(tolua_S,"NumKeys",tolua_AllToLua_cIniFile_NumKeys00); tolua_function(tolua_S,"GetNumKeys",tolua_AllToLua_cIniFile_GetNumKeys00); tolua_function(tolua_S,"AddKeyName",tolua_AllToLua_cIniFile_AddKeyName00); - tolua_function(tolua_S,"KeyName",tolua_AllToLua_cIniFile_KeyName00); tolua_function(tolua_S,"GetKeyName",tolua_AllToLua_cIniFile_GetKeyName00); - tolua_function(tolua_S,"NumValues",tolua_AllToLua_cIniFile_NumValues00); tolua_function(tolua_S,"GetNumValues",tolua_AllToLua_cIniFile_GetNumValues00); - tolua_function(tolua_S,"NumValues",tolua_AllToLua_cIniFile_NumValues01); tolua_function(tolua_S,"GetNumValues",tolua_AllToLua_cIniFile_GetNumValues01); - tolua_function(tolua_S,"ValueName",tolua_AllToLua_cIniFile_ValueName00); tolua_function(tolua_S,"GetValueName",tolua_AllToLua_cIniFile_GetValueName00); - tolua_function(tolua_S,"ValueName",tolua_AllToLua_cIniFile_ValueName01); tolua_function(tolua_S,"GetValueName",tolua_AllToLua_cIniFile_GetValueName01); tolua_function(tolua_S,"GetValue",tolua_AllToLua_cIniFile_GetValue00); tolua_function(tolua_S,"GetValue",tolua_AllToLua_cIniFile_GetValue01); @@ -29387,17 +29129,17 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"DeleteValueByID",tolua_AllToLua_cIniFile_DeleteValueByID00); tolua_function(tolua_S,"DeleteValue",tolua_AllToLua_cIniFile_DeleteValue00); tolua_function(tolua_S,"DeleteKey",tolua_AllToLua_cIniFile_DeleteKey00); - tolua_function(tolua_S,"NumHeaderComments",tolua_AllToLua_cIniFile_NumHeaderComments00); - tolua_function(tolua_S,"HeaderComment",tolua_AllToLua_cIniFile_HeaderComment00); - tolua_function(tolua_S,"HeaderComment",tolua_AllToLua_cIniFile_HeaderComment01); + tolua_function(tolua_S,"GetNumHeaderComments",tolua_AllToLua_cIniFile_GetNumHeaderComments00); + tolua_function(tolua_S,"AddHeaderComment",tolua_AllToLua_cIniFile_AddHeaderComment00); + tolua_function(tolua_S,"GetHeaderComment",tolua_AllToLua_cIniFile_GetHeaderComment00); tolua_function(tolua_S,"DeleteHeaderComment",tolua_AllToLua_cIniFile_DeleteHeaderComment00); tolua_function(tolua_S,"DeleteHeaderComments",tolua_AllToLua_cIniFile_DeleteHeaderComments00); - tolua_function(tolua_S,"NumKeyComments",tolua_AllToLua_cIniFile_NumKeyComments00); - tolua_function(tolua_S,"NumKeyComments",tolua_AllToLua_cIniFile_NumKeyComments01); - tolua_function(tolua_S,"KeyComment",tolua_AllToLua_cIniFile_KeyComment00); - tolua_function(tolua_S,"KeyComment",tolua_AllToLua_cIniFile_KeyComment01); - tolua_function(tolua_S,"KeyComment",tolua_AllToLua_cIniFile_KeyComment02); - tolua_function(tolua_S,"KeyComment",tolua_AllToLua_cIniFile_KeyComment03); + tolua_function(tolua_S,"GetNumKeyComments",tolua_AllToLua_cIniFile_GetNumKeyComments00); + tolua_function(tolua_S,"GetNumKeyComments",tolua_AllToLua_cIniFile_GetNumKeyComments01); + tolua_function(tolua_S,"AddKeyComment",tolua_AllToLua_cIniFile_AddKeyComment00); + tolua_function(tolua_S,"AddKeyComment",tolua_AllToLua_cIniFile_AddKeyComment01); + tolua_function(tolua_S,"GetKeyComment",tolua_AllToLua_cIniFile_GetKeyComment00); + tolua_function(tolua_S,"GetKeyComment",tolua_AllToLua_cIniFile_GetKeyComment01); tolua_function(tolua_S,"DeleteKeyComment",tolua_AllToLua_cIniFile_DeleteKeyComment00); tolua_function(tolua_S,"DeleteKeyComment",tolua_AllToLua_cIniFile_DeleteKeyComment01); tolua_function(tolua_S,"DeleteKeyComments",tolua_AllToLua_cIniFile_DeleteKeyComments00); diff --git a/source/Bindings.h b/source/Bindings.h index 58f6023c1..edcdfd12f 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/25/13 10:38:51. +** Generated automatically by tolua++-1.0.92 on 10/25/13 11:34:58. */ /* Exported function */ diff --git a/source/BlockID.cpp b/source/BlockID.cpp index 2e957593b..7193094d8 100644 --- a/source/BlockID.cpp +++ b/source/BlockID.cpp @@ -47,15 +47,15 @@ public: { return; } - long KeyID = Ini.FindKey("Items"); + int KeyID = Ini.FindKey("Items"); if (KeyID == cIniFile::noID) { return; } - unsigned NumValues = Ini.GetNumValues(KeyID); - for (unsigned i = 0; i < NumValues; i++) + int NumValues = Ini.GetNumValues(KeyID); + for (int i = 0; i < NumValues; i++) { - AString Name = Ini.ValueName(KeyID, i); + AString Name = Ini.GetValueName(KeyID, i); if (Name.empty()) { continue; diff --git a/source/MonsterConfig.cpp b/source/MonsterConfig.cpp index 69d639bdb..a5a1ebd49 100644 --- a/source/MonsterConfig.cpp +++ b/source/MonsterConfig.cpp @@ -63,10 +63,10 @@ void cMonsterConfig::Initialize() return; } - for (int i = (int)MonstersIniFile.NumKeys(); i >= 0; i--) + for (int i = (int)MonstersIniFile.GetNumKeys(); i >= 0; i--) { sAttributesStruct Attributes; - AString Name = MonstersIniFile.KeyName(i); + AString Name = MonstersIniFile.GetKeyName(i); Attributes.m_Name = Name; Attributes.m_AttackDamage = MonstersIniFile.GetValueF(Name, "AttackDamage", 0); Attributes.m_AttackRange = MonstersIniFile.GetValueF(Name, "AttackRange", 0); -- cgit v1.2.3 From 77661f4c594190ff93de4924d62aaac9e112e8a2 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 26 Oct 2013 17:08:28 +0200 Subject: Both the LoadWorlds() function and cAuthenticator now use the cIniFile object from the Root::Start() function. --- source/Authenticator.cpp | 12 +++--------- source/Authenticator.h | 4 ++-- source/Root.cpp | 8 +++----- source/Root.h | 2 +- 4 files changed, 9 insertions(+), 17 deletions(-) (limited to 'source') diff --git a/source/Authenticator.cpp b/source/Authenticator.cpp index a45617f93..a8aad524f 100644 --- a/source/Authenticator.cpp +++ b/source/Authenticator.cpp @@ -28,7 +28,6 @@ cAuthenticator::cAuthenticator(void) : m_Address(DEFAULT_AUTH_ADDRESS), m_ShouldAuthenticate(true) { - ReadINI(); } @@ -45,14 +44,8 @@ cAuthenticator::~cAuthenticator() /// Read custom values from INI -void cAuthenticator::ReadINI(void) +void cAuthenticator::ReadINI(cIniFile IniFile) { - cIniFile IniFile("settings.ini"); - if (!IniFile.ReadFile()) - { - return; - } - m_Server = IniFile.GetValue("Authentication", "Server"); m_Address = IniFile.GetValue("Authentication", "Address"); m_ShouldAuthenticate = IniFile.GetValueB("Authentication", "Authenticate", true); @@ -100,8 +93,9 @@ void cAuthenticator::Authenticate(int a_ClientID, const AString & a_UserName, co -void cAuthenticator::Start(void) +void cAuthenticator::Start(cIniFile IniFile) { + ReadINI(IniFile); m_ShouldTerminate = false; super::Start(); } diff --git a/source/Authenticator.h b/source/Authenticator.h index 868476d80..9c7c57e6d 100644 --- a/source/Authenticator.h +++ b/source/Authenticator.h @@ -37,13 +37,13 @@ public: ~cAuthenticator(); /// (Re-)read server and address from INI: - void ReadINI(void); + void ReadINI(cIniFile IniFile); /// Queues a request for authenticating a user. If the auth fails, the user is kicked void Authenticate(int a_ClientID, const AString & a_UserName, const AString & a_ServerHash); /// Starts the authenticator thread. The thread may be started and stopped repeatedly - void Start(void); + void Start(cIniFile IniFile); /// Stops the authenticator thread. The thread may be started and stopped repeatedly void Stop(void); diff --git a/source/Root.cpp b/source/Root.cpp index 1f6437784..df98c3537 100644 --- a/source/Root.cpp +++ b/source/Root.cpp @@ -149,7 +149,7 @@ void cRoot::Start(void) m_FurnaceRecipe = new cFurnaceRecipe(); LOGD("Loading worlds..."); - LoadWorlds(); + LoadWorlds(IniFile); LOGD("Loading plugin manager..."); m_PluginManager = new cPluginManager(); @@ -160,7 +160,7 @@ void cRoot::Start(void) // This sets stuff in motion LOGD("Starting Authenticator..."); - m_Authenticator.Start(); + m_Authenticator.Start(IniFile); LOGD("Starting worlds..."); StartWorlds(); @@ -245,10 +245,8 @@ void cRoot::LoadGlobalSettings() -void cRoot::LoadWorlds(void) +void cRoot::LoadWorlds(cIniFile IniFile) { - cIniFile IniFile("settings.ini"); IniFile.ReadFile(); - // First get the default world AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world"); m_pDefaultWorld = new cWorld( DefaultWorldName.c_str() ); diff --git a/source/Root.h b/source/Root.h index c05b29d14..6bd8217d9 100644 --- a/source/Root.h +++ b/source/Root.h @@ -162,7 +162,7 @@ private: void LoadGlobalSettings(); /// Loads the worlds from settings.ini, creates the worldmap - void LoadWorlds(void); + void LoadWorlds(cIniFile IniFile); /// Starts each world's life void StartWorlds(void); -- cgit v1.2.3 From cb06f35cb80c2162c3b1e9e329fc81b5d8b417da Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 26 Oct 2013 19:47:12 +0200 Subject: Changed "cIniFile IniFile" to cIniFile & IniFile" --- source/Authenticator.cpp | 4 ++-- source/Authenticator.h | 4 ++-- source/Root.cpp | 2 +- source/Root.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source') diff --git a/source/Authenticator.cpp b/source/Authenticator.cpp index a8aad524f..368431010 100644 --- a/source/Authenticator.cpp +++ b/source/Authenticator.cpp @@ -44,7 +44,7 @@ cAuthenticator::~cAuthenticator() /// Read custom values from INI -void cAuthenticator::ReadINI(cIniFile IniFile) +void cAuthenticator::ReadINI(cIniFile & IniFile) { m_Server = IniFile.GetValue("Authentication", "Server"); m_Address = IniFile.GetValue("Authentication", "Address"); @@ -93,7 +93,7 @@ void cAuthenticator::Authenticate(int a_ClientID, const AString & a_UserName, co -void cAuthenticator::Start(cIniFile IniFile) +void cAuthenticator::Start(cIniFile & IniFile) { ReadINI(IniFile); m_ShouldTerminate = false; diff --git a/source/Authenticator.h b/source/Authenticator.h index 9c7c57e6d..02cd6f4c5 100644 --- a/source/Authenticator.h +++ b/source/Authenticator.h @@ -37,13 +37,13 @@ public: ~cAuthenticator(); /// (Re-)read server and address from INI: - void ReadINI(cIniFile IniFile); + void ReadINI(cIniFile & IniFile); /// Queues a request for authenticating a user. If the auth fails, the user is kicked void Authenticate(int a_ClientID, const AString & a_UserName, const AString & a_ServerHash); /// Starts the authenticator thread. The thread may be started and stopped repeatedly - void Start(cIniFile IniFile); + void Start(cIniFile & IniFile); /// Stops the authenticator thread. The thread may be started and stopped repeatedly void Stop(void); diff --git a/source/Root.cpp b/source/Root.cpp index df98c3537..346bb2c9f 100644 --- a/source/Root.cpp +++ b/source/Root.cpp @@ -245,7 +245,7 @@ void cRoot::LoadGlobalSettings() -void cRoot::LoadWorlds(cIniFile IniFile) +void cRoot::LoadWorlds(cIniFile & IniFile) { // First get the default world AString DefaultWorldName = IniFile.GetValueSet("Worlds", "DefaultWorld", "world"); diff --git a/source/Root.h b/source/Root.h index 6bd8217d9..175084c53 100644 --- a/source/Root.h +++ b/source/Root.h @@ -162,7 +162,7 @@ private: void LoadGlobalSettings(); /// Loads the worlds from settings.ini, creates the worldmap - void LoadWorlds(cIniFile IniFile); + void LoadWorlds(cIniFile & IniFile); /// Starts each world's life void StartWorlds(void); -- cgit v1.2.3 From a7d44d69ddd8bfd5cd749dc9bcdf23597ae6d1cd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Oct 2013 09:09:39 +0100 Subject: Authenticator doesn't save the ini file. Didn't load it -> shouldn't save it. --- source/Authenticator.cpp | 1 - source/Root.cpp | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/Authenticator.cpp b/source/Authenticator.cpp index a32e9ce8f..e09fd0871 100644 --- a/source/Authenticator.cpp +++ b/source/Authenticator.cpp @@ -67,7 +67,6 @@ void cAuthenticator::ReadINI(cIniFile & IniFile) if (bSave) { IniFile.SetValueB("Authentication", "Authenticate", m_ShouldAuthenticate); - IniFile.WriteFile("settings.ini"); } } diff --git a/source/Root.cpp b/source/Root.cpp index 2397fc875..e992ff614 100644 --- a/source/Root.cpp +++ b/source/Root.cpp @@ -138,7 +138,6 @@ void cRoot::Start(void) LOGERROR("Failure starting server, aborting..."); return; } - IniFile.WriteFile("settings.ini"); m_WebAdmin = new cWebAdmin(); m_WebAdmin->Init(); @@ -162,6 +161,8 @@ void cRoot::Start(void) LOGD("Starting Authenticator..."); m_Authenticator.Start(IniFile); + IniFile.WriteFile("settings.ini"); + LOGD("Starting worlds..."); StartWorlds(); -- cgit v1.2.3 From 3fa03e854f02f8046ace97d184647c0594e3f23c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 27 Oct 2013 09:19:13 +0100 Subject: Added cChunk::UnboundedRelGetBlockLights(). This queries both BlockLight and SkyLight for the specified block. --- source/Chunk.cpp | 23 +++++++++++++++++++++++ source/Chunk.h | 5 +++++ 2 files changed, 28 insertions(+) (limited to 'source') diff --git a/source/Chunk.cpp b/source/Chunk.cpp index c7bac879a..c9d457af3 100644 --- a/source/Chunk.cpp +++ b/source/Chunk.cpp @@ -1155,6 +1155,29 @@ bool cChunk::UnboundedRelGetBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NI +bool cChunk::UnboundedRelGetBlockLights(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE & a_BlockLight, NIBBLETYPE & a_SkyLight) const +{ + if ((a_RelY < 0) || (a_RelY >= cChunkDef::Height)) + { + LOGWARNING("%s: requesting a block with a_RelY out of range: %d", __FUNCTION__, a_RelY); + return false; + } + cChunk * Chunk = GetRelNeighborChunkAdjustCoords(a_RelX, a_RelZ); + if ((Chunk == NULL) || !Chunk->IsValid()) + { + // The chunk is not available, bail out + return false; + } + int idx = Chunk->MakeIndex(a_RelX, a_RelY, a_RelZ); + a_BlockLight = Chunk->GetBlockLight(idx); + a_SkyLight = Chunk->GetSkyLight(idx); + return true; +} + + + + + bool cChunk::UnboundedRelSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { if ((a_RelY < 0) || (a_RelY > cChunkDef::Height)) diff --git a/source/Chunk.h b/source/Chunk.h index e709a4718..ab110c7cb 100644 --- a/source/Chunk.h +++ b/source/Chunk.h @@ -299,6 +299,8 @@ public: inline NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const {return cChunkDef::GetNibble(m_BlockLight, a_RelX, a_RelY, a_RelZ); } inline NIBBLETYPE GetSkyLight (int a_RelX, int a_RelY, int a_RelZ) const {return cChunkDef::GetNibble(m_BlockSkyLight, a_RelX, a_RelY, a_RelZ); } + inline NIBBLETYPE GetBlockLight(int a_Idx) const {return cChunkDef::GetNibble(m_BlockLight, a_Idx); } + inline NIBBLETYPE GetSkyLight (int a_Idx) const {return cChunkDef::GetNibble(m_BlockSkyLight, a_Idx); } /// Same as GetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success bool UnboundedRelGetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; @@ -315,6 +317,9 @@ public: /// Same as GetBlockSkyLight(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success bool UnboundedRelGetBlockSkyLight(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE & a_SkyLight) const; + /// Queries both BlockLight and SkyLight, relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success + bool UnboundedRelGetBlockLights(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE & a_BlockLight, NIBBLETYPE & a_SkyLight) const; + /// Same as SetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success bool UnboundedRelSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); -- cgit v1.2.3 From a42561cf5a2e8cf86848cb1925097173787de808 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Sun, 27 Oct 2013 10:41:25 +0100 Subject: Sheep fixes. Now amount of wool you get when shearing a sheep is random. Sheeps only spawn in white color (I will add sheep dying soon). --- source/Mobs/Sheep.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'source') diff --git a/source/Mobs/Sheep.cpp b/source/Mobs/Sheep.cpp index 0d7d43e27..54cce9cbe 100644 --- a/source/Mobs/Sheep.cpp +++ b/source/Mobs/Sheep.cpp @@ -1,4 +1,3 @@ - #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Sheep.h" @@ -13,7 +12,7 @@ cSheep::cSheep(int a_Color) : super("Sheep", mtSheep, "mob.sheep.say", "mob.sheep.say", 0.6, 1.3), m_IsSheared(false), - m_WoolColor(a_Color) + m_WoolColor(0) { } @@ -33,6 +32,7 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer) + void cSheep::OnRightClicked(cPlayer & a_Player) { if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_SHEARS) && (!m_IsSheared)) @@ -46,11 +46,26 @@ void cSheep::OnRightClicked(cPlayer & a_Player) } cItems Drops; - Drops.push_back(cItem(E_BLOCK_WOOL, 4, m_WoolColor)); - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + int wooldrops = m_World->GetTickRandomNumber(2); + if (wooldrops == 0) + { + Drops.push_back(cItem(E_BLOCK_WOOL, 1, m_WoolColor)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + } + if (wooldrops == 1) + { + Drops.push_back(cItem(E_BLOCK_WOOL, 2, m_WoolColor)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + } + if (wooldrops == 2) + { + Drops.push_back(cItem(E_BLOCK_WOOL, 3, m_WoolColor)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + } } } + -- cgit v1.2.3 From 144b528257140710856d6150e854b08f0e5368b9 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Sun, 27 Oct 2013 10:42:16 +0100 Subject: Extra line --- source/Mobs/Sheep.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'source') diff --git a/source/Mobs/Sheep.cpp b/source/Mobs/Sheep.cpp index 54cce9cbe..2a92cf5b2 100644 --- a/source/Mobs/Sheep.cpp +++ b/source/Mobs/Sheep.cpp @@ -1,3 +1,4 @@ + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Sheep.h" -- cgit v1.2.3 From df20c19986805380cfd728d63f2e3003331b1665 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 28 Oct 2013 13:30:24 +0100 Subject: Renamed cWindow constants to include the "wt" prefix. --- source/Bindings.cpp | 24 ++++++++++++------------ source/Bindings.h | 2 +- source/ClientHandle.cpp | 4 ++-- source/LuaWindow.cpp | 4 ++-- source/Protocol/Protocol125.cpp | 2 +- source/UI/SlotArea.cpp | 2 +- source/UI/Window.cpp | 20 ++++++++++---------- source/UI/Window.h | 22 +++++++++++----------- 8 files changed, 40 insertions(+), 40 deletions(-) (limited to 'source') diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 5de3a3b38..8259eda81 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/25/13 11:34:58. +** Generated automatically by tolua++-1.0.92 on 10/28/13 13:11:03. */ #ifndef __cplusplus @@ -31025,17 +31025,17 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_endmodule(tolua_S); tolua_cclass(tolua_S,"cWindow","cWindow","",NULL); tolua_beginmodule(tolua_S,"cWindow"); - tolua_constant(tolua_S,"Inventory",cWindow::Inventory); - tolua_constant(tolua_S,"Chest",cWindow::Chest); - tolua_constant(tolua_S,"Workbench",cWindow::Workbench); - tolua_constant(tolua_S,"Furnace",cWindow::Furnace); - tolua_constant(tolua_S,"DropSpenser",cWindow::DropSpenser); - tolua_constant(tolua_S,"Enchantment",cWindow::Enchantment); - tolua_constant(tolua_S,"Brewery",cWindow::Brewery); - tolua_constant(tolua_S,"NPCTrade",cWindow::NPCTrade); - tolua_constant(tolua_S,"Beacon",cWindow::Beacon); - tolua_constant(tolua_S,"Anvil",cWindow::Anvil); - tolua_constant(tolua_S,"Hopper",cWindow::Hopper); + tolua_constant(tolua_S,"wtInventory",cWindow::wtInventory); + tolua_constant(tolua_S,"wtChest",cWindow::wtChest); + tolua_constant(tolua_S,"wtWorkbench",cWindow::wtWorkbench); + tolua_constant(tolua_S,"wtFurnace",cWindow::wtFurnace); + tolua_constant(tolua_S,"wtDropSpenser",cWindow::wtDropSpenser); + tolua_constant(tolua_S,"wtEnchantment",cWindow::wtEnchantment); + tolua_constant(tolua_S,"wtBrewery",cWindow::wtBrewery); + tolua_constant(tolua_S,"wtNPCTrade",cWindow::wtNPCTrade); + tolua_constant(tolua_S,"wtBeacon",cWindow::wtBeacon); + tolua_constant(tolua_S,"wtAnvil",cWindow::wtAnvil); + tolua_constant(tolua_S,"wtHopper",cWindow::wtHopper); tolua_function(tolua_S,"GetWindowID",tolua_AllToLua_cWindow_GetWindowID00); tolua_function(tolua_S,"GetWindowType",tolua_AllToLua_cWindow_GetWindowType00); tolua_function(tolua_S,"GetSlot",tolua_AllToLua_cWindow_GetSlot00); diff --git a/source/Bindings.h b/source/Bindings.h index edcdfd12f..411e608d9 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/25/13 11:34:58. +** Generated automatically by tolua++-1.0.92 on 10/28/13 13:11:04. */ /* Exported function */ diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index f67a546fd..90802aa71 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -469,12 +469,12 @@ bool cClientHandle::HandleLogin(int a_ProtocolVersion, const AString & a_Usernam void cClientHandle::HandleCreativeInventory(short a_SlotNum, const cItem & a_HeldItem) { // This is for creative Inventory changes - if (m_Player->GetGameMode() != eGameMode_Creative) + if (m_Player->IsGameModeCreative()) { LOGWARNING("Got a CreativeInventoryAction packet from user \"%s\" while not in creative mode. Ignoring.", m_Username.c_str()); return; } - if (m_Player->GetWindow()->GetWindowType() != cWindow::Inventory) + if (m_Player->GetWindow()->GetWindowType() != cWindow::wtInventory) { LOGWARNING("Got a CreativeInventoryAction packet from user \"%s\" while not in the inventory window. Ignoring.", m_Username.c_str()); return; diff --git a/source/LuaWindow.cpp b/source/LuaWindow.cpp index a0609f746..9011d668c 100644 --- a/source/LuaWindow.cpp +++ b/source/LuaWindow.cpp @@ -31,8 +31,8 @@ cLuaWindow::cLuaWindow(cWindow::WindowType a_WindowType, int a_SlotsX, int a_Slo // If appropriate, add an Armor slot area: switch (a_WindowType) { - case cWindow::Inventory: - case cWindow::Workbench: + case cWindow::wtInventory: + case cWindow::wtWorkbench: { m_SlotAreas.push_back(new cSlotAreaArmor(*this)); break; diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index fb7315468..ef40f265a 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -963,7 +963,7 @@ void cProtocol125::SendWholeInventory(const cWindow & a_Window) void cProtocol125::SendWindowClose(const cWindow & a_Window) { - if (a_Window.GetWindowType() == cWindow::Inventory) + if (a_Window.GetWindowType() == cWindow::wtInventory) { // Do not send inventory-window-close return; diff --git a/source/UI/SlotArea.cpp b/source/UI/SlotArea.cpp index 463e56bce..82e87e126 100644 --- a/source/UI/SlotArea.cpp +++ b/source/UI/SlotArea.cpp @@ -559,7 +559,7 @@ cSlotAreaInventoryBase::cSlotAreaInventoryBase(int a_NumSlots, int a_SlotOffset, void cSlotAreaInventoryBase::Clicked(cPlayer & a_Player, int a_SlotNum, eClickAction a_ClickAction, const cItem & a_ClickedItem) { - if ((a_Player.GetGameMode() == eGameMode_Creative) && (m_ParentWindow.GetWindowType() == cWindow::Inventory)) + if (a_Player.IsGameModeCreative() && (m_ParentWindow.GetWindowType() == cWindow::wtInventory)) { // Creative inventory must treat a_ClickedItem as a DraggedItem instead, replacing the inventory slot with it SetSlot(a_SlotNum, a_Player, a_ClickedItem); diff --git a/source/UI/Window.cpp b/source/UI/Window.cpp index 2794abe22..1318cbca8 100644 --- a/source/UI/Window.cpp +++ b/source/UI/Window.cpp @@ -23,7 +23,7 @@ char cWindow::m_WindowIDCounter = 1; -cWindow::cWindow(cWindow::WindowType a_WindowType, const AString & a_WindowTitle) : +cWindow::cWindow(WindowType a_WindowType, const AString & a_WindowTitle) : m_WindowID((++m_WindowIDCounter) % 127), m_WindowType(a_WindowType), m_WindowTitle(a_WindowTitle), @@ -31,7 +31,7 @@ cWindow::cWindow(cWindow::WindowType a_WindowType, const AString & a_WindowTitle m_IsDestroyed(false), m_ShouldDistributeToHotbarFirst(true) { - if (a_WindowType == Inventory) + if (a_WindowType == wtInventory) { m_WindowID = 0; } @@ -277,7 +277,7 @@ bool cWindow::ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse) m_OpenedBy.remove(&a_Player); - if ((m_WindowType != Inventory) && m_OpenedBy.empty()) + if ((m_WindowType != wtInventory) && m_OpenedBy.empty()) { Destroy(); } @@ -703,7 +703,7 @@ void cWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player) // cInventoryWindow: cInventoryWindow::cInventoryWindow(cPlayer & a_Player) : - cWindow(cWindow::Inventory, "Inventory"), + cWindow(wtInventory, "Inventory"), m_Player(a_Player) { m_SlotAreas.push_back(new cSlotAreaCrafting(2, *this)); // The creative inventory doesn't display it, but it's still counted into slot numbers @@ -720,7 +720,7 @@ cInventoryWindow::cInventoryWindow(cPlayer & a_Player) : // cCraftingWindow: cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : - cWindow(cWindow::Workbench, "Crafting Table") + cWindow(wtWorkbench, "Crafting Table") { m_SlotAreas.push_back(new cSlotAreaCrafting(3, *this)); m_SlotAreas.push_back(new cSlotAreaInventory(*this)); @@ -735,7 +735,7 @@ cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) : // cChestWindow: cChestWindow::cChestWindow(cChestEntity * a_Chest) : - cWindow(cWindow::Chest, "Chest"), + cWindow(wtChest, "Chest"), m_World(a_Chest->GetWorld()), m_BlockX(a_Chest->GetPosX()), m_BlockY(a_Chest->GetPosY()), @@ -757,7 +757,7 @@ cChestWindow::cChestWindow(cChestEntity * a_Chest) : cChestWindow::cChestWindow(cChestEntity * a_PrimaryChest, cChestEntity * a_SecondaryChest) : - cWindow(cWindow::Chest, "Double Chest"), + cWindow(wtChest, "Double Chest"), m_World(a_PrimaryChest->GetWorld()), m_BlockX(a_PrimaryChest->GetPosX()), m_BlockY(a_PrimaryChest->GetPosY()), @@ -796,7 +796,7 @@ cChestWindow::~cChestWindow() // cDropSpenserWindow: cDropSpenserWindow::cDropSpenserWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cDropSpenserEntity * a_DropSpenser) : - cWindow(cWindow::DropSpenser, "Dropspenser") + cWindow(wtDropSpenser, "Dropspenser") { m_ShouldDistributeToHotbarFirst = false; m_SlotAreas.push_back(new cSlotAreaItemGrid(a_DropSpenser->GetContents(), *this)); @@ -812,7 +812,7 @@ cDropSpenserWindow::cDropSpenserWindow(int a_BlockX, int a_BlockY, int a_BlockZ, // cHopperWindow: cHopperWindow::cHopperWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cHopperEntity * a_Hopper) : - super(cWindow::Hopper, "Hopper") + super(wtHopper, "Hopper") { m_ShouldDistributeToHotbarFirst = false; m_SlotAreas.push_back(new cSlotAreaItemGrid(a_Hopper->GetContents(), *this)); @@ -828,7 +828,7 @@ cHopperWindow::cHopperWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cHopperEn // cFurnaceWindow: cFurnaceWindow::cFurnaceWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceEntity * a_Furnace) : - cWindow(cWindow::Furnace, "Furnace") + cWindow(wtFurnace, "Furnace") { m_ShouldDistributeToHotbarFirst = false; m_SlotAreas.push_back(new cSlotAreaFurnace(a_Furnace, *this)); diff --git a/source/UI/Window.h b/source/UI/Window.h index aa7e9d0d0..2d5e81e9e 100644 --- a/source/UI/Window.h +++ b/source/UI/Window.h @@ -49,17 +49,17 @@ class cWindow public: enum WindowType { - Inventory = -1, // This value is never actually sent to a client - Chest = 0, - Workbench = 1, - Furnace = 2, - DropSpenser = 3, // Dropper or Dispenser - Enchantment = 4, - Brewery = 5, - NPCTrade = 6, - Beacon = 7, - Anvil = 8, - Hopper = 9, + wtInventory = -1, // This value is never actually sent to a client + wtChest = 0, + wtWorkbench = 1, + wtFurnace = 2, + wtDropSpenser = 3, // Dropper or Dispenser + wtEnchantment = 4, + wtBrewery = 5, + wtNPCTrade = 6, + wtBeacon = 7, + wtAnvil = 8, + wtHopper = 9, }; // tolua_end -- cgit v1.2.3 From 6e554c3b5256c43feb4be66f46b08e9d6440f7b3 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Mon, 28 Oct 2013 19:42:02 +0100 Subject: Use STR_Warrior code and changed variable name --- source/Mobs/Sheep.cpp | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'source') diff --git a/source/Mobs/Sheep.cpp b/source/Mobs/Sheep.cpp index 2a92cf5b2..46749d967 100644 --- a/source/Mobs/Sheep.cpp +++ b/source/Mobs/Sheep.cpp @@ -13,7 +13,7 @@ cSheep::cSheep(int a_Color) : super("Sheep", mtSheep, "mob.sheep.say", "mob.sheep.say", 0.6, 1.3), m_IsSheared(false), - m_WoolColor(0) + m_WoolColor(a_Color) { } @@ -47,22 +47,9 @@ void cSheep::OnRightClicked(cPlayer & a_Player) } cItems Drops; - int wooldrops = m_World->GetTickRandomNumber(2); - if (wooldrops == 0) - { - Drops.push_back(cItem(E_BLOCK_WOOL, 1, m_WoolColor)); - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); - } - if (wooldrops == 1) - { - Drops.push_back(cItem(E_BLOCK_WOOL, 2, m_WoolColor)); - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); - } - if (wooldrops == 2) - { - Drops.push_back(cItem(E_BLOCK_WOOL, 3, m_WoolColor)); - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); - } + int NumDrops = m_World->GetTickRandomumber(2) + 1 + Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); } } -- cgit v1.2.3 From 984277f65e6781ffffc89b7bd382879eda8c8fe6 Mon Sep 17 00:00:00 2001 From: tonibm19 Date: Mon, 28 Oct 2013 19:47:38 +0100 Subject: Fixed compilation STR_Warrior code had an error (I copied&pasted it before) --- source/Mobs/Sheep.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source') diff --git a/source/Mobs/Sheep.cpp b/source/Mobs/Sheep.cpp index 46749d967..5a3b2d015 100644 --- a/source/Mobs/Sheep.cpp +++ b/source/Mobs/Sheep.cpp @@ -47,7 +47,7 @@ void cSheep::OnRightClicked(cPlayer & a_Player) } cItems Drops; - int NumDrops = m_World->GetTickRandomumber(2) + 1 + int NumDrops = m_World->GetTickRandomNumber(2) + 1; Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor)); m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); } -- cgit v1.2.3 From 1eac38f3d7c70295bf986ee02c849d50b3c4f7eb Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 28 Oct 2013 19:54:03 +0100 Subject: Fixed indentation in tonibm19's code. --- source/Mobs/Sheep.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/Mobs/Sheep.cpp b/source/Mobs/Sheep.cpp index 5a3b2d015..703482ddb 100644 --- a/source/Mobs/Sheep.cpp +++ b/source/Mobs/Sheep.cpp @@ -47,9 +47,9 @@ void cSheep::OnRightClicked(cPlayer & a_Player) } cItems Drops; - int NumDrops = m_World->GetTickRandomNumber(2) + 1; - Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor)); - m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); + int NumDrops = m_World->GetTickRandomNumber(2) + 1; + Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor)); + m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10); } } -- cgit v1.2.3 From c9b6c3bc2e3b6e9c06d7cd43345565bc88bb30f9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 28 Oct 2013 20:40:42 +0100 Subject: cByteBuffer: Added the VarInt and VarUTF8String type reading and writing. This implements #296. --- source/ByteBuffer.cpp | 130 +++++++++++++++++++++++++++++++++++++++++++++++++- source/ByteBuffer.h | 22 +++++++-- 2 files changed, 147 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/ByteBuffer.cpp b/source/ByteBuffer.cpp index c82951271..78cc1385e 100644 --- a/source/ByteBuffer.cpp +++ b/source/ByteBuffer.cpp @@ -13,8 +13,54 @@ -#define NEEDBYTES(Num) if (!CanReadBytes(Num)) return false; -#define PUTBYTES(Num) if (!CanWriteBytes(Num)) return false; +// If a string sent over the protocol is larger than this, a warning is emitted to the console +#define MAX_STRING_SIZE (512 KiB) + +#define NEEDBYTES(Num) if (!CanReadBytes(Num)) return false; // Check if at least Num bytes can be read from the buffer, return false if not +#define PUTBYTES(Num) if (!CanWriteBytes(Num)) return false; // Check if at least Num bytes can be written to the buffer, return false if not + + + + + +#if 0 + +/// Self-test of the VarInt-reading and writing code +class cByteBufferSelfTest +{ +public: + cByteBufferSelfTest(void) + { + TestRead(); + TestWrite(); + } + + void TestRead(void) + { + cByteBuffer buf(50); + buf.Write("\x05\xac\x02\x00", 4); + UInt64 v1; + ASSERT(buf.ReadVarInt(v1) && (v1 == 5)); + UInt64 v2; + ASSERT(buf.ReadVarInt(v2) && (v2 == 300)); + UInt64 v3; + ASSERT(buf.ReadVarInt(v3) && (v3 == 0)); + } + + void TestWrite(void) + { + cByteBuffer buf(50); + buf.WriteVarInt(5); + buf.WriteVarInt(300); + buf.WriteVarInt(0); + AString All; + buf.ReadAll(All); + ASSERT(All.size() == 4); + ASSERT(memcmp(All.data(), "\x05\xac\x02\x00", All.size()) == 0); + } +} g_ByteBufferTest; + +#endif @@ -328,6 +374,48 @@ bool cByteBuffer::ReadBEUTF16String16(AString & a_Value) +bool cByteBuffer::ReadVarInt(UInt64 & a_Value) +{ + CHECK_THREAD; + CheckValid(); + UInt64 Value = 0; + int Shift = 0; + unsigned char b = 0; + do + { + NEEDBYTES(1); + ReadBuf(&b, 1); + Value = Value | (((Int64)(b & 0x7f)) << Shift); + Shift += 7; + } while ((b & 0x80) != 0); + a_Value = Value; + return true; +} + + + + + +bool cByteBuffer::ReadVarUTF8String(AString & a_Value) +{ + CHECK_THREAD; + CheckValid(); + UInt64 Size = 0; + if (!ReadVarInt(Size)) + { + return false; + } + if (Size > MAX_STRING_SIZE) + { + LOGWARNING("%s: String too large: %llu (%llu KiB)", __FUNCTION__, Size, Size / 1024); + } + return ReadString(a_Value, (int)Size); +} + + + + + bool cByteBuffer::WriteChar(char a_Value) { CHECK_THREAD; @@ -446,6 +534,44 @@ bool cByteBuffer::WriteBEUTF16String16(const AString & a_Value) +bool cByteBuffer::WriteVarInt(UInt64 a_Value) +{ + CHECK_THREAD; + CheckValid(); + + // A 64-bit integer can be encoded by at most 10 bytes: + unsigned char b[10]; + int idx = 0; + do + { + b[idx] = (a_Value & 0x7f) | ((a_Value > 0x7f) ? 0x80 : 0x00); + a_Value = a_Value >> 7; + idx++; + } while (a_Value > 0); + + return WriteBuf(b, idx); +} + + + + +bool cByteBuffer::WriteVarUTF8String(AString & a_Value) +{ + CHECK_THREAD; + CheckValid(); + PUTBYTES(a_Value.size() + 1); // This is a lower-bound on the bytes that will be actually written. Fail early. + bool res = WriteVarInt(a_Value.size()); + if (!res) + { + return false; + } + return WriteBuf(a_Value.data(), a_Value.size()); +} + + + + + bool cByteBuffer::ReadBuf(void * a_Buffer, int a_Count) { CHECK_THREAD; diff --git a/source/ByteBuffer.h b/source/ByteBuffer.h index 650eda5b0..eb5ce5910 100644 --- a/source/ByteBuffer.h +++ b/source/ByteBuffer.h @@ -57,8 +57,22 @@ public: bool ReadBEFloat (float & a_Value); bool ReadBEDouble (double & a_Value); bool ReadBool (bool & a_Value); - bool ReadBEUTF16String16(AString & a_Value); - + bool ReadBEUTF16String16(AString & a_Value); // string length as BE short, then string as UTF-16BE + bool ReadVarInt (UInt64 & a_Value); + bool ReadVarUTF8String (AString & a_Value); // string length as VarInt, then string as UTF-8 + + /// Reads VarInt, assigns it to anything that can be assigned from an UInt64 (unsigned int, short, char, Byte, double, ...) + template bool ReadVarUInt(T & a_Value) + { + UInt64 v; + bool res = ReadVarInt(v); + if (res) + { + a_Value = v; + } + return res; + } + // Write the specified datatype; return true if successfully written bool WriteChar (char a_Value); bool WriteByte (unsigned char a_Value); @@ -68,7 +82,9 @@ public: bool WriteBEFloat (float a_Value); bool WriteBEDouble (double a_Value); bool WriteBool (bool a_Value); - bool WriteBEUTF16String16(const AString & a_Value); + bool WriteBEUTF16String16(const AString & a_Value); // string length as BE short, then string as UTF-16BE + bool WriteVarInt (UInt64 a_Value); + bool WriteVarUTF8String (AString & a_Value); // string length as VarInt, then string as UTF-8 /// Reads a_Count bytes into a_Buffer; returns true if successful bool ReadBuf(void * a_Buffer, int a_Count); -- cgit v1.2.3 From dfefdcf7f1cb1c7a741bb2deb82b7fb9634657b1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 28 Oct 2013 20:57:03 +0100 Subject: MC uses VarInts only up to 32-bits. --- source/ByteBuffer.cpp | 18 +++++++++--------- source/ByteBuffer.h | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'source') diff --git a/source/ByteBuffer.cpp b/source/ByteBuffer.cpp index 78cc1385e..6659b4dd4 100644 --- a/source/ByteBuffer.cpp +++ b/source/ByteBuffer.cpp @@ -39,11 +39,11 @@ public: { cByteBuffer buf(50); buf.Write("\x05\xac\x02\x00", 4); - UInt64 v1; + UInt32 v1; ASSERT(buf.ReadVarInt(v1) && (v1 == 5)); - UInt64 v2; + UInt32 v2; ASSERT(buf.ReadVarInt(v2) && (v2 == 300)); - UInt64 v3; + UInt32 v3; ASSERT(buf.ReadVarInt(v3) && (v3 == 0)); } @@ -374,11 +374,11 @@ bool cByteBuffer::ReadBEUTF16String16(AString & a_Value) -bool cByteBuffer::ReadVarInt(UInt64 & a_Value) +bool cByteBuffer::ReadVarInt(UInt32 & a_Value) { CHECK_THREAD; CheckValid(); - UInt64 Value = 0; + UInt32 Value = 0; int Shift = 0; unsigned char b = 0; do @@ -400,7 +400,7 @@ bool cByteBuffer::ReadVarUTF8String(AString & a_Value) { CHECK_THREAD; CheckValid(); - UInt64 Size = 0; + UInt32 Size = 0; if (!ReadVarInt(Size)) { return false; @@ -534,13 +534,13 @@ bool cByteBuffer::WriteBEUTF16String16(const AString & a_Value) -bool cByteBuffer::WriteVarInt(UInt64 a_Value) +bool cByteBuffer::WriteVarInt(UInt32 a_Value) { CHECK_THREAD; CheckValid(); - // A 64-bit integer can be encoded by at most 10 bytes: - unsigned char b[10]; + // A 32-bit integer can be encoded by at most 5 bytes: + unsigned char b[5]; int idx = 0; do { diff --git a/source/ByteBuffer.h b/source/ByteBuffer.h index eb5ce5910..71ee4764e 100644 --- a/source/ByteBuffer.h +++ b/source/ByteBuffer.h @@ -58,13 +58,13 @@ public: bool ReadBEDouble (double & a_Value); bool ReadBool (bool & a_Value); bool ReadBEUTF16String16(AString & a_Value); // string length as BE short, then string as UTF-16BE - bool ReadVarInt (UInt64 & a_Value); + bool ReadVarInt (UInt32 & a_Value); bool ReadVarUTF8String (AString & a_Value); // string length as VarInt, then string as UTF-8 - /// Reads VarInt, assigns it to anything that can be assigned from an UInt64 (unsigned int, short, char, Byte, double, ...) + /// Reads VarInt, assigns it to anything that can be assigned from an UInt32 (unsigned short, char, Byte, double, ...) template bool ReadVarUInt(T & a_Value) { - UInt64 v; + UInt32 v; bool res = ReadVarInt(v); if (res) { @@ -83,7 +83,7 @@ public: bool WriteBEDouble (double a_Value); bool WriteBool (bool a_Value); bool WriteBEUTF16String16(const AString & a_Value); // string length as BE short, then string as UTF-16BE - bool WriteVarInt (UInt64 a_Value); + bool WriteVarInt (UInt32 a_Value); bool WriteVarUTF8String (AString & a_Value); // string length as VarInt, then string as UTF-8 /// Reads a_Count bytes into a_Buffer; returns true if successful -- cgit v1.2.3