OSDN Git Service

プロトコルバージョンを3に変更
authorh2so5 <h2so5@git.sourceforge.jp>
Thu, 18 Oct 2012 09:53:29 +0000 (18:53 +0900)
committerh2so5 <h2so5@git.sourceforge.jp>
Thu, 18 Oct 2012 09:53:29 +0000 (18:53 +0900)
Command.cpp, Command.hppを整理

client/CommandManager.cpp
client/version.hpp
common/network/Command.cpp
common/network/Command.hpp
common/network/CommandHeader.hpp
common/network/Session.cpp
common/network/Utils.hpp
server/Server.cpp
server/main.cpp
server/version.hpp

index 98723d4..ac3223a 100644 (file)
@@ -191,8 +191,9 @@ void CommandManager::FetchCommand(const network::Command& command)
        case ClientReceiveAccountRevisionPatch:
        {
                Logger::Info(_T("Receive account database update data"));
-               assert(command.body().size() > 0);
-               player_manager->ApplyRevisionPatch(command.body());
+               std::string data = network::Utils::Deserialize<std::string>(command.body());
+               assert(!data.empty());
+               player_manager->ApplyRevisionPatch(data);
        }
                break;
 
index 13eb856..2bae79b 100644 (file)
@@ -11,7 +11,7 @@
 #define MMO_VERSION_MINOR 4
 #define MMO_VERSION_REVISION 0
 
-#define MMO_PROTOCOL_VERSION 2
+#define MMO_PROTOCOL_VERSION 3
 
 #ifdef MMO_VERSION_BUILD
 #define MMO_VERSION_BUILD_TEXT " Build " MMO_VERSION_TOSTRING(MMO_VERSION_BUILD)
index 8b1f5e3..e5398cc 100644 (file)
@@ -33,114 +33,4 @@ bool Command::plain() const
        return plain_;
 }
 
-FatalConnectionError::FatalConnectionError() :
-        Command(header::FatalConnectionError, "")
-{
-
-}
-
-FatalConnectionError::FatalConnectionError(uint32_t user_id) :\r
-        Command(header::FatalConnectionError, "")
-{
-    body_ = Utils::Serialize(user_id);
-}
-
-ServerReceivePublicKey::ServerReceivePublicKey(const std::string& key) :
-        Command(header::ServerReceivePublicKey, key)
-{
-}
-
-ClientReceiveCommonKey::ClientReceiveCommonKey(const std::string& key,
-        const std::string& sign,
-        uint32_t user_id) :\r
-        Command(header::ClientReceiveCommonKey, Utils::Serialize(key, sign, user_id))
-{
-}
-
-ClientUpdatePlayerPosition::ClientUpdatePlayerPosition
-(uint32_t id, int16_t x, int16_t y, int16_t z, uint8_t theta, uint8_t vy) :\r
-Command(header::ClientUpdatePlayerPosition, Utils::Serialize(id, x, y, z, theta, vy))
-{
-
-}
-
-ServerUpdatePlayerPosition::ServerUpdatePlayerPosition(int16_t x, int16_t y, int16_t z, uint8_t theta, uint8_t vy) :\r
-        Command(header::ServerUpdatePlayerPosition, Utils::Serialize(x, y, z, theta, vy))
-{
-}
-
-ServerReceiveClientInfo::ServerReceiveClientInfo(const std::string& key, uint16_t version, uint16_t udp_port) :
-                Command(header::ServerReceiveClientInfo, Utils::Serialize(key, version, udp_port))
-{
-
-}
-
-ServerRequestedAccountRevisionPatch::ServerRequestedAccountRevisionPatch(uint32_t user_id, int revision) :\r
-                                           Command(header::ServerRequestedAccountRevisionPatch,
-                                                   Utils::Serialize(user_id, revision))
-{
-}
-
-ClientReceiveAccountRevisionPatch::ClientReceiveAccountRevisionPatch(const std::string& patch) :
-    Command(header::ClientReceiveAccountRevisionPatch, patch)
-{
-
-}
-
-ClientReceiveAccountRevisionUpdateNotify::
-ClientReceiveAccountRevisionUpdateNotify(uint32_t user_id, int revision) :\r
-        Command(header::ClientReceiveAccountRevisionUpdateNotify, Utils::Serialize(user_id, revision))
-{
-}
-
-ClientReceiveWriteAverageLimitUpdate::ClientReceiveWriteAverageLimitUpdate(uint16_t byte) :\r
-        Command(header::ClientReceiveWriteAverageLimitUpdate, Utils::Serialize(byte))
-{
-}
-
-ClientReceiveUnsupportVersionError::ClientReceiveUnsupportVersionError(uint32_t require_version) :
-        Command(header::ClientReceiveUnsupportVersionError, Utils::Serialize(require_version))
-{
-}
-
-ServerReceiveAccountInitializeData::ServerReceiveAccountInitializeData(const std::string& data):
-        Command(header::ServerReceiveAccountInitializeData, data)
-{
-
-}
-
-ServerUpdateAccountProperty::ServerUpdateAccountProperty(AccountProperty property, const std::string& value) :
-Command(header::ServerUpdateAccountProperty, Utils::Serialize(property, value))
-{
-
-}
-
-ServerReceiveJSON::ServerReceiveJSON(const std::string& json) :
-        Command(header::ServerReceiveJSON, json)
-{
-}
-
-ClientReceiveJSON::ClientReceiveJSON(const std::string& info_json, const std::string& message_json) :
-        Command(header::ClientReceiveJSON, Utils::Serialize(info_json, message_json))
-{
-}
-
-ClientReceiveServerInfo::ClientReceiveServerInfo(const std::string& stage) :
-       Command(header::ClientReceiveServerInfo, Utils::Serialize(stage))
-{
-
-}
-
-ClientReceiveFullServerInfo::ClientReceiveFullServerInfo(const std::string& xml) :
-       Command(header::ClientReceiveFullServerInfo, Utils::Serialize(xml))
-{
-
-}
-
-ClientReceivePlainFullServerInfo::ClientReceivePlainFullServerInfo(const std::string& xml) :
-       Command(header::ClientReceivePlainFullServerInfo, Utils::Serialize(xml))
-{
-       plain_ = true;
-}
-
 }
