修订版 | 39630f65538f113a9e2562e710525b6a84a4e4e0 (tree) |
---|---|
时间 | 2012-10-06 01:23:54 |
作者 | h2so5 <h2so5@git....> |
Commiter | h2so5 |
ClientReceiveFullServerInfo, ServerRequestedFullServerInfo コマンドを追加
サーバーのconfig.jsonのリポジトリ上の位置を変更
@@ -17,7 +17,6 @@ log_*.txt | ||
17 | 17 | /Client/bin/account.xml |
18 | 18 | /Client/bin/config.json |
19 | 19 | /Client/bin/Log.txt |
20 | -/Client/bin/server | |
21 | 20 | /Server/server_key.pub |
22 | 21 | /Server/server_key |
23 | 22 | /Server/Debug |
@@ -30,7 +29,6 @@ log_*.txt | ||
30 | 29 | /server/buildversion.hpp |
31 | 30 | /server/Release |
32 | 31 | /ServerLauncher |
33 | -/client/bin/server | |
34 | 32 | /client/bin/tool |
35 | 33 | /client/bin/widgets |
36 | 34 | /client/bin/models |
@@ -108,6 +108,8 @@ Client::Client(const std::string& host, | ||
108 | 108 | (uint16_t)MMO_PROTOCOL_VERSION, |
109 | 109 | session->udp_port() |
110 | 110 | )); |
111 | + | |
112 | + session->Send(network::ServerRequestedFullServerInfo()); | |
111 | 113 | } |
112 | 114 | } |
113 | 115 | break; |
@@ -85,6 +85,14 @@ void CommandManager::FetchCommand(const network::Command& command) | ||
85 | 85 | } |
86 | 86 | break; |
87 | 87 | |
88 | + // サーバーデータ受信 | |
89 | + case ClientReceiveFullServerInfo: | |
90 | + { | |
91 | + std::string xml; | |
92 | + network::Utils::Deserialize(command.body(), &xml); | |
93 | + } | |
94 | + break; | |
95 | + | |
88 | 96 | case ClientReceiveJSON: |
89 | 97 | // case ClientReceiveChatLog: |
90 | 98 | { |
@@ -9,6 +9,7 @@ | ||
9 | 9 | "status": |
10 | 10 | { |
11 | 11 | "name": "Status", |
12 | + "trip": "Tripcode", | |
12 | 13 | "nickname": "Nickname", |
13 | 14 | "modelname": "Model", |
14 | 15 | "user_id": "UserID", |
@@ -9,6 +9,7 @@ | ||
9 | 9 | "status": |
10 | 10 | { |
11 | 11 | "name": "ステータス", |
12 | + "trip": "トリップ", | |
12 | 13 | "nickname": "ニックネーム", |
13 | 14 | "modelname": "モデル名", |
14 | 15 | "user_id": "ユーザーID", |
@@ -17,6 +17,11 @@ var list; | ||
17 | 17 | // チャットメッセージ受信 |
18 | 18 | var even_line = false; |
19 | 19 | Network.onReceive = function (info, msg) { |
20 | + | |
21 | + if (msg.type && msg.type != "chat") { | |
22 | + return; | |
23 | + } | |
24 | + | |
20 | 25 | var trip = "" |
21 | 26 | if (info.player.trip()) { |
22 | 27 | trip = "《" + info.player.trip() + "》" |
@@ -151,13 +156,14 @@ InputBox.onEnter = function (text) { | ||
151 | 156 | |
152 | 157 | // システム |
153 | 158 | case "system": |
154 | - var msgObject = { system: args.trim() }; | |
159 | + var msgObject = { type: "system", system: args.trim() }; | |
155 | 160 | Network.sendAll(msgObject); |
156 | 161 | break; |
157 | 162 | |
158 | 163 | // プライベート |
159 | 164 | case "private": |
160 | 165 | var msgObject = { |
166 | + type: "chat", | |
161 | 167 | private: [ |
162 | 168 | Player.myself().id(), |
163 | 169 | Player.getFromName([args.trim()]).id() |
@@ -177,7 +183,7 @@ InputBox.onEnter = function (text) { | ||
177 | 183 | |
178 | 184 | } else { |
179 | 185 | // コマンドでない場合はそのままチャットメッセージとして送信 |
180 | - var msgObject = { body: text }; | |
186 | + var msgObject = { type: "chat", body: text }; | |
181 | 187 | Network.sendAll(msgObject); |
182 | 188 | } |
183 | 189 |
@@ -40,22 +40,9 @@ FatalConnectionError::FatalConnectionError(uint32_t user_id) : | ||
40 | 40 | body_ = Utils::Serialize(user_id); |
41 | 41 | } |
42 | 42 | |
43 | -ServerStartEncryptedSession::ServerStartEncryptedSession() : | |
44 | - Command(header::ServerStartEncryptedSession, "") | |
45 | -{ | |
46 | - | |
47 | -} | |
48 | - | |
49 | -ClientStartEncryptedSession::ClientStartEncryptedSession() : | |
50 | - Command(header::ClientStartEncryptedSession, "") | |
51 | -{ | |
52 | - | |
53 | -} | |
54 | - | |
55 | 43 | ServerReceivePublicKey::ServerReceivePublicKey(const std::string& key) : |
56 | 44 | Command(header::ServerReceivePublicKey, key) |
57 | 45 | { |
58 | - | |
59 | 46 | } |
60 | 47 | |
61 | 48 | ClientReceiveCommonKey::ClientReceiveCommonKey(const std::string& key, |
@@ -83,18 +70,6 @@ ServerReceiveClientInfo::ServerReceiveClientInfo(const std::string& key, uint16_ | ||
83 | 70 | |
84 | 71 | } |
85 | 72 | |
86 | -ClientRequestedPublicKey::ClientRequestedPublicKey() : | |
87 | - Command(header::ClientRequestedPublicKey, "") | |
88 | -{ | |
89 | - | |
90 | -} | |
91 | - | |
92 | -ClientRequestedClientInfo::ClientRequestedClientInfo() : | |
93 | - Command(header::ClientRequestedClientInfo, "") | |
94 | -{ | |
95 | - | |
96 | -} | |
97 | - | |
98 | 73 | ServerRequestedAccountRevisionPatch::ServerRequestedAccountRevisionPatch(uint32_t user_id, int revision) : |
99 | 74 | Command(header::ServerRequestedAccountRevisionPatch, |
100 | 75 | Utils::Serialize(user_id, revision)) |
@@ -118,12 +93,6 @@ ClientReceiveWriteAverageLimitUpdate::ClientReceiveWriteAverageLimitUpdate(uint1 | ||
118 | 93 | { |
119 | 94 | } |
120 | 95 | |
121 | -ClientReceiveServerCrowdedError::ClientReceiveServerCrowdedError() : | |
122 | - Command(header::ClientReceiveServerCrowdedError, "") | |
123 | -{ | |
124 | - | |
125 | -} | |
126 | - | |
127 | 96 | ClientReceiveUnsupportVersionError::ClientReceiveUnsupportVersionError(uint32_t require_version) : |
128 | 97 | Command(header::ClientReceiveUnsupportVersionError, Utils::Serialize(require_version)) |
129 | 98 | { |
@@ -157,4 +126,10 @@ ClientReceiveServerInfo::ClientReceiveServerInfo(const std::string& stage) : | ||
157 | 126 | |
158 | 127 | } |
159 | 128 | |
129 | +ClientReceiveFullServerInfo::ClientReceiveFullServerInfo(const std::string& xml) : | |
130 | + Command(header::ClientReceiveFullServerInfo, Utils::Serialize(xml)) | |
131 | +{ | |
132 | + | |
133 | +} | |
134 | + | |
160 | 135 | } |
@@ -43,6 +43,20 @@ typedef boost::weak_ptr<Session> SessionWeakPtr; | ||
43 | 43 | boost::asio::ip::udp::endpoint udp_endpoint_; |
44 | 44 | }; |
45 | 45 | |
46 | + template<header::CommandHeader Header> | |
47 | + class CommandTemplate : public Command { | |
48 | + public: | |
49 | + CommandTemplate() : | |
50 | + Command(Header, "") {} | |
51 | + }; | |
52 | + | |
53 | + typedef CommandTemplate<header::ServerStartEncryptedSession> ServerStartEncryptedSession; | |
54 | + typedef CommandTemplate<header::ClientStartEncryptedSession> ClientStartEncryptedSession; | |
55 | + typedef CommandTemplate<header::ClientRequestedPublicKey> ClientRequestedPublicKey; | |
56 | + typedef CommandTemplate<header::ClientRequestedClientInfo> ClientRequestedClientInfo; | |
57 | + typedef CommandTemplate<header::ClientReceiveServerCrowdedError> ClientReceiveServerCrowdedError; | |
58 | + typedef CommandTemplate<header::ServerRequestedFullServerInfo> ServerRequestedFullServerInfo; | |
59 | + | |
46 | 60 | // コネクションの切断 |
47 | 61 | class FatalConnectionError : public Command { |
48 | 62 | public: |
@@ -50,18 +64,6 @@ typedef boost::weak_ptr<Session> SessionWeakPtr; | ||
50 | 64 | FatalConnectionError(uint32_t user_id); |
51 | 65 | }; |
52 | 66 | |
53 | - // 暗号化通信を開始 | |
54 | - class ServerStartEncryptedSession : public Command { | |
55 | - public: | |
56 | - ServerStartEncryptedSession(); | |
57 | - }; | |
58 | - | |
59 | - // 暗号化通信を開始 | |
60 | - class ClientStartEncryptedSession : public Command { | |
61 | - public: | |
62 | - ClientStartEncryptedSession(); | |
63 | - }; | |
64 | - | |
65 | 67 | // クライアントからの公開鍵を受信 |
66 | 68 | class ServerReceivePublicKey : public Command { |
67 | 69 | public: |
@@ -94,18 +96,6 @@ typedef boost::weak_ptr<Session> SessionWeakPtr; | ||
94 | 96 | ServerReceiveClientInfo(const std::string& key, uint16_t version, uint16_t udp_port); |
95 | 97 | }; |
96 | 98 | |
97 | - // 公開鍵を要求された | |
98 | - class ClientRequestedPublicKey : public Command { | |
99 | - public: | |
100 | - ClientRequestedPublicKey(); | |
101 | - }; | |
102 | - | |
103 | - // クライアントの情報を要求された | |
104 | - class ClientRequestedClientInfo : public Command { | |
105 | - public: | |
106 | - ClientRequestedClientInfo(); | |
107 | - }; | |
108 | - | |
109 | 99 | class ServerRequestedAccountRevisionPatch : public Command { |
110 | 100 | public: |
111 | 101 | ServerRequestedAccountRevisionPatch(uint32_t user_id, int revision); |
@@ -128,11 +118,6 @@ typedef boost::weak_ptr<Session> SessionWeakPtr; | ||
128 | 118 | ClientReceiveWriteAverageLimitUpdate(uint16_t byte); |
129 | 119 | }; |
130 | 120 | |
131 | - class ClientReceiveServerCrowdedError : public Command { | |
132 | - public: | |
133 | - ClientReceiveServerCrowdedError(); | |
134 | - }; | |
135 | - | |
136 | 121 | class ClientReceiveUnsupportVersionError : public Command { |
137 | 122 | public: |
138 | 123 | ClientReceiveUnsupportVersionError(uint32_t require_version); |
@@ -163,4 +148,9 @@ typedef boost::weak_ptr<Session> SessionWeakPtr; | ||
163 | 148 | ClientReceiveServerInfo(const std::string& stage); |
164 | 149 | }; |
165 | 150 | |
151 | + class ClientReceiveFullServerInfo : public Command { | |
152 | + public: | |
153 | + ClientReceiveFullServerInfo(const std::string& xml); | |
154 | + }; | |
155 | + | |
166 | 156 | } |
@@ -28,6 +28,8 @@ namespace header { | ||
28 | 28 | ServerUpdateAccountProperty = 0x13, |
29 | 29 | ServerReceiveJSON = 0x14, |
30 | 30 | ClientReceiveJSON = 0x15, |
31 | + ServerRequestedFullServerInfo = 0x16, | |
32 | + ClientReceiveFullServerInfo = 0x17, | |
31 | 33 | |
32 | 34 | ServerReceiveWriteLimit = 0x20, |
33 | 35 | ServerRequstedStatus = 0xE0, |
@@ -35,7 +35,7 @@ def make_full_package(model = True): | ||
35 | 35 | zip.write(os.path.join(base_dir, 'license.txt'), 'license.txt') |
36 | 36 | zip.write(os.path.join(base_dir, 'mmd.txt'), 'mmd.txt') |
37 | 37 | |
38 | - zip.write(os.path.join(base_dir, 'server/config.json'), 'server/config.json') | |
38 | + zip.write(os.path.join(bin_path, 'server/config.json'), 'server/config.json') | |
39 | 39 | |
40 | 40 | zip.write(os.path.join(bin_path, 'config.json'), 'config.json') |
41 | 41 | zip.write(os.path.join(bin_path, 'server/server.exe'), 'server/server.exe') |
@@ -91,11 +91,11 @@ def make_server_package(): | ||
91 | 91 | zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) |
92 | 92 | |
93 | 93 | zip.write(os.path.join(base_dir, 'license.txt'), 'license.txt') |
94 | - zip.write(os.path.join(base_dir, 'server/config.json'), 'config.json') | |
95 | 94 | zip.write(os.path.join(base_dir, 'server/readme.txt'), 'readme.txt') |
96 | 95 | |
97 | 96 | bin_path = os.path.join(base_dir, 'client/bin/') |
98 | 97 | zip.write(os.path.join(bin_path, 'server/server.exe'), 'server.exe') |
98 | + zip.write(os.path.join(bin_path, 'server/config.json'), 'config.json') | |
99 | 99 | |
100 | 100 | zip.close() |
101 | 101 |
@@ -40,36 +40,36 @@ Config::Config() | ||
40 | 40 | |
41 | 41 | void Config::Load() |
42 | 42 | { |
43 | - using boost::property_tree::ptree; | |
44 | - ptree pt; | |
45 | - | |
46 | - try { | |
47 | - read_json(std::ifstream(CONFIG_JSON), pt); | |
48 | - } catch(std::exception& e) { | |
43 | + try { | |
44 | + read_json(std::ifstream(CONFIG_JSON), pt_); | |
45 | + } catch(std::exception& e) { | |
49 | 46 | Logger::Error(unicode::ToTString(e.what())); |
50 | - } | |
47 | + } | |
51 | 48 | |
52 | - port_ = pt.get<uint16_t>("port", 39390); | |
53 | - server_name_ = pt.get<std::string>("server_name", "MMO Server"); | |
54 | - stage_ = pt.get<std::string>("stage", "stage:ケロリン町"); | |
55 | - capacity_ = pt.get<int>("capacity", 20); | |
49 | + port_ = pt_.get<uint16_t>("port", 39390); | |
50 | + server_name_ = pt_.get<std::string>("server_name", "MMO Server"); | |
51 | + stage_ = pt_.get<std::string>("stage", unicode::sjis2utf8("stage:ケロリン町")); | |
52 | + capacity_ = pt_.get<int>("capacity", 20); | |
56 | 53 | |
57 | - public_ = pt.get<bool>("public", false); | |
54 | + public_ = pt_.get<bool>("public", false); | |
58 | 55 | |
59 | - receive_limit_1_ = pt.get<int>("receive_limit_1", 60); | |
60 | - receive_limit_2_ = pt.get<int>("receive_limit_2", 100); | |
56 | + receive_limit_1_ = pt_.get<int>("receive_limit_1", 60); | |
57 | + receive_limit_2_ = pt_.get<int>("receive_limit_2", 100); | |
61 | 58 | |
62 | - auto patterns = pt.get_child("blocking_address_patterns", ptree()); | |
59 | + auto patterns = pt_.get_child("blocking_address_patterns", ptree()); | |
63 | 60 | BOOST_FOREACH(const auto& item, patterns) { |
64 | 61 | blocking_address_patterns_.push_back(item.second.get_value<std::string>()); |
65 | 62 | } |
66 | 63 | |
67 | - timestamp_ = last_write_time(CONFIG_JSON); | |
64 | + if (exists(CONFIG_JSON)) { | |
65 | + timestamp_ = last_write_time(CONFIG_JSON); | |
66 | + } | |
68 | 67 | } |
69 | 68 | |
70 | 69 | void Config::Reload() |
71 | 70 | { |
72 | - if (timestamp_ < last_write_time(CONFIG_JSON)) { | |
71 | + if (exists(CONFIG_JSON) && | |
72 | + timestamp_ < last_write_time(CONFIG_JSON)) { | |
73 | 73 | Config::Load(); |
74 | 74 | Logger::Info(_T("Configuration reloaded.")); |
75 | 75 | } |
@@ -112,4 +112,9 @@ int Config::receive_limit_2() const | ||
112 | 112 | const std::list<std::string>& Config::blocking_address_patterns() const |
113 | 113 | { |
114 | 114 | return blocking_address_patterns_; |
115 | +} | |
116 | + | |
117 | +const boost::property_tree::ptree& Config::pt() const | |
118 | +{ | |
119 | + return pt_; | |
115 | 120 | } |
\ No newline at end of file |
@@ -31,6 +31,8 @@ class Config | ||
31 | 31 | |
32 | 32 | std::list<std::string> blocking_address_patterns_; |
33 | 33 | |
34 | + boost::property_tree::ptree pt_; | |
35 | + | |
34 | 36 | public: |
35 | 37 | uint16_t port() const; |
36 | 38 | const std::string& server_name() const; |
@@ -42,6 +44,8 @@ class Config | ||
42 | 44 | |
43 | 45 | const std::list<std::string>& blocking_address_patterns() const; |
44 | 46 | |
47 | + const boost::property_tree::ptree& pt() const; | |
48 | + | |
45 | 49 | private: |
46 | 50 | static const char* CONFIG_JSON; |
47 | 51 | time_t timestamp_; |
@@ -99,6 +99,18 @@ namespace network { | ||
99 | 99 | return msg; |
100 | 100 | } |
101 | 101 | |
102 | + std::string Server::GetFullStatus() const | |
103 | + { | |
104 | + using namespace boost::property_tree; | |
105 | + ptree xml_ptree; | |
106 | + | |
107 | + xml_ptree.put_child("config", config_.pt()); | |
108 | + | |
109 | + std::stringstream stream; | |
110 | + write_xml(stream, xml_ptree); | |
111 | + return stream.str(); | |
112 | + } | |
113 | + | |
102 | 114 | bool Server::Empty() const |
103 | 115 | { |
104 | 116 | return GetUserCount() == 0; |
@@ -120,16 +132,13 @@ namespace network { | ||
120 | 132 | config_.Reload(); |
121 | 133 | |
122 | 134 | const auto address = session->tcp_socket().remote_endpoint().address(); |
135 | + | |
136 | + // 拒否IPでないか判定 | |
123 | 137 | if(IsBlockedAddress(address)) { |
124 | 138 | Logger::Info("Blocked IP Address: %s", address); |
125 | 139 | session->Close(); |
126 | 140 | |
127 | - } else if (GetUserCount() >= config_.capacity()) { | |
128 | - Logger::Info("Refused Session"); | |
129 | - session->SyncSend(ClientReceiveServerCrowdedError()); | |
130 | - session->Close(); | |
131 | - | |
132 | - } else { | |
141 | + } else { | |
133 | 142 | session->set_on_receive(callback_); |
134 | 143 | session->Start(); |
135 | 144 | sessions_.push_back(SessionWeakPtr(session)); |
@@ -37,6 +37,7 @@ class Server { | ||
37 | 37 | |
38 | 38 | bool Empty() const; |
39 | 39 | std::string GetStatusJSON() const; |
40 | + std::string GetFullStatus() const; | |
40 | 41 | |
41 | 42 | int GetSessionReadAverageLimit(); |
42 | 43 | int GetUserCount() const; |
@@ -18,6 +18,7 @@ | ||
18 | 18 | #include "Config.hpp" |
19 | 19 | #include "Account.hpp" |
20 | 20 | #include "version.hpp" |
21 | + | |
21 | 22 | #ifdef __linux__ |
22 | 23 | #include "ServerSigHandler.hpp" |
23 | 24 | #include <csignal> |
@@ -82,6 +83,15 @@ void server() | ||
82 | 83 | |
83 | 84 | switch (c.header()) { |
84 | 85 | |
86 | + // フルステータス要求 | |
87 | + case network::header::ServerRequestedFullServerInfo: | |
88 | + { | |
89 | + if (auto session = c.session().lock()) { | |
90 | + session->Send(network::ClientReceiveFullServerInfo(server.GetFullStatus())); | |
91 | + } | |
92 | + } | |
93 | + break; | |
94 | + | |
85 | 95 | // ステータス要求 |
86 | 96 | case network::header::ServerRequstedStatus: |
87 | 97 | { |
@@ -156,6 +166,14 @@ void server() | ||
156 | 166 | { |
157 | 167 | if (auto session = c.session().lock()) { |
158 | 168 | |
169 | + // 最大接続数を超えていないか判定 | |
170 | + if (server.GetUserCount() >= config.capacity()) { | |
171 | + Logger::Info("Refused Session"); | |
172 | + session->SyncSend(network::ClientReceiveServerCrowdedError()); | |
173 | + session->Close(); | |
174 | + | |
175 | + } | |
176 | + | |
159 | 177 | session->ResetReadByteAverage(); |
160 | 178 | |
161 | 179 | std::string finger_print; |