• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

Commit MetaInfo

修訂4169eaba9b61717a5898fe1bd883d52240008c21 (tree)
時間2012-10-07 21:58:12
作者h2so5 <h2so5@git....>
Commiterh2so5

Log Message

Linux環境でビルドが通らない問題を修正
チャンネル機能を途中まで実装

Change Summary

差異

--- a/client/bin/server/config.json
+++ b/client/bin/server/config.json
@@ -1,6 +1,15 @@
11 {
22 "port": 39390,
3+
34 "server_name": "MMO Server",
5+ "server_note": "MikuMikuOnlineのサーバーです",
6+
7+ "public": true,
8+ "lobby_servers":
9+ [
10+ "m2op.net"
11+ ],
12+
413 "stage": "stage:ケロリン町",
514 "capacity": 20,
615
--- a/common/network/Command.cpp
+++ b/common/network/Command.cpp
@@ -28,6 +28,11 @@ boost::asio::ip::udp::endpoint Command::udp_endpoint() const
2828 return udp_endpoint_;
2929 }
3030
31+bool Command::plain() const
32+{
33+ return plain_;
34+}
35+
3136 FatalConnectionError::FatalConnectionError() :
3237 Command(header::FatalConnectionError, "")
3338 {
@@ -132,4 +137,10 @@ ClientReceiveFullServerInfo::ClientReceiveFullServerInfo(const std::string& xml)
132137
133138 }
134139
140+ClientReceivePlainFullServerInfo::ClientReceivePlainFullServerInfo(const std::string& xml) :
141+ Command(header::ClientReceivePlainFullServerInfo, Utils::Serialize(xml))
142+{
143+ plain_ = true;
144+}
145+
135146 }
--- a/common/network/Command.hpp
+++ b/common/network/Command.hpp
@@ -19,20 +19,25 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
1919
2020 class Command {
2121 public:
22- Command(header::CommandHeader header, const std::string body) :
23- header_(header), body_(body) {}
22+ Command(header::CommandHeader header,
23+ const std::string body) :
24+ header_(header), body_(body), plain_(false) {}
2425
25- Command(header::CommandHeader header, const std::string body, const SessionWeakPtr& session) :
26- header_(header), body_(body), session_(session) {}
26+ Command(header::CommandHeader header,
27+ const std::string body,
28+ const SessionWeakPtr& session) :
29+ header_(header), body_(body), session_(session), plain_(false) {}
2730
28- Command(header::CommandHeader header, const std::string body,
31+ Command(header::CommandHeader header,
32+ const std::string body,
2933 const boost::asio::ip::udp::endpoint& udp_endpoint) :
30- header_(header), body_(body), udp_endpoint_(udp_endpoint) {}
34+ header_(header), body_(body), udp_endpoint_(udp_endpoint), plain_(false) {}
3135
3236 header::CommandHeader header() const;
3337 const std::string& body() const;
3438 SessionWeakPtr session();
3539 boost::asio::ip::udp::endpoint udp_endpoint() const;
40+ bool plain() const;
3641
3742 private:
3843 header::CommandHeader header_;
@@ -41,6 +46,7 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
4146 std::string body_;
4247 SessionWeakPtr session_;
4348 boost::asio::ip::udp::endpoint udp_endpoint_;
49+ bool plain_;
4450 };
4551
4652 template<header::CommandHeader Header>
@@ -56,6 +62,7 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
5662 typedef CommandTemplate<header::ClientRequestedClientInfo> ClientRequestedClientInfo;
5763 typedef CommandTemplate<header::ClientReceiveServerCrowdedError> ClientReceiveServerCrowdedError;
5864 typedef CommandTemplate<header::ServerRequestedFullServerInfo> ServerRequestedFullServerInfo;
65+ typedef CommandTemplate<header::ServerRequestedPlainFullServerInfo> ServerRequestedPlainFullServerInfo;
5966
6067 // コネクションの切断
6168 class FatalConnectionError : public Command {
@@ -153,4 +160,8 @@ typedef boost::weak_ptr<Session> SessionWeakPtr;
153160 ClientReceiveFullServerInfo(const std::string& xml);
154161 };
155162
163+ class ClientReceivePlainFullServerInfo : public Command {
164+ public:
165+ ClientReceivePlainFullServerInfo(const std::string& xml);
166+ };
156167 }
--- a/common/network/CommandHeader.hpp
+++ b/common/network/CommandHeader.hpp
@@ -32,6 +32,10 @@ namespace header {
3232 ClientReceiveFullServerInfo = 0x17,
3333
3434 ServerReceiveWriteLimit = 0x20,
35+
36+ ServerRequestedPlainFullServerInfo = 0x40,
37+ ClientReceivePlainFullServerInfo = 0x41,
38+
3539 ServerRequstedStatus = 0xE0,
3640
3741 LZ4_COMPRESS_HEADER = 0xF0,
--- a/common/network/Session.cpp
+++ b/common/network/Session.cpp
@@ -43,7 +43,7 @@ namespace network {
4343
4444 void Session::Send(const Command& command)
4545 {
46- auto msg = Serialize(command);
46+ auto msg = Serialize(command, command.plain());
4747 write_byte_sum_ += msg.size();
4848 UpdateWriteByteAverage();
4949
@@ -54,7 +54,7 @@ namespace network {
5454
5555 void Session::SyncSend(const Command& command)
5656 {
57- auto msg = Serialize(command);
57+ auto msg = Serialize(command, command.plain());
5858 write_byte_sum_ += msg.size();
5959 UpdateWriteByteAverage();
6060
@@ -194,7 +194,7 @@ namespace network {
194194 write_average_limit_ = limit;
195195 }
196196
197- std::string Session::Serialize(const Command& command)
197+ std::string Session::Serialize(const Command& command, bool plain)
198198 {
199199 assert(command.header() < 0xFF);
200200 auto header = static_cast<uint8_t>(command.header());
@@ -202,24 +202,29 @@ namespace network {
202202
203203 std::string msg = Utils::Serialize(header) + body;
204204
205- // 圧縮
206- if (body.size() >= COMPRESS_MIN_LENGTH) {
207- auto compressed = Utils::LZ4Compress(msg);
208- if (msg.size() > compressed.size() + sizeof(uint8_t)) {
209- assert(msg.size() < 65535);
210- msg = Utils::Serialize(static_cast<uint8_t>(header::LZ4_COMPRESS_HEADER),
211- static_cast<uint16_t>(msg.size()))
212- + compressed;
213- }
214- }
215-
216- // 暗号化
217- if (encryption_) {
218- msg = Utils::Serialize(static_cast<uint8_t>(header::ENCRYPT_HEADER))
219- + encrypter_.Encrypt(msg);
220- }
205+ if (plain) {
206+ auto length = Utils::Serialize(static_cast<unsigned int>(msg.size()));
207+ return length + msg;
208+ } else {
209+ // 圧縮
210+ if (body.size() >= COMPRESS_MIN_LENGTH) {
211+ auto compressed = Utils::LZ4Compress(msg);
212+ if (msg.size() > compressed.size() + sizeof(uint8_t)) {
213+ assert(msg.size() < 65535);
214+ msg = Utils::Serialize(static_cast<uint8_t>(header::LZ4_COMPRESS_HEADER),
215+ static_cast<uint16_t>(msg.size()))
216+ + compressed;
217+ }
218+ }
219+
220+ // 暗号化
221+ if (encryption_) {
222+ msg = Utils::Serialize(static_cast<uint8_t>(header::ENCRYPT_HEADER))
223+ + encrypter_.Encrypt(msg);
224+ }
225+ return Utils::Encode(msg);
226+ }
221227
222- return Utils::Encode(msg);
223228 }
224229
225230 Command Session::Deserialize(const std::string& msg)
@@ -247,7 +252,7 @@ namespace network {
247252
248253 std::string body = decoded_msg.substr(sizeof(header));
249254
250- return Command(static_cast<header::CommandHeader>(header), body, shared_from_this());
255+ return Command(static_cast<header::CommandHeader>(header), body, shared_from_this());
251256 }
252257
253258 void Session::ReceiveTCP(const boost::system::error_code& error)
--- a/common/network/Session.hpp
+++ b/common/network/Session.hpp
@@ -81,7 +81,7 @@ namespace network {
8181 void UpdateReadByteAverage();
8282 void UpdateWriteByteAverage();
8383
84- std::string Serialize(const Command& command);
84+ std::string Serialize(const Command& command, bool plain);
8585 Command Deserialize(const std::string& msg);
8686
8787 void ReceiveTCP(const boost::system::error_code& error);
--- a/server/Account.cpp
+++ b/server/Account.cpp
@@ -9,7 +9,7 @@
99 #include <boost/date_time/posix_time/posix_time.hpp>
1010 #include <assert.h>
1111
12-Account::Account(const std::string& logfile) :
12+Account::Account() :
1313 revision_(0),
1414 max_user_id_(0)
1515 {
--- a/server/Account.hpp
+++ b/server/Account.hpp
@@ -15,10 +15,11 @@
1515 #include <boost/thread.hpp>
1616
1717 typedef uint32_t UserID;
18+#undef GetUserName
1819
1920 class Account {
2021 public:
21- Account(const std::string&);
22+ Account();
2223 ~Account();
2324
2425 void LoadInitializeData(UserID user_id, std::string data);
--- /dev/null
+++ b/server/Channel.cpp
@@ -0,0 +1,43 @@
1+//
2+// Channel.hpp
3+//
4+
5+#include "Channel.hpp"
6+#include <boost/filesystem.hpp>
7+
8+using namespace boost::filesystem;
9+
10+Channel::Channel()
11+{
12+ Load();
13+}
14+
15+void Channel::Load()
16+{
17+ pt_.clear();
18+ path p("./channels");
19+
20+ if (exists(p) && is_directory(p)) {
21+ for (auto it_dir = directory_iterator(p); it_dir != directory_iterator(); ++it_dir) {
22+ if (is_directory(*it_dir)) {
23+ path json_path = it_dir->path() / "config.json";
24+ if (exists(json_path)) {
25+ auto channel_str = it_dir->path().leaf().string();
26+ try {
27+ boost::property_tree::ptree config_pt;
28+ read_json(json_path.string(), config_pt);
29+ pt_.put_child(channel_str, config_pt);
30+
31+ } catch (const std::exception& e) {
32+ Logger::Error("%d", e.what());
33+ }
34+ }
35+ }
36+ }
37+ }
38+}
39+
40+const boost::property_tree::ptree& Channel::pt() const
41+{
42+ return pt_;
43+}
\ No newline at end of file
--- /dev/null
+++ b/server/Channel.hpp
@@ -0,0 +1,19 @@
1+//
2+// Channel.cpp
3+//
4+
5+#pragma once
6+#include <boost/property_tree/json_parser.hpp>
7+
8+class Channel {
9+ public:
10+ Channel();
11+
12+ const boost::property_tree::ptree& pt() const;
13+
14+ private:
15+ void Load();
16+
17+ private:
18+ boost::property_tree::ptree pt_;
19+};
\ No newline at end of file
--- a/server/Config.cpp
+++ b/server/Config.cpp
@@ -40,15 +40,19 @@ Config::Config()
4040
4141 void Config::Load()
4242 {
43+
4344 try {
44- read_json(std::ifstream(CONFIG_JSON), pt_);
45+ std::ifstream ifs;
46+ ifs.open(CONFIG_JSON);
47+ read_json(ifs, pt_);
4548 } catch(std::exception& e) {
4649 Logger::Error(unicode::ToTString(e.what()));
4750 }
4851
4952 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:ケロリン町"));
53+ server_name_ = pt_.get<std::string>("server_name", "MMO Server");
54+ server_note_ = pt_.get<std::string>("server_note", "");
55+ stage_ = pt_.get<std::string>("stage", unicode::ToString(_T("stage:ケロリン町")));
5256 capacity_ = pt_.get<int>("capacity", 20);
5357
5458 public_ = pt_.get<bool>("public", false);
@@ -60,6 +64,11 @@ void Config::Load()
6064 BOOST_FOREACH(const auto& item, patterns) {
6165 blocking_address_patterns_.push_back(item.second.get_value<std::string>());
6266 }
67+
68+ auto lobby_servers = pt_.get_child("lobby_servers", ptree());
69+ BOOST_FOREACH(const auto& item, lobby_servers) {
70+ lobby_servers_.push_back(item.second.get_value<std::string>());
71+ }
6372
6473 if (exists(CONFIG_JSON)) {
6574 timestamp_ = last_write_time(CONFIG_JSON);
@@ -89,6 +98,16 @@ const std::string& Config::server_name() const
8998 return server_name_;
9099 }
91100
101+const std::string& Config::server_note() const
102+{
103+ return server_note_;
104+}
105+
106+bool Config::is_public() const
107+{
108+ return public_;
109+}
110+
92111 const std::string& Config::stage() const
93112 {
94113 return stage_;
@@ -113,6 +132,11 @@ const std::list<std::string>& Config::blocking_address_patterns() const
113132 {
114133 return blocking_address_patterns_;
115134 }
135+
136+const std::list<std::string>& Config::lobby_servers() const
137+{
138+ return lobby_servers_;
139+}
116140
117141 const boost::property_tree::ptree& Config::pt() const
118142 {
--- a/server/Config.hpp
+++ b/server/Config.hpp
@@ -21,6 +21,7 @@ class Config
2121
2222 uint16_t port_;
2323 std::string server_name_;
24+ std::string server_note_;
2425 std::string stage_;
2526 int capacity_;
2627
@@ -30,12 +31,17 @@ class Config
3031 int receive_limit_2_;
3132
3233 std::list<std::string> blocking_address_patterns_;
34+ std::list<std::string> lobby_servers_;
3335
3436 boost::property_tree::ptree pt_;
3537
3638 public:
3739 uint16_t port() const;
3840 const std::string& server_name() const;
41+ const std::string& server_note() const;
42+
43+ bool is_public() const;
44+
3945 const std::string& stage() const;
4046 int capacity() const;
4147
@@ -43,6 +49,7 @@ class Config
4349 int receive_limit_2() const;
4450
4551 const std::list<std::string>& blocking_address_patterns() const;
52+ const std::list<std::string>& lobby_servers() const;
4653
4754 const boost::property_tree::ptree& pt() const;
4855
--- a/server/Makefile
+++ b/server/Makefile
@@ -15,6 +15,7 @@ OBJS += $(patsubst %.c,%.o,$(wildcard ../common/network/lz4/*.c))
1515
1616 all: stdafx.h.gch $(OBJS)
1717 $(LD) $(CXXFLAGS) -o $(TARGET) $(OBJS) $(LIBS) $(LIBDIRS)
18+ cp ../client/bin/server/config.json .
1819
1920 clean:
2021 @rm -f $(OBJS) $(TARGET) stdafx.h.gch
--- a/server/Server.cpp
+++ b/server/Server.cpp
@@ -13,12 +13,12 @@
1313
1414 namespace network {
1515
16- Server::Server(Config& config) :
17- config_(config),
18- endpoint_(tcp::v4(), config.port()),
16+ Server::Server() :
17+ endpoint_(tcp::v4(), config_.port()),
1918 acceptor_(io_service_, endpoint_),
20- socket_udp_(io_service_, udp::endpoint(udp::v4(), config.port())),
21- udp_packet_count_(0)
19+ socket_udp_(io_service_, udp::endpoint(udp::v4(), config_.port())),
20+ udp_packet_count_(0),
21+ recent_chat_log_(10)
2222 {
2323 }
2424
@@ -48,6 +48,12 @@ namespace network {
4848
4949 });
5050
51+ BOOST_FOREACH(const auto& host, config().lobby_servers()) {
52+ udp::resolver resolver(io_service_);
53+ udp::resolver::query query(udp::v4(), host.c_str(), "39380");
54+ lobby_hosts_.push_back(resolver.resolve(query));
55+ }
56+
5157 {
5258 auto new_session = boost::make_shared<ServerSession>(io_service_);
5359 acceptor_.async_accept(new_session->tcp_socket(),
@@ -105,12 +111,52 @@ namespace network {
105111 ptree xml_ptree;
106112
107113 xml_ptree.put_child("config", config_.pt());
114+ xml_ptree.put("version", (boost::format("%d.%d.%d")
115+ % MMO_VERSION_MAJOR % MMO_VERSION_MINOR % MMO_VERSION_REVISION).str());
116+ xml_ptree.put("protocol_version", MMO_PROTOCOL_VERSION);
117+
118+ {
119+ ptree player_array;
120+ auto id_list = account_.GetIDList();
121+ BOOST_FOREACH(unsigned int id, id_list) {
122+ ptree player;
123+ player.put("name", account_.GetUserName(id));
124+ player.put("model_name", account_.GetUserModelName(id));
125+ player_array.push_back(std::make_pair("", player));
126+ }
127+ xml_ptree.put_child("players", player_array);
128+ }
129+
130+ {
131+ ptree log_array;
132+ BOOST_FOREACH(const std::string& msg, recent_chat_log_) {
133+ log_array.push_back(std::make_pair("", msg));
134+ }
135+ xml_ptree.put_child("recent_chat_log", log_array);
136+ }
108137
138+ xml_ptree.put_child("channels", channel_.pt());
139+
109140 std::stringstream stream;
110141 write_xml(stream, xml_ptree);
111142 return stream.str();
112143 }
113144
145+ const Config& Server::config() const
146+ {
147+ return config_;
148+ }
149+
150+ Account& Server::account()
151+ {
152+ return account_;
153+ }
154+
155+ void Server::AddChatLog(const std::string& msg)
156+ {
157+ recent_chat_log_.push_back(msg);
158+ }
159+
114160 bool Server::Empty() const
115161 {
116162 return GetUserCount() == 0;
@@ -171,7 +217,9 @@ namespace network {
171217 if (auto session = ptr.lock()) {
172218 if (channel < 0 || (channel >= 0 && session->channel() == channel)) {
173219 if (!limited || session->write_average_limit() > session->GetWriteByteAverage()) {
174- session->Send(command);
220+ if (session->id() > 0) {
221+ session->Send(command);
222+ }
175223 }
176224 }
177225 }
@@ -184,7 +232,7 @@ namespace network {
184232 if (auto session = ptr.lock()) {
185233 if (channel < 0 || (channel >= 0 && session->channel() == channel)) {
186234 if (!limited || session->write_average_limit() > session->GetWriteByteAverage()) {
187- if (session->id() != self_id) {
235+ if (session->id() > 0 && session->id() != self_id) {
188236 session->Send(command);
189237 }
190238 }
@@ -223,6 +271,14 @@ namespace network {
223271 }
224272 }
225273
274+ void Server::SendPublicPing()
275+ {
276+ static char request[] = "P";
277+ BOOST_FOREACH(const auto& iterator, lobby_hosts_) {
278+ io_service_.post(boost::bind(&Server::DoWriteUDP, this, request, *iterator));
279+ }
280+ }
281+
226282 void Server::SendUDP(const std::string& message, const boost::asio::ip::udp::endpoint endpoint)
227283 {
228284 io_service_.post(boost::bind(&Server::DoWriteUDP, this, message, endpoint));
--- a/server/Server.hpp
+++ b/server/Server.hpp
@@ -7,8 +7,11 @@
77 #include <string>
88 #include <list>
99 #include <functional>
10+#include <boost/circular_buffer.hpp>
1011 #include "../common/network/Session.hpp"
1112 #include "Config.hpp"
13+#include "Account.hpp"
14+#include "Channel.hpp"
1215
1316 #define UDP_MAX_RECEIVE_LENGTH (2048)
1417 #define UDP_TEST_PACKET_TIME (5)
@@ -26,7 +29,7 @@ class Server {
2629 };
2730
2831 public:
29- Server(Config& config);
32+ Server();
3033 void Start(CallbackFuncPtr callback);
3134 void Stop();
3235 void Stop(int interrupt_type);
@@ -39,12 +42,18 @@ class Server {
3942 std::string GetStatusJSON() const;
4043 std::string GetFullStatus() const;
4144
45+ const Config& config() const;
46+ Account& account();
47+
48+ void AddChatLog(const std::string& msg);
49+
4250 int GetSessionReadAverageLimit();
4351 int GetUserCount() const;
4452 void RefreshSession();
4553
4654 void SendUDPTestPacket(const std::string& ip_address, uint16_t port);
4755 void SendUDP(const std::string& message, const boost::asio::ip::udp::endpoint endpoint);
56+ void SendPublicPing();
4857
4958 bool IsBlockedAddress(const boost::asio::ip::address& address);
5059
@@ -58,7 +67,9 @@ class Server {
5867 void FetchUDP(const std::string& buffer, const boost::asio::ip::udp::endpoint endpoint);
5968
6069 private:
61- Config& config_;
70+ Config config_;
71+ Account account_;
72+ Channel channel_;
6273
6374 boost::asio::io_service io_service_;
6475 tcp::endpoint endpoint_;
@@ -75,6 +86,9 @@ class Server {
7586 boost::mutex mutex_;
7687 std::list<SessionWeakPtr> sessions_;
7788
89+ boost::circular_buffer<std::string> recent_chat_log_;
90+ std::list<udp::resolver::iterator> lobby_hosts_;
91+
7892 };
7993
8094 }
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -16,7 +16,6 @@
1616 #include "../common/database/AccountProperty.hpp"
1717 #include "../common/Logger.hpp"
1818 #include "Config.hpp"
19-#include "Account.hpp"
2019 #include "version.hpp"
2120
2221 #ifdef __linux__
@@ -32,6 +31,7 @@
3231 using namespace boost::posix_time;
3332
3433 void client_sync(network::Server& server);
34+void public_ping(network::Server& server);
3535 void server();
3636
3737 int main(int argc, char* argv[])
@@ -58,18 +58,14 @@ int main(int argc, char* argv[])
5858 void server()
5959 {
6060
61- // 設定を読み込み
62- Config config;
63-
6461 // 署名
6562 network::Signature sign("server_key");
6663
6764 // アカウント
68- Account account("account.db");
69- network::Server server(config);
65+ network::Server server;
7066
7167 auto callback = std::make_shared<std::function<void(network::Command)>>(
72- [&server, &account, &sign, &config](network::Command c){
68+ [&server, &sign](network::Command c){
7369
7470 // ログを出力
7571 auto msg = (boost::format("Receive: 0x%08x %dbyte") % c.header() % c.body().size()).str();
@@ -80,10 +76,9 @@ void server()
8076 // if (auto session = c.session().lock()) {
8177 // std::cout << "Write Average: " << session->GetReadByteAverage() << "bytes" << std::endl;
8278 // }
83-
79+ auto header = c.header();
8480 switch (c.header()) {
8581
86- // フルステータス要求
8782 case network::header::ServerRequestedFullServerInfo:
8883 {
8984 if (auto session = c.session().lock()) {
@@ -92,6 +87,14 @@ void server()
9287 }
9388 break;
9489
90+ case network::header::ServerRequestedPlainFullServerInfo:
91+ {
92+ if (auto session = c.session().lock()) {
93+ session->Send(network::ClientReceivePlainFullServerInfo(server.GetFullStatus()));
94+ }
95+ }
96+ break;
97+
9598 // ステータス要求
9699 case network::header::ServerRequstedStatus:
97100 {
@@ -139,6 +142,10 @@ void server()
139142 server.SendTo(send_command, user_id);
140143 }
141144 } else {
145+ auto name = server.account().GetUserName(id);
146+ auto body = message_tree.get<std::string>("body", std::string());
147+ server.AddChatLog((boost::format("[%s] %s") % name % body).str());
148+
142149 server.SendAll(send_command, session->channel());
143150 }
144151
@@ -154,7 +161,7 @@ void server()
154161 if (auto session = c.session().lock()) {
155162 PlayerPosition pos;
156163 network::Utils::Deserialize(c.body(), &pos.x, &pos.y, &pos.z, &pos.theta, &pos.vy);
157- account.SetUserPosition(session->id(), pos);
164+ server.account().SetUserPosition(session->id(), pos);
158165 server.SendOthers(network::ClientUpdatePlayerPosition(session->id(),
159166 pos.x,pos.y,pos.z,pos.theta, pos.vy), session->id(), session->channel(), true);
160167 }
@@ -167,7 +174,7 @@ void server()
167174 if (auto session = c.session().lock()) {
168175
169176 // 最大接続数を超えていないか判定
170- if (server.GetUserCount() >= config.capacity()) {
177+ if (server.GetUserCount() >= server.config().capacity()) {
171178 Logger::Info("Refused Session");
172179 session->SyncSend(network::ClientReceiveServerCrowdedError());
173180 session->Close();
@@ -197,7 +204,7 @@ void server()
197204 // テスト送信
198205 server.SendUDPTestPacket(session->global_ip(), session->udp_port());
199206
200- uint32_t id = account.GetUserIdFromFingerPrint(finger_print);
207+ uint32_t id = server.account().GetUserIdFromFingerPrint(finger_print);
201208 if (id == 0) {
202209 // 未登録の場合、公開鍵を要求
203210 session->Send(network::ClientRequestedPublicKey());
@@ -205,11 +212,11 @@ void server()
205212 uint32_t user_id = static_cast<uint32_t>(id);
206213 // ログイン
207214 session->set_id(user_id);
208- account.LogIn(user_id);
209- session->encrypter().SetPublicKey(account.GetPublicKey(user_id));
215+ server.account().LogIn(user_id);
216+ session->encrypter().SetPublicKey(server.account().GetPublicKey(user_id));
210217
211- account.SetUserIPAddress(session->id(), session->global_ip());
212- account.SetUserUDPPort(session->id(), session->udp_port());
218+ server.account().SetUserIPAddress(session->id(), session->global_ip());
219+ server.account().SetUserUDPPort(session->id(), session->udp_port());
213220
214221 // 共通鍵を送り返す
215222 auto key = session->encrypter().GetCryptedCommonKey();
@@ -225,18 +232,18 @@ void server()
225232 case network::header::ServerReceivePublicKey:
226233 {
227234 if (auto session = c.session().lock()) {
228- uint32_t user_id = account.RegisterPublicKey(c.body());
235+ uint32_t user_id = server.account().RegisterPublicKey(c.body());
229236 assert(user_id > 0);
230237
231238 session->ResetReadByteAverage();
232239
233240 // ログイン
234241 session->set_id(user_id);
235- account.LogIn(user_id);
236- session->encrypter().SetPublicKey(account.GetPublicKey(user_id));
242+ server.account().LogIn(user_id);
243+ session->encrypter().SetPublicKey(server.account().GetPublicKey(user_id));
237244
238- account.SetUserIPAddress(session->id(), session->global_ip());
239- account.SetUserUDPPort(session->id(), session->udp_port());
245+ server.account().SetUserIPAddress(session->id(), session->global_ip());
246+ server.account().SetUserUDPPort(session->id(), session->udp_port());
240247
241248 // 共通鍵を送り返す
242249 auto key = session->encrypter().GetCryptedCommonKey();
@@ -252,7 +259,7 @@ void server()
252259 {
253260 if (auto session = c.session().lock()) {
254261
255- session->Send(network::ClientReceiveServerInfo(config.stage()));
262+ session->Send(network::ClientReceiveServerInfo(server.config().stage()));
256263
257264 session->Send(network::ClientStartEncryptedSession());
258265 session->EnableEncryption();
@@ -266,17 +273,17 @@ void server()
266273 case network::header::ServerReceiveAccountInitializeData:
267274 {
268275 if (auto session = c.session().lock()) {
269- account.LoadInitializeData(session->id(), c.body());
276+ server.account().LoadInitializeData(session->id(), c.body());
270277
271- const auto& list = account.GetIDList();
278+ const auto& list = server.account().GetIDList();
272279 BOOST_FOREACH(UserID user_id, list) {
273280 session->Send(network::ClientReceiveAccountRevisionUpdateNotify(user_id,
274- account.GetUserRevision(user_id)));
281+ server.account().GetUserRevision(user_id)));
275282 }
276283
277284 server.SendOthers(
278285 network::ClientReceiveAccountRevisionUpdateNotify(session->id(),
279- account.GetUserRevision(session->id())), session->id());
286+ server.account().GetUserRevision(session->id())), session->id());
280287
281288 Logger::Info(msg);
282289 }
@@ -291,9 +298,9 @@ void server()
291298 uint32_t client_revision;
292299 network::Utils::Deserialize(c.body(), &user_id, &client_revision);
293300
294- if (client_revision < account.GetUserRevision(user_id)) {
301+ if (client_revision < server.account().GetUserRevision(user_id)) {
295302 session->Send(network::ClientReceiveAccountRevisionPatch(
296- account.GetUserRevisionPatch(user_id, client_revision)));
303+ server.account().GetUserRevisionPatch(user_id, client_revision)));
297304 }
298305 Logger::Info(msg);
299306 }
@@ -307,7 +314,7 @@ void server()
307314 std::string buffer = c.body().substr(sizeof(AccountProperty));
308315 network::Utils::Deserialize(c.body(), &property);
309316
310- auto old_revision = account.GetUserRevision(session->id());
317+ auto old_revision = server.account().GetUserRevision(session->id());
311318
312319 switch (property) {
313320
@@ -315,36 +322,37 @@ void server()
315322 {
316323 std::string value;
317324 network::Utils::Deserialize(buffer, &value);
318- account.SetUserName(session->id(), value);
325+ server.account().SetUserName(session->id(), value);
319326 }
320327 break;
321328 case TRIP:
322329 {
323330 std::string value;
324331 network::Utils::Deserialize(buffer, &value);
325- account.SetUserTrip(session->id(), value);
332+ server.account().SetUserTrip(session->id(), value);
326333 }
327334 break;
328335 case MODEL_NAME:
329336 {
330337 std::string value;
331338 network::Utils::Deserialize(buffer, &value);
332- account.SetUserModelName(session->id(), value);
339+ server.account().SetUserModelName(session->id(), value);
340+ }
341+ break;
342+ case CHANNEL:
343+ {
344+ std::string value;
345+ network::Utils::Deserialize(buffer, &value);
346+ auto channel = *reinterpret_cast<const unsigned int*>(value.data());
347+ server.account().SetUserChannel(session->id(), channel);
348+ session->set_channel(channel);
333349 }
334350 break;
335- // case CHANNEL:
336- // {
337- //unsigned char value;
338- //network::Utils::Deserialize(buffer, &value);
339- // account.SetUserChannel(session->id(), value);
340- //session->set_channel(value);
341- // }
342- // break;
343351 default:
344352 ;
345353 }
346354
347- auto new_revison = account.GetUserRevision(session->id());
355+ auto new_revison = server.account().GetUserRevision(session->id());
348356 if (new_revison > old_revision) {
349357 server.SendAll(
350358 network::ClientReceiveAccountRevisionUpdateNotify(
@@ -362,14 +370,14 @@ void server()
362370 if (c.body().size() > 0) {
363371 int user_id;
364372 network::Utils::Deserialize(c.body(), &user_id);
365- account.LogOut(user_id);
373+ server.account().LogOut(user_id);
366374
367375 server.SendAll(
368376 network::ClientReceiveAccountRevisionUpdateNotify(user_id,
369- account.GetUserRevision(user_id)));
377+ server.account().GetUserRevision(user_id)));
370378
371379 Logger::Info("Logout User: %d", user_id);
372- account.Remove(user_id);
380+ server.account().Remove(user_id);
373381 }
374382 }
375383 Logger::Info(msg);
@@ -382,9 +390,24 @@ void server()
382390 });
383391
384392 client_sync(server);
393+
394+ if (server.config().is_public()) {
395+ public_ping(server);
396+ }
397+
385398 server.Start(callback);
386399 }
387400
401+void public_ping(network::Server& server)
402+{
403+ boost::thread([&server](){
404+ while (1) {
405+ boost::this_thread::sleep(boost::posix_time::seconds(10));
406+ server.SendPublicPing();
407+ }
408+ });
409+}
410+
388411 void client_sync(network::Server& server)
389412 {
390413 bool execute_with_client;
@@ -404,7 +427,7 @@ void client_sync(network::Server& server)
404427 if (execute_with_client) {
405428 boost::thread([&server](){
406429 while (1) {
407- boost::this_thread::sleep(boost::posix_time::milliseconds(4000));
430+ boost::this_thread::sleep(boost::posix_time::seconds(4));
408431 try {
409432 using namespace boost::interprocess;
410433 windows_shared_memory shm(open_only, "MMO_SERVER_WITH_CLIENT", read_only);
--- a/server/stdafx.h
+++ b/server/stdafx.h
@@ -54,5 +54,7 @@
5454 #include <boost/format.hpp>
5555 #include <boost/thread.hpp>
5656 #include <boost/foreach.hpp>
57+#include <boost/circular_buffer.hpp>
58+#include <boost/lexical_cast.hpp>
5759
5860 #include "../common/Logger.hpp"
\ No newline at end of file