index 3bfc52c..7fe6bc2 100644 (file)
@@ -50,118 +50,112 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
     };
 
        template<header::CommandHeader Header>
-       class CommandTemplate : public Command {
+       class CommandTemplate0 : public Command {
                public:
-                       CommandTemplate() :
+                       CommandTemplate0() :
                          Command(Header, "") {}
        };
 
-       typedef CommandTemplate<header::ServerStartEncryptedSession>            ServerStartEncryptedSession;
-       typedef CommandTemplate<header::ClientStartEncryptedSession>            ClientStartEncryptedSession;
-       typedef CommandTemplate<header::ClientRequestedPublicKey>                       ClientRequestedPublicKey;
-       typedef CommandTemplate<header::ClientRequestedClientInfo>                      ClientRequestedClientInfo;
-       typedef CommandTemplate<header::ClientReceiveServerCrowdedError>        ClientReceiveServerCrowdedError;
-       typedef CommandTemplate<header::ServerRequestedFullServerInfo>          ServerRequestedFullServerInfo;
-       typedef CommandTemplate<header::ServerRequestedPlainFullServerInfo>     ServerRequestedPlainFullServerInfo;
-
-    // コネクションの切断
-    class FatalConnectionError : public Command {
-    public:
-        FatalConnectionError();
-        FatalConnectionError(uint32_t user_id);\r
-    };
+       template<header::CommandHeader Header, class T1>
+       class CommandTemplate1 : public Command {
+               public:
+                       CommandTemplate1(T1 t1) :
+                         Command(Header, Utils::Serialize(t1)) {}
+       };
 
-    // クライアントからの公開鍵を受信
-    class ServerReceivePublicKey : public Command {
-    public:
-        ServerReceivePublicKey(const std::string& key);
-    };
+       template<header::CommandHeader Header, class T1, class T2>
+       class CommandTemplate2 : public Command {
+               public:
+                       CommandTemplate2(T1 t1, T2 t2) :
+                         Command(Header, Utils::Serialize(t1, t2)) {}
+       };
 
-    // サーバーからの共通鍵を受信
-    class ClientReceiveCommonKey : public Command {
-    public:
-        ClientReceiveCommonKey(const std::string& key,
-                const std::string& sign,
-                uint32_t user_id);\r
-    };
+       template<header::CommandHeader Header, class T1, class T2, class T3>
+       class CommandTemplate3 : public Command {
+               public:
+                       CommandTemplate3(T1 t1, T2 t2, T3 t3) :
+                         Command(Header, Utils::Serialize(t1, t2, t3)) {}
+       };
 
-    // 他のプレイヤーの位置情報が更新された
-    class ClientUpdatePlayerPosition : public Command {
-    public:
-        ClientUpdatePlayerPosition(uint32_t id, int16_t x, int16_t y, int16_t z, uint8_t theta, uint8_t vy);\r
-    };
+       template<header::CommandHeader Header, class T1, class T2, class T3, class T4>
+       class CommandTemplate4 : public Command {
+               public:
+                       CommandTemplate4(T1 t1, T2 t2, T3 t3, T4 t4) :
+                         Command(Header, Utils::Serialize(t1, t2, t3, t4)) {}
+       };
 
-    // プレイヤーの位置情報が更新された
-    class ServerUpdatePlayerPosition : public Command {
-    public:
-        ServerUpdatePlayerPosition(int16_t x, int16_t y, int16_t z, uint8_t theta, uint8_t vy);\r
-    };
+       template<header::CommandHeader Header, class T1, class T2, class T3, class T4, class T5>
+       class CommandTemplate5 : public Command {
+               public:
+                       CommandTemplate5(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) :
+                         Command(Header, Utils::Serialize(t1, t2, t3, t4, t5)) {}
+       };
 
-    // クライアントの情報を受信した (公開鍵のフィンガープリント, UDPポート)
-    class ServerReceiveClientInfo : public Command {
-    public:
-        ServerReceiveClientInfo(const std::string& key, uint16_t version, uint16_t udp_port);
-    };
+       template<header::CommandHeader Header, class T1, class T2, class T3, class T4, class T5, class T6>
+       class CommandTemplate6 : public Command {
+               public:
+                       CommandTemplate6(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) :
+                         Command(Header, Utils::Serialize(t1, t2, t3, t4, t5, t6)) {}
+       };
+       
+       typedef CommandTemplate0<header::FatalConnectionError>                                  FatalConnectionError;
+       typedef CommandTemplate0<header::ServerStartEncryptedSession>                   ServerStartEncryptedSession;
+       typedef CommandTemplate0<header::ClientStartEncryptedSession>                   ClientStartEncryptedSession;
+       typedef CommandTemplate0<header::ClientRequestedPublicKey>                              ClientRequestedPublicKey;
+       typedef CommandTemplate0<header::ClientRequestedClientInfo>                             ClientRequestedClientInfo;
+       typedef CommandTemplate0<header::ClientReceiveServerCrowdedError>               ClientReceiveServerCrowdedError;
+       typedef CommandTemplate0<header::ServerRequestedFullServerInfo>                 ServerRequestedFullServerInfo;
+       typedef CommandTemplate0<header::ServerRequestedPlainFullServerInfo>    ServerRequestedPlainFullServerInfo;
 
-    class ServerRequestedAccountRevisionPatch : public Command {
-    public:
-        ServerRequestedAccountRevisionPatch(uint32_t user_id, int revision);\r
-    };
+       typedef CommandTemplate1<header::ServerReceivePublicKey,
+               const std::string&>     ServerReceivePublicKey;
 
-    // アカウントデータベースの更新データ
-    class ClientReceiveAccountRevisionPatch : public Command {
-    public:
-        ClientReceiveAccountRevisionPatch(const std::string& patch);
-    };
+       typedef CommandTemplate1<header::ClientReceiveAccountRevisionPatch,
+               const std::string&>     ClientReceiveAccountRevisionPatch;
 
-    // アカウントデータベースの更新通知
-    class ClientReceiveAccountRevisionUpdateNotify : public Command {
-    public:
-        ClientReceiveAccountRevisionUpdateNotify(uint32_t user_id, int revision);\r
-    };
+       typedef CommandTemplate6<header::ClientUpdatePlayerPosition,
+               uint32_t, int16_t, int16_t, int16_t, uint8_t, uint8_t> ClientUpdatePlayerPosition;
 
-    class ClientReceiveWriteAverageLimitUpdate : public Command {
-    public:
-        ClientReceiveWriteAverageLimitUpdate(uint16_t byte);\r
-    };
+       typedef CommandTemplate5<header::ServerUpdatePlayerPosition,
+               int16_t, int16_t, int16_t, uint8_t, uint8_t> ServerUpdatePlayerPosition;
 
-    class ClientReceiveUnsupportVersionError : public Command {
-    public:
-        ClientReceiveUnsupportVersionError(uint32_t require_version);
-    };
+       typedef CommandTemplate2<header::ServerRequestedAccountRevisionPatch,
+               uint32_t, int> ServerRequestedAccountRevisionPatch;
 
-    class ServerReceiveAccountInitializeData : public Command {
-    public:
-        ServerReceiveAccountInitializeData(const std::string& data);
-    };
+       typedef CommandTemplate2<header::ClientReceiveAccountRevisionUpdateNotify,
+               uint32_t, int> ClientReceiveAccountRevisionUpdateNotify;
 
-    class ServerUpdateAccountProperty : public Command {
-    public:
-        ServerUpdateAccountProperty(AccountProperty uint16_t, const std::string& value);\r
-    };
+       typedef CommandTemplate3<header::ClientReceiveCommonKey,
+               const std::string&, const std::string&, uint32_t> ClientReceiveCommonKey;
+       
+       typedef CommandTemplate2<header::ServerUpdateAccountProperty,
+               AccountProperty, const std::string&> ServerUpdateAccountProperty;
 
-    class ServerReceiveJSON : public Command {
-    public:
-        ServerReceiveJSON(const std::string& json);
-    };
+       typedef CommandTemplate3<header::ServerReceiveClientInfo,
+               const std::string&, uint16_t, uint16_t> ServerReceiveClientInfo;
 
-    class ClientReceiveJSON : public Command {
-    public:
-        ClientReceiveJSON(const std::string& info_json, const std::string& message_json);
-    };
+       typedef CommandTemplate1<header::ClientReceiveWriteAverageLimitUpdate,
+               uint16_t> ClientReceiveWriteAverageLimitUpdate;
 
-       class ClientReceiveServerInfo : public Command {
-    public:
-        ClientReceiveServerInfo(const std::string& stage);
-       };
+       typedef CommandTemplate1<header::ClientReceiveUnsupportVersionError,
+               uint32_t> ClientReceiveUnsupportVersionError;
 
-       class ClientReceiveFullServerInfo : public Command {
-    public:
-        ClientReceiveFullServerInfo(const std::string& xml);
-       };
+       typedef CommandTemplate1<header::ServerReceiveAccountInitializeData,
+               const std::string&> ServerReceiveAccountInitializeData;
+
+       typedef CommandTemplate1<header::ServerReceiveJSON,
+               const std::string&> ServerReceiveJSON;
+
+       typedef CommandTemplate2<header::ClientReceiveJSON,
+               const std::string&, const std::string&> ClientReceiveJSON;
+
+       typedef CommandTemplate1<header::ClientReceiveServerInfo,
+               const std::string&> ClientReceiveServerInfo;
+
+       typedef CommandTemplate1<header::ClientReceiveFullServerInfo,
+               const std::string&> ClientReceiveFullServerInfo;
+
+       typedef CommandTemplate1<header::UserFatalConnectionError,
+               uint32_t> UserFatalConnectionError;
 
-       class ClientReceivePlainFullServerInfo : public Command {
-    public:
-        ClientReceivePlainFullServerInfo(const std::string& xml);
-       };
 }
