• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版39630f65538f113a9e2562e710525b6a84a4e4e0 (tree)
时间2012-10-06 01:23:54
作者h2so5 <h2so5@git....>
Commiterh2so5

Log Message

ClientReceiveFullServerInfo, ServerRequestedFullServerInfo コマンドを追加
サーバーのconfig.jsonのリポジトリ上の位置を変更

更改概述

差异

--- a/.gitignore
+++ b/.gitignore
@@ -17,7 +17,6 @@ log_*.txt
1717 /Client/bin/account.xml
1818 /Client/bin/config.json
1919 /Client/bin/Log.txt
20-/Client/bin/server
2120 /Server/server_key.pub
2221 /Server/server_key
2322 /Server/Debug
@@ -30,7 +29,6 @@ log_*.txt
3029 /server/buildversion.hpp
3130 /server/Release
3231 /ServerLauncher
33-/client/bin/server
3432 /client/bin/tool
3533 /client/bin/widgets
3634 /client/bin/models
--- a/client/Client.cpp
+++ b/client/Client.cpp
@@ -108,6 +108,8 @@ Client::Client(const std::string& host,
108108 (uint16_t)MMO_PROTOCOL_VERSION,
109109 session->udp_port()
110110 ));
111+
112+ session->Send(network::ServerRequestedFullServerInfo());
111113 }
112114 }
113115 break;
--- a/client/CommandManager.cpp
+++ b/client/CommandManager.cpp
@@ -85,6 +85,14 @@ void CommandManager::FetchCommand(const network::Command& command)
8585 }
8686 break;
8787
88+ // サーバーデータ受信
89+ case ClientReceiveFullServerInfo:
90+ {
91+ std::string xml;
92+ network::Utils::Deserialize(command.body(), &xml);
93+ }
94+ break;
95+
8896 case ClientReceiveJSON:
8997 // case ClientReceiveChatLog:
9098 {
--- a/mmo-0.3.9_123/system/languages/en.json
+++ b/client/bin/system/languages/en.json
@@ -9,6 +9,7 @@
99 "status":
1010 {
1111 "name": "Status",
12+ "trip": "Tripcode",
1213 "nickname": "Nickname",
1314 "modelname": "Model",
1415 "user_id": "UserID",
--- a/mmo-0.3.9_123/system/languages/jp.json
+++ b/client/bin/system/languages/jp.json
@@ -9,6 +9,7 @@
99 "status":
1010 {
1111 "name": "ステータス",
12+ "trip": "トリップ",
1213 "nickname": "ニックネーム",
1314 "modelname": "モデル名",
1415 "user_id": "ユーザーID",
--- a/client/bin/system/plugins/textchat/main.js
+++ b/client/bin/system/plugins/textchat/main.js
@@ -17,6 +17,11 @@ var list;
1717 // チャットメッセージ受信
1818 var even_line = false;
1919 Network.onReceive = function (info, msg) {
20+
21+ if (msg.type && msg.type != "chat") {
22+ return;
23+ }
24+
2025 var trip = ""
2126 if (info.player.trip()) {
2227 trip = "《" + info.player.trip() + "》"
@@ -151,13 +156,14 @@ InputBox.onEnter = function (text) {
151156
152157 // システム
153158 case "system":
154- var msgObject = { system: args.trim() };
159+ var msgObject = { type: "system", system: args.trim() };
155160 Network.sendAll(msgObject);
156161 break;
157162
158163 // プライベート
159164 case "private":
160165 var msgObject = {
166+ type: "chat",
161167 private: [
162168 Player.myself().id(),
163169 Player.getFromName([args.trim()]).id()
@@ -177,7 +183,7 @@ InputBox.onEnter = function (text) {
177183
178184 } else {
179185 // コマンドでない場合はそのままチャットメッセージとして送信
180- var msgObject = { body: text };
186+ var msgObject = { type: "chat", body: text };
181187 Network.sendAll(msgObject);
182188 }
183189
--- a/common/network/Command.cpp
+++ b/common/network/Command.cpp
@@ -40,22 +40,9 @@ FatalConnectionError::FatalConnectionError(uint32_t user_id) :
4040 body_ = Utils::Serialize(user_id);
4141 }
4242
43-ServerStartEncryptedSession::ServerStartEncryptedSession() :
44- Command(header::ServerStartEncryptedSession, "")
45-{
46-
47-}
48-
49-ClientStartEncryptedSession::ClientStartEncryptedSession() :
50- Command(header::ClientStartEncryptedSession, "")
51-{
52-
53-}
54-
5543 ServerReceivePublicKey::ServerReceivePublicKey(const std::string& key) :
5644 Command(header::ServerReceivePublicKey, key)
5745 {
58-
5946 }
6047
6148 ClientReceiveCommonKey::ClientReceiveCommonKey(const std::string& key,
@@ -83,18 +70,6 @@ ServerReceiveClientInfo::ServerReceiveClientInfo(const std::string& key, uint16_
8370
8471 }
8572
86-ClientRequestedPublicKey::ClientRequestedPublicKey() :
87- Command(header::ClientRequestedPublicKey, "")
88-{
89-
90-}
91-
92-ClientRequestedClientInfo::ClientRequestedClientInfo() :
93- Command(header::ClientRequestedClientInfo, "")
94-{
95-
96-}
97-
9873 ServerRequestedAccountRevisionPatch::ServerRequestedAccountRevisionPatch(uint32_t user_id, int revision) :
9974 Command(header::ServerRequestedAccountRevisionPatch,
10075 Utils::Serialize(user_id, revision))
@@ -118,12 +93,6 @@ ClientReceiveWriteAverageLimitUpdate::ClientReceiveWriteAverageLimitUpdate(uint1
11893 {
11994 }
12095
121-ClientReceiveServerCrowdedError::ClientReceiveServerCrowdedError() :
122- Command(header::ClientReceiveServerCrowdedError, "")
123-{
124-
125-}
126-
12796 ClientReceiveUnsupportVersionError::ClientReceiveUnsupportVersionError(uint32_t require_version) :
12897 Command(header::ClientReceiveUnsupportVersionError, Utils::Serialize(require_version))
12998 {
@@ -157,4 +126,10 @@ ClientReceiveServerInfo::ClientReceiveServerInfo(const std::string& stage) :
157126
158127 }
159128
129+ClientReceiveFullServerInfo::ClientReceiveFullServerInfo(const std::string& xml) :
130+ Command(header::ClientReceiveFullServerInfo, Utils::Serialize(xml))
131+{
132+
133+}
134+
160135 }
--- a/common/network/Command.hpp
+++ b/common/network/Command.hpp
@@ -43,6 +43,20 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
4343 boost::asio::ip::udp::endpoint udp_endpoint_;
4444 };
4545
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+
4660 // コネクションの切断
4761 class FatalConnectionError : public Command {
4862 public:
@@ -50,18 +64,6 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
5064 FatalConnectionError(uint32_t user_id);
5165 };
5266
53- // 暗号化通信を開始
54- class ServerStartEncryptedSession : public Command {
55- public:
56- ServerStartEncryptedSession();
57- };
58-
59- // 暗号化通信を開始
60- class ClientStartEncryptedSession : public Command {
61- public:
62- ClientStartEncryptedSession();
63- };
64-
6567 // クライアントからの公開鍵を受信
6668 class ServerReceivePublicKey : public Command {
6769 public:
@@ -94,18 +96,6 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
9496 ServerReceiveClientInfo(const std::string& key, uint16_t version, uint16_t udp_port);
9597 };
9698
97- // 公開鍵を要求された
98- class ClientRequestedPublicKey : public Command {
99- public:
100- ClientRequestedPublicKey();
101- };
102-
103- // クライアントの情報を要求された
104- class ClientRequestedClientInfo : public Command {
105- public:
106- ClientRequestedClientInfo();
107- };
108-
10999 class ServerRequestedAccountRevisionPatch : public Command {
110100 public:
111101 ServerRequestedAccountRevisionPatch(uint32_t user_id, int revision);
@@ -128,11 +118,6 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
128118 ClientReceiveWriteAverageLimitUpdate(uint16_t byte);
129119 };
130120
131- class ClientReceiveServerCrowdedError : public Command {
132- public:
133- ClientReceiveServerCrowdedError();
134- };
135-
136121 class ClientReceiveUnsupportVersionError : public Command {
137122 public:
138123 ClientReceiveUnsupportVersionError(uint32_t require_version);
@@ -163,4 +148,9 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
163148 ClientReceiveServerInfo(const std::string& stage);
164149 };
165150
151+ class ClientReceiveFullServerInfo : public Command {
152+ public:
153+ ClientReceiveFullServerInfo(const std::string& xml);
154+ };
155+
166156 }
--- a/common/network/CommandHeader.hpp
+++ b/common/network/CommandHeader.hpp
@@ -28,6 +28,8 @@ namespace header {
2828 ServerUpdateAccountProperty = 0x13,
2929 ServerReceiveJSON = 0x14,
3030 ClientReceiveJSON = 0x15,
31+ ServerRequestedFullServerInfo = 0x16,
32+ ClientReceiveFullServerInfo = 0x17,
3133
3234 ServerReceiveWriteLimit = 0x20,
3335 ServerRequstedStatus = 0xE0,
--- a/package.py
+++ b/package.py
@@ -35,7 +35,7 @@ def make_full_package(model = True):
3535 zip.write(os.path.join(base_dir, 'license.txt'), 'license.txt')
3636 zip.write(os.path.join(base_dir, 'mmd.txt'), 'mmd.txt')
3737
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')
3939
4040 zip.write(os.path.join(bin_path, 'config.json'), 'config.json')
4141 zip.write(os.path.join(bin_path, 'server/server.exe'), 'server/server.exe')
@@ -91,11 +91,11 @@ def make_server_package():
9191 zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
9292
9393 zip.write(os.path.join(base_dir, 'license.txt'), 'license.txt')
94- zip.write(os.path.join(base_dir, 'server/config.json'), 'config.json')
9594 zip.write(os.path.join(base_dir, 'server/readme.txt'), 'readme.txt')
9695
9796 bin_path = os.path.join(base_dir, 'client/bin/')
9897 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')
9999
100100 zip.close()
101101
--- a/server/Config.cpp
+++ b/server/Config.cpp
@@ -40,36 +40,36 @@ Config::Config()
4040
4141 void Config::Load()
4242 {
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) {
4946 Logger::Error(unicode::ToTString(e.what()));
50- }
47+ }
5148
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);
5653
57- public_ = pt.get<bool>("public", false);
54+ public_ = pt_.get<bool>("public", false);
5855
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);
6158
62- auto patterns = pt.get_child("blocking_address_patterns", ptree());
59+ auto patterns = pt_.get_child("blocking_address_patterns", ptree());
6360 BOOST_FOREACH(const auto& item, patterns) {
6461 blocking_address_patterns_.push_back(item.second.get_value<std::string>());
6562 }
6663
67- timestamp_ = last_write_time(CONFIG_JSON);
64+ if (exists(CONFIG_JSON)) {
65+ timestamp_ = last_write_time(CONFIG_JSON);
66+ }
6867 }
6968
7069 void Config::Reload()
7170 {
72- if (timestamp_ < last_write_time(CONFIG_JSON)) {
71+ if (exists(CONFIG_JSON) &&
72+ timestamp_ < last_write_time(CONFIG_JSON)) {
7373 Config::Load();
7474 Logger::Info(_T("Configuration reloaded."));
7575 }
@@ -112,4 +112,9 @@ int Config::receive_limit_2() const
112112 const std::list<std::string>& Config::blocking_address_patterns() const
113113 {
114114 return blocking_address_patterns_;
115+}
116+
117+const boost::property_tree::ptree& Config::pt() const
118+{
119+ return pt_;
115120 }
\ No newline at end of file
--- a/server/Config.hpp
+++ b/server/Config.hpp
@@ -31,6 +31,8 @@ class Config
3131
3232 std::list<std::string> blocking_address_patterns_;
3333
34+ boost::property_tree::ptree pt_;
35+
3436 public:
3537 uint16_t port() const;
3638 const std::string& server_name() const;
@@ -42,6 +44,8 @@ class Config
4244
4345 const std::list<std::string>& blocking_address_patterns() const;
4446
47+ const boost::property_tree::ptree& pt() const;
48+
4549 private:
4650 static const char* CONFIG_JSON;
4751 time_t timestamp_;
--- a/server/Server.cpp
+++ b/server/Server.cpp
@@ -99,6 +99,18 @@ namespace network {
9999 return msg;
100100 }
101101
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+
102114 bool Server::Empty() const
103115 {
104116 return GetUserCount() == 0;
@@ -120,16 +132,13 @@ namespace network {
120132 config_.Reload();
121133
122134 const auto address = session->tcp_socket().remote_endpoint().address();
135+
136+ // 拒否IPでないか判定
123137 if(IsBlockedAddress(address)) {
124138 Logger::Info("Blocked IP Address: %s", address);
125139 session->Close();
126140
127- } else if (GetUserCount() >= config_.capacity()) {
128- Logger::Info("Refused Session");
129- session->SyncSend(ClientReceiveServerCrowdedError());
130- session->Close();
131-
132- } else {
141+ } else {
133142 session->set_on_receive(callback_);
134143 session->Start();
135144 sessions_.push_back(SessionWeakPtr(session));
--- a/server/Server.hpp
+++ b/server/Server.hpp
@@ -37,6 +37,7 @@ class Server {
3737
3838 bool Empty() const;
3939 std::string GetStatusJSON() const;
40+ std::string GetFullStatus() const;
4041
4142 int GetSessionReadAverageLimit();
4243 int GetUserCount() const;
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -18,6 +18,7 @@
1818 #include "Config.hpp"
1919 #include "Account.hpp"
2020 #include "version.hpp"
21+
2122 #ifdef __linux__
2223 #include "ServerSigHandler.hpp"
2324 #include <csignal>
@@ -82,6 +83,15 @@ void server()
8283
8384 switch (c.header()) {
8485
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+
8595 // ステータス要求
8696 case network::header::ServerRequstedStatus:
8797 {
@@ -156,6 +166,14 @@ void server()
156166 {
157167 if (auto session = c.session().lock()) {
158168
169+ // 最大接続数を超えていないか判定
170+ if (server.GetUserCount() >= config.capacity()) {
171+ Logger::Info("Refused Session");
172+ session->SyncSend(network::ClientReceiveServerCrowdedError());
173+ session->Close();
174+
175+ }
176+
159177 session->ResetReadByteAverage();
160178
161179 std::string finger_print;