]> jfr.im git - irc/gameservirc.git/commitdiff
Made FilePlayerDAO::Insert() only append a line instead of writing the whole file...
authorkainazzzo <redacted>
Sat, 12 Sep 2009 17:41:41 +0000 (17:41 +0000)
committerkainazzzo <redacted>
Sat, 12 Sep 2009 17:41:41 +0000 (17:41 +0000)
Made FilePlayerDAO::Update() write the cache
Added a bunch of TODO lines, which should signify the rest of the necessary work on the player portion of libgameservgldl

git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@515 bc333340-6410-0410-a689-9d09f3c113fa

gameserv-2.0/libgameservgldl/include/GameServ/GameLayer/GameObjects/PlayerGO.h
gameserv-2.0/libgameservgldl/src/DataLayer/File/FilePlayerDAO.cpp

index cbc2aee4ffd9d2eb68f09eb57824b1271a1991e3..2862c6b60cf2b506ee675631183700b7bf08785d 100644 (file)
@@ -113,6 +113,8 @@ namespace GameServ { namespace GameLayer { namespace GameObjects
                //! Property get - LastLogin\r
                ptime LastLogin(void) const;\r
 \r
+               // TODO: Add boolean flags\r
+\r
                bool operator==(const PlayerGO &right) const;\r
                bool operator!=(const PlayerGO &right) const;\r
 \r
@@ -135,6 +137,8 @@ namespace GameServ { namespace GameLayer { namespace GameObjects
                shared_ptr<ArmorGO> mArmor;\r
                vector< shared_ptr<ItemGO> > mInventory;\r
                ptime mLastLogin;\r
+\r
+               // TODO: Add flag long int\r
        };\r
 }}} // GameServ::GameLayer::GameObjects\r
 #endif
\ No newline at end of file
index 2e47b14e2d6b20f53a9d89a6e6a39c74f65fa2f1..2d5d7e24ab3fcb8345da0b28e220af18950eeabd 100644 (file)
@@ -160,13 +160,16 @@ shared_ptr<PlayerGO> FilePlayerDAO::CreatePlayerFromLine(const string &line) con
        tok_iter++;\r
        spPlayer->Password((*tok_iter));\r
 \r
+       // TODO: Add weapons, armor, and items\r
+\r
        return spPlayer;\r
 }\r
 \r
 string FilePlayerDAO::CreateLineFromPlayer(shared_ptr<PlayerGO> spPlayer) const\r
 {\r
        string line;\r
-       line = str(format("%1% %2% %3% %4% %5% %6% %7% %8% %9% %10% %11% %12%") % \r
+       // TODO: Add weapons, armor, and items\r
+       line = str(format("%1% %2% %3% %4% %5% %6% %7% %8% %9% %10% %11% %12% %13%") % \r
                spPlayer->Name() % spPlayer->Level() % spPlayer->Experience() % spPlayer->Gold() %\r
                spPlayer->Bank() % spPlayer->Health() % spPlayer->MaxHealth() % spPlayer->Strength() %\r
                spPlayer->Defense() % spPlayer->ForestFights() % spPlayer->PlayerFights() %\r
@@ -176,10 +179,12 @@ string FilePlayerDAO::CreateLineFromPlayer(shared_ptr<PlayerGO> spPlayer) const
 \r
 void FilePlayerDAO::SetFlags(shared_ptr<PlayerGO> spPlayer, const int &flags) const\r
 {\r
+       // TODO: Add flags of course\r
 }\r
 \r
 int FilePlayerDAO::GetFlags(shared_ptr<PlayerGO> spPlayer) const\r
 {\r
+       // TODO: Return real flags\r
        return 0;\r
 }\r
 \r
@@ -189,9 +194,11 @@ void FilePlayerDAO::Update(shared_ptr<PlayerGO> spPlayer)
        assert(!spPlayer->Id().empty());\r
        assert(!spPlayer->Name().empty());\r
 \r
+       // TODO: Lock the file\r
        if (IdExists(spPlayer->Id()))\r
        {\r
                spPlayerCache[spPlayer->Id()] = spPlayer;\r
+               WritePlayerCache();\r
        }\r
        else\r
        {\r
@@ -204,11 +211,19 @@ void FilePlayerDAO::Insert(shared_ptr<PlayerGO> spPlayer)
 {\r
        assert(spPlayer != 0);\r
        assert(!spPlayer->Name().empty());\r
+       // TODO: Lock the file\r
        if (!IdExists(FileId::CreatePlayerId(spPlayer->Name())))\r
        {\r
                spPlayer->Id(FileId::CreatePlayerId(spPlayer->Name()));\r
                spPlayerCache[spPlayer->Id()] = spPlayer;\r
-               WritePlayerCache();\r
+               ofstream outfile;\r
+               outfile.open(mFilename.c_str(), std::ios::app);\r
+               if (outfile.fail())\r
+               {\r
+                       throw ResourceException(str(format("Unable to open %1% for appending.") % mFilename), __FILE__, __LINE__);\r
+               }\r
+               outfile << CreateLineFromPlayer(spPlayer) << endl;\r
+               outfile.close();\r
        }\r
        else\r
        {\r