index cdb9599..eb9fc1a 100644 (file)
@@ -7,7 +7,9 @@
 namespace network {
 namespace header {
     enum CommandHeader {
-        FatalConnectionError =                      0x01,
+        FatalConnectionError =                      0xA0,
+        UserFatalConnectionError =                  0xA1,
+
         ServerStartEncryptedSession =               0x02,
         ClientStartEncryptedSession =               0x03,
         ServerReceivePublicKey =                    0x04,
index 3810daf..f2d6536 100644 (file)
@@ -79,7 +79,7 @@ namespace network {
 \r
     void Session::UpdateReadByteAverage()\r
     {\r
-        unsigned long elapsed_time = time(nullptr) - read_start_time_;\r
+        auto elapsed_time = time(nullptr) - read_start_time_;\r
         if (elapsed_time >= BYTE_AVERAGE_REFRESH_SECONDS) {\r
             read_byte_sum_ /= 2;\r
             read_start_time_ = time(nullptr) - elapsed_time / 2;\r
@@ -88,7 +88,7 @@ namespace network {
 \r
     void Session::UpdateWriteByteAverage()\r
     {\r
-        unsigned long elapsed_time = time(nullptr) - write_start_time_;\r
+        auto elapsed_time = time(nullptr) - write_start_time_;\r
         if (elapsed_time >= BYTE_AVERAGE_REFRESH_SECONDS) {\r
             write_byte_sum_ /= 2;\r
             write_start_time_ = time(nullptr) - elapsed_time / 2;\r
@@ -351,7 +351,7 @@ namespace network {
             online_ = false;\r
             if (on_receive_) {\r
                 if (id_ > 0) {\r
-                    (*on_receive_)(FatalConnectionError(id_));\r
+                    (*on_receive_)(UserFatalConnectionError(id_));\r
                 } else {\r
                     (*on_receive_)(FatalConnectionError());\r
                 }\r
index b2deb8c..c31423a 100644 (file)
@@ -135,6 +135,17 @@ namespace network {
             *first = GetDeserializedValue<First>(buffer);
         }
 
+        template<class T>
+        inline T Deserialize(const std::string& data)
+        {
+            std::string buffer(data);
+
+                       T t;
+            GetDeserializedItems(buffer, &t);
+
+                       return t;
+        }
+
         template<class T1>
         inline size_t Deserialize(const std::string& data, T1 t1)
         {
index 16dcd29..59e6912 100644 (file)
@@ -30,7 +30,8 @@ namespace network {
                 [&](network::Command c){\r
 \r
             // ログアウト\r
-            if (c.header() == network::header::FatalConnectionError) {\r
+            if (c.header() == network::header::FatalConnectionError || \r
+                               c.header() == network::header::UserFatalConnectionError) {\r
                 if (callback) {\r
                                        (*callback)(c);\r
                                }\r
index 654f792..d3403f4 100644 (file)
@@ -89,9 +89,9 @@ void server()
 \r
                case network::header::ServerRequestedPlainFullServerInfo:\r
                {\r
-                       if (auto session = c.session().lock()) {\r
-                               session->Send(network::ClientReceivePlainFullServerInfo(server.GetFullStatus()));\r
-                       }\r
+                       //if (auto session = c.session().lock()) {\r
+                       //      session->Send(network::ClientReceivePlainFullServerInfo(server.GetFullStatus()));\r
+                       //}\r
                }\r
                break;\r
 \r
@@ -113,7 +113,7 @@ void server()
                                        break;\r
                                }\r
                                \r
-                               std::stringstream message_json(c.body());\r
+                               std::stringstream message_json(network::Utils::Deserialize<std::string>(c.body()));\r
 \r
                                using namespace boost::property_tree;\r
                                ptree message_tree;\r
@@ -232,7 +232,9 @@ void server()
         case network::header::ServerReceivePublicKey:\r
         {\r
             if (auto session = c.session().lock()) {\r
-                uint32_t user_id = server.account().RegisterPublicKey(c.body());\r
+                               auto public_key = network::Utils::Deserialize<std::string>(c.body());\r
+                uint32_t user_id = server.account().RegisterPublicKey(public_key);\r
+\r
                                assert(user_id > 0);\r
 \r
                                session->ResetReadByteAverage();\r
@@ -273,7 +275,8 @@ void server()
         case network::header::ServerReceiveAccountInitializeData:\r
         {\r
             if (auto session = c.session().lock()) {\r
-                server.account().LoadInitializeData(session->id(), c.body());\r
+                               auto data = network::Utils::Deserialize<std::string>(c.body());\r
+                server.account().LoadInitializeData(session->id(), data);\r
 \r
                 const auto& list = server.account().GetIDList();\r
                 BOOST_FOREACH(UserID user_id, list) {\r
@@ -365,11 +368,10 @@ void server()
         break;\r
 \r
         // エラー\r
-        case network::header::FatalConnectionError:\r
+        case network::header::UserFatalConnectionError:\r
         {\r
             if (c.body().size() > 0) {\r
-                int user_id;\r
-                network::Utils::Deserialize(c.body(), &user_id);\r
+                uint32_t user_id = network::Utils::Deserialize<uint32_t>(c.body());\r
                 server.account().LogOut(user_id);\r
 \r
                 server.SendAll(\r
index 77a53b2..b6afe6e 100644 (file)
@@ -11,7 +11,7 @@
 #define MMO_VERSION_MINOR 3\r
 #define MMO_VERSION_REVISION 0\r
 \r
-#define MMO_PROTOCOL_VERSION 2\r
+#define MMO_PROTOCOL_VERSION 3\r
 \r
 #ifdef MMO_VERSION_BUILD\r
 #define MMO_VERSION_BUILD_TEXT " Build " MMO_VERSION_TOSTRING(MMO_VERSION_BUILD)\r