• 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

修订版8b758e5dfb3e33bdd34068906a7bdc015bda817b (tree)
时间2012-09-30 03:00:28
作者h2so5 <h2so5@git....>
Commiterh2so5

Log Message

チャンネル機能を仮実装

更改概述

差异

--- a/client/Card.cpp
+++ b/client/Card.cpp
@@ -18,6 +18,7 @@
1818 #include "ResourceManager.hpp"
1919 #include "../common/unicode.hpp"
2020 #include "../common/network/Command.hpp"
21+#include "../common/network/Utils.hpp"
2122 #include "../common/database/AccountProperty.hpp"
2223 #include "Profiler.hpp"
2324 #include "GenerateJSON.hpp"
@@ -403,6 +404,42 @@ Handle<Value> Card::Function_Account_updateTrip(const Arguments& args)
403404 return Undefined();
404405 }
405406
407+Handle<Value> Card::Function_Account_channel(const Arguments& args)
408+{
409+ auto self = static_cast<Card*>(args.Holder()->GetPointerFromInternalField(0));
410+
411+ int id = 0;
412+ if (auto command_manager = self->manager_accessor_->command_manager().lock()) {
413+ id = command_manager->user_id();
414+ }
415+ if (auto player_manager = self->manager_accessor_->player_manager().lock()) {
416+ if (auto player = player_manager->GetFromId(id)) {
417+ return Integer::New(player->channel());
418+ }
419+ }
420+
421+ return Undefined();
422+}
423+
424+Handle<Value> Card::Function_Account_updateChannel(const Arguments& args)
425+{
426+ auto self = static_cast<Card*>(args.Holder()->GetPointerFromInternalField(0));
427+
428+ if (args.Length() >= 1 && args[0]->IsNumber()) {
429+
430+ int channel = args[0]->ToInteger()->Int32Value();
431+
432+ if (channel >= 0 && channel <= UCHAR_MAX) {
433+ if (auto command_manager = self->manager_accessor_->command_manager().lock()) {
434+ auto channel_str = network::Utils::Serialize((unsigned char)channel);
435+ command_manager->Write(network::ServerUpdateAccountProperty(CHANNEL, channel_str));
436+ }
437+ }
438+ }
439+
440+ return Undefined();
441+}
442+
406443
407444 Handle<Value> Card::Function_Screen_width(const Arguments& args)
408445 {
@@ -931,6 +968,26 @@ void Card::SetFunctions()
931968 script_.SetFunction("Account.updateTrip", Function_Account_updateTrip);
932969
933970 /**
971+ * 現在のチャンネルを返します
972+ *
973+ * @method channel
974+ * @return {Integer} チャンネル
975+ *
976+ * @static
977+ */
978+ script_.SetFunction("Account.channel", Function_Account_channel);
979+
980+ /**
981+ * 現在のチャンネルを設定します
982+ *
983+ * @method updateChannel
984+ * @param {Integer} channel チャンネル
985+ *
986+ * @static
987+ */
988+ script_.SetFunction("Account.updateChannel", Function_Account_updateChannel);
989+
990+ /**
934991 * カード
935992 *
936993 * @class Card
Binary files a/client/Card.hpp and b/client/Card.hpp differ
--- a/client/Player.cpp
+++ b/client/Player.cpp
@@ -33,6 +33,7 @@ id_(id),
3333 name_(""),
3434 model_name_(""),
3535 login_(false),
36+channel_(0),
3637 revision_(0)
3738 {
3839 name_tip_image_handle_ = ResourceManager::LoadCachedDivGraph<4>(
@@ -291,6 +292,14 @@ Handle<Value> Player::Function_Player_login(const Arguments& args)
291292 return Boolean::New(self->login_);
292293 }
293294
295+Handle<Value> Player::Function_Player_channel(const Arguments& args)
296+{
297+ assert(args.This()->InternalFieldCount() > 0);
298+ auto self = *static_cast<PlayerPtr*>(args.This()->GetPointerFromInternalField(0));
299+ assert(self);
300+ return Integer::New(self->channel_);
301+}
302+
294303 Handle<Value> Player::Function_Player_setBalloonContent(const Arguments& args)
295304 {
296305
@@ -386,6 +395,13 @@ void Player::RegisterFunctionTemplate(Handle<FunctionTemplate>& func)
386395 */
387396 object->Set(String::New("login"), FunctionTemplate::New(Function_Player_login));
388397
398+ /**
399+ * プレイヤーチャンネルを返します
400+ *
401+ * @method channel
402+ * @return {Integer} ログインしている時trueを返します
403+ */
404+ object->Set(String::New("channel"), FunctionTemplate::New(Function_Player_channel));
389405
390406 /**
391407 * プレイヤーの頭上の吹き出しに表示する内容を設定します
@@ -541,6 +557,16 @@ void Player::set_model_name(const std::string& trip)
541557 model_name_ = trip;
542558 }
543559
560+std::string Player::current_model_name() const
561+{
562+ return current_model_name_;
563+}
564+
565+void Player::set_current_model_name(const std::string& model_name)
566+{
567+ current_model_name_ = model_name;
568+}
569+
544570 bool Player::login() const
545571 {
546572 return login_;
@@ -551,6 +577,16 @@ void Player::set_login(bool login)
551577 login_ = login;
552578 }
553579
580+unsigned char Player::channel() const
581+{
582+ return channel_;
583+}
584+
585+void Player::set_channel(unsigned char channel)
586+{
587+ channel_ = channel;
588+}
589+
554590 uint32_t Player::revision() const
555591 {
556592 return revision_;
--- a/client/Player.hpp
+++ b/client/Player.hpp
@@ -52,6 +52,7 @@ class Player : public std::enable_shared_from_this<Player> {
5252 static Handle<Value> Function_Player_name(const Arguments& args);
5353 static Handle<Value> Function_Player_trip(const Arguments& args);
5454 static Handle<Value> Function_Player_login(const Arguments& args);
55+ static Handle<Value> Function_Player_channel(const Arguments& args);
5556 static Handle<Value> Function_Player_setBalloonContent(const Arguments& args);
5657 static Handle<Value> Function_Player_position(const Arguments& args);
5758
@@ -65,12 +66,19 @@ class Player : public std::enable_shared_from_this<Player> {
6566 void set_trip(const std::string& trip);
6667 std::string model_name() const;
6768 void set_model_name(const std::string& model_name);
69+
6870 bool login() const;
6971 void set_login(bool login);
72+ unsigned char channel() const;
73+ void set_channel(unsigned char channel);
74+
7075 uint32_t revision() const;
7176 void set_revision(uint32_t revision);
7277 const PlayerPosition& position() const;
7378 void set_position(const PlayerPosition& pos);
79+
80+ std::string current_model_name() const;
81+ void set_current_model_name(const std::string& model_name);
7482
7583 std::string ip_address() const;
7684 void set_ip_address(const std::string& ip_address);
@@ -88,8 +96,9 @@ class Player : public std::enable_shared_from_this<Player> {
8896 unsigned int id_;
8997 std::string name_;
9098 std::string trip_;
91- std::string model_name_;
99+ std::string model_name_, current_model_name_;
92100 bool login_;
101+ unsigned char channel_;
93102 unsigned int revision_;
94103 PlayerPosition pos_;
95104
Binary files a/client/PlayerManager.cpp and b/client/PlayerManager.cpp differ
--- a/client/ui/UIList.cpp
+++ b/client/ui/UIList.cpp
@@ -49,7 +49,7 @@ Handle<Value> UIList::Function_addItem(const Arguments& args)
4949 if (args.This() != child) {
5050 UIBasePtr child_ptr = *static_cast<UIBasePtr*>(child->GetPointerFromInternalField(0));
5151 child_ptr->set_parent(args.This());
52- self->items_.push_back(Persistent<Object>::New(child));
52+ self->items_.push_back(child_ptr);
5353 }
5454 }
5555 return args.This();
@@ -64,10 +64,9 @@ Handle<Value> UIList::Function_removeItem(const Arguments& args)
6464 assert(self);
6565
6666 if (args.Length() > 0 && args[0]->IsObject()) {
67- auto child = args[0]->ToObject();
68- auto it = std::find(self->items_.begin(), self->items_.end(), child);
67+ auto it = std::find(self->items_.begin(), self->items_.end(), self);
6968 if (it != self->items_.end()) {
70- UIBasePtr chid_ptr = *static_cast<UIBasePtr*>((*it)->GetPointerFromInternalField(0));
69+ UIBasePtr chid_ptr = *it;
7170 chid_ptr->set_parent(Handle<Object>());
7271 self->items_.erase(it);
7372 }
@@ -84,7 +83,7 @@ Handle<Value> UIList::Function_clearItems(const Arguments& args)
8483 assert(self);
8584
8685 BOOST_FOREACH(auto it, self->items_) {
87- UIBasePtr chid_ptr = *static_cast<UIBasePtr*>(it->GetPointerFromInternalField(0));
86+ UIBasePtr chid_ptr = it;
8887 chid_ptr->set_parent(Handle<Object>());
8988 }
9089 self->items_.clear();
@@ -159,9 +158,7 @@ void UIList::DefineInstanceTemplate(Handle<ObjectTemplate>* object)
159158
160159 void UIList::ProcessInput(InputManager* input)
161160 {
162- for (auto it = items_.begin(); it != items_.end(); ++it) {
163- auto item = *it;
164- UIBasePtr item_ptr = *static_cast<UIBasePtr*>(item->GetPointerFromInternalField(0));
161+ BOOST_FOREACH (UIBasePtr& item_ptr, items_) {
165162 if (input->GetMousePos().second > absolute_y() &&
166163 input->GetMousePos().second < absolute_y() + absolute_height()) {
167164 item_ptr->ProcessInput(input);
@@ -226,9 +223,7 @@ void UIList::Update()
226223
227224 int content_height = 0;
228225 int index = 0;
229- for (auto it = items_.begin(); it != items_.end(); ++it) {
230- auto item = *it;
231- UIBasePtr item_ptr = *static_cast<UIBasePtr*>(item->GetPointerFromInternalField(0));
226+ BOOST_FOREACH (UIBasePtr& item_ptr, items_) {
232227 item_ptr->set_offset_y(offset_y - BASE_BLOCK_SIZE);
233228 // item_ptr->set_offset_width(-18);
234229 item_ptr->Update();
@@ -271,8 +266,7 @@ void UIList::Draw()
271266 SetDrawArea(absolute_x(), absolute_y(),
272267 absolute_x() + absolute_width(), absolute_y() + absolute_height());
273268 if (item_start_ >= 0) {
274- for (int i = item_start_; i <= item_end_; i++) {
275- UIBasePtr item_ptr = *static_cast<UIBasePtr*>(items_[i]->GetPointerFromInternalField(0));
269+ BOOST_FOREACH (UIBasePtr& item_ptr, items_) {
276270 item_ptr->Draw();
277271 }
278272 }
--- a/client/ui/UIList.hpp
+++ b/client/ui/UIList.hpp
@@ -33,7 +33,7 @@ class UIList : public UIBase {
3333 private:
3434 std::array<ImageHandlePtr,4> scrollbar_base_image_handle_;
3535
36- std::vector<Persistent<Object>> items_;
36+ std::vector<UIBasePtr> items_;
3737
3838 int scroll_y_, max_scroll_y_, scroll_y_target_;
3939 int scrollbar_height_, scrollbar_y_;
--- a/common/database/AccountProperty.hpp
+++ b/common/database/AccountProperty.hpp
@@ -8,6 +8,7 @@ enum AccountProperty {
88 REVISION = 0x0,
99 PUBLIC_KEY = 0x1,
1010 LOGIN = 0x2,
11+ CHANNEL = 0x3,
1112 NAME = 0xA3,
1213 TRIP = 0xA4,
1314 MODEL_NAME = 0xA5,
--- a/common/network/Command.cpp
+++ b/common/network/Command.cpp
@@ -136,7 +136,7 @@ ServerReceiveAccountInitializeData::ServerReceiveAccountInitializeData(const std
136136 }
137137
138138 ServerUpdateAccountProperty::ServerUpdateAccountProperty(AccountProperty property, const std::string& value) :
139-Command(header::ServerUpdateAccountProperty, Utils::Serialize(property, value))
139+Command(header::ServerUpdateAccountProperty, Utils::Serialize(property) + value)
140140 {
141141
142142 }
--- a/common/network/Session.cpp
+++ b/common/network/Session.cpp
@@ -25,7 +25,8 @@ namespace network {
2525 serialized_byte_sum_(0),
2626 compressed_byte_sum_(0),
2727 write_average_limit_(999999),
28- id_(0)
28+ id_(0),
29+ channel_(0)
2930 {
3031
3132 }
@@ -129,6 +130,16 @@ namespace network {
129130 id_ = id;
130131 }
131132
133+ unsigned char Session::channel() const
134+ {
135+ return channel_;
136+ }
137+
138+ void Session::set_channel(unsigned char channel)
139+ {
140+ channel_ = channel;
141+ }
142+
132143 bool Session::online() const
133144 {
134145 return online_;
--- a/common/network/Session.hpp
+++ b/common/network/Session.hpp
@@ -60,6 +60,9 @@ namespace network {
6060 void set_id(UserID id);
6161 bool online() const;
6262
63+ unsigned char channel() const;
64+ void set_channel(unsigned char channel);
65+
6366 std::string global_ip() const;
6467 uint16_t udp_port() const;
6568 void set_global_ip(const std::string& global_ip);
@@ -118,6 +121,7 @@ namespace network {
118121 int write_average_limit_;
119122
120123 UserID id_;
124+ unsigned char channel_;
121125 };
122126
123127 }
--- a/server/Account.cpp
+++ b/server/Account.cpp
@@ -78,9 +78,9 @@ std::string Account::GetUserRevisionPatch(UserID user_id, uint32_t revision)
7878
7979 PropertyMap& property_map = usermap_it->second;
8080
81- for (auto it = property_map.begin(); it != property_map.end(); ++it) {
82- if (it->second.revision > revision) {
83- patch += network::Utils::Serialize((uint16_t)it->first) + it->second.value;
81+ BOOST_FOREACH (auto& property, property_map) {
82+ if (property.second.revision > revision) {
83+ patch += network::Utils::Serialize((uint16_t)property.first) + property.second.value;
8484 }
8585 }
8686 }
@@ -261,6 +261,18 @@ uint32_t Account::GetUserRevision(UserID user_id) const
261261 return revision;
262262 }
263263
264+void Account::SetUserChannel(UserID user_id, unsigned char channel)
265+{
266+ Set(user_id, CHANNEL, channel);
267+}
268+
269+unsigned char Account::GetUserChannel(UserID user_id) const
270+{
271+ unsigned char channel = 0;
272+ Get(user_id, CHANNEL, &channel);
273+ return channel;
274+}
275+
264276 void Account::SetUserPosition(UserID user_id, const PlayerPosition& pos)
265277 {
266278 auto it = position_map_.find(user_id);
--- a/server/Account.hpp
+++ b/server/Account.hpp
@@ -48,6 +48,9 @@ class Account {
4848 uint16_t GetUserUDPPort(UserID) const;
4949 void SetUserUDPPort(UserID, uint16_t);
5050 uint32_t GetUserRevision(UserID) const;
51+
52+ void SetUserChannel(UserID, unsigned char);
53+ unsigned char GetUserChannel(UserID) const;
5154
5255 void SetUserPosition(UserID, const PlayerPosition&);
5356 PlayerPosition GetUserPosition(UserID) const;
--- a/server/Server.cpp
+++ b/server/Server.cpp
@@ -153,21 +153,29 @@ namespace network {
153153 Logger::Info("Active connection: %d", GetUserCount());
154154 }
155155
156- void Server::SendAll(const Command& command)
156+ void Server::SendAll(const Command& command, int channel, bool limited)
157157 {
158158 BOOST_FOREACH(SessionWeakPtr& ptr, sessions_) {
159159 if (auto session = ptr.lock()) {
160- session->Send(command);
160+ if (channel < 0 || (channel >= 0 && session->channel() == channel)) {
161+ if (!limited || session->write_average_limit() > session->GetWriteByteAverage()) {
162+ session->Send(command);
163+ }
164+ }
161165 }
162166 }
163167 }
164168
165- void Server::SendAllLimited(const Command& command)
169+ void Server::SendOthers(const Command& command, uint32_t self_id, int channel, bool limited)
166170 {
167171 BOOST_FOREACH(SessionWeakPtr& ptr, sessions_) {
168172 if (auto session = ptr.lock()) {
169- if (session->write_average_limit() > session->GetWriteByteAverage()) {
170- session->Send(command);
173+ if (channel < 0 || (channel >= 0 && session->channel() == channel)) {
174+ if (!limited || session->write_average_limit() > session->GetWriteByteAverage()) {
175+ if (session->id() != self_id) {
176+ session->Send(command);
177+ }
178+ }
171179 }
172180 }
173181 }
@@ -185,34 +193,6 @@ namespace network {
185193 }
186194 }
187195
188- void Server::SendOthers(const Command& command, SessionWeakPtr self_ptr)
189- {
190- BOOST_FOREACH(SessionWeakPtr& ptr, sessions_) {
191- if (auto session = ptr.lock()) {
192- if (auto self = self_ptr.lock()) {
193- if (*session != *self) {
194- session->Send(command);
195- }
196- }
197- }
198- }
199- }
200-
201- void Server::SendOthersLimited(const Command& command, SessionWeakPtr self_ptr)
202- {
203- BOOST_FOREACH(SessionWeakPtr& ptr, sessions_) {
204- if (auto session = ptr.lock()) {
205- if (auto self = self_ptr.lock()) {
206- if (*session != *self) {
207- if (session->write_average_limit() > session->GetWriteByteAverage()) {
208- session->Send(command);
209- }
210- }
211- }
212- }
213- }
214- }
215-
216196 void Server::SendUDPTestPacket(const std::string& ip_address, uint16_t port)
217197 {
218198 using boost::asio::ip::udp;
--- a/server/Server.hpp
+++ b/server/Server.hpp
@@ -30,11 +30,10 @@ class Server {
3030 void Start(CallbackFuncPtr callback);
3131 void Stop();
3232 void Stop(int interrupt_type);
33- void SendAll(const Command&);
34- void SendAllLimited(const Command& command);
33+
34+ void SendAll(const Command&, int channel = -1, bool limited = false);
35+ void SendOthers(const Command&, uint32_t self_id, int channel = -1, bool limited = false);
3536 void SendTo(const Command&, uint32_t);
36- void SendOthers(const Command&, SessionWeakPtr);
37- void SendOthersLimited(const Command&, SessionWeakPtr);
3837
3938 bool Empty() const;
4039 std::string GetStatusJSON() const;
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -108,7 +108,7 @@ int main(int argc, char* argv[])
108108 server.SendTo(send_command, user_id);
109109 }
110110 } else {
111- server.SendAll(send_command);
111+ server.SendAll(send_command, session->channel());
112112 }
113113
114114 Logger::Info("Receive JSON: %s", message_json.str());
@@ -124,8 +124,8 @@ int main(int argc, char* argv[])
124124 PlayerPosition pos;
125125 network::Utils::Deserialize(c.body(), &pos.x, &pos.y, &pos.z, &pos.theta, &pos.vy);
126126 account.SetUserPosition(session->id(), pos);
127- server.SendOthersLimited(network::ClientUpdatePlayerPosition(session->id(),
128- pos.x,pos.y,pos.z,pos.theta, pos.vy), c.session());
127+ server.SendOthers(network::ClientUpdatePlayerPosition(session->id(),
128+ pos.x,pos.y,pos.z,pos.theta, pos.vy), session->id(), session->channel(), true);
129129 }
130130 }
131131 break;
@@ -237,7 +237,7 @@ int main(int argc, char* argv[])
237237
238238 server.SendOthers(
239239 network::ClientReceiveAccountRevisionUpdateNotify(session->id(),
240- account.GetUserRevision(session->id())), c.session());
240+ account.GetUserRevision(session->id())), session->id());
241241
242242 Logger::Info(msg);
243243 }
@@ -265,8 +265,8 @@ int main(int argc, char* argv[])
265265 {
266266 if (auto session = c.session().lock()) {
267267 AccountProperty property;
268- std::string value;
269- network::Utils::Deserialize(c.body(), &property, &value);
268+ std::string buffer = c.body().substr(sizeof(AccountProperty));
269+ network::Utils::Deserialize(c.body(), &property);
270270
271271 auto old_revision = account.GetUserRevision(session->id());
272272
@@ -274,17 +274,24 @@ int main(int argc, char* argv[])
274274
275275 case NAME:
276276 {
277- account.SetUserName(session->id(), value);
277+ account.SetUserName(session->id(), buffer);
278278 }
279279 break;
280280 case TRIP:
281281 {
282- account.SetUserTrip(session->id(), value);
282+ account.SetUserTrip(session->id(), buffer);
283283 }
284284 break;
285285 case MODEL_NAME:
286286 {
287- account.SetUserModelName(session->id(), value);
287+ account.SetUserModelName(session->id(), buffer);
288+ }
289+ break;
290+ case CHANNEL:
291+ {
292+ unsigned char value;
293+ network::Utils::Deserialize(buffer, &value);
294+ account.SetUserChannel(session->id(), value);
288295 }
289296 break;
290297 default:
--- a/server/version.hpp
+++ b/server/version.hpp
@@ -8,10 +8,10 @@
88 #define MMO_VERSION_TOSTRING(val) MMO_VERSION_TOSTRING_(val)
99
1010 #define MMO_VERSION_MAJOR 0
11-#define MMO_VERSION_MINOR 1
12-#define MMO_VERSION_REVISION 9
11+#define MMO_VERSION_MINOR 2
12+#define MMO_VERSION_REVISION 0
1313
14-#define MMO_PROTOCOL_VERSION 2
14+#define MMO_PROTOCOL_VERSION 3
1515
1616 #ifdef MMO_VERSION_BUILD
1717 #define MMO_VERSION_BUILD_TEXT " Build " MMO_VERSION_TOSTRING(MMO_VERSION_BUILD)