OSDN Git Service

ClientReceiveFullServerInfo, ServerRequestedFullServerInfo コマンドを追加
authorh2so5 <h2so5@git.sourceforge.jp>
Fri, 5 Oct 2012 16:23:54 +0000 (01:23 +0900)
committerh2so5 <h2so5@git.sourceforge.jp>
Fri, 5 Oct 2012 16:23:54 +0000 (01:23 +0900)
サーバーのconfig.jsonのリポジトリ上の位置を変更

16 files changed:
.gitignore
client/Client.cpp
client/CommandManager.cpp
client/bin/server/config.json [moved from server/config.json with 100% similarity]
client/bin/system/languages/en.json [moved from mmo-0.3.9_123/system/languages/en.json with 96% similarity]
client/bin/system/languages/jp.json [moved from mmo-0.3.9_123/system/languages/jp.json with 97% similarity]
client/bin/system/plugins/textchat/main.js
common/network/Command.cpp
common/network/Command.hpp
common/network/CommandHeader.hpp
package.py
server/Config.cpp
server/Config.hpp
server/Server.cpp
server/Server.hpp
server/main.cpp

index 1586b35..82abd28 100644 (file)
@@ -17,7 +17,6 @@ log_*.txt
 /Client/bin/account.xml
 /Client/bin/config.json
 /Client/bin/Log.txt
-/Client/bin/server
 /Server/server_key.pub
 /Server/server_key
 /Server/Debug
@@ -30,7 +29,6 @@ log_*.txt
 /server/buildversion.hpp
 /server/Release
 /ServerLauncher
-/client/bin/server
 /client/bin/tool
 /client/bin/widgets
 /client/bin/models
index 6ba34d9..52f9f77 100644 (file)
@@ -108,6 +108,8 @@ Client::Client(const std::string& host,
                                             (uint16_t)MMO_PROTOCOL_VERSION,
                                             session->udp_port()
                                     ));
+                                                       
+                                                       session->Send(network::ServerRequestedFullServerInfo());
                         }
                     }
                     break;
index fe77563..711d760 100644 (file)
@@ -85,6 +85,14 @@ void CommandManager::FetchCommand(const network::Command& command)
        }
        break;
 
