コード例 #1
0
ファイル: matcher.hpp プロジェクト: ariosx/actor-framework
 bool operator()(const message& tup, pseudo_tuple<Us...>* out) const {
   auto& tarr = static_types_array<Ts...>::arr;
   if (sizeof...(Us) == 0) {
     // this pattern only has wildcards and thus always matches
     return true;
   }
   if (tup.size() < sizeof...(Us)) {
     return false;
   }
   if (out) {
     size_t pos = 0;
     size_t fallback_pos = 0;
     auto fpush = [&](const typename message::const_iterator& iter) {
       (*out)[pos++] = const_cast<void*>(iter.value());
     };
     auto fcommit = [&] { fallback_pos = pos; };
     auto frollback = [&] { pos = fallback_pos; };
     return (*this)(tup.begin(), tup.end(), tarr.begin(), tarr.end(), fpush,
                    fcommit, frollback);
   }
   auto no_push = [](const typename message::const_iterator&) { };
   auto nop = [] { };
   return (*this)(tup.begin(), tup.end(), tarr.begin(), tarr.end(), no_push,
                  nop, nop);
 }
コード例 #2
0
ファイル: GateModule.cpp プロジェクト: dr520/moon_net
void GateModule::ClientClose(const message& msg)
{
	buffer_reader buf(msg.data(), msg.size());

	std::string addr;
	buf >> addr;

	Log.trace("1.client close [socketid:{0}] [address:{1}] begin.", msg.get_socket_id().value, addr.data());
	auto pconn = m_Connections->find(msg.get_socket_id());
	if (pconn == nullptr)
	{
		Log.trace("!!client close failed can not find conn [socketid:{0}].", msg.get_socket_id().value);
		return;
	}

	auto accountID = pconn->getaccount_id();
	auto playerID = pconn->getplayer_id();

	Log.trace("3.client close [socketid:{0}] [address:{1}] find account data[accountid:{2}]  success[playerid:{3}].", msg.get_socket_id().value, addr.data(), accountID.value,playerID.value);
	
	OnClientClose(accountID, playerID);
	
	if (m_Connections->remove(msg.get_socket_id()))
	{
		Log.trace("client close [socketid:{0}] [address:{1}]  accountID[{2}] playerID[{3}] end.", msg.get_socket_id().value, addr.data(), accountID.value, playerID.value);
	}
	else
	{
		assert(0);
	}
}
コード例 #3
0
ファイル: GateModule.cpp プロジェクト: dr520/moon_net
void GateModule::ClientConnect(const message& msg)
{
	buffer_reader buf(msg.data(), msg.size());

	std::string addr;
	buf >> addr;
	Log.trace("socket [socket:{0}] [address:{1}] connect", msg.get_socket_id().value,addr.data());
}
コード例 #4
0
ファイル: GateModule.cpp プロジェクト: dr520/moon_net
//客户端发来的数据
void GateModule::ClientData(const message& msg)
{
	if (msg.size() == 0)
		return;

	user_id id(account_id::create(0));
	id.set_socket_id(msg.get_socket_id());

	if (DispatchMessages(id,msg,0))
	{
		return;
	}
	
	auto pconn = m_Connections->find(msg.get_socket_id());
	if (pconn == nullptr)
	{
		Log.trace("非法数据!");
		return;
	}


	uint16_t msgID = *(uint16_t*)msg.data();
	if (msgID > (uint16_t)EMsgID::MSG_MUST_HAVE_PLAYERID)
	{
		if (pconn->getplayer_id() == player_id())
		{
			Log.trace("非法数据!");
			return;
		}
	}

	UserContext ctx;
	ctx.accountid = pconn->getaccount_id();
	ctx.playerid = pconn->getplayer_id();

	msg.set_userdata((uint8_t*)&ctx,sizeof(ctx));

	if (pconn->getscene_id() != 0)
	{
		//如果在玩家在场景模块中 则发送给场景模块
	}
	else
	{
		if (m_WorldModule == 0)
		{
			m_WorldModule = GetOtherModule("world");
			assert(m_WorldModule != 0);
		}

		//否则发送给 world 模块
	}
}
コード例 #5
0
merged_tuple::cow_ptr merged_tuple::make(message x, message y) {
  data_type data{x.vals(), y.vals()};
  mapping_type mapping;
  auto s = x.size();
  for (size_t i = 0; i < s; ++i) {
    if (x.match_element<index_mapping>(i))
      mapping.emplace_back(1, x.get_as<index_mapping>(i).value - 1);
    else
      mapping.emplace_back(0, i);
  }
  return cow_ptr{make_counted<merged_tuple>(std::move(data),
                                            std::move(mapping))};
}
コード例 #6
0
ファイル: ModuleBases.cpp プロジェクト: dr520/moon_net
bool ModuleBases::DispatchMessages(const user_id & userid, const message & msg, uint64_t sender_echo_id)
{
	buffer_reader br(msg.data(), msg.size());

	uint16_t msgID = 0;
	br >> msgID;

	if (msgID == uint16_t(EMsgID::MSG_S2S_ClientClose))
	{
		account_id accountID;
		player_id playerID;
		br >> accountID.value;
		br >> playerID.value;
		OnClientClose(accountID, playerID);
		return true;
	}
コード例 #7
0
ファイル: match_case.hpp プロジェクト: CCJY/actor-framework
 match_case::result invoke(optional<message>& res, message& msg) override {
   intermediate_tuple it;
   detail::meta_elements<pattern> ms;
   // check if try_match() reports success
   if (!detail::try_match(msg, ms.arr.data(), ms.arr.size(), it.data)) {
     return match_case::no_match;
   }
   // detach msg before invoking m_fun if needed
   if (is_manipulator) {
     msg.force_detach();
     // update pointers in our intermediate tuple
     for (size_t i = 0; i < msg.size(); ++i) {
       // msg is guaranteed to be detached, hence we don't need to
       // check this condition over and over again via mutable_at
       it[i] = const_cast<void*>(msg.at(i));
     }
   }
   lfinvoker<std::is_same<result_type, void>::value, F> fun{m_fun};
   detail::optional_message_visitor omv;
   auto funres = apply_args(fun, detail::get_indices(it), it);
   res = omv(funres);
   return match_case::match;
 }