+       // サーバーデータ受信
+       case ClientReceiveFullServerInfo:
+       {
+               std::string xml;
+               network::Utils::Deserialize(command.body(), &xml);
+       }
+       break;
+
        case ClientReceiveJSON:
        // case ClientReceiveChatLog:
        {
similarity index 96%
rename from mmo-0.3.9_123/system/languages/en.json
rename to client/bin/system/languages/en.json
index f625a33..8132c62 100644 (file)
@@ -9,6 +9,7 @@
                        "status":
                                {
                                        "name":                                 "Status",
+                                       "trip":                                 "Tripcode",
                                        "nickname":                             "Nickname",
                                        "modelname":                    "Model",
                                        "user_id":                              "UserID",
similarity index 97%
rename from mmo-0.3.9_123/system/languages/jp.json
rename to client/bin/system/languages/jp.json
index a7245b7..a3453e0 100644 (file)
@@ -9,6 +9,7 @@
                        "status":
                                {
                                        "name":                                 "ステータス",
+                                       "trip":                                 "トリップ",
                                        "nickname":                             "ニックネーム",
                                        "modelname":                    "モデル名",
                                        "user_id":                              "ユーザーID",
index 572010b..23773ab 100644 (file)
@@ -17,6 +17,11 @@ var list;
 // チャットメッセージ受信
 var even_line = false;
 Network.onReceive = function (info, msg) {
+
+       if (msg.type && msg.type != "chat") {
+               return;
+       }
+
        var trip = ""
        if (info.player.trip()) {
                trip = "《" + info.player.trip() + "》"
@@ -151,13 +156,14 @@ InputBox.onEnter = function (text) {
 
             // システム      
             case "system":
-                var msgObject = { system: args.trim() };
+                var msgObject = { type: "system", system: args.trim() };
                 Network.sendAll(msgObject);
                 break;
 
             // プライベート      
             case "private":
                 var msgObject = {
+                       type: "chat", 
                     private: [
                                        Player.myself().id(),
                                        Player.getFromName([args.trim()]).id()
@@ -177,7 +183,7 @@ InputBox.onEnter = function (text) {
 
     } else {
         // コマンドでない場合はそのままチャットメッセージとして送信
-        var msgObject = { body: text };
+        var msgObject = { type: "chat", body: text };
         Network.sendAll(msgObject);
     }
 
index 6db7de0..067e729 100644 (file)
@@ -40,22 +40,9 @@ FatalConnectionError::FatalConnectionError(uint32_t user_id) :
     body_ = Utils::Serialize(user_id);
 }
 
-ServerStartEncryptedSession::ServerStartEncryptedSession() :
-        Command(header::ServerStartEncryptedSession, "")
-{
-
-}
-
-ClientStartEncryptedSession::ClientStartEncryptedSession() :
-        Command(header::ClientStartEncryptedSession, "")
-{
-
-}
-
 ServerReceivePublicKey::ServerReceivePublicKey(const std::string& key) :
         Command(header::ServerReceivePublicKey, key)
 {
-
 }
 
 ClientReceiveCommonKey::ClientReceiveCommonKey(const std::string& key,
@@ -83,18 +70,6 @@ ServerReceiveClientInfo::ServerReceiveClientInfo(const std::string& key, uint16_
 
 }
 
-ClientRequestedPublicKey::ClientRequestedPublicKey() :
-        Command(header::ClientRequestedPublicKey, "")
-{
-
-}
-
-ClientRequestedClientInfo::ClientRequestedClientInfo() :
-        Command(header::ClientRequestedClientInfo, "")
-{
-
-}
-
 ServerRequestedAccountRevisionPatch::ServerRequestedAccountRevisionPatch(uint32_t user_id, int revision) :\r
                                            Command(header::ServerRequestedAccountRevisionPatch,
                                                    Utils::Serialize(user_id, revision))
@@ -118,12 +93,6 @@ ClientReceiveWriteAverageLimitUpdate::ClientReceiveWriteAverageLimitUpdate(uint1
 {
 }
 
-ClientReceiveServerCrowdedError::ClientReceiveServerCrowdedError() :
-        Command(header::ClientReceiveServerCrowdedError, "")
-{
-
-}
-
 ClientReceiveUnsupportVersionError::ClientReceiveUnsupportVersionError(uint32_t require_version) :
         Command(header::ClientReceiveUnsupportVersionError, Utils::Serialize(require_version))
 {
@@ -157,4 +126,10 @@ ClientReceiveServerInfo::ClientReceiveServerInfo(const std::string& stage) :
 
 }
 
+ClientReceiveFullServerInfo::ClientReceiveFullServerInfo(const std::string& xml) :
+       Command(header::ClientReceiveFullServerInfo, Utils::Serialize(xml))
+{
+
+}
+
 }
index 36be6f4..1db37b7 100644 (file)
@@ -43,6 +43,20 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
                        boost::asio::ip::udp::endpoint udp_endpoint_;
     };
 
+       template<header::CommandHeader Header>
+       class CommandTemplate : public Command {
+               public:
+                       CommandTemplate() :
+                         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;
+
     // コネクションの切断
     class FatalConnectionError : public Command {
     public:
@@ -50,18 +64,6 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
         FatalConnectionError(uint32_t user_id);\r
     };
 
-    // 暗号化通信を開始
-    class ServerStartEncryptedSession : public Command {
-    public:
-        ServerStartEncryptedSession();
-    };
-
-    // 暗号化通信を開始
-    class ClientStartEncryptedSession : public Command {
-    public:
-        ClientStartEncryptedSession();
-    };
-
     // クライアントからの公開鍵を受信
     class ServerReceivePublicKey : public Command {
     public:
@@ -94,18 +96,6 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
         ServerReceiveClientInfo(const std::string& key, uint16_t version, uint16_t udp_port);
     };
 
-    // 公開鍵を要求された
-    class ClientRequestedPublicKey : public Command {
-    public:
-        ClientRequestedPublicKey();
-    };
-
-    // クライアントの情報を要求された
-    class ClientRequestedClientInfo : public Command {
-    public:
-        ClientRequestedClientInfo();
-    };
-
     class ServerRequestedAccountRevisionPatch : public Command {
     public:
         ServerRequestedAccountRevisionPatch(uint32_t user_id, int revision);\r
@@ -128,11 +118,6 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
         ClientReceiveWriteAverageLimitUpdate(uint16_t byte);\r
     };
 
-    class ClientReceiveServerCrowdedError : public Command {
-    public:
-        ClientReceiveServerCrowdedError();
-    };
-
     class ClientReceiveUnsupportVersionError : public Command {
     public:
         ClientReceiveUnsupportVersionError(uint32_t require_version);
@@ -163,4 +148,9 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
         ClientReceiveServerInfo(const std::string& stage);
        };
 
+       class ClientReceiveFullServerInfo : public Command {
+    public:
+        ClientReceiveFullServerInfo(const std::string& xml);
+       };
+
 }
index 8ead657..dab686d 100644 (file)
@@ -28,6 +28,8 @@ namespace header {
         ServerUpdateAccountProperty =               0x13,
         ServerReceiveJSON =                         0x14,
         ClientReceiveJSON =                         0x15,
+        ServerRequestedFullServerInfo =             0x16,
+        ClientReceiveFullServerInfo =               0x17,
                
                ServerReceiveWriteLimit =                                       0x20,
                ServerRequstedStatus =                                          0xE0,
index 2253a7b..50665c1 100644 (file)
@@ -35,7 +35,7 @@ def make_full_package(model = True):
        zip.write(os.path.join(base_dir, 'license.txt'), 'license.txt')
        zip.write(os.path.join(base_dir, 'mmd.txt'), 'mmd.txt')
 
-       zip.write(os.path.join(base_dir, 'server/config.json'), 'server/config.json')
+       zip.write(os.path.join(bin_path, 'server/config.json'), 'server/config.json')
 
        zip.write(os.path.join(bin_path, 'config.json'), 'config.json')
        zip.write(os.path.join(bin_path, 'server/server.exe'), 'server/server.exe')
@@ -91,11 +91,11 @@ def make_server_package():
        zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
 
        zip.write(os.path.join(base_dir, 'license.txt'), 'license.txt')
-       zip.write(os.path.join(base_dir, 'server/config.json'), 'config.json')
        zip.write(os.path.join(base_dir, 'server/readme.txt'), 'readme.txt')
 
        bin_path = os.path.join(base_dir, 'client/bin/')
        zip.write(os.path.join(bin_path, 'server/server.exe'), 'server.exe')
+       zip.write(os.path.join(bin_path, 'server/config.json'), 'config.json')
                
        zip.close()
        
index 8b97eb7..b398de9 100644 (file)
@@ -40,36 +40,36 @@ Config::Config()
 
 void Config::Load()
 {
-    using boost::property_tree::ptree;
-    ptree pt;
-
-    try {
-        read_json(std::ifstream(CONFIG_JSON), pt);
-    } catch(std::exception& e) {
+       try {
+               read_json(std::ifstream(CONFIG_JSON), pt_);
+       } catch(std::exception& e) {
                Logger::Error(unicode::ToTString(e.what()));
-    }
+       }
        
-    port_ =             pt.get<uint16_t>("port", 39390);\r
-    server_name_ =             pt.get<std::string>("server_name", "MMO Server");
-    stage_ =                   pt.get<std::string>("stage", "stage:ケロリン町");
-    capacity_ =                        pt.get<int>("capacity", 20);
+    port_ =             pt_.get<uint16_t>("port", 39390);\r
+    server_name_ =             pt_.get<std::string>("server_name", "MMO Server");
+       stage_ =                        pt_.get<std::string>("stage", unicode::sjis2utf8("stage:ケロリン町"));
+    capacity_ =                        pt_.get<int>("capacity", 20);
 
-       public_ =                       pt.get<bool>("public", false);
+       public_ =                       pt_.get<bool>("public", false);
 
-       receive_limit_1_ =      pt.get<int>("receive_limit_1", 60);
-       receive_limit_2_ =      pt.get<int>("receive_limit_2", 100);
+       receive_limit_1_ =      pt_.get<int>("receive_limit_1", 60);
+       receive_limit_2_ =      pt_.get<int>("receive_limit_2", 100);
 
-       auto patterns =         pt.get_child("blocking_address_patterns", ptree());
+       auto patterns =         pt_.get_child("blocking_address_patterns", ptree());
        BOOST_FOREACH(const auto& item, patterns) {
                blocking_address_patterns_.push_back(item.second.get_value<std::string>());
        }
        
-       timestamp_ = last_write_time(CONFIG_JSON);
+       if (exists(CONFIG_JSON)) {
+               timestamp_ = last_write_time(CONFIG_JSON);
+       }
 }
 
 void Config::Reload()
 {
-       if (timestamp_ < last_write_time(CONFIG_JSON)) {
+       if (exists(CONFIG_JSON) &&
+               timestamp_ < last_write_time(CONFIG_JSON)) {
                Config::Load();
                Logger::Info(_T("Configuration reloaded."));
        }
@@ -112,4 +112,9 @@ int Config::receive_limit_2() const
 const std::list<std::string>& Config::blocking_address_patterns() const
 {
        return blocking_address_patterns_;
+}
+
+const boost::property_tree::ptree& Config::pt() const
+{
+       return pt_;
 }
\ No newline at end of file
index 0b2d42a..f1bddf4 100644 (file)
@@ -31,6 +31,8 @@ class Config
                \r
                std::list<std::string> blocking_address_patterns_;\r
 \r
+               boost::property_tree::ptree pt_;\r
+\r
     public:\r
         uint16_t port() const;\r
         const std::string& server_name() const;\r
@@ -42,6 +44,8 @@ class Config
 \r
                const std::list<std::string>& blocking_address_patterns() const;\r
 \r
+               const boost::property_tree::ptree& pt() const;\r
+\r
        private:\r
                static const char* CONFIG_JSON;\r
                time_t timestamp_;\r
index 35f7b60..5c3f279 100644 (file)
@@ -99,6 +99,18 @@ namespace network {
                return msg;\r
        }\r
 \r
+       std::string Server::GetFullStatus() const\r
+       {\r
+               using namespace boost::property_tree;\r
+               ptree xml_ptree;\r
+\r
+               xml_ptree.put_child("config", config_.pt());\r
+\r
+               std::stringstream stream;\r
+               write_xml(stream, xml_ptree);\r
+               return stream.str();\r
+       }\r
+\r
     bool Server::Empty() const\r
     {\r
         return GetUserCount() == 0;\r
@@ -120,16 +132,13 @@ namespace network {
                config_.Reload();\r
 \r
                const auto address = session->tcp_socket().remote_endpoint().address();\r
+\r
+               // 拒否IPでないか判定\r
                if(IsBlockedAddress(address)) {\r
                        Logger::Info("Blocked IP Address: %s", address);\r
             session->Close();\r
 \r
-               } else if (GetUserCount() >= config_.capacity()) {\r
-                       Logger::Info("Refused Session");\r
-            session->SyncSend(ClientReceiveServerCrowdedError());\r
-            session->Close();\r
-\r
-        } else {\r
+               } else {\r
             session->set_on_receive(callback_);\r
             session->Start();\r
             sessions_.push_back(SessionWeakPtr(session));\r
index d23d3d5..c28af92 100644 (file)
@@ -37,6 +37,7 @@ class Server {
 \r
         bool Empty() const;\r
                std::string GetStatusJSON() const;\r
+               std::string GetFullStatus() const;\r
 \r
         int GetSessionReadAverageLimit();\r
                int GetUserCount() const;\r
index ddcdaed..dc4ec85 100644 (file)
@@ -18,6 +18,7 @@
 #include "Config.hpp"\r
 #include "Account.hpp"\r
 #include "version.hpp"\r
+\r
 #ifdef __linux__\r
 #include "ServerSigHandler.hpp"\r
 #include <csignal>\r
@@ -82,6 +83,15 @@ void server()
 \r
         switch (c.header()) {\r
 \r
+               // フルステータス要求\r
+               case network::header::ServerRequestedFullServerInfo:\r
+               {\r
+                       if (auto session = c.session().lock()) {\r
+                               session->Send(network::ClientReceiveFullServerInfo(server.GetFullStatus()));\r
+                       }\r
+               }\r
+               break;\r
+\r
                // ステータス要求\r
                case network::header::ServerRequstedStatus:\r
                {\r
@@ -156,6 +166,14 @@ void server()
         {\r
             if (auto session = c.session().lock()) {\r
 \r
+                               // 最大接続数を超えていないか判定\r
+                               if (server.GetUserCount() >= config.capacity()) {\r
+                                       Logger::Info("Refused Session");\r
+                                       session->SyncSend(network::ClientReceiveServerCrowdedError());\r
+                                       session->Close();\r
+\r
+                               }\r
+\r
                                session->ResetReadByteAverage();\r
 \r
                 std::string finger_print